diff --git a/src/core/api/child_supervision_api.cpp b/src/core/api/child_supervision_api.cpp index 8f6f0b54f..6cab46de2 100644 --- a/src/core/api/child_supervision_api.cpp +++ b/src/core/api/child_supervision_api.cpp @@ -42,6 +42,8 @@ using namespace ot; +#if OPENTHREAD_FTD + uint16_t otChildSupervisionGetInterval(otInstance *aInstance) { Instance &instance = *static_cast(aInstance); @@ -56,6 +58,8 @@ void otChildSupervisionSetInterval(otInstance *aInstance, uint16_t aInterval) instance.Get().SetSupervisionInterval(aInterval); } +#endif + uint16_t otChildSupervisionGetCheckTimeout(otInstance *aInstance) { Instance &instance = *static_cast(aInstance); diff --git a/src/core/common/instance.hpp b/src/core/common/instance.hpp index cbffac0e5..3ffd8c855 100644 --- a/src/core/common/instance.hpp +++ b/src/core/common/instance.hpp @@ -780,15 +780,18 @@ template <> inline Sntp::Client &Instance::Get(void) } #endif +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE +#if OPENTHREAD_FTD template <> inline Utils::ChildSupervisor &Instance::Get(void) { return mThreadNetif.mChildSupervisor; } - +#endif template <> inline Utils::SupervisionListener &Instance::Get(void) { return mThreadNetif.mSupervisionListener; } +#endif #if OPENTHREAD_CONFIG_PING_SENDER_ENABLE template <> inline Utils::PingSender &Instance::Get(void) diff --git a/src/core/thread/indirect_sender.cpp b/src/core/thread/indirect_sender.cpp index 393efd69e..ed77a4524 100644 --- a/src/core/thread/indirect_sender.cpp +++ b/src/core/thread/indirect_sender.cpp @@ -423,10 +423,12 @@ void IndirectSender::HandleSentFrameToChild(const Mac::TxFrame &aFrame, VerifyOrExit(mEnabled); +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE if (aError == kErrorNone) { Get().UpdateOnSend(aChild); } +#endif // A zero `nextOffset` indicates that the sent frame is an empty // frame generated by `PrepareFrameForChild()` when there was no diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index ca9d1cdbb..c1a649abf 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -407,12 +407,16 @@ void MeshForwarder::SetRxOnWhenIdle(bool aRxOnWhenIdle) if (aRxOnWhenIdle) { mDataPollSender.StopPolling(); +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE Get().Stop(); +#endif } else { mDataPollSender.StartPolling(); +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE Get().Start(); +#endif } } @@ -1111,7 +1115,9 @@ void MeshForwarder::HandleReceivedFrame(Mac::RxFrame &aFrame) payload = aFrame.GetPayload(); payloadLength = aFrame.GetPayloadLength(); +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE Get().UpdateOnReceive(macSource, linkInfo.IsLinkSecurityEnabled()); +#endif switch (aFrame.GetType()) { diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index ed3688f33..49077aba8 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -117,6 +117,7 @@ Error MeshForwarder::SendMessage(Message &aMessage) break; } +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE case Message::kTypeSupervision: { Child *child = Get().GetDestination(aMessage); @@ -124,6 +125,7 @@ Error MeshForwarder::SendMessage(Message &aMessage) mIndirectSender.AddMessageForSleepyChild(aMessage, *child); break; } +#endif default: aMessage.SetDirectTransmission(); diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 5ce526c99..3c522fbd7 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -139,8 +139,12 @@ ThreadNetif::ThreadNetif(Instance &aInstance) , mSrpServer(aInstance) #endif +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE +#if OPENTHREAD_FTD , mChildSupervisor(aInstance) +#endif , mSupervisionListener(aInstance) +#endif , mAnnounceBegin(aInstance) , mPanIdQuery(aInstance) , mEnergyScan(aInstance) diff --git a/src/core/thread/thread_netif.hpp b/src/core/thread/thread_netif.hpp index 694280283..0a39c9955 100644 --- a/src/core/thread/thread_netif.hpp +++ b/src/core/thread/thread_netif.hpp @@ -288,11 +288,15 @@ private: Srp::Server mSrpServer; #endif - Utils::ChildSupervisor mChildSupervisor; +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE +#if OPENTHREAD_FTD + Utils::ChildSupervisor mChildSupervisor; +#endif Utils::SupervisionListener mSupervisionListener; - AnnounceBeginServer mAnnounceBegin; - PanIdQueryServer mPanIdQuery; - EnergyScanServer mEnergyScan; +#endif + AnnounceBeginServer mAnnounceBegin; + PanIdQueryServer mPanIdQuery; + EnergyScanServer mEnergyScan; #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE TimeSync mTimeSync; diff --git a/src/core/utils/child_supervision.hpp b/src/core/utils/child_supervision.hpp index e11148f6f..4638e7488 100644 --- a/src/core/utils/child_supervision.hpp +++ b/src/core/utils/child_supervision.hpp @@ -85,7 +85,9 @@ namespace Utils { * */ -#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE && OPENTHREAD_FTD +#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE + +#if OPENTHREAD_FTD /** * This class implements a child supervisor. @@ -171,23 +173,7 @@ private: uint16_t mSupervisionInterval; }; -#else // #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE && OPENTHREAD_FTD - -class ChildSupervisor -{ -public: - explicit ChildSupervisor(otInstance &) {} - void Start(void) {} - void Stop(void) {} - void SetSupervisionInterval(uint16_t) {} - uint16_t GetSupervisionInterval(void) const { return 0; } - Child * GetDestination(const Message &) const { return nullptr; } - void UpdateOnSend(Child &) {} -}; - -#endif // #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE && OPENTHREAD_FTD - -#if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE +#endif // #if OPENTHREAD_FTD /** * This class implements a child supervision listener. @@ -262,19 +248,6 @@ private: TimerMilli mTimer; }; -#else // #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE - -class SupervisionListener : private NonCopyable -{ -public: - SupervisionListener(otInstance &) {} - void Start(void) {} - void Stop(void) {} - void SetTimeout(uint16_t) {} - uint16_t GetTimeout(void) const { return 0; } - void UpdateOnReceive(const Mac::Address &, bool) {} -}; - #endif // #if OPENTHREAD_CONFIG_CHILD_SUPERVISION_ENABLE /**