Skip to content

Commit bcca759

Browse files
reseting the security db
1 parent c2bbc94 commit bcca759

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

features/FEATURE_BLE/ble/generic/FileSecurityDb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ class FileSecurityDb : public SecurityDb {
126126

127127
virtual void set_restore(bool reload);
128128

129+
virtual void reset();
130+
129131
private:
130132
virtual uint8_t get_entry_count();
131133

features/FEATURE_BLE/ble/generic/MemorySecurityDb.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ class MemorySecurityDb : public SecurityDb {
148148
}
149149
}
150150

151+
152+
/* saving and loading from nvm */
153+
154+
virtual void reset() {
155+
SecurityDb::reset();
156+
for (size_t i = 0; i < MAX_ENTRIES; ++i) {
157+
_entries[i] = entry_t();
158+
}
159+
}
160+
151161
private:
152162
virtual uint8_t get_entry_count() {
153163
return MAX_ENTRIES;

features/FEATURE_BLE/ble/generic/SecurityDb.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,15 @@ class SecurityDb {
656656
*/
657657
virtual void set_restore(bool reload) { };
658658

659+
/**
660+
* Reset the databse by removing all information
661+
*/
662+
virtual void reset() {
663+
_local_identity = SecurityEntryIdentity_t();
664+
_local_csrk = csrk_t();
665+
_local_sign_counter = 0;
666+
}
667+
659668
private:
660669
/**
661670
* Get an entry for a new connection not present in the db yet. This will find a free entry

features/FEATURE_BLE/source/generic/FileSecurityDb.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ void FileSecurityDb::set_restore(bool reload) {
304304
db_write(&reload, DB_OFFSET_RESTORE);
305305
}
306306

307+
void FileSecurityDb::reset() {
308+
SecurityDb::reset();
309+
erase_db_file(_db_file);
310+
}
311+
307312
/* helper functions */
308313

309314
uint8_t FileSecurityDb::get_entry_count() {

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ ble_error_t GenericSecurityManager::init(
116116
}
117117

118118
ble_error_t GenericSecurityManager::reset(void) {
119+
MBED_ASSERT(_db);
119120
_pal.reset();
121+
_db->reset();
120122
SecurityManager::reset();
121123

122124
return BLE_ERROR_NONE;

0 commit comments

Comments
 (0)