BLE: Report connection internally when address resolution has completed.

pull/13759/head
Vincent Coubard 2020-09-23 17:38:58 +01:00
parent 8716298ea2
commit 8fe2d7ebbe
2 changed files with 53 additions and 44 deletions

View File

@ -1306,27 +1306,6 @@ void Gap::on_connection_complete(const GapConnectionCompleteEvent &e)
} }
#endif // BLE_ROLE_PERIPHERAL #endif // BLE_ROLE_PERIPHERAL
ble::address_t address;
if (_address_type == own_address_type_t::PUBLIC) {
address = _pal_gap.get_device_address();
} else {
address = _pal_gap.get_random_address();
}
// signal internal stack
if (_connection_event_handler) {
_connection_event_handler->on_connected(
e.connection_handle,
e.role,
e.peer_address_type,
e.peer_address,
_address_type,
address
);
}
// signal application
if (_event_handler) {
ConnectionCompleteEvent event( ConnectionCompleteEvent event(
BLE_ERROR_NONE, BLE_ERROR_NONE,
e.connection_handle, e.connection_handle,
@ -1340,9 +1319,11 @@ void Gap::on_connection_complete(const GapConnectionCompleteEvent &e)
supervision_timeout_t(e.supervision_timeout), supervision_timeout_t(e.supervision_timeout),
/* default master clock accuracy */ ble::clock_accuracy_t::PPM_500 /* default master clock accuracy */ ble::clock_accuracy_t::PPM_500
); );
signal_connection_complete(
event if (_event_handler) {
); signal_connection_complete(event);
} else {
report_internal_connection_complete(event);
} }
} }
@ -2299,6 +2280,30 @@ void Gap::on_extended_advertising_report(
} }
#if BLE_FEATURE_CONNECTABLE #if BLE_FEATURE_CONNECTABLE
void Gap::report_internal_connection_complete(const ConnectionCompleteEvent& event)
{
if (!_connection_event_handler || event.getStatus() != BLE_ERROR_NONE) {
return;
}
ble::address_t address;
if (_address_type == own_address_type_t::PUBLIC) {
address = _pal_gap.get_device_address();
} else {
address = _pal_gap.get_random_address();
}
_connection_event_handler->on_connected(
event.getConnectionHandle(),
event.getOwnRole(),
event.getPeerAddressType(),
event.getPeerAddress(),
_address_type,
address
);
}
void Gap::signal_connection_complete( void Gap::signal_connection_complete(
ConnectionCompleteEvent& event ConnectionCompleteEvent& event
) )
@ -2354,9 +2359,8 @@ void Gap::signal_connection_complete(
/* if successful then proceed to call the handler immediately same as for when privacy is disabled */ /* if successful then proceed to call the handler immediately same as for when privacy is disabled */
if (address_resolved) { if (address_resolved) {
_event_handler->onConnectionComplete( report_internal_connection_complete(event);
event _event_handler->onConnectionComplete(event);
);
} else { } else {
bool resolution_pending = false; bool resolution_pending = false;
ble_error_t ret = _address_registry.queue_resolve_address(event.getPeerAddress()); ble_error_t ret = _address_registry.queue_resolve_address(event.getPeerAddress());
@ -2382,9 +2386,8 @@ void Gap::signal_connection_complete(
} }
} }
#else #else
_event_handler->onConnectionComplete( report_internal_connection_complete(event);
event _event_handler->onConnectionComplete(event);
);
#endif // BLE_FEATURE_PRIVACY #endif // BLE_FEATURE_PRIVACY
} }
@ -2424,9 +2427,8 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
} }
#endif // BLE_ROLE_PERIPHERAL #endif // BLE_ROLE_PERIPHERAL
_event_handler->onConnectionComplete( report_internal_connection_complete(event);
event _event_handler->onConnectionComplete(event);
);
#if BLE_ROLE_PERIPHERAL #if BLE_ROLE_PERIPHERAL
#if BLE_FEATURE_SECURITY #if BLE_FEATURE_SECURITY
if (resolvable_address_not_known) { if (resolvable_address_not_known) {

View File

@ -597,6 +597,13 @@ private:
ble_error_t prepare_legacy_advertising_set(const AdvertisingParameters& parameters); ble_error_t prepare_legacy_advertising_set(const AdvertisingParameters& parameters);
#if BLE_FEATURE_CONNECTABLE #if BLE_FEATURE_CONNECTABLE
/** Call the internal handlers that report to the security manager and GATT
* that a connection has been established.
*
* @param report Connection event
*/
void report_internal_connection_complete(const ConnectionCompleteEvent& report);
/** Pass the connection complete event to the application. This may involve privacy resolution. /** Pass the connection complete event to the application. This may involve privacy resolution.
* *
* @param report Event to be passed to the user application. * @param report Event to be passed to the user application.