Skip to content

Commit

Permalink
ble security db complete sync implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-szczepanek-arm committed Jun 23, 2021
1 parent 7b4d1d5 commit c9d0ff8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
16 changes: 16 additions & 0 deletions connectivity/FEATURE_BLE/source/generic/FileSecurityDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ void FileSecurityDb::restore()

void FileSecurityDb::sync(entry_handle_t db_handle)
{
/* if no entry is selected we will sync all entries */
if (db_handle == invalid_entry_handle) {
/* only write the connected devices as others are already written */
for (size_t i = 0; i < get_entry_count(); i++) {
entry_handle_t db_handle = get_entry_handle_by_index(i);
SecurityDistributionFlags_t* flags = get_distribution_flags(db_handle);

if (flags && flags->connected) {
sync(db_handle);
}
}
/* global sync triggers a flush */
fflush(_db_file);
return;
}

entry_t *entry = as_entry(db_handle);
if (!entry) {
return;
Expand Down
16 changes: 16 additions & 0 deletions connectivity/FEATURE_BLE/source/generic/KVStoreSecurityDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,22 @@ void KVStoreSecurityDb::restore()

void KVStoreSecurityDb::sync(entry_handle_t db_handle)
{
/* storage synchronisation is handled by KVStore itself, no explicit flushing */

/* if no entry is selected we will sync all entries */
if (db_handle == invalid_entry_handle) {
/* only write the connected devices as others are already written */
for (size_t i = 0; i < get_entry_count(); i++) {
entry_handle_t db_handle = get_entry_handle_by_index(i);
SecurityDistributionFlags_t* flags = get_distribution_flags(db_handle);

if (flags && flags->connected) {
sync(db_handle);
}
}
return;
}

entry_t *entry = as_entry(db_handle);
if (!entry) {
return;
Expand Down
6 changes: 5 additions & 1 deletion connectivity/FEATURE_BLE/source/generic/SecurityDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,11 @@ class SecurityDb {
virtual void restore();

/**
* Flush all values which might be stored in memory into NVM.
* Write all values and attempt to sync persistent storage. Passing in an optional valid
* db_handle will only write the given entry and not attempt to flush buffers.
*
* @param db_handle database entry to write. If invalid all entries are written and
* persistent storage attempts to sync (flush buffers).
*/
virtual void sync(entry_handle_t db_handle = invalid_entry_handle);

Expand Down

0 comments on commit c9d0ff8

Please sign in to comment.