From b641e2af2d6c07ca1136bed7543d108e12d31fa9 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 27 Aug 2024 11:43:38 +0200 Subject: [PATCH] gatt_client: add service and connection id to long reads --- src/ble/gatt_client.c | 12 +++++----- src/btstack_defines.h | 8 +++++-- src/btstack_event.h | 52 ++++++++++++++++++++++++++++++++++++------- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index 8eda65deb..d71fb8081 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -1048,8 +1048,8 @@ setup_characteristic_value_packet(const gatt_client_t *gatt_client, uint8_t type } // @return packet pointer -// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes -#define LONG_CHARACTERISTIC_VALUE_EVENT_HEADER_SIZE 10 +// @note assume that value is part of an l2cap buffer - overwrite HCI + L2CAP packet headers + 6 pre_buffer bytes +#define LONG_CHARACTERISTIC_VALUE_EVENT_HEADER_SIZE 14 // L2CAP Header (4) + ACL Header (4) => 8 bytes #if !defined(HCI_INCOMING_PRE_BUFFER_SIZE) || ((HCI_INCOMING_PRE_BUFFER_SIZE < LONG_CHARACTERISTIC_VALUE_EVENT_HEADER_SIZE - 8)) @@ -1071,9 +1071,11 @@ setup_long_characteristic_value_packet(const gatt_client_t *gatt_client, uint8_t packet[0] = type; packet[1] = LONG_CHARACTERISTIC_VALUE_EVENT_HEADER_SIZE - 2 + length; little_endian_store_16(packet, 2, gatt_client->con_handle); - little_endian_store_16(packet, 4, attribute_handle); - little_endian_store_16(packet, 6, offset); - little_endian_store_16(packet, 8, length); + little_endian_store_16(packet, 4, gatt_client->service_id); + little_endian_store_16(packet, 6, gatt_client->connection_id); + little_endian_store_16(packet, 8, attribute_handle); + little_endian_store_16(packet, 10, offset); + little_endian_store_16(packet, 12, length); return packet; } diff --git a/src/btstack_defines.h b/src/btstack_defines.h index 1989c0a65..26cbe6176 100644 --- a/src/btstack_defines.h +++ b/src/btstack_defines.h @@ -1478,8 +1478,10 @@ typedef uint8_t sm_key_t[16]; #define GATT_EVENT_CHARACTERISTIC_VALUE_QUERY_RESULT 0xA5u /** - * @format H22LV + * @format H2222LV * @param handle + * @param service_id + * @param connection_id * @param value_handle * @param value_offset * @param value_length @@ -1515,8 +1517,10 @@ typedef uint8_t sm_key_t[16]; #define GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT 0xA9u /** - * @format H22LV + * @format H2222LV * @param handle + * @param service_id + * @param connection_id * @param descriptor_handle * @param descriptor_offset * @param descriptor_length diff --git a/src/btstack_event.h b/src/btstack_event.h index 51fb877a3..f0e47e6db 100644 --- a/src/btstack_event.h +++ b/src/btstack_event.h @@ -2912,6 +2912,24 @@ static inline const uint8_t * gatt_event_characteristic_value_query_result_get_v static inline hci_con_handle_t gatt_event_long_characteristic_value_query_result_get_handle(const uint8_t * event){ return little_endian_read_16(event, 2); } +/** + * @brief Get field service_id from event GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT + * @param event packet + * @return service_id + * @note: btstack_type 2 + */ +static inline uint16_t gatt_event_long_characteristic_value_query_result_get_service_id(const uint8_t * event){ + return little_endian_read_16(event, 4); +} +/** + * @brief Get field connection_id from event GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT + * @param event packet + * @return connection_id + * @note: btstack_type 2 + */ +static inline uint16_t gatt_event_long_characteristic_value_query_result_get_connection_id(const uint8_t * event){ + return little_endian_read_16(event, 6); +} /** * @brief Get field value_handle from event GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT * @param event packet @@ -2919,7 +2937,7 @@ static inline hci_con_handle_t gatt_event_long_characteristic_value_query_result * @note: btstack_type 2 */ static inline uint16_t gatt_event_long_characteristic_value_query_result_get_value_handle(const uint8_t * event){ - return little_endian_read_16(event, 4); + return little_endian_read_16(event, 8); } /** * @brief Get field value_offset from event GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT @@ -2928,7 +2946,7 @@ static inline uint16_t gatt_event_long_characteristic_value_query_result_get_val * @note: btstack_type 2 */ static inline uint16_t gatt_event_long_characteristic_value_query_result_get_value_offset(const uint8_t * event){ - return little_endian_read_16(event, 6); + return little_endian_read_16(event, 10); } /** * @brief Get field value_length from event GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT @@ -2937,7 +2955,7 @@ static inline uint16_t gatt_event_long_characteristic_value_query_result_get_val * @note: btstack_type L */ static inline uint16_t gatt_event_long_characteristic_value_query_result_get_value_length(const uint8_t * event){ - return little_endian_read_16(event, 8); + return little_endian_read_16(event, 12); } /** * @brief Get field value from event GATT_EVENT_LONG_CHARACTERISTIC_VALUE_QUERY_RESULT @@ -2946,7 +2964,7 @@ static inline uint16_t gatt_event_long_characteristic_value_query_result_get_val * @note: btstack_type V */ static inline const uint8_t * gatt_event_long_characteristic_value_query_result_get_value(const uint8_t * event){ - return &event[10]; + return &event[14]; } #endif @@ -3077,6 +3095,24 @@ static inline const uint8_t * gatt_event_characteristic_descriptor_query_result_ static inline hci_con_handle_t gatt_event_long_characteristic_descriptor_query_result_get_handle(const uint8_t * event){ return little_endian_read_16(event, 2); } +/** + * @brief Get field service_id from event GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT + * @param event packet + * @return service_id + * @note: btstack_type 2 + */ +static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_get_service_id(const uint8_t * event){ + return little_endian_read_16(event, 4); +} +/** + * @brief Get field connection_id from event GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT + * @param event packet + * @return connection_id + * @note: btstack_type 2 + */ +static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_get_connection_id(const uint8_t * event){ + return little_endian_read_16(event, 6); +} /** * @brief Get field descriptor_handle from event GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT * @param event packet @@ -3084,7 +3120,7 @@ static inline hci_con_handle_t gatt_event_long_characteristic_descriptor_query_r * @note: btstack_type 2 */ static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_get_descriptor_handle(const uint8_t * event){ - return little_endian_read_16(event, 4); + return little_endian_read_16(event, 8); } /** * @brief Get field descriptor_offset from event GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT @@ -3093,7 +3129,7 @@ static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_ge * @note: btstack_type 2 */ static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_get_descriptor_offset(const uint8_t * event){ - return little_endian_read_16(event, 6); + return little_endian_read_16(event, 10); } /** * @brief Get field descriptor_length from event GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT @@ -3102,7 +3138,7 @@ static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_ge * @note: btstack_type L */ static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_get_descriptor_length(const uint8_t * event){ - return little_endian_read_16(event, 8); + return little_endian_read_16(event, 12); } /** * @brief Get field descriptor from event GATT_EVENT_LONG_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT @@ -3111,7 +3147,7 @@ static inline uint16_t gatt_event_long_characteristic_descriptor_query_result_ge * @note: btstack_type V */ static inline const uint8_t * gatt_event_long_characteristic_descriptor_query_result_get_descriptor(const uint8_t * event){ - return &event[10]; + return &event[14]; } #endif