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 54*36f8195cSMatthias Ringwald // Use Find Information for CCC Discovery by default 55*36f8195cSMatthias Ringwald #if !defined(ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY) && !defined(ENABLE_GATT_LEGACY_CCC_DISCOVERY) 56*36f8195cSMatthias Ringwald #define ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY 57*36f8195cSMatthias Ringwald #endif 58*36f8195cSMatthias Ringwald 593deb3ec6SMatthias Ringwald typedef enum { 603deb3ec6SMatthias Ringwald P_READY, 61544a5845SMatthias Ringwald P_W2_EMIT_QUERY_COMPLETE_EVENT, 623deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_QUERY, 633deb3ec6SMatthias Ringwald P_W4_SERVICE_QUERY_RESULT, 643deb3ec6SMatthias Ringwald P_W2_SEND_SERVICE_WITH_UUID_QUERY, 653deb3ec6SMatthias Ringwald P_W4_SERVICE_WITH_UUID_RESULT, 663deb3ec6SMatthias Ringwald 673deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY, 683deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT, 693deb3ec6SMatthias Ringwald P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY, 703deb3ec6SMatthias Ringwald P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT, 713deb3ec6SMatthias Ringwald 723deb3ec6SMatthias Ringwald P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY, 733deb3ec6SMatthias Ringwald P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT, 743deb3ec6SMatthias Ringwald 753deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_QUERY, 763deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_QUERY_RESULT, 773deb3ec6SMatthias Ringwald P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY, 783deb3ec6SMatthias Ringwald P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT, 793deb3ec6SMatthias Ringwald 803deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY, 813deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_VALUE_RESULT, 823deb3ec6SMatthias Ringwald 833deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_QUERY, 843deb3ec6SMatthias Ringwald P_W4_READ_BLOB_RESULT, 853deb3ec6SMatthias Ringwald 863deb3ec6SMatthias Ringwald P_W2_SEND_READ_BY_TYPE_REQUEST, 873deb3ec6SMatthias Ringwald P_W4_READ_BY_TYPE_RESPONSE, 883deb3ec6SMatthias Ringwald 893deb3ec6SMatthias Ringwald P_W2_SEND_READ_MULTIPLE_REQUEST, 903deb3ec6SMatthias Ringwald P_W4_READ_MULTIPLE_RESPONSE, 913deb3ec6SMatthias Ringwald 92f125a8efSMatthias Ringwald P_W2_SEND_READ_MULTIPLE_VARIABLE_REQUEST, 93f125a8efSMatthias Ringwald P_W4_READ_MULTIPLE_VARIABLE_RESPONSE, 94f125a8efSMatthias Ringwald 953deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_VALUE, 963deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT, 973deb3ec6SMatthias Ringwald 983deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE, 993deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_RESULT, 1003deb3ec6SMatthias Ringwald P_W2_PREPARE_RELIABLE_WRITE, 1013deb3ec6SMatthias Ringwald P_W4_PREPARE_RELIABLE_WRITE_RESULT, 1023deb3ec6SMatthias Ringwald 1033deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE, 1043deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_RESULT, 1053deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE, 1063deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_RESULT, 1073deb3ec6SMatthias Ringwald P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH, 1083deb3ec6SMatthias Ringwald P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT, 1093deb3ec6SMatthias Ringwald 110197b4dd3SMatthias Ringwald #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY 111abdc9fb5SMatthias Ringwald P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 112abdc9fb5SMatthias Ringwald P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 113197b4dd3SMatthias Ringwald #else 114197b4dd3SMatthias Ringwald P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY, 115197b4dd3SMatthias Ringwald P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT, 116197b4dd3SMatthias Ringwald #endif 1173deb3ec6SMatthias Ringwald P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION, 1183deb3ec6SMatthias Ringwald P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT, 1193deb3ec6SMatthias Ringwald 1203deb3ec6SMatthias Ringwald P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY, 1213deb3ec6SMatthias Ringwald P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT, 1223deb3ec6SMatthias Ringwald 1233deb3ec6SMatthias Ringwald P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY, 1243deb3ec6SMatthias Ringwald P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT, 1253deb3ec6SMatthias Ringwald 1263deb3ec6SMatthias Ringwald P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR, 1273deb3ec6SMatthias Ringwald P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1283deb3ec6SMatthias Ringwald 1293deb3ec6SMatthias Ringwald // all long writes use this 1303deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR, 1313deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1323deb3ec6SMatthias Ringwald P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR, 1333deb3ec6SMatthias Ringwald P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT, 1343deb3ec6SMatthias Ringwald 1353deb3ec6SMatthias Ringwald // gatt reliable write API use this (manual version of the above) 1363deb3ec6SMatthias Ringwald P_W2_PREPARE_WRITE_SINGLE, 1373deb3ec6SMatthias Ringwald P_W4_PREPARE_WRITE_SINGLE_RESULT, 1383deb3ec6SMatthias Ringwald 139793cf6ceSMatthias Ringwald P_W4_IDENTITY_RESOLVING, 1403deb3ec6SMatthias Ringwald P_W4_CMAC_READY, 1413deb3ec6SMatthias Ringwald P_W4_CMAC_RESULT, 1423deb3ec6SMatthias Ringwald P_W2_SEND_SIGNED_WRITE, 1434c7c987fSMatthias Ringwald P_W4_SEND_SIGNED_WRITE_DONE, 1441450cdc6SMatthias Ringwald 1451450cdc6SMatthias Ringwald P_W2_SDP_QUERY, 1461450cdc6SMatthias Ringwald P_W4_SDP_QUERY, 147180cbe79SMatthias Ringwald P_W2_L2CAP_CONNECT, 1481450cdc6SMatthias Ringwald P_W4_L2CAP_CONNECTION, 14974daebdeSMatthias Ringwald P_W2_EMIT_CONNECTED, 150df0a5c68SMatthias Ringwald P_L2CAP_CLOSED, 1513deb3ec6SMatthias Ringwald } gatt_client_state_t; 1523deb3ec6SMatthias Ringwald 1533deb3ec6SMatthias Ringwald 1543deb3ec6SMatthias Ringwald typedef enum{ 1553deb3ec6SMatthias Ringwald SEND_MTU_EXCHANGE, 1563deb3ec6SMatthias Ringwald SENT_MTU_EXCHANGE, 1575cf6c434SJakob Krantz MTU_EXCHANGED, 1585cf6c434SJakob Krantz MTU_AUTO_EXCHANGE_DISABLED 1593deb3ec6SMatthias Ringwald } gatt_client_mtu_t; 1603deb3ec6SMatthias Ringwald 1612acb2842SMatthias Ringwald typedef enum { 1622acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_W2_SEND, 1632acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_W4_DONE, 1642acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_CHARACTERISTICS_W2_SEND, 1652acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DISCOVER_CHARACTERISTICS_W4_DONE, 1662acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_SERVICE_CHANGED_WRITE_CCCD_W2_SEND, 1672acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_SERVICE_CHANGED_WRITE_CCCD_W4_DONE, 1682acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_READ_W2_SEND, 1692acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_READ_W4_DONE, 1702acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_WRITE_CCCD_W2_SEND, 1712acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DATABASE_HASH_WRITE_CCCD_W4_DONE, 1722acb2842SMatthias Ringwald GATT_CLIENT_SERVICE_DONE, 1732acb2842SMatthias Ringwald } gatt_client_service_state_t; 1742acb2842SMatthias Ringwald 175cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 176cbd76cecSMatthias Ringwald typedef enum { 177cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_IDLE, 1787627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W2_SEND, 1797627a0deSMatthias Ringwald GATT_CLIENT_EATT_DISCOVER_GATT_SERVICE_W4_DONE, 18026166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W2_SEND, 18126166ecfSMatthias Ringwald GATT_CLIENT_EATT_READ_SERVER_SUPPORTED_FEATURES_W4_DONE, 18226166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W2_SEND, 18326166ecfSMatthias Ringwald GATT_CLIENT_EATT_FIND_CLIENT_SUPPORTED_FEATURES_W4_DONE, 18426166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W2_SEND, 18526166ecfSMatthias Ringwald GATT_CLIENT_EATT_WRITE_ClIENT_SUPPORTED_FEATURES_W4_DONE, 1867627a0deSMatthias Ringwald GATT_CLIENT_EATT_L2CAP_SETUP, 187cbd76cecSMatthias Ringwald GATT_CLIENT_EATT_READY, 188cbd76cecSMatthias Ringwald } gatt_client_eatt_state_t; 189cbd76cecSMatthias Ringwald #endif 190cbd76cecSMatthias Ringwald 1913deb3ec6SMatthias Ringwald typedef struct gatt_client{ 192665d90f2SMatthias Ringwald btstack_linked_item_t item; 1934c7c987fSMatthias Ringwald 194052dc82aSMatthias Ringwald gatt_client_state_t state; 1953deb3ec6SMatthias Ringwald 1969c662c9bSMatthias Ringwald // user callback 1979c662c9bSMatthias Ringwald btstack_packet_handler_t callback; 1983deb3ec6SMatthias Ringwald 19947181045SMatthias Ringwald // can write without response callback 20047181045SMatthias Ringwald btstack_packet_handler_t write_without_response_callback; 20147181045SMatthias Ringwald 20259d34cd2SMatthias Ringwald // can write without response requests 20359d34cd2SMatthias Ringwald btstack_linked_list_t write_without_response_requests; 20459d34cd2SMatthias Ringwald 20553e9c18fSMatthias Ringwald // regular gatt query requests 20653e9c18fSMatthias Ringwald btstack_linked_list_t query_requests; 20753e9c18fSMatthias Ringwald 208fc64f94aSMatthias Ringwald hci_con_handle_t con_handle; 209f4b33574SMatthias Ringwald 210e9cdf30bSMatthias Ringwald att_bearer_type_t bearer_type; 211e9cdf30bSMatthias Ringwald 2121aa186afSMatthias Ringwald #if defined(ENABLE_GATT_OVER_CLASSIC) || defined(ENABLE_GATT_OVER_EATT) 2131aa186afSMatthias Ringwald uint16_t l2cap_cid; 214e4f1c903SMatthias Ringwald bd_addr_t addr; 215b2d70d58SMatthias Ringwald bd_addr_type_t addr_type; 2161aa186afSMatthias Ringwald #endif 2171aa186afSMatthias Ringwald 2181450cdc6SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 2191450cdc6SMatthias Ringwald uint16_t l2cap_psm; 220052dc82aSMatthias Ringwald btstack_context_callback_registration_t callback_request; 2211450cdc6SMatthias Ringwald #endif 2221450cdc6SMatthias Ringwald 223cbd76cecSMatthias Ringwald #ifdef ENABLE_GATT_OVER_EATT 224cbd76cecSMatthias Ringwald gatt_client_eatt_state_t eatt_state; 2257627a0deSMatthias Ringwald btstack_linked_list_t eatt_clients; 2267627a0deSMatthias Ringwald uint8_t * eatt_storage_buffer; 2277627a0deSMatthias Ringwald uint16_t eatt_storage_size; 2287627a0deSMatthias Ringwald uint8_t eatt_num_clients; 2297627a0deSMatthias Ringwald uint8_t gatt_server_supported_features; 230cbd76cecSMatthias Ringwald uint16_t gatt_client_supported_features_handle; 231cbd76cecSMatthias Ringwald #endif 232cbd76cecSMatthias Ringwald 2333deb3ec6SMatthias Ringwald uint16_t mtu; 2343deb3ec6SMatthias Ringwald gatt_client_mtu_t mtu_state; 2353deb3ec6SMatthias Ringwald 2363deb3ec6SMatthias Ringwald uint16_t uuid16; 2373deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 2383deb3ec6SMatthias Ringwald 2393deb3ec6SMatthias Ringwald uint16_t start_group_handle; 2403deb3ec6SMatthias Ringwald uint16_t end_group_handle; 2413deb3ec6SMatthias Ringwald 2423deb3ec6SMatthias Ringwald uint16_t query_start_handle; 2433deb3ec6SMatthias Ringwald uint16_t query_end_handle; 2443deb3ec6SMatthias Ringwald 2453deb3ec6SMatthias Ringwald uint8_t characteristic_properties; 2463deb3ec6SMatthias Ringwald uint16_t characteristic_start_handle; 2473deb3ec6SMatthias Ringwald 2483deb3ec6SMatthias Ringwald uint16_t attribute_handle; 2493deb3ec6SMatthias Ringwald uint16_t attribute_offset; 2503deb3ec6SMatthias Ringwald uint16_t attribute_length; 2513deb3ec6SMatthias Ringwald uint8_t* attribute_value; 2523deb3ec6SMatthias Ringwald 2533deb3ec6SMatthias Ringwald // read multiple characteristic values 2543deb3ec6SMatthias Ringwald uint16_t read_multiple_handle_count; 2553deb3ec6SMatthias Ringwald uint16_t * read_multiple_handles; 2563deb3ec6SMatthias Ringwald 2573deb3ec6SMatthias Ringwald uint16_t client_characteristic_configuration_handle; 2583deb3ec6SMatthias Ringwald uint8_t client_characteristic_configuration_value[2]; 2593deb3ec6SMatthias Ringwald 260ab415e75SMatthias Ringwald bool filter_with_uuid; 26152377058SMatthias Ringwald bool send_confirmation; 2623deb3ec6SMatthias Ringwald 2633deb3ec6SMatthias Ringwald int le_device_index; 2643deb3ec6SMatthias Ringwald uint8_t cmac[8]; 2653deb3ec6SMatthias Ringwald 266ec820d77SMatthias Ringwald btstack_timer_source_t gc_timeout; 267f4b33574SMatthias Ringwald 268f4b33574SMatthias Ringwald uint8_t security_counter; 2692197dbafSMatthias Ringwald bool wait_for_authentication_complete; 270f4b33574SMatthias Ringwald uint8_t pending_error_code; 271f4b33574SMatthias Ringwald 2728918bbdaSMatthias Ringwald bool reencryption_active; 2738918bbdaSMatthias Ringwald uint8_t reencryption_result; 2748918bbdaSMatthias Ringwald 2751dfae9c7SMatthias Ringwald gap_security_level_t security_level; 2761dfae9c7SMatthias Ringwald 2779da02385SMatthias Ringwald // Context 2789da02385SMatthias Ringwald uint16_t service_id; 2799da02385SMatthias Ringwald uint16_t connection_id; 2809da02385SMatthias Ringwald 2812acb2842SMatthias Ringwald // GATT Service Changes 2822acb2842SMatthias Ringwald gatt_client_service_state_t gatt_service_state; 2832acb2842SMatthias Ringwald uint16_t gatt_service_start_group_handle; 2842acb2842SMatthias Ringwald uint16_t gatt_service_end_group_handle; 2852acb2842SMatthias Ringwald // - Service Changed 2862acb2842SMatthias Ringwald uint16_t gatt_service_changed_value_handle; 2872acb2842SMatthias Ringwald uint16_t gatt_service_changed_cccd_handle; 2882acb2842SMatthias Ringwald uint16_t gatt_service_changed_end_handle; 2892acb2842SMatthias Ringwald // - Database Hash 2902acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_value_handle; 2912acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_cccd_handle; 2922acb2842SMatthias Ringwald uint16_t gatt_service_database_hash_end_handle; 2932acb2842SMatthias Ringwald 2943deb3ec6SMatthias Ringwald } gatt_client_t; 2953deb3ec6SMatthias Ringwald 2961a4874dcSMatthias Ringwald // Single characteristic, with wildcards for con_handle and attribute_handle 2971a4874dcSMatthias Ringwald typedef struct { 298665d90f2SMatthias Ringwald btstack_linked_item_t item; 299b6e96f14SMatthias Ringwald btstack_packet_handler_t callback; 300711e6c80SMatthias Ringwald hci_con_handle_t con_handle; 3019c662c9bSMatthias Ringwald uint16_t attribute_handle; 3029c662c9bSMatthias Ringwald } gatt_client_notification_t; 3033deb3ec6SMatthias Ringwald 3041a4874dcSMatthias Ringwald // Attribute range, aka service, no wildcards, used for implementing GATT Service clients 3051a4874dcSMatthias Ringwald typedef struct { 3061a4874dcSMatthias Ringwald btstack_linked_item_t item; 3071a4874dcSMatthias Ringwald btstack_packet_handler_t callback; 3081a4874dcSMatthias Ringwald hci_con_handle_t con_handle; 3091a4874dcSMatthias Ringwald uint16_t start_group_handle; 3101a4874dcSMatthias Ringwald uint16_t end_group_handle; 3111a4874dcSMatthias Ringwald // Context 3121a4874dcSMatthias Ringwald uint16_t service_id; 3131a4874dcSMatthias Ringwald uint16_t connection_id; 3141a4874dcSMatthias Ringwald } gatt_client_service_notification_t; 3151a4874dcSMatthias Ringwald 3163deb3ec6SMatthias Ringwald /* API_START */ 3173deb3ec6SMatthias Ringwald 318d25c33e5SMatthias Ringwald typedef struct { 3193deb3ec6SMatthias Ringwald uint16_t start_group_handle; 3203deb3ec6SMatthias Ringwald uint16_t end_group_handle; 3213deb3ec6SMatthias Ringwald uint16_t uuid16; 3223deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 323d25c33e5SMatthias Ringwald } gatt_client_service_t; 3243deb3ec6SMatthias Ringwald 325d25c33e5SMatthias Ringwald typedef struct { 3263deb3ec6SMatthias Ringwald uint16_t start_handle; 3273deb3ec6SMatthias Ringwald uint16_t value_handle; 3283deb3ec6SMatthias Ringwald uint16_t end_handle; 3293deb3ec6SMatthias Ringwald uint16_t properties; 3303deb3ec6SMatthias Ringwald uint16_t uuid16; 3313deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 332d25c33e5SMatthias Ringwald } gatt_client_characteristic_t; 3333deb3ec6SMatthias Ringwald 334d25c33e5SMatthias Ringwald typedef struct { 3353deb3ec6SMatthias Ringwald uint16_t handle; 3363deb3ec6SMatthias Ringwald uint16_t uuid16; 3373deb3ec6SMatthias Ringwald uint8_t uuid128[16]; 338d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t; 3393deb3ec6SMatthias Ringwald 3403deb3ec6SMatthias Ringwald /** 3413deb3ec6SMatthias Ringwald * @brief Set up GATT client. 3423deb3ec6SMatthias Ringwald */ 3433deb3ec6SMatthias Ringwald void gatt_client_init(void); 3443deb3ec6SMatthias Ringwald 3453deb3ec6SMatthias Ringwald /** 34611279da7SMatthias Ringwald * @brief Set minimum required security level for GATT Client 34711279da7SMatthias Ringwald * @note The Bluetooth specification makes the GATT Server responsible to check for security. 348b11289a8SMatthias Ringwald * This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part. 349b11289a8SMatthias Ringwald * If your application is exchanging sensitive data with a remote device, you would need to manually check 350b11289a8SMatthias Ringwald * the security level before sending/receive such data. 351b11289a8SMatthias Ringwald * With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange 352b11289a8SMatthias Ringwald * until the required security level is established. 353b11289a8SMatthias Ringwald * gatt_client_request_can_write_without_response_event does not trigger authentication 35459d34cd2SMatthias Ringwald * gatt_client_request_to_write_without_response does not trigger authentication 35511279da7SMatthias Ringwald * @pram level, default LEVEL_0 (no encryption required) 35611279da7SMatthias Ringwald */ 35711279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level); 35811279da7SMatthias Ringwald 35911279da7SMatthias Ringwald /** 3601450cdc6SMatthias Ringwald * @brief Connect to remote GATT Server over Classic (BR/EDR) Connection 361effecf77SMatthias Ringwald * GATT_EVENT_CONNECTED with status and con_handle for other API functions 362effecf77SMatthias Ringwald * is emitted on connection complete. 363effecf77SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC. 3641450cdc6SMatthias Ringwald * @param addr 3651450cdc6SMatthias Ringwald * @return status 3661450cdc6SMatthias Ringwald */ 3671450cdc6SMatthias Ringwald uint8_t gatt_client_classic_connect(btstack_packet_handler_t callback, bd_addr_t addr); 3681450cdc6SMatthias Ringwald 3691450cdc6SMatthias Ringwald /** 3701450cdc6SMatthias Ringwald * @brief Disconnect o Classic (BR/EDR) connection to a remote GATT Server 3711450cdc6SMatthias Ringwald * @note requires ENABLE_GATT_OVER_CLASSIC 372effecf77SMatthias Ringwald * @param con_handle 3731450cdc6SMatthias Ringwald * @return status 3741450cdc6SMatthias Ringwald */ 3751450cdc6SMatthias Ringwald uint8_t gatt_client_classic_disconnect(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 3761450cdc6SMatthias Ringwald 3771450cdc6SMatthias Ringwald /** 3787627a0deSMatthias Ringwald * @brief Setup Enhanced LE Bearer with up to 5 channels on existing LE connection 3797627a0deSMatthias Ringwald * @param callback for GATT_EVENT_CONNECTED and GATT_EVENT_DISCONNECTED events 38026166ecfSMatthias Ringwald * @param con_handle 38126166ecfSMatthias Ringwald * @param num_channels 3827627a0deSMatthias Ringwald * @param storage_buffer for L2CAP connection 3838540586aSMatthias Ringwald * @param storage_size - each channel requires (2 * ATT MTU) + 10 bytes 38426166ecfSMatthias Ringwald * @return 38526166ecfSMatthias Ringwald */ 38626166ecfSMatthias 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); 38726166ecfSMatthias Ringwald 38826166ecfSMatthias Ringwald /** 38979188ed7SMilanka Ringwald * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value, 39079188ed7SMilanka Ringwald * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h). 3916da84376SMilanka Ringwald * @param con_handle 3926201dbadSMatthias Ringwald * @param mtu or 0 in case of error 39340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 39440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 395692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if MTU is not exchanged and MTU auto-exchange is disabled 3966201dbadSMatthias Ringwald * ERROR_CODE_SUCCESS on success 3973deb3ec6SMatthias Ringwald */ 398fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu); 3993deb3ec6SMatthias Ringwald 4003deb3ec6SMatthias Ringwald /** 40179188ed7SMilanka Ringwald * @brief Sets whether a MTU Exchange Request shall be automatically send before the 40279188ed7SMilanka Ringwald * first attribute read request is send. Default is enabled. 4036da84376SMilanka Ringwald * @param enabled 4045cf6c434SJakob Krantz */ 4055cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled); 4065cf6c434SJakob Krantz 4075cf6c434SJakob Krantz /** 40879188ed7SMilanka Ringwald * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU 40979188ed7SMilanka Ringwald * when gatt_client_mtu_enable_auto_negotiation is disabled. 4106da84376SMilanka Ringwald * @param callback 4116da84376SMilanka Ringwald * @param con_handle 4125cf6c434SJakob Krantz */ 4135cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4145cf6c434SJakob Krantz 4155cf6c434SJakob Krantz /** 416aacf1b1aSMilanka Ringwald * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon. 4176da84376SMilanka Ringwald * @param con_handle 418692bf1adSMilanka Ringwald * @return is_ready_status 0 - if no GATT client for con_handle is found, or is not ready, otherwise 1 4193deb3ec6SMatthias Ringwald */ 420fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle); 4213deb3ec6SMatthias Ringwald 4223deb3ec6SMatthias Ringwald /** 42379188ed7SMilanka Ringwald * @brief Discovers all primary services. 42479188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 42579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4266da84376SMilanka Ringwald * @param callback 4276da84376SMilanka Ringwald * @param con_handle 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_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4333deb3ec6SMatthias Ringwald 4343deb3ec6SMatthias Ringwald /** 43579188ed7SMilanka Ringwald * @brief Discovers all secondary services. 43679188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 43779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4388d1f34d3SMatheus Eduardo Garbelini * @param callback 4398d1f34d3SMatheus Eduardo Garbelini * @param con_handle 4408d1f34d3SMatheus Eduardo Garbelini * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 4418d1f34d3SMatheus Eduardo Garbelini * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 4428d1f34d3SMatheus Eduardo Garbelini * ERROR_CODE_SUCCESS , if query is successfully registered 4438d1f34d3SMatheus Eduardo Garbelini */ 4448d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 4458d1f34d3SMatheus Eduardo Garbelini 4468d1f34d3SMatheus Eduardo Garbelini /** 44779188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 44879188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 44979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4506da84376SMilanka Ringwald * @param callback 4516da84376SMilanka Ringwald * @param con_handle 4526da84376SMilanka Ringwald * @param uuid16 453692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 454692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 455692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4563deb3ec6SMatthias Ringwald */ 457711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); 4586da84376SMilanka Ringwald 4596da84376SMilanka Ringwald /** 46068ced5c9SMatthias Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 46168ced5c9SMatthias Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 46268ced5c9SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 46368ced5c9SMatthias Ringwald * @param callback 46468ced5c9SMatthias Ringwald * @param con_handle 46568ced5c9SMatthias Ringwald * @param uuid16 46668ced5c9SMatthias Ringwald * @param service_id - context provided to callback in events 46768ced5c9SMatthias Ringwald * @param connection_id - contest provided to callback in events 46868ced5c9SMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 46968ced5c9SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 47068ced5c9SMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 47168ced5c9SMatthias Ringwald */ 47268ced5c9SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 47368ced5c9SMatthias Ringwald uint16_t uuid16, uint16_t service_id, uint16_t connection_id); 47468ced5c9SMatthias Ringwald 47568ced5c9SMatthias Ringwald /** 47679188ed7SMilanka Ringwald * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. 47779188ed7SMilanka Ringwald * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. 47879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 4796da84376SMilanka Ringwald * @param callback 4806da84376SMilanka Ringwald * @param con_handle 4816da84376SMilanka Ringwald * @param uuid128 482692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 483692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 484692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 4856da84376SMilanka Ringwald */ 4866da84376SMilanka 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); 4873deb3ec6SMatthias Ringwald 4883deb3ec6SMatthias Ringwald /** 48979188ed7SMilanka Ringwald * @brief Finds included services within the specified service. 49079188ed7SMilanka Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 49179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 49279188ed7SMilanka Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 49379188ed7SMilanka Ringwald * an ATT find information request for the returned start group handle 49479188ed7SMilanka Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 49579188ed7SMilanka Ringwald * to the list of all primary services. 4966da84376SMilanka Ringwald * @param callback 4976da84376SMilanka Ringwald * @param con_handle 4986da84376SMilanka Ringwald * @param service 499692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 500692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 501692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5023deb3ec6SMatthias Ringwald */ 503711e6c80SMatthias 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); 5043deb3ec6SMatthias Ringwald 5053deb3ec6SMatthias Ringwald /** 506aa43543aSMatthias Ringwald * @brief Finds included services within the specified service. 507aa43543aSMatthias Ringwald * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted. 508aa43543aSMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 509aa43543aSMatthias Ringwald * Information about included service type (primary/secondary) can be retrieved either by sending 510aa43543aSMatthias Ringwald * an ATT find information request for the returned start group handle 511aa43543aSMatthias Ringwald * (returning the handle and the UUID for primary or secondary service) or by comparing the service 512aa43543aSMatthias Ringwald * to the list of all primary services. 513aa43543aSMatthias Ringwald * @param callback 514aa43543aSMatthias Ringwald * @param con_handle 515aa43543aSMatthias Ringwald * @param service_id - context provided to callback in events 516aa43543aSMatthias Ringwald * @param connection_id - contest provided to callback in events 517aa43543aSMatthias Ringwald * @param service_id 518aa43543aSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 519aa43543aSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 520aa43543aSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 521aa43543aSMatthias Ringwald */ 522aa43543aSMatthias Ringwald uint8_t gatt_client_find_included_services_for_service_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 523aa43543aSMatthias Ringwald gatt_client_service_t * service, uint16_t service_id, uint16_t connection_id); 524aa43543aSMatthias Ringwald 525aa43543aSMatthias Ringwald /** 52679188ed7SMilanka Ringwald * @brief Discovers all characteristics within the specified service. 52779188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 52879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5296da84376SMilanka Ringwald * @param callback 5306da84376SMilanka Ringwald * @param con_handle 5316da84376SMilanka Ringwald * @param service 532692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 533692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 534692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5353deb3ec6SMatthias Ringwald */ 536711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_service(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service); 5373deb3ec6SMatthias Ringwald 5383deb3ec6SMatthias Ringwald /** 5398183ac30SMatthias Ringwald * @brief Discovers all characteristics within the specified service. 5408183ac30SMatthias Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited. 5418183ac30SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5428183ac30SMatthias Ringwald * @param callback 5438183ac30SMatthias Ringwald * @param con_handle 5448183ac30SMatthias Ringwald * @param service 5458183ac30SMatthias Ringwald * @param service_id - context provided to callback in events 5468183ac30SMatthias Ringwald * @param connection_id - contest provided to callback in events 5478183ac30SMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 5488183ac30SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 5498183ac30SMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5508183ac30SMatthias Ringwald */ 5518183ac30SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_service_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_service_t * service, 5528183ac30SMatthias Ringwald uint16_t service_id, uint16_t connection_id); 5538183ac30SMatthias Ringwald 5548183ac30SMatthias Ringwald /** 55579188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within 55679188ed7SMilanka Ringwald * the specified service or handle range, and return those that match the given UUID. 55779188ed7SMilanka Ringwald * 55879188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 55979188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5606da84376SMilanka Ringwald * @param callback 5616da84376SMilanka Ringwald * @param con_handle 5626da84376SMilanka Ringwald * @param start_handle 5636da84376SMilanka Ringwald * @param end_handle 5646da84376SMilanka Ringwald * @param uuid16 565692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 566692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 567692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5683deb3ec6SMatthias Ringwald */ 569711e6c80SMatthias 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); 5706da84376SMilanka Ringwald 5716da84376SMilanka Ringwald /** 57279188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 57379188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 57479188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 57579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5766da84376SMilanka Ringwald * @param callback 5776da84376SMilanka Ringwald * @param con_handle 5786da84376SMilanka Ringwald * @param start_handle 5796da84376SMilanka Ringwald * @param end_handle 5806da84376SMilanka Ringwald * @param uuid128 581692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 582692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 583692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5846da84376SMilanka Ringwald */ 585045d700dSDavid 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); 5866da84376SMilanka Ringwald 5876da84376SMilanka Ringwald /** 58879188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 58979188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 59079188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 59179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 5926da84376SMilanka Ringwald * @param callback 5936da84376SMilanka Ringwald * @param con_handle 5946da84376SMilanka Ringwald * @param service 5956da84376SMilanka Ringwald * @param uuid16 596692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 597692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 598692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 5996da84376SMilanka Ringwald */ 600711e6c80SMatthias 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); 6016da84376SMilanka Ringwald 6026da84376SMilanka Ringwald /** 60379188ed7SMilanka Ringwald * @brief The following four functions are used to discover all characteristics within the 60479188ed7SMilanka Ringwald * specified service or handle range, and return those that match the given UUID. 60579188ed7SMilanka Ringwald * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted. 60679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 6076da84376SMilanka Ringwald * @param callback 6086da84376SMilanka Ringwald * @param con_handle 6096da84376SMilanka Ringwald * @param service 6106da84376SMilanka Ringwald * @param uuid128 611692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 612692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 613692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6146da84376SMilanka Ringwald */ 615045d700dSDavid 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); 6163deb3ec6SMatthias Ringwald 6173deb3ec6SMatthias Ringwald /** 61879188ed7SMilanka Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 61979188ed7SMilanka Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 62079188ed7SMilanka Ringwald * 62179188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 6226da84376SMilanka Ringwald * @param callback 6236da84376SMilanka Ringwald * @param con_handle 6246da84376SMilanka Ringwald * @param characteristic 625692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 626692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 627692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6283deb3ec6SMatthias Ringwald */ 629711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 630a94d23eaSMatthias Ringwald 631a94d23eaSMatthias Ringwald 632a94d23eaSMatthias Ringwald /** 633a94d23eaSMatthias Ringwald * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. 634a94d23eaSMatthias Ringwald * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted. 635a94d23eaSMatthias Ringwald * 636a94d23eaSMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. 637a94d23eaSMatthias Ringwald * @param callback 638a94d23eaSMatthias Ringwald * @param con_handle 639a94d23eaSMatthias Ringwald * @param characteristic 640a94d23eaSMatthias Ringwald * @param service_id - context provided to callback in events 641a94d23eaSMatthias Ringwald * @param connection_id - contest provided to callback in events 642a94d23eaSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 643a94d23eaSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 644a94d23eaSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 645a94d23eaSMatthias Ringwald */ 646a94d23eaSMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 647a94d23eaSMatthias Ringwald gatt_client_characteristic_t * characteristic, uint16_t service_id, uint16_t connection_it); 6483deb3ec6SMatthias Ringwald 6493deb3ec6SMatthias Ringwald /** 65079188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 65179188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 65279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6536da84376SMilanka Ringwald * @param callback 6546da84376SMilanka Ringwald * @param con_handle 6556da84376SMilanka Ringwald * @param characteristic 656692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 657692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 658692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6593deb3ec6SMatthias Ringwald */ 660711e6c80SMatthias 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); 6616da84376SMilanka Ringwald 6626da84376SMilanka Ringwald /** 66379188ed7SMilanka Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 66479188ed7SMilanka Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 66579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6666da84376SMilanka Ringwald * @param callback 6676da84376SMilanka Ringwald * @param con_handle 668b45b7749SMilanka Ringwald * @param value_handle 669692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 670692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 671692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 6726da84376SMilanka Ringwald */ 673b45b7749SMilanka 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); 6743deb3ec6SMatthias Ringwald 6753deb3ec6SMatthias Ringwald /** 676e38d764eSMatthias Ringwald * @brief Reads the characteristic value using the characteristic's value handle. 677e38d764eSMatthias Ringwald * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 678e38d764eSMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 679e38d764eSMatthias Ringwald * @param callback 680e38d764eSMatthias Ringwald * @param con_handle 681e38d764eSMatthias Ringwald * @param value_handle 682e38d764eSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 683e38d764eSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 684e38d764eSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 685e38d764eSMatthias Ringwald */ 686e38d764eSMatthias Ringwald uint8_t gatt_client_read_value_of_characteristic_using_value_handle_with_context(btstack_packet_handler_t callback, 687e38d764eSMatthias Ringwald hci_con_handle_t con_handle, 688e38d764eSMatthias Ringwald uint16_t value_handle, 689e38d764eSMatthias Ringwald uint16_t service_id, 690e38d764eSMatthias Ringwald uint16_t connection_id); 691e38d764eSMatthias Ringwald 692e38d764eSMatthias Ringwald /** 69379188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 69479188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 69579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 6966da84376SMilanka Ringwald * @param callback 6976da84376SMilanka Ringwald * @param con_handle 6986da84376SMilanka Ringwald * @param start_handle 6996da84376SMilanka Ringwald * @param end_handle 7006da84376SMilanka Ringwald * @param uuid16 701692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 702692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 703692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7043deb3ec6SMatthias Ringwald */ 705711e6c80SMatthias 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); 7066da84376SMilanka Ringwald 7076da84376SMilanka Ringwald /** 70879188ed7SMilanka Ringwald * @brief Reads the characteric value of all characteristics with the uuid. 70979188ed7SMilanka Ringwald * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted. 71079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7116da84376SMilanka Ringwald * @param callback 7126da84376SMilanka Ringwald * @param con_handle 7136da84376SMilanka Ringwald * @param start_handle 7146da84376SMilanka Ringwald * @param end_handle 7156da84376SMilanka Ringwald * @param uuid128 716692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 717692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 718692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7196da84376SMilanka Ringwald */ 720045d700dSDavid 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); 7213deb3ec6SMatthias Ringwald 7223deb3ec6SMatthias Ringwald /** 72379188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 72479188ed7SMilanka Ringwald * The value will be returned in several blobs. 72579188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 72679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7276da84376SMilanka Ringwald * @param callback 7286da84376SMilanka Ringwald * @param con_handle 7296da84376SMilanka Ringwald * @param characteristic 730692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 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_long_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic); 7356da84376SMilanka Ringwald 7366da84376SMilanka Ringwald /** 73779188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 73879188ed7SMilanka Ringwald * The value will be returned in several blobs. 73979188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 74079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7416da84376SMilanka Ringwald * @param callback 7426da84376SMilanka Ringwald * @param con_handle 743b45b7749SMilanka Ringwald * @param value_handle 744692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 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 */ 748b45b7749SMilanka 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); 7496da84376SMilanka Ringwald 7506da84376SMilanka Ringwald /** 751691e02c2SMatthias Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 752691e02c2SMatthias Ringwald * The value will be returned in several blobs. 753691e02c2SMatthias Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 754691e02c2SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 755691e02c2SMatthias Ringwald * @param callback 756691e02c2SMatthias Ringwald * @param con_handle 757691e02c2SMatthias Ringwald * @param value_handle 758691e02c2SMatthias Ringwald * @param service_id - context provided to callback in events 759691e02c2SMatthias Ringwald * @param connection_id - contest provided to callback in events 760691e02c2SMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 761691e02c2SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 762691e02c2SMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 763691e02c2SMatthias Ringwald */ 764691e02c2SMatthias Ringwald uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_context(btstack_packet_handler_t callback, 765691e02c2SMatthias Ringwald hci_con_handle_t con_handle, uint16_t value_handle, 766691e02c2SMatthias Ringwald uint16_t service_id, uint16_t connection_id); 767691e02c2SMatthias Ringwald 768691e02c2SMatthias Ringwald /** 76979188ed7SMilanka Ringwald * @brief Reads the long characteristic value using the characteristic's value handle. 77079188ed7SMilanka Ringwald * The value will be returned in several blobs. 77179188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted. 77279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 7736da84376SMilanka Ringwald * @param callback 7746da84376SMilanka Ringwald * @param con_handle 775b45b7749SMilanka Ringwald * @param value_handle 7766da84376SMilanka Ringwald * @param offset 777692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 778692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 779692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7806da84376SMilanka Ringwald */ 781b45b7749SMilanka 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); 7823deb3ec6SMatthias Ringwald 7833deb3ec6SMatthias Ringwald /* 78479188ed7SMilanka Ringwald * @brief Read multiple characteristic values. 78579188ed7SMilanka Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 78679188ed7SMilanka Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 7876da84376SMilanka Ringwald * @param callback 7886da84376SMilanka Ringwald * @param con_handle 7896da84376SMilanka Ringwald * @param num_value_handles 7906da84376SMilanka Ringwald * @param value_handles list of handles 79179188ed7SMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 79279188ed7SMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 79379188ed7SMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 7943deb3ec6SMatthias Ringwald */ 795711e6c80SMatthias 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); 7963deb3ec6SMatthias Ringwald 797f125a8efSMatthias Ringwald /* 798f125a8efSMatthias Ringwald * @brief Read multiple varaible characteristic values. Only supported over LE Enhanced Bearer 799f125a8efSMatthias Ringwald * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event, 800f125a8efSMatthias Ringwald * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read. 801f125a8efSMatthias Ringwald * @param callback 802f125a8efSMatthias Ringwald * @param con_handle 803f125a8efSMatthias Ringwald * @param num_value_handles 804f125a8efSMatthias Ringwald * @param value_handles list of handles 805f125a8efSMatthias Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 806f125a8efSMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 807f125a8efSMatthias Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 808f125a8efSMatthias Ringwald */ 809f125a8efSMatthias 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); 810f125a8efSMatthias Ringwald 8113deb3ec6SMatthias Ringwald /** 81279188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle without 81379188ed7SMilanka Ringwald * an acknowledgment that the write was successfully performed. 8146da84376SMilanka Ringwald * @param con_handle 815b45b7749SMilanka Ringwald * @param value_handle 816b45b7749SMilanka Ringwald * @param value_length 8177e6f0853SDavid Lechner * @param value is copied on success and does not need to be retained 818692bf1adSMilanka Ringwald * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found 819692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready 820692bf1adSMilanka Ringwald * BTSTACK_ACL_BUFFERS_FULL , if L2CAP cannot send, there are no free ACL slots 821692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS , if query is successfully registered 8223deb3ec6SMatthias Ringwald */ 823b45b7749SMilanka 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); 8243deb3ec6SMatthias Ringwald 8253deb3ec6SMatthias Ringwald /** 82679188ed7SMilanka Ringwald * @brief Writes the authenticated characteristic value using the characteristic's value handle 82779188ed7SMilanka Ringwald * without an acknowledgment that the write was successfully performed. 82879188ed7SMilanka Ringwald * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success, 82979188ed7SMilanka Ringwald * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored. 8306da84376SMilanka Ringwald * @param callback 8316da84376SMilanka Ringwald * @param con_handle 8326da84376SMilanka Ringwald * @param value_handle 8336da84376SMilanka Ringwald * @param message_len 8346da84376SMilanka Ringwald * @param message is not copied, make sure memory is accessible until write is done 83540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 83640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 837692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 838692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8393deb3ec6SMatthias Ringwald */ 840b444aa75SMatthias Ringwald uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, 841b444aa75SMatthias Ringwald uint16_t message_len, uint8_t * message); 8423deb3ec6SMatthias Ringwald 8433deb3ec6SMatthias Ringwald /** 844b2468039SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 845b2468039SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 846b2468039SMilanka Ringwald * The write is successfully performed, if the event's att_status field is set to 847b2468039SMilanka Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 8486da84376SMilanka Ringwald * @param callback 8496da84376SMilanka Ringwald * @param con_handle 850b45b7749SMilanka Ringwald * @param value_handle 851b45b7749SMilanka Ringwald * @param value_length 852b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 85340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 85440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 855692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 856692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8573deb3ec6SMatthias Ringwald */ 858b45b7749SMilanka 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); 8596da84376SMilanka Ringwald 8606da84376SMilanka Ringwald /** 86179188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 86279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 863b444aa75SMatthias Ringwald * The write is successfully performed, if the event's att_status field is set to 864b444aa75SMatthias Ringwald * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes). 865b444aa75SMatthias Ringwald * @param callback 866b444aa75SMatthias Ringwald * @param con_handle 867b444aa75SMatthias Ringwald * @param value_handle 868b444aa75SMatthias Ringwald * @param value_length 869b444aa75SMatthias Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 870e38d764eSMatthias Ringwald * @param service_id - context provided to callback in events 871e38d764eSMatthias Ringwald * @param connection_id - contest provided to callback in events 872b444aa75SMatthias Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 873b444aa75SMatthias Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 874b444aa75SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 875b444aa75SMatthias Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 876b444aa75SMatthias Ringwald */ 877b444aa75SMatthias Ringwald uint8_t gatt_client_write_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, 878b444aa75SMatthias Ringwald uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id); 879b444aa75SMatthias Ringwald 880b444aa75SMatthias Ringwald /** 881b444aa75SMatthias Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 882b444aa75SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 88379188ed7SMilanka 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). 8846da84376SMilanka Ringwald * @param callback 8856da84376SMilanka Ringwald * @param con_handle 886b45b7749SMilanka Ringwald * @param value_handle 887b45b7749SMilanka Ringwald * @param value_length 888b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 88940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 89040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 891692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 892692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 8936da84376SMilanka Ringwald */ 894b45b7749SMilanka 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); 8956da84376SMilanka Ringwald 8966da84376SMilanka Ringwald /** 897b538fb89SMatthias Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 898b538fb89SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 899b538fb89SMatthias 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). 900b538fb89SMatthias Ringwald * @param callback 901b538fb89SMatthias Ringwald * @param con_handle 902b538fb89SMatthias Ringwald * @param value_handle 903b538fb89SMatthias Ringwald * @param value_length 904b538fb89SMatthias Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 905b538fb89SMatthias Ringwald * @param service_id - context provided to callback in events 906b538fb89SMatthias Ringwald * @param connection_id - contest provided to callback in events 907b538fb89SMatthias Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 908b538fb89SMatthias Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 909b538fb89SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 910b538fb89SMatthias Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 911b538fb89SMatthias Ringwald */ 912b538fb89SMatthias Ringwald uint8_t gatt_client_write_long_value_of_characteristic_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, 913b538fb89SMatthias Ringwald uint16_t value_length, uint8_t * value, uint16_t service_id, uint16_t connection_id); 914b538fb89SMatthias Ringwald 915b538fb89SMatthias Ringwald /** 91679188ed7SMilanka Ringwald * @brief Writes the characteristic value using the characteristic's value handle. 91779188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 91879188ed7SMilanka 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). 9196da84376SMilanka Ringwald * @param callback 9206da84376SMilanka Ringwald * @param con_handle 921b45b7749SMilanka Ringwald * @param value_handle 9226da84376SMilanka Ringwald * @param offset of value 923b45b7749SMilanka Ringwald * @param value_length 924b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 92540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 92640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 927692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 928692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9296da84376SMilanka Ringwald */ 930b45b7749SMilanka 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); 9313deb3ec6SMatthias Ringwald 9323deb3ec6SMatthias Ringwald /** 93379188ed7SMilanka Ringwald * @brief Writes of the long characteristic value using the characteristic's value handle. 93479188ed7SMilanka Ringwald * It uses server response to validate that the write was correctly received. 93579188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write. 93679188ed7SMilanka 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). 9376da84376SMilanka Ringwald * @param callback 9386da84376SMilanka Ringwald * @param con_handle 939b45b7749SMilanka Ringwald * @param value_handle 940b45b7749SMilanka Ringwald * @param value_length 941b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 94240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 94340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 944692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 945692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9463deb3ec6SMatthias Ringwald */ 947b45b7749SMilanka 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); 9483deb3ec6SMatthias Ringwald 9493deb3ec6SMatthias Ringwald /** 95079188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 95179188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 95279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9536da84376SMilanka Ringwald * @param callback 9546da84376SMilanka Ringwald * @param con_handle 9556da84376SMilanka Ringwald * @param descriptor 95640faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 95740faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 958692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 959692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9603deb3ec6SMatthias Ringwald */ 961711e6c80SMatthias 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); 9626da84376SMilanka Ringwald 9636da84376SMilanka Ringwald /** 96479188ed7SMilanka Ringwald * @brief Reads the characteristic descriptor using its handle. 96579188ed7SMilanka Ringwald * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 96679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9676da84376SMilanka Ringwald * @param callback 9686da84376SMilanka Ringwald * @param con_handle 9696da84376SMilanka Ringwald * @param descriptor 97040faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 97140faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 972692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 973692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9746da84376SMilanka Ringwald */ 975711e6c80SMatthias 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); 9763deb3ec6SMatthias Ringwald 9773deb3ec6SMatthias Ringwald /** 97879188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 97979188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 98079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9816da84376SMilanka Ringwald * @param callback 9826da84376SMilanka Ringwald * @param con_handle 983b45b7749SMilanka Ringwald * @param descriptor 98440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 98540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 986692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 987692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 9883deb3ec6SMatthias Ringwald */ 989711e6c80SMatthias 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); 9906da84376SMilanka Ringwald 9916da84376SMilanka Ringwald /** 99279188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 99379188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 99479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 9956da84376SMilanka Ringwald * @param callback 9966da84376SMilanka Ringwald * @param con_handle 9976da84376SMilanka Ringwald * @param descriptor_handle 99840faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 99940faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1000692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1001692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10026da84376SMilanka Ringwald */ 1003711e6c80SMatthias 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); 10046da84376SMilanka Ringwald 10056da84376SMilanka Ringwald /** 100679188ed7SMilanka Ringwald * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. 100779188ed7SMilanka Ringwald * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted. 100879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of read. 10096da84376SMilanka Ringwald * @param callback 10106da84376SMilanka Ringwald * @param con_handle 10116da84376SMilanka Ringwald * @param descriptor_handle 10126da84376SMilanka Ringwald * @param offset 101340faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 101440faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1015692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1016692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10176da84376SMilanka Ringwald */ 1018711e6c80SMatthias 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); 10193deb3ec6SMatthias Ringwald 10203deb3ec6SMatthias Ringwald /** 102179188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 102279188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 102379188ed7SMilanka 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). 10246da84376SMilanka Ringwald * @param callback 10256da84376SMilanka Ringwald * @param con_handle 10266da84376SMilanka Ringwald * @param descriptor 1027b45b7749SMilanka Ringwald * @param value_length 1028b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 102940faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 103040faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1031692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1032692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10333deb3ec6SMatthias Ringwald */ 1034b45b7749SMilanka 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); 10356da84376SMilanka Ringwald 10366da84376SMilanka Ringwald /** 103779188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 103879188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 103979188ed7SMilanka 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). 10406da84376SMilanka Ringwald * @param callback 10416da84376SMilanka Ringwald * @param con_handle 10426da84376SMilanka Ringwald * @param descriptor_handle 1043b45b7749SMilanka Ringwald * @param value_length 1044b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 104540faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 104640faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1047692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1048692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10496da84376SMilanka Ringwald */ 1050b45b7749SMilanka 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); 10516da84376SMilanka Ringwald 10526da84376SMilanka Ringwald /** 105379188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 105479188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 105579188ed7SMilanka 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). 10566da84376SMilanka Ringwald * @param callback 10576da84376SMilanka Ringwald * @param con_handle 10586da84376SMilanka Ringwald * @param descriptor 1059b45b7749SMilanka Ringwald * @param value_length 1060b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 106140faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 106240faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1063692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1064692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10656da84376SMilanka Ringwald */ 1066b45b7749SMilanka 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); 10676da84376SMilanka Ringwald 10686da84376SMilanka Ringwald /** 106979188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 107079188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 107179188ed7SMilanka 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). 10726da84376SMilanka Ringwald * @param callback 10736da84376SMilanka Ringwald * @param con_handle 10746da84376SMilanka Ringwald * @param descriptor_handle 1075b45b7749SMilanka Ringwald * @param value_length 1076b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 107740faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 107840faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1079692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1080692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10816da84376SMilanka Ringwald */ 1082b45b7749SMilanka 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); 10836da84376SMilanka Ringwald 10846da84376SMilanka Ringwald /** 108579188ed7SMilanka Ringwald * @brief Writes the characteristic descriptor using its handle. 108679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 108779188ed7SMilanka 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). 10886da84376SMilanka Ringwald * @param callback 10896da84376SMilanka Ringwald * @param con_handle 10906da84376SMilanka Ringwald * @param descriptor_handle 10916da84376SMilanka Ringwald * @param offset of value 1092b45b7749SMilanka Ringwald * @param value_length 1093b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 109440faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 109540faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1096692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1097692bf1adSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 10986da84376SMilanka Ringwald */ 1099b45b7749SMilanka 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); 11003deb3ec6SMatthias Ringwald 11013deb3ec6SMatthias Ringwald /** 110279188ed7SMilanka Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 110379188ed7SMilanka Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 110479188ed7SMilanka Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 110579188ed7SMilanka Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 110679188ed7SMilanka Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 110779188ed7SMilanka 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). 11086da84376SMilanka Ringwald * @param callback 11096da84376SMilanka Ringwald * @param con_handle 11106da84376SMilanka Ringwald * @param characteristic 1111b7e5512fSMilanka Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 111240faeb84SMilanka Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 111340faeb84SMilanka Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1114692bf1adSMilanka Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1115b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 1116b7e5512fSMilanka Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 11176b04f675SMilanka Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 1118b7e5512fSMilanka Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 11193deb3ec6SMatthias Ringwald */ 1120711e6c80SMatthias 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); 11219c662c9bSMatthias Ringwald 11229c662c9bSMatthias Ringwald /** 1123cb5b2b64SMatthias Ringwald * @brief Writes the client characteristic configuration of the specified characteristic. 1124cb5b2b64SMatthias Ringwald * It is used to subscribe for notifications or indications of the characteristic value. 1125cb5b2b64SMatthias Ringwald * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 1126cb5b2b64SMatthias Ringwald * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value. 1127cb5b2b64SMatthias Ringwald * The GATT_EVENT_QUERY_COMPLETE event marks the end of write. 1128cb5b2b64SMatthias 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). 1129cb5b2b64SMatthias Ringwald * @param callback 1130cb5b2b64SMatthias Ringwald * @param con_handle 1131cb5b2b64SMatthias Ringwald * @param characteristic 1132cb5b2b64SMatthias Ringwald * @param configuration GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 1133cb5b2b64SMatthias Ringwald * @param service_id - context provided to callback in events 1134cb5b2b64SMatthias Ringwald * @param connection_id - contest provided to callback in events 1135cb5b2b64SMatthias Ringwald * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if no HCI connection for con_handle is found 1136cb5b2b64SMatthias Ringwald * BTSTACK_MEMORY_ALLOC_FAILED if no GATT client for con_handle could be allocated 1137cb5b2b64SMatthias Ringwald * GATT_CLIENT_IN_WRONG_STATE if GATT client is not ready 1138cb5b2b64SMatthias Ringwald * GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED if configuring notification, but characteristic has no notification property set 1139cb5b2b64SMatthias Ringwald * GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED if configuring indication, but characteristic has no indication property set 1140cb5b2b64SMatthias Ringwald * ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if configuration is invalid 1141cb5b2b64SMatthias Ringwald * ERROR_CODE_SUCCESS if query is successfully registered 1142cb5b2b64SMatthias Ringwald */ 1143cb5b2b64SMatthias Ringwald uint8_t gatt_client_write_client_characteristic_configuration_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, 1144cb5b2b64SMatthias Ringwald gatt_client_characteristic_t * characteristic, uint16_t configuration, uint16_t service_id, uint16_t connection_id); 1145cb5b2b64SMatthias Ringwald 1146cb5b2b64SMatthias Ringwald /** 114758e8c9f5SMatthias Ringwald * @brief Register for changes to the Service Changed and Database Hash Characteristics of the remote GATT Service 1148842492f0SMatthias Ringwald * * 114958e8c9f5SMatthias Ringwald * When configured, GATT_EVENT_QUERY_COMPLETE event is emitted 115058e8c9f5SMatthias Ringwald * If supported, the Database Hash is read as well 115158e8c9f5SMatthias Ringwald * 1152842492f0SMatthias Ringwald * Requires ENABLE_GATT_CLIENT_SERVICE_CHANGED 1153842492f0SMatthias Ringwald * 115458e8c9f5SMatthias Ringwald * @param callback 115558e8c9f5SMatthias Ringwald */ 115658e8c9f5SMatthias Ringwald void gatt_client_add_service_changed_handler(btstack_packet_callback_registration_t * callback); 115758e8c9f5SMatthias Ringwald 115858e8c9f5SMatthias Ringwald /** 115958e8c9f5SMatthias Ringwald * @brief Remove callback for service changes 1160842492f0SMatthias Ringwald * 1161842492f0SMatthias Ringwald * Requires ENABLE_GATT_CLIENT_SERVICE_CHANGED 1162842492f0SMatthias Ringwald * 116358e8c9f5SMatthias Ringwald * @param callback 116458e8c9f5SMatthias Ringwald */ 116558e8c9f5SMatthias Ringwald void gatt_client_remove_service_changed_handler(btstack_packet_callback_registration_t * callback); 116658e8c9f5SMatthias Ringwald 116758e8c9f5SMatthias Ringwald /** 116879188ed7SMilanka Ringwald * @brief Register for notifications and indications of a characteristic enabled by 116979188ed7SMilanka Ringwald * the gatt_client_write_client_characteristic_configuration function. 11709c662c9bSMatthias Ringwald * @param notification struct used to store registration 11716da84376SMilanka Ringwald * @param callback 1172b3f03c84SMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 1173b3f03c84SMatthias Ringwald * @param characteristic or NULL to receive updates for all characteristics 11749c662c9bSMatthias Ringwald */ 11756da84376SMilanka 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); 11763deb3ec6SMatthias Ringwald 11773deb3ec6SMatthias Ringwald /** 117879188ed7SMilanka Ringwald * @brief Stop listening to characteristic value updates registered with 117979188ed7SMilanka Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 11801f734b5fSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 11811f734b5fSMatthias Ringwald */ 11821f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification); 11831f734b5fSMatthias Ringwald 11841f734b5fSMatthias Ringwald /** 11851a4874dcSMatthias Ringwald * @brief Register for notifications and indications of characteristic in a service 11861a4874dcSMatthias Ringwald * the gatt_client_write_client_characteristic_configuration function. 11871a4874dcSMatthias Ringwald * @param notification struct used to store registration 11881a4874dcSMatthias Ringwald * @param callback 11891a4874dcSMatthias Ringwald * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices 11901a4874dcSMatthias Ringwald * @param service 11911a4874dcSMatthias Ringwald * @param end_handle 11921a4874dcSMatthias Ringwald * @param service_id - context provided to callback in events 11931a4874dcSMatthias Ringwald * @param connection_id - contest provided to callback in events 11941a4874dcSMatthias Ringwald */ 11951a4874dcSMatthias Ringwald void gatt_client_listen_for_service_characteristic_value_updates(gatt_client_service_notification_t * notification, 11961a4874dcSMatthias Ringwald btstack_packet_handler_t callback, 11971a4874dcSMatthias Ringwald hci_con_handle_t con_handle, 11981a4874dcSMatthias Ringwald gatt_client_service_t * service, 11991a4874dcSMatthias Ringwald uint16_t service_id, 12001a4874dcSMatthias Ringwald uint16_t connection_id); 12011a4874dcSMatthias Ringwald 12021a4874dcSMatthias Ringwald /** 12031a4874dcSMatthias Ringwald * @brief Stop listening to characteristic value updates for registered service with 12041a4874dcSMatthias Ringwald * the gatt_client_listen_for_characteristic_value_updates function. 12051a4874dcSMatthias Ringwald * @param notification struct used in gatt_client_listen_for_characteristic_value_updates 12061a4874dcSMatthias Ringwald */ 12071a4874dcSMatthias Ringwald void gatt_client_stop_listening_for_service_characteristic_value_updates(gatt_client_service_notification_t * notification); 12081a4874dcSMatthias Ringwald 12091a4874dcSMatthias Ringwald 12101a4874dcSMatthias Ringwald /** 121179188ed7SMilanka Ringwald * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction. 121279188ed7SMilanka Ringwald * Call the gatt_client_execute_write function to commit the transaction. 12136da84376SMilanka Ringwald * @param callback 12146da84376SMilanka Ringwald * @param con_handle 12156da84376SMilanka Ringwald * @param attribute_handle 12166da84376SMilanka Ringwald * @param offset of value 1217b45b7749SMilanka Ringwald * @param value_length 1218b45b7749SMilanka Ringwald * @param value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received 12193deb3ec6SMatthias Ringwald */ 1220b45b7749SMilanka 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); 12213deb3ec6SMatthias Ringwald 12223deb3ec6SMatthias Ringwald /** 12236da84376SMilanka Ringwald * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received. 12246da84376SMilanka Ringwald * @param callback 12256da84376SMilanka Ringwald * @param con_handle 122640faeb84SMilanka Ringwald * @return status 12273deb3ec6SMatthias Ringwald */ 1228711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 12293deb3ec6SMatthias Ringwald 12303deb3ec6SMatthias Ringwald /** 12316da84376SMilanka Ringwald * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received. 12326da84376SMilanka Ringwald * @param callback 12336da84376SMilanka Ringwald * @param con_handle 123440faeb84SMilanka Ringwald * @return status 12353deb3ec6SMatthias Ringwald */ 1236711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 12373deb3ec6SMatthias Ringwald 123859d34cd2SMatthias Ringwald /** 123953e9c18fSMatthias Ringwald * @brief Request callback when regular gatt query can be sent 124053e9c18fSMatthias Ringwald * @note callback might happen during call to this function 124153e9c18fSMatthias Ringwald * @param callback_registration to point to callback function and context information 124253e9c18fSMatthias Ringwald * @param con_handle 124353e9c18fSMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 124453e9c18fSMatthias Ringwald */ 124553e9c18fSMatthias Ringwald uint8_t gatt_client_request_to_send_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 124653e9c18fSMatthias Ringwald 124753e9c18fSMatthias Ringwald /** 124848553f67SDirk Helbig * @brief Remove queued callback for regular gatt queries, to be used on disconnect for example 124948553f67SDirk Helbig * @param callback_registration 125048553f67SDirk Helbig * @param con_handle 125148553f67SDirk Helbig * @return ERROR_CODE_SUCCESS if ok 125248553f67SDirk Helbig */ 125348553f67SDirk Helbig uint8_t gatt_client_remove_gatt_query(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 125448553f67SDirk Helbig 125548553f67SDirk Helbig /** 125659d34cd2SMatthias Ringwald * @brief Request callback when writing characteristic value without response is possible 125753e9c18fSMatthias Ringwald * @note callback might happen during call to this function 125859d34cd2SMatthias Ringwald * @param callback_registration to point to callback function and context information 125959d34cd2SMatthias Ringwald * @param con_handle 126059d34cd2SMatthias Ringwald * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered 126159d34cd2SMatthias Ringwald */ 126259d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle); 126359d34cd2SMatthias Ringwald 126459d34cd2SMatthias Ringwald 126559d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually 126659d34cd2SMatthias Ringwald /** 126759d34cd2SMatthias Ringwald * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees 126859d34cd2SMatthias Ringwald * a single successful gatt_client_write_value_of_characteristic_without_response call. 126959d34cd2SMatthias Ringwald * @deprecated please use gatt_client_request_to_write_without_response instead 127059d34cd2SMatthias Ringwald * @param callback 127159d34cd2SMatthias Ringwald * @param con_handle 127259d34cd2SMatthias Ringwald * @return status 127359d34cd2SMatthias Ringwald */ 127459d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle); 127559d34cd2SMatthias Ringwald 1276e80543a7SMatthias Ringwald /** 1277e80543a7SMatthias Ringwald * @brief Map ATT Error Code to (extended) Error Codes 1278e80543a7SMatthias Ringwald * @param att_error_code 1279e80543a7SMatthias Ringwald * @return 1280e80543a7SMatthias Ringwald */ 1281e80543a7SMatthias Ringwald uint8_t gatt_client_att_status_to_error_code(uint8_t att_error_code); 128259d34cd2SMatthias Ringwald 12833deb3ec6SMatthias Ringwald /* API_END */ 12843deb3ec6SMatthias Ringwald 12856ba2ad22SMatthias Ringwald // used by generated btstack_event.c 12866ba2ad22SMatthias Ringwald 1287313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service); 1288313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic); 1289313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor); 12906ba2ad22SMatthias Ringwald 1291a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION 1292a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size); 129340faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client); 1294a6121b51SMilanka Ringwald #endif 1295a6121b51SMilanka Ringwald 1296bbb8e698SMatthias Ringwald // used for testing, default is ON 1297bbb8e698SMatthias Ringwald void gatt_client_le_enhanced_enable(bool enable); 1298bbb8e698SMatthias Ringwald 12993deb3ec6SMatthias Ringwald #if defined __cplusplus 13003deb3ec6SMatthias Ringwald } 13013deb3ec6SMatthias Ringwald #endif 13023deb3ec6SMatthias Ringwald 13033deb3ec6SMatthias Ringwald #endif 1304