From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 5/6] transport: Don't set linked transports pending before they are enabled
Date: Mon, 2 Nov 2026 13:12:55 -0500 [thread overview]
Message-ID: <20261102181256.2321329-6-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261102181256.2321329-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
As a server, when the client enables one ASE of a bidirectional CIS
before the other, the transport of the enabled one becomes pending once
the CIS is established, and so did its link, still in QoS Configured.
An audio server would then acquire the link, which was rejected with
NotAuthorized as a server cannot enable an ASE, or acquire the enabled
one and make the link active along with it:
bap.c:ep_enable() ep 0x5e382ebaba40 id 0x03 dir 0x02
transport.c:transport_set_state() fd1: IDLE -> PENDING
transport.c:transport_set_state() fd0: IDLE -> PENDING
> org.bluez.MediaTransport1.Acquire fd0
< org.bluez.Error.NotAuthorized
As a server, only update the state and owner of a link once its stream
is enabled, only make it active along with the transport if it was
given its owner, keep the owner of a link acquired on its own, and
don't set a link that is acquired already back to pending.
A link acquired on its own is also released on its own: don't propagate
the state of the transport to it, nor disable it along with the stream,
or disabling one ASE would stop the other direction as well.
Fixes: 47ba235f5a6f ("profiles: Add initial code for bap plugin")
Assisted-by: Claude:claude-opus-5-5
---
profiles/audio/transport.c | 95 ++++++++++++++++++++++++++++++++++++--
1 file changed, 92 insertions(+), 3 deletions(-)
diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c
index e001f73151d9..c6b675f0b6ec 100644
--- a/profiles/audio/transport.c
+++ b/profiles/audio/transport.c
@@ -727,6 +727,44 @@ static void media_owner_exit(DBusConnection *connection, void *user_data)
media_transport_remove_owner(owner->transport);
}
+static bool bap_link_enabled(struct bt_bap_stream *link)
+{
+ /* A client enables its links along with the stream, while a server
+ * has to wait for the client to enable each of them.
+ */
+ if (bt_bap_stream_is_client(link))
+ return true;
+
+ switch (bt_bap_stream_get_state(link)) {
+ case BT_BAP_STREAM_STATE_ENABLING:
+ case BT_BAP_STREAM_STATE_STREAMING:
+ return true;
+ }
+
+ return false;
+}
+
+static bool bap_link_independent(struct bt_bap_stream *link,
+ struct media_owner *owner)
+{
+ struct media_transport *transport;
+
+ /* A server has its links enabled separately by the client, so they
+ * may have been acquired by a different owner.
+ */
+ if (bt_bap_stream_is_client(link))
+ return false;
+
+ transport = find_transport_by_bap_stream(link);
+
+ return transport && transport->owner && transport->owner != owner;
+}
+
+static bool match_link_independent(const void *data, const void *user_data)
+{
+ return bap_link_independent((void *)data, (void *)user_data);
+}
+
static void linked_transport_set_owner(void *data, void *user_data)
{
struct bt_bap_stream *stream = data;
@@ -739,6 +777,19 @@ static void linked_transport_set_owner(void *data, void *user_data)
return;
}
+ /* A link that is not enabled cannot be acquired yet, and once it is
+ * it will be acquired on its own.
+ */
+ if (!bap_link_enabled(stream))
+ return;
+
+ /* As a server, links are enabled separately by the client, so a link
+ * acquired already keeps its own owner.
+ */
+ if (!bt_bap_stream_is_client(stream) && transport->owner &&
+ transport->owner != owner)
+ return;
+
/* If the linked transport already has a different owner (e.g. it
* was Acquired separately), tear it down properly instead of
* silently overwriting it. Otherwise the previous owner is
@@ -2209,6 +2260,7 @@ static guint transport_bap_suspend(struct media_transport *transport,
struct bap_transport *bap = transport->data;
struct queue *links = bt_bap_stream_io_get_links(bap->stream);
bt_bap_stream_func_t func = NULL;
+ bool disable_links;
guint id;
if (!bap->stream)
@@ -2225,7 +2277,13 @@ static guint transport_bap_suspend(struct media_transport *transport,
bap_update_links(transport);
- id = bt_bap_stream_disable(bap->stream, bap->linked, func, owner);
+ /* Don't disable links acquired on their own, they are disabled
+ * when they are released.
+ */
+ disable_links = bap->linked &&
+ !queue_find(links, match_link_independent, owner);
+
+ id = bt_bap_stream_disable(bap->stream, disable_links, func, owner);
if (bt_bap_stream_get_type(bap->stream) == BT_BAP_STREAM_TYPE_BCAST) {
if (transport->owner == owner)
@@ -2262,10 +2320,16 @@ static void transport_bap_cancel(struct media_transport *transport, guint id)
bt_bap_stream_cancel(bap->stream, id);
}
+struct link_state {
+ transport_state_t state;
+ struct media_owner *owner;
+};
+
static void link_set_state(void *data, void *user_data)
{
struct bt_bap_stream *stream = data;
- transport_state_t state = PTR_TO_UINT(user_data);
+ struct link_state *ls = user_data;
+ transport_state_t state = ls->state;
struct media_transport *transport;
transport = find_transport_by_bap_stream(stream);
@@ -2274,6 +2338,30 @@ static void link_set_state(void *data, void *user_data)
return;
}
+ /* A link acquired on its own keeps its state */
+ if (bap_link_independent(stream, ls->owner))
+ return;
+
+ /* Don't bring back a link that is acquired already */
+ if (state == TRANSPORT_STATE_PENDING &&
+ transport->state >= TRANSPORT_STATE_REQUESTING)
+ return;
+
+ /* A link whose stream is not enabled cannot be acquired */
+ if ((state == TRANSPORT_STATE_PENDING ||
+ state == TRANSPORT_STATE_ACTIVE) &&
+ !bap_link_enabled(stream))
+ return;
+
+ /* As a server, a link only becomes active along with the transport
+ * if it was given its owner, otherwise it may have been enabled in
+ * the meantime and has to be acquired on its own.
+ */
+ if (state == TRANSPORT_STATE_ACTIVE &&
+ !bt_bap_stream_is_client(stream) &&
+ transport->owner != ls->owner)
+ return;
+
transport_set_state(transport, state);
}
@@ -2281,13 +2369,14 @@ static void transport_bap_set_state(struct media_transport *transport,
transport_state_t state)
{
struct bap_transport *bap = transport->data;
+ struct link_state ls = { state, transport->owner };
if (!bap->linked || bap->desync)
return;
/* Update links */
queue_foreach(bt_bap_stream_io_get_links(bap->stream), link_set_state,
- UINT_TO_PTR(state));
+ &ls);
}
static void bap_metadata_changed(struct media_transport *transport)
--
2.56.0
next prev parent reply other threads:[~2026-11-02 18:13 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-02 18:12 [PATCH BlueZ v1 0/6] Fix linked transports of an ASE not enabled yet Luiz Augusto von Dentz
2026-11-02 18:12 ` [PATCH BlueZ v1 1/6] client/scripts: Add bap-duplex-lc3.bt Luiz Augusto von Dentz
2026-11-02 19:43 ` Fix linked transports of an ASE not enabled yet bluez.test.bot
2026-11-02 18:12 ` [PATCH BlueZ v1 2/6] doc/functional-bap: Document the duplex unicast test cases Luiz Augusto von Dentz
2026-11-02 18:12 ` [PATCH BlueZ v1 3/6] test: functional: Cover enabling one ASE of a bidirectional CIS Luiz Augusto von Dentz
2026-11-02 18:12 ` [PATCH BlueZ v1 4/6] shared/bap: Add bt_bap_stream_is_client Luiz Augusto von Dentz
2026-11-02 18:12 ` Luiz Augusto von Dentz [this message]
2026-11-02 18:12 ` [PATCH BlueZ v1 6/6] transport: Don't disable desynchronized links on release 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=20261102181256.2321329-6-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.