diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 8c081fe99..3bc8ca28f 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (173) +#define OPENTHREAD_API_VERSION (174) /** * @addtogroup api-instance diff --git a/include/openthread/thread.h b/include/openthread/thread.h index cbac610ec..b23bd6669 100644 --- a/include/openthread/thread.h +++ b/include/openthread/thread.h @@ -168,10 +168,7 @@ typedef struct otMleCounters uint16_t mBetterPartitionAttachAttempts; ///< Number of attempts to attach to a better partition. /** - * Number of times device changed its parents. - * - * Support for this counter requires the feature option OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH to - * be enabled. + * Number of times device changed its parent. * * A parent change can happen if device detaches from its current parent and attaches to a different one, or even * while device is attached when the periodic parent search feature is enabled (please see option diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 8703a2c98..cf1967585 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -97,9 +97,7 @@ Mle::Mle(Instance &aInstance) #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE , mCslTimeout(OPENTHREAD_CONFIG_CSL_TIMEOUT) #endif -#if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH , mPreviousParentRloc(Mac::kShortAddrInvalid) -#endif #if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE , mParentSearchIsInBackoff(false) , mParentSearchBackoffWasCanceled(false) @@ -386,9 +384,7 @@ Error Mle::Restore(void) mParent.SetRloc16(Rloc16FromRouterId(RouterIdFromRloc16(networkInfo.GetRloc16()))); mParent.SetState(Neighbor::kStateRestored); -#if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH mPreviousParentRloc = mParent.GetRloc16(); -#endif } #if OPENTHREAD_FTD else @@ -693,10 +689,16 @@ void Mle::SetStateChild(uint16_t aRloc16) UpdateParentSearchState(); #endif + if ((mPreviousParentRloc != Mac::kShortAddrInvalid) && (mPreviousParentRloc != mParent.GetRloc16())) + { + mCounters.mParentChanges++; + #if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH - InformPreviousParent(); - mPreviousParentRloc = mParent.GetRloc16(); + InformPreviousParent(); #endif + } + + mPreviousParentRloc = mParent.GetRloc16(); #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE if (Get().IsCslCapable()) @@ -4155,10 +4157,6 @@ void Mle::InformPreviousParent(void) Message * message = nullptr; Ip6::MessageInfo messageInfo; - VerifyOrExit((mPreviousParentRloc != Mac::kShortAddrInvalid) && (mPreviousParentRloc != mParent.GetRloc16())); - - mCounters.mParentChanges++; - VerifyOrExit((message = Get().NewMessage(0)) != nullptr, error = kErrorNoBufs); SuccessOrExit(error = message->SetLength(0)); diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 71c27e2f3..3db3637d4 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1887,9 +1887,7 @@ private: uint32_t mCslTimeout; #endif -#if OPENTHREAD_CONFIG_MLE_INFORM_PREVIOUS_PARENT_ON_REATTACH uint16_t mPreviousParentRloc; -#endif #if OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE bool mParentSearchIsInBackoff : 1;