[mle] use ChildUpdateResponseInfo to pass parameters (#12073)

This commit introduces the `ChildUpdateResponseInfo` struct to
encapsulate parameters for sending "Child Update Response" messages.

The new struct holds the list of TLVs to include, the received
challenge, and the destination address.

Related methods such as `SendChildUpdateResponse()` are updated to use
the new struct. This simplifies the method signatures by reducing the
number of arguments and improves code clarity by grouping related
data.
This commit is contained in:
Abtin Keshavarzian
2025-10-28 14:17:01 -07:00
committed by GitHub
parent ca3e4d50fc
commit eede70c0ef
3 changed files with 79 additions and 80 deletions
+37 -39
View File
@@ -2213,38 +2213,39 @@ exit:
void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
{
Error error = kErrorNone;
Mac::ExtAddress extAddr;
DeviceMode mode;
RxChallenge challenge;
LeaderData leaderData;
uint32_t timeout;
uint16_t supervisionInterval;
Child *child;
DeviceMode oldMode;
TlvList requestedTlvList;
TlvList tlvList;
bool childDidChange = false;
Error error = kErrorNone;
Mac::ExtAddress extAddr;
DeviceMode mode;
LeaderData leaderData;
uint32_t timeout;
uint16_t supervisionInterval;
Child *child;
DeviceMode oldMode;
TlvList requestedTlvList;
ChildUpdateResponseInfo info;
bool childDidChange = false;
Log(kMessageReceive, kTypeChildUpdateRequestOfChild, aRxInfo.mMessageInfo.GetPeerAddr());
VerifyOrExit(!mDetacher.IsDetaching());
info.mDestination = aRxInfo.mMessageInfo.GetPeerAddr();
SuccessOrExit(error = aRxInfo.mMessage.ReadModeTlv(mode));
switch (aRxInfo.mMessage.ReadChallengeTlv(challenge))
switch (aRxInfo.mMessage.ReadChallengeTlv(info.mChallenge))
{
case kErrorNone:
tlvList.Add(Tlv::kResponse);
info.mTlvList.Add(Tlv::kResponse);
break;
case kErrorNotFound:
challenge.Clear();
info.mChallenge.Clear();
break;
default:
ExitNow(error = kErrorParse);
}
tlvList.Add(Tlv::kSourceAddress);
info.mTlvList.Add(Tlv::kSourceAddress);
extAddr.SetFromIid(aRxInfo.mMessageInfo.GetPeerAddr().GetIid());
child = mChildTable.FindChild(extAddr, Child::kInStateAnyExceptInvalid);
@@ -2255,7 +2256,7 @@ void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
// Status TLV (error).
if (mode.IsRxOnWhenIdle())
{
IgnoreError(SendChildUpdateRejectResponse(challenge, aRxInfo.mMessageInfo.GetPeerAddr()));
IgnoreError(SendChildUpdateRejectResponse(info));
}
ExitNow();
@@ -2272,22 +2273,22 @@ void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
oldMode = child->GetDeviceMode();
child->SetDeviceMode(mode);
tlvList.Add(Tlv::kMode);
tlvList.Add(Tlv::kLinkMargin);
info.mTlvList.Add(Tlv::kMode);
info.mTlvList.Add(Tlv::kLinkMargin);
// Parent MUST include Leader Data TLV in Child Update Response
tlvList.Add(Tlv::kLeaderData);
info.mTlvList.Add(Tlv::kLeaderData);
if (!challenge.IsEmpty())
if (!info.mChallenge.IsEmpty())
{
tlvList.Add(Tlv::kMleFrameCounter);
tlvList.Add(Tlv::kLinkFrameCounter);
info.mTlvList.Add(Tlv::kMleFrameCounter);
info.mTlvList.Add(Tlv::kLinkFrameCounter);
}
switch (ProcessAddressRegistrationTlv(aRxInfo, *child))
{
case kErrorNone:
tlvList.Add(Tlv::kAddressRegistration);
info.mTlvList.Add(Tlv::kAddressRegistration);
break;
case kErrorNotFound:
break;
@@ -2315,7 +2316,7 @@ void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
childDidChange = true;
}
tlvList.Add(Tlv::kTimeout);
info.mTlvList.Add(Tlv::kTimeout);
break;
case kErrorNotFound:
@@ -2328,7 +2329,7 @@ void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
switch (Tlv::Find<SupervisionIntervalTlv>(aRxInfo.mMessage, supervisionInterval))
{
case kErrorNone:
tlvList.Add(Tlv::kSupervisionInterval);
info.mTlvList.Add(Tlv::kSupervisionInterval);
break;
case kErrorNotFound:
@@ -2345,7 +2346,7 @@ void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
switch (aRxInfo.mMessage.ReadTlvRequestTlv(requestedTlvList))
{
case kErrorNone:
tlvList.AddElementsFrom(requestedTlvList);
info.mTlvList.AddElementsFrom(requestedTlvList);
break;
case kErrorNotFound:
break;
@@ -2364,7 +2365,7 @@ void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
case kErrorNone:
child->SetCslTimeout(cslTimeout);
// MUST include CSL accuracy TLV when request includes CSL timeout
tlvList.Add(Tlv::kCslClockAccuracy);
info.mTlvList.Add(Tlv::kCslClockAccuracy);
break;
case kErrorNotFound:
break;
@@ -2416,13 +2417,13 @@ void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo)
// from a detached child trying to restore its link with its
// parent which is indicated by the presence of Challenge TLV in
// the message.
if (!challenge.IsEmpty())
if (!info.mChallenge.IsEmpty())
{
child->ClearLastRxFragmentTag();
}
#endif
SendChildUpdateResponseToChild(child, aRxInfo.mMessageInfo, tlvList, challenge);
SendChildUpdateResponseToChild(child, info);
aRxInfo.mClass = RxInfo::kPeerMessage;
@@ -3011,17 +3012,14 @@ exit:
return error;
}
void Mle::SendChildUpdateResponseToChild(Child *aChild,
const Ip6::MessageInfo &aMessageInfo,
const TlvList &aTlvList,
const RxChallenge &aChallenge)
void Mle::SendChildUpdateResponseToChild(Child *aChild, const ChildUpdateResponseInfo &aInfo)
{
Error error = kErrorNone;
TxMessage *message;
VerifyOrExit((message = NewMleMessage(kCommandChildUpdateResponse)) != nullptr, error = kErrorNoBufs);
for (uint8_t tlvType : aTlvList)
for (uint8_t tlvType : aInfo.mTlvList)
{
// Add all TLV types that do not depend on `child`
@@ -3036,7 +3034,7 @@ void Mle::SendChildUpdateResponseToChild(Child *aChild,
break;
case Tlv::kResponse:
SuccessOrExit(error = message->AppendResponseTlv(aChallenge));
SuccessOrExit(error = message->AppendResponseTlv(aInfo.mChallenge));
break;
case Tlv::kSourceAddress:
@@ -3098,15 +3096,15 @@ void Mle::SendChildUpdateResponseToChild(Child *aChild,
}
}
SuccessOrExit(error = message->SendTo(aMessageInfo.GetPeerAddr()));
SuccessOrExit(error = message->SendTo(aInfo.mDestination));
if (aChild == nullptr)
{
Log(kMessageSend, kTypeChildUpdateResponseOfChild, aMessageInfo.GetPeerAddr());
Log(kMessageSend, kTypeChildUpdateResponseOfChild, aInfo.mDestination);
}
else
{
Log(kMessageSend, kTypeChildUpdateResponseOfChild, aMessageInfo.GetPeerAddr(), aChild->GetRloc16());
Log(kMessageSend, kTypeChildUpdateResponseOfChild, aInfo.mDestination, aChild->GetRloc16());
}
exit: