Use a new specialized ChildInfo structure for children information persistent storage (#1572)

Create a new specialized ChildInfo structure, which will be only used for children information storage

Also update otPlatSettingsGet() to be consistent with its documentation:
* return the actual length of the setting, but not the actual length it read to aValue
This commit is contained in:
Shu Chen
2017-04-11 19:17:20 -07:00
committed by Jonathan Hui
parent a5c3fb6aaf
commit 7eed76c781
4 changed files with 45 additions and 28 deletions
+1 -1
View File
@@ -378,7 +378,7 @@ ThreadError otPlatSettingsGet(otInstance *aInstance, uint16_t aKey, int aIndex,
utilsFlashRead(address + sizeof(struct settingsBlock), aValue, readLength);
}
valueLength = readLength;
valueLength = block.length;
error = kThreadError_None;
}
+18 -18
View File
@@ -123,6 +123,24 @@ enum AlocAllocation
kAloc16NeighborDiscoveryAgentEnd = 0xfc4e,
};
/**
* This structure represents the device's own network information for persistent storage.
*
*/
struct NetworkInfo
{
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 mMlIid[OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE]; ///< IID from ML-EID
};
/**
* This class implements MLE Header generation and parsing.
*
@@ -1398,24 +1416,6 @@ private:
MessageQueue mDelayedResponses;
/**
* This struct represents the device's own network information for persistent storage.
*
*/
typedef struct NetworkInfo
{
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 mMlIid[OT_IP6_ADDRESS_SIZE - OT_IP6_PREFIX_SIZE]; ///< IID from ML-EID
} NetworkInfo;
struct
{
uint8_t mChallenge[ChallengeTlv::kMaxSize];
+14 -9
View File
@@ -3322,13 +3322,13 @@ ThreadError MleRouter::RestoreChildren(void)
for (uint8_t i = 0; ; i++)
{
Child *child;
otChildInfo childInfo;
ChildInfo childInfo;
uint16_t length;
length = sizeof(childInfo);
SuccessOrExit(otPlatSettingsGet(mNetif.GetInstance(), kKeyChildInfo, i,
reinterpret_cast<uint8_t *>(&childInfo), &length));
VerifyOrExit(length == sizeof(childInfo), error = kThreadError_Failed);
VerifyOrExit(length >= sizeof(childInfo), error = kThreadError_Parse);
VerifyOrExit((child = NewChild()) != NULL, error = kThreadError_NoBufs);
memset(child, 0, sizeof(*child));
@@ -3336,10 +3336,7 @@ ThreadError MleRouter::RestoreChildren(void)
child->SetExtAddress(*static_cast<Mac::ExtAddress *>(&childInfo.mExtAddress));
child->SetRloc16(childInfo.mRloc16);
child->SetTimeout(childInfo.mTimeout);
child->SetDeviceMode((childInfo.mRxOnWhenIdle ? ModeTlv::kModeRxOnWhenIdle : 0) |
(childInfo.mSecureDataRequest ? ModeTlv::kModeSecureDataRequest : 0) |
(childInfo.mFullFunction ? ModeTlv::kModeFFD : 0) |
(childInfo.mFullNetworkData ? ModeTlv::kModeFullNetworkData : 0));
child->SetDeviceMode(childInfo.mMode);
child->SetState(Neighbor::kStateRestored);
child->SetLastHeard(Timer::GetNow());
mNetif.GetMeshForwarder().GetSourceMatchController().SetSrcMatchAsShort(*child, true);
@@ -3355,7 +3352,7 @@ ThreadError MleRouter::RemoveStoredChild(uint16_t aChildRloc16)
for (uint8_t i = 0; i < kMaxChildren; i++)
{
otChildInfo childInfo;
ChildInfo childInfo;
uint16_t length = sizeof(childInfo);
SuccessOrExit(otPlatSettingsGet(mNetif.GetInstance(), kKeyChildInfo, i,
@@ -3376,12 +3373,20 @@ exit:
ThreadError MleRouter::StoreChild(uint16_t aChildRloc16)
{
ThreadError error = kThreadError_None;
otChildInfo childInfo;
Child *child;
ChildInfo childInfo;
SuccessOrExit(error = GetChildInfoById(GetChildId(aChildRloc16), childInfo));
VerifyOrExit((child = FindChild(GetChildId(aChildRloc16))) != NULL, error = kThreadError_NotFound);
IgnoreReturnValue(RemoveStoredChild(aChildRloc16));
memset(&childInfo, 0, sizeof(childInfo));
memcpy(&childInfo.mExtAddress, &child->GetExtAddress(), sizeof(childInfo.mExtAddress));
childInfo.mTimeout = child->GetTimeout();
childInfo.mRloc16 = child->GetRloc16();
childInfo.mMode = child->GetDeviceMode();
error = otPlatSettingsAdd(mNetif.GetInstance(), kKeyChildInfo, reinterpret_cast<uint8_t *>(&childInfo),
sizeof(childInfo));
+12
View File
@@ -64,6 +64,18 @@ class NetworkDataLeader;
* @{
*/
/**
* This structure represents the child information for persistent storage.
*
*/
struct ChildInfo
{
Mac::ExtAddress mExtAddress; ///< Extended Address
uint32_t mTimeout; ///< Timeout
uint16_t mRloc16; ///< RLOC16
uint8_t mMode; ///< The MLE device mode
};
/**
* This class implements MLE functionality required by the Thread Router and Leader roles.
*