diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 40948c152..e80b788b0 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -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 diff --git a/include/openthread/thread_ftd.h b/include/openthread/thread_ftd.h index f5b5838ae..4d81193c6 100644 --- a/include/openthread/thread_ftd.h +++ b/include/openthread/thread_ftd.h @@ -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. diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index da3f6f1da..ef8983604 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -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(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 diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index 6cfb7689b..29629f0f4 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -71,10 +71,12 @@ otError otThreadSetRouterEligible(otInstance *aInstance, bool aEligible) return AsCoreType(aInstance).Get().SetRouterEligible(aEligible); } +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId) { return AsCoreType(aInstance).Get().SetPreferredRouterId(aRouterId); } +#endif #if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE const otDeviceProperties *otThreadGetDeviceProperties(otInstance *aInstance) diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 2fc4a5166..76cbda6e7 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -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. */ diff --git a/src/core/thread/mle_ftd.cpp b/src/core/thread/mle_ftd.cpp index 8e0416fe9..fb65a9aea 100644 --- a/src/core/thread/mle_ftd.cpp +++ b/src/core/thread/mle_ftd.cpp @@ -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) { diff --git a/src/ncp/ncp_base.cpp b/src/ncp/ncp_base.cpp index 044e099b5..6726380d0 100644 --- a/src/ncp/ncp_base.cpp +++ b/src/ncp/ncp_base.cpp @@ -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) diff --git a/src/ncp/ncp_base.hpp b/src/ncp/ncp_base.hpp index a0f4d3526..d9aa796ae 100644 --- a/src/ncp/ncp_base.hpp +++ b/src/ncp/ncp_base.hpp @@ -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; diff --git a/src/ncp/ncp_base_dispatcher.cpp b/src/ncp/ncp_base_dispatcher.cpp index f025e95a6..9a8fd7ee6 100644 --- a/src/ncp/ncp_base_dispatcher.cpp +++ b/src/ncp/ncp_base_dispatcher.cpp @@ -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), diff --git a/src/ncp/ncp_base_ftd.cpp b/src/ncp/ncp_base_ftd.cpp index bcc8d54cc..cb1ed88ec 100644 --- a/src/ncp/ncp_base_ftd.cpp +++ b/src/ncp/ncp_base_ftd.cpp @@ -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(void) { return mEncoder.WriteUint8(mPreferredRouteId); @@ -1235,6 +1237,8 @@ exit: return error; } +#endif + template <> otError NcpBase::HandlePropertyRemove(void) { otError error = OT_ERROR_NONE;