Linux bluetooth development
 help / color / mirror / Atom feed
From: Weihong Guan <weihong.guan@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Weihong Guan <weihong.guan@gmail.com>
Subject: [PATCH BlueZ 2/2] mgmt-tester: Add single advertising set tests
Date: Thu, 12 Nov 2026 02:38:58 +0000	[thread overview]
Message-ID: <20261112023858.892176-3-weihong.guan@gmail.com> (raw)
In-Reply-To: <20261112023858.892176-1-weihong.guan@gmail.com>

With a controller supporting one advertising set the kernel gives
instance 1 handle 0x00. Check that the set's commands and events use
the handle rather than the instance number:

 - adding a non-connectable instance sets its random address on handle
   0x00;
 - an instance whose timeout the controller enforces (the set's
   duration) is removed when the set terminates on handle 0x00;
 - removing instance 1 removes the set on handle 0x00.

They pass on bluetooth-next, which has the fixes since commit
4dce35adafb5 ("Bluetooth: hci_event: Find the owner of a terminated adv
set") and the three before it, and fail without them: the random
address goes to handle 0x01, a set the controller doesn't have.

Assisted-by: Claude:claude-opus-5.5
---
 tools/mgmt-tester.c | 87 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)

diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index 201bd43..c8282f7 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -367,6 +367,7 @@ struct generic_data {
 	bdaddr_t *setup_bdaddr;
 	bool setup_le_states;
 	const uint8_t *le_states;
+	uint8_t setup_adv_sets;
 	const uint16_t *setup_settings;
 	bool setup_nobredr;
 	bool setup_limited_discov;
@@ -505,6 +506,13 @@ static void read_index_list_callback(uint8_t status, uint16_t length,
 	if (test && test->setup_le_states)
 		hciemu_set_central_le_states(data->hciemu, test->le_states);
 
+	if (test && test->setup_adv_sets &&
+			!hciemu_set_central_le_adv_sets(data->hciemu,
+							test->setup_adv_sets)) {
+		tester_warn("hciemu_set_central_le_adv_sets failed");
+		tester_pre_setup_failed();
+	}
+
 }
 
 static void test_pre_setup(const void *test_data)
@@ -9244,6 +9252,72 @@ static const struct generic_data add_ext_advertising_timeout_expired = {
 	.expect_alt_ev_len = sizeof(advertising_instance1_param),
 };
 
+/* A controller with a single advertising set: instance 1 is given handle
+ * 0x00, so the set's commands and events carry handle 0x00, not the
+ * instance number.
+ */
+static int set_adv_set_rand_addr_handle_0_check(const void *param,
+							uint16_t length)
+{
+	const struct bt_hci_cmd_le_set_adv_set_rand_addr *cp = param;
+
+	if (length != sizeof(*cp))
+		return -EINVAL;
+
+	return cp->handle != 0x00;
+}
+
+static const uint8_t remove_adv_set_handle_0_param[] = {
+	0x00,
+};
+
+/* Handle 0x00 and any address: printed if the check fails */
+static const uint8_t set_adv_set_rand_addr_handle_0_param[] = {
+	0x00,					/* handle */
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00,	/* address */
+};
+
+static const struct generic_data add_ext_advertising_1_set = {
+	.setup_adv_sets = 1,
+	.setup_settings = settings_powered_le,
+	.send_opcode = MGMT_OP_ADD_ADVERTISING,
+	.send_param = add_advertising_param_uuid,
+	.send_len = sizeof(add_advertising_param_uuid),
+	.expect_param = advertising_instance1_param,
+	.expect_len = sizeof(advertising_instance1_param),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_alt_ev = MGMT_EV_ADVERTISING_ADDED,
+	.expect_alt_ev_param = advertising_instance1_param,
+	.expect_alt_ev_len = sizeof(advertising_instance1_param),
+	.expect_hci_command = BT_HCI_CMD_LE_SET_ADV_SET_RAND_ADDR,
+	.expect_hci_param = set_adv_set_rand_addr_handle_0_param,
+	.expect_hci_len = sizeof(set_adv_set_rand_addr_handle_0_param),
+	.expect_hci_param_check_func = set_adv_set_rand_addr_handle_0_check,
+};
+
+static const struct generic_data add_ext_adv_1_set_timeout_expired = {
+	.setup_adv_sets = 1,
+	.expect_alt_ev = MGMT_EV_ADVERTISING_REMOVED,
+	.expect_alt_ev_param = advertising_instance1_param,
+	.expect_alt_ev_len = sizeof(advertising_instance1_param),
+};
+
+static const struct generic_data remove_ext_advertising_1_set = {
+	.setup_adv_sets = 1,
+	.send_opcode = MGMT_OP_REMOVE_ADVERTISING,
+	.send_param = remove_advertising_param_1,
+	.send_len = sizeof(remove_advertising_param_1),
+	.expect_status = MGMT_STATUS_SUCCESS,
+	.expect_param = remove_advertising_param_1,
+	.expect_len = sizeof(remove_advertising_param_1),
+	.expect_alt_ev = MGMT_EV_ADVERTISING_REMOVED,
+	.expect_alt_ev_param = advertising_instance1_param,
+	.expect_alt_ev_len = sizeof(advertising_instance1_param),
+	.expect_hci_command = BT_HCI_CMD_LE_REMOVE_ADV_SET,
+	.expect_hci_param = remove_adv_set_handle_0_param,
+	.expect_hci_len = sizeof(remove_adv_set_handle_0_param),
+};
+
 static const struct generic_data remove_ext_advertising_fail_1 = {
 	.send_opcode = MGMT_OP_REMOVE_ADVERTISING,
 	.send_param = remove_advertising_param_1,
@@ -15713,6 +15787,19 @@ int main(int argc, char *argv[])
 					setup_add_advertising_connectable_1m,
 					test_command_generic);
 
+	/* A single advertising set: instance 1 on handle 0x00 */
+	test_bredrle50("Add Ext Advertising - Success (1 set, Rand Addr)",
+					&add_ext_advertising_1_set,
+					NULL, test_command_generic);
+	test_bredrle50_full("Add Ext Advertising - Success (1 set, Timeout)",
+					&add_ext_adv_1_set_timeout_expired,
+					setup_add_advertising_timeout,
+					test_command_generic, 3);
+	test_bredrle50("Remove Ext Advertising - Success (1 set)",
+					&remove_ext_advertising_1_set,
+					setup_add_advertising,
+					test_command_generic);
+
 	test_bredrle50("Remove Ext Advertising - Invalid Params 1",
 					&remove_ext_advertising_fail_1,
 					NULL, test_command_generic);
-- 
2.47.3


      parent reply	other threads:[~2026-11-12  2:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12  2:38 [PATCH BlueZ 0/2] Single advertising set in the emulator and mgmt-tester Weihong Guan
2026-11-12  2:38 ` [PATCH BlueZ 1/2] emulator: Set the number of advertising sets Weihong Guan
2026-11-12  9:14   ` Single advertising set in the emulator and mgmt-tester bluez.test.bot
2026-11-12  2:38 ` Weihong Guan [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112023858.892176-3-weihong.guan@gmail.com \
    --to=weihong.guan@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox