@@ -468,7 +468,11 @@ ble_error_t Gap::stopScan()
468
468
{
469
469
ble_error_t err;
470
470
471
- if ((!_scan_enabled && !_scan_pending) || _scan_pending) {
471
+ if ((!_scan_enabled && !_scan_pending) || _scan_pending
472
+ #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
473
+ || _ready_to_connect_to_host_resolved_address
474
+ #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
475
+ ) {
472
476
return BLE_STACK_BUSY;
473
477
}
474
478
@@ -524,6 +528,17 @@ ble_error_t Gap::connect(
524
528
525
529
ble_error_t ret = BLE_ERROR_INTERNAL_STACK_FAILURE;
526
530
531
+ #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
532
+ if (_ready_to_connect_to_host_resolved_address) {
533
+ _ready_to_connect_to_host_resolved_address = false ;
534
+ _connect_to_address_type = peer_address_type_t ::ANONYMOUS;
535
+ } else if (peerAddressType == peer_address_type_t ::RANDOM_STATIC_IDENTITY ||
536
+ peerAddressType == peer_address_type_t ::PUBLIC_IDENTITY) {
537
+ _connect_to_address_type = peerAddressType;
538
+ _connect_to_address = peerAddress;
539
+ }
540
+ #endif BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
541
+
527
542
if (is_extended_advertising_available () == false ) {
528
543
phy_set_t set (connectionParams.getPhySet ());
529
544
if (set.count () != 1 || set.get_1m () == false ) {
@@ -533,35 +548,52 @@ ble_error_t Gap::connect(
533
548
if (!_scan_enabled) {
534
549
if (!_active_sets.get (LEGACY_ADVERTISING_HANDLE) &&
535
550
!_pending_sets.get (LEGACY_ADVERTISING_HANDLE)
536
- ) {
551
+ ) {
537
552
_pal_gap.set_random_address (*address);
538
553
}
539
554
} else {
540
- // ensure scan is stopped.
541
- _pal_gap.scan_enable (false , false );
555
+ stopScan ();
556
+ }
557
+ #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
558
+ if (_connect_to_address_type != peer_address_type_t ::ANONYMOUS) {
559
+ ret = startScan (
560
+ (scan_duration_t )connectionParams.getConnectionSupervisionTimeoutArray ()[0 ],
561
+ duplicates_filter_t ::ENABLE,
562
+ (scan_period_t )0
563
+ );
564
+ if (ret == BLE_ERROR_NONE) {
565
+ _connection_parameters = new ConnectionParameters (connectionParams);
566
+ if (_connection_parameters) {
567
+ _ready_to_connect_to_host_resolved_address = true ;
568
+ } else {
569
+ ret = BLE_ERROR_NO_MEM;
570
+ }
571
+ }
572
+ } else
573
+ #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
574
+ {
575
+ ret = _pal_gap.create_connection (
576
+ connectionParams.getScanIntervalArray ()[0 ],
577
+ connectionParams.getScanWindowArray ()[0 ],
578
+ connectionParams.getFilter (),
579
+ (connection_peer_address_type_t ::type) peerAddressType.value (),
580
+ peerAddress,
581
+ connectionParams.getOwnAddressType (),
582
+ connectionParams.getMinConnectionIntervalArray ()[0 ],
583
+ connectionParams.getMaxConnectionIntervalArray ()[0 ],
584
+ connectionParams.getSlaveLatencyArray ()[0 ],
585
+ connectionParams.getConnectionSupervisionTimeoutArray ()[0 ],
586
+ connectionParams.getMinEventLengthArray ()[0 ],
587
+ connectionParams.getMaxConnectionIntervalArray ()[0 ]
588
+ );
542
589
}
543
-
544
- ret = _pal_gap.create_connection (
545
- connectionParams.getScanIntervalArray ()[0 ],
546
- connectionParams.getScanWindowArray ()[0 ],
547
- connectionParams.getFilter (),
548
- (connection_peer_address_type_t ::type) peerAddressType.value (),
549
- peerAddress,
550
- connectionParams.getOwnAddressType (),
551
- connectionParams.getMinConnectionIntervalArray ()[0 ],
552
- connectionParams.getMaxConnectionIntervalArray ()[0 ],
553
- connectionParams.getSlaveLatencyArray ()[0 ],
554
- connectionParams.getConnectionSupervisionTimeoutArray ()[0 ],
555
- connectionParams.getMinEventLengthArray ()[0 ],
556
- connectionParams.getMaxConnectionIntervalArray ()[0 ]
557
- );
558
590
} else {
559
591
// set the correct mac address before starting scanning.
560
592
if (!_scan_enabled) {
561
593
_pal_gap.set_random_address (*address);
562
594
} else {
563
595
// ensure scan is stopped.
564
- _pal_gap. extended_scan_enable ( false , duplicates_filter_t ::DISABLE, 0 , 0 );
596
+ stopScan ( );
565
597
}
566
598
567
599
// reduce the address type to public or random
@@ -1150,6 +1182,32 @@ void Gap::on_scan_stopped(bool success)
1150
1182
}
1151
1183
}
1152
1184
1185
+ #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1186
+ void Gap::connecting_to_host_resolved_address_failed ()
1187
+ {
1188
+ if (_event_handler) {
1189
+ _event_handler->onConnectionComplete (
1190
+ ConnectionCompleteEvent (
1191
+ BLE_ERROR_NOT_FOUND,
1192
+ INVALID_ADVERTISING_HANDLE,
1193
+ connection_role_t ::CENTRAL,
1194
+ peer_address_type_t ::ANONYMOUS,
1195
+ ble::address_t (),
1196
+ ble::address_t (),
1197
+ ble::address_t (),
1198
+ ble::conn_interval_t::max (),
1199
+ /* dummy slave latency */ 0 ,
1200
+ ble::supervision_timeout_t::max (),
1201
+ /* master clock accuracy */ 0
1202
+ )
1203
+ );
1204
+ }
1205
+ _ready_to_connect_to_host_resolved_address = false ;
1206
+ _connect_to_address_type = peer_address_type_t ::ANONYMOUS;
1207
+ delete _connection_parameters;
1208
+ _connection_parameters = nullptr ;
1209
+ }
1210
+ #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1153
1211
1154
1212
void Gap::on_scan_timeout ()
1155
1213
{
@@ -1161,6 +1219,13 @@ void Gap::on_scan_timeout()
1161
1219
_scan_enabled = false ;
1162
1220
_scan_pending = false ;
1163
1221
1222
+ #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1223
+ if (_ready_to_connect_to_host_resolved_address) {
1224
+ connecting_to_host_resolved_address_failed ();
1225
+ return ;
1226
+ }
1227
+ #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1228
+
1164
1229
if (_event_handler) {
1165
1230
_event_handler->onScanTimeout (ScanTimeoutEvent ());
1166
1231
}
@@ -1176,6 +1241,13 @@ void Gap::process_legacy_scan_timeout()
1176
1241
/* legacy scanning timed out is based on timer so we need to stop the scan manually */
1177
1242
_pal_gap.scan_enable (false , false );
1178
1243
1244
+ #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1245
+ if (_ready_to_connect_to_host_resolved_address) {
1246
+ connecting_to_host_resolved_address_failed ();
1247
+ return ;
1248
+ }
1249
+ #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1250
+
1179
1251
if (_event_handler) {
1180
1252
_event_handler->onScanTimeout (ScanTimeoutEvent ());
1181
1253
}
@@ -2551,9 +2623,18 @@ void Gap::signal_advertising_report(
2551
2623
2552
2624
/* if successful then proceed to call the handler immediately same as for when privacy is disabled */
2553
2625
if (address_resolved) {
2554
- _event_handler->onAdvertisingReport (
2555
- event
2556
- );
2626
+ if (_ready_to_connect_to_host_resolved_address) {
2627
+ if (_connect_to_address_type == event.getDirectAddressType () &&
2628
+ _connect_to_address == event.getDirectAddress ()) {
2629
+ connect (_connect_to_address_type, _connect_to_address, *_connection_parameters);
2630
+ delete _connection_parameters;
2631
+ _connection_parameters = nullptr ;
2632
+ }
2633
+ } else {
2634
+ _event_handler->onAdvertisingReport (
2635
+ event
2636
+ );
2637
+ }
2557
2638
} else {
2558
2639
/* check if there already is a RPA like that in the list of other pending reports */
2559
2640
PendingAdvertisingReportEvent *duplicate_pending_event = _reports_pending_address_resolution.find (
@@ -2602,12 +2683,25 @@ void Gap::conclude_signal_advertising_report_after_address_resolution(
2602
2683
const address_t *identity_address
2603
2684
)
2604
2685
{
2686
+
2687
+
2605
2688
/* fix the report with the new address if there's an identity found */
2606
2689
if (identity_address) {
2690
+ const peer_address_type_t peer_address_type = (identity_address_type == target_peer_address_type_t ::RANDOM) ?
2691
+ peer_address_type_t ::RANDOM_STATIC_IDENTITY
2692
+ : peer_address_type_t ::PUBLIC_IDENTITY;
2693
+
2694
+ if (_ready_to_connect_to_host_resolved_address) {
2695
+ if (_connect_to_address_type == peer_address_type && _connect_to_address == *identity_address) {
2696
+ connect (event.getPeerAddressType (), event.getPeerAddress (), *_connection_parameters);
2697
+ delete _connection_parameters;
2698
+ _connection_parameters = nullptr ;
2699
+ return ;
2700
+ }
2701
+ }
2702
+
2607
2703
event.setPeerAddress (*identity_address);
2608
- event.setPeerAddressType (identity_address_type == target_peer_address_type_t ::RANDOM ?
2609
- peer_address_type_t ::RANDOM_STATIC_IDENTITY
2610
- : peer_address_type_t ::PUBLIC_IDENTITY);
2704
+ event.setPeerAddressType (peer_address_type);
2611
2705
} else if (_central_privacy_configuration.resolution_strategy ==
2612
2706
central_privacy_configuration_t ::RESOLVE_AND_FILTER &&
2613
2707
_address_registry.read_resolving_list_size () > 0 ) {
@@ -2887,7 +2981,11 @@ ble_error_t Gap::startScan(
2887
2981
scan_period_t period
2888
2982
)
2889
2983
{
2890
- if (_scan_pending || _scan_address_refresh) {
2984
+ if (_scan_pending || _scan_address_refresh
2985
+ #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
2986
+ || _ready_to_connect_to_host_resolved_address
2987
+ #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
2988
+ ) {
2891
2989
return BLE_STACK_BUSY;
2892
2990
}
2893
2991
0 commit comments