Skip to content

Commit 267c360

Browse files
scan forever and allow cancellation
1 parent 4c66c98 commit 267c360

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ ble_error_t Gap::connect(
554554
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
555555
if (_connect_to_address_type != peer_address_type_t::ANONYMOUS) {
556556
ret = startScan(
557-
(scan_duration_t)connectionParams.getConnectionSupervisionTimeoutArray()[0],
557+
scan_duration_t::forever(),
558558
duplicates_filter_t::ENABLE,
559559
(scan_period_t)0
560560
);
@@ -697,6 +697,14 @@ ble_error_t Gap::rejectConnectionParametersUpdate(
697697

698698
ble_error_t Gap::cancelConnect()
699699
{
700+
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
701+
if (_ready_to_connect_to_host_resolved_address) {
702+
connecting_to_host_resolved_address_failed(false);
703+
stopScan();
704+
return BLE_ERROR_NONE;
705+
}
706+
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
707+
700708
if (!_initiating) {
701709
return BLE_ERROR_NONE;
702710
}
@@ -1137,9 +1145,9 @@ void Gap::on_scan_stopped(bool success)
11371145
}
11381146

11391147
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1140-
void Gap::connecting_to_host_resolved_address_failed()
1148+
void Gap::connecting_to_host_resolved_address_failed(bool inform_user)
11411149
{
1142-
if (_event_handler) {
1150+
if (inform_user && _event_handler) {
11431151
_event_handler->onConnectionComplete(
11441152
ConnectionCompleteEvent(
11451153
BLE_ERROR_NOT_FOUND,
@@ -1173,13 +1181,6 @@ void Gap::on_scan_timeout()
11731181
_scan_enabled = false;
11741182
_scan_pending = false;
11751183

1176-
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1177-
if (_ready_to_connect_to_host_resolved_address) {
1178-
connecting_to_host_resolved_address_failed();
1179-
return;
1180-
}
1181-
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1182-
11831184
if (_event_handler) {
11841185
_event_handler->onScanTimeout(ScanTimeoutEvent());
11851186
}
@@ -1195,13 +1196,6 @@ void Gap::process_legacy_scan_timeout()
11951196
/* legacy scanning timed out is based on timer so we need to stop the scan manually */
11961197
_pal_gap.scan_enable(false, false);
11971198

1198-
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1199-
if (_ready_to_connect_to_host_resolved_address) {
1200-
connecting_to_host_resolved_address_failed();
1201-
return;
1202-
}
1203-
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
1204-
12051199
if (_event_handler) {
12061200
_event_handler->onScanTimeout(ScanTimeoutEvent());
12071201
}

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ class Gap :
799799
const address_t *get_random_address(controller_operation_t operation, size_t advertising_set = 0);
800800

801801
#if BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
802-
void connecting_to_host_resolved_address_failed();
802+
void connecting_to_host_resolved_address_failed(bool inform_user = true);
803803
#endif // BLE_GAP_HOST_BASED_PRIVATE_ADDRESS_RESOLUTION
804804

805805
private:

0 commit comments

Comments
 (0)