[mle] add Mle::IsAttaching() method (#4419)

This commit is contained in:
Abtin Keshavarzian
2019-12-19 13:27:15 -08:00
committed by Jonathan Hui
parent 194ea70abb
commit bf4c7370bf
3 changed files with 18 additions and 5 deletions
+1 -1
View File
@@ -624,7 +624,7 @@ otError Mle::BecomeChild(AttachMode aMode)
otError error = OT_ERROR_NONE;
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mAttachState == kAttachStateIdle, error = OT_ERROR_BUSY);
VerifyOrExit(!IsAttaching(), error = OT_ERROR_BUSY);
if (mReattachState == kReattachStart)
{
+13
View File
@@ -602,6 +602,19 @@ public:
*/
bool IsAttached(void) const;
/**
* This method indicates whether device is currently attaching or not.
*
* Note that an already attached device may also be in attaching state. Examples of this include a leader/router
* trying to attach to a better partition, or a child trying to find a better parent (when feature
* `OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE` is enabled).
*
* @retval TRUE Device is currently trying to attach.
* @retval FALSE Device is not in middle of attach process.
*
*/
bool IsAttaching(void) const { return (mAttachState != kAttachStateIdle); }
/**
* This method returns the current Thread interface state.
*
+4 -4
View File
@@ -416,7 +416,7 @@ otError MleRouter::SendAdvertisement(void)
// Without this suppression, a device may send an MLE Advertisement before receiving the MLE Child ID Response.
// The candidate parent then removes the attaching device because the Source Address TLV includes an RLOC16 that
// indicates a Router role (i.e. a Child ID equal to zero).
VerifyOrExit(mAttachState == kAttachStateIdle);
VerifyOrExit(!IsAttaching());
// Suppress MLE Advertisements when transitioning to the router role.
//
@@ -573,7 +573,7 @@ otError MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::Message
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(mAttachState == kAttachStateIdle, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(!IsAttaching(), error = OT_ERROR_INVALID_STATE);
// Challenge
SuccessOrExit(error = Tlv::GetTlv(aMessage, Tlv::kChallenge, sizeof(challenge), challenge));
@@ -1603,7 +1603,7 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa
// A Router MUST NOT send an MLE Parent Response if:
// 0. It is detached or attempting to another partition
VerifyOrExit((mRole != OT_DEVICE_ROLE_DETACHED) && (mAttachState == kAttachStateIdle), error = OT_ERROR_DROP);
VerifyOrExit((mRole != OT_DEVICE_ROLE_DETACHED) && !IsAttaching(), error = OT_ERROR_DROP);
// 1. It has no available Child capacity (if Max Child Count minus
// Child Count would be equal to zero)
@@ -3287,7 +3287,7 @@ Neighbor *MleRouter::GetNeighbor(const Mac::ExtAddress &aAddress)
ExitNow();
}
if (mAttachState != kAttachStateIdle)
if (IsAttaching())
{
rval = Mle::GetNeighbor(aAddress);
}