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; }