@@ -354,7 +354,7 @@ ble_error_t GenericSecurityManager::enableSigning(
354
354
355
355
if (enabled && !cb->signing_requested && !_default_key_distribution.get_signing ()) {
356
356
cb->signing_requested = true ;
357
- if (flags->csrk_stored ) {
357
+ if (flags->csrk_stored && flags-> csrk_sent ) {
358
358
/* used the stored ones when available */
359
359
_db->get_entry_peer_csrk (
360
360
mbed::callback (this , &GenericSecurityManager::set_peer_csrk_cb),
@@ -389,7 +389,7 @@ ble_error_t GenericSecurityManager::getLinkEncryption(
389
389
connection_handle_t connection,
390
390
link_encryption_t *encryption
391
391
) {
392
-
392
+ MBED_ASSERT (_db);
393
393
ControlBlock_t *cb = get_control_block (connection);
394
394
if (!cb) {
395
395
return BLE_ERROR_INVALID_PARAM;
@@ -419,6 +419,7 @@ ble_error_t GenericSecurityManager::setLinkEncryption(
419
419
connection_handle_t connection,
420
420
link_encryption_t encryption
421
421
) {
422
+ MBED_ASSERT (_db);
422
423
ControlBlock_t *cb = get_control_block (connection);
423
424
if (!cb) {
424
425
return BLE_ERROR_INVALID_PARAM;
@@ -475,6 +476,7 @@ ble_error_t GenericSecurityManager::getEncryptionKeySize(
475
476
connection_handle_t connection,
476
477
uint8_t *size
477
478
) {
479
+ MBED_ASSERT (_db);
478
480
ControlBlock_t *cb = get_control_block (connection);
479
481
if (!cb) {
480
482
return BLE_ERROR_INVALID_PARAM;
@@ -547,6 +549,7 @@ ble_error_t GenericSecurityManager::setPrivateAddressTimeout(uint16_t timeout_in
547
549
//
548
550
549
551
ble_error_t GenericSecurityManager::requestAuthentication (connection_handle_t connection) {
552
+ MBED_ASSERT (_db);
550
553
ControlBlock_t *cb = get_control_block (connection);
551
554
if (!cb) {
552
555
return BLE_ERROR_INVALID_PARAM;
@@ -663,6 +666,7 @@ ble_error_t GenericSecurityManager::legacyPairingOobReceived(
663
666
const address_t *address,
664
667
const oob_tk_t *tk
665
668
) {
669
+ MBED_ASSERT (_db);
666
670
if (address && tk) {
667
671
ControlBlock_t *cb = get_control_block (*address);
668
672
if (!cb) {
@@ -792,6 +796,7 @@ void GenericSecurityManager::enable_encryption_cb(
792
796
SecurityDb::entry_handle_t db_entry,
793
797
const SecurityEntryKeys_t* entryKeys
794
798
) {
799
+ MBED_ASSERT (_db);
795
800
ControlBlock_t *cb = get_control_block (db_entry);
796
801
if (!cb) {
797
802
return ;
@@ -815,6 +820,7 @@ void GenericSecurityManager::set_ltk_cb(
815
820
SecurityDb::entry_handle_t db_entry,
816
821
const SecurityEntryKeys_t* entryKeys
817
822
) {
823
+ MBED_ASSERT (_db);
818
824
ControlBlock_t *cb = get_control_block (db_entry);
819
825
if (!cb) {
820
826
return ;
@@ -858,6 +864,7 @@ void GenericSecurityManager::return_csrk_cb(
858
864
SecurityDb::entry_handle_t db_entry,
859
865
const SecurityEntrySigning_t *signing
860
866
) {
867
+ MBED_ASSERT (_db);
861
868
ControlBlock_t *cb = get_control_block (db_entry);
862
869
if (!cb || !signing) {
863
870
return ;
@@ -876,6 +883,7 @@ void GenericSecurityManager::return_csrk_cb(
876
883
}
877
884
878
885
void GenericSecurityManager::update_oob_presence (connection_handle_t connection) {
886
+ MBED_ASSERT (_db);
879
887
ControlBlock_t *cb = get_control_block (connection);
880
888
if (!cb) {
881
889
return ;
@@ -1142,6 +1150,7 @@ void GenericSecurityManager::on_slave_security_request(
1142
1150
connection_handle_t connection,
1143
1151
AuthenticationMask authentication
1144
1152
) {
1153
+ MBED_ASSERT (_db);
1145
1154
ControlBlock_t *cb = get_control_block (connection);
1146
1155
if (!cb) {
1147
1156
return ;
@@ -1276,6 +1285,7 @@ void GenericSecurityManager::on_secure_connections_oob_request(connection_handle
1276
1285
}
1277
1286
1278
1287
void GenericSecurityManager::on_legacy_pairing_oob_request (connection_handle_t connection) {
1288
+ MBED_ASSERT (_db);
1279
1289
ControlBlock_t *cb = get_control_block (connection);
1280
1290
if (!cb) {
1281
1291
return ;
@@ -1334,6 +1344,7 @@ void GenericSecurityManager::on_secure_connections_ltk_generated(
1334
1344
1335
1345
flags->ltk_mitm_protected = cb->mitm_performed ;
1336
1346
flags->secure_connections_paired = true ;
1347
+ flags->ltk_stored = true ;
1337
1348
1338
1349
_db->set_entry_peer_ltk (cb->db_entry , ltk);
1339
1350
}
@@ -1354,6 +1365,7 @@ void GenericSecurityManager::on_keys_distributed_ltk(
1354
1365
}
1355
1366
1356
1367
flags->ltk_mitm_protected = cb->mitm_performed ;
1368
+ flags->ltk_stored = true ;
1357
1369
_db->set_entry_peer_ltk (cb->db_entry , ltk);
1358
1370
}
1359
1371
@@ -1381,6 +1393,12 @@ void GenericSecurityManager::on_keys_distributed_local_ltk(
1381
1393
return ;
1382
1394
}
1383
1395
1396
+ SecurityDistributionFlags_t* flags = _db->get_distribution_flags (cb->db_entry );
1397
+ if (!flags) {
1398
+ return ;
1399
+ }
1400
+
1401
+ flags->ltk_sent = true ;
1384
1402
_db->set_entry_local_ltk (cb->db_entry , ltk);
1385
1403
}
1386
1404
@@ -1408,6 +1426,12 @@ void GenericSecurityManager::on_keys_distributed_irk(
1408
1426
return ;
1409
1427
}
1410
1428
1429
+ SecurityDistributionFlags_t* flags = _db->get_distribution_flags (cb->db_entry );
1430
+ if (!flags) {
1431
+ return ;
1432
+ }
1433
+
1434
+ flags->irk_stored = true ;
1411
1435
_db->set_entry_peer_irk (cb->db_entry , irk);
1412
1436
}
1413
1437
@@ -1445,6 +1469,7 @@ void GenericSecurityManager::on_keys_distributed_csrk(
1445
1469
}
1446
1470
1447
1471
flags->csrk_mitm_protected = cb->mitm_performed ;
1472
+ flags->csrk_stored = true ;
1448
1473
1449
1474
_db->set_entry_peer_csrk (cb->db_entry , csrk);
1450
1475
@@ -1466,12 +1491,19 @@ void GenericSecurityManager::on_ltk_request(
1466
1491
return ;
1467
1492
}
1468
1493
1469
- _db->get_entry_local_keys (
1470
- mbed::callback (this , &GenericSecurityManager::set_ltk_cb),
1471
- cb->db_entry ,
1472
- ediv,
1473
- rand
1474
- );
1494
+ SecurityDistributionFlags_t* flags = _db->get_distribution_flags (cb->db_entry );
1495
+ if (!flags) {
1496
+ return ;
1497
+ }
1498
+
1499
+ if (flags->ltk_stored ) {
1500
+ _db->get_entry_local_keys (
1501
+ mbed::callback (this , &GenericSecurityManager::set_ltk_cb),
1502
+ cb->db_entry ,
1503
+ ediv,
1504
+ rand
1505
+ );
1506
+ }
1475
1507
}
1476
1508
1477
1509
/* control blocks list management */
@@ -1542,6 +1574,7 @@ GenericSecurityManager::ControlBlock_t* GenericSecurityManager::get_control_bloc
1542
1574
GenericSecurityManager::ControlBlock_t* GenericSecurityManager::get_control_block (
1543
1575
const address_t &peer_address
1544
1576
) {
1577
+ MBED_ASSERT (_db);
1545
1578
for (size_t i = 0 ; i < MAX_CONTROL_BLOCKS; i++) {
1546
1579
ControlBlock_t *cb = &_control_blocks[i];
1547
1580
if (cb->connected ) {
0 commit comments