From 7ac9e9323734d8a23c5cce30d81a3cc875519078 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hubert=20Mi=C5=9B?= Date: Tue, 7 Mar 2017 19:56:31 +0100 Subject: [PATCH] Store IID of ML-EID in NVM. (#1423) --- include/openthread/types.h | 1 + src/core/thread/mle.cpp | 10 +++++++++- src/core/thread/mle.hpp | 17 +++++++++-------- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/openthread/types.h b/include/openthread/types.h index d58380e6d..64e346fc9 100644 --- a/include/openthread/types.h +++ b/include/openthread/types.h @@ -311,6 +311,7 @@ typedef struct otExtAddress uint8_t m8[OT_EXT_ADDRESS_SIZE]; ///< IEEE 802.15.4 Extended Address bytes } otExtAddress; +#define OT_IP6_PREFIX_SIZE 8 ///< Size of an IPv6 prefix (bytes) #define OT_IP6_ADDRESS_SIZE 16 ///< Size of an IPv6 address (bytes) /** diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index ec238113a..3540c406b 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -128,7 +128,7 @@ Mle::Mle(ThreadNetif &aThreadNetif) : meshLocalPrefix[7] = 0x00; // mesh-local 64 - for (int i = 8; i < 16; i++) + for (int i = OT_IP6_PREFIX_SIZE; i < OT_IP6_ADDRESS_SIZE; i++) { mMeshLocal64.GetAddress().mFields.m8[i] = static_cast(otPlatRandomGet()); } @@ -284,6 +284,10 @@ ThreadError Mle::Restore(void) mNetif.GetMac().SetExtAddress(networkInfo.mExtAddress); UpdateLinkLocalAddress(); + memcpy(&mMeshLocal64.GetAddress().mFields.m8[OT_IP6_PREFIX_SIZE], + networkInfo.mMlIid, + OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE); + if (networkInfo.mDeviceState == kDeviceStateChild) { length = sizeof(mParent); @@ -327,6 +331,10 @@ ThreadError Mle::Store(void) OPENTHREAD_CONFIG_STORE_FRAME_COUNTER_AHEAD; networkInfo.mPreviousPartitionId = mLeaderData.GetPartitionId(); memcpy(networkInfo.mExtAddress.m8, mNetif.GetMac().GetExtAddress(), sizeof(networkInfo.mExtAddress)); + memcpy(networkInfo.mMlIid, + &mMeshLocal64.GetAddress().mFields.m8[OT_IP6_PREFIX_SIZE], + OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE); + if (mDeviceState == kDeviceStateChild) { diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 2091f5f9c..65310d5a8 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1392,15 +1392,16 @@ private: */ typedef struct NetworkInfo { - DeviceState mDeviceState; ///< Current Thread interface state. + DeviceState mDeviceState; ///< Current Thread interface state. - uint8_t mDeviceMode; ///< Device mode setting. - uint16_t mRloc16; ///< RLOC16 - uint32_t mKeySequence; ///< Key Sequence - uint32_t mMleFrameCounter; ///< MLE Frame Counter - uint32_t mMacFrameCounter; ///< MAC Frame Counter - uint32_t mPreviousPartitionId; ///< PartitionId - Mac::ExtAddress mExtAddress; ///< Extended Address + uint8_t mDeviceMode; ///< Device mode setting. + uint16_t mRloc16; ///< RLOC16 + uint32_t mKeySequence; ///< Key Sequence + uint32_t mMleFrameCounter; ///< MLE Frame Counter + uint32_t mMacFrameCounter; ///< MAC Frame Counter + uint32_t mPreviousPartitionId; ///< PartitionId + Mac::ExtAddress mExtAddress; ///< Extended Address + uint8_t mMlIid[OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE]; ///< IID from ML-EID } NetworkInfo; struct