From 4384a3100b56c2bfa3934e97329a620a28720d88 Mon Sep 17 00:00:00 2001 From: Jonathan Hui Date: Mon, 6 Jun 2022 10:51:47 -0700 Subject: [PATCH] [mle] fix handling of MLE Orphan Announce messages (#7786) MLE Orphan Announce messages include a timestamp value that has both seconds and ticks set to zero, but authoritative bit set. However, the default Active Timestamp value is all zeros. As a result, an MLE Orphan Announce timestamp can appear to be greater than the default Active Timestamp value and cause a device to detach. This commit adds a special case to check for the Orphan Announce timestamp. --- src/core/meshcop/timestamp.hpp | 9 +++++++++ src/core/thread/mle.cpp | 18 +++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/core/meshcop/timestamp.hpp b/src/core/meshcop/timestamp.hpp index b4a6bfd0a..1eace251d 100644 --- a/src/core/meshcop/timestamp.hpp +++ b/src/core/meshcop/timestamp.hpp @@ -140,6 +140,15 @@ public: */ void AdvanceRandomTicks(void); + /** + * This method indicates whether the timestamp indicates an MLE Orphan Announce message. + * + * @retval TRUE The timestamp indicates an Orphan Announce message. + * @retval FALSE If the timestamp does not indicate an Orphan Announce message. + * + */ + bool IsOrphanTimestamp(void) const { return GetSeconds() == 0 && GetTicks() == 0 && GetAuthoritative(); } + /** * This static method compares two timestamps. * diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 99b93ef05..bde0550ed 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -4113,7 +4113,15 @@ void Mle::HandleAnnounce(RxInfo &aRxInfo) localTimestamp = Get().GetTimestamp(); - if (MeshCoP::Timestamp::Compare(×tamp, localTimestamp) > 0) + if (timestamp.IsOrphanTimestamp() || MeshCoP::Timestamp::Compare(×tamp, localTimestamp) < 0) + { + SendAnnounce(channel); + +#if OPENTHREAD_CONFIG_MLE_SEND_UNICAST_ANNOUNCE_RESPONSE + SendAnnounce(channel, aRxInfo.mMessageInfo.GetPeerAddr()); +#endif + } + else if (MeshCoP::Timestamp::Compare(×tamp, localTimestamp) > 0) { // No action is required if device is detached, and current // channel and pan-id match the values from the received MLE @@ -4136,14 +4144,6 @@ void Mle::HandleAnnounce(RxInfo &aRxInfo) LogNote("Delay processing Announce - channel %d, panid 0x%02x", channel, panId); } - else if (MeshCoP::Timestamp::Compare(×tamp, localTimestamp) < 0) - { - SendAnnounce(channel); - -#if OPENTHREAD_CONFIG_MLE_SEND_UNICAST_ANNOUNCE_RESPONSE - SendAnnounce(channel, aRxInfo.mMessageInfo.GetPeerAddr()); -#endif - } else { // Timestamps are equal.