[mle] avoid setting mode D flag on MTD builds (#7519)

When building with `OPENTHREAD_MTD` make sure that the device is not
configured as Full Thread Device, whether by the API or by the stored
settings.
This commit is contained in:
Eduardo Montoya
2022-03-29 22:13:07 -07:00
committed by GitHub
parent 7e4ada6f16
commit b489c35769
+15 -1
View File
@@ -327,7 +327,12 @@ void Mle::Restore(void)
Get<KeyManager>().SetCurrentKeySequence(networkInfo.GetKeySequence());
Get<KeyManager>().SetMleFrameCounter(networkInfo.GetMleFrameCounter());
Get<KeyManager>().SetAllMacFrameCounters(networkInfo.GetMacFrameCounter());
#if OPENTHREAD_MTD
mDeviceMode.Set(networkInfo.GetDeviceMode() & ~DeviceMode::kModeFullThreadDevice);
#else
mDeviceMode.Set(networkInfo.GetDeviceMode());
#endif
// force re-attach when version mismatch.
VerifyOrExit(networkInfo.GetVersion() == kThreadVersion);
@@ -343,7 +348,12 @@ void Mle::Restore(void)
ExitNow();
}
Get<Mac::Mac>().SetShortAddress(networkInfo.GetRloc16());
#if OPENTHREAD_MTD
if (!IsActiveRouter(networkInfo.GetRloc16()))
#endif
{
Get<Mac::Mac>().SetShortAddress(networkInfo.GetRloc16());
}
Get<Mac::Mac>().SetExtAddress(networkInfo.GetExtAddress());
mMeshLocal64.GetAddress().SetIid(networkInfo.GetMeshLocalIid());
@@ -755,6 +765,10 @@ Error Mle::SetDeviceMode(DeviceMode aDeviceMode)
Error error = kErrorNone;
DeviceMode oldMode = mDeviceMode;
#if OPENTHREAD_MTD
VerifyOrExit(!aDeviceMode.IsFullThreadDevice(), error = kErrorInvalidArgs);
#endif
VerifyOrExit(aDeviceMode.IsValid(), error = kErrorInvalidArgs);
VerifyOrExit(mDeviceMode != aDeviceMode);
mDeviceMode = aDeviceMode;