From aab0c297933a45ee4ac0f331c808aa9eb367b7ee Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Mon, 16 Jun 2025 21:46:29 -0700 Subject: [PATCH] [mle] move AnnounceHandler methods together (#11598) This commit moves the `Mle::AnnounceHandler` methods to be located together in the same section. The `AnnounceHandler` sub-component was added in a previous commit, but its methods were intentionally left in their original locations to keep the `git diff` small and easy to review. This change simply relocates the methods to their proper place and includes no logical modifications. --- src/core/thread/mle.cpp | 308 ++++++++++++++++++++-------------------- 1 file changed, 154 insertions(+), 154 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 00dbaa559..4147a8a23 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -813,37 +813,6 @@ void Mle::SetStateChild(uint16_t aRloc16) mPreviousParentRloc = mParent.GetRloc16(); } -void Mle::AnnounceHandler::HandleAnnounceAttachSuccess(void) -{ - // Clear state and send announce on previous channel. - - VerifyOrExit(mState == kStateAnnounceAttaching); - mState = kStateToInformPreviousChannel; - -#if OPENTHREAD_FTD - if (Get().IsFullThreadDevice() && !Get().IsRouter() && Get().IsRouterRoleTransitionPending()) - { - ExitNow(); - } -#endif - - InformPreviousChannel(); - -exit: - return; -} - -void Mle::AnnounceHandler::InformPreviousChannel(void) -{ - VerifyOrExit(mState == kStateToInformPreviousChannel); - - mState = kStateIdle; - Get().SendAnnounce(1 << mAlternateChannel); - -exit: - return; -} - void Mle::SetTimeout(uint32_t aTimeout, TimeoutAction aAction) { // Determine `kMinTimeout` based on other parameters. `kMaxTimeout` @@ -3688,103 +3657,6 @@ exit: LogProcessError(kTypeChildUpdateResponseAsChild, error); } -void Mle::AnnounceHandler::HandleAnnounce(RxInfo &aRxInfo) -{ - Error error = kErrorNone; - ChannelTlvValue channelTlvValue; - MeshCoP::Timestamp timestamp; - MeshCoP::Timestamp pendingActiveTimestamp; - uint8_t channel; - uint16_t panId; - bool isFromOrphan; - bool channelAndPanIdMatch; - int timestampCompare; - - Log(kMessageReceive, kTypeAnnounce, aRxInfo.mMessageInfo.GetPeerAddr()); - - SuccessOrExit(error = Tlv::Find(aRxInfo.mMessage, channelTlvValue)); - channel = static_cast(channelTlvValue.GetChannel()); - - SuccessOrExit(error = Tlv::Find(aRxInfo.mMessage, timestamp)); - SuccessOrExit(error = Tlv::Find(aRxInfo.mMessage, panId)); - - aRxInfo.mClass = RxInfo::kPeerMessage; - - isFromOrphan = timestamp.IsOrphanAnnounce(); - timestampCompare = MeshCoP::Timestamp::Compare(timestamp, Get().GetTimestamp()); - channelAndPanIdMatch = (channel == Get().GetPanChannel()) && (panId == Get().GetPanId()); - - if (isFromOrphan || (timestampCompare < 0)) - { - if (isFromOrphan) - { - VerifyOrExit(!channelAndPanIdMatch); - } - - Get().SendAnnounce(channel); - -#if OPENTHREAD_CONFIG_MLE_SEND_UNICAST_ANNOUNCE_RESPONSE - Get().SendAnnounce(channel, aRxInfo.mMessageInfo.GetPeerAddr()); -#endif - } - else if (timestampCompare > 0) - { - // No action is required if device is detached, and current - // channel and pan-id match the values from the received MLE - // Announce message. - - if (Get().IsDetached()) - { - VerifyOrExit(!channelAndPanIdMatch); - } - - if (Get().ReadActiveTimestamp(pendingActiveTimestamp) == kErrorNone) - { - // Ignore the Announce and take no action, if a pending - // dataset exists with an equal or more recent timestamp, - // and it will be applied soon. - - if (pendingActiveTimestamp >= timestamp) - { - uint32_t remainingDelay; - - if ((Get().ReadRemainingDelay(remainingDelay) == kErrorNone) && - (remainingDelay < kAnnounceBackoffForPendingDataset)) - { - ExitNow(); - } - } - } - - if (mState == kStateToAnnounceAttach) - { - VerifyOrExit(mAlternateTimestamp < timestamp.GetSeconds()); - } - - mAlternateTimestamp = timestamp.GetSeconds(); - mAlternateChannel = channel; - mAlternatePanId = panId; - mState = kStateToAnnounceAttach; - mTimer.Start(kAnnounceProcessTimeout); - - LogNote("Delay processing Announce - channel %d, panid 0x%02x", channel, panId); - } - else - { - // Timestamps are equal. - -#if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE - // Notify `AnnounceSender` of the received Announce - // message so it can update its state to determine - // whether to send Announce or not. - Get().UpdateOnReceivedAnnounce(); -#endif - } - -exit: - LogProcessError(kTypeAnnounce, error); -} - #if OPENTHREAD_CONFIG_MLE_LINK_METRICS_SUBJECT_ENABLE void Mle::HandleLinkMetricsManagementRequest(RxInfo &aRxInfo) { @@ -3863,32 +3735,6 @@ exit: } #endif -void Mle::AnnounceHandler::StartAnnounceAttach(void) -{ - uint8_t newChannel = mAlternateChannel; - uint16_t newPanId = mAlternatePanId; - - VerifyOrExit(mState == kStateToAnnounceAttach); - - LogNote("Starting Announce attach - channel %d, panid 0x%02x", newChannel, newPanId); - - Get().Stop(kKeepNetworkDatasets); - - // Save the current/previous channel and pan-id - mAlternateChannel = Get().GetPanChannel(); - mAlternatePanId = Get().GetPanId(); - mAlternateTimestamp = 0; - - IgnoreError(Get().SetPanChannel(newChannel)); - Get().SetPanId(newPanId); - - mState = kStateAnnounceAttaching; - IgnoreError(Get().Start(kAnnounceAttach)); - -exit: - return; -} - uint16_t Mle::GetParentRloc16(void) const { return (mParent.IsStateValid() ? mParent.GetRloc16() : kInvalidRloc16); } Error Mle::GetParentInfo(Router::Info &aParentInfo) const @@ -5621,6 +5467,160 @@ void Mle::AnnounceHandler::Stop(void) mState = kStateIdle; } +void Mle::AnnounceHandler::HandleAnnounce(RxInfo &aRxInfo) +{ + Error error = kErrorNone; + ChannelTlvValue channelTlvValue; + MeshCoP::Timestamp timestamp; + MeshCoP::Timestamp pendingActiveTimestamp; + uint8_t channel; + uint16_t panId; + bool isFromOrphan; + bool channelAndPanIdMatch; + int timestampCompare; + + Log(kMessageReceive, kTypeAnnounce, aRxInfo.mMessageInfo.GetPeerAddr()); + + SuccessOrExit(error = Tlv::Find(aRxInfo.mMessage, channelTlvValue)); + channel = static_cast(channelTlvValue.GetChannel()); + + SuccessOrExit(error = Tlv::Find(aRxInfo.mMessage, timestamp)); + SuccessOrExit(error = Tlv::Find(aRxInfo.mMessage, panId)); + + aRxInfo.mClass = RxInfo::kPeerMessage; + + isFromOrphan = timestamp.IsOrphanAnnounce(); + timestampCompare = MeshCoP::Timestamp::Compare(timestamp, Get().GetTimestamp()); + channelAndPanIdMatch = (channel == Get().GetPanChannel()) && (panId == Get().GetPanId()); + + if (isFromOrphan || (timestampCompare < 0)) + { + if (isFromOrphan) + { + VerifyOrExit(!channelAndPanIdMatch); + } + + Get().SendAnnounce(channel); + +#if OPENTHREAD_CONFIG_MLE_SEND_UNICAST_ANNOUNCE_RESPONSE + Get().SendAnnounce(channel, aRxInfo.mMessageInfo.GetPeerAddr()); +#endif + } + else if (timestampCompare > 0) + { + // No action is required if device is detached, and current + // channel and pan-id match the values from the received MLE + // Announce message. + + if (Get().IsDetached()) + { + VerifyOrExit(!channelAndPanIdMatch); + } + + if (Get().ReadActiveTimestamp(pendingActiveTimestamp) == kErrorNone) + { + // Ignore the Announce and take no action, if a pending + // dataset exists with an equal or more recent timestamp, + // and it will be applied soon. + + if (pendingActiveTimestamp >= timestamp) + { + uint32_t remainingDelay; + + if ((Get().ReadRemainingDelay(remainingDelay) == kErrorNone) && + (remainingDelay < kAnnounceBackoffForPendingDataset)) + { + ExitNow(); + } + } + } + + if (mState == kStateToAnnounceAttach) + { + VerifyOrExit(mAlternateTimestamp < timestamp.GetSeconds()); + } + + mAlternateTimestamp = timestamp.GetSeconds(); + mAlternateChannel = channel; + mAlternatePanId = panId; + mState = kStateToAnnounceAttach; + mTimer.Start(kAnnounceProcessTimeout); + + LogNote("Delay processing Announce - channel %d, panid 0x%02x", channel, panId); + } + else + { + // Timestamps are equal. + +#if OPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE + // Notify `AnnounceSender` of the received Announce + // message so it can update its state to determine + // whether to send Announce or not. + Get().UpdateOnReceivedAnnounce(); +#endif + } + +exit: + LogProcessError(kTypeAnnounce, error); +} + +void Mle::AnnounceHandler::StartAnnounceAttach(void) +{ + uint8_t newChannel = mAlternateChannel; + uint16_t newPanId = mAlternatePanId; + + VerifyOrExit(mState == kStateToAnnounceAttach); + + LogNote("Starting Announce attach - channel %d, panid 0x%02x", newChannel, newPanId); + + Get().Stop(kKeepNetworkDatasets); + + // Save the current/previous channel and pan-id + mAlternateChannel = Get().GetPanChannel(); + mAlternatePanId = Get().GetPanId(); + mAlternateTimestamp = 0; + + IgnoreError(Get().SetPanChannel(newChannel)); + Get().SetPanId(newPanId); + + mState = kStateAnnounceAttaching; + IgnoreError(Get().Start(kAnnounceAttach)); + +exit: + return; +} + +void Mle::AnnounceHandler::HandleAnnounceAttachSuccess(void) +{ + // Clear state and send announce on previous channel. + + VerifyOrExit(mState == kStateAnnounceAttaching); + mState = kStateToInformPreviousChannel; + +#if OPENTHREAD_FTD + if (Get().IsFullThreadDevice() && !Get().IsRouter() && Get().IsRouterRoleTransitionPending()) + { + ExitNow(); + } +#endif + + InformPreviousChannel(); + +exit: + return; +} + +void Mle::AnnounceHandler::InformPreviousChannel(void) +{ + VerifyOrExit(mState == kStateToInformPreviousChannel); + + mState = kStateIdle; + Get().SendAnnounce(1 << mAlternateChannel); + +exit: + return; +} + void Mle::AnnounceHandler::HandleAnnounceAttachFailure(void) { VerifyOrExit(mState == kStateAnnounceAttaching);