Skip to content

Host privacy implementation #13560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions connectivity/FEATURE_BLE/include/ble/common/Duration.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@ namespace ble {
* @tparam Min left-bound
* @tparam Max right-bound
*/
template<uint32_t Min, uint32_t Max>
template<uint32_t Min, uint32_t Max, uint32_t Default = Min>
struct Range {
static const uint32_t MIN = Min;
static const uint32_t MAX = Max;
static const uint32_t DEFAULT = Default;
};

/**
Expand Down Expand Up @@ -111,7 +112,7 @@ struct Duration {
*
* It is initialized with the minimum value acceptable.
*/
Duration() : duration(Range::MIN)
Duration() : duration(Range::DEFAULT)
{
}

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

#if !defined(DOXYGEN_ONLY)

template<uint32_t Min, uint32_t Max>
const uint32_t Range<Min, Max>::MIN;
template<uint32_t Min, uint32_t Max, uint32_t Default>
const uint32_t Range<Min, Max, Default>::MIN;

template<uint32_t Min, uint32_t Max>
const uint32_t Range<Min, Max>::MAX;
template<uint32_t Min, uint32_t Max, uint32_t Default>
const uint32_t Range<Min, Max, Default>::MAX;

template<uint32_t Min, uint32_t Max, uint32_t Default>
const uint32_t Range<Min, Max, Default>::DEFAULT;

template<typename T, T V>
const T Value<T, V>::VALUE;
Expand Down
10 changes: 10 additions & 0 deletions connectivity/FEATURE_BLE/include/ble/gap/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ typedef Duration<uint16_t, 10000, Range<0x0A, 0x4000> > sync_timeout_t;
*/
typedef Duration<uint16_t, 1250, Range<0x06, 0xFFFF> > periodic_interval_t;

/**
* Resolvable address timeout.
*
* The duration is in seconds and ranges from 1 to 0xA1B8. The default value is
* 900 seconds.
*/
using resolvable_address_timeout_t = Duration<
uint16_t, second_t::TIME_BASE, Range<1, 0xA1B8, 0x0384>
>;

/**
* Number of connection events that can be skipped by the slave.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ ble::impl::Gap &BLEInstanceBase::getGapImpl()
_event_queue,
ble::impl::PalGap::get_gap(),
cordio_gap_service,
ble::impl::PalSecurityManager::get_security_manager()
ble::impl::PalSecurityManager::get_security_manager(),
getPrivateAddressRegistry()
);
return gap;
}
Expand Down Expand Up @@ -285,7 +286,8 @@ ble::impl::SecurityManager &BLEInstanceBase::getSecurityManagerImpl()
static ble::impl::SecurityManager m_instance(
ble::impl::PalSecurityManager::get_security_manager(),
getGapImpl(),
signing_event_monitor
signing_event_monitor,
getPrivateAddressRegistry()
);

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

#if BLE_FEATURE_PRIVACY
ble::PrivateAddressController &BLEInstanceBase::getPrivateAddressRegistry()
{
static ble::PrivateAddressController registry(
impl::PalPrivateAddressController::instance(),
_event_queue,
ble::resolvable_address_timeout_t{}
);
return registry;
}
#endif

#endif // BLE_FEATURE_SECURITY

void BLEInstanceBase::waitForEvent()
Expand Down Expand Up @@ -337,6 +351,12 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
if (ble::impl::PalSecurityManager::get_security_manager().sm_handler(msg)) {
return;
}

#if BLE_FEATURE_PRIVACY
if (impl::PalPrivateAddressController::instance().cordio_handler(msg)) {
return;
}
#endif
#endif // BLE_FEATURE_SECURITY

switch (msg->event) {
Expand Down Expand Up @@ -365,6 +385,7 @@ void BLEInstanceBase::stack_handler(wsfEventMask_t event, wsfMsgHdr_t *msg)
#if BLE_FEATURE_GATT_SERVER
deviceInstance().getGattServerImpl().initialize();
#endif

deviceInstance().initialization_status = INITIALIZED;
_init_callback.call(&context);
} break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "source/generic/SecurityManagerImpl.h"
#include "source/GattServerImpl.h"
#include "source/PalEventQueueImpl.h"
#include "source/PalPrivateAddressControllerImpl.h"
#include "source/generic/PrivateAddressController.h"

#include "drivers/LowPowerTimer.h"

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

#if BLE_FEATURE_PRIVACY
ble::PrivateAddressController &getPrivateAddressRegistry();
#endif

#endif // BLE_FEATURE_SECURITY

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ class PalEventQueue final : public ble::PalEventQueue {
void process()
{
while (_events) {
EventNode *next = _events->next;
_events->event();
_events->~EventNode();
WsfBufFree(_events);
_events = next;
// pop
auto *event = _events;
_events = event->next;
// execute and delete
event->event();
event->~EventNode();
WsfBufFree(event);
}
}

Expand Down
47 changes: 25 additions & 22 deletions connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,23 +462,6 @@ ble_error_t PalGap::disconnect(
return BLE_ERROR_NONE;
}


bool PalGap::is_privacy_supported()
{
// We only support controller-based privacy, so return whether the controller supports it
return HciLlPrivacySupported();
}


ble_error_t PalGap::set_address_resolution(
bool enable
)
{
DmPrivSetAddrResEnable(enable);
return BLE_ERROR_NONE;
}


ble_error_t PalGap::read_phy(connection_handle_t connection)
{
if (is_feature_supported(controller_supported_features_t::LE_2M_PHY)
Expand All @@ -489,7 +472,6 @@ ble_error_t PalGap::read_phy(connection_handle_t connection)
return BLE_ERROR_NOT_IMPLEMENTED;
}


ble_error_t PalGap::set_preferred_phys(
const phy_set_t &tx_phys,
const phy_set_t &rx_phys
Expand Down Expand Up @@ -639,6 +621,20 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
break;
#endif // BLE_FEATURE_PERIODIC_ADVERTISING

case DM_ADV_START_IND:
if (!handler) {
break;
}
handler->on_legacy_advertising_started();
break;

case DM_ADV_STOP_IND:
if (!handler) {
break;
}
handler->on_legacy_advertising_stopped();
break;

#if BLE_FEATURE_EXTENDED_ADVERTISING && BLE_ROLE_BROADCASTER
case DM_SCAN_REQ_RCVD_IND: {
if (!handler) {
Expand All @@ -651,8 +647,16 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
connection_peer_address_type_t(evt->scanAddrType),
evt->scanAddr
);
}
break;
} break;

case DM_ADV_SET_START_IND: {
if (!handler) {
break;
}
const auto *evt = (const dmAdvSetStartEvt_t *) msg;
handler->on_advertising_set_started({evt->advHandle, evt->numSets});
} break;


case DM_ADV_SET_STOP_IND: {
const auto *evt = (const hciLeAdvSetTermEvt_t *) msg;
Expand All @@ -676,8 +680,7 @@ void PalGap::gap_handler(const wsfMsgHdr_t *msg)
evt->handle,
evt->numComplEvts
);
}
break;
} break;
#endif // BLE_FEATURE_EXTENDED_ADVERTISING && BLE_ROLE_BROADCASTER

#if BLE_FEATURE_EXTENDED_ADVERTISING && BLE_ROLE_OBSERVER
Expand Down
6 changes: 0 additions & 6 deletions connectivity/FEATURE_BLE/source/cordio/source/PalGapImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ class PalGap final : public ble::PalGap {
local_disconnection_reason_t disconnection_reason
) final;

bool is_privacy_supported() final;

ble_error_t set_address_resolution(
bool enable
) final;

ble_error_t read_phy(connection_handle_t connection) final;

ble_error_t set_preferred_phys(
Expand Down
Loading