@@ -1306,43 +1306,24 @@ void Gap::on_connection_complete(const GapConnectionCompleteEvent &e)
1306
1306
}
1307
1307
#endif // BLE_ROLE_PERIPHERAL
1308
1308
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
+ );
1327
1322
1328
- // signal application
1329
1323
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);
1346
1327
}
1347
1328
}
1348
1329
@@ -2299,6 +2280,30 @@ void Gap::on_extended_advertising_report(
2299
2280
}
2300
2281
2301
2282
#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
+
2302
2307
void Gap::signal_connection_complete (
2303
2308
ConnectionCompleteEvent& event
2304
2309
)
@@ -2354,9 +2359,8 @@ void Gap::signal_connection_complete(
2354
2359
2355
2360
/* if successful then proceed to call the handler immediately same as for when privacy is disabled */
2356
2361
if (address_resolved) {
2357
- _event_handler->onConnectionComplete (
2358
- event
2359
- );
2362
+ report_internal_connection_complete (event);
2363
+ _event_handler->onConnectionComplete (event);
2360
2364
} else {
2361
2365
bool resolution_pending = false ;
2362
2366
ble_error_t ret = _address_registry.queue_resolve_address (event.getPeerAddress ());
@@ -2382,9 +2386,8 @@ void Gap::signal_connection_complete(
2382
2386
}
2383
2387
}
2384
2388
#else
2385
- _event_handler->onConnectionComplete (
2386
- event
2387
- );
2389
+ report_internal_connection_complete (event);
2390
+ _event_handler->onConnectionComplete (event);
2388
2391
#endif // BLE_FEATURE_PRIVACY
2389
2392
}
2390
2393
@@ -2424,9 +2427,8 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
2424
2427
}
2425
2428
#endif // BLE_ROLE_PERIPHERAL
2426
2429
2427
- _event_handler->onConnectionComplete (
2428
- event
2429
- );
2430
+ report_internal_connection_complete (event);
2431
+ _event_handler->onConnectionComplete (event);
2430
2432
#if BLE_ROLE_PERIPHERAL
2431
2433
#if BLE_FEATURE_SECURITY
2432
2434
if (resolvable_address_not_known) {
0 commit comments