mirror of
https://github.com/espressif/openthread.git
synced 2026-08-13 14:17:47 +00:00
Cleanup MLE attach names. (#1816)
This commit is contained in:
@@ -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<GUID,uint8_t,uint8_t> 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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
+22
-22
@@ -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);
|
||||
|
||||
+15
-3
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user