diff --git a/examples/drivers/windows/otApi/otApi.cpp b/examples/drivers/windows/otApi/otApi.cpp index 2f096c1cb..b19db0f6c 100644 --- a/examples/drivers/windows/otApi/otApi.cpp +++ b/examples/drivers/windows/otApi/otApi.cpp @@ -2795,17 +2795,11 @@ OTAPI otError OTCALL otThreadBecomeChild( - _In_ otInstance *aInstance, - otMleAttachFilter aFilter + _In_ otInstance *aInstance ) { if (aInstance == nullptr) return OT_ERROR_INVALID_ARGS; - - uint8_t Role = kDeviceRoleDetached; - uint8_t Filter = (uint8_t)aFilter; - - PackedBuffer3 Buffer(aInstance->InterfaceGuid, Role, Filter); - return DwordToThreadError(SendIOCTL(aInstance->ApiHandle, IOCTL_OTLWF_OT_DEVICE_ROLE, &Buffer, sizeof(Buffer), nullptr, 0)); + return DwordToThreadError(SetIOCTL(aInstance, IOCTL_OTLWF_OT_DEVICE_ROLE, (uint8_t)kDeviceRoleChild)); } OTAPI diff --git a/examples/drivers/windows/otLwf/iocontrol.c b/examples/drivers/windows/otLwf/iocontrol.c index 93ccc5844..3c6e121d3 100644 --- a/examples/drivers/windows/otLwf/iocontrol.c +++ b/examples/drivers/windows/otLwf/iocontrol.c @@ -3773,12 +3773,9 @@ otLwfIoCtl_otDeviceRole( } else if (role == kDeviceRoleChild) { - if (InBufferLength >= sizeof(uint8_t)) - { - status = ThreadErrorToNtstatus( - otThreadBecomeChild(pFilter->otCtx, *(uint8_t*)InBuffer) - ); - } + status = ThreadErrorToNtstatus( + otThreadBecomeChild(pFilter->otCtx) + ); } else if (role == kDeviceRoleDetached) { diff --git a/examples/drivers/windows/otNodeApi/otNodeApi.cpp b/examples/drivers/windows/otNodeApi/otNodeApi.cpp index 24f5c745c..56df95b48 100644 --- a/examples/drivers/windows/otNodeApi/otNodeApi.cpp +++ b/examples/drivers/windows/otNodeApi/otNodeApi.cpp @@ -1406,7 +1406,7 @@ OTNODEAPI int32_t OTCALL otNodeSetState(otNode* aNode, const char *aState) } else if (strcmp(aState, "child") == 0) { - error = otThreadBecomeChild(aNode->mInstance, kMleAttachAnyPartition); + error = otThreadBecomeChild(aNode->mInstance); } else if (strcmp(aState, "router") == 0) { diff --git a/include/openthread/thread.h b/include/openthread/thread.h index 58175fbb8..2757a87fe 100644 --- a/include/openthread/thread.h +++ b/include/openthread/thread.h @@ -359,12 +359,11 @@ OTAPI otError OTCALL otThreadBecomeDetached(otInstance *aInstance); * Attempt to reattach as a child. * * @param[in] aInstance A pointer to an OpenThread instance. - * @param[in] aFilter Identifies whether to join any, same, or better partition. * * @retval OT_ERROR_NONE Successfully begin attempt to become a child. * @retval OT_ERROR_INVALID_STATE Thread is disabled. */ -OTAPI otError OTCALL otThreadBecomeChild(otInstance *aInstance, otMleAttachFilter aFilter); +OTAPI otError OTCALL otThreadBecomeChild(otInstance *aInstance); /** * This function gets the next neighbor information. It is used to go through the entries of diff --git a/include/openthread/types.h b/include/openthread/types.h index a11a25b9b..939ea8043 100644 --- a/include/openthread/types.h +++ b/include/openthread/types.h @@ -755,17 +755,6 @@ typedef enum otRoutePreference OT_ROUTE_PREFERENCE_HIGH = 1, ///< High route preference. } otRoutePreference; -/** - * Represents any restrictions on the attach process. - */ -typedef enum otMleAttachFilter -{ - kMleAttachAnyPartition = 0, ///< Attach to any Thread partition. - kMleAttachSamePartition1 = 1, ///< Attach to the same Thread partition (attempt 1). - kMleAttachSamePartition2 = 2, ///< Attach to the same Thread partition (attempt 2). - kMleAttachBetterPartition = 3, ///< Attach to a better (i.e. higher weight/partition id) Thread partition. -} otMleAttachFilter; - /** * This structure represents a whitelist entry. * diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 4e9d48d9a..412cb9492 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2451,7 +2451,7 @@ void Interpreter::ProcessState(int argc, char *argv[]) } else if (strcmp(argv[0], "child") == 0) { - SuccessOrExit(error = otThreadBecomeChild(mInstance, kMleAttachSamePartition1)); + SuccessOrExit(error = otThreadBecomeChild(mInstance)); } #if OPENTHREAD_FTD diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index bd5878f51..3fc119995 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -240,9 +240,9 @@ otError otThreadBecomeDetached(otInstance *aInstance) return aInstance->mThreadNetif.GetMle().BecomeDetached(); } -otError otThreadBecomeChild(otInstance *aInstance, otMleAttachFilter aFilter) +otError otThreadBecomeChild(otInstance *aInstance) { - return aInstance->mThreadNetif.GetMle().BecomeChild(aFilter); + return aInstance->mThreadNetif.GetMle().BecomeChild(Mle::kAttachAny); } otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index edf638461..da6834035 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -81,7 +81,7 @@ Mle::Mle(ThreadNetif &aThreadNetif) : mLastPartitionRouterIdSequence(0), mLastPartitionId(0), mParentLeaderCost(0), - mParentRequestMode(kMleAttachAnyPartition), + mParentRequestMode(kAttachAny), mParentPriority(0), mParentLinkQuality3(0), mParentLinkQuality2(0), @@ -232,13 +232,13 @@ otError Mle::Start(bool aEnableReattach, bool aAnnounceAttach) if (aAnnounceAttach || (GetRloc16() == Mac::kShortAddrInvalid)) { - BecomeChild(kMleAttachAnyPartition); + BecomeChild(kAttachAny); } else if (IsActiveRouter(GetRloc16())) { if (mNetif.GetMle().BecomeRouter(ThreadStatusTlv::kTooFewRouters) != OT_ERROR_NONE) { - BecomeChild(kMleAttachAnyPartition); + BecomeChild(kAttachAny); } } else @@ -480,14 +480,14 @@ otError Mle::BecomeDetached(void) SetStateDetached(); SetRloc16(Mac::kShortAddrInvalid); - BecomeChild(kMleAttachAnyPartition); + BecomeChild(kAttachAny); exit: otLogFuncExitErr(error); return error; } -otError Mle::BecomeChild(otMleAttachFilter aFilter) +otError Mle::BecomeChild(AttachMode aMode) { otError error = OT_ERROR_NONE; @@ -510,9 +510,9 @@ otError Mle::BecomeChild(otMleAttachFilter aFilter) ResetParentCandidate(); mParentRequestState = kParentRequestStart; - mParentRequestMode = aFilter; + mParentRequestMode = aMode; - if (aFilter != kMleAttachBetterPartition) + if (aMode != kAttachBetter) { memset(&mParent, 0, sizeof(mParent)); @@ -522,7 +522,7 @@ otError Mle::BecomeChild(otMleAttachFilter aFilter) } } - if (aFilter == kMleAttachAnyPartition) + if (aMode == kAttachAny) { mParent.SetState(Neighbor::kStateInvalid); mLastPartitionId = mNetif.GetMle().GetPreviousPartitionId(); @@ -1292,7 +1292,7 @@ void Mle::HandleParentRequestTimer(void) case kParentSynchronize: mParentRequestState = kParentIdle; - BecomeChild(kMleAttachAnyPartition); + BecomeChild(kAttachAny); break; case kParentRequestStart: @@ -1355,7 +1355,7 @@ void Mle::HandleParentRequestTimer(void) { switch (mParentRequestMode) { - case kMleAttachAnyPartition: + case kAttachAny: if (mPreviousPanId != Mac::kPanIdBroadcast) { mNetif.GetMac().SetChannel(mPreviousChannel); @@ -1376,17 +1376,17 @@ void Mle::HandleParentRequestTimer(void) break; - case kMleAttachSamePartition1: + case kAttachSame1: mParentRequestState = kParentIdle; - BecomeChild(kMleAttachSamePartition2); + BecomeChild(kAttachSame2); break; - case kMleAttachSamePartition2: + case kAttachSame2: mParentRequestState = kParentIdle; - BecomeChild(kMleAttachAnyPartition); + BecomeChild(kAttachAny); break; - case kMleAttachBetterPartition: + case kAttachBetter: mParentRequestState = kParentIdle; if (mDeviceState == kDeviceStateChild) @@ -1406,7 +1406,7 @@ void Mle::HandleParentRequestTimer(void) mParentRequestState = kParentIdle; ResetParentCandidate(); - if ((mParentRequestMode == kMleAttachBetterPartition) || (mDeviceState == kDeviceStateRouter) || + if ((mParentRequestMode == kAttachBetter) || (mDeviceState == kDeviceStateRouter) || (mDeviceState == kDeviceStateLeader)) { if (mDeviceState == kDeviceStateChild) @@ -1494,8 +1494,8 @@ otError Mle::SendParentRequest(void) case kParentRequestRouter: scanMask = ScanMaskTlv::kRouterFlag; - if (mParentRequestMode == kMleAttachSamePartition1 || - mParentRequestMode == kMleAttachSamePartition2) + if (mParentRequestMode == kAttachSame1 || + mParentRequestMode == kAttachSame2) { scanMask |= ScanMaskTlv::kEndDeviceFlag; } @@ -2599,18 +2599,18 @@ otError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInf switch (mParentRequestMode) { - case kMleAttachAnyPartition: + case kAttachAny: VerifyOrExit(leaderData.GetPartitionId() != mLeaderData.GetPartitionId() || diff > 0); break; - case kMleAttachSamePartition1: - case kMleAttachSamePartition2: + case kAttachSame1: + case kAttachSame2: VerifyOrExit(leaderData.GetPartitionId() == mLeaderData.GetPartitionId()); VerifyOrExit(diff > 0 || (diff == 0 && mNetif.GetMle().GetLeaderAge() < mNetif.GetMle().GetNetworkIdTimeout())); break; - case kMleAttachBetterPartition: + case kAttachBetter: VerifyOrExit(leaderData.GetPartitionId() != mLeaderData.GetPartitionId()); VerifyOrExit(mNetif.GetMle().ComparePartitions(connectivity.GetActiveRouters() <= 1, leaderData, mNetif.GetMle().IsSingleton(), mLeaderData) > 0); diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 32b4ab6b8..12e4cdb4c 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -103,6 +103,18 @@ enum DeviceState kDeviceStateLeader = 4, ///< Thread interface participating as a Leader. }; +/** + * MLE Attach modes + * + */ +enum AttachMode +{ + kAttachAny = 0, ///< Attach to any Thread partition. + kAttachSame1 = 1, ///< Attach to the same Thread partition (attempt 1). + kAttachSame2 = 2, ///< Attach to the same Thread partition (attempt 2). + kAttachBetter = 3, ///< Attach to a better (i.e. higher weight/partition id) Thread partition. +}; + /** * This enumeration represents the allocation of the ALOC Space * @@ -590,14 +602,14 @@ public: /** * This method causes the Thread interface to attempt an MLE attach. * - * @param[in] aFilter Indicates what partitions to attach to. + * @param[in] aMode Indicates what partitions to attach to. * * @retval OT_ERROR_NONE Successfully began the attach process. * @retval OT_ERROR_INVALID_STATE MLE is Disabled. * @retval OT_ERROR_BUSY An attach process is in progress. * */ - otError BecomeChild(otMleAttachFilter aFilter); + otError BecomeChild(AttachMode aMode); /** * This method indicates whether or not the Thread device is attached to a Thread network. @@ -1400,7 +1412,7 @@ private: uint8_t mChallenge[ChallengeTlv::kMaxSize]; } mParentRequest; - otMleAttachFilter mParentRequestMode; + AttachMode mParentRequestMode; int8_t mParentPriority; uint8_t mParentLinkQuality3; uint8_t mParentLinkQuality2; diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 05c4c8fe6..3a9438c69 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -349,7 +349,7 @@ otError MleRouter::HandleDetachStart(void) return error; } -otError MleRouter::HandleChildStart(otMleAttachFilter aFilter) +otError MleRouter::HandleChildStart(AttachMode aMode) { otError error = OT_ERROR_NONE; mRouterIdSequenceLastUpdated = Timer::GetNow(); @@ -367,10 +367,10 @@ otError MleRouter::HandleChildStart(otMleAttachFilter aFilter) VerifyOrExit(IsRouterIdValid(mPreviousRouterId), error = OT_ERROR_INVALID_STATE); - switch (aFilter) + switch (aMode) { - case kMleAttachSamePartition1: - case kMleAttachSamePartition2: + case kAttachSame1: + case kAttachSame2: // downgrade if (GetActiveRouterCount() > mRouterDowngradeThreshold) @@ -393,8 +393,8 @@ otError MleRouter::HandleChildStart(otMleAttachFilter aFilter) break; - case kMleAttachAnyPartition: - case kMleAttachBetterPartition: + case kAttachAny: + case kAttachBetter: if (HasChildren() && mPreviousPartitionId != mLeaderData.GetPartitionId()) { @@ -1330,7 +1330,7 @@ otError MleRouter::HandleAdvertisement(const Message &aMessage, const Ip6::Messa if (ComparePartitions(routerCount <= 1, leaderData, IsSingleton(), mLeaderData) > 0) { otLogDebgMle(GetInstance(), "trying to migrate"); - BecomeChild(kMleAttachBetterPartition); + BecomeChild(kAttachBetter); } ExitNow(error = OT_ERROR_DROP); @@ -1791,13 +1791,13 @@ void MleRouter::HandleStateUpdateTimer(void) if (GetLeaderAge() >= mNetworkIdTimeout) { - BecomeChild(kMleAttachSamePartition1); + BecomeChild(kAttachSame1); } if (routerStateUpdate && GetActiveRouterCount() > mRouterDowngradeThreshold) { // downgrade to REED - BecomeChild(kMleAttachSamePartition1); + BecomeChild(kAttachSame1); } break; diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index 58520756b..9acb7b97a 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -680,7 +680,7 @@ private: otError AppendPendingDataset(Message &aMessage); otError GetChildInfo(Child &aChild, otChildInfo &aChildInfo); otError HandleDetachStart(void); - otError HandleChildStart(otMleAttachFilter aFilter); + otError HandleChildStart(AttachMode aMode); otError HandleLinkRequest(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo); otError HandleLinkAccept(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence); otError HandleLinkAccept(const Message &aMessage, const Ip6::MessageInfo &aMessageInfo, uint32_t aKeySequence, diff --git a/src/core/thread/mle_router_mtd.hpp b/src/core/thread/mle_router_mtd.hpp index 0b8aea18e..4cf21ef67 100644 --- a/src/core/thread/mle_router_mtd.hpp +++ b/src/core/thread/mle_router_mtd.hpp @@ -131,7 +131,7 @@ public: private: otError HandleDetachStart(void) { return OT_ERROR_NONE; } - otError HandleChildStart(otMleAttachFilter) { return OT_ERROR_NONE; } + otError HandleChildStart(AttachMode) { return OT_ERROR_NONE; } otError HandleLinkRequest(const Message &, const Ip6::MessageInfo &) { return OT_ERROR_DROP; } otError HandleLinkAccept(const Message &, const Ip6::MessageInfo &, uint32_t) { return OT_ERROR_DROP; } otError HandleLinkAccept(const Message &, const Ip6::MessageInfo &, uint32_t, bool) { return OT_ERROR_DROP; } diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 9e2ed4913..5f6af7387 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -4576,7 +4576,7 @@ otError NcpBase::SetPropertyHandler_NET_ROLE(uint8_t header, spinel_prop_key_t k #endif // OPENTHREAD_FTD case SPINEL_NET_ROLE_CHILD: - errorCode = otThreadBecomeChild(mInstance, kMleAttachAnyPartition); + errorCode = otThreadBecomeChild(mInstance); break; }