Skip to content
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: 16 additions & 0 deletions connectivity/FEATURE_BLE/include/ble/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@ class Gap {
)
{
}

/**
* Function invoked when the privacy subsystem has been enabled and is
* ready to be used.
*/
virtual void onPrivacyEnabled()
{
}
protected:
/**
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
Expand Down Expand Up @@ -1244,6 +1252,14 @@ class Gap {
* resolved and advertisement packets are forwarded to the application
* even if the advertiser private address is unknown.
*
* @par Initialization of the privacy subsystem
*
* When privacy is enabled, the system generates new resolvable and non
* resolvable private addresses. Scan, Advertising and Connecting to a peer
* won't be available until the generation process completes. When addresses
* have been generated, the application is notified that privacy
* initialisation as completed with a call to EventHandler::onPrivacyEnabled .
*
* @param[in] enable Should be set to true to enable the privacy mode and
* false to disable it.
*
Expand Down
29 changes: 29 additions & 0 deletions connectivity/FEATURE_BLE/source/generic/GapImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,20 @@ ble_error_t Gap::enablePrivacy(bool enable)

if (_privacy_enabled) {
_address_registry.start_private_address_generation();
if (_address_registry.get_non_resolvable_private_address() != address_t {} &&
_address_registry.get_resolvable_private_address() != address_t{}
) {
_event_queue.post([this] {
if (_event_handler) {
_event_handler->onPrivacyEnabled();
}
});
} else {
_privacy_initialization_pending = true;
}
} else {
_address_registry.stop_private_address_generation();
_privacy_initialization_pending = false;
}

#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
Expand Down Expand Up @@ -970,6 +982,10 @@ ble_error_t Gap::reset()

_event_handler = nullptr;

#if BLE_FEATURE_PRIVACY
_privacy_initialization_pending = false;
#endif

#if BLE_ROLE_BROADCASTER
_advertising_timeout.detach();
#endif
Expand Down Expand Up @@ -3042,6 +3058,15 @@ void Gap::on_private_address_generated(bool connectable)
return;
}

if (_privacy_initialization_pending &&
_address_registry.get_resolvable_private_address() != address_t{} &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that possible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is if privacy is enabled then disabled or if the security manager has been enabled ~50ms before the privacy.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how would the on_private_address_generated be called then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is called but it has no effect since privacy is not enabled.

_address_registry.get_non_resolvable_private_address() != address_t{}
) {
_privacy_initialization_pending = false;
if (_event_handler) {
_event_handler->onPrivacyEnabled();
}
}

// refresh for address for all connectable advertising sets
for (size_t i = 0; i < BLE_GAP_MAX_ADVERTISING_SETS; ++i) {
Expand Down Expand Up @@ -3240,6 +3265,10 @@ const address_t *Gap::get_random_address(controller_operation_t operation, size_
break;
}

if (*desired_address == address_t{}) {
return nullptr;
}

if (!address_in_use) {
return desired_address;
}
Expand Down
1 change: 1 addition & 0 deletions connectivity/FEATURE_BLE/source/generic/GapImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,7 @@ class Gap :

bool _privacy_enabled;
#if BLE_FEATURE_PRIVACY
bool _privacy_initialization_pending = false;
#if BLE_ROLE_PERIPHERAL
peripheral_privacy_configuration_t _peripheral_privacy_configuration;
#endif // BLE_ROLE_PERIPHERAL
Expand Down