diff --git a/src/ble/att_db.c b/src/ble/att_db.c index 213b4b6c3..7e4325b2f 100644 --- a/src/ble/att_db.c +++ b/src/ble/att_db.c @@ -79,7 +79,7 @@ typedef struct att_iterator { uint8_t const * value; } att_iterator_t; -static void att_persistent_ccc_cache(uint16_t handle, att_iterator_t * it); +static void att_persistent_ccc_cache(att_iterator_t * it); static uint8_t const * att_db = NULL; static att_read_callback_t att_read_callback = NULL; @@ -89,7 +89,7 @@ static uint16_t att_prepare_write_error_handle = 0x0000; // single cache for att_is_persistent_ccc - stores flags before write callback static uint16_t att_persistent_ccc_handle; -static uint16_t att_persistent_ccc_flags; +static uint16_t att_persistent_ccc_uuid16; static void att_iterator_init(att_iterator_t *it){ it->att_ptr = att_db; @@ -897,7 +897,7 @@ static uint16_t handle_write_request(att_connection_t * att_connection, uint8_t if (error_code) { return setup_error(response_buffer, request_type, handle, error_code); } - att_persistent_ccc_cache(handle, &it); + att_persistent_ccc_cache(&it); error_code = (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_NONE, 0, request_buffer + 3, request_len - 3); if (error_code) { return setup_error(response_buffer, request_type, handle, error_code); @@ -1011,7 +1011,7 @@ static void handle_write_command(att_connection_t * att_connection, uint8_t * re if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0) return; if ((it.flags & ATT_PROPERTY_WRITE_WITHOUT_RESPONSE) == 0) return; if (att_validate_security(att_connection, &it)) return; - att_persistent_ccc_cache(handle, &it); + att_persistent_ccc_cache(&it); (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_NONE, 0, request_buffer + 3, request_len - 3); } @@ -1185,23 +1185,23 @@ uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uui } // 1-item cache to optimize query during write_callback -static void att_persistent_ccc_cache(uint16_t handle, att_iterator_t * it){ - att_persistent_ccc_flags = it->flags; - att_persistent_ccc_handle = handle; +static void att_persistent_ccc_cache(att_iterator_t * it){ + att_persistent_ccc_handle = it->handle; + if (it->flags & ATT_PROPERTY_UUID128){ + att_persistent_ccc_uuid16 = 0; + } else { + att_persistent_ccc_uuid16 = little_endian_read_16(it->uuid, 0); + } } int att_is_persistent_ccc(uint16_t handle){ - uint16_t flags = 0; - if (handle == att_persistent_ccc_handle){ - flags = att_persistent_ccc_flags; - } else { + if (handle != att_persistent_ccc_handle){ att_iterator_t it; int ok = att_find_handle(&it, handle); - if (ok) { - flags = it.flags; - } + if (!ok) return 0; + att_persistent_ccc_cache(&it); } - return flags & ATT_DB_PERSISTENT_WRITE_CCC; + return att_persistent_ccc_uuid16 == GATT_CLIENT_CHARACTERISTICS_CONFIGURATION; } // att_read_callback helpers