xref: /btstack/src/ble/gatt_client.h (revision 630ffdd469bbec3276322f46b93e6cfdfcb21c27)
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 MATTHIAS
24  * RINGWALD 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 #ifndef btstack_gatt_client_h
40 #define btstack_gatt_client_h
41 
42 #include "hci.h"
43 
44 #if defined __cplusplus
45 extern "C" {
46 #endif
47 
48 typedef enum {
49     P_READY,
50     P_W2_SEND_SERVICE_QUERY,
51     P_W4_SERVICE_QUERY_RESULT,
52     P_W2_SEND_SERVICE_WITH_UUID_QUERY,
53     P_W4_SERVICE_WITH_UUID_RESULT,
54 
55     P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY,
56     P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT,
57     P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY,
58     P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT,
59 
60     P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY,
61     P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT,
62 
63     P_W2_SEND_INCLUDED_SERVICE_QUERY,
64     P_W4_INCLUDED_SERVICE_QUERY_RESULT,
65     P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY,
66     P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT,
67 
68     P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY,
69     P_W4_READ_CHARACTERISTIC_VALUE_RESULT,
70 
71     P_W2_SEND_READ_BLOB_QUERY,
72     P_W4_READ_BLOB_RESULT,
73 
74     P_W2_SEND_READ_BY_TYPE_REQUEST,
75     P_W4_READ_BY_TYPE_RESPONSE,
76 
77     P_W2_SEND_READ_MULTIPLE_REQUEST,
78     P_W4_READ_MULTIPLE_RESPONSE,
79 
80     P_W2_SEND_WRITE_CHARACTERISTIC_VALUE,
81     P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT,
82 
83     P_W2_PREPARE_WRITE,
84     P_W4_PREPARE_WRITE_RESULT,
85     P_W2_PREPARE_RELIABLE_WRITE,
86     P_W4_PREPARE_RELIABLE_WRITE_RESULT,
87 
88     P_W2_EXECUTE_PREPARED_WRITE,
89     P_W4_EXECUTE_PREPARED_WRITE_RESULT,
90     P_W2_CANCEL_PREPARED_WRITE,
91     P_W4_CANCEL_PREPARED_WRITE_RESULT,
92     P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH,
93     P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT,
94 
95 #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY
96     P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
97     P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
98 #else
99     P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
100     P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
101 #endif
102     P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION,
103     P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT,
104 
105     P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY,
106     P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT,
107 
108     P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY,
109     P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT,
110 
111     P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR,
112     P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
113 
114     // all long writes use this
115     P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR,
116     P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
117     P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR,
118     P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
119 
120     // gatt reliable write API use this (manual version of the above)
121     P_W2_PREPARE_WRITE_SINGLE,
122     P_W4_PREPARE_WRITE_SINGLE_RESULT,
123 
124     P_W4_CMAC_READY,
125     P_W4_CMAC_RESULT,
126     P_W2_SEND_SIGNED_WRITE,
127     P_W4_SEND_SINGED_WRITE_DONE,
128 } gatt_client_state_t;
129 
130 
131 typedef enum{
132     SEND_MTU_EXCHANGE,
133     SENT_MTU_EXCHANGE,
134     MTU_EXCHANGED,
135     MTU_AUTO_EXCHANGE_DISABLED
136 } gatt_client_mtu_t;
137 
138 typedef struct gatt_client{
139     btstack_linked_item_t    item;
140     // TODO: rename gatt_client_state -> state
141     gatt_client_state_t gatt_client_state;
142 
143     // user callback
144     btstack_packet_handler_t callback;
145 
146     // can write without response callback
147     btstack_packet_handler_t write_without_response_callback;
148 
149     hci_con_handle_t con_handle;
150 
151     uint8_t   address_type;
152     bd_addr_t address;
153 
154     uint16_t          mtu;
155     gatt_client_mtu_t mtu_state;
156 
157     uint16_t uuid16;
158     uint8_t  uuid128[16];
159 
160     uint16_t start_group_handle;
161     uint16_t end_group_handle;
162 
163     uint16_t query_start_handle;
164     uint16_t query_end_handle;
165 
166     uint8_t  characteristic_properties;
167     uint16_t characteristic_start_handle;
168 
169     uint16_t attribute_handle;
170     uint16_t attribute_offset;
171     uint16_t attribute_length;
172     uint8_t* attribute_value;
173 
174     // read multiple characteristic values
175     uint16_t    read_multiple_handle_count;
176     uint16_t  * read_multiple_handles;
177 
178     uint16_t client_characteristic_configuration_handle;
179     uint8_t  client_characteristic_configuration_value[2];
180 
181     uint8_t  filter_with_uuid;
182     uint8_t  send_confirmation;
183 
184     int      le_device_index;
185     uint8_t  cmac[8];
186 
187     btstack_timer_source_t gc_timeout;
188 
189 #ifdef ENABLE_GATT_CLIENT_PAIRING
190     uint8_t  security_counter;
191     uint8_t  wait_for_pairing_complete;
192     uint8_t  pending_error_code;
193 #endif
194 
195 } gatt_client_t;
196 
197 typedef struct gatt_client_notification {
198     btstack_linked_item_t    item;
199     btstack_packet_handler_t callback;
200     hci_con_handle_t con_handle;
201     uint16_t attribute_handle;
202 } gatt_client_notification_t;
203 
204 /* API_START */
205 
206 typedef struct {
207     uint16_t start_group_handle;
208     uint16_t end_group_handle;
209     uint16_t uuid16;
210     uint8_t  uuid128[16];
211 } gatt_client_service_t;
212 
213 typedef struct {
214     uint16_t start_handle;
215     uint16_t value_handle;
216     uint16_t end_handle;
217     uint16_t properties;
218     uint16_t uuid16;
219     uint8_t  uuid128[16];
220 } gatt_client_characteristic_t;
221 
222 typedef struct {
223     uint16_t handle;
224     uint16_t uuid16;
225     uint8_t  uuid128[16];
226 } gatt_client_characteristic_descriptor_t;
227 
228 /**
229  * @brief Set up GATT client.
230  */
231 void gatt_client_init(void);
232 
233 /**
234  * @brief MTU is available after the first query has completed. If status is equal to 0, it returns the real value, otherwise the default value of 23.
235  * @param con_handle
236  * @param mtu
237  */
238 
239 uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu);
240 
241 /**
242  * @brief Sets whether a MTU Exchange Request shall be automatically send before the first attribute read request is send. Default is enabled.
243  * @param enabled
244  */
245 void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled);
246 
247 /**
248 * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU when gatt_client_mtu_enable_auto_negotiation is disabled.
249  * @param callback
250  * @param con_handle
251  */
252 void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
253 
254 /**
255  * @brief Returns if the GATT client is ready to receive a query. It is used with daemon.
256  * @param con_handle
257  */
258 int gatt_client_is_ready(hci_con_handle_t con_handle);
259 
260 /**
261  * @brief Discovers all primary services. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
262  * @param callback
263  * @param con_handle
264  */
265 uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
266 
267 /**
268  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
269  * @param callback
270  * @param con_handle
271  * @param uuid16
272  */
273 uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16);
274 
275 /**
276  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
277  * @param callback
278  * @param con_handle
279  * @param uuid128
280  */
281 uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, const uint8_t  * uuid128);
282 
283 /**
284  * @brief Finds included services within the specified service. For each found included service, an le_service_event_t with type set to GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery. Information about included service type (primary/secondary) can be retrieved either by sending an ATT find information request for the returned start group handle (returning the handle and the UUID for primary or secondary service) or by comparing the service to the list of all primary services.
285  * @param callback
286  * @param con_handle
287  * @param service
288  */
289 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);
290 
291 /**
292  * @brief Discovers all characteristics within the specified service. For each found characteristic, an le_characteristics_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
293  * @param callback
294  * @param con_handle
295  * @param service
296  */
297 uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t  *service);
298 
299 /**
300  * @brief The following four functions are used to discover all characteristics within the specified service or handle range, and return those that match the given UUID. For each found characteristic, an le_characteristic_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
301  * @param callback
302  * @param con_handle
303  * @param start_handle
304  * @param end_handle
305  * @param uuid16
306  */
307 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);
308 
309 /**
310  * @brief The following four functions are used to discover all characteristics within the specified service or handle range, and return those that match the given UUID. For each found characteristic, an le_characteristic_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
311  * @param callback
312  * @param con_handle
313  * @param start_handle
314  * @param end_handle
315  * @param uuid128
316  */
317 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, uint8_t  * uuid128);
318 
319 /**
320  * @brief The following four functions are used to discover all characteristics within the specified service or handle range, and return those that match the given UUID. For each found characteristic, an le_characteristic_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
321  * @param callback
322  * @param con_handle
323  * @param service
324  * @param uuid16
325  */
326 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);
327 
328 /**
329  * @brief The following four functions are used to discover all characteristics within the specified service or handle range, and return those that match the given UUID. For each found characteristic, an le_characteristic_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
330  * @param callback
331  * @param con_handle
332  * @param service
333  * @param uuid128
334  */
335 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, uint8_t  * uuid128);
336 
337 /**
338  * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. For each found descriptor, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
339  * @param callback
340  * @param con_handle
341  * @param characteristic
342  */
343 uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t  *characteristic);
344 
345 /**
346  * @brief Reads the characteristic value using the characteristic's value handle. If the characteristic value is found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
347  * @param callback
348  * @param con_handle
349  * @param characteristic
350  */
351 uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t  *characteristic);
352 
353 /**
354  * @brief Reads the characteristic value using the characteristic's value handle. If the characteristic value is found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
355  * @param callback
356  * @param con_handle
357  * @param characteristic_value_handle
358  */
359 uint8_t gatt_client_read_value_of_characteristic_using_value_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t characteristic_value_handle);
360 
361 /**
362  * @brief Reads the characteric value of all characteristics with the uuid. For each found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
363  * @param callback
364  * @param con_handle
365  * @param start_handle
366  * @param end_handle
367  * @param uuid16
368  */
369 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);
370 
371 /**
372  * @brief Reads the characteric value of all characteristics with the uuid. For each found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
373  * @param callback
374  * @param con_handle
375  * @param start_handle
376  * @param end_handle
377  * @param uuid128
378  */
379 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, uint8_t * uuid128);
380 
381 /**
382  * @brief Reads the long characteristic value using the characteristic's value handle. The value will be returned in several blobs. For each blob, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT and updated value offset will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, mark the end of read.
383  * @param callback
384  * @param con_handle
385  * @param characteristic
386  */
387 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);
388 
389 /**
390  * @brief Reads the long characteristic value using the characteristic's value handle. The value will be returned in several blobs. For each blob, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT and updated value offset will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, mark the end of read.
391  * @param callback
392  * @param con_handle
393  * @param characteristic_value_handle
394  */
395 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 characteristic_value_handle);
396 
397 /**
398  * @brief Reads the long characteristic value using the characteristic's value handle. The value will be returned in several blobs. For each blob, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT and updated value offset will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, mark the end of read.
399  * @param callback
400  * @param con_handle
401  * @param characteristic_value_handle
402  * @param offset
403  */
404 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 characteristic_value_handle, uint16_t offset);
405 
406 /*
407  * @brief Read multiple characteristic values
408  * @param callback
409  * @param con_handle
410  * @param num_value_handles
411  * @param value_handles list of handles
412  */
413 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);
414 
415 /**
416  * @brief Writes the characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.
417  * @param con_handle
418  * @param characteristic_value_handle
419  * @param length of data
420  * @param data is not copied, make sure memory is accessible until write is done
421  */
422 uint8_t gatt_client_write_value_of_characteristic_without_response(hci_con_handle_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
423 
424 /**
425  * @brief Writes the authenticated characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.
426  * @param callback
427  * @param con_handle
428  * @param value_handle
429  * @param message_len
430  * @param message is not copied, make sure memory is accessible until write is done
431  */
432 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);
433 
434 /**
435  * @brief Writes the characteristic value using the characteristic's value handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
436  * @param callback
437  * @param con_handle
438  * @param characteristic_value_handle
439  * @param length of data
440  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
441  */
442 uint8_t gatt_client_write_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
443 
444 /**
445  * @brief Writes the characteristic value using the characteristic's value handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
446  * @param callback
447  * @param con_handle
448  * @param characteristic_value_handle
449  * @param length of data
450  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
451  */
452 uint8_t gatt_client_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
453 
454 /**
455  * @brief Writes the characteristic value using the characteristic's value handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
456  * @param callback
457  * @param con_handle
458  * @param characteristic_value_handle
459  * @param offset of value
460  * @param length of data
461  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
462  */
463 uint8_t gatt_client_write_long_value_of_characteristic_with_offset(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t characteristic_value_handle, uint16_t offset, uint16_t length, uint8_t  * data);
464 
465 /**
466  * @brief Writes of the long characteristic value using the characteristic's value handle. It uses server response to validate that the write was correctly received. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE marks the end of write. The write is successfully performed, if the event's status field is set to 0.
467  * @param callback
468  * @param con_handle
469  * @param characteristic_value_handle
470  * @param length of data
471  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
472  */
473 uint8_t gatt_client_reliable_write_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
474 
475 /**
476  * @brief Reads the characteristic descriptor using its handle. If the characteristic descriptor is found, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
477  * @param callback
478  * @param con_handle
479  * @param descriptor
480  */
481 uint8_t gatt_client_read_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t  * descriptor);
482 
483 /**
484  * @brief Reads the characteristic descriptor using its handle. If the characteristic descriptor is found, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
485  * @param callback
486  * @param con_handle
487  * @param descriptor
488  */
489 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);
490 
491 /**
492  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. For each blob, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
493  * @param callback
494  * @param con_handle
495  * @param descriptor_handle
496  */
497 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);
498 
499 /**
500  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. For each blob, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
501  * @param callback
502  * @param con_handle
503  * @param descriptor_handle
504  */
505 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);
506 
507 /**
508  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. For each blob, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
509  * @param callback
510  * @param con_handle
511  * @param descriptor_handle
512  * @param offset
513  */
514 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);
515 
516 /**
517  * @brief Writes the characteristic descriptor using its handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
518  * @param callback
519  * @param con_handle
520  * @param descriptor
521  * @param length of data
522  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
523  */
524 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 length, uint8_t  * data);
525 
526 /**
527  * @brief Writes the characteristic descriptor using its handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
528  * @param callback
529  * @param con_handle
530  * @param descriptor_handle
531  * @param length of data
532  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
533  */
534 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 length, uint8_t  * data);
535 
536 /**
537  * @brief Writes the characteristic descriptor using its handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
538  * @param callback
539  * @param con_handle
540  * @param descriptor
541  * @param length of data
542  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
543  */
544 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 length, uint8_t  * data);
545 
546 /**
547  * @brief Writes the characteristic descriptor using its handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
548  * @param callback
549  * @param con_handle
550  * @param descriptor_handle
551  * @param length of data
552  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
553  */
554 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 length, uint8_t  * data);
555 
556 /**
557  * @brief Writes the characteristic descriptor using its handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
558  * @param callback
559  * @param con_handle
560  * @param descriptor_handle
561  * @param offset of value
562  * @param length of data
563  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
564  */
565 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 length, uint8_t  * data);
566 
567 /**
568  * @brief Writes the client characteristic configuration of the specified characteristic. It is used to subscribe for notifications or indications of the characteristic value. For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value.
569  * @param callback
570  * @param con_handle
571  * @param characteristic
572  * @param configuration
573  */
574 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);
575 
576 /**
577  * @brief Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration
578  * @param notification struct used to store registration
579  * @param callback
580  * @param con_handle
581  * @param characteristic
582  */
583 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);
584 
585 /**
586  * @brief Stop listening to characteristic value updates registered with gatt_client_listen_for_characteristic_value_updates
587  * @param notification struct used in gatt_client_listen_for_characteristic_value_updates
588  */
589 void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification);
590 
591 /**
592  * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees a single successful gatt_client_write_value_of_characteristic_without_response
593  * @param callback
594  * @param con_handle
595  * @returns status
596  */
597 uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
598 
599 /**
600  * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. Call gatt_client_execute_write to commit the transaction.
601  * @param callback
602  * @param con_handle
603  * @param attribute_handle
604  * @param offset of value
605  * @param length of data
606  * @param data is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
607  */
608 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 length, uint8_t * data);
609 
610 /**
611  * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received.
612  * @param callback
613  * @param con_handle
614  */
615 uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
616 
617 /**
618  * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received.
619  * @param callback
620  * @param con_handle
621  */
622 uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
623 
624 /* API_END */
625 
626 // used by generated btstack_event.c
627 
628 void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t *service);
629 void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic);
630 void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor);
631 
632 #if defined __cplusplus
633 }
634 #endif
635 
636 #endif
637