mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 14:17:47 +00:00
[topology] adding Child:Clear() and Router::Clear() (#4195)
This commit is contained in:
committed by
Jonathan Hui
parent
4feadec950
commit
c5d4fc5cbe
@@ -102,7 +102,15 @@ ChildTable::ChildTable(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, mMaxChildrenAllowed(kMaxChildren)
|
||||
{
|
||||
memset(mChildren, 0, sizeof(mChildren));
|
||||
Clear();
|
||||
}
|
||||
|
||||
void ChildTable::Clear(void)
|
||||
{
|
||||
for (Child *child = &mChildren[0]; child < OT_ARRAY_END(mChildren); child++)
|
||||
{
|
||||
child->Clear();
|
||||
}
|
||||
}
|
||||
|
||||
Child *ChildTable::GetChildAtIndex(uint16_t aChildIndex)
|
||||
@@ -124,7 +132,7 @@ Child *ChildTable::GetNewChild(void)
|
||||
{
|
||||
if (child->GetState() == Child::kStateInvalid)
|
||||
{
|
||||
memset(child, 0, sizeof(Child));
|
||||
child->Clear();
|
||||
ExitNow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public:
|
||||
* This method clears the child table.
|
||||
*
|
||||
*/
|
||||
void Clear(void) { memset(mChildren, 0, sizeof(mChildren)); }
|
||||
void Clear(void);
|
||||
|
||||
/**
|
||||
* This method returns the child table index for a given `Child` instance.
|
||||
|
||||
@@ -117,7 +117,7 @@ Mle::Mle(Instance &aInstance)
|
||||
|
||||
memset(&mLeaderData, 0, sizeof(mLeaderData));
|
||||
memset(&mParentLeaderData, 0, sizeof(mParentLeaderData));
|
||||
memset(&mParent, 0, sizeof(mParent));
|
||||
mParent.Clear();
|
||||
memset(&mChildIdRequest, 0, sizeof(mChildIdRequest));
|
||||
memset(&mLinkLocal64, 0, sizeof(mLinkLocal64));
|
||||
memset(&mMeshLocal64, 0, sizeof(mMeshLocal64));
|
||||
@@ -125,7 +125,7 @@ Mle::Mle(Instance &aInstance)
|
||||
memset(&mLinkLocalAllThreadNodes, 0, sizeof(mLinkLocalAllThreadNodes));
|
||||
memset(&mRealmLocalAllThreadNodes, 0, sizeof(mRealmLocalAllThreadNodes));
|
||||
memset(&mLeaderAloc, 0, sizeof(mLeaderAloc));
|
||||
memset(&mParentCandidate, 0, sizeof(mParentCandidate));
|
||||
mParentCandidate.Clear();
|
||||
ResetCounters();
|
||||
|
||||
// link-local 64
|
||||
@@ -423,7 +423,7 @@ otError Mle::Restore(void)
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
memset(&mParent, 0, sizeof(mParent));
|
||||
mParent.Clear();
|
||||
mParent.SetExtAddress(*static_cast<Mac::ExtAddress *>(&parentInfo.mExtAddress));
|
||||
mParent.SetDeviceMode(DeviceMode(DeviceMode::kModeFullThreadDevice | DeviceMode::kModeRxOnWhenIdle |
|
||||
DeviceMode::kModeFullNetworkData | DeviceMode::kModeSecureDataRequest));
|
||||
@@ -3175,8 +3175,7 @@ exit:
|
||||
|
||||
void Mle::ResetParentCandidate(void)
|
||||
{
|
||||
memset(&mParentCandidate, 0, sizeof(mParentCandidate));
|
||||
mParentCandidate.SetState(Neighbor::kStateInvalid);
|
||||
mParentCandidate.Clear();
|
||||
}
|
||||
|
||||
otError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence)
|
||||
|
||||
@@ -1650,8 +1650,6 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa
|
||||
{
|
||||
VerifyOrExit((child = mChildTable.GetNewChild()) != NULL);
|
||||
|
||||
memset(child, 0, sizeof(*child));
|
||||
|
||||
// MAC Address
|
||||
child->SetExtAddress(macAddr);
|
||||
child->GetLinkInfo().Clear();
|
||||
@@ -3531,7 +3529,7 @@ void MleRouter::RestoreChildren(void)
|
||||
foundDuplicate = true;
|
||||
}
|
||||
|
||||
memset(child, 0, sizeof(*child));
|
||||
child->Clear();
|
||||
|
||||
child->SetExtAddress(*static_cast<const Mac::ExtAddress *>(&childInfo.mExtAddress));
|
||||
child->GetLinkInfo().Clear();
|
||||
|
||||
@@ -183,7 +183,7 @@ void RouterTable::UpdateAllocation(void)
|
||||
|
||||
if (router.GetRouterId() != routerId)
|
||||
{
|
||||
memset(&router, 0, sizeof(router));
|
||||
router.Clear();
|
||||
router.SetRloc16(Mle::Mle::GetRloc16(routerId));
|
||||
router.SetNextHop(Mle::kInvalidRouterId);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ void RouterTable::UpdateAllocation(void)
|
||||
for (uint8_t index = mActiveRouterCount; index < Mle::kMaxRouters; index++)
|
||||
{
|
||||
Router &router = mRouters[index];
|
||||
memset(&router, 0, sizeof(router));
|
||||
router.Clear();
|
||||
router.SetRloc16(0xffff);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,12 @@ void Neighbor::GenerateChallenge(void)
|
||||
Random::NonCrypto::FillBuffer(mValidPending.mPending.mChallenge, sizeof(mValidPending.mPending.mChallenge));
|
||||
}
|
||||
|
||||
void Child::Clear(void)
|
||||
{
|
||||
memset(reinterpret_cast<void *>(this), 0, sizeof(Child));
|
||||
SetState(kStateInvalid);
|
||||
}
|
||||
|
||||
bool Child::IsStateValidOrAttaching(void) const
|
||||
{
|
||||
bool rval = false;
|
||||
@@ -240,4 +246,10 @@ void Child::GenerateChallenge(void)
|
||||
Random::NonCrypto::FillBuffer(mAttachChallenge, sizeof(mAttachChallenge));
|
||||
}
|
||||
|
||||
void Router::Clear(void)
|
||||
{
|
||||
memset(reinterpret_cast<void *>(this), 0, sizeof(Router));
|
||||
SetState(kStateInvalid);
|
||||
}
|
||||
|
||||
} // namespace ot
|
||||
|
||||
@@ -434,6 +434,12 @@ public:
|
||||
otChildIp6AddressIterator mIndex;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method clears the child entry.
|
||||
*
|
||||
*/
|
||||
void Clear(void);
|
||||
|
||||
/**
|
||||
* This method indicates if the child state is valid or being attached or being restored.
|
||||
*
|
||||
@@ -654,6 +660,12 @@ private:
|
||||
class Router : public Neighbor
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* This method clears the router entry.
|
||||
*
|
||||
*/
|
||||
void Clear(void);
|
||||
|
||||
/**
|
||||
* This method gets the router ID of the next hop to this router.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user