mirror of
https://github.com/espressif/openthread.git
synced 2026-08-30 22:09:54 +00:00
Assign a new child id if the none is already assigned to the child. (#907)
This commit changes the `MleRouter::SendChildIdResponse()` so that a new child id (and rloc16) is assigned to the child if it does not already have one. This ensures that it we receive multiple MLE ChildIdRequest from the same child, the child id remains the same on all the responses.
This commit is contained in:
committed by
Jonathan Hui
parent
a21db36a5b
commit
3688b2a88a
@@ -2064,7 +2064,11 @@ ThreadError MleRouter::HandleChildIdRequest(const Message &aMessage, const Ip6::
|
||||
}
|
||||
}
|
||||
|
||||
child->mState = Neighbor::kStateChildIdRequest;
|
||||
if (child->mState != Neighbor::kStateValid)
|
||||
{
|
||||
child->mState = Neighbor::kStateChildIdRequest;
|
||||
}
|
||||
|
||||
child->mLastHeard = Timer::GetNow();
|
||||
child->mValid.mLinkFrameCounter = linkFrameCounter.GetFrameCounter();
|
||||
child->mValid.mMleFrameCounter = mleFrameCounter.GetFrameCounter();
|
||||
@@ -2112,6 +2116,7 @@ ThreadError MleRouter::HandleChildIdRequest(const Message &aMessage, const Ip6::
|
||||
break;
|
||||
|
||||
case kDeviceStateChild:
|
||||
child->mState = Neighbor::kStateChildIdRequest;
|
||||
BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest);
|
||||
break;
|
||||
|
||||
@@ -2310,20 +2315,23 @@ ThreadError MleRouter::SendChildIdResponse(Child *aChild)
|
||||
SuccessOrExit(error = AppendSourceAddress(*message));
|
||||
SuccessOrExit(error = AppendLeaderData(*message));
|
||||
|
||||
// pick next Child ID that is not being used
|
||||
do
|
||||
if (aChild->mState != Neighbor::kStateValid)
|
||||
{
|
||||
mNextChildId++;
|
||||
|
||||
if (mNextChildId > kMaxChildId)
|
||||
// pick next Child ID that is not being used
|
||||
do
|
||||
{
|
||||
mNextChildId = kMinChildId;
|
||||
}
|
||||
}
|
||||
while (FindChild(mNextChildId) != NULL);
|
||||
mNextChildId++;
|
||||
|
||||
// allocate Child ID
|
||||
aChild->mValid.mRloc16 = mMac.GetShortAddress() | mNextChildId;
|
||||
if (mNextChildId > kMaxChildId)
|
||||
{
|
||||
mNextChildId = kMinChildId;
|
||||
}
|
||||
}
|
||||
while (FindChild(mNextChildId) != NULL);
|
||||
|
||||
// allocate Child ID
|
||||
aChild->mValid.mRloc16 = mMac.GetShortAddress() | mNextChildId;
|
||||
}
|
||||
|
||||
SuccessOrExit(error = AppendAddress16(*message, aChild->mValid.mRloc16));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user