Skip to content

Commit 03cc0f9

Browse files
paul-szczepanek-armpan-
authored andcommitted
host privacy config option to enable it
1 parent 76f89f6 commit 03cc0f9

File tree

9 files changed

+191
-132
lines changed

9 files changed

+191
-132
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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,20 @@
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"
100110
}
101111
}
102112
}

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: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,11 @@ ble_error_t Gap::enablePrivacy(bool enable)
929929
_address_registry.stop_private_address_generation();
930930
}
931931

932+
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
932933
if (_address_registry.is_controller_privacy_supported()) {
933934
update_ll_address_resolution_setting();
934935
}
936+
#endif // !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
935937

936938
return BLE_ERROR_NONE;
937939
}
@@ -946,9 +948,11 @@ ble_error_t Gap::setPeripheralPrivacyConfiguration(
946948
{
947949
_peripheral_privacy_configuration = *configuration;
948950

951+
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
949952
if (_address_registry.is_controller_privacy_supported()) {
950953
update_ll_address_resolution_setting();
951954
}
955+
#endif // !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
952956

953957
return BLE_ERROR_NONE;
954958
}
@@ -978,9 +982,11 @@ ble_error_t Gap::setCentralPrivacyConfiguration(
978982
{
979983
_central_privacy_configuration = *configuration;
980984

985+
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
981986
if (_address_registry.is_controller_privacy_supported()) {
982987
update_ll_address_resolution_setting();
983988
}
989+
#endif // !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
984990

985991
return BLE_ERROR_NONE;
986992
}
@@ -1474,7 +1480,7 @@ bool Gap::initialize_whitelist() const
14741480
return true;
14751481
}
14761482

1477-
1483+
#if BLE_FEATURE_PRIVACY && !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
14781484
ble_error_t Gap::update_ll_address_resolution_setting()
14791485
{
14801486
// enable if privacy is enabled and resolution is requested in either central or peripheral mode
@@ -1496,6 +1502,7 @@ ble_error_t Gap::update_ll_address_resolution_setting()
14961502

14971503
return _address_registry.enable_controller_address_resolution(enable);
14981504
}
1505+
#endif // BLE_FEATURE_PRIVACY && !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
14991506

15001507
#if BLE_ROLE_BROADCASTER
15011508
uint8_t Gap::getMaxAdvertisingSetNumber()
@@ -2314,12 +2321,11 @@ void Gap::signal_connection_complete(
23142321
ConnectionCompleteEvent& event
23152322
)
23162323
{
2317-
#if BLE_FEATURE_PRIVACY
2324+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
23182325
bool address_resolved = false;
23192326

23202327
/* if address resolution is not needed or already handled then the address is already resolved */
23212328
if (!_privacy_enabled ||
2322-
_address_registry.is_controller_privacy_supported() ||
23232329
event.getPeerAddressType() == peer_address_type_t::PUBLIC ||
23242330
!is_random_private_resolvable_address(event.getPeerAddress())) {
23252331
address_resolved = true;
@@ -2330,7 +2336,7 @@ void Gap::signal_connection_complete(
23302336
address_resolved = true;
23312337
}
23322338
}
2333-
#endif
2339+
#endif // BLE_ROLE_CENTRAL
23342340

23352341
#if BLE_ROLE_PERIPHERAL
23362342
if (event.getOwnRole() == connection_role_t::PERIPHERAL) {
@@ -2347,7 +2353,7 @@ void Gap::signal_connection_complete(
23472353

23482354
/* first try to resolve synchronously in cache */
23492355
if (!address_resolved) {
2350-
address_resolved = _address_registry.resolve_address_in_cache(
2356+
address_resolved = _address_registry.resolve_address_in_host_cache(
23512357
event.getPeerAddress(),
23522358
&peer_address_type,
23532359
&peer_address
@@ -2372,7 +2378,7 @@ void Gap::signal_connection_complete(
23722378
_event_handler->onConnectionComplete(event);
23732379
} else {
23742380
bool resolution_pending = false;
2375-
ble_error_t ret = _address_registry.queue_resolve_address(event.getPeerAddress());
2381+
ble_error_t ret = _address_registry.queue_resolve_address_on_host(event.getPeerAddress());
23762382

23772383
if (ret == BLE_ERROR_NONE) {
23782384
ConnectionCompleteEvent* event_copy = new(std::nothrow) ConnectionCompleteEvent(event);
@@ -2397,11 +2403,10 @@ void Gap::signal_connection_complete(
23972403
#else
23982404
report_internal_connection_complete(event);
23992405
_event_handler->onConnectionComplete(event);
2400-
#endif // BLE_FEATURE_PRIVACY
2406+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
24012407
}
24022408

24032409
#if BLE_FEATURE_PRIVACY
2404-
24052410
bool Gap::apply_peripheral_privacy_connection_policy(
24062411
const ConnectionCompleteEvent &event
24072412
)
@@ -2451,8 +2456,9 @@ bool Gap::apply_peripheral_privacy_connection_policy(
24512456
return true;
24522457
#endif
24532458
}
2459+
#endif // BLE_FEATURE_PRIVACY
24542460

2455-
2461+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
24562462
void Gap::conclude_signal_connection_complete_after_address_resolution(
24572463
ConnectionCompleteEvent &event,
24582464
target_peer_address_type_t identity_address_type,
@@ -2478,21 +2484,20 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
24782484
report_internal_connection_complete(event);
24792485
_event_handler->onConnectionComplete(event);
24802486
}
2481-
#endif // BLE_FEATURE_PRIVACY
2487+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
24822488
#endif // BLE_FEATURE_CONNECTABLE
24832489

24842490
#if BLE_ROLE_OBSERVER
24852491
void Gap::signal_advertising_report(
24862492
AdvertisingReportEvent& event
24872493
)
24882494
{
2489-
#if BLE_FEATURE_PRIVACY
2495+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
24902496
bool address_resolved = false;
24912497

24922498
/* if address resolution is not needed or already handled then the address is already resolved */
24932499
if (!_privacy_enabled ||
24942500
_central_privacy_configuration.resolution_strategy == central_privacy_configuration_t::DO_NOT_RESOLVE ||
2495-
_address_registry.is_controller_privacy_supported() ||
24962501
event.getPeerAddressType() == peer_address_type_t::PUBLIC ||
24972502
!is_random_private_resolvable_address(event.getPeerAddress())) {
24982503
address_resolved = true;
@@ -2503,7 +2508,7 @@ void Gap::signal_advertising_report(
25032508
const address_t *peer_address = nullptr;
25042509
target_peer_address_type_t peer_address_type(target_peer_address_type_t::RANDOM);
25052510

2506-
address_resolved = _address_registry.resolve_address_in_cache(
2511+
address_resolved = _address_registry.resolve_address_in_host_cache(
25072512
event.getPeerAddress(),
25082513
&peer_address_type,
25092514
&peer_address
@@ -2536,7 +2541,7 @@ void Gap::signal_advertising_report(
25362541

25372542
/* if there is already an item with the same address pending don't kick off resolution*/
25382543
if (!duplicate_pending_event) {
2539-
ret = _address_registry.queue_resolve_address(event.getPeerAddress());
2544+
ret = _address_registry.queue_resolve_address_on_host(event.getPeerAddress());
25402545
}
25412546

25422547
if (ret == BLE_ERROR_NONE) {
@@ -2553,11 +2558,11 @@ void Gap::signal_advertising_report(
25532558
_event_handler->onAdvertisingReport(
25542559
event
25552560
);
2556-
#endif // BLE_FEATURE_PRIVACY
2561+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
25572562
}
25582563
#endif //BLE_ROLE_OBSERVER
25592564

2560-
#if BLE_FEATURE_PRIVACY
2565+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
25612566
#if BLE_ROLE_OBSERVER
25622567
void Gap::conclude_signal_advertising_report_after_address_resolution(
25632568
AdvertisingReportEvent &event,
@@ -2581,7 +2586,7 @@ void Gap::conclude_signal_advertising_report_after_address_resolution(
25812586
_event_handler->onAdvertisingReport(event);
25822587
}
25832588
#endif // BLE_ROLE_OBSERVER
2584-
#endif // BLE_FEATURE_PRIVACY
2589+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
25852590

25862591
void Gap::on_periodic_advertising_sync_established(
25872592
hci_error_code_t error,
@@ -3179,15 +3184,15 @@ void Gap::on_private_address_generated(bool connectable)
31793184
}
31803185
}
31813186

3182-
3187+
#if BLE_FEATURE_PRIVACY
3188+
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
31833189
void Gap::on_address_resolution_completed(
31843190
const address_t &peer_resolvable_address,
31853191
bool resolved,
31863192
target_peer_address_type_t identity_address_type,
31873193
const address_t &identity_address
31883194
)
31893195
{
3190-
#if BLE_FEATURE_PRIVACY
31913196
if (!_event_handler || !_privacy_enabled) {
31923197
return;
31933198
}
@@ -3237,9 +3242,9 @@ void Gap::on_address_resolution_completed(
32373242
delete event;
32383243
}
32393244
#endif // BLE_ROLE_OBSERVER
3240-
#endif // BLE_FEATURE_PRIVACY
32413245
}
3242-
3246+
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
3247+
#endif // BLE_FEATURE_PRIVACY
32433248

32443249
bool Gap::is_advertising() const
32453250
{
@@ -3297,7 +3302,7 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
32973302
#if BLE_FEATURE_EXTENDED_ADVERTISING
32983303
if (is_extended_advertising_available()) {
32993304
if (operation == controller_operation_t::advertising) {
3300-
if (_set_is_connectable.get(set_id) == false && peripheral_non_resolvable) {
3305+
if (!_set_is_connectable.get(set_id) && peripheral_non_resolvable) {
33013306
return &non_resolvable_address;
33023307
} else {
33033308
return &resolvable_address;

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ class Gap :
493493
IndexType _current_index = 0;
494494
};
495495

496+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
496497
class PendingAdvertisingReportEvent {
497498
public:
498499
PendingAdvertisingReportEvent(
@@ -530,6 +531,7 @@ class Gap :
530531
AdvertisingReportEvent event;
531532
uint8_t *advertising_data_buffer = nullptr;
532533
};
534+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
533535

534536
private:
535537
/* Disallow copy and assignment. */
@@ -585,7 +587,9 @@ class Gap :
585587

586588
bool initialize_whitelist() const;
587589

590+
#if BLE_FEATURE_PRIVACY && !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
588591
ble_error_t update_ll_address_resolution_setting();
592+
#endif // BLE_FEATURE_PRIVACY && !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
589593

590594
ble_error_t setExtendedAdvertisingParameters(
591595
advertising_handle_t handle,
@@ -620,7 +624,9 @@ class Gap :
620624
bool apply_peripheral_privacy_connection_policy(
621625
const ConnectionCompleteEvent &event
622626
);
627+
#endif // BLE_FEATURE_PRIVACY
623628

629+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
624630
/** Pass the connection complete event to the application after privacy resolution completed.
625631
*
626632
* @param event Event to be passed to the user application.
@@ -632,7 +638,7 @@ class Gap :
632638
target_peer_address_type_t identity_address_type,
633639
const address_t *identity_address
634640
);
635-
#endif // BLE_FEATURE_PRIVACY
641+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
636642
#endif // BLE_FEATURE_CONNECTABLE
637643

638644
#if BLE_ROLE_OBSERVER
@@ -642,7 +648,7 @@ class Gap :
642648
*/
643649
void signal_advertising_report(AdvertisingReportEvent& report);
644650

645-
#if BLE_FEATURE_PRIVACY
651+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
646652
/** Pass the advertising report to the application after privacy resolution completed.
647653
*
648654
* @param event Event to be passed to the user application.
@@ -654,7 +660,7 @@ class Gap :
654660
target_peer_address_type_t identity_address_type,
655661
const address_t *identity_address
656662
);
657-
#endif // BLE_FEATURE_PRIVACY
663+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
658664
#endif // BLE_ROLE_OBSERVER
659665

660666
/* implements PalGap::EventHandler */
@@ -767,13 +773,14 @@ class Gap :
767773
void on_non_resolvable_private_addresses_generated(const address_t &address) final;
768774

769775
void on_private_address_generated(bool connectable);
770-
776+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
771777
void on_address_resolution_completed(
772778
const address_t &peer_resolvable_address,
773779
bool resolved,
774780
target_peer_address_type_t identity_address_type,
775781
const address_t &identity_address
776782
) final;
783+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
777784

778785
private:
779786
bool is_advertising() const;
@@ -803,14 +810,14 @@ class Gap :
803810
*/
804811
ble::Gap::EventHandler *_event_handler;
805812

806-
#if BLE_FEATURE_PRIVACY
813+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
807814
#if BLE_ROLE_OBSERVER
808815
EventList<PendingAdvertisingReportEvent, uint8_t, BLE_GAP_MAX_ADVERTISING_REPORTS_PENDING_ADDRESS_RESOLUTION> _reports_pending_address_resolution;
809816
#endif // BLE_ROLE_OBSERVER
810817
#if BLE_FEATURE_CONNECTABLE
811818
EventList<ConnectionCompleteEvent, uint8_t, DM_CONN_MAX> _connections_pending_address_resolution;
812819
#endif // BLE_FEATURE_CONNECTABLE
813-
#endif // BLE_FEATURE_PRIVACY
820+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
814821

815822
PalEventQueue &_event_queue;
816823
PalGap &_pal_gap;

0 commit comments

Comments
 (0)