From 68ced5c9a37ce931927bf94db59fb6454b4e465b Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Mon, 26 Aug 2024 11:18:47 +0200 Subject: [PATCH] gatt_client: add gatt_client_discover_primary_services_by_uuid16_with_context --- src/ble/gatt_client.c | 9 ++++++++- src/ble/gatt_client.h | 18 +++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index ccb65ca8e..8cf630602 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -2525,7 +2525,8 @@ uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callbac return ERROR_CODE_SUCCESS; } -uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16){ +uint8_t gatt_client_discover_primary_services_by_uuid16_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, + uint16_t uuid16, uint16_t service_id, uint16_t connection_id){ gatt_client_t * gatt_client; uint8_t status = gatt_client_provide_context_for_request(con_handle, &gatt_client); if (status != ERROR_CODE_SUCCESS){ @@ -2533,6 +2534,8 @@ uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t } gatt_client->callback = callback; + gatt_client->service_id = service_id; + gatt_client->connection_id = connection_id; gatt_client->start_group_handle = 0x0001; gatt_client->end_group_handle = 0xffff; gatt_client->state = P_W2_SEND_SERVICE_WITH_UUID_QUERY; @@ -2542,6 +2545,10 @@ uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t return ERROR_CODE_SUCCESS; } +uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16){ + return gatt_client_discover_primary_services_by_uuid16_with_context(callback, con_handle, uuid16, 0, 0); +} + uint8_t gatt_client_discover_primary_services_by_uuid128(btstack_packet_handler_t callback, hci_con_handle_t con_handle, const uint8_t * uuid128){ gatt_client_t * gatt_client; uint8_t status = gatt_client_provide_context_for_request(con_handle, &gatt_client); diff --git a/src/ble/gatt_client.h b/src/ble/gatt_client.h index ab051aa64..155143a53 100644 --- a/src/ble/gatt_client.h +++ b/src/ble/gatt_client.h @@ -438,7 +438,23 @@ uint8_t gatt_client_discover_secondary_services(btstack_packet_handler_t callbac */ uint8_t gatt_client_discover_primary_services_by_uuid16(btstack_packet_handler_t callback, hci_con_handle_t con_handle, uint16_t uuid16); -/** +/** + * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. + * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. + * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery. + * @param callback + * @param con_handle + * @param uuid16 + * @param service_id - context provided to callback in events + * @param connection_id - contest provided to callback in events + * @return status BTSTACK_MEMORY_ALLOC_FAILED, if no GATT client for con_handle is found + * GATT_CLIENT_IN_WRONG_STATE , if GATT client is not ready + * ERROR_CODE_SUCCESS , if query is successfully registered + */ +uint8_t gatt_client_discover_primary_services_by_uuid16_with_context(btstack_packet_handler_t callback, hci_con_handle_t con_handle, + uint16_t uuid16, uint16_t service_id, uint16_t connection_id); + +/** * @brief Discovers a specific primary service given its UUID. This service may exist multiple times. * For each found service a GATT_EVENT_SERVICE_QUERY_RESULT event will be emitted. * The GATT_EVENT_QUERY_COMPLETE event marks the end of discovery.