BLE: Add function to signal privacy initialization.

pull/13759/head
Vincent Coubard 2020-09-29 10:39:24 +01:00
parent 5216a9aa8c
commit bb35cba134
3 changed files with 46 additions and 0 deletions

View File

@ -538,6 +538,14 @@ public:
)
{
}
/**
* 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
@ -1244,6 +1252,14 @@ public:
* 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.
*

View File

@ -925,8 +925,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
@ -1016,6 +1028,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
@ -3174,6 +3190,15 @@ void Gap::on_private_address_generated(bool connectable)
return;
}
if (_privacy_initialization_pending &&
_address_registry.get_resolvable_private_address() != address_t{} &&
_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) {
@ -3372,6 +3397,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;
}

View File

@ -832,6 +832,7 @@ private:
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