@@ -1260,43 +1260,24 @@ void Gap::on_connection_complete(const GapConnectionCompleteEvent &e)
12601260 }
12611261#endif // BLE_ROLE_PERIPHERAL
12621262
1263- ble::address_t address;
1264- if (_address_type == own_address_type_t ::PUBLIC) {
1265- address = _pal_gap.get_device_address ();
1266- } else {
1267- address = _pal_gap.get_random_address ();
1268- }
1269-
1270- // signal internal stack
1271- if (_connection_event_handler) {
1272- _connection_event_handler->on_connected (
1273- e.connection_handle ,
1274- e.role ,
1275- e.peer_address_type ,
1276- e.peer_address ,
1277- _address_type,
1278- address
1279- );
1280- }
1263+ ConnectionCompleteEvent event (
1264+ BLE_ERROR_NONE,
1265+ e.connection_handle ,
1266+ e.role ,
1267+ e.peer_address_type ,
1268+ e.peer_address ,
1269+ e.local_resolvable_private_address ,
1270+ e.peer_resolvable_private_address ,
1271+ conn_interval_t (e.connection_interval ),
1272+ e.connection_latency ,
1273+ supervision_timeout_t (e.supervision_timeout ),
1274+ /* default master clock accuracy */ ble::clock_accuracy_t ::PPM_500
1275+ );
12811276
1282- // signal application
12831277 if (_event_handler) {
1284- ConnectionCompleteEvent event (
1285- BLE_ERROR_NONE,
1286- e.connection_handle ,
1287- e.role ,
1288- e.peer_address_type ,
1289- e.peer_address ,
1290- e.local_resolvable_private_address ,
1291- e.peer_resolvable_private_address ,
1292- conn_interval_t (e.connection_interval ),
1293- e.connection_latency ,
1294- supervision_timeout_t (e.supervision_timeout ),
1295- /* default master clock accuracy */ ble::clock_accuracy_t ::PPM_500
1296- );
1297- signal_connection_complete (
1298- event
1299- );
1278+ signal_connection_complete (event);
1279+ } else {
1280+ report_internal_connection_complete (event);
13001281 }
13011282}
13021283
@@ -2204,6 +2185,30 @@ void Gap::on_extended_advertising_report(
22042185}
22052186
22062187#if BLE_FEATURE_CONNECTABLE
2188+ void Gap::report_internal_connection_complete (const ConnectionCompleteEvent& event)
2189+ {
2190+ if (!_connection_event_handler || event.getStatus () != BLE_ERROR_NONE) {
2191+ return ;
2192+ }
2193+
2194+ ble::address_t address;
2195+ if (_address_type == own_address_type_t ::PUBLIC) {
2196+ address = _pal_gap.get_device_address ();
2197+ } else {
2198+ address = _pal_gap.get_random_address ();
2199+ }
2200+
2201+ _connection_event_handler->on_connected (
2202+ event.getConnectionHandle (),
2203+ event.getOwnRole (),
2204+ event.getPeerAddressType (),
2205+ event.getPeerAddress (),
2206+ _address_type,
2207+ address
2208+ );
2209+ }
2210+
2211+
22072212void Gap::signal_connection_complete (
22082213 ConnectionCompleteEvent& event
22092214)
@@ -2259,9 +2264,8 @@ void Gap::signal_connection_complete(
22592264
22602265 /* if successful then proceed to call the handler immediately same as for when privacy is disabled */
22612266 if (address_resolved) {
2262- _event_handler->onConnectionComplete (
2263- event
2264- );
2267+ report_internal_connection_complete (event);
2268+ _event_handler->onConnectionComplete (event);
22652269 } else {
22662270 bool resolution_pending = false ;
22672271 ble_error_t ret = _address_registry.queue_resolve_address (event.getPeerAddress ());
@@ -2287,9 +2291,8 @@ void Gap::signal_connection_complete(
22872291 }
22882292 }
22892293#else
2290- _event_handler->onConnectionComplete (
2291- event
2292- );
2294+ report_internal_connection_complete (event);
2295+ _event_handler->onConnectionComplete (event);
22932296#endif // BLE_FEATURE_PRIVACY
22942297}
22952298
@@ -2329,9 +2332,8 @@ void Gap::conclude_signal_connection_complete_after_address_resolution(
23292332 }
23302333#endif // BLE_ROLE_PERIPHERAL
23312334
2332- _event_handler->onConnectionComplete (
2333- event
2334- );
2335+ report_internal_connection_complete (event);
2336+ _event_handler->onConnectionComplete (event);
23352337#if BLE_ROLE_PERIPHERAL
23362338#if BLE_FEATURE_SECURITY
23372339 if (resolvable_address_not_known) {
0 commit comments