Skip to content

Commit 6ee5740

Browse files
paul-szczepanek-armpan-
authored andcommitted
use _initiating to block scan manipulation
1 parent f0bbc4c commit 6ee5740

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,7 @@ ble_error_t Gap::stopScan()
468468
{
469469
ble_error_t err;
470470

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) {
476472
return BLE_STACK_BUSY;
477473
}
478474

@@ -535,15 +531,26 @@ ble_error_t Gap::connect(
535531
ble_error_t ret = BLE_ERROR_INTERNAL_STACK_FAILURE;
536532

537533
#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 */
538536
if (_connect_to_host_resolved_address_state == ConnectionToHostResolvedAddressState::idle) {
539537
if (peerAddressType == peer_address_type_t::RANDOM_STATIC_IDENTITY ||
540538
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+
541545
_connect_to_host_resolved_address_type = peerAddressType;
542546
_connect_to_host_resolved_address = peerAddress;
543547
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::scan;
544548
}
545549
} 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 */
546552
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::idle;
553+
_initiating = false;
547554
}
548555

549556
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
@@ -570,13 +577,7 @@ ble_error_t Gap::connect(
570577
duplicates_filter_t::ENABLE,
571578
(scan_period_t)0
572579
);
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) {
580581
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::idle;
581582
}
582583
} else
@@ -1077,7 +1078,7 @@ ble_error_t Gap::reset()
10771078
shutdownCallChain.clear();
10781079

10791080
_event_handler = nullptr;
1080-
1081+
_initiating = false;
10811082
#if BLE_FEATURE_PRIVACY
10821083
_privacy_initialization_pending = false;
10831084
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
@@ -1228,6 +1229,7 @@ void Gap::connecting_to_host_resolved_address_failed(bool inform_user)
12281229
_connect_to_host_resolved_address_state = ConnectionToHostResolvedAddressState::idle;
12291230
delete _connect_to_host_resolved_address_parameters;
12301231
_connect_to_host_resolved_address_parameters = nullptr;
1232+
_initiating = false;
12311233
}
12321234
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
12331235

@@ -2999,11 +3001,7 @@ ble_error_t Gap::startScan(
29993001
scan_period_t period
30003002
)
30013003
{
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) {
30073005
return BLE_STACK_BUSY;
30083006
}
30093007

0 commit comments

Comments
 (0)