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 typedef enum otSrpServerAddressMode
89 {
90     OT_SRP_SERVER_ADDRESS_MODE_UNICAST = 0, ///< Unicast address mode.
91     OT_SRP_SERVER_ADDRESS_MODE_ANYCAST = 1, ///< Anycast address mode.
92 } otSrpServerAddressMode;
93 
94 /**
95  * Includes SRP server TTL configurations.
96  */
97 typedef struct otSrpServerTtlConfig
98 {
99     uint32_t mMinTtl; ///< The minimum TTL in seconds.
100     uint32_t mMaxTtl; ///< The maximum TTL in seconds.
101 } otSrpServerTtlConfig;
102 
103 /**
104  * Includes SRP server LEASE and KEY-LEASE configurations.
105  */
106 typedef struct otSrpServerLeaseConfig
107 {
108     uint32_t mMinLease;    ///< The minimum LEASE interval in seconds.
109     uint32_t mMaxLease;    ///< The maximum LEASE interval in seconds.
110     uint32_t mMinKeyLease; ///< The minimum KEY-LEASE interval in seconds.
111     uint32_t mMaxKeyLease; ///< The maximum KEY-LEASE interval in seconds.
112 } otSrpServerLeaseConfig;
113 
114 /**
115  * Includes SRP server lease information of a host/service.
116  */
117 typedef struct otSrpServerLeaseInfo
118 {
119     uint32_t mLease;             ///< The lease time of a host/service in milliseconds.
120     uint32_t mKeyLease;          ///< The key lease time of a host/service in milliseconds.
121     uint32_t mRemainingLease;    ///< The remaining lease time of the host/service in milliseconds.
122     uint32_t mRemainingKeyLease; ///< The remaining key lease time of a host/service in milliseconds.
123 } otSrpServerLeaseInfo;
124 
125 /**
126  * Includes the statistics of SRP server responses.
127  */
128 typedef struct otSrpServerResponseCounters
129 {
130     uint32_t mSuccess;       ///< The number of successful responses.
131     uint32_t mServerFailure; ///< The number of server failure responses.
132     uint32_t mFormatError;   ///< The number of format error responses.
133     uint32_t mNameExists;    ///< The number of 'name exists' responses.
134     uint32_t mRefused;       ///< The number of refused responses.
135     uint32_t mOther;         ///< The number of other responses.
136 } otSrpServerResponseCounters;
137 
138 /**
139  * Returns the domain authorized to the SRP server.
140  *
141  * If the domain if not set by SetDomain, "default.service.arpa." will be returned.
142  * A trailing dot is always appended even if the domain is set without it.
143  *
144  * @param[in]  aInstance  A pointer to an OpenThread instance.
145  *
146  * @returns A pointer to the dot-joined domain string.
147  */
148 const char *otSrpServerGetDomain(otInstance *aInstance);
149 
150 /**
151  * Sets the domain on the SRP server.
152  *
153  * A trailing dot will be appended to @p aDomain if it is not already there.
154  * Should only be called before the SRP server is enabled.
155  *
156  * @param[in]  aInstance  A pointer to an OpenThread instance.
157  * @param[in]  aDomain    The domain to be set. MUST NOT be NULL.
158  *
159  * @retval  OT_ERROR_NONE           Successfully set the domain to @p aDomain.
160  * @retval  OT_ERROR_INVALID_STATE  The SRP server is already enabled and the Domain cannot be changed.
161  * @retval  OT_ERROR_INVALID_ARGS   The argument @p aDomain is not a valid DNS domain name.
162  * @retval  OT_ERROR_NO_BUFS        There is no memory to store content of @p aDomain.
163  */
164 otError otSrpServerSetDomain(otInstance *aInstance, const char *aDomain);
165 
166 /**
167  * Returns the state of the SRP server.
168  *
169  * @param[in]  aInstance  A pointer to an OpenThread instance.
170  *
171  * @returns The current state of the SRP server.
172  */
173 otSrpServerState otSrpServerGetState(otInstance *aInstance);
174 
175 /**
176  * Returns the port the SRP server is listening to.
177  *
178  * @param[in]  aInstance  A pointer to an OpenThread instance.
179  *
180  * @returns  The port of the SRP server. It returns 0 if the server is not running.
181  */
182 uint16_t otSrpServerGetPort(otInstance *aInstance);
183 
184 /**
185  * Returns the address mode being used by the SRP server.
186  *
187  * @param[in] aInstance  A pointer to an OpenThread instance.
188  *
189  * @returns The SRP server's address mode.
190  */
191 otSrpServerAddressMode otSrpServerGetAddressMode(otInstance *aInstance);
192 
193 /**
194  * Sets the address mode to be used by the SRP server.
195  *
196  * @param[in] aInstance  A pointer to an OpenThread instance.
197  * @param[in] aMode      The address mode to use.
198  *
199  * @retval OT_ERROR_NONE           Successfully set the address mode.
200  * @retval OT_ERROR_INVALID_STATE  The SRP server is enabled and the address mode cannot be changed.
201  */
202 otError otSrpServerSetAddressMode(otInstance *aInstance, otSrpServerAddressMode aMode);
203 
204 /**
205  * Returns the sequence number used with anycast address mode.
206  *
207  * The sequence number is included in "DNS/SRP Service Anycast Address" entry published in the Network Data.
208  *
209  * @param[in] aInstance  A pointer to an OpenThread instance.
210  *
211  * @returns The anycast sequence number.
212  */
213 uint8_t otSrpServerGetAnycastModeSequenceNumber(otInstance *aInstance);
214 
215 /**
216  * Sets the sequence number used with anycast address mode.
217  *
218  * @param[in] aInstance        A pointer to an OpenThread instance.
219  * @param[in] aSequenceNumber  The sequence number to use.
220  *
221  * @retval OT_ERROR_NONE            Successfully set the address mode.
222  * @retval OT_ERROR_INVALID_STATE   The SRP server is enabled and the sequence number cannot be changed.
223  */
224 otError otSrpServerSetAnycastModeSequenceNumber(otInstance *aInstance, uint8_t aSequenceNumber);
225 
226 /**
227  * Enables/disables the SRP server.
228  *
229  * On a Border Router, it is recommended to use `otSrpServerSetAutoEnableMode()` instead.
230  *
231  * @param[in]  aInstance  A pointer to an OpenThread instance.
232  * @param[in]  aEnabled   A boolean to enable/disable the SRP server.
233  */
234 void otSrpServerSetEnabled(otInstance *aInstance, bool aEnabled);
235 
236 /**
237  * Enables/disables the auto-enable mode on SRP server.
238  *
239  * Requires `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` feature.
240  *
241  * When this mode is enabled, the Border Routing Manager controls if/when to enable or disable the SRP server.
242  * SRP sever is auto-enabled if/when Border Routing is started and it is done with the initial prefix and route
243  * configurations (when the OMR and on-link prefixes are determined, advertised in emitted Router Advertisement message
244  * on infrastructure side and published in the Thread Network Data). The SRP server is auto-disabled if/when BR is
245  * stopped (e.g., if the infrastructure network interface is brought down or if BR gets detached).
246  *
247  * This mode can be disabled by a `otSrpServerSetAutoEnableMode()` call with @p aEnabled set to `false` or if the SRP
248  * server is explicitly enabled or disabled by a call to `otSrpServerSetEnabled()` function. Disabling auto-enable mode
249  * using `otSrpServerSetAutoEnableMode(false)` will not change the current state of SRP sever (e.g., if it is enabled
250  * it stays enabled).
251  *
252  * @param[in] aInstance   A pointer to an OpenThread instance.
253  * @param[in] aEnabled    A boolean to enable/disable the auto-enable mode.
254  */
255 void otSrpServerSetAutoEnableMode(otInstance *aInstance, bool aEnabled);
256 
257 /**
258  * Indicates whether the auto-enable mode is enabled or disabled.
259  *
260  * Requires `OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE` feature.
261  *
262  * @param[in]  aInstance  A pointer to an OpenThread instance.
263  *
264  * @retval TRUE   The auto-enable mode is enabled.
265  * @retval FALSE  The auto-enable mode is disabled.
266  */
267 bool otSrpServerIsAutoEnableMode(otInstance *aInstance);
268 
269 /**
270  * Returns SRP server TTL configuration.
271  *
272  * @param[in]   aInstance   A pointer to an OpenThread instance.
273  * @param[out]  aTtlConfig  A pointer to an `otSrpServerTtlConfig` instance.
274  */
275 void otSrpServerGetTtlConfig(otInstance *aInstance, otSrpServerTtlConfig *aTtlConfig);
276 
277 /**
278  * Sets SRP server TTL configuration.
279  *
280  * The granted TTL will always be no greater than the max lease interval configured via `otSrpServerSetLeaseConfig()`,
281  * regardless of the minimum and maximum TTL configuration.
282  *
283  * @param[in]  aInstance   A pointer to an OpenThread instance.
284  * @param[in]  aTtlConfig  A pointer to an `otSrpServerTtlConfig` instance.
285  *
286  * @retval  OT_ERROR_NONE          Successfully set the TTL configuration.
287  * @retval  OT_ERROR_INVALID_ARGS  The TTL configuration is not valid.
288  */
289 otError otSrpServerSetTtlConfig(otInstance *aInstance, const otSrpServerTtlConfig *aTtlConfig);
290 
291 /**
292  * Returns SRP server LEASE and KEY-LEASE configurations.
293  *
294  * @param[in]   aInstance     A pointer to an OpenThread instance.
295  * @param[out]  aLeaseConfig  A pointer to an `otSrpServerLeaseConfig` instance.
296  */
297 void otSrpServerGetLeaseConfig(otInstance *aInstance, otSrpServerLeaseConfig *aLeaseConfig);
298 
299 /**
300  * Sets SRP server LEASE and KEY-LEASE configurations.
301  *
302  * When a non-zero LEASE time is requested from a client, the granted value will be
303  * limited in range [aMinLease, aMaxLease]; and a non-zero KEY-LEASE will be granted
304  * in range [aMinKeyLease, aMaxKeyLease]. For zero LEASE or KEY-LEASE time, zero will
305  * be granted.
306  *
307  * @param[in]  aInstance     A pointer to an OpenThread instance.
308  * @param[in]  aLeaseConfig  A pointer to an `otSrpServerLeaseConfig` instance.
309  *
310  * @retval  OT_ERROR_NONE          Successfully set the LEASE and KEY-LEASE ranges.
311  * @retval  OT_ERROR_INVALID_ARGS  The LEASE or KEY-LEASE range is not valid.
312  */
313 otError otSrpServerSetLeaseConfig(otInstance *aInstance, const otSrpServerLeaseConfig *aLeaseConfig);
314 
315 /**
316  * Handles SRP service updates.
317  *
318  * Is called by the SRP server to notify that a SRP host and possibly SRP services
319  * are being updated. It is important that the SRP updates are not committed until the handler
320  * returns the result by calling otSrpServerHandleServiceUpdateResult or times out after @p aTimeout.
321  *
322  * A SRP service observer should always call otSrpServerHandleServiceUpdateResult with error code
323  * OT_ERROR_NONE immediately after receiving the update events.
324  *
325  * A more generic handler may perform validations on the SRP host/services and rejects the SRP updates
326  * if any validation fails. For example, an Advertising Proxy should advertise (or remove) the host and
327  * services on a multicast-capable link and returns specific error code if any failure occurs.
328  *
329  * @param[in]  aId       The service update transaction ID. This ID must be passed back with
330  *                       `otSrpServerHandleServiceUpdateResult`.
331  * @param[in]  aHost     A pointer to the otSrpServerHost object which contains the SRP updates. The
332  *                       handler should publish/un-publish the host and each service points to this
333  *                       host with below rules:
334  *                         1. If the host is not deleted (indicated by `otSrpServerHostIsDeleted`),
335  *                            then it should be published or updated with mDNS. Otherwise, the host
336  *                            should be un-published (remove AAAA RRs).
337  *                         2. For each service points to this host, it must be un-published if the host
338  *                            is to be un-published. Otherwise, the handler should publish or update the
339  *                            service when it is not deleted (indicated by `otSrpServerServiceIsDeleted`)
340  *                            and un-publish it when deleted.
341  * @param[in]  aTimeout  The maximum time in milliseconds for the handler to process the service event.
342  * @param[in]  aContext  A pointer to application-specific context.
343  *
344  * @sa otSrpServerSetServiceUpdateHandler
345  * @sa otSrpServerHandleServiceUpdateResult
346  */
347 typedef void (*otSrpServerServiceUpdateHandler)(otSrpServerServiceUpdateId aId,
348                                                 const otSrpServerHost     *aHost,
349                                                 uint32_t                   aTimeout,
350                                                 void                      *aContext);
351 
352 /**
353  * Sets the SRP service updates handler on SRP server.
354  *
355  * @param[in]  aInstance        A pointer to an OpenThread instance.
356  * @param[in]  aServiceHandler  A pointer to a service handler. Use NULL to remove the handler.
357  * @param[in]  aContext         A pointer to arbitrary context information.
358  *                              May be NULL if not used.
359  */
360 void otSrpServerSetServiceUpdateHandler(otInstance                     *aInstance,
361                                         otSrpServerServiceUpdateHandler aServiceHandler,
362                                         void                           *aContext);
363 
364 /**
365  * Reports the result of processing a SRP update to the SRP server.
366  *
367  * The Service Update Handler should call this function to return the result of its
368  * processing of a SRP update.
369  *
370  * @param[in]  aInstance  A pointer to an OpenThread instance.
371  * @param[in]  aId        The service update transaction ID. This should be the same ID
372  *                        provided via `otSrpServerServiceUpdateHandler`.
373  * @param[in]  aError     An error to be returned to the SRP server. Use OT_ERROR_DUPLICATED
374  *                        to represent DNS name conflicts.
375  */
376 void otSrpServerHandleServiceUpdateResult(otInstance *aInstance, otSrpServerServiceUpdateId aId, otError aError);
377 
378 /**
379  * Returns the next registered host on the SRP server.
380  *
381  * @param[in]  aInstance  A pointer to an OpenThread instance.
382  * @param[in]  aHost      A pointer to current host; use NULL to get the first host.
383  *
384  * @returns  A pointer to the registered host. NULL, if no more hosts can be found.
385  */
386 const otSrpServerHost *otSrpServerGetNextHost(otInstance *aInstance, const otSrpServerHost *aHost);
387 
388 /**
389  * Returns the response counters of the SRP server.
390  *
391  * @param[in]  aInstance  A pointer to an OpenThread instance.
392  *
393  * @returns  A pointer to the response counters of the SRP server.
394  */
395 const otSrpServerResponseCounters *otSrpServerGetResponseCounters(otInstance *aInstance);
396 
397 /**
398  * Tells if the SRP service host has been deleted.
399  *
400  * A SRP service host can be deleted but retains its name for future uses.
401  * In this case, the host instance is not removed from the SRP server/registry.
402  *
403  * @param[in]  aHost  A pointer to the SRP service host.
404  *
405  * @returns  TRUE if the host has been deleted, FALSE if not.
406  */
407 bool otSrpServerHostIsDeleted(const otSrpServerHost *aHost);
408 
409 /**
410  * Returns the full name of the host.
411  *
412  * @param[in]  aHost  A pointer to the SRP service host.
413  *
414  * @returns  A pointer to the null-terminated host name string.
415  */
416 const char *otSrpServerHostGetFullName(const otSrpServerHost *aHost);
417 
418 /**
419  * Indicates whether the host matches a given host name.
420  *
421  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
422  * be the same).
423  *
424  * @param[in]  aHost       A pointer to the SRP service host.
425  * @param[in]  aFullName   A full host name.
426  *
427  * @retval  TRUE   If host matches the host name.
428  * @retval  FALSE  If host does not match the host name.
429  */
430 bool otSrpServerHostMatchesFullName(const otSrpServerHost *aHost, const char *aFullName);
431 
432 /**
433  * Returns the addresses of given host.
434  *
435  * @param[in]   aHost          A pointer to the SRP service host.
436  * @param[out]  aAddressesNum  A pointer to where we should output the number of the addresses to.
437  *
438  * @returns  A pointer to the array of IPv6 Address.
439  */
440 const otIp6Address *otSrpServerHostGetAddresses(const otSrpServerHost *aHost, uint8_t *aAddressesNum);
441 
442 /**
443  * Returns the LEASE and KEY-LEASE information of a given host.
444  *
445  * @param[in]   aHost       A pointer to the SRP server host.
446  * @param[out]  aLeaseInfo  A pointer to where to output the LEASE and KEY-LEASE information.
447  */
448 void otSrpServerHostGetLeaseInfo(const otSrpServerHost *aHost, otSrpServerLeaseInfo *aLeaseInfo);
449 
450 /**
451  * Returns the next service of given host.
452  *
453  * @param[in]  aHost     A pointer to the SRP service host.
454  * @param[in]  aService  A pointer to current SRP service instance; use NULL to get the first service.
455  *
456  * @returns  A pointer to the next service or NULL if there is no more services.
457  */
458 const otSrpServerService *otSrpServerHostGetNextService(const otSrpServerHost    *aHost,
459                                                         const otSrpServerService *aService);
460 
461 /**
462  * Indicates whether or not the SRP service has been deleted.
463  *
464  * A SRP service can be deleted but retains its name for future uses.
465  * In this case, the service instance is not removed from the SRP server/registry.
466  * It is guaranteed that all services are deleted if the host is deleted.
467  *
468  * @param[in]  aService  A pointer to the SRP service.
469  *
470  * @returns  TRUE if the service has been deleted, FALSE if not.
471  */
472 bool otSrpServerServiceIsDeleted(const otSrpServerService *aService);
473 
474 /**
475  * Returns the full service instance name of the service.
476  *
477  * @param[in]  aService  A pointer to the SRP service.
478  *
479  * @returns  A pointer to the null-terminated service instance name string.
480  */
481 const char *otSrpServerServiceGetInstanceName(const otSrpServerService *aService);
482 
483 /**
484  * Indicates whether this service matches a given service instance name.
485  *
486  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
487  * be the same).
488  *
489  * @param[in]  aService       A pointer to the SRP service.
490  * @param[in]  aInstanceName  The service instance name.
491  *
492  * @retval  TRUE   If service matches the service instance name.
493  * @retval  FALSE  If service does not match the service instance name.
494  */
495 bool otSrpServerServiceMatchesInstanceName(const otSrpServerService *aService, const char *aInstanceName);
496 
497 /**
498  * Returns the service instance label (first label in instance name) of the service.
499  *
500  * @param[in]  aService  A pointer to the SRP service.
501  *
502  * @returns  A pointer to the null-terminated service instance label string..
503  */
504 const char *otSrpServerServiceGetInstanceLabel(const otSrpServerService *aService);
505 
506 /**
507  * Returns the full service name of the service.
508  *
509  * @param[in]  aService  A pointer to the SRP service.
510  *
511  * @returns  A pointer to the null-terminated service name string.
512  */
513 const char *otSrpServerServiceGetServiceName(const otSrpServerService *aService);
514 
515 /**
516  * Indicates whether this service matches a given service name.
517  *
518  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
519  * be the same).
520  *
521  * @param[in]  aService       A pointer to the SRP service.
522  * @param[in]  aServiceName  The service  name.
523  *
524  * @retval  TRUE   If service matches the service name.
525  * @retval  FALSE  If service does not match the service name.
526  */
527 bool otSrpServerServiceMatchesServiceName(const otSrpServerService *aService, const char *aServiceName);
528 
529 /**
530  * Gets the number of sub-types of the service.
531  *
532  * @param[in]  aService  A pointer to the SRP service.
533  *
534  * @returns The number of sub-types of @p aService.
535  */
536 uint16_t otSrpServerServiceGetNumberOfSubTypes(const otSrpServerService *aService);
537 
538 /**
539  * Gets the sub-type service name (full name) of the service at a given index
540  *
541  * The full service name for a sub-type service follows "<sub-label>._sub.<service-labels>.<domain>.".
542  *
543  * @param[in]  aService  A pointer to the SRP service.
544  * @param[in] aIndex     The index to get.
545  *
546  * @returns A pointer to sub-type service name at @p aIndex, or `NULL` if no sub-type at this index.
547  */
548 const char *otSrpServerServiceGetSubTypeServiceNameAt(const otSrpServerService *aService, uint16_t aIndex);
549 
550 /**
551  * Indicates whether or not the service has a given sub-type.
552  *
553  * DNS name matches are performed using a case-insensitive string comparison (i.e., "Abc" and "aBc" are considered to
554  * be the same).
555  *
556  * @param[in] aService             A pointer to the SRP service.
557  * @param[in] aSubTypeServiceName  The sub-type service name (full name) to check.
558  *
559  * @retval TRUE   Service contains the sub-type @p aSubTypeServiceName.
560  * @retval FALSE  Service does not contain the sub-type @p aSubTypeServiceName.
561  */
562 bool otSrpServerServiceHasSubTypeServiceName(const otSrpServerService *aService, const char *aSubTypeServiceName);
563 
564 /**
565  * Parses a sub-type service name (full name) and extracts the sub-type label.
566  *
567  * The full service name for a sub-type service follows "<sub-label>._sub.<service-labels>.<domain>.".
568  *
569  * @param[in]  aSubTypeServiceName  A sub-type service name (full name).
570  * @param[out] aLabel               A pointer to a buffer to copy the extracted sub-type label.
571  * @param[in]  aLabelSize           Maximum size of @p aLabel buffer.
572  *
573  * @retval OT_ERROR_NONE          Name was successfully parsed and @p aLabel was updated.
574  * @retval OT_ERROR_NO_BUFS       The sub-type label could not fit in @p aLabel buffer (number of chars from label
575  *                                that could fit are copied in @p aLabel ensuring it is null-terminated).
576  * @retval OT_ERROR_INVALID_ARGS  @p aSubTypeServiceName is not a valid sub-type format.
577  */
578 otError otSrpServerParseSubTypeServiceName(const char *aSubTypeServiceName, char *aLabel, uint8_t aLabelSize);
579 
580 /**
581  * Returns the port of the service instance.
582  *
583  * @param[in]  aService  A pointer to the SRP service.
584  *
585  * @returns  The port of the service.
586  */
587 uint16_t otSrpServerServiceGetPort(const otSrpServerService *aService);
588 
589 /**
590  * Returns the weight of the service instance.
591  *
592  * @param[in]  aService  A pointer to the SRP service.
593  *
594  * @returns  The weight of the service.
595  */
596 uint16_t otSrpServerServiceGetWeight(const otSrpServerService *aService);
597 
598 /**
599  * Returns the priority of the service instance.
600  *
601  * @param[in]  aService  A pointer to the SRP service.
602  *
603  * @returns  The priority of the service.
604  */
605 uint16_t otSrpServerServiceGetPriority(const otSrpServerService *aService);
606 
607 /**
608  * Returns the TTL of the service instance.
609  *
610  * @param[in]  aService  A pointer to the SRP service.
611  *
612  * @returns  The TTL of the service instance..
613  */
614 uint32_t otSrpServerServiceGetTtl(const otSrpServerService *aService);
615 
616 /**
617  * Returns the TXT record data of the service instance.
618  *
619  * @param[in]  aService        A pointer to the SRP service.
620  * @param[out] aDataLength     A pointer to return the TXT record data length. MUST NOT be NULL.
621  *
622  * @returns A pointer to the buffer containing the TXT record data (the TXT data length is returned in @p aDataLength).
623  */
624 const uint8_t *otSrpServerServiceGetTxtData(const otSrpServerService *aService, uint16_t *aDataLength);
625 
626 /**
627  * Returns the host which the service instance reside on.
628  *
629  * @param[in]  aService  A pointer to the SRP service.
630  *
631  * @returns  A pointer to the host instance.
632  */
633 const otSrpServerHost *otSrpServerServiceGetHost(const otSrpServerService *aService);
634 
635 /**
636  * Returns the LEASE and KEY-LEASE information of a given service.
637  *
638  * @param[in]   aService    A pointer to the SRP server service.
639  * @param[out]  aLeaseInfo  A pointer to where to output the LEASE and KEY-LEASE information.
640  */
641 void otSrpServerServiceGetLeaseInfo(const otSrpServerService *aService, otSrpServerLeaseInfo *aLeaseInfo);
642 /**
643  * @}
644  */
645 
646 #ifdef __cplusplus
647 } // extern "C"
648 #endif
649 
650 #endif // OPENTHREAD_SRP_SERVER_H_
651