mirror of
https://github.com/espressif/openthread.git
synced 2026-08-12 21:57:47 +00:00
[mle] save network info on mle mode change (#4078)
This commit ensures to save the network info in non-volatile settings when the MLE device mode is changed (`Mle::SetDevcieMode()`) independent of whether the device is currently attached or not. This helps address the situation where there is a single router/leader device in network and user changes the MLE thread mode to make it a sleepy (where due to device being the only node in the network it would not attach). Then, later upon device reset (without the change in this commit) the device would have started again as router/leader. Note that network info is saved/updated in non-volatile memory after a successful attach.
This commit is contained in:
committed by
Jonathan Hui
parent
278315c6e5
commit
f73b6b9337
@@ -382,6 +382,7 @@ otError Mle::Restore(void)
|
||||
Get<KeyManager>().SetCurrentKeySequence(networkInfo.mKeySequence);
|
||||
Get<KeyManager>().SetMleFrameCounter(networkInfo.mMleFrameCounter);
|
||||
Get<KeyManager>().SetMacFrameCounter(networkInfo.mMacFrameCounter);
|
||||
mDeviceMode.Set(networkInfo.mDeviceMode);
|
||||
|
||||
switch (networkInfo.mRole)
|
||||
{
|
||||
@@ -394,7 +395,6 @@ otError Mle::Restore(void)
|
||||
ExitNow();
|
||||
}
|
||||
|
||||
mDeviceMode.Set(networkInfo.mDeviceMode);
|
||||
Get<Mac::Mac>().SetShortAddress(networkInfo.mRloc16);
|
||||
Get<Mac::Mac>().SetExtAddress(networkInfo.mExtAddress);
|
||||
|
||||
@@ -458,7 +458,6 @@ otError Mle::Store(void)
|
||||
// avoid losing/overwriting previous information when a reboot
|
||||
// occurs after a message is sent but before attaching.
|
||||
|
||||
networkInfo.mDeviceMode = mDeviceMode.Get();
|
||||
networkInfo.mRole = mRole;
|
||||
networkInfo.mRloc16 = GetRloc16();
|
||||
networkInfo.mPreviousPartitionId = mLeaderData.GetPartitionId();
|
||||
@@ -491,6 +490,7 @@ otError Mle::Store(void)
|
||||
networkInfo.mKeySequence = Get<KeyManager>().GetCurrentKeySequence();
|
||||
networkInfo.mMleFrameCounter = Get<KeyManager>().GetMleFrameCounter() + OPENTHREAD_CONFIG_STORE_FRAME_COUNTER_AHEAD;
|
||||
networkInfo.mMacFrameCounter = Get<KeyManager>().GetMacFrameCounter() + OPENTHREAD_CONFIG_STORE_FRAME_COUNTER_AHEAD;
|
||||
networkInfo.mDeviceMode = mDeviceMode.Get();
|
||||
|
||||
SuccessOrExit(error = Get<Settings>().SaveNetworkInfo(networkInfo));
|
||||
|
||||
@@ -842,6 +842,8 @@ otError Mle::SetDeviceMode(DeviceMode aDeviceMode)
|
||||
|
||||
otLogNoteMle("Mode 0x%02x -> 0x%02x [%s]", oldMode.Get(), mDeviceMode.Get(), mDeviceMode.ToString().AsCString());
|
||||
|
||||
Store();
|
||||
|
||||
switch (mRole)
|
||||
{
|
||||
case OT_DEVICE_ROLE_DISABLED:
|
||||
|
||||
Reference in New Issue
Block a user