From b6f6d34606316f6511dfce2a496ea0953876b50a Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Fri, 15 May 2026 22:31:14 +0800 Subject: [PATCH] [diag] invoke SetDiagMode before setting channel/power (#12941) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Host + RCP mode, running `diag start` from the host CLI may trigger RadioSpinel warnings: InvalidState, “Error processing result” / “Error waiting response”. **Root cause** Diags::ProcessStart sent channel / power commands before enabling diag mode. On Spinel, these are forwarded to the RCP (via `SPINEL_PROP_NEST_STREAM_MFG`), but the RCP only accepts other diag commands after start. ``` if (!IsEnabled() && !StringMatch(aArgs[0], "start")) { Output("diagnostics mode is disabled\r\n"); ExitNow(error = kErrorInvalidState); } ``` As a result, early channel / power commands are rejected with InvalidState. --- src/core/diags/factory_diags.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/core/diags/factory_diags.cpp b/src/core/diags/factory_diags.cpp index f9658e56f..307176489 100644 --- a/src/core/diags/factory_diags.cpp +++ b/src/core/diags/factory_diags.cpp @@ -491,19 +491,24 @@ Error Diags::ProcessStart(uint8_t aArgsLength, char *aArgs[]) VerifyOrExit(!Get().IsUp(), error = kErrorInvalidState); #endif + mStats.Clear(); + IgnoreError(Get().Enable()); + Get().SetDiagMode(true); otPlatDiagChannelSet(mChannel); otPlatDiagTxPowerSet(mTxPower); - IgnoreError(Get().Enable()); Get().SetPromiscuous(true); Get().SetRxOnWhenIdle(true); otPlatAlarmMilliStop(&GetInstance()); SuccessOrExit(error = Get().Receive(mChannel)); SuccessOrExit(error = Get().SetTransmitPower(mTxPower)); - Get().SetDiagMode(true); - mStats.Clear(); exit: + if (error != kErrorNone) + { + Get().SetDiagMode(false); + } + return error; }