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 48b1da4983SMatthias Ringwald // spec defines 100 ms, PTS might indicate an error if we sent after 100 ms 49b1da4983SMatthias Ringwald #define GATT_CLIENT_COLLISION_BACKOFF_MS 150 503deb3ec6SMatthias Ringwald #if defined __cplusplus 513deb3ec6SMatthias Ringwald extern "C" { 523deb3ec6SMatthias Ringwald #endif 533deb3ec6SMatthias Ringwald 543deb3ec6SMatthias Ringwald typedef enum { 553deb3ec6SMatthias Ringwald P_READY, 56544a5845SMatthias Ringwald P_W2_EMIT_QUERY_COMPLETE_EVENT, 573deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_QUERY, 583deb3ec6SMatthias Ringwald P_W4_SERVICE_QUERY_RESULT, 593deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_WITH_UUID_QUERY, 603deb3ec6SMatthias Ringwald P_W4_SERVICE_WITH_UUID_RESULT, 613deb3ec6SMatthias Ringwald 623deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY, 633deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT, 643deb3ec6SMatthias Ringwald P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY, 653deb3ec6SMatthias Ringwald P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT, 663deb3ec6SMatthias Ringwald 673deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, 683deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT, 693deb3ec6SMatthias Ringwald 703deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_QUERY, 713deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_QUERY_RESULT, 723deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, 733deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT, 743deb3ec6SMatthias Ringwald 753deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY, 763deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_VALUE_RESULT, 773deb3ec6SMatthias Ringwald 783deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_QUERY, 793deb3ec6SMatthias Ringwald P_W4_READ_BLOB_RESULT, 803deb3ec6SMatthias Ringwald 813deb3ec6SMatthias Ringwald P_W2_SEND_READ_BY_TYPE_REQUEST, 823deb3ec6SMatthias Ringwald P_W4_READ_BY_TYPE_RESPONSE, 833deb3ec6SMatthias Ringwald 843deb3ec6SMatthias Ringwald P_W2_SEND_READ_MULTIPLE_REQUEST, 853deb3ec6SMatthias Ringwald P_W4_READ_MULTIPLE_RESPONSE, 863deb3ec6SMatthias Ringwald 87f125a8efSMatthias Ringwald P_W2_SEND_READ_MULTIPLE_VARIABLE_REQUEST, 88f125a8efSMatthias Ringwald P_W4_READ_MULTIPLE_VARIABLE_RESPONSE, 89f125a8efSMatthias Ringwald 903deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, 913deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, 923deb3ec6SMatthias Ringwald 933deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE, 943deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_RESULT, 953deb3ec6SMatthias Ringwald P_W2_PREPARE_RELIABLE_WRITE, 963deb3ec6SMatthias Ringwald P_W4_PREPARE_RELIABLE_WRITE_RESULT, 973deb3ec6SMatthias Ringwald 983deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE, 993deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_RESULT, 1003deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE, 1013deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_RESULT, 1023deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, 1033deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, 1043deb3ec6SMatthias Ringwald 105abdc9fb5SMatthias Ringwald #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY 106abdc9fb5SMatthias Ringwald P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 107abdc9fb5SMatthias Ringwald P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 108abdc9fb5SMatthias Ringwald #else 1093deb3ec6SMatthias Ringwald P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 1103deb3ec6SMatthias Ringwald P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 111abdc9fb5SMatthias Ringwald #endif 1123deb3ec6SMatthias Ringwald P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, 1133deb3ec6SMatthias Ringwald P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, 1143deb3ec6SMatthias Ringwald 1153deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY, 1163deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, 1173deb3ec6SMatthias Ringwald 1183deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, 1193deb3ec6SMatthias Ringwald P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, 1203deb3ec6SMatthias Ringwald 1213deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR, 1223deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1233deb3ec6SMatthias Ringwald 1243deb3ec6SMatthias Ringwald // all long writes use this 1253deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, 1263deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1273deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, 1283deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1293deb3ec6SMatthias Ringwald 1303deb3ec6SMatthias Ringwald // gatt reliable write API use this (manual version of the above) 1313deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_SINGLE, 1323deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_SINGLE_RESULT, 1333deb3ec6SMatthias Ringwald 134793cf6ceSMatthias Ringwald P_W4_IDENTITY_RESOLVING, 1353deb3ec6SMatthias Ringwald P_W4_CMAC_READY, 1363deb3ec6SMatthias Ringwald P_W4_CMAC_RESULT, 1373deb3ec6SMatthias Ringwald P_W2_SEND_SIGNED_WRITE, 1384c7c987fSMatthias Ringwald P_W4_SEND_SIGNED_WRITE_DONE, 1391450cdc6SMatthias Ringwald 1401450cdc6SMatthias Ringwald P_W2_SDP_QUERY, 1411450cdc6SMatthias Ringwald P_W4_SDP_QUERY, 142180cbe79SMatthias Ringwald P_W2_L2CAP_CONNECT, 1431450cdc6SMatthias Ringwald P_W4_L2CAP_CONNECTION, 14474daebdeSMatthias Ringwald P_W2_EMIT_CONNECTED, 145df0a5c68SMatthias Ringwald P_L2CAP_CLOSED, 1463deb3ec6SMatthias Ringwald } gatt_client_state_t; 1473deb3ec6SMatthias Ringwald 1483deb3ec6SMatthias Ringwald 1493deb3ec6SMatthias Ringwald typedef enum{ 1503deb3ec6SMatthias Ringwald SEND_MTU_EXCHANGE, 1513deb3ec6SMatthias Ringwald SENT_MTU_EXCHANGE, 1525cf6c434SJakob Krantz MTU_EXCHANGED, 1535cf6c434SJakob Krantz MTU_AUTO_EXCHANGE_DISABLED 1543deb3ec6SMatthias Ringwald } gatt_client_mtu_t; 1553deb3ec6SMatthias Ringwald 156cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 157cbd76cecSMatthias Ringwald typedef enum { 158cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_IDLE, 1597627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W2_SEND, 1607627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W4_DONE, 16126166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND, 16226166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE, 16326166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND, 16426166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE, 16526166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND, 16626166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE, 1677627a0deSMatthias Ringwald GATT_CLIENT_EATT_L2CAP_SETUP, 168cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_READY, 169cbd76cecSMatthias Ringwald } gatt_client_eatt_state_t; 170cbd76cecSMatthias Ringwald #endif 171cbd76cecSMatthias Ringwald 1723deb3ec6SMatthias Ringwald typedef struct gatt_client{ 173665d90f2SMatthias Ringwald btstack_linked_item_t item; 1744c7c987fSMatthias Ringwald 175052dc82aSMatthias Ringwald gatt_client_state_t state; 1763deb3ec6SMatthias Ringwald 1779c662c9bSMatthias Ringwald // user callback 1789c662c9bSMatthias Ringwald btstack_packet_handler_t callback; 1793deb3ec6SMatthias Ringwald 18047181045SMatthias Ringwald // can write without response callback 18147181045SMatthias Ringwald btstack_packet_handler_t write_without_response_callback; 18247181045SMatthias Ringwald 18359d34cd2SMatthias Ringwald // can write without response requests 18459d34cd2SMatthias Ringwald btstack_linked_list_t write_without_response_requests; 18559d34cd2SMatthias Ringwald 18653e9c18fSMatthias Ringwald // regular gatt query requests 18753e9c18fSMatthias Ringwald btstack_linked_list_t query_requests; 18853e9c18fSMatthias Ringwald 189fc64f94aSMatthias Ringwald hci_con_handle_t con_handle; 190f4b33574SMatthias Ringwald 191e9cdf30bSMatthias Ringwald att_bearer_type_t bearer_type; 192e9cdf30bSMatthias Ringwald 193*1aa186afSMatthias Ringwald #if defined(ENABLE_GATT_OVER_CLASSIC) || defined(ENABLE_GATT_OVER_EATT) 194*1aa186afSMatthias Ringwald uint16_t l2cap_cid; 195*1aa186afSMatthias Ringwald #endif 196*1aa186afSMatthias Ringwald 1971450cdc6SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 1981450cdc6SMatthias Ringwald bd_addr_t addr; 1991450cdc6SMatthias Ringwald uint16_t l2cap_psm; 200052dc82aSMatthias Ringwald btstack_context_callback_registration_t callback_request; 2011450cdc6SMatthias Ringwald #endif 2021450cdc6SMatthias Ringwald 203cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 204cbd76cecSMatthias Ringwald gatt_client_eatt_state_t eatt_state; 2057627a0deSMatthias Ringwald btstack_linked_list_t eatt_clients; 2067627a0deSMatthias Ringwald uint8_t * eatt_storage_buffer; 2077627a0deSMatthias Ringwald uint16_t eatt_storage_size; 2087627a0deSMatthias Ringwald uint8_t eatt_num_clients; 2097627a0deSMatthias Ringwald uint8_t gatt_server_supported_features; 2107627a0deSMatthias Ringwald uint16_t gatt_service_start_group_handle; 2117627a0deSMatthias Ringwald uint16_t gatt_service_end_group_handle; 212cbd76cecSMatthias Ringwald uint16_t gatt_client_supported_features_handle; 213cbd76cecSMatthias Ringwald #endif 214cbd76cecSMatthias Ringwald 2153deb3ec6SMatthias Ringwald uint16_t mtu; 2163deb3ec6SMatthias Ringwald gatt_client_mtu_t mtu_state; 2173deb3ec6SMatthias Ringwald 2183deb3ec6SMatthias Ringwald uint16_t uuid16; 2193deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 2203deb3ec6SMatthias Ringwald 2213deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2223deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2233deb3ec6SMatthias Ringwald 2243deb3ec6SMatthias Ringwald uint16_t query_start_handle; 2253deb3ec6SMatthias Ringwald uint16_t query_end_handle; 2263deb3ec6SMatthias Ringwald 2273deb3ec6SMatthias Ringwald uint8_t characteristic_properties; 2283deb3ec6SMatthias Ringwald uint16_t characteristic_start_handle; 2293deb3ec6SMatthias Ringwald 2303deb3ec6SMatthias Ringwald uint16_t attribute_handle; 2313deb3ec6SMatthias Ringwald uint16_t attribute_offset; 2323deb3ec6SMatthias Ringwald uint16_t attribute_length; 2333deb3ec6SMatthias Ringwald uint8_t* attribute_value; 2343deb3ec6SMatthias Ringwald 2353deb3ec6SMatthias Ringwald // read multiple characteristic values 2363deb3ec6SMatthias Ringwald uint16_t read_multiple_handle_count; 2373deb3ec6SMatthias Ringwald uint16_t * read_multiple_handles; 2383deb3ec6SMatthias Ringwald 2393deb3ec6SMatthias Ringwald uint16_t client_characteristic_configuration_handle; 2403deb3ec6SMatthias Ringwald uint8_t client_characteristic_configuration_value[2]; 2413deb3ec6SMatthias Ringwald 242ab415e75SMatthias Ringwald bool filter_with_uuid; 24352377058SMatthias Ringwald bool send_confirmation; 2443deb3ec6SMatthias Ringwald 2453deb3ec6SMatthias Ringwald int le_device_index; 2463deb3ec6SMatthias Ringwald uint8_t cmac[8]; 2473deb3ec6SMatthias Ringwald 248ec820d77SMatthias Ringwald btstack_timer_source_t gc_timeout; 249f4b33574SMatthias Ringwald 250f4b33574SMatthias Ringwald uint8_t security_counter; 2512197dbafSMatthias Ringwald bool wait_for_authentication_complete; 252f4b33574SMatthias Ringwald uint8_t pending_error_code; 253f4b33574SMatthias Ringwald 2548918bbdaSMatthias Ringwald bool reencryption_active; 2558918bbdaSMatthias Ringwald uint8_t reencryption_result; 2568918bbdaSMatthias Ringwald 2571dfae9c7SMatthias Ringwald gap_security_level_t security_level; 2581dfae9c7SMatthias Ringwald 2593deb3ec6SMatthias Ringwald } gatt_client_t; 2603deb3ec6SMatthias Ringwald 2619c662c9bSMatthias Ringwald typedef struct gatt_client_notification { 262665d90f2SMatthias Ringwald btstack_linked_item_t item; 263b6e96f14SMatthias Ringwald btstack_packet_handler_t callback; 264711e6c80SMatthias Ringwald hci_con_handle_t con_handle; 2659c662c9bSMatthias Ringwald uint16_t attribute_handle; 2669c662c9bSMatthias Ringwald } gatt_client_notification_t; 2673deb3ec6SMatthias Ringwald 2683deb3ec6SMatthias Ringwald /* API_START */ 2693deb3ec6SMatthias Ringwald 270d25c33e5SMatthias Ringwald typedef struct { 2713deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2723deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2733deb3ec6SMatthias Ringwald uint16_t uuid16; 2743deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 275d25c33e5SMatthias Ringwald } gatt_client_service_t; 2763deb3ec6SMatthias Ringwald 277d25c33e5SMatthias Ringwald typedef struct { 2783deb3ec6SMatthias Ringwald uint16_t start_handle; 2793deb3ec6SMatthias Ringwald uint16_t value_handle; 2803deb3ec6SMatthias Ringwald uint16_t end_handle; 2813deb3ec6SMatthias Ringwald uint16_t properties; 2823deb3ec6SMatthias Ringwald uint16_t uuid16; 2833deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 284d25c33e5SMatthias Ringwald } gatt_client_characteristic_t; 2853deb3ec6SMatthias Ringwald 286d25c33e5SMatthias Ringwald typedef struct { 2873deb3ec6SMatthias Ringwald uint16_t handle; 2883deb3ec6SMatthias Ringwald uint16_t uuid16; 2893deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 290d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t; 2913deb3ec6SMatthias Ringwald 2923deb3ec6SMatthias Ringwald /** 2933deb3ec6SMatthias Ringwald * @brief Set up GATT client. 2943deb3ec6SMatthias Ringwald */ 2953deb3ec6SMatthias Ringwald void gatt_client_init(void); 2963deb3ec6SMatthias Ringwald 2973deb3ec6SMatthias Ringwald /** 29811279da7SMatthias Ringwald * @brief Set minimum required security level for GATT Client 29911279da7SMatthias Ringwald * @note The Bluetooth specification makes the GATT Server responsible to check for security. 300b11289a8SMatthias Ringwald * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. 301b11289a8SMatthias Ringwald * If your application is exchanging sensitive data with a remote device, you would need to manually check 302b11289a8SMatthias Ringwald * the security level before sending/receive such data. 303b11289a8SMatthias Ringwald * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange 304b11289a8SMatthias Ringwald * until the required security level is established. 305b11289a8SMatthias Ringwald * gatt_client_request_can_write_without_response_event does not trigger authentication 30659d34cd2SMatthias Ringwald * gatt_client_request_to_write_without_response does not trigger authentication 30711279da7SMatthias Ringwald * @pram level, default LEVEL_0 (no encryption required) 30811279da7SMatthias Ringwald */ 30911279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level); 31011279da7SMatthias Ringwald 31111279da7SMatthias Ringwald /** 3121450cdc6SMatthias Ringwald * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection 313effecf77SMatthias Ringwald * GATT_EVENT_CONNECTED with status and con_handle for other API functions 314effecf77SMatthias Ringwald * is emitted on connection complete. 315effecf77SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC. 3161450cdc6SMatthias Ringwald * @param addr 3171450cdc6SMatthias Ringwald * @return status 3181450cdc6SMatthias Ringwald */ 3191450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); 3201450cdc6SMatthias Ringwald 3211450cdc6SMatthias Ringwald /** 3221450cdc6SMatthias Ringwald * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server 3231450cdc6SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC 324effecf77SMatthias Ringwald * @param con_handle 3251450cdc6SMatthias Ringwald * @return status 3261450cdc6SMatthias Ringwald */ 3271450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3281450cdc6SMatthias Ringwald 3291450cdc6SMatthias Ringwald /** 3307627a0deSMatthias Ringwald * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection 3317627a0deSMatthias Ringwald * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events 33226166ecfSMatthias Ringwald * @param con_handle 33326166ecfSMatthias Ringwald * @param num_channels 3347627a0deSMatthias Ringwald * @param storage_buffer for L2CAP connection 3358540586aSMatthias Ringwald * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes 33626166ecfSMatthias Ringwald * @return 33726166ecfSMatthias Ringwald */ 33826166ecfSMatthias 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); 33926166ecfSMatthias Ringwald 34026166ecfSMatthias Ringwald /** 34179188ed7SMilanka Ringwald * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, 34279188ed7SMilanka Ringwald * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). 3436da84376SMilanka Ringwald * @param con_handle 3446da84376SMilanka Ringwald * @param mtu 34540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 34640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 347692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled 348692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 3493deb3ec6SMatthias Ringwald */ 350fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); 3513deb3ec6SMatthias Ringwald 3523deb3ec6SMatthias Ringwald /** 35379188ed7SMilanka Ringwald * @brief Sets whether a MTU Exchange Request shall be automatically send before the 35479188ed7SMilanka Ringwald * first attribute read request is send. Default is enabled. 3556da84376SMilanka Ringwald * @param enabled 3565cf6c434SJakob Krantz */ 3575cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); 3585cf6c434SJakob Krantz 3595cf6c434SJakob Krantz /** 36079188ed7SMilanka Ringwald * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU 36179188ed7SMilanka Ringwald * when gatt_client_mtu_enable_auto_negotiation is disabled. 3626da84376SMilanka Ringwald * @param callback 3636da84376SMilanka Ringwald * @param con_handle 3645cf6c434SJakob Krantz */ 3655cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3665cf6c434SJakob Krantz 3675cf6c434SJakob Krantz /** 368aacf1b1aSMilanka Ringwald * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. 3696da84376SMilanka Ringwald * @param con_handle 370692bf1adSMilanka Ringwald * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 3713deb3ec6SMatthias Ringwald */ 372fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle); 3733deb3ec6SMatthias Ringwald 3743deb3ec6SMatthias Ringwald /** 37579188ed7SMilanka Ringwald * @brief Discovers all primary services. 37679188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 37779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3786da84376SMilanka Ringwald * @param callback 3796da84376SMilanka Ringwald * @param con_handle 380692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 381692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 382692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 3833deb3ec6SMatthias Ringwald */ 384711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3853deb3ec6SMatthias Ringwald 3863deb3ec6SMatthias Ringwald /** 38779188ed7SMilanka Ringwald * @brief Discovers all secondary services. 38879188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 38979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3908d1f34d3SMatheus Eduardo Garbelini * @param callback 3918d1f34d3SMatheus Eduardo Garbelini * @param con_handle 3928d1f34d3SMatheus Eduardo Garbelini * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 3938d1f34d3SMatheus Eduardo Garbelini * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 3948d1f34d3SMatheus Eduardo Garbelini * ERROR_CODE_SUCCESS , if query is successfully registered 3958d1f34d3SMatheus Eduardo Garbelini */ 3968d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3978d1f34d3SMatheus Eduardo Garbelini 3988d1f34d3SMatheus Eduardo Garbelini /** 39979188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 40079188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 40179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4026da84376SMilanka Ringwald * @param callback 4036da84376SMilanka Ringwald * @param con_handle 4046da84376SMilanka Ringwald * @param uuid16 405692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 406692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 407692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4083deb3ec6SMatthias Ringwald */ 409711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); 4106da84376SMilanka Ringwald 4116da84376SMilanka Ringwald /** 41279188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 41379188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 41479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4156da84376SMilanka Ringwald * @param callback 4166da84376SMilanka Ringwald * @param con_handle 4176da84376SMilanka Ringwald * @param uuid128 418692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 419692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 420692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4216da84376SMilanka Ringwald */ 4226da84376SMilanka 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); 4233deb3ec6SMatthias Ringwald 4243deb3ec6SMatthias Ringwald /** 42579188ed7SMilanka Ringwald * @brief Finds included services within the specified service. 42679188ed7SMilanka Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 42779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 42879188ed7SMilanka Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 42979188ed7SMilanka Ringwald * an ATT find information request for the returned start group handle 43079188ed7SMilanka Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 43179188ed7SMilanka Ringwald * to the list of all primary services. 4326da84376SMilanka Ringwald * @param callback 4336da84376SMilanka Ringwald * @param con_handle 4346da84376SMilanka Ringwald * @param service 435692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 436692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 437692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4383deb3ec6SMatthias Ringwald */ 439711e6c80SMatthias 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); 4403deb3ec6SMatthias Ringwald 4413deb3ec6SMatthias Ringwald /** 44279188ed7SMilanka Ringwald * @brief Discovers all characteristics within the specified service. 44379188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 44479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4456da84376SMilanka Ringwald * @param callback 4466da84376SMilanka Ringwald * @param con_handle 4476da84376SMilanka Ringwald * @param service 448692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 449692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 450692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4513deb3ec6SMatthias Ringwald */ 452711e6c80SMatthias 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); 4533deb3ec6SMatthias Ringwald 4543deb3ec6SMatthias Ringwald /** 45579188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within 45679188ed7SMilanka Ringwald * the specified service or handle range, and return those that match the given UUID. 45779188ed7SMilanka Ringwald * 45879188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 45979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4606da84376SMilanka Ringwald * @param callback 4616da84376SMilanka Ringwald * @param con_handle 4626da84376SMilanka Ringwald * @param start_handle 4636da84376SMilanka Ringwald * @param end_handle 4646da84376SMilanka Ringwald * @param uuid16 465692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 466692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 467692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4683deb3ec6SMatthias Ringwald */ 469711e6c80SMatthias 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); 4706da84376SMilanka Ringwald 4716da84376SMilanka Ringwald /** 47279188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 47379188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 47479188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 47579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4766da84376SMilanka Ringwald * @param callback 4776da84376SMilanka Ringwald * @param con_handle 4786da84376SMilanka Ringwald * @param start_handle 4796da84376SMilanka Ringwald * @param end_handle 4806da84376SMilanka Ringwald * @param uuid128 481692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 482692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 483692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4846da84376SMilanka Ringwald */ 485045d700dSDavid 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); 4866da84376SMilanka Ringwald 4876da84376SMilanka Ringwald /** 48879188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 48979188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 49079188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 49179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4926da84376SMilanka Ringwald * @param callback 4936da84376SMilanka Ringwald * @param con_handle 4946da84376SMilanka Ringwald * @param service 4956da84376SMilanka Ringwald * @param uuid16 496692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 497692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 498692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4996da84376SMilanka Ringwald */ 500711e6c80SMatthias 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); 5016da84376SMilanka Ringwald 5026da84376SMilanka Ringwald /** 50379188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 50479188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 50579188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 50679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5076da84376SMilanka Ringwald * @param callback 5086da84376SMilanka Ringwald * @param con_handle 5096da84376SMilanka Ringwald * @param service 5106da84376SMilanka Ringwald * @param uuid128 511692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 512692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 513692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5146da84376SMilanka Ringwald */ 515045d700dSDavid 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); 5163deb3ec6SMatthias Ringwald 5173deb3ec6SMatthias Ringwald /** 51879188ed7SMilanka Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 51979188ed7SMilanka Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 52079188ed7SMilanka Ringwald * 52179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5226da84376SMilanka Ringwald * @param callback 5236da84376SMilanka Ringwald * @param con_handle 5246da84376SMilanka Ringwald * @param characteristic 525692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 526692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 527692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5283deb3ec6SMatthias Ringwald */ 529711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 5303deb3ec6SMatthias Ringwald 5313deb3ec6SMatthias Ringwald /** 53279188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 53379188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 53479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5356da84376SMilanka Ringwald * @param callback 5366da84376SMilanka Ringwald * @param con_handle 5376da84376SMilanka Ringwald * @param characteristic 538692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 539692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 540692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5413deb3ec6SMatthias Ringwald */ 542711e6c80SMatthias 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); 5436da84376SMilanka Ringwald 5446da84376SMilanka Ringwald /** 54579188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 54679188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 54779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5486da84376SMilanka Ringwald * @param callback 5496da84376SMilanka Ringwald * @param con_handle 550b45b7749SMilanka Ringwald * @param value_handle 551692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 552692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 553692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5546da84376SMilanka Ringwald */ 555b45b7749SMilanka 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); 5563deb3ec6SMatthias Ringwald 5573deb3ec6SMatthias Ringwald /** 55879188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 55979188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 56079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5616da84376SMilanka Ringwald * @param callback 5626da84376SMilanka Ringwald * @param con_handle 5636da84376SMilanka Ringwald * @param start_handle 5646da84376SMilanka Ringwald * @param end_handle 5656da84376SMilanka Ringwald * @param uuid16 566692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 567692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 568692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5693deb3ec6SMatthias Ringwald */ 570711e6c80SMatthias 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); 5716da84376SMilanka Ringwald 5726da84376SMilanka Ringwald /** 57379188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 57479188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 57579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5766da84376SMilanka Ringwald * @param callback 5776da84376SMilanka Ringwald * @param con_handle 5786da84376SMilanka Ringwald * @param start_handle 5796da84376SMilanka Ringwald * @param end_handle 5806da84376SMilanka Ringwald * @param uuid128 581692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 582692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 583692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5846da84376SMilanka Ringwald */ 585045d700dSDavid 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); 5863deb3ec6SMatthias Ringwald 5873deb3ec6SMatthias Ringwald /** 58879188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 58979188ed7SMilanka Ringwald * The value will be returned in several blobs. 59079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 59179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5926da84376SMilanka Ringwald * @param callback 5936da84376SMilanka Ringwald * @param con_handle 5946da84376SMilanka Ringwald * @param characteristic 595692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 596692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 597692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5983deb3ec6SMatthias Ringwald */ 599711e6c80SMatthias 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); 6006da84376SMilanka Ringwald 6016da84376SMilanka Ringwald /** 60279188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 60379188ed7SMilanka Ringwald * The value will be returned in several blobs. 60479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 60579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6066da84376SMilanka Ringwald * @param callback 6076da84376SMilanka Ringwald * @param con_handle 608b45b7749SMilanka Ringwald * @param value_handle 609692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 610692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 611692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6126da84376SMilanka Ringwald */ 613b45b7749SMilanka 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); 6146da84376SMilanka Ringwald 6156da84376SMilanka Ringwald /** 61679188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 61779188ed7SMilanka Ringwald * The value will be returned in several blobs. 61879188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 61979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6206da84376SMilanka Ringwald * @param callback 6216da84376SMilanka Ringwald * @param con_handle 622b45b7749SMilanka Ringwald * @param value_handle 6236da84376SMilanka Ringwald * @param offset 624692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 625692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 626692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6276da84376SMilanka Ringwald */ 628b45b7749SMilanka 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); 6293deb3ec6SMatthias Ringwald 6303deb3ec6SMatthias Ringwald /* 63179188ed7SMilanka Ringwald * @brief Read multiple characteristic values. 63279188ed7SMilanka Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 63379188ed7SMilanka Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 6346da84376SMilanka Ringwald * @param callback 6356da84376SMilanka Ringwald * @param con_handle 6366da84376SMilanka Ringwald * @param num_value_handles 6376da84376SMilanka Ringwald * @param value_handles list of handles 63879188ed7SMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 63979188ed7SMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 64079188ed7SMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6413deb3ec6SMatthias Ringwald */ 642711e6c80SMatthias 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); 6433deb3ec6SMatthias Ringwald 644f125a8efSMatthias Ringwald /* 645f125a8efSMatthias Ringwald * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer 646f125a8efSMatthias Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 647f125a8efSMatthias Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 648f125a8efSMatthias Ringwald * @param callback 649f125a8efSMatthias Ringwald * @param con_handle 650f125a8efSMatthias Ringwald * @param num_value_handles 651f125a8efSMatthias Ringwald * @param value_handles list of handles 652f125a8efSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 653f125a8efSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 654f125a8efSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 655f125a8efSMatthias Ringwald */ 656f125a8efSMatthias 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); 657f125a8efSMatthias Ringwald 6583deb3ec6SMatthias Ringwald /** 65979188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle without 66079188ed7SMilanka Ringwald * an acknowledgment that the write was successfully performed. 6616da84376SMilanka Ringwald * @param con_handle 662b45b7749SMilanka Ringwald * @param value_handle 663b45b7749SMilanka Ringwald * @param value_length 6647e6f0853SDavid Lechner * @param value is copied on success and does not need to be retained 665692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 666692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 667692bf1adSMilanka Ringwald * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots 668692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6693deb3ec6SMatthias Ringwald */ 670b45b7749SMilanka 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); 6713deb3ec6SMatthias Ringwald 6723deb3ec6SMatthias Ringwald /** 67379188ed7SMilanka Ringwald * @brief Writes the authenticated characteristic value using the characteristic's value handle 67479188ed7SMilanka Ringwald * without an acknowledgment that the write was successfully performed. 67579188ed7SMilanka Ringwald * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, 67679188ed7SMilanka Ringwald * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. 6776da84376SMilanka Ringwald * @param callback 6786da84376SMilanka Ringwald * @param con_handle 6796da84376SMilanka Ringwald * @param value_handle 6806da84376SMilanka Ringwald * @param message_len 6816da84376SMilanka Ringwald * @param message is not copied, make sure memory is accessible until write is done 68240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 68340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 684692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 685692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 6863deb3ec6SMatthias Ringwald */ 6876da84376SMilanka 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); 6883deb3ec6SMatthias Ringwald 6893deb3ec6SMatthias Ringwald /** 690b2468039SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 691b2468039SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 692b2468039SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to 693b2468039SMilanka Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 6946da84376SMilanka Ringwald * @param callback 6956da84376SMilanka Ringwald * @param con_handle 696b45b7749SMilanka Ringwald * @param value_handle 697b45b7749SMilanka Ringwald * @param value_length 698b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 69940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 70040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 701692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 702692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7033deb3ec6SMatthias Ringwald */ 704b45b7749SMilanka 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); 7056da84376SMilanka Ringwald 7066da84376SMilanka Ringwald /** 70779188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 70879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 70979188ed7SMilanka 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). 7106da84376SMilanka Ringwald * @param callback 7116da84376SMilanka Ringwald * @param con_handle 712b45b7749SMilanka Ringwald * @param value_handle 713b45b7749SMilanka Ringwald * @param value_length 714b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 71540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 71640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 717692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 718692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7196da84376SMilanka Ringwald */ 720b45b7749SMilanka 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); 7216da84376SMilanka Ringwald 7226da84376SMilanka Ringwald /** 72379188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 72479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 72579188ed7SMilanka 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). 7266da84376SMilanka Ringwald * @param callback 7276da84376SMilanka Ringwald * @param con_handle 728b45b7749SMilanka Ringwald * @param value_handle 7296da84376SMilanka Ringwald * @param offset of value 730b45b7749SMilanka Ringwald * @param value_length 731b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 73240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 73340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 734692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 735692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7366da84376SMilanka Ringwald */ 737b45b7749SMilanka 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); 7383deb3ec6SMatthias Ringwald 7393deb3ec6SMatthias Ringwald /** 74079188ed7SMilanka Ringwald * @brief Writes of the long characteristic value using the characteristic's value handle. 74179188ed7SMilanka Ringwald * It uses server response to validate that the write was correctly received. 74279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. 74379188ed7SMilanka 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). 7446da84376SMilanka Ringwald * @param callback 7456da84376SMilanka Ringwald * @param con_handle 746b45b7749SMilanka Ringwald * @param value_handle 747b45b7749SMilanka Ringwald * @param value_length 748b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 74940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 75040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 751692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 752692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7533deb3ec6SMatthias Ringwald */ 754b45b7749SMilanka 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); 7553deb3ec6SMatthias Ringwald 7563deb3ec6SMatthias Ringwald /** 75779188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 75879188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 75979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7606da84376SMilanka Ringwald * @param callback 7616da84376SMilanka Ringwald * @param con_handle 7626da84376SMilanka Ringwald * @param descriptor 76340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 76440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 765692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 766692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7673deb3ec6SMatthias Ringwald */ 768711e6c80SMatthias 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); 7696da84376SMilanka Ringwald 7706da84376SMilanka Ringwald /** 77179188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 77279188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 77379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7746da84376SMilanka Ringwald * @param callback 7756da84376SMilanka Ringwald * @param con_handle 7766da84376SMilanka Ringwald * @param descriptor 77740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 77840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 779692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 780692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7816da84376SMilanka Ringwald */ 782711e6c80SMatthias 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); 7833deb3ec6SMatthias Ringwald 7843deb3ec6SMatthias Ringwald /** 78579188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 78679188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 78779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7886da84376SMilanka Ringwald * @param callback 7896da84376SMilanka Ringwald * @param con_handle 790b45b7749SMilanka Ringwald * @param descriptor 79140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 79240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 793692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 794692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7953deb3ec6SMatthias Ringwald */ 796711e6c80SMatthias 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); 7976da84376SMilanka Ringwald 7986da84376SMilanka Ringwald /** 79979188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 80079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 80179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8026da84376SMilanka Ringwald * @param callback 8036da84376SMilanka Ringwald * @param con_handle 8046da84376SMilanka Ringwald * @param descriptor_handle 80540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 80640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 807692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 808692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8096da84376SMilanka Ringwald */ 810711e6c80SMatthias 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); 8116da84376SMilanka Ringwald 8126da84376SMilanka Ringwald /** 81379188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 81479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 81579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8166da84376SMilanka Ringwald * @param callback 8176da84376SMilanka Ringwald * @param con_handle 8186da84376SMilanka Ringwald * @param descriptor_handle 8196da84376SMilanka Ringwald * @param offset 82040faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 82140faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 822692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 823692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8246da84376SMilanka Ringwald */ 825711e6c80SMatthias 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); 8263deb3ec6SMatthias Ringwald 8273deb3ec6SMatthias Ringwald /** 82879188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 82979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 83079188ed7SMilanka 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). 8316da84376SMilanka Ringwald * @param callback 8326da84376SMilanka Ringwald * @param con_handle 8336da84376SMilanka Ringwald * @param descriptor 834b45b7749SMilanka Ringwald * @param value_length 835b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 83640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 83740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 838692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 839692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8403deb3ec6SMatthias Ringwald */ 841b45b7749SMilanka 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); 8426da84376SMilanka Ringwald 8436da84376SMilanka Ringwald /** 84479188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 84579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 84679188ed7SMilanka 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). 8476da84376SMilanka Ringwald * @param callback 8486da84376SMilanka Ringwald * @param con_handle 8496da84376SMilanka Ringwald * @param descriptor_handle 850b45b7749SMilanka Ringwald * @param value_length 851b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 85240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 85340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 854692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 855692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8566da84376SMilanka Ringwald */ 857b45b7749SMilanka 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); 8586da84376SMilanka Ringwald 8596da84376SMilanka Ringwald /** 86079188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 86179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 86279188ed7SMilanka 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). 8636da84376SMilanka Ringwald * @param callback 8646da84376SMilanka Ringwald * @param con_handle 8656da84376SMilanka Ringwald * @param descriptor 866b45b7749SMilanka Ringwald * @param value_length 867b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 86840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 86940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 870692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 871692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8726da84376SMilanka Ringwald */ 873b45b7749SMilanka 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); 8746da84376SMilanka Ringwald 8756da84376SMilanka Ringwald /** 87679188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 87779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 87879188ed7SMilanka 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). 8796da84376SMilanka Ringwald * @param callback 8806da84376SMilanka Ringwald * @param con_handle 8816da84376SMilanka Ringwald * @param descriptor_handle 882b45b7749SMilanka Ringwald * @param value_length 883b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 88440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 88540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 886692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 887692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8886da84376SMilanka Ringwald */ 889b45b7749SMilanka 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); 8906da84376SMilanka Ringwald 8916da84376SMilanka Ringwald /** 89279188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 89379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 89479188ed7SMilanka 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). 8956da84376SMilanka Ringwald * @param callback 8966da84376SMilanka Ringwald * @param con_handle 8976da84376SMilanka Ringwald * @param descriptor_handle 8986da84376SMilanka Ringwald * @param offset of value 899b45b7749SMilanka Ringwald * @param value_length 900b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 90140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 90240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 903692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 904692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9056da84376SMilanka Ringwald */ 906b45b7749SMilanka 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); 9073deb3ec6SMatthias Ringwald 9083deb3ec6SMatthias Ringwald /** 90979188ed7SMilanka Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 91079188ed7SMilanka Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 91179188ed7SMilanka Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 91279188ed7SMilanka Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 91379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 91479188ed7SMilanka 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). 9156da84376SMilanka Ringwald * @param callback 9166da84376SMilanka Ringwald * @param con_handle 9176da84376SMilanka Ringwald * @param characteristic 918b7e5512fSMilanka Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 91940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 92040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 921692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 922b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 923b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 9246b04f675SMilanka Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 925b7e5512fSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9263deb3ec6SMatthias Ringwald */ 927711e6c80SMatthias 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); 9289c662c9bSMatthias Ringwald 9299c662c9bSMatthias Ringwald /** 93079188ed7SMilanka Ringwald * @brief Register for notifications and indications of a characteristic enabled by 93179188ed7SMilanka Ringwald * the gatt_client_write_client_characteristic_configuration function. 9329c662c9bSMatthias Ringwald * @param notification struct used to store registration 9336da84376SMilanka Ringwald * @param callback 934b3f03c84SMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 935b3f03c84SMatthias Ringwald * @param characteristic or NULL to receive updates for all characteristics 9369c662c9bSMatthias Ringwald */ 9376da84376SMilanka 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); 9383deb3ec6SMatthias Ringwald 9393deb3ec6SMatthias Ringwald /** 94079188ed7SMilanka Ringwald * @brief Stop listening to characteristic value updates registered with 94179188ed7SMilanka Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 9421f734b5fSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 9431f734b5fSMatthias Ringwald */ 9441f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); 9451f734b5fSMatthias Ringwald 9461f734b5fSMatthias Ringwald /** 94779188ed7SMilanka Ringwald * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. 94879188ed7SMilanka Ringwald * Call the gatt_client_execute_write function to commit the transaction. 9496da84376SMilanka Ringwald * @param callback 9506da84376SMilanka Ringwald * @param con_handle 9516da84376SMilanka Ringwald * @param attribute_handle 9526da84376SMilanka Ringwald * @param offset of value 953b45b7749SMilanka Ringwald * @param value_length 954b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 9553deb3ec6SMatthias Ringwald */ 956b45b7749SMilanka 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); 9573deb3ec6SMatthias Ringwald 9583deb3ec6SMatthias Ringwald /** 9596da84376SMilanka Ringwald * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9606da84376SMilanka Ringwald * @param callback 9616da84376SMilanka Ringwald * @param con_handle 96240faeb84SMilanka Ringwald * @return status 9633deb3ec6SMatthias Ringwald */ 964711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9653deb3ec6SMatthias Ringwald 9663deb3ec6SMatthias Ringwald /** 9676da84376SMilanka Ringwald * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9686da84376SMilanka Ringwald * @param callback 9696da84376SMilanka Ringwald * @param con_handle 97040faeb84SMilanka Ringwald * @return status 9713deb3ec6SMatthias Ringwald */ 972711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9733deb3ec6SMatthias Ringwald 97459d34cd2SMatthias Ringwald /** 97553e9c18fSMatthias Ringwald * @brief Request callback when regular gatt query can be sent 97653e9c18fSMatthias Ringwald * @note callback might happen during call to this function 97753e9c18fSMatthias Ringwald * @param callback_registration to point to callback function and context information 97853e9c18fSMatthias Ringwald * @param con_handle 97953e9c18fSMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 98053e9c18fSMatthias Ringwald */ 98153e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 98253e9c18fSMatthias Ringwald 98353e9c18fSMatthias Ringwald /** 98448553f67SDirk Helbig * @brief Remove queued callback for regular gatt queries, to be used on disconnect for example 98548553f67SDirk Helbig * @param callback_registration 98648553f67SDirk Helbig * @param con_handle 98748553f67SDirk Helbig * @return ERROR_CODE_SUCCESS if ok 98848553f67SDirk Helbig */ 98948553f67SDirk Helbig uint8_t gatt_client_remove_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 99048553f67SDirk Helbig 99148553f67SDirk Helbig /** 99259d34cd2SMatthias Ringwald * @brief Request callback when writing characteristic value without response is possible 99353e9c18fSMatthias Ringwald * @note callback might happen during call to this function 99459d34cd2SMatthias Ringwald * @param callback_registration to point to callback function and context information 99559d34cd2SMatthias Ringwald * @param con_handle 99659d34cd2SMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 99759d34cd2SMatthias Ringwald */ 99859d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 99959d34cd2SMatthias Ringwald 100059d34cd2SMatthias Ringwald 100159d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually 100259d34cd2SMatthias Ringwald /** 100359d34cd2SMatthias Ringwald * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees 100459d34cd2SMatthias Ringwald * a single successful gatt_client_write_value_of_characteristic_without_response call. 100559d34cd2SMatthias Ringwald * @deprecated please use gatt_client_request_to_write_without_response instead 100659d34cd2SMatthias Ringwald * @param callback 100759d34cd2SMatthias Ringwald * @param con_handle 100859d34cd2SMatthias Ringwald * @return status 100959d34cd2SMatthias Ringwald */ 101059d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 101159d34cd2SMatthias Ringwald 101259d34cd2SMatthias Ringwald 10133deb3ec6SMatthias Ringwald /* API_END */ 10143deb3ec6SMatthias Ringwald 10156ba2ad22SMatthias Ringwald // used by generated btstack_event.c 10166ba2ad22SMatthias Ringwald 1017313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); 1018313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); 1019313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); 10206ba2ad22SMatthias Ringwald 1021a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 1022a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); 102340faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client); 1024a6121b51SMilanka Ringwald #endif 1025a6121b51SMilanka Ringwald 10263deb3ec6SMatthias Ringwald #if defined __cplusplus 10273deb3ec6SMatthias Ringwald } 10283deb3ec6SMatthias Ringwald #endif 10293deb3ec6SMatthias Ringwald 10303deb3ec6SMatthias Ringwald #endif 1031