Skip to content

Commit 8fe2d7e

Browse files
committed
BLE: Report connection internally when address resolution has completed.
1 parent 8716298 commit 8fe2d7e

File tree

2 files changed

+53
-44
lines changed

2 files changed

+53
-44
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,43 +1306,24 @@ void Gap::on_connection_complete(const GapConnectionCompleteEvent &e)
13061306
}
13071307
#endif // BLE_ROLE_PERIPHERAL
13081308

1309-
ble::address_t address;
1310-
if (_address_type == own_address_type_t::PUBLIC) {
1311-
address = _pal_gap.get_device_address();
1312-
} else {
1313-
address = _pal_gap.get_random_address();
1314-
}
1315-
1316-
// signal internal stack
1317-
if (_connection_event_handler) {
1318-
_connection_event_handler->on_connected(
1319-
e.connection_handle,
1320-
e.role,
1321-
e.peer_address_type,
1322-
e.peer_address,
1323-
_address_type,
1324-
address
1325-
);
1326-
}
1309+
ConnectionCompleteEvent event(
1310+
BLE_ERROR_NONE,
1311+
e.connection_handle,
1312+
e.role,
1313+
e.peer_address_type,
1314+
e.peer_address,
1315+
e.local_resolvable_private_address,
1316+
e.peer_resolvable_private_address,
1317+
conn_interval_t(e.connection_interval),
1318+
e.connection_latency,
1319+
supervision_timeout_t(e.supervision_timeout),
1320+
/* default master clock accuracy */ ble::clock_accuracy_t::PPM_500
1321+
);
13271322

1328-
// signal application
13291323
if (_event_handler) {
1330-
ConnectionCompleteEvent event(
1331-
BLE_ERROR_NONE,
1332-
e.connection_handle,
1333-
e.role,
1334-
e.peer_address_type,
1335-
e.peer_address,
1336-
e.local_resolvable_private_address,
1337-
e.peer_resolvable_private_address,
1338-
conn_interval_t(e.connection_interval),
1339-
e.connection_latency,
1340-
supervision_timeout_t(e.supervision_timeout),
1341-
/* default master clock accuracy */ ble::clock_accuracy_t::PPM_500
1342-
);
1343-
signal_connection_complete(
1344-
event
1345-
);
1324+
signal_connection_complete(event);
1325+
} else {
1326+
report_internal_connection_complete(event);
13461327
}
13471328
}
13481329

@@ -2299,6 +2280,30 @@ void Gap::on_extended_advertising_report(
22992280
}
23002281

23012282
#if BLE_FEATURE_CONNECTABLE
2283+
void Gap::report_internal_connection_complete(const ConnectionCompleteEvent& event)
2284+
{
2285+
if (!_connection_event_handler || event.getStatus() != BLE_ERROR_NONE) {
2286+
return;
2287+
}
2288+
2289+
ble::address_t address;
2290+
if (_address_type == own_address_type_t::PUBLIC) {
2291+
address = _pal_gap.get_device_address();
2292+
} else {
2293+
address = _pal_gap.get_random_address();
2294+
}
2295+
2296+
_connection_event_handler->on_connected(
2297+
event.getConnectionHandle(),
2298+
event.getOwnRole(),
2299+
event.getPeerAddressType(),
2300+
event.getPeerAddress(),
2301+
_address_type,
2302+
address
2303+
);
2304+
}
2305+
2306+
23022307
void Gap::signal_connection_complete(
23032308
ConnectionCompleteEvent& event
23042309
)
@@ -2354,9 +2359,8 @@ void Gap::signal_connection_complete(
23542359

23552360
/* if successful then proceed to call the handler immediately same as for when privacy is disabled */
23562361
if (address_resolved) {
2357-
_event_handler->onConnectionComplete(
2358-
event
2359-
);
2362+
report_internal_connection_complete(event);
2363+
_event_handler->onConnectionComplete(event);
23602364
} else {
23612365
bool resolution_pending = false;
23622366
ble_error_t ret = _address_registry.queue_resolve_address(event.getPeerAddress());
@@ -2382,9 +2386,8 @@ void Gap::signal_connection_complete(
23822386
}
23832387
}
23842388
#else
2385-
_event_handler->onConnectionComplete(
2386-
event
2387-
);
2389+
report_internal_connection_complete(event);
2390+
_event_handler->onConnectionComplete(event);
23882391
#endif // BLE_FEATURE_PRIVACY
23892392
}
23902393

@@ -2424,9 +2427,8 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
24242427
}
24252428
#endif // BLE_ROLE_PERIPHERAL
24262429

2427-
_event_handler->onConnectionComplete(
2428-
event
2429-
);
2430+
report_internal_connection_complete(event);
2431+
_event_handler->onConnectionComplete(event);
24302432
#if BLE_ROLE_PERIPHERAL
24312433
#if BLE_FEATURE_SECURITY
24322434
if (resolvable_address_not_known) {

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,13 @@ class Gap :
597597
ble_error_t prepare_legacy_advertising_set(const AdvertisingParameters& parameters);
598598

599599
#if BLE_FEATURE_CONNECTABLE
600+
/** Call the internal handlers that report to the security manager and GATT
601+
* that a connection has been established.
602+
*
603+
* @param report Connection event
604+
*/
605+
void report_internal_connection_complete(const ConnectionCompleteEvent& report);
606+
600607
/** Pass the connection complete event to the application. This may involve privacy resolution.
601608
*
602609
* @param report Event to be passed to the user application.

0 commit comments

Comments
 (0)