[mle] use PrevRoleRestorer for child update challenge (#11801)

This commit updates the challenge/response mechanism used when a
detached device sends a "Child Update Request" to restore its role as
a child.

Previously, this process shared the `mParentRequestChallenge` with the
parent search mechanism. This logic is now consolidated within the
`PrevRoleRestorer` class, which now manages the generation and
tracking of the `TxChallenge` used in "Child Update Request".

This change simplifies the `Mle` class design and makes the child role
restoration logic separate from the parent search and attach process.
This separation allows for future enhancements where a device may run
both mechanisms in parallel.
This commit is contained in:
Abtin Keshavarzian
2025-08-11 12:18:25 -07:00
committed by GitHub
parent 2bc7712f57
commit 343e10dafe
2 changed files with 14 additions and 11 deletions
+11 -4
View File
@@ -1912,10 +1912,16 @@ Error Mle::SendChildUpdateRequestToParent(ChildUpdateRequestMode aMode)
VerifyOrExit((message = NewMleMessage(kCommandChildUpdateRequest)) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->AppendModeTlv(mDeviceMode));
if ((aMode == kAppendChallengeTlv) || IsDetached())
switch (aMode)
{
mParentRequestChallenge.GenerateRandom();
SuccessOrExit(error = message->AppendChallengeTlv(mParentRequestChallenge));
case kNormalChildUpdateRequest:
case kAppendZeroTimeout:
break;
case kAppendChallengeTlv:
case kToRestoreChildRole:
mPrevRoleRestorer.GenerateRandomChallenge();
SuccessOrExit(error = message->AppendChallengeTlv(mPrevRoleRestorer.GetChallenge()));
break;
}
switch (mRole)
@@ -3425,7 +3431,8 @@ void Mle::HandleChildUpdateResponseOnChild(RxInfo &aRxInfo)
switch (mRole)
{
case kRoleDetached:
VerifyOrExit(response == mParentRequestChallenge, error = kErrorSecurity);
VerifyOrExit(mPrevRoleRestorer.IsRestoringChildRole(), error = kErrorSecurity);
VerifyOrExit(response == mPrevRoleRestorer.GetChallenge(), error = kErrorSecurity);
break;
case kRoleChild:
+3 -7
View File
@@ -1755,10 +1755,8 @@ private:
bool IsRestoringRouterOrLeaderRole(void) const { return mState == kRestoringRouterOrLeaderRole; }
void HandleTimer(void);
#if OPENTHREAD_FTD
void GenerateRandomChallenge(void) { mChallenge.GenerateRandom(); }
const TxChallenge &GetChallenge(void) const { return mChallenge; }
#endif
private:
static constexpr uint32_t kMaxStartDelay = 25;
@@ -1782,12 +1780,10 @@ private:
using DelayTimer = TimerMilliIn<Mle, &Mle::HandleRoleRestorerTimer>;
State mState;
uint8_t mAttempts;
DelayTimer mTimer;
#if OPENTHREAD_FTD
State mState;
uint8_t mAttempts;
DelayTimer mTimer;
TxChallenge mChallenge;
#endif
};
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -