Skip to content

Commit fbd3de8

Browse files
host privacy config option to enable it
1 parent 3ac37dc commit fbd3de8

File tree

8 files changed

+183
-119
lines changed

8 files changed

+183
-119
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-privacy": {
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_PRIVACY"
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-resolving-list-size": {
107+
"help": "Used for host privacy. How many pairs of resolvable private addresses and identity address to store.",
108+
"value": 8,
109+
"macro_name": "BLE_GAP_HOST_PRIVACY_RESOLVED_LIST_SIZE"
110+
},
111+
"ble-gap-host-privacy-resolved-cache-size": {
112+
"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.",
113+
"value": 16,
114+
"macro_name": "BLE_GAP_HOST_PRIVACY_RESOLVED_CACHE_SIZE"
100115
}
101116
}
102117
}

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_PRIVACY
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_PRIVACY
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: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,12 @@ ble_error_t Gap::setWhitelist(const whitelist_t &whitelist)
880880

881881
ble_error_t Gap::enablePrivacy(bool enable)
882882
{
883+
#if (BLE_GAP_HOST_BASED_PRIVACY == 0)
884+
/* we need either privacy on host or controller to enable it */
885+
if (enable && !_address_registry.is_controller_privacy_supported()) {
886+
return BLE_ERROR_NOT_IMPLEMENTED;
887+
}
888+
#endif
883889
if (enable == _privacy_enabled) {
884890
// No change
885891
return BLE_ERROR_NONE;
@@ -1444,8 +1450,11 @@ ble_error_t Gap::update_ll_address_resolution_setting()
14441450
}
14451451
#endif // BLE_ROLE_OBSERVER
14461452
}
1447-
1453+
#if BLE_GAP_HOST_BASED_PRIVACY
1454+
return BLE_ERROR_NONE;
1455+
#else
14481456
return _address_registry.enable_controller_address_resolution(enable);
1457+
#endif // BLE_GAP_HOST_BASED_PRIVACY
14491458
}
14501459

14511460
uint8_t Gap::getMaxAdvertisingSetNumber()
@@ -2213,7 +2222,7 @@ void Gap::signal_connection_complete(
22132222
ConnectionCompleteEvent& event
22142223
)
22152224
{
2216-
#if BLE_FEATURE_PRIVACY
2225+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
22172226
bool address_resolved = false;
22182227

22192228
/* if address resolution is not needed or already handled then the address is already resolved */
@@ -2246,7 +2255,7 @@ void Gap::signal_connection_complete(
22462255

22472256
/* first try to resolve synchronously in cache */
22482257
if (!address_resolved) {
2249-
address_resolved = _address_registry.resolve_address_in_cache(
2258+
address_resolved = _address_registry.resolve_address_in_host_cache(
22502259
event.getPeerAddress(),
22512260
&peer_address_type,
22522261
&peer_address
@@ -2268,7 +2277,7 @@ void Gap::signal_connection_complete(
22682277
_event_handler->onConnectionComplete(event);
22692278
} else {
22702279
bool resolution_pending = false;
2271-
ble_error_t ret = _address_registry.queue_resolve_address(event.getPeerAddress());
2280+
ble_error_t ret = _address_registry.queue_resolve_address_on_host(event.getPeerAddress());
22722281

22732282
if (ret == BLE_ERROR_NONE) {
22742283
ConnectionCompleteEvent* event_copy = new(std::nothrow) ConnectionCompleteEvent(event);
@@ -2293,10 +2302,10 @@ void Gap::signal_connection_complete(
22932302
#else
22942303
report_internal_connection_complete(event);
22952304
_event_handler->onConnectionComplete(event);
2296-
#endif // BLE_FEATURE_PRIVACY
2305+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
22972306
}
22982307

2299-
#if BLE_FEATURE_PRIVACY
2308+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
23002309
void Gap::conclude_signal_connection_complete_after_address_resolution(
23012310
ConnectionCompleteEvent &event,
23022311
target_peer_address_type_t identity_address_type,
@@ -2354,21 +2363,20 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
23542363
#endif // BLE_FEATURE_SECURITY
23552364
#endif // BLE_ROLE_PERIPHERAL
23562365
}
2357-
#endif // BLE_FEATURE_PRIVACY
2366+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
23582367
#endif // BLE_FEATURE_CONNECTABLE
23592368

23602369
#if BLE_ROLE_OBSERVER
23612370
void Gap::signal_advertising_report(
23622371
AdvertisingReportEvent& event
23632372
)
23642373
{
2365-
#if BLE_FEATURE_PRIVACY
2374+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
23662375
bool address_resolved = false;
23672376

23682377
/* if address resolution is not needed or already handled then the address is already resolved */
23692378
if (!_privacy_enabled ||
23702379
_central_privacy_configuration.resolution_strategy == central_privacy_configuration_t::DO_NOT_RESOLVE ||
2371-
_address_registry.is_controller_privacy_supported() ||
23722380
event.getPeerAddressType() == peer_address_type_t::PUBLIC ||
23732381
!is_random_private_resolvable_address(event.getPeerAddress())) {
23742382
address_resolved = true;
@@ -2379,7 +2387,7 @@ void Gap::signal_advertising_report(
23792387
const address_t *peer_address = nullptr;
23802388
target_peer_address_type_t peer_address_type(target_peer_address_type_t::RANDOM);
23812389

2382-
address_resolved = _address_registry.resolve_address_in_cache(
2390+
address_resolved = _address_registry.resolve_address_in_host_cache(
23832391
event.getPeerAddress(),
23842392
&peer_address_type,
23852393
&peer_address
@@ -2412,7 +2420,7 @@ void Gap::signal_advertising_report(
24122420

24132421
/* if there is already an item with the same address pending don't kick off resolution*/
24142422
if (!duplicate_pending_event) {
2415-
ret = _address_registry.queue_resolve_address(event.getPeerAddress());
2423+
ret = _address_registry.queue_resolve_address_on_host(event.getPeerAddress());
24162424
}
24172425

24182426
if (ret == BLE_ERROR_NONE) {
@@ -2429,11 +2437,11 @@ void Gap::signal_advertising_report(
24292437
_event_handler->onAdvertisingReport(
24302438
event
24312439
);
2432-
#endif // BLE_FEATURE_PRIVACY
2440+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
24332441
}
24342442
#endif //BLE_ROLE_OBSERVER
24352443

2436-
#if BLE_FEATURE_PRIVACY
2444+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
24372445
#if BLE_ROLE_OBSERVER
24382446
void Gap::conclude_signal_advertising_report_after_address_resolution(
24392447
AdvertisingReportEvent &event,
@@ -2457,7 +2465,7 @@ void Gap::conclude_signal_advertising_report_after_address_resolution(
24572465
_event_handler->onAdvertisingReport(event);
24582466
}
24592467
#endif // BLE_ROLE_OBSERVER
2460-
#endif // BLE_FEATURE_PRIVACY
2468+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
24612469

24622470
void Gap::on_periodic_advertising_sync_established(
24632471
hci_error_code_t error,
@@ -3135,7 +3143,7 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
31353143
#if BLE_FEATURE_EXTENDED_ADVERTISING
31363144
if (is_extended_advertising_available()) {
31373145
if (operation == controller_operation_t::advertising) {
3138-
if (_set_is_connectable.get(set_id) == false && peripheral_non_resolvable) {
3146+
if (!_set_is_connectable.get(set_id) && peripheral_non_resolvable) {
31393147
return &non_resolvable_address;
31403148
} else {
31413149
return &resolvable_address;

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ class Gap :
610610
*/
611611
void signal_connection_complete(ConnectionCompleteEvent& report);
612612

613-
#if BLE_FEATURE_PRIVACY
613+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
614614
/** Pass the connection complete event to the application after privacy resolution completed.
615615
*
616616
* @param event Event to be passed to the user application.
@@ -622,7 +622,7 @@ class Gap :
622622
target_peer_address_type_t identity_address_type,
623623
const address_t *identity_address
624624
);
625-
#endif // BLE_FEATURE_PRIVACY
625+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
626626
#endif // BLE_FEATURE_CONNECTABLE
627627

628628
#if BLE_ROLE_OBSERVER
@@ -632,7 +632,7 @@ class Gap :
632632
*/
633633
void signal_advertising_report(AdvertisingReportEvent& report);
634634

635-
#if BLE_FEATURE_PRIVACY
635+
#if BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
636636
/** Pass the advertising report to the application after privacy resolution completed.
637637
*
638638
* @param event Event to be passed to the user application.
@@ -644,7 +644,7 @@ class Gap :
644644
target_peer_address_type_t identity_address_type,
645645
const address_t *identity_address
646646
);
647-
#endif // BLE_FEATURE_PRIVACY
647+
#endif // BLE_FEATURE_PRIVACY && BLE_GAP_HOST_BASED_PRIVACY
648648
#endif // BLE_ROLE_OBSERVER
649649

650650
/* implements PalGap::EventHandler */

0 commit comments

Comments
 (0)