mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-26 09:41:01 +00:00
tlv: handle error for store_tag, document delete_tag expectations
This commit is contained in:
parent
88aeaf6c97
commit
0fe46bc15b
@ -898,7 +898,10 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_
|
||||
entry.value = value;
|
||||
entry.seq_nr = highest_seq_nr + 1;
|
||||
log_info("CCC Index %u: Store", index);
|
||||
tlv_impl->store_tag(tlv_context, tag, (const uint8_t *) &entry, sizeof(persistent_ccc_entry_t));
|
||||
int result = tlv_impl->store_tag(tlv_context, tag, (const uint8_t *) &entry, sizeof(persistent_ccc_entry_t));
|
||||
if (result != 0){
|
||||
log_error("Store tag index %u failed", index);
|
||||
}
|
||||
} else {
|
||||
// delete
|
||||
log_info("CCC Index %u: Delete", index);
|
||||
@ -907,7 +910,7 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_
|
||||
return;
|
||||
}
|
||||
|
||||
log_info("tag_for_empy %"PRIx32", tag_for_lowest_seq_nr %"PRIx32, tag_for_empty, tag_for_lowest_seq_nr);
|
||||
log_info("tag_for_empty %"PRIx32", tag_for_lowest_seq_nr %"PRIx32, tag_for_empty, tag_for_lowest_seq_nr);
|
||||
|
||||
if (value == 0){
|
||||
// done
|
||||
@ -928,7 +931,10 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_
|
||||
entry.device_index = le_device_index;
|
||||
entry.att_handle = att_handle;
|
||||
entry.value = value;
|
||||
tlv_impl->store_tag(tlv_context, tag_to_use, (uint8_t *) &entry, sizeof(persistent_ccc_entry_t));
|
||||
int result = tlv_impl->store_tag(tlv_context, tag_to_use, (uint8_t *) &entry, sizeof(persistent_ccc_entry_t));
|
||||
if (result != 0){
|
||||
log_error("Store tag index %u failed", index);
|
||||
}
|
||||
}
|
||||
|
||||
static void att_server_persistent_ccc_clear(att_server_t * att_server){
|
||||
|
@ -110,7 +110,7 @@ static uint32_t le_device_db_tlv_tag_for_index(uint8_t index){
|
||||
|
||||
// @returns success
|
||||
// @param index = entry_pos
|
||||
static int le_device_db_tlv_fetch(int index, le_device_db_entry_t * entry){
|
||||
static bool le_device_db_tlv_fetch(int index, le_device_db_entry_t * entry){
|
||||
btstack_assert(le_device_db_tlv_btstack_tlv_impl != NULL);
|
||||
btstack_assert(index >= 0);
|
||||
btstack_assert(index < NVM_NUM_DEVICE_DB_ENTRIES);
|
||||
@ -122,25 +122,25 @@ static int le_device_db_tlv_fetch(int index, le_device_db_entry_t * entry){
|
||||
|
||||
// @returns success
|
||||
// @param index = entry_pos
|
||||
static int le_device_db_tlv_store(int index, le_device_db_entry_t * entry){
|
||||
static bool le_device_db_tlv_store(int index, le_device_db_entry_t * entry){
|
||||
btstack_assert(le_device_db_tlv_btstack_tlv_impl != NULL);
|
||||
btstack_assert(index >= 0);
|
||||
btstack_assert(index < NVM_NUM_DEVICE_DB_ENTRIES);
|
||||
|
||||
uint32_t tag = le_device_db_tlv_tag_for_index(index);
|
||||
le_device_db_tlv_btstack_tlv_impl->store_tag(le_device_db_tlv_btstack_tlv_context, tag, (uint8_t*) entry, sizeof(le_device_db_entry_t));
|
||||
return 1;
|
||||
int result = le_device_db_tlv_btstack_tlv_impl->store_tag(le_device_db_tlv_btstack_tlv_context, tag, (uint8_t*) entry, sizeof(le_device_db_entry_t));
|
||||
return result == 0;
|
||||
}
|
||||
|
||||
// @param index = entry_pos
|
||||
static int le_device_db_tlv_delete(int index){
|
||||
static bool le_device_db_tlv_delete(int index){
|
||||
btstack_assert(le_device_db_tlv_btstack_tlv_impl != NULL);
|
||||
btstack_assert(index >= 0);
|
||||
btstack_assert(index < NVM_NUM_DEVICE_DB_ENTRIES);
|
||||
|
||||
uint32_t tag = le_device_db_tlv_tag_for_index(index);
|
||||
le_device_db_tlv_btstack_tlv_impl->delete_tag(le_device_db_tlv_btstack_tlv_context, tag);
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void le_device_db_tlv_scan(void){
|
||||
@ -256,8 +256,11 @@ int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){
|
||||
#endif
|
||||
|
||||
// store
|
||||
le_device_db_tlv_store(index_to_use, &entry);
|
||||
|
||||
bool ok = le_device_db_tlv_store(index_to_use, &entry);
|
||||
if (!ok){
|
||||
log_error("tag store failed");
|
||||
return -1;
|
||||
}
|
||||
// set in entry_mape
|
||||
entry_map[index_to_use] = 1;
|
||||
|
||||
@ -308,7 +311,10 @@ void le_device_db_encryption_set(int index, uint16_t ediv, uint8_t rand[8], sm_k
|
||||
entry.secure_connection = secure_connection;
|
||||
|
||||
// store
|
||||
le_device_db_tlv_store(index, &entry);
|
||||
ok = le_device_db_tlv_store(index, &entry);
|
||||
if (!ok){
|
||||
log_error("Set encryption data failed");
|
||||
}
|
||||
}
|
||||
|
||||
void le_device_db_encryption_get(int index, uint16_t * ediv, uint8_t rand[8], sm_key_t ltk, int * key_size, int * authenticated, int * authorized, int * secure_connection){
|
||||
|
@ -69,6 +69,7 @@ typedef struct {
|
||||
|
||||
/**
|
||||
* Delete Tag
|
||||
* @note it is not expected that delete operation fails, please use at least log_error in case of errors
|
||||
* @param context
|
||||
* @param tag
|
||||
*/
|
||||
|
@ -171,7 +171,10 @@ static void btstack_link_key_db_tlv_put_link_key(bd_addr_t bd_addr, link_key_t l
|
||||
entry.link_key_type = link_key_type;
|
||||
entry.seq_nr = highest_seq_nr + 1;
|
||||
|
||||
self->btstack_tlv_impl->store_tag(self->btstack_tlv_context, tag_to_use, (uint8_t*) &entry, sizeof(entry));
|
||||
int result = self->btstack_tlv_impl->store_tag(self->btstack_tlv_context, tag_to_use, (uint8_t*) &entry, sizeof(entry));
|
||||
if (result != 0){
|
||||
log_error("store link key failed");
|
||||
}
|
||||
}
|
||||
|
||||
static int btstack_link_key_db_tlv_iterator_init(btstack_link_key_iterator_t * it){
|
||||
|
@ -335,6 +335,12 @@ static void hci_packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *
|
||||
}
|
||||
}
|
||||
|
||||
static void report_store_error(int result, const char * type){
|
||||
if (result != 0){
|
||||
log_error("Store %s data failed", type);
|
||||
}
|
||||
}
|
||||
|
||||
// Foundation state
|
||||
static const uint32_t mesh_foundation_state_tag = ((uint32_t) 'M' << 24) | ((uint32_t) 'F' << 16) | ((uint32_t) 'N' << 8) | ((uint32_t) 'D' << 8);
|
||||
|
||||
@ -362,7 +368,8 @@ void mesh_foundation_state_store(void){
|
||||
data.network_transmit = mesh_foundation_network_transmit_get();
|
||||
data.relay = mesh_foundation_relay_get();
|
||||
data.relay_retransmit = mesh_foundation_relay_retransmit_get();
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_foundation_state_tag, (uint8_t *) &data, sizeof(data));
|
||||
report_store_error(result, "foundation");
|
||||
}
|
||||
|
||||
// Mesh Virtual Address Management
|
||||
@ -375,7 +382,8 @@ static void mesh_store_virtual_address(uint16_t pseudo_dest, uint16_t hash, cons
|
||||
uint32_t tag = mesh_virtual_address_tag_for_pseudo_dst(pseudo_dest);
|
||||
data.hash = hash;
|
||||
memcpy(data.label_uuid, label_uuid, 16);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
report_store_error(result, "virtual address");
|
||||
}
|
||||
|
||||
static void mesh_delete_virtual_address(uint16_t pseudo_dest){
|
||||
@ -458,7 +466,8 @@ static void mesh_model_load_subscriptions(mesh_model_t * mesh_model){
|
||||
|
||||
void mesh_model_store_subscriptions(mesh_model_t * model){
|
||||
uint32_t tag = mesh_model_subscription_tag_for_index(model->mid);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->subscriptions, sizeof(model->subscriptions));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->subscriptions, sizeof(model->subscriptions));
|
||||
report_store_error(result, "subscription");
|
||||
}
|
||||
|
||||
static void mesh_model_delete_subscriptions(mesh_model_t * model){
|
||||
@ -543,7 +552,8 @@ void mesh_model_store_publication(mesh_model_t * mesh_model){
|
||||
data.publish_period = publication->period;
|
||||
data.publish_retransmit = publication->retransmit;
|
||||
uint32_t tag = mesh_model_publication_tag_for_index(mesh_model->mid);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(mesh_persistent_publication_t));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(mesh_persistent_publication_t));
|
||||
report_store_error(result, "publication");
|
||||
}
|
||||
|
||||
static void mesh_model_delete_publication(mesh_model_t * mesh_model){
|
||||
@ -603,7 +613,8 @@ void mesh_store_network_key(mesh_network_key_t * network_key){
|
||||
data.version = network_key->version;
|
||||
memcpy(data.encryption_key, network_key->encryption_key, 16);
|
||||
memcpy(data.privacy_key, network_key->privacy_key, 16);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(mesh_persistent_net_key_t));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(mesh_persistent_net_key_t));
|
||||
report_store_error(result, "network key");
|
||||
}
|
||||
|
||||
void mesh_delete_network_key(uint16_t internal_index){
|
||||
@ -676,7 +687,8 @@ void mesh_store_app_key(mesh_transport_key_t * app_key){
|
||||
data.aid = app_key->aid;
|
||||
data.version = app_key->version;
|
||||
memcpy(data.key, app_key->key, 16);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &data, sizeof(data));
|
||||
report_store_error(result, "app key");
|
||||
}
|
||||
|
||||
void mesh_delete_app_key(uint16_t internal_index){
|
||||
@ -735,7 +747,8 @@ static void mesh_load_appkey_list(mesh_model_t * model){
|
||||
|
||||
static void mesh_store_appkey_list(mesh_model_t * model){
|
||||
uint32_t tag = mesh_model_tag_for_index(model->mid);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->appkey_indices, sizeof(model->appkey_indices));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, tag, (uint8_t *) &model->appkey_indices, sizeof(model->appkey_indices));
|
||||
report_store_error(result, "appkey list");
|
||||
}
|
||||
|
||||
static void mesh_delete_appkey_list(mesh_model_t * model){
|
||||
@ -854,7 +867,8 @@ static void mesh_store_iv_index_and_sequence_number(uint32_t iv_index, uint32_t
|
||||
iv_index_and_sequence_number_t data;
|
||||
data.iv_index = iv_index;
|
||||
data.seq_number = sequence_number;
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_tag_for_iv_index_and_seq_number, (uint8_t *) &data, sizeof(data));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_tag_for_iv_index_and_seq_number, (uint8_t *) &data, sizeof(data));
|
||||
report_store_error(result, "index and sequence number");
|
||||
|
||||
sequence_number_last_stored = data.seq_number;
|
||||
sequence_number_storage_trigger = sequence_number_last_stored + MESH_SEQUENCE_NUMBER_STORAGE_INTERVAL;
|
||||
@ -1025,7 +1039,8 @@ static void mesh_node_store_provisioning_data(mesh_provisioning_data_t * provisi
|
||||
|
||||
// store in tlv
|
||||
btstack_tlv_get_instance(&btstack_tlv_singleton_impl, &btstack_tlv_singleton_context);
|
||||
btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_tag_for_prov_data, (uint8_t *) &persistent_provisioning_data, sizeof(mesh_persistent_provisioning_data_t));
|
||||
int result = btstack_tlv_singleton_impl->store_tag(btstack_tlv_singleton_context, mesh_tag_for_prov_data, (uint8_t *) &persistent_provisioning_data, sizeof(mesh_persistent_provisioning_data_t));
|
||||
report_store_error(result, "provisioning");
|
||||
|
||||
// store IV Index and sequence number
|
||||
mesh_store_iv_index_and_sequence_number(provisioning_data->iv_index, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user