diff --git a/CHANGELOG.md b/CHANGELOG.md index 98a89811c..2077b8a8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed +## Changes March 2020 + +### Added +GATT Client: allow to register for any notification/indication and/or any connection + ## Changes Februar 2020 ### Fixed diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index 34c25acf3..5e125f5f1 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -491,7 +491,11 @@ static void emit_event_new(btstack_packet_handler_t callback, uint8_t * packet, void gatt_client_listen_for_characteristic_value_updates(gatt_client_notification_t * notification, btstack_packet_handler_t packet_handler, hci_con_handle_t con_handle, gatt_client_characteristic_t * characteristic){ notification->callback = packet_handler; notification->con_handle = con_handle; - notification->attribute_handle = characteristic->value_handle; + if (characteristic == NULL){ + notification->attribute_handle = GATT_CLIENT_ANY_VALUE_HANDLE; + } else { + notification->attribute_handle = characteristic->value_handle; + } btstack_linked_list_add(&gatt_client_value_listeners, (btstack_linked_item_t*) notification); } @@ -504,8 +508,8 @@ static void emit_event_to_registered_listeners(hci_con_handle_t con_handle, uint btstack_linked_list_iterator_init(&it, &gatt_client_value_listeners); while (btstack_linked_list_iterator_has_next(&it)){ gatt_client_notification_t * notification = (gatt_client_notification_t*) btstack_linked_list_iterator_next(&it); - if (notification->con_handle != con_handle) continue; - if (notification->attribute_handle != attribute_handle) continue; + if ((notification->con_handle != GATT_CLIENT_ANY_CONNECTION) && (notification->con_handle != con_handle)) continue; + if ((notification->attribute_handle != GATT_CLIENT_ANY_VALUE_HANDLE) && (notification->attribute_handle != attribute_handle)) continue; (*notification->callback)(HCI_EVENT_PACKET, 0, packet, size); } } diff --git a/src/ble/gatt_client.h b/src/ble/gatt_client.h index 9bba696c2..5b3f566c6 100644 --- a/src/ble/gatt_client.h +++ b/src/ble/gatt_client.h @@ -691,8 +691,8 @@ uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_han * @brief Register for notifications and indications of a characteristic enabled by gatt_client_write_client_characteristic_configuration * @param notification struct used to store registration * @param callback - * @param con_handle - * @param characteristic + * @param con_handle or GATT_CLIENT_ANY_CONNECTION to receive updates from all connected devices + * @param characteristic or NULL to receive updates for all characteristics */ 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); diff --git a/src/bluetooth.h b/src/bluetooth.h index 7cd30127e..0986383bc 100644 --- a/src/bluetooth.h +++ b/src/bluetooth.h @@ -632,6 +632,9 @@ typedef enum { #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION 1 #define GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION 2 +#define GATT_CLIENT_ANY_CONNECTION 0xffff +#define GATT_CLIENT_ANY_VALUE_HANDLE 0x0000 + // GAP Service and Characteristics #define GAP_SERVICE_UUID 0x1800 #define GAP_DEVICE_NAME_UUID 0x2a00