@@ -26,8 +26,6 @@ namespace ble {
2626#error "BLE_SECURITY_DATABASE_MAX_ENTRIES must be only one digit long"
2727#endif
2828
29- #define ENTRY_INVALID (0xFF )
30-
3129constexpr uint8_t KVStoreSecurityDb::KVSTORESECURITYDB_VERSION;
3230constexpr size_t KVStoreSecurityDb::DB_PREFIX_SIZE;
3331constexpr size_t KVStoreSecurityDb::DB_KEY_SIZE;
@@ -54,9 +52,6 @@ typedef SecurityDb::entry_handle_t entry_handle_t;
5452KVStoreSecurityDb::KVStoreSecurityDb ()
5553 : SecurityDb() {
5654 memset (_entries, 0 , sizeof (_entries));
57- for (size_t i = 0 ; i < get_entry_count (); i++) {
58- _entries[i].index = ENTRY_INVALID;
59- }
6055}
6156
6257KVStoreSecurityDb::~KVStoreSecurityDb ()
@@ -95,7 +90,7 @@ bool KVStoreSecurityDb::erase_db()
9590
9691 /* we zero the database and make sure we can fit all our keys */
9792
98- db_write (zero.entries , DB_ENTRIES);
93+ db_write (& zero.entries , DB_ENTRIES);
9994 db_write ((SecurityEntryIdentity_t*)zero.buffer , DB_LOCAL_IDENTITY);
10095 db_write ((csrk_t *)zero.buffer , DB_LOCAL_CSRK);
10196 db_write ((sign_count_t *)zero.buffer , DB_LOCAL_SIGN_COUNT);
@@ -144,7 +139,7 @@ void KVStoreSecurityDb::set_entry_local_ltk(
144139 SecurityEntryKeys_t* current_entry = read_in_entry_local_keys (db_handle);
145140 current_entry->ltk = ltk;
146141
147- db_write_entry (current_entry, DB_ENTRY_LOCAL_KEYS, entry-> index );
142+ db_write_entry (current_entry, DB_ENTRY_LOCAL_KEYS, get_index ( entry) );
148143}
149144
150145void KVStoreSecurityDb::set_entry_local_ediv_rand (
@@ -162,7 +157,7 @@ void KVStoreSecurityDb::set_entry_local_ediv_rand(
162157 current_entry->ediv = ediv;
163158 current_entry->rand = rand;
164159
165- db_write_entry (current_entry, DB_ENTRY_LOCAL_KEYS, entry-> index );
160+ db_write_entry (current_entry, DB_ENTRY_LOCAL_KEYS, get_index ( entry) );
166161}
167162
168163/* peer's keys */
@@ -184,7 +179,7 @@ void KVStoreSecurityDb::set_entry_peer_ltk(
184179 SecurityEntryKeys_t* current_entry = read_in_entry_peer_keys (db_handle);
185180 current_entry->ltk = ltk;
186181
187- db_write_entry (current_entry, DB_ENTRY_PEER_KEYS, entry-> index );
182+ db_write_entry (current_entry, DB_ENTRY_PEER_KEYS, get_index ( entry) );
188183}
189184
190185void KVStoreSecurityDb::set_entry_peer_ediv_rand (
@@ -202,7 +197,7 @@ void KVStoreSecurityDb::set_entry_peer_ediv_rand(
202197 current_entry->ediv = ediv;
203198 current_entry->rand = rand;
204199
205- db_write_entry (current_entry, DB_ENTRY_PEER_KEYS, entry-> index );
200+ db_write_entry (current_entry, DB_ENTRY_PEER_KEYS, get_index ( entry) );
206201}
207202
208203void KVStoreSecurityDb::set_entry_peer_irk (
@@ -220,7 +215,7 @@ void KVStoreSecurityDb::set_entry_peer_irk(
220215 SecurityEntryIdentity_t* current_entry = read_in_entry_peer_identity (db_handle);
221216 current_entry->irk = irk;
222217
223- db_write_entry (current_entry, DB_ENTRY_PEER_IDENTITY, entry-> index );
218+ db_write_entry (current_entry, DB_ENTRY_PEER_IDENTITY, get_index ( entry) );
224219}
225220
226221void KVStoreSecurityDb::set_entry_peer_bdaddr (
@@ -238,7 +233,7 @@ void KVStoreSecurityDb::set_entry_peer_bdaddr(
238233 current_entry->identity_address = peer_address;
239234 current_entry->identity_address_is_public = address_is_public;
240235
241- db_write_entry (current_entry, DB_ENTRY_PEER_IDENTITY, entry-> index );
236+ db_write_entry (current_entry, DB_ENTRY_PEER_IDENTITY, get_index ( entry) );
242237}
243238
244239void KVStoreSecurityDb::set_entry_peer_csrk (
@@ -256,7 +251,7 @@ void KVStoreSecurityDb::set_entry_peer_csrk(
256251 SecurityEntrySigning_t* current_entry = read_in_entry_peer_signing (db_handle);
257252 current_entry->csrk = csrk;
258253
259- db_write_entry (current_entry, DB_ENTRY_PEER_SIGNING, entry-> index );
254+ db_write_entry (current_entry, DB_ENTRY_PEER_SIGNING, get_index ( entry) );
260255}
261256
262257void KVStoreSecurityDb::set_entry_peer_sign_counter (
@@ -349,16 +344,12 @@ void KVStoreSecurityDb::reset_entry(entry_handle_t db_handle)
349344 return ;
350345 }
351346
352- if (entry->index != ENTRY_INVALID) {
353- uint8_t zero_buffer[sizeof (SecurityEntryKeys_t)] = {0 };
347+ uint8_t zero_buffer[sizeof (SecurityEntryKeys_t)] = {0 };
354348
355- db_write_entry ((SecurityEntryKeys_t*)zero_buffer, DB_ENTRY_LOCAL_KEYS, entry->index );
356- db_write_entry ((SecurityEntryIdentity_t*)zero_buffer, DB_ENTRY_PEER_IDENTITY, entry->index );
357- db_write_entry ((SecurityEntryKeys_t*)zero_buffer, DB_ENTRY_PEER_KEYS, entry->index );
358- db_write_entry ((SecurityEntrySigning_t*)zero_buffer, DB_ENTRY_PEER_SIGNING, entry->index );
359-
360- entry->index = ENTRY_INVALID;
361- }
349+ db_write_entry ((SecurityEntryKeys_t*)zero_buffer, DB_ENTRY_LOCAL_KEYS, get_index (entry));
350+ db_write_entry ((SecurityEntryIdentity_t*)zero_buffer, DB_ENTRY_PEER_IDENTITY, get_index (entry));
351+ db_write_entry ((SecurityEntryKeys_t*)zero_buffer, DB_ENTRY_PEER_KEYS, get_index (entry));
352+ db_write_entry ((SecurityEntrySigning_t*)zero_buffer, DB_ENTRY_PEER_SIGNING, get_index (entry));
362353
363354 entry->flags = SecurityDistributionFlags_t ();
364355 entry->peer_sign_counter = 0 ;
@@ -372,7 +363,7 @@ SecurityEntryIdentity_t* KVStoreSecurityDb::read_in_entry_peer_identity(entry_ha
372363 }
373364
374365 SecurityEntryIdentity_t* identity = reinterpret_cast <SecurityEntryIdentity_t*>(_buffer);
375- db_read_entry (identity, DB_ENTRY_PEER_IDENTITY, entry-> index );
366+ db_read_entry (identity, DB_ENTRY_PEER_IDENTITY, get_index ( entry) );
376367
377368 return identity;
378369};
@@ -385,7 +376,7 @@ SecurityEntryKeys_t* KVStoreSecurityDb::read_in_entry_peer_keys(entry_handle_t d
385376 }
386377
387378 SecurityEntryKeys_t* keys = reinterpret_cast <SecurityEntryKeys_t*>(_buffer);
388- db_read_entry (keys, DB_ENTRY_PEER_KEYS, entry-> index );
379+ db_read_entry (keys, DB_ENTRY_PEER_KEYS, get_index ( entry) );
389380
390381 return keys;
391382};
@@ -398,7 +389,7 @@ SecurityEntryKeys_t* KVStoreSecurityDb::read_in_entry_local_keys(entry_handle_t
398389 }
399390
400391 SecurityEntryKeys_t* keys = reinterpret_cast <SecurityEntryKeys_t*>(_buffer);
401- db_read_entry (keys, DB_ENTRY_LOCAL_KEYS, entry-> index );
392+ db_read_entry (keys, DB_ENTRY_LOCAL_KEYS, get_index ( entry) );
402393
403394 return keys;
404395};
@@ -412,7 +403,7 @@ SecurityEntrySigning_t* KVStoreSecurityDb::read_in_entry_peer_signing(entry_hand
412403
413404 /* only read in the csrk */
414405 csrk_t * csrk = reinterpret_cast <csrk_t *>(_buffer);
415- db_read_entry (csrk, DB_ENTRY_PEER_SIGNING, entry-> index );
406+ db_read_entry (csrk, DB_ENTRY_PEER_SIGNING,get_index ( entry) );
416407
417408
418409 /* use the counter held in memory */
0 commit comments