xref: /btstack/src/ble/gatt_client.h (revision 8540586af0ee71c9a09a556d06400811fa64cd9c)
13deb3ec6SMatthias Ringwald /*
23deb3ec6SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
33deb3ec6SMatthias Ringwald  *
43deb3ec6SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53deb3ec6SMatthias Ringwald  * modification, are permitted provided that the following conditions
63deb3ec6SMatthias Ringwald  * are met:
73deb3ec6SMatthias Ringwald  *
83deb3ec6SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103deb3ec6SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123deb3ec6SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133deb3ec6SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143deb3ec6SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153deb3ec6SMatthias Ringwald  *    from this software without specific prior written permission.
163deb3ec6SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173deb3ec6SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183deb3ec6SMatthias Ringwald  *    monetary gain.
193deb3ec6SMatthias Ringwald  *
203deb3ec6SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213deb3ec6SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223deb3ec6SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253deb3ec6SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263deb3ec6SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273deb3ec6SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283deb3ec6SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293deb3ec6SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303deb3ec6SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313deb3ec6SMatthias Ringwald  * SUCH DAMAGE.
323deb3ec6SMatthias Ringwald  *
333deb3ec6SMatthias Ringwald  * Please inquire about commercial licensing options at
343deb3ec6SMatthias Ringwald  * [email protected]
353deb3ec6SMatthias Ringwald  *
363deb3ec6SMatthias Ringwald  */
373deb3ec6SMatthias Ringwald 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title GATT Client
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  */
423deb3ec6SMatthias Ringwald 
433deb3ec6SMatthias Ringwald #ifndef btstack_gatt_client_h
443deb3ec6SMatthias Ringwald #define btstack_gatt_client_h
453deb3ec6SMatthias Ringwald 
463deb3ec6SMatthias Ringwald #include "hci.h"
473deb3ec6SMatthias Ringwald 
483deb3ec6SMatthias Ringwald #if defined __cplusplus
493deb3ec6SMatthias Ringwald extern "C" {
503deb3ec6SMatthias Ringwald #endif
513deb3ec6SMatthias Ringwald 
523deb3ec6SMatthias Ringwald typedef enum {
533deb3ec6SMatthias Ringwald     P_READY,
543deb3ec6SMatthias Ringwald     P_W2_SEND_SERVICE_QUERY,
553deb3ec6SMatthias Ringwald     P_W4_SERVICE_QUERY_RESULT,
563deb3ec6SMatthias Ringwald     P_W2_SEND_SERVICE_WITH_UUID_QUERY,
573deb3ec6SMatthias Ringwald     P_W4_SERVICE_WITH_UUID_RESULT,
583deb3ec6SMatthias Ringwald 
593deb3ec6SMatthias Ringwald     P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY,
603deb3ec6SMatthias Ringwald     P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT,
613deb3ec6SMatthias Ringwald     P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY,
623deb3ec6SMatthias Ringwald     P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT,
633deb3ec6SMatthias Ringwald 
643deb3ec6SMatthias Ringwald     P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY,
653deb3ec6SMatthias Ringwald     P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT,
663deb3ec6SMatthias Ringwald 
673deb3ec6SMatthias Ringwald     P_W2_SEND_INCLUDED_SERVICE_QUERY,
683deb3ec6SMatthias Ringwald     P_W4_INCLUDED_SERVICE_QUERY_RESULT,
693deb3ec6SMatthias Ringwald     P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY,
703deb3ec6SMatthias Ringwald     P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT,
713deb3ec6SMatthias Ringwald 
723deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY,
733deb3ec6SMatthias Ringwald     P_W4_READ_CHARACTERISTIC_VALUE_RESULT,
743deb3ec6SMatthias Ringwald 
753deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BLOB_QUERY,
763deb3ec6SMatthias Ringwald     P_W4_READ_BLOB_RESULT,
773deb3ec6SMatthias Ringwald 
783deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BY_TYPE_REQUEST,
793deb3ec6SMatthias Ringwald     P_W4_READ_BY_TYPE_RESPONSE,
803deb3ec6SMatthias Ringwald 
813deb3ec6SMatthias Ringwald     P_W2_SEND_READ_MULTIPLE_REQUEST,
823deb3ec6SMatthias Ringwald     P_W4_READ_MULTIPLE_RESPONSE,
833deb3ec6SMatthias Ringwald 
84f125a8efSMatthias Ringwald     P_W2_SEND_READ_MULTIPLE_VARIABLE_REQUEST,
85f125a8efSMatthias Ringwald     P_W4_READ_MULTIPLE_VARIABLE_RESPONSE,
86f125a8efSMatthias Ringwald 
873deb3ec6SMatthias Ringwald     P_W2_SEND_WRITE_CHARACTERISTIC_VALUE,
883deb3ec6SMatthias Ringwald     P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT,
893deb3ec6SMatthias Ringwald 
903deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE,
913deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_RESULT,
923deb3ec6SMatthias Ringwald     P_W2_PREPARE_RELIABLE_WRITE,
933deb3ec6SMatthias Ringwald     P_W4_PREPARE_RELIABLE_WRITE_RESULT,
943deb3ec6SMatthias Ringwald 
953deb3ec6SMatthias Ringwald     P_W2_EXECUTE_PREPARED_WRITE,
963deb3ec6SMatthias Ringwald     P_W4_EXECUTE_PREPARED_WRITE_RESULT,
973deb3ec6SMatthias Ringwald     P_W2_CANCEL_PREPARED_WRITE,
983deb3ec6SMatthias Ringwald     P_W4_CANCEL_PREPARED_WRITE_RESULT,
993deb3ec6SMatthias Ringwald     P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH,
1003deb3ec6SMatthias Ringwald     P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT,
1013deb3ec6SMatthias Ringwald 
102abdc9fb5SMatthias Ringwald #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY
103abdc9fb5SMatthias Ringwald     P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
104abdc9fb5SMatthias Ringwald     P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
105abdc9fb5SMatthias Ringwald #else
1063deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
1073deb3ec6SMatthias Ringwald     P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
108abdc9fb5SMatthias Ringwald #endif
1093deb3ec6SMatthias Ringwald     P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION,
1103deb3ec6SMatthias Ringwald     P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT,
1113deb3ec6SMatthias Ringwald 
1123deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY,
1133deb3ec6SMatthias Ringwald     P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT,
1143deb3ec6SMatthias Ringwald 
1153deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY,
1163deb3ec6SMatthias Ringwald     P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT,
1173deb3ec6SMatthias Ringwald 
1183deb3ec6SMatthias Ringwald     P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR,
1193deb3ec6SMatthias Ringwald     P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1203deb3ec6SMatthias Ringwald 
1213deb3ec6SMatthias Ringwald     // all long writes use this
1223deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR,
1233deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1243deb3ec6SMatthias Ringwald     P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR,
1253deb3ec6SMatthias Ringwald     P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1263deb3ec6SMatthias Ringwald 
1273deb3ec6SMatthias Ringwald     // gatt reliable write API use this (manual version of the above)
1283deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE_SINGLE,
1293deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_SINGLE_RESULT,
1303deb3ec6SMatthias Ringwald 
131793cf6ceSMatthias Ringwald     P_W4_IDENTITY_RESOLVING,
1323deb3ec6SMatthias Ringwald     P_W4_CMAC_READY,
1333deb3ec6SMatthias Ringwald     P_W4_CMAC_RESULT,
1343deb3ec6SMatthias Ringwald     P_W2_SEND_SIGNED_WRITE,
1353deb3ec6SMatthias Ringwald     P_W4_SEND_SINGED_WRITE_DONE,
1361450cdc6SMatthias Ringwald 
1371450cdc6SMatthias Ringwald     P_W2_SDP_QUERY,
1381450cdc6SMatthias Ringwald     P_W4_SDP_QUERY,
1391450cdc6SMatthias Ringwald     P_W4_L2CAP_CONNECTION,
1403deb3ec6SMatthias Ringwald } gatt_client_state_t;
1413deb3ec6SMatthias Ringwald 
1423deb3ec6SMatthias Ringwald 
1433deb3ec6SMatthias Ringwald typedef enum{
1443deb3ec6SMatthias Ringwald     SEND_MTU_EXCHANGE,
1453deb3ec6SMatthias Ringwald     SENT_MTU_EXCHANGE,
1465cf6c434SJakob Krantz     MTU_EXCHANGED,
1475cf6c434SJakob Krantz     MTU_AUTO_EXCHANGE_DISABLED
1483deb3ec6SMatthias Ringwald } gatt_client_mtu_t;
1493deb3ec6SMatthias Ringwald 
150cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT
151cbd76cecSMatthias Ringwald typedef enum {
152cbd76cecSMatthias Ringwald     GATT_CLIENT_EATT_IDLE,
1537627a0deSMatthias Ringwald     GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W2_SEND,
1547627a0deSMatthias Ringwald     GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W4_DONE,
15526166ecfSMatthias Ringwald     GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND,
15626166ecfSMatthias Ringwald     GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE,
15726166ecfSMatthias Ringwald     GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND,
15826166ecfSMatthias Ringwald     GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE,
15926166ecfSMatthias Ringwald     GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND,
16026166ecfSMatthias Ringwald     GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE,
1617627a0deSMatthias Ringwald     GATT_CLIENT_EATT_L2CAP_SETUP,
162cbd76cecSMatthias Ringwald     GATT_CLIENT_EATT_READY,
163cbd76cecSMatthias Ringwald } gatt_client_eatt_state_t;
164cbd76cecSMatthias Ringwald #endif
165cbd76cecSMatthias Ringwald 
1663deb3ec6SMatthias Ringwald typedef struct gatt_client{
167665d90f2SMatthias Ringwald     btstack_linked_item_t    item;
1683deb3ec6SMatthias Ringwald     // TODO: rename gatt_client_state -> state
1693deb3ec6SMatthias Ringwald     gatt_client_state_t gatt_client_state;
1703deb3ec6SMatthias Ringwald 
1719c662c9bSMatthias Ringwald     // user callback
1729c662c9bSMatthias Ringwald     btstack_packet_handler_t callback;
1733deb3ec6SMatthias Ringwald 
17447181045SMatthias Ringwald     // can write without response callback
17547181045SMatthias Ringwald     btstack_packet_handler_t write_without_response_callback;
17647181045SMatthias Ringwald 
17759d34cd2SMatthias Ringwald     // can write without response requests
17859d34cd2SMatthias Ringwald     btstack_linked_list_t write_without_response_requests;
17959d34cd2SMatthias Ringwald 
18053e9c18fSMatthias Ringwald     // regular gatt query requests
18153e9c18fSMatthias Ringwald     btstack_linked_list_t query_requests;
18253e9c18fSMatthias Ringwald 
183fc64f94aSMatthias Ringwald     hci_con_handle_t con_handle;
184f4b33574SMatthias Ringwald 
185e9cdf30bSMatthias Ringwald     att_bearer_type_t bearer_type;
186e9cdf30bSMatthias Ringwald 
1871450cdc6SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC
1881450cdc6SMatthias Ringwald     bd_addr_t addr;
1891450cdc6SMatthias Ringwald     uint16_t  l2cap_psm;
1901450cdc6SMatthias Ringwald     uint16_t  l2cap_cid;
1911450cdc6SMatthias Ringwald     btstack_context_callback_registration_t sdp_query_request;
1921450cdc6SMatthias Ringwald #endif
1931450cdc6SMatthias Ringwald 
194cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT
195cbd76cecSMatthias Ringwald     gatt_client_eatt_state_t eatt_state;
1967627a0deSMatthias Ringwald     btstack_linked_list_t eatt_clients;
1977627a0deSMatthias Ringwald     uint8_t * eatt_storage_buffer;
1987627a0deSMatthias Ringwald     uint16_t eatt_storage_size;
1997627a0deSMatthias Ringwald     uint8_t  eatt_num_clients;
2007627a0deSMatthias Ringwald     uint8_t  gatt_server_supported_features;
2017627a0deSMatthias Ringwald     uint16_t gatt_service_start_group_handle;
2027627a0deSMatthias Ringwald     uint16_t gatt_service_end_group_handle;
203cbd76cecSMatthias Ringwald     uint16_t gatt_client_supported_features_handle;
204cbd76cecSMatthias Ringwald #endif
205cbd76cecSMatthias Ringwald 
2063deb3ec6SMatthias Ringwald     uint16_t          mtu;
2073deb3ec6SMatthias Ringwald     gatt_client_mtu_t mtu_state;
2083deb3ec6SMatthias Ringwald 
2093deb3ec6SMatthias Ringwald     uint16_t uuid16;
2103deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
2113deb3ec6SMatthias Ringwald 
2123deb3ec6SMatthias Ringwald     uint16_t start_group_handle;
2133deb3ec6SMatthias Ringwald     uint16_t end_group_handle;
2143deb3ec6SMatthias Ringwald 
2153deb3ec6SMatthias Ringwald     uint16_t query_start_handle;
2163deb3ec6SMatthias Ringwald     uint16_t query_end_handle;
2173deb3ec6SMatthias Ringwald 
2183deb3ec6SMatthias Ringwald     uint8_t  characteristic_properties;
2193deb3ec6SMatthias Ringwald     uint16_t characteristic_start_handle;
2203deb3ec6SMatthias Ringwald 
2213deb3ec6SMatthias Ringwald     uint16_t attribute_handle;
2223deb3ec6SMatthias Ringwald     uint16_t attribute_offset;
2233deb3ec6SMatthias Ringwald     uint16_t attribute_length;
2243deb3ec6SMatthias Ringwald     uint8_t* attribute_value;
2253deb3ec6SMatthias Ringwald 
2263deb3ec6SMatthias Ringwald     // read multiple characteristic values
2273deb3ec6SMatthias Ringwald     uint16_t    read_multiple_handle_count;
2283deb3ec6SMatthias Ringwald     uint16_t  * read_multiple_handles;
2293deb3ec6SMatthias Ringwald 
2303deb3ec6SMatthias Ringwald     uint16_t client_characteristic_configuration_handle;
2313deb3ec6SMatthias Ringwald     uint8_t  client_characteristic_configuration_value[2];
2323deb3ec6SMatthias Ringwald 
2333deb3ec6SMatthias Ringwald     uint8_t  filter_with_uuid;
2343deb3ec6SMatthias Ringwald     uint8_t  send_confirmation;
2353deb3ec6SMatthias Ringwald 
2363deb3ec6SMatthias Ringwald     int      le_device_index;
2373deb3ec6SMatthias Ringwald     uint8_t  cmac[8];
2383deb3ec6SMatthias Ringwald 
239ec820d77SMatthias Ringwald     btstack_timer_source_t gc_timeout;
240f4b33574SMatthias Ringwald 
241f4b33574SMatthias Ringwald     uint8_t  security_counter;
2423503dc74SMatthias Ringwald     uint8_t  wait_for_authentication_complete;
243f4b33574SMatthias Ringwald     uint8_t  pending_error_code;
244f4b33574SMatthias Ringwald 
2458918bbdaSMatthias Ringwald     bool     reencryption_active;
2468918bbdaSMatthias Ringwald     uint8_t  reencryption_result;
2478918bbdaSMatthias Ringwald 
2481dfae9c7SMatthias Ringwald     gap_security_level_t security_level;
2491dfae9c7SMatthias Ringwald 
2503deb3ec6SMatthias Ringwald } gatt_client_t;
2513deb3ec6SMatthias Ringwald 
2529c662c9bSMatthias Ringwald typedef struct gatt_client_notification {
253665d90f2SMatthias Ringwald     btstack_linked_item_t    item;
254b6e96f14SMatthias Ringwald     btstack_packet_handler_t callback;
255711e6c80SMatthias Ringwald     hci_con_handle_t con_handle;
2569c662c9bSMatthias Ringwald     uint16_t attribute_handle;
2579c662c9bSMatthias Ringwald } gatt_client_notification_t;
2583deb3ec6SMatthias Ringwald 
2593deb3ec6SMatthias Ringwald /* API_START */
2603deb3ec6SMatthias Ringwald 
261d25c33e5SMatthias Ringwald typedef struct {
2623deb3ec6SMatthias Ringwald     uint16_t start_group_handle;
2633deb3ec6SMatthias Ringwald     uint16_t end_group_handle;
2643deb3ec6SMatthias Ringwald     uint16_t uuid16;
2653deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
266d25c33e5SMatthias Ringwald } gatt_client_service_t;
2673deb3ec6SMatthias Ringwald 
268d25c33e5SMatthias Ringwald typedef struct {
2693deb3ec6SMatthias Ringwald     uint16_t start_handle;
2703deb3ec6SMatthias Ringwald     uint16_t value_handle;
2713deb3ec6SMatthias Ringwald     uint16_t end_handle;
2723deb3ec6SMatthias Ringwald     uint16_t properties;
2733deb3ec6SMatthias Ringwald     uint16_t uuid16;
2743deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
275d25c33e5SMatthias Ringwald } gatt_client_characteristic_t;
2763deb3ec6SMatthias Ringwald 
277d25c33e5SMatthias Ringwald typedef struct {
2783deb3ec6SMatthias Ringwald     uint16_t handle;
2793deb3ec6SMatthias Ringwald     uint16_t uuid16;
2803deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
281d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t;
2823deb3ec6SMatthias Ringwald 
2833deb3ec6SMatthias Ringwald /**
2843deb3ec6SMatthias Ringwald  * @brief Set up GATT client.
2853deb3ec6SMatthias Ringwald  */
2863deb3ec6SMatthias Ringwald void gatt_client_init(void);
2873deb3ec6SMatthias Ringwald 
2883deb3ec6SMatthias Ringwald /**
28911279da7SMatthias Ringwald  * @brief Set minimum required security level for GATT Client
29011279da7SMatthias Ringwald  * @note  The Bluetooth specification makes the GATT Server responsible to check for security.
291b11289a8SMatthias Ringwald  *        This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part.
292b11289a8SMatthias Ringwald  *        If your application is exchanging sensitive data with a remote device, you would need to manually check
293b11289a8SMatthias Ringwald  *        the security level before sending/receive such data.
294b11289a8SMatthias Ringwald  *        With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange
295b11289a8SMatthias Ringwald  *        until the required security level is established.
296b11289a8SMatthias Ringwald  *        gatt_client_request_can_write_without_response_event does not trigger authentication
29759d34cd2SMatthias Ringwald  *        gatt_client_request_to_write_without_response does not trigger authentication
29811279da7SMatthias Ringwald  *  @pram level, default LEVEL_0 (no encryption required)
29911279da7SMatthias Ringwald  */
30011279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level);
30111279da7SMatthias Ringwald 
30211279da7SMatthias Ringwald /**
3031450cdc6SMatthias Ringwald  * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection
304effecf77SMatthias Ringwald  *        GATT_EVENT_CONNECTED with status and con_handle for other API functions
305effecf77SMatthias Ringwald  *        is emitted on connection complete.
306effecf77SMatthias Ringwald  * @note requires ENABLE_GATT_OVER_CLASSIC.
3071450cdc6SMatthias Ringwald  * @param addr
3081450cdc6SMatthias Ringwald  * @return status
3091450cdc6SMatthias Ringwald  */
3101450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr);
3111450cdc6SMatthias Ringwald 
3121450cdc6SMatthias Ringwald /**
3131450cdc6SMatthias Ringwald  * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server
3141450cdc6SMatthias Ringwald  * @note requires ENABLE_GATT_OVER_CLASSIC
315effecf77SMatthias Ringwald  * @param con_handle
3161450cdc6SMatthias Ringwald  * @return status
3171450cdc6SMatthias Ringwald  */
3181450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
3191450cdc6SMatthias Ringwald 
3201450cdc6SMatthias Ringwald /**
3217627a0deSMatthias Ringwald  * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection
3227627a0deSMatthias Ringwald  * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events
32326166ecfSMatthias Ringwald  * @param con_handle
32426166ecfSMatthias Ringwald  * @param num_channels
3257627a0deSMatthias Ringwald  * @param storage_buffer for L2CAP connection
326*8540586aSMatthias Ringwald  * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes
32726166ecfSMatthias Ringwald  * @return
32826166ecfSMatthias Ringwald  */
32926166ecfSMatthias Ringwald uint8_t gatt_client_le_enhanced_connect(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint8_t num_channels, uint8_t * storage_buffer, uint16_t storage_size);
33026166ecfSMatthias Ringwald 
33126166ecfSMatthias Ringwald /**
33279188ed7SMilanka Ringwald  * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value,
33379188ed7SMilanka Ringwald  * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h).
3346da84376SMilanka Ringwald  * @param  con_handle
3356da84376SMilanka Ringwald  * @param  mtu
33640faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
33740faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
338692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if MTU is not exchanged and MTU auto-exchange is disabled
339692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
3403deb3ec6SMatthias Ringwald  */
341fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu);
3423deb3ec6SMatthias Ringwald 
3433deb3ec6SMatthias Ringwald /**
34479188ed7SMilanka Ringwald  * @brief Sets whether a MTU Exchange Request shall be automatically send before the
34579188ed7SMilanka Ringwald  * first attribute read request is send. Default is enabled.
3466da84376SMilanka Ringwald  * @param enabled
3475cf6c434SJakob Krantz  */
3485cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled);
3495cf6c434SJakob Krantz 
3505cf6c434SJakob Krantz /**
35179188ed7SMilanka Ringwald  * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU
35279188ed7SMilanka Ringwald  * when gatt_client_mtu_enable_auto_negotiation is disabled.
3536da84376SMilanka Ringwald  * @param  callback
3546da84376SMilanka Ringwald  * @param  con_handle
3555cf6c434SJakob Krantz  */
3565cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
3575cf6c434SJakob Krantz 
3585cf6c434SJakob Krantz /**
359aacf1b1aSMilanka Ringwald  * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon.
3606da84376SMilanka Ringwald  * @param  con_handle
361692bf1adSMilanka Ringwald  * @return is_ready_status     0 - if no GATT client for con_handle is found, or is not ready, otherwise 1
3623deb3ec6SMatthias Ringwald  */
363fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle);
3643deb3ec6SMatthias Ringwald 
3653deb3ec6SMatthias Ringwald /**
36679188ed7SMilanka Ringwald  * @brief Discovers all primary services.
36779188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
36879188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3696da84376SMilanka Ringwald  * @param  callback
3706da84376SMilanka Ringwald  * @param  con_handle
371692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
372692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
373692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3743deb3ec6SMatthias Ringwald  */
375711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
3763deb3ec6SMatthias Ringwald 
3773deb3ec6SMatthias Ringwald /**
37879188ed7SMilanka Ringwald  * @brief Discovers all secondary services.
37979188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
38079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3818d1f34d3SMatheus Eduardo Garbelini  * @param  callback
3828d1f34d3SMatheus Eduardo Garbelini  * @param  con_handle
3838d1f34d3SMatheus Eduardo Garbelini  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
3848d1f34d3SMatheus Eduardo Garbelini  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
3858d1f34d3SMatheus Eduardo Garbelini  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3868d1f34d3SMatheus Eduardo Garbelini  */
3878d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
3888d1f34d3SMatheus Eduardo Garbelini 
3898d1f34d3SMatheus Eduardo Garbelini /**
39079188ed7SMilanka Ringwald  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
39179188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
39279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3936da84376SMilanka Ringwald  * @param callback
3946da84376SMilanka Ringwald  * @param con_handle
3956da84376SMilanka Ringwald  * @param uuid16
396692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
397692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
398692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3993deb3ec6SMatthias Ringwald  */
400711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16);
4016da84376SMilanka Ringwald 
4026da84376SMilanka Ringwald /**
40379188ed7SMilanka Ringwald  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
40479188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
40579188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4066da84376SMilanka Ringwald  * @param  callback
4076da84376SMilanka Ringwald  * @param  con_handle
4086da84376SMilanka Ringwald  * @param  uuid128
409692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
410692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
411692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4126da84376SMilanka Ringwald  */
4136da84376SMilanka Ringwald uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, const uint8_t * uuid128);
4143deb3ec6SMatthias Ringwald 
4153deb3ec6SMatthias Ringwald /**
41679188ed7SMilanka Ringwald  * @brief Finds included services within the specified service.
41779188ed7SMilanka Ringwald  * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted.
41879188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
41979188ed7SMilanka Ringwald  * Information about included service type (primary/secondary) can be retrieved either by sending
42079188ed7SMilanka Ringwald  * an ATT find information request for the returned start group handle
42179188ed7SMilanka Ringwald  * (returning the handle and the UUID for primary or secondary service) or by comparing the service
42279188ed7SMilanka Ringwald  * to the list of all primary services.
4236da84376SMilanka Ringwald  * @param  callback
4246da84376SMilanka Ringwald  * @param  con_handle
4256da84376SMilanka Ringwald  * @param  service
426692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
427692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
428692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4293deb3ec6SMatthias Ringwald  */
430711e6c80SMatthias Ringwald 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);
4313deb3ec6SMatthias Ringwald 
4323deb3ec6SMatthias Ringwald /**
43379188ed7SMilanka Ringwald  * @brief Discovers all characteristics within the specified service.
43479188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited.
43579188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4366da84376SMilanka Ringwald  * @param  callback
4376da84376SMilanka Ringwald  * @param  con_handle
4386da84376SMilanka Ringwald  * @param  service
439692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
440692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
441692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4423deb3ec6SMatthias Ringwald  */
443711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service);
4443deb3ec6SMatthias Ringwald 
4453deb3ec6SMatthias Ringwald /**
44679188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within
44779188ed7SMilanka Ringwald  * the specified service or handle range, and return those that match the given UUID.
44879188ed7SMilanka Ringwald  *
44979188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
45079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4516da84376SMilanka Ringwald  * @param  callback
4526da84376SMilanka Ringwald  * @param  con_handle
4536da84376SMilanka Ringwald  * @param  start_handle
4546da84376SMilanka Ringwald  * @param  end_handle
4556da84376SMilanka Ringwald  * @param  uuid16
456692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
457692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
458692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4593deb3ec6SMatthias Ringwald  */
460711e6c80SMatthias Ringwald 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);
4616da84376SMilanka Ringwald 
4626da84376SMilanka Ringwald /**
46379188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within the
46479188ed7SMilanka Ringwald  * specified service or handle range, and return those that match the given UUID.
46579188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
46679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4676da84376SMilanka Ringwald  * @param  callback
4686da84376SMilanka Ringwald  * @param  con_handle
4696da84376SMilanka Ringwald  * @param  start_handle
4706da84376SMilanka Ringwald  * @param  end_handle
4716da84376SMilanka Ringwald  * @param  uuid128
472692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
473692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
474692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4756da84376SMilanka Ringwald  */
476045d700dSDavid Lechner 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);
4776da84376SMilanka Ringwald 
4786da84376SMilanka Ringwald /**
47979188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within the
48079188ed7SMilanka Ringwald  * specified service or handle range, and return those that match the given UUID.
48179188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
48279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4836da84376SMilanka Ringwald  * @param  callback
4846da84376SMilanka Ringwald  * @param  con_handle
4856da84376SMilanka Ringwald  * @param  service
4866da84376SMilanka Ringwald  * @param  uuid16
487692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
488692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
489692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4906da84376SMilanka Ringwald  */
491711e6c80SMatthias Ringwald 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);
4926da84376SMilanka Ringwald 
4936da84376SMilanka Ringwald /**
49479188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within the
49579188ed7SMilanka Ringwald  * specified service or handle range, and return those that match the given UUID.
49679188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
49779188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4986da84376SMilanka Ringwald  * @param  callback
4996da84376SMilanka Ringwald  * @param  con_handle
5006da84376SMilanka Ringwald  * @param  service
5016da84376SMilanka Ringwald  * @param  uuid128
502692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
503692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
504692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5056da84376SMilanka Ringwald  */
506045d700dSDavid Lechner 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);
5073deb3ec6SMatthias Ringwald 
5083deb3ec6SMatthias Ringwald /**
50979188ed7SMilanka Ringwald  * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic.
51079188ed7SMilanka Ringwald  * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted.
51179188ed7SMilanka Ringwald  *
51279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
5136da84376SMilanka Ringwald  * @param  callback
5146da84376SMilanka Ringwald  * @param  con_handle
5156da84376SMilanka Ringwald  * @param  characteristic
516692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
517692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
518692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5193deb3ec6SMatthias Ringwald  */
520711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
5213deb3ec6SMatthias Ringwald 
5223deb3ec6SMatthias Ringwald /**
52379188ed7SMilanka Ringwald  * @brief Reads the characteristic value using the characteristic's value handle.
52479188ed7SMilanka Ringwald  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
52579188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5266da84376SMilanka Ringwald  * @param  callback
5276da84376SMilanka Ringwald  * @param  con_handle
5286da84376SMilanka Ringwald  * @param  characteristic
529692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
530692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
531692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5323deb3ec6SMatthias Ringwald  */
533711e6c80SMatthias Ringwald uint8_t gatt_client_read_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
5346da84376SMilanka Ringwald 
5356da84376SMilanka Ringwald /**
53679188ed7SMilanka Ringwald  * @brief Reads the characteristic value using the characteristic's value handle.
53779188ed7SMilanka Ringwald  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
53879188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5396da84376SMilanka Ringwald  * @param  callback
5406da84376SMilanka Ringwald  * @param  con_handle
541b45b7749SMilanka Ringwald  * @param  value_handle
542692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
543692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
544692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5456da84376SMilanka Ringwald  */
546b45b7749SMilanka Ringwald 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);
5473deb3ec6SMatthias Ringwald 
5483deb3ec6SMatthias Ringwald /**
54979188ed7SMilanka Ringwald  * @brief Reads the characteric value of all characteristics with the uuid.
55079188ed7SMilanka Ringwald  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
55179188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5526da84376SMilanka Ringwald  * @param  callback
5536da84376SMilanka Ringwald  * @param  con_handle
5546da84376SMilanka Ringwald  * @param  start_handle
5556da84376SMilanka Ringwald  * @param  end_handle
5566da84376SMilanka Ringwald  * @param  uuid16
557692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
558692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
559692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5603deb3ec6SMatthias Ringwald  */
561711e6c80SMatthias Ringwald 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);
5626da84376SMilanka Ringwald 
5636da84376SMilanka Ringwald /**
56479188ed7SMilanka Ringwald  * @brief Reads the characteric value of all characteristics with the uuid.
56579188ed7SMilanka Ringwald  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
56679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5676da84376SMilanka Ringwald  * @param  callback
5686da84376SMilanka Ringwald  * @param  con_handle
5696da84376SMilanka Ringwald  * @param  start_handle
5706da84376SMilanka Ringwald  * @param  end_handle
5716da84376SMilanka Ringwald  * @param  uuid128
572692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
573692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
574692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5756da84376SMilanka Ringwald  */
576045d700dSDavid Lechner 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);
5773deb3ec6SMatthias Ringwald 
5783deb3ec6SMatthias Ringwald /**
57979188ed7SMilanka Ringwald  * @brief Reads the long characteristic value using the characteristic's value handle.
58079188ed7SMilanka Ringwald  * The value will be returned in several blobs.
58179188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
58279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5836da84376SMilanka Ringwald  * @param  callback
5846da84376SMilanka Ringwald  * @param  con_handle
5856da84376SMilanka Ringwald  * @param  characteristic
586692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
587692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
588692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5893deb3ec6SMatthias Ringwald  */
590711e6c80SMatthias Ringwald 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);
5916da84376SMilanka Ringwald 
5926da84376SMilanka Ringwald /**
59379188ed7SMilanka Ringwald  * @brief Reads the long characteristic value using the characteristic's value handle.
59479188ed7SMilanka Ringwald  * The value will be returned in several blobs.
59579188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
59679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5976da84376SMilanka Ringwald  * @param  callback
5986da84376SMilanka Ringwald  * @param  con_handle
599b45b7749SMilanka Ringwald  * @param  value_handle
600692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
601692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
602692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
6036da84376SMilanka Ringwald  */
604b45b7749SMilanka Ringwald 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);
6056da84376SMilanka Ringwald 
6066da84376SMilanka Ringwald /**
60779188ed7SMilanka Ringwald  * @brief Reads the long characteristic value using the characteristic's value handle.
60879188ed7SMilanka Ringwald  * The value will be returned in several blobs.
60979188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
61079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
6116da84376SMilanka Ringwald  * @param  callback
6126da84376SMilanka Ringwald  * @param  con_handle
613b45b7749SMilanka Ringwald  * @param  value_handle
6146da84376SMilanka Ringwald  * @param  offset
615692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
616692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
617692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
6186da84376SMilanka Ringwald  */
619b45b7749SMilanka Ringwald 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);
6203deb3ec6SMatthias Ringwald 
6213deb3ec6SMatthias Ringwald /*
62279188ed7SMilanka Ringwald  * @brief Read multiple characteristic values.
62379188ed7SMilanka Ringwald  * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event,
62479188ed7SMilanka Ringwald  * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read.
6256da84376SMilanka Ringwald  * @param  callback
6266da84376SMilanka Ringwald  * @param  con_handle
6276da84376SMilanka Ringwald  * @param  num_value_handles
6286da84376SMilanka Ringwald  * @param  value_handles list of handles
62979188ed7SMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
63079188ed7SMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
63179188ed7SMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
6323deb3ec6SMatthias Ringwald  */
633711e6c80SMatthias Ringwald 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);
6343deb3ec6SMatthias Ringwald 
635f125a8efSMatthias Ringwald /*
636f125a8efSMatthias Ringwald  * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer
637f125a8efSMatthias Ringwald  * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event,
638f125a8efSMatthias Ringwald  * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read.
639f125a8efSMatthias Ringwald  * @param  callback
640f125a8efSMatthias Ringwald  * @param  con_handle
641f125a8efSMatthias Ringwald  * @param  num_value_handles
642f125a8efSMatthias Ringwald  * @param  value_handles list of handles
643f125a8efSMatthias Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
644f125a8efSMatthias Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
645f125a8efSMatthias Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
646f125a8efSMatthias Ringwald  */
647f125a8efSMatthias Ringwald uint8_t gatt_client_read_multiple_variable_characteristic_values(btstack_packet_handler_t callback, hci_con_handle_t con_handle, int num_value_handles, uint16_t * value_handles);
648f125a8efSMatthias Ringwald 
6493deb3ec6SMatthias Ringwald /**
65079188ed7SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle without
65179188ed7SMilanka Ringwald  * an acknowledgment that the write was successfully performed.
6526da84376SMilanka Ringwald  * @param  con_handle
653b45b7749SMilanka Ringwald  * @param  value_handle
654b45b7749SMilanka Ringwald  * @param  value_length
6557e6f0853SDavid Lechner  * @param  value is copied on success and does not need to be retained
656692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
657692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
658692bf1adSMilanka Ringwald  *                BTSTACK_ACL_BUFFERS_FULL   , if L2CAP cannot send, there are no free ACL slots
659692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
6603deb3ec6SMatthias Ringwald  */
661b45b7749SMilanka Ringwald 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);
6623deb3ec6SMatthias Ringwald 
6633deb3ec6SMatthias Ringwald /**
66479188ed7SMilanka Ringwald  * @brief Writes the authenticated characteristic value using the characteristic's value handle
66579188ed7SMilanka Ringwald  * without an acknowledgment that the write was successfully performed.
66679188ed7SMilanka Ringwald  * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success,
66779188ed7SMilanka Ringwald  * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored.
6686da84376SMilanka Ringwald  * @param  callback
6696da84376SMilanka Ringwald  * @param  con_handle
6706da84376SMilanka Ringwald  * @param  value_handle
6716da84376SMilanka Ringwald  * @param  message_len
6726da84376SMilanka Ringwald  * @param  message is not copied, make sure memory is accessible until write is done
67340faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
67440faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
675692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
676692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6773deb3ec6SMatthias Ringwald  */
6786da84376SMilanka Ringwald 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);
6793deb3ec6SMatthias Ringwald 
6803deb3ec6SMatthias Ringwald /**
681b2468039SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle.
682b2468039SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
683b2468039SMilanka Ringwald  * The write is successfully performed, if the event's att_status field is set to
684b2468039SMilanka Ringwald  * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
6856da84376SMilanka Ringwald  * @param  callback
6866da84376SMilanka Ringwald  * @param  con_handle
687b45b7749SMilanka Ringwald  * @param  value_handle
688b45b7749SMilanka Ringwald  * @param  value_length
689b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
69040faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
69140faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
692692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
693692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6943deb3ec6SMatthias Ringwald  */
695b45b7749SMilanka Ringwald 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);
6966da84376SMilanka Ringwald 
6976da84376SMilanka Ringwald /**
69879188ed7SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle.
69979188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
70079188ed7SMilanka Ringwald  * 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).
7016da84376SMilanka Ringwald  * @param  callback
7026da84376SMilanka Ringwald  * @param  con_handle
703b45b7749SMilanka Ringwald  * @param  value_handle
704b45b7749SMilanka Ringwald  * @param  value_length
705b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
70640faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
70740faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
708692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
709692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7106da84376SMilanka Ringwald  */
711b45b7749SMilanka Ringwald 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);
7126da84376SMilanka Ringwald 
7136da84376SMilanka Ringwald /**
71479188ed7SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle.
71579188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
71679188ed7SMilanka Ringwald  * 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).
7176da84376SMilanka Ringwald  * @param  callback
7186da84376SMilanka Ringwald  * @param  con_handle
719b45b7749SMilanka Ringwald  * @param  value_handle
7206da84376SMilanka Ringwald  * @param  offset of value
721b45b7749SMilanka Ringwald  * @param  value_length
722b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
72340faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
72440faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
725692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
726692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7276da84376SMilanka Ringwald  */
728b45b7749SMilanka Ringwald 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);
7293deb3ec6SMatthias Ringwald 
7303deb3ec6SMatthias Ringwald /**
73179188ed7SMilanka Ringwald  * @brief Writes of the long characteristic value using the characteristic's value handle.
73279188ed7SMilanka Ringwald  * It uses server response to validate that the write was correctly received.
73379188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write.
73479188ed7SMilanka Ringwald  * 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).
7356da84376SMilanka Ringwald  * @param  callback
7366da84376SMilanka Ringwald  * @param  con_handle
737b45b7749SMilanka Ringwald  * @param  value_handle
738b45b7749SMilanka Ringwald  * @param  value_length
739b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
74040faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
74140faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
742692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
743692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7443deb3ec6SMatthias Ringwald  */
745b45b7749SMilanka Ringwald 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);
7463deb3ec6SMatthias Ringwald 
7473deb3ec6SMatthias Ringwald /**
74879188ed7SMilanka Ringwald  * @brief Reads the characteristic descriptor using its handle.
74979188ed7SMilanka Ringwald  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
75079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
7516da84376SMilanka Ringwald  * @param  callback
7526da84376SMilanka Ringwald  * @param  con_handle
7536da84376SMilanka Ringwald  * @param  descriptor
75440faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
75540faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
756692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
757692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7583deb3ec6SMatthias Ringwald  */
759711e6c80SMatthias Ringwald uint8_t gatt_client_read_characteristic_descriptor(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_descriptor_t * descriptor);
7606da84376SMilanka Ringwald 
7616da84376SMilanka Ringwald /**
76279188ed7SMilanka Ringwald  * @brief Reads the characteristic descriptor using its handle.
76379188ed7SMilanka Ringwald  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
76479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
7656da84376SMilanka Ringwald  * @param  callback
7666da84376SMilanka Ringwald  * @param  con_handle
7676da84376SMilanka Ringwald  * @param  descriptor
76840faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
76940faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
770692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
771692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7726da84376SMilanka Ringwald  */
773711e6c80SMatthias Ringwald 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);
7743deb3ec6SMatthias Ringwald 
7753deb3ec6SMatthias Ringwald /**
77679188ed7SMilanka Ringwald  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
77779188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
77879188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
7796da84376SMilanka Ringwald  * @param  callback
7806da84376SMilanka Ringwald  * @param  con_handle
781b45b7749SMilanka Ringwald  * @param  descriptor
78240faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
78340faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
784692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
785692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7863deb3ec6SMatthias Ringwald  */
787711e6c80SMatthias Ringwald 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);
7886da84376SMilanka Ringwald 
7896da84376SMilanka Ringwald /**
79079188ed7SMilanka Ringwald  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
79179188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
79279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
7936da84376SMilanka Ringwald  * @param  callback
7946da84376SMilanka Ringwald  * @param  con_handle
7956da84376SMilanka Ringwald  * @param  descriptor_handle
79640faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
79740faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
798692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
799692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8006da84376SMilanka Ringwald  */
801711e6c80SMatthias Ringwald 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);
8026da84376SMilanka Ringwald 
8036da84376SMilanka Ringwald /**
80479188ed7SMilanka Ringwald  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
80579188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
80679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
8076da84376SMilanka Ringwald  * @param  callback
8086da84376SMilanka Ringwald  * @param  con_handle
8096da84376SMilanka Ringwald  * @param  descriptor_handle
8106da84376SMilanka Ringwald  * @param  offset
81140faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
81240faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
813692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
814692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8156da84376SMilanka Ringwald  */
816711e6c80SMatthias Ringwald 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);
8173deb3ec6SMatthias Ringwald 
8183deb3ec6SMatthias Ringwald /**
81979188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
82079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
82179188ed7SMilanka Ringwald  * 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).
8226da84376SMilanka Ringwald  * @param  callback
8236da84376SMilanka Ringwald  * @param  con_handle
8246da84376SMilanka Ringwald  * @param  descriptor
825b45b7749SMilanka Ringwald  * @param  value_length
826b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
82740faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
82840faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
829692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
830692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8313deb3ec6SMatthias Ringwald  */
832b45b7749SMilanka Ringwald 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);
8336da84376SMilanka Ringwald 
8346da84376SMilanka Ringwald /**
83579188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
83679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
83779188ed7SMilanka Ringwald  * 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).
8386da84376SMilanka Ringwald  * @param  callback
8396da84376SMilanka Ringwald  * @param  con_handle
8406da84376SMilanka Ringwald  * @param  descriptor_handle
841b45b7749SMilanka Ringwald  * @param  value_length
842b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
84340faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
84440faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
845692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
846692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8476da84376SMilanka Ringwald  */
848b45b7749SMilanka Ringwald 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);
8496da84376SMilanka Ringwald 
8506da84376SMilanka Ringwald /**
85179188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
85279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
85379188ed7SMilanka Ringwald  * 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).
8546da84376SMilanka Ringwald  * @param  callback
8556da84376SMilanka Ringwald  * @param  con_handle
8566da84376SMilanka Ringwald  * @param  descriptor
857b45b7749SMilanka Ringwald  * @param  value_length
858b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
85940faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
86040faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
861692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
862692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8636da84376SMilanka Ringwald  */
864b45b7749SMilanka Ringwald 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);
8656da84376SMilanka Ringwald 
8666da84376SMilanka Ringwald /**
86779188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
86879188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
86979188ed7SMilanka Ringwald  * 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).
8706da84376SMilanka Ringwald  * @param  callback
8716da84376SMilanka Ringwald  * @param  con_handle
8726da84376SMilanka Ringwald  * @param  descriptor_handle
873b45b7749SMilanka Ringwald  * @param  value_length
874b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
87540faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
87640faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
877692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
878692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8796da84376SMilanka Ringwald  */
880b45b7749SMilanka Ringwald 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);
8816da84376SMilanka Ringwald 
8826da84376SMilanka Ringwald /**
88379188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
88479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
88579188ed7SMilanka Ringwald  * 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).
8866da84376SMilanka Ringwald  * @param  callback
8876da84376SMilanka Ringwald  * @param  con_handle
8886da84376SMilanka Ringwald  * @param  descriptor_handle
8896da84376SMilanka Ringwald  * @param  offset of value
890b45b7749SMilanka Ringwald  * @param  value_length
891b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
89240faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
89340faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
894692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
895692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8966da84376SMilanka Ringwald  */
897b45b7749SMilanka Ringwald 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);
8983deb3ec6SMatthias Ringwald 
8993deb3ec6SMatthias Ringwald /**
90079188ed7SMilanka Ringwald  * @brief Writes the client characteristic configuration of the specified characteristic.
90179188ed7SMilanka Ringwald  * It is used to subscribe for notifications or indications of the characteristic value.
90279188ed7SMilanka Ringwald  * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION
90379188ed7SMilanka Ringwald  * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value.
90479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
90579188ed7SMilanka Ringwald  * 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).
9066da84376SMilanka Ringwald  * @param  callback
9076da84376SMilanka Ringwald  * @param  con_handle
9086da84376SMilanka Ringwald  * @param  characteristic
909b7e5512fSMilanka Ringwald  * @param  configuration                                                    GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION
91040faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
91140faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
912692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
913b7e5512fSMilanka Ringwald  *                GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED     if configuring notification, but characteristic has no notification property set
914b7e5512fSMilanka Ringwald  *                GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED       if configuring indication, but characteristic has no indication property set
9156b04f675SMilanka Ringwald  *                ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE         if configuration is invalid
916b7e5512fSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
9173deb3ec6SMatthias Ringwald  */
918711e6c80SMatthias Ringwald 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);
9199c662c9bSMatthias Ringwald 
9209c662c9bSMatthias Ringwald /**
92179188ed7SMilanka Ringwald  * @brief Register for notifications and indications of a characteristic enabled by
92279188ed7SMilanka Ringwald  * the gatt_client_write_client_characteristic_configuration function.
9239c662c9bSMatthias Ringwald  * @param notification struct used to store registration
9246da84376SMilanka Ringwald  * @param callback
925b3f03c84SMatthias Ringwald  * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices
926b3f03c84SMatthias Ringwald  * @param characteristic or NULL to receive updates for all characteristics
9279c662c9bSMatthias Ringwald  */
9286da84376SMilanka Ringwald 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);
9293deb3ec6SMatthias Ringwald 
9303deb3ec6SMatthias Ringwald /**
93179188ed7SMilanka Ringwald  * @brief Stop listening to characteristic value updates registered with
93279188ed7SMilanka Ringwald  * the gatt_client_listen_for_characteristic_value_updates function.
9331f734b5fSMatthias Ringwald  * @param notification struct used in gatt_client_listen_for_characteristic_value_updates
9341f734b5fSMatthias Ringwald  */
9351f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification);
9361f734b5fSMatthias Ringwald 
9371f734b5fSMatthias Ringwald /**
93879188ed7SMilanka Ringwald  * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction.
93979188ed7SMilanka Ringwald  * Call the gatt_client_execute_write function to commit the transaction.
9406da84376SMilanka Ringwald  * @param  callback
9416da84376SMilanka Ringwald  * @param  con_handle
9426da84376SMilanka Ringwald  * @param  attribute_handle
9436da84376SMilanka Ringwald  * @param  offset of value
944b45b7749SMilanka Ringwald  * @param  value_length
945b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
9463deb3ec6SMatthias Ringwald  */
947b45b7749SMilanka Ringwald 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);
9483deb3ec6SMatthias Ringwald 
9493deb3ec6SMatthias Ringwald /**
9506da84376SMilanka Ringwald  * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received.
9516da84376SMilanka Ringwald  * @param  callback
9526da84376SMilanka Ringwald  * @param  con_handle
95340faeb84SMilanka Ringwald  * @return status
9543deb3ec6SMatthias Ringwald  */
955711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
9563deb3ec6SMatthias Ringwald 
9573deb3ec6SMatthias Ringwald /**
9586da84376SMilanka Ringwald  * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received.
9596da84376SMilanka Ringwald  * @param  callback
9606da84376SMilanka Ringwald  * @param  con_handle
96140faeb84SMilanka Ringwald  * @return status
9623deb3ec6SMatthias Ringwald  */
963711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
9643deb3ec6SMatthias Ringwald 
96559d34cd2SMatthias Ringwald /**
96653e9c18fSMatthias Ringwald  * @brief Request callback when regular gatt query can be sent
96753e9c18fSMatthias Ringwald  * @note callback might happen during call to this function
96853e9c18fSMatthias Ringwald  * @param callback_registration to point to callback function and context information
96953e9c18fSMatthias Ringwald  * @param con_handle
97053e9c18fSMatthias Ringwald  * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
97153e9c18fSMatthias Ringwald  */
97253e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
97353e9c18fSMatthias Ringwald 
97453e9c18fSMatthias Ringwald /**
97559d34cd2SMatthias Ringwald  * @brief Request callback when writing characteristic value without response is possible
97653e9c18fSMatthias Ringwald  * @note callback might happen during call to this function
97759d34cd2SMatthias Ringwald  * @param callback_registration to point to callback function and context information
97859d34cd2SMatthias Ringwald  * @param con_handle
97959d34cd2SMatthias Ringwald  * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
98059d34cd2SMatthias Ringwald  */
98159d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
98259d34cd2SMatthias Ringwald 
98359d34cd2SMatthias Ringwald 
98459d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually
98559d34cd2SMatthias Ringwald /**
98659d34cd2SMatthias Ringwald  * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees
98759d34cd2SMatthias Ringwald  * a single successful gatt_client_write_value_of_characteristic_without_response call.
98859d34cd2SMatthias Ringwald  * @deprecated please use gatt_client_request_to_write_without_response instead
98959d34cd2SMatthias Ringwald  * @param  callback
99059d34cd2SMatthias Ringwald  * @param  con_handle
99159d34cd2SMatthias Ringwald  * @return status
99259d34cd2SMatthias Ringwald  */
99359d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
99459d34cd2SMatthias Ringwald 
99559d34cd2SMatthias Ringwald 
9963deb3ec6SMatthias Ringwald /* API_END */
9973deb3ec6SMatthias Ringwald 
9986ba2ad22SMatthias Ringwald // used by generated btstack_event.c
9996ba2ad22SMatthias Ringwald 
1000313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service);
1001313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic);
1002313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor);
10036ba2ad22SMatthias Ringwald 
1004a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
1005a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size);
100640faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client);
1007a6121b51SMilanka Ringwald #endif
1008a6121b51SMilanka Ringwald 
10093deb3ec6SMatthias Ringwald #if defined __cplusplus
10103deb3ec6SMatthias Ringwald }
10113deb3ec6SMatthias Ringwald #endif
10123deb3ec6SMatthias Ringwald 
10133deb3ec6SMatthias Ringwald #endif
1014