xref: /btstack/src/ble/gatt_client.h (revision 7e4c9b5dd1d710d44c3e167b1542e913a43014c9)
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 } gatt_client_state_t;
134 
135 
136 typedef enum{
137     SEND_MTU_EXCHANGE,
138     SENT_MTU_EXCHANGE,
139     MTU_EXCHANGED,
140     MTU_AUTO_EXCHANGE_DISABLED
141 } gatt_client_mtu_t;
142 
143 typedef struct gatt_client{
144     btstack_linked_item_t    item;
145     // TODO: rename gatt_client_state -> state
146     gatt_client_state_t gatt_client_state;
147 
148     // user callback
149     btstack_packet_handler_t callback;
150 
151     // can write without response callback
152     btstack_packet_handler_t write_without_response_callback;
153 
154     // can write without response requests
155     btstack_linked_list_t write_without_response_requests;
156 
157     hci_con_handle_t con_handle;
158 
159     uint16_t          mtu;
160     gatt_client_mtu_t mtu_state;
161 
162     uint16_t uuid16;
163     uint8_t  uuid128[16];
164 
165     uint16_t start_group_handle;
166     uint16_t end_group_handle;
167 
168     uint16_t query_start_handle;
169     uint16_t query_end_handle;
170 
171     uint8_t  characteristic_properties;
172     uint16_t characteristic_start_handle;
173 
174     uint16_t attribute_handle;
175     uint16_t attribute_offset;
176     uint16_t attribute_length;
177     uint8_t* attribute_value;
178 
179     // read multiple characteristic values
180     uint16_t    read_multiple_handle_count;
181     uint16_t  * read_multiple_handles;
182 
183     uint16_t client_characteristic_configuration_handle;
184     uint8_t  client_characteristic_configuration_value[2];
185 
186     uint8_t  filter_with_uuid;
187     uint8_t  send_confirmation;
188 
189     int      le_device_index;
190     uint8_t  cmac[8];
191 
192     btstack_timer_source_t gc_timeout;
193 
194     uint8_t  security_counter;
195     uint8_t  wait_for_authentication_complete;
196     uint8_t  pending_error_code;
197 
198     bool     reencryption_active;
199     uint8_t  reencryption_result;
200 
201     gap_security_level_t security_level;
202 
203 } gatt_client_t;
204 
205 typedef struct gatt_client_notification {
206     btstack_linked_item_t    item;
207     btstack_packet_handler_t callback;
208     hci_con_handle_t con_handle;
209     uint16_t attribute_handle;
210 } gatt_client_notification_t;
211 
212 /* API_START */
213 
214 typedef struct {
215     uint16_t start_group_handle;
216     uint16_t end_group_handle;
217     uint16_t uuid16;
218     uint8_t  uuid128[16];
219 } gatt_client_service_t;
220 
221 typedef struct {
222     uint16_t start_handle;
223     uint16_t value_handle;
224     uint16_t end_handle;
225     uint16_t properties;
226     uint16_t uuid16;
227     uint8_t  uuid128[16];
228 } gatt_client_characteristic_t;
229 
230 typedef struct {
231     uint16_t handle;
232     uint16_t uuid16;
233     uint8_t  uuid128[16];
234 } gatt_client_characteristic_descriptor_t;
235 
236 /**
237  * @brief Set up GATT client.
238  */
239 void gatt_client_init(void);
240 
241 /**
242  * @brief Set minimum required security level for GATT Client
243  * @note  The Bluetooth specification makes the GATT Server responsible to check for security.
244  *        This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part.
245  *        If your application is exchanging sensitive data with a remote device, you would need to manually check
246  *        the security level before sending/receive such data.
247  *        With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange
248  *        until the required security level is established.
249  *        gatt_client_request_can_write_without_response_event does not trigger authentication
250  *        gatt_client_request_to_write_without_response does not trigger authentication
251  *  @pram level, default LEVEL_0 (no encryption required)
252  */
253 void gatt_client_set_required_security_level(gap_security_level_t level);
254 
255 /**
256  * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value,
257  * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h).
258  * @param  con_handle
259  * @param  mtu
260  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
261  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
262  *                GATT_CLIENT_IN_WRONG_STATE                                if MTU is not exchanged and MTU auto-exchange is disabled
263  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
264  */
265 uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu);
266 
267 /**
268  * @brief Sets whether a MTU Exchange Request shall be automatically send before the
269  * first attribute read request is send. Default is enabled.
270  * @param enabled
271  */
272 void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled);
273 
274 /**
275  * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU
276  * when gatt_client_mtu_enable_auto_negotiation is disabled.
277  * @param  callback
278  * @param  con_handle
279  */
280 void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
281 
282 /**
283  * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon.
284  * @param  con_handle
285  * @return is_ready_status     0 - if no GATT client for con_handle is found, or is not ready, otherwise 1
286  */
287 int gatt_client_is_ready(hci_con_handle_t con_handle);
288 
289 /**
290  * @brief Discovers all primary services.
291  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
292  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
293  * @param  callback
294  * @param  con_handle
295  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
296  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
297  *                ERROR_CODE_SUCCESS         , if query is successfully registered
298  */
299 uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
300 
301 /**
302  * @brief Discovers all secondary services.
303  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
304  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
305  * @param  callback
306  * @param  con_handle
307  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
308  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
309  *                ERROR_CODE_SUCCESS         , if query is successfully registered
310  */
311 uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
312 
313 /**
314  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
315  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
316  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
317  * @param callback
318  * @param con_handle
319  * @param uuid16
320  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
321  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
322  *                ERROR_CODE_SUCCESS         , if query is successfully registered
323  */
324 uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16);
325 
326 /**
327  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
328  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
329  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
330  * @param  callback
331  * @param  con_handle
332  * @param  uuid128
333  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
334  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
335  *                ERROR_CODE_SUCCESS         , if query is successfully registered
336  */
337 uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, const uint8_t * uuid128);
338 
339 /**
340  * @brief Finds included services within the specified service.
341  * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted.
342  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
343  * Information about included service type (primary/secondary) can be retrieved either by sending
344  * an ATT find information request for the returned start group handle
345  * (returning the handle and the UUID for primary or secondary service) or by comparing the service
346  * to the list of all primary services.
347  * @param  callback
348  * @param  con_handle
349  * @param  service
350  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
351  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
352  *                ERROR_CODE_SUCCESS         , if query is successfully registered
353  */
354 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);
355 
356 /**
357  * @brief Discovers all characteristics within the specified service.
358  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited.
359  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
360  * @param  callback
361  * @param  con_handle
362  * @param  service
363  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
364  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
365  *                ERROR_CODE_SUCCESS         , if query is successfully registered
366  */
367 uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service);
368 
369 /**
370  * @brief The following four functions are used to discover all characteristics within
371  * the specified service or handle range, and return those that match the given UUID.
372  *
373  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
374  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
375  * @param  callback
376  * @param  con_handle
377  * @param  start_handle
378  * @param  end_handle
379  * @param  uuid16
380  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
381  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
382  *                ERROR_CODE_SUCCESS         , if query is successfully registered
383  */
384 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);
385 
386 /**
387  * @brief The following four functions are used to discover all characteristics within the
388  * specified service or handle range, and return those that match the given UUID.
389  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
390  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
391  * @param  callback
392  * @param  con_handle
393  * @param  start_handle
394  * @param  end_handle
395  * @param  uuid128
396  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
397  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
398  *                ERROR_CODE_SUCCESS         , if query is successfully registered
399  */
400 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);
401 
402 /**
403  * @brief The following four functions are used to discover all characteristics within the
404  * specified service or handle range, and return those that match the given UUID.
405  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
406  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
407  * @param  callback
408  * @param  con_handle
409  * @param  service
410  * @param  uuid16
411  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
412  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
413  *                ERROR_CODE_SUCCESS         , if query is successfully registered
414  */
415 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);
416 
417 /**
418  * @brief The following four functions are used to discover all characteristics within the
419  * specified service or handle range, and return those that match the given UUID.
420  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
421  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
422  * @param  callback
423  * @param  con_handle
424  * @param  service
425  * @param  uuid128
426  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
427  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
428  *                ERROR_CODE_SUCCESS         , if query is successfully registered
429  */
430 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);
431 
432 /**
433  * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic.
434  * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted.
435  *
436  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
437  * @param  callback
438  * @param  con_handle
439  * @param  characteristic
440  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
441  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
442  *                ERROR_CODE_SUCCESS         , if query is successfully registered
443  */
444 uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
445 
446 /**
447  * @brief Reads the characteristic value using the characteristic's value handle.
448  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
449  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
450  * @param  callback
451  * @param  con_handle
452  * @param  characteristic
453  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
454  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
455  *                ERROR_CODE_SUCCESS         , if query is successfully registered
456  */
457 uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
458 
459 /**
460  * @brief Reads the characteristic value using the characteristic's value handle.
461  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
462  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
463  * @param  callback
464  * @param  con_handle
465  * @param  value_handle
466  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
467  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
468  *                ERROR_CODE_SUCCESS         , if query is successfully registered
469  */
470 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);
471 
472 /**
473  * @brief Reads the characteric value of all characteristics with the uuid.
474  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
475  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
476  * @param  callback
477  * @param  con_handle
478  * @param  start_handle
479  * @param  end_handle
480  * @param  uuid16
481  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
482  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
483  *                ERROR_CODE_SUCCESS         , if query is successfully registered
484  */
485 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);
486 
487 /**
488  * @brief Reads the characteric value of all characteristics with the uuid.
489  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
490  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
491  * @param  callback
492  * @param  con_handle
493  * @param  start_handle
494  * @param  end_handle
495  * @param  uuid128
496  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
497  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
498  *                ERROR_CODE_SUCCESS         , if query is successfully registered
499  */
500 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);
501 
502 /**
503  * @brief Reads the long characteristic value using the characteristic's value handle.
504  * The value will be returned in several blobs.
505  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
506  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
507  * @param  callback
508  * @param  con_handle
509  * @param  characteristic
510  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
511  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
512  *                ERROR_CODE_SUCCESS         , if query is successfully registered
513  */
514 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);
515 
516 /**
517  * @brief Reads the long characteristic value using the characteristic's value handle.
518  * The value will be returned in several blobs.
519  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
520  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
521  * @param  callback
522  * @param  con_handle
523  * @param  value_handle
524  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
525  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
526  *                ERROR_CODE_SUCCESS         , if query is successfully registered
527  */
528 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);
529 
530 /**
531  * @brief Reads the long characteristic value using the characteristic's value handle.
532  * The value will be returned in several blobs.
533  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
534  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
535  * @param  callback
536  * @param  con_handle
537  * @param  value_handle
538  * @param  offset
539  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
540  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
541  *                ERROR_CODE_SUCCESS         , if query is successfully registered
542  */
543 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);
544 
545 /*
546  * @brief Read multiple characteristic values.
547  * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event,
548  * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read.
549  * @param  callback
550  * @param  con_handle
551  * @param  num_value_handles
552  * @param  value_handles list of handles
553  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
554  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
555  *                ERROR_CODE_SUCCESS         , if query is successfully registered
556  */
557 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);
558 
559 /**
560  * @brief Writes the characteristic value using the characteristic's value handle without
561  * an acknowledgment that the write was successfully performed.
562  * @param  con_handle
563  * @param  value_handle
564  * @param  value_length
565  * @param  value is copied on success and does not need to be retained
566  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
567  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
568  *                BTSTACK_ACL_BUFFERS_FULL   , if L2CAP cannot send, there are no free ACL slots
569  *                ERROR_CODE_SUCCESS         , if query is successfully registered
570  */
571 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);
572 
573 /**
574  * @brief Writes the authenticated characteristic value using the characteristic's value handle
575  * without an acknowledgment that the write was successfully performed.
576  * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success,
577  * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored.
578  * @param  callback
579  * @param  con_handle
580  * @param  value_handle
581  * @param  message_len
582  * @param  message is not copied, make sure memory is accessible until write is done
583  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
584  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
585  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
586  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
587  */
588 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);
589 
590 /**
591  * @brief Writes the characteristic value using the characteristic's value handle.
592  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
593  * The write is successfully performed, if the event's att_status field is set to
594  * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
595  * @param  callback
596  * @param  con_handle
597  * @param  value_handle
598  * @param  value_length
599  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
600  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
601  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
602  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
603  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
604  */
605 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);
606 
607 /**
608  * @brief Writes the characteristic value using the characteristic's value handle.
609  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
610  * 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).
611  * @param  callback
612  * @param  con_handle
613  * @param  value_handle
614  * @param  value_length
615  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
616  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
617  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
618  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
619  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
620  */
621 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);
622 
623 /**
624  * @brief Writes the characteristic value using the characteristic's value handle.
625  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
626  * 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).
627  * @param  callback
628  * @param  con_handle
629  * @param  value_handle
630  * @param  offset of value
631  * @param  value_length
632  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
633  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
634  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
635  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
636  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
637  */
638 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);
639 
640 /**
641  * @brief Writes of the long characteristic value using the characteristic's value handle.
642  * It uses server response to validate that the write was correctly received.
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_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);
656 
657 /**
658  * @brief Reads the characteristic descriptor using its handle.
659  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
660  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
661  * @param  callback
662  * @param  con_handle
663  * @param  descriptor
664  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
665  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
666  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
667  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
668  */
669 uint8_t gatt_client_read_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor);
670 
671 /**
672  * @brief Reads the characteristic descriptor using its handle.
673  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
674  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
675  * @param  callback
676  * @param  con_handle
677  * @param  descriptor
678  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
679  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
680  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
681  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
682  */
683 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);
684 
685 /**
686  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
687  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
688  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
689  * @param  callback
690  * @param  con_handle
691  * @param  descriptor
692  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
693  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
694  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
695  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
696  */
697 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);
698 
699 /**
700  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
701  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
702  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
703  * @param  callback
704  * @param  con_handle
705  * @param  descriptor_handle
706  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
707  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
708  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
709  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
710  */
711 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);
712 
713 /**
714  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
715  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
716  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
717  * @param  callback
718  * @param  con_handle
719  * @param  descriptor_handle
720  * @param  offset
721  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
722  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
723  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
724  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
725  */
726 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);
727 
728 /**
729  * @brief Writes the characteristic descriptor using its handle.
730  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
731  * 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).
732  * @param  callback
733  * @param  con_handle
734  * @param  descriptor
735  * @param  value_length
736  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
737  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
738  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
739  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
740  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
741  */
742 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);
743 
744 /**
745  * @brief Writes the characteristic descriptor using its handle.
746  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
747  * 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).
748  * @param  callback
749  * @param  con_handle
750  * @param  descriptor_handle
751  * @param  value_length
752  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
753  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
754  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
755  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
756  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
757  */
758 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);
759 
760 /**
761  * @brief Writes the characteristic descriptor using its handle.
762  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
763  * 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).
764  * @param  callback
765  * @param  con_handle
766  * @param  descriptor
767  * @param  value_length
768  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
769  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
770  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
771  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
772  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
773  */
774 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);
775 
776 /**
777  * @brief Writes the characteristic descriptor using its handle.
778  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
779  * 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).
780  * @param  callback
781  * @param  con_handle
782  * @param  descriptor_handle
783  * @param  value_length
784  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
785  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
786  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
787  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
788  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
789  */
790 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);
791 
792 /**
793  * @brief Writes the characteristic descriptor using its handle.
794  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
795  * 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).
796  * @param  callback
797  * @param  con_handle
798  * @param  descriptor_handle
799  * @param  offset of value
800  * @param  value_length
801  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
802  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
803  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
804  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
805  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
806  */
807 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);
808 
809 /**
810  * @brief Writes the client characteristic configuration of the specified characteristic.
811  * It is used to subscribe for notifications or indications of the characteristic value.
812  * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION
813  * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value.
814  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
815  * 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).
816  * @param  callback
817  * @param  con_handle
818  * @param  characteristic
819  * @param  configuration                                                    GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION
820  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
821  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
822  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
823  *                GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED     if configuring notification, but characteristic has no notification property set
824  *                GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED       if configuring indication, but characteristic has no indication property set
825  *                ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE         if configuration is invalid
826  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
827  */
828 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);
829 
830 /**
831  * @brief Register for notifications and indications of a characteristic enabled by
832  * the gatt_client_write_client_characteristic_configuration function.
833  * @param notification struct used to store registration
834  * @param callback
835  * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices
836  * @param characteristic or NULL to receive updates for all characteristics
837  */
838 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);
839 
840 /**
841  * @brief Stop listening to characteristic value updates registered with
842  * the gatt_client_listen_for_characteristic_value_updates function.
843  * @param notification struct used in gatt_client_listen_for_characteristic_value_updates
844  */
845 void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification);
846 
847 /**
848  * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction.
849  * Call the gatt_client_execute_write function to commit the transaction.
850  * @param  callback
851  * @param  con_handle
852  * @param  attribute_handle
853  * @param  offset of value
854  * @param  value_length
855  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
856  */
857 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);
858 
859 /**
860  * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received.
861  * @param  callback
862  * @param  con_handle
863  * @return status
864  */
865 uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
866 
867 /**
868  * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received.
869  * @param  callback
870  * @param  con_handle
871  * @return status
872  */
873 uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
874 
875 /**
876  * @brief Request callback when writing characteristic value without response is possible
877  * @note callback might happend during call to this function
878  * @param callback_registration to point to callback function and context information
879  * @param con_handle
880  * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
881  */
882 uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
883 
884 
885 // the following functions are marked as deprecated and will be removed eventually
886 /**
887  * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees
888  * a single successful gatt_client_write_value_of_characteristic_without_response call.
889  * @deprecated please use gatt_client_request_to_write_without_response instead
890  * @param  callback
891  * @param  con_handle
892  * @return status
893  */
894 uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
895 
896 
897 /* API_END */
898 
899 // used by generated btstack_event.c
900 
901 void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service);
902 void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic);
903 void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor);
904 
905 #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
906 void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size);
907 uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client);
908 #endif
909 
910 #if defined __cplusplus
911 }
912 #endif
913 
914 #endif
915