diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index 803bb4114..baa718c33 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -54,7 +54,7 @@ otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel) VerifyOrExit(aInstance->mThreadNetif.GetMle().GetRole() == OT_DEVICE_ROLE_DISABLED, error = OT_ERROR_INVALID_STATE); - error = aInstance->mThreadNetif.GetMac().SetChannel(aChannel); + SuccessOrExit(error = aInstance->mThreadNetif.GetMac().SetChannel(aChannel)); aInstance->mThreadNetif.GetActiveDataset().Clear(); aInstance->mThreadNetif.GetPendingDataset().Clear(); diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 0ee80de77..ef64b7b33 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -475,7 +475,12 @@ otError Mac::SetShortAddress(ShortAddress aShortAddress) otError Mac::SetChannel(uint8_t aChannel) { + otError error = OT_ERROR_NONE; + otLogFuncEntryMsg("%d", aChannel); + + VerifyOrExit(OT_RADIO_CHANNEL_MIN <= aChannel && aChannel <= OT_RADIO_CHANNEL_MAX, error = OT_ERROR_INVALID_ARGS); + mChannel = aChannel; if (mState == kStateIdle) @@ -483,8 +488,9 @@ otError Mac::SetChannel(uint8_t aChannel) NextOperation(); } +exit: otLogFuncExit(); - return OT_ERROR_NONE; + return error; } otError Mac::SetNetworkName(const char *aNetworkName)