mirror of
https://github.com/espressif/openthread.git
synced 2026-08-03 01:17:46 +00:00
[radio] only allow disable in sleep state (#3733)
There's missing error definition for otPlatRadioDisable(). This commit adds an error case OT_ERROR_INVALID_STATE to make sure this is only called when the radio is in sleep mode.
This commit is contained in:
@@ -422,7 +422,8 @@ otError otPlatRadioEnable(otInstance *aInstance);
|
||||
*
|
||||
* @param[in] aInstance The OpenThread instance structure.
|
||||
*
|
||||
* @retval OT_ERROR_NONE Successfully transitioned to Disabled.
|
||||
* @retval OT_ERROR_NONE Successfully transitioned to Disabled.
|
||||
* @retval OT_ERROR_INVALID_STATE The radio was not in sleep state.
|
||||
*
|
||||
*/
|
||||
otError otPlatRadioDisable(otInstance *aInstance);
|
||||
|
||||
@@ -148,10 +148,11 @@ otError SubMac::Disable(void)
|
||||
otError error;
|
||||
|
||||
mTimer.Stop();
|
||||
error = otPlatRadioDisable(&GetInstance());
|
||||
assert(error == OT_ERROR_NONE);
|
||||
SuccessOrExit(error = otPlatRadioSleep(&GetInstance()));
|
||||
SuccessOrExit(error = otPlatRadioDisable(&GetInstance()));
|
||||
SetState(kStateDisabled);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@@ -1308,22 +1308,24 @@ otError RadioSpinel::Enable(otInstance *aInstance)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (!otPlatRadioIsEnabled(mInstance))
|
||||
{
|
||||
mInstance = aInstance;
|
||||
VerifyOrExit(!IsEnabled());
|
||||
|
||||
SuccessOrExit(error = Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
|
||||
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_PANID, SPINEL_DATATYPE_UINT16_S, mPanId));
|
||||
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_SADDR, SPINEL_DATATYPE_UINT16_S, mShortAddress));
|
||||
mInstance = aInstance;
|
||||
|
||||
error = Get(SPINEL_PROP_PHY_RX_SENSITIVITY, SPINEL_DATATYPE_INT8_S, &mRxSensitivity);
|
||||
VerifyOrExit(error == OT_ERROR_NONE);
|
||||
SuccessOrExit(error = Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, true));
|
||||
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_PANID, SPINEL_DATATYPE_UINT16_S, mPanId));
|
||||
SuccessOrExit(error = Set(SPINEL_PROP_MAC_15_4_SADDR, SPINEL_DATATYPE_UINT16_S, mShortAddress));
|
||||
SuccessOrExit(error = Get(SPINEL_PROP_PHY_RX_SENSITIVITY, SPINEL_DATATYPE_INT8_S, &mRxSensitivity));
|
||||
|
||||
mState = kStateSleep;
|
||||
}
|
||||
mState = kStateSleep;
|
||||
|
||||
exit:
|
||||
assert(error == OT_ERROR_NONE);
|
||||
if (error != OT_ERROR_NONE)
|
||||
{
|
||||
otLogWarnPlat("RadioSpinel enable: %s", otThreadErrorToString(error));
|
||||
error = OT_ERROR_FAILED;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
@@ -1331,14 +1333,12 @@ otError RadioSpinel::Disable(void)
|
||||
{
|
||||
otError error = OT_ERROR_NONE;
|
||||
|
||||
if (otPlatRadioIsEnabled(mInstance))
|
||||
{
|
||||
mInstance = NULL;
|
||||
error = sRadioSpinel.Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, false);
|
||||
VerifyOrExit(error == OT_ERROR_NONE);
|
||||
VerifyOrExit(IsEnabled());
|
||||
VerifyOrExit(mState == kStateSleep, error = OT_ERROR_INVALID_STATE);
|
||||
|
||||
mState = kStateDisabled;
|
||||
}
|
||||
SuccessOrDie(sRadioSpinel.Set(SPINEL_PROP_PHY_ENABLED, SPINEL_DATATYPE_BOOL_S, false));
|
||||
mState = kStateDisabled;
|
||||
mInstance = NULL;
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
Reference in New Issue
Block a user