suppress scan timeout if we disabled scanning

pull/9058/head
paul-szczepanek-arm 2018-12-10 16:31:34 +00:00
parent a545da7790
commit 13a10f3efa
2 changed files with 44 additions and 8 deletions

View File

@ -726,6 +726,7 @@ private:
ble::address_t _random_static_identity_address; ble::address_t _random_static_identity_address;
bool _random_address_rotating; bool _random_address_rotating;
bool _scan_enabled;
mbed::Timeout _advertising_timeout; mbed::Timeout _advertising_timeout;
mbed::Timeout _scan_timeout; mbed::Timeout _scan_timeout;
mbed::Ticker _address_rotation_ticker; mbed::Ticker _address_rotation_ticker;

View File

@ -435,6 +435,7 @@ GenericGap::GenericGap(
_peripheral_privacy_configuration(default_peripheral_privacy_configuration), _peripheral_privacy_configuration(default_peripheral_privacy_configuration),
_central_privacy_configuration(default_central_privacy_configuration), _central_privacy_configuration(default_central_privacy_configuration),
_random_address_rotating(false), _random_address_rotating(false),
_scan_enabled(false),
_advertising_timeout(), _advertising_timeout(),
_scan_timeout(), _scan_timeout(),
_connection_event_handler(NULL), _connection_event_handler(NULL),
@ -564,15 +565,27 @@ ble_error_t GenericGap::stopAdvertising()
ble_error_t GenericGap::stopScan() ble_error_t GenericGap::stopScan()
{ {
ble_error_t err; ble_error_t err;
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
if (!_scan_enabled) {
return BLE_ERROR_NONE;
}
_scan_enabled = false;
err = _pal_gap.extended_scan_enable(false, pal::duplicates_filter_t::DISABLE, 0, 0); err = _pal_gap.extended_scan_enable(false, pal::duplicates_filter_t::DISABLE, 0, 0);
if (err) {
_scan_enabled = true;
return err;
}
} else { } else {
err = _pal_gap.scan_enable(false, false); err = _pal_gap.scan_enable(false, false);
}
if (err) { if (err) {
return err; return err;
} }
}
// Stop address rotation if required // Stop address rotation if required
set_random_address_rotation(false); set_random_address_rotation(false);
@ -1465,6 +1478,12 @@ BLE_DEPRECATED_API_USE_END()
void GenericGap::on_scan_timeout() void GenericGap::on_scan_timeout()
{ {
if (!_scan_enabled) {
return;
}
_scan_enabled = false;
if (!_eventHandler) { if (!_eventHandler) {
return; return;
} }
@ -2368,6 +2387,9 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
ble_error_t status; ble_error_t status;
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
_active_sets.clear(handle);
status = _pal_gap.extended_advertising_enable( status = _pal_gap.extended_advertising_enable(
/*enable ? */ false, /*enable ? */ false,
/* number of advertising sets */ 1, /* number of advertising sets */ 1,
@ -2377,6 +2399,7 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
); );
if (status) { if (status) {
_active_sets.set(handle);
return status; return status;
} }
} else { } else {
@ -2384,17 +2407,18 @@ ble_error_t GenericGap::stopAdvertising(advertising_handle_t handle)
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
} }
_active_sets.clear(handle);
status = _pal_gap.advertising_enable(false); status = _pal_gap.advertising_enable(false);
if (status) { if (status) {
_active_sets.set(handle);
return status; return status;
} }
_advertising_timeout.detach(); _advertising_timeout.detach();
} }
_active_sets.clear(handle);
return status; return status;
} }
@ -2722,6 +2746,10 @@ void GenericGap::on_advertising_set_terminated(
uint8_t number_of_completed_extended_advertising_events uint8_t number_of_completed_extended_advertising_events
) )
{ {
if (!_active_sets.get(advertising_handle)) {
return;
}
_active_sets.clear(advertising_handle); _active_sets.clear(advertising_handle);
if (!_eventHandler) { if (!_eventHandler) {
@ -2875,12 +2903,19 @@ ble_error_t GenericGap::startScan(
} }
if (is_extended_advertising_available()) { if (is_extended_advertising_available()) {
return _pal_gap.extended_scan_enable( _scan_enabled = true;
ble_error_t err = _pal_gap.extended_scan_enable(
/* enable */true, /* enable */true,
filtering, filtering,
duration.value(), duration.value(),
period.value() period.value()
); );
if (err) {
_scan_enabled = false;
return err;
}
} else { } else {
if (period.value() != 0) { if (period.value() != 0) {
return BLE_ERROR_INVALID_PARAM; return BLE_ERROR_INVALID_PARAM;
@ -2902,10 +2937,10 @@ ble_error_t GenericGap::startScan(
microsecond_t(duration).value() microsecond_t(duration).value()
); );
} }
}
return BLE_ERROR_NONE; return BLE_ERROR_NONE;
} }
}
ble_error_t GenericGap::createSync( ble_error_t GenericGap::createSync(
peer_address_type_t peerAddressType, peer_address_type_t peerAddressType,