[mle] simplify device role checks using IsAttached method (#2975)

This commit is contained in:
Abtin Keshavarzian
2018-08-18 18:04:33 -07:00
committed by Jonathan Hui
parent f993ba5f89
commit e731babedb
2 changed files with 12 additions and 3 deletions
+11 -2
View File
@@ -347,7 +347,16 @@ otError Mle::Restore(void)
netif.GetKeyManager().SetMleFrameCounter(networkInfo.mMleFrameCounter);
netif.GetKeyManager().SetMacFrameCounter(networkInfo.mMacFrameCounter);
VerifyOrExit(networkInfo.mRole >= OT_DEVICE_ROLE_CHILD);
switch (networkInfo.mRole)
{
case OT_DEVICE_ROLE_CHILD:
case OT_DEVICE_ROLE_ROUTER:
case OT_DEVICE_ROLE_LEADER:
break;
default:
ExitNow();
}
mDeviceMode = networkInfo.mDeviceMode;
SetRloc16(networkInfo.mRloc16);
@@ -879,7 +888,7 @@ otError Mle::SetMeshLocalPrefix(const otMeshLocalPrefix &aMeshLocalPrefix)
netif.SubscribeMulticast(mLinkLocalAllThreadNodes);
netif.SubscribeMulticast(mRealmLocalAllThreadNodes);
if (mRole >= OT_DEVICE_ROLE_CHILD)
if (IsAttached())
{
netif.AddUnicastAddress(mMeshLocal16);
}
+1 -1
View File
@@ -2074,7 +2074,7 @@ otError MleRouter::HandleChildIdRequest(const Message & aMessage,
VerifyOrExit(IsRouterRoleEnabled(), error = OT_ERROR_INVALID_STATE);
// only process message when operating as a child, router, or leader
VerifyOrExit(mRole >= OT_DEVICE_ROLE_CHILD, error = OT_ERROR_INVALID_STATE);
VerifyOrExit(IsAttached(), error = OT_ERROR_INVALID_STATE);
// Find Child
aMessageInfo.GetPeerAddr().ToExtAddress(macAddr);