diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 938f1aa460..6a115c2df4 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -591,6 +591,7 @@ ble_error_t GenericGap::stopScan() set_random_address_rotation(false); _scan_timeout.detach(); + return BLE_ERROR_NONE; } @@ -1487,7 +1488,7 @@ void GenericGap::on_scan_timeout() } /* if timeout happened on a 4.2 chip we need to stop the scan manually */ - if (is_extended_advertising_available()) { + if (!is_extended_advertising_available()) { _pal_gap.scan_enable(false, false); set_random_address_rotation(false); } @@ -2983,8 +2984,6 @@ ble_error_t GenericGap::startScan( if (err) { return err; } - - _scan_enabled = true; } else { if (period.value() != 0) { return BLE_ERROR_INVALID_PARAM; @@ -2999,8 +2998,6 @@ ble_error_t GenericGap::startScan( return err; } - _scan_enabled = true; - _scan_timeout.detach(); if (duration.value()) { _scan_timeout.attach_us( @@ -3010,6 +3007,8 @@ ble_error_t GenericGap::startScan( } } + _scan_enabled = true; + return BLE_ERROR_NONE; }