• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2020, The OpenThread Authors.
3  *  All rights reserved.
4  *
5  *  Redistribution and use in source and binary forms, with or without
6  *  modification, are permitted provided that the following conditions are met:
7  *  1. Redistributions of source code must retain the above copyright
8  *     notice, this list of conditions and the following disclaimer.
9  *  2. Redistributions in binary form must reproduce the above copyright
10  *     notice, this list of conditions and the following disclaimer in the
11  *     documentation and/or other materials provided with the distribution.
12  *  3. Neither the name of the copyright holder nor the
13  *     names of its contributors may be used to endorse or promote products
14  *     derived from this software without specific prior written permission.
15  *
16  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  *  POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 /**
30  * @file
31  * @brief
32  *  This file defines the API for server of the Service Registration Protocol (SRP).
33  */
34 
35 #ifndef OPENTHREAD_SRP_SERVER_H_
36 #define OPENTHREAD_SRP_SERVER_H_
37 
38 #include <stdint.h>
39 
40 #include <openthread/dns.h>
41 #include <openthread/instance.h>
42 #include <openthread/ip6.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @addtogroup api-srp
50  *
51  * @brief
52  *  This module includes functions of the Service Registration Protocol.
53  *
54  * @{
55  */
56 
57 /**
58  * This opaque type represents a SRP service host.
59  */
60 typedef struct otSrpServerHost otSrpServerHost;
61 
62 /**
63  * This opaque type represents a SRP service.
64  */
65 typedef struct otSrpServerService otSrpServerService;
66 
67 /**
68  * The ID of a SRP service update transaction on the SRP Server.
69  */
70 typedef uint32_t otSrpServerServiceUpdateId;
71 
72 /**
73  * Represents the state of the SRP server.
74  */
75 typedef enum
76 {
77     OT_SRP_SERVER_STATE_DISABLED = 0, ///< The SRP server is disabled.
78     OT_SRP_SERVER_STATE_RUNNING  = 1, ///< The SRP server is enabled and running.
79     OT_SRP_SERVER_STATE_STOPPED  = 2, ///< The SRP server is enabled but stopped.
80 } otSrpServerState;
81 
82 /**
83  * Represents the address mode used by the SRP server.
84  *
85  * Address mode specifies how the address and port number are determined by the SRP server and how this info is
86  * published in the Thread Network Data.
87  *
88  * @warning Using the `OT_SRP_SERVER_ADDRESS_MODE_UNICAST_FORCE_ADD` option will make the implementation
89  * non-compliant with the Thread specification. This option is intended for testing and specific use-cases.
90  * When selected, the SRP server, upon being enabled, will bypass the Network Data publisher and always add the
91  * "SRP/DNS unicast" entry directly to the Network Data, regardless of how many other similar entries are present.
92  */
93 typedef enum otSrpServerAddressMode
94 {
95     OT_SRP_SERVER_ADDRESS_MODE_UNICAST           = 0, ///< Unicast address mode. Use Network Data publisher.
96     OT_SRP_SERVER_ADDRESS_MODE_ANYCAST           = 1, ///< Anycast address mode. Use Network Data publisher
97     OT_SRP_SERVER_ADDRESS_MODE_UNICAST_FORCE_ADD = 2, ///< Unicast address mode. Immediately force add to Network Data.
98 } otSrpServerAddressMode;
99 
100 /**
101  * Includes SRP server TTL configurations.
102  */
103 typedef struct otSrpServerTtlConfig
104 {
105     uint32_t mMinTtl; ///< The minimum TTL in seconds.
106     uint32_t mMaxTtl; ///< The maximum TTL in seconds.
107 } otSrpServerTtlConfig;
108 
109 /**
110  * Includes SRP server LEASE and KEY-LEASE configurations.
111  */
112 typedef struct otSrpServerLeaseConfig
113 {
114     uint32_t mMinLease;    ///< The minimum LEASE interval in seconds.
115     uint32_t mMaxLease;    ///< The maximum LEASE interval in seconds.
116     uint32_t mMinKeyLease; ///< The minimum KEY-LEASE interval in seconds.
117     uint32_t mMaxKeyLease; ///< The maximum KEY-LEASE interval in seconds.
118 } otSrpServerLeaseConfig;
119 
120 /**
121  * Includes SRP server lease information of a host/service.
122  */
123 typedef struct otSrpServerLeaseInfo
124 {
125     uint32_t mLease;             ///< The lease time of a host/service in milliseconds.
126     uint32_t mKeyLease;          ///< The key lease time of a host/service in milliseconds.
127     uint32_t mRemainingLease;    ///< The remaining lease time of the host/service in milliseconds.
128     uint32_t mRemainingKeyLease; ///< The remaining key lease time of a host/service in milliseconds.
129 } otSrpServerLeaseInfo;
130 
131 /**
132  * Includes the statistics of SRP server responses.
133  */
134 typedef struct otSrpServerResponseCounters
135 {
136     uint32_t mSuccess;       ///< The number of successful responses.
137     uint32_t mServerFailure; ///< The number of server failure responses.
138     uint32_t mFormatError;   ///< The number of format error responses.
139     uint32_t mNameExists;    ///< The number of 'name exists' responses.
140     uint32_t mRefused;       ///< The number of refused responses.
141     uint32_t mOther;         ///< The number of other responses.
142 } otSrpServerResponseCounters;
143 
144 /**
145  * Returns the domain authorized to the SRP server.
146  *
147  * If the domain if not set by SetDomain, "default.service.arpa." will be returned.
148  * A trailing dot is always appended even if the domain is set without it.
149  *
150  * @param[in]  aInstance  A pointer to an OpenThread instance.
151  *
152  * @returns A pointer to the dot-joined domain string.
153  */
154 const char *otSrpServerGetDomain(otInstance *aInstance);
155 
156 /**
157  * Sets the domain on the SRP server.
158  *
159  * A trailing dot will be appended to @p aDomain if it is not already there.
160  * Should only be called before the SRP server is enabled.
161  *
162  * @param[in]  aInstance  A pointer to an OpenThread instance.
163  * @param[in]  aDomain    The domain to be set. MUST NOT be NULL.
164  *
165  * @retval  OT_ERROR_NONE           Successfully set the domain to @p aDomain.
166  * @retval  OT_ERROR_INVALID_STATE  The SRP server is already enabled and the Domain cannot be changed.
167  * @retval  OT_ERROR_INVALID_ARGS   The argument @p aDomain is not a valid DNS domain name.
168  * @retval  OT_ERROR_NO_BUFS        There is no memory to store content of @p aDomain.
169  */
170 otError otSrpServerSetDomain(otInstance *aInstance, const char *aDomain);
171 
172 /**
173  * Returns the state of the SRP server.
174  *
175  * @param[in]  aInstance  A pointer to an OpenThread instance.
176  *
177  * @returns The current state of the SRP server.
178  */
179 otSrpServerState otSrpServerGetState(otInstance *aInstance);
180 
181 /**
182  * Returns the port the SRP server is listening to.
183  *
184  * @param[in]  aInstance  A pointer to an OpenThread instance.
185  *
186  * @returns  The port of the SRP server. It returns 0 if the server is not running.
187  */
188 uint16_t otSrpServerGetPort(otInstance *aInstance);
189 
190 /**
191  * Returns the address mode being used by the SRP server.
192  *
193  * @param[in] aInstance  A pointer to an OpenThread instance.
194  *
195  * @returns The SRP server's address mode.
196  */
197 otSrpServerAddressMode otSrpServerGetAddressMode(otInstance *aInstance);
198 
199 /**
200  * Sets the address mode to be used by the SRP server.
201  *
202  * @param[in] aInstance  A pointer to an OpenThread instance.
203  * @param[in] aMode      The address mode to use.
204  *
205  * @retval OT_ERROR_NONE           Successfully set the address mode.
206  * @retval OT_ERROR_INVALID_STATE  The SRP server is enabled and the address mode cannot be changed.
207  */
208 otError otSrpServerSetAddressMode(otInstance *aInstance, otSrpServerAddressMode aMode);
209 
210 /**
211  * Returns the sequence number used with anycast address mode.
212  *
213  * The sequence number is included in "DNS/SRP Service Anycast Address" entry published in the Network Data.
214  *
215  * @param[in] aInstance  A pointer to an OpenThread instance.
216  *
217  * @returns The anycast sequence number.
218  */
219 uint8_t otSrpServerGetAnycastModeSequenceNumber(otInstance *aInstance);
220 
221 /**
222  * Sets the sequence number used with anycast address mode.
223  *
224  * @param[in] aInstance        A pointer to an OpenThread instance.
225  * @param[in] aSequenceNumber  The sequence number to use.
226  *
227  * @retval OT_ERROR_NONE            Successfully set the address mode.
228  * @retval OT_ERROR_INVALID_STATE   The SRP server is enabled and the sequence number cannot be changed.
229  */
230 otError otSrpServerSetAnycastModeSequenceNumber(otInstance *aInstance, uint8_t aSequenceNumber);
231 
232 /**
233  * Enables/disables the SRP server.
234  *
235  * On a Border Router, it is recommended to use `otSrpServerSetAutoEnableMode()` instead.
236  *
237  * @param[in]  aInstance  A pointer to an OpenThread instance.
238  * @param[in]  aEnabled   A boolean to enable/disable the SRP server.
239  */
240 void otSrpServerSetEnabled(otInstance *aInstance, bool aEnabled);
241 
242 /**
243  * Enables/disables the auto-enable mode on SRP server.
244  *
245  * Requires `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` feature.
246  *
247  * When this mode is enabled, the Border Routing Manager controls if/when to enable or disable the SRP server.
248  * SRP sever is auto-enabled if/when Border Routing is started and it is done with the initial prefix and route
249  * configurations (when the OMR and on-link prefixes are determined, advertised in emitted Router Advertisement message
250  * on infrastructure side and published in the Thread Network Data). The SRP server is auto-disabled if/when BR is
251  * stopped (e.g., if the infrastructure network interface is brought down or if BR gets detached).
252  *
253  * This mode can be disabled by a `otSrpServerSetAutoEnableMode()` call with @p aEnabled set to `false` or if the SRP
254  * server is explicitly enabled or disabled by a call to `otSrpServerSetEnabled()` function. Disabling auto-enable mode
255  * using `otSrpServerSetAutoEnableMode(false)` will not change the current state of SRP sever (e.g., if it is enabled
256  * it stays enabled).
257  *
258  * @param[in] aInstance   A pointer to an OpenThread instance.
259  * @param[in] aEnabled    A boolean to enable/disable the auto-enable mode.
260  */
261 void otSrpServerSetAutoEnableMode(otInstance *aInstance, bool aEnabled);
262 
263 /**
264  * Indicates whether the auto-enable mode is enabled or disabled.
265  *
266  * Requires `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` feature.
267  *
268  * @param[in]  aInstance  A pointer to an OpenThread instance.
269  *
270  * @retval TRUE   The auto-enable mode is enabled.
271  * @retval FALSE  The auto-enable mode is disabled.
272  */
273 bool otSrpServerIsAutoEnableMode(otInstance *aInstance);
274 
275 /**
276  * Enables the "Fast Start Mode" on the SRP server.
277  *
278  * Requires the `OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE` feature to be enabled.
279  *
280  * The Fast Start Mode is designed for scenarios where a device, often a mobile device, needs to act as a provisional
281  * SRP server (e.g., functioning as a temporary Border Router). The SRP server function is enabled only if no other
282  * Border Routers (BRs) are already providing the SRP service within the Thread network. A common use case is a mobile
283  * device joining a Thread network where it may be the first, or only, BR.  Importantly, Fast Start Mode allows the
284  * device to quickly start its SRP server functionality upon joining the network, allowing other Thread devices to
285  * quickly connect and register their services without the typical delays associated with standard Border Router
286  * initialization (and SRP server startup).
287  *
288  * When Fast Start Mode is enabled, the SRP server manages when to start or stop based on the presence of other BRs,
289  * following this process:
290  * - Upon initial attachment to the Thread network, the device immediately inspects the received Network Data for any
291  *   existing "SRP/DNS" entries. These entries indicate the presence of other active BRs providing SRP server service:
292  *   - If no "SRP/DNS" entries from other BRs are found, the device immediately enables its own SRP server. This
293  *     activation uses `OT_SRP_SERVER_ADDRESS_MODE_UNICAST_FORCE_ADD`, which bypasses the usual delay associated with
294  *     the standard Network Data publisher, directly adding its own "SRP/DNS unicast" entry to the Network Data.
295  *   - If "SRP/DNS" entries from other BRs are detected, the device will not enable its SRP server, deferring to the
296  *     existing ones.
297  * - After starting its SRP server in Fast Start Mode, the device continuously monitors the Network Data. If, at any
298  *   point, new "SRP/DNS" entries appear (indicating that another BR has become active), the device automatically
299  *   disables its own SRP server functionality, relinquishing the role to the newly available BR.
300  *
301  * The Fast Start Mode can be enabled when the device is in the detached or disabled state, the SRP server is currently
302  * disabled, and "auto-enable mode" is not in use (i.e., `otSrpServerIsAutoEnableMode()` returns `false`).
303  *
304  * After successfully enabling Fast Start Mode, it can be disabled either by a call to `otSrpServerSetEnabled()`,
305  * explicitly enabling or disabling the SRP server, or by a call to `otSrpServerSetAutoEnableMode()`, enabling or
306  * disabling the auto-enable mode. If the Fast Start Mode (while active) enables the SRP server, upon disabling
307  * Fast Start Mode (regardless of how it is done), the SRP server will also be stopped, and the use of the
308  * `OT_SRP_SERVER_ADDRESS_MODE_UNICAST_FORCE_ADD` address mode will be stopped, and the address mode will be
309  * automatically reverted back to its previous setting before Fast Start Mode was enabled.
310  *
311  * @param[in] aInstance             A pointer to the OpenThread instance.
312  *
313  * @retval OT_ERROR_NONE            Fast Start Mode was successfully enabled.
314  * @retval OT_ERROR_INVALID_STATE   Cannot enable Fast Start Mode (e.g., already attached or server already enabled).
315  */
316 otError otSrpServerEnableFastStartMode(otInstance *aInstance);
317 
318 /**
319  * Indicates whether the Fast Start Mode is enabled or disabled.
320  *
321  * Requires `OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE` feature to be enabled.
322  *
323  * @param[in]  aInstance     A pointer to an OpenThread instance.
324  *
325  * @retval TRUE   The fast-start mode is enabled.
326  * @retval FALSE  The fast-start mode is disabled.
327  */
328 bool otSrpServerIsFastStartModeEnabled(otInstance *aInstance);
329 
330 /**
331  * Returns SRP server TTL configuration.
332  *
333  * @param[in]   aInstance   A pointer to an OpenThread instance.
334  * @param[out]  aTtlConfig  A pointer to an `otSrpServerTtlConfig` instance.
335  */
336 void otSrpServerGetTtlConfig(otInstance *aInstance, otSrpServerTtlConfig *aTtlConfig);
337 
338 /**
339  * Sets SRP server TTL configuration.
340  *
341  * The granted TTL will always be no greater than the max lease interval configured via `otSrpServerSetLeaseConfig()`,
342  * regardless of the minimum and maximum TTL configuration.
343  *
344  * @param[in]  aInstance   A pointer to an OpenThread instance.
345  * @param[in]  aTtlConfig  A pointer to an `otSrpServerTtlConfig` instance.
346  *
347  * @retval  OT_ERROR_NONE          Successfully set the TTL configuration.
348  * @retval  OT_ERROR_INVALID_ARGS  The TTL configuration is not valid.
349  */
350 otError otSrpServerSetTtlConfig(otInstance *aInstance, const otSrpServerTtlConfig *aTtlConfig);
351 
352 /**
353  * Returns SRP server LEASE and KEY-LEASE configurations.
354  *
355  * @param[in]   aInstance     A pointer to an OpenThread instance.
356  * @param[out]  aLeaseConfig  A pointer to an `otSrpServerLeaseConfig` instance.
357  */
358 void otSrpServerGetLeaseConfig(otInstance *aInstance, otSrpServerLeaseConfig *aLeaseConfig);
359 
360 /**
361  * Sets SRP server LEASE and KEY-LEASE configurations.
362  *
363  * When a non-zero LEASE time is requested from a client, the granted value will be
364  * limited in range [aMinLease, aMaxLease]; and a non-zero KEY-LEASE will be granted
365  * in range [aMinKeyLease, aMaxKeyLease]. For zero LEASE or KEY-LEASE time, zero will
366  * be granted.
367  *
368  * @param[in]  aInstance     A pointer to an OpenThread instance.
369  * @param[in]  aLeaseConfig  A pointer to an `otSrpServerLeaseConfig` instance.
370  *
371  * @retval  OT_ERROR_NONE          Successfully set the LEASE and KEY-LEASE ranges.
372  * @retval  OT_ERROR_INVALID_ARGS  The LEASE or KEY-LEASE range is not valid.
373  */
374 otError otSrpServerSetLeaseConfig(otInstance *aInstance, const otSrpServerLeaseConfig *aLeaseConfig);
375 
376 /**
377  * Handles SRP service updates.
378  *
379  * Is called by the SRP server to notify that a SRP host and possibly SRP services
380  * are being updated. It is important that the SRP updates are not committed until the handler
381  * returns the result by calling otSrpServerHandleServiceUpdateResult or times out after @p aTimeout.
382  *
383  * A SRP service observer should always call otSrpServerHandleServiceUpdateResult with error code
384  * OT_ERROR_NONE immediately after receiving the update events.
385  *
386  * A more generic handler may perform validations on the SRP host/services and rejects the SRP updates
387  * if any validation fails. For example, an Advertising Proxy should advertise (or remove) the host and
388  * services on a multicast-capable link and returns specific error code if any failure occurs.
389  *
390  * @param[in]  aId       The service update transaction ID. This ID must be passed back with
391  *                       `otSrpServerHandleServiceUpdateResult`.
392  * @param[in]  aHost     A pointer to the otSrpServerHost object which contains the SRP updates. The
393  *                       handler should publish/un-publish the host and each service points to this
394  *                       host with below rules:
395  *                         1. If the host is not deleted (indicated by `otSrpServerHostIsDeleted`),
396  *                            then it should be published or updated with mDNS. Otherwise, the host
397  *                            should be un-published (remove AAAA RRs).
398  *                         2. For each service points to this host, it must be un-published if the host
399  *                            is to be un-published. Otherwise, the handler should publish or update the
400  *                            service when it is not deleted (indicated by `otSrpServerServiceIsDeleted`)
401  *                            and un-publish it when deleted.
402  * @param[in]  aTimeout  The maximum time in milliseconds for the handler to process the service event.
403  * @param[in]  aContext  A pointer to application-specific context.
404  *
405  * @sa otSrpServerSetServiceUpdateHandler
406  * @sa otSrpServerHandleServiceUpdateResult
407  */
408 typedef void (*otSrpServerServiceUpdateHandler)(otSrpServerServiceUpdateId aId,
409                                                 const otSrpServerHost     *aHost,
410                                                 uint32_t                   aTimeout,
411                                                 void                      *aContext);
412 
413 /**
414  * Sets the SRP service updates handler on SRP server.
415  *
416  * @param[in]  aInstance        A pointer to an OpenThread instance.
417  * @param[in]  aServiceHandler  A pointer to a service handler. Use NULL to remove the handler.
418  * @param[in]  aContext         A pointer to arbitrary context information.
419  *                              May be NULL if not used.
420  */
421 void otSrpServerSetServiceUpdateHandler(otInstance                     *aInstance,
422                                         otSrpServerServiceUpdateHandler aServiceHandler,
423                                         void                           *aContext);
424 
425 /**
426  * Reports the result of processing a SRP update to the SRP server.
427  *
428  * The Service Update Handler should call this function to return the result of its
429  * processing of a SRP update.
430  *
431  * @param[in]  aInstance  A pointer to an OpenThread instance.
432  * @param[in]  aId        The service update transaction ID. This should be the same ID
433  *                        provided via `otSrpServerServiceUpdateHandler`.
434  * @param[in]  aError     An error to be returned to the SRP server. Use OT_ERROR_DUPLICATED
435  *                        to represent DNS name conflicts.
436  */
437 void otSrpServerHandleServiceUpdateResult(otInstance *aInstance, otSrpServerServiceUpdateId aId, otError aError);
438 
439 /**
440  * Returns the next registered host on the SRP server.
441  *
442  * @param[in]  aInstance  A pointer to an OpenThread instance.
443  * @param[in]  aHost      A pointer to current host; use NULL to get the first host.
444  *
445  * @returns  A pointer to the registered host. NULL, if no more hosts can be found.
446  */
447 const otSrpServerHost *otSrpServerGetNextHost(otInstance *aInstance, const otSrpServerHost *aHost);
448 
449 /**
450  * Returns the response counters of the SRP server.
451  *
452  * @param[in]  aInstance  A pointer to an OpenThread instance.
453  *
454  * @returns  A pointer to the response counters of the SRP server.
455  */
456 const otSrpServerResponseCounters *otSrpServerGetResponseCounters(otInstance *aInstance);
457 
458 /**
459  * Tells if the SRP service host has been deleted.
460  *
461  * A SRP service host can be deleted but retains its name for future uses.
462  * In this case, the host instance is not removed from the SRP server/registry.
463  *
464  * @param[in]  aHost  A pointer to the SRP service host.
465  *
466  * @returns  TRUE if the host has been deleted, FALSE if not.
467  */
468 bool otSrpServerHostIsDeleted(const otSrpServerHost *aHost);
469 
470 /**
471  * Returns the full name of the host.
472  *
473  * @param[in]  aHost  A pointer to the SRP service host.
474  *
475  * @returns  A pointer to the null-terminated host name string.
476  */
477 const char *otSrpServerHostGetFullName(const otSrpServerHost *aHost);
478 
479 /**
480  * Indicates whether the host matches a given host name.
481  *
482  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
483  * be the same).
484  *
485  * @param[in]  aHost       A pointer to the SRP service host.
486  * @param[in]  aFullName   A full host name.
487  *
488  * @retval  TRUE   If host matches the host name.
489  * @retval  FALSE  If host does not match the host name.
490  */
491 bool otSrpServerHostMatchesFullName(const otSrpServerHost *aHost, const char *aFullName);
492 
493 /**
494  * Returns the addresses of given host.
495  *
496  * @param[in]   aHost          A pointer to the SRP service host.
497  * @param[out]  aAddressesNum  A pointer to where we should output the number of the addresses to.
498  *
499  * @returns  A pointer to the array of IPv6 Address.
500  */
501 const otIp6Address *otSrpServerHostGetAddresses(const otSrpServerHost *aHost, uint8_t *aAddressesNum);
502 
503 /**
504  * Returns the LEASE and KEY-LEASE information of a given host.
505  *
506  * @param[in]   aHost       A pointer to the SRP server host.
507  * @param[out]  aLeaseInfo  A pointer to where to output the LEASE and KEY-LEASE information.
508  */
509 void otSrpServerHostGetLeaseInfo(const otSrpServerHost *aHost, otSrpServerLeaseInfo *aLeaseInfo);
510 
511 /**
512  * Returns the next service of given host.
513  *
514  * @param[in]  aHost     A pointer to the SRP service host.
515  * @param[in]  aService  A pointer to current SRP service instance; use NULL to get the first service.
516  *
517  * @returns  A pointer to the next service or NULL if there is no more services.
518  */
519 const otSrpServerService *otSrpServerHostGetNextService(const otSrpServerHost    *aHost,
520                                                         const otSrpServerService *aService);
521 
522 /**
523  * Indicates whether or not the SRP service has been deleted.
524  *
525  * A SRP service can be deleted but retains its name for future uses.
526  * In this case, the service instance is not removed from the SRP server/registry.
527  * It is guaranteed that all services are deleted if the host is deleted.
528  *
529  * @param[in]  aService  A pointer to the SRP service.
530  *
531  * @returns  TRUE if the service has been deleted, FALSE if not.
532  */
533 bool otSrpServerServiceIsDeleted(const otSrpServerService *aService);
534 
535 /**
536  * Returns the full service instance name of the service.
537  *
538  * @param[in]  aService  A pointer to the SRP service.
539  *
540  * @returns  A pointer to the null-terminated service instance name string.
541  */
542 const char *otSrpServerServiceGetInstanceName(const otSrpServerService *aService);
543 
544 /**
545  * Indicates whether this service matches a given service instance name.
546  *
547  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
548  * be the same).
549  *
550  * @param[in]  aService       A pointer to the SRP service.
551  * @param[in]  aInstanceName  The service instance name.
552  *
553  * @retval  TRUE   If service matches the service instance name.
554  * @retval  FALSE  If service does not match the service instance name.
555  */
556 bool otSrpServerServiceMatchesInstanceName(const otSrpServerService *aService, const char *aInstanceName);
557 
558 /**
559  * Returns the service instance label (first label in instance name) of the service.
560  *
561  * @param[in]  aService  A pointer to the SRP service.
562  *
563  * @returns  A pointer to the null-terminated service instance label string..
564  */
565 const char *otSrpServerServiceGetInstanceLabel(const otSrpServerService *aService);
566 
567 /**
568  * Returns the full service name of the service.
569  *
570  * @param[in]  aService  A pointer to the SRP service.
571  *
572  * @returns  A pointer to the null-terminated service name string.
573  */
574 const char *otSrpServerServiceGetServiceName(const otSrpServerService *aService);
575 
576 /**
577  * Indicates whether this service matches a given service name.
578  *
579  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
580  * be the same).
581  *
582  * @param[in]  aService       A pointer to the SRP service.
583  * @param[in]  aServiceName  The service  name.
584  *
585  * @retval  TRUE   If service matches the service name.
586  * @retval  FALSE  If service does not match the service name.
587  */
588 bool otSrpServerServiceMatchesServiceName(const otSrpServerService *aService, const char *aServiceName);
589 
590 /**
591  * Gets the number of sub-types of the service.
592  *
593  * @param[in]  aService  A pointer to the SRP service.
594  *
595  * @returns The number of sub-types of @p aService.
596  */
597 uint16_t otSrpServerServiceGetNumberOfSubTypes(const otSrpServerService *aService);
598 
599 /**
600  * Gets the sub-type service name (full name) of the service at a given index
601  *
602  * The full service name for a sub-type service follows "<sub-label>._sub.<service-labels>.<domain>.".
603  *
604  * @param[in]  aService  A pointer to the SRP service.
605  * @param[in] aIndex     The index to get.
606  *
607  * @returns A pointer to sub-type service name at @p aIndex, or `NULL` if no sub-type at this index.
608  */
609 const char *otSrpServerServiceGetSubTypeServiceNameAt(const otSrpServerService *aService, uint16_t aIndex);
610 
611 /**
612  * Indicates whether or not the service has a given sub-type.
613  *
614  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
615  * be the same).
616  *
617  * @param[in] aService             A pointer to the SRP service.
618  * @param[in] aSubTypeServiceName  The sub-type service name (full name) to check.
619  *
620  * @retval TRUE   Service contains the sub-type @p aSubTypeServiceName.
621  * @retval FALSE  Service does not contain the sub-type @p aSubTypeServiceName.
622  */
623 bool otSrpServerServiceHasSubTypeServiceName(const otSrpServerService *aService, const char *aSubTypeServiceName);
624 
625 /**
626  * Parses a sub-type service name (full name) and extracts the sub-type label.
627  *
628  * The full service name for a sub-type service follows "<sub-label>._sub.<service-labels>.<domain>.".
629  *
630  * @param[in]  aSubTypeServiceName  A sub-type service name (full name).
631  * @param[out] aLabel               A pointer to a buffer to copy the extracted sub-type label.
632  * @param[in]  aLabelSize           Maximum size of @p aLabel buffer.
633  *
634  * @retval OT_ERROR_NONE          Name was successfully parsed and @p aLabel was updated.
635  * @retval OT_ERROR_NO_BUFS       The sub-type label could not fit in @p aLabel buffer (number of chars from label
636  *                                that could fit are copied in @p aLabel ensuring it is null-terminated).
637  * @retval OT_ERROR_INVALID_ARGS  @p aSubTypeServiceName is not a valid sub-type format.
638  */
639 otError otSrpServerParseSubTypeServiceName(const char *aSubTypeServiceName, char *aLabel, uint8_t aLabelSize);
640 
641 /**
642  * Returns the port of the service instance.
643  *
644  * @param[in]  aService  A pointer to the SRP service.
645  *
646  * @returns  The port of the service.
647  */
648 uint16_t otSrpServerServiceGetPort(const otSrpServerService *aService);
649 
650 /**
651  * Returns the weight of the service instance.
652  *
653  * @param[in]  aService  A pointer to the SRP service.
654  *
655  * @returns  The weight of the service.
656  */
657 uint16_t otSrpServerServiceGetWeight(const otSrpServerService *aService);
658 
659 /**
660  * Returns the priority of the service instance.
661  *
662  * @param[in]  aService  A pointer to the SRP service.
663  *
664  * @returns  The priority of the service.
665  */
666 uint16_t otSrpServerServiceGetPriority(const otSrpServerService *aService);
667 
668 /**
669  * Returns the TTL of the service instance.
670  *
671  * @param[in]  aService  A pointer to the SRP service.
672  *
673  * @returns  The TTL of the service instance..
674  */
675 uint32_t otSrpServerServiceGetTtl(const otSrpServerService *aService);
676 
677 /**
678  * Returns the TXT record data of the service instance.
679  *
680  * @param[in]  aService        A pointer to the SRP service.
681  * @param[out] aDataLength     A pointer to return the TXT record data length. MUST NOT be NULL.
682  *
683  * @returns A pointer to the buffer containing the TXT record data (the TXT data length is returned in @p aDataLength).
684  */
685 const uint8_t *otSrpServerServiceGetTxtData(const otSrpServerService *aService, uint16_t *aDataLength);
686 
687 /**
688  * Returns the host which the service instance reside on.
689  *
690  * @param[in]  aService  A pointer to the SRP service.
691  *
692  * @returns  A pointer to the host instance.
693  */
694 const otSrpServerHost *otSrpServerServiceGetHost(const otSrpServerService *aService);
695 
696 /**
697  * Returns the LEASE and KEY-LEASE information of a given service.
698  *
699  * @param[in]   aService    A pointer to the SRP server service.
700  * @param[out]  aLeaseInfo  A pointer to where to output the LEASE and KEY-LEASE information.
701  */
702 void otSrpServerServiceGetLeaseInfo(const otSrpServerService *aService, otSrpServerLeaseInfo *aLeaseInfo);
703 /**
704  * @}
705  */
706 
707 #ifdef __cplusplus
708 } // extern "C"
709 #endif
710 
711 #endif // OPENTHREAD_SRP_SERVER_H_
712