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 1/2] emulator: Set the number of advertising sets
Date: Thu, 12 Nov 2026 02:38:57 +0000	[thread overview]
Message-ID: <20261112023858.892176-2-weihong.guan@gmail.com> (raw)
In-Reply-To: <20261112023858.892176-1-weihong.guan@gmail.com>

btdev reports MAX_EXT_ADV_SETS (3) in LE Read Number of Supported
Advertising Sets and allows that many sets. A controller may support a
single set (the command's range is 0x01 to 0xF0), and the kernel then
gives advertising instance 1 handle 0x00, the handle Global Advertising
uses too; bugs on that path don't show with three sets.

Add btdev_set_adv_sets() and hciemu_set_central_le_adv_sets() to report
and allow fewer sets, kept across HCI_Reset as a controller keeps its
capabilities.

Assisted-by: Claude:claude-opus-5.5
---
 emulator/btdev.c  | 18 ++++++++++++++++--
 emulator/btdev.h  |  2 ++
 emulator/hciemu.c | 14 ++++++++++++++
 emulator/hciemu.h |  2 ++
 4 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/emulator/btdev.c b/emulator/btdev.c
index 7a8d8a4..d7f9e5e 100644
--- a/emulator/btdev.c
+++ b/emulator/btdev.c
@@ -280,6 +280,8 @@ struct btdev {
 	uint16_t le_rl_timeout;
 
 	struct queue *le_ext_adv;
+	/* Number of advertising sets reported, kept across HCI_Reset */
+	uint8_t le_adv_sets;
 	struct queue *le_per_adv;
 	struct queue *le_big;
 
@@ -576,6 +578,17 @@ void btdev_set_rl_len(struct btdev *btdev, uint8_t len)
 	btdev->le_rl_len = len;
 }
 
+/* Set the number of advertising sets, 1 to MAX_EXT_ADV_SETS */
+bool btdev_set_adv_sets(struct btdev *btdev, uint8_t num)
+{
+	if (!num || num > MAX_EXT_ADV_SETS)
+		return false;
+
+	btdev->le_adv_sets = num;
+
+	return true;
+}
+
 static void conn_unlink(struct btdev_conn *conn1, struct btdev_conn *conn2)
 {
 	conn1->link = NULL;
@@ -5350,7 +5363,7 @@ static int cmd_set_ext_adv_params(struct btdev *dev, const void *data,
 						UINT_TO_PTR(cmd->handle));
 	if (!ext_adv) {
 		/* No more than maximum number */
-		if (queue_length(dev->le_ext_adv) >= MAX_EXT_ADV_SETS) {
+		if (queue_length(dev->le_ext_adv) >= dev->le_adv_sets) {
 			rsp.status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED;
 			cmd_complete(dev, BT_HCI_CMD_LE_SET_EXT_ADV_PARAMS,
 						&rsp, sizeof(rsp));
@@ -5707,7 +5720,7 @@ static int cmd_read_num_adv_sets(struct btdev *dev, const void *data,
 	memset(&rsp, 0, sizeof(rsp));
 
 	rsp.status = BT_HCI_ERR_SUCCESS;
-	rsp.num_of_sets = MAX_EXT_ADV_SETS;
+	rsp.num_of_sets = dev->le_adv_sets;
 	cmd_complete(dev, BT_HCI_CMD_LE_READ_NUM_SUPPORTED_ADV_SETS, &rsp,
 							sizeof(rsp));
 
@@ -8420,6 +8433,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id)
 
 	btdev->le_al_len = AL_SIZE;
 	btdev->le_rl_len = RL_SIZE;
+	btdev->le_adv_sets = MAX_EXT_ADV_SETS;
 	return btdev;
 }
 
diff --git a/emulator/btdev.h b/emulator/btdev.h
index aa04ca6..b40df29 100644
--- a/emulator/btdev.h
+++ b/emulator/btdev.h
@@ -95,6 +95,8 @@ void btdev_set_al_len(struct btdev *btdev, uint8_t len);
 
 void btdev_set_rl_len(struct btdev *btdev, uint8_t len);
 
+bool btdev_set_adv_sets(struct btdev *btdev, uint8_t num);
+
 void btdev_set_command_handler(struct btdev *btdev, btdev_command_func handler,
 							void *user_data);
 
diff --git a/emulator/hciemu.c b/emulator/hciemu.c
index 2f544f3..eb791fa 100644
--- a/emulator/hciemu.c
+++ b/emulator/hciemu.c
@@ -701,6 +701,20 @@ void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len)
 	btdev_set_rl_len(dev, len);
 }
 
+bool hciemu_set_central_le_adv_sets(struct hciemu *hciemu, uint8_t num)
+{
+	struct btdev *dev;
+
+	if (!hciemu || !hciemu->vhci)
+		return false;
+
+	dev = vhci_get_btdev(hciemu->vhci);
+	if (!dev)
+		return false;
+
+	return btdev_set_adv_sets(dev, num);
+}
+
 const uint8_t *hciemu_get_central_adv_addr(struct hciemu *hciemu,
 								uint8_t handle)
 {
diff --git a/emulator/hciemu.h b/emulator/hciemu.h
index cdf1ebe..7299763 100644
--- a/emulator/hciemu.h
+++ b/emulator/hciemu.h
@@ -80,6 +80,8 @@ void hciemu_set_central_le_al_len(struct hciemu *hciemu, uint8_t len);
 
 void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len);
 
+bool hciemu_set_central_le_adv_sets(struct hciemu *hciemu, uint8_t num);
+
 const uint8_t *hciemu_get_central_adv_addr(struct hciemu *hciemu,
 							uint8_t handle);
 
-- 
2.47.3


  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 ` Weihong Guan [this message]
2026-11-12  9:14   ` bluez.test.bot
2026-11-12  2:38 ` [PATCH BlueZ 2/2] mgmt-tester: Add single advertising set tests Weihong Guan

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-2-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