• 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 OpenThread SRP (Service Registration Protocol) client APIs.
33  */
34 
35 #ifndef OPENTHREAD_SRP_CLIENT_H_
36 #define OPENTHREAD_SRP_CLIENT_H_
37 
38 #include <openthread/dns.h>
39 #include <openthread/ip6.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /**
46  * @addtogroup api-srp
47  *
48  * @brief
49  *   This module includes functions that control SRP client behavior.
50  *
51  * @{
52  */
53 
54 /**
55  * Specifies an SRP client item (service or host info) state.
56  */
57 typedef enum
58 {
59     OT_SRP_CLIENT_ITEM_STATE_TO_ADD,     ///< Item to be added/registered.
60     OT_SRP_CLIENT_ITEM_STATE_ADDING,     ///< Item is being added/registered.
61     OT_SRP_CLIENT_ITEM_STATE_TO_REFRESH, ///< Item to be refreshed (re-register to renew lease).
62     OT_SRP_CLIENT_ITEM_STATE_REFRESHING, ///< Item is being refreshed.
63     OT_SRP_CLIENT_ITEM_STATE_TO_REMOVE,  ///< Item to be removed.
64     OT_SRP_CLIENT_ITEM_STATE_REMOVING,   ///< Item is being removed.
65     OT_SRP_CLIENT_ITEM_STATE_REGISTERED, ///< Item is registered with server.
66     OT_SRP_CLIENT_ITEM_STATE_REMOVED,    ///< Item is removed.
67 } otSrpClientItemState;
68 
69 /**
70  * Represents an SRP client host info.
71  */
72 typedef struct otSrpClientHostInfo
73 {
74     const char          *mName;         ///< Host name (label) string (NULL if not yet set).
75     const otIp6Address  *mAddresses;    ///< Array of host IPv6 addresses (NULL if not set or auto address is enabled).
76     uint8_t              mNumAddresses; ///< Number of IPv6 addresses in `mAddresses` array.
77     bool                 mAutoAddress;  ///< Indicates whether auto address mode is enabled or not.
78     otSrpClientItemState mState;        ///< Host info state.
79 } otSrpClientHostInfo;
80 
81 /**
82  * Represents an SRP client service.
83  *
84  * The values in this structure, including the string buffers for the names and the TXT record entries, MUST persist
85  * and stay constant after an instance of this structure is passed to OpenThread from `otSrpClientAddService()` or
86  * `otSrpClientRemoveService()`.
87  *
88  * The `mState`, `mData`, `mNext` fields are used/managed by OT core only. Their value is ignored when an instance of
89  * `otSrpClientService` is passed in `otSrpClientAddService()` or `otSrpClientRemoveService()` or other functions. The
90  * caller does not need to set these fields.
91  *
92  * The `mLease` and `mKeyLease` fields specify the desired lease and key lease intervals for this service. Zero value
93  * indicates that the interval is unspecified and then the default lease or key lease intervals from
94  * `otSrpClientGetLeaseInterval()` and `otSrpClientGetKeyLeaseInterval()` are used for this service. If the key lease
95  * interval (whether set explicitly or determined from the default) is shorter than the lease interval for a service,
96  * SRP client will re-use the lease interval value for key lease interval as well. For example, if in service `mLease`
97  * is explicitly set to 2 days and `mKeyLease` is set to zero and default key lease is set to 1 day, then when
98  * registering this service, the requested key lease for this service is also set to 2 days.
99  */
100 typedef struct otSrpClientService
101 {
102     const char                *mName;          ///< The service labels (e.g., "_mt._udp", not the full domain name).
103     const char                *mInstanceName;  ///< The service instance name label (not the full name).
104     const char *const         *mSubTypeLabels; ///< Array of sub-type labels (must end with `NULL` or can be `NULL`).
105     const otDnsTxtEntry       *mTxtEntries;    ///< Array of TXT entries (`mNumTxtEntries` gives num of entries).
106     uint16_t                   mPort;          ///< The service port number.
107     uint16_t                   mPriority;      ///< The service priority.
108     uint16_t                   mWeight;        ///< The service weight.
109     uint8_t                    mNumTxtEntries; ///< Number of entries in the `mTxtEntries` array.
110     otSrpClientItemState       mState;         ///< Service state (managed by OT core).
111     uint32_t                   mData;          ///< Internal data (used by OT core).
112     struct otSrpClientService *mNext;          ///< Pointer to next entry in a linked-list (managed by OT core).
113     uint32_t                   mLease;         ///< Desired lease interval in sec - zero to use default.
114     uint32_t                   mKeyLease;      ///< Desired key lease interval in sec - zero to use default.
115 } otSrpClientService;
116 
117 /**
118  * Pointer type defines the callback used by SRP client to notify user of changes/events/errors.
119  *
120  * This callback is invoked on a successful registration of an update (i.e., add/remove of host-info and/or some
121  * service(s)) with the SRP server, or if there is a failure or error (e.g., server rejects a update request or client
122  * times out waiting for response, etc).
123  *
124  * In case of a successful reregistration of an update, `aError` parameter would be `OT_ERROR_NONE` and the host info
125  * and the full list of services is provided as input parameters to the callback. Note that host info and services each
126  * track its own state in the corresponding `mState` member variable of the related data structure (the state
127  * indicating whether the host-info/service is registered or removed or still being added/removed, etc).
128  *
129  * The list of removed services is passed as its own linked-list `aRemovedServices` in the callback. Note that when the
130  * callback is invoked, the SRP client (OpenThread implementation) is done with the removed service instances listed in
131  * `aRemovedServices` and no longer tracks/stores them (i.e., if from the callback we call `otSrpClientGetServices()`
132  * the removed services will not be present in the returned list). Providing a separate list of removed services in
133  * the callback helps indicate to user which items are now removed and allow user to re-claim/reuse the instances.
134  *
135  * If the server rejects an SRP update request, the DNS response code (RFC 2136) is mapped to the following errors:
136  *
137  *  - (0)  NOERROR   Success (no error condition)                    -> OT_ERROR_NONE
138  *  - (1)  FORMERR   Server unable to interpret due to format error  -> OT_ERROR_PARSE
139  *  - (2)  SERVFAIL  Server encountered an internal failure          -> OT_ERROR_FAILED
140  *  - (3)  NXDOMAIN  Name that ought to exist, does not exist        -> OT_ERROR_NOT_FOUND
141  *  - (4)  NOTIMP    Server does not support the query type (OpCode) -> OT_ERROR_NOT_IMPLEMENTED
142  *  - (5)  REFUSED   Server refused for policy/security reasons      -> OT_ERROR_SECURITY
143  *  - (6)  YXDOMAIN  Some name that ought not to exist, does exist   -> OT_ERROR_DUPLICATED
144  *  - (7)  YXRRSET   Some RRset that ought not to exist, does exist  -> OT_ERROR_DUPLICATED
145  *  - (8)  NXRRSET   Some RRset that ought to exist, does not exist  -> OT_ERROR_NOT_FOUND
146  *  - (9)  NOTAUTH   Service is not authoritative for zone           -> OT_ERROR_SECURITY
147  *  - (10) NOTZONE   A name is not in the zone                       -> OT_ERROR_PARSE
148  *  - (20) BADNAME   Bad name                                        -> OT_ERROR_PARSE
149  *  - (21) BADALG    Bad algorithm                                   -> OT_ERROR_SECURITY
150  *  - (22) BADTRUN   Bad truncation                                  -> OT_ERROR_PARSE
151  *  - Other response codes                                           -> OT_ERROR_FAILED
152  *
153  * The following errors are also possible:
154  *
155  *  - OT_ERROR_RESPONSE_TIMEOUT : Timed out waiting for response from server (client would continue to retry).
156  *  - OT_ERROR_INVALID_ARGS     : The provided service structure is invalid (e.g., bad service name or `otDnsTxtEntry`).
157  *  - OT_ERROR_NO_BUFS          : Insufficient buffer to prepare or send the update message.
158  *
159  * Note that in case of any failure, the client continues the operation, i.e. it prepares and (re)transmits the SRP
160  * update message to the server, after some wait interval. The retry wait interval starts from the minimum value and
161  * is increased by the growth factor every failure up to the max value (please see configuration parameter
162  * `OPENTHREAD_CONFIG_SRP_CLIENT_MIN_RETRY_WAIT_INTERVAL` and the related ones for more details).
163  *
164  * @param[in] aError            The error (see above).
165  * @param[in] aHostInfo         A pointer to host info.
166  * @param[in] aServices         The head of linked-list containing all services (excluding the ones removed). NULL if
167  *                              the list is empty.
168  * @param[in] aRemovedServices  The head of linked-list containing all removed services. NULL if the list is empty.
169  * @param[in] aContext          A pointer to an arbitrary context (provided when callback was registered).
170  */
171 typedef void (*otSrpClientCallback)(otError                    aError,
172                                     const otSrpClientHostInfo *aHostInfo,
173                                     const otSrpClientService  *aServices,
174                                     const otSrpClientService  *aRemovedServices,
175                                     void                      *aContext);
176 
177 /**
178  * Pointer type defines the callback used by SRP client to notify user when it is auto-started or stopped.
179  *
180  * This is only used when auto-start feature `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE` is enabled.
181  *
182  * This callback is invoked when auto-start mode is enabled and the SRP client is either automatically started or
183  * stopped.
184  *
185  * @param[in] aServerSockAddr   A non-NULL pointer indicates SRP server was started and pointer will give the
186  *                              selected server socket address. A NULL pointer indicates SRP server was stopped.
187  * @param[in] aContext          A pointer to an arbitrary context (provided when callback was registered).
188  */
189 typedef void (*otSrpClientAutoStartCallback)(const otSockAddr *aServerSockAddr, void *aContext);
190 
191 /**
192  * Starts the SRP client operation.
193  *
194  * SRP client will prepare and send "SRP Update" message to the SRP server once all the following conditions are met:
195  *
196  *  - The SRP client is started - `otSrpClientStart()` is called.
197  *  - Host name is set - `otSrpClientSetHostName()` is called.
198  *  - At least one host IPv6 address is set - `otSrpClientSetHostAddresses()` is called.
199  *  - At least one service is added - `otSrpClientAddService()` is called.
200  *
201  * It does not matter in which order these functions are called. When all conditions are met, the SRP client will
202  * wait for a short delay before preparing an "SRP Update" message and sending it to server. This delay allows for user
203  * to add multiple services and/or IPv6 addresses before the first SRP Update message is sent (ensuring a single SRP
204  * Update is sent containing all the info). The config `OPENTHREAD_CONFIG_SRP_CLIENT_UPDATE_TX_DELAY` specifies the
205  * delay interval.
206  *
207  * @param[in] aInstance        A pointer to the OpenThread instance.
208  * @param[in] aServerSockAddr  The socket address (IPv6 address and port number) of the SRP server.
209  *
210  * @retval OT_ERROR_NONE       SRP client operation started successfully or it is already running with same server
211  *                             socket address and callback.
212  * @retval OT_ERROR_BUSY       SRP client is busy running with a different socket address.
213  * @retval OT_ERROR_FAILED     Failed to open/connect the client's UDP socket.
214  */
215 otError otSrpClientStart(otInstance *aInstance, const otSockAddr *aServerSockAddr);
216 
217 /**
218  * Stops the SRP client operation.
219  *
220  * Stops any further interactions with the SRP server. Note that it does not remove or clear host info
221  * and/or list of services. It marks all services to be added/removed again once the client is (re)started.
222  *
223  * @param[in] aInstance       A pointer to the OpenThread instance.
224  */
225 void otSrpClientStop(otInstance *aInstance);
226 
227 /**
228  * Indicates whether the SRP client is running or not.
229  *
230  * @param[in] aInstance       A pointer to the OpenThread instance.
231  *
232  * @returns TRUE if the SRP client is running, FALSE otherwise.
233  */
234 bool otSrpClientIsRunning(otInstance *aInstance);
235 
236 /**
237  * Gets the socket address (IPv6 address and port number) of the SRP server which is being used by SRP
238  * client.
239  *
240  * If the client is not running, the address is unspecified (all zero) with zero port number.
241  *
242  * @param[in] aInstance       A pointer to the OpenThread instance.
243  *
244  * @returns A pointer to the SRP server's socket address (is always non-NULL).
245  */
246 const otSockAddr *otSrpClientGetServerAddress(otInstance *aInstance);
247 
248 /**
249  * Sets the callback to notify caller of events/changes from SRP client.
250  *
251  * The SRP client allows a single callback to be registered. So consecutive calls to this function will overwrite any
252  * previously set callback functions.
253  *
254  * @param[in] aInstance   A pointer to the OpenThread instance.
255  * @param[in] aCallback   The callback to notify of events and changes. Can be NULL if not needed.
256  * @param[in] aContext    An arbitrary context used with @p aCallback.
257  */
258 void otSrpClientSetCallback(otInstance *aInstance, otSrpClientCallback aCallback, void *aContext);
259 
260 /**
261  * Enables the auto-start mode.
262  *
263  * This is only available when auto-start feature `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE` is enabled.
264  *
265  * Config option `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_DEFAULT_MODE` specifies the default auto-start mode (whether
266  * it is enabled or disabled at the start of OT stack).
267  *
268  * When auto-start is enabled, the SRP client will monitor the Thread Network Data to discover SRP servers and select
269  * the preferred server and automatically start and stop the client when an SRP server is detected.
270  *
271  * There are three categories of Network Data entries indicating presence of SRP sever. They are preferred in the
272  * following order:
273  *
274  *   1) Preferred unicast entries where server address is included in the service data. If there are multiple options,
275  *      the one with numerically lowest IPv6 address is preferred.
276  *
277  *   2) Anycast entries each having a seq number. A larger sequence number in the sense specified by Serial Number
278  *      Arithmetic logic in RFC-1982 is considered more recent and therefore preferred. The largest seq number using
279  *      serial number arithmetic is preferred if it is well-defined (i.e., the seq number is larger than all other
280  *      seq numbers). If it is not well-defined, then the numerically largest seq number is preferred.
281  *
282  *   3) Unicast entries where the server address info is included in server data. If there are multiple options, the
283  *      one with numerically lowest IPv6 address is preferred.
284  *
285  * When there is a change in the Network Data entries, client will check that the currently selected server is still
286  * present in the Network Data and is still the preferred one. Otherwise the client will switch to the new preferred
287  * server or stop if there is none.
288  *
289  * When the SRP client is explicitly started through a successful call to `otSrpClientStart()`, the given SRP server
290  * address in `otSrpClientStart()` will continue to be used regardless of the state of auto-start mode and whether the
291  * same SRP server address is discovered or not in the Thread Network Data. In this case, only an explicit
292  * `otSrpClientStop()` call will stop the client.
293  *
294  * @param[in] aInstance   A pointer to the OpenThread instance.
295  * @param[in] aCallback   A callback to notify when client is auto-started/stopped. Can be NULL if not needed.
296  * @param[in] aContext    A context to be passed when invoking @p aCallback.
297  */
298 void otSrpClientEnableAutoStartMode(otInstance *aInstance, otSrpClientAutoStartCallback aCallback, void *aContext);
299 
300 /**
301  * Disables the auto-start mode.
302  *
303  * This is only available when auto-start feature `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE` is enabled.
304  *
305  * Disabling the auto-start mode will not stop the client if it is already running but the client stops monitoring
306  * the Thread Network Data to verify that the selected SRP server is still present in it.
307  *
308  * Note that a call to `otSrpClientStop()` will also disable the auto-start mode.
309  *
310  * @param[in] aInstance   A pointer to the OpenThread instance.
311  */
312 void otSrpClientDisableAutoStartMode(otInstance *aInstance);
313 
314 /**
315  * Indicates the current state of auto-start mode (enabled or disabled).
316  *
317  * This is only available when auto-start feature `OPENTHREAD_CONFIG_SRP_CLIENT_AUTO_START_API_ENABLE` is enabled.
318  *
319  * @param[in] aInstance   A pointer to the OpenThread instance.
320  *
321  * @returns TRUE if the auto-start mode is enabled, FALSE otherwise.
322  */
323 bool otSrpClientIsAutoStartModeEnabled(otInstance *aInstance);
324 
325 /**
326  * Gets the TTL value in every record included in SRP update requests.
327  *
328  * Note that this is the TTL requested by the SRP client. The server may choose to accept a different TTL.
329  *
330  * By default, the TTL will equal the lease interval. Passing 0 or a value larger than the lease interval via
331  * `otSrpClientSetTtl()` will also cause the TTL to equal the lease interval.
332  *
333  * @param[in] aInstance  A pointer to the OpenThread instance.
334  *
335  * @returns The TTL (in seconds).
336  */
337 uint32_t otSrpClientGetTtl(otInstance *aInstance);
338 
339 /**
340  * Sets the TTL value in every record included in SRP update requests.
341  *
342  * Changing the TTL does not impact the TTL of already registered services/host-info.
343  * It only affects future SRP update messages (i.e., adding new services and/or refreshes of the existing services).
344  *
345  * @param[in] aInstance   A pointer to the OpenThread instance.
346  * @param[in] aTtl        The TTL (in seconds). If value is zero or greater than lease interval, the TTL is set to the
347  *                        lease interval.
348  */
349 void otSrpClientSetTtl(otInstance *aInstance, uint32_t aTtl);
350 
351 /**
352  * Gets the default lease interval used in SRP update requests.
353  *
354  * The default interval is used only for `otSrpClientService` instances with `mLease` set to zero.
355  *
356  * Note that this is the lease duration requested by the SRP client. The server may choose to accept a different lease
357  * interval.
358  *
359  * @param[in] aInstance        A pointer to the OpenThread instance.
360  *
361  * @returns The lease interval (in seconds).
362  */
363 uint32_t otSrpClientGetLeaseInterval(otInstance *aInstance);
364 
365 /**
366  * Sets the default lease interval used in SRP update requests.
367  *
368  * The default interval is used only for `otSrpClientService` instances with `mLease` set to zero.
369  *
370  * Changing the lease interval does not impact the accepted lease interval of already registered services/host-info.
371  * It only affects any future SRP update messages (i.e., adding new services and/or refreshes of the existing services).
372  *
373  * @param[in] aInstance   A pointer to the OpenThread instance.
374  * @param[in] aInterval   The lease interval (in seconds). If zero, the default value specified by
375  *                        `OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_LEASE` would be used.
376  */
377 void otSrpClientSetLeaseInterval(otInstance *aInstance, uint32_t aInterval);
378 
379 /**
380  * Gets the default key lease interval used in SRP update requests.
381  *
382  * The default interval is used only for `otSrpClientService` instances with `mKeyLease` set to zero.
383  *
384  * Note that this is the lease duration requested by the SRP client. The server may choose to accept a different lease
385  * interval.
386  *
387  * @param[in] aInstance        A pointer to the OpenThread instance.
388  *
389  * @returns The key lease interval (in seconds).
390  */
391 uint32_t otSrpClientGetKeyLeaseInterval(otInstance *aInstance);
392 
393 /**
394  * Sets the default key lease interval used in SRP update requests.
395  *
396  * The default interval is used only for `otSrpClientService` instances with `mKeyLease` set to zero.
397  *
398  * Changing the lease interval does not impact the accepted lease interval of already registered services/host-info.
399  * It only affects any future SRP update messages (i.e., adding new services and/or refreshes of existing services).
400  *
401  * @param[in] aInstance    A pointer to the OpenThread instance.
402  * @param[in] aInterval    The key lease interval (in seconds). If zero, the default value specified by
403  *                         `OPENTHREAD_CONFIG_SRP_CLIENT_DEFAULT_KEY_LEASE` would be used.
404  */
405 void otSrpClientSetKeyLeaseInterval(otInstance *aInstance, uint32_t aInterval);
406 
407 /**
408  * Gets the host info.
409  *
410  * @param[in] aInstance        A pointer to the OpenThread instance.
411  *
412  * @returns A pointer to host info structure.
413  */
414 const otSrpClientHostInfo *otSrpClientGetHostInfo(otInstance *aInstance);
415 
416 /**
417  * Sets the host name label.
418  *
419  * After a successful call to this function, `otSrpClientCallback` will be called to report the status of host info
420  * registration with SRP server.
421  *
422  * The name string buffer pointed to by @p aName MUST persist and stay unchanged after returning from this function.
423  * OpenThread will keep the pointer to the string.
424  *
425  * The host name can be set before client is started or after start but before host info is registered with server
426  * (host info should be in either `STATE_TO_ADD` or `STATE_REMOVED`).
427  *
428  * @param[in] aInstance   A pointer to the OpenThread instance.
429  * @param[in] aName       A pointer to host name label string (MUST NOT be NULL). Pointer to the string buffer MUST
430  *                        persist and remain valid and constant after return from this function.
431  *
432  * @retval OT_ERROR_NONE            The host name label was set successfully.
433  * @retval OT_ERROR_INVALID_ARGS    The @p aName is NULL.
434  * @retval OT_ERROR_INVALID_STATE   The host name is already set and registered with the server.
435  */
436 otError otSrpClientSetHostName(otInstance *aInstance, const char *aName);
437 
438 /**
439  * Enables auto host address mode.
440  *
441  * When enabled host IPv6 addresses are automatically set by SRP client using all the preferred unicast addresses on
442  * Thread netif excluding all link-local and mesh-local addresses. If there is no preferred address, then Mesh Local
443  * EID address is added. The SRP client will automatically re-register when/if addresses on Thread netif are updated
444  * (new addresses are added or existing addresses are removed or marked as non-preferred).
445  *
446  * The auto host address mode can be enabled before start or during operation of SRP client except when the host info
447  * is being removed (client is busy handling a remove request from an call to `otSrpClientRemoveHostAndServices()` and
448  * host info still being in  either `STATE_TO_REMOVE` or `STATE_REMOVING` states).
449  *
450  * After auto host address mode is enabled, it can be disabled by a call to `otSrpClientSetHostAddresses()` which
451  * then explicitly sets the host addresses.
452  *
453  * @retval OT_ERROR_NONE            Successfully enabled auto host address mode.
454  * @retval OT_ERROR_INVALID_STATE   Host is being removed and therefore cannot enable auto host address mode.
455  */
456 otError otSrpClientEnableAutoHostAddress(otInstance *aInstance);
457 
458 /**
459  * Sets/updates the list of host IPv6 address.
460  *
461  * Host IPv6 addresses can be set/changed before start or during operation of SRP client (e.g. to add/remove or change
462  * a previously registered host address), except when the host info is being removed (client is busy handling a remove
463  * request from an earlier call to `otSrpClientRemoveHostAndServices()` and host info still being in  either
464  * `STATE_TO_REMOVE` or `STATE_REMOVING` states).
465  *
466  * The host IPv6 address array pointed to by @p aIp6Addresses MUST persist and remain unchanged after returning from
467  * this function (with `OT_ERROR_NONE`). OpenThread will save the pointer to the array.
468  *
469  * After a successful call to this function, `otSrpClientCallback` will be called to report the status of the address
470  * registration with SRP server.
471  *
472  * Calling this function disables auto host address mode if it was previously enabled from a successful call to
473  * `otSrpClientEnableAutoHostAddress()`.
474  *
475  * @param[in] aInstance           A pointer to the OpenThread instance.
476  * @param[in] aIp6Addresses       A pointer to the an array containing the host IPv6 addresses.
477  * @param[in] aNumAddresses       The number of addresses in the @p aIp6Addresses array.
478  *
479  * @retval OT_ERROR_NONE            The host IPv6 address list change started successfully. The `otSrpClientCallback`
480  *                                  will be called to report the status of registering addresses with server.
481  * @retval OT_ERROR_INVALID_ARGS    The address list is invalid (e.g., must contain at least one address).
482  * @retval OT_ERROR_INVALID_STATE   Host is being removed and therefore cannot change host address.
483  */
484 otError otSrpClientSetHostAddresses(otInstance *aInstance, const otIp6Address *aIp6Addresses, uint8_t aNumAddresses);
485 
486 /**
487  * Adds a service to be registered with server.
488  *
489  * After a successful call to this function, `otSrpClientCallback` will be called to report the status of the service
490  * addition/registration with SRP server.
491  *
492  * The `otSrpClientService` instance being pointed to by @p aService MUST persist and remain unchanged after returning
493  * from this function (with `OT_ERROR_NONE`). OpenThread will save the pointer to the service instance.
494  *
495  * The `otSrpClientService` instance is not longer tracked by OpenThread and can be reclaimed only when
496  *
497  *  -  It is removed explicitly by a call to `otSrpClientRemoveService()` or removed along with other services by a
498  *     call to `otSrpClientRemoveHostAndServices() and only after the `otSrpClientCallback` is called indicating the
499  *     service was removed. Or,
500  *  -  A call to `otSrpClientClearHostAndServices()` which removes the host and all related services immediately.
501  *
502  * @param[in] aInstance        A pointer to the OpenThread instance.
503  * @param[in] aService         A pointer to a `otSrpClientService` instance to add.
504 
505  * @retval OT_ERROR_NONE          The addition of service started successfully. The `otSrpClientCallback` will be
506  *                                called to report the status.
507  * @retval OT_ERROR_ALREADY       A service with the same service and instance names is already in the list.
508  * @retval OT_ERROR_INVALID_ARGS  The service structure is invalid (e.g., bad service name or `otDnsTxtEntry`).
509  */
510 otError otSrpClientAddService(otInstance *aInstance, otSrpClientService *aService);
511 
512 /**
513  * Requests a service to be unregistered with server.
514  *
515  * After a successful call to this function, `otSrpClientCallback` will be called to report the status of remove
516  * request with SRP server.
517 
518  * The `otSrpClientService` instance being pointed to by @p aService MUST persist and remain unchanged after returning
519  * from this function (with `OT_ERROR_NONE`). OpenThread will keep the service instance during the remove process.
520  * Only after the `otSrpClientCallback` is called indicating the service instance is removed from SRP client
521  * service list and can be be freed/reused.
522  *
523  * @param[in] aInstance        A pointer to the OpenThread instance.
524  * @param[in] aService         A pointer to a `otSrpClientService` instance to remove.
525  *
526  * @retval OT_ERROR_NONE       The removal of service started successfully. The `otSrpClientCallback` will be called to
527  *                             report the status.
528  * @retval OT_ERROR_NOT_FOUND  The service could not be found in the list.
529  */
530 otError otSrpClientRemoveService(otInstance *aInstance, otSrpClientService *aService);
531 
532 /**
533  * Clears a service, immediately removing it from the client service list.
534  *
535  * Unlike `otSrpClientRemoveService()` which sends an update message to the server to remove the service, this function
536  * clears the service from the client's service list without any interaction with the server. On a successful call to
537  * this function, the `otSrpClientCallback` will NOT be called and the @p aService entry can be reclaimed and re-used
538  * by the caller immediately.
539  *
540  * Can be used along with a subsequent call to `otSrpClientAddService()` (potentially reusing the same @p
541  * aService entry with the same service and instance names) to update some of the parameters in an existing service.
542  *
543  * @param[in] aInstance        A pointer to the OpenThread instance.
544  * @param[in] aService         A pointer to a `otSrpClientService` instance to delete.
545  *
546  * @retval OT_ERROR_NONE       The @p aService is deleted successfully. It can be reclaimed and re-used immediately.
547  * @retval OT_ERROR_NOT_FOUND  The service could not be found in the list.
548  */
549 otError otSrpClientClearService(otInstance *aInstance, otSrpClientService *aService);
550 
551 /**
552  * Gets the list of services being managed by client.
553  *
554  * @param[in] aInstance        A pointer to the OpenThread instance.
555  *
556  * @returns A pointer to the head of linked-list of all services or NULL if the list is empty.
557  */
558 const otSrpClientService *otSrpClientGetServices(otInstance *aInstance);
559 
560 /**
561  * Starts the remove process of the host info and all services.
562  *
563  * After returning from this function, `otSrpClientCallback` will be called to report the status of remove request with
564  * SRP server.
565  *
566  * If the host info is to be permanently removed from server, @p aRemoveKeyLease should be set to `true` which removes
567  * the key lease associated with host on server. Otherwise, the key lease record is kept as before, which ensures
568  * that the server holds the host name in reserve for when the client is once again able to provide and register its
569  * service(s).
570  *
571  * The @p aSendUnregToServer determines the behavior when the host info is not yet registered with the server. If
572  * @p aSendUnregToServer is set to `false` (which is the default/expected value) then the SRP client will immediately
573  * remove the host info and services without sending an update message to server (no need to update the server if
574  * nothing is yet registered with it). If @p aSendUnregToServer is set to `true` then the SRP client will send an
575  * update message to the server. Note that if the host info is registered then the value of @p aSendUnregToServer does
576  * not matter and the SRP client will always send an update message to server requesting removal of all info.
577  *
578  * One situation where @p aSendUnregToServer can be useful is on a device reset/reboot, caller may want to remove any
579  * previously registered services with the server. In this case, caller can `otSrpClientSetHostName()` and then request
580  * `otSrpClientRemoveHostAndServices()` with `aSendUnregToServer` as `true`.
581  *
582  * @param[in] aInstance          A pointer to the OpenThread instance.
583  * @param[in] aRemoveKeyLease    A boolean indicating whether or not the host key lease should also be removed.
584  * @param[in] aSendUnregToServer A boolean indicating whether to send update to server when host info is not registered.
585  *
586  * @retval OT_ERROR_NONE       The removal of host info and services started successfully. The `otSrpClientCallback`
587  *                             will be called to report the status.
588  * @retval OT_ERROR_ALREADY    The host info is already removed.
589  */
590 otError otSrpClientRemoveHostAndServices(otInstance *aInstance, bool aRemoveKeyLease, bool aSendUnregToServer);
591 
592 /**
593  * Clears all host info and all the services.
594  *
595  * Unlike `otSrpClientRemoveHostAndServices()` which sends an update message to the server to remove all the info, this
596  * function clears all the info immediately without any interaction with the server.
597  *
598  * @param[in] aInstance        A pointer to the OpenThread instance.
599  */
600 void otSrpClientClearHostAndServices(otInstance *aInstance);
601 
602 /**
603  * Gets the domain name being used by SRP client.
604  *
605  * Requires `OPENTHREAD_CONFIG_SRP_CLIENT_DOMAIN_NAME_API_ENABLE` to be enabled.
606  *
607  * If domain name is not set, "default.service.arpa" will be used.
608  *
609  * @param[in] aInstance        A pointer to the OpenThread instance.
610  *
611  * @returns The domain name string.
612  */
613 const char *otSrpClientGetDomainName(otInstance *aInstance);
614 
615 /**
616  * Sets the domain name to be used by SRP client.
617  *
618  * Requires `OPENTHREAD_CONFIG_SRP_CLIENT_DOMAIN_NAME_API_ENABLE` to be enabled.
619  *
620  * If not set "default.service.arpa" will be used.
621  *
622  * The name string buffer pointed to by @p aName MUST persist and stay unchanged after returning from this function.
623  * OpenThread will keep the pointer to the string.
624  *
625  * The domain name can be set before client is started or after start but before host info is registered with server
626  * (host info should be in either `STATE_TO_ADD` or `STATE_TO_REMOVE`).
627  *
628  * @param[in] aInstance     A pointer to the OpenThread instance.
629  * @param[in] aName         A pointer to the domain name string. If NULL sets it to default "default.service.arpa".
630  *
631  * @retval OT_ERROR_NONE            The domain name label was set successfully.
632  * @retval OT_ERROR_INVALID_STATE   The host info is already registered with server.
633  */
634 otError otSrpClientSetDomainName(otInstance *aInstance, const char *aName);
635 
636 /**
637  * Converts a `otSrpClientItemState` to a string.
638  *
639  * @param[in] aItemState  An item state.
640  *
641  * @returns A string representation of @p aItemState.
642  */
643 const char *otSrpClientItemStateToString(otSrpClientItemState aItemState);
644 
645 /**
646  * Enables/disables "service key record inclusion" mode.
647  *
648  * When enabled, SRP client will include KEY record in Service Description Instructions in the SRP update messages
649  * that it sends.
650  *
651  * Is available when `OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE` configuration is enabled.
652  *
653  * @note KEY record is optional in Service Description Instruction (it is required and always included in the Host
654  * Description Instruction). The default behavior of SRP client is to not include it. This function is intended to
655  * override the default behavior for testing only.
656  *
657  * @param[in] aInstance  A pointer to the OpenThread instance.
658  * @param[in] aEnabled   TRUE to enable, FALSE to disable the "service key record inclusion" mode.
659  */
660 void otSrpClientSetServiceKeyRecordEnabled(otInstance *aInstance, bool aEnabled);
661 
662 /**
663  * Indicates whether the "service key record inclusion" mode is enabled or disabled.
664  *
665  * Is available when `OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE` configuration is enabled.
666  *
667  * @param[in] aInstance     A pointer to the OpenThread instance.
668  *
669  * @returns TRUE if "service key record inclusion" mode is enabled, FALSE otherwise.
670  */
671 bool otSrpClientIsServiceKeyRecordEnabled(otInstance *aInstance);
672 
673 /**
674  * @}
675  */
676 
677 #ifdef __cplusplus
678 } // extern "C"
679 #endif
680 
681 #endif // OPENTHREAD_SRP_CLIENT_H_
682