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, 563deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_QUERY, 573deb3ec6SMatthias Ringwald P_W4_SERVICE_QUERY_RESULT, 583deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_WITH_UUID_QUERY, 593deb3ec6SMatthias Ringwald P_W4_SERVICE_WITH_UUID_RESULT, 603deb3ec6SMatthias Ringwald 613deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY, 623deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT, 633deb3ec6SMatthias Ringwald P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY, 643deb3ec6SMatthias Ringwald P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT, 653deb3ec6SMatthias Ringwald 663deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, 673deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT, 683deb3ec6SMatthias Ringwald 693deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_QUERY, 703deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_QUERY_RESULT, 713deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, 723deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT, 733deb3ec6SMatthias Ringwald 743deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY, 753deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_VALUE_RESULT, 763deb3ec6SMatthias Ringwald 773deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_QUERY, 783deb3ec6SMatthias Ringwald P_W4_READ_BLOB_RESULT, 793deb3ec6SMatthias Ringwald 803deb3ec6SMatthias Ringwald P_W2_SEND_READ_BY_TYPE_REQUEST, 813deb3ec6SMatthias Ringwald P_W4_READ_BY_TYPE_RESPONSE, 823deb3ec6SMatthias Ringwald 833deb3ec6SMatthias Ringwald P_W2_SEND_READ_MULTIPLE_REQUEST, 843deb3ec6SMatthias Ringwald P_W4_READ_MULTIPLE_RESPONSE, 853deb3ec6SMatthias Ringwald 86f125a8efSMatthias Ringwald P_W2_SEND_READ_MULTIPLE_VARIABLE_REQUEST, 87f125a8efSMatthias Ringwald P_W4_READ_MULTIPLE_VARIABLE_RESPONSE, 88f125a8efSMatthias Ringwald 893deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, 903deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, 913deb3ec6SMatthias Ringwald 923deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE, 933deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_RESULT, 943deb3ec6SMatthias Ringwald P_W2_PREPARE_RELIABLE_WRITE, 953deb3ec6SMatthias Ringwald P_W4_PREPARE_RELIABLE_WRITE_RESULT, 963deb3ec6SMatthias Ringwald 973deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE, 983deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_RESULT, 993deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE, 1003deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_RESULT, 1013deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, 1023deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, 1033deb3ec6SMatthias Ringwald 104abdc9fb5SMatthias Ringwald #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY 105abdc9fb5SMatthias Ringwald P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 106abdc9fb5SMatthias Ringwald P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 107abdc9fb5SMatthias Ringwald #else 1083deb3ec6SMatthias Ringwald P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 1093deb3ec6SMatthias Ringwald P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 110abdc9fb5SMatthias Ringwald #endif 1113deb3ec6SMatthias Ringwald P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, 1123deb3ec6SMatthias Ringwald P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, 1133deb3ec6SMatthias Ringwald 1143deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY, 1153deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, 1163deb3ec6SMatthias Ringwald 1173deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, 1183deb3ec6SMatthias Ringwald P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, 1193deb3ec6SMatthias Ringwald 1203deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR, 1213deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1223deb3ec6SMatthias Ringwald 1233deb3ec6SMatthias Ringwald // all long writes use this 1243deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, 1253deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1263deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, 1273deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1283deb3ec6SMatthias Ringwald 1293deb3ec6SMatthias Ringwald // gatt reliable write API use this (manual version of the above) 1303deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_SINGLE, 1313deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_SINGLE_RESULT, 1323deb3ec6SMatthias Ringwald 133793cf6ceSMatthias Ringwald P_W4_IDENTITY_RESOLVING, 1343deb3ec6SMatthias Ringwald P_W4_CMAC_READY, 1353deb3ec6SMatthias Ringwald P_W4_CMAC_RESULT, 1363deb3ec6SMatthias Ringwald P_W2_SEND_SIGNED_WRITE, 137*4c7c987fSMatthias Ringwald P_W4_SEND_SIGNED_WRITE_DONE, 1381450cdc6SMatthias Ringwald 1391450cdc6SMatthias Ringwald P_W2_SDP_QUERY, 1401450cdc6SMatthias Ringwald P_W4_SDP_QUERY, 141180cbe79SMatthias Ringwald P_W2_L2CAP_CONNECT, 1421450cdc6SMatthias Ringwald P_W4_L2CAP_CONNECTION, 14374daebdeSMatthias Ringwald P_W2_EMIT_CONNECTED, 144df0a5c68SMatthias Ringwald P_L2CAP_CLOSED, 1453deb3ec6SMatthias Ringwald } gatt_client_state_t; 1463deb3ec6SMatthias Ringwald 1473deb3ec6SMatthias Ringwald 1483deb3ec6SMatthias Ringwald typedef enum{ 1493deb3ec6SMatthias Ringwald SEND_MTU_EXCHANGE, 1503deb3ec6SMatthias Ringwald SENT_MTU_EXCHANGE, 1515cf6c434SJakob Krantz MTU_EXCHANGED, 1525cf6c434SJakob Krantz MTU_AUTO_EXCHANGE_DISABLED 1533deb3ec6SMatthias Ringwald } gatt_client_mtu_t; 1543deb3ec6SMatthias Ringwald 155cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 156cbd76cecSMatthias Ringwald typedef enum { 157cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_IDLE, 1587627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W2_SEND, 1597627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W4_DONE, 16026166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND, 16126166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE, 16226166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND, 16326166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE, 16426166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND, 16526166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE, 1667627a0deSMatthias Ringwald GATT_CLIENT_EATT_L2CAP_SETUP, 167cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_READY, 168cbd76cecSMatthias Ringwald } gatt_client_eatt_state_t; 169cbd76cecSMatthias Ringwald #endif 170cbd76cecSMatthias Ringwald 1713deb3ec6SMatthias Ringwald typedef struct gatt_client{ 172665d90f2SMatthias Ringwald btstack_linked_item_t item; 173*4c7c987fSMatthias Ringwald 174052dc82aSMatthias Ringwald gatt_client_state_t state; 1753deb3ec6SMatthias Ringwald 1769c662c9bSMatthias Ringwald // user callback 1779c662c9bSMatthias Ringwald btstack_packet_handler_t callback; 1783deb3ec6SMatthias Ringwald 17947181045SMatthias Ringwald // can write without response callback 18047181045SMatthias Ringwald btstack_packet_handler_t write_without_response_callback; 18147181045SMatthias Ringwald 18259d34cd2SMatthias Ringwald // can write without response requests 18359d34cd2SMatthias Ringwald btstack_linked_list_t write_without_response_requests; 18459d34cd2SMatthias Ringwald 18553e9c18fSMatthias Ringwald // regular gatt query requests 18653e9c18fSMatthias Ringwald btstack_linked_list_t query_requests; 18753e9c18fSMatthias Ringwald 188fc64f94aSMatthias Ringwald hci_con_handle_t con_handle; 189f4b33574SMatthias Ringwald 190e9cdf30bSMatthias Ringwald att_bearer_type_t bearer_type; 191e9cdf30bSMatthias Ringwald 1921450cdc6SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 1931450cdc6SMatthias Ringwald bd_addr_t addr; 1941450cdc6SMatthias Ringwald uint16_t l2cap_psm; 1951450cdc6SMatthias Ringwald uint16_t l2cap_cid; 196052dc82aSMatthias Ringwald btstack_context_callback_registration_t callback_request; 1971450cdc6SMatthias Ringwald #endif 1981450cdc6SMatthias Ringwald 199cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 200cbd76cecSMatthias Ringwald gatt_client_eatt_state_t eatt_state; 2017627a0deSMatthias Ringwald btstack_linked_list_t eatt_clients; 2027627a0deSMatthias Ringwald uint8_t * eatt_storage_buffer; 2037627a0deSMatthias Ringwald uint16_t eatt_storage_size; 2047627a0deSMatthias Ringwald uint8_t eatt_num_clients; 2057627a0deSMatthias Ringwald uint8_t gatt_server_supported_features; 2067627a0deSMatthias Ringwald uint16_t gatt_service_start_group_handle; 2077627a0deSMatthias Ringwald uint16_t gatt_service_end_group_handle; 208cbd76cecSMatthias Ringwald uint16_t gatt_client_supported_features_handle; 209cbd76cecSMatthias Ringwald #endif 210cbd76cecSMatthias Ringwald 2113deb3ec6SMatthias Ringwald uint16_t mtu; 2123deb3ec6SMatthias Ringwald gatt_client_mtu_t mtu_state; 2133deb3ec6SMatthias Ringwald 2143deb3ec6SMatthias Ringwald uint16_t uuid16; 2153deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 2163deb3ec6SMatthias Ringwald 2173deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2183deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2193deb3ec6SMatthias Ringwald 2203deb3ec6SMatthias Ringwald uint16_t query_start_handle; 2213deb3ec6SMatthias Ringwald uint16_t query_end_handle; 2223deb3ec6SMatthias Ringwald 2233deb3ec6SMatthias Ringwald uint8_t characteristic_properties; 2243deb3ec6SMatthias Ringwald uint16_t characteristic_start_handle; 2253deb3ec6SMatthias Ringwald 2263deb3ec6SMatthias Ringwald uint16_t attribute_handle; 2273deb3ec6SMatthias Ringwald uint16_t attribute_offset; 2283deb3ec6SMatthias Ringwald uint16_t attribute_length; 2293deb3ec6SMatthias Ringwald uint8_t* attribute_value; 2303deb3ec6SMatthias Ringwald 2313deb3ec6SMatthias Ringwald // read multiple characteristic values 2323deb3ec6SMatthias Ringwald uint16_t read_multiple_handle_count; 2333deb3ec6SMatthias Ringwald uint16_t * read_multiple_handles; 2343deb3ec6SMatthias Ringwald 2353deb3ec6SMatthias Ringwald uint16_t client_characteristic_configuration_handle; 2363deb3ec6SMatthias Ringwald uint8_t client_characteristic_configuration_value[2]; 2373deb3ec6SMatthias Ringwald 2383deb3ec6SMatthias Ringwald uint8_t filter_with_uuid; 2393deb3ec6SMatthias Ringwald uint8_t send_confirmation; 2403deb3ec6SMatthias Ringwald 2413deb3ec6SMatthias Ringwald int le_device_index; 2423deb3ec6SMatthias Ringwald uint8_t cmac[8]; 2433deb3ec6SMatthias Ringwald 244ec820d77SMatthias Ringwald btstack_timer_source_t gc_timeout; 245f4b33574SMatthias Ringwald 246f4b33574SMatthias Ringwald uint8_t security_counter; 2473503dc74SMatthias Ringwald uint8_t wait_for_authentication_complete; 248f4b33574SMatthias Ringwald uint8_t pending_error_code; 249f4b33574SMatthias Ringwald 2508918bbdaSMatthias Ringwald bool reencryption_active; 2518918bbdaSMatthias Ringwald uint8_t reencryption_result; 2528918bbdaSMatthias Ringwald 2531dfae9c7SMatthias Ringwald gap_security_level_t security_level; 2541dfae9c7SMatthias Ringwald 2553deb3ec6SMatthias Ringwald } gatt_client_t; 2563deb3ec6SMatthias Ringwald 2579c662c9bSMatthias Ringwald typedef struct gatt_client_notification { 258665d90f2SMatthias Ringwald btstack_linked_item_t item; 259b6e96f14SMatthias Ringwald btstack_packet_handler_t callback; 260711e6c80SMatthias Ringwald hci_con_handle_t con_handle; 2619c662c9bSMatthias Ringwald uint16_t attribute_handle; 2629c662c9bSMatthias Ringwald } gatt_client_notification_t; 2633deb3ec6SMatthias Ringwald 2643deb3ec6SMatthias Ringwald /* API_START */ 2653deb3ec6SMatthias Ringwald 266d25c33e5SMatthias Ringwald typedef struct { 2673deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2683deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2693deb3ec6SMatthias Ringwald uint16_t uuid16; 2703deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 271d25c33e5SMatthias Ringwald } gatt_client_service_t; 2723deb3ec6SMatthias Ringwald 273d25c33e5SMatthias Ringwald typedef struct { 2743deb3ec6SMatthias Ringwald uint16_t start_handle; 2753deb3ec6SMatthias Ringwald uint16_t value_handle; 2763deb3ec6SMatthias Ringwald uint16_t end_handle; 2773deb3ec6SMatthias Ringwald uint16_t properties; 2783deb3ec6SMatthias Ringwald uint16_t uuid16; 2793deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 280d25c33e5SMatthias Ringwald } gatt_client_characteristic_t; 2813deb3ec6SMatthias Ringwald 282d25c33e5SMatthias Ringwald typedef struct { 2833deb3ec6SMatthias Ringwald uint16_t handle; 2843deb3ec6SMatthias Ringwald uint16_t uuid16; 2853deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 286d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t; 2873deb3ec6SMatthias Ringwald 2883deb3ec6SMatthias Ringwald /** 2893deb3ec6SMatthias Ringwald * @brief Set up GATT client. 2903deb3ec6SMatthias Ringwald */ 2913deb3ec6SMatthias Ringwald void gatt_client_init(void); 2923deb3ec6SMatthias Ringwald 2933deb3ec6SMatthias Ringwald /** 29411279da7SMatthias Ringwald * @brief Set minimum required security level for GATT Client 29511279da7SMatthias Ringwald * @note The Bluetooth specification makes the GATT Server responsible to check for security. 296b11289a8SMatthias Ringwald * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. 297b11289a8SMatthias Ringwald * If your application is exchanging sensitive data with a remote device, you would need to manually check 298b11289a8SMatthias Ringwald * the security level before sending/receive such data. 299b11289a8SMatthias Ringwald * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange 300b11289a8SMatthias Ringwald * until the required security level is established. 301b11289a8SMatthias Ringwald * gatt_client_request_can_write_without_response_event does not trigger authentication 30259d34cd2SMatthias Ringwald * gatt_client_request_to_write_without_response does not trigger authentication 30311279da7SMatthias Ringwald * @pram level, default LEVEL_0 (no encryption required) 30411279da7SMatthias Ringwald */ 30511279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level); 30611279da7SMatthias Ringwald 30711279da7SMatthias Ringwald /** 3081450cdc6SMatthias Ringwald * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection 309effecf77SMatthias Ringwald * GATT_EVENT_CONNECTED with status and con_handle for other API functions 310effecf77SMatthias Ringwald * is emitted on connection complete. 311effecf77SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC. 3121450cdc6SMatthias Ringwald * @param addr 3131450cdc6SMatthias Ringwald * @return status 3141450cdc6SMatthias Ringwald */ 3151450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); 3161450cdc6SMatthias Ringwald 3171450cdc6SMatthias Ringwald /** 3181450cdc6SMatthias Ringwald * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server 3191450cdc6SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC 320effecf77SMatthias Ringwald * @param con_handle 3211450cdc6SMatthias Ringwald * @return status 3221450cdc6SMatthias Ringwald */ 3231450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3241450cdc6SMatthias Ringwald 3251450cdc6SMatthias Ringwald /** 3267627a0deSMatthias Ringwald * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection 3277627a0deSMatthias Ringwald * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events 32826166ecfSMatthias Ringwald * @param con_handle 32926166ecfSMatthias Ringwald * @param num_channels 3307627a0deSMatthias Ringwald * @param storage_buffer for L2CAP connection 3318540586aSMatthias Ringwald * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes 33226166ecfSMatthias Ringwald * @return 33326166ecfSMatthias Ringwald */ 33426166ecfSMatthias 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); 33526166ecfSMatthias Ringwald 33626166ecfSMatthias Ringwald /** 33779188ed7SMilanka Ringwald * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, 33879188ed7SMilanka Ringwald * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). 3396da84376SMilanka Ringwald * @param con_handle 3406da84376SMilanka Ringwald * @param mtu 34140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 34240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 343692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled 344692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 3453deb3ec6SMatthias Ringwald */ 346fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); 3473deb3ec6SMatthias Ringwald 3483deb3ec6SMatthias Ringwald /** 34979188ed7SMilanka Ringwald * @brief Sets whether a MTU Exchange Request shall be automatically send before the 35079188ed7SMilanka Ringwald * first attribute read request is send. Default is enabled. 3516da84376SMilanka Ringwald * @param enabled 3525cf6c434SJakob Krantz */ 3535cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); 3545cf6c434SJakob Krantz 3555cf6c434SJakob Krantz /** 35679188ed7SMilanka Ringwald * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU 35779188ed7SMilanka Ringwald * when gatt_client_mtu_enable_auto_negotiation is disabled. 3586da84376SMilanka Ringwald * @param callback 3596da84376SMilanka Ringwald * @param con_handle 3605cf6c434SJakob Krantz */ 3615cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3625cf6c434SJakob Krantz 3635cf6c434SJakob Krantz /** 364aacf1b1aSMilanka Ringwald * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. 3656da84376SMilanka Ringwald * @param con_handle 366692bf1adSMilanka Ringwald * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 3673deb3ec6SMatthias Ringwald */ 368fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle); 3693deb3ec6SMatthias Ringwald 3703deb3ec6SMatthias Ringwald /** 37179188ed7SMilanka Ringwald * @brief Discovers all primary services. 37279188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 37379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3746da84376SMilanka Ringwald * @param callback 3756da84376SMilanka Ringwald * @param con_handle 376692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 377692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 378692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 3793deb3ec6SMatthias Ringwald */ 380711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3813deb3ec6SMatthias Ringwald 3823deb3ec6SMatthias Ringwald /** 38379188ed7SMilanka Ringwald * @brief Discovers all secondary services. 38479188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 38579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3868d1f34d3SMatheus Eduardo Garbelini * @param callback 3878d1f34d3SMatheus Eduardo Garbelini * @param con_handle 3888d1f34d3SMatheus Eduardo Garbelini * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 3898d1f34d3SMatheus Eduardo Garbelini * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 3908d1f34d3SMatheus Eduardo Garbelini * ERROR_CODE_SUCCESS , if query is successfully registered 3918d1f34d3SMatheus Eduardo Garbelini */ 3928d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3938d1f34d3SMatheus Eduardo Garbelini 3948d1f34d3SMatheus Eduardo Garbelini /** 39579188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 39679188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 39779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3986da84376SMilanka Ringwald * @param callback 3996da84376SMilanka Ringwald * @param con_handle 4006da84376SMilanka Ringwald * @param uuid16 401692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 402692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 403692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4043deb3ec6SMatthias Ringwald */ 405711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); 4066da84376SMilanka Ringwald 4076da84376SMilanka Ringwald /** 40879188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 40979188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 41079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4116da84376SMilanka Ringwald * @param callback 4126da84376SMilanka Ringwald * @param con_handle 4136da84376SMilanka Ringwald * @param uuid128 414692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 415692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 416692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4176da84376SMilanka Ringwald */ 4186da84376SMilanka 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); 4193deb3ec6SMatthias Ringwald 4203deb3ec6SMatthias Ringwald /** 42179188ed7SMilanka Ringwald * @brief Finds included services within the specified service. 42279188ed7SMilanka Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 42379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 42479188ed7SMilanka Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 42579188ed7SMilanka Ringwald * an ATT find information request for the returned start group handle 42679188ed7SMilanka Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 42779188ed7SMilanka Ringwald * to the list of all primary services. 4286da84376SMilanka Ringwald * @param callback 4296da84376SMilanka Ringwald * @param con_handle 4306da84376SMilanka Ringwald * @param service 431692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 432692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 433692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4343deb3ec6SMatthias Ringwald */ 435711e6c80SMatthias Ringwald uint8_t gatt_client_find_included_services_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service); 4363deb3ec6SMatthias Ringwald 4373deb3ec6SMatthias Ringwald /** 43879188ed7SMilanka Ringwald * @brief Discovers all characteristics within the specified service. 43979188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 44079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4416da84376SMilanka Ringwald * @param callback 4426da84376SMilanka Ringwald * @param con_handle 4436da84376SMilanka Ringwald * @param service 444692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 445692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 446692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4473deb3ec6SMatthias Ringwald */ 448711e6c80SMatthias 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); 4493deb3ec6SMatthias Ringwald 4503deb3ec6SMatthias Ringwald /** 45179188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within 45279188ed7SMilanka Ringwald * the specified service or handle range, and return those that match the given UUID. 45379188ed7SMilanka Ringwald * 45479188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 45579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4566da84376SMilanka Ringwald * @param callback 4576da84376SMilanka Ringwald * @param con_handle 4586da84376SMilanka Ringwald * @param start_handle 4596da84376SMilanka Ringwald * @param end_handle 4606da84376SMilanka Ringwald * @param uuid16 461692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 462692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 463692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4643deb3ec6SMatthias Ringwald */ 465711e6c80SMatthias Ringwald uint8_t gatt_client_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); 4666da84376SMilanka Ringwald 4676da84376SMilanka Ringwald /** 46879188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 46979188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 47079188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 47179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4726da84376SMilanka Ringwald * @param callback 4736da84376SMilanka Ringwald * @param con_handle 4746da84376SMilanka Ringwald * @param start_handle 4756da84376SMilanka Ringwald * @param end_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 */ 481045d700dSDavid 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); 4826da84376SMilanka Ringwald 4836da84376SMilanka Ringwald /** 48479188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 48579188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 48679188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 48779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4886da84376SMilanka Ringwald * @param callback 4896da84376SMilanka Ringwald * @param con_handle 4906da84376SMilanka Ringwald * @param service 4916da84376SMilanka Ringwald * @param uuid16 492692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 493692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 494692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4956da84376SMilanka Ringwald */ 496711e6c80SMatthias 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); 4976da84376SMilanka Ringwald 4986da84376SMilanka Ringwald /** 49979188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 50079188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 50179188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 50279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5036da84376SMilanka Ringwald * @param callback 5046da84376SMilanka Ringwald * @param con_handle 5056da84376SMilanka Ringwald * @param service 5066da84376SMilanka Ringwald * @param uuid128 507692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 508692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 509692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5106da84376SMilanka Ringwald */ 511045d700dSDavid Lechner uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service, const uint8_t * uuid128); 5123deb3ec6SMatthias Ringwald 5133deb3ec6SMatthias Ringwald /** 51479188ed7SMilanka Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 51579188ed7SMilanka Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 51679188ed7SMilanka Ringwald * 51779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5186da84376SMilanka Ringwald * @param callback 5196da84376SMilanka Ringwald * @param con_handle 5206da84376SMilanka Ringwald * @param characteristic 521692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 522692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 523692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5243deb3ec6SMatthias Ringwald */ 525711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 5263deb3ec6SMatthias Ringwald 5273deb3ec6SMatthias Ringwald /** 52879188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 52979188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 53079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5316da84376SMilanka Ringwald * @param callback 5326da84376SMilanka Ringwald * @param con_handle 5336da84376SMilanka Ringwald * @param characteristic 534692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 535692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 536692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5373deb3ec6SMatthias Ringwald */ 538711e6c80SMatthias 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); 5396da84376SMilanka Ringwald 5406da84376SMilanka Ringwald /** 54179188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 54279188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 54379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5446da84376SMilanka Ringwald * @param callback 5456da84376SMilanka Ringwald * @param con_handle 546b45b7749SMilanka Ringwald * @param value_handle 547692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 548692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 549692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5506da84376SMilanka Ringwald */ 551b45b7749SMilanka 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); 5523deb3ec6SMatthias Ringwald 5533deb3ec6SMatthias Ringwald /** 55479188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 55579188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 55679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5576da84376SMilanka Ringwald * @param callback 5586da84376SMilanka Ringwald * @param con_handle 5596da84376SMilanka Ringwald * @param start_handle 5606da84376SMilanka Ringwald * @param end_handle 5616da84376SMilanka Ringwald * @param uuid16 562692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 563692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 564692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5653deb3ec6SMatthias Ringwald */ 566711e6c80SMatthias 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); 5676da84376SMilanka Ringwald 5686da84376SMilanka Ringwald /** 56979188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 57079188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 57179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5726da84376SMilanka Ringwald * @param callback 5736da84376SMilanka Ringwald * @param con_handle 5746da84376SMilanka Ringwald * @param start_handle 5756da84376SMilanka Ringwald * @param end_handle 5766da84376SMilanka Ringwald * @param uuid128 577692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 578692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 579692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5806da84376SMilanka Ringwald */ 581045d700dSDavid 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); 5823deb3ec6SMatthias Ringwald 5833deb3ec6SMatthias Ringwald /** 58479188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 58579188ed7SMilanka Ringwald * The value will be returned in several blobs. 58679188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 58779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5886da84376SMilanka Ringwald * @param callback 5896da84376SMilanka Ringwald * @param con_handle 5906da84376SMilanka Ringwald * @param characteristic 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 5943deb3ec6SMatthias Ringwald */ 595711e6c80SMatthias 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); 5966da84376SMilanka Ringwald 5976da84376SMilanka Ringwald /** 59879188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 59979188ed7SMilanka Ringwald * The value will be returned in several blobs. 60079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 60179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6026da84376SMilanka Ringwald * @param callback 6036da84376SMilanka Ringwald * @param con_handle 604b45b7749SMilanka Ringwald * @param value_handle 605692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 606692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 607692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6086da84376SMilanka Ringwald */ 609b45b7749SMilanka 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); 6106da84376SMilanka Ringwald 6116da84376SMilanka Ringwald /** 61279188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 61379188ed7SMilanka Ringwald * The value will be returned in several blobs. 61479188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 61579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6166da84376SMilanka Ringwald * @param callback 6176da84376SMilanka Ringwald * @param con_handle 618b45b7749SMilanka Ringwald * @param value_handle 6196da84376SMilanka Ringwald * @param offset 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 6236da84376SMilanka Ringwald */ 624b45b7749SMilanka 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); 6253deb3ec6SMatthias Ringwald 6263deb3ec6SMatthias Ringwald /* 62779188ed7SMilanka Ringwald * @brief Read multiple characteristic values. 62879188ed7SMilanka Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 62979188ed7SMilanka Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 6306da84376SMilanka Ringwald * @param callback 6316da84376SMilanka Ringwald * @param con_handle 6326da84376SMilanka Ringwald * @param num_value_handles 6336da84376SMilanka Ringwald * @param value_handles list of handles 63479188ed7SMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 63579188ed7SMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 63679188ed7SMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6373deb3ec6SMatthias Ringwald */ 638711e6c80SMatthias 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); 6393deb3ec6SMatthias Ringwald 640f125a8efSMatthias Ringwald /* 641f125a8efSMatthias Ringwald * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer 642f125a8efSMatthias Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 643f125a8efSMatthias Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 644f125a8efSMatthias Ringwald * @param callback 645f125a8efSMatthias Ringwald * @param con_handle 646f125a8efSMatthias Ringwald * @param num_value_handles 647f125a8efSMatthias Ringwald * @param value_handles list of handles 648f125a8efSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 649f125a8efSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 650f125a8efSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 651f125a8efSMatthias Ringwald */ 652f125a8efSMatthias 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); 653f125a8efSMatthias Ringwald 6543deb3ec6SMatthias Ringwald /** 65579188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle without 65679188ed7SMilanka Ringwald * an acknowledgment that the write was successfully performed. 6576da84376SMilanka Ringwald * @param con_handle 658b45b7749SMilanka Ringwald * @param value_handle 659b45b7749SMilanka Ringwald * @param value_length 6607e6f0853SDavid Lechner * @param value is copied on success and does not need to be retained 661692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 662692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 663692bf1adSMilanka Ringwald * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots 664692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6653deb3ec6SMatthias Ringwald */ 666b45b7749SMilanka 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); 6673deb3ec6SMatthias Ringwald 6683deb3ec6SMatthias Ringwald /** 66979188ed7SMilanka Ringwald * @brief Writes the authenticated characteristic value using the characteristic's value handle 67079188ed7SMilanka Ringwald * without an acknowledgment that the write was successfully performed. 67179188ed7SMilanka Ringwald * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, 67279188ed7SMilanka Ringwald * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. 6736da84376SMilanka Ringwald * @param callback 6746da84376SMilanka Ringwald * @param con_handle 6756da84376SMilanka Ringwald * @param value_handle 6766da84376SMilanka Ringwald * @param message_len 6776da84376SMilanka Ringwald * @param message is not copied, make sure memory is accessible until write is done 67840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 67940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 680692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 681692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 6823deb3ec6SMatthias Ringwald */ 6836da84376SMilanka 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); 6843deb3ec6SMatthias Ringwald 6853deb3ec6SMatthias Ringwald /** 686b2468039SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 687b2468039SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 688b2468039SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to 689b2468039SMilanka Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 6906da84376SMilanka Ringwald * @param callback 6916da84376SMilanka Ringwald * @param con_handle 692b45b7749SMilanka Ringwald * @param value_handle 693b45b7749SMilanka Ringwald * @param value_length 694b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 69540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 69640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 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 */ 700b45b7749SMilanka 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); 7016da84376SMilanka Ringwald 7026da84376SMilanka Ringwald /** 70379188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 70479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 70579188ed7SMilanka 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). 7066da84376SMilanka Ringwald * @param callback 7076da84376SMilanka Ringwald * @param con_handle 708b45b7749SMilanka Ringwald * @param value_handle 709b45b7749SMilanka Ringwald * @param value_length 710b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 71140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 71240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 713692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 714692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7156da84376SMilanka Ringwald */ 716b45b7749SMilanka 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); 7176da84376SMilanka Ringwald 7186da84376SMilanka Ringwald /** 71979188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 72079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 72179188ed7SMilanka 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). 7226da84376SMilanka Ringwald * @param callback 7236da84376SMilanka Ringwald * @param con_handle 724b45b7749SMilanka Ringwald * @param value_handle 7256da84376SMilanka Ringwald * @param offset of value 726b45b7749SMilanka Ringwald * @param value_length 727b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 72840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 72940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 730692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 731692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7326da84376SMilanka Ringwald */ 733b45b7749SMilanka 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); 7343deb3ec6SMatthias Ringwald 7353deb3ec6SMatthias Ringwald /** 73679188ed7SMilanka Ringwald * @brief Writes of the long characteristic value using the characteristic's value handle. 73779188ed7SMilanka Ringwald * It uses server response to validate that the write was correctly received. 73879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. 73979188ed7SMilanka 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). 7406da84376SMilanka Ringwald * @param callback 7416da84376SMilanka Ringwald * @param con_handle 742b45b7749SMilanka Ringwald * @param value_handle 743b45b7749SMilanka Ringwald * @param value_length 744b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 74540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 74640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 747692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 748692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7493deb3ec6SMatthias Ringwald */ 750b45b7749SMilanka 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); 7513deb3ec6SMatthias Ringwald 7523deb3ec6SMatthias Ringwald /** 75379188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 75479188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 75579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7566da84376SMilanka Ringwald * @param callback 7576da84376SMilanka Ringwald * @param con_handle 7586da84376SMilanka Ringwald * @param descriptor 75940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 76040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 761692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 762692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7633deb3ec6SMatthias Ringwald */ 764711e6c80SMatthias 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); 7656da84376SMilanka Ringwald 7666da84376SMilanka Ringwald /** 76779188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 76879188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 76979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7706da84376SMilanka Ringwald * @param callback 7716da84376SMilanka Ringwald * @param con_handle 7726da84376SMilanka Ringwald * @param descriptor 77340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 77440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 775692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 776692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7776da84376SMilanka Ringwald */ 778711e6c80SMatthias 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); 7793deb3ec6SMatthias Ringwald 7803deb3ec6SMatthias Ringwald /** 78179188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 78279188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 78379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7846da84376SMilanka Ringwald * @param callback 7856da84376SMilanka Ringwald * @param con_handle 786b45b7749SMilanka Ringwald * @param descriptor 78740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 78840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 789692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 790692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7913deb3ec6SMatthias Ringwald */ 792711e6c80SMatthias 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); 7936da84376SMilanka Ringwald 7946da84376SMilanka Ringwald /** 79579188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 79679188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 79779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7986da84376SMilanka Ringwald * @param callback 7996da84376SMilanka Ringwald * @param con_handle 8006da84376SMilanka Ringwald * @param descriptor_handle 80140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 80240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 803692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 804692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8056da84376SMilanka Ringwald */ 806711e6c80SMatthias 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); 8076da84376SMilanka Ringwald 8086da84376SMilanka Ringwald /** 80979188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 81079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 81179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 8126da84376SMilanka Ringwald * @param callback 8136da84376SMilanka Ringwald * @param con_handle 8146da84376SMilanka Ringwald * @param descriptor_handle 8156da84376SMilanka Ringwald * @param offset 81640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 81740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 818692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 819692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8206da84376SMilanka Ringwald */ 821711e6c80SMatthias 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); 8223deb3ec6SMatthias Ringwald 8233deb3ec6SMatthias Ringwald /** 82479188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 82579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 82679188ed7SMilanka 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). 8276da84376SMilanka Ringwald * @param callback 8286da84376SMilanka Ringwald * @param con_handle 8296da84376SMilanka Ringwald * @param descriptor 830b45b7749SMilanka Ringwald * @param value_length 831b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 83240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 83340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 834692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 835692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8363deb3ec6SMatthias Ringwald */ 837b45b7749SMilanka 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); 8386da84376SMilanka Ringwald 8396da84376SMilanka Ringwald /** 84079188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 84179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 84279188ed7SMilanka 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). 8436da84376SMilanka Ringwald * @param callback 8446da84376SMilanka Ringwald * @param con_handle 8456da84376SMilanka Ringwald * @param descriptor_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 8526da84376SMilanka Ringwald */ 853b45b7749SMilanka 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); 8546da84376SMilanka Ringwald 8556da84376SMilanka Ringwald /** 85679188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 85779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 85879188ed7SMilanka 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). 8596da84376SMilanka Ringwald * @param callback 8606da84376SMilanka Ringwald * @param con_handle 8616da84376SMilanka Ringwald * @param descriptor 862b45b7749SMilanka Ringwald * @param value_length 863b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 86440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 86540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 866692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 867692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8686da84376SMilanka Ringwald */ 869b45b7749SMilanka 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); 8706da84376SMilanka Ringwald 8716da84376SMilanka Ringwald /** 87279188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 87379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 87479188ed7SMilanka 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). 8756da84376SMilanka Ringwald * @param callback 8766da84376SMilanka Ringwald * @param con_handle 8776da84376SMilanka Ringwald * @param descriptor_handle 878b45b7749SMilanka Ringwald * @param value_length 879b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 88040faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 88140faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 882692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 883692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8846da84376SMilanka Ringwald */ 885b45b7749SMilanka 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); 8866da84376SMilanka Ringwald 8876da84376SMilanka Ringwald /** 88879188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 88979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 89079188ed7SMilanka 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). 8916da84376SMilanka Ringwald * @param callback 8926da84376SMilanka Ringwald * @param con_handle 8936da84376SMilanka Ringwald * @param descriptor_handle 8946da84376SMilanka Ringwald * @param offset of value 895b45b7749SMilanka Ringwald * @param value_length 896b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 89740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 89840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 899692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 900692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9016da84376SMilanka Ringwald */ 902b45b7749SMilanka 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); 9033deb3ec6SMatthias Ringwald 9043deb3ec6SMatthias Ringwald /** 90579188ed7SMilanka Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 90679188ed7SMilanka Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 90779188ed7SMilanka Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 90879188ed7SMilanka Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 90979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 91079188ed7SMilanka 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). 9116da84376SMilanka Ringwald * @param callback 9126da84376SMilanka Ringwald * @param con_handle 9136da84376SMilanka Ringwald * @param characteristic 914b7e5512fSMilanka Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 91540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 91640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 917692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 918b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 919b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 9206b04f675SMilanka Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 921b7e5512fSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9223deb3ec6SMatthias Ringwald */ 923711e6c80SMatthias 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); 9249c662c9bSMatthias Ringwald 9259c662c9bSMatthias Ringwald /** 92679188ed7SMilanka Ringwald * @brief Register for notifications and indications of a characteristic enabled by 92779188ed7SMilanka Ringwald * the gatt_client_write_client_characteristic_configuration function. 9289c662c9bSMatthias Ringwald * @param notification struct used to store registration 9296da84376SMilanka Ringwald * @param callback 930b3f03c84SMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 931b3f03c84SMatthias Ringwald * @param characteristic or NULL to receive updates for all characteristics 9329c662c9bSMatthias Ringwald */ 9336da84376SMilanka 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); 9343deb3ec6SMatthias Ringwald 9353deb3ec6SMatthias Ringwald /** 93679188ed7SMilanka Ringwald * @brief Stop listening to characteristic value updates registered with 93779188ed7SMilanka Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 9381f734b5fSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 9391f734b5fSMatthias Ringwald */ 9401f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); 9411f734b5fSMatthias Ringwald 9421f734b5fSMatthias Ringwald /** 94379188ed7SMilanka Ringwald * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. 94479188ed7SMilanka Ringwald * Call the gatt_client_execute_write function to commit the transaction. 9456da84376SMilanka Ringwald * @param callback 9466da84376SMilanka Ringwald * @param con_handle 9476da84376SMilanka Ringwald * @param attribute_handle 9486da84376SMilanka Ringwald * @param offset of value 949b45b7749SMilanka Ringwald * @param value_length 950b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 9513deb3ec6SMatthias Ringwald */ 952b45b7749SMilanka 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); 9533deb3ec6SMatthias Ringwald 9543deb3ec6SMatthias Ringwald /** 9556da84376SMilanka Ringwald * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9566da84376SMilanka Ringwald * @param callback 9576da84376SMilanka Ringwald * @param con_handle 95840faeb84SMilanka Ringwald * @return status 9593deb3ec6SMatthias Ringwald */ 960711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9613deb3ec6SMatthias Ringwald 9623deb3ec6SMatthias Ringwald /** 9636da84376SMilanka Ringwald * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9646da84376SMilanka Ringwald * @param callback 9656da84376SMilanka Ringwald * @param con_handle 96640faeb84SMilanka Ringwald * @return status 9673deb3ec6SMatthias Ringwald */ 968711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9693deb3ec6SMatthias Ringwald 97059d34cd2SMatthias Ringwald /** 97153e9c18fSMatthias Ringwald * @brief Request callback when regular gatt query can be sent 97253e9c18fSMatthias Ringwald * @note callback might happen during call to this function 97353e9c18fSMatthias Ringwald * @param callback_registration to point to callback function and context information 97453e9c18fSMatthias Ringwald * @param con_handle 97553e9c18fSMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 97653e9c18fSMatthias Ringwald */ 97753e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 97853e9c18fSMatthias Ringwald 97953e9c18fSMatthias Ringwald /** 98059d34cd2SMatthias Ringwald * @brief Request callback when writing characteristic value without response is possible 98153e9c18fSMatthias Ringwald * @note callback might happen during call to this function 98259d34cd2SMatthias Ringwald * @param callback_registration to point to callback function and context information 98359d34cd2SMatthias Ringwald * @param con_handle 98459d34cd2SMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 98559d34cd2SMatthias Ringwald */ 98659d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 98759d34cd2SMatthias Ringwald 98859d34cd2SMatthias Ringwald 98959d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually 99059d34cd2SMatthias Ringwald /** 99159d34cd2SMatthias Ringwald * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees 99259d34cd2SMatthias Ringwald * a single successful gatt_client_write_value_of_characteristic_without_response call. 99359d34cd2SMatthias Ringwald * @deprecated please use gatt_client_request_to_write_without_response instead 99459d34cd2SMatthias Ringwald * @param callback 99559d34cd2SMatthias Ringwald * @param con_handle 99659d34cd2SMatthias Ringwald * @return status 99759d34cd2SMatthias Ringwald */ 99859d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 99959d34cd2SMatthias Ringwald 100059d34cd2SMatthias Ringwald 10013deb3ec6SMatthias Ringwald /* API_END */ 10023deb3ec6SMatthias Ringwald 10036ba2ad22SMatthias Ringwald // used by generated btstack_event.c 10046ba2ad22SMatthias Ringwald 1005313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); 1006313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); 1007313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); 10086ba2ad22SMatthias Ringwald 1009a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 1010a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); 101140faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client); 1012a6121b51SMilanka Ringwald #endif 1013a6121b51SMilanka Ringwald 10143deb3ec6SMatthias Ringwald #if defined __cplusplus 10153deb3ec6SMatthias Ringwald } 10163deb3ec6SMatthias Ringwald #endif 10173deb3ec6SMatthias Ringwald 10183deb3ec6SMatthias Ringwald #endif 1019