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; 210b2d70d58SMatthias 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 2729da02385SMatthias Ringwald // Context 2739da02385SMatthias Ringwald uint16_t service_id; 2749da02385SMatthias Ringwald uint16_t connection_id; 2759da02385SMatthias Ringwald 2762acb2842SMatthias Ringwald // GATT Service Changes 2772acb2842SMatthias Ringwald gatt_client_service_state_t gatt_service_state; 2782acb2842SMatthias Ringwald uint16_t gatt_service_start_group_handle; 2792acb2842SMatthias Ringwald uint16_t gatt_service_end_group_handle; 2802acb2842SMatthias Ringwald // - Service Changed 2812acb2842SMatthias Ringwald uint16_t gatt_service_changed_value_handle; 2822acb2842SMatthias Ringwald uint16_t gatt_service_changed_cccd_handle; 2832acb2842SMatthias Ringwald uint16_t gatt_service_changed_end_handle; 2842acb2842SMatthias Ringwald // - Database Hash 2852acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_value_handle; 2862acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_cccd_handle; 2872acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_end_handle; 2882acb2842SMatthias Ringwald 2893deb3ec6SMatthias Ringwald } gatt_client_t; 2903deb3ec6SMatthias Ringwald 2911a4874dcSMatthias Ringwald // Single characteristic, with wildcards for con_handle and attribute_handle 2921a4874dcSMatthias Ringwald typedef struct { 293665d90f2SMatthias Ringwald btstack_linked_item_t item; 294b6e96f14SMatthias Ringwald btstack_packet_handler_t callback; 295711e6c80SMatthias Ringwald hci_con_handle_t con_handle; 2969c662c9bSMatthias Ringwald uint16_t attribute_handle; 2979c662c9bSMatthias Ringwald } gatt_client_notification_t; 2983deb3ec6SMatthias Ringwald 2991a4874dcSMatthias Ringwald // Attribute range, aka service, no wildcards, used for implementing GATT Service clients 3001a4874dcSMatthias Ringwald typedef struct { 3011a4874dcSMatthias Ringwald btstack_linked_item_t item; 3021a4874dcSMatthias Ringwald btstack_packet_handler_t callback; 3031a4874dcSMatthias Ringwald hci_con_handle_t con_handle; 3041a4874dcSMatthias Ringwald uint16_t start_group_handle; 3051a4874dcSMatthias Ringwald uint16_t end_group_handle; 3061a4874dcSMatthias Ringwald // Context 3071a4874dcSMatthias Ringwald uint16_t service_id; 3081a4874dcSMatthias Ringwald uint16_t connection_id; 3091a4874dcSMatthias Ringwald } gatt_client_service_notification_t; 3101a4874dcSMatthias Ringwald 3113deb3ec6SMatthias Ringwald /* API_START */ 3123deb3ec6SMatthias Ringwald 313d25c33e5SMatthias Ringwald typedef struct { 3143deb3ec6SMatthias Ringwald uint16_t start_group_handle; 3153deb3ec6SMatthias Ringwald uint16_t end_group_handle; 3163deb3ec6SMatthias Ringwald uint16_t uuid16; 3173deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 318d25c33e5SMatthias Ringwald } gatt_client_service_t; 3193deb3ec6SMatthias Ringwald 320d25c33e5SMatthias Ringwald typedef struct { 3213deb3ec6SMatthias Ringwald uint16_t start_handle; 3223deb3ec6SMatthias Ringwald uint16_t value_handle; 3233deb3ec6SMatthias Ringwald uint16_t end_handle; 3243deb3ec6SMatthias Ringwald uint16_t properties; 3253deb3ec6SMatthias Ringwald uint16_t uuid16; 3263deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 327d25c33e5SMatthias Ringwald } gatt_client_characteristic_t; 3283deb3ec6SMatthias Ringwald 329d25c33e5SMatthias Ringwald typedef struct { 3303deb3ec6SMatthias Ringwald uint16_t handle; 3313deb3ec6SMatthias Ringwald uint16_t uuid16; 3323deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 333d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t; 3343deb3ec6SMatthias Ringwald 3353deb3ec6SMatthias Ringwald /** 3363deb3ec6SMatthias Ringwald * @brief Set up GATT client. 3373deb3ec6SMatthias Ringwald */ 3383deb3ec6SMatthias Ringwald void gatt_client_init(void); 3393deb3ec6SMatthias Ringwald 3403deb3ec6SMatthias Ringwald /** 34111279da7SMatthias Ringwald * @brief Set minimum required security level for GATT Client 34211279da7SMatthias Ringwald * @note The Bluetooth specification makes the GATT Server responsible to check for security. 343b11289a8SMatthias Ringwald * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. 344b11289a8SMatthias Ringwald * If your application is exchanging sensitive data with a remote device, you would need to manually check 345b11289a8SMatthias Ringwald * the security level before sending/receive such data. 346b11289a8SMatthias Ringwald * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange 347b11289a8SMatthias Ringwald * until the required security level is established. 348b11289a8SMatthias Ringwald * gatt_client_request_can_write_without_response_event does not trigger authentication 34959d34cd2SMatthias Ringwald * gatt_client_request_to_write_without_response does not trigger authentication 35011279da7SMatthias Ringwald * @pram level, default LEVEL_0 (no encryption required) 35111279da7SMatthias Ringwald */ 35211279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level); 35311279da7SMatthias Ringwald 35411279da7SMatthias Ringwald /** 3551450cdc6SMatthias Ringwald * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection 356effecf77SMatthias Ringwald * GATT_EVENT_CONNECTED with status and con_handle for other API functions 357effecf77SMatthias Ringwald * is emitted on connection complete. 358effecf77SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC. 3591450cdc6SMatthias Ringwald * @param addr 3601450cdc6SMatthias Ringwald * @return status 3611450cdc6SMatthias Ringwald */ 3621450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); 3631450cdc6SMatthias Ringwald 3641450cdc6SMatthias Ringwald /** 3651450cdc6SMatthias Ringwald * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server 3661450cdc6SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC 367effecf77SMatthias Ringwald * @param con_handle 3681450cdc6SMatthias Ringwald * @return status 3691450cdc6SMatthias Ringwald */ 3701450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3711450cdc6SMatthias Ringwald 3721450cdc6SMatthias Ringwald /** 3737627a0deSMatthias Ringwald * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection 3747627a0deSMatthias Ringwald * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events 37526166ecfSMatthias Ringwald * @param con_handle 37626166ecfSMatthias Ringwald * @param num_channels 3777627a0deSMatthias Ringwald * @param storage_buffer for L2CAP connection 3788540586aSMatthias Ringwald * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes 37926166ecfSMatthias Ringwald * @return 38026166ecfSMatthias Ringwald */ 38126166ecfSMatthias 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); 38226166ecfSMatthias Ringwald 38326166ecfSMatthias Ringwald /** 38479188ed7SMilanka Ringwald * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, 38579188ed7SMilanka Ringwald * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). 3866da84376SMilanka Ringwald * @param con_handle 3876201dbadSMatthias Ringwald * @param mtu or 0 in case of error 38840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 38940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 390692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled 3916201dbadSMatthias Ringwald * ERROR_CODE_SUCCESS on success 3923deb3ec6SMatthias Ringwald */ 393fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); 3943deb3ec6SMatthias Ringwald 3953deb3ec6SMatthias Ringwald /** 39679188ed7SMilanka Ringwald * @brief Sets whether a MTU Exchange Request shall be automatically send before the 39779188ed7SMilanka Ringwald * first attribute read request is send. Default is enabled. 3986da84376SMilanka Ringwald * @param enabled 3995cf6c434SJakob Krantz */ 4005cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); 4015cf6c434SJakob Krantz 4025cf6c434SJakob Krantz /** 40379188ed7SMilanka Ringwald * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU 40479188ed7SMilanka Ringwald * when gatt_client_mtu_enable_auto_negotiation is disabled. 4056da84376SMilanka Ringwald * @param callback 4066da84376SMilanka Ringwald * @param con_handle 4075cf6c434SJakob Krantz */ 4085cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4095cf6c434SJakob Krantz 4105cf6c434SJakob Krantz /** 411aacf1b1aSMilanka Ringwald * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. 4126da84376SMilanka Ringwald * @param con_handle 413692bf1adSMilanka Ringwald * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 4143deb3ec6SMatthias Ringwald */ 415fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle); 4163deb3ec6SMatthias Ringwald 4173deb3ec6SMatthias Ringwald /** 41879188ed7SMilanka Ringwald * @brief Discovers all primary services. 41979188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 42079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4216da84376SMilanka Ringwald * @param callback 4226da84376SMilanka Ringwald * @param con_handle 423692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 424692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 425692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4263deb3ec6SMatthias Ringwald */ 427711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4283deb3ec6SMatthias Ringwald 4293deb3ec6SMatthias Ringwald /** 43079188ed7SMilanka Ringwald * @brief Discovers all secondary services. 43179188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 43279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4338d1f34d3SMatheus Eduardo Garbelini * @param callback 4348d1f34d3SMatheus Eduardo Garbelini * @param con_handle 4358d1f34d3SMatheus Eduardo Garbelini * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 4368d1f34d3SMatheus Eduardo Garbelini * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 4378d1f34d3SMatheus Eduardo Garbelini * ERROR_CODE_SUCCESS , if query is successfully registered 4388d1f34d3SMatheus Eduardo Garbelini */ 4398d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4408d1f34d3SMatheus Eduardo Garbelini 4418d1f34d3SMatheus Eduardo Garbelini /** 44279188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 44379188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 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 uuid16 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_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); 4536da84376SMilanka Ringwald 4546da84376SMilanka Ringwald /** 45568ced5c9SMatthias Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 45668ced5c9SMatthias Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 45768ced5c9SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 45868ced5c9SMatthias Ringwald * @param callback 45968ced5c9SMatthias Ringwald * @param con_handle 46068ced5c9SMatthias Ringwald * @param uuid16 46168ced5c9SMatthias Ringwald * @param service_id - context provided to callback in events 46268ced5c9SMatthias Ringwald * @param connection_id - contest provided to callback in events 46368ced5c9SMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 46468ced5c9SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 46568ced5c9SMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 46668ced5c9SMatthias Ringwald */ 46768ced5c9SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 46868ced5c9SMatthias Ringwald uint16_t uuid16, uint16_t service_id, uint16_t connection_id); 46968ced5c9SMatthias Ringwald 47068ced5c9SMatthias Ringwald /** 47179188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 47279188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 47379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4746da84376SMilanka Ringwald * @param callback 4756da84376SMilanka Ringwald * @param con_handle 4766da84376SMilanka Ringwald * @param uuid128 477692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 478692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 479692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4806da84376SMilanka Ringwald */ 4816da84376SMilanka 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); 4823deb3ec6SMatthias Ringwald 4833deb3ec6SMatthias Ringwald /** 48479188ed7SMilanka Ringwald * @brief Finds included services within the specified service. 48579188ed7SMilanka Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 48679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 48779188ed7SMilanka Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 48879188ed7SMilanka Ringwald * an ATT find information request for the returned start group handle 48979188ed7SMilanka Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 49079188ed7SMilanka Ringwald * to the list of all primary services. 4916da84376SMilanka Ringwald * @param callback 4926da84376SMilanka Ringwald * @param con_handle 4936da84376SMilanka Ringwald * @param service 494692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 495692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 496692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4973deb3ec6SMatthias Ringwald */ 498711e6c80SMatthias 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); 4993deb3ec6SMatthias Ringwald 5003deb3ec6SMatthias Ringwald /** 501aa43543aSMatthias Ringwald * @brief Finds included services within the specified service. 502aa43543aSMatthias Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 503aa43543aSMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 504aa43543aSMatthias Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 505aa43543aSMatthias Ringwald * an ATT find information request for the returned start group handle 506aa43543aSMatthias Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 507aa43543aSMatthias Ringwald * to the list of all primary services. 508aa43543aSMatthias Ringwald * @param callback 509aa43543aSMatthias Ringwald * @param con_handle 510aa43543aSMatthias Ringwald * @param service_id - context provided to callback in events 511aa43543aSMatthias Ringwald * @param connection_id - contest provided to callback in events 512aa43543aSMatthias Ringwald * @param service_id 513aa43543aSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 514aa43543aSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 515aa43543aSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 516aa43543aSMatthias Ringwald */ 517aa43543aSMatthias Ringwald uint8_t gatt_client_find_included_services_for_service_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 518aa43543aSMatthias Ringwald gatt_client_service_t * service, uint16_t service_id, uint16_t connection_id); 519aa43543aSMatthias Ringwald 520aa43543aSMatthias Ringwald /** 52179188ed7SMilanka Ringwald * @brief Discovers all characteristics within the specified service. 52279188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 52379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5246da84376SMilanka Ringwald * @param callback 5256da84376SMilanka Ringwald * @param con_handle 5266da84376SMilanka Ringwald * @param service 527692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 528692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 529692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5303deb3ec6SMatthias Ringwald */ 531711e6c80SMatthias 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); 5323deb3ec6SMatthias Ringwald 5333deb3ec6SMatthias Ringwald /** 5348183ac30SMatthias Ringwald * @brief Discovers all characteristics within the specified service. 5358183ac30SMatthias Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 5368183ac30SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5378183ac30SMatthias Ringwald * @param callback 5388183ac30SMatthias Ringwald * @param con_handle 5398183ac30SMatthias Ringwald * @param service 5408183ac30SMatthias Ringwald * @param service_id - context provided to callback in events 5418183ac30SMatthias Ringwald * @param connection_id - contest provided to callback in events 5428183ac30SMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 5438183ac30SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 5448183ac30SMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5458183ac30SMatthias Ringwald */ 5468183ac30SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_service_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service, 5478183ac30SMatthias Ringwald uint16_t service_id, uint16_t connection_id); 5488183ac30SMatthias Ringwald 5498183ac30SMatthias Ringwald /** 55079188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within 55179188ed7SMilanka Ringwald * the specified service or handle range, and return those that match the given UUID. 55279188ed7SMilanka Ringwald * 55379188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 55479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5556da84376SMilanka Ringwald * @param callback 5566da84376SMilanka Ringwald * @param con_handle 5576da84376SMilanka Ringwald * @param start_handle 5586da84376SMilanka Ringwald * @param end_handle 5596da84376SMilanka Ringwald * @param uuid16 560692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 561692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 562692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5633deb3ec6SMatthias Ringwald */ 564711e6c80SMatthias 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); 5656da84376SMilanka Ringwald 5666da84376SMilanka Ringwald /** 56779188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 56879188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 56979188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 57079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5716da84376SMilanka Ringwald * @param callback 5726da84376SMilanka Ringwald * @param con_handle 5736da84376SMilanka Ringwald * @param start_handle 5746da84376SMilanka Ringwald * @param end_handle 5756da84376SMilanka Ringwald * @param uuid128 576692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 577692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 578692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5796da84376SMilanka Ringwald */ 580045d700dSDavid 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); 5816da84376SMilanka Ringwald 5826da84376SMilanka Ringwald /** 58379188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 58479188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 58579188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 58679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5876da84376SMilanka Ringwald * @param callback 5886da84376SMilanka Ringwald * @param con_handle 5896da84376SMilanka Ringwald * @param service 5906da84376SMilanka Ringwald * @param uuid16 591692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 592692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 593692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5946da84376SMilanka Ringwald */ 595711e6c80SMatthias 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); 5966da84376SMilanka Ringwald 5976da84376SMilanka Ringwald /** 59879188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 59979188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 60079188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 60179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 6026da84376SMilanka Ringwald * @param callback 6036da84376SMilanka Ringwald * @param con_handle 6046da84376SMilanka Ringwald * @param service 6056da84376SMilanka Ringwald * @param uuid128 606692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 607692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 608692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6096da84376SMilanka Ringwald */ 610045d700dSDavid 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); 6113deb3ec6SMatthias Ringwald 6123deb3ec6SMatthias Ringwald /** 61379188ed7SMilanka Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 61479188ed7SMilanka Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 61579188ed7SMilanka Ringwald * 61679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 6176da84376SMilanka Ringwald * @param callback 6186da84376SMilanka Ringwald * @param con_handle 6196da84376SMilanka Ringwald * @param characteristic 620692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 621692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 622692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6233deb3ec6SMatthias Ringwald */ 624711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 625a94d23eaSMatthias Ringwald 626a94d23eaSMatthias Ringwald 627a94d23eaSMatthias Ringwald /** 628a94d23eaSMatthias Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 629a94d23eaSMatthias Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 630a94d23eaSMatthias Ringwald * 631a94d23eaSMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 632a94d23eaSMatthias Ringwald * @param callback 633a94d23eaSMatthias Ringwald * @param con_handle 634a94d23eaSMatthias Ringwald * @param characteristic 635a94d23eaSMatthias Ringwald * @param service_id - context provided to callback in events 636a94d23eaSMatthias Ringwald * @param connection_id - contest provided to callback in events 637a94d23eaSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 638a94d23eaSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 639a94d23eaSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 640a94d23eaSMatthias Ringwald */ 641a94d23eaSMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 642a94d23eaSMatthias Ringwald gatt_client_characteristic_t * characteristic, uint16_t service_id, uint16_t connection_it); 6433deb3ec6SMatthias Ringwald 6443deb3ec6SMatthias Ringwald /** 64579188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 64679188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 64779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6486da84376SMilanka Ringwald * @param callback 6496da84376SMilanka Ringwald * @param con_handle 6506da84376SMilanka Ringwald * @param characteristic 651692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 652692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 653692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6543deb3ec6SMatthias Ringwald */ 655711e6c80SMatthias 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); 6566da84376SMilanka Ringwald 6576da84376SMilanka Ringwald /** 65879188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 65979188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 66079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6616da84376SMilanka Ringwald * @param callback 6626da84376SMilanka Ringwald * @param con_handle 663b45b7749SMilanka Ringwald * @param value_handle 664692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 665692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 666692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6676da84376SMilanka Ringwald */ 668b45b7749SMilanka 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); 6693deb3ec6SMatthias Ringwald 6703deb3ec6SMatthias Ringwald /** 671e38d764eSMatthias Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 672e38d764eSMatthias Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 673e38d764eSMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 674e38d764eSMatthias Ringwald * @param callback 675e38d764eSMatthias Ringwald * @param con_handle 676e38d764eSMatthias Ringwald * @param value_handle 677e38d764eSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 678e38d764eSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 679e38d764eSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 680e38d764eSMatthias Ringwald */ 681e38d764eSMatthias Ringwald uint8_t gatt_client_read_value_of_characteristic_using_value_handle_with_context(btstack_packet_handler_t callback, 682e38d764eSMatthias Ringwald hci_con_handle_t con_handle, 683e38d764eSMatthias Ringwald uint16_t value_handle, 684e38d764eSMatthias Ringwald uint16_t service_id, 685e38d764eSMatthias Ringwald uint16_t connection_id); 686e38d764eSMatthias Ringwald 687e38d764eSMatthias Ringwald /** 68879188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 68979188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 69079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6916da84376SMilanka Ringwald * @param callback 6926da84376SMilanka Ringwald * @param con_handle 6936da84376SMilanka Ringwald * @param start_handle 6946da84376SMilanka Ringwald * @param end_handle 6956da84376SMilanka Ringwald * @param uuid16 696692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 697692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 698692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6993deb3ec6SMatthias Ringwald */ 700711e6c80SMatthias 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); 7016da84376SMilanka Ringwald 7026da84376SMilanka Ringwald /** 70379188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 70479188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 70579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7066da84376SMilanka Ringwald * @param callback 7076da84376SMilanka Ringwald * @param con_handle 7086da84376SMilanka Ringwald * @param start_handle 7096da84376SMilanka Ringwald * @param end_handle 7106da84376SMilanka Ringwald * @param uuid128 711692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 712692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 713692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7146da84376SMilanka Ringwald */ 715045d700dSDavid 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); 7163deb3ec6SMatthias Ringwald 7173deb3ec6SMatthias Ringwald /** 71879188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 71979188ed7SMilanka Ringwald * The value will be returned in several blobs. 72079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 72179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7226da84376SMilanka Ringwald * @param callback 7236da84376SMilanka Ringwald * @param con_handle 7246da84376SMilanka Ringwald * @param characteristic 725692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 726692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 727692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7283deb3ec6SMatthias Ringwald */ 729711e6c80SMatthias 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); 7306da84376SMilanka Ringwald 7316da84376SMilanka Ringwald /** 73279188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 73379188ed7SMilanka Ringwald * The value will be returned in several blobs. 73479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 73579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7366da84376SMilanka Ringwald * @param callback 7376da84376SMilanka Ringwald * @param con_handle 738b45b7749SMilanka Ringwald * @param value_handle 739692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 740692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 741692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7426da84376SMilanka Ringwald */ 743b45b7749SMilanka 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); 7446da84376SMilanka Ringwald 7456da84376SMilanka Ringwald /** 746691e02c2SMatthias Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 747691e02c2SMatthias Ringwald * The value will be returned in several blobs. 748691e02c2SMatthias Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 749691e02c2SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 750691e02c2SMatthias Ringwald * @param callback 751691e02c2SMatthias Ringwald * @param con_handle 752691e02c2SMatthias Ringwald * @param value_handle 753691e02c2SMatthias Ringwald * @param service_id - context provided to callback in events 754691e02c2SMatthias Ringwald * @param connection_id - contest provided to callback in events 755691e02c2SMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 756691e02c2SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 757691e02c2SMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 758691e02c2SMatthias Ringwald */ 759691e02c2SMatthias Ringwald uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_context(btstack_packet_handler_t callback, 760691e02c2SMatthias Ringwald hci_con_handle_t con_handle, uint16_t value_handle, 761691e02c2SMatthias Ringwald uint16_t service_id, uint16_t connection_id); 762691e02c2SMatthias Ringwald 763691e02c2SMatthias Ringwald /** 76479188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 76579188ed7SMilanka Ringwald * The value will be returned in several blobs. 76679188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 76779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7686da84376SMilanka Ringwald * @param callback 7696da84376SMilanka Ringwald * @param con_handle 770b45b7749SMilanka Ringwald * @param value_handle 7716da84376SMilanka Ringwald * @param offset 772692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 773692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 774692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7756da84376SMilanka Ringwald */ 776b45b7749SMilanka 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); 7773deb3ec6SMatthias Ringwald 7783deb3ec6SMatthias Ringwald /* 77979188ed7SMilanka Ringwald * @brief Read multiple characteristic values. 78079188ed7SMilanka Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 78179188ed7SMilanka Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 7826da84376SMilanka Ringwald * @param callback 7836da84376SMilanka Ringwald * @param con_handle 7846da84376SMilanka Ringwald * @param num_value_handles 7856da84376SMilanka Ringwald * @param value_handles list of handles 78679188ed7SMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 78779188ed7SMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 78879188ed7SMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7893deb3ec6SMatthias Ringwald */ 790711e6c80SMatthias 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); 7913deb3ec6SMatthias Ringwald 792f125a8efSMatthias Ringwald /* 793f125a8efSMatthias Ringwald * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer 794f125a8efSMatthias Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 795f125a8efSMatthias Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 796f125a8efSMatthias Ringwald * @param callback 797f125a8efSMatthias Ringwald * @param con_handle 798f125a8efSMatthias Ringwald * @param num_value_handles 799f125a8efSMatthias Ringwald * @param value_handles list of handles 800f125a8efSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 801f125a8efSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 802f125a8efSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 803f125a8efSMatthias Ringwald */ 804f125a8efSMatthias 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); 805f125a8efSMatthias Ringwald 8063deb3ec6SMatthias Ringwald /** 80779188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle without 80879188ed7SMilanka Ringwald * an acknowledgment that the write was successfully performed. 8096da84376SMilanka Ringwald * @param con_handle 810b45b7749SMilanka Ringwald * @param value_handle 811b45b7749SMilanka Ringwald * @param value_length 8127e6f0853SDavid Lechner * @param value is copied on success and does not need to be retained 813692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 814692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 815692bf1adSMilanka Ringwald * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots 816692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 8173deb3ec6SMatthias Ringwald */ 818b45b7749SMilanka 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); 8193deb3ec6SMatthias Ringwald 8203deb3ec6SMatthias Ringwald /** 82179188ed7SMilanka Ringwald * @brief Writes the authenticated characteristic value using the characteristic's value handle 82279188ed7SMilanka Ringwald * without an acknowledgment that the write was successfully performed. 82379188ed7SMilanka Ringwald * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, 82479188ed7SMilanka Ringwald * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. 8256da84376SMilanka Ringwald * @param callback 8266da84376SMilanka Ringwald * @param con_handle 8276da84376SMilanka Ringwald * @param value_handle 8286da84376SMilanka Ringwald * @param message_len 8296da84376SMilanka Ringwald * @param message is not copied, make sure memory is accessible until write is done 83040faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 83140faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 832692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 833692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8343deb3ec6SMatthias Ringwald */ 835b444aa75SMatthias Ringwald uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, 836b444aa75SMatthias Ringwald uint16_t message_len, uint8_t * message); 8373deb3ec6SMatthias Ringwald 8383deb3ec6SMatthias Ringwald /** 839b2468039SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 840b2468039SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 841b2468039SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to 842b2468039SMilanka Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 8436da84376SMilanka Ringwald * @param callback 8446da84376SMilanka Ringwald * @param con_handle 845b45b7749SMilanka Ringwald * @param value_handle 846b45b7749SMilanka Ringwald * @param value_length 847b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 84840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 84940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 850692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 851692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8523deb3ec6SMatthias Ringwald */ 853b45b7749SMilanka 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); 8546da84376SMilanka Ringwald 8556da84376SMilanka Ringwald /** 85679188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 85779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 858b444aa75SMatthias Ringwald * The write is successfully performed, if the event's att_status field is set to 859b444aa75SMatthias Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 860b444aa75SMatthias Ringwald * @param callback 861b444aa75SMatthias Ringwald * @param con_handle 862b444aa75SMatthias Ringwald * @param value_handle 863b444aa75SMatthias Ringwald * @param value_length 864b444aa75SMatthias Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 865e38d764eSMatthias Ringwald * @param service_id - context provided to callback in events 866e38d764eSMatthias Ringwald * @param connection_id - contest provided to callback in events 867b444aa75SMatthias Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 868b444aa75SMatthias Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 869b444aa75SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 870b444aa75SMatthias Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 871b444aa75SMatthias Ringwald */ 872b444aa75SMatthias Ringwald uint8_t gatt_client_write_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, 873b444aa75SMatthias Ringwald uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id); 874b444aa75SMatthias Ringwald 875b444aa75SMatthias Ringwald /** 876b444aa75SMatthias Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 877b444aa75SMatthias 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 881b45b7749SMilanka Ringwald * @param value_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_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); 8906da84376SMilanka Ringwald 8916da84376SMilanka Ringwald /** 892b538fb89SMatthias Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 893b538fb89SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 894b538fb89SMatthias 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). 895b538fb89SMatthias Ringwald * @param callback 896b538fb89SMatthias Ringwald * @param con_handle 897b538fb89SMatthias Ringwald * @param value_handle 898b538fb89SMatthias Ringwald * @param value_length 899b538fb89SMatthias Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 900b538fb89SMatthias Ringwald * @param service_id - context provided to callback in events 901b538fb89SMatthias Ringwald * @param connection_id - contest provided to callback in events 902b538fb89SMatthias Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 903b538fb89SMatthias Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 904b538fb89SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 905b538fb89SMatthias Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 906b538fb89SMatthias Ringwald */ 907b538fb89SMatthias Ringwald uint8_t gatt_client_write_long_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, 908b538fb89SMatthias Ringwald uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id); 909b538fb89SMatthias Ringwald 910b538fb89SMatthias Ringwald /** 91179188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 91279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 91379188ed7SMilanka 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). 9146da84376SMilanka Ringwald * @param callback 9156da84376SMilanka Ringwald * @param con_handle 916b45b7749SMilanka Ringwald * @param value_handle 9176da84376SMilanka Ringwald * @param offset of value 918b45b7749SMilanka Ringwald * @param value_length 919b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 92040faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 92140faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 922692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 923692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9246da84376SMilanka Ringwald */ 925b45b7749SMilanka 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); 9263deb3ec6SMatthias Ringwald 9273deb3ec6SMatthias Ringwald /** 92879188ed7SMilanka Ringwald * @brief Writes of the long characteristic value using the characteristic's value handle. 92979188ed7SMilanka Ringwald * It uses server response to validate that the write was correctly received. 93079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. 93179188ed7SMilanka 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). 9326da84376SMilanka Ringwald * @param callback 9336da84376SMilanka Ringwald * @param con_handle 934b45b7749SMilanka Ringwald * @param value_handle 935b45b7749SMilanka Ringwald * @param value_length 936b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 93740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 93840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 939692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 940692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9413deb3ec6SMatthias Ringwald */ 942b45b7749SMilanka 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); 9433deb3ec6SMatthias Ringwald 9443deb3ec6SMatthias Ringwald /** 94579188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 94679188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 94779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9486da84376SMilanka Ringwald * @param callback 9496da84376SMilanka Ringwald * @param con_handle 9506da84376SMilanka Ringwald * @param descriptor 95140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 95240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 953692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 954692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9553deb3ec6SMatthias Ringwald */ 956711e6c80SMatthias 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); 9576da84376SMilanka Ringwald 9586da84376SMilanka Ringwald /** 95979188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 96079188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 96179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9626da84376SMilanka Ringwald * @param callback 9636da84376SMilanka Ringwald * @param con_handle 9646da84376SMilanka Ringwald * @param descriptor 96540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 96640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 967692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 968692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9696da84376SMilanka Ringwald */ 970711e6c80SMatthias 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); 9713deb3ec6SMatthias Ringwald 9723deb3ec6SMatthias Ringwald /** 97379188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 97479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 97579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9766da84376SMilanka Ringwald * @param callback 9776da84376SMilanka Ringwald * @param con_handle 978b45b7749SMilanka Ringwald * @param descriptor 97940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 98040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 981692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 982692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9833deb3ec6SMatthias Ringwald */ 984711e6c80SMatthias 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); 9856da84376SMilanka Ringwald 9866da84376SMilanka Ringwald /** 98779188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 98879188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 98979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9906da84376SMilanka Ringwald * @param callback 9916da84376SMilanka Ringwald * @param con_handle 9926da84376SMilanka Ringwald * @param descriptor_handle 99340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 99440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 995692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 996692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9976da84376SMilanka Ringwald */ 998711e6c80SMatthias 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); 9996da84376SMilanka Ringwald 10006da84376SMilanka Ringwald /** 100179188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 100279188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 100379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 10046da84376SMilanka Ringwald * @param callback 10056da84376SMilanka Ringwald * @param con_handle 10066da84376SMilanka Ringwald * @param descriptor_handle 10076da84376SMilanka Ringwald * @param offset 100840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 100940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1010692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1011692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10126da84376SMilanka Ringwald */ 1013711e6c80SMatthias 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); 10143deb3ec6SMatthias Ringwald 10153deb3ec6SMatthias Ringwald /** 101679188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 101779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 101879188ed7SMilanka 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). 10196da84376SMilanka Ringwald * @param callback 10206da84376SMilanka Ringwald * @param con_handle 10216da84376SMilanka Ringwald * @param descriptor 1022b45b7749SMilanka Ringwald * @param value_length 1023b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 102440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 102540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1026692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1027692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10283deb3ec6SMatthias Ringwald */ 1029b45b7749SMilanka 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); 10306da84376SMilanka Ringwald 10316da84376SMilanka Ringwald /** 103279188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 103379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 103479188ed7SMilanka 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). 10356da84376SMilanka Ringwald * @param callback 10366da84376SMilanka Ringwald * @param con_handle 10376da84376SMilanka Ringwald * @param descriptor_handle 1038b45b7749SMilanka Ringwald * @param value_length 1039b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 104040faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 104140faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1042692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1043692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10446da84376SMilanka Ringwald */ 1045b45b7749SMilanka 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); 10466da84376SMilanka Ringwald 10476da84376SMilanka Ringwald /** 104879188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 104979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 105079188ed7SMilanka 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). 10516da84376SMilanka Ringwald * @param callback 10526da84376SMilanka Ringwald * @param con_handle 10536da84376SMilanka Ringwald * @param descriptor 1054b45b7749SMilanka Ringwald * @param value_length 1055b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 105640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 105740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1058692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1059692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10606da84376SMilanka Ringwald */ 1061b45b7749SMilanka 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); 10626da84376SMilanka Ringwald 10636da84376SMilanka Ringwald /** 106479188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 106579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 106679188ed7SMilanka 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). 10676da84376SMilanka Ringwald * @param callback 10686da84376SMilanka Ringwald * @param con_handle 10696da84376SMilanka Ringwald * @param descriptor_handle 1070b45b7749SMilanka Ringwald * @param value_length 1071b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 107240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 107340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1074692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1075692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10766da84376SMilanka Ringwald */ 1077b45b7749SMilanka 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); 10786da84376SMilanka Ringwald 10796da84376SMilanka Ringwald /** 108079188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 108179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 108279188ed7SMilanka 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). 10836da84376SMilanka Ringwald * @param callback 10846da84376SMilanka Ringwald * @param con_handle 10856da84376SMilanka Ringwald * @param descriptor_handle 10866da84376SMilanka Ringwald * @param offset of value 1087b45b7749SMilanka Ringwald * @param value_length 1088b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 108940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 109040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1091692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1092692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10936da84376SMilanka Ringwald */ 1094b45b7749SMilanka 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); 10953deb3ec6SMatthias Ringwald 10963deb3ec6SMatthias Ringwald /** 109779188ed7SMilanka Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 109879188ed7SMilanka Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 109979188ed7SMilanka Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 110079188ed7SMilanka Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 110179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 110279188ed7SMilanka 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). 11036da84376SMilanka Ringwald * @param callback 11046da84376SMilanka Ringwald * @param con_handle 11056da84376SMilanka Ringwald * @param characteristic 1106b7e5512fSMilanka Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 110740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 110840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1109692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1110b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 1111b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 11126b04f675SMilanka Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 1113b7e5512fSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 11143deb3ec6SMatthias Ringwald */ 1115711e6c80SMatthias 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); 11169c662c9bSMatthias Ringwald 11179c662c9bSMatthias Ringwald /** 1118cb5b2b64SMatthias Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 1119cb5b2b64SMatthias Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 1120cb5b2b64SMatthias Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 1121cb5b2b64SMatthias Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 1122cb5b2b64SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 1123cb5b2b64SMatthias 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). 1124cb5b2b64SMatthias Ringwald * @param callback 1125cb5b2b64SMatthias Ringwald * @param con_handle 1126cb5b2b64SMatthias Ringwald * @param characteristic 1127cb5b2b64SMatthias Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 1128cb5b2b64SMatthias Ringwald * @param service_id - context provided to callback in events 1129cb5b2b64SMatthias Ringwald * @param connection_id - contest provided to callback in events 1130cb5b2b64SMatthias Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 1131cb5b2b64SMatthias Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1132cb5b2b64SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1133cb5b2b64SMatthias Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 1134cb5b2b64SMatthias Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 1135cb5b2b64SMatthias Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 1136cb5b2b64SMatthias Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 1137cb5b2b64SMatthias Ringwald */ 1138cb5b2b64SMatthias Ringwald uint8_t gatt_client_write_client_characteristic_configuration_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 1139cb5b2b64SMatthias Ringwald gatt_client_characteristic_t * characteristic, uint16_t configuration, uint16_t service_id, uint16_t connection_id); 1140cb5b2b64SMatthias Ringwald 1141cb5b2b64SMatthias Ringwald /** 114258e8c9f5SMatthias Ringwald * @brief Register for changes to the Service Changed and Database Hash Characteristics of the remote GATT Service 1143842492f0SMatthias Ringwald * * 114458e8c9f5SMatthias Ringwald * When configured, GATT_EVENT_QUERY_COMPLETE event is emitted 114558e8c9f5SMatthias Ringwald * If supported, the Database Hash is read as well 114658e8c9f5SMatthias Ringwald * 1147842492f0SMatthias Ringwald * Requires ENABLE_GATT_CLIENT_SERVICE_CHANGED 1148842492f0SMatthias Ringwald * 114958e8c9f5SMatthias Ringwald * @param callback 115058e8c9f5SMatthias Ringwald */ 115158e8c9f5SMatthias Ringwald void gatt_client_add_service_changed_handler(btstack_packet_callback_registration_t * callback); 115258e8c9f5SMatthias Ringwald 115358e8c9f5SMatthias Ringwald /** 115458e8c9f5SMatthias Ringwald * @brief Remove callback for service changes 1155842492f0SMatthias Ringwald * 1156842492f0SMatthias Ringwald * Requires ENABLE_GATT_CLIENT_SERVICE_CHANGED 1157842492f0SMatthias Ringwald * 115858e8c9f5SMatthias Ringwald * @param callback 115958e8c9f5SMatthias Ringwald */ 116058e8c9f5SMatthias Ringwald void gatt_client_remove_service_changed_handler(btstack_packet_callback_registration_t * callback); 116158e8c9f5SMatthias Ringwald 116258e8c9f5SMatthias Ringwald /** 116379188ed7SMilanka Ringwald * @brief Register for notifications and indications of a characteristic enabled by 116479188ed7SMilanka Ringwald * the gatt_client_write_client_characteristic_configuration function. 11659c662c9bSMatthias Ringwald * @param notification struct used to store registration 11666da84376SMilanka Ringwald * @param callback 1167b3f03c84SMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 1168b3f03c84SMatthias Ringwald * @param characteristic or NULL to receive updates for all characteristics 11699c662c9bSMatthias Ringwald */ 11706da84376SMilanka 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); 11713deb3ec6SMatthias Ringwald 11723deb3ec6SMatthias Ringwald /** 117379188ed7SMilanka Ringwald * @brief Stop listening to characteristic value updates registered with 117479188ed7SMilanka Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 11751f734b5fSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 11761f734b5fSMatthias Ringwald */ 11771f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); 11781f734b5fSMatthias Ringwald 11791f734b5fSMatthias Ringwald /** 11801a4874dcSMatthias Ringwald * @brief Register for notifications and indications of characteristic in a service 11811a4874dcSMatthias Ringwald * the gatt_client_write_client_characteristic_configuration function. 11821a4874dcSMatthias Ringwald * @param notification struct used to store registration 11831a4874dcSMatthias Ringwald * @param callback 11841a4874dcSMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 11851a4874dcSMatthias Ringwald * @param service 11861a4874dcSMatthias Ringwald * @param end_handle 11871a4874dcSMatthias Ringwald * @param service_id - context provided to callback in events 11881a4874dcSMatthias Ringwald * @param connection_id - contest provided to callback in events 11891a4874dcSMatthias Ringwald */ 11901a4874dcSMatthias Ringwald void gatt_client_listen_for_service_characteristic_value_updates(gatt_client_service_notification_t * notification, 11911a4874dcSMatthias Ringwald btstack_packet_handler_t callback, 11921a4874dcSMatthias Ringwald hci_con_handle_t con_handle, 11931a4874dcSMatthias Ringwald gatt_client_service_t * service, 11941a4874dcSMatthias Ringwald uint16_t service_id, 11951a4874dcSMatthias Ringwald uint16_t connection_id); 11961a4874dcSMatthias Ringwald 11971a4874dcSMatthias Ringwald /** 11981a4874dcSMatthias Ringwald * @brief Stop listening to characteristic value updates for registered service with 11991a4874dcSMatthias Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 12001a4874dcSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 12011a4874dcSMatthias Ringwald */ 12021a4874dcSMatthias Ringwald void gatt_client_stop_listening_for_service_characteristic_value_updates(gatt_client_service_notification_t * notification); 12031a4874dcSMatthias Ringwald 12041a4874dcSMatthias Ringwald 12051a4874dcSMatthias Ringwald /** 120679188ed7SMilanka Ringwald * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. 120779188ed7SMilanka Ringwald * Call the gatt_client_execute_write function to commit the transaction. 12086da84376SMilanka Ringwald * @param callback 12096da84376SMilanka Ringwald * @param con_handle 12106da84376SMilanka Ringwald * @param attribute_handle 12116da84376SMilanka Ringwald * @param offset of value 1212b45b7749SMilanka Ringwald * @param value_length 1213b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 12143deb3ec6SMatthias Ringwald */ 1215b45b7749SMilanka 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); 12163deb3ec6SMatthias Ringwald 12173deb3ec6SMatthias Ringwald /** 12186da84376SMilanka Ringwald * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. 12196da84376SMilanka Ringwald * @param callback 12206da84376SMilanka Ringwald * @param con_handle 122140faeb84SMilanka Ringwald * @return status 12223deb3ec6SMatthias Ringwald */ 1223711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 12243deb3ec6SMatthias Ringwald 12253deb3ec6SMatthias Ringwald /** 12266da84376SMilanka Ringwald * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. 12276da84376SMilanka Ringwald * @param callback 12286da84376SMilanka Ringwald * @param con_handle 122940faeb84SMilanka Ringwald * @return status 12303deb3ec6SMatthias Ringwald */ 1231711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 12323deb3ec6SMatthias Ringwald 123359d34cd2SMatthias Ringwald /** 123453e9c18fSMatthias Ringwald * @brief Request callback when regular gatt query can be sent 123553e9c18fSMatthias Ringwald * @note callback might happen during call to this function 123653e9c18fSMatthias Ringwald * @param callback_registration to point to callback function and context information 123753e9c18fSMatthias Ringwald * @param con_handle 123853e9c18fSMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 123953e9c18fSMatthias Ringwald */ 124053e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 124153e9c18fSMatthias Ringwald 124253e9c18fSMatthias Ringwald /** 124348553f67SDirk Helbig * @brief Remove queued callback for regular gatt queries, to be used on disconnect for example 124448553f67SDirk Helbig * @param callback_registration 124548553f67SDirk Helbig * @param con_handle 124648553f67SDirk Helbig * @return ERROR_CODE_SUCCESS if ok 124748553f67SDirk Helbig */ 124848553f67SDirk Helbig uint8_t gatt_client_remove_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 124948553f67SDirk Helbig 125048553f67SDirk Helbig /** 125159d34cd2SMatthias Ringwald * @brief Request callback when writing characteristic value without response is possible 125253e9c18fSMatthias Ringwald * @note callback might happen during call to this function 125359d34cd2SMatthias Ringwald * @param callback_registration to point to callback function and context information 125459d34cd2SMatthias Ringwald * @param con_handle 125559d34cd2SMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 125659d34cd2SMatthias Ringwald */ 125759d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 125859d34cd2SMatthias Ringwald 125959d34cd2SMatthias Ringwald 126059d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually 126159d34cd2SMatthias Ringwald /** 126259d34cd2SMatthias Ringwald * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees 126359d34cd2SMatthias Ringwald * a single successful gatt_client_write_value_of_characteristic_without_response call. 126459d34cd2SMatthias Ringwald * @deprecated please use gatt_client_request_to_write_without_response instead 126559d34cd2SMatthias Ringwald * @param callback 126659d34cd2SMatthias Ringwald * @param con_handle 126759d34cd2SMatthias Ringwald * @return status 126859d34cd2SMatthias Ringwald */ 126959d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 127059d34cd2SMatthias Ringwald 1271e80543a7SMatthias Ringwald /** 1272e80543a7SMatthias Ringwald * @brief Map ATT Error Code to (extended) Error Codes 1273e80543a7SMatthias Ringwald * @param att_error_code 1274e80543a7SMatthias Ringwald * @return 1275e80543a7SMatthias Ringwald */ 1276e80543a7SMatthias Ringwald uint8_t gatt_client_att_status_to_error_code(uint8_t att_error_code); 127759d34cd2SMatthias Ringwald 12783deb3ec6SMatthias Ringwald /* API_END */ 12793deb3ec6SMatthias Ringwald 12806ba2ad22SMatthias Ringwald // used by generated btstack_event.c 12816ba2ad22SMatthias Ringwald 1282313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); 1283313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); 1284313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); 12856ba2ad22SMatthias Ringwald 1286a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 1287a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); 128840faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client); 1289a6121b51SMilanka Ringwald #endif 1290a6121b51SMilanka Ringwald 1291*bbb8e698SMatthias Ringwald // used for testing, default is ON 1292*bbb8e698SMatthias Ringwald void gatt_client_le_enhanced_enable(bool enable); 1293*bbb8e698SMatthias Ringwald 12943deb3ec6SMatthias Ringwald #if defined __cplusplus 12953deb3ec6SMatthias Ringwald } 12963deb3ec6SMatthias Ringwald #endif 12973deb3ec6SMatthias Ringwald 12983deb3ec6SMatthias Ringwald #endif 1299