From 4460fb1815aab8a02b3472826a3c53eb52525ebc Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Sat, 3 Jun 2017 00:03:48 +0800 Subject: [PATCH] Don't return parent info if the device is not a child (#1868) * Fix the issue that the previous parent information could be retrieved even after the device is not a child * Print more parent information in CLI --- src/cli/cli.cpp | 3 +++ src/core/api/thread_api.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index e649a2716..9fbc9fef8 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -1534,6 +1534,9 @@ void Interpreter::ProcessParent(int argc, char *argv[]) mServer->OutputFormat("\r\n"); mServer->OutputFormat("Rloc: %x\r\n", parentInfo.mRloc16); + mServer->OutputFormat("Link Quality In: %d\r\n", parentInfo.mLinkQualityIn); + mServer->OutputFormat("Link Quality Out: %d\r\n", parentInfo.mLinkQualityOut); + mServer->OutputFormat("Age: %d\r\n", parentInfo.mAge); exit: (void)argc; diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 5426b6d1a..e55f88be1 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -304,6 +304,9 @@ otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) otError error = OT_ERROR_NONE; Router *parent; + VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_CHILD, + error = OT_ERROR_INVALID_STATE); + VerifyOrExit(aParentInfo != NULL, error = OT_ERROR_INVALID_ARGS); parent = aInstance->mThreadNetif.GetMle().GetParent();