From d03dbc9c8de54e78de1d2f00e5665175e7c2e6f4 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Wed, 28 Aug 2024 09:12:26 +0200 Subject: [PATCH] gatt_client: extract report_gatt_characteristic_value_change for notification/indications --- src/ble/gatt_client.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index a079cf69c..c64bff0b1 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -1177,14 +1177,18 @@ static void report_gatt_included_service_uuid128(gatt_client_t * gatt_client, ui gatt_client->query_end_handle, uuid128); } -// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes -static void report_gatt_notification(gatt_client_t *gatt_client, uint16_t value_handle, uint8_t *value, int length) { - if (!gatt_client_accept_server_message(gatt_client)) return; - uint8_t * packet = setup_characteristic_value_packet(gatt_client, GATT_EVENT_NOTIFICATION, value_handle, +static void report_gatt_characteristic_value_change(gatt_client_t *gatt_client, uint8_t event_type, uint16_t value_handle, uint8_t *value, int length) { + uint8_t * packet = setup_characteristic_value_packet(gatt_client, event_type, value_handle, value, length, 0, 0); emit_event_to_registered_listeners(gatt_client->con_handle, value_handle, packet, CHARACTERISTIC_VALUE_EVENT_HEADER_SIZE + length); } +// @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes +static void report_gatt_notification(gatt_client_t *gatt_client, uint16_t value_handle, uint8_t *value, int length) { + if (!gatt_client_accept_server_message(gatt_client)) return; + report_gatt_characteristic_value_change(gatt_client, GATT_EVENT_NOTIFICATION, value_handle, value, length); +} + // @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes static void report_gatt_indication(gatt_client_t *gatt_client, uint16_t value_handle, uint8_t *value, int length) { if (!gatt_client_accept_server_message(gatt_client)) return; @@ -1197,9 +1201,7 @@ static void report_gatt_indication(gatt_client_t *gatt_client, uint16_t value_ha gatt_client_service_emit_service_changed(gatt_client, value, length); } #endif - uint8_t * packet = setup_characteristic_value_packet(gatt_client, GATT_EVENT_INDICATION, value_handle, - value, length, 0, 0); - emit_event_to_registered_listeners(gatt_client->con_handle, value_handle, packet, CHARACTERISTIC_VALUE_EVENT_HEADER_SIZE + length); + report_gatt_characteristic_value_change(gatt_client, GATT_EVENT_INDICATION, value_handle, value, length); } // @note assume that value is part of an l2cap buffer - overwrite parts of the HCI/L2CAP/ATT packet (4/4/3) bytes