From a8b5b078492a9f0afebb6b3433068d05164bc5f8 Mon Sep 17 00:00:00 2001 From: Yakun Xu Date: Thu, 3 Dec 2020 15:16:08 +0800 Subject: [PATCH] [diag] check state before entering diagnostic mode (#5908) This commit restrict diagnostic mode only when network stack is not up, which prevents some issues caused by switching to diag mode after the device was attached. For example, timers may not be triggered properly after returnning from diagnostic mode. --- src/core/diags/factory_diags.cpp | 2 ++ tests/scripts/expect/cli-misc.exp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/core/diags/factory_diags.cpp b/src/core/diags/factory_diags.cpp index 12bfefb0e..783b845f8 100644 --- a/src/core/diags/factory_diags.cpp +++ b/src/core/diags/factory_diags.cpp @@ -288,6 +288,8 @@ otError Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[], char *aOutput, s otError error = OT_ERROR_NONE; + VerifyOrExit(!Get().IsUp(), error = OT_ERROR_INVALID_STATE); + otPlatDiagChannelSet(mChannel); otPlatDiagTxPowerSet(mTxPower); diff --git a/tests/scripts/expect/cli-misc.exp b/tests/scripts/expect/cli-misc.exp index 999efd1e5..65992bb19 100755 --- a/tests/scripts/expect/cli-misc.exp +++ b/tests/scripts/expect/cli-misc.exp @@ -164,4 +164,7 @@ expect "0:0:0:0::/64 s low" send "route remove ::/64\n" expect "Done" +send "diag start\n" +expect ": InvalidState" + dispose_all