Skip to content

Commit c9d0ff8

Browse files
ble security db complete sync implementation
1 parent 7b4d1d5 commit c9d0ff8

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

connectivity/FEATURE_BLE/source/generic/FileSecurityDb.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,22 @@ void FileSecurityDb::restore()
361361

362362
void FileSecurityDb::sync(entry_handle_t db_handle)
363363
{
364+
/* if no entry is selected we will sync all entries */
365+
if (db_handle == invalid_entry_handle) {
366+
/* only write the connected devices as others are already written */
367+
for (size_t i = 0; i < get_entry_count(); i++) {
368+
entry_handle_t db_handle = get_entry_handle_by_index(i);
369+
SecurityDistributionFlags_t* flags = get_distribution_flags(db_handle);
370+
371+
if (flags && flags->connected) {
372+
sync(db_handle);
373+
}
374+
}
375+
/* global sync triggers a flush */
376+
fflush(_db_file);
377+
return;
378+
}
379+
364380
entry_t *entry = as_entry(db_handle);
365381
if (!entry) {
366382
return;

connectivity/FEATURE_BLE/source/generic/KVStoreSecurityDb.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,22 @@ void KVStoreSecurityDb::restore()
333333

334334
void KVStoreSecurityDb::sync(entry_handle_t db_handle)
335335
{
336+
/* storage synchronisation is handled by KVStore itself, no explicit flushing */
337+
338+
/* if no entry is selected we will sync all entries */
339+
if (db_handle == invalid_entry_handle) {
340+
/* only write the connected devices as others are already written */
341+
for (size_t i = 0; i < get_entry_count(); i++) {
342+
entry_handle_t db_handle = get_entry_handle_by_index(i);
343+
SecurityDistributionFlags_t* flags = get_distribution_flags(db_handle);
344+
345+
if (flags && flags->connected) {
346+
sync(db_handle);
347+
}
348+
}
349+
return;
350+
}
351+
336352
entry_t *entry = as_entry(db_handle);
337353
if (!entry) {
338354
return;

connectivity/FEATURE_BLE/source/generic/SecurityDb.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,11 @@ class SecurityDb {
522522
virtual void restore();
523523

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

0 commit comments

Comments
 (0)