diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 1811cf49b..6bf2ca39d 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -395,7 +395,18 @@ otError otThreadSetEnabled(otInstance *aInstance, bool aEnabled) uint16_t otThreadGetVersion(void) { return kThreadVersion; } -bool otThreadIsSingleton(otInstance *aInstance) { return AsCoreType(aInstance).Get().IsSingleton(); } +bool otThreadIsSingleton(otInstance *aInstance) +{ + bool isSingleton = false; + +#if OPENTHREAD_FTD + isSingleton = AsCoreType(aInstance).Get().IsSingleton(); +#else + OT_UNUSED_VARIABLE(aInstance); +#endif + + return isSingleton; +} otError otThreadDiscover(otInstance *aInstance, uint32_t aScanChannels, diff --git a/src/core/instance/instance.hpp b/src/core/instance/instance.hpp index 1d5f5b5a5..4d1a3255b 100644 --- a/src/core/instance/instance.hpp +++ b/src/core/instance/instance.hpp @@ -713,7 +713,9 @@ template <> inline RadioSelector &Instance::Get(void) { return mRadioSelector; } template <> inline Mle::Mle &Instance::Get(void) { return mMleRouter; } +#if OPENTHREAD_FTD template <> inline Mle::MleRouter &Instance::Get(void) { return mMleRouter; } +#endif template <> inline Mle::DiscoverScanner &Instance::Get(void) { return mDiscoverScanner; } diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 5fd24dd72..4355447f2 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -1157,7 +1157,11 @@ void MeshForwarder::UpdateNeighborLinkFailures(Neighbor &aNeighbor, if (aAllowNeighborRemove && (Mle::IsActiveRouter(aNeighbor.GetRloc16())) && (aNeighbor.GetLinkFailures() >= aFailLimit)) { +#if OPENTHREAD_FTD Get().RemoveRouterLink(static_cast(aNeighbor)); +#else + IgnoreError(Get().BecomeDetached()); +#endif } } } diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index a90b2396b..7719bf62b 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -96,7 +96,9 @@ namespace Mle { * */ +#if OPENTHREAD_FTD class MleRouter; +#endif /** * Implements MLE functionality required by the Thread EndDevices, Router, and Leader roles. @@ -104,7 +106,9 @@ class MleRouter; */ class Mle : public InstanceLocator, private NonCopyable { +#if OPENTHREAD_FTD friend class MleRouter; +#endif friend class DiscoverScanner; friend class ot::Instance; friend class ot::Notifier; @@ -699,6 +703,16 @@ public: return (&aAddress == &mLinkLocalAllThreadNodes) || (&aAddress == &mRealmLocalAllThreadNodes); } + /** + * Determines the next hop towards an RLOC16 destination. + * + * @param[in] aDestination The RLOC16 of the destination. + * + * @returns A RLOC16 of the next hop if a route is known, kInvalidRloc16 otherwise. + * + */ + uint16_t GetNextHop(uint16_t aDestination) const; + #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE /** * Gets the CSL timeout. @@ -1219,7 +1233,6 @@ private: void InitNeighbor(Neighbor &aNeighbor, const RxInfo &aRxInfo); void ClearParentCandidate(void) { mParentCandidate.Clear(); } Error CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header); - uint16_t GetNextHop(uint16_t aDestination) const; Error SendDataRequest(const Ip6::Address &aDestination); void HandleNotifierEvents(Events aEvents); void SendDelayedResponse(TxMessage &aMessage, const DelayedResponseMetadata &aMetadata); diff --git a/src/core/thread/mle_router.hpp b/src/core/thread/mle_router.hpp index 048d901d9..65bfe114a 100644 --- a/src/core/thread/mle_router.hpp +++ b/src/core/thread/mle_router.hpp @@ -770,33 +770,9 @@ DeclareTmfHandler(MleRouter, kUriAddressRelease); #if OPENTHREAD_MTD -class MleRouter : public Mle -{ - friend class Mle; - friend class ot::Instance; +typedef Mle MleRouter; -public: - explicit MleRouter(Instance &aInstance) - : Mle(aInstance) - { - } - - bool IsSingleton(void) const { return false; } - - uint16_t GetNextHop(uint16_t aDestination) const { return Mle::GetNextHop(aDestination); } - - Error RemoveNeighbor(Neighbor &) { return BecomeDetached(); } - void RemoveRouterLink(Router &) { IgnoreError(BecomeDetached()); } - - Error SendChildUpdateRequest(void) { return Mle::SendChildUpdateRequest(); } - - Error CheckReachability(uint16_t aMeshDest, const Ip6::Header &aIp6Header) - { - return Mle::CheckReachability(aMeshDest, aIp6Header); - } -}; - -#endif // OPENTHREAD_MTD +#endif } // namespace Mle