mirror of
https://github.com/espressif/openthread.git
synced 2026-08-19 08:59:52 +00:00
[mle] add DeviceRole type, and IsChild, IsRouter, etc method (#4794)
This commit defines a new enum type `Mle::DeviceRole` mirroring the
public `otDeviceRole` enumeration. The enumerator in the new type
follow `kRole{Value}` style and intended for use in the core modules.
It also adds helper method in `Mle`, `IsChild()`, `IsRouter()`,
`IsLeader()`, etc to check the current device role.
This commit is contained in:
@@ -74,7 +74,7 @@ otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel)
|
||||
}
|
||||
#endif
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
SuccessOrExit(error = instance.Get<Mac::Mac>().SetPanChannel(aChannel));
|
||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||
@@ -96,7 +96,7 @@ otError otLinkSetSupportedChannelMask(otInstance *aInstance, uint32_t aChannelMa
|
||||
otError error = OT_ERROR_NONE;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<Mac::Mac>().SetSupportedChannelMask(static_cast<Mac::ChannelMask>(aChannelMask));
|
||||
|
||||
@@ -117,7 +117,7 @@ otError otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExt
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
OT_ASSERT(aExtAddress != NULL);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<Mac::Mac>().SetExtAddress(*static_cast<const Mac::ExtAddress *>(aExtAddress));
|
||||
|
||||
@@ -146,7 +146,7 @@ otError otLinkSetPanId(otInstance *aInstance, otPanId aPanId)
|
||||
otError error = OT_ERROR_NONE;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<Mac::Mac>().SetPanId(aPanId);
|
||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||
|
||||
@@ -54,7 +54,7 @@ otError otNetworkTimeSetSyncPeriod(otInstance *aInstance, uint16_t aTimeSyncPeri
|
||||
otError error = OT_ERROR_NONE;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<TimeSync>().SetTimeSyncPeriod(aTimeSyncPeriod);
|
||||
|
||||
@@ -74,7 +74,7 @@ otError otNetworkTimeSetXtalThreshold(otInstance *aInstance, uint16_t aXtalThres
|
||||
otError error = OT_ERROR_NONE;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<TimeSync>().SetXtalThreshold(aXtalThreshold);
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *a
|
||||
const Mac::ExtendedPanId &extPanId = *static_cast<const Mac::ExtendedPanId *>(aExtendedPanId);
|
||||
Mle::MeshLocalPrefix prefix;
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<Mac::Mac>().SetExtendedPanId(extPanId);
|
||||
|
||||
@@ -125,7 +125,7 @@ otError otThreadSetMasterKey(otInstance *aInstance, const otMasterKey *aKey)
|
||||
|
||||
OT_ASSERT(aKey != NULL);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
error = instance.Get<KeyManager>().SetMasterKey(*static_cast<const MasterKey *>(aKey));
|
||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||
@@ -161,7 +161,7 @@ otError otThreadSetMeshLocalPrefix(otInstance *aInstance, const otMeshLocalPrefi
|
||||
otError error = OT_ERROR_NONE;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<Mle::MleRouter>().SetMeshLocalPrefix(*static_cast<const Mle::MeshLocalPrefix *>(aMeshLocalPrefix));
|
||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||
@@ -190,7 +190,7 @@ otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName)
|
||||
otError error = OT_ERROR_NONE;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
error = instance.Get<Mac::Mac>().SetNetworkName(aNetworkName);
|
||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||
@@ -310,7 +310,7 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo)
|
||||
|
||||
// Reference device needs get the original parent's info even after the node state changed.
|
||||
#if !OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_CHILD, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsChild(), error = OT_ERROR_INVALID_STATE);
|
||||
#endif
|
||||
|
||||
parent = &instance.Get<Mle::MleRouter>().GetParent();
|
||||
|
||||
@@ -201,16 +201,16 @@ otError otThreadBecomeRouter(otInstance *aInstance)
|
||||
|
||||
switch (instance.Get<Mle::MleRouter>().GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case Mle::kRoleDisabled:
|
||||
case Mle::kRoleDetached:
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case Mle::kRoleChild:
|
||||
error = instance.Get<Mle::MleRouter>().BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case Mle::kRoleRouter:
|
||||
case Mle::kRoleLeader:
|
||||
error = OT_ERROR_NONE;
|
||||
break;
|
||||
}
|
||||
@@ -346,7 +346,7 @@ otError otThreadSetPskc(otInstance *aInstance, const otPskc *aPskc)
|
||||
otError error = OT_ERROR_NONE;
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(instance.Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
instance.Get<KeyManager>().SetPskc(*static_cast<const Pskc *>(aPskc));
|
||||
instance.Get<MeshCoP::ActiveDataset>().Clear();
|
||||
|
||||
@@ -206,7 +206,7 @@ void Local::UpdateBackboneRouterPrimary(Leader::State aState, const BackboneRout
|
||||
{
|
||||
uint8_t delay = 1;
|
||||
|
||||
if (Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_LEADER)
|
||||
if (!Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
delay += Random::NonCrypto::GetUint8InRange(0, mRegistrationJitter < 255 ? mRegistrationJitter + 1
|
||||
: mRegistrationJitter);
|
||||
|
||||
@@ -221,7 +221,7 @@ otError Instance::ErasePersistentInfo(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
Get<Settings>().Wipe();
|
||||
|
||||
exit:
|
||||
|
||||
@@ -54,7 +54,7 @@ void SettingsBase::LogNetworkInfo(const char *aAction, const NetworkInfo &aNetwo
|
||||
otLogInfoCore(
|
||||
"Non-volatile: %s NetworkInfo {rloc:0x%04x, extaddr:%s, role:%s, mode:0x%02x, version:%hu, keyseq:0x%x, ...",
|
||||
aAction, aNetworkInfo.GetRloc16(), aNetworkInfo.GetExtAddress().ToString().AsCString(),
|
||||
Mle::Mle::RoleToString(static_cast<otDeviceRole>(aNetworkInfo.GetRole())), aNetworkInfo.GetDeviceMode(),
|
||||
Mle::Mle::RoleToString(static_cast<Mle::DeviceRole>(aNetworkInfo.GetRole())), aNetworkInfo.GetDeviceMode(),
|
||||
aNetworkInfo.GetVersion(), aNetworkInfo.GetKeySequence());
|
||||
|
||||
otLogInfoCore(
|
||||
|
||||
@@ -131,7 +131,7 @@ void DataPollHandler::HandleDataPoll(Mac::RxFrame &aFrame)
|
||||
uint16_t indirectMsgCount;
|
||||
|
||||
VerifyOrExit(aFrame.GetSecurityEnabled());
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_DETACHED);
|
||||
VerifyOrExit(!Get<Mle::MleRouter>().IsDetached());
|
||||
|
||||
SuccessOrExit(aFrame.GetSrcAddr(macSource));
|
||||
child = Get<ChildTable>().FindChild(macSource, Child::kInStateValidOrRestoring);
|
||||
|
||||
@@ -183,19 +183,19 @@ otError DatasetManager::Save(const otOperationalDataset &aDataset)
|
||||
|
||||
switch (Get<Mle::MleRouter>().GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case Mle::kRoleDisabled:
|
||||
Restore();
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case Mle::kRoleChild:
|
||||
mTimer.Start(1000);
|
||||
break;
|
||||
#if OPENTHREAD_FTD
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case Mle::kRoleRouter:
|
||||
mTimer.Start(1000);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case Mle::kRoleLeader:
|
||||
Restore();
|
||||
Get<NetworkData::Leader>().IncrementVersionAndStableVersion();
|
||||
break;
|
||||
|
||||
@@ -92,7 +92,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf
|
||||
channel.SetLength(0);
|
||||
pendingTimestamp.SetLength(0);
|
||||
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER);
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsLeader());
|
||||
|
||||
// verify that TLV data size is less than maximum TLV value size
|
||||
while (offset < aMessage.GetLength())
|
||||
@@ -269,7 +269,7 @@ otError DatasetManager::HandleSet(Coap::Message &aMessage, const Ip6::MessageInf
|
||||
|
||||
exit:
|
||||
|
||||
if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
SendSetResponse(aMessage, aMessageInfo, state);
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ void Leader::HandleTimer(Timer &aTimer)
|
||||
|
||||
void Leader::HandleTimer(void)
|
||||
{
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER);
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsLeader());
|
||||
|
||||
ResignCommissioner();
|
||||
|
||||
|
||||
@@ -132,12 +132,12 @@ void AnnounceSender::CheckState(void)
|
||||
|
||||
switch (mle.GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case Mle::kRoleRouter:
|
||||
case Mle::kRoleLeader:
|
||||
interval = kRouterTxInterval;
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case Mle::kRoleChild:
|
||||
#if OPENTHREAD_FTD
|
||||
if (mle.IsRouterEligible() && mle.IsRxOnWhenIdle())
|
||||
{
|
||||
@@ -148,8 +148,8 @@ void AnnounceSender::CheckState(void)
|
||||
|
||||
// fall through
|
||||
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case Mle::kRoleDisabled:
|
||||
case Mle::kRoleDetached:
|
||||
Stop();
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
|
||||
GetMacSourceAddress(ip6Header.GetSource(), mMacSource);
|
||||
|
||||
if (mle.GetRole() == OT_DEVICE_ROLE_DISABLED || mle.GetRole() == OT_DEVICE_ROLE_DETACHED)
|
||||
if (mle.IsDisabled() || mle.IsDetached())
|
||||
{
|
||||
if (ip6Header.GetDestination().IsLinkLocal() || ip6Header.GetDestination().IsLinkLocalMulticast())
|
||||
{
|
||||
@@ -312,7 +312,7 @@ otError MeshForwarder::UpdateIp6Route(Message &aMessage)
|
||||
// transmits multicasts, as IEEE 802.15.4 unicasts to its
|
||||
// parent.
|
||||
|
||||
if (mle.GetRole() == OT_DEVICE_ROLE_CHILD && !aMessage.IsSubTypeMle())
|
||||
if (mle.IsChild() && !aMessage.IsSubTypeMle())
|
||||
{
|
||||
mMacDest.SetShort(mle.GetNextHop(Mac::kShortAddrBroadcast));
|
||||
}
|
||||
@@ -646,7 +646,7 @@ start:
|
||||
uint16_t meshHeaderLength;
|
||||
uint8_t hopsLeft;
|
||||
|
||||
if (mle.GetRole() == OT_DEVICE_ROLE_CHILD)
|
||||
if (mle.IsChild())
|
||||
{
|
||||
// REED sets hopsLeft to max (16) + 1. It does not know the route cost.
|
||||
hopsLeft = Mle::kMaxRouteCost + 1;
|
||||
|
||||
+86
-82
@@ -67,7 +67,7 @@ namespace Mle {
|
||||
Mle::Mle(Instance &aInstance)
|
||||
: InstanceLocator(aInstance)
|
||||
, mRetrieveNewNetworkData(false)
|
||||
, mRole(OT_DEVICE_ROLE_DISABLED)
|
||||
, mRole(kRoleDisabled)
|
||||
, mDeviceMode(DeviceMode::kModeRxOnWhenIdle | DeviceMode::kModeSecureDataRequest)
|
||||
, mAttachState(kAttachStateIdle)
|
||||
, mReattachState(kReattachStop)
|
||||
@@ -326,7 +326,7 @@ void Mle::Stop(bool aClearNetworkDatasets)
|
||||
Get<MeshCoP::PendingDataset>().HandleDetach();
|
||||
}
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED);
|
||||
VerifyOrExit(!IsDisabled());
|
||||
|
||||
Get<KeyManager>().Stop();
|
||||
SetStateDetached();
|
||||
@@ -335,15 +335,15 @@ void Mle::Stop(bool aClearNetworkDatasets)
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mMeshLocal16);
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mMeshLocal64);
|
||||
|
||||
SetRole(OT_DEVICE_ROLE_DISABLED);
|
||||
SetRole(kRoleDisabled);
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
|
||||
void Mle::SetRole(otDeviceRole aRole)
|
||||
void Mle::SetRole(DeviceRole aRole)
|
||||
{
|
||||
otDeviceRole oldRole = mRole;
|
||||
DeviceRole oldRole = mRole;
|
||||
|
||||
SuccessOrExit(Get<Notifier>().Update(mRole, aRole, OT_CHANGED_THREAD_ROLE));
|
||||
|
||||
@@ -351,25 +351,25 @@ void Mle::SetRole(otDeviceRole aRole)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
mCounters.mDisabledRole++;
|
||||
break;
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
mCounters.mDetachedRole++;
|
||||
break;
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
mCounters.mChildRole++;
|
||||
break;
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case kRoleRouter:
|
||||
mCounters.mRouterRole++;
|
||||
break;
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleLeader:
|
||||
mCounters.mLeaderRole++;
|
||||
break;
|
||||
}
|
||||
|
||||
// If the previous state is disabled, the parent can be in kStateRestored.
|
||||
if (mRole != OT_DEVICE_ROLE_CHILD && oldRole != OT_DEVICE_ROLE_DISABLED)
|
||||
if (!IsChild() && oldRole != kRoleDisabled)
|
||||
{
|
||||
mParent.SetState(Neighbor::kStateInvalid);
|
||||
}
|
||||
@@ -420,9 +420,9 @@ otError Mle::Restore(void)
|
||||
|
||||
switch (networkInfo.GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleChild:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -502,7 +502,7 @@ otError Mle::Store(void)
|
||||
networkInfo.SetMeshLocalIid(&mMeshLocal64.GetAddress().mFields.m8[OT_IP6_PREFIX_SIZE]);
|
||||
networkInfo.SetVersion(kThreadVersion);
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD)
|
||||
if (IsChild())
|
||||
{
|
||||
Settings::ParentInfo parentInfo;
|
||||
|
||||
@@ -636,13 +636,13 @@ otError Mle::BecomeDetached(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
// In case role is already detached and attach state is `kAttachStateStart`
|
||||
// (i.e., waiting to start an attach attempt), there is no need to make any
|
||||
// changes.
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DETACHED || mAttachState != kAttachStateStart);
|
||||
VerifyOrExit(!IsDetached() || mAttachState != kAttachStateStart);
|
||||
|
||||
// not in reattach stage after reset
|
||||
if (mReattachState == kReattachStop)
|
||||
@@ -667,7 +667,7 @@ otError Mle::BecomeChild(AttachMode aMode)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!IsAttaching(), error = OT_ERROR_BUSY);
|
||||
|
||||
if (mReattachState == kReattachStart)
|
||||
@@ -702,7 +702,7 @@ otError Mle::BecomeChild(AttachMode aMode)
|
||||
|
||||
mAttachTimer.Start(GetAttachStartDelay());
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_DETACHED)
|
||||
if (IsDetached())
|
||||
{
|
||||
mAttachCounter++;
|
||||
|
||||
@@ -728,7 +728,7 @@ uint32_t Mle::GetAttachStartDelay(void) const
|
||||
uint32_t delay = 1;
|
||||
uint32_t jitter;
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_DETACHED);
|
||||
VerifyOrExit(IsDetached());
|
||||
|
||||
if (mAttachCounter == 0)
|
||||
{
|
||||
@@ -769,7 +769,12 @@ exit:
|
||||
|
||||
bool Mle::IsAttached(void) const
|
||||
{
|
||||
return (mRole == OT_DEVICE_ROLE_CHILD || mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER);
|
||||
return (IsChild() || IsRouter() || IsLeader());
|
||||
}
|
||||
|
||||
bool Mle::IsRouterOrLeader(void) const
|
||||
{
|
||||
return (IsRouter() || IsLeader());
|
||||
}
|
||||
|
||||
void Mle::SetStateDetached(void)
|
||||
@@ -781,12 +786,12 @@ void Mle::SetStateDetached(void)
|
||||
Get<BackboneRouter::Leader>().Reset();
|
||||
#endif
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_LEADER)
|
||||
if (IsLeader())
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mLeaderAloc);
|
||||
}
|
||||
|
||||
SetRole(OT_DEVICE_ROLE_DETACHED);
|
||||
SetRole(kRoleDetached);
|
||||
SetAttachState(kAttachStateIdle);
|
||||
mAttachTimer.Stop();
|
||||
mMessageTransmissionTimer.Stop();
|
||||
@@ -807,13 +812,13 @@ void Mle::SetStateDetached(void)
|
||||
|
||||
void Mle::SetStateChild(uint16_t aRloc16)
|
||||
{
|
||||
if (mRole == OT_DEVICE_ROLE_LEADER)
|
||||
if (IsLeader())
|
||||
{
|
||||
Get<ThreadNetif>().RemoveUnicastAddress(mLeaderAloc);
|
||||
}
|
||||
|
||||
SetRloc16(aRloc16);
|
||||
SetRole(OT_DEVICE_ROLE_CHILD);
|
||||
SetRole(kRoleChild);
|
||||
SetAttachState(kAttachStateIdle);
|
||||
mAttachTimer.Stop();
|
||||
mAttachCounter = 0;
|
||||
@@ -851,11 +856,10 @@ void Mle::SetStateChild(uint16_t aRloc16)
|
||||
void Mle::InformPreviousChannel(void)
|
||||
{
|
||||
VerifyOrExit(mAlternatePanId != Mac::kPanIdBroadcast);
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_CHILD || mRole == OT_DEVICE_ROLE_ROUTER);
|
||||
VerifyOrExit(IsChild() || IsRouter());
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
VerifyOrExit(!IsFullThreadDevice() || mRole == OT_DEVICE_ROLE_ROUTER ||
|
||||
Get<MleRouter>().GetRouterSelectionJitterTimeout() == 0);
|
||||
VerifyOrExit(!IsFullThreadDevice() || IsRouter() || Get<MleRouter>().GetRouterSelectionJitterTimeout() == 0);
|
||||
#endif
|
||||
|
||||
mAlternatePanId = Mac::kPanIdBroadcast;
|
||||
@@ -878,7 +882,7 @@ void Mle::SetTimeout(uint32_t aTimeout)
|
||||
|
||||
Get<DataPollSender>().RecalculatePollPeriod();
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD)
|
||||
if (IsChild())
|
||||
{
|
||||
SendChildUpdateRequest();
|
||||
}
|
||||
@@ -902,22 +906,22 @@ otError Mle::SetDeviceMode(DeviceMode aDeviceMode)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
mAttachCounter = 0;
|
||||
SetStateDetached();
|
||||
BecomeChild(kAttachAny);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
SetStateChild(GetRloc16());
|
||||
SendChildUpdateRequest();
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
if (oldMode.IsFullThreadDevice() && !mDeviceMode.IsFullThreadDevice())
|
||||
{
|
||||
BecomeDetached();
|
||||
@@ -989,7 +993,7 @@ void Mle::ApplyMeshLocalPrefix(void)
|
||||
mLinkLocalAllThreadNodes.GetAddress().SetMulticastNetworkPrefix(GetMeshLocalPrefix());
|
||||
mRealmLocalAllThreadNodes.GetAddress().SetMulticastNetworkPrefix(GetMeshLocalPrefix());
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED);
|
||||
VerifyOrExit(!IsDisabled());
|
||||
|
||||
// Add the addresses back into the table.
|
||||
Get<ThreadNetif>().AddUnicastAddress(mMeshLocal64);
|
||||
@@ -1002,7 +1006,7 @@ void Mle::ApplyMeshLocalPrefix(void)
|
||||
}
|
||||
|
||||
// update Leader ALOC
|
||||
if (mRole == OT_DEVICE_ROLE_LEADER)
|
||||
if (IsLeader())
|
||||
{
|
||||
Get<ThreadNetif>().AddUnicastAddress(mLeaderAloc);
|
||||
}
|
||||
@@ -1148,7 +1152,7 @@ otError Mle::AddLeaderAloc(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(IsLeader(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
SuccessOrExit(error = GetLeaderAloc(mLeaderAloc.GetAddress()));
|
||||
|
||||
@@ -1549,11 +1553,11 @@ void Mle::HandleStateChanged(Notifier::Callback &aCallback, otChangedFlags aFlag
|
||||
|
||||
void Mle::HandleStateChanged(otChangedFlags aFlags)
|
||||
{
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED);
|
||||
VerifyOrExit(!IsDisabled());
|
||||
|
||||
if (aFlags & OT_CHANGED_THREAD_ROLE)
|
||||
{
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD && !IsFullThreadDevice() && mAddressRegistrationMode == kAppendMeshLocalOnly)
|
||||
if (IsChild() && !IsFullThreadDevice() && mAddressRegistrationMode == kAppendMeshLocalOnly)
|
||||
{
|
||||
// If only mesh-local address was registered in the "Child
|
||||
// ID Request" message, after device is attached, trigger a
|
||||
@@ -1578,7 +1582,7 @@ void Mle::HandleStateChanged(otChangedFlags aFlags)
|
||||
Get<Notifier>().Signal(OT_CHANGED_THREAD_ML_ADDR);
|
||||
}
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD && !IsFullThreadDevice())
|
||||
if (IsChild() && !IsFullThreadDevice())
|
||||
{
|
||||
mChildUpdateRequestState = kChildUpdateRequestPending;
|
||||
ScheduleMessageTransmissionTimer();
|
||||
@@ -1587,7 +1591,7 @@ void Mle::HandleStateChanged(otChangedFlags aFlags)
|
||||
|
||||
if ((aFlags & (OT_CHANGED_IP6_MULTICAST_SUBSCRIBED | OT_CHANGED_IP6_MULTICAST_UNSUBSCRIBED)) != 0)
|
||||
{
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD && !IsFullThreadDevice() && !IsRxOnWhenIdle())
|
||||
if (IsChild() && !IsFullThreadDevice() && !IsRxOnWhenIdle())
|
||||
{
|
||||
mChildUpdateRequestState = kChildUpdateRequestPending;
|
||||
ScheduleMessageTransmissionTimer();
|
||||
@@ -1685,7 +1689,7 @@ void Mle::UpdateServiceAlocs(void)
|
||||
NetworkData::Iterator serviceIterator = NetworkData::kIteratorInit;
|
||||
int serviceAlocsLength = OT_ARRAY_LENGTH(mServiceAlocs);
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED);
|
||||
VerifyOrExit(!IsDisabled());
|
||||
|
||||
// First remove all alocs which are no longer necessary, to free up space in mServiceAlocs
|
||||
for (i = 0; i < serviceAlocsLength; i++)
|
||||
@@ -1770,7 +1774,7 @@ void Mle::HandleAttachTimer(void)
|
||||
|
||||
if ((linkQuality == 3 || mAttachState != kAttachStateParentRequestRouter) &&
|
||||
mParentCandidate.IsStateParentResponse() &&
|
||||
(mRole != OT_DEVICE_ROLE_CHILD || mReceivedResponseFromParent || mParentRequestMode == kAttachBetter) &&
|
||||
(!IsChild() || mReceivedResponseFromParent || mParentRequestMode == kAttachBetter) &&
|
||||
SendChildIdRequest() == OT_ERROR_NONE)
|
||||
{
|
||||
SetAttachState(kAttachStateChildIdRequest);
|
||||
@@ -1875,7 +1879,7 @@ bool Mle::PrepareAnnounceState(void)
|
||||
bool shouldAnnounce = false;
|
||||
Mac::ChannelMask channelMask;
|
||||
|
||||
VerifyOrExit((mRole != OT_DEVICE_ROLE_CHILD) && (mReattachState == kReattachStop) &&
|
||||
VerifyOrExit(!IsChild() && (mReattachState == kReattachStop) &&
|
||||
(Get<MeshCoP::ActiveDataset>().IsPartiallyComplete() || !IsFullThreadDevice()));
|
||||
|
||||
if (Get<MeshCoP::ActiveDataset>().GetChannelMask(channelMask) != OT_ERROR_NONE)
|
||||
@@ -1925,7 +1929,7 @@ uint32_t Mle::Reattach(void)
|
||||
switch (mParentRequestMode)
|
||||
{
|
||||
case kAttachAny:
|
||||
if (mRole != OT_DEVICE_ROLE_CHILD)
|
||||
if (!IsChild())
|
||||
{
|
||||
if (mAlternatePanId != Mac::kPanIdBroadcast)
|
||||
{
|
||||
@@ -2127,7 +2131,7 @@ otError Mle::SendChildIdRequest(void)
|
||||
|
||||
if (mParent.GetExtAddress() == mParentCandidate.GetExtAddress())
|
||||
{
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD)
|
||||
if (IsChild())
|
||||
{
|
||||
otLogInfoMle("Already attached to candidate parent");
|
||||
ExitNow(error = OT_ERROR_ALREADY);
|
||||
@@ -2234,7 +2238,7 @@ exit:
|
||||
message->Free();
|
||||
}
|
||||
|
||||
if ((mRole == OT_DEVICE_ROLE_CHILD) && !IsRxOnWhenIdle())
|
||||
if (IsChild() && !IsRxOnWhenIdle())
|
||||
{
|
||||
mDataRequestState = kDataRequestActive;
|
||||
|
||||
@@ -2272,7 +2276,7 @@ void Mle::ScheduleMessageTransmissionTimer(void)
|
||||
ExitNow(interval = kUnicastRetransmissionDelay);
|
||||
}
|
||||
|
||||
if ((mRole == OT_DEVICE_ROLE_CHILD) && IsRxOnWhenIdle())
|
||||
if (IsChild() && IsRxOnWhenIdle())
|
||||
{
|
||||
interval =
|
||||
Time::SecToMsec(mTimeout) - static_cast<uint32_t>(kUnicastRetransmissionDelay) * kMaxChildKeepAliveAttempts;
|
||||
@@ -2326,7 +2330,7 @@ void Mle::HandleMessageTransmissionTimer(void)
|
||||
}
|
||||
|
||||
// Keep-alive "Child Update Request" only on a non-sleepy child
|
||||
VerifyOrExit((mRole == OT_DEVICE_ROLE_CHILD) && IsRxOnWhenIdle());
|
||||
VerifyOrExit(IsChild() && IsRxOnWhenIdle());
|
||||
break;
|
||||
|
||||
case kChildUpdateRequestPending:
|
||||
@@ -2385,20 +2389,20 @@ otError Mle::SendChildUpdateRequest(void)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
mParentRequestChallenge.GenerateRandom();
|
||||
SuccessOrExit(error = AppendChallenge(*message, mParentRequestChallenge));
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
SuccessOrExit(error = AppendSourceAddress(*message));
|
||||
SuccessOrExit(error = AppendLeaderData(*message));
|
||||
SuccessOrExit(error = AppendTimeout(*message, mTimeout));
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleDisabled:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
OT_ASSERT(false);
|
||||
break;
|
||||
}
|
||||
@@ -2718,7 +2722,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(header.GetSecuritySuite() == Header::k154Security, error = OT_ERROR_PARSE);
|
||||
|
||||
keySequence = header.GetKeyId();
|
||||
@@ -2783,13 +2787,13 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleDetached:
|
||||
case kRoleChild:
|
||||
neighbor = GetNeighbor(macAddr);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
if (command == Header::kCommandChildIdResponse)
|
||||
{
|
||||
neighbor = GetNeighbor(macAddr);
|
||||
@@ -2846,7 +2850,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
|
||||
|
||||
case Header::kCommandChildUpdateRequest:
|
||||
#if OPENTHREAD_FTD
|
||||
if (mRole == OT_DEVICE_ROLE_LEADER || mRole == OT_DEVICE_ROLE_ROUTER)
|
||||
if (IsRouterOrLeader())
|
||||
{
|
||||
Get<MleRouter>().HandleChildUpdateRequest(aMessage, aMessageInfo, keySequence);
|
||||
}
|
||||
@@ -2860,7 +2864,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn
|
||||
|
||||
case Header::kCommandChildUpdateResponse:
|
||||
#if OPENTHREAD_FTD
|
||||
if (mRole == OT_DEVICE_ROLE_LEADER || mRole == OT_DEVICE_ROLE_ROUTER)
|
||||
if (IsRouterOrLeader())
|
||||
{
|
||||
Get<MleRouter>().HandleChildUpdateResponse(aMessage, aMessageInfo, keySequence, neighbor);
|
||||
}
|
||||
@@ -2934,7 +2938,7 @@ otError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo
|
||||
// Leader Data
|
||||
SuccessOrExit(error = ReadLeaderData(aMessage, leaderData));
|
||||
|
||||
if (mRole != OT_DEVICE_ROLE_DETACHED)
|
||||
if (!IsDetached())
|
||||
{
|
||||
#if OPENTHREAD_FTD
|
||||
if (IsFullThreadDevice())
|
||||
@@ -2954,11 +2958,11 @@ otError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
ExitNow();
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
VerifyOrExit(aNeighbor == &mParent);
|
||||
|
||||
if ((mParent.GetRloc16() == sourceAddress) && (leaderData.GetPartitionId() != mLeaderData.GetPartitionId() ||
|
||||
@@ -2985,8 +2989,8 @@ otError Mle::HandleAdvertisement(const Message &aMessage, const Ip6::MessageInfo
|
||||
mParent.SetLastHeard(TimerMilli::GetNow());
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
VerifyOrExit(aNeighbor && aNeighbor->IsStateValid());
|
||||
break;
|
||||
}
|
||||
@@ -3073,7 +3077,7 @@ otError Mle::HandleLeaderData(const Message &aMessage, const Ip6::MessageInfo &a
|
||||
if ((leaderData.GetPartitionId() != mLeaderData.GetPartitionId()) ||
|
||||
(leaderData.GetWeighting() != mLeaderData.GetWeighting()) || (leaderData.GetLeaderRouterId() != GetLeaderId()))
|
||||
{
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD)
|
||||
if (IsChild())
|
||||
{
|
||||
SetLeaderData(leaderData.GetPartitionId(), leaderData.GetWeighting(), leaderData.GetLeaderRouterId());
|
||||
mRetrieveNewNetworkData = true;
|
||||
@@ -3305,7 +3309,7 @@ otError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInf
|
||||
|
||||
aMessageInfo.GetPeerAddr().ToExtAddress(extAddress);
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD && mParent.GetExtAddress() == extAddress)
|
||||
if (IsChild() && mParent.GetExtAddress() == extAddress)
|
||||
{
|
||||
mReceivedResponseFromParent = true;
|
||||
}
|
||||
@@ -3347,7 +3351,7 @@ otError Mle::HandleParentResponse(const Message &aMessage, const Ip6::MessageInf
|
||||
}
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
if (IsFullThreadDevice() && (mRole != OT_DEVICE_ROLE_DETACHED))
|
||||
if (IsFullThreadDevice() && !IsDetached())
|
||||
{
|
||||
int8_t diff = static_cast<int8_t>(connectivity.GetIdSequence() - Get<RouterTable>().GetRouterIdSequence());
|
||||
|
||||
@@ -3716,12 +3720,12 @@ otError Mle::HandleChildUpdateResponse(const Message & aMessage,
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
SuccessOrExit(error = ReadResponse(aMessage, response));
|
||||
VerifyOrExit(response == mParentRequestChallenge, error = OT_ERROR_SECURITY);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
VerifyOrExit((aNeighbor == &mParent) && mParent.IsStateValid(), error = OT_ERROR_SECURITY);
|
||||
break;
|
||||
|
||||
@@ -3743,7 +3747,7 @@ otError Mle::HandleChildUpdateResponse(const Message & aMessage,
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
SuccessOrExit(error = Tlv::ReadUint32Tlv(aMessage, Tlv::kLinkFrameCounter, linkFrameCounter));
|
||||
|
||||
switch (Tlv::ReadUint32Tlv(aMessage, Tlv::kMleFrameCounter, mleFrameCounter))
|
||||
@@ -3767,7 +3771,7 @@ otError Mle::HandleChildUpdateResponse(const Message & aMessage,
|
||||
|
||||
// fall through
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
// Source Address
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kSourceAddress, sourceAddress));
|
||||
|
||||
@@ -3859,7 +3863,7 @@ otError Mle::HandleAnnounce(const Message &aMessage, const Ip6::MessageInfo &aMe
|
||||
// channel and pan-id match the values from the received MLE
|
||||
// Announce message.
|
||||
|
||||
VerifyOrExit((mRole != OT_DEVICE_ROLE_DETACHED) || (Get<Mac::Mac>().GetPanChannel() != channel) ||
|
||||
VerifyOrExit(!IsDetached() || (Get<Mac::Mac>().GetPanChannel() != channel) ||
|
||||
(Get<Mac::Mac>().GetPanId() != panId));
|
||||
|
||||
if (mAttachState == kAttachStateProcessAnnounce)
|
||||
@@ -4192,7 +4196,7 @@ void Mle::HandleParentSearchTimer(void)
|
||||
|
||||
mParentSearchIsInBackoff = false;
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_CHILD);
|
||||
VerifyOrExit(IsChild());
|
||||
|
||||
parentRss = GetParent().GetLinkInfo().GetAverageRss();
|
||||
otLogInfoMle("PeriodicParentSearch: Parent RSS %d", parentRss);
|
||||
@@ -4289,29 +4293,29 @@ void Mle::LogMleMessage(const char *aLogString, const Ip6::Address &aAddress, ui
|
||||
otLogInfoMle("%s (%s,0x%04x)", aLogString, aAddress.ToString().AsCString(), aRloc);
|
||||
}
|
||||
|
||||
const char *Mle::RoleToString(otDeviceRole aRole)
|
||||
const char *Mle::RoleToString(DeviceRole aRole)
|
||||
{
|
||||
const char *roleString = "Unknown";
|
||||
|
||||
switch (aRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
roleString = "Disabled";
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
roleString = "Detached";
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
roleString = "Child";
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case kRoleRouter:
|
||||
roleString = "Router";
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleLeader:
|
||||
roleString = "Leader";
|
||||
break;
|
||||
}
|
||||
|
||||
+60
-6
@@ -471,12 +471,66 @@ public:
|
||||
bool IsAttaching(void) const { return (mAttachState != kAttachStateIdle); }
|
||||
|
||||
/**
|
||||
* This method returns the current Thread interface state.
|
||||
* This method returns the current Thread device role.
|
||||
*
|
||||
* @returns The current Thread interface state.
|
||||
* @returns The current Thread device role.
|
||||
*
|
||||
*/
|
||||
otDeviceRole GetRole(void) const { return mRole; }
|
||||
DeviceRole GetRole(void) const { return mRole; }
|
||||
|
||||
/**
|
||||
* This method indicates whether device role is disabled.
|
||||
*
|
||||
* @retval TRUE Device role is disabled.
|
||||
* @retval FALSE Device role is not disabled.
|
||||
*
|
||||
*/
|
||||
bool IsDisabled(void) const { return (mRole == kRoleDisabled); }
|
||||
|
||||
/**
|
||||
* This method indicates whether device role is detached.
|
||||
*
|
||||
* @retval TRUE Device role is detached.
|
||||
* @retval FALSE Device role is not detached.
|
||||
*
|
||||
*/
|
||||
bool IsDetached(void) const { return (mRole == kRoleDetached); }
|
||||
|
||||
/**
|
||||
* This method indicates whether device role is child.
|
||||
*
|
||||
* @retval TRUE Device role is child.
|
||||
* @retval FALSE Device role is not child.
|
||||
*
|
||||
*/
|
||||
bool IsChild(void) const { return (mRole == kRoleChild); }
|
||||
|
||||
/**
|
||||
* This method indicates whether device role is router.
|
||||
*
|
||||
* @retval TRUE Device role is router.
|
||||
* @retval FALSE Device role is not router.
|
||||
*
|
||||
*/
|
||||
bool IsRouter(void) const { return (mRole == kRoleRouter); }
|
||||
|
||||
/**
|
||||
* This method indicates whether device role is leader.
|
||||
*
|
||||
* @retval TRUE Device role is leader.
|
||||
* @retval FALSE Device role is not leader.
|
||||
*
|
||||
*/
|
||||
bool IsLeader(void) const { return (mRole == kRoleLeader); }
|
||||
|
||||
/**
|
||||
* This method indicates whether device role is either router or leader.
|
||||
*
|
||||
* @retval TRUE Device role is either router or leader.
|
||||
* @retval FALSE Device role is neither router nor leader.
|
||||
*
|
||||
*/
|
||||
bool IsRouterOrLeader(void) const;
|
||||
|
||||
/**
|
||||
* This method returns the Device Mode as reported in the Mode TLV.
|
||||
@@ -884,7 +938,7 @@ public:
|
||||
* This method converts a device role into a human-readable string.
|
||||
*
|
||||
*/
|
||||
static const char *RoleToString(otDeviceRole aRole);
|
||||
static const char *RoleToString(DeviceRole aRole);
|
||||
|
||||
/**
|
||||
* This method gets the MLE counters.
|
||||
@@ -1031,7 +1085,7 @@ protected:
|
||||
* @param[in] aRole A device role.
|
||||
*
|
||||
*/
|
||||
void SetRole(otDeviceRole aRole);
|
||||
void SetRole(DeviceRole aRole);
|
||||
|
||||
/**
|
||||
* This method sets the attach state
|
||||
@@ -1595,7 +1649,7 @@ protected:
|
||||
|
||||
LeaderData mLeaderData; ///< Last received Leader Data TLV.
|
||||
bool mRetrieveNewNetworkData; ///< Indicating new Network Data is needed if set.
|
||||
otDeviceRole mRole; ///< Current Thread role.
|
||||
DeviceRole mRole; ///< Current Thread role.
|
||||
Router mParent; ///< Parent information.
|
||||
DeviceMode mDeviceMode; ///< Device mode setting.
|
||||
AttachState mAttachState; ///< The parent request state.
|
||||
|
||||
@@ -119,16 +119,16 @@ otError MleRouter::SetRouterEligible(bool aEligible)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
Get<Mac::Mac>().SetBeaconEnabled(mRouterEligible);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
if (!mRouterEligible)
|
||||
{
|
||||
BecomeDetached();
|
||||
@@ -145,8 +145,8 @@ otError MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_ROUTER, error = OT_ERROR_NONE);
|
||||
VerifyOrExit(!IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!IsRouter(), error = OT_ERROR_NONE);
|
||||
VerifyOrExit(IsRouterEligible(), error = OT_ERROR_NOT_CAPABLE);
|
||||
|
||||
otLogInfoMle("Attempt to become router");
|
||||
@@ -156,12 +156,12 @@ otError MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
SuccessOrExit(error = SendLinkRequest(NULL));
|
||||
mStateUpdateTimer.Start(kStateUpdatePeriod);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
SuccessOrExit(error = SendAddressSolicit(aStatus));
|
||||
break;
|
||||
|
||||
@@ -182,8 +182,8 @@ otError MleRouter::BecomeLeader(void)
|
||||
uint8_t leaderId;
|
||||
|
||||
VerifyOrExit(!Get<MeshCoP::ActiveDataset>().IsPartiallyComplete(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(mRole != OT_DEVICE_ROLE_LEADER, error = OT_ERROR_NONE);
|
||||
VerifyOrExit(!IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!IsLeader(), error = OT_ERROR_NONE);
|
||||
VerifyOrExit(IsRouterEligible(), error = OT_ERROR_NOT_CAPABLE);
|
||||
|
||||
mRouterTable.Clear();
|
||||
@@ -310,7 +310,7 @@ void MleRouter::SetStateRouter(uint16_t aRloc16)
|
||||
{
|
||||
SetRloc16(aRloc16);
|
||||
|
||||
SetRole(OT_DEVICE_ROLE_ROUTER);
|
||||
SetRole(kRoleRouter);
|
||||
SetAttachState(kAttachStateIdle);
|
||||
mAttachCounter = 0;
|
||||
mAttachTimer.Stop();
|
||||
@@ -339,7 +339,7 @@ void MleRouter::SetStateLeader(uint16_t aRloc16)
|
||||
{
|
||||
SetRloc16(aRloc16);
|
||||
|
||||
SetRole(OT_DEVICE_ROLE_LEADER);
|
||||
SetRole(kRoleLeader);
|
||||
SetAttachState(kAttachStateIdle);
|
||||
mAttachCounter = 0;
|
||||
mAttachTimer.Stop();
|
||||
@@ -398,7 +398,7 @@ void MleRouter::StopAdvertiseTimer(void)
|
||||
|
||||
void MleRouter::ResetAdvertiseInterval(void)
|
||||
{
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER);
|
||||
VerifyOrExit(IsRouterOrLeader());
|
||||
|
||||
if (!mAdvertiseTimer.IsRunning())
|
||||
{
|
||||
@@ -438,16 +438,16 @@ otError MleRouter::SendAdvertisement(void)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
OT_ASSERT(false);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
SuccessOrExit(error = AppendRoute(*message));
|
||||
break;
|
||||
}
|
||||
@@ -486,21 +486,21 @@ otError MleRouter::SendLinkRequest(Neighbor *aNeighbor)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
OT_ASSERT(false);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
SuccessOrExit(error = AppendTlvRequest(*message, detachedTlvs, sizeof(detachedTlvs)));
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
SuccessOrExit(error = AppendSourceAddress(*message));
|
||||
SuccessOrExit(error = AppendLeaderData(*message));
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
if (aNeighbor == NULL || !aNeighbor->IsStateValid())
|
||||
{
|
||||
SuccessOrExit(error = AppendTlvRequest(*message, routerTlvs, sizeof(routerTlvs)));
|
||||
@@ -577,7 +577,7 @@ otError MleRouter::HandleLinkRequest(const Message &aMessage, const Ip6::Message
|
||||
|
||||
LogMleMessage("Receive Link Request", aMessageInfo.GetPeerAddr());
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(IsRouterOrLeader(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
VerifyOrExit(!IsAttaching(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
@@ -895,7 +895,7 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
break;
|
||||
case OT_ERROR_NOT_FOUND:
|
||||
// Link Margin TLV may be skipped in Router Synchronization process after Reset
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_DETACHED, error = OT_ERROR_NOT_FOUND);
|
||||
VerifyOrExit(IsDetached(), error = OT_ERROR_NOT_FOUND);
|
||||
// Wait for an MLE Advertisement to establish a routing cost to the neighbor
|
||||
linkMargin = 0;
|
||||
break;
|
||||
@@ -905,11 +905,11 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
OT_ASSERT(false);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
// Address16
|
||||
SuccessOrExit(error = Tlv::ReadUint16Tlv(aMessage, Tlv::kAddress16, address16));
|
||||
VerifyOrExit(GetRloc16() == address16, error = OT_ERROR_DROP);
|
||||
@@ -943,12 +943,12 @@ otError MleRouter::HandleLinkAccept(const Message & aMessage,
|
||||
#endif
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
VerifyOrExit(router != NULL);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
VerifyOrExit(router != NULL);
|
||||
|
||||
// Leader Data
|
||||
@@ -1083,7 +1083,7 @@ otError MleRouter::ProcessRouteTlv(const RouteTlv &aRoute)
|
||||
|
||||
mRouterTable.UpdateRouterIdSet(aRoute.GetRouterIdSequence(), aRoute.GetRouterIdMask());
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_ROUTER && !mRouterTable.IsAllocated(mRouterId))
|
||||
if (IsRouter() && !mRouterTable.IsAllocated(mRouterId))
|
||||
{
|
||||
BecomeDetached();
|
||||
error = OT_ERROR_NO_ROUTE;
|
||||
@@ -1209,7 +1209,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
error = OT_ERROR_DROP);
|
||||
}
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD && (aNeighbor == &mParent || !IsFullThreadDevice()))
|
||||
if (IsChild() && (aNeighbor == &mParent || !IsFullThreadDevice()))
|
||||
{
|
||||
ExitNow();
|
||||
}
|
||||
@@ -1230,7 +1230,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
{
|
||||
VerifyOrExit(aNeighbor && aNeighbor->IsStateValid());
|
||||
|
||||
if (mRole != OT_DEVICE_ROLE_CHILD)
|
||||
if (!IsChild())
|
||||
{
|
||||
otLogInfoMle("Leader ID mismatch");
|
||||
BecomeDetached();
|
||||
@@ -1255,11 +1255,11 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
if (sourceAddress == mParent.GetRloc16())
|
||||
{
|
||||
processRouteTlv = true;
|
||||
@@ -1276,8 +1276,8 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
processRouteTlv = true;
|
||||
break;
|
||||
}
|
||||
@@ -1290,11 +1290,11 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
ExitNow();
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
if (aNeighbor == &mParent)
|
||||
{
|
||||
// MLE Advertisement from parent
|
||||
@@ -1374,7 +1374,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
|
||||
ExitNow();
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case kRoleRouter:
|
||||
router = mRouterTable.GetRouter(routerId);
|
||||
VerifyOrExit(router != NULL);
|
||||
|
||||
@@ -1398,7 +1398,7 @@ otError MleRouter::HandleAdvertisement(const Message & aMessage,
|
||||
|
||||
// fall through
|
||||
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleLeader:
|
||||
router = mRouterTable.GetRouter(routerId);
|
||||
VerifyOrExit(router != NULL);
|
||||
|
||||
@@ -1606,7 +1606,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) && !IsAttaching(), error = OT_ERROR_DROP);
|
||||
VerifyOrExit(!IsDetached() && !IsAttaching(), error = OT_ERROR_DROP);
|
||||
|
||||
// 1. It has no available Child capacity (if Max Child Count minus
|
||||
// Child Count would be equal to zero)
|
||||
@@ -1621,8 +1621,8 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa
|
||||
leader = mRouterTable.GetLeader();
|
||||
OT_ASSERT(leader != NULL);
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_LEADER || GetLinkCost(GetLeaderId()) < kMaxRouteCost ||
|
||||
(mRole == OT_DEVICE_ROLE_CHILD && leader->GetCost() + 1 < kMaxRouteCost) ||
|
||||
VerifyOrExit(IsLeader() || GetLinkCost(GetLeaderId()) < kMaxRouteCost ||
|
||||
(IsChild() && leader->GetCost() + 1 < kMaxRouteCost) ||
|
||||
(leader->GetCost() + GetLinkCost(leader->GetNextHop()) < kMaxRouteCost),
|
||||
error = OT_ERROR_DROP);
|
||||
|
||||
@@ -1637,16 +1637,16 @@ otError MleRouter::HandleParentRequest(const Message &aMessage, const Ip6::Messa
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
ExitNow();
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
VerifyOrExit(ScanMaskTlv::IsEndDeviceFlagSet(scanMask));
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
VerifyOrExit(ScanMaskTlv::IsRouterFlagSet(scanMask));
|
||||
break;
|
||||
}
|
||||
@@ -1752,11 +1752,11 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
OT_ASSERT(false);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDetached:
|
||||
if (mChallengeTimeout == 0)
|
||||
{
|
||||
BecomeDetached();
|
||||
@@ -1765,7 +1765,7 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
if (routerStateUpdate)
|
||||
{
|
||||
if (mRouterTable.GetActiveRouterCount() < mRouterUpgradeThreshold)
|
||||
@@ -1793,7 +1793,7 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
|
||||
// fall through
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case kRoleRouter:
|
||||
// verify path to leader
|
||||
otLogDebgMle("network id timeout = %d", mRouterTable.GetLeaderAge());
|
||||
|
||||
@@ -1812,7 +1812,7 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleLeader:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1846,7 +1846,7 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
otLogInfoMle("Child timeout expired");
|
||||
RemoveNeighbor(child);
|
||||
}
|
||||
else if ((mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER) && child.IsStateRestored())
|
||||
else if (IsRouterOrLeader() && child.IsStateRestored())
|
||||
{
|
||||
SendChildUpdateRequest(child);
|
||||
}
|
||||
@@ -1905,7 +1905,7 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (IsLeader())
|
||||
{
|
||||
if (mRouterTable.GetRouter(router.GetNextHop()) == NULL &&
|
||||
mRouterTable.GetLinkCost(router) >= kMaxRouteCost && age >= Time::SecToMsec(kMaxLeaderToRouterTimeout))
|
||||
@@ -1921,7 +1921,7 @@ void MleRouter::HandleStateUpdateTimer(void)
|
||||
SynchronizeChildNetworkData();
|
||||
|
||||
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE
|
||||
if (mRole == OT_DEVICE_ROLE_LEADER || mRole == OT_DEVICE_ROLE_ROUTER)
|
||||
if (IsRouterOrLeader())
|
||||
{
|
||||
Get<TimeSync>().ProcessTimeSync();
|
||||
}
|
||||
@@ -2288,18 +2288,18 @@ otError MleRouter::HandleChildIdRequest(const Message & aMessage,
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
OT_ASSERT(false);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
child->SetState(Neighbor::kStateChildIdRequest);
|
||||
BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
SuccessOrExit(error = SendChildIdResponse(*child));
|
||||
break;
|
||||
}
|
||||
@@ -2702,14 +2702,13 @@ void MleRouter::HandleNetworkDataUpdateRouter(void)
|
||||
Ip6::Address destination;
|
||||
uint16_t delay;
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER);
|
||||
VerifyOrExit(IsRouterOrLeader());
|
||||
|
||||
destination.Clear();
|
||||
destination.mFields.m16[0] = HostSwap16(0xff02);
|
||||
destination.mFields.m16[7] = HostSwap16(0x0001);
|
||||
|
||||
delay =
|
||||
(mRole == OT_DEVICE_ROLE_LEADER) ? 0 : Random::NonCrypto::GetUint16InRange(0, kUnsolicitedDataResponseJitter);
|
||||
delay = IsLeader() ? 0 : Random::NonCrypto::GetUint16InRange(0, kUnsolicitedDataResponseJitter);
|
||||
SendDataResponse(destination, tlvs, sizeof(tlvs), delay);
|
||||
|
||||
SynchronizeChildNetworkData();
|
||||
@@ -2720,7 +2719,7 @@ exit:
|
||||
|
||||
void MleRouter::SynchronizeChildNetworkData(void)
|
||||
{
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER);
|
||||
VerifyOrExit(IsRouterOrLeader());
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
@@ -3295,7 +3294,7 @@ void MleRouter::RemoveRouterLink(Router &aRouter)
|
||||
{
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
if (&aRouter == &mParent)
|
||||
{
|
||||
BecomeDetached();
|
||||
@@ -3303,8 +3302,8 @@ void MleRouter::RemoveRouterLink(Router &aRouter)
|
||||
break;
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
mRouterTable.RemoveRouterLink(aRouter);
|
||||
break;
|
||||
#endif
|
||||
@@ -3318,7 +3317,7 @@ void MleRouter::RemoveNeighbor(Neighbor &aNeighbor)
|
||||
{
|
||||
if (&aNeighbor == &mParent)
|
||||
{
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD)
|
||||
if (IsChild())
|
||||
{
|
||||
BecomeDetached();
|
||||
}
|
||||
@@ -3361,16 +3360,16 @@ Neighbor *MleRouter::GetNeighbor(uint16_t aAddress)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleDetached:
|
||||
case kRoleChild:
|
||||
rval = Mle::GetNeighbor(aAddress);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
rval = mChildTable.FindChild(aAddress, Child::kInStateValidOrRestoring);
|
||||
VerifyOrExit(rval == NULL);
|
||||
|
||||
@@ -3388,16 +3387,16 @@ Neighbor *MleRouter::GetNeighbor(const Mac::ExtAddress &aAddress)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case kRoleDisabled:
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleDetached:
|
||||
case kRoleChild:
|
||||
rval = Mle::GetNeighbor(aAddress);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleRouter:
|
||||
case kRoleLeader:
|
||||
rval = mChildTable.FindChild(aAddress, Child::kInStateValidOrRestoring);
|
||||
VerifyOrExit(rval == NULL);
|
||||
|
||||
@@ -3493,7 +3492,7 @@ Neighbor *MleRouter::GetRxOnlyNeighborRouter(const Mac::Address &aAddress)
|
||||
{
|
||||
Neighbor *rval = NULL;
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_CHILD, rval = NULL);
|
||||
VerifyOrExit(IsChild(), rval = NULL);
|
||||
|
||||
switch (aAddress.GetType())
|
||||
{
|
||||
@@ -3522,7 +3521,7 @@ uint16_t MleRouter::GetNextHop(uint16_t aDestination)
|
||||
const Router *router;
|
||||
const Router *nextHop;
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD)
|
||||
if (IsChild())
|
||||
{
|
||||
ExitNow(rval = Mle::GetNextHop(aDestination));
|
||||
}
|
||||
@@ -3593,8 +3592,7 @@ otError MleRouter::SetPreferredRouterId(uint8_t aRouterId)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
VerifyOrExit((mRole == OT_DEVICE_ROLE_DETACHED) || (mRole == OT_DEVICE_ROLE_DISABLED),
|
||||
error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(IsDetached() || IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mPreviousRouterId = aRouterId;
|
||||
|
||||
@@ -3893,7 +3891,7 @@ otError MleRouter::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, I
|
||||
Ip6::MessageInfo messageInfo;
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (mRole == OT_DEVICE_ROLE_CHILD)
|
||||
if (IsChild())
|
||||
{
|
||||
error = Mle::CheckReachability(aMeshSource, aMeshDest, aIp6Header);
|
||||
ExitNow();
|
||||
@@ -4326,12 +4324,12 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv)
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case kRoleDisabled:
|
||||
case kRoleDetached:
|
||||
cost = static_cast<uint8_t>(kMaxRouteCost);
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case kRoleChild:
|
||||
switch (mParent.GetLinkInfo().GetLinkQuality())
|
||||
{
|
||||
case 1:
|
||||
@@ -4350,7 +4348,7 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv)
|
||||
cost += LinkQualityToCost(mParent.GetLinkInfo().GetLinkQuality());
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case kRoleRouter:
|
||||
if (leader != NULL)
|
||||
{
|
||||
cost += GetLinkCost(leader->GetNextHop());
|
||||
@@ -4363,7 +4361,7 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv)
|
||||
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case kRoleLeader:
|
||||
cost = 0;
|
||||
break;
|
||||
}
|
||||
@@ -4702,7 +4700,7 @@ otError MleRouter::GetMaxChildTimeout(uint32_t &aTimeout) const
|
||||
{
|
||||
otError error = OT_ERROR_NOT_FOUND;
|
||||
|
||||
VerifyOrExit(mRole == OT_DEVICE_ROLE_ROUTER || mRole == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(IsRouterOrLeader(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
for (ChildTable::Iterator iter(GetInstance(), Child::kInStateValid); !iter.IsDone(); iter++)
|
||||
{
|
||||
|
||||
@@ -190,6 +190,19 @@ enum
|
||||
kMplRouterDataMessageTimerExpirations = 2, ///< Number of MPL retransmissions for Routers.
|
||||
};
|
||||
|
||||
/**
|
||||
* This type represents a Thread device role.
|
||||
*
|
||||
*/
|
||||
enum DeviceRole
|
||||
{
|
||||
kRoleDisabled = OT_DEVICE_ROLE_DISABLED, ///< The Thread stack is disabled.
|
||||
kRoleDetached = OT_DEVICE_ROLE_DETACHED, ///< Not currently participating in a Thread network/partition.
|
||||
kRoleChild = OT_DEVICE_ROLE_CHILD, ///< The Thread Child role.
|
||||
kRoleRouter = OT_DEVICE_ROLE_ROUTER, ///< The Thread Router role.
|
||||
kRoleLeader = OT_DEVICE_ROLE_LEADER, ///< The Thread Leader role.
|
||||
};
|
||||
|
||||
/**
|
||||
* MLE Attach modes
|
||||
*
|
||||
|
||||
@@ -436,7 +436,7 @@ otError LeaderBase::SetNetworkData(uint8_t aVersion,
|
||||
|
||||
#if OPENTHREAD_FTD
|
||||
// Synchronize internal 6LoWPAN Context ID Set with recently obtained Network Data.
|
||||
if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
Get<Leader>().UpdateContextsAfterReset();
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ void Leader::Stop(void)
|
||||
|
||||
void Leader::IncrementVersion(void)
|
||||
{
|
||||
if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
IncrementVersions(/* aIncludeStable */ false);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ void Leader::IncrementVersion(void)
|
||||
|
||||
void Leader::IncrementVersionAndStableVersion(void)
|
||||
{
|
||||
if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
IncrementVersions(/* aIncludeStable */ true);
|
||||
}
|
||||
@@ -190,7 +190,7 @@ void Leader::HandleCommissioningSet(Coap::Message &aMessage, const Ip6::MessageI
|
||||
MeshCoP::Tlv *end;
|
||||
|
||||
VerifyOrExit(length <= sizeof(tlvs));
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER);
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsLeader());
|
||||
|
||||
aMessage.Read(offset, length, tlvs);
|
||||
|
||||
@@ -267,7 +267,7 @@ void Leader::HandleCommissioningSet(Coap::Message &aMessage, const Ip6::MessageI
|
||||
|
||||
exit:
|
||||
|
||||
if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
SendCommissioningSetResponse(aMessage, aMessageInfo, state);
|
||||
}
|
||||
@@ -1390,12 +1390,11 @@ void Leader::HandleTimer(void)
|
||||
|
||||
otError Leader::RemoveStaleChildEntries(Coap::ResponseHandler aHandler, void *aContext)
|
||||
{
|
||||
otError error = OT_ERROR_NOT_FOUND;
|
||||
Iterator iterator = kIteratorInit;
|
||||
otDeviceRole role = Get<Mle::MleRouter>().GetRole();
|
||||
uint16_t rloc16;
|
||||
otError error = OT_ERROR_NOT_FOUND;
|
||||
Iterator iterator = kIteratorInit;
|
||||
uint16_t rloc16;
|
||||
|
||||
VerifyOrExit((role == OT_DEVICE_ROLE_ROUTER) || (role == OT_DEVICE_ROLE_LEADER));
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsRouterOrLeader());
|
||||
|
||||
while (GetNextServer(iterator, rloc16) == OT_ERROR_NONE)
|
||||
{
|
||||
|
||||
@@ -320,7 +320,7 @@ otError Local::UpdateInconsistentServerData(Coap::ResponseHandler aHandler, void
|
||||
#if OPENTHREAD_FTD
|
||||
|
||||
// Don't send this Server Data Notification if the device is going to upgrade to Router
|
||||
if (Get<Mle::MleRouter>().IsRouterEligible() && (Get<Mle::MleRouter>().GetRole() < OT_DEVICE_ROLE_ROUTER) &&
|
||||
if (Get<Mle::MleRouter>().IsRouterEligible() && !Get<Mle::MleRouter>().IsRouterOrLeader() &&
|
||||
(Get<RouterTable>().GetActiveRouterCount() < Get<Mle::MleRouter>().GetRouterUpgradeThreshold()))
|
||||
{
|
||||
ExitNow(error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
@@ -438,8 +438,7 @@ otError NetworkDiagnostic::FillRequestedTlvs(Message & aRequest,
|
||||
// Thread 1.1.1 Specification Section 10.11.2.2:
|
||||
// If a Thread device is unable to supply a specific Diagnostic TLV, that TLV is omitted.
|
||||
// Here only Leader or Router may have children.
|
||||
if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER ||
|
||||
Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_ROUTER)
|
||||
if (Get<Mle::MleRouter>().IsRouterOrLeader())
|
||||
{
|
||||
SuccessOrExit(error = AppendChildTable(aResponse));
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ otError RouterTable::Release(uint8_t aRouterId)
|
||||
|
||||
OT_ASSERT(aRouterId <= Mle::kMaxRouterId);
|
||||
|
||||
VerifyOrExit(Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsLeader(), error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(IsAllocated(aRouterId), error = OT_ERROR_NOT_FOUND);
|
||||
|
||||
mAllocatedRouterIds.Remove(aRouterId);
|
||||
@@ -536,7 +536,7 @@ void RouterTable::ProcessTimerTick(void)
|
||||
{
|
||||
Mle::MleRouter &mle = Get<Mle::MleRouter>();
|
||||
|
||||
if (mle.GetRole() == OT_DEVICE_ROLE_LEADER)
|
||||
if (mle.IsLeader())
|
||||
{
|
||||
// update router id sequence
|
||||
if (GetLeaderAge() >= Mle::kRouterIdSequencePeriod)
|
||||
|
||||
@@ -94,7 +94,7 @@ void TimeSync::HandleTimeSyncMessage(const Message &aMessage)
|
||||
otLogInfoCore("Older time sync seq received:%u. Forwarding current seq:%u", aMessage.GetTimeSyncSeq(),
|
||||
mTimeSyncSeq);
|
||||
}
|
||||
else if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER && timeSyncSeqDelta > 0)
|
||||
else if (Get<Mle::MleRouter>().IsLeader() && timeSyncSeqDelta > 0)
|
||||
{
|
||||
// Another device is forwarding a later time sync sequence, perhaps because it merged from a different
|
||||
// partition. The leader is authoritative, so ensure all devices synchronize to the time being seeded by this
|
||||
@@ -105,14 +105,13 @@ void TimeSync::HandleTimeSyncMessage(const Message &aMessage)
|
||||
otLogInfoCore("Newer time sync seq:%u received by leader. Setting current seq to:%u and forwarding",
|
||||
aMessage.GetTimeSyncSeq(), mTimeSyncSeq);
|
||||
}
|
||||
else if (Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_LEADER)
|
||||
else if (!Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
// For all devices aside from the leader, update network time in following three cases:
|
||||
// 1. During first attach.
|
||||
// 2. Already attached, and a newer time sync sequence was received.
|
||||
// 3. During reattach or migration process.
|
||||
if (mTimeSyncSeq == OT_TIME_SYNC_INVALID_SEQ || timeSyncSeqDelta > 0 ||
|
||||
Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_DETACHED)
|
||||
if (mTimeSyncSeq == OT_TIME_SYNC_INVALID_SEQ || timeSyncSeqDelta > 0 || Get<Mle::MleRouter>().IsDetached())
|
||||
{
|
||||
// Update network time and forward it.
|
||||
mLastTimeSyncReceived = TimerMilli::GetNow();
|
||||
@@ -152,7 +151,7 @@ void TimeSync::NotifyTimeSyncCallback(void)
|
||||
#if OPENTHREAD_FTD
|
||||
void TimeSync::ProcessTimeSync(void)
|
||||
{
|
||||
if (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_LEADER &&
|
||||
if (Get<Mle::MleRouter>().IsLeader() &&
|
||||
(TimerMilli::GetNow() - mLastTimeSyncSent > Time::SecToMsec(mTimeSyncPeriod)))
|
||||
{
|
||||
IncrementTimeSyncSeq();
|
||||
@@ -183,7 +182,7 @@ void TimeSync::HandleStateChanged(otChangedFlags aFlags)
|
||||
stateChanged = true;
|
||||
}
|
||||
|
||||
if ((aFlags & OT_CHANGED_THREAD_PARTITION_ID) != 0 && Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_LEADER)
|
||||
if ((aFlags & OT_CHANGED_THREAD_PARTITION_ID) != 0 && !Get<Mle::MleRouter>().IsLeader())
|
||||
{
|
||||
// Partition has changed. Accept any network time currently being seeded on the new partition
|
||||
// and don't attempt to forward the currently held network time from the previous partition.
|
||||
@@ -230,14 +229,14 @@ void TimeSync::CheckAndHandleChanges(bool aTimeUpdated)
|
||||
|
||||
switch (Get<Mle::MleRouter>().GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case OT_DEVICE_ROLE_DETACHED:
|
||||
case Mle::kRoleDisabled:
|
||||
case Mle::kRoleDetached:
|
||||
networkTimeStatus = OT_NETWORK_TIME_UNSYNCHRONIZED;
|
||||
otLogInfoCore("Time sync status UNSYNCHRONIZED as role:DISABLED/DETACHED");
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_CHILD:
|
||||
case OT_DEVICE_ROLE_ROUTER:
|
||||
case Mle::kRoleChild:
|
||||
case Mle::kRoleRouter:
|
||||
if (mLastTimeSyncReceived.GetValue() == 0)
|
||||
{
|
||||
// Haven't yet received any time sync
|
||||
@@ -260,7 +259,7 @@ void TimeSync::CheckAndHandleChanges(bool aTimeUpdated)
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_DEVICE_ROLE_LEADER:
|
||||
case Mle::kRoleLeader:
|
||||
otLogInfoCore("Time sync status SYNCHRONIZED as role:LEADER");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ void ChannelManager::PreparePendingDataset(void)
|
||||
// situation where a channel change request comes right after the
|
||||
// network is formed but before the active dataset is created.
|
||||
|
||||
if (Get<Mle::Mle>().GetRole() != OT_DEVICE_ROLE_DISABLED)
|
||||
if (!Get<Mle::Mle>().IsDisabled())
|
||||
{
|
||||
mTimer.Start(kPendingDatasetTxRetryInterval);
|
||||
}
|
||||
@@ -345,7 +345,7 @@ otError ChannelManager::RequestChannelSelect(bool aSkipQualityCheck)
|
||||
otLogInfoUtil("ChannelManager: Request to select channel (skip quality check: %s)",
|
||||
aSkipQualityCheck ? "yes" : "no");
|
||||
|
||||
VerifyOrExit(Get<Mle::Mle>().GetRole() != OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE);
|
||||
VerifyOrExit(!Get<Mle::Mle>().IsDisabled(), error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
VerifyOrExit(aSkipQualityCheck || ShouldAttemptChannelChange());
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ void ChildSupervisor::CheckState(void)
|
||||
// zero, Thread MLE operation is enabled, and there is at least one
|
||||
// "valid" child in the child table.
|
||||
|
||||
shouldRun = ((mSupervisionInterval != 0) && (Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_DISABLED) &&
|
||||
shouldRun = ((mSupervisionInterval != 0) && !Get<Mle::MleRouter>().IsDisabled() &&
|
||||
Get<ChildTable>().HasChildren(Child::kInStateValid));
|
||||
|
||||
if (shouldRun && !mTimer.IsRunning())
|
||||
@@ -208,7 +208,7 @@ void SupervisionListener::UpdateOnReceive(const Mac::Address &aSourceAddress, bo
|
||||
{
|
||||
// If listener is enabled and device is a child and it received a secure frame from its parent, restart the timer.
|
||||
|
||||
VerifyOrExit(mTimer.IsRunning() && aIsSecure && (Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_CHILD) &&
|
||||
VerifyOrExit(mTimer.IsRunning() && aIsSecure && Get<Mle::MleRouter>().IsChild() &&
|
||||
(Get<Mle::MleRouter>().GetNeighbor(aSourceAddress) == &Get<Mle::MleRouter>().GetParent()));
|
||||
|
||||
RestartTimer();
|
||||
@@ -219,8 +219,7 @@ exit:
|
||||
|
||||
void SupervisionListener::RestartTimer(void)
|
||||
{
|
||||
if ((mTimeout != 0) && (Get<Mle::MleRouter>().GetRole() != OT_DEVICE_ROLE_DISABLED) &&
|
||||
!Get<MeshForwarder>().GetRxOnWhenIdle())
|
||||
if ((mTimeout != 0) && !Get<Mle::MleRouter>().IsDisabled() && !Get<MeshForwarder>().GetRxOnWhenIdle())
|
||||
{
|
||||
mTimer.Start(Time::SecToMsec(mTimeout));
|
||||
}
|
||||
@@ -237,7 +236,7 @@ void SupervisionListener::HandleTimer(Timer &aTimer)
|
||||
|
||||
void SupervisionListener::HandleTimer(void)
|
||||
{
|
||||
VerifyOrExit((Get<Mle::MleRouter>().GetRole() == OT_DEVICE_ROLE_CHILD) && !Get<MeshForwarder>().GetRxOnWhenIdle());
|
||||
VerifyOrExit(Get<Mle::MleRouter>().IsChild() && !Get<MeshForwarder>().GetRxOnWhenIdle());
|
||||
|
||||
otLogWarnUtil("Supervision timeout. No frame from parent in %d sec", mTimeout);
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ void JamDetector::CheckState(void)
|
||||
|
||||
switch (Get<Mle::MleRouter>().GetRole())
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
case Mle::kRoleDisabled:
|
||||
VerifyOrExit(mTimer.IsRunning());
|
||||
mTimer.Stop();
|
||||
SetJamState(false);
|
||||
|
||||
Reference in New Issue
Block a user