diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 355f45c01..57fa4e79d 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -3712,6 +3712,9 @@ void Mle::HandleAnnounce(RxInfo &aRxInfo) const MeshCoP::Timestamp *localTimestamp; uint8_t channel; uint16_t panId; + bool isFromOrphan; + bool channelAndPanIdMatch; + int timestampCompare; Log(kMessageReceive, kTypeAnnounce, aRxInfo.mMessageInfo.GetPeerAddr()); @@ -3727,22 +3730,33 @@ void Mle::HandleAnnounce(RxInfo &aRxInfo) localTimestamp = Get().GetTimestamp(); - if (timestamp.IsOrphanTimestamp() || MeshCoP::Timestamp::Compare(×tamp, localTimestamp) < 0) + isFromOrphan = timestamp.IsOrphanTimestamp(); + timestampCompare = MeshCoP::Timestamp::Compare(×tamp, localTimestamp); + channelAndPanIdMatch = (channel == Get().GetPanChannel()) && (panId == Get().GetPanId()); + + if (isFromOrphan || (timestampCompare < 0)) { + if (isFromOrphan) + { + VerifyOrExit(!channelAndPanIdMatch); + } + SendAnnounce(channel); #if OPENTHREAD_CONFIG_MLE_SEND_UNICAST_ANNOUNCE_RESPONSE SendAnnounce(channel, aRxInfo.mMessageInfo.GetPeerAddr()); #endif } - else if (MeshCoP::Timestamp::Compare(×tamp, localTimestamp) > 0) + 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. - VerifyOrExit(!IsDetached() || (Get().GetPanChannel() != channel) || - (Get().GetPanId() != panId)); + if (IsDetached()) + { + VerifyOrExit(!channelAndPanIdMatch); + } if (mAttachState == kAttachStateProcessAnnounce) {