* [PATCH BlueZ] bap: Sync to the BISes of a broadcast in ascending order
@ 2026-11-22 11:49 Simon Mikuda
2026-11-22 18:55 ` [BlueZ] " bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: Simon Mikuda @ 2026-11-22 11:49 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Simon Mikuda
From: Simon Mikuda <simon.mikuda@gmail.com>
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(-)
diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c
index 457ba5de8..98ef26997 100644
--- a/profiles/audio/bap.c
+++ b/profiles/audio/bap.c
@@ -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
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-22 18:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 11:49 [PATCH BlueZ] bap: Sync to the BISes of a broadcast in ascending order Simon Mikuda
2026-11-22 18:55 ` [BlueZ] " bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox