Skip to contentSkip to conversation

bap: Sync to the BISes of a broadcast in ascending order

PATCH Applied Simon Mikuda 3 participants 3 messages Nov 22 – Nov 23 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bap: Sync to the BISes of a broadcast in ascending order

From: Simon Mikuda <[email protected]>

The BIS list of a BIG sync is built in the order the transports were acquired, so when BIS 2 is acquired before BIS 1, the kernel sends LE BIG Create Sync with BIS 2 listed first. Core Vol 4 Part E 7.8.106 requires ascending order, so the controller can reject the command with Invalid HCI Command Parameters (0x12). Nothing reports that, so the transports stay broadcasting and the stream is silent.

Sort the BIS numbers in ascending order. The kernel notifies the BIS fds in that order, so give each fd to the stream with the lowest BIS that has no fd yet.

Fixes e59a915db9d8 ("bap: Remove PA idle timer logic")
Assisted-by Claude:claude-opus-5-5
---
 profiles/audio/bap.c | 54 ++++++++++++++++++++++++++------------------
 1 file changed, 32 insertions(+), 22 deletions(-)
profiles/audio/bap.c +32 -22
index 457ba5de8..98ef26997 100644
@@ -1672,10 +1672,23 @@ static bool stream_io_unset(const void *data, const void *user_data)
 	return !bt_bap_stream_get_io(stream);
 }
 
+static void find_lowest_unset_bis(void *data, void *user_data)
+{
+	struct bt_bap_stream *stream = data;
+	struct bt_bap_stream **lowest = user_data;
+
+	if (bt_bap_stream_get_io(stream))
+		return;
+
+	if (!*lowest || bt_bap_stream_get_qos(stream)->bcast.bis <
+				bt_bap_stream_get_qos(*lowest)->bcast.bis)
+		*lowest = stream;
+}
+
 static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data)
 {
 	struct bap_setup *setup = user_data;
-	struct bt_bap_stream *stream = setup->stream;
+	struct bt_bap_stream *stream = NULL;
 	int fd;
 	struct bap_data *bap_data = setup->data;
 
@@ -1685,12 +1698,15 @@ static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data)
 		DBG("BIG Sync completed");
 
 	/* The order of the BIS fds notified from kernel corresponds
-	 * to the order of the BISes that were enqueued before
-	 * calling bt_io_bcast_accept.
+	 * to the order of the BISes passed to bt_io_bcast_accept,
+	 * which is ascending, so the fd belongs to the stream with
+	 * the lowest BIS that has no fd yet.
 	 */
-	if (bt_bap_stream_get_io(stream))
-		stream = queue_find(bt_bap_stream_io_get_links(stream),
-				stream_io_unset, NULL);
+	find_lowest_unset_bis(setup->stream, &stream);
+	queue_foreach(bt_bap_stream_io_get_links(setup->stream),
+					find_lowest_unset_bis, &stream);
+	if (!stream)
+		return;
 
 	fd = g_io_channel_unix_get_fd(io);
 
@@ -3902,22 +3918,7 @@ static void append_setup(void *data, void *user_data)
 {
 	struct bt_bap_stream *stream = data;
 	struct sockaddr_iso_bc *addr = user_data;
-	char *path = bt_bap_stream_get_user_data(stream);
-	int bis = 1;
-	int s_err;
-	const char *strbis = NULL;
-
-	strbis = strstr(path, "/bis");
-	if (!strbis) {
-		DBG("bis index cannot be found");
-		return;
-	}
-
-	s_err = sscanf(strbis, "/bis%d", &bis);
-	if (s_err == -1) {
-		DBG("sscanf error");
-		return;
-	}
+	uint8_t bis = bt_bap_stream_get_qos(stream)->bcast.bis;
 
 	DBG("Do BIG Sync with BIS %d", bis);
 
@@ -3925,6 +3926,11 @@ static void append_setup(void *data, void *user_data)
 	addr->bc_num_bis++;
 }
 
+static int bis_cmp(const void *a, const void *b)
+{
+	return *(const uint8_t *)a - *(const uint8_t *)b;
+}
+
 static void setup_refresh_qos(void *data, void *user_data)
 {
 	struct bt_bap_stream *stream = data;
@@ -3957,6 +3963,10 @@ static gboolean iso_do_big_sync(GIOChannel *io, GIOCondition cond,
 	append_setup(setup->stream, &iso_bc_addr);
 	queue_foreach(links, append_setup, &iso_bc_addr);
 
+	/* The BIS list shall be in ascending order */
+	qsort(iso_bc_addr.bc_bis, iso_bc_addr.bc_num_bis, sizeof(uint8_t),
+								bis_cmp);
+
 	/* Refresh qos stored in setups */
 	setup->qos = *bt_bap_stream_get_qos(setup->stream);
 	queue_foreach(links, setup_refresh_qos, data);

base-commit: 1adfe662efeff12997df9ddd0960dbd0de9c8ea7

Signature · 1 line
2.43.0
#1 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1218592/

---Test result---

Test Summary:

CheckPatch                    PASS      0.48 seconds
GitLint                       PASS      0.30 seconds
BuildEll                      PASS      20.85 seconds
BluezMake                     PASS      315.44 seconds
MakeCheck                     PASS      3.01 seconds
MakeDistcheck                 PASS      148.93 seconds
CheckValgrind                 PASS      161.60 seconds
CheckSmatch                   PASS      323.34 seconds
bluezmakeextell               PASS      103.40 seconds
TestFunctional                PASS      1259.73 seconds
IncrementalBuild              PASS      324.01 seconds
ScanBuild                     PASS      1223.73 seconds

https://github.com/bluez/bluez/pull/2873

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Simon Mikuda
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 10 lines · On Sun, 22 Nov 2026 12:49:18 +0100 you wrote:

From: Simon Mikuda <[email protected]>

The BIS list of a BIG sync is built in the order the transports were acquired, so when BIS 2 is acquired before BIS 1, the kernel sends LE BIG Create Sync with BIS 2 listed first. Core Vol 4 Part E 7.8.106 requires ascending order, so the controller can reject the command with Invalid HCI Command Parameters (0x12). Nothing reports that, so the transports stay broadcasting and the stream is silent.

[...]

Here is the summary with links:
- [BlueZ] bap: Sync to the BISes of a broadcast in ascending order

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=532e05b1257b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html