[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:
Jonathan Hui
2019-12-03 09:28:35 +08:00
parent 27f5d9a06e
commit e2723f6c05
6 changed files with 21 additions and 8 deletions
+4 -1
View File
@@ -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
View File
@@ -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
{
+2 -2
View File
@@ -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)
+8 -1
View File
@@ -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)
+4 -1
View File
@@ -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.
+1 -1
View File
@@ -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;