From afcb3452199e2c7c09abb5f807ffd4d00e8acd13 Mon Sep 17 00:00:00 2001 From: Abtin Keshavarzian Date: Fri, 19 Jan 2018 09:04:35 -0800 Subject: [PATCH] [mle] become detached if no valid parent when sending "Child Update Request" (#2492) This commit changes the checks in `Mle::SendChildUpdateRequest()` so that if there is no valid/restoring parent the device immediately becomes detached and will go through full attach process. This addresses an issue with an end-device failing to re-attach after reset in case the device can restore its network info from settings/flash but there is no parent info entry in the settings. --- src/core/thread/mle.cpp | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 957143432..51646132a 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -337,8 +337,23 @@ otError Mle::Restore(void) if (!IsActiveRouter(networkInfo.mRloc16)) { length = sizeof(parentInfo); - SuccessOrExit(error = otPlatSettingsGet(&netif.GetInstance(), Settings::kKeyParentInfo, 0, - reinterpret_cast(&parentInfo), &length)); + + error = otPlatSettingsGet(&netif.GetInstance(), Settings::kKeyParentInfo, 0, + reinterpret_cast(&parentInfo), &length); + + if (error != OT_ERROR_NONE) + { + // If the restored RLOC16 corresponds to an end-device, it + // is expected that the `ParentInfo` settings to be valid + // as well. The device can still recover from such an invalid + // setting by skipping the re-attach ("Child Update Request" + // exchange) and going through the full attach process. + + otLogWarnMle(GetInstance(), "Invalid settings - no saved parent info with valid end-device RLOC16 0x%04x", + networkInfo.mRloc16); + ExitNow(); + } + VerifyOrExit(length >= sizeof(parentInfo), error = OT_ERROR_PARSE); memset(&mParent, 0, sizeof(mParent)); @@ -1811,7 +1826,12 @@ otError Mle::SendChildUpdateRequest(void) ExitNow(); } - VerifyOrExit(mParent.IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE); + if (!mParent.IsStateValidOrRestoring()) + { + otLogWarnMle(GetInstance(), "No valid parent when sending Child Update Request"); + BecomeDetached(); + ExitNow(); + } mChildUpdateRequestTimer.Start(kUnicastRetransmissionDelay); mChildUpdateAttempts++;