Home | History | Annotate | Line # | Download | only in ServiceRegistration
      1 /* cti-services.h
      2  *
      3  * Copyright (c) 2020-2024 Apple Inc. All rights reserved.
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *     http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  *
     17  * This code adds border router support to 3rd party HomeKit Routers as part of Apples commitment to the CHIP project.
     18  *
     19  * Concise Thread Interface for Thread Border router control.
     20  */
     21 
     22 #ifndef __CTI_SERVICES_H__
     23 #define __CTI_SERVICES_H__
     24 
     25 #include <netinet/in.h>
     26 #include <arpa/inet.h>
     27 typedef void *run_context_t;
     28 #include "srp.h"
     29 
     30 #if (defined(__GNUC__) && (__GNUC__ >= 4))
     31 #define DNS_SERVICES_EXPORT __attribute__((visibility("default")))
     32 #else
     33 #define DNS_SERVICES_EXPORT
     34 #endif
     35 
     36 #include "cti-common.h"
     37 
     38 typedef enum _offmesh_route_origin {
     39     offmesh_route_origin_user,
     40     offmesh_route_origin_ncp,
     41 } offmesh_route_origin_t;
     42 
     43 typedef enum _offmesh_route_preference {
     44     offmesh_route_preference_low = -1,
     45     offmesh_route_preference_medium,
     46     offmesh_route_preference_high,
     47 } offmesh_route_preference_t;
     48 
     49 typedef struct _cti_service {
     50     uint64_t enterprise_number;
     51     uint16_t service_type;
     52     uint16_t service_version;
     53     uint16_t rloc16;
     54     uint16_t service_id;
     55     uint8_t *NONNULL service;
     56     uint8_t *NONNULL server;
     57     size_t service_length;
     58     size_t server_length;
     59     int ref_count;
     60     int flags;      // E.g., kCTIFlag_NCP
     61 } cti_service_t;
     62 
     63 typedef struct _cti_service_vec {
     64     size_t num;
     65     int ref_count;
     66     cti_service_t *NULLABLE *NONNULL services;
     67 } cti_service_vec_t;
     68 
     69 typedef struct _cti_prefix {
     70     struct in6_addr prefix;
     71     int prefix_length;
     72     int metric;
     73     int flags;
     74     int rloc;
     75     bool stable;
     76     bool ncp;
     77     int ref_count;
     78 } cti_prefix_t;
     79 
     80 // Bits in the prefix flags
     81 #define kCTIPriorityShift      14
     82 #define kCTIPreferredShift     13
     83 #define kCTISLAACShift         12
     84 #define kCTIDHCPShift          11
     85 #define kCTIConfigureShift     10
     86 #define kCTIDefaultRouteShift  9
     87 #define kCTIOnMeshShift        8
     88 #define kCTIDNSShift           7
     89 #define kCTIDPShift            6
     90 
     91 // Priority values
     92 #define kCTIPriorityMedium    0
     93 #define kCTIPriorityHigh      1
     94 #define kCTIPriorityReserved  2
     95 #define kCTIPriorityLow       3
     96 
     97 // Macros to fetch values from the prefix flags
     98 #define CTI_PREFIX_FLAGS_PRIORITY(flags)       (((flags) >> kCTIPriorityShift) & 3)
     99 #define CTI_PREFIX_FLAGS_PREFERRED(flags)      (((flags) >> kCTIPreferredShift) & 1)
    100 #define CTI_PREFIX_FLAGS_SLAAC(flags)          (((flags) >> kCTISLAACShift) & 1)
    101 #define CTI_PREFIX_FLAGS_DHCP(flags)           (((flags) >> kCTIDHCPShift) & 1)
    102 #define CTI_PREFIX_FLAGS_CONFIGURE(flags)      (((flags) >> kCTIConfigureShift) & 1)
    103 #define CTI_PREFIX_FLAGS_DEFAULT_ROUTE(flags)  (((flags) >> kCTIDefaultRouteShift) & 1)
    104 #define CTI_PREFIX_FLAGS_ON_MESH(flags)        (((flags) >> kCTIOnMeshShift) & 1)
    105 #define CTI_PREFIX_FLAGS_DNS(flags)            (((flags) >> kCTIDNSShift) & 1)
    106 #define CTI_PREFIX_DLAGS_DP(flags)             (((flags) >> kCTIDPShift) & 1)
    107 
    108 // Macros to set values in the prefix flags
    109 #define CTI_PREFIX_FLAGS_PRIORITY_SET(flags, value)       ((flags) = \
    110                                                             (((flags) & ~(3 << kCTIPriorityShift)) | \
    111                                                              (((value) & 3) << kCTIPriorityShift)))
    112 #define CTI_PREFIX_FLAGS_PREFERRED_SET(flags, value)      ((flags) = \
    113                                                             (((flags) & ~(1 << kCTIPreferredShift)) | \
    114                                                              (((value) & 1) << kCTIPreferredShift)))
    115 #define CTI_PREFIX_FLAGS_SLAAC_SET(flags, value)          ((flags) = \
    116                                                             (((flags) & ~(1 << kCTISLAACShift)) | \
    117                                                              (((value) & 1) << kCTISLAACShift)))
    118 #define CTI_PREFIX_FLAGS_DHCP_SET(flags, value)           ((flags) = \
    119                                                             (((flags) & ~(1 << kCTIDHCPShift)) | \
    120                                                              (((value) & 1) << kCTIDHCPShift)))
    121 #define CTI_PREFIX_FLAGS_CONFIGURE_SET(flags, value)      ((flags) = \
    122                                                             (((flags) & ~(1 << kCTIConfigureShift)) | \
    123                                                              (((value) & 1) << kCTIConfigureShift)))
    124 #define CTI_PREFIX_FLAGS_DEFAULT_ROUTE_SET(flags, value)  ((flags) = \
    125                                                             (((flags) & ~(1 << kCTIDefaultRouteShift)) | \
    126                                                              (((value) & 1) << kCTIDefaultRouteShift)))
    127 #define CTI_PREFIX_FLAGS_ON_MESH_SET(flags, value)        ((flags) = \
    128                                                             (((flags) & ~(1 << kCTIOnMeshShift)) | \
    129                                                              (((value) & 1) << kCTIOnMeshShift)))
    130 #define CTI_PREFIX_FLAGS_DNS_SET(flags, value)            ((flags) = \
    131                                                             (((flags) & ~(1 << kCTIDNSShift)) | \
    132                                                              (((value) & 1) << kCTIDNSShift)))
    133 #define CTI_PREFIX_DLAGS_DP_SET(flags, value)             ((flags) = \
    134                                                             (((flags) & ~(1 << kCTIDPShift)) | \
    135                                                              (((value) & 1) << kCTIDPShift)))
    136 
    137 typedef struct _cti_prefix_vec {
    138     size_t num;
    139     int ref_count;
    140     cti_prefix_t *NULLABLE *NONNULL prefixes;
    141 } cti_prefix_vec_t;
    142 
    143 typedef struct _cti_route {
    144     struct in6_addr prefix;
    145     int prefix_length;
    146     offmesh_route_origin_t origin;
    147     bool nat64;
    148     bool stable;
    149     offmesh_route_preference_t preference;
    150     int rloc;
    151     bool next_hop_is_host;
    152     int ref_count;
    153 } cti_route_t;
    154 
    155 typedef struct _cti_route_vec {
    156     size_t num;
    157     int ref_count;
    158     cti_route_t *NULLABLE *NONNULL routes;
    159 } cti_route_vec_t;
    160 
    161 typedef struct srp_server_state srp_server_t;
    162 
    163 /* cti_reply:
    164  *
    165  * A general reply mechanism to indicate success or failure for a cti call that doesn't
    166  * return any data.
    167  *
    168  * cti_reply parameters:
    169  *
    170  * context:    The context that was passed to the cti service call to which this is a callback.
    171  *
    172  * status:	   Will be kCTIStatus_NoError on success, otherwise will indicate the
    173  * 			   failure that occurred.
    174  */
    175 
    176 typedef void
    177 (*cti_reply_t)(void *NULLABLE context, cti_status_t status);
    178 
    179 /* cti_string_property_reply: Callback for get calls that fetch a string property
    180  *
    181  * Called exactly once in response to (for example) a cti_get_tunnel_name() or cti_get_on_link_prefix() call, either
    182  * with an error or with a string containing the response.
    183  *
    184  * cti_reply parameters:
    185  *
    186  * context:       The context that was passed to the cti service call to which this is a callback.
    187  *
    188  * tunnel_name:   If error is kCTIStatus_NoError, a string containing the name of the Thread
    189  * 			      interface.
    190  *
    191  * status:	      Will be kCTIStatus_NoError on success, otherwise will indicate the
    192  * 			      failure that occurred.
    193  */
    194 
    195 typedef void
    196 (*cti_string_property_reply_t)(void *NULLABLE context, const char *NONNULL string,
    197                                cti_status_t status);
    198 
    199 /* cti_get_tunnel_name
    200  *
    201  * Get the name of the tunnel that wpantund is presenting as the Thread network interface.
    202  * The tunnel name is passed to the reply callback if the request succeeds; otherwise an error
    203  * is either returned immediately or returned to the callback.
    204  *
    205  * context:        An anonymous pointer that will be passed along to the callback when
    206  *                 an event occurs.
    207  *
    208  * callback:       CallBack function for the client that indicates success or failure.
    209  *
    210  * client_queue:   Queue the client wants to schedule the callback on
    211  *
    212  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating the
    213  *                 error that occurred. Note: A return value of kCTIStatus_NoError does not mean that the
    214  *                 request succeeded, merely that it was successfully started.
    215  */
    216 
    217 #define cti_get_tunnel_name(server, context, callback, client_queue) \
    218     cti_get_tunnel_name_(server, context, callback, client_queue, __FILE__, __LINE__)
    219 DNS_SERVICES_EXPORT cti_status_t
    220 cti_get_tunnel_name_(srp_server_t *NULLABLE server, void *NULLABLE context, cti_string_property_reply_t NONNULL callback,
    221                      run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
    222 
    223 /* cti_track_neighbor_ml_eid
    224  *
    225  * Track changes in our neighbor's mesh-local address (ML-EID). This makes sense when acting as an end device, not as a
    226  * router.  The ML-EID tunnel is passed to the reply callback if the request succeeds; otherwise an error is either
    227  * returned immediately or returned to the callback.
    228  *
    229  * context:        An anonymous pointer that will be passed along to the callback when
    230  *                 an event occurs.
    231  *
    232  * callback:       CallBack function for the client that indicates success or failure.
    233  *
    234  * client_queue:   Queue the client wants to schedule the callback on
    235  *
    236  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating the
    237  *                 error that occurred. Note: A return value of kCTIStatus_NoError does not mean that the
    238  *                 request succeeded, merely that it was successfully started.
    239  */
    240 
    241 #define cti_track_neighbor_ml_eid(server, ref, context, callback, client_queue) \
    242     cti_track_neighbor_ml_eid_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
    243 DNS_SERVICES_EXPORT cti_status_t
    244 cti_track_neighbor_ml_eid_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref,
    245                            void *NULLABLE context, cti_string_property_reply_t NONNULL callback,
    246                            run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
    247 
    248 /* cti_get_mesh_local_prefix
    249  *
    250  * Get the mesh_local IPv6 prefix that is in use on the Thread mesh. The prefix is passed to the reply callback if the
    251  * request succeeds; otherwise an error is either returned immediately or returned to the callback.
    252  *
    253  * context:        An anonymous pointer that will be passed along to the callback when
    254  *                 an event occurs.
    255  *
    256  * callback:       CallBack function for the client that indicates success or failure.
    257  *
    258  * client_queue:   Queue the client wants to schedule the callback on
    259  *
    260  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating the
    261  *                 error that occurred. Note: A return value of kCTIStatus_NoError does not mean that the
    262  *                 request succeeded, merely that it was successfully started.
    263  */
    264 
    265 #define cti_get_mesh_local_prefix(server, context, callback, client_queue) \
    266     cti_get_mesh_local_prefix_(server, context, callback, client_queue, __FILE__, __LINE__)
    267 DNS_SERVICES_EXPORT cti_status_t
    268 cti_get_mesh_local_prefix_(srp_server_t *NULLABLE server,
    269                            void *NULLABLE context, cti_string_property_reply_t NONNULL callback,
    270                            run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
    271 
    272 /* cti_get_mesh_local_address
    273  *
    274  * Get the mesh_local IPv6 address that is in use on this device on the Thread mesh. The address is passed to the reply
    275  * callback if the request succeeds; otherwise an error is either returned immediately or returned to the callback.
    276  *
    277  * context:        An anonymous pointer that will be passed along to the callback when
    278  *                 an event occurs.
    279  *
    280  * callback:       CallBack function for the client that indicates success or failure.
    281  *
    282  * client_queue:   Queue the client wants to schedule the callback on
    283  *
    284  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating the
    285  *                 error that occurred. Note: A return value of kCTIStatus_NoError does not mean that the
    286  *                 request succeeded, merely that it was successfully started.
    287  */
    288 
    289 #define cti_get_mesh_local_address(server, context, callback, client_queue) \
    290     cti_get_mesh_local_address_(server, context, callback, client_queue, __FILE__, __LINE__)
    291 DNS_SERVICES_EXPORT cti_status_t
    292 cti_get_mesh_local_address_(srp_server_t *NULLABLE server,
    293                             void *NULLABLE context, cti_string_property_reply_t NONNULL callback,
    294                             run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
    295 
    296 /*
    297  * cti_service_vec_create
    298  *
    299  * creates a service array vector of specified length
    300  *
    301  * num_services:     Number of service slots available in the service vector.
    302  *
    303  * return value:     NULL, if the call failed; otherwise a service vector capable of containing the requested number of
    304  *                   services.
    305  */
    306 cti_service_vec_t *NULLABLE
    307 cti_service_vec_create_(size_t num_services, const char *NONNULL file, int line);
    308 #define cti_service_vec_create(num_services) cti_service_vec_create_(num_services, __FILE__, __LINE__)
    309 
    310 /*
    311  * cti_service_vec_release
    312  *
    313  * decrements the reference count on the provided service vector and, if it reaches zero, finalizes the service vector,
    314  * which calls cti_service_release on each service in the vector, potentially also finalizing them.
    315  *
    316  * num_services:     Number of service slots available in the service vector.
    317  *
    318  * return value:     NULL, if the call failed; otherwise a service vector capable of containing the requested number of
    319  *                   services.
    320  */
    321 
    322 void
    323 cti_service_vec_release_(cti_service_vec_t *NONNULL services, const char *NONNULL file, int line);
    324 #define cti_service_vec_release(services) cti_service_vec_release_(services, __FILE__, __LINE__)
    325 
    326 /*
    327  * cti_service_create
    328  *
    329  * Creates a service containing the specified information.   service and server are retained, and will be
    330  * freed using free() when the service object is finalized.   Caller must not retain or free these values, and
    331  * they must be allocated on the malloc heap.
    332  *
    333  * enterprise_number: The enterprise number for this service.
    334  *
    335  * service_type:      The service type, from the service data.
    336  *
    337  * service_version:   The service version, from the service data.
    338  *
    339  * server:            Server information for this service, stored in network byte order.   Format depends on service type.
    340  *
    341  * server_length:     Length of server information in bytes.
    342  *
    343  * flags:             Thread network status flags, e.g. NCP versue User
    344  *
    345  * return value:     NULL, if the call failed; otherwise a service object containing the specified state.
    346  */
    347 
    348 cti_service_t *NULLABLE
    349 cti_service_create_(uint64_t enterprise_number, uint16_t rloc16, uint16_t service_type, uint16_t service_version,
    350                     uint8_t *NONNULL service, size_t service_length, uint8_t *NONNULL server, size_t server_length,
    351                     uint16_t service_id, int flags, const char *NONNULL file, int line);
    352 #define cti_service_create(enterprise_number, rloc16, service_type, service_version, service, service_length, \
    353                            server, server_length, service_id, flags) \
    354     cti_service_create_(enterprise_number, rloc16, service_type, service_version, service, service_length, \
    355                         server, server_length, service_id, flags, __FILE__, __LINE__)
    356 
    357 /*
    358  * cti_service_vec_release
    359  *
    360  * decrements the reference count on the provided service vector and, if it reaches zero, finalizes the service vector,
    361  * which calls cti_service_release on each service in the vector, potentially also finalizing them.
    362  *
    363  * services:         The service vector to release
    364  *
    365  * return value:     NULL, if the call failed; otherwise a service vector capable of containing the requested number of
    366  *                   services.
    367  */
    368 
    369 void
    370 cti_service_release_(cti_service_t *NONNULL service, const char *NONNULL file, int line);
    371 #define cti_service_release(services) cti_service_release(service, __FILE__, __LINE__)
    372 
    373 /* cti_service_reply: Callback from cti_get_service_list()
    374  *
    375  * Called when an error occurs during processing of the cti_get_service_list call, or when data
    376  * is available in response to the call.
    377  *
    378  * In the case of an error, the callback will not be called again, and the caller is responsible for
    379  * releasing the connection state and restarting if needed.
    380  *
    381  * The callback will be called once immediately upon success, and once again each time the service list
    382  * is updated.   If the callback wishes to retain either the cti_service_vec_t or any of the elements
    383  * of that vector, the appropriate retain function should be called; when the object is no longer needed,
    384  * the corresponding release call must be called.
    385  *
    386  * cti_reply parameters:
    387  *
    388  * context:           The context that was passed to the cti service call to which this is a callback.
    389  *
    390  * services:          If status is kCTIStatus_NoError, a cti_service_vec_t containing the list of services
    391  *                    provided in the update.
    392  *
    393  * status:	          Will be kCTIStatus_NoError if the service list request is successful, or
    394  *                    will indicate the failure that occurred.
    395  */
    396 
    397 typedef void
    398 (*cti_service_reply_t)(void *NULLABLE context, cti_service_vec_t *NULLABLE services, cti_status_t status);
    399 
    400 /* cti_get_service_list
    401  *
    402  * Requests wpantund to immediately send the current list of services published in the Thread network data.
    403  * Whenever the service list is updated, the callback will be called again with the new information.  A
    404  * return value of kCTIStatus_NoError means that the caller can expect the reply callback to be called at least
    405  * once.  Any other error status means that the request could not be sent, and the callback will never be
    406  * called.
    407  *
    408  * To discontinue receiving service add/remove callbacks, the calling program should call
    409  * cti_connection_ref_deallocate on the conn_ref returned by a successful call to get_service_list();
    410  *
    411  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
    412  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
    413  *
    414  * context:        An anonymous pointer that will be passed along to the callback when
    415  *                 an event occurs.
    416  *
    417  * callback:       CallBack function for the client that indicates success or failure.
    418  *                 If the get_services call fails, response will be NULL and status
    419  *                 will indicate what went wrong.  No further callbacks can be expected
    420  *                 after this.   If the request succeeds, then the callback will be called
    421  *                 once immediately with the current service list, and then again whenever
    422  *                 the service list is updated.
    423  *
    424  * client_queue:   Queue the client wants to schedule the callback on
    425  *
    426  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    427  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    428  *                 that the request succeeded, merely that it was successfully started.
    429  */
    430 
    431 #define cti_get_service_list(server, ref, context, callback, client_queue) \
    432     cti_get_service_list_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
    433 DNS_SERVICES_EXPORT cti_status_t
    434 cti_get_service_list_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref, void *NULLABLE context,
    435                       cti_service_reply_t NONNULL callback, run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
    436 
    437 /*
    438  * cti_service_vec_create
    439  *
    440  * creates a service array vector of specified length
    441  *
    442  * num_prefixes:     Number of prefix slots available in the prefix vector.
    443  *
    444  * return value:     NULL, if the call failed; otherwise a prefix vector capable of containing the requested number of
    445  *                   prefixes.
    446  */
    447 cti_prefix_vec_t *NULLABLE
    448 cti_prefix_vec_create_(size_t num_prefixes, const char *NONNULL file, int line);
    449 #define cti_prefix_vec_create(num_prefixes) cti_prefix_vec_create_(num_prefixes, __FILE__, __LINE__)
    450 
    451 /*
    452  * cti_prefix_vec_release
    453  *
    454  * decrements the reference count on the provided prefix vector and, if it reaches zero, finalizes the prefix vector,
    455  * which calls cti_prefix_release on each prefix in the vector, potentially also finalizing them.
    456  *
    457  * num_prefixes:     Number of prefix slots available in the prefix vector.
    458  *
    459  * return value:     NULL, if the call failed; otherwise a prefix vector capable of containing the requested number of
    460  *                   prefixes.
    461  */
    462 
    463 void
    464 cti_prefix_vec_release_(cti_prefix_vec_t *NONNULL prefixes, const char *NONNULL file, int line);
    465 #define cti_prefix_vec_release(prefixes) cti_prefix_vec_release_(prefixes, __FILE__, __LINE__)
    466 
    467 /*
    468  * cti_prefix_create
    469  *
    470  * Creates a prefix containing the specified information.   prefix and server are retained, and will be
    471  * freed using free() when the prefix object is finalized.   Caller must not retain or free these values, and
    472  * they must be allocated on the malloc heap.
    473  *
    474  * enterprise_number: The enterprise number for this prefix.
    475  *
    476  * prefix_type:      The prefix type, from the prefix data.
    477  *
    478  * prefix_version:   The prefix version, from the prefix data.
    479  *
    480  * server:            Server information for this prefix, stored in network byte order.   Format depends on prefix type.
    481  *
    482  * server_length:     Length of server information in bytes.
    483  *
    484  * flags:             Thread network status flags, e.g. NCP versue User
    485  *
    486  * return value:     NULL, if the call failed; otherwise a prefix object containing the specified state.
    487  */
    488 
    489 cti_prefix_t *NULLABLE
    490 cti_prefix_create_(struct in6_addr *NONNULL prefix, int prefix_length, int metric, int flags, int rloc, bool stable, bool ncp,
    491                    const char *NONNULL file, int line);
    492 #define cti_prefix_create(prefix, prefix_length, metric, flags, rloc, stable, ncp) \
    493     cti_prefix_create_(prefix, prefix_length, metric, flags, rloc, stable, ncp, __FILE__, __LINE__)
    494 
    495 /*
    496  * cti_prefix_vec_release
    497  *
    498  * decrements the reference count on the provided prefix vector and, if it reaches zero, finalizes the prefix vector,
    499  * which calls cti_prefix_release on each prefix in the vector, potentially also finalizing them.
    500  *
    501  * prefixes:         The prefix vector to release.
    502  *
    503  * return value:     NULL, if the call failed; otherwise a prefix vector capable of containing the requested number of
    504  *                   prefixes.
    505  */
    506 
    507 void
    508 cti_prefix_release_(cti_prefix_t *NONNULL prefix, const char *NONNULL file, int line);
    509 #define cti_prefix_release(prefixes) cti_prefix_release(prefix, __FILE__, __LINE__)
    510 
    511 /* cti_prefix_reply: Callback from cti_get_prefix_list()
    512  *
    513  * Called when an error occurs during processing of the cti_get_prefix_list call, or when a prefix
    514  * is added or removed.
    515  *
    516  * In the case of an error, the callback will not be called again, and the caller is responsible for
    517  * releasing the connection state and restarting if needed.
    518  *
    519  * The callback will be called once for each prefix present on the Thread network at the time
    520  * get_prefix_list() is first called, and then again whenever a prefix is added or removed.
    521  *
    522  * cti_reply parameters:
    523  *
    524  * context:           The context that was passed to the cti prefix call to which this is a callback.
    525  *
    526  * prefix_vec:        If status is kCTIStatus_NoError, a vector containing all of the prefixes that were reported in
    527  *                    this event.
    528  *
    529  * status:	          Will be kCTIStatus_NoError if the prefix list request is successful, or
    530  *                    will indicate the failure that occurred.
    531  */
    532 
    533 typedef void
    534 (*cti_prefix_reply_t)(void *NULLABLE context, cti_prefix_vec_t *NULLABLE prefixes, cti_status_t status);
    535 
    536 /* cti_get_prefix_list
    537  *
    538  * Requests wpantund to immediately send the current list of off-mesh prefixes configured in the Thread
    539  * network data.  Whenever the prefix list is updated, the callback will be called again with the new
    540  * information.  A return value of kCTIStatus_NoError means that the caller can expect the reply callback to be
    541  * called at least once.  Any other error means that the request could not be sent, and the callback will
    542  * never be called.
    543  *
    544  * To discontinue receiving prefix add/remove callbacks, the calling program should call
    545  * cti_connection_ref_deallocate on the conn_ref returned by a successful call to get_prefix_list();
    546  *
    547  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
    548  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
    549  *
    550  * context:        An anonymous pointer that will be passed along to the callback when
    551  *                 an event occurs.
    552  *
    553  * callback:       CallBack function for the client that indicates success or failure.
    554  *
    555  * client_queue:   Queue the client wants to schedule the callback on
    556  *
    557  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    558  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    559  *                 that the request succeeded, merely that it was successfully started.
    560  */
    561 
    562 #define cti_get_prefix_list(server, ref, context, callback, client_queue) \
    563     cti_get_prefix_list_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
    564 DNS_SERVICES_EXPORT cti_status_t
    565 cti_get_prefix_list_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref, void *NULLABLE context,
    566                      cti_prefix_reply_t NONNULL callback, run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
    567 
    568 /* cti_state_reply: Callback from cti_get_state()
    569  *
    570  * Called when an error occurs during processing of the cti_get_state call, or when network state
    571  * information is available.
    572  *
    573  * In the case of an error, the callback will not be called again, and the caller is responsible for
    574  * releasing the connection state and restarting if needed.
    575  *
    576  * The callback will be called initially to report the network state, and subsequently whenever the
    577  * network state changes.
    578  *
    579  * cti_reply parameters:
    580  *
    581  * context:           The context that was passed to the cti state call to which this is a callback.
    582  *
    583  * state:             The network state.
    584  *
    585  * status:	          Will be kCTIStatus_NoError if the prefix list request is successful, or
    586  *                    will indicate the failure that occurred.
    587  */
    588 
    589 typedef void
    590 (*cti_state_reply_t)(void *NULLABLE context, cti_network_state_t state, cti_status_t status);
    591 
    592 /* cti_get_state
    593  *
    594  * Requests wpantund to immediately send the current state of the thread network.  Whenever the thread
    595  * network state changes, the callback will be called again with the new state.  A return value of
    596  * kCTIStatus_NoError means that the caller can expect the reply callback to be called at least once.  Any
    597  * other error means that the request could not be sent, and the callback will never be called.
    598  *
    599  * To discontinue receiving state change callbacks, the calling program should call
    600  * cti_connection_ref_deallocate on the conn_ref returned by a successful call to cti_get_state();
    601  *
    602  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
    603  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
    604  *
    605  * context:        An anonymous pointer that will be passed along to the callback when
    606  *                 an event occurs.
    607  *
    608  * callback:       CallBack function for the client that indicates success or failure.
    609  *
    610  * client_queue:   Queue the client wants to schedule the callback on
    611  *
    612  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    613  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    614  *                 that the request succeeded, merely that it was successfully started.
    615  */
    616 
    617 #define cti_get_state(server, ref, context, callback, client_queue) \
    618     cti_get_state_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
    619 DNS_SERVICES_EXPORT cti_status_t
    620 cti_get_state_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref, void *NULLABLE context,
    621                cti_state_reply_t NONNULL callback, run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
    622 
    623 /* cti_uint64_property_reply: Callback from cti_get_partition_id() or cti_get_xpanid()
    624  *
    625  * Called when an error occurs during processing of the cti_get_* call, or when a new value for the requested property
    626  * is available.
    627  *
    628  * In the case of an error, the callback will not be called again, and the caller is responsible for
    629  * releasing the connection and restarting if needed.
    630  *
    631  * The callback will be called initially to report the current value for the property, and subsequently whenever the
    632  * property changes.
    633  *
    634  * cti_uint64_property_reply parameters:
    635  *
    636  * context:           The context that was passed to the cti prefix call to which this is a callback.
    637  *
    638  * property_value     The value of the property (only valid if status is kCTIStatus_NoError).
    639  *
    640  * status:	          Will be kCTIStatus_NoError if the partition ID request is successful, or will indicate the failure
    641  *                    that occurred.
    642  */
    643 
    644 typedef void
    645 (*cti_uint64_property_reply_t)(void *NULLABLE context, uint64_t property_value, cti_status_t status);
    646 
    647 /* cti_get_partition_id
    648  *
    649  * Requests wpantund to immediately send the current partition_id of the thread network.  Whenever the thread
    650  * network partition_id changes, the callback will be called again with the new partition_id.  A return value of
    651  * kCTIStatus_NoError means that the caller can expect the reply callback to be called at least once.  Any
    652  * other error means that the request could not be sent, and the callback will never be called.
    653  *
    654  * To discontinue receiving partition_id change callbacks, the calling program should call
    655  * cti_connection_ref_deallocate on the conn_ref returned by a successful call to cti_get_partition_id();
    656  *
    657  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
    658  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
    659  *
    660  * context:        An anonymous pointer that will be passed along to the callback when
    661  *                 an event occurs.
    662  * callback:       CallBack function for the client that indicates success or failure.
    663  *
    664  * client_queue:   Queue the client wants to schedule the callback on
    665  *
    666  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    667  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    668  *                 that the request succeeded, merely that it was successfully started.
    669  */
    670 
    671 #define cti_get_partition_id(server, ref, context, callback, client_queue) \
    672     cti_get_partition_id_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
    673 DNS_SERVICES_EXPORT cti_status_t
    674 cti_get_partition_id_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref, void *NULLABLE context,
    675                       cti_uint64_property_reply_t NONNULL callback, run_context_t NULLABLE client_queue,
    676                       const char *NONNULL file, int line);
    677 
    678 /* cti_get_extended_pan_id
    679  *
    680  * Requests wpantund to immediately send the current extended_pan_id of the thread network.  Whenever the thread
    681  * network extended_pan_id changes, the callback will be called again with the new extended_pan_id.  A return value of
    682  * kCTIStatus_NoError means that the caller can expect the reply callback to be called at least once.  Any
    683  * other error means that the request could not be sent, and the callback will never be called.
    684  *
    685  * To discontinue receiving extended_pan_id change callbacks, the calling program should call
    686  * cti_connection_ref_deallocate on the conn_ref returned by a successful call to cti_get_extended_pan_id();
    687  *
    688  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
    689  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
    690  *
    691  * context:        An anonymous pointer that will be passed along to the callback when
    692  *                 an event occurs.
    693  * callback:       CallBack function for the client that indicates success or failure.
    694  *
    695  * client_queue:   Queue the client wants to schedule the callback on
    696  *
    697  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    698  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    699  *                 that the request succeeded, merely that it was successfully started.
    700  */
    701 
    702 #define cti_get_extended_pan_id(server, ref, context, callback, client_queue) \
    703     cti_get_extended_pan_id_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
    704 DNS_SERVICES_EXPORT cti_status_t
    705 cti_get_extended_pan_id_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref, void *NULLABLE context,
    706                          cti_uint64_property_reply_t NONNULL callback, run_context_t NULLABLE client_queue,
    707                          const char *NONNULL file, int line);
    708 
    709 /* cti_network_node_type_reply: Callback from cti_get_network_node_type()
    710  *
    711  * Called when an error occurs during processing of the cti_get_network_node_type call, or when network partition ID
    712  * information is available.
    713  *
    714  * In the case of an error, the callback will not be called again, and the caller is responsible for releasing the
    715  * connection network_node_type and restarting if needed.
    716  *
    717  * The callback will be called initially to report the network partition ID, and subsequently whenever the network
    718  * partition ID changes.
    719  *
    720  * cti_reply parameters:
    721  *
    722  * context:           The context that was passed to the cti prefix call to which this is a callback.
    723  *
    724  * network_node_type: The network node type, kCTI_NetworkNodeType_Unknown if it is not known.
    725  *
    726  * status:	          Will be kCTIStatus_NoError if the partition ID request is successful, or will indicate the failure
    727  *                    that occurred.
    728  */
    729 
    730 typedef void
    731 (*cti_network_node_type_reply_t)(void *NULLABLE context, cti_network_node_type_t network_node_type, cti_status_t status);
    732 
    733 /* cti_get_network_node_type
    734  *
    735  * Requests wpantund to immediately send the current network_node_type of the thread network.  Whenever the thread
    736  * network network_node_type changes, the callback will be called again with the new network_node_type.  A return value of
    737  * kCTIStatus_NoError means that the caller can expect the reply callback to be called at least once.  Any
    738  * other error means that the request could not be sent, and the callback will never be called.
    739  *
    740  * To discontinue receiving network_node_type change callbacks, the calling program should call
    741  * cti_connection_ref_deallocate on the conn_ref returned by a successful call to cti_get_network_node_type();
    742  *
    743  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
    744  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
    745  *
    746  * context:        An anonymous pointer that will be passed along to the callback when
    747  *                 an event occurs.
    748  * callback:       CallBack function for the client that indicates success or failure.
    749  *
    750  * client_queue:   Queue the client wants to schedule the callback on
    751  *
    752  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    753  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    754  *                 that the request succeeded, merely that it was successfully started.
    755  */
    756 
    757 #define cti_get_network_node_type(server, ref, context, callback, client_queue) \
    758     cti_get_network_node_type_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
    759 DNS_SERVICES_EXPORT cti_status_t
    760 cti_get_network_node_type_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref, void *NULLABLE context,
    761                            cti_network_node_type_reply_t NONNULL callback, run_context_t NULLABLE client_queue,
    762                            const char *NONNULL file, int line);
    763 
    764 /* cti_add_service
    765  *
    766  * Requests wpantund to add the specified service to the thread network data.  A return value of
    767  * kCTIStatus_NoError means that the caller can expect the reply callback to be called with a success or fail
    768  * status exactly one time.  Any other error means that the request could not be sent, and the callback will
    769  * never be called.
    770  *
    771  * context:           An anonymous pointer that will be passed along to the callback when
    772  *                    an event occurs.
    773  *
    774  * callback:          CallBack function for the client that indicates success or failure.
    775  *
    776  * client_queue:      Queue the client wants to schedule the callback on
    777  *
    778  * enterprise_number: Contains the enterprise number of the service.
    779  *
    780  * service_data:      Typically four bytes, in network byte order, the first two bytes indicate
    781  *                    the type of service within the enterprise' number space, and the second
    782  *                    two bytes indicate the version number.
    783  *
    784  * service_data_len:  The length of the service data in bytes.
    785  *
    786  * server_data:       Typically four bytes, in network byte order, the first two bytes indicate
    787  *                    the type of service within the enterprise' number space, and the second
    788  *                    two bytes indicate the version number.
    789  *
    790  * server_data_len:   The length of the service data in bytes.
    791  *
    792  * return value:      Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    793  *                    the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    794  *                    that the request succeeded, merely that it was successfully started.
    795  */
    796 
    797 #define cti_add_service(server, context, callback, client_queue, \
    798                         enterprise_number, service_data, service_data_length, server_data, server_data_length) \
    799     cti_add_service_(server, context, callback, client_queue, enterprise_number, \
    800                      service_data, service_data_length, server_data, server_data_length, __FILE__, __LINE__)
    801 DNS_SERVICES_EXPORT cti_status_t
    802 cti_add_service_(srp_server_t *NULLABLE server, void *NULLABLE context, cti_reply_t NONNULL callback,
    803                  run_context_t NULLABLE client_queue, uint32_t enterprise_number, const uint8_t *NONNULL service_data,
    804                  size_t service_data_length, const uint8_t *NULLABLE server_data, size_t server_data_length,
    805                  const char *NONNULL file, int line);
    806 
    807 /* cti_remove_service
    808  *
    809  * Requests wpantund to remove the specified service from the thread network data.  A return value of
    810  * kCTIStatus_NoError means that the caller can expect the reply callback to be called with a success or fail
    811  * status exactly one time.  Any other error means that the request could not be sent, and the callback will
    812  * never be called.
    813  *
    814  * context:           An anonymous pointer that will be passed along to the callback when
    815  *                    an event occurs.
    816  *
    817  * callback:          callback function for the client that indicates success or failure.
    818  *
    819  * client_queue:      Queue the client wants to schedule the callback on
    820  *
    821  * enterprise_number: Contains the enterprise number of the service.
    822  *
    823  * service_data:      Typically four bytes, in network byte order, the first two bytes indicate
    824  *                    the type of service within the enterprise' number space, and the second
    825  *                    two bytes indicate the version number.
    826  *
    827  * service_data_len:  The length of the service data in bytes.
    828  *
    829  * return value:      Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    830  *                    the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    831  *                    that the request succeeded, merely that it was successfully started.
    832  */
    833 
    834 #define cti_remove_service(server, context, callback, client_queue, \
    835                            enterprise_number, service_data, service_data_length) \
    836     cti_remove_service_(server, context, callback, client_queue,            \
    837                         enterprise_number, service_data, service_data_length, __FILE__, __LINE__)
    838 DNS_SERVICES_EXPORT cti_status_t
    839 cti_remove_service_(srp_server_t *NULLABLE server, void *NULLABLE context, cti_reply_t NONNULL callback,
    840                     run_context_t NULLABLE client_queue, uint32_t enterprise_number, const uint8_t *NONNULL service_data,
    841                     size_t service_data_length, const char *NONNULL file, int line);
    842 
    843 /* cti_add_prefix
    844  *
    845  * Requests wpantund to add the specified prefix to the set of off-mesh prefixes configured on the thread
    846  * network.  A return value of kCTIStatus_NoError means that the caller can expect the reply callback to be
    847  * called with a success or fail status exactly one time.  Any other error means that the request could not
    848  * be sent, and the callback will never be called.
    849  *
    850  * context:        An anonymous pointer that will be passed along to the callback when
    851  *                 an event occurs.
    852  *
    853  * callback:       CallBack function for the client that indicates success or failure.
    854  *
    855  * client_queue:   Queue the client wants to schedule the callback on
    856  *
    857  * prefix:         A pointer to a struct in6_addr.  Must not be reatained by the callback.
    858  *
    859  * prefix_len:     The length of the prefix in bits.
    860  *
    861  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    862  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    863  *                 that the request succeeded, merely that it was successfully started.
    864  */
    865 
    866 #define cti_add_prefix(server, context, callback, client_queue, \
    867                        prefix, prefix_length, on_mesh, preferred, slaac, stable, priority) \
    868     cti_add_prefix_(server, context, callback, client_queue, prefix, prefix_length, \
    869                     on_mesh, preferred, slaac, stable, priority, __FILE__, __LINE__)
    870 DNS_SERVICES_EXPORT cti_status_t
    871 cti_add_prefix_(srp_server_t *NULLABLE server, void *NULLABLE context, cti_reply_t NONNULL callback, run_context_t NULLABLE client_queue,
    872                 struct in6_addr *NONNULL prefix, int prefix_length, bool on_mesh, bool preferred, bool slaac,
    873                 bool stable, int priority, const char *NONNULL file, int line);
    874 
    875 /* cti_remove_prefix
    876  *
    877  * Requests wpantund to remove the specified prefix from the set of off-mesh prefixes configured on the thread network.
    878  * A return value of kCTIStatus_NoError means that the caller can expect the reply callback to be called with a success
    879  * or fail status exactly one time.  Any other error means that the request could not be sent, and the callback will
    880  * never be called.
    881  *
    882  * context:        An anonymous pointer that will be passed along to the callback when
    883  *                 an event occurs.
    884  *
    885  * callback:       CallBack function for the client that indicates success or failure.
    886  *
    887  * client_queue:   Queue the client wants to schedule the callback on
    888  *
    889  * prefix:         A pointer to a struct in6_addr.  Must not be reatained by the callback.
    890  *
    891  * prefix_len:     The length of the prefix in bits.
    892  *
    893  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    894  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    895  *                 that the request succeeded, merely that it was successfully started.
    896  */
    897 
    898 #define cti_remove_prefix(server, context, callback, client_queue, prefix, prefix_length) \
    899     cti_remove_prefix_(server, context, callback, client_queue, prefix, prefix_length, __FILE__, __LINE__)
    900 DNS_SERVICES_EXPORT cti_status_t
    901 cti_remove_prefix_(srp_server_t *NULLABLE server, void *NULLABLE context, cti_reply_t NONNULL callback,
    902                    run_context_t NULLABLE client_queue, struct in6_addr *NONNULL prefix, int prefix_length,
    903                    const char *NONNULL file, int line);
    904 
    905 /* cti_add_route
    906  *
    907  * Requests wpantund to add the specified route on the thread network.
    908  * A return value of kCTIStatus_NoError means that the caller can expect the reply callback to be
    909  * called with a success or fail status exactly one time.  Any other error means that the request could not
    910  * be sent, and the callback will never be called.
    911  *
    912  * context:        An anonymous pointer that will be passed along to the callback when
    913  *                 an event occurs.
    914  *
    915  * callback:       CallBack function for the client that indicates success or failure.
    916  *
    917  * client_queue:   Queue the client wants to schedule the callback on
    918  *
    919  * prefix:         A pointer to a struct in6_addr.
    920  *
    921  * prefix_len:     The length of the prefix in bits.
    922  *
    923  * priority:       Route priority (>0 for high, 0 for medium, <0 for low).
    924  *
    925  * domain_id:      Domain id for the route (default is zero).
    926  *
    927  * stable:         True if the route is part of stable network data.
    928  *
    929  * nat64:          True if this is NAT64 prefix.
    930  *
    931  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    932  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    933  *                 that the request succeeded, merely that it was successfully started.
    934  */
    935 
    936 #define cti_add_route(server, context, callback, client_queue, \
    937                        prefix, prefix_length, priority, domain_id, stable, nat64) \
    938     cti_add_route_(server, context, callback, client_queue, prefix, prefix_length, \
    939                     priority, domain_id, stable, nat64, __FILE__, __LINE__)
    940 DNS_SERVICES_EXPORT cti_status_t
    941 cti_add_route_(srp_server_t *NULLABLE server, void *NULLABLE context, cti_reply_t NONNULL callback,
    942                run_context_t NULLABLE client_queue, struct in6_addr *NONNULL prefix, int prefix_length,
    943                int priority, int domain_id, bool stable, bool nat64, const char *NONNULL file, int line);
    944 
    945 /* cti_remove_route
    946  *
    947  * Requests wpantund to remove the specified route on the thread network.
    948  * A return value of kCTIStatus_NoError means that the caller can expect the reply callback to be called with a success
    949  * or fail status exactly one time.  Any other error means that the request could not be sent, and the callback will
    950  * never be called.
    951  *
    952  * context:        An anonymous pointer that will be passed along to the callback when
    953  *                 an event occurs.
    954  *
    955  * callback:       CallBack function for the client that indicates success or failure.
    956  *
    957  * client_queue:   Queue the client wants to schedule the callback on
    958  *
    959  * prefix:         A pointer to a struct in6_addr.
    960  *
    961  * prefix_len:     The length of the prefix in bits.
    962  *
    963  * domain_id:      Domain id for the route (default is zero).
    964  *
    965  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
    966  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
    967  *                 that the request succeeded, merely that it was successfully started.
    968  */
    969 
    970 #define cti_remove_route(server, context, callback, client_queue, prefix, prefix_length, domain_id) \
    971     cti_remove_route_(server, context, callback, client_queue, prefix, prefix_length, domain_id, __FILE__, __LINE__)
    972 DNS_SERVICES_EXPORT cti_status_t
    973 cti_remove_route_(srp_server_t *NULLABLE server, void *NULLABLE context, cti_reply_t NONNULL callback,
    974                   run_context_t NULLABLE client_queue, struct in6_addr *NONNULL prefix, int prefix_length,
    975                   int domain_id, const char *NONNULL file, int line);
    976 
    977 /*
    978  * cti_route_vec_create
    979  *
    980  * creates a route array vector of specified length
    981  *
    982  * num_routes:    Number of route slots available in the route vector.
    983  *
    984  * return value:  NULL, if the call failed; otherwise a prefix vector capable of containing the
    985  *                requested number of routes.
    986  */
    987 cti_route_vec_t *NULLABLE
    988 cti_route_vec_create_(size_t num_routes, const char *NONNULL file, int line);
    989 #define cti_route_vec_create(num_routes) cti_route_vec_create_(num_routes, __FILE__, __LINE__)
    990 
    991 /*
    992  * cti_route_vec_release
    993  *
    994  * decrements the reference count on the provided route vector and, if it reaches zero, finalizes the route vector,
    995  * which calls cti_route_release on each route in the vector, potentially also finalizing them.
    996  *
    997  * num_routes:     Number of route slots available in the route vector.
    998  *
    999  * return value:   NULL, if the call failed; otherwise a route vector capable of containing the
   1000  *                 requested number of routes.
   1001  */
   1002 
   1003 void
   1004 cti_route_vec_release_(cti_route_vec_t *NONNULL routes, const char *NONNULL file, int line);
   1005 #define cti_route_vec_release(routes) cti_route_vec_release_(routes, __FILE__, __LINE__)
   1006 
   1007 /*
   1008  * cti_route_create
   1009  *
   1010  * Creates a cti_route_t containing the specified information. The route is retained, and will be
   1011  * freed using free() when the route object is finalized. Caller must not retain or free these values, and
   1012  * they must be allocated on the malloc heap.
   1013  *
   1014  * prefix:            A pointer to a struct in6_addr.
   1015  *
   1016  * prefix_len:        The length of the prefix in bits.
   1017  *
   1018  * origin:            User or ncp.
   1019  *
   1020  * nat64:             True if this is NAT64 prefix.
   1021  *
   1022  * stable:            True if the route is part of stable network data.
   1023  *
   1024  * preference:        Route priority.
   1025  *
   1026  * rloc:              Routing locator.
   1027  *
   1028  * next_hop_is_host:  True if next hop is host.
   1029  *
   1030  * return value:      NULL, if the call failed; otherwise a route object containing the specified state.
   1031  */
   1032 
   1033 cti_route_t *NULLABLE
   1034 cti_route_create_(struct in6_addr *NONNULL prefix, int prefix_length, offmesh_route_origin_t origin,
   1035                   bool nat64, bool stable, offmesh_route_preference_t preference, int rloc,
   1036                   bool next_hop_is_host, const char *NONNULL file, int line);
   1037 #define cti_route_create(prefix, prefix_length, origin, nat64, stable, preference, rloc, next_hop_is_host) \
   1038     cti_route_create_(prefix, prefix_length, origin, nat64, stable, preference, rloc, next_hop_is_host, __FILE__, __LINE__)
   1039 
   1040 /*
   1041  * cti_route_release
   1042  *
   1043  * Decrements the reference count on the provided route vector and, if it reaches zero, finalizes the route vector,
   1044  * which calls cti_route_release on each route in the vector, potentially also finalizing them.
   1045  *
   1046  * routes:           The route vector to release.
   1047  *
   1048  * return value:     NULL, if the call failed; otherwise a route vector capable of containing the requested number of
   1049  *                   routes.
   1050  */
   1051 
   1052 void
   1053 cti_route_release_(cti_route_t *NONNULL route, const char *NONNULL file, int line);
   1054 #define cti_route_release(routes) cti_route_release(route, __FILE__, __LINE__)
   1055 
   1056 /* cti_offmesh_route_reply: Callback from cti_get_offmesh_route_list()
   1057  *
   1058  * Called when an error occurs during processing of the cti_get_offmesh_route_list call, or when a route
   1059  * is added or removed.
   1060  *
   1061  * In the case of an error, the callback will not be called again, and the caller is responsible for
   1062  * releasing the connection state and restarting if needed.
   1063  *
   1064  * The callback will be called once for each offmesh route present on the Thread network at the time
   1065  * cti_get_offmesh_prefix_list() is first called, and then again whenever a route is added or removed.
   1066  *
   1067  * cti_offmesh_route_reply parameters:
   1068  *
   1069  * context:           The context that was passed to the cti_get_offmesh_route_list call to which this is a callback.
   1070  *
   1071  * route_vec:         If status is kCTIStatus_NoError, a vector containing all of the routes that were reported in
   1072  *                    this event.
   1073  *
   1074  * status:	          Will be kCTIStatus_NoError if the offmesh route list request is successful, or
   1075  *                    will indicate the failure that occurred.
   1076  */
   1077 
   1078 typedef void
   1079 (*cti_offmesh_route_reply_t)(void *NULLABLE context, cti_route_vec_t *NULLABLE routes, cti_status_t status);
   1080 
   1081 /* cti_get_offmesh_route_list
   1082  *
   1083  * Requests wpantund to immediately send the current list of off-mesh routes configured in the Thread
   1084  * network data.  Whenever the route list is updated, the callback will be called again with the new
   1085  * information.  A return value of kCTIStatus_NoError means that the caller can expect the reply callback to be
   1086  * called at least once.  Any other error means that the request could not be sent, and the callback will
   1087  * never be called.
   1088  *
   1089  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
   1090  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
   1091  *
   1092  * context:        An anonymous pointer that will be passed along to the callback when
   1093  *                 an event occurs.
   1094  *
   1095  * callback:       CallBack function for the client that indicates success or failure.
   1096  *
   1097  * client_queue:   Queue the client wants to schedule the callback on
   1098  *
   1099  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
   1100  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
   1101  *                 that the request succeeded, merely that it was successfully started.
   1102  */
   1103 
   1104 #define cti_get_offmesh_route_list(server, ref, context, callback, client_queue) \
   1105     cti_get_offmesh_route_list_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
   1106 DNS_SERVICES_EXPORT cti_status_t
   1107 cti_get_offmesh_route_list_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref,
   1108                             void *NULLABLE context, cti_offmesh_route_reply_t NONNULL callback,
   1109                             run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
   1110 
   1111 /* cti_onmesh_prefix_reply: Callback from cti_get_onmesh_prefix_list()
   1112  *
   1113  * Called when an error occurs during processing of the cti_get_onmesh_prefix_list call, or when a route
   1114  * is added or removed.
   1115  *
   1116  * In the case of an error, the callback will not be called again, and the caller is responsible for
   1117  * releasing the connection state and restarting if needed.
   1118  *
   1119  * The callback will be called once for each offmesh route present on the Thread network at the time
   1120  * cti_get_offmesh_prefix_list() is first called, and then again whenever a route is added or removed.
   1121  *
   1122  * cti_onmesh_prefix_reply parameters:
   1123  *
   1124  * context:           The context that was passed to the cti_get_onmesh_prefix_list call to which this is a callback.
   1125  *
   1126  * prefix_vec:        If status is kCTIStatus_NoError, a vector containing all of the prefixes that were reported in
   1127  *                    this event.
   1128  *
   1129  * status:	          Will be kCTIStatus_NoError if the onmesh prefix list request is successful, or
   1130  *                    will indicate the failure that occurred.
   1131  */
   1132 
   1133 typedef void
   1134 (*cti_onmesh_prefix_reply_t)(void *NULLABLE context, cti_prefix_vec_t *NULLABLE routes, cti_status_t status);
   1135 
   1136 /* cti_get_onmesh_prefix_list
   1137  *
   1138  * Requests wpantund to immediately send the current list of on-mesh prefixes configured in the Thread
   1139  * network data.  Whenever the prefix list is updated, the callback will be called again with the new
   1140  * information.  A return value of kCTIStatus_NoError means that the caller can expect the reply callback to be
   1141  * called at least once.  Any other error means that the request could not be sent, and the callback will
   1142  * never be called.
   1143  *
   1144  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
   1145  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
   1146  *
   1147  * context:        An anonymous pointer that will be passed along to the callback when
   1148  *                 an event occurs.
   1149  *
   1150  * callback:       CallBack function for the client that indicates success or failure.
   1151  *
   1152  * client_queue:   Queue the client wants to schedule the callback on
   1153  *
   1154  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
   1155  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
   1156  *                 that the request succeeded, merely that it was successfully started.
   1157  */
   1158 
   1159 #define cti_get_onmesh_prefix_list(server, ref, context, callback, client_queue) \
   1160     cti_get_onmesh_prefix_list_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
   1161 DNS_SERVICES_EXPORT cti_status_t
   1162 cti_get_onmesh_prefix_list_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref,
   1163                             void *NULLABLE context, cti_onmesh_prefix_reply_t NONNULL callback,
   1164                             run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
   1165 
   1166 /* cti_rloc16_reply: Callback from cti_get_rloc16()
   1167  *
   1168  * Called when an error occurs during processing of the cti_get_rloc16 call, or when rloc16
   1169  * is updated.
   1170  *
   1171  * In the case of an error, the callback will not be called again, and the caller is responsible for
   1172  * releasing the connection state and restarting if needed.
   1173  *
   1174  * The callback will be called initially to report the current value for the property, and subsequently
   1175  * whenever the property changes.
   1176  *
   1177  * cti_rloc16_reply parameters:
   1178  *
   1179  * context:           The context that was passed to the cti call to which this is a callback.
   1180  *
   1181  * rloc16:            The rloc16 value(only valid if status is kCTIStatus_NoError).
   1182  *
   1183  * status:            Will be kCTIStatus_NoError if the rloc16 request is successful, or will indicate the failure
   1184  *                    that occurred.
   1185  */
   1186 typedef void
   1187 (*cti_rloc16_reply_t)(void *NULLABLE context, uint16_t rloc16, cti_status_t status);
   1188 
   1189 /* cti_get_rloc16
   1190  *
   1191  * Requests wpantund to immediately send the rloc16 of the local device. Whenever the RLOC16
   1192  * changes, the callback will be called again with the new RLOC16.  A return value of
   1193  * kCTIStatus_NoError means that the caller can expect the reply callback to be called at least once.  Any
   1194  * other error means that the request could not be sent, and the callback will never be called.
   1195  *
   1196  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
   1197  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
   1198  *
   1199  * context:        An anonymous pointer that will be passed along to the callback when
   1200  *                 an event occurs.
   1201  * callback:       CallBack function for the client that indicates success or failure.
   1202  *
   1203  * client_queue:   Queue the client wants to schedule the callback on
   1204  *
   1205  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
   1206  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
   1207  *                 that the request succeeded, merely that it was successfully started.
   1208  */
   1209 #define cti_get_rloc16(server, ref, context, callback, client_queue) \
   1210     cti_get_rloc16_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
   1211 
   1212 DNS_SERVICES_EXPORT cti_status_t
   1213 cti_get_rloc16_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref,
   1214                 void *NULLABLE context, cti_rloc16_reply_t NONNULL callback,
   1215                 run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
   1216 
   1217 /* cti_active_data_set_change_reply: Callback from cti_get_active_data_set_change()
   1218  *
   1219  * Called when an error occurs during processing of the cti_get_active_data_set_change call, or when the active data set
   1220  * is updated.
   1221  *
   1222  * In the case of an error, the callback will not be called again, and the caller is responsible for
   1223  * releasing the connection state and restarting if needed.
   1224  *
   1225  * The callback will be called whenever the active data set changes.
   1226  *
   1227  * cti_active_data_set_change_reply parameters:
   1228  *
   1229  * context:           The context that was passed to the cti call to which this is a callback.
   1230  *
   1231  * status:            Will be kCTIStatus_NoError if the active_data_set_change request is successful, or will indicate the failure
   1232  *                    that occurred.
   1233  */
   1234 typedef void
   1235 (*cti_reply_t)(void *NULLABLE context, cti_status_t status);
   1236 
   1237 /* cti_get_active_data_set_change
   1238  *
   1239  * Requests wpantund to immediately send the active_data_set_change of the local device. Whenever the ACTIVE_DATA_SET_CHANGE
   1240  * changes, the callback will be called again with the new ACTIVE_DATA_SET_CHANGE.  A return value of
   1241  * kCTIStatus_NoError means that the caller can expect the reply callback to be called at least once.  Any
   1242  * other error means that the request could not be sent, and the callback will never be called.
   1243  *
   1244  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
   1245  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
   1246  *
   1247  * context:        An anonymous pointer that will be passed along to the callback when
   1248  *                 an event occurs.
   1249  * callback:       CallBack function for the client that indicates success or failure.
   1250  *
   1251  * client_queue:   Queue the client wants to schedule the callback on
   1252  *
   1253  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
   1254  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
   1255  *                 that the request succeeded, merely that it was successfully started.
   1256  */
   1257 #define cti_track_active_data_set(server, ref, context, callback, client_queue) \
   1258     cti_track_active_data_set_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
   1259 
   1260 DNS_SERVICES_EXPORT cti_status_t
   1261 cti_track_active_data_set_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref,
   1262                 void *NULLABLE context, cti_reply_t NONNULL callback,
   1263                 run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
   1264 
   1265 /* cti_wed_change_reply: Callback from cti_get_wed_change()
   1266  *
   1267  * Called when an error occurs during processing of the cti_get_wed_change call, or when the active data set
   1268  * is updated.
   1269  *
   1270  * In the case of an error, the callback will not be called again, and the caller is responsible for
   1271  * releasing the connection state and restarting if needed.
   1272  *
   1273  * The callback will be called whenever the active data set changes.
   1274  *
   1275  * cti_wed_change_reply parameters:
   1276  *
   1277  * context:           The context that was passed to the cti call to which this is a callback.
   1278  *
   1279  * status:            Will be kCTIStatus_NoError if the wed_change request is successful, or will indicate the failure
   1280  *                    that occurred.
   1281  */
   1282 typedef void
   1283 (*cti_reply_t)(void *NULLABLE context, cti_status_t status);
   1284 
   1285 /* cti_wed_reply: Callback for get calls that fetch the current WED status
   1286  *
   1287  * Called one or more times in response to a cti_track_wed_status() call, either with an error or with the current WED status.
   1288  *
   1289  * cti_wed_reply parameters:
   1290  *
   1291  * context:       The context that was passed to the cti service call to which this is a callback.
   1292  *
   1293  * ext_address:   If error is kCTIStatus_NoError, a string containing the name of the ext address.
   1294  *
   1295  * ml_eid:        If error is kCTIStatus_NoError, a string containing the ML-EID
   1296  *
   1297  * added:         If true, this was added; otherwise it was removed.
   1298  *
   1299  * status:	      Will be kCTIStatus_NoError on success, otherwise will indicate the
   1300  * 			      failure that occurred.
   1301  */
   1302 
   1303 typedef void
   1304 (*cti_wed_reply_t)(void *NULLABLE context, const char *NULLABLE ext_address, const char *NULLABLE ml_eid, bool added,
   1305                    cti_status_t status);
   1306 
   1307 /* cti_get_wed_change
   1308  *
   1309  * Requests wpantund to immediately send the WED attachment status of the local device. Whenever the WED attachment
   1310  * status changes, the callback will be called again with the new status.  A return value of kCTIStatus_NoError means
   1311  * that the caller can expect the reply callback to be called at least once.  Any other error means that the request
   1312  * could not be sent, and the callback will never be called.
   1313  *
   1314  * ref:            A pointer to a reference to the connection is stored through ref if ref is not NULL.
   1315  *                 When events are no longer needed, call cti_discontinue_events() on the returned pointer.
   1316  *
   1317  * context:        An anonymous pointer that will be passed along to the callback when
   1318  *                 an event occurs.
   1319  *
   1320  * callback:       CallBack function for the client that indicates success or failure, and on success
   1321  *                 indicates attachment to a Wake-on End Device (WED).
   1322  *
   1323  * client_queue:   Queue the client wants to schedule the callback on
   1324  *
   1325  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
   1326  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
   1327  *                 that the request succeeded, merely that it was successfully started.
   1328  */
   1329 #define cti_track_wed_status(server, ref, context, callback, client_queue) \
   1330     cti_track_wed_status_(server, ref, context, callback, client_queue, __FILE__, __LINE__)
   1331 
   1332 DNS_SERVICES_EXPORT cti_status_t
   1333 cti_track_wed_status_(srp_server_t *NULLABLE server, cti_connection_t NULLABLE *NULLABLE ref,
   1334                       void *NULLABLE context, cti_wed_reply_t NONNULL callback,
   1335                       run_context_t NULLABLE client_queue, const char *NONNULL file, int line);
   1336 
   1337 /* cti_add_ml_eid_mapping
   1338  *
   1339  * Provides the thread daemon with a mapping between an IP address registered by an SRP client and
   1340  * the source address from which the registration was received, which will be the client's ml-eid.
   1341  * Additionally provides the client's hostname.
   1342  *
   1343  * context:        An anonymous pointer that will be passed along to the callback when
   1344  *                 an event occurs.
   1345  *
   1346  * callback:       CallBack function for the client that indicates success or failure, and on success
   1347  *                 indicates that the update was accepted by the thread daemon.
   1348  *
   1349  * omr_addr:       IP address on the OMR prefix registered by the client.
   1350  *
   1351  * ml_eid:         IP address on the mesh-local prefix of the client.
   1352  *
   1353  * client_queue:   Queue the client wants to schedule the callback on
   1354  *
   1355  *
   1356  * return value:   Returns kCTIStatus_NoError when no error otherwise returns an error code indicating
   1357  *                 the error that occurred. Note: A return value of kCTIStatus_NoError does not mean
   1358  *                 that the request succeeded, merely that it was successfully started.
   1359  */
   1360 #define cti_add_ml_eid_mapping(server, context, callback, client_queue, omr_addr, ml_eid, hostname) \
   1361     cti_add_ml_eid_mapping_(server, context, callback, client_queue, omr_addr, ml_eid, hostname, __FILE__, __LINE__)
   1362 
   1363 DNS_SERVICES_EXPORT cti_status_t
   1364 cti_add_ml_eid_mapping_(srp_server_t *NULLABLE server, void *NULLABLE context,
   1365                         cti_reply_t NONNULL callback, run_context_t NULLABLE client_queue,
   1366                         struct in6_addr *NONNULL omr_addr, struct in6_addr *NONNULL ml_eid,
   1367                         const char *NONNULL hostname, const char *NONNULL file, int line);
   1368 
   1369 /* cti_events_discontinue
   1370  *
   1371  * Requests that the CTI library stop delivering events on the specified connection.   The connection will have
   1372  * been returned by a CTI library call that subscribes to events.
   1373  */
   1374 DNS_SERVICES_EXPORT cti_status_t
   1375 cti_events_discontinue(cti_connection_t NONNULL ref);
   1376 
   1377 typedef union cti_callback {
   1378     cti_reply_t NULLABLE reply;
   1379     cti_string_property_reply_t NONNULL string_property_reply;
   1380     cti_service_reply_t NONNULL service_reply;
   1381     cti_prefix_reply_t NONNULL prefix_reply;
   1382     cti_state_reply_t NONNULL state_reply;
   1383     cti_uint64_property_reply_t NONNULL uint64_property_reply;
   1384     cti_network_node_type_reply_t NONNULL network_node_type_reply;
   1385     cti_offmesh_route_reply_t NONNULL offmesh_route_reply;
   1386     cti_onmesh_prefix_reply_t NONNULL onmesh_prefix_reply;
   1387     cti_rloc16_reply_t NONNULL rloc16_reply;
   1388     cti_wed_reply_t NONNULL wed_reply;
   1389 } cti_callback_t;
   1390 
   1391 #endif /* __CTI_SERVICES_H__ */
   1392 
   1393 // Local Variables:
   1394 // mode: C
   1395 // tab-width: 4
   1396 // c-file-style: "bsd"
   1397 // c-basic-offset: 4
   1398 // fill-column: 120
   1399 // indent-tabs-mode: nil
   1400 // End:
   1401