Skip to content

Commit a8e3694

Browse files
authored
Merge pull request #13560 from pan-/host-privacy-implementation
Host privacy implementation
2 parents 3b5ab54 + f851f0e commit a8e3694

21 files changed

+2049
-716
lines changed

connectivity/FEATURE_BLE/include/ble/common/Duration.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ namespace ble {
3333
* @tparam Min left-bound
3434
* @tparam Max right-bound
3535
*/
36-
template<uint32_t Min, uint32_t Max>
36+
template<uint32_t Min, uint32_t Max, uint32_t Default = Min>
3737
struct Range {
3838
static const uint32_t MIN = Min;
3939
static const uint32_t MAX = Max;
40+
static const uint32_t DEFAULT = Default;
4041
};
4142

4243
/**
@@ -111,7 +112,7 @@ struct Duration {
111112
*
112113
* It is initialized with the minimum value acceptable.
113114
*/
114-
Duration() : duration(Range::MIN)
115+
Duration() : duration(Range::DEFAULT)
115116
{
116117
}
117118

@@ -598,11 +599,14 @@ bool operator>(Duration<Rep, Us, Range, F> lhs, Duration<Rep, Us, Range, F> rhs)
598599

599600
#if !defined(DOXYGEN_ONLY)
600601

601-
template<uint32_t Min, uint32_t Max>
602-
const uint32_t Range<Min, Max>::MIN;
602+
template<uint32_t Min, uint32_t Max, uint32_t Default>
603+
const uint32_t Range<Min, Max, Default>::MIN;
603604

604-
template<uint32_t Min, uint32_t Max>
605-
const uint32_t Range<Min, Max>::MAX;
605+
template<uint32_t Min, uint32_t Max, uint32_t Default>
606+
const uint32_t Range<Min, Max, Default>::MAX;
607+
608+
template<uint32_t Min, uint32_t Max, uint32_t Default>
609+
const uint32_t Range<Min, Max, Default>::DEFAULT;
606610

607611
template<typename T, T V>
608612
const T Value<T, V>::VALUE;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ typedef Duration<uint16_t, 10000, Range<0x0A, 0x4000> > sync_timeout_t;
121121
*/
122122
typedef Duration<uint16_t, 1250, Range<0x06, 0xFFFF> > periodic_interval_t;
123123

124+
/**
125+
* Resolvable address timeout.
126+
*
127+
* The duration is in seconds and ranges from 1 to 0xA1B8. The default value is
128+
* 900 seconds.
129+
*/
130+
using resolvable_address_timeout_t = Duration<
131+
uint16_t, second_t::TIME_BASE, Range<1, 0xA1B8, 0x0384>
132+
>;
133+
124134
/**
125135
* Number of connection events that can be skipped by the slave.
126136
*

connectivity/FEATURE_BLE/source/cordio/source/BLEInstanceBaseImpl.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ ble::impl::Gap &BLEInstanceBase::getGapImpl()
201201
_event_queue,
202202
ble::impl::PalGap::get_gap(),
203203
cordio_gap_service,
204-
ble::impl::PalSecurityManager::get_security_manager()
204+
ble::impl::PalSecurityManager::get_security_manager(),
205+
getPrivateAddressRegistry()
205206
);
206207
return gap;
207208
}
@@ -285,7 +286,8 @@ ble::impl::SecurityManager &BLEInstanceBase::getSecurityManagerImpl()
285286
static ble::impl::SecurityManager m_instance(
286287
ble::impl::PalSecurityManager::get_security_manager(),
287288
getGapImpl(),
288-
signing_event_monitor
289+
signing_event_monitor,
290+
getPrivateAddressRegistry()
289291
);
290292

291293
return m_instance;
@@ -303,6 +305,18 @@ const ble::SecurityManager &BLEInstanceBase::getSecurityManager() const
303305
return const_cast<const ble::SecurityManager &>(self.getSecurityManager());
304306
}
305307

308+
#if BLE_FEATURE_PRIVACY
309+
ble::PrivateAddressController &BLEInstanceBase::getPrivateAddressRegistry()
310+
{
311+
static ble::PrivateAddressController registry(
312+
impl::PalPrivateAddressController::instance(),
313+
_event_queue,
314+
ble::resolvable_address_timeout_t{}
315+
);
316+
return registry;
317+
}
318+
#endif
319+
306320
#endif // BLE_FEATURE_SECURITY
307321

308322
void BLEInstanceBase::waitForEvent()
@@ -337,6 +351,12 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
337351
if (ble::impl::PalSecurityManager::get_security_manager().sm_handler(msg)) {
338352
return;
339353
}
354+
355+
#if BLE_FEATURE_PRIVACY
356+
if (impl::PalPrivateAddressController::instance().cordio_handler(msg)) {
357+
return;
358+
}
359+
#endif
340360
#endif // BLE_FEATURE_SECURITY
341361

342362
switch (msg->event) {
@@ -365,6 +385,7 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
365385
#if BLE_FEATURE_GATT_SERVER
366386
deviceInstance().getGattServerImpl().initialize();
367387
#endif
388+
368389
deviceInstance().initialization_status = INITIALIZED;
369390
_init_callback.call(&context);
370391
} break;

connectivity/FEATURE_BLE/source/cordio/source/BLEInstanceBaseImpl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
#include "source/generic/SecurityManagerImpl.h"
4343
#include "source/GattServerImpl.h"
4444
#include "source/PalEventQueueImpl.h"
45+
#include "source/PalPrivateAddressControllerImpl.h"
46+
#include "source/generic/PrivateAddressController.h"
4547

4648
#include "drivers/LowPowerTimer.h"
4749

@@ -157,6 +159,10 @@ class BLEInstanceBase final : public ble::BLEInstanceBase {
157159
*/
158160
const ble::SecurityManager &getSecurityManager() const final;
159161

162+
#if BLE_FEATURE_PRIVACY
163+
ble::PrivateAddressController &getPrivateAddressRegistry();
164+
#endif
165+
160166
#endif // BLE_FEATURE_SECURITY
161167

162168
/**

connectivity/FEATURE_BLE/source/cordio/source/PalEventQueueImpl.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,13 @@ class PalEventQueue final : public ble::PalEventQueue {
116116
void process()
117117
{
118118
while (_events) {
119-
EventNode *next = _events->next;
120-
_events->event();
121-
_events->~EventNode();
122-
WsfBufFree(_events);
123-
_events = next;
119+
// pop
120+
auto *event = _events;
121+
_events = event->next;
122+
// execute and delete
123+
event->event();
124+
event->~EventNode();
125+
WsfBufFree(event);
124126
}
125127
}
126128

connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.cpp

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -462,23 +462,6 @@ ble_error_t PalGap::disconnect(
462462
return BLE_ERROR_NONE;
463463
}
464464

465-
466-
bool PalGap::is_privacy_supported()
467-
{
468-
// We only support controller-based privacy, so return whether the controller supports it
469-
return HciLlPrivacySupported();
470-
}
471-
472-
473-
ble_error_t PalGap::set_address_resolution(
474-
bool enable
475-
)
476-
{
477-
DmPrivSetAddrResEnable(enable);
478-
return BLE_ERROR_NONE;
479-
}
480-
481-
482465
ble_error_t PalGap::read_phy(connection_handle_t connection)
483466
{
484467
if (is_feature_supported(controller_supported_features_t::LE_2M_PHY)
@@ -489,7 +472,6 @@ ble_error_t PalGap::read_phy(connection_handle_t connection)
489472
return BLE_ERROR_NOT_IMPLEMENTED;
490473
}
491474

492-
493475
ble_error_t PalGap::set_preferred_phys(
494476
const phy_set_t &tx_phys,
495477
const phy_set_t &rx_phys
@@ -639,6 +621,20 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
639621
break;
640622
#endif // BLE_FEATURE_PERIODIC_ADVERTISING
641623

624+
case DM_ADV_START_IND:
625+
if (!handler) {
626+
break;
627+
}
628+
handler->on_legacy_advertising_started();
629+
break;
630+
631+
case DM_ADV_STOP_IND:
632+
if (!handler) {
633+
break;
634+
}
635+
handler->on_legacy_advertising_stopped();
636+
break;
637+
642638
#if BLE_FEATURE_EXTENDED_ADVERTISING && BLE_ROLE_BROADCASTER
643639
case DM_SCAN_REQ_RCVD_IND: {
644640
if (!handler) {
@@ -651,8 +647,16 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
651647
connection_peer_address_type_t(evt->scanAddrType),
652648
evt->scanAddr
653649
);
654-
}
655-
break;
650+
} break;
651+
652+
case DM_ADV_SET_START_IND: {
653+
if (!handler) {
654+
break;
655+
}
656+
const auto *evt = (const dmAdvSetStartEvt_t *) msg;
657+
handler->on_advertising_set_started({evt->advHandle, evt->numSets});
658+
} break;
659+
656660

657661
case DM_ADV_SET_STOP_IND: {
658662
const auto *evt = (const hciLeAdvSetTermEvt_t *) msg;
@@ -676,8 +680,7 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
676680
evt->handle,
677681
evt->numComplEvts
678682
);
679-
}
680-
break;
683+
} break;
681684
#endif // BLE_FEATURE_EXTENDED_ADVERTISING && BLE_ROLE_BROADCASTER
682685

683686
#if BLE_FEATURE_EXTENDED_ADVERTISING && BLE_ROLE_OBSERVER

connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ class PalGap final : public ble::PalGap {
147147
local_disconnection_reason_t disconnection_reason
148148
) final;
149149

150-
bool is_privacy_supported() final;
151-
152-
ble_error_t set_address_resolution(
153-
bool enable
154-
) final;
155-
156150
ble_error_t read_phy(connection_handle_t connection) final;
157151

158152
ble_error_t set_preferred_phys(

0 commit comments

Comments
 (0)