xref: /btstack/src/ble/gatt_client.h (revision e9cdf30bbcdc3ad1eebaf0d535ba80c0cc39a66b)
1 /*
2  * Copyright (C) 2014 BlueKitchen GmbH
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the copyright holders nor the names of
14  *    contributors may be used to endorse or promote products derived
15  *    from this software without specific prior written permission.
16  * 4. Any redistribution, use, or modification is done solely for
17  *    personal benefit and not for any commercial purpose or for
18  *    monetary gain.
19  *
20  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
24  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * Please inquire about commercial licensing options at
34  * [email protected]
35  *
36  */
37 
38 /**
39  * @title GATT Client
40  *
41  */
42 
43 #ifndef btstack_gatt_client_h
44 #define btstack_gatt_client_h
45 
46 #include "hci.h"
47 
48 #if defined __cplusplus
49 extern "C" {
50 #endif
51 
52 typedef enum {
53     P_READY,
54     P_W2_SEND_SERVICE_QUERY,
55     P_W4_SERVICE_QUERY_RESULT,
56     P_W2_SEND_SERVICE_WITH_UUID_QUERY,
57     P_W4_SERVICE_WITH_UUID_RESULT,
58 
59     P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY,
60     P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT,
61     P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY,
62     P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT,
63 
64     P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY,
65     P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT,
66 
67     P_W2_SEND_INCLUDED_SERVICE_QUERY,
68     P_W4_INCLUDED_SERVICE_QUERY_RESULT,
69     P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY,
70     P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT,
71 
72     P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY,
73     P_W4_READ_CHARACTERISTIC_VALUE_RESULT,
74 
75     P_W2_SEND_READ_BLOB_QUERY,
76     P_W4_READ_BLOB_RESULT,
77 
78     P_W2_SEND_READ_BY_TYPE_REQUEST,
79     P_W4_READ_BY_TYPE_RESPONSE,
80 
81     P_W2_SEND_READ_MULTIPLE_REQUEST,
82     P_W4_READ_MULTIPLE_RESPONSE,
83 
84     P_W2_SEND_WRITE_CHARACTERISTIC_VALUE,
85     P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT,
86 
87     P_W2_PREPARE_WRITE,
88     P_W4_PREPARE_WRITE_RESULT,
89     P_W2_PREPARE_RELIABLE_WRITE,
90     P_W4_PREPARE_RELIABLE_WRITE_RESULT,
91 
92     P_W2_EXECUTE_PREPARED_WRITE,
93     P_W4_EXECUTE_PREPARED_WRITE_RESULT,
94     P_W2_CANCEL_PREPARED_WRITE,
95     P_W4_CANCEL_PREPARED_WRITE_RESULT,
96     P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH,
97     P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT,
98 
99 #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY
100     P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
101     P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
102 #else
103     P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
104     P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
105 #endif
106     P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION,
107     P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT,
108 
109     P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY,
110     P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT,
111 
112     P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY,
113     P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT,
114 
115     P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR,
116     P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
117 
118     // all long writes use this
119     P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR,
120     P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
121     P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR,
122     P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
123 
124     // gatt reliable write API use this (manual version of the above)
125     P_W2_PREPARE_WRITE_SINGLE,
126     P_W4_PREPARE_WRITE_SINGLE_RESULT,
127 
128     P_W4_IDENTITY_RESOLVING,
129     P_W4_CMAC_READY,
130     P_W4_CMAC_RESULT,
131     P_W2_SEND_SIGNED_WRITE,
132     P_W4_SEND_SINGED_WRITE_DONE,
133 
134     P_W2_SDP_QUERY,
135     P_W4_SDP_QUERY,
136     P_W4_L2CAP_CONNECTION,
137 } gatt_client_state_t;
138 
139 
140 typedef enum{
141     SEND_MTU_EXCHANGE,
142     SENT_MTU_EXCHANGE,
143     MTU_EXCHANGED,
144     MTU_AUTO_EXCHANGE_DISABLED
145 } gatt_client_mtu_t;
146 
147 typedef struct gatt_client{
148     btstack_linked_item_t    item;
149     // TODO: rename gatt_client_state -> state
150     gatt_client_state_t gatt_client_state;
151 
152     // user callback
153     btstack_packet_handler_t callback;
154 
155     // can write without response callback
156     btstack_packet_handler_t write_without_response_callback;
157 
158     // can write without response requests
159     btstack_linked_list_t write_without_response_requests;
160 
161     // regular gatt query requests
162     btstack_linked_list_t query_requests;
163 
164     hci_con_handle_t con_handle;
165 
166     att_bearer_type_t bearer_type;
167 
168 #ifdef ENABLE_GATT_OVER_CLASSIC
169     bd_addr_t addr;
170     uint16_t  l2cap_psm;
171     uint16_t  l2cap_cid;
172     btstack_context_callback_registration_t sdp_query_request;
173 #endif
174 
175     uint16_t          mtu;
176     gatt_client_mtu_t mtu_state;
177 
178     uint16_t uuid16;
179     uint8_t  uuid128[16];
180 
181     uint16_t start_group_handle;
182     uint16_t end_group_handle;
183 
184     uint16_t query_start_handle;
185     uint16_t query_end_handle;
186 
187     uint8_t  characteristic_properties;
188     uint16_t characteristic_start_handle;
189 
190     uint16_t attribute_handle;
191     uint16_t attribute_offset;
192     uint16_t attribute_length;
193     uint8_t* attribute_value;
194 
195     // read multiple characteristic values
196     uint16_t    read_multiple_handle_count;
197     uint16_t  * read_multiple_handles;
198 
199     uint16_t client_characteristic_configuration_handle;
200     uint8_t  client_characteristic_configuration_value[2];
201 
202     uint8_t  filter_with_uuid;
203     uint8_t  send_confirmation;
204 
205     int      le_device_index;
206     uint8_t  cmac[8];
207 
208     btstack_timer_source_t gc_timeout;
209 
210     uint8_t  security_counter;
211     uint8_t  wait_for_authentication_complete;
212     uint8_t  pending_error_code;
213 
214     bool     reencryption_active;
215     uint8_t  reencryption_result;
216 
217     gap_security_level_t security_level;
218 
219 } gatt_client_t;
220 
221 typedef struct gatt_client_notification {
222     btstack_linked_item_t    item;
223     btstack_packet_handler_t callback;
224     hci_con_handle_t con_handle;
225     uint16_t attribute_handle;
226 } gatt_client_notification_t;
227 
228 /* API_START */
229 
230 typedef struct {
231     uint16_t start_group_handle;
232     uint16_t end_group_handle;
233     uint16_t uuid16;
234     uint8_t  uuid128[16];
235 } gatt_client_service_t;
236 
237 typedef struct {
238     uint16_t start_handle;
239     uint16_t value_handle;
240     uint16_t end_handle;
241     uint16_t properties;
242     uint16_t uuid16;
243     uint8_t  uuid128[16];
244 } gatt_client_characteristic_t;
245 
246 typedef struct {
247     uint16_t handle;
248     uint16_t uuid16;
249     uint8_t  uuid128[16];
250 } gatt_client_characteristic_descriptor_t;
251 
252 /**
253  * @brief Set up GATT client.
254  */
255 void gatt_client_init(void);
256 
257 /**
258  * @brief Set minimum required security level for GATT Client
259  * @note  The Bluetooth specification makes the GATT Server responsible to check for security.
260  *        This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part.
261  *        If your application is exchanging sensitive data with a remote device, you would need to manually check
262  *        the security level before sending/receive such data.
263  *        With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange
264  *        until the required security level is established.
265  *        gatt_client_request_can_write_without_response_event does not trigger authentication
266  *        gatt_client_request_to_write_without_response does not trigger authentication
267  *  @pram level, default LEVEL_0 (no encryption required)
268  */
269 void gatt_client_set_required_security_level(gap_security_level_t level);
270 
271 /**
272  * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection
273  *        GATT_EVENT_CONNECTED with status and con_handle for other API functions
274  *        is emitted on connection complete.
275  * @note requires ENABLE_GATT_OVER_CLASSIC.
276  * @param addr
277  * @return status
278  */
279 uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr);
280 
281 /**
282  * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server
283  * @note requires ENABLE_GATT_OVER_CLASSIC
284  * @param con_handle
285  * @return status
286  */
287 uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
288 
289 /**
290  * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value,
291  * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h).
292  * @param  con_handle
293  * @param  mtu
294  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
295  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
296  *                GATT_CLIENT_IN_WRONG_STATE                                if MTU is not exchanged and MTU auto-exchange is disabled
297  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
298  */
299 uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu);
300 
301 /**
302  * @brief Sets whether a MTU Exchange Request shall be automatically send before the
303  * first attribute read request is send. Default is enabled.
304  * @param enabled
305  */
306 void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled);
307 
308 /**
309  * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU
310  * when gatt_client_mtu_enable_auto_negotiation is disabled.
311  * @param  callback
312  * @param  con_handle
313  */
314 void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
315 
316 /**
317  * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon.
318  * @param  con_handle
319  * @return is_ready_status     0 - if no GATT client for con_handle is found, or is not ready, otherwise 1
320  */
321 int gatt_client_is_ready(hci_con_handle_t con_handle);
322 
323 /**
324  * @brief Discovers all primary services.
325  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
326  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
327  * @param  callback
328  * @param  con_handle
329  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
330  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
331  *                ERROR_CODE_SUCCESS         , if query is successfully registered
332  */
333 uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
334 
335 /**
336  * @brief Discovers all secondary services.
337  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
338  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
339  * @param  callback
340  * @param  con_handle
341  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
342  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
343  *                ERROR_CODE_SUCCESS         , if query is successfully registered
344  */
345 uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
346 
347 /**
348  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
349  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
350  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
351  * @param callback
352  * @param con_handle
353  * @param uuid16
354  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
355  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
356  *                ERROR_CODE_SUCCESS         , if query is successfully registered
357  */
358 uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16);
359 
360 /**
361  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
362  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
363  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
364  * @param  callback
365  * @param  con_handle
366  * @param  uuid128
367  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
368  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
369  *                ERROR_CODE_SUCCESS         , if query is successfully registered
370  */
371 uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, const uint8_t * uuid128);
372 
373 /**
374  * @brief Finds included services within the specified service.
375  * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted.
376  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
377  * Information about included service type (primary/secondary) can be retrieved either by sending
378  * an ATT find information request for the returned start group handle
379  * (returning the handle and the UUID for primary or secondary service) or by comparing the service
380  * to the list of all primary services.
381  * @param  callback
382  * @param  con_handle
383  * @param  service
384  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
385  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
386  *                ERROR_CODE_SUCCESS         , if query is successfully registered
387  */
388 uint8_t gatt_client_find_included_services_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service);
389 
390 /**
391  * @brief Discovers all characteristics within the specified service.
392  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited.
393  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
394  * @param  callback
395  * @param  con_handle
396  * @param  service
397  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
398  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
399  *                ERROR_CODE_SUCCESS         , if query is successfully registered
400  */
401 uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service);
402 
403 /**
404  * @brief The following four functions are used to discover all characteristics within
405  * the specified service or handle range, and return those that match the given UUID.
406  *
407  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
408  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
409  * @param  callback
410  * @param  con_handle
411  * @param  start_handle
412  * @param  end_handle
413  * @param  uuid16
414  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
415  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
416  *                ERROR_CODE_SUCCESS         , if query is successfully registered
417  */
418 uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
419 
420 /**
421  * @brief The following four functions are used to discover all characteristics within the
422  * specified service or handle range, and return those that match the given UUID.
423  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
424  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
425  * @param  callback
426  * @param  con_handle
427  * @param  start_handle
428  * @param  end_handle
429  * @param  uuid128
430  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
431  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
432  *                ERROR_CODE_SUCCESS         , if query is successfully registered
433  */
434 uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, const uint8_t * uuid128);
435 
436 /**
437  * @brief The following four functions are used to discover all characteristics within the
438  * specified service or handle range, and return those that match the given UUID.
439  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
440  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
441  * @param  callback
442  * @param  con_handle
443  * @param  service
444  * @param  uuid16
445  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
446  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
447  *                ERROR_CODE_SUCCESS         , if query is successfully registered
448  */
449 uint8_t gatt_client_discover_characteristics_for_service_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service, uint16_t uuid16);
450 
451 /**
452  * @brief The following four functions are used to discover all characteristics within the
453  * specified service or handle range, and return those that match the given UUID.
454  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
455  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
456  * @param  callback
457  * @param  con_handle
458  * @param  service
459  * @param  uuid128
460  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
461  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
462  *                ERROR_CODE_SUCCESS         , if query is successfully registered
463  */
464 uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service, const uint8_t * uuid128);
465 
466 /**
467  * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic.
468  * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted.
469  *
470  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
471  * @param  callback
472  * @param  con_handle
473  * @param  characteristic
474  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
475  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
476  *                ERROR_CODE_SUCCESS         , if query is successfully registered
477  */
478 uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
479 
480 /**
481  * @brief Reads the characteristic value using the characteristic's value handle.
482  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
483  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
484  * @param  callback
485  * @param  con_handle
486  * @param  characteristic
487  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
488  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
489  *                ERROR_CODE_SUCCESS         , if query is successfully registered
490  */
491 uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
492 
493 /**
494  * @brief Reads the characteristic value using the characteristic's value handle.
495  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
496  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
497  * @param  callback
498  * @param  con_handle
499  * @param  value_handle
500  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
501  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
502  *                ERROR_CODE_SUCCESS         , if query is successfully registered
503  */
504 uint8_t gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle);
505 
506 /**
507  * @brief Reads the characteric value of all characteristics with the uuid.
508  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
509  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
510  * @param  callback
511  * @param  con_handle
512  * @param  start_handle
513  * @param  end_handle
514  * @param  uuid16
515  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
516  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
517  *                ERROR_CODE_SUCCESS         , if query is successfully registered
518  */
519 uint8_t gatt_client_read_value_of_characteristics_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
520 
521 /**
522  * @brief Reads the characteric value of all characteristics with the uuid.
523  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
524  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
525  * @param  callback
526  * @param  con_handle
527  * @param  start_handle
528  * @param  end_handle
529  * @param  uuid128
530  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
531  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
532  *                ERROR_CODE_SUCCESS         , if query is successfully registered
533  */
534 uint8_t gatt_client_read_value_of_characteristics_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t start_handle, uint16_t end_handle, const uint8_t * uuid128);
535 
536 /**
537  * @brief Reads the long characteristic value using the characteristic's value handle.
538  * The value will be returned in several blobs.
539  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
540  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
541  * @param  callback
542  * @param  con_handle
543  * @param  characteristic
544  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
545  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
546  *                ERROR_CODE_SUCCESS         , if query is successfully registered
547  */
548 uint8_t gatt_client_read_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
549 
550 /**
551  * @brief Reads the long characteristic value using the characteristic's value handle.
552  * The value will be returned in several blobs.
553  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
554  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
555  * @param  callback
556  * @param  con_handle
557  * @param  value_handle
558  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
559  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
560  *                ERROR_CODE_SUCCESS         , if query is successfully registered
561  */
562 uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle);
563 
564 /**
565  * @brief Reads the long characteristic value using the characteristic's value handle.
566  * The value will be returned in several blobs.
567  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
568  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
569  * @param  callback
570  * @param  con_handle
571  * @param  value_handle
572  * @param  offset
573  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
574  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
575  *                ERROR_CODE_SUCCESS         , if query is successfully registered
576  */
577 uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t offset);
578 
579 /*
580  * @brief Read multiple characteristic values.
581  * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event,
582  * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read.
583  * @param  callback
584  * @param  con_handle
585  * @param  num_value_handles
586  * @param  value_handles list of handles
587  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
588  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
589  *                ERROR_CODE_SUCCESS         , if query is successfully registered
590  */
591 uint8_t gatt_client_read_multiple_characteristic_values(btstack_packet_handler_t callback, hci_con_handle_t con_handle, int num_value_handles, uint16_t * value_handles);
592 
593 /**
594  * @brief Writes the characteristic value using the characteristic's value handle without
595  * an acknowledgment that the write was successfully performed.
596  * @param  con_handle
597  * @param  value_handle
598  * @param  value_length
599  * @param  value is copied on success and does not need to be retained
600  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
601  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
602  *                BTSTACK_ACL_BUFFERS_FULL   , if L2CAP cannot send, there are no free ACL slots
603  *                ERROR_CODE_SUCCESS         , if query is successfully registered
604  */
605 uint8_t gatt_client_write_value_of_characteristic_without_response(hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value);
606 
607 /**
608  * @brief Writes the authenticated characteristic value using the characteristic's value handle
609  * without an acknowledgment that the write was successfully performed.
610  * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success,
611  * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored.
612  * @param  callback
613  * @param  con_handle
614  * @param  value_handle
615  * @param  message_len
616  * @param  message is not copied, make sure memory is accessible until write is done
617  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
618  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
619  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
620  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
621  */
622 uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t message_len, uint8_t * message);
623 
624 /**
625  * @brief Writes the characteristic value using the characteristic's value handle.
626  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
627  * The write is successfully performed, if the event's att_status field is set to
628  * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
629  * @param  callback
630  * @param  con_handle
631  * @param  value_handle
632  * @param  value_length
633  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
634  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
635  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
636  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
637  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
638  */
639 uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value);
640 
641 /**
642  * @brief Writes the characteristic value using the characteristic's value handle.
643  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
644  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
645  * @param  callback
646  * @param  con_handle
647  * @param  value_handle
648  * @param  value_length
649  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
650  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
651  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
652  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
653  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
654  */
655 uint8_t gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value);
656 
657 /**
658  * @brief Writes the characteristic value using the characteristic's value handle.
659  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
660  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
661  * @param  callback
662  * @param  con_handle
663  * @param  value_handle
664  * @param  offset of value
665  * @param  value_length
666  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
667  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
668  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
669  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
670  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
671  */
672 uint8_t gatt_client_write_long_value_of_characteristic_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t offset, uint16_t value_length, uint8_t * value);
673 
674 /**
675  * @brief Writes of the long characteristic value using the characteristic's value handle.
676  * It uses server response to validate that the write was correctly received.
677  * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write.
678  * The write is successfully performed, if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
679  * @param  callback
680  * @param  con_handle
681  * @param  value_handle
682  * @param  value_length
683  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
684  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
685  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
686  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
687  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
688  */
689 uint8_t gatt_client_reliable_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t value_length, uint8_t * value);
690 
691 /**
692  * @brief Reads the characteristic descriptor using its handle.
693  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
694  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
695  * @param  callback
696  * @param  con_handle
697  * @param  descriptor
698  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
699  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
700  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
701  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
702  */
703 uint8_t gatt_client_read_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor);
704 
705 /**
706  * @brief Reads the characteristic descriptor using its handle.
707  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
708  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
709  * @param  callback
710  * @param  con_handle
711  * @param  descriptor
712  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
713  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
714  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
715  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
716  */
717 uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle);
718 
719 /**
720  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
721  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
722  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
723  * @param  callback
724  * @param  con_handle
725  * @param  descriptor
726  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
727  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
728  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
729  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
730  */
731 uint8_t gatt_client_read_long_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor);
732 
733 /**
734  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
735  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
736  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
737  * @param  callback
738  * @param  con_handle
739  * @param  descriptor_handle
740  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
741  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
742  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
743  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
744  */
745 uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle);
746 
747 /**
748  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
749  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
750  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
751  * @param  callback
752  * @param  con_handle
753  * @param  descriptor_handle
754  * @param  offset
755  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
756  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
757  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
758  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
759  */
760 uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t offset);
761 
762 /**
763  * @brief Writes the characteristic descriptor using its handle.
764  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
765  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
766  * @param  callback
767  * @param  con_handle
768  * @param  descriptor
769  * @param  value_length
770  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
771  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
772  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
773  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
774  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
775  */
776 uint8_t gatt_client_write_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor, uint16_t value_length, uint8_t * value);
777 
778 /**
779  * @brief Writes the characteristic descriptor using its handle.
780  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
781  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
782  * @param  callback
783  * @param  con_handle
784  * @param  descriptor_handle
785  * @param  value_length
786  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
787  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
788  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
789  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
790  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
791  */
792 uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t value_length, uint8_t * value);
793 
794 /**
795  * @brief Writes the characteristic descriptor using its handle.
796  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
797  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
798  * @param  callback
799  * @param  con_handle
800  * @param  descriptor
801  * @param  value_length
802  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
803  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
804  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
805  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
806  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
807  */
808 uint8_t gatt_client_write_long_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor, uint16_t value_length, uint8_t * value);
809 
810 /**
811  * @brief Writes the characteristic descriptor using its handle.
812  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
813  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
814  * @param  callback
815  * @param  con_handle
816  * @param  descriptor_handle
817  * @param  value_length
818  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
819  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
820  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
821  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
822  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
823  */
824 uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t value_length, uint8_t * value);
825 
826 /**
827  * @brief Writes the characteristic descriptor using its handle.
828  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
829  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
830  * @param  callback
831  * @param  con_handle
832  * @param  descriptor_handle
833  * @param  offset of value
834  * @param  value_length
835  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
836  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
837  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
838  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
839  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
840  */
841 uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t value_length, uint8_t * value);
842 
843 /**
844  * @brief Writes the client characteristic configuration of the specified characteristic.
845  * It is used to subscribe for notifications or indications of the characteristic value.
846  * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION
847  * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value.
848  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
849  * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
850  * @param  callback
851  * @param  con_handle
852  * @param  characteristic
853  * @param  configuration                                                    GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION
854  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
855  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
856  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
857  *                GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED     if configuring notification, but characteristic has no notification property set
858  *                GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED       if configuring indication, but characteristic has no indication property set
859  *                ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE         if configuration is invalid
860  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
861  */
862 uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic, uint16_t configuration);
863 
864 /**
865  * @brief Register for notifications and indications of a characteristic enabled by
866  * the gatt_client_write_client_characteristic_configuration function.
867  * @param notification struct used to store registration
868  * @param callback
869  * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices
870  * @param characteristic or NULL to receive updates for all characteristics
871  */
872 void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
873 
874 /**
875  * @brief Stop listening to characteristic value updates registered with
876  * the gatt_client_listen_for_characteristic_value_updates function.
877  * @param notification struct used in gatt_client_listen_for_characteristic_value_updates
878  */
879 void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification);
880 
881 /**
882  * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction.
883  * Call the gatt_client_execute_write function to commit the transaction.
884  * @param  callback
885  * @param  con_handle
886  * @param  attribute_handle
887  * @param  offset of value
888  * @param  value_length
889  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
890  */
891 uint8_t gatt_client_prepare_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t value_length, uint8_t * value);
892 
893 /**
894  * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received.
895  * @param  callback
896  * @param  con_handle
897  * @return status
898  */
899 uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
900 
901 /**
902  * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received.
903  * @param  callback
904  * @param  con_handle
905  * @return status
906  */
907 uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
908 
909 /**
910  * @brief Request callback when regular gatt query can be sent
911  * @note callback might happen during call to this function
912  * @param callback_registration to point to callback function and context information
913  * @param con_handle
914  * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
915  */
916 uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
917 
918 /**
919  * @brief Request callback when writing characteristic value without response is possible
920  * @note callback might happen during call to this function
921  * @param callback_registration to point to callback function and context information
922  * @param con_handle
923  * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
924  */
925 uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
926 
927 
928 // the following functions are marked as deprecated and will be removed eventually
929 /**
930  * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees
931  * a single successful gatt_client_write_value_of_characteristic_without_response call.
932  * @deprecated please use gatt_client_request_to_write_without_response instead
933  * @param  callback
934  * @param  con_handle
935  * @return status
936  */
937 uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
938 
939 
940 /* API_END */
941 
942 // used by generated btstack_event.c
943 
944 void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service);
945 void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic);
946 void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor);
947 
948 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
949 void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size);
950 uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client);
951 #endif
952 
953 #if defined __cplusplus
954 }
955 #endif
956 
957 #endif
958