From: Simon Mikuda <simon.mikuda@streamunlimited.com>
To: linux-bluetooth@vger.kernel.org
Cc: Simon Mikuda <simon.mikuda@gmail.com>
Subject: [PATCH BlueZ] bap: Sync to the BISes of a broadcast in ascending order
Date: Sun, 22 Nov 2026 12:49:18 +0100 [thread overview]
Message-ID: <20261122114918.1063391-1-simon.mikuda@streamunlimited.com> (raw)
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
next reply other threads:[~2026-11-22 11:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-22 11:49 Simon Mikuda [this message]
2026-11-22 18:55 ` [BlueZ] bap: Sync to the BISes of a broadcast in ascending order bluez.test.bot
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=20261122114918.1063391-1-simon.mikuda@streamunlimited.com \
--to=simon.mikuda@streamunlimited.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=simon.mikuda@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