[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:
Yakun Xu
2019-04-08 21:24:52 -07:00
committed by Jonathan Hui
parent 5d2e6cd0d9
commit bbb19c2aa2
3 changed files with 23 additions and 21 deletions
+2 -1
View File
@@ -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);
+3 -2
View File
@@ -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;
}
+18 -18
View File
@@ -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;