From 31f92b6a2ec9113815a52f8bdd57952459bc98d6 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Wed, 16 Oct 2024 11:29:42 -0700 Subject: [PATCH] [mle] fix updating of `mDataRequestState` for Network Data (#10841) This commit updates and fixes how the `mDataRequestState` variable, which controls retransmissions of MLE Data Request messages, is updated. An MLE Data Request message can be sent for different purposes: either to request updated Network Data or to retrieve a Link Metrics Report from a neighbor/parent. The `mDataRequestState` retransmission mechanism is used to handle retx of Data Requests for retrieving Network Data. This commit ensures that the code that updates these variables is moved to `SendDataRequestAfterDelay()` and not in the common version, which can be used for both Network Data and Link Metric Reports. This ensures these states are not incorrectly updated when a Link Metrics Report is retrieved. --- src/core/thread/mle.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 8d1b19b90..609cc4206 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1730,10 +1730,26 @@ Error Mle::SendDataRequestAfterDelay(const Ip6::Address &aDestination, uint16_t { static const uint8_t kTlvs[] = {Tlv::kNetworkData, Tlv::kRoute}; + Error error; + + mDelayedSender.RemoveDataRequestMessage(aDestination); + // Based on `mRequestRouteTlv` include both Network Data and Route // TLVs or only Network Data TLV. - return SendDataRequest(aDestination, kTlvs, mRequestRouteTlv ? 2 : 1, aDelay); + error = SendDataRequest(aDestination, kTlvs, mRequestRouteTlv ? 2 : 1, aDelay); + + if (IsChild() && !IsRxOnWhenIdle()) + { + mDataRequestState = kDataRequestActive; + + if (mChildUpdateRequestState == kChildUpdateRequestNone) + { + ScheduleMessageTransmissionTimer(); + } + } + + return error; } #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_INITIATOR_ENABLE @@ -1757,8 +1773,6 @@ Error Mle::SendDataRequest(const Ip6::Address &aDestination, const uint8_t *aTlv Error error = kErrorNone; TxMessage *message; - mDelayedSender.RemoveDataRequestMessage(aDestination); - VerifyOrExit((message = NewMleMessage(kCommandDataRequest)) != nullptr, error = kErrorNoBufs); SuccessOrExit(error = message->AppendTlvRequestTlv(aTlvs, aTlvsLength)); @@ -1789,17 +1803,6 @@ Error Mle::SendDataRequest(const Ip6::Address &aDestination, const uint8_t *aTlv exit: FreeMessageOnError(message, error); - - if (IsChild() && !IsRxOnWhenIdle()) - { - mDataRequestState = kDataRequestActive; - - if (mChildUpdateRequestState == kChildUpdateRequestNone) - { - ScheduleMessageTransmissionTimer(); - } - } - return error; }