mirror of
https://github.com/espressif/openthread.git
synced 2026-08-04 01:47:47 +00:00
[mle] add return error to otThreadSetRouterEligible (#4363)
When trying to set router-eligible and the device is not capable of becoming a router, return OT_ERROR_NOT_CAPABLE.
This commit is contained in:
@@ -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.
|
||||
|
||||
+2
-2
@@ -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
|
||||
{
|
||||
|
||||
@@ -65,11 +65,11 @@ bool otThreadIsRouterEligible(otInstance *aInstance)
|
||||
return instance.Get<Mle::MleRouter>().IsRouterEligible();
|
||||
}
|
||||
|
||||
void otThreadSetRouterEligible(otInstance *aInstance, bool aEligible)
|
||||
otError otThreadSetRouterEligible(otInstance *aInstance, bool aEligible)
|
||||
{
|
||||
Instance &instance = *static_cast<Instance *>(aInstance);
|
||||
|
||||
instance.Get<Mle::MleRouter>().SetRouterEligible(aEligible);
|
||||
return instance.Get<Mle::MleRouter>().SetRouterEligible(aEligible);
|
||||
}
|
||||
|
||||
otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -304,7 +304,7 @@ template <> otError NcpBase::HandlePropertySet<SPINEL_PROP_THREAD_ROUTER_ROLE_EN
|
||||
|
||||
SuccessOrExit(error = mDecoder.ReadBool(eligible));
|
||||
|
||||
otThreadSetRouterEligible(mInstance, eligible);
|
||||
error = otThreadSetRouterEligible(mInstance, eligible);
|
||||
|
||||
exit:
|
||||
return error;
|
||||
|
||||
Reference in New Issue
Block a user