Commit c2e4029a authored by Jonathan Rico's avatar Jonathan Rico Committed by Johan Hedberg
Browse files

Bluetooth: host: resume advertising even when BT_EXT_ADV=y



When using extended advertising commands, the advertising set is not
considered to be over until we receive `BT_HCI_EVT_LE_ADV_SET_TERMINATED`
from the controller. Only then do we clear the `BT_ADV_ENABLED` flag.

The problem is that `bt_le_adv_resume` is called on connection established,
which can happen before adv set terminated, and in that case it will
early-return because `BT_ADV_ENABLED` is still set.

This change triggers `bt_le_adv_resume` when we get
`BT_HCI_EVT_LE_ADV_SET_TERMINATED`.

Fixes #53048

Signed-off-by: default avatarJonathan Rico <jonathan.rico@nordicsemi.no>
parent ca843964
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -2069,10 +2069,16 @@ void bt_hci_le_adv_set_terminated(struct net_buf *buf)
		}
	}

	if (!atomic_test_bit(adv->flags, BT_ADV_PERSIST) && adv == bt_dev.adv) {
	if (adv == bt_dev.adv) {
		if (atomic_test_bit(adv->flags, BT_ADV_PERSIST)) {
#if defined(CONFIG_BT_PERIPHERAL)
			bt_le_adv_resume();
#endif
		} else {
			bt_le_adv_delete_legacy();
		}
	}
}

void bt_hci_le_scan_req_received(struct net_buf *buf)
{
+18 −0
Original line number Diff line number Diff line
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_CENTRAL=y

CONFIG_ASSERT=y
CONFIG_BT_TESTING=y
CONFIG_BT_DEBUG_LOG=y

CONFIG_BT_EXT_ADV=y
CONFIG_BT_PRIVACY=n

CONFIG_BT_AUTO_PHY_UPDATE=n
CONFIG_BT_AUTO_DATA_LEN_UPDATE=n
CONFIG_BT_GAP_AUTO_UPDATE_CONN_PARAMS=n

CONFIG_BT_MAX_CONN=2
CONFIG_BT_MAX_PAIRED=2
CONFIG_BT_ID_MAX=2
+5 −2
Original line number Diff line number Diff line
@@ -14,6 +14,9 @@ BUILD_ASSERT(CONFIG_BT_ID_MAX == 2, "CONFIG_BT_ID_MAX should be 2.");
#define BS_SECONDS(dur_sec)    ((bs_time_t)dur_sec * USEC_PER_SEC)
#define TEST_TIMEOUT_SIMULATED BS_SECONDS(60)

DEFINE_FLAG(flag_is_connected);
DEFINE_FLAG(flag_test_end);

void test_tick(bs_time_t HW_device_time)
{
	bs_trace_debug_time(0, "Simulation ends now.\n");
@@ -29,8 +32,6 @@ void test_init(void)
	bst_result = In_progress;
}

DEFINE_FLAG(flag_is_connected);

void wait_connected(void)
{
	UNSET_FLAG(flag_is_connected);
@@ -68,6 +69,8 @@ void bs_bt_utils_setup(void)
{
	int err;

	UNSET_FLAG(flag_test_end);

	err = bt_enable(NULL);
	ASSERT(!err, "bt_enable failed.\n");
}
+13 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@

extern enum bst_result_t bst_result;

#define DECLARE_FLAG(flag) extern atomic_t flag
#define DEFINE_FLAG(flag)  atomic_t flag = (atomic_t) false
#define SET_FLAG(flag)	   (void)atomic_set(&flag, (atomic_t) true)
#define UNSET_FLAG(flag)   (void)atomic_set(&flag, (atomic_t) false)
@@ -47,13 +48,17 @@ extern enum bst_result_t bst_result;
		}                                                                                  \
	} while (0)

DECLARE_FLAG(flag_test_end);

#define FAIL(...)					\
	SET_FLAG(flag_test_end);			\
	do {						\
		bst_result = Failed;			\
		bs_trace_error_time_line(__VA_ARGS__);	\
	} while (0)

#define PASS(...)					\
	SET_FLAG(flag_test_end);			\
	do {						\
		bst_result = Passed;			\
		bs_trace_info_time(1, __VA_ARGS__);	\
+12 −0
Original line number Diff line number Diff line
@@ -52,3 +52,15 @@ void dut_procedure(void)

	PASS("PASS\n");
}

void dut_procedure_2(void)
{
	bs_bt_utils_setup();

	printk("DUT start\n");

	/* Start a resumable advertiser. */
	advertise_connectable(0, true);

	PASS("DUT done\n");
}
Loading