xref: /btstack/src/ble/gatt_client.h (revision 59d34cd29ebe9f8526ac56be348591c9a588fbdc)
13deb3ec6SMatthias Ringwald /*
23deb3ec6SMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
33deb3ec6SMatthias Ringwald  *
43deb3ec6SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
53deb3ec6SMatthias Ringwald  * modification, are permitted provided that the following conditions
63deb3ec6SMatthias Ringwald  * are met:
73deb3ec6SMatthias Ringwald  *
83deb3ec6SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
93deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
103deb3ec6SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
113deb3ec6SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
123deb3ec6SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
133deb3ec6SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
143deb3ec6SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
153deb3ec6SMatthias Ringwald  *    from this software without specific prior written permission.
163deb3ec6SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
173deb3ec6SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
183deb3ec6SMatthias Ringwald  *    monetary gain.
193deb3ec6SMatthias Ringwald  *
203deb3ec6SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
213deb3ec6SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
223deb3ec6SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232fca4dadSMilanka Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242fca4dadSMilanka Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
253deb3ec6SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
263deb3ec6SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
273deb3ec6SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
283deb3ec6SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
293deb3ec6SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
303deb3ec6SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
313deb3ec6SMatthias Ringwald  * SUCH DAMAGE.
323deb3ec6SMatthias Ringwald  *
333deb3ec6SMatthias Ringwald  * Please inquire about commercial licensing options at
343deb3ec6SMatthias Ringwald  * [email protected]
353deb3ec6SMatthias Ringwald  *
363deb3ec6SMatthias Ringwald  */
373deb3ec6SMatthias Ringwald 
38fe5a6c4eSMilanka Ringwald /**
39fe5a6c4eSMilanka Ringwald  * @title GATT Client
40fe5a6c4eSMilanka Ringwald  *
41fe5a6c4eSMilanka Ringwald  */
423deb3ec6SMatthias Ringwald 
433deb3ec6SMatthias Ringwald #ifndef btstack_gatt_client_h
443deb3ec6SMatthias Ringwald #define btstack_gatt_client_h
453deb3ec6SMatthias Ringwald 
463deb3ec6SMatthias Ringwald #include "hci.h"
473deb3ec6SMatthias Ringwald 
483deb3ec6SMatthias Ringwald #if defined __cplusplus
493deb3ec6SMatthias Ringwald extern "C" {
503deb3ec6SMatthias Ringwald #endif
513deb3ec6SMatthias Ringwald 
523deb3ec6SMatthias Ringwald typedef enum {
533deb3ec6SMatthias Ringwald     P_READY,
543deb3ec6SMatthias Ringwald     P_W2_SEND_SERVICE_QUERY,
553deb3ec6SMatthias Ringwald     P_W4_SERVICE_QUERY_RESULT,
563deb3ec6SMatthias Ringwald     P_W2_SEND_SERVICE_WITH_UUID_QUERY,
573deb3ec6SMatthias Ringwald     P_W4_SERVICE_WITH_UUID_RESULT,
583deb3ec6SMatthias Ringwald 
593deb3ec6SMatthias Ringwald     P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY,
603deb3ec6SMatthias Ringwald     P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT,
613deb3ec6SMatthias Ringwald     P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY,
623deb3ec6SMatthias Ringwald     P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT,
633deb3ec6SMatthias Ringwald 
643deb3ec6SMatthias Ringwald     P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY,
653deb3ec6SMatthias Ringwald     P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT,
663deb3ec6SMatthias Ringwald 
673deb3ec6SMatthias Ringwald     P_W2_SEND_INCLUDED_SERVICE_QUERY,
683deb3ec6SMatthias Ringwald     P_W4_INCLUDED_SERVICE_QUERY_RESULT,
693deb3ec6SMatthias Ringwald     P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY,
703deb3ec6SMatthias Ringwald     P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT,
713deb3ec6SMatthias Ringwald 
723deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY,
733deb3ec6SMatthias Ringwald     P_W4_READ_CHARACTERISTIC_VALUE_RESULT,
743deb3ec6SMatthias Ringwald 
753deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BLOB_QUERY,
763deb3ec6SMatthias Ringwald     P_W4_READ_BLOB_RESULT,
773deb3ec6SMatthias Ringwald 
783deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BY_TYPE_REQUEST,
793deb3ec6SMatthias Ringwald     P_W4_READ_BY_TYPE_RESPONSE,
803deb3ec6SMatthias Ringwald 
813deb3ec6SMatthias Ringwald     P_W2_SEND_READ_MULTIPLE_REQUEST,
823deb3ec6SMatthias Ringwald     P_W4_READ_MULTIPLE_RESPONSE,
833deb3ec6SMatthias Ringwald 
843deb3ec6SMatthias Ringwald     P_W2_SEND_WRITE_CHARACTERISTIC_VALUE,
853deb3ec6SMatthias Ringwald     P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT,
863deb3ec6SMatthias Ringwald 
873deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE,
883deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_RESULT,
893deb3ec6SMatthias Ringwald     P_W2_PREPARE_RELIABLE_WRITE,
903deb3ec6SMatthias Ringwald     P_W4_PREPARE_RELIABLE_WRITE_RESULT,
913deb3ec6SMatthias Ringwald 
923deb3ec6SMatthias Ringwald     P_W2_EXECUTE_PREPARED_WRITE,
933deb3ec6SMatthias Ringwald     P_W4_EXECUTE_PREPARED_WRITE_RESULT,
943deb3ec6SMatthias Ringwald     P_W2_CANCEL_PREPARED_WRITE,
953deb3ec6SMatthias Ringwald     P_W4_CANCEL_PREPARED_WRITE_RESULT,
963deb3ec6SMatthias Ringwald     P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH,
973deb3ec6SMatthias Ringwald     P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT,
983deb3ec6SMatthias Ringwald 
99abdc9fb5SMatthias Ringwald #ifdef ENABLE_GATT_FIND_INFORMATION_FOR_CCC_DISCOVERY
100abdc9fb5SMatthias Ringwald     P_W2_SEND_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
101abdc9fb5SMatthias Ringwald     P_W4_FIND_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
102abdc9fb5SMatthias Ringwald #else
1033deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
1043deb3ec6SMatthias Ringwald     P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
105abdc9fb5SMatthias Ringwald #endif
1063deb3ec6SMatthias Ringwald     P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION,
1073deb3ec6SMatthias Ringwald     P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT,
1083deb3ec6SMatthias Ringwald 
1093deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY,
1103deb3ec6SMatthias Ringwald     P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT,
1113deb3ec6SMatthias Ringwald 
1123deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY,
1133deb3ec6SMatthias Ringwald     P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT,
1143deb3ec6SMatthias Ringwald 
1153deb3ec6SMatthias Ringwald     P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR,
1163deb3ec6SMatthias Ringwald     P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1173deb3ec6SMatthias Ringwald 
1183deb3ec6SMatthias Ringwald     // all long writes use this
1193deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR,
1203deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1213deb3ec6SMatthias Ringwald     P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR,
1223deb3ec6SMatthias Ringwald     P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1233deb3ec6SMatthias Ringwald 
1243deb3ec6SMatthias Ringwald     // gatt reliable write API use this (manual version of the above)
1253deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE_SINGLE,
1263deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_SINGLE_RESULT,
1273deb3ec6SMatthias Ringwald 
128793cf6ceSMatthias Ringwald     P_W4_IDENTITY_RESOLVING,
1293deb3ec6SMatthias Ringwald     P_W4_CMAC_READY,
1303deb3ec6SMatthias Ringwald     P_W4_CMAC_RESULT,
1313deb3ec6SMatthias Ringwald     P_W2_SEND_SIGNED_WRITE,
1323deb3ec6SMatthias Ringwald     P_W4_SEND_SINGED_WRITE_DONE,
1333deb3ec6SMatthias Ringwald } gatt_client_state_t;
1343deb3ec6SMatthias Ringwald 
1353deb3ec6SMatthias Ringwald 
1363deb3ec6SMatthias Ringwald typedef enum{
1373deb3ec6SMatthias Ringwald     SEND_MTU_EXCHANGE,
1383deb3ec6SMatthias Ringwald     SENT_MTU_EXCHANGE,
1395cf6c434SJakob Krantz     MTU_EXCHANGED,
1405cf6c434SJakob Krantz     MTU_AUTO_EXCHANGE_DISABLED
1413deb3ec6SMatthias Ringwald } gatt_client_mtu_t;
1423deb3ec6SMatthias Ringwald 
1433deb3ec6SMatthias Ringwald typedef struct gatt_client{
144665d90f2SMatthias Ringwald     btstack_linked_item_t    item;
1453deb3ec6SMatthias Ringwald     // TODO: rename gatt_client_state -> state
1463deb3ec6SMatthias Ringwald     gatt_client_state_t gatt_client_state;
1473deb3ec6SMatthias Ringwald 
1489c662c9bSMatthias Ringwald     // user callback
1499c662c9bSMatthias Ringwald     btstack_packet_handler_t callback;
1503deb3ec6SMatthias Ringwald 
15147181045SMatthias Ringwald     // can write without response callback
15247181045SMatthias Ringwald     btstack_packet_handler_t write_without_response_callback;
15347181045SMatthias Ringwald 
154*59d34cd2SMatthias Ringwald     // can write without response requests
155*59d34cd2SMatthias Ringwald     btstack_linked_list_t write_without_response_requests;
156*59d34cd2SMatthias Ringwald 
157fc64f94aSMatthias Ringwald     hci_con_handle_t con_handle;
158f4b33574SMatthias Ringwald 
1593deb3ec6SMatthias Ringwald     uint16_t          mtu;
1603deb3ec6SMatthias Ringwald     gatt_client_mtu_t mtu_state;
1613deb3ec6SMatthias Ringwald 
1623deb3ec6SMatthias Ringwald     uint16_t uuid16;
1633deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
1643deb3ec6SMatthias Ringwald 
1653deb3ec6SMatthias Ringwald     uint16_t start_group_handle;
1663deb3ec6SMatthias Ringwald     uint16_t end_group_handle;
1673deb3ec6SMatthias Ringwald 
1683deb3ec6SMatthias Ringwald     uint16_t query_start_handle;
1693deb3ec6SMatthias Ringwald     uint16_t query_end_handle;
1703deb3ec6SMatthias Ringwald 
1713deb3ec6SMatthias Ringwald     uint8_t  characteristic_properties;
1723deb3ec6SMatthias Ringwald     uint16_t characteristic_start_handle;
1733deb3ec6SMatthias Ringwald 
1743deb3ec6SMatthias Ringwald     uint16_t attribute_handle;
1753deb3ec6SMatthias Ringwald     uint16_t attribute_offset;
1763deb3ec6SMatthias Ringwald     uint16_t attribute_length;
1773deb3ec6SMatthias Ringwald     uint8_t* attribute_value;
1783deb3ec6SMatthias Ringwald 
1793deb3ec6SMatthias Ringwald     // read multiple characteristic values
1803deb3ec6SMatthias Ringwald     uint16_t    read_multiple_handle_count;
1813deb3ec6SMatthias Ringwald     uint16_t  * read_multiple_handles;
1823deb3ec6SMatthias Ringwald 
1833deb3ec6SMatthias Ringwald     uint16_t client_characteristic_configuration_handle;
1843deb3ec6SMatthias Ringwald     uint8_t  client_characteristic_configuration_value[2];
1853deb3ec6SMatthias Ringwald 
1863deb3ec6SMatthias Ringwald     uint8_t  filter_with_uuid;
1873deb3ec6SMatthias Ringwald     uint8_t  send_confirmation;
1883deb3ec6SMatthias Ringwald 
1893deb3ec6SMatthias Ringwald     int      le_device_index;
1903deb3ec6SMatthias Ringwald     uint8_t  cmac[8];
1913deb3ec6SMatthias Ringwald 
192ec820d77SMatthias Ringwald     btstack_timer_source_t gc_timeout;
193f4b33574SMatthias Ringwald 
194f4b33574SMatthias Ringwald     uint8_t  security_counter;
1953503dc74SMatthias Ringwald     uint8_t  wait_for_authentication_complete;
196f4b33574SMatthias Ringwald     uint8_t  pending_error_code;
197f4b33574SMatthias Ringwald 
1988918bbdaSMatthias Ringwald     bool     reencryption_active;
1998918bbdaSMatthias Ringwald     uint8_t  reencryption_result;
2008918bbdaSMatthias Ringwald 
2011dfae9c7SMatthias Ringwald     gap_security_level_t security_level;
2021dfae9c7SMatthias Ringwald 
2033deb3ec6SMatthias Ringwald } gatt_client_t;
2043deb3ec6SMatthias Ringwald 
2059c662c9bSMatthias Ringwald typedef struct gatt_client_notification {
206665d90f2SMatthias Ringwald     btstack_linked_item_t    item;
207b6e96f14SMatthias Ringwald     btstack_packet_handler_t callback;
208711e6c80SMatthias Ringwald     hci_con_handle_t con_handle;
2099c662c9bSMatthias Ringwald     uint16_t attribute_handle;
2109c662c9bSMatthias Ringwald } gatt_client_notification_t;
2113deb3ec6SMatthias Ringwald 
2123deb3ec6SMatthias Ringwald /* API_START */
2133deb3ec6SMatthias Ringwald 
214d25c33e5SMatthias Ringwald typedef struct {
2153deb3ec6SMatthias Ringwald     uint16_t start_group_handle;
2163deb3ec6SMatthias Ringwald     uint16_t end_group_handle;
2173deb3ec6SMatthias Ringwald     uint16_t uuid16;
2183deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
219d25c33e5SMatthias Ringwald } gatt_client_service_t;
2203deb3ec6SMatthias Ringwald 
221d25c33e5SMatthias Ringwald typedef struct {
2223deb3ec6SMatthias Ringwald     uint16_t start_handle;
2233deb3ec6SMatthias Ringwald     uint16_t value_handle;
2243deb3ec6SMatthias Ringwald     uint16_t end_handle;
2253deb3ec6SMatthias Ringwald     uint16_t properties;
2263deb3ec6SMatthias Ringwald     uint16_t uuid16;
2273deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
228d25c33e5SMatthias Ringwald } gatt_client_characteristic_t;
2293deb3ec6SMatthias Ringwald 
230d25c33e5SMatthias Ringwald typedef struct {
2313deb3ec6SMatthias Ringwald     uint16_t handle;
2323deb3ec6SMatthias Ringwald     uint16_t uuid16;
2333deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
234d25c33e5SMatthias Ringwald } gatt_client_characteristic_descriptor_t;
2353deb3ec6SMatthias Ringwald 
2363deb3ec6SMatthias Ringwald /**
2373deb3ec6SMatthias Ringwald  * @brief Set up GATT client.
2383deb3ec6SMatthias Ringwald  */
2393deb3ec6SMatthias Ringwald void gatt_client_init(void);
2403deb3ec6SMatthias Ringwald 
2413deb3ec6SMatthias Ringwald /**
24211279da7SMatthias Ringwald  * @brief Set minimum required security level for GATT Client
24311279da7SMatthias Ringwald  * @note  The Bluetooth specification makes the GATT Server responsible to check for security.
244b11289a8SMatthias Ringwald  *        This allows an attacker to spoof an existing device with a GATT Servers, but skip the authentication part.
245b11289a8SMatthias Ringwald  *        If your application is exchanging sensitive data with a remote device, you would need to manually check
246b11289a8SMatthias Ringwald  *        the security level before sending/receive such data.
247b11289a8SMatthias Ringwald  *        With level > 0, the GATT Client triggers authentication for all GATT Requests and defers any exchange
248b11289a8SMatthias Ringwald  *        until the required security level is established.
249b11289a8SMatthias Ringwald  *        gatt_client_request_can_write_without_response_event does not trigger authentication
250*59d34cd2SMatthias Ringwald  *        gatt_client_request_to_write_without_response does not trigger authentication
25111279da7SMatthias Ringwald  *  @pram level, default LEVEL_0 (no encryption required)
25211279da7SMatthias Ringwald  */
25311279da7SMatthias Ringwald void gatt_client_set_required_security_level(gap_security_level_t level);
25411279da7SMatthias Ringwald 
25511279da7SMatthias Ringwald /**
25679188ed7SMilanka Ringwald  * @brief MTU is available after the first query has completed. If status is equal to ERROR_CODE_SUCCESS, it returns the real value,
25779188ed7SMilanka Ringwald  * otherwise the default value ATT_DEFAULT_MTU (see bluetooth.h).
2586da84376SMilanka Ringwald  * @param  con_handle
2596da84376SMilanka Ringwald  * @param  mtu
26040faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
26140faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
262692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if MTU is not exchanged and MTU auto-exchange is disabled
263692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
2643deb3ec6SMatthias Ringwald  */
265fc64f94aSMatthias Ringwald uint8_t gatt_client_get_mtu(hci_con_handle_t con_handle, uint16_t * mtu);
2663deb3ec6SMatthias Ringwald 
2673deb3ec6SMatthias Ringwald /**
26879188ed7SMilanka Ringwald  * @brief Sets whether a MTU Exchange Request shall be automatically send before the
26979188ed7SMilanka Ringwald  * first attribute read request is send. Default is enabled.
2706da84376SMilanka Ringwald  * @param enabled
2715cf6c434SJakob Krantz  */
2725cf6c434SJakob Krantz void gatt_client_mtu_enable_auto_negotiation(uint8_t enabled);
2735cf6c434SJakob Krantz 
2745cf6c434SJakob Krantz /**
27579188ed7SMilanka Ringwald  * @brief Sends a MTU Exchange Request, this allows for the client to exchange MTU
27679188ed7SMilanka Ringwald  * when gatt_client_mtu_enable_auto_negotiation is disabled.
2776da84376SMilanka Ringwald  * @param  callback
2786da84376SMilanka Ringwald  * @param  con_handle
2795cf6c434SJakob Krantz  */
2805cf6c434SJakob Krantz void gatt_client_send_mtu_negotiation(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
2815cf6c434SJakob Krantz 
2825cf6c434SJakob Krantz /**
283aacf1b1aSMilanka Ringwald  * @brief Returns 1 if the GATT client is ready to receive a query. It is used with daemon.
2846da84376SMilanka Ringwald  * @param  con_handle
285692bf1adSMilanka Ringwald  * @return is_ready_status     0 - if no GATT client for con_handle is found, or is not ready, otherwise 1
2863deb3ec6SMatthias Ringwald  */
287fc64f94aSMatthias Ringwald int gatt_client_is_ready(hci_con_handle_t con_handle);
2883deb3ec6SMatthias Ringwald 
2893deb3ec6SMatthias Ringwald /**
29079188ed7SMilanka Ringwald  * @brief Discovers all primary services.
29179188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
29279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
2936da84376SMilanka Ringwald  * @param  callback
2946da84376SMilanka Ringwald  * @param  con_handle
295692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
296692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
297692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
2983deb3ec6SMatthias Ringwald  */
299711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
3003deb3ec6SMatthias Ringwald 
3013deb3ec6SMatthias Ringwald /**
30279188ed7SMilanka Ringwald  * @brief Discovers all secondary services.
30379188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
30479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3058d1f34d3SMatheus Eduardo Garbelini  * @param  callback
3068d1f34d3SMatheus Eduardo Garbelini  * @param  con_handle
3078d1f34d3SMatheus Eduardo Garbelini  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
3088d1f34d3SMatheus Eduardo Garbelini  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
3098d1f34d3SMatheus Eduardo Garbelini  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3108d1f34d3SMatheus Eduardo Garbelini  */
3118d1f34d3SMatheus Eduardo Garbelini uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
3128d1f34d3SMatheus Eduardo Garbelini 
3138d1f34d3SMatheus Eduardo Garbelini /**
31479188ed7SMilanka Ringwald  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
31579188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
31679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3176da84376SMilanka Ringwald  * @param callback
3186da84376SMilanka Ringwald  * @param con_handle
3196da84376SMilanka Ringwald  * @param uuid16
320692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
321692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
322692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3233deb3ec6SMatthias Ringwald  */
324711e6c80SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16);
3256da84376SMilanka Ringwald 
3266da84376SMilanka Ringwald /**
32779188ed7SMilanka Ringwald  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times.
32879188ed7SMilanka Ringwald  * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted.
32979188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3306da84376SMilanka Ringwald  * @param  callback
3316da84376SMilanka Ringwald  * @param  con_handle
3326da84376SMilanka Ringwald  * @param  uuid128
333692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
334692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
335692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3366da84376SMilanka Ringwald  */
3376da84376SMilanka 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);
3383deb3ec6SMatthias Ringwald 
3393deb3ec6SMatthias Ringwald /**
34079188ed7SMilanka Ringwald  * @brief Finds included services within the specified service.
34179188ed7SMilanka Ringwald  * For each found included service a GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT event will be emitted.
34279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
34379188ed7SMilanka Ringwald  * Information about included service type (primary/secondary) can be retrieved either by sending
34479188ed7SMilanka Ringwald  * an ATT find information request for the returned start group handle
34579188ed7SMilanka Ringwald  * (returning the handle and the UUID for primary or secondary service) or by comparing the service
34679188ed7SMilanka Ringwald  * to the list of all primary services.
3476da84376SMilanka Ringwald  * @param  callback
3486da84376SMilanka Ringwald  * @param  con_handle
3496da84376SMilanka Ringwald  * @param  service
350692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
351692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
352692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3533deb3ec6SMatthias Ringwald  */
354711e6c80SMatthias 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);
3553deb3ec6SMatthias Ringwald 
3563deb3ec6SMatthias Ringwald /**
35779188ed7SMilanka Ringwald  * @brief Discovers all characteristics within the specified service.
35879188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will be emited.
35979188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3606da84376SMilanka Ringwald  * @param  callback
3616da84376SMilanka Ringwald  * @param  con_handle
3626da84376SMilanka Ringwald  * @param  service
363692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
364692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
365692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3663deb3ec6SMatthias Ringwald  */
367711e6c80SMatthias 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);
3683deb3ec6SMatthias Ringwald 
3693deb3ec6SMatthias Ringwald /**
37079188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within
37179188ed7SMilanka Ringwald  * the specified service or handle range, and return those that match the given UUID.
37279188ed7SMilanka Ringwald  *
37379188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
37479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3756da84376SMilanka Ringwald  * @param  callback
3766da84376SMilanka Ringwald  * @param  con_handle
3776da84376SMilanka Ringwald  * @param  start_handle
3786da84376SMilanka Ringwald  * @param  end_handle
3796da84376SMilanka Ringwald  * @param  uuid16
380692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
381692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
382692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3833deb3ec6SMatthias Ringwald  */
384711e6c80SMatthias 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);
3856da84376SMilanka Ringwald 
3866da84376SMilanka Ringwald /**
38779188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within the
38879188ed7SMilanka Ringwald  * specified service or handle range, and return those that match the given UUID.
38979188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
39079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
3916da84376SMilanka Ringwald  * @param  callback
3926da84376SMilanka Ringwald  * @param  con_handle
3936da84376SMilanka Ringwald  * @param  start_handle
3946da84376SMilanka Ringwald  * @param  end_handle
3956da84376SMilanka Ringwald  * @param  uuid128
396692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
397692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
398692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
3996da84376SMilanka Ringwald  */
400045d700dSDavid 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);
4016da84376SMilanka Ringwald 
4026da84376SMilanka Ringwald /**
40379188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within the
40479188ed7SMilanka Ringwald  * specified service or handle range, and return those that match the given UUID.
40579188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
40679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4076da84376SMilanka Ringwald  * @param  callback
4086da84376SMilanka Ringwald  * @param  con_handle
4096da84376SMilanka Ringwald  * @param  service
4106da84376SMilanka Ringwald  * @param  uuid16
411692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
412692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
413692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4146da84376SMilanka Ringwald  */
415711e6c80SMatthias 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);
4166da84376SMilanka Ringwald 
4176da84376SMilanka Ringwald /**
41879188ed7SMilanka Ringwald  * @brief The following four functions are used to discover all characteristics within the
41979188ed7SMilanka Ringwald  * specified service or handle range, and return those that match the given UUID.
42079188ed7SMilanka Ringwald  * For each found characteristic a GATT_EVENT_CHARACTERISTIC_QUERY_RESULT event will emitted.
42179188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4226da84376SMilanka Ringwald  * @param  callback
4236da84376SMilanka Ringwald  * @param  con_handle
4246da84376SMilanka Ringwald  * @param  service
4256da84376SMilanka Ringwald  * @param  uuid128
426692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
427692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
428692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4296da84376SMilanka Ringwald  */
430045d700dSDavid 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);
4313deb3ec6SMatthias Ringwald 
4323deb3ec6SMatthias Ringwald /**
43379188ed7SMilanka Ringwald  * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic.
43479188ed7SMilanka Ringwald  * For each found descriptor a GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT event will be emitted.
43579188ed7SMilanka Ringwald  *
43679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.
4376da84376SMilanka Ringwald  * @param  callback
4386da84376SMilanka Ringwald  * @param  con_handle
4396da84376SMilanka Ringwald  * @param  characteristic
440692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
441692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
442692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4433deb3ec6SMatthias Ringwald  */
444711e6c80SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
4453deb3ec6SMatthias Ringwald 
4463deb3ec6SMatthias Ringwald /**
44779188ed7SMilanka Ringwald  * @brief Reads the characteristic value using the characteristic's value handle.
44879188ed7SMilanka Ringwald  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
44979188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
4506da84376SMilanka Ringwald  * @param  callback
4516da84376SMilanka Ringwald  * @param  con_handle
4526da84376SMilanka Ringwald  * @param  characteristic
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_read_value_of_characteristic(btstack_packet_handler_t callback, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic);
4586da84376SMilanka Ringwald 
4596da84376SMilanka Ringwald /**
46079188ed7SMilanka Ringwald  * @brief Reads the characteristic value using the characteristic's value handle.
46179188ed7SMilanka Ringwald  * If the characteristic value is found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
46279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
4636da84376SMilanka Ringwald  * @param  callback
4646da84376SMilanka Ringwald  * @param  con_handle
465b45b7749SMilanka Ringwald  * @param  value_handle
466692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
467692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
468692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4696da84376SMilanka Ringwald  */
470b45b7749SMilanka 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);
4713deb3ec6SMatthias Ringwald 
4723deb3ec6SMatthias Ringwald /**
47379188ed7SMilanka Ringwald  * @brief Reads the characteric value of all characteristics with the uuid.
47479188ed7SMilanka Ringwald  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
47579188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
4766da84376SMilanka Ringwald  * @param  callback
4776da84376SMilanka Ringwald  * @param  con_handle
4786da84376SMilanka Ringwald  * @param  start_handle
4796da84376SMilanka Ringwald  * @param  end_handle
4806da84376SMilanka Ringwald  * @param  uuid16
481692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
482692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
483692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4843deb3ec6SMatthias Ringwald  */
485711e6c80SMatthias 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);
4866da84376SMilanka Ringwald 
4876da84376SMilanka Ringwald /**
48879188ed7SMilanka Ringwald  * @brief Reads the characteric value of all characteristics with the uuid.
48979188ed7SMilanka Ringwald  * For each characteristic value found a GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event will be emitted.
49079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
4916da84376SMilanka Ringwald  * @param  callback
4926da84376SMilanka Ringwald  * @param  con_handle
4936da84376SMilanka Ringwald  * @param  start_handle
4946da84376SMilanka Ringwald  * @param  end_handle
4956da84376SMilanka Ringwald  * @param  uuid128
496692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
497692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
498692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
4996da84376SMilanka Ringwald  */
500045d700dSDavid 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);
5013deb3ec6SMatthias Ringwald 
5023deb3ec6SMatthias Ringwald /**
50379188ed7SMilanka Ringwald  * @brief Reads the long characteristic value using the characteristic's value handle.
50479188ed7SMilanka Ringwald  * The value will be returned in several blobs.
50579188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
50679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5076da84376SMilanka Ringwald  * @param  callback
5086da84376SMilanka Ringwald  * @param  con_handle
5096da84376SMilanka Ringwald  * @param  characteristic
510692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
511692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
512692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5133deb3ec6SMatthias Ringwald  */
514711e6c80SMatthias 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);
5156da84376SMilanka Ringwald 
5166da84376SMilanka Ringwald /**
51779188ed7SMilanka Ringwald  * @brief Reads the long characteristic value using the characteristic's value handle.
51879188ed7SMilanka Ringwald  * The value will be returned in several blobs.
51979188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
52079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5216da84376SMilanka Ringwald  * @param  callback
5226da84376SMilanka Ringwald  * @param  con_handle
523b45b7749SMilanka Ringwald  * @param  value_handle
524692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
525692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
526692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5276da84376SMilanka Ringwald  */
528b45b7749SMilanka 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);
5296da84376SMilanka Ringwald 
5306da84376SMilanka Ringwald /**
53179188ed7SMilanka Ringwald  * @brief Reads the long characteristic value using the characteristic's value handle.
53279188ed7SMilanka Ringwald  * The value will be returned in several blobs.
53379188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT event with updated value offset will be emitted.
53479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
5356da84376SMilanka Ringwald  * @param  callback
5366da84376SMilanka Ringwald  * @param  con_handle
537b45b7749SMilanka Ringwald  * @param  value_handle
5386da84376SMilanka Ringwald  * @param  offset
539692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
540692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
541692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5426da84376SMilanka Ringwald  */
543b45b7749SMilanka 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);
5443deb3ec6SMatthias Ringwald 
5453deb3ec6SMatthias Ringwald /*
54679188ed7SMilanka Ringwald  * @brief Read multiple characteristic values.
54779188ed7SMilanka Ringwald  * The all results are emitted via single GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT event,
54879188ed7SMilanka Ringwald  * followed by the GATT_EVENT_QUERY_COMPLETE event, which marks the end of read.
5496da84376SMilanka Ringwald  * @param  callback
5506da84376SMilanka Ringwald  * @param  con_handle
5516da84376SMilanka Ringwald  * @param  num_value_handles
5526da84376SMilanka Ringwald  * @param  value_handles list of handles
55379188ed7SMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
55479188ed7SMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
55579188ed7SMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5563deb3ec6SMatthias Ringwald  */
557711e6c80SMatthias 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);
5583deb3ec6SMatthias Ringwald 
5593deb3ec6SMatthias Ringwald /**
56079188ed7SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle without
56179188ed7SMilanka Ringwald  * an acknowledgment that the write was successfully performed.
5626da84376SMilanka Ringwald  * @param  con_handle
563b45b7749SMilanka Ringwald  * @param  value_handle
564b45b7749SMilanka Ringwald  * @param  value_length
5657e6f0853SDavid Lechner  * @param  value is copied on success and does not need to be retained
566692bf1adSMilanka Ringwald  * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found
567692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready
568692bf1adSMilanka Ringwald  *                BTSTACK_ACL_BUFFERS_FULL   , if L2CAP cannot send, there are no free ACL slots
569692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS         , if query is successfully registered
5703deb3ec6SMatthias Ringwald  */
571b45b7749SMilanka 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);
5723deb3ec6SMatthias Ringwald 
5733deb3ec6SMatthias Ringwald /**
57479188ed7SMilanka Ringwald  * @brief Writes the authenticated characteristic value using the characteristic's value handle
57579188ed7SMilanka Ringwald  * without an acknowledgment that the write was successfully performed.
57679188ed7SMilanka Ringwald  * @note GATT_EVENT_QUERY_COMPLETE is emitted with ATT_ERROR_SUCCESS for success,
57779188ed7SMilanka Ringwald  * or ATT_ERROR_BONDING_INFORMATION_MISSING if there is no bonding information stored.
5786da84376SMilanka Ringwald  * @param  callback
5796da84376SMilanka Ringwald  * @param  con_handle
5806da84376SMilanka Ringwald  * @param  value_handle
5816da84376SMilanka Ringwald  * @param  message_len
5826da84376SMilanka Ringwald  * @param  message is not copied, make sure memory is accessible until write is done
58340faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
58440faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
585692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
586692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
5873deb3ec6SMatthias Ringwald  */
5886da84376SMilanka Ringwald uint8_t gatt_client_signed_write_without_response(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t value_handle, uint16_t message_len, uint8_t * message);
5893deb3ec6SMatthias Ringwald 
5903deb3ec6SMatthias Ringwald /**
591b2468039SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle.
592b2468039SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
593b2468039SMilanka Ringwald  * The write is successfully performed, if the event's att_status field is set to
594b2468039SMilanka Ringwald  * ATT_ERROR_SUCCESS (see bluetooth.h for ATT_ERROR codes).
5956da84376SMilanka Ringwald  * @param  callback
5966da84376SMilanka Ringwald  * @param  con_handle
597b45b7749SMilanka Ringwald  * @param  value_handle
598b45b7749SMilanka Ringwald  * @param  value_length
599b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
60040faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
60140faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
602692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
603692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6043deb3ec6SMatthias Ringwald  */
605b45b7749SMilanka 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);
6066da84376SMilanka Ringwald 
6076da84376SMilanka Ringwald /**
60879188ed7SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle.
60979188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
61079188ed7SMilanka 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).
6116da84376SMilanka Ringwald  * @param  callback
6126da84376SMilanka Ringwald  * @param  con_handle
613b45b7749SMilanka Ringwald  * @param  value_handle
614b45b7749SMilanka Ringwald  * @param  value_length
615b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
61640faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
61740faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
618692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
619692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6206da84376SMilanka Ringwald  */
621b45b7749SMilanka 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);
6226da84376SMilanka Ringwald 
6236da84376SMilanka Ringwald /**
62479188ed7SMilanka Ringwald  * @brief Writes the characteristic value using the characteristic's value handle.
62579188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
62679188ed7SMilanka 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).
6276da84376SMilanka Ringwald  * @param  callback
6286da84376SMilanka Ringwald  * @param  con_handle
629b45b7749SMilanka Ringwald  * @param  value_handle
6306da84376SMilanka Ringwald  * @param  offset of value
631b45b7749SMilanka Ringwald  * @param  value_length
632b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
63340faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
63440faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
635692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
636692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6376da84376SMilanka Ringwald  */
638b45b7749SMilanka 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);
6393deb3ec6SMatthias Ringwald 
6403deb3ec6SMatthias Ringwald /**
64179188ed7SMilanka Ringwald  * @brief Writes of the long characteristic value using the characteristic's value handle.
64279188ed7SMilanka Ringwald  * It uses server response to validate that the write was correctly received.
64379188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE EVENT marks the end of write.
64479188ed7SMilanka 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).
6456da84376SMilanka Ringwald  * @param  callback
6466da84376SMilanka Ringwald  * @param  con_handle
647b45b7749SMilanka Ringwald  * @param  value_handle
648b45b7749SMilanka Ringwald  * @param  value_length
649b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
65040faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
65140faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
652692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
653692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6543deb3ec6SMatthias Ringwald  */
655b45b7749SMilanka 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);
6563deb3ec6SMatthias Ringwald 
6573deb3ec6SMatthias Ringwald /**
65879188ed7SMilanka Ringwald  * @brief Reads the characteristic descriptor using its handle.
65979188ed7SMilanka Ringwald  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
66079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
6616da84376SMilanka Ringwald  * @param  callback
6626da84376SMilanka Ringwald  * @param  con_handle
6636da84376SMilanka Ringwald  * @param  descriptor
66440faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
66540faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
666692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
667692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6683deb3ec6SMatthias Ringwald  */
669711e6c80SMatthias 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);
6706da84376SMilanka Ringwald 
6716da84376SMilanka Ringwald /**
67279188ed7SMilanka Ringwald  * @brief Reads the characteristic descriptor using its handle.
67379188ed7SMilanka Ringwald  * If the characteristic descriptor is found, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
67479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
6756da84376SMilanka Ringwald  * @param  callback
6766da84376SMilanka Ringwald  * @param  con_handle
6776da84376SMilanka Ringwald  * @param  descriptor
67840faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
67940faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
680692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
681692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6826da84376SMilanka Ringwald  */
683711e6c80SMatthias 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);
6843deb3ec6SMatthias Ringwald 
6853deb3ec6SMatthias Ringwald /**
68679188ed7SMilanka Ringwald  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
68779188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
68879188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
6896da84376SMilanka Ringwald  * @param  callback
6906da84376SMilanka Ringwald  * @param  con_handle
691b45b7749SMilanka Ringwald  * @param  descriptor
69240faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
69340faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
694692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
695692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
6963deb3ec6SMatthias Ringwald  */
697711e6c80SMatthias 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);
6986da84376SMilanka Ringwald 
6996da84376SMilanka Ringwald /**
70079188ed7SMilanka Ringwald  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
70179188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
70279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
7036da84376SMilanka Ringwald  * @param  callback
7046da84376SMilanka Ringwald  * @param  con_handle
7056da84376SMilanka Ringwald  * @param  descriptor_handle
70640faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
70740faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
708692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
709692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7106da84376SMilanka Ringwald  */
711711e6c80SMatthias 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);
7126da84376SMilanka Ringwald 
7136da84376SMilanka Ringwald /**
71479188ed7SMilanka Ringwald  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs.
71579188ed7SMilanka Ringwald  * For each blob, a GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT event will be emitted.
71679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of read.
7176da84376SMilanka Ringwald  * @param  callback
7186da84376SMilanka Ringwald  * @param  con_handle
7196da84376SMilanka Ringwald  * @param  descriptor_handle
7206da84376SMilanka Ringwald  * @param  offset
72140faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
72240faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
723692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
724692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7256da84376SMilanka Ringwald  */
726711e6c80SMatthias 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);
7273deb3ec6SMatthias Ringwald 
7283deb3ec6SMatthias Ringwald /**
72979188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
73079188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
73179188ed7SMilanka 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).
7326da84376SMilanka Ringwald  * @param  callback
7336da84376SMilanka Ringwald  * @param  con_handle
7346da84376SMilanka Ringwald  * @param  descriptor
735b45b7749SMilanka Ringwald  * @param  value_length
736b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
73740faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
73840faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
739692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
740692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7413deb3ec6SMatthias Ringwald  */
742b45b7749SMilanka 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);
7436da84376SMilanka Ringwald 
7446da84376SMilanka Ringwald /**
74579188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
74679188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
74779188ed7SMilanka 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).
7486da84376SMilanka Ringwald  * @param  callback
7496da84376SMilanka Ringwald  * @param  con_handle
7506da84376SMilanka Ringwald  * @param  descriptor_handle
751b45b7749SMilanka Ringwald  * @param  value_length
752b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
75340faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
75440faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
755692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
756692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7576da84376SMilanka Ringwald  */
758b45b7749SMilanka 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);
7596da84376SMilanka Ringwald 
7606da84376SMilanka Ringwald /**
76179188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
76279188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
76379188ed7SMilanka 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).
7646da84376SMilanka Ringwald  * @param  callback
7656da84376SMilanka Ringwald  * @param  con_handle
7666da84376SMilanka Ringwald  * @param  descriptor
767b45b7749SMilanka Ringwald  * @param  value_length
768b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
76940faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
77040faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
771692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
772692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7736da84376SMilanka Ringwald  */
774b45b7749SMilanka 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);
7756da84376SMilanka Ringwald 
7766da84376SMilanka Ringwald /**
77779188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
77879188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
77979188ed7SMilanka 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).
7806da84376SMilanka Ringwald  * @param  callback
7816da84376SMilanka Ringwald  * @param  con_handle
7826da84376SMilanka Ringwald  * @param  descriptor_handle
783b45b7749SMilanka Ringwald  * @param  value_length
784b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
78540faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
78640faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
787692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
788692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
7896da84376SMilanka Ringwald  */
790b45b7749SMilanka 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);
7916da84376SMilanka Ringwald 
7926da84376SMilanka Ringwald /**
79379188ed7SMilanka Ringwald  * @brief Writes the characteristic descriptor using its handle.
79479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
79579188ed7SMilanka 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).
7966da84376SMilanka Ringwald  * @param  callback
7976da84376SMilanka Ringwald  * @param  con_handle
7986da84376SMilanka Ringwald  * @param  descriptor_handle
7996da84376SMilanka Ringwald  * @param  offset of value
800b45b7749SMilanka Ringwald  * @param  value_length
801b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
80240faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
80340faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
804692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
805692bf1adSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8066da84376SMilanka Ringwald  */
807b45b7749SMilanka 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);
8083deb3ec6SMatthias Ringwald 
8093deb3ec6SMatthias Ringwald /**
81079188ed7SMilanka Ringwald  * @brief Writes the client characteristic configuration of the specified characteristic.
81179188ed7SMilanka Ringwald  * It is used to subscribe for notifications or indications of the characteristic value.
81279188ed7SMilanka Ringwald  * For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION
81379188ed7SMilanka Ringwald  * resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value.
81479188ed7SMilanka Ringwald  * The GATT_EVENT_QUERY_COMPLETE event marks the end of write.
81579188ed7SMilanka 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).
8166da84376SMilanka Ringwald  * @param  callback
8176da84376SMilanka Ringwald  * @param  con_handle
8186da84376SMilanka Ringwald  * @param  characteristic
819b7e5512fSMilanka Ringwald  * @param  configuration                                                    GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION, GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION
82040faeb84SMilanka Ringwald  * @return status ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER                  if no HCI connection for con_handle is found
82140faeb84SMilanka Ringwald  *                BTSTACK_MEMORY_ALLOC_FAILED                               if no GATT client for con_handle could be allocated
822692bf1adSMilanka Ringwald  *                GATT_CLIENT_IN_WRONG_STATE                                if GATT client is not ready
823b7e5512fSMilanka Ringwald  *                GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED     if configuring notification, but characteristic has no notification property set
824b7e5512fSMilanka Ringwald  *                GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED       if configuring indication, but characteristic has no indication property set
8256b04f675SMilanka Ringwald  *                ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE         if configuration is invalid
826b7e5512fSMilanka Ringwald  *                ERROR_CODE_SUCCESS                                        if query is successfully registered
8273deb3ec6SMatthias Ringwald  */
828711e6c80SMatthias 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);
8299c662c9bSMatthias Ringwald 
8309c662c9bSMatthias Ringwald /**
83179188ed7SMilanka Ringwald  * @brief Register for notifications and indications of a characteristic enabled by
83279188ed7SMilanka Ringwald  * the gatt_client_write_client_characteristic_configuration function.
8339c662c9bSMatthias Ringwald  * @param notification struct used to store registration
8346da84376SMilanka Ringwald  * @param callback
835b3f03c84SMatthias Ringwald  * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices
836b3f03c84SMatthias Ringwald  * @param characteristic or NULL to receive updates for all characteristics
8379c662c9bSMatthias Ringwald  */
8386da84376SMilanka 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);
8393deb3ec6SMatthias Ringwald 
8403deb3ec6SMatthias Ringwald /**
84179188ed7SMilanka Ringwald  * @brief Stop listening to characteristic value updates registered with
84279188ed7SMilanka Ringwald  * the gatt_client_listen_for_characteristic_value_updates function.
8431f734b5fSMatthias Ringwald  * @param notification struct used in gatt_client_listen_for_characteristic_value_updates
8441f734b5fSMatthias Ringwald  */
8451f734b5fSMatthias Ringwald void gatt_client_stop_listening_for_characteristic_value_updates(gatt_client_notification_t * notification);
8461f734b5fSMatthias Ringwald 
8471f734b5fSMatthias Ringwald /**
84879188ed7SMilanka Ringwald  * @brief Transactional write. It can be called as many times as it is needed to write the characteristics within the same transaction.
84979188ed7SMilanka Ringwald  * Call the gatt_client_execute_write function to commit the transaction.
8506da84376SMilanka Ringwald  * @param  callback
8516da84376SMilanka Ringwald  * @param  con_handle
8526da84376SMilanka Ringwald  * @param  attribute_handle
8536da84376SMilanka Ringwald  * @param  offset of value
854b45b7749SMilanka Ringwald  * @param  value_length
855b45b7749SMilanka Ringwald  * @param  value is not copied, make sure memory is accessible until write is done, i.e. GATT_EVENT_QUERY_COMPLETE is received
8563deb3ec6SMatthias Ringwald  */
857b45b7749SMilanka 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);
8583deb3ec6SMatthias Ringwald 
8593deb3ec6SMatthias Ringwald /**
8606da84376SMilanka Ringwald  * @brief Commit transactional write. GATT_EVENT_QUERY_COMPLETE is received.
8616da84376SMilanka Ringwald  * @param  callback
8626da84376SMilanka Ringwald  * @param  con_handle
86340faeb84SMilanka Ringwald  * @return status
8643deb3ec6SMatthias Ringwald  */
865711e6c80SMatthias Ringwald uint8_t gatt_client_execute_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
8663deb3ec6SMatthias Ringwald 
8673deb3ec6SMatthias Ringwald /**
8686da84376SMilanka Ringwald  * @brief Abort transactional write. GATT_EVENT_QUERY_COMPLETE is received.
8696da84376SMilanka Ringwald  * @param  callback
8706da84376SMilanka Ringwald  * @param  con_handle
87140faeb84SMilanka Ringwald  * @return status
8723deb3ec6SMatthias Ringwald  */
873711e6c80SMatthias Ringwald uint8_t gatt_client_cancel_write(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
8743deb3ec6SMatthias Ringwald 
875*59d34cd2SMatthias Ringwald /**
876*59d34cd2SMatthias Ringwald  * @brief Request callback when writing characteristic value without response is possible
877*59d34cd2SMatthias Ringwald  * @note callback might happend during call to this function
878*59d34cd2SMatthias Ringwald  * @param callback_registration to point to callback function and context information
879*59d34cd2SMatthias Ringwald  * @param con_handle
880*59d34cd2SMatthias Ringwald  * @return ERROR_CODE_SUCCESS if ok, ERROR_CODE_UNKNOWN_CONNECTION_IDENTIFIER if handle unknown, and ERROR_CODE_COMMAND_DISALLOWED if callback already registered
881*59d34cd2SMatthias Ringwald  */
882*59d34cd2SMatthias Ringwald uint8_t gatt_client_request_to_write_without_response(btstack_context_callback_registration_t * callback_registration, hci_con_handle_t con_handle);
883*59d34cd2SMatthias Ringwald 
884*59d34cd2SMatthias Ringwald 
885*59d34cd2SMatthias Ringwald // the following functions are marked as deprecated and will be removed eventually
886*59d34cd2SMatthias Ringwald /**
887*59d34cd2SMatthias Ringwald  * @brief Requests GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE that guarantees
888*59d34cd2SMatthias Ringwald  * a single successful gatt_client_write_value_of_characteristic_without_response call.
889*59d34cd2SMatthias Ringwald  * @deprecated please use gatt_client_request_to_write_without_response instead
890*59d34cd2SMatthias Ringwald  * @param  callback
891*59d34cd2SMatthias Ringwald  * @param  con_handle
892*59d34cd2SMatthias Ringwald  * @return status
893*59d34cd2SMatthias Ringwald  */
894*59d34cd2SMatthias Ringwald uint8_t gatt_client_request_can_write_without_response_event(btstack_packet_handler_t callback, hci_con_handle_t con_handle);
895*59d34cd2SMatthias Ringwald 
896*59d34cd2SMatthias Ringwald 
8973deb3ec6SMatthias Ringwald /* API_END */
8983deb3ec6SMatthias Ringwald 
8996ba2ad22SMatthias Ringwald // used by generated btstack_event.c
9006ba2ad22SMatthias Ringwald 
901313e337bSMatthias Ringwald void gatt_client_deserialize_service(const uint8_t *packet, int offset, gatt_client_service_t * service);
902313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic(const uint8_t * packet, int offset, gatt_client_characteristic_t * characteristic);
903313e337bSMatthias Ringwald void gatt_client_deserialize_characteristic_descriptor(const uint8_t * packet, int offset, gatt_client_characteristic_descriptor_t * descriptor);
9046ba2ad22SMatthias Ringwald 
905a6121b51SMilanka Ringwald #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
906a6121b51SMilanka Ringwald void gatt_client_att_packet_handler_fuzz(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size);
90740faeb84SMilanka Ringwald uint8_t gatt_client_get_client(hci_con_handle_t con_handle, gatt_client_t ** gatt_client);
908a6121b51SMilanka Ringwald #endif
909a6121b51SMilanka Ringwald 
9103deb3ec6SMatthias Ringwald #if defined __cplusplus
9113deb3ec6SMatthias Ringwald }
9123deb3ec6SMatthias Ringwald #endif
9133deb3ec6SMatthias Ringwald 
9143deb3ec6SMatthias Ringwald #endif
915