From 9a175befedd6a14c8dfb8390a933c19c8056a599 Mon Sep 17 00:00:00 2001 From: rongli Date: Fri, 17 Mar 2017 00:04:51 +0800 Subject: [PATCH] Fix bugs in Announce (#1471) --- src/core/api/thread_api.cpp | 2 +- src/core/thread/mle.cpp | 16 ++++++---------- src/core/thread/mle.hpp | 6 ++++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 464fb4a78..34f227591 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -589,7 +589,7 @@ ThreadError otThreadSetEnabled(otInstance *aInstance, bool aEnabled) { VerifyOrExit(aInstance->mThreadNetif.GetMac().GetPanId() != Mac::kPanIdBroadcast, error = kThreadError_InvalidState); - error = aInstance->mThreadNetif.GetMle().Start(true); + error = aInstance->mThreadNetif.GetMle().Start(true, false); } else { diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index b83bca352..d3bf89060 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -202,7 +202,7 @@ exit: return error; } -ThreadError Mle::Start(bool aEnableReattach) +ThreadError Mle::Start(bool aEnableReattach, bool aAnnounceAttach) { ThreadError error = kThreadError_None; @@ -223,7 +223,7 @@ ThreadError Mle::Start(bool aEnableReattach) mReattachState = kReattachStart; } - if (GetRloc16() == Mac::kShortAddrInvalid) + if (aAnnounceAttach || (GetRloc16() == Mac::kShortAddrInvalid)) { BecomeChild(kMleAttachAnyPartition); } @@ -562,7 +562,9 @@ ThreadError Mle::SetStateChild(uint16_t aRloc16) mNetif.GetIp6().SetForwardingEnabled(false); mNetif.GetIp6().mMpl.SetTimerExpirations(kMplChildDataMessageTimerExpirations); - if (mPreviousPanId != Mac::kPanIdBroadcast && (mDeviceMode & ModeTlv::kModeFFD)) + // Once the Thread device receives the new Active Commissioning Dataset, the device MUST + // transmit its own Announce messages on the channel it was on prior to the attachment. + if (mPreviousPanId != Mac::kPanIdBroadcast) { mPreviousPanId = Mac::kPanIdBroadcast; mNetif.GetAnnounceBeginServer().SendAnnounce(1 << mPreviousChannel); @@ -2448,12 +2450,6 @@ ThreadError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInf mNetif.GetPendingDataset().Clear(false); } - if (mPreviousPanId != Mac::kPanIdBroadcast && ((mDeviceMode & ModeTlv::kModeFFD) == 0)) - { - mPreviousPanId = Mac::kPanIdBroadcast; - mNetif.GetAnnounceBeginServer().SendAnnounce(1 << mPreviousChannel); - } - mRetrieveNewNetworkData = false; exit: @@ -2993,7 +2989,7 @@ ThreadError Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo mPreviousPanId = mNetif.GetMac().GetPanId(); mNetif.GetMac().SetChannel(static_cast(channel.GetChannel())); mNetif.GetMac().SetPanId(panid.GetPanId()); - Start(false); + Start(false, true); } else { diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 3d61f9f3b..49fbe6cc2 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -488,13 +488,15 @@ public: /** * This method starts the MLE protocol operation. * - * @param[in] aEnableReattach True to enable reattach process using stored dataset, False not. + * @param[in] aEnableReattach True if reattach using stored dataset, or False if not. + * @param[in] aAnnounceAttach True if attach on the announced thread network with newer active timestamp, + * or False if not. * * @retval kThreadError_None Successfully started the protocol operation. * @retval kThreadError_Already The protocol operation was already started. * */ - ThreadError Start(bool aEnableReattach); + ThreadError Start(bool aEnableReattach, bool aAnnounceAttach); /** * This method stops the MLE protocol operation.