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