@@ -26,8 +26,6 @@ namespace ble {
26
26
#error "BLE_SECURITY_DATABASE_MAX_ENTRIES must be only one digit long"
27
27
#endif
28
28
29
- #define ENTRY_INVALID (0xFF )
30
-
31
29
constexpr uint8_t KVStoreSecurityDb::KVSTORESECURITYDB_VERSION;
32
30
constexpr size_t KVStoreSecurityDb::DB_PREFIX_SIZE;
33
31
constexpr size_t KVStoreSecurityDb::DB_KEY_SIZE;
@@ -54,9 +52,6 @@ typedef SecurityDb::entry_handle_t entry_handle_t;
54
52
KVStoreSecurityDb::KVStoreSecurityDb ()
55
53
: SecurityDb() {
56
54
memset (_entries, 0 , sizeof (_entries));
57
- for (size_t i = 0 ; i < get_entry_count (); i++) {
58
- _entries[i].index = ENTRY_INVALID;
59
- }
60
55
}
61
56
62
57
KVStoreSecurityDb::~KVStoreSecurityDb ()
@@ -95,7 +90,7 @@ bool KVStoreSecurityDb::erase_db()
95
90
96
91
/* we zero the database and make sure we can fit all our keys */
97
92
98
- db_write (zero.entries , DB_ENTRIES);
93
+ db_write (& zero.entries , DB_ENTRIES);
99
94
db_write ((SecurityEntryIdentity_t*)zero.buffer , DB_LOCAL_IDENTITY);
100
95
db_write ((csrk_t *)zero.buffer , DB_LOCAL_CSRK);
101
96
db_write ((sign_count_t *)zero.buffer , DB_LOCAL_SIGN_COUNT);
@@ -144,7 +139,7 @@ void KVStoreSecurityDb::set_entry_local_ltk(
144
139
SecurityEntryKeys_t* current_entry = read_in_entry_local_keys (db_handle);
145
140
current_entry->ltk = ltk;
146
141
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) );
148
143
}
149
144
150
145
void KVStoreSecurityDb::set_entry_local_ediv_rand (
@@ -162,7 +157,7 @@ void KVStoreSecurityDb::set_entry_local_ediv_rand(
162
157
current_entry->ediv = ediv;
163
158
current_entry->rand = rand;
164
159
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) );
166
161
}
167
162
168
163
/* peer's keys */
@@ -184,7 +179,7 @@ void KVStoreSecurityDb::set_entry_peer_ltk(
184
179
SecurityEntryKeys_t* current_entry = read_in_entry_peer_keys (db_handle);
185
180
current_entry->ltk = ltk;
186
181
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) );
188
183
}
189
184
190
185
void KVStoreSecurityDb::set_entry_peer_ediv_rand (
@@ -202,7 +197,7 @@ void KVStoreSecurityDb::set_entry_peer_ediv_rand(
202
197
current_entry->ediv = ediv;
203
198
current_entry->rand = rand;
204
199
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) );
206
201
}
207
202
208
203
void KVStoreSecurityDb::set_entry_peer_irk (
@@ -220,7 +215,7 @@ void KVStoreSecurityDb::set_entry_peer_irk(
220
215
SecurityEntryIdentity_t* current_entry = read_in_entry_peer_identity (db_handle);
221
216
current_entry->irk = irk;
222
217
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) );
224
219
}
225
220
226
221
void KVStoreSecurityDb::set_entry_peer_bdaddr (
@@ -238,7 +233,7 @@ void KVStoreSecurityDb::set_entry_peer_bdaddr(
238
233
current_entry->identity_address = peer_address;
239
234
current_entry->identity_address_is_public = address_is_public;
240
235
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) );
242
237
}
243
238
244
239
void KVStoreSecurityDb::set_entry_peer_csrk (
@@ -256,7 +251,7 @@ void KVStoreSecurityDb::set_entry_peer_csrk(
256
251
SecurityEntrySigning_t* current_entry = read_in_entry_peer_signing (db_handle);
257
252
current_entry->csrk = csrk;
258
253
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) );
260
255
}
261
256
262
257
void KVStoreSecurityDb::set_entry_peer_sign_counter (
@@ -349,16 +344,12 @@ void KVStoreSecurityDb::reset_entry(entry_handle_t db_handle)
349
344
return ;
350
345
}
351
346
352
- if (entry->index != ENTRY_INVALID) {
353
- uint8_t zero_buffer[sizeof (SecurityEntryKeys_t)] = {0 };
347
+ uint8_t zero_buffer[sizeof (SecurityEntryKeys_t)] = {0 };
354
348
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));
362
353
363
354
entry->flags = SecurityDistributionFlags_t ();
364
355
entry->peer_sign_counter = 0 ;
@@ -372,7 +363,7 @@ SecurityEntryIdentity_t* KVStoreSecurityDb::read_in_entry_peer_identity(entry_ha
372
363
}
373
364
374
365
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) );
376
367
377
368
return identity;
378
369
};
@@ -385,7 +376,7 @@ SecurityEntryKeys_t* KVStoreSecurityDb::read_in_entry_peer_keys(entry_handle_t d
385
376
}
386
377
387
378
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) );
389
380
390
381
return keys;
391
382
};
@@ -398,7 +389,7 @@ SecurityEntryKeys_t* KVStoreSecurityDb::read_in_entry_local_keys(entry_handle_t
398
389
}
399
390
400
391
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) );
402
393
403
394
return keys;
404
395
};
@@ -412,7 +403,7 @@ SecurityEntrySigning_t* KVStoreSecurityDb::read_in_entry_peer_signing(entry_hand
412
403
413
404
/* only read in the csrk */
414
405
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) );
416
407
417
408
418
409
/* use the counter held in memory */
0 commit comments