@@ -468,11 +468,7 @@ ble_error_t Gap::stopScan()
468
468
{
469
469
ble_error_t err;
470
470
471
- if ((!_scan_enabled && !_scan_pending) || _scan_pending
472
- #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
473
- || (_connect_to_host_resolved_address_state != ConnectionToHostResolvedAddressState::idle)
474
- #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
475
- ) {
471
+ if ((!_scan_enabled && !_scan_pending) || _scan_pending || _initiating) {
476
472
return BLE_STACK_BUSY;
477
473
}
478
474
@@ -535,15 +531,26 @@ ble_error_t Gap::connect(
535
531
ble_error_t ret = BLE_ERROR_INTERNAL_STACK_FAILURE;
536
532
537
533
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
534
+ /* if host resolution is used we need to connect in two passes, first we scan for addresses to find
535
+ * a resolving match and then we call connect again with the correct address */
538
536
if (_connect_to_host_resolved_address_state == ConnectionToHostResolvedAddressState::idle) {
539
537
if (peerAddressType == peer_address_type_t ::RANDOM_STATIC_IDENTITY ||
540
538
peerAddressType == peer_address_type_t ::PUBLIC_IDENTITY) {
539
+
540
+ _connect_to_host_resolved_address_parameters = new ConnectionParameters (connectionParams);
541
+ if (!_connect_to_host_resolved_address_parameters) {
542
+ return BLE_ERROR_NO_MEM;
543
+ }
544
+
541
545
_connect_to_host_resolved_address_type = peerAddressType;
542
546
_connect_to_host_resolved_address = peerAddress;
543
547
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::scan;
544
548
}
545
549
} else if (_connect_to_host_resolved_address_state == ConnectionToHostResolvedAddressState::connect) {
550
+ /* the first pass of connect has completed and this is the second connect that doesn't require
551
+ * address resolution */
546
552
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::idle;
553
+ _initiating = false ;
547
554
}
548
555
549
556
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
@@ -570,13 +577,7 @@ ble_error_t Gap::connect(
570
577
duplicates_filter_t ::ENABLE,
571
578
(scan_period_t )0
572
579
);
573
- if (ret == BLE_ERROR_NONE) {
574
- _connect_to_host_resolved_address_parameters = new ConnectionParameters (connectionParams);
575
- if (!_connect_to_host_resolved_address_parameters) {
576
- _connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::idle;
577
- ret = BLE_ERROR_NO_MEM;
578
- }
579
- } else {
580
+ if (ret != BLE_ERROR_NONE) {
580
581
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::idle;
581
582
}
582
583
} else
@@ -1077,7 +1078,7 @@ ble_error_t Gap::reset()
1077
1078
shutdownCallChain.clear ();
1078
1079
1079
1080
_event_handler = nullptr ;
1080
-
1081
+ _initiating = false ;
1081
1082
#if BLE_FEATURE_PRIVACY
1082
1083
_privacy_initialization_pending = false ;
1083
1084
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
@@ -1228,6 +1229,7 @@ void Gap::connecting_to_host_resolved_address_failed(bool inform_user)
1228
1229
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::idle;
1229
1230
delete _connect_to_host_resolved_address_parameters;
1230
1231
_connect_to_host_resolved_address_parameters = nullptr ;
1232
+ _initiating = false ;
1231
1233
}
1232
1234
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1233
1235
@@ -2999,11 +3001,7 @@ ble_error_t Gap::startScan(
2999
3001
scan_period_t period
3000
3002
)
3001
3003
{
3002
- if (_scan_pending || _scan_address_refresh
3003
- #if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
3004
- || (_connect_to_host_resolved_address_state != ConnectionToHostResolvedAddressState::idle)
3005
- #endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
3006
- ) {
3004
+ if (_scan_pending || _scan_address_refresh || _initiating) {
3007
3005
return BLE_STACK_BUSY;
3008
3006
}
3009
3007
0 commit comments