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 843deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, 853deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, 863deb3ec6SMatthias Ringwald 873deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE, 883deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_RESULT, 893deb3ec6SMatthias Ringwald P_W2_PREPARE_RELIABLE_WRITE, 903deb3ec6SMatthias Ringwald P_W4_PREPARE_RELIABLE_WRITE_RESULT, 913deb3ec6SMatthias Ringwald 923deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE, 933deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_RESULT, 943deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE, 953deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_RESULT, 963deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, 973deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, 983deb3ec6SMatthias Ringwald 99abdc9fb5SMatthias Ringwald #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY 100abdc9fb5SMatthias Ringwald P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 101abdc9fb5SMatthias Ringwald P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 102abdc9fb5SMatthias Ringwald #else 1033deb3ec6SMatthias Ringwald P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 1043deb3ec6SMatthias Ringwald P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 105abdc9fb5SMatthias Ringwald #endif 1063deb3ec6SMatthias Ringwald P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, 1073deb3ec6SMatthias Ringwald P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, 1083deb3ec6SMatthias Ringwald 1093deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY, 1103deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, 1113deb3ec6SMatthias Ringwald 1123deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, 1133deb3ec6SMatthias Ringwald P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, 1143deb3ec6SMatthias Ringwald 1153deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR, 1163deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1173deb3ec6SMatthias Ringwald 1183deb3ec6SMatthias Ringwald // all long writes use this 1193deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, 1203deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1213deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, 1223deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1233deb3ec6SMatthias Ringwald 1243deb3ec6SMatthias Ringwald // gatt reliable write API use this (manual version of the above) 1253deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_SINGLE, 1263deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_SINGLE_RESULT, 1273deb3ec6SMatthias Ringwald 128793cf6ceSMatthias Ringwald P_W4_IDENTITY_RESOLVING, 1293deb3ec6SMatthias Ringwald P_W4_CMAC_READY, 1303deb3ec6SMatthias Ringwald P_W4_CMAC_RESULT, 1313deb3ec6SMatthias Ringwald P_W2_SEND_SIGNED_WRITE, 1323deb3ec6SMatthias Ringwald P_W4_SEND_SINGED_WRITE_DONE, 1331450cdc6SMatthias Ringwald 1341450cdc6SMatthias Ringwald P_W2_SDP_QUERY, 1351450cdc6SMatthias Ringwald P_W4_SDP_QUERY, 1361450cdc6SMatthias Ringwald P_W4_L2CAP_CONNECTION, 1373deb3ec6SMatthias Ringwald } gatt_client_state_t; 1383deb3ec6SMatthias Ringwald 1393deb3ec6SMatthias Ringwald 1403deb3ec6SMatthias Ringwald typedef enum{ 1413deb3ec6SMatthias Ringwald SEND_MTU_EXCHANGE, 1423deb3ec6SMatthias Ringwald SENT_MTU_EXCHANGE, 1435cf6c434SJakob Krantz MTU_EXCHANGED, 1445cf6c434SJakob Krantz MTU_AUTO_EXCHANGE_DISABLED 1453deb3ec6SMatthias Ringwald } gatt_client_mtu_t; 1463deb3ec6SMatthias Ringwald 147cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 148cbd76cecSMatthias Ringwald typedef enum { 149cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_IDLE, 150*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND, 151*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_VALUE, 152*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE, 153*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND, 154*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_CHARACTERISTIC, 155*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE, 156*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND, 157*26166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE, 158cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_READY, 159cbd76cecSMatthias Ringwald } gatt_client_eatt_state_t; 160cbd76cecSMatthias Ringwald #endif 161cbd76cecSMatthias Ringwald 1623deb3ec6SMatthias Ringwald typedef struct gatt_client{ 163665d90f2SMatthias Ringwald btstack_linked_item_t item; 1643deb3ec6SMatthias Ringwald // TODO: rename gatt_client_state -> state 1653deb3ec6SMatthias Ringwald gatt_client_state_t gatt_client_state; 1663deb3ec6SMatthias Ringwald 1679c662c9bSMatthias Ringwald // user callback 1689c662c9bSMatthias Ringwald btstack_packet_handler_t callback; 1693deb3ec6SMatthias Ringwald 17047181045SMatthias Ringwald // can write without response callback 17147181045SMatthias Ringwald btstack_packet_handler_t write_without_response_callback; 17247181045SMatthias Ringwald 17359d34cd2SMatthias Ringwald // can write without response requests 17459d34cd2SMatthias Ringwald btstack_linked_list_t write_without_response_requests; 17559d34cd2SMatthias Ringwald 17653e9c18fSMatthias Ringwald // regular gatt query requests 17753e9c18fSMatthias Ringwald btstack_linked_list_t query_requests; 17853e9c18fSMatthias Ringwald 179fc64f94aSMatthias Ringwald hci_con_handle_t con_handle; 180f4b33574SMatthias Ringwald 181e9cdf30bSMatthias Ringwald att_bearer_type_t bearer_type; 182e9cdf30bSMatthias Ringwald 1831450cdc6SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 1841450cdc6SMatthias Ringwald bd_addr_t addr; 1851450cdc6SMatthias Ringwald uint16_t l2cap_psm; 1861450cdc6SMatthias Ringwald uint16_t l2cap_cid; 1871450cdc6SMatthias Ringwald btstack_context_callback_registration_t sdp_query_request; 1881450cdc6SMatthias Ringwald #endif 1891450cdc6SMatthias Ringwald 190cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 191cbd76cecSMatthias Ringwald gatt_client_eatt_state_t eatt_state; 192cbd76cecSMatthias Ringwald uint16_t gatt_client_supported_features_handle; 193cbd76cecSMatthias Ringwald #endif 194cbd76cecSMatthias Ringwald 1953deb3ec6SMatthias Ringwald uint16_t mtu; 1963deb3ec6SMatthias Ringwald gatt_client_mtu_t mtu_state; 1973deb3ec6SMatthias Ringwald 1983deb3ec6SMatthias Ringwald uint16_t uuid16; 1993deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 2003deb3ec6SMatthias Ringwald 2013deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2023deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2033deb3ec6SMatthias Ringwald 2043deb3ec6SMatthias Ringwald uint16_t query_start_handle; 2053deb3ec6SMatthias Ringwald uint16_t query_end_handle; 2063deb3ec6SMatthias Ringwald 2073deb3ec6SMatthias Ringwald uint8_t characteristic_properties; 2083deb3ec6SMatthias Ringwald uint16_t characteristic_start_handle; 2093deb3ec6SMatthias Ringwald 2103deb3ec6SMatthias Ringwald uint16_t attribute_handle; 2113deb3ec6SMatthias Ringwald uint16_t attribute_offset; 2123deb3ec6SMatthias Ringwald uint16_t attribute_length; 2133deb3ec6SMatthias Ringwald uint8_t* attribute_value; 2143deb3ec6SMatthias Ringwald 2153deb3ec6SMatthias Ringwald // read multiple characteristic values 2163deb3ec6SMatthias Ringwald uint16_t read_multiple_handle_count; 2173deb3ec6SMatthias Ringwald uint16_t * read_multiple_handles; 2183deb3ec6SMatthias Ringwald 2193deb3ec6SMatthias Ringwald uint16_t client_characteristic_configuration_handle; 2203deb3ec6SMatthias Ringwald uint8_t client_characteristic_configuration_value[2]; 2213deb3ec6SMatthias Ringwald 2223deb3ec6SMatthias Ringwald uint8_t filter_with_uuid; 2233deb3ec6SMatthias Ringwald uint8_t send_confirmation; 2243deb3ec6SMatthias Ringwald 2253deb3ec6SMatthias Ringwald int le_device_index; 2263deb3ec6SMatthias Ringwald uint8_t cmac[8]; 2273deb3ec6SMatthias Ringwald 228ec820d77SMatthias Ringwald btstack_timer_source_t gc_timeout; 229f4b33574SMatthias Ringwald 230f4b33574SMatthias Ringwald uint8_t security_counter; 2313503dc74SMatthias Ringwald uint8_t wait_for_authentication_complete; 232f4b33574SMatthias Ringwald uint8_t pending_error_code; 233f4b33574SMatthias Ringwald 2348918bbdaSMatthias Ringwald bool reencryption_active; 2358918bbdaSMatthias Ringwald uint8_t reencryption_result; 2368918bbdaSMatthias Ringwald 2371dfae9c7SMatthias Ringwald gap_security_level_t security_level; 2381dfae9c7SMatthias Ringwald 2393deb3ec6SMatthias Ringwald } gatt_client_t; 2403deb3ec6SMatthias Ringwald 2419c662c9bSMatthias Ringwald typedef struct gatt_client_notification { 242665d90f2SMatthias Ringwald btstack_linked_item_t item; 243b6e96f14SMatthias Ringwald btstack_packet_handler_t callback; 244711e6c80SMatthias Ringwald hci_con_handle_t con_handle; 2459c662c9bSMatthias Ringwald uint16_t attribute_handle; 2469c662c9bSMatthias Ringwald } gatt_client_notification_t; 2473deb3ec6SMatthias Ringwald 2483deb3ec6SMatthias Ringwald /* API_START */ 2493deb3ec6SMatthias Ringwald 250d25c33e5SMatthias Ringwald typedef struct { 2513deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2523deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2533deb3ec6SMatthias Ringwald uint16_t uuid16; 2543deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 255d25c33e5SMatthias Ringwald } gatt_client_service_t; 2563deb3ec6SMatthias Ringwald 257d25c33e5SMatthias Ringwald typedef struct { 2583deb3ec6SMatthias Ringwald uint16_t start_handle; 2593deb3ec6SMatthias Ringwald uint16_t value_handle; 2603deb3ec6SMatthias Ringwald uint16_t end_handle; 2613deb3ec6SMatthias Ringwald uint16_t properties; 2623deb3ec6SMatthias Ringwald uint16_t uuid16; 2633deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 264d25c33e5SMatthias Ringwald } gatt_client_characteristic_t; 2653deb3ec6SMatthias Ringwald 266d25c33e5SMatthias Ringwald typedef struct { 2673deb3ec6SMatthias Ringwald uint16_t handle; 2683deb3ec6SMatthias Ringwald uint16_t uuid16; 2693deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 270d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t; 2713deb3ec6SMatthias Ringwald 2723deb3ec6SMatthias Ringwald /** 2733deb3ec6SMatthias Ringwald * @brief Set up GATT client. 2743deb3ec6SMatthias Ringwald */ 2753deb3ec6SMatthias Ringwald void gatt_client_init(void); 2763deb3ec6SMatthias Ringwald 2773deb3ec6SMatthias Ringwald /** 27811279da7SMatthias Ringwald * @brief Set minimum required security level for GATT Client 27911279da7SMatthias Ringwald * @note The Bluetooth specification makes the GATT Server responsible to check for security. 280b11289a8SMatthias Ringwald * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. 281b11289a8SMatthias Ringwald * If your application is exchanging sensitive data with a remote device, you would need to manually check 282b11289a8SMatthias Ringwald * the security level before sending/receive such data. 283b11289a8SMatthias Ringwald * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange 284b11289a8SMatthias Ringwald * until the required security level is established. 285b11289a8SMatthias Ringwald * gatt_client_request_can_write_without_response_event does not trigger authentication 28659d34cd2SMatthias Ringwald * gatt_client_request_to_write_without_response does not trigger authentication 28711279da7SMatthias Ringwald * @pram level, default LEVEL_0 (no encryption required) 28811279da7SMatthias Ringwald */ 28911279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level); 29011279da7SMatthias Ringwald 29111279da7SMatthias Ringwald /** 2921450cdc6SMatthias Ringwald * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection 293effecf77SMatthias Ringwald * GATT_EVENT_CONNECTED with status and con_handle for other API functions 294effecf77SMatthias Ringwald * is emitted on connection complete. 295effecf77SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC. 2961450cdc6SMatthias Ringwald * @param addr 2971450cdc6SMatthias Ringwald * @return status 2981450cdc6SMatthias Ringwald */ 2991450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); 3001450cdc6SMatthias Ringwald 3011450cdc6SMatthias Ringwald /** 3021450cdc6SMatthias Ringwald * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server 3031450cdc6SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC 304effecf77SMatthias Ringwald * @param con_handle 3051450cdc6SMatthias Ringwald * @return status 3061450cdc6SMatthias Ringwald */ 3071450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3081450cdc6SMatthias Ringwald 3091450cdc6SMatthias Ringwald /** 310*26166ecfSMatthias Ringwald * 311*26166ecfSMatthias Ringwald * @param callback 312*26166ecfSMatthias Ringwald * @param con_handle 313*26166ecfSMatthias Ringwald * @param num_channels 314*26166ecfSMatthias Ringwald * @param storage_buffer 315*26166ecfSMatthias Ringwald * @param storage_size 316*26166ecfSMatthias Ringwald * @return 317*26166ecfSMatthias Ringwald */ 318*26166ecfSMatthias 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); 319*26166ecfSMatthias Ringwald 320*26166ecfSMatthias Ringwald /** 32179188ed7SMilanka Ringwald * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, 32279188ed7SMilanka Ringwald * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). 3236da84376SMilanka Ringwald * @param con_handle 3246da84376SMilanka Ringwald * @param mtu 32540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 32640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 327692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled 328692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 3293deb3ec6SMatthias Ringwald */ 330fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); 3313deb3ec6SMatthias Ringwald 3323deb3ec6SMatthias Ringwald /** 33379188ed7SMilanka Ringwald * @brief Sets whether a MTU Exchange Request shall be automatically send before the 33479188ed7SMilanka Ringwald * first attribute read request is send. Default is enabled. 3356da84376SMilanka Ringwald * @param enabled 3365cf6c434SJakob Krantz */ 3375cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); 3385cf6c434SJakob Krantz 3395cf6c434SJakob Krantz /** 34079188ed7SMilanka Ringwald * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU 34179188ed7SMilanka Ringwald * when gatt_client_mtu_enable_auto_negotiation is disabled. 3426da84376SMilanka Ringwald * @param callback 3436da84376SMilanka Ringwald * @param con_handle 3445cf6c434SJakob Krantz */ 3455cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3465cf6c434SJakob Krantz 3475cf6c434SJakob Krantz /** 348aacf1b1aSMilanka Ringwald * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. 3496da84376SMilanka Ringwald * @param con_handle 350692bf1adSMilanka Ringwald * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 3513deb3ec6SMatthias Ringwald */ 352fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle); 3533deb3ec6SMatthias Ringwald 3543deb3ec6SMatthias Ringwald /** 35579188ed7SMilanka Ringwald * @brief Discovers all primary services. 35679188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 35779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3586da84376SMilanka Ringwald * @param callback 3596da84376SMilanka Ringwald * @param con_handle 360692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 361692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 362692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 3633deb3ec6SMatthias Ringwald */ 364711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3653deb3ec6SMatthias Ringwald 3663deb3ec6SMatthias Ringwald /** 36779188ed7SMilanka Ringwald * @brief Discovers all secondary services. 36879188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 36979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3708d1f34d3SMatheus Eduardo Garbelini * @param callback 3718d1f34d3SMatheus Eduardo Garbelini * @param con_handle 3728d1f34d3SMatheus Eduardo Garbelini * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 3738d1f34d3SMatheus Eduardo Garbelini * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 3748d1f34d3SMatheus Eduardo Garbelini * ERROR_CODE_SUCCESS , if query is successfully registered 3758d1f34d3SMatheus Eduardo Garbelini */ 3768d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3778d1f34d3SMatheus Eduardo Garbelini 3788d1f34d3SMatheus Eduardo Garbelini /** 37979188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 38079188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 38179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3826da84376SMilanka Ringwald * @param callback 3836da84376SMilanka Ringwald * @param con_handle 3846da84376SMilanka Ringwald * @param uuid16 385692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 386692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 387692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 3883deb3ec6SMatthias Ringwald */ 389711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); 3906da84376SMilanka Ringwald 3916da84376SMilanka Ringwald /** 39279188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 39379188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 39479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 3956da84376SMilanka Ringwald * @param callback 3966da84376SMilanka Ringwald * @param con_handle 3976da84376SMilanka Ringwald * @param uuid128 398692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 399692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 400692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4016da84376SMilanka Ringwald */ 4026da84376SMilanka 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); 4033deb3ec6SMatthias Ringwald 4043deb3ec6SMatthias Ringwald /** 40579188ed7SMilanka Ringwald * @brief Finds included services within the specified service. 40679188ed7SMilanka Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 40779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 40879188ed7SMilanka Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 40979188ed7SMilanka Ringwald * an ATT find information request for the returned start group handle 41079188ed7SMilanka Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 41179188ed7SMilanka Ringwald * to the list of all primary services. 4126da84376SMilanka Ringwald * @param callback 4136da84376SMilanka Ringwald * @param con_handle 4146da84376SMilanka Ringwald * @param service 415692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 416692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 417692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4183deb3ec6SMatthias Ringwald */ 419711e6c80SMatthias 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); 4203deb3ec6SMatthias Ringwald 4213deb3ec6SMatthias Ringwald /** 42279188ed7SMilanka Ringwald * @brief Discovers all characteristics within the specified service. 42379188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 42479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4256da84376SMilanka Ringwald * @param callback 4266da84376SMilanka Ringwald * @param con_handle 4276da84376SMilanka Ringwald * @param service 428692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 429692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 430692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4313deb3ec6SMatthias Ringwald */ 432711e6c80SMatthias 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); 4333deb3ec6SMatthias Ringwald 4343deb3ec6SMatthias Ringwald /** 43579188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within 43679188ed7SMilanka Ringwald * the specified service or handle range, and return those that match the given UUID. 43779188ed7SMilanka Ringwald * 43879188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 43979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4406da84376SMilanka Ringwald * @param callback 4416da84376SMilanka Ringwald * @param con_handle 4426da84376SMilanka Ringwald * @param start_handle 4436da84376SMilanka Ringwald * @param end_handle 4446da84376SMilanka Ringwald * @param uuid16 445692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 446692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 447692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4483deb3ec6SMatthias Ringwald */ 449711e6c80SMatthias 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); 4506da84376SMilanka Ringwald 4516da84376SMilanka Ringwald /** 45279188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 45379188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 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 uuid128 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 4646da84376SMilanka Ringwald */ 465045d700dSDavid 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); 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 service 4756da84376SMilanka Ringwald * @param uuid16 476692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 477692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 478692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4796da84376SMilanka Ringwald */ 480711e6c80SMatthias 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); 4816da84376SMilanka Ringwald 4826da84376SMilanka Ringwald /** 48379188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 48479188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 48579188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 48679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4876da84376SMilanka Ringwald * @param callback 4886da84376SMilanka Ringwald * @param con_handle 4896da84376SMilanka Ringwald * @param service 4906da84376SMilanka Ringwald * @param uuid128 491692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 492692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 493692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4946da84376SMilanka Ringwald */ 495045d700dSDavid 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); 4963deb3ec6SMatthias Ringwald 4973deb3ec6SMatthias Ringwald /** 49879188ed7SMilanka Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 49979188ed7SMilanka Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 50079188ed7SMilanka Ringwald * 50179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5026da84376SMilanka Ringwald * @param callback 5036da84376SMilanka Ringwald * @param con_handle 5046da84376SMilanka Ringwald * @param characteristic 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 5083deb3ec6SMatthias Ringwald */ 509711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 5103deb3ec6SMatthias Ringwald 5113deb3ec6SMatthias Ringwald /** 51279188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 51379188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 51479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5156da84376SMilanka Ringwald * @param callback 5166da84376SMilanka Ringwald * @param con_handle 5176da84376SMilanka Ringwald * @param characteristic 518692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 519692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 520692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5213deb3ec6SMatthias Ringwald */ 522711e6c80SMatthias 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); 5236da84376SMilanka Ringwald 5246da84376SMilanka Ringwald /** 52579188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 52679188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 52779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5286da84376SMilanka Ringwald * @param callback 5296da84376SMilanka Ringwald * @param con_handle 530b45b7749SMilanka Ringwald * @param value_handle 531692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 532692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 533692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5346da84376SMilanka Ringwald */ 535b45b7749SMilanka 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); 5363deb3ec6SMatthias Ringwald 5373deb3ec6SMatthias Ringwald /** 53879188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 53979188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 54079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5416da84376SMilanka Ringwald * @param callback 5426da84376SMilanka Ringwald * @param con_handle 5436da84376SMilanka Ringwald * @param start_handle 5446da84376SMilanka Ringwald * @param end_handle 5456da84376SMilanka Ringwald * @param uuid16 546692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 547692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 548692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5493deb3ec6SMatthias Ringwald */ 550711e6c80SMatthias 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); 5516da84376SMilanka Ringwald 5526da84376SMilanka Ringwald /** 55379188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 55479188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 55579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 5566da84376SMilanka Ringwald * @param callback 5576da84376SMilanka Ringwald * @param con_handle 5586da84376SMilanka Ringwald * @param start_handle 5596da84376SMilanka Ringwald * @param end_handle 5606da84376SMilanka Ringwald * @param uuid128 561692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 562692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 563692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5646da84376SMilanka Ringwald */ 565045d700dSDavid 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); 5663deb3ec6SMatthias Ringwald 5673deb3ec6SMatthias Ringwald /** 56879188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 56979188ed7SMilanka Ringwald * The value will be returned in several blobs. 57079188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset 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 characteristic 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 5783deb3ec6SMatthias Ringwald */ 579711e6c80SMatthias 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); 5806da84376SMilanka Ringwald 5816da84376SMilanka 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 588b45b7749SMilanka Ringwald * @param value_handle 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 5926da84376SMilanka Ringwald */ 593b45b7749SMilanka 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); 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 6036da84376SMilanka Ringwald * @param offset 604692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 605692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 606692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6076da84376SMilanka Ringwald */ 608b45b7749SMilanka 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); 6093deb3ec6SMatthias Ringwald 6103deb3ec6SMatthias Ringwald /* 61179188ed7SMilanka Ringwald * @brief Read multiple characteristic values. 61279188ed7SMilanka Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 61379188ed7SMilanka Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 6146da84376SMilanka Ringwald * @param callback 6156da84376SMilanka Ringwald * @param con_handle 6166da84376SMilanka Ringwald * @param num_value_handles 6176da84376SMilanka Ringwald * @param value_handles list of handles 61879188ed7SMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 61979188ed7SMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 62079188ed7SMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6213deb3ec6SMatthias Ringwald */ 622711e6c80SMatthias 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); 6233deb3ec6SMatthias Ringwald 6243deb3ec6SMatthias Ringwald /** 62579188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle without 62679188ed7SMilanka Ringwald * an acknowledgment that the write was successfully performed. 6276da84376SMilanka Ringwald * @param con_handle 628b45b7749SMilanka Ringwald * @param value_handle 629b45b7749SMilanka Ringwald * @param value_length 6307e6f0853SDavid Lechner * @param value is copied on success and does not need to be retained 631692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 632692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 633692bf1adSMilanka Ringwald * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots 634692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6353deb3ec6SMatthias Ringwald */ 636b45b7749SMilanka 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); 6373deb3ec6SMatthias Ringwald 6383deb3ec6SMatthias Ringwald /** 63979188ed7SMilanka Ringwald * @brief Writes the authenticated characteristic value using the characteristic's value handle 64079188ed7SMilanka Ringwald * without an acknowledgment that the write was successfully performed. 64179188ed7SMilanka Ringwald * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, 64279188ed7SMilanka Ringwald * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. 6436da84376SMilanka Ringwald * @param callback 6446da84376SMilanka Ringwald * @param con_handle 6456da84376SMilanka Ringwald * @param value_handle 6466da84376SMilanka Ringwald * @param message_len 6476da84376SMilanka Ringwald * @param message is not copied, make sure memory is accessible until write is done 64840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 64940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 650692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 651692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 6523deb3ec6SMatthias Ringwald */ 6536da84376SMilanka 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); 6543deb3ec6SMatthias Ringwald 6553deb3ec6SMatthias Ringwald /** 656b2468039SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 657b2468039SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 658b2468039SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to 659b2468039SMilanka Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 6606da84376SMilanka Ringwald * @param callback 6616da84376SMilanka Ringwald * @param con_handle 662b45b7749SMilanka Ringwald * @param value_handle 663b45b7749SMilanka Ringwald * @param value_length 664b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 66540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 66640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 667692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 668692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 6693deb3ec6SMatthias Ringwald */ 670b45b7749SMilanka 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); 6716da84376SMilanka Ringwald 6726da84376SMilanka Ringwald /** 67379188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 67479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 67579188ed7SMilanka 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). 6766da84376SMilanka Ringwald * @param callback 6776da84376SMilanka Ringwald * @param con_handle 678b45b7749SMilanka Ringwald * @param value_handle 679b45b7749SMilanka Ringwald * @param value_length 680b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 68140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 68240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 683692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 684692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 6856da84376SMilanka Ringwald */ 686b45b7749SMilanka 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); 6876da84376SMilanka Ringwald 6886da84376SMilanka Ringwald /** 68979188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 69079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 69179188ed7SMilanka 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). 6926da84376SMilanka Ringwald * @param callback 6936da84376SMilanka Ringwald * @param con_handle 694b45b7749SMilanka Ringwald * @param value_handle 6956da84376SMilanka Ringwald * @param offset of value 696b45b7749SMilanka Ringwald * @param value_length 697b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 69840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 69940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 700692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 701692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7026da84376SMilanka Ringwald */ 703b45b7749SMilanka 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); 7043deb3ec6SMatthias Ringwald 7053deb3ec6SMatthias Ringwald /** 70679188ed7SMilanka Ringwald * @brief Writes of the long characteristic value using the characteristic's value handle. 70779188ed7SMilanka Ringwald * It uses server response to validate that the write was correctly received. 70879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. 70979188ed7SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 7106da84376SMilanka Ringwald * @param callback 7116da84376SMilanka Ringwald * @param con_handle 712b45b7749SMilanka Ringwald * @param value_handle 713b45b7749SMilanka Ringwald * @param value_length 714b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 71540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 71640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 717692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 718692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7193deb3ec6SMatthias Ringwald */ 720b45b7749SMilanka 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); 7213deb3ec6SMatthias Ringwald 7223deb3ec6SMatthias Ringwald /** 72379188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 72479188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 72579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7266da84376SMilanka Ringwald * @param callback 7276da84376SMilanka Ringwald * @param con_handle 7286da84376SMilanka Ringwald * @param descriptor 72940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 73040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 731692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 732692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7333deb3ec6SMatthias Ringwald */ 734711e6c80SMatthias 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); 7356da84376SMilanka Ringwald 7366da84376SMilanka Ringwald /** 73779188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 73879188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 73979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7406da84376SMilanka Ringwald * @param callback 7416da84376SMilanka Ringwald * @param con_handle 7426da84376SMilanka Ringwald * @param descriptor 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 7476da84376SMilanka Ringwald */ 748711e6c80SMatthias 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); 7493deb3ec6SMatthias Ringwald 7503deb3ec6SMatthias Ringwald /** 75179188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 75279188ed7SMilanka Ringwald * For each blob, 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 756b45b7749SMilanka 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_long_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 long characteristic descriptor using its handle. It will be returned in several blobs. 76679188ed7SMilanka Ringwald * For each blob, 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_handle 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_long_characteristic_descriptor_using_descriptor_handle(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t descriptor_handle); 7776da84376SMilanka Ringwald 7786da84376SMilanka 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 7846da84376SMilanka Ringwald * @param descriptor_handle 7856da84376SMilanka Ringwald * @param offset 78640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 78740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 788692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 789692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 7906da84376SMilanka Ringwald */ 791711e6c80SMatthias 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); 7923deb3ec6SMatthias Ringwald 7933deb3ec6SMatthias Ringwald /** 79479188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 79579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 79679188ed7SMilanka 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). 7976da84376SMilanka Ringwald * @param callback 7986da84376SMilanka Ringwald * @param con_handle 7996da84376SMilanka Ringwald * @param descriptor 800b45b7749SMilanka Ringwald * @param value_length 801b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 80240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 80340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 804692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 805692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8063deb3ec6SMatthias Ringwald */ 807b45b7749SMilanka 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); 8086da84376SMilanka Ringwald 8096da84376SMilanka Ringwald /** 81079188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 81179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 81279188ed7SMilanka 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). 8136da84376SMilanka Ringwald * @param callback 8146da84376SMilanka Ringwald * @param con_handle 8156da84376SMilanka Ringwald * @param descriptor_handle 816b45b7749SMilanka Ringwald * @param value_length 817b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 81840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 81940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 820692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 821692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8226da84376SMilanka Ringwald */ 823b45b7749SMilanka 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); 8246da84376SMilanka Ringwald 8256da84376SMilanka Ringwald /** 82679188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 82779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 82879188ed7SMilanka 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). 8296da84376SMilanka Ringwald * @param callback 8306da84376SMilanka Ringwald * @param con_handle 8316da84376SMilanka Ringwald * @param descriptor 832b45b7749SMilanka Ringwald * @param value_length 833b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 83440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 83540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 836692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 837692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8386da84376SMilanka Ringwald */ 839b45b7749SMilanka 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); 8406da84376SMilanka Ringwald 8416da84376SMilanka Ringwald /** 84279188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 84379188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 84479188ed7SMilanka 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). 8456da84376SMilanka Ringwald * @param callback 8466da84376SMilanka Ringwald * @param con_handle 8476da84376SMilanka Ringwald * @param descriptor_handle 848b45b7749SMilanka Ringwald * @param value_length 849b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 85040faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 85140faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 852692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 853692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8546da84376SMilanka Ringwald */ 855b45b7749SMilanka 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); 8566da84376SMilanka Ringwald 8576da84376SMilanka Ringwald /** 85879188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 85979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 86079188ed7SMilanka 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). 8616da84376SMilanka Ringwald * @param callback 8626da84376SMilanka Ringwald * @param con_handle 8636da84376SMilanka Ringwald * @param descriptor_handle 8646da84376SMilanka Ringwald * @param offset of value 865b45b7749SMilanka Ringwald * @param value_length 866b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 86740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 86840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 869692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 870692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8716da84376SMilanka Ringwald */ 872b45b7749SMilanka 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); 8733deb3ec6SMatthias Ringwald 8743deb3ec6SMatthias Ringwald /** 87579188ed7SMilanka Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 87679188ed7SMilanka Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 87779188ed7SMilanka Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 87879188ed7SMilanka Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 87979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 88079188ed7SMilanka 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). 8816da84376SMilanka Ringwald * @param callback 8826da84376SMilanka Ringwald * @param con_handle 8836da84376SMilanka Ringwald * @param characteristic 884b7e5512fSMilanka Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 88540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 88640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 887692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 888b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 889b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 8906b04f675SMilanka Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 891b7e5512fSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8923deb3ec6SMatthias Ringwald */ 893711e6c80SMatthias 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); 8949c662c9bSMatthias Ringwald 8959c662c9bSMatthias Ringwald /** 89679188ed7SMilanka Ringwald * @brief Register for notifications and indications of a characteristic enabled by 89779188ed7SMilanka Ringwald * the gatt_client_write_client_characteristic_configuration function. 8989c662c9bSMatthias Ringwald * @param notification struct used to store registration 8996da84376SMilanka Ringwald * @param callback 900b3f03c84SMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 901b3f03c84SMatthias Ringwald * @param characteristic or NULL to receive updates for all characteristics 9029c662c9bSMatthias Ringwald */ 9036da84376SMilanka 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); 9043deb3ec6SMatthias Ringwald 9053deb3ec6SMatthias Ringwald /** 90679188ed7SMilanka Ringwald * @brief Stop listening to characteristic value updates registered with 90779188ed7SMilanka Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 9081f734b5fSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 9091f734b5fSMatthias Ringwald */ 9101f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); 9111f734b5fSMatthias Ringwald 9121f734b5fSMatthias Ringwald /** 91379188ed7SMilanka Ringwald * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. 91479188ed7SMilanka Ringwald * Call the gatt_client_execute_write function to commit the transaction. 9156da84376SMilanka Ringwald * @param callback 9166da84376SMilanka Ringwald * @param con_handle 9176da84376SMilanka Ringwald * @param attribute_handle 9186da84376SMilanka Ringwald * @param offset of value 919b45b7749SMilanka Ringwald * @param value_length 920b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 9213deb3ec6SMatthias Ringwald */ 922b45b7749SMilanka 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); 9233deb3ec6SMatthias Ringwald 9243deb3ec6SMatthias Ringwald /** 9256da84376SMilanka Ringwald * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9266da84376SMilanka Ringwald * @param callback 9276da84376SMilanka Ringwald * @param con_handle 92840faeb84SMilanka Ringwald * @return status 9293deb3ec6SMatthias Ringwald */ 930711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9313deb3ec6SMatthias Ringwald 9323deb3ec6SMatthias Ringwald /** 9336da84376SMilanka Ringwald * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. 9346da84376SMilanka Ringwald * @param callback 9356da84376SMilanka Ringwald * @param con_handle 93640faeb84SMilanka Ringwald * @return status 9373deb3ec6SMatthias Ringwald */ 938711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 9393deb3ec6SMatthias Ringwald 94059d34cd2SMatthias Ringwald /** 94153e9c18fSMatthias Ringwald * @brief Request callback when regular gatt query can be sent 94253e9c18fSMatthias Ringwald * @note callback might happen during call to this function 94353e9c18fSMatthias Ringwald * @param callback_registration to point to callback function and context information 94453e9c18fSMatthias Ringwald * @param con_handle 94553e9c18fSMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 94653e9c18fSMatthias Ringwald */ 94753e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 94853e9c18fSMatthias Ringwald 94953e9c18fSMatthias Ringwald /** 95059d34cd2SMatthias Ringwald * @brief Request callback when writing characteristic value without response is possible 95153e9c18fSMatthias Ringwald * @note callback might happen during call to this function 95259d34cd2SMatthias Ringwald * @param callback_registration to point to callback function and context information 95359d34cd2SMatthias Ringwald * @param con_handle 95459d34cd2SMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 95559d34cd2SMatthias Ringwald */ 95659d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 95759d34cd2SMatthias Ringwald 95859d34cd2SMatthias Ringwald 95959d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually 96059d34cd2SMatthias Ringwald /** 96159d34cd2SMatthias Ringwald * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees 96259d34cd2SMatthias Ringwald * a single successful gatt_client_write_value_of_characteristic_without_response call. 96359d34cd2SMatthias Ringwald * @deprecated please use gatt_client_request_to_write_without_response instead 96459d34cd2SMatthias Ringwald * @param callback 96559d34cd2SMatthias Ringwald * @param con_handle 96659d34cd2SMatthias Ringwald * @return status 96759d34cd2SMatthias Ringwald */ 96859d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 96959d34cd2SMatthias Ringwald 97059d34cd2SMatthias Ringwald 9713deb3ec6SMatthias Ringwald /* API_END */ 9723deb3ec6SMatthias Ringwald 9736ba2ad22SMatthias Ringwald // used by generated btstack_event.c 9746ba2ad22SMatthias Ringwald 975313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); 976313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); 977313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); 9786ba2ad22SMatthias Ringwald 979a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 980a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); 98140faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client); 982a6121b51SMilanka Ringwald #endif 983a6121b51SMilanka Ringwald 9843deb3ec6SMatthias Ringwald #if defined __cplusplus 9853deb3ec6SMatthias Ringwald } 9863deb3ec6SMatthias Ringwald #endif 9873deb3ec6SMatthias Ringwald 9883deb3ec6SMatthias Ringwald #endif 989