* [PATCH BlueZ v1] bass: Fix handling of BT_BASS_MOD_SRC
@ 2025-10-24 16:25 Luiz Augusto von Dentz
2025-10-24 17:52 ` [BlueZ,v1] " bluez.test.bot
2025-10-24 20:30 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
0 siblings, 2 replies; 3+ messages in thread
From: Luiz Augusto von Dentz @ 2025-10-24 16:25 UTC (permalink / raw)
To: linux-bluetooth
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If BT_BASS_MOD_SRC is received and the sync_state is set to
BT_BASS_SYNCHRONIZED_TO_PA it doesn't necessarily mean that the device
shall be removed, specially in case the assistant and broadcast source
are the same device.
In order to fix this behavior this attempts to free the setups that were
used for the BIS being modified, then if all setups are freed in the
process proceed to disconnect the service and then check if the
device is still considered connected after that, only if is not
connected then remove it.
---
profiles/audio/bass.c | 139 +++++++++++++++++++++++++-----------------
1 file changed, 82 insertions(+), 57 deletions(-)
diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c
index d42740ca4afb..6501d361e6ee 100644
--- a/profiles/audio/bass.c
+++ b/profiles/audio/bass.c
@@ -335,6 +335,25 @@ static bool link_enabled(const void *data, const void *match_data)
bt_bap_stream_get_io(stream));
}
+static void setup_free(void *data)
+{
+ struct bass_setup *setup = data;
+
+ DBG("setup %p", setup);
+
+ util_iov_free(setup->qos.bcast.bcode, 1);
+ util_iov_free(setup->meta, 1);
+ util_iov_free(setup->config, 1);
+ free(setup->path);
+
+ /* Clear bis index from the bis sync bitmask, if it
+ * has been previously set.
+ */
+ bt_bass_clear_bis_sync(setup->dg->src, setup->bis);
+
+ free(setup);
+}
+
static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
uint8_t new_state, void *user_data)
{
@@ -426,6 +445,8 @@ static void bap_state_changed(struct bt_bap_stream *stream, uint8_t old_state,
case BT_BAP_STREAM_STATE_IDLE:
bt_bass_clear_bis_sync(dg->src, bis);
setup->stream = NULL;
+ queue_remove(setup->dg->setups, setup);
+ setup_free(setup);
break;
}
}
@@ -695,23 +716,6 @@ static void bap_attached(struct bt_bap *bap, void *user_data)
btd_service_set_user_data(service, dg);
}
-static void setup_free(void *data)
-{
- struct bass_setup *setup = data;
-
- DBG("setup %p", setup);
-
- util_iov_free(setup->qos.bcast.bcode, 1);
- util_iov_free(setup->meta, 1);
- util_iov_free(setup->config, 1);
- free(setup->path);
-
- /* Clear bis index from the bis sync bitmask, if it
- * has been previously set.
- */
- bt_bass_clear_bis_sync(setup->dg->src, setup->bis);
-}
-
static bool match_device(const void *data, const void *match_data)
{
const struct bass_data *bdata = data;
@@ -720,6 +724,41 @@ static bool match_device(const void *data, const void *match_data)
return bdata->device == device;
}
+static void delegator_free(struct bass_delegator *dg)
+{
+ DBG("%p", dg);
+
+ if (dg->io_id)
+ g_source_remove(dg->io_id);
+
+ if (dg->io) {
+ g_io_channel_shutdown(dg->io, TRUE, NULL);
+ g_io_channel_unref(dg->io);
+ }
+
+ queue_destroy(dg->setups, setup_free);
+
+ /* Update Broadcast Receive State characteristic value and notify
+ * peers.
+ */
+ if (bt_bass_set_pa_sync(dg->src, BT_BASS_NOT_SYNCHRONIZED_TO_PA))
+ DBG("Failed to update Broadcast Receive State characteristic");
+
+ /* Unregister BAP stream state changed callback. */
+ bt_bap_state_unregister(dg->bap, dg->state_id);
+
+ bt_bap_bcode_cb_unregister(dg->bap, dg->bcode_id);
+
+ if (dg->timeout)
+ g_source_remove(dg->timeout);
+
+ queue_destroy(dg->bcode_reqs, free);
+
+ free(dg->bcode);
+
+ free(dg);
+}
+
static void bap_detached(struct bt_bap *bap, void *user_data)
{
struct btd_service *service;
@@ -755,37 +794,7 @@ static void bap_detached(struct bt_bap *bap, void *user_data)
if (!dg)
return;
- DBG("%p", dg);
-
- if (dg->io_id)
- g_source_remove(dg->io_id);
-
- if (dg->io) {
- g_io_channel_shutdown(dg->io, TRUE, NULL);
- g_io_channel_unref(dg->io);
- }
-
- queue_destroy(dg->setups, setup_free);
-
- /* Update Broadcast Receive State characteristic value and notify
- * peers.
- */
- if (bt_bass_set_pa_sync(dg->src, BT_BASS_NOT_SYNCHRONIZED_TO_PA))
- DBG("Failed to update Broadcast Receive State characteristic");
-
- /* Unregister BAP stream state changed callback. */
- bt_bap_state_unregister(dg->bap, dg->state_id);
-
- bt_bap_bcode_cb_unregister(dg->bap, dg->bcode_id);
-
- if (dg->timeout)
- g_source_remove(dg->timeout);
-
- queue_destroy(dg->bcode_reqs, free);
-
- free(dg->bcode);
-
- free(dg);
+ delegator_free(dg);
btd_service_set_user_data(service, NULL);
}
@@ -1468,22 +1477,37 @@ static int handle_mod_src_req(struct bt_bcast_src *bcast_src,
switch (sync_state) {
case BT_BASS_SYNCHRONIZED_TO_PA:
- if (params->pa_sync == PA_SYNC_NO_SYNC) {
- struct btd_adapter *adapter =
- device_get_adapter(dg->device);
+ bass_update_bis_sync(dg, bcast_src);
+ /* Check if there are any setups left since it means the PA
+ * should be no longer synchronized.
+ */
+ if (queue_isempty(dg->setups)) {
+ /* IO is no longer needed since there are no setups */
g_io_channel_shutdown(dg->io, TRUE, NULL);
g_io_channel_unref(dg->io);
dg->io = NULL;
- bt_bass_set_pa_sync(dg->src,
- BT_BASS_NOT_SYNCHRONIZED_TO_PA);
+ if (!dg->service)
+ return 0;
- /* Remove device of BIS source*/
- btd_adapter_remove_device(adapter, dg->device);
- } else {
- bass_update_bis_sync(dg, bcast_src);
+ /* Disconnect service so BAP driver is cleanup
+ * properly.
+ */
+ btd_service_disconnect(dg->service);
+
+ /* If the device is no longer consider connected
+ * it means no other service was connected so it
+ * has no longer any use and can be safely removed.
+ */
+ if (!btd_device_is_connected(dg->device)) {
+ struct btd_adapter *adapter;
+
+ adapter = device_get_adapter(dg->device);
+ btd_adapter_remove_device(adapter, dg->device);
+ }
}
+
break;
case BT_BASS_NOT_SYNCHRONIZED_TO_PA:
if (params->pa_sync == PA_SYNC_NO_PAST) {
@@ -1720,6 +1744,7 @@ static void bass_remove(struct btd_service *service)
bass_data_remove(data);
}
+
static int bass_accept(struct btd_service *service)
{
struct btd_device *device = btd_service_get_device(service);
--
2.51.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [BlueZ,v1] bass: Fix handling of BT_BASS_MOD_SRC
2025-10-24 16:25 [PATCH BlueZ v1] bass: Fix handling of BT_BASS_MOD_SRC Luiz Augusto von Dentz
@ 2025-10-24 17:52 ` bluez.test.bot
2025-10-24 20:30 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: bluez.test.bot @ 2025-10-24 17:52 UTC (permalink / raw)
To: linux-bluetooth, luiz.dentz
[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]
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/project/bluetooth/list/?series=1015549
---Test result---
Test Summary:
CheckPatch PENDING 0.25 seconds
GitLint PENDING 0.30 seconds
BuildEll PASS 20.03 seconds
BluezMake PASS 2650.83 seconds
MakeCheck PASS 20.68 seconds
MakeDistcheck PASS 184.05 seconds
CheckValgrind PASS 235.84 seconds
CheckSmatch PASS 309.91 seconds
bluezmakeextell PASS 128.68 seconds
IncrementalBuild PENDING 0.31 seconds
ScanBuild PASS 918.28 seconds
Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script
Output:
##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH BlueZ v1] bass: Fix handling of BT_BASS_MOD_SRC
2025-10-24 16:25 [PATCH BlueZ v1] bass: Fix handling of BT_BASS_MOD_SRC Luiz Augusto von Dentz
2025-10-24 17:52 ` [BlueZ,v1] " bluez.test.bot
@ 2025-10-24 20:30 ` patchwork-bot+bluetooth
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+bluetooth @ 2025-10-24 20:30 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hello:
This patch was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:
On Fri, 24 Oct 2025 12:25:53 -0400 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> If BT_BASS_MOD_SRC is received and the sync_state is set to
> BT_BASS_SYNCHRONIZED_TO_PA it doesn't necessarily mean that the device
> shall be removed, specially in case the assistant and broadcast source
> are the same device.
>
> [...]
Here is the summary with links:
- [BlueZ,v1] bass: Fix handling of BT_BASS_MOD_SRC
https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=81a995932768
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-24 20:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-24 16:25 [PATCH BlueZ v1] bass: Fix handling of BT_BASS_MOD_SRC Luiz Augusto von Dentz
2025-10-24 17:52 ` [BlueZ,v1] " bluez.test.bot
2025-10-24 20:30 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox