att_db: add att_is_persistent_ccc

This commit is contained in:
Matthias Ringwald 2017-10-23 14:52:17 +02:00
parent 3d71c7a4e0
commit 8b1d64c6f3
2 changed files with 39 additions and 0 deletions

View File

@ -65,12 +65,19 @@ static uint16_t uuid16_from_uuid(uint16_t uuid_len, uint8_t * uuid){
}
// ATT Database
static void att_persistent_ccc_cache(uint16_t handle, uint16_t flags);
static uint8_t const * att_db = NULL;
static att_read_callback_t att_read_callback = NULL;
static att_write_callback_t att_write_callback = NULL;
static uint8_t att_prepare_write_error_code = 0;
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;
// new java-style iterator
typedef struct att_iterator {
// private
@ -890,6 +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.flags);
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);
@ -1003,6 +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.flags);
(*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_NONE, 0, request_buffer + 3, request_len - 3);
}
@ -1175,6 +1184,26 @@ uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uui
return 0;
}
// 1-item cache to optimize query during write_callback
static void att_persistent_ccc_cache(uint16_t handle, uint16_t flags){
att_persistent_ccc_flags = flags;
att_persistent_ccc_handle = handle;
}
int att_is_persistent_ccc(uint16_t handle){
uint16_t flags = 0;
if (handle == att_persistent_ccc_handle){
flags = att_persistent_ccc_flags;
} else {
att_iterator_t it;
int ok = att_find_handle(&it, handle);
if (ok) {
flags = it.flags;
}
}
return flags & ATT_DB_PERSISTENT_WRITE_CCC;
}
// att_read_callback helpers
uint16_t att_read_callback_handle_blob(const uint8_t * blob, uint16_t blob_size, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){
if (buffer){

View File

@ -230,6 +230,16 @@ uint16_t gatt_server_get_value_handle_for_characteristic_with_uuid16(uint16_t st
// returns 0 if not found
uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(uint16_t start_handle, uint16_t end_handle, uint16_t uuid16);
// non-user functionality for att_server
/*
* @brief Check if writes to handle should be persistent
* @param handle
* @returns 1 if persistent
*/
int att_is_persistent_ccc(uint16_t handle);
#if defined __cplusplus
}
#endif