diff --git a/include/openthread/thread_ftd.h b/include/openthread/thread_ftd.h index 5ed1cde65..4dae3b1d2 100644 --- a/include/openthread/thread_ftd.h +++ b/include/openthread/thread_ftd.h @@ -333,6 +333,7 @@ OTAPI void OTCALL otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8 * @param[in] aRouterId The Router ID to release. Valid range is [0, 62]. * * @retval OT_ERROR_NONE Successfully released the router id. + * @retval OT_ERROR_INVALID_ARGS @p aRouterId is not in the range [0, 62]. * @retval OT_ERROR_INVALID_STATE The device is not currently operating as a leader. * @retval OT_ERROR_NOT_FOUND The router id is not currently allocated. * diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index 71738fcd9..6c7963446 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -166,9 +166,15 @@ void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId) { + otError error = OT_ERROR_NONE; Instance &instance = *static_cast(aInstance); - return instance.GetThreadNetif().GetMle().GetRouterTable().Release(aRouterId); + VerifyOrExit(aRouterId <= Mle::kMaxRouterId, error = OT_ERROR_INVALID_ARGS); + + error = instance.GetThreadNetif().GetMle().GetRouterTable().Release(aRouterId); + +exit: + return error; } otError otThreadBecomeRouter(otInstance *aInstance) diff --git a/src/core/thread/router_table.cpp b/src/core/thread/router_table.cpp index 4e3499d41..dbf7028dd 100644 --- a/src/core/thread/router_table.cpp +++ b/src/core/thread/router_table.cpp @@ -261,6 +261,8 @@ otError RouterTable::Release(uint8_t aRouterId) ThreadNetif &netif = GetNetif(); uint16_t rloc16 = Mle::Mle::GetRloc16(aRouterId); + assert(aRouterId <= Mle::kMaxRouterId); + VerifyOrExit(netif.GetMle().GetRole() == OT_DEVICE_ROLE_LEADER, error = OT_ERROR_INVALID_STATE); VerifyOrExit(IsAllocated(aRouterId), error = OT_ERROR_NOT_FOUND);