From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 2/4] profiles/audio/bass: Handle PA_SYNC_NO_SYNC in handle_mod_src_req
Date: Thu, 11 Jun 2026 13:22:33 -0400 [thread overview]
Message-ID: <20260611172235.92930-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20260611172235.92930-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When the delegator receives a Modify Source operation with pa_sync set
to PA_SYNC_NO_SYNC while already synchronized to PA, release all
setups instead of updating BIS sync which would not apply the
requested termination.
Also reset the encryption state to no encryption when the last BIS
index is cleared from a subgroup, so subsequent source additions
start with a clean encryption state.
---
profiles/audio/bass.c | 72 ++++++++++++++++++++++++++++++++++++++++---
src/shared/bass.c | 6 ++++
2 files changed, 73 insertions(+), 5 deletions(-)
diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index f018f8b3ad7f..5eb7bff076bb 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -420,7 +420,13 @@ static void setup_clear(struct bass_setup *setup, int bis)
bt_bass_clear_bis_sync(dg->src, bis);
setup->stream = NULL;
- queue_remove(setup->dg->setups, setup);
+
+ if (!queue_remove(setup->dg->setups, setup))
+ /* Setup has already been removed from the queue (e.g. during
+ * handle_mod_src_req PA_SYNC_NO_SYNC processing). Skip
+ * disconnect check and free since the caller handles cleanup.
+ */
+ return;
/* Remove any pending bcode request associated with setup */
req = queue_remove_if(dg->bcode_reqs, match_bcode_setup, setup);
@@ -596,6 +602,8 @@ static void bass_remove_bis(struct bass_setup *setup)
{
struct queue *links = bt_bap_stream_io_get_links(setup->stream);
+ DBG("%p", setup);
+
queue_foreach(links, stream_unlink, setup->stream);
bt_bap_stream_release(setup->stream, NULL, NULL);
}
@@ -618,6 +626,8 @@ static void setup_disable_streaming(void *data, void *user_data)
static void bass_add_bis(struct bass_setup *setup)
{
+ DBG("%p", setup);
+
queue_foreach(setup->dg->setups, setup_disable_streaming, NULL);
setup_configure_stream(setup);
}
@@ -1941,8 +1951,40 @@ static int handle_set_bcode_req(struct bt_bcast_src *bcast_src,
return 0;
}
+static bool check_bis_sync(struct bt_bass_mod_src_params *params, uint8_t bis)
+{
+ uint32_t bitmask = 1 << (bis - 1);
+ struct iovec iov = {
+ .iov_base = params->subgroup_data,
+ .iov_len = 0,
+ };
+
+ /* Calculate subgroup data length based on each subgroup's
+ * bis_sync (4 bytes) + meta_len (1 byte) + meta fields.
+ */
+ for (uint8_t i = 0; i < params->num_subgroups; i++) {
+ uint32_t bis_sync;
+ uint8_t meta_len;
+
+ iov.iov_len += sizeof(bis_sync) + sizeof(meta_len);
+
+ memcpy(&bis_sync, params->subgroup_data + iov.iov_len -
+ sizeof(bis_sync) - sizeof(meta_len),
+ sizeof(bis_sync));
+ memcpy(&meta_len, params->subgroup_data + iov.iov_len -
+ sizeof(meta_len), sizeof(meta_len));
+
+ if (le32_to_cpu(bis_sync) & bitmask)
+ return true;
+
+ iov.iov_len += meta_len;
+ }
+
+ return false;
+}
+
static void bass_update_bis_sync(struct bass_delegator *dg,
- struct bt_bcast_src *bcast_src)
+ struct bt_bass_mod_src_params *params)
{
const struct queue_entry *entry;
@@ -1954,11 +1996,14 @@ static void bass_update_bis_sync(struct bass_delegator *dg,
state = bt_bap_stream_get_state(setup->stream);
- if (!setup->stream && bt_bass_check_bis(bcast_src, setup->bis))
+ DBG("stream %p: BIS %d state %s(%u)", setup->stream, setup->bis,
+ bt_bap_stream_statestr(state), state);
+
+ if (!setup->stream && check_bis_sync(params, setup->bis))
bass_add_bis(setup);
else if (setup->stream &&
state == BT_BAP_STREAM_STATE_STREAMING &&
- !bt_bass_check_bis(bcast_src, setup->bis))
+ !check_bis_sync(params, setup->bis))
bass_remove_bis(setup);
}
}
@@ -1981,9 +2026,26 @@ static int handle_mod_src_req(struct bt_bcast_src *bcast_src,
if (err)
return err;
+ DBG("PA sync state %d", sync_state);
+
switch (sync_state) {
case BT_BASS_SYNCHRONIZED_TO_PA:
- bass_update_bis_sync(dg, bcast_src);
+ if (params->pa_sync == PA_SYNC_NO_SYNC) {
+ /* Release all setups. Note: bass_remove_bis may
+ * trigger synchronous state transitions that call
+ * setup_clear which will return early since the
+ * setup has already been removed from the queue.
+ */
+ struct bass_setup *setup;
+
+ while ((setup = queue_pop_head(dg->setups))) {
+ bass_remove_bis(setup);
+ setup_free(setup);
+ }
+
+ delegator_disconnect(dg);
+ } else
+ bass_update_bis_sync(dg, params);
break;
case BT_BASS_NOT_SYNCHRONIZED_TO_PA:
if (params->pa_sync == PA_SYNC_NO_PAST) {
diff --git a/src/shared/bass.c b/src/shared/bass.c
index 19cc9531d617..65ee4a8cbb18 100644
--- a/src/shared/bass.c
+++ b/src/shared/bass.c
@@ -1930,6 +1930,12 @@ int bt_bass_clear_bis_sync(struct bt_bcast_src *bcast_src, uint8_t bis)
if (sgrp->bis_sync & bitmask) {
sgrp->bis_sync &= ~bitmask;
+ /* If there are no BIS index left then reset encryption
+ * state to no encryption.
+ */
+ if (!sgrp->bis_sync)
+ bcast_src->enc = BT_BASS_BIG_ENC_STATE_NO_ENC;
+
iov = bass_parse_bcast_src(bcast_src);
if (!iov)
return -ENOMEM;
--
2.54.0
next prev parent reply other threads:[~2026-06-11 17:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-11 17:22 [PATCH BlueZ v1 1/4] profiles/audio/bass: Use BASS_Modify_Source when assistant is active Luiz Augusto von Dentz
2026-06-11 17:22 ` Luiz Augusto von Dentz [this message]
2026-06-11 17:22 ` [PATCH BlueZ v1 3/4] profiles/audio/bass: Fix delegator reprobing after disconnect Luiz Augusto von Dentz
2026-06-11 17:22 ` [PATCH BlueZ v1 4/4] doc: Document Push behavior when MediaAssistant is active Luiz Augusto von Dentz
2026-06-11 18:50 ` [PATCH BlueZ v1 1/4] profiles/audio/bass: Use BASS_Modify_Source when assistant " patchwork-bot+bluetooth
2026-06-11 18:53 ` [BlueZ,v1,1/4] " bluez.test.bot
-- strict thread matches above, loose matches on Subject: below --
2026-06-02 21:00 [PATCH BlueZ v1 1/4] " Luiz Augusto von Dentz
2026-06-02 21:00 ` [PATCH BlueZ v1 2/4] profiles/audio/bass: Handle PA_SYNC_NO_SYNC in handle_mod_src_req Luiz Augusto von Dentz
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=20260611172235.92930-2-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/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