From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2] shared/bap: Fix swallowing states transitions
Date: Tue, 1 Apr 2025 09:51:15 -0400 [thread overview]
Message-ID: <20250401135115.3735533-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
In certain cases (e.g ASCS_Enable) a Control Point operation may change
states multiple times causing states not to be notified.
To fix this attempts to queue states if timeout is pending (state_id)
and then proceed to notify them ahead of the last state set in the ASE
so the remote side is informed of all the state transitions.
---
src/shared/bap.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
diff --git a/src/shared/bap.c b/src/shared/bap.c
index 5d4d69d2925b..650bea2f4e8d 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -293,6 +293,7 @@ struct bt_bap_stream {
uint8_t old_state;
uint8_t state;
unsigned int state_id;
+ struct queue *pending_states;
bool client;
void *user_data;
};
@@ -1205,6 +1206,7 @@ static void bap_stream_free(void *data)
struct bt_bap_stream *stream = data;
timeout_remove(stream->state_id);
+ queue_destroy(stream->pending_states, NULL);
if (stream->ep)
stream->ep->stream = NULL;
@@ -1705,19 +1707,11 @@ static bool bap_queue_req(struct bt_bap *bap, struct bt_bap_req *req)
return true;
}
-static bool stream_notify_state(void *data)
+static void stream_notify(struct bt_bap_stream *stream, uint8_t state)
{
- struct bt_bap_stream *stream = data;
- struct bt_bap_endpoint *ep = stream->ep;
+ DBG(stream->bap, "stream %p state %d", stream, state);
- DBG(stream->bap, "stream %p status %d", stream, ep->state);
-
- if (stream->state_id) {
- timeout_remove(stream->state_id);
- stream->state_id = 0;
- }
-
- switch (ep->state) {
+ switch (state) {
case BT_ASCS_ASE_STATE_IDLE:
break;
case BT_ASCS_ASE_STATE_CONFIG:
@@ -1735,6 +1729,24 @@ static bool stream_notify_state(void *data)
stream_notify_release(stream);
break;
}
+}
+
+static bool stream_notify_state(void *data)
+{
+ struct bt_bap_stream *stream = data;
+ struct bt_bap_endpoint *ep = stream->ep;
+ uint8_t state;
+
+ if (stream->state_id) {
+ timeout_remove(stream->state_id);
+ stream->state_id = 0;
+ }
+
+ /* Notify any pending states before notifying ep->state */
+ while ((state = PTR_TO_UINT(queue_pop_head(stream->pending_states))))
+ stream_notify(stream, state);
+
+ stream_notify(stream, ep->state);
return false;
}
@@ -1760,6 +1772,10 @@ static void bap_ucast_set_state(struct bt_bap_stream *stream, uint8_t state)
stream->state_id = timeout_add(BAP_PROCESS_TIMEOUT,
stream_notify_state,
stream, NULL);
+ else /* If a state_id is already pending then queue the old one */
+ queue_push_tail(stream->pending_states,
+ UINT_TO_PTR(ep->old_state));
+
done:
bap_stream_state_changed(stream);
@@ -2716,6 +2732,7 @@ static struct bt_bap_stream *bap_stream_new(struct bt_bap *bap,
stream->cc = util_iov_dup(data, 1);
stream->client = client;
stream->ops = bap_stream_new_ops(stream);
+ stream->pending_states = queue_new();
queue_push_tail(bap->streams, stream);
--
2.48.1
next reply other threads:[~2025-04-01 13:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-01 13:51 Luiz Augusto von Dentz [this message]
2025-04-01 15:11 ` [BlueZ,v2] shared/bap: Fix swallowing states transitions bluez.test.bot
2025-04-01 21:40 ` [PATCH BlueZ v2] " patchwork-bot+bluetooth
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=20250401135115.3735533-1-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