[mle] restrict SetPreferredRouterId() API to REF_DEVICE (#12973)

This commit restricts the API to set a preferred router ID under
`OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE`. This feature is intended
for testing and therefore be excluded from standard builds to ensure
compliance with the Thread Specification.
This commit is contained in:
Abtin Keshavarzian
2026-04-27 17:04:20 -07:00
committed by GitHub
parent 71d43b5cca
commit 1413778a09
10 changed files with 25 additions and 9 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ extern "C" {
*
* @note This number versions both OpenThread platform and user APIs.
*/
#define OPENTHREAD_API_VERSION (591)
#define OPENTHREAD_API_VERSION (592)
/**
* @addtogroup api-instance
+5 -3
View File
@@ -180,14 +180,16 @@ bool otThreadIsRouterEligible(otInstance *aInstance);
otError otThreadSetRouterEligible(otInstance *aInstance, bool aEligible);
/**
* Set the preferred Router Id.
* Sets the preferred Router Id.
*
* Requires `OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE`.
*
* Upon becoming a router/leader the node attempts to use this Router Id. If the preferred Router Id is not set or if
* it can not be used, a randomly generated router id is picked. This property can be set only when the device role is
* either detached or disabled.
*
* @note This API is reserved for testing and demo purposes only. Changing settings with
* this API will render a production application non-compliant with the Thread Specification.
* @note This API is reserved for testing and demo purposes only. Changing settings with this API will render a
* production application non-compliant with the Thread Specification.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aRouterId The preferred Router Id.
+2 -2
View File
@@ -5618,7 +5618,7 @@ exit:
* Specifies the preferred router ID that the leader should provide when solicited.
* @sa otThreadSetPreferredRouterId
*/
#if OPENTHREAD_FTD
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
template <> otError Interpreter::Process<Cmd("preferrouterid")>(Arg aArgs[])
{
return ProcessSet(aArgs, otThreadSetPreferredRouterId);
@@ -8656,7 +8656,7 @@ otError Interpreter::ProcessCommand(Arg aArgs[])
#endif
CmdEntry("platform"),
CmdEntry("pollperiod"),
#if OPENTHREAD_FTD
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
CmdEntry("preferrouterid"),
#endif
#if OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE
+2
View File
@@ -71,10 +71,12 @@ otError otThreadSetRouterEligible(otInstance *aInstance, bool aEligible)
return AsCoreType(aInstance).Get<Mle::Mle>().SetRouterEligible(aEligible);
}
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId)
{
return AsCoreType(aInstance).Get<Mle::Mle>().SetPreferredRouterId(aRouterId);
}
#endif
#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE
const otDeviceProperties *otThreadGetDeviceProperties(otInstance *aInstance)
+2 -2
View File
@@ -875,8 +875,6 @@ public:
*/
void SetPreferredLeaderPartitionId(uint32_t aPartitionId) { mPreferredLeaderPartitionId = aPartitionId; }
#endif
/**
* Sets the preferred Router Id. Upon becoming a router/leader the node
* attempts to use this Router Id. If the preferred Router Id is not set or if it
@@ -890,6 +888,8 @@ public:
*/
Error SetPreferredRouterId(uint8_t aRouterId);
#endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
/**
* Gets the Partition Id which the device joined successfully once.
*/
+2
View File
@@ -3296,6 +3296,7 @@ exit:
return;
}
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
Error Mle::SetPreferredRouterId(uint8_t aRouterId)
{
Error error = kErrorNone;
@@ -3307,6 +3308,7 @@ Error Mle::SetPreferredRouterId(uint8_t aRouterId)
exit:
return error;
}
#endif
void Mle::SetRouterId(uint8_t aRouterId)
{
+1 -1
View File
@@ -298,7 +298,7 @@ NcpBase::NcpBase(Instance *aInstance)
#if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE
, mAllowLocalServerDataChange(false)
#endif
#if OPENTHREAD_FTD
#if OPENTHREAD_FTD && OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
, mPreferredRouteId(0)
#endif
, mCurCommandIid(0)
+2
View File
@@ -816,7 +816,9 @@ protected:
#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE
otExtAddress mSteeringDataAddress;
#endif
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
uint8_t mPreferredRouteId;
#endif
#endif
uint8_t mCurCommandIid;
+4
View File
@@ -292,7 +292,9 @@ NcpBase::PropertyHandler NcpBase::FindGetPropertyHandler(spinel_prop_key_t aKey)
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_ROUTER_ROLE_ENABLED),
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_ROUTER_DOWNGRADE_THRESHOLD),
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_ROUTER_SELECTION_JITTER),
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_PREFERRED_ROUTER_ID),
#endif
#endif
OT_NCP_GET_HANDLER_ENTRY(SPINEL_PROP_THREAD_NEIGHBOR_TABLE),
#if OPENTHREAD_FTD
@@ -610,7 +612,9 @@ NcpBase::PropertyHandler NcpBase::FindSetPropertyHandler(spinel_prop_key_t aKey)
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_ROUTER_ROLE_ENABLED),
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_ROUTER_DOWNGRADE_THRESHOLD),
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_ROUTER_SELECTION_JITTER),
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_PREFERRED_ROUTER_ID),
#endif
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_CHILD_COUNT_MAX),
#endif
OT_NCP_SET_HANDLER_ENTRY(SPINEL_PROP_THREAD_DISCOVERY_SCAN_JOINER_FLAG),
+4
View File
@@ -1218,6 +1218,8 @@ exit:
}
#endif // #if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE
#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE
template <> otError NcpBase::HandlePropertyGet<SPINEL_PROP_THREAD_PREFERRED_ROUTER_ID>(void)
{
return mEncoder.WriteUint8(mPreferredRouteId);
@@ -1235,6 +1237,8 @@ exit:
return error;
}
#endif
template <> otError NcpBase::HandlePropertyRemove<SPINEL_PROP_THREAD_ACTIVE_ROUTER_IDS>(void)
{
otError error = OT_ERROR_NONE;