13deb3ec6SMatthias Ringwald /* 23deb3ec6SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 33deb3ec6SMatthias Ringwald * 43deb3ec6SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 53deb3ec6SMatthias Ringwald * modification, are permitted provided that the following conditions 63deb3ec6SMatthias Ringwald * are met: 73deb3ec6SMatthias Ringwald * 83deb3ec6SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 93deb3ec6SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 103deb3ec6SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 113deb3ec6SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 123deb3ec6SMatthias Ringwald * documentation and/or other materials provided with the distribution. 133deb3ec6SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 143deb3ec6SMatthias Ringwald * contributors may be used to endorse or promote products derived 153deb3ec6SMatthias Ringwald * from this software without specific prior written permission. 163deb3ec6SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 173deb3ec6SMatthias Ringwald * personal benefit and not for any commercial purpose or for 183deb3ec6SMatthias Ringwald * monetary gain. 193deb3ec6SMatthias Ringwald * 203deb3ec6SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 213deb3ec6SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 223deb3ec6SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 232fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 242fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 253deb3ec6SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 263deb3ec6SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 273deb3ec6SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 283deb3ec6SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 293deb3ec6SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 303deb3ec6SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 313deb3ec6SMatthias Ringwald * SUCH DAMAGE. 323deb3ec6SMatthias Ringwald * 333deb3ec6SMatthias Ringwald * Please inquire about commercial licensing options at 343deb3ec6SMatthias Ringwald * [email protected] 353deb3ec6SMatthias Ringwald * 363deb3ec6SMatthias Ringwald */ 373deb3ec6SMatthias Ringwald 38fe5a6c4eSMilanka Ringwald /** 39fe5a6c4eSMilanka Ringwald * @title GATT Client 40fe5a6c4eSMilanka Ringwald * 41fe5a6c4eSMilanka Ringwald */ 423deb3ec6SMatthias Ringwald 433deb3ec6SMatthias Ringwald #ifndef btstack_gatt_client_h 443deb3ec6SMatthias Ringwald #define btstack_gatt_client_h 453deb3ec6SMatthias Ringwald 463deb3ec6SMatthias Ringwald #include "hci.h" 473deb3ec6SMatthias Ringwald 483deb3ec6SMatthias Ringwald #if defined __cplusplus 493deb3ec6SMatthias Ringwald extern "C" { 503deb3ec6SMatthias Ringwald #endif 513deb3ec6SMatthias Ringwald 523deb3ec6SMatthias Ringwald typedef enum { 533deb3ec6SMatthias Ringwald P_READY, 543deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_QUERY, 553deb3ec6SMatthias Ringwald P_W4_SERVICE_QUERY_RESULT, 563deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_WITH_UUID_QUERY, 573deb3ec6SMatthias Ringwald P_W4_SERVICE_WITH_UUID_RESULT, 583deb3ec6SMatthias Ringwald 593deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY, 603deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT, 613deb3ec6SMatthias Ringwald P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY, 623deb3ec6SMatthias Ringwald P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT, 633deb3ec6SMatthias Ringwald 643deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, 653deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT, 663deb3ec6SMatthias Ringwald 673deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_QUERY, 683deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_QUERY_RESULT, 693deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, 703deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT, 713deb3ec6SMatthias Ringwald 723deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY, 733deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_VALUE_RESULT, 743deb3ec6SMatthias Ringwald 753deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_QUERY, 763deb3ec6SMatthias Ringwald P_W4_READ_BLOB_RESULT, 773deb3ec6SMatthias Ringwald 783deb3ec6SMatthias Ringwald P_W2_SEND_READ_BY_TYPE_REQUEST, 793deb3ec6SMatthias Ringwald P_W4_READ_BY_TYPE_RESPONSE, 803deb3ec6SMatthias Ringwald 813deb3ec6SMatthias Ringwald P_W2_SEND_READ_MULTIPLE_REQUEST, 823deb3ec6SMatthias Ringwald P_W4_READ_MULTIPLE_RESPONSE, 833deb3ec6SMatthias Ringwald 84f125a8efSMatthias Ringwald P_W2_SEND_READ_MULTIPLE_VARIABLE_REQUEST, 85f125a8efSMatthias Ringwald P_W4_READ_MULTIPLE_VARIABLE_RESPONSE, 86f125a8efSMatthias Ringwald 873deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, 883deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, 893deb3ec6SMatthias Ringwald 903deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE, 913deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_RESULT, 923deb3ec6SMatthias Ringwald P_W2_PREPARE_RELIABLE_WRITE, 933deb3ec6SMatthias Ringwald P_W4_PREPARE_RELIABLE_WRITE_RESULT, 943deb3ec6SMatthias Ringwald 953deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE, 963deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_RESULT, 973deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE, 983deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_RESULT, 993deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, 1003deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, 1013deb3ec6SMatthias Ringwald 102abdc9fb5SMatthias Ringwald #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY 103abdc9fb5SMatthias Ringwald P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 104abdc9fb5SMatthias Ringwald P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 105abdc9fb5SMatthias Ringwald #else 1063deb3ec6SMatthias Ringwald P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 1073deb3ec6SMatthias Ringwald P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 108abdc9fb5SMatthias Ringwald #endif 1093deb3ec6SMatthias Ringwald P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, 1103deb3ec6SMatthias Ringwald P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, 1113deb3ec6SMatthias Ringwald 1123deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY, 1133deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, 1143deb3ec6SMatthias Ringwald 1153deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, 1163deb3ec6SMatthias Ringwald P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, 1173deb3ec6SMatthias Ringwald 1183deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR, 1193deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1203deb3ec6SMatthias Ringwald 1213deb3ec6SMatthias Ringwald // all long writes use this 1223deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, 1233deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1243deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, 1253deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1263deb3ec6SMatthias Ringwald 1273deb3ec6SMatthias Ringwald // gatt reliable write API use this (manual version of the above) 1283deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_SINGLE, 1293deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_SINGLE_RESULT, 1303deb3ec6SMatthias Ringwald 131793cf6ceSMatthias Ringwald P_W4_IDENTITY_RESOLVING, 1323deb3ec6SMatthias Ringwald P_W4_CMAC_READY, 1333deb3ec6SMatthias Ringwald P_W4_CMAC_RESULT, 1343deb3ec6SMatthias Ringwald P_W2_SEND_SIGNED_WRITE, 1353deb3ec6SMatthias Ringwald P_W4_SEND_SINGED_WRITE_DONE, 1361450cdc6SMatthias Ringwald 1371450cdc6SMatthias Ringwald P_W2_SDP_QUERY, 1381450cdc6SMatthias Ringwald P_W4_SDP_QUERY, 139180cbe79SMatthias Ringwald P_W2_L2CAP_CONNECT, 1401450cdc6SMatthias Ringwald P_W4_L2CAP_CONNECTION, 14174daebdeSMatthias Ringwald P_W2_EMIT_CONNECTED, 142*df0a5c68SMatthias Ringwald P_L2CAP_CLOSED, 1433deb3ec6SMatthias Ringwald } gatt_client_state_t; 1443deb3ec6SMatthias Ringwald 1453deb3ec6SMatthias Ringwald 1463deb3ec6SMatthias Ringwald typedef enum{ 1473deb3ec6SMatthias Ringwald SEND_MTU_EXCHANGE, 1483deb3ec6SMatthias Ringwald SENT_MTU_EXCHANGE, 1495cf6c434SJakob Krantz MTU_EXCHANGED, 1505cf6c434SJakob Krantz MTU_AUTO_EXCHANGE_DISABLED 1513deb3ec6SMatthias Ringwald } gatt_client_mtu_t; 1523deb3ec6SMatthias Ringwald 153cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 154cbd76cecSMatthias Ringwald typedef enum { 155cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_IDLE, 1567627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W2_SEND, 1577627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W4_DONE, 15826166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND, 15926166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE, 16026166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND, 16126166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE, 16226166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND, 16326166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE, 1647627a0deSMatthias Ringwald GATT_CLIENT_EATT_L2CAP_SETUP, 165cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_READY, 166cbd76cecSMatthias Ringwald } gatt_client_eatt_state_t; 167cbd76cecSMatthias Ringwald #endif 168cbd76cecSMatthias Ringwald 1693deb3ec6SMatthias Ringwald typedef struct gatt_client{ 170665d90f2SMatthias Ringwald btstack_linked_item_t item; 1713deb3ec6SMatthias Ringwald // TODO: rename gatt_client_state -> state 172052dc82aSMatthias Ringwald gatt_client_state_t state; 1733deb3ec6SMatthias Ringwald 1749c662c9bSMatthias Ringwald // user callback 1759c662c9bSMatthias Ringwald btstack_packet_handler_t callback; 1763deb3ec6SMatthias Ringwald 17747181045SMatthias Ringwald // can write without response callback 17847181045SMatthias Ringwald btstack_packet_handler_t write_without_response_callback; 17947181045SMatthias Ringwald 18059d34cd2SMatthias Ringwald // can write without response requests 18159d34cd2SMatthias Ringwald btstack_linked_list_t write_without_response_requests; 18259d34cd2SMatthias Ringwald 18353e9c18fSMatthias Ringwald // regular gatt query requests 18453e9c18fSMatthias Ringwald btstack_linked_list_t query_requests; 18553e9c18fSMatthias Ringwald 186fc64f94aSMatthias Ringwald hci_con_handle_t con_handle; 187f4b33574SMatthias Ringwald 188e9cdf30bSMatthias Ringwald att_bearer_type_t bearer_type; 189e9cdf30bSMatthias Ringwald 1901450cdc6SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 1911450cdc6SMatthias Ringwald bd_addr_t addr; 1921450cdc6SMatthias Ringwald uint16_t l2cap_psm; 1931450cdc6SMatthias Ringwald uint16_t l2cap_cid; 194052dc82aSMatthias Ringwald btstack_context_callback_registration_t callback_request; 1951450cdc6SMatthias Ringwald #endif 1961450cdc6SMatthias Ringwald 197cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 198cbd76cecSMatthias Ringwald gatt_client_eatt_state_t eatt_state; 1997627a0deSMatthias Ringwald btstack_linked_list_t eatt_clients; 2007627a0deSMatthias Ringwald uint8_t * eatt_storage_buffer; 2017627a0deSMatthias Ringwald uint16_t eatt_storage_size; 2027627a0deSMatthias Ringwald uint8_t eatt_num_clients; 2037627a0deSMatthias Ringwald uint8_t gatt_server_supported_features; 2047627a0deSMatthias Ringwald uint16_t gatt_service_start_group_handle; 2057627a0deSMatthias Ringwald uint16_t gatt_service_end_group_handle; 206cbd76cecSMatthias Ringwald uint16_t gatt_client_supported_features_handle; 207cbd76cecSMatthias Ringwald #endif 208cbd76cecSMatthias Ringwald 2093deb3ec6SMatthias Ringwald uint16_t mtu; 2103deb3ec6SMatthias Ringwald gatt_client_mtu_t mtu_state; 2113deb3ec6SMatthias Ringwald 2123deb3ec6SMatthias Ringwald uint16_t uuid16; 2133deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 2143deb3ec6SMatthias Ringwald 2153deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2163deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2173deb3ec6SMatthias Ringwald 2183deb3ec6SMatthias Ringwald uint16_t query_start_handle; 2193deb3ec6SMatthias Ringwald uint16_t query_end_handle; 2203deb3ec6SMatthias Ringwald 2213deb3ec6SMatthias Ringwald uint8_t characteristic_properties; 2223deb3ec6SMatthias Ringwald uint16_t characteristic_start_handle; 2233deb3ec6SMatthias Ringwald 2243deb3ec6SMatthias Ringwald uint16_t attribute_handle; 2253deb3ec6SMatthias Ringwald uint16_t attribute_offset; 2263deb3ec6SMatthias Ringwald uint16_t attribute_length; 2273deb3ec6SMatthias Ringwald uint8_t* attribute_value; 2283deb3ec6SMatthias Ringwald 2293deb3ec6SMatthias Ringwald // read multiple characteristic values 2303deb3ec6SMatthias Ringwald uint16_t read_multiple_handle_count; 2313deb3ec6SMatthias Ringwald uint16_t * read_multiple_handles; 2323deb3ec6SMatthias Ringwald 2333deb3ec6SMatthias Ringwald uint16_t client_characteristic_configuration_handle; 2343deb3ec6SMatthias Ringwald uint8_t client_characteristic_configuration_value[2]; 2353deb3ec6SMatthias Ringwald 2363deb3ec6SMatthias Ringwald uint8_t filter_with_uuid; 2373deb3ec6SMatthias Ringwald uint8_t send_confirmation; 2383deb3ec6SMatthias Ringwald 2393deb3ec6SMatthias Ringwald int le_device_index; 2403deb3ec6SMatthias Ringwald uint8_t cmac[8]; 2413deb3ec6SMatthias Ringwald 242ec820d77SMatthias Ringwald btstack_timer_source_t gc_timeout; 243f4b33574SMatthias Ringwald 244f4b33574SMatthias Ringwald uint8_t security_counter; 2453503dc74SMatthias Ringwald uint8_t wait_for_authentication_complete; 246f4b33574SMatthias Ringwald uint8_t pending_error_code; 247f4b33574SMatthias Ringwald 2488918bbdaSMatthias Ringwald bool reencryption_active; 2498918bbdaSMatthias Ringwald uint8_t reencryption_result; 2508918bbdaSMatthias Ringwald 2511dfae9c7SMatthias Ringwald gap_security_level_t security_level; 2521dfae9c7SMatthias Ringwald 2533deb3ec6SMatthias Ringwald } gatt_client_t; 2543deb3ec6SMatthias Ringwald 2559c662c9bSMatthias Ringwald typedef struct gatt_client_notification { 256665d90f2SMatthias Ringwald btstack_linked_item_t item; 257b6e96f14SMatthias Ringwald btstack_packet_handler_t callback; 258711e6c80SMatthias Ringwald hci_con_handle_t con_handle; 2599c662c9bSMatthias Ringwald uint16_t attribute_handle; 2609c662c9bSMatthias Ringwald } gatt_client_notification_t; 2613deb3ec6SMatthias Ringwald 2623deb3ec6SMatthias Ringwald /* API_START */ 2633deb3ec6SMatthias Ringwald 264d25c33e5SMatthias Ringwald typedef struct { 2653deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2663deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2673deb3ec6SMatthias Ringwald uint16_t uuid16; 2683deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 269d25c33e5SMatthias Ringwald } gatt_client_service_t; 2703deb3ec6SMatthias Ringwald 271d25c33e5SMatthias Ringwald typedef struct { 2723deb3ec6SMatthias Ringwald uint16_t start_handle; 2733deb3ec6SMatthias Ringwald uint16_t value_handle; 2743deb3ec6SMatthias Ringwald uint16_t end_handle; 2753deb3ec6SMatthias Ringwald uint16_t properties; 2763deb3ec6SMatthias Ringwald uint16_t uuid16; 2773deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 278d25c33e5SMatthias Ringwald } gatt_client_characteristic_t; 2793deb3ec6SMatthias Ringwald 280d25c33e5SMatthias Ringwald typedef struct { 2813deb3ec6SMatthias Ringwald uint16_t handle; 2823deb3ec6SMatthias Ringwald uint16_t uuid16; 2833deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 284d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t; 2853deb3ec6SMatthias Ringwald 2863deb3ec6SMatthias Ringwald /** 2873deb3ec6SMatthias Ringwald * @brief Set up GATT client. 2883deb3ec6SMatthias Ringwald */ 2893deb3ec6SMatthias Ringwald void gatt_client_init(void); 2903deb3ec6SMatthias Ringwald 2913deb3ec6SMatthias Ringwald /** 29211279da7SMatthias Ringwald * @brief Set minimum required security level for GATT Client 29311279da7SMatthias Ringwald * @note The Bluetooth specification makes the GATT Server responsible to check for security. 294b11289a8SMatthias Ringwald * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. 295b11289a8SMatthias Ringwald * If your application is exchanging sensitive data with a remote device, you would need to manually check 296b11289a8SMatthias Ringwald * the security level before sending/receive such data. 297b11289a8SMatthias Ringwald * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange 298b11289a8SMatthias Ringwald * until the required security level is established. 299b11289a8SMatthias Ringwald * gatt_client_request_can_write_without_response_event does not trigger authentication 30059d34cd2SMatthias Ringwald * gatt_client_request_to_write_without_response does not trigger authentication 30111279da7SMatthias Ringwald * @pram level, default LEVEL_0 (no encryption required) 30211279da7SMatthias Ringwald */ 30311279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level); 30411279da7SMatthias Ringwald 30511279da7SMatthias Ringwald /** 3061450cdc6SMatthias Ringwald * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection 307effecf77SMatthias Ringwald * GATT_EVENT_CONNECTED with status and con_handle for other API functions 308effecf77SMatthias Ringwald * is emitted on connection complete. 309effecf77SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC. 3101450cdc6SMatthias Ringwald * @param addr 3111450cdc6SMatthias Ringwald * @return status 3121450cdc6SMatthias Ringwald */ 3131450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); 3141450cdc6SMatthias Ringwald 3151450cdc6SMatthias Ringwald /** 3161450cdc6SMatthias Ringwald * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server 3171450cdc6SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC 318effecf77SMatthias Ringwald * @param con_handle 3191450cdc6SMatthias Ringwald * @return status 3201450cdc6SMatthias Ringwald */ 3211450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3221450cdc6SMatthias Ringwald 3231450cdc6SMatthias Ringwald /** 3247627a0deSMatthias Ringwald * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection 3257627a0deSMatthias Ringwald * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events 32626166ecfSMatthias Ringwald * @param con_handle 32726166ecfSMatthias Ringwald * @param num_channels 3287627a0deSMatthias Ringwald * @param storage_buffer for L2CAP connection 3298540586aSMatthias Ringwald * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes 33026166ecfSMatthias Ringwald * @return 33126166ecfSMatthias Ringwald */ 33226166ecfSMatthias 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); 33326166ecfSMatthias Ringwald 33426166ecfSMatthias Ringwald /** 33579188ed7SMilanka Ringwald * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, 33679188ed7SMilanka Ringwald * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). 3376da84376SMilanka Ringwald * @param con_handle 3386da84376SMilanka Ringwald * @param mtu 33940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 34040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 341692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled 342692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 3433deb3ec6SMatthias Ringwald */ 344fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); 3453deb3ec6SMatthias Ringwald 3463deb3ec6SMatthias Ringwald /** 34779188ed7SMilanka Ringwald * @brief Sets whether a MTU Exchange Request shall be automatically send before the 34879188ed7SMilanka Ringwald * first attribute read request is send. Default is enabled. 3496da84376SMilanka Ringwald * @param enabled 3505cf6c434SJakob Krantz */ 3515cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); 3525cf6c434SJakob Krantz 3535cf6c434SJakob Krantz /** 35479188ed7SMilanka Ringwald * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU 35579188ed7SMilanka Ringwald * when gatt_client_mtu_enable_auto_negotiation is disabled. 3566da84376SMilanka Ringwald * @param callback 3576da84376SMilanka Ringwald * @param con_handle 3585cf6c434SJakob Krantz */ 3595cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3605cf6c434SJakob Krantz 3615cf6c434SJakob Krantz /** 362aacf1b1aSMilanka Ringwald * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. 3636da84376SMilanka Ringwald * @param con_handle 364692bf1adSMilanka Ringwald * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 3653deb3ec6SMatthias Ringwald */ 366fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle); 3673deb3ec6SMatthias Ringwald 3683deb3ec6SMatthias Ringwald /** 36979188ed7SMilanka Ringwald * @brief Discovers all primary services. 37079188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 37179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3726da84376SMilanka Ringwald * @param callback 3736da84376SMilanka Ringwald * @param con_handle 374692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 375692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 376692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 3773deb3ec6SMatthias Ringwald */ 378711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3793deb3ec6SMatthias Ringwald 3803deb3ec6SMatthias Ringwald /** 38179188ed7SMilanka Ringwald * @brief Discovers all secondary services. 38279188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 38379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3848d1f34d3SMatheus Eduardo Garbelini * @param callback 3858d1f34d3SMatheus Eduardo Garbelini * @param con_handle 3868d1f34d3SMatheus Eduardo Garbelini * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 3878d1f34d3SMatheus Eduardo Garbelini * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 3888d1f34d3SMatheus Eduardo Garbelini * ERROR_CODE_SUCCESS , if query is successfully registered 3898d1f34d3SMatheus Eduardo Garbelini */ 3908d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3918d1f34d3SMatheus Eduardo Garbelini 3928d1f34d3SMatheus Eduardo Garbelini /** 39379188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 39479188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 39579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3966da84376SMilanka Ringwald * @param callback 3976da84376SMilanka Ringwald * @param con_handle 3986da84376SMilanka Ringwald * @param uuid16 399692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 400692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 401692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4023deb3ec6SMatthias Ringwald */ 403711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); 4046da84376SMilanka Ringwald 4056da84376SMilanka Ringwald /** 40679188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 40779188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 40879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4096da84376SMilanka Ringwald * @param callback 4106da84376SMilanka Ringwald * @param con_handle 4116da84376SMilanka Ringwald * @param uuid128 412692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 413692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 414692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4156da84376SMilanka Ringwald */ 4166da84376SMilanka 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); 4173deb3ec6SMatthias Ringwald 4183deb3ec6SMatthias Ringwald /** 41979188ed7SMilanka Ringwald * @brief Finds included services within the specified service. 42079188ed7SMilanka Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 42179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 42279188ed7SMilanka Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 42379188ed7SMilanka Ringwald * an ATT find information request for the returned start group handle 42479188ed7SMilanka Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 42579188ed7SMilanka Ringwald * to the list of all primary services. 4266da84376SMilanka Ringwald * @param callback 4276da84376SMilanka Ringwald * @param con_handle 4286da84376SMilanka Ringwald * @param service 429692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 430692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 431692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4323deb3ec6SMatthias Ringwald */ 433711e6c80SMatthias 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); 4343deb3ec6SMatthias Ringwald 4353deb3ec6SMatthias Ringwald /** 43679188ed7SMilanka Ringwald * @brief Discovers all characteristics within the specified service. 43779188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 43879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4396da84376SMilanka Ringwald * @param callback 4406da84376SMilanka Ringwald * @param con_handle 4416da84376SMilanka Ringwald * @param service 442692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 443692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 444692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4453deb3ec6SMatthias Ringwald */ 446711e6c80SMatthias 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); 4473deb3ec6SMatthias Ringwald 4483deb3ec6SMatthias Ringwald /** 44979188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within 45079188ed7SMilanka Ringwald * the specified service or handle range, and return those that match the given UUID. 45179188ed7SMilanka Ringwald * 45279188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 45379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4546da84376SMilanka Ringwald * @param callback 4556da84376SMilanka Ringwald * @param con_handle 4566da84376SMilanka Ringwald * @param start_handle 4576da84376SMilanka Ringwald * @param end_handle 4586da84376SMilanka Ringwald * @param uuid16 459692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 460692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 461692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4623deb3ec6SMatthias Ringwald */ 463711e6c80SMatthias 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); 4646da84376SMilanka Ringwald 4656da84376SMilanka Ringwald /** 46679188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 46779188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 46879188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 46979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4706da84376SMilanka Ringwald * @param callback 4716da84376SMilanka Ringwald * @param con_handle 4726da84376SMilanka Ringwald * @param start_handle 4736da84376SMilanka Ringwald * @param end_handle 4746da84376SMilanka Ringwald * @param uuid128 475692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 476692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 477692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4786da84376SMilanka Ringwald */ 479045d700dSDavid 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); 4806da84376SMilanka Ringwald 4816da84376SMilanka Ringwald /** 48279188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 48379188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 48479188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 48579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4866da84376SMilanka Ringwald * @param callback 4876da84376SMilanka Ringwald * @param con_handle 4886da84376SMilanka Ringwald * @param service 4896da84376SMilanka Ringwald * @param uuid16 490692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 491692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 492692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4936da84376SMilanka Ringwald */ 494711e6c80SMatthias 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); 4956da84376SMilanka Ringwald 4966da84376SMilanka Ringwald /** 49779188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 49879188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 49979188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 50079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5016da84376SMilanka Ringwald * @param callback 5026da84376SMilanka Ringwald * @param con_handle 5036da84376SMilanka Ringwald * @param service 5046da84376SMilanka Ringwald * @param uuid128 505692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 506692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 507692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5086da84376SMilanka Ringwald */ 509045d700dSDavid 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); 5103deb3ec6SMatthias Ringwald 5113deb3ec6SMatthias Ringwald /** 51279188ed7SMilanka Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 51379188ed7SMilanka Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 51479188ed7SMilanka Ringwald * 51579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5166da84376SMilanka Ringwald * @param callback 5176da84376SMilanka Ringwald * @param con_handle 5186da84376SMilanka Ringwald * @param characteristic 519692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 520692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 521692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5223deb3ec6SMatthias Ringwald */ 523711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 5243deb3ec6SMatthias Ringwald 5253deb3ec6SMatthias Ringwald /** 52679188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 52779188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 52879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5296da84376SMilanka Ringwald * @param callback 5306da84376SMilanka Ringwald * @param con_handle 5316da84376SMilanka Ringwald * @param characteristic 532692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 533692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 534692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5353deb3ec6SMatthias Ringwald */ 536711e6c80SMatthias 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); 5376da84376SMilanka Ringwald 5386da84376SMilanka Ringwald /** 53979188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 54079188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 54179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5426da84376SMilanka Ringwald * @param callback 5436da84376SMilanka Ringwald * @param con_handle 544b45b7749SMilanka Ringwald * @param value_handle 545692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 546692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 547692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5486da84376SMilanka Ringwald */ 549b45b7749SMilanka 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); 5503deb3ec6SMatthias Ringwald 5513deb3ec6SMatthias Ringwald /** 55279188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 55379188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 55479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 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_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); 5656da84376SMilanka Ringwald 5666da84376SMilanka Ringwald /** 56779188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 56879188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 56979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5706da84376SMilanka Ringwald * @param callback 5716da84376SMilanka Ringwald * @param con_handle 5726da84376SMilanka Ringwald * @param start_handle 5736da84376SMilanka Ringwald * @param end_handle 5746da84376SMilanka Ringwald * @param uuid128 575692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 576692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 577692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5786da84376SMilanka Ringwald */ 579045d700dSDavid 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); 5803deb3ec6SMatthias Ringwald 5813deb3ec6SMatthias Ringwald /** 58279188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 58379188ed7SMilanka Ringwald * The value will be returned in several blobs. 58479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 58579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5866da84376SMilanka Ringwald * @param callback 5876da84376SMilanka Ringwald * @param con_handle 5886da84376SMilanka Ringwald * @param characteristic 589692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 590692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 591692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5923deb3ec6SMatthias Ringwald */ 593711e6c80SMatthias 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); 5946da84376SMilanka Ringwald 5956da84376SMilanka Ringwald /** 59679188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 59779188ed7SMilanka Ringwald * The value will be returned in several blobs. 59879188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 59979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6006da84376SMilanka Ringwald * @param callback 6016da84376SMilanka Ringwald * @param con_handle 602b45b7749SMilanka Ringwald * @param value_handle 603692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 604692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 605692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6066da84376SMilanka Ringwald */ 607b45b7749SMilanka 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); 6086da84376SMilanka Ringwald 6096da84376SMilanka Ringwald /** 61079188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 61179188ed7SMilanka Ringwald * The value will be returned in several blobs. 61279188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 61379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6146da84376SMilanka Ringwald * @param callback 6156da84376SMilanka Ringwald * @param con_handle 616b45b7749SMilanka Ringwald * @param value_handle 6176da84376SMilanka Ringwald * @param offset 618692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 619692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 620692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6216da84376SMilanka Ringwald */ 622b45b7749SMilanka 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); 6233deb3ec6SMatthias Ringwald 6243deb3ec6SMatthias Ringwald /* 62579188ed7SMilanka Ringwald * @brief Read multiple characteristic values. 62679188ed7SMilanka Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 62779188ed7SMilanka Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 6286da84376SMilanka Ringwald * @param callback 6296da84376SMilanka Ringwald * @param con_handle 6306da84376SMilanka Ringwald * @param num_value_handles 6316da84376SMilanka Ringwald * @param value_handles list of handles 63279188ed7SMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 63379188ed7SMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 63479188ed7SMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6353deb3ec6SMatthias Ringwald */ 636711e6c80SMatthias 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); 6373deb3ec6SMatthias Ringwald 638f125a8efSMatthias Ringwald /* 639f125a8efSMatthias Ringwald * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer 640f125a8efSMatthias Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 641f125a8efSMatthias Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 642f125a8efSMatthias Ringwald * @param callback 643f125a8efSMatthias Ringwald * @param con_handle 644f125a8efSMatthias Ringwald * @param num_value_handles 645f125a8efSMatthias Ringwald * @param value_handles list of handles 646f125a8efSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 647f125a8efSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 648f125a8efSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 649f125a8efSMatthias Ringwald */ 650f125a8efSMatthias 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); 651f125a8efSMatthias Ringwald 6523deb3ec6SMatthias Ringwald /** 65379188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle without 65479188ed7SMilanka Ringwald * an acknowledgment that the write was successfully performed. 6556da84376SMilanka Ringwald * @param con_handle 656b45b7749SMilanka Ringwald * @param value_handle 657b45b7749SMilanka Ringwald * @param value_length 6587e6f0853SDavid Lechner * @param value is copied on success and does not need to be retained 659692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 660692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 661692bf1adSMilanka Ringwald * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots 662692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6633deb3ec6SMatthias Ringwald */ 664b45b7749SMilanka 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); 6653deb3ec6SMatthias Ringwald 6663deb3ec6SMatthias Ringwald /** 66779188ed7SMilanka Ringwald * @brief Writes the authenticated characteristic value using the characteristic's value handle 66879188ed7SMilanka Ringwald * without an acknowledgment that the write was successfully performed. 66979188ed7SMilanka Ringwald * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, 67079188ed7SMilanka Ringwald * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. 6716da84376SMilanka Ringwald * @param callback 6726da84376SMilanka Ringwald * @param con_handle 6736da84376SMilanka Ringwald * @param value_handle 6746da84376SMilanka Ringwald * @param message_len 6756da84376SMilanka Ringwald * @param message is not copied, make sure memory is accessible until write is done 67640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 67740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 678692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 679692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 6803deb3ec6SMatthias Ringwald */ 6816da84376SMilanka Ringwald uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t message_len, uint8_t * message); 6823deb3ec6SMatthias Ringwald 6833deb3ec6SMatthias Ringwald /** 684b2468039SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 685b2468039SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 686b2468039SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to 687b2468039SMilanka Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 6886da84376SMilanka Ringwald * @param callback 6896da84376SMilanka Ringwald * @param con_handle 690b45b7749SMilanka Ringwald * @param value_handle 691b45b7749SMilanka Ringwald * @param value_length 692b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 69340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 69440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 695692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 696692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 6973deb3ec6SMatthias Ringwald */ 698b45b7749SMilanka 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); 6996da84376SMilanka Ringwald 7006da84376SMilanka Ringwald /** 70179188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 70279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 70379188ed7SMilanka 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). 7046da84376SMilanka Ringwald * @param callback 7056da84376SMilanka Ringwald * @param con_handle 706b45b7749SMilanka Ringwald * @param value_handle 707b45b7749SMilanka Ringwald * @param value_length 708b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 70940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 71040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 711692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 712692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7136da84376SMilanka Ringwald */ 714b45b7749SMilanka 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); 7156da84376SMilanka Ringwald 7166da84376SMilanka Ringwald /** 71779188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 71879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 71979188ed7SMilanka 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). 7206da84376SMilanka Ringwald * @param callback 7216da84376SMilanka Ringwald * @param con_handle 722b45b7749SMilanka Ringwald * @param value_handle 7236da84376SMilanka Ringwald * @param offset of value 724b45b7749SMilanka Ringwald * @param value_length 725b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 72640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 72740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 728692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 729692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7306da84376SMilanka Ringwald */ 731b45b7749SMilanka 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); 7323deb3ec6SMatthias Ringwald 7333deb3ec6SMatthias Ringwald /** 73479188ed7SMilanka Ringwald * @brief Writes of the long characteristic value using the characteristic's value handle. 73579188ed7SMilanka Ringwald * It uses server response to validate that the write was correctly received. 73679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. 73779188ed7SMilanka 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). 7386da84376SMilanka Ringwald * @param callback 7396da84376SMilanka Ringwald * @param con_handle 740b45b7749SMilanka Ringwald * @param value_handle 741b45b7749SMilanka Ringwald * @param value_length 742b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 74340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 74440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 745692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 746692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7473deb3ec6SMatthias Ringwald */ 748b45b7749SMilanka 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); 7493deb3ec6SMatthias Ringwald 7503deb3ec6SMatthias Ringwald /** 75179188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 75279188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 75379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7546da84376SMilanka Ringwald * @param callback 7556da84376SMilanka Ringwald * @param con_handle 7566da84376SMilanka Ringwald * @param descriptor 75740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 75840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 759692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 760692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7613deb3ec6SMatthias Ringwald */ 762711e6c80SMatthias 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); 7636da84376SMilanka Ringwald 7646da84376SMilanka Ringwald /** 76579188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 76679188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event 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 7706da84376SMilanka Ringwald * @param descriptor 77140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 77240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 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 */ 776711e6c80SMatthias 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); 7773deb3ec6SMatthias Ringwald 7783deb3ec6SMatthias Ringwald /** 77979188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 78079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 78179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7826da84376SMilanka Ringwald * @param callback 7836da84376SMilanka Ringwald * @param con_handle 784b45b7749SMilanka Ringwald * @param descriptor 78540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 78640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 787692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 788692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7893deb3ec6SMatthias Ringwald */ 790711e6c80SMatthias 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); 7916da84376SMilanka Ringwald 7926da84376SMilanka Ringwald /** 79379188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 79479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 79579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7966da84376SMilanka Ringwald * @param callback 7976da84376SMilanka Ringwald * @param con_handle 7986da84376SMilanka Ringwald * @param descriptor_handle 79940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 80040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 801692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 802692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8036da84376SMilanka Ringwald */ 804711e6c80SMatthias 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); 8056da84376SMilanka Ringwald 8066da84376SMilanka Ringwald /** 80779188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 80879188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 80979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8106da84376SMilanka Ringwald * @param callback 8116da84376SMilanka Ringwald * @param con_handle 8126da84376SMilanka Ringwald * @param descriptor_handle 8136da84376SMilanka Ringwald * @param offset 81440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 81540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 816692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 817692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8186da84376SMilanka Ringwald */ 819711e6c80SMatthias 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); 8203deb3ec6SMatthias Ringwald 8213deb3ec6SMatthias Ringwald /** 82279188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 82379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 82479188ed7SMilanka 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). 8256da84376SMilanka Ringwald * @param callback 8266da84376SMilanka Ringwald * @param con_handle 8276da84376SMilanka Ringwald * @param descriptor 828b45b7749SMilanka Ringwald * @param value_length 829b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 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 */ 835b45b7749SMilanka 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); 8366da84376SMilanka Ringwald 8376da84376SMilanka Ringwald /** 83879188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 83979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 84079188ed7SMilanka 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). 8416da84376SMilanka Ringwald * @param callback 8426da84376SMilanka Ringwald * @param con_handle 8436da84376SMilanka Ringwald * @param descriptor_handle 844b45b7749SMilanka Ringwald * @param value_length 845b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 84640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 84740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 848692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 849692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8506da84376SMilanka Ringwald */ 851b45b7749SMilanka 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); 8526da84376SMilanka Ringwald 8536da84376SMilanka Ringwald /** 85479188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 85579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 85679188ed7SMilanka Ringwald * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 8576da84376SMilanka Ringwald * @param callback 8586da84376SMilanka Ringwald * @param con_handle 8596da84376SMilanka Ringwald * @param descriptor 860b45b7749SMilanka Ringwald * @param value_length 861b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 86240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 86340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 864692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 865692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8666da84376SMilanka Ringwald */ 867b45b7749SMilanka 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); 8686da84376SMilanka Ringwald 8696da84376SMilanka Ringwald /** 87079188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 87179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 87279188ed7SMilanka Ringwald * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 8736da84376SMilanka Ringwald * @param callback 8746da84376SMilanka Ringwald * @param con_handle 8756da84376SMilanka Ringwald * @param descriptor_handle 876b45b7749SMilanka Ringwald * @param value_length 877b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 87840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 87940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 880692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 881692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8826da84376SMilanka Ringwald */ 883b45b7749SMilanka Ringwald uint8_t gatt_client_write_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); 8846da84376SMilanka Ringwald 8856da84376SMilanka Ringwald /** 88679188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 88779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 88879188ed7SMilanka Ringwald * The write is successfully performed if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 8896da84376SMilanka Ringwald * @param callback 8906da84376SMilanka Ringwald * @param con_handle 8916da84376SMilanka Ringwald * @param descriptor_handle 8926da84376SMilanka Ringwald * @param offset of value 893b45b7749SMilanka Ringwald * @param value_length 894b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 89540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 89640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 897692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 898692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8996da84376SMilanka Ringwald */ 900b45b7749SMilanka 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); 9013deb3ec6SMatthias Ringwald 9023deb3ec6SMatthias Ringwald /** 90379188ed7SMilanka Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 90479188ed7SMilanka Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 90579188ed7SMilanka Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 90679188ed7SMilanka Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 90779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 90879188ed7SMilanka 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). 9096da84376SMilanka Ringwald * @param callback 9106da84376SMilanka Ringwald * @param con_handle 9116da84376SMilanka Ringwald * @param characteristic 912b7e5512fSMilanka Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 91340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 91440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 915692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 916b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 917b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 9186b04f675SMilanka Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 919b7e5512fSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9203deb3ec6SMatthias Ringwald */ 921711e6c80SMatthias 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); 9229c662c9bSMatthias Ringwald 9239c662c9bSMatthias Ringwald /** 92479188ed7SMilanka Ringwald * @brief Register for notifications and indications of a characteristic enabled by 92579188ed7SMilanka Ringwald * the gatt_client_write_client_characteristic_configuration function. 9269c662c9bSMatthias Ringwald * @param notification struct used to store registration 9276da84376SMilanka Ringwald * @param callback 928b3f03c84SMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 929b3f03c84SMatthias Ringwald * @param characteristic or NULL to receive updates for all characteristics 9309c662c9bSMatthias Ringwald */ 9316da84376SMilanka 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); 9323deb3ec6SMatthias Ringwald 9333deb3ec6SMatthias Ringwald /** 93479188ed7SMilanka Ringwald * @brief Stop listening to characteristic value updates registered with 93579188ed7SMilanka Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 9361f734b5fSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 9371f734b5fSMatthias Ringwald */ 9381f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); 9391f734b5fSMatthias Ringwald 9401f734b5fSMatthias Ringwald /** 94179188ed7SMilanka Ringwald * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. 94279188ed7SMilanka Ringwald * Call the gatt_client_execute_write function to commit the transaction. 9436da84376SMilanka Ringwald * @param callback 9446da84376SMilanka Ringwald * @param con_handle 9456da84376SMilanka Ringwald * @param attribute_handle 9466da84376SMilanka Ringwald * @param offset of value 947b45b7749SMilanka Ringwald * @param value_length 948b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 9493deb3ec6SMatthias Ringwald */ 950b45b7749SMilanka 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); 9513deb3ec6SMatthias Ringwald 9523deb3ec6SMatthias Ringwald /** 9536da84376SMilanka Ringwald * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9546da84376SMilanka Ringwald * @param callback 9556da84376SMilanka Ringwald * @param con_handle 95640faeb84SMilanka Ringwald * @return status 9573deb3ec6SMatthias Ringwald */ 958711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9593deb3ec6SMatthias Ringwald 9603deb3ec6SMatthias Ringwald /** 9616da84376SMilanka Ringwald * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9626da84376SMilanka Ringwald * @param callback 9636da84376SMilanka Ringwald * @param con_handle 96440faeb84SMilanka Ringwald * @return status 9653deb3ec6SMatthias Ringwald */ 966711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9673deb3ec6SMatthias Ringwald 96859d34cd2SMatthias Ringwald /** 96953e9c18fSMatthias Ringwald * @brief Request callback when regular gatt query can be sent 97053e9c18fSMatthias Ringwald * @note callback might happen during call to this function 97153e9c18fSMatthias Ringwald * @param callback_registration to point to callback function and context information 97253e9c18fSMatthias Ringwald * @param con_handle 97353e9c18fSMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 97453e9c18fSMatthias Ringwald */ 97553e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 97653e9c18fSMatthias Ringwald 97753e9c18fSMatthias Ringwald /** 97859d34cd2SMatthias Ringwald * @brief Request callback when writing characteristic value without response is possible 97953e9c18fSMatthias Ringwald * @note callback might happen during call to this function 98059d34cd2SMatthias Ringwald * @param callback_registration to point to callback function and context information 98159d34cd2SMatthias Ringwald * @param con_handle 98259d34cd2SMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 98359d34cd2SMatthias Ringwald */ 98459d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 98559d34cd2SMatthias Ringwald 98659d34cd2SMatthias Ringwald 98759d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually 98859d34cd2SMatthias Ringwald /** 98959d34cd2SMatthias Ringwald * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees 99059d34cd2SMatthias Ringwald * a single successful gatt_client_write_value_of_characteristic_without_response call. 99159d34cd2SMatthias Ringwald * @deprecated please use gatt_client_request_to_write_without_response instead 99259d34cd2SMatthias Ringwald * @param callback 99359d34cd2SMatthias Ringwald * @param con_handle 99459d34cd2SMatthias Ringwald * @return status 99559d34cd2SMatthias Ringwald */ 99659d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 99759d34cd2SMatthias Ringwald 99859d34cd2SMatthias Ringwald 9993deb3ec6SMatthias Ringwald /* API_END */ 10003deb3ec6SMatthias Ringwald 10016ba2ad22SMatthias Ringwald // used by generated btstack_event.c 10026ba2ad22SMatthias Ringwald 1003313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); 1004313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); 1005313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); 10066ba2ad22SMatthias Ringwald 1007a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 1008a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); 100940faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client); 1010a6121b51SMilanka Ringwald #endif 1011a6121b51SMilanka Ringwald 10123deb3ec6SMatthias Ringwald #if defined __cplusplus 10133deb3ec6SMatthias Ringwald } 10143deb3ec6SMatthias Ringwald #endif 10153deb3ec6SMatthias Ringwald 10163deb3ec6SMatthias Ringwald #endif 1017