Skip to content

Commit 293b41c

Browse files
authored
[border-agent] manage mDNS MeshCoP service registrations (openthread#11455)
This commit updates `BorderAgent` modules to directly manage the registration of mDNS MeshCoP services. Previously, this was the responsibility of the platform or higher-level code. This behavior is enabled using `OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE` configuration option. When enabled, the `BorderAgent` module itself will register the `_meshcop._udp` service name with properly formatted TXT data. As the state changes, the service registration is updated accordingly. If the ephemeral key feature is enabled and used, the `BorderAgent` will also manage the registration of the `_meshcop-e._udp` service. The implementation allows the service instance name to be configured in different ways. The Thread specification recommends using a user-friendly name, such as "<VendorName> <ProductName>". The name can be set using a newly added configuration option, or alternatively, using a newly added public API for projects where the name needs to be set at run-time after device initialization. This commit also updates `test_border_agent`, validating all the newly added behaviors related to MeshCoP service registrations.
1 parent 65098eb commit 293b41c

15 files changed

Lines changed: 632 additions & 8 deletions

File tree

etc/cmake/options.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ ot_option(OT_BLE_TCAT OPENTHREAD_CONFIG_BLE_TCAT_ENABLE "Ble based thread commis
176176
ot_option(OT_BORDER_AGENT OPENTHREAD_CONFIG_BORDER_AGENT_ENABLE "border agent")
177177
ot_option(OT_BORDER_AGENT_EPSKC OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE "border agent ephemeral PSKc")
178178
ot_option(OT_BORDER_AGENT_ID OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE "create and save border agent ID")
179+
ot_option(OT_BORDER_AGENT_MESHCOP_SERVICE OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE "border agent meshcop service")
179180
ot_option(OT_BORDER_ROUTER OPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE "border router")
180181
ot_option(OT_BORDER_ROUTING OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE "border routing")
181182
ot_option(OT_BORDER_ROUTING_DHCP6_PD OPENTHREAD_CONFIG_BORDER_ROUTING_DHCP6_PD_ENABLE "dhcpv6 pd support in border routing")
@@ -332,6 +333,7 @@ ot_multi_option(OT_LOG_OUTPUT OT_LOG_OUTPUT_VALUES OPENTHREAD_CONFIG_LOG_OUTPUT
332333
ot_string_option(OT_VENDOR_NAME OPENTHREAD_CONFIG_NET_DIAG_VENDOR_NAME "set the vendor name config")
333334
ot_string_option(OT_VENDOR_MODEL OPENTHREAD_CONFIG_NET_DIAG_VENDOR_MODEL "set the vendor model config")
334335
ot_string_option(OT_VENDOR_SW_VERSION OPENTHREAD_CONFIG_NET_DIAG_VENDOR_SW_VERSION "set the vendor sw version config")
336+
ot_string_option(OT_BORDER_AGENT_SERVICE_NAME OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME "set the border agent service base name")
335337

336338
set(OT_POWER_SUPPLY_VALUES "BATTERY" "EXTERNAL" "EXTERNAL_STABLE" "EXTERNAL_UNSTABLE")
337339
ot_multi_option(OT_POWER_SUPPLY OT_POWER_SUPPLY_VALUES OPENTHREAD_CONFIG_DEVICE_POWER_SUPPLY OT_POWER_SUPPLY_ "set the device power supply config")

include/openthread/border_agent.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#ifndef OPENTHREAD_BORDER_AGENT_H_
3636
#define OPENTHREAD_BORDER_AGENT_H_
3737

38+
#include <openthread/dns.h>
3839
#include <openthread/instance.h>
3940
#include <openthread/ip6.h>
4041

@@ -242,6 +243,41 @@ void otBorderAgentSetMeshCoPServiceChangedCallback(otInstance
242243
*/
243244
otError otBorderAgentGetMeshCoPServiceTxtData(otInstance *aInstance, otBorderAgentMeshCoPServiceTxtData *aTxtData);
244245

246+
/**
247+
* Maximum string length of base name used in `otBorderAgentSetMeshCoPServiceBaseName()`.
248+
*
249+
* The full DNS label is constructed by appending the Extended Address of the device (as 16-character hex digits) to
250+
* the given base name.
251+
*/
252+
#define OT_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME_MAX_LENGTH (OT_DNS_MAX_LABEL_SIZE - 17)
253+
254+
/**
255+
* Sets the base name to construct the service instance name used when advertising the mDNS `_meshcop._udp` service by
256+
* the Border Agent.
257+
*
258+
* Requires the `OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE` feature.
259+
*
260+
* The name can also be configured using the `OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME` configuration
261+
* option (which is the recommended way to specify this name). This API is provided for projects where the name needs
262+
* to be set after device initialization and at run-time.
263+
*
264+
* Per the Thread specification, the service instance should be a user-friendly name identifying the device model or
265+
* product. A recommended format is "<VendorName> <ProductName>".
266+
*
267+
* To construct the full name and ensure name uniqueness, the OpenThread Border Agent module will append the Extended
268+
* Address of the device (as 16-character hex digits) to the given base name.
269+
*
270+
* Note that the same name will be used for the ephemeral key service `_meshcop-e._udp` when the ephemeral key feature
271+
* is enabled and used.
272+
*
273+
* @param[in] aInstance The OpenThread instance.
274+
* @param[in] aBaseName The base name to use (MUST not be NULL).
275+
*
276+
* @retval OT_ERROR_NONE The name was set successfully.
277+
* @retval OT_ERROR_INVALID_ARGS The name is too long or invalid.
278+
*/
279+
otError otBorderAgentSetMeshCoPServiceBaseName(otInstance *aInstance, const char *aBaseName);
280+
245281
/**
246282
* Gets the randomly generated Border Agent ID.
247283
*

include/openthread/instance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ extern "C" {
5252
*
5353
* @note This number versions both OpenThread platform and user APIs.
5454
*/
55-
#define OPENTHREAD_API_VERSION (505)
55+
#define OPENTHREAD_API_VERSION (506)
5656

5757
/**
5858
* @addtogroup api-instance

src/cli/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,21 @@ Active
410410
Done
411411
```
412412

413+
### ba servicebasename \<name\>
414+
415+
Sets the base name to construct the service instance name used when advertising the mDNS `_meshcop._udp` service by the Border Agent.
416+
417+
Requires the `OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE` feature.
418+
419+
The name can also be configured using the `OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME` configuration option (which is the recommended way to specify this name). This CLI command (and its corresponding API) is provided for projects where the name needs to be set after device initialization and at run-time.
420+
421+
Per the Thread specification, the service instance should be a user-friendly name identifying the device model or product. A recommended format is "<VendorName> <ProductName>". To construct the full name and ensure name uniqueness, the OpenThread Border Agent module will append the Extended Address of the device (as 16-character hex digits) to the given base name. Note that the same name will be used for the ephemeral key service `_meshcop-e._udp` when the ephemeral key feature is enabled and used.
422+
423+
```bash
424+
ba servicebasename OpenThreadBorderAgent
425+
Done
426+
```
427+
413428
### ba sessions
414429

415430
Prints the list of Border Agent's sessions. Information per session:

src/cli/cli.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,22 @@ template <> otError Interpreter::Process<Cmd("ba")>(Arg aArgs[])
502502
OutputLine("%s", otBorderAgentIsActive(GetInstancePtr()) ? "Active" : "Inactive");
503503
}
504504
}
505+
#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE
506+
/**
507+
* @cli ba servicebasename
508+
* @code
509+
* ba servicebasename OpenThreadBorderAgent
510+
* Done
511+
* @endcode
512+
* @par api_copy
513+
* #otBorderAgentSetMeshCoPServiceBaseName
514+
*/
515+
else if (aArgs[0] == "servicebasename")
516+
{
517+
VerifyOrExit(!aArgs[1].IsEmpty() && aArgs[2].IsEmpty(), error = OT_ERROR_INVALID_ARGS);
518+
error = otBorderAgentSetMeshCoPServiceBaseName(GetInstancePtr(), aArgs[1].GetCString());
519+
}
520+
#endif
505521
/**
506522
* @cli ba sessions
507523
* @code

src/core/api/border_agent_api.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ bool otBorderAgentIsActive(otInstance *aInstance)
5757
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().IsRunning();
5858
}
5959

60+
#if OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE
61+
otError otBorderAgentSetMeshCoPServiceBaseName(otInstance *aInstance, const char *aBaseName)
62+
{
63+
AssertPointerIsNotNull(aBaseName);
64+
65+
return AsCoreType(aInstance).Get<MeshCoP::BorderAgent>().SetServiceBaseName(aBaseName);
66+
}
67+
#endif
68+
6069
#if OPENTHREAD_CONFIG_BORDER_AGENT_ID_ENABLE
6170
otError otBorderAgentGetId(otInstance *aInstance, otBorderAgentId *aId)
6271
{

src/core/config/border_agent.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,38 @@
8989
OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE
9090
#endif
9191

92+
/**
93+
* @def OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE
94+
*
95+
* Define to 1 to enable Border Agent to manage registering/updating of the mDNS MeshCoP service(s) on the
96+
* infrastructure link
97+
*
98+
* This includes the ephemeral key service when the `OPENTHREAD_CONFIG_BORDER_AGENT_EPHEMERAL_KEY_ENABLE` is enabled.
99+
*/
100+
#ifndef OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE
101+
#define OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE \
102+
(OPENTHREAD_CONFIG_PLATFORM_DNSSD_ENABLE || OPENTHREAD_CONFIG_MULTICAST_DNS_ENABLE)
103+
#endif
104+
105+
/**
106+
* @def OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME
107+
*
108+
* Specifies the base name to construct the service instance name used when advertising the mDNS `_meshcop._udp`
109+
* service by the Border Agent.
110+
*
111+
* Applicable when the `OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_ENABLE` feature is enabled.
112+
*
113+
* The name can also be configured using the `otBorderAgentSetMeshCoPServiceBaseName()` API at run-time.
114+
*
115+
* Per the Thread specification, the service instance should be a user-friendly name identifying the device model or
116+
* product. A recommended format is "<VendorName> <ProductName>".
117+
*
118+
* The name MUST have a length less than or equal to `OT_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME_MAX_LENGTH` (47 chars).
119+
*/
120+
#ifndef OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME
121+
#define OPENTHREAD_CONFIG_BORDER_AGENT_MESHCOP_SERVICE_BASE_NAME "OpenThread BR (unspecified vendor) "
122+
#endif
123+
92124
/**
93125
* @}
94126
*/

0 commit comments

Comments
 (0)