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 1562acb2842SMatthias Ringwald typedef enum { 1572acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_W2_SEND, 1582acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_W4_DONE, 1592acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_CHARACTERISTICS_W2_SEND, 1602acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_CHARACTERISTICS_W4_DONE, 1612acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_SERVICE_CHANGED_WRITE_CCCD_W2_SEND, 1622acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_SERVICE_CHANGED_WRITE_CCCD_W4_DONE, 1632acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_READ_W2_SEND, 1642acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_READ_W4_DONE, 1652acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_WRITE_CCCD_W2_SEND, 1662acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_WRITE_CCCD_W4_DONE, 1672acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DONE, 1682acb2842SMatthias Ringwald } gatt_client_service_state_t; 1692acb2842SMatthias Ringwald 170cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 171cbd76cecSMatthias Ringwald typedef enum { 172cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_IDLE, 1737627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W2_SEND, 1747627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W4_DONE, 17526166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND, 17626166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE, 17726166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND, 17826166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE, 17926166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND, 18026166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE, 1817627a0deSMatthias Ringwald GATT_CLIENT_EATT_L2CAP_SETUP, 182cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_READY, 183cbd76cecSMatthias Ringwald } gatt_client_eatt_state_t; 184cbd76cecSMatthias Ringwald #endif 185cbd76cecSMatthias Ringwald 1863deb3ec6SMatthias Ringwald typedef struct gatt_client{ 187665d90f2SMatthias Ringwald btstack_linked_item_t item; 1884c7c987fSMatthias Ringwald 189052dc82aSMatthias Ringwald gatt_client_state_t state; 1903deb3ec6SMatthias Ringwald 1919c662c9bSMatthias Ringwald // user callback 1929c662c9bSMatthias Ringwald btstack_packet_handler_t callback; 1933deb3ec6SMatthias Ringwald 19447181045SMatthias Ringwald // can write without response callback 19547181045SMatthias Ringwald btstack_packet_handler_t write_without_response_callback; 19647181045SMatthias Ringwald 19759d34cd2SMatthias Ringwald // can write without response requests 19859d34cd2SMatthias Ringwald btstack_linked_list_t write_without_response_requests; 19959d34cd2SMatthias Ringwald 20053e9c18fSMatthias Ringwald // regular gatt query requests 20153e9c18fSMatthias Ringwald btstack_linked_list_t query_requests; 20253e9c18fSMatthias Ringwald 203fc64f94aSMatthias Ringwald hci_con_handle_t con_handle; 204f4b33574SMatthias Ringwald 205e9cdf30bSMatthias Ringwald att_bearer_type_t bearer_type; 206e9cdf30bSMatthias Ringwald 2071aa186afSMatthias Ringwald #if defined(ENABLE_GATT_OVER_CLASSIC) || defined(ENABLE_GATT_OVER_EATT) 2081aa186afSMatthias Ringwald uint16_t l2cap_cid; 209e4f1c903SMatthias Ringwald bd_addr_t addr; 210*b2d70d58SMatthias Ringwald bd_addr_type_t addr_type; 2111aa186afSMatthias Ringwald #endif 2121aa186afSMatthias Ringwald 2131450cdc6SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 2141450cdc6SMatthias Ringwald uint16_t l2cap_psm; 215052dc82aSMatthias Ringwald btstack_context_callback_registration_t callback_request; 2161450cdc6SMatthias Ringwald #endif 2171450cdc6SMatthias Ringwald 218cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 219cbd76cecSMatthias Ringwald gatt_client_eatt_state_t eatt_state; 2207627a0deSMatthias Ringwald btstack_linked_list_t eatt_clients; 2217627a0deSMatthias Ringwald uint8_t * eatt_storage_buffer; 2227627a0deSMatthias Ringwald uint16_t eatt_storage_size; 2237627a0deSMatthias Ringwald uint8_t eatt_num_clients; 2247627a0deSMatthias Ringwald uint8_t gatt_server_supported_features; 225cbd76cecSMatthias Ringwald uint16_t gatt_client_supported_features_handle; 226cbd76cecSMatthias Ringwald #endif 227cbd76cecSMatthias Ringwald 2283deb3ec6SMatthias Ringwald uint16_t mtu; 2293deb3ec6SMatthias Ringwald gatt_client_mtu_t mtu_state; 2303deb3ec6SMatthias Ringwald 2313deb3ec6SMatthias Ringwald uint16_t uuid16; 2323deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 2333deb3ec6SMatthias Ringwald 2343deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2353deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2363deb3ec6SMatthias Ringwald 2373deb3ec6SMatthias Ringwald uint16_t query_start_handle; 2383deb3ec6SMatthias Ringwald uint16_t query_end_handle; 2393deb3ec6SMatthias Ringwald 2403deb3ec6SMatthias Ringwald uint8_t characteristic_properties; 2413deb3ec6SMatthias Ringwald uint16_t characteristic_start_handle; 2423deb3ec6SMatthias Ringwald 2433deb3ec6SMatthias Ringwald uint16_t attribute_handle; 2443deb3ec6SMatthias Ringwald uint16_t attribute_offset; 2453deb3ec6SMatthias Ringwald uint16_t attribute_length; 2463deb3ec6SMatthias Ringwald uint8_t* attribute_value; 2473deb3ec6SMatthias Ringwald 2483deb3ec6SMatthias Ringwald // read multiple characteristic values 2493deb3ec6SMatthias Ringwald uint16_t read_multiple_handle_count; 2503deb3ec6SMatthias Ringwald uint16_t * read_multiple_handles; 2513deb3ec6SMatthias Ringwald 2523deb3ec6SMatthias Ringwald uint16_t client_characteristic_configuration_handle; 2533deb3ec6SMatthias Ringwald uint8_t client_characteristic_configuration_value[2]; 2543deb3ec6SMatthias Ringwald 255ab415e75SMatthias Ringwald bool filter_with_uuid; 25652377058SMatthias Ringwald bool send_confirmation; 2573deb3ec6SMatthias Ringwald 2583deb3ec6SMatthias Ringwald int le_device_index; 2593deb3ec6SMatthias Ringwald uint8_t cmac[8]; 2603deb3ec6SMatthias Ringwald 261ec820d77SMatthias Ringwald btstack_timer_source_t gc_timeout; 262f4b33574SMatthias Ringwald 263f4b33574SMatthias Ringwald uint8_t security_counter; 2642197dbafSMatthias Ringwald bool wait_for_authentication_complete; 265f4b33574SMatthias Ringwald uint8_t pending_error_code; 266f4b33574SMatthias Ringwald 2678918bbdaSMatthias Ringwald bool reencryption_active; 2688918bbdaSMatthias Ringwald uint8_t reencryption_result; 2698918bbdaSMatthias Ringwald 2701dfae9c7SMatthias Ringwald gap_security_level_t security_level; 2711dfae9c7SMatthias Ringwald 2722acb2842SMatthias Ringwald // GATT Service Changes 2732acb2842SMatthias Ringwald gatt_client_service_state_t gatt_service_state; 2742acb2842SMatthias Ringwald uint16_t gatt_service_start_group_handle; 2752acb2842SMatthias Ringwald uint16_t gatt_service_end_group_handle; 2762acb2842SMatthias Ringwald // - Service Changed 2772acb2842SMatthias Ringwald uint16_t gatt_service_changed_value_handle; 2782acb2842SMatthias Ringwald uint16_t gatt_service_changed_cccd_handle; 2792acb2842SMatthias Ringwald uint16_t gatt_service_changed_end_handle; 2802acb2842SMatthias Ringwald // - Database Hash 2812acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_value_handle; 2822acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_cccd_handle; 2832acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_end_handle; 2842acb2842SMatthias Ringwald 2853deb3ec6SMatthias Ringwald } gatt_client_t; 2863deb3ec6SMatthias Ringwald 2879c662c9bSMatthias Ringwald typedef struct gatt_client_notification { 288665d90f2SMatthias Ringwald btstack_linked_item_t item; 289b6e96f14SMatthias Ringwald btstack_packet_handler_t callback; 290711e6c80SMatthias Ringwald hci_con_handle_t con_handle; 2919c662c9bSMatthias Ringwald uint16_t attribute_handle; 2929c662c9bSMatthias Ringwald } gatt_client_notification_t; 2933deb3ec6SMatthias Ringwald 2943deb3ec6SMatthias Ringwald /* API_START */ 2953deb3ec6SMatthias Ringwald 296d25c33e5SMatthias Ringwald typedef struct { 2973deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2983deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2993deb3ec6SMatthias Ringwald uint16_t uuid16; 3003deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 301d25c33e5SMatthias Ringwald } gatt_client_service_t; 3023deb3ec6SMatthias Ringwald 303d25c33e5SMatthias Ringwald typedef struct { 3043deb3ec6SMatthias Ringwald uint16_t start_handle; 3053deb3ec6SMatthias Ringwald uint16_t value_handle; 3063deb3ec6SMatthias Ringwald uint16_t end_handle; 3073deb3ec6SMatthias Ringwald uint16_t properties; 3083deb3ec6SMatthias Ringwald uint16_t uuid16; 3093deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 310d25c33e5SMatthias Ringwald } gatt_client_characteristic_t; 3113deb3ec6SMatthias Ringwald 312d25c33e5SMatthias Ringwald typedef struct { 3133deb3ec6SMatthias Ringwald uint16_t handle; 3143deb3ec6SMatthias Ringwald uint16_t uuid16; 3153deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 316d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t; 3173deb3ec6SMatthias Ringwald 3183deb3ec6SMatthias Ringwald /** 3193deb3ec6SMatthias Ringwald * @brief Set up GATT client. 3203deb3ec6SMatthias Ringwald */ 3213deb3ec6SMatthias Ringwald void gatt_client_init(void); 3223deb3ec6SMatthias Ringwald 3233deb3ec6SMatthias Ringwald /** 32411279da7SMatthias Ringwald * @brief Set minimum required security level for GATT Client 32511279da7SMatthias Ringwald * @note The Bluetooth specification makes the GATT Server responsible to check for security. 326b11289a8SMatthias Ringwald * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. 327b11289a8SMatthias Ringwald * If your application is exchanging sensitive data with a remote device, you would need to manually check 328b11289a8SMatthias Ringwald * the security level before sending/receive such data. 329b11289a8SMatthias Ringwald * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange 330b11289a8SMatthias Ringwald * until the required security level is established. 331b11289a8SMatthias Ringwald * gatt_client_request_can_write_without_response_event does not trigger authentication 33259d34cd2SMatthias Ringwald * gatt_client_request_to_write_without_response does not trigger authentication 33311279da7SMatthias Ringwald * @pram level, default LEVEL_0 (no encryption required) 33411279da7SMatthias Ringwald */ 33511279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level); 33611279da7SMatthias Ringwald 33711279da7SMatthias Ringwald /** 3381450cdc6SMatthias Ringwald * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection 339effecf77SMatthias Ringwald * GATT_EVENT_CONNECTED with status and con_handle for other API functions 340effecf77SMatthias Ringwald * is emitted on connection complete. 341effecf77SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC. 3421450cdc6SMatthias Ringwald * @param addr 3431450cdc6SMatthias Ringwald * @return status 3441450cdc6SMatthias Ringwald */ 3451450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); 3461450cdc6SMatthias Ringwald 3471450cdc6SMatthias Ringwald /** 3481450cdc6SMatthias Ringwald * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server 3491450cdc6SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC 350effecf77SMatthias Ringwald * @param con_handle 3511450cdc6SMatthias Ringwald * @return status 3521450cdc6SMatthias Ringwald */ 3531450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3541450cdc6SMatthias Ringwald 3551450cdc6SMatthias Ringwald /** 3567627a0deSMatthias Ringwald * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection 3577627a0deSMatthias Ringwald * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events 35826166ecfSMatthias Ringwald * @param con_handle 35926166ecfSMatthias Ringwald * @param num_channels 3607627a0deSMatthias Ringwald * @param storage_buffer for L2CAP connection 3618540586aSMatthias Ringwald * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes 36226166ecfSMatthias Ringwald * @return 36326166ecfSMatthias Ringwald */ 36426166ecfSMatthias 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); 36526166ecfSMatthias Ringwald 36626166ecfSMatthias Ringwald /** 36779188ed7SMilanka Ringwald * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, 36879188ed7SMilanka Ringwald * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). 3696da84376SMilanka Ringwald * @param con_handle 3706da84376SMilanka Ringwald * @param mtu 37140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 37240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 373692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled 374692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 3753deb3ec6SMatthias Ringwald */ 376fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); 3773deb3ec6SMatthias Ringwald 3783deb3ec6SMatthias Ringwald /** 37979188ed7SMilanka Ringwald * @brief Sets whether a MTU Exchange Request shall be automatically send before the 38079188ed7SMilanka Ringwald * first attribute read request is send. Default is enabled. 3816da84376SMilanka Ringwald * @param enabled 3825cf6c434SJakob Krantz */ 3835cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); 3845cf6c434SJakob Krantz 3855cf6c434SJakob Krantz /** 38679188ed7SMilanka Ringwald * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU 38779188ed7SMilanka Ringwald * when gatt_client_mtu_enable_auto_negotiation is disabled. 3886da84376SMilanka Ringwald * @param callback 3896da84376SMilanka Ringwald * @param con_handle 3905cf6c434SJakob Krantz */ 3915cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3925cf6c434SJakob Krantz 3935cf6c434SJakob Krantz /** 394aacf1b1aSMilanka Ringwald * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. 3956da84376SMilanka Ringwald * @param con_handle 396692bf1adSMilanka Ringwald * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 3973deb3ec6SMatthias Ringwald */ 398fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle); 3993deb3ec6SMatthias Ringwald 4003deb3ec6SMatthias Ringwald /** 40179188ed7SMilanka Ringwald * @brief Discovers all primary services. 40279188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 40379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4046da84376SMilanka Ringwald * @param callback 4056da84376SMilanka Ringwald * @param con_handle 406692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 407692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 408692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4093deb3ec6SMatthias Ringwald */ 410711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4113deb3ec6SMatthias Ringwald 4123deb3ec6SMatthias Ringwald /** 41379188ed7SMilanka Ringwald * @brief Discovers all secondary services. 41479188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 41579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4168d1f34d3SMatheus Eduardo Garbelini * @param callback 4178d1f34d3SMatheus Eduardo Garbelini * @param con_handle 4188d1f34d3SMatheus Eduardo Garbelini * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 4198d1f34d3SMatheus Eduardo Garbelini * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 4208d1f34d3SMatheus Eduardo Garbelini * ERROR_CODE_SUCCESS , if query is successfully registered 4218d1f34d3SMatheus Eduardo Garbelini */ 4228d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4238d1f34d3SMatheus Eduardo Garbelini 4248d1f34d3SMatheus Eduardo Garbelini /** 42579188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 42679188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 42779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4286da84376SMilanka Ringwald * @param callback 4296da84376SMilanka Ringwald * @param con_handle 4306da84376SMilanka Ringwald * @param uuid16 431692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 432692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 433692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4343deb3ec6SMatthias Ringwald */ 435711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); 4366da84376SMilanka Ringwald 4376da84376SMilanka Ringwald /** 43879188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 43979188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 44079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4416da84376SMilanka Ringwald * @param callback 4426da84376SMilanka Ringwald * @param con_handle 4436da84376SMilanka Ringwald * @param uuid128 444692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 445692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 446692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4476da84376SMilanka Ringwald */ 4486da84376SMilanka 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); 4493deb3ec6SMatthias Ringwald 4503deb3ec6SMatthias Ringwald /** 45179188ed7SMilanka Ringwald * @brief Finds included services within the specified service. 45279188ed7SMilanka Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 45379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 45479188ed7SMilanka Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 45579188ed7SMilanka Ringwald * an ATT find information request for the returned start group handle 45679188ed7SMilanka Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 45779188ed7SMilanka Ringwald * to the list of all primary services. 4586da84376SMilanka Ringwald * @param callback 4596da84376SMilanka Ringwald * @param con_handle 4606da84376SMilanka Ringwald * @param service 461692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 462692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 463692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4643deb3ec6SMatthias Ringwald */ 465711e6c80SMatthias 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); 4663deb3ec6SMatthias Ringwald 4673deb3ec6SMatthias Ringwald /** 46879188ed7SMilanka Ringwald * @brief Discovers all characteristics within the specified service. 46979188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 47079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4716da84376SMilanka Ringwald * @param callback 4726da84376SMilanka Ringwald * @param con_handle 4736da84376SMilanka Ringwald * @param service 474692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 475692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 476692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4773deb3ec6SMatthias Ringwald */ 478711e6c80SMatthias 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); 4793deb3ec6SMatthias Ringwald 4803deb3ec6SMatthias Ringwald /** 48179188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within 48279188ed7SMilanka Ringwald * the specified service or handle range, and return those that match the given UUID. 48379188ed7SMilanka Ringwald * 48479188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 48579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4866da84376SMilanka Ringwald * @param callback 4876da84376SMilanka Ringwald * @param con_handle 4886da84376SMilanka Ringwald * @param start_handle 4896da84376SMilanka Ringwald * @param end_handle 4906da84376SMilanka Ringwald * @param uuid16 491692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 492692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 493692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4943deb3ec6SMatthias Ringwald */ 495711e6c80SMatthias 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); 4966da84376SMilanka Ringwald 4976da84376SMilanka Ringwald /** 49879188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 49979188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 50079188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 50179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5026da84376SMilanka Ringwald * @param callback 5036da84376SMilanka Ringwald * @param con_handle 5046da84376SMilanka Ringwald * @param start_handle 5056da84376SMilanka Ringwald * @param end_handle 5066da84376SMilanka Ringwald * @param uuid128 507692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 508692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 509692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5106da84376SMilanka Ringwald */ 511045d700dSDavid 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); 5126da84376SMilanka Ringwald 5136da84376SMilanka Ringwald /** 51479188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 51579188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 51679188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 51779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5186da84376SMilanka Ringwald * @param callback 5196da84376SMilanka Ringwald * @param con_handle 5206da84376SMilanka Ringwald * @param service 5216da84376SMilanka Ringwald * @param uuid16 522692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 523692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 524692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5256da84376SMilanka Ringwald */ 526711e6c80SMatthias 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); 5276da84376SMilanka Ringwald 5286da84376SMilanka Ringwald /** 52979188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 53079188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 53179188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 53279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5336da84376SMilanka Ringwald * @param callback 5346da84376SMilanka Ringwald * @param con_handle 5356da84376SMilanka Ringwald * @param service 5366da84376SMilanka Ringwald * @param uuid128 537692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 538692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 539692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5406da84376SMilanka Ringwald */ 541045d700dSDavid 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); 5423deb3ec6SMatthias Ringwald 5433deb3ec6SMatthias Ringwald /** 54479188ed7SMilanka Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 54579188ed7SMilanka Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 54679188ed7SMilanka Ringwald * 54779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5486da84376SMilanka Ringwald * @param callback 5496da84376SMilanka Ringwald * @param con_handle 5506da84376SMilanka Ringwald * @param characteristic 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 5543deb3ec6SMatthias Ringwald */ 555711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 5563deb3ec6SMatthias Ringwald 5573deb3ec6SMatthias Ringwald /** 55879188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 55979188ed7SMilanka Ringwald * If the characteristic value is 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 characteristic 564692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 565692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 566692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5673deb3ec6SMatthias Ringwald */ 568711e6c80SMatthias 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); 5696da84376SMilanka Ringwald 5706da84376SMilanka Ringwald /** 57179188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 57279188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 57379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5746da84376SMilanka Ringwald * @param callback 5756da84376SMilanka Ringwald * @param con_handle 576b45b7749SMilanka Ringwald * @param value_handle 577692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 578692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 579692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5806da84376SMilanka Ringwald */ 581b45b7749SMilanka 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); 5823deb3ec6SMatthias Ringwald 5833deb3ec6SMatthias Ringwald /** 58479188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 58579188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 58679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5876da84376SMilanka Ringwald * @param callback 5886da84376SMilanka Ringwald * @param con_handle 5896da84376SMilanka Ringwald * @param start_handle 5906da84376SMilanka Ringwald * @param end_handle 5916da84376SMilanka Ringwald * @param uuid16 592692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 593692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 594692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5953deb3ec6SMatthias Ringwald */ 596711e6c80SMatthias 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); 5976da84376SMilanka Ringwald 5986da84376SMilanka Ringwald /** 59979188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 60079188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 60179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6026da84376SMilanka Ringwald * @param callback 6036da84376SMilanka Ringwald * @param con_handle 6046da84376SMilanka Ringwald * @param start_handle 6056da84376SMilanka Ringwald * @param end_handle 6066da84376SMilanka Ringwald * @param uuid128 607692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 608692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 609692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6106da84376SMilanka Ringwald */ 611045d700dSDavid 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); 6123deb3ec6SMatthias Ringwald 6133deb3ec6SMatthias Ringwald /** 61479188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 61579188ed7SMilanka Ringwald * The value will be returned in several blobs. 61679188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 61779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6186da84376SMilanka Ringwald * @param callback 6196da84376SMilanka Ringwald * @param con_handle 6206da84376SMilanka Ringwald * @param characteristic 621692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 622692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 623692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6243deb3ec6SMatthias Ringwald */ 625711e6c80SMatthias 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); 6266da84376SMilanka Ringwald 6276da84376SMilanka Ringwald /** 62879188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 62979188ed7SMilanka Ringwald * The value will be returned in several blobs. 63079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 63179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6326da84376SMilanka Ringwald * @param callback 6336da84376SMilanka Ringwald * @param con_handle 634b45b7749SMilanka Ringwald * @param value_handle 635692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 636692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 637692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6386da84376SMilanka Ringwald */ 639b45b7749SMilanka 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); 6406da84376SMilanka Ringwald 6416da84376SMilanka Ringwald /** 64279188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 64379188ed7SMilanka Ringwald * The value will be returned in several blobs. 64479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 64579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6466da84376SMilanka Ringwald * @param callback 6476da84376SMilanka Ringwald * @param con_handle 648b45b7749SMilanka Ringwald * @param value_handle 6496da84376SMilanka Ringwald * @param offset 650692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 651692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 652692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6536da84376SMilanka Ringwald */ 654b45b7749SMilanka 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); 6553deb3ec6SMatthias Ringwald 6563deb3ec6SMatthias Ringwald /* 65779188ed7SMilanka Ringwald * @brief Read multiple characteristic values. 65879188ed7SMilanka Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 65979188ed7SMilanka Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 6606da84376SMilanka Ringwald * @param callback 6616da84376SMilanka Ringwald * @param con_handle 6626da84376SMilanka Ringwald * @param num_value_handles 6636da84376SMilanka Ringwald * @param value_handles list of handles 66479188ed7SMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 66579188ed7SMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 66679188ed7SMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6673deb3ec6SMatthias Ringwald */ 668711e6c80SMatthias 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); 6693deb3ec6SMatthias Ringwald 670f125a8efSMatthias Ringwald /* 671f125a8efSMatthias Ringwald * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer 672f125a8efSMatthias Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 673f125a8efSMatthias Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 674f125a8efSMatthias Ringwald * @param callback 675f125a8efSMatthias Ringwald * @param con_handle 676f125a8efSMatthias Ringwald * @param num_value_handles 677f125a8efSMatthias Ringwald * @param value_handles list of handles 678f125a8efSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 679f125a8efSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 680f125a8efSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 681f125a8efSMatthias Ringwald */ 682f125a8efSMatthias 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); 683f125a8efSMatthias Ringwald 6843deb3ec6SMatthias Ringwald /** 68579188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle without 68679188ed7SMilanka Ringwald * an acknowledgment that the write was successfully performed. 6876da84376SMilanka Ringwald * @param con_handle 688b45b7749SMilanka Ringwald * @param value_handle 689b45b7749SMilanka Ringwald * @param value_length 6907e6f0853SDavid Lechner * @param value is copied on success and does not need to be retained 691692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 692692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 693692bf1adSMilanka Ringwald * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots 694692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6953deb3ec6SMatthias Ringwald */ 696b45b7749SMilanka 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); 6973deb3ec6SMatthias Ringwald 6983deb3ec6SMatthias Ringwald /** 69979188ed7SMilanka Ringwald * @brief Writes the authenticated characteristic value using the characteristic's value handle 70079188ed7SMilanka Ringwald * without an acknowledgment that the write was successfully performed. 70179188ed7SMilanka Ringwald * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, 70279188ed7SMilanka Ringwald * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. 7036da84376SMilanka Ringwald * @param callback 7046da84376SMilanka Ringwald * @param con_handle 7056da84376SMilanka Ringwald * @param value_handle 7066da84376SMilanka Ringwald * @param message_len 7076da84376SMilanka Ringwald * @param message is not copied, make sure memory is accessible until write is done 70840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 70940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 710692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 711692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7123deb3ec6SMatthias Ringwald */ 7136da84376SMilanka 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); 7143deb3ec6SMatthias Ringwald 7153deb3ec6SMatthias Ringwald /** 716b2468039SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 717b2468039SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 718b2468039SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to 719b2468039SMilanka Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 7206da84376SMilanka Ringwald * @param callback 7216da84376SMilanka Ringwald * @param con_handle 722b45b7749SMilanka Ringwald * @param value_handle 723b45b7749SMilanka Ringwald * @param value_length 724b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 72540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 72640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 727692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 728692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7293deb3ec6SMatthias Ringwald */ 730b45b7749SMilanka 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); 7316da84376SMilanka Ringwald 7326da84376SMilanka Ringwald /** 73379188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 73479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 73579188ed7SMilanka 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). 7366da84376SMilanka Ringwald * @param callback 7376da84376SMilanka Ringwald * @param con_handle 738b45b7749SMilanka Ringwald * @param value_handle 739b45b7749SMilanka Ringwald * @param value_length 740b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 74140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 74240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 743692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 744692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7456da84376SMilanka Ringwald */ 746b45b7749SMilanka 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); 7476da84376SMilanka Ringwald 7486da84376SMilanka Ringwald /** 74979188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 75079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 75179188ed7SMilanka 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). 7526da84376SMilanka Ringwald * @param callback 7536da84376SMilanka Ringwald * @param con_handle 754b45b7749SMilanka Ringwald * @param value_handle 7556da84376SMilanka Ringwald * @param offset of value 756b45b7749SMilanka Ringwald * @param value_length 757b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 75840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 75940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 760692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 761692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7626da84376SMilanka Ringwald */ 763b45b7749SMilanka 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); 7643deb3ec6SMatthias Ringwald 7653deb3ec6SMatthias Ringwald /** 76679188ed7SMilanka Ringwald * @brief Writes of the long characteristic value using the characteristic's value handle. 76779188ed7SMilanka Ringwald * It uses server response to validate that the write was correctly received. 76879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. 76979188ed7SMilanka 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). 7706da84376SMilanka Ringwald * @param callback 7716da84376SMilanka Ringwald * @param con_handle 772b45b7749SMilanka Ringwald * @param value_handle 773b45b7749SMilanka Ringwald * @param value_length 774b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 77540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 77640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 777692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 778692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7793deb3ec6SMatthias Ringwald */ 780b45b7749SMilanka 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); 7813deb3ec6SMatthias Ringwald 7823deb3ec6SMatthias Ringwald /** 78379188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 78479188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 78579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7866da84376SMilanka Ringwald * @param callback 7876da84376SMilanka Ringwald * @param con_handle 7886da84376SMilanka Ringwald * @param descriptor 78940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 79040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 791692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 792692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7933deb3ec6SMatthias Ringwald */ 794711e6c80SMatthias 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); 7956da84376SMilanka Ringwald 7966da84376SMilanka Ringwald /** 79779188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 79879188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 79979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8006da84376SMilanka Ringwald * @param callback 8016da84376SMilanka Ringwald * @param con_handle 8026da84376SMilanka Ringwald * @param descriptor 80340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 80440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 805692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 806692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8076da84376SMilanka Ringwald */ 808711e6c80SMatthias 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); 8093deb3ec6SMatthias Ringwald 8103deb3ec6SMatthias Ringwald /** 81179188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 81279188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 81379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8146da84376SMilanka Ringwald * @param callback 8156da84376SMilanka Ringwald * @param con_handle 816b45b7749SMilanka Ringwald * @param descriptor 81740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 81840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 819692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 820692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8213deb3ec6SMatthias Ringwald */ 822711e6c80SMatthias 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); 8236da84376SMilanka Ringwald 8246da84376SMilanka Ringwald /** 82579188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 82679188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 82779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8286da84376SMilanka Ringwald * @param callback 8296da84376SMilanka Ringwald * @param con_handle 8306da84376SMilanka Ringwald * @param descriptor_handle 83140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 83240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 833692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 834692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8356da84376SMilanka Ringwald */ 836711e6c80SMatthias 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); 8376da84376SMilanka Ringwald 8386da84376SMilanka Ringwald /** 83979188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 84079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 84179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8426da84376SMilanka Ringwald * @param callback 8436da84376SMilanka Ringwald * @param con_handle 8446da84376SMilanka Ringwald * @param descriptor_handle 8456da84376SMilanka Ringwald * @param offset 84640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 84740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 848692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 849692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8506da84376SMilanka Ringwald */ 851711e6c80SMatthias 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); 8523deb3ec6SMatthias Ringwald 8533deb3ec6SMatthias Ringwald /** 85479188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 85579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 85679188ed7SMilanka 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). 8576da84376SMilanka Ringwald * @param callback 8586da84376SMilanka Ringwald * @param con_handle 8596da84376SMilanka Ringwald * @param descriptor 860b45b7749SMilanka Ringwald * @param value_length 861b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 86240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 86340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 864692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 865692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8663deb3ec6SMatthias Ringwald */ 867b45b7749SMilanka 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); 8686da84376SMilanka Ringwald 8696da84376SMilanka Ringwald /** 87079188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 87179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 87279188ed7SMilanka 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). 8736da84376SMilanka Ringwald * @param callback 8746da84376SMilanka Ringwald * @param con_handle 8756da84376SMilanka Ringwald * @param descriptor_handle 876b45b7749SMilanka Ringwald * @param value_length 877b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 87840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 87940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 880692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 881692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8826da84376SMilanka Ringwald */ 883b45b7749SMilanka 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); 8846da84376SMilanka Ringwald 8856da84376SMilanka Ringwald /** 88679188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 88779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 88879188ed7SMilanka 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). 8896da84376SMilanka Ringwald * @param callback 8906da84376SMilanka Ringwald * @param con_handle 8916da84376SMilanka Ringwald * @param descriptor 892b45b7749SMilanka Ringwald * @param value_length 893b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 89440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 89540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 896692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 897692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8986da84376SMilanka Ringwald */ 899b45b7749SMilanka 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); 9006da84376SMilanka Ringwald 9016da84376SMilanka Ringwald /** 90279188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 90379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 90479188ed7SMilanka 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). 9056da84376SMilanka Ringwald * @param callback 9066da84376SMilanka Ringwald * @param con_handle 9076da84376SMilanka Ringwald * @param descriptor_handle 908b45b7749SMilanka Ringwald * @param value_length 909b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 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 913692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9146da84376SMilanka Ringwald */ 915b45b7749SMilanka 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); 9166da84376SMilanka Ringwald 9176da84376SMilanka Ringwald /** 91879188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 91979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 92079188ed7SMilanka 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). 9216da84376SMilanka Ringwald * @param callback 9226da84376SMilanka Ringwald * @param con_handle 9236da84376SMilanka Ringwald * @param descriptor_handle 9246da84376SMilanka Ringwald * @param offset of value 925b45b7749SMilanka Ringwald * @param value_length 926b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 92740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 92840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 929692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 930692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9316da84376SMilanka Ringwald */ 932b45b7749SMilanka 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); 9333deb3ec6SMatthias Ringwald 9343deb3ec6SMatthias Ringwald /** 93579188ed7SMilanka Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 93679188ed7SMilanka Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 93779188ed7SMilanka Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 93879188ed7SMilanka Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 93979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 94079188ed7SMilanka 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). 9416da84376SMilanka Ringwald * @param callback 9426da84376SMilanka Ringwald * @param con_handle 9436da84376SMilanka Ringwald * @param characteristic 944b7e5512fSMilanka Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 94540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 94640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 947692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 948b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 949b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 9506b04f675SMilanka Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 951b7e5512fSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9523deb3ec6SMatthias Ringwald */ 953711e6c80SMatthias 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); 9549c662c9bSMatthias Ringwald 9559c662c9bSMatthias Ringwald /** 95658e8c9f5SMatthias Ringwald * @brief Register for changes to the Service Changed and Database Hash Characteristics of the remote GATT Service 957842492f0SMatthias Ringwald * * 95858e8c9f5SMatthias Ringwald * When configured, GATT_EVENT_QUERY_COMPLETE event is emitted 95958e8c9f5SMatthias Ringwald * If supported, the Database Hash is read as well 96058e8c9f5SMatthias Ringwald * 961842492f0SMatthias Ringwald * Requires ENABLE_GATT_CLIENT_SERVICE_CHANGED 962842492f0SMatthias Ringwald * 96358e8c9f5SMatthias Ringwald * @param callback 96458e8c9f5SMatthias Ringwald */ 96558e8c9f5SMatthias Ringwald void gatt_client_add_service_changed_handler(btstack_packet_callback_registration_t * callback); 96658e8c9f5SMatthias Ringwald 96758e8c9f5SMatthias Ringwald /** 96858e8c9f5SMatthias Ringwald * @brief Remove callback for service changes 969842492f0SMatthias Ringwald * 970842492f0SMatthias Ringwald * Requires ENABLE_GATT_CLIENT_SERVICE_CHANGED 971842492f0SMatthias Ringwald * 97258e8c9f5SMatthias Ringwald * @param callback 97358e8c9f5SMatthias Ringwald */ 97458e8c9f5SMatthias Ringwald void gatt_client_remove_service_changed_handler(btstack_packet_callback_registration_t * callback); 97558e8c9f5SMatthias Ringwald 97658e8c9f5SMatthias Ringwald /** 97779188ed7SMilanka Ringwald * @brief Register for notifications and indications of a characteristic enabled by 97879188ed7SMilanka Ringwald * the gatt_client_write_client_characteristic_configuration function. 9799c662c9bSMatthias Ringwald * @param notification struct used to store registration 9806da84376SMilanka Ringwald * @param callback 981b3f03c84SMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 982b3f03c84SMatthias Ringwald * @param characteristic or NULL to receive updates for all characteristics 9839c662c9bSMatthias Ringwald */ 9846da84376SMilanka 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); 9853deb3ec6SMatthias Ringwald 9863deb3ec6SMatthias Ringwald /** 98779188ed7SMilanka Ringwald * @brief Stop listening to characteristic value updates registered with 98879188ed7SMilanka Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 9891f734b5fSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 9901f734b5fSMatthias Ringwald */ 9911f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); 9921f734b5fSMatthias Ringwald 9931f734b5fSMatthias Ringwald /** 99479188ed7SMilanka Ringwald * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. 99579188ed7SMilanka Ringwald * Call the gatt_client_execute_write function to commit the transaction. 9966da84376SMilanka Ringwald * @param callback 9976da84376SMilanka Ringwald * @param con_handle 9986da84376SMilanka Ringwald * @param attribute_handle 9996da84376SMilanka Ringwald * @param offset of value 1000b45b7749SMilanka Ringwald * @param value_length 1001b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 10023deb3ec6SMatthias Ringwald */ 1003b45b7749SMilanka 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); 10043deb3ec6SMatthias Ringwald 10053deb3ec6SMatthias Ringwald /** 10066da84376SMilanka Ringwald * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. 10076da84376SMilanka Ringwald * @param callback 10086da84376SMilanka Ringwald * @param con_handle 100940faeb84SMilanka Ringwald * @return status 10103deb3ec6SMatthias Ringwald */ 1011711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 10123deb3ec6SMatthias Ringwald 10133deb3ec6SMatthias Ringwald /** 10146da84376SMilanka Ringwald * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. 10156da84376SMilanka Ringwald * @param callback 10166da84376SMilanka Ringwald * @param con_handle 101740faeb84SMilanka Ringwald * @return status 10183deb3ec6SMatthias Ringwald */ 1019711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 10203deb3ec6SMatthias Ringwald 102159d34cd2SMatthias Ringwald /** 102253e9c18fSMatthias Ringwald * @brief Request callback when regular gatt query can be sent 102353e9c18fSMatthias Ringwald * @note callback might happen during call to this function 102453e9c18fSMatthias Ringwald * @param callback_registration to point to callback function and context information 102553e9c18fSMatthias Ringwald * @param con_handle 102653e9c18fSMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 102753e9c18fSMatthias Ringwald */ 102853e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 102953e9c18fSMatthias Ringwald 103053e9c18fSMatthias Ringwald /** 103148553f67SDirk Helbig * @brief Remove queued callback for regular gatt queries, to be used on disconnect for example 103248553f67SDirk Helbig * @param callback_registration 103348553f67SDirk Helbig * @param con_handle 103448553f67SDirk Helbig * @return ERROR_CODE_SUCCESS if ok 103548553f67SDirk Helbig */ 103648553f67SDirk Helbig uint8_t gatt_client_remove_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 103748553f67SDirk Helbig 103848553f67SDirk Helbig /** 103959d34cd2SMatthias Ringwald * @brief Request callback when writing characteristic value without response is possible 104053e9c18fSMatthias Ringwald * @note callback might happen during call to this function 104159d34cd2SMatthias Ringwald * @param callback_registration to point to callback function and context information 104259d34cd2SMatthias Ringwald * @param con_handle 104359d34cd2SMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 104459d34cd2SMatthias Ringwald */ 104559d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 104659d34cd2SMatthias Ringwald 104759d34cd2SMatthias Ringwald 104859d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually 104959d34cd2SMatthias Ringwald /** 105059d34cd2SMatthias Ringwald * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees 105159d34cd2SMatthias Ringwald * a single successful gatt_client_write_value_of_characteristic_without_response call. 105259d34cd2SMatthias Ringwald * @deprecated please use gatt_client_request_to_write_without_response instead 105359d34cd2SMatthias Ringwald * @param callback 105459d34cd2SMatthias Ringwald * @param con_handle 105559d34cd2SMatthias Ringwald * @return status 105659d34cd2SMatthias Ringwald */ 105759d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 105859d34cd2SMatthias Ringwald 105959d34cd2SMatthias Ringwald 10603deb3ec6SMatthias Ringwald /* API_END */ 10613deb3ec6SMatthias Ringwald 10626ba2ad22SMatthias Ringwald // used by generated btstack_event.c 10636ba2ad22SMatthias Ringwald 1064313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); 1065313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); 1066313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); 10676ba2ad22SMatthias Ringwald 1068a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 1069a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); 107040faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client); 1071a6121b51SMilanka Ringwald #endif 1072a6121b51SMilanka Ringwald 10733deb3ec6SMatthias Ringwald #if defined __cplusplus 10743deb3ec6SMatthias Ringwald } 10753deb3ec6SMatthias Ringwald #endif 10763deb3ec6SMatthias Ringwald 10773deb3ec6SMatthias Ringwald #endif 1078