From 2eafc826e31b44a100bf9a7860c5728afa768280 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 3 Sep 2024 09:45:50 +0200 Subject: [PATCH] Bluetooth: Host: Fix unable to start scanning after scan param failure Fix scan_update() implementation for missing flags clear that prevented starting scanning after previous attempt to start failed due to parameters being rejected by the Controller. Example, attempting to start coded PHY scanning with a Controller implementation that does not support it can fail, but attempting again without coded PHY scanning should succeed. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/host/scan.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/subsys/bluetooth/host/scan.c b/subsys/bluetooth/host/scan.c index ad469a57588..0dbfa27bd08 100644 --- a/subsys/bluetooth/host/scan.c +++ b/subsys/bluetooth/host/scan.c @@ -476,7 +476,7 @@ static int scan_update(void) return err; } -static uint32_t scan_check_if_state_allowed(enum bt_le_scan_user flag) +static int scan_check_if_state_allowed(enum bt_le_scan_user flag) { /* check if state is already set */ if (atomic_test_bit(scan_state.scan_flags, flag)) { @@ -499,16 +499,22 @@ int bt_le_scan_user_add(enum bt_le_scan_user flag) /* Only check if the scanner parameters should be updated / the scanner should be * started. This is mainly triggered once connections are established. */ - } else { - /* Check if it can be enabled */ - err = scan_check_if_state_allowed(flag); - if (err) { - return err; - } - atomic_set_bit(scan_state.scan_flags, flag); + return scan_update(); } - return scan_update(); + err = scan_check_if_state_allowed(flag); + if (err) { + return err; + } + + atomic_set_bit(scan_state.scan_flags, flag); + + err = scan_update(); + if (err) { + atomic_clear_bit(scan_state.scan_flags, flag); + } + + return err; } int bt_le_scan_user_remove(enum bt_le_scan_user flag)