mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Add function to signal privacy initialization.
parent
5216a9aa8c
commit
bb35cba134
|
@ -538,6 +538,14 @@ public:
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function invoked when the privacy subsystem has been enabled and is
|
||||||
|
* ready to be used.
|
||||||
|
*/
|
||||||
|
virtual void onPrivacyEnabled()
|
||||||
|
{
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
|
* Prevent polymorphic deletion and avoid unnecessary virtual destructor
|
||||||
|
@ -1244,6 +1252,14 @@ public:
|
||||||
* resolved and advertisement packets are forwarded to the application
|
* resolved and advertisement packets are forwarded to the application
|
||||||
* even if the advertiser private address is unknown.
|
* 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
|
* @param[in] enable Should be set to true to enable the privacy mode and
|
||||||
* false to disable it.
|
* false to disable it.
|
||||||
*
|
*
|
||||||
|
|
|
@ -925,8 +925,20 @@ ble_error_t Gap::enablePrivacy(bool enable)
|
||||||
|
|
||||||
if (_privacy_enabled) {
|
if (_privacy_enabled) {
|
||||||
_address_registry.start_private_address_generation();
|
_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 {
|
} else {
|
||||||
_address_registry.stop_private_address_generation();
|
_address_registry.stop_private_address_generation();
|
||||||
|
_privacy_initialization_pending = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
|
#if !BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
|
||||||
|
@ -1016,6 +1028,10 @@ ble_error_t Gap::reset()
|
||||||
|
|
||||||
_event_handler = nullptr;
|
_event_handler = nullptr;
|
||||||
|
|
||||||
|
#if BLE_FEATURE_PRIVACY
|
||||||
|
_privacy_initialization_pending = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BLE_ROLE_BROADCASTER
|
#if BLE_ROLE_BROADCASTER
|
||||||
_advertising_timeout.detach();
|
_advertising_timeout.detach();
|
||||||
#endif
|
#endif
|
||||||
|
@ -3174,6 +3190,15 @@ void Gap::on_private_address_generated(bool connectable)
|
||||||
return;
|
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
|
// refresh for address for all connectable advertising sets
|
||||||
for (size_t i = 0; i < BLE_GAP_MAX_ADVERTISING_SETS; ++i) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*desired_address == address_t{}) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
if (!address_in_use) {
|
if (!address_in_use) {
|
||||||
return desired_address;
|
return desired_address;
|
||||||
}
|
}
|
||||||
|
|
|
@ -832,6 +832,7 @@ private:
|
||||||
|
|
||||||
bool _privacy_enabled;
|
bool _privacy_enabled;
|
||||||
#if BLE_FEATURE_PRIVACY
|
#if BLE_FEATURE_PRIVACY
|
||||||
|
bool _privacy_initialization_pending = false;
|
||||||
#if BLE_ROLE_PERIPHERAL
|
#if BLE_ROLE_PERIPHERAL
|
||||||
peripheral_privacy_configuration_t _peripheral_privacy_configuration;
|
peripheral_privacy_configuration_t _peripheral_privacy_configuration;
|
||||||
#endif // BLE_ROLE_PERIPHERAL
|
#endif // BLE_ROLE_PERIPHERAL
|
||||||
|
|
Loading…
Reference in New Issue