Skip to content

Commit 2eafc82

Browse files
cvinayakfabiobaltieri
authored andcommitted
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 <vich@nordicsemi.no>
1 parent 226e343 commit 2eafc82

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

subsys/bluetooth/host/scan.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ static int scan_update(void)
476476
return err;
477477
}
478478

479-
static uint32_t scan_check_if_state_allowed(enum bt_le_scan_user flag)
479+
static int scan_check_if_state_allowed(enum bt_le_scan_user flag)
480480
{
481481
/* check if state is already set */
482482
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)
499499
/* Only check if the scanner parameters should be updated / the scanner should be
500500
* started. This is mainly triggered once connections are established.
501501
*/
502-
} else {
503-
/* Check if it can be enabled */
504-
err = scan_check_if_state_allowed(flag);
505-
if (err) {
506-
return err;
507-
}
508-
atomic_set_bit(scan_state.scan_flags, flag);
502+
return scan_update();
509503
}
510504

511-
return scan_update();
505+
err = scan_check_if_state_allowed(flag);
506+
if (err) {
507+
return err;
508+
}
509+
510+
atomic_set_bit(scan_state.scan_flags, flag);
511+
512+
err = scan_update();
513+
if (err) {
514+
atomic_clear_bit(scan_state.scan_flags, flag);
515+
}
516+
517+
return err;
512518
}
513519

514520
int bt_le_scan_user_remove(enum bt_le_scan_user flag)

0 commit comments

Comments
 (0)