[mle] simplify SendChildUpdateRequest() (#8951)

This commit updates `Mle::SendChildUpdateRequest()`:
- It removes the use of default parameter.
- It adds a private version which accepts `ChildUpdateRequestMode`
  indicating actions like whether to append challenge TLV, or
  whether to append zero timeout value (used for graceful detach).
This commit is contained in:
Abtin Keshavarzian
2023-04-12 13:49:21 -07:00
committed by GitHub
parent e7a92f6aaa
commit 0ca01ae501
2 changed files with 19 additions and 14 deletions
+10 -10
View File
@@ -2027,14 +2027,14 @@ exit:
return;
}
Error Mle::SendChildUpdateRequest(bool aAppendChallenge) { return SendChildUpdateRequest(aAppendChallenge, mTimeout); }
Error Mle::SendChildUpdateRequest(void) { return SendChildUpdateRequest(kNormalChildUpdateRequest); }
Error Mle::SendChildUpdateRequest(bool aAppendChallenge, uint32_t aTimeout)
Error Mle::SendChildUpdateRequest(ChildUpdateRequestMode aMode)
{
Error error = kErrorNone;
Ip6::Address destination;
TxMessage *message = nullptr;
AddressRegistrationMode mode = kAppendAllAddresses;
TxMessage *message = nullptr;
AddressRegistrationMode addrRegMode = kAppendAllAddresses;
if (!mParent.IsStateValidOrRestoring())
{
@@ -2049,7 +2049,7 @@ Error Mle::SendChildUpdateRequest(bool aAppendChallenge, uint32_t aTimeout)
VerifyOrExit((message = NewMleMessage(kCommandChildUpdateRequest)) != nullptr, error = kErrorNoBufs);
SuccessOrExit(error = message->AppendModeTlv(mDeviceMode));
if (aAppendChallenge || IsDetached())
if ((aMode == kAppendChallengeTlv) || IsDetached())
{
mParentRequestChallenge.GenerateRandom();
SuccessOrExit(error = message->AppendChallengeTlv(mParentRequestChallenge));
@@ -2058,13 +2058,13 @@ Error Mle::SendChildUpdateRequest(bool aAppendChallenge, uint32_t aTimeout)
switch (mRole)
{
case kRoleDetached:
mode = kAppendMeshLocalOnly;
addrRegMode = kAppendMeshLocalOnly;
break;
case kRoleChild:
SuccessOrExit(error = message->AppendSourceAddressTlv());
SuccessOrExit(error = message->AppendLeaderDataTlv());
SuccessOrExit(error = message->AppendTimeoutTlv(aTimeout));
SuccessOrExit(error = message->AppendTimeoutTlv((aMode == kAppendZeroTimeout) ? 0 : mTimeout));
SuccessOrExit(error = message->AppendSupervisionIntervalTlv(Get<SupervisionListener>().GetInterval()));
#if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE
if (Get<Mac::Mac>().IsCslEnabled())
@@ -2083,7 +2083,7 @@ Error Mle::SendChildUpdateRequest(bool aAppendChallenge, uint32_t aTimeout)
if (!IsFullThreadDevice())
{
SuccessOrExit(error = message->AppendAddressRegistrationTlv(mode));
SuccessOrExit(error = message->AppendAddressRegistrationTlv(addrRegMode));
}
destination.SetToLinkLocalAddress(mParent.GetExtAddress());
@@ -2707,7 +2707,7 @@ void Mle::ReestablishLinkWithNeighbor(Neighbor &aNeighbor)
if (IsChild() && (&aNeighbor == &mParent))
{
IgnoreError(SendChildUpdateRequest(/* aAppendChallenge */ true));
IgnoreError(SendChildUpdateRequest(kAppendChallengeTlv));
ExitNow();
}
@@ -4330,7 +4330,7 @@ Error Mle::DetachGracefully(otDetachGracefullyCallback aCallback, void *aContext
break;
case kRoleChild:
IgnoreError(SendChildUpdateRequest(/* aAppendChallenge */ false, /* aTimeout */ 0));
IgnoreError(SendChildUpdateRequest(kAppendZeroTimeout));
break;
case kRoleDisabled:
+9 -4
View File
@@ -1565,13 +1565,11 @@ protected:
/**
* This method generates an MLE Child Update Request message.
*
* @param[in] aAppendChallenge Indicates whether or not to include a Challenge TLV (even when already attached).
*
* @retval kErrorNone Successfully generated an MLE Child Update Request message.
* @retval kErrorNoBufs Insufficient buffers to generate the MLE Child Update Request message.
*
*/
Error SendChildUpdateRequest(bool aAppendChallenge = false);
Error SendChildUpdateRequest(void);
/**
* This method generates an MLE Child Update Response message.
@@ -1846,6 +1844,13 @@ private:
kChildUpdateRequestActive, // Child Update Request has been sent and Child Update Response is expected.
};
enum ChildUpdateRequestMode : uint8_t // Used in `SendChildUpdateRequest()`
{
kNormalChildUpdateRequest, // Normal Child Update Request.
kAppendChallengeTlv, // Append Challenge TLV to Child Update Request even if currently attached.
kAppendZeroTimeout, // Use zero timeout when appending Timeout TLV (used for graceful detach).
};
enum DataRequestState : uint8_t
{
kDataRequestNone, // Not waiting for a Data Response.
@@ -1978,7 +1983,7 @@ private:
static void HandleDetachGracefullyTimer(Timer &aTimer);
void HandleDetachGracefullyTimer(void);
bool IsDetachingGracefully(void) { return mDetachGracefullyTimer.IsRunning(); }
Error SendChildUpdateRequest(bool aAppendChallenge, uint32_t aTimeout);
Error SendChildUpdateRequest(ChildUpdateRequestMode aMode);
#if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE || OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE
Error SendDataRequest(const Ip6::Address &aDestination,