Skip to content

Commit d361960

Browse files
committed
BLE: Use peer_address_type_t instead of the legacy address in security manager.
1 parent a052afd commit d361960

File tree

4 files changed

+27
-15
lines changed

4 files changed

+27
-15
lines changed

features/FEATURE_BLE/ble/generic/GenericSecurityManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,12 @@ class GenericSecurityManager : public SecurityManager,
381381
virtual void on_connected(
382382
connection_handle_t connection,
383383
Gap::Role_t role,
384-
BLEProtocol::AddressType_t peer_address_type,
384+
peer_address_type_t peer_address_type,
385385
const BLEProtocol::AddressBytes_t peer_address,
386386
BLEProtocol::AddressType_t local_address_type,
387387
const BLEProtocol::AddressBytes_t local_address,
388-
const Gap::ConnectionParams_t *connection_params
388+
const Gap::ConnectionParams_t *connection_params,
389+
const BLEProtocol::AddressBytes_t resolved_peer_address
389390
);
390391

391392
/**

features/FEATURE_BLE/ble/generic/SecurityDb.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ class SecurityDb {
440440
* @return A handle to the entry.
441441
*/
442442
virtual entry_handle_t open_entry(
443-
BLEProtocol::AddressType_t peer_address_type,
443+
peer_address_type_t peer_address_type,
444444
const address_t &peer_address
445445
) {
446446
entry_handle_t db_handle = find_entry_by_peer_address(peer_address_type, peer_address);
@@ -451,8 +451,8 @@ class SecurityDb {
451451
SecurityDistributionFlags_t* flags = get_free_entry_flags();
452452
if (flags) {
453453
const bool peer_address_public =
454-
(peer_address_type == BLEProtocol::AddressType::PUBLIC) ||
455-
(peer_address_type == BLEProtocol::AddressType::PUBLIC_IDENTITY);
454+
(peer_address_type == peer_address_type_t::PUBLIC) ||
455+
(peer_address_type == peer_address_type_t::PUBLIC_IDENTITY);
456456
/* we need some address to store, so we store even random ones
457457
* this address will be used as an id, possibly replaced later
458458
* by identity address */
@@ -473,20 +473,20 @@ class SecurityDb {
473473
* @return A handle to the entry.
474474
*/
475475
virtual entry_handle_t find_entry_by_peer_address(
476-
BLEProtocol::AddressType_t peer_address_type,
476+
peer_address_type_t peer_address_type,
477477
const address_t &peer_address
478478
) {
479479
const bool peer_address_public =
480-
(peer_address_type == BLEProtocol::AddressType::PUBLIC) ||
481-
(peer_address_type == BLEProtocol::AddressType::PUBLIC_IDENTITY);
480+
(peer_address_type == peer_address_type_t::PUBLIC) ||
481+
(peer_address_type == peer_address_type_t::PUBLIC_IDENTITY);
482482

483483
for (size_t i = 0; i < get_entry_count(); i++) {
484484
entry_handle_t db_handle = get_entry_handle_by_index(i);
485485
SecurityDistributionFlags_t* flags = get_distribution_flags(db_handle);
486486

487487
/* only look among disconnected entries */
488488
if (flags && !flags->connected) {
489-
if (peer_address_type == BLEProtocol::AddressType::PUBLIC_IDENTITY &&
489+
if (peer_address_type == peer_address_type_t::PUBLIC_IDENTITY &&
490490
flags->irk_stored == false) {
491491
continue;
492492
}
@@ -536,7 +536,7 @@ class SecurityDb {
536536
* @return A handle to the entry.
537537
*/
538538
virtual void remove_entry(
539-
BLEProtocol::AddressType_t peer_address_type,
539+
peer_address_type_t peer_address_type,
540540
const address_t &peer_address
541541
) {
542542
entry_handle_t db_handle = find_entry_by_peer_address(peer_address_type, peer_address);

features/FEATURE_BLE/ble/pal/ConnectionEventMonitor.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,18 @@ class ConnectionEventMonitor {
4848
* @param[in] local_address_type type of address of the local device.
4949
* @param[in] local_address Address of the local device that was used during connection.
5050
* @param[in] connection_params connection parameters like interval, latency and timeout.
51+
* @param[in] resolved_peer_address resolved address of the peer; may
52+
* be NULL.
5153
*/
5254
virtual void on_connected(
5355
connection_handle_t connection,
5456
::Gap::Role_t role,
55-
BLEProtocol::AddressType_t peer_address_type,
57+
ble::peer_address_type_t peer_address_type,
5658
const BLEProtocol::AddressBytes_t peer_address,
5759
BLEProtocol::AddressType_t local_address_type,
5860
const BLEProtocol::AddressBytes_t local_address,
59-
const ::Gap::ConnectionParams_t *connection_params
61+
const ::Gap::ConnectionParams_t *connection_params,
62+
const BLEProtocol::AddressBytes_t resolved_peer_address
6063
) = 0;
6164

6265
/**

features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,11 +964,12 @@ void GenericSecurityManager::set_mitm_performed(connection_handle_t connection,
964964
void GenericSecurityManager::on_connected(
965965
connection_handle_t connection,
966966
Gap::Role_t role,
967-
BLEProtocol::AddressType_t peer_address_type,
967+
peer_address_type_t peer_address_type,
968968
const BLEProtocol::AddressBytes_t peer_address,
969969
BLEProtocol::AddressType_t local_address_type,
970970
const BLEProtocol::AddressBytes_t local_address,
971-
const Gap::ConnectionParams_t *connection_params
971+
const Gap::ConnectionParams_t *connection_params,
972+
const BLEProtocol::AddressBytes_t resolved_peer_address
972973
) {
973974
MBED_ASSERT(_db);
974975
ControlBlock_t *cb = acquire_control_block(connection);
@@ -980,13 +981,20 @@ void GenericSecurityManager::on_connected(
980981
cb->local_address = local_address;
981982
cb->is_master = (role == Gap::CENTRAL);
982983

984+
// normalize the address
985+
if (resolved_peer_address && resolved_peer_address != ble::address_t()) {
986+
peer_address = resolved_peer_address;
987+
}
988+
983989
// get the associated db handle and the distribution flags if any
984990
cb->db_entry = _db->open_entry(peer_address_type, peer_address);
985991

986992
SecurityDistributionFlags_t* flags = _db->get_distribution_flags(cb->db_entry);
987993

988994
flags->peer_address = peer_address;
989-
flags->peer_address_is_public = (peer_address_type == BLEProtocol::AddressType::PUBLIC);
995+
flags->peer_address_is_public =
996+
(peer_address_type == peer_address_type_t::PUBLIC) ||
997+
(peer_address_type == peer_address_type_t::PUBLIC_IDENTITY);
990998

991999
const bool signing = cb->signing_override_default ?
9921000
cb->signing_requested :

0 commit comments

Comments
 (0)