From 27e56b301b1f2b69a49e401f101f980dea20d057 Mon Sep 17 00:00:00 2001 From: Yang Sun Date: Tue, 14 Feb 2023 13:30:39 +0800 Subject: [PATCH] [trel] add `otTrelSetEnabled` API (#8731) --- include/openthread/instance.h | 2 +- include/openthread/trel.h | 33 ++++++++++++++++++++----------- src/cli/cli.cpp | 9 +-------- src/core/api/trel_api.cpp | 5 +++++ src/core/radio/trel_interface.cpp | 12 +++++++++++ src/core/radio/trel_interface.hpp | 7 +++++++ 6 files changed, 47 insertions(+), 21 deletions(-) diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 5789685a7..85fb2d8e5 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -53,7 +53,7 @@ extern "C" { * @note This number versions both OpenThread platform and user APIs. * */ -#define OPENTHREAD_API_VERSION (286) +#define OPENTHREAD_API_VERSION (287) /** * @addtogroup api-instance diff --git a/include/openthread/trel.h b/include/openthread/trel.h index e2dcbdbe4..6e26e83c7 100644 --- a/include/openthread/trel.h +++ b/include/openthread/trel.h @@ -73,6 +73,25 @@ typedef struct otTrelPeer */ typedef uint16_t otTrelPeerIterator; +/** + * Enables or disables TREL operation. + * + * When @p aEnable is true, this function initiates an ongoing DNS-SD browse on the service name "_trel._udp" within the + * local browsing domain to discover other devices supporting TREL. Device also registers a new service to be advertised + * using DNS-SD, with the service name is "_trel._udp" indicating its support for TREL. Device is then ready to receive + * TREL messages from peers. + * + * When @p aEnable is false, this function stops the DNS-SD browse on the service name "_trel._udp", stops advertising + * TREL DNS-SD service, and clears the TREL peer table. + * + * @note By default the OpenThread stack enables the TREL operation on start. + * + * @param[in] aInstance A pointer to an OpenThread instance. + * @param[in] aEnable A boolean to enable/disable the TREL operation. + * + */ +void otTrelSetEnabled(otInstance *aInstance, bool aEnable); + /** * This function enables TREL operation. * @@ -89,23 +108,13 @@ typedef uint16_t otTrelPeerIterator; void otTrelEnable(otInstance *aInstance); /** - * This function disables TREL operation. - * - * This function stops the DNS-SD browse on the service name "_trel._udp", stops advertising TREL DNS-SD service, and - * clears the TREL peer table. - * - * @param[in] aInstance The OpenThread instance. + * This function is deprecated. * */ void otTrelDisable(otInstance *aInstance); /** - * This function indicates whether the TREL operation is enabled. - * - * @param[in] aInstance The OpenThread instance. - * - * @retval TRUE if the TREL operation is enabled. - * @retval FALSE if the TREL operation is disabled. + * This function is deprecated. * */ bool otTrelIsEnabled(otInstance *aInstance); diff --git a/src/cli/cli.cpp b/src/cli/cli.cpp index e45c1ac5f..bebce24e0 100644 --- a/src/cli/cli.cpp +++ b/src/cli/cli.cpp @@ -7135,14 +7135,7 @@ template <> otError Interpreter::Process(Arg aArgs[]) } else if (ParseEnableOrDisable(aArgs[0], enable) == OT_ERROR_NONE) { - if (enable) - { - otTrelEnable(GetInstancePtr()); - } - else - { - otTrelDisable(GetInstancePtr()); - } + otTrelSetEnabled(GetInstancePtr(), enable); } else if (aArgs[0] == "filter") { diff --git a/src/core/api/trel_api.cpp b/src/core/api/trel_api.cpp index 717d58c3a..f385dc232 100644 --- a/src/core/api/trel_api.cpp +++ b/src/core/api/trel_api.cpp @@ -43,6 +43,11 @@ using namespace ot; +void otTrelSetEnabled(otInstance *aInstance, bool aEnable) +{ + AsCoreType(aInstance).Get().SetEnabled(aEnable); +} + void otTrelEnable(otInstance *aInstance) { AsCoreType(aInstance).Get().Enable(); } void otTrelDisable(otInstance *aInstance) { AsCoreType(aInstance).Get().Disable(); } diff --git a/src/core/radio/trel_interface.cpp b/src/core/radio/trel_interface.cpp index 89bf38b7c..a1d3ee6b9 100644 --- a/src/core/radio/trel_interface.cpp +++ b/src/core/radio/trel_interface.cpp @@ -76,6 +76,18 @@ void Interface::Init(void) } } +void Interface::SetEnabled(bool aEnable) +{ + if (aEnable) + { + Enable(); + } + else + { + Disable(); + } +} + void Interface::Enable(void) { VerifyOrExit(!mEnabled); diff --git a/src/core/radio/trel_interface.hpp b/src/core/radio/trel_interface.hpp index f68c8ffb2..2181915ec 100644 --- a/src/core/radio/trel_interface.hpp +++ b/src/core/radio/trel_interface.hpp @@ -151,6 +151,13 @@ public: */ typedef otTrelPeerIterator PeerIterator; + /** + * This method enables or disables the TREL interface. + * + * @param[in] aEnable A boolean to enable/disable the TREL interface. + */ + void SetEnabled(bool aEnable); + /** * This method enables the TREL interface. *