diff --git a/include/openthread/thread_ftd.h b/include/openthread/thread_ftd.h index 1839297a5..a64e2228e 100644 --- a/include/openthread/thread_ftd.h +++ b/include/openthread/thread_ftd.h @@ -142,8 +142,11 @@ bool otThreadIsRouterEligible(otInstance *aInstance); * @param[in] aInstance A pointer to an OpenThread instance. * @param[in] aEligible TRUE to configure the device as router-eligible, FALSE otherwise. * + * @retval OT_ERROR_NONE Successfully set the router-eligible configuration. + * @retval OT_ERROR_NOT_CAPABLE The device is not capable of becoming a router. + * */ -void otThreadSetRouterEligible(otInstance *aInstance, bool aEligible); +otError otThreadSetRouterEligible(otInstance *aInstance, bool aEligible); /** * Set the preferred Router Id. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index 2c1917c26..c50cdfe2e 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -2777,11 +2777,11 @@ void Interpreter::ProcessRouterEligible(int argc, char *argv[]) } else if (strcmp(argv[0], "enable") == 0) { - otThreadSetRouterEligible(mInstance, true); + error = otThreadSetRouterEligible(mInstance, true); } else if (strcmp(argv[0], "disable") == 0) { - otThreadSetRouterEligible(mInstance, false); + error = otThreadSetRouterEligible(mInstance, false); } else { diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index 338d6c727..4746ed976 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -65,11 +65,11 @@ bool otThreadIsRouterEligible(otInstance *aInstance) return instance.Get().IsRouterEligible(); } -void otThreadSetRouterEligible(otInstance *aInstance, bool aEligible) +otError otThreadSetRouterEligible(otInstance *aInstance, bool aEligible) { Instance &instance = *static_cast(aInstance); - instance.Get().SetRouterEligible(aEligible); + return instance.Get().SetRouterEligible(aEligible); } otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId) diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index f6b2d119d..e883ac342 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -102,8 +102,12 @@ bool MleRouter::IsRouterEligible(void) const return mRouterEligible && IsFullThreadDevice(); } -void MleRouter::SetRouterEligible(bool aEligible) +otError MleRouter::SetRouterEligible(bool aEligible) { + otError error = OT_ERROR_NONE; + + VerifyOrExit(IsFullThreadDevice(), error = OT_ERROR_NOT_CAPABLE); + mRouterEligible = aEligible; switch (mRole) @@ -125,6 +129,9 @@ void MleRouter::SetRouterEligible(bool aEligible) break; } + +exit: + return error; } otError MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus) diff --git a/src/core/thread/mle_router_ftd.hpp b/src/core/thread/mle_router_ftd.hpp index f4e1495c4..e2e9d9680 100644 --- a/src/core/thread/mle_router_ftd.hpp +++ b/src/core/thread/mle_router_ftd.hpp @@ -102,8 +102,11 @@ public: * * @param[in] aEligible TRUE to configure device router-eligible, FALSE otherwise. * + * @retval OT_ERROR_NONE Successfully set the router-eligible configuration. + * @retval OT_ERROR_NOT_CAPABLE The device is not capable of becoming a router. + * */ - void SetRouterEligible(bool aEligible); + otError SetRouterEligible(bool aEligible); /** * This method indicates whether a node is the only router on the network. diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index f15b8321b..dde5c9d0e 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -304,7 +304,7 @@ template <> otError NcpBase::HandlePropertySet