diff --git a/CHANGELOG.md b/CHANGELOG.md index 889c32afc..49985f888 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - GAP: support extended advertising with ENABLE_LE_EXTENDED_ADVERTISING +- ATT DB: provide gatt_server_get_handle_range_for_service_with_uuid16 to find included service within handle range ### Fixed - GAP: disable scanning, advertising, connection before updating random address diff --git a/src/ble/att_db.c b/src/ble/att_db.c index db941d7e9..d7786cad6 100644 --- a/src/ble/att_db.c +++ b/src/ble/att_db.c @@ -1542,6 +1542,34 @@ uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uui } +bool gatt_server_get_included_service_with_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t uuid16, + uint16_t * out_included_service_handle, uint16_t * out_included_service_start_handle, uint16_t * out_included_service_end_handle){ + + att_iterator_t it; + att_iterator_init(&it); + while (att_iterator_has_next(&it)){ + att_iterator_fetch_next(&it); + if ((it.handle != 0u) && (it.handle < start_handle)){ + continue; + } + if (it.handle > end_handle){ + break; // (1) + } + if (it.handle == 0u){ + break; + } + if ((it.value_len == 6) && (att_iterator_match_uuid16(&it, GATT_INCLUDE_SERVICE_UUID))){ + if (little_endian_read_16(it.value, 4) == uuid16){ + *out_included_service_handle = it.handle; + *out_included_service_start_handle = little_endian_read_16(it.value, 0); + *out_included_service_end_handle = little_endian_read_16(it.value, 2); + return true; + } + } + } + return false; +} + // 1-item cache to optimize query during write_callback static void att_persistent_ccc_cache(att_iterator_t * it){ att_persistent_ccc_handle = it->handle; diff --git a/src/ble/att_db.h b/src/ble/att_db.h index 41308c467..02e044896 100644 --- a/src/ble/att_db.h +++ b/src/ble/att_db.h @@ -309,6 +309,19 @@ uint16_t att_uuid_for_handle(uint16_t attribute_handle); */ bool gatt_server_get_handle_range_for_service_with_uuid16(uint16_t uuid16, uint16_t * start_handle, uint16_t * end_handle); +/** + * @brief Get handle range for included service. + * @param start_handle + * @param end_handle + * @param uuid16 + * @param out_included_service_handle + * @param out_included_service_start_handle + * @param out_included_service_end_handle + * @return false if not found + */ +bool gatt_server_get_included_service_with_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t uuid16, + uint16_t * out_included_service_handle, uint16_t * out_included_service_start_handle, uint16_t * out_included_service_end_handle); + /** * @brief Get value handle for characteristic. * @param start_handle