xref: /btstack/src/ble/gatt_client.h (revision 5611a760af48d1ce1beea59c7908be73bd2393f1)
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
233deb3ec6SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
243deb3ec6SMatthias Ringwald  * RINGWALD 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 
383deb3ec6SMatthias Ringwald 
393deb3ec6SMatthias Ringwald #ifndef btstack_gatt_client_h
403deb3ec6SMatthias Ringwald #define btstack_gatt_client_h
413deb3ec6SMatthias Ringwald 
423deb3ec6SMatthias Ringwald #include "hci.h"
433deb3ec6SMatthias Ringwald 
443deb3ec6SMatthias Ringwald #if defined __cplusplus
453deb3ec6SMatthias Ringwald extern "C" {
463deb3ec6SMatthias Ringwald #endif
473deb3ec6SMatthias Ringwald 
483deb3ec6SMatthias Ringwald typedef struct le_event {
493deb3ec6SMatthias Ringwald     uint8_t   type;
503deb3ec6SMatthias Ringwald     uint16_t handle;
513deb3ec6SMatthias Ringwald } le_event_t;
523deb3ec6SMatthias Ringwald 
533deb3ec6SMatthias Ringwald typedef void (*gatt_client_callback_t)(uint8_t packet_type, uint8_t *packet, uint16_t size);
543deb3ec6SMatthias Ringwald 
553deb3ec6SMatthias Ringwald typedef enum {
563deb3ec6SMatthias Ringwald     P_READY,
573deb3ec6SMatthias Ringwald     P_W2_SEND_SERVICE_QUERY,
583deb3ec6SMatthias Ringwald     P_W4_SERVICE_QUERY_RESULT,
593deb3ec6SMatthias Ringwald     P_W2_SEND_SERVICE_WITH_UUID_QUERY,
603deb3ec6SMatthias Ringwald     P_W4_SERVICE_WITH_UUID_RESULT,
613deb3ec6SMatthias Ringwald 
623deb3ec6SMatthias Ringwald     P_W2_SEND_ALL_CHARACTERISTICS_OF_SERVICE_QUERY,
633deb3ec6SMatthias Ringwald     P_W4_ALL_CHARACTERISTICS_OF_SERVICE_QUERY_RESULT,
643deb3ec6SMatthias Ringwald     P_W2_SEND_CHARACTERISTIC_WITH_UUID_QUERY,
653deb3ec6SMatthias Ringwald     P_W4_CHARACTERISTIC_WITH_UUID_QUERY_RESULT,
663deb3ec6SMatthias Ringwald 
673deb3ec6SMatthias Ringwald     P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY,
683deb3ec6SMatthias Ringwald     P_W4_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT,
693deb3ec6SMatthias Ringwald 
703deb3ec6SMatthias Ringwald     P_W2_SEND_INCLUDED_SERVICE_QUERY,
713deb3ec6SMatthias Ringwald     P_W4_INCLUDED_SERVICE_QUERY_RESULT,
723deb3ec6SMatthias Ringwald     P_W2_SEND_INCLUDED_SERVICE_WITH_UUID_QUERY,
733deb3ec6SMatthias Ringwald     P_W4_INCLUDED_SERVICE_UUID_WITH_QUERY_RESULT,
743deb3ec6SMatthias Ringwald 
753deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CHARACTERISTIC_VALUE_QUERY,
763deb3ec6SMatthias Ringwald     P_W4_READ_CHARACTERISTIC_VALUE_RESULT,
773deb3ec6SMatthias Ringwald 
783deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BLOB_QUERY,
793deb3ec6SMatthias Ringwald     P_W4_READ_BLOB_RESULT,
803deb3ec6SMatthias Ringwald 
813deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BY_TYPE_REQUEST,
823deb3ec6SMatthias Ringwald     P_W4_READ_BY_TYPE_RESPONSE,
833deb3ec6SMatthias Ringwald 
843deb3ec6SMatthias Ringwald     P_W2_SEND_READ_MULTIPLE_REQUEST,
853deb3ec6SMatthias Ringwald     P_W4_READ_MULTIPLE_RESPONSE,
863deb3ec6SMatthias Ringwald 
873deb3ec6SMatthias Ringwald     P_W2_SEND_WRITE_CHARACTERISTIC_VALUE,
883deb3ec6SMatthias Ringwald     P_W4_WRITE_CHARACTERISTIC_VALUE_RESULT,
893deb3ec6SMatthias Ringwald 
903deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE,
913deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_RESULT,
923deb3ec6SMatthias Ringwald     P_W2_PREPARE_RELIABLE_WRITE,
933deb3ec6SMatthias Ringwald     P_W4_PREPARE_RELIABLE_WRITE_RESULT,
943deb3ec6SMatthias Ringwald 
953deb3ec6SMatthias Ringwald     P_W2_EXECUTE_PREPARED_WRITE,
963deb3ec6SMatthias Ringwald     P_W4_EXECUTE_PREPARED_WRITE_RESULT,
973deb3ec6SMatthias Ringwald     P_W2_CANCEL_PREPARED_WRITE,
983deb3ec6SMatthias Ringwald     P_W4_CANCEL_PREPARED_WRITE_RESULT,
993deb3ec6SMatthias Ringwald     P_W2_CANCEL_PREPARED_WRITE_DATA_MISMATCH,
1003deb3ec6SMatthias Ringwald     P_W4_CANCEL_PREPARED_WRITE_DATA_MISMATCH_RESULT,
1013deb3ec6SMatthias Ringwald 
1023deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY,
1033deb3ec6SMatthias Ringwald     P_W4_READ_CLIENT_CHARACTERISTIC_CONFIGURATION_QUERY_RESULT,
1043deb3ec6SMatthias Ringwald     P_W2_WRITE_CLIENT_CHARACTERISTIC_CONFIGURATION,
1053deb3ec6SMatthias Ringwald     P_W4_CLIENT_CHARACTERISTIC_CONFIGURATION_RESULT,
1063deb3ec6SMatthias Ringwald 
1073deb3ec6SMatthias Ringwald     P_W2_SEND_READ_CHARACTERISTIC_DESCRIPTOR_QUERY,
1083deb3ec6SMatthias Ringwald     P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT,
1093deb3ec6SMatthias Ringwald 
1103deb3ec6SMatthias Ringwald     P_W2_SEND_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_QUERY,
1113deb3ec6SMatthias Ringwald     P_W4_READ_BLOB_CHARACTERISTIC_DESCRIPTOR_RESULT,
1123deb3ec6SMatthias Ringwald 
1133deb3ec6SMatthias Ringwald     P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR,
1143deb3ec6SMatthias Ringwald     P_W4_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1153deb3ec6SMatthias Ringwald 
1163deb3ec6SMatthias Ringwald     // all long writes use this
1173deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR,
1183deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1193deb3ec6SMatthias Ringwald     P_W2_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR,
1203deb3ec6SMatthias Ringwald     P_W4_EXECUTE_PREPARED_WRITE_CHARACTERISTIC_DESCRIPTOR_RESULT,
1213deb3ec6SMatthias Ringwald 
1223deb3ec6SMatthias Ringwald     // gatt reliable write API use this (manual version of the above)
1233deb3ec6SMatthias Ringwald     P_W2_PREPARE_WRITE_SINGLE,
1243deb3ec6SMatthias Ringwald     P_W4_PREPARE_WRITE_SINGLE_RESULT,
1253deb3ec6SMatthias Ringwald 
1263deb3ec6SMatthias Ringwald     P_W4_CMAC_READY,
1273deb3ec6SMatthias Ringwald     P_W4_CMAC_RESULT,
1283deb3ec6SMatthias Ringwald     P_W2_SEND_SIGNED_WRITE,
1293deb3ec6SMatthias Ringwald     P_W4_SEND_SINGED_WRITE_DONE,
1303deb3ec6SMatthias Ringwald } gatt_client_state_t;
1313deb3ec6SMatthias Ringwald 
1323deb3ec6SMatthias Ringwald 
1333deb3ec6SMatthias Ringwald typedef enum{
1343deb3ec6SMatthias Ringwald     SEND_MTU_EXCHANGE,
1353deb3ec6SMatthias Ringwald     SENT_MTU_EXCHANGE,
1363deb3ec6SMatthias Ringwald     MTU_EXCHANGED
1373deb3ec6SMatthias Ringwald } gatt_client_mtu_t;
1383deb3ec6SMatthias Ringwald 
1393deb3ec6SMatthias Ringwald typedef struct gatt_client{
140665d90f2SMatthias Ringwald     btstack_linked_item_t    item;
1413deb3ec6SMatthias Ringwald     // TODO: rename gatt_client_state -> state
1423deb3ec6SMatthias Ringwald     gatt_client_state_t gatt_client_state;
1433deb3ec6SMatthias Ringwald 
1443deb3ec6SMatthias Ringwald     // subclient
1453deb3ec6SMatthias Ringwald     uint16_t subclient_id;
1463deb3ec6SMatthias Ringwald 
1473deb3ec6SMatthias Ringwald     uint16_t handle;
1483deb3ec6SMatthias Ringwald 
1493deb3ec6SMatthias Ringwald     uint8_t   address_type;
1503deb3ec6SMatthias Ringwald     bd_addr_t address;
1513deb3ec6SMatthias Ringwald     uint16_t mtu;
1523deb3ec6SMatthias Ringwald     gatt_client_mtu_t mtu_state;
1533deb3ec6SMatthias Ringwald 
1543deb3ec6SMatthias Ringwald     uint16_t uuid16;
1553deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
1563deb3ec6SMatthias Ringwald 
1573deb3ec6SMatthias Ringwald     uint16_t start_group_handle;
1583deb3ec6SMatthias Ringwald     uint16_t end_group_handle;
1593deb3ec6SMatthias Ringwald 
1603deb3ec6SMatthias Ringwald     uint16_t query_start_handle;
1613deb3ec6SMatthias Ringwald     uint16_t query_end_handle;
1623deb3ec6SMatthias Ringwald 
1633deb3ec6SMatthias Ringwald     uint8_t  characteristic_properties;
1643deb3ec6SMatthias Ringwald     uint16_t characteristic_start_handle;
1653deb3ec6SMatthias Ringwald 
1663deb3ec6SMatthias Ringwald     uint16_t attribute_handle;
1673deb3ec6SMatthias Ringwald     uint16_t attribute_offset;
1683deb3ec6SMatthias Ringwald     uint16_t attribute_length;
1693deb3ec6SMatthias Ringwald     uint8_t* attribute_value;
1703deb3ec6SMatthias Ringwald 
1713deb3ec6SMatthias Ringwald     // read multiple characteristic values
1723deb3ec6SMatthias Ringwald     uint16_t    read_multiple_handle_count;
1733deb3ec6SMatthias Ringwald     uint16_t  * read_multiple_handles;
1743deb3ec6SMatthias Ringwald 
1753deb3ec6SMatthias Ringwald     uint16_t client_characteristic_configuration_handle;
1763deb3ec6SMatthias Ringwald     uint8_t  client_characteristic_configuration_value[2];
1773deb3ec6SMatthias Ringwald 
1783deb3ec6SMatthias Ringwald     uint8_t  filter_with_uuid;
1793deb3ec6SMatthias Ringwald     uint8_t  send_confirmation;
1803deb3ec6SMatthias Ringwald 
1813deb3ec6SMatthias Ringwald     int      le_device_index;
1823deb3ec6SMatthias Ringwald     uint8_t  cmac[8];
1833deb3ec6SMatthias Ringwald 
184ec820d77SMatthias Ringwald     btstack_timer_source_t gc_timeout;
1853deb3ec6SMatthias Ringwald } gatt_client_t;
1863deb3ec6SMatthias Ringwald 
1873deb3ec6SMatthias Ringwald typedef struct gatt_subclient {
188665d90f2SMatthias Ringwald     btstack_linked_item_t   item;
1893deb3ec6SMatthias Ringwald     uint16_t        id;
1903deb3ec6SMatthias Ringwald     gatt_client_callback_t callback;
1913deb3ec6SMatthias Ringwald } gatt_subclient_t;
1923deb3ec6SMatthias Ringwald 
1933deb3ec6SMatthias Ringwald /* API_START */
1943deb3ec6SMatthias Ringwald 
1953deb3ec6SMatthias Ringwald typedef struct le_service{
1963deb3ec6SMatthias Ringwald     uint16_t start_group_handle;
1973deb3ec6SMatthias Ringwald     uint16_t end_group_handle;
1983deb3ec6SMatthias Ringwald     uint16_t uuid16;
1993deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
2003deb3ec6SMatthias Ringwald } le_service_t;
2013deb3ec6SMatthias Ringwald 
2023deb3ec6SMatthias Ringwald typedef struct le_characteristic{
2033deb3ec6SMatthias Ringwald     uint16_t start_handle;
2043deb3ec6SMatthias Ringwald     uint16_t value_handle;
2053deb3ec6SMatthias Ringwald     uint16_t end_handle;
2063deb3ec6SMatthias Ringwald     uint16_t properties;
2073deb3ec6SMatthias Ringwald     uint16_t uuid16;
2083deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
2093deb3ec6SMatthias Ringwald } le_characteristic_t;
2103deb3ec6SMatthias Ringwald 
2113deb3ec6SMatthias Ringwald typedef struct le_characteristic_descriptor{
2123deb3ec6SMatthias Ringwald     uint16_t handle;
2133deb3ec6SMatthias Ringwald     uint16_t uuid16;
2143deb3ec6SMatthias Ringwald     uint8_t  uuid128[16];
2153deb3ec6SMatthias Ringwald } le_characteristic_descriptor_t;
2163deb3ec6SMatthias Ringwald 
2173deb3ec6SMatthias Ringwald /**
2183deb3ec6SMatthias Ringwald  * @brief Set up GATT client.
2193deb3ec6SMatthias Ringwald  */
2203deb3ec6SMatthias Ringwald void gatt_client_init(void);
2213deb3ec6SMatthias Ringwald 
2223deb3ec6SMatthias Ringwald /**
2233deb3ec6SMatthias Ringwald  * @brief Register callback (packet handler) for GATT client. Returns GATT client ID.
2243deb3ec6SMatthias Ringwald  */
2253deb3ec6SMatthias Ringwald uint16_t gatt_client_register_packet_handler (gatt_client_callback_t callback);
2263deb3ec6SMatthias Ringwald 
2273deb3ec6SMatthias Ringwald /**
2283deb3ec6SMatthias Ringwald  * @brief Unregister callback (packet handler) for GATT client.
2293deb3ec6SMatthias Ringwald  */
2303deb3ec6SMatthias Ringwald void gatt_client_unregister_packet_handler(uint16_t gatt_client_id);
2313deb3ec6SMatthias Ringwald 
2323deb3ec6SMatthias Ringwald /**
233616edd56SMatthias Ringwald  * @brief MTU is available after the first query has completed. If status is equal to 0, it returns the real value, otherwise the default value of 23.
2343deb3ec6SMatthias Ringwald  */
235616edd56SMatthias Ringwald uint8_t gatt_client_get_mtu(uint16_t handle, uint16_t * mtu);
2363deb3ec6SMatthias Ringwald 
2373deb3ec6SMatthias Ringwald /**
2383deb3ec6SMatthias Ringwald  * @brief Returns if the GATT client is ready to receive a query. It is used with daemon.
2393deb3ec6SMatthias Ringwald  */
2403deb3ec6SMatthias Ringwald int gatt_client_is_ready(uint16_t handle);
2413deb3ec6SMatthias Ringwald 
2423deb3ec6SMatthias Ringwald /**
243*5611a760SMatthias Ringwald  * @brief Discovers all primary services. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
2443deb3ec6SMatthias Ringwald  */
245616edd56SMatthias Ringwald uint8_t gatt_client_discover_primary_services(uint16_t gatt_client_id, uint16_t con_handle);
2463deb3ec6SMatthias Ringwald 
2473deb3ec6SMatthias Ringwald /**
248*5611a760SMatthias Ringwald  * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. For each found service, an le_service_event_t with type set to GATT_EVENT_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t, with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
2493deb3ec6SMatthias Ringwald  */
250616edd56SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t uuid16);
251616edd56SMatthias Ringwald uint8_t gatt_client_discover_primary_services_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, const uint8_t  * uuid);
2523deb3ec6SMatthias Ringwald 
2533deb3ec6SMatthias Ringwald /**
254*5611a760SMatthias Ringwald  * @brief Finds included services within the specified service. For each found included service, an le_service_event_t with type set to GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery. Information about included service type (primary/secondary) can be retrieved either by sending an ATT find information request for the returned start group handle (returning the handle and the UUID for primary or secondary service) or by comparing the service to the list of all primary services.
2553deb3ec6SMatthias Ringwald  */
256616edd56SMatthias Ringwald uint8_t gatt_client_find_included_services_for_service(uint16_t gatt_client_id, uint16_t con_handle, le_service_t  *service);
2573deb3ec6SMatthias Ringwald 
2583deb3ec6SMatthias Ringwald /**
259*5611a760SMatthias Ringwald  * @brief Discovers all characteristics within the specified service. For each found characteristic, an le_characteristics_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
2603deb3ec6SMatthias Ringwald  */
261616edd56SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_service(uint16_t gatt_client_id, uint16_t con_handle, le_service_t  *service);
2623deb3ec6SMatthias Ringwald 
2633deb3ec6SMatthias Ringwald /**
264*5611a760SMatthias Ringwald  * @brief The following four functions are used to discover all characteristics within the specified service or handle range, and return those that match the given UUID. For each found characteristic, an le_characteristic_event_t with type set to GATT_EVENT_CHARACTERISTIC_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
2653deb3ec6SMatthias Ringwald  */
266616edd56SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
267616edd56SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_handle_range_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t  * uuid);
268616edd56SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_service_by_uuid16 (uint16_t gatt_client_id, uint16_t con_handle, le_service_t  *service, uint16_t  uuid16);
269616edd56SMatthias Ringwald uint8_t gatt_client_discover_characteristics_for_service_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, le_service_t  *service, uint8_t  * uuid128);
2703deb3ec6SMatthias Ringwald 
2713deb3ec6SMatthias Ringwald /**
272*5611a760SMatthias Ringwald  * @brief Discovers attribute handle and UUID of a characteristic descriptor within the specified characteristic. For each found descriptor, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of discovery.
2733deb3ec6SMatthias Ringwald  */
274616edd56SMatthias Ringwald uint8_t gatt_client_discover_characteristic_descriptors(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t  *characteristic);
2753deb3ec6SMatthias Ringwald 
2763deb3ec6SMatthias Ringwald /**
277*5611a760SMatthias Ringwald  * @brief Reads the characteristic value using the characteristic's value handle. If the characteristic value is found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
2783deb3ec6SMatthias Ringwald  */
279616edd56SMatthias Ringwald uint8_t gatt_client_read_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t  *characteristic);
280616edd56SMatthias Ringwald uint8_t gatt_client_read_value_of_characteristic_using_value_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle);
2813deb3ec6SMatthias Ringwald 
2823deb3ec6SMatthias Ringwald /**
283*5611a760SMatthias Ringwald  * @brief Reads the characteric value of all characteristics with the uuid. For each found, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
2843deb3ec6SMatthias Ringwald  */
285616edd56SMatthias Ringwald uint8_t gatt_client_read_value_of_characteristics_by_uuid16(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
286616edd56SMatthias Ringwald uint8_t gatt_client_read_value_of_characteristics_by_uuid128(uint16_t gatt_client_id, uint16_t con_handle, uint16_t start_handle, uint16_t end_handle, uint8_t * uuid128);
2873deb3ec6SMatthias Ringwald 
2883deb3ec6SMatthias Ringwald /**
289*5611a760SMatthias Ringwald  * @brief Reads the long characteristic value using the characteristic's value handle. The value will be returned in several blobs. For each blob, an le_characteristic_value_event_t with type set to GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT and updated value offset will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, mark the end of read.
2903deb3ec6SMatthias Ringwald  */
291616edd56SMatthias Ringwald uint8_t gatt_client_read_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t  *characteristic);
292616edd56SMatthias Ringwald uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle);
293616edd56SMatthias Ringwald uint8_t gatt_client_read_long_value_of_characteristic_using_value_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset);
2943deb3ec6SMatthias Ringwald 
2953deb3ec6SMatthias Ringwald /*
2963deb3ec6SMatthias Ringwald  * @brief Read multiple characteristic values
2973deb3ec6SMatthias Ringwald  * @param number handles
2983deb3ec6SMatthias Ringwald  * @param list_of_handles list of handles
2993deb3ec6SMatthias Ringwald  */
300616edd56SMatthias Ringwald uint8_t gatt_client_read_multiple_characteristic_values(uint16_t gatt_client_id, uint16_t con_handle, int num_value_handles, uint16_t * value_handles);
3013deb3ec6SMatthias Ringwald 
3023deb3ec6SMatthias Ringwald /**
3033deb3ec6SMatthias Ringwald  * @brief Writes the characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.
3043deb3ec6SMatthias Ringwald  */
305616edd56SMatthias Ringwald uint8_t gatt_client_write_value_of_characteristic_without_response(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
3063deb3ec6SMatthias Ringwald 
3073deb3ec6SMatthias Ringwald /**
3083deb3ec6SMatthias Ringwald  * @brief Writes the authenticated characteristic value using the characteristic's value handle without an acknowledgment that the write was successfully performed.
3093deb3ec6SMatthias Ringwald  */
310616edd56SMatthias Ringwald uint8_t gatt_client_signed_write_without_response(uint16_t gatt_client_id, uint16_t con_handle, uint16_t handle, uint16_t message_len, uint8_t  * message);
3113deb3ec6SMatthias Ringwald 
3123deb3ec6SMatthias Ringwald /**
313*5611a760SMatthias Ringwald  * @brief Writes the characteristic value using the characteristic's value handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
3143deb3ec6SMatthias Ringwald  */
315616edd56SMatthias Ringwald uint8_t gatt_client_write_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
316616edd56SMatthias Ringwald uint8_t gatt_client_write_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
317616edd56SMatthias Ringwald uint8_t gatt_client_write_long_value_of_characteristic_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t offset, uint16_t length, uint8_t  * data);
3183deb3ec6SMatthias Ringwald 
3193deb3ec6SMatthias Ringwald /**
320*5611a760SMatthias Ringwald  * @brief Writes of the long characteristic value using the characteristic's value handle. It uses server response to validate that the write was correctly received. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE marks the end of write. The write is successfully performed, if the event's status field is set to 0.
3213deb3ec6SMatthias Ringwald  */
322616edd56SMatthias Ringwald uint8_t gatt_client_reliable_write_long_value_of_characteristic(uint16_t gatt_client_id, uint16_t con_handle, uint16_t characteristic_value_handle, uint16_t length, uint8_t  * data);
3233deb3ec6SMatthias Ringwald 
3243deb3ec6SMatthias Ringwald /**
325*5611a760SMatthias Ringwald  * @brief Reads the characteristic descriptor using its handle. If the characteristic descriptor is found, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
3263deb3ec6SMatthias Ringwald  */
327616edd56SMatthias Ringwald uint8_t gatt_client_read_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t  * descriptor);
328616edd56SMatthias Ringwald uint8_t gatt_client_read_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle);
3293deb3ec6SMatthias Ringwald 
3303deb3ec6SMatthias Ringwald /**
331*5611a760SMatthias Ringwald  * @brief Reads the long characteristic descriptor using its handle. It will be returned in several blobs. For each blob, an le_characteristic_descriptor_event_t with type set to GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT will be generated and passed to the registered callback. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of read.
3323deb3ec6SMatthias Ringwald  */
333616edd56SMatthias Ringwald uint8_t gatt_client_read_long_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t  * descriptor);
334616edd56SMatthias Ringwald uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle);
335616edd56SMatthias Ringwald uint8_t gatt_client_read_long_characteristic_descriptor_using_descriptor_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset);
3363deb3ec6SMatthias Ringwald 
3373deb3ec6SMatthias Ringwald /**
338*5611a760SMatthias Ringwald  * @brief Writes the characteristic descriptor using its handle. The gatt_complete_event_t with type set to GATT_EVENT_QUERY_COMPLETE, marks the end of write. The write is successfully performed, if the event's status field is set to 0.
3393deb3ec6SMatthias Ringwald  */
340616edd56SMatthias Ringwald uint8_t gatt_client_write_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t  * descriptor, uint16_t length, uint8_t  * data);
341616edd56SMatthias Ringwald uint8_t gatt_client_write_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t  * data);
342616edd56SMatthias Ringwald uint8_t gatt_client_write_long_characteristic_descriptor(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_descriptor_t  * descriptor, uint16_t length, uint8_t  * data);
343616edd56SMatthias Ringwald uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t length, uint8_t  * data);
344616edd56SMatthias Ringwald uint8_t gatt_client_write_long_characteristic_descriptor_using_descriptor_handle_with_offset(uint16_t gatt_client_id, uint16_t con_handle, uint16_t descriptor_handle, uint16_t offset, uint16_t length, uint8_t  * data);
3453deb3ec6SMatthias Ringwald 
3463deb3ec6SMatthias Ringwald /**
3473deb3ec6SMatthias Ringwald  * @brief Writes the client characteristic configuration of the specified characteristic. It is used to subscribe for notifications or indications of the characteristic value. For notifications or indications specify: GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION resp. GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION as configuration value.
3483deb3ec6SMatthias Ringwald  */
349616edd56SMatthias Ringwald uint8_t gatt_client_write_client_characteristic_configuration(uint16_t gatt_client_id, uint16_t con_handle, le_characteristic_t * characteristic, uint16_t configuration);
3503deb3ec6SMatthias Ringwald 
3513deb3ec6SMatthias Ringwald /**
3523deb3ec6SMatthias Ringwald  * @brief -> gatt complete event
3533deb3ec6SMatthias Ringwald  */
354616edd56SMatthias Ringwald uint8_t gatt_client_prepare_write(uint16_t gatt_client_id, uint16_t con_handle, uint16_t attribute_handle, uint16_t offset, uint16_t length, uint8_t * data);
3553deb3ec6SMatthias Ringwald 
3563deb3ec6SMatthias Ringwald /**
3573deb3ec6SMatthias Ringwald  * @brief -> gatt complete event
3583deb3ec6SMatthias Ringwald  */
359616edd56SMatthias Ringwald uint8_t gatt_client_execute_write(uint16_t gatt_client_id, uint16_t con_handle);
3603deb3ec6SMatthias Ringwald 
3613deb3ec6SMatthias Ringwald /**
3623deb3ec6SMatthias Ringwald  * @brief -> gatt complete event
3633deb3ec6SMatthias Ringwald  */
364616edd56SMatthias Ringwald uint8_t gatt_client_cancel_write(uint16_t gatt_client_id, uint16_t con_handle);
3653deb3ec6SMatthias Ringwald 
3663deb3ec6SMatthias Ringwald 
3673deb3ec6SMatthias Ringwald /* API_END */
3683deb3ec6SMatthias Ringwald 
3693deb3ec6SMatthias Ringwald // only used for testing
3703deb3ec6SMatthias Ringwald void gatt_client_pts_suppress_mtu_exchange(void);
3713deb3ec6SMatthias Ringwald 
3723deb3ec6SMatthias Ringwald #if defined __cplusplus
3733deb3ec6SMatthias Ringwald }
3743deb3ec6SMatthias Ringwald #endif
3753deb3ec6SMatthias Ringwald 
3763deb3ec6SMatthias Ringwald #endif
377