Skip to content

Commit 2f283e2

Browse files
authored
Merge pull request #13662 from paul-szczepanek-arm/host-privacy-feature
Host privacy feature configuration
2 parents 1b99763 + 1e5e475 commit 2f283e2

File tree

9 files changed

+236
-138
lines changed

9 files changed

+236
-138
lines changed

connectivity/FEATURE_BLE/include/ble/gap/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ struct scanning_filter_policy_t : SafeEnum<scanning_filter_policy_t, uint8_t> {
455455
NO_FILTER = 0x00,
456456

457457
/**
458-
* Accept only advertising packets from devices in the whitelist except
459-
* directed advertising packets not addressed to this device.
458+
* Accept only advertising packets from devices in the whitelist.
459+
* Directed advertising packets not addressed to this device will be ignored.
460460
*/
461461
FILTER_ADVERTISING = 0x01,
462462

connectivity/FEATURE_BLE/mbed_lib.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,25 @@
9393
"value": 15,
9494
"macro_name": "BLE_GAP_MAX_ADVERTISING_SETS"
9595
},
96+
"ble-gap-host-based-private-address-resolution": {
97+
"help": "Perform address resolution on the host, not the controller. Controller based privacy is preferred as it happens lower down the stack but this can be used in case controller based privacy is unavailable. If this is enabled the controller will not be used for privacy.",
98+
"value": true,
99+
"macro_name": "BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION"
100+
},
96101
"ble-gap-max-advertising-reports-pending-address-resolution": {
97102
"help": "How many advertising reports can be pending while awaiting private address resolution. This is only used if host privacy is enabled and controller privacy is disabled. Must be non-zero",
98103
"value": 16,
99104
"macro_name": "BLE_GAP_MAX_ADVERTISING_REPORTS_PENDING_ADDRESS_RESOLUTION"
105+
},
106+
"ble-gap-host-privacy-resolved-cache-size": {
107+
"help": "Used for host privacy. How many last resolved addresses to store to speed up resolution. This is especially valuable for resolving advertising which creates repeated queries for the same address.",
108+
"value": 16,
109+
"macro_name": "BLE_GAP_HOST_PRIVACY_RESOLVED_CACHE_SIZE"
110+
}
111+
},
112+
"target_overrides": {
113+
"MCU_NRF52840": {
114+
"ble-gap-host-based-private-address-resolution": false
100115
}
101116
}
102117
}

connectivity/FEATURE_BLE/source/Gap.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* mbed Microcontroller Library
22
* Copyright (c) 2020 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
4-
*
4+
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
@@ -506,4 +506,4 @@ ble::address_t Gap::getRandomStaticAddress()
506506
return impl->getRandomStaticAddress();
507507
}
508508

509-
} // namespace ble
509+
} // namespace ble

connectivity/FEATURE_BLE/source/cordio/source/PalPrivateAddressControllerImpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* mbed Microcontroller Library
22
* Copyright (c) 2020 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
4-
*
4+
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
@@ -193,6 +193,7 @@ bool PalPrivateAddressController::cordio_handler(const wsfMsgHdr_t *msg)
193193
return true;
194194
}
195195

196+
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
196197
case DM_PRIV_RESOLVED_ADDR_IND: {
197198
instance()._resolving_rpa = false;
198199

@@ -203,6 +204,7 @@ bool PalPrivateAddressController::cordio_handler(const wsfMsgHdr_t *msg)
203204
handler->on_private_address_resolved(msg->status == HCI_SUCCESS);
204205
return true;
205206
}
207+
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
206208

207209
case DM_PRIV_ADD_DEV_TO_RES_LIST_IND: // Device added to resolving list
208210
case DM_PRIV_REM_DEV_FROM_RES_LIST_IND: // Device removed from resolving list

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -900,9 +900,11 @@ ble_error_t Gap::enablePrivacy(bool enable)
900900
_address_registry.stop_private_address_generation();
901901
}
902902

903+
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
903904
if (_address_registry.is_controller_privacy_supported()) {
904905
update_ll_address_resolution_setting();
905906
}
907+
#endif // !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
906908

907909
return BLE_ERROR_NONE;
908910
}
@@ -914,9 +916,11 @@ ble_error_t Gap::setPeripheralPrivacyConfiguration(
914916
{
915917
_peripheral_privacy_configuration = *configuration;
916918

919+
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
917920
if (_address_registry.is_controller_privacy_supported()) {
918921
update_ll_address_resolution_setting();
919922
}
923+
#endif // !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
920924

921925
return BLE_ERROR_NONE;
922926
}
@@ -938,9 +942,11 @@ ble_error_t Gap::setCentralPrivacyConfiguration(
938942
{
939943
_central_privacy_configuration = *configuration;
940944

945+
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
941946
if (_address_registry.is_controller_privacy_supported()) {
942947
update_ll_address_resolution_setting();
943948
}
949+
#endif // !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
944950

945951
return BLE_ERROR_NONE;
946952
}
@@ -1428,7 +1434,7 @@ bool Gap::initialize_whitelist() const
14281434
return true;
14291435
}
14301436

1431-
1437+
#if BLE_FEATURE_PRIVACY && !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
14321438
ble_error_t Gap::update_ll_address_resolution_setting()
14331439
{
14341440
// enable if privacy is enabled and resolution is requested in either central or peripheral mode
@@ -1450,6 +1456,7 @@ ble_error_t Gap::update_ll_address_resolution_setting()
14501456

14511457
return _address_registry.enable_controller_address_resolution(enable);
14521458
}
1459+
#endif // BLE_FEATURE_PRIVACY && !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
14531460

14541461
uint8_t Gap::getMaxAdvertisingSetNumber()
14551462
{
@@ -2219,12 +2226,11 @@ void Gap::signal_connection_complete(
22192226
ConnectionCompleteEvent& event
22202227
)
22212228
{
2222-
#if BLE_FEATURE_PRIVACY
2229+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
22232230
bool address_resolved = false;
22242231

22252232
/* if address resolution is not needed or already handled then the address is already resolved */
22262233
if (!_privacy_enabled ||
2227-
_address_registry.is_controller_privacy_supported() ||
22282234
event.getPeerAddressType() == peer_address_type_t::PUBLIC ||
22292235
!is_random_private_resolvable_address(event.getPeerAddress())) {
22302236
address_resolved = true;
@@ -2235,7 +2241,7 @@ void Gap::signal_connection_complete(
22352241
address_resolved = true;
22362242
}
22372243
}
2238-
#endif
2244+
#endif // BLE_ROLE_CENTRAL
22392245

22402246
#if BLE_ROLE_PERIPHERAL
22412247
if (event.getOwnRole() == connection_role_t::PERIPHERAL) {
@@ -2252,7 +2258,7 @@ void Gap::signal_connection_complete(
22522258

22532259
/* first try to resolve synchronously in cache */
22542260
if (!address_resolved) {
2255-
address_resolved = _address_registry.resolve_address_in_cache(
2261+
address_resolved = _address_registry.resolve_address_in_host_cache(
22562262
event.getPeerAddress(),
22572263
&peer_address_type,
22582264
&peer_address
@@ -2277,7 +2283,7 @@ void Gap::signal_connection_complete(
22772283
_event_handler->onConnectionComplete(event);
22782284
} else {
22792285
bool resolution_pending = false;
2280-
ble_error_t ret = _address_registry.queue_resolve_address(event.getPeerAddress());
2286+
ble_error_t ret = _address_registry.queue_resolve_address_on_host(event.getPeerAddress());
22812287

22822288
if (ret == BLE_ERROR_NONE) {
22832289
ConnectionCompleteEvent* event_copy = new(std::nothrow) ConnectionCompleteEvent(event);
@@ -2300,13 +2306,17 @@ void Gap::signal_connection_complete(
23002306
}
23012307
}
23022308
#else
2309+
#if BLE_FEATURE_PRIVACY
2310+
if (!apply_peripheral_privacy_connection_policy(event)) {
2311+
return;
2312+
}
2313+
#endif // BLE_FEATURE_PRIVACY
23032314
report_internal_connection_complete(event);
23042315
_event_handler->onConnectionComplete(event);
2305-
#endif // BLE_FEATURE_PRIVACY
2316+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
23062317
}
23072318

23082319
#if BLE_FEATURE_PRIVACY
2309-
23102320
bool Gap::apply_peripheral_privacy_connection_policy(
23112321
const ConnectionCompleteEvent &event
23122322
)
@@ -2328,6 +2338,10 @@ bool Gap::apply_peripheral_privacy_connection_policy(
23282338

23292339
switch (_peripheral_privacy_configuration.resolution_strategy) {
23302340
case peripheral_privacy_configuration_t::REJECT_NON_RESOLVED_ADDRESS:
2341+
/* if there is no bond then allow unresolved addresses */
2342+
if (_address_registry.read_resolving_list_size() == 0) {
2343+
return true;
2344+
}
23312345
_pal_gap.disconnect(
23322346
connection_handle,
23332347
local_disconnection_reason_t::AUTHENTICATION_FAILURE
@@ -2356,8 +2370,9 @@ bool Gap::apply_peripheral_privacy_connection_policy(
23562370
return true;
23572371
#endif
23582372
}
2373+
#endif // BLE_FEATURE_PRIVACY
23592374

2360-
2375+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
23612376
void Gap::conclude_signal_connection_complete_after_address_resolution(
23622377
ConnectionCompleteEvent &event,
23632378
target_peer_address_type_t identity_address_type,
@@ -2383,21 +2398,20 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
23832398
report_internal_connection_complete(event);
23842399
_event_handler->onConnectionComplete(event);
23852400
}
2386-
#endif // BLE_FEATURE_PRIVACY
2401+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
23872402
#endif // BLE_FEATURE_CONNECTABLE
23882403

23892404
#if BLE_ROLE_OBSERVER
23902405
void Gap::signal_advertising_report(
23912406
AdvertisingReportEvent& event
23922407
)
23932408
{
2394-
#if BLE_FEATURE_PRIVACY
2409+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
23952410
bool address_resolved = false;
23962411

23972412
/* if address resolution is not needed or already handled then the address is already resolved */
23982413
if (!_privacy_enabled ||
23992414
_central_privacy_configuration.resolution_strategy == central_privacy_configuration_t::DO_NOT_RESOLVE ||
2400-
_address_registry.is_controller_privacy_supported() ||
24012415
event.getPeerAddressType() == peer_address_type_t::PUBLIC ||
24022416
!is_random_private_resolvable_address(event.getPeerAddress())) {
24032417
address_resolved = true;
@@ -2408,7 +2422,7 @@ void Gap::signal_advertising_report(
24082422
const address_t *peer_address = nullptr;
24092423
target_peer_address_type_t peer_address_type(target_peer_address_type_t::RANDOM);
24102424

2411-
address_resolved = _address_registry.resolve_address_in_cache(
2425+
address_resolved = _address_registry.resolve_address_in_host_cache(
24122426
event.getPeerAddress(),
24132427
&peer_address_type,
24142428
&peer_address
@@ -2441,7 +2455,7 @@ void Gap::signal_advertising_report(
24412455

24422456
/* if there is already an item with the same address pending don't kick off resolution*/
24432457
if (!duplicate_pending_event) {
2444-
ret = _address_registry.queue_resolve_address(event.getPeerAddress());
2458+
ret = _address_registry.queue_resolve_address_on_host(event.getPeerAddress());
24452459
}
24462460

24472461
if (ret == BLE_ERROR_NONE) {
@@ -2455,14 +2469,21 @@ void Gap::signal_advertising_report(
24552469
}
24562470
}
24572471
#else
2472+
/* filter out unresolved address if at least one bond exists */
2473+
if (_address_registry.read_resolving_list_size() > 0 &&
2474+
_central_privacy_configuration.resolution_strategy == central_privacy_configuration_t::RESOLVE_AND_FILTER &&
2475+
event.getPeerAddressType() != peer_address_type_t::PUBLIC &&
2476+
is_random_private_resolvable_address(event.getPeerAddress())) {
2477+
return;
2478+
}
24582479
_event_handler->onAdvertisingReport(
24592480
event
24602481
);
2461-
#endif // BLE_FEATURE_PRIVACY
2482+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
24622483
}
24632484
#endif //BLE_ROLE_OBSERVER
24642485

2465-
#if BLE_FEATURE_PRIVACY
2486+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
24662487
#if BLE_ROLE_OBSERVER
24672488
void Gap::conclude_signal_advertising_report_after_address_resolution(
24682489
AdvertisingReportEvent &event,
@@ -2472,21 +2493,21 @@ void Gap::conclude_signal_advertising_report_after_address_resolution(
24722493
{
24732494
/* fix the report with the new address if there's an identity found */
24742495
if (identity_address) {
2475-
/* filter out resolved address based on policy */
2476-
if (_central_privacy_configuration.resolution_strategy ==
2477-
central_privacy_configuration_t::RESOLVE_AND_FILTER) {
2478-
return;
2479-
}
24802496
event.setPeerAddress(*identity_address);
24812497
event.setPeerAddressType(identity_address_type == target_peer_address_type_t::RANDOM ?
24822498
peer_address_type_t::RANDOM_STATIC_IDENTITY
24832499
: peer_address_type_t::PUBLIC_IDENTITY);
2500+
} else if (_central_privacy_configuration.resolution_strategy ==
2501+
central_privacy_configuration_t::RESOLVE_AND_FILTER &&
2502+
_address_registry.read_resolving_list_size() > 0) {
2503+
/* filter out unresolved address if at least one bond exists */
2504+
return;
24842505
}
24852506

24862507
_event_handler->onAdvertisingReport(event);
24872508
}
24882509
#endif // BLE_ROLE_OBSERVER
2489-
#endif // BLE_FEATURE_PRIVACY
2510+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
24902511

24912512
void Gap::on_periodic_advertising_sync_established(
24922513
hci_error_code_t error,
@@ -3047,15 +3068,15 @@ void Gap::on_private_address_generated(bool connectable)
30473068
}
30483069
}
30493070

3050-
3071+
#if BLE_FEATURE_PRIVACY
3072+
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
30513073
void Gap::on_address_resolution_completed(
30523074
const address_t &peer_resolvable_address,
30533075
bool resolved,
30543076
target_peer_address_type_t identity_address_type,
30553077
const address_t &identity_address
30563078
)
30573079
{
3058-
#if BLE_FEATURE_PRIVACY
30593080
if (!_event_handler || !_privacy_enabled) {
30603081
return;
30613082
}
@@ -3105,9 +3126,9 @@ void Gap::on_address_resolution_completed(
31053126
delete event;
31063127
}
31073128
#endif // BLE_ROLE_OBSERVER
3108-
#endif // BLE_FEATURE_PRIVACY
31093129
}
3110-
3130+
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
3131+
#endif // BLE_FEATURE_PRIVACY
31113132

31123133
bool Gap::is_advertising() const
31133134
{
@@ -3165,7 +3186,7 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
31653186
#if BLE_FEATURE_EXTENDED_ADVERTISING
31663187
if (is_extended_advertising_available()) {
31673188
if (operation == controller_operation_t::advertising) {
3168-
if (_set_is_connectable.get(set_id) == false && peripheral_non_resolvable) {
3189+
if (!_set_is_connectable.get(set_id) && peripheral_non_resolvable) {
31693190
return &non_resolvable_address;
31703191
} else {
31713192
return &resolvable_address;

0 commit comments

Comments
 (0)