From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1] shared/bap: Use util_ltv_foreach to process metadata
Date: Tue, 7 Jul 2026 14:39:44 -0400 [thread overview]
Message-ID: <20260707183944.1215551-1-luiz.dentz@gmail.com> (raw)
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This makes use of util_ltv_foreach to process the metadata entries
instead of attempting to iterate over the entries manually which
probably only works with the exact same order as used by PTS.
---
src/shared/bap.c | 88 +++++++++++++++++++++++++++++++++---------------
1 file changed, 61 insertions(+), 27 deletions(-)
diff --git a/src/shared/bap.c b/src/shared/bap.c
index f2be7c07ba5d..db6f4f204787 100644
--- a/src/shared/bap.c
+++ b/src/shared/bap.c
@@ -3404,35 +3404,69 @@ static uint8_t stream_enable(struct bt_bap_stream *stream, struct iovec *meta,
return 0;
}
-static bool ascs_metadata_rsp(struct bt_bap_endpoint *ep, struct iovec *meta,
- struct iovec *rsp)
+struct bap_metadata_process {
+ struct bt_bap_endpoint *ep;
+ uint16_t context;
+ struct iovec *rsp;
+ uint8_t err;
+};
+
+static void bap_metadata_process(size_t i, uint8_t l, uint8_t t, uint8_t *v,
+ void *user_data)
{
- struct bt_ltv *ltv;
- uint16_t supported_context = 0;
+ struct bap_metadata_process *data = user_data;
uint16_t context;
- if (ep->stream && ep->stream->lpac)
- supported_context = ep->stream->lpac->qos.supported_context;
-
- ltv = meta->iov_base;
- if (meta->iov_len >= sizeof(*ltv) &&
- (ltv->type < BAP_METADATA_PREF_CONTEXT_LTV_TYPE ||
- ltv->type > BAP_METADATA_LANGUAGE_LTV_TYPE)) {
- ascs_ase_rsp_add(rsp, ep->id,
- BT_ASCS_RSP_METADATA_UNSUPPORTED, ltv->type);
- return true;
- }
-
- if (meta->iov_len >= sizeof(*ltv) + sizeof(context) &&
- ltv->type == BAP_METADATA_CONTEXT_LTV_TYPE &&
- ltv->len == sizeof(context) + 1) {
- context = get_le16(ltv->value);
- if (!context || (context & ~supported_context)) {
- ascs_ase_rsp_add(rsp, ep->id,
- BT_ASCS_RSP_METADATA_INVALID,
- ltv->type);
- return true;
+ switch (t) {
+ case BAP_METADATA_PREF_CONTEXT_LTV_TYPE:
+ break;
+ case BAP_METADATA_CONTEXT_LTV_TYPE:
+ if (l != sizeof(context)) {
+ ascs_ase_rsp_add(data->rsp, data->ep->id,
+ BT_ASCS_RSP_METADATA_INVALID, t);
+ data->err = BT_ASCS_RSP_METADATA_INVALID;
+ break;
}
+
+ context = get_le16(v);
+ if (!context || (context & ~data->context)) {
+ ascs_ase_rsp_add(data->rsp, data->ep->id,
+ BT_ASCS_RSP_METADATA_INVALID, t);
+ data->err = BT_ASCS_RSP_METADATA_INVALID;
+ }
+
+ break;
+ case BAP_METADATA_PROGRAM_INFO_LTV_TYPE:
+ case BAP_METADATA_LANGUAGE_LTV_TYPE:
+ break;
+ default:
+ ascs_ase_rsp_add(data->rsp, data->ep->id,
+ BT_ASCS_RSP_METADATA_UNSUPPORTED,
+ t);
+ data->err = BT_ASCS_RSP_METADATA_UNSUPPORTED;
+ break;
+ };
+}
+
+static bool ascs_metadata_rsp(struct bt_bap_endpoint *ep, struct bt_bap *bap,
+ struct iovec *meta, struct iovec *rsp)
+{
+ struct bap_metadata_process data = {
+ .ep = ep,
+ .rsp = rsp,
+ .err = 0,
+ };
+
+ if (ep->stream && ep->stream->lpac)
+ data.context = ep->stream->lpac->qos.supported_context;
+
+ util_ltv_foreach(meta->iov_base, meta->iov_len, NULL,
+ bap_metadata_process, &data);
+
+ if (data.err) {
+ DBG(bap, "ep %p id 0x%02x metadata error 0x%02x", ep, ep->id,
+ data.err);
+ return true;
}
return false;
@@ -3469,7 +3503,7 @@ static uint8_t ep_enable(struct bt_bap_endpoint *ep, struct bt_bap *bap,
return 0;
}
- if (ascs_metadata_rsp(ep, &meta, rsp))
+ if (ascs_metadata_rsp(ep, bap, &meta, rsp))
return 0;
if (!ep->stream) {
@@ -3705,7 +3739,7 @@ static uint8_t ep_metadata(struct bt_bap_endpoint *ep,
meta.iov_base = util_iov_pull_mem(iov, req->len);
meta.iov_len = req->len;
- if (ascs_metadata_rsp(ep, &meta, rsp))
+ if (ascs_metadata_rsp(ep, stream->bap, &meta, rsp))
return 0;
return stream_metadata(ep->stream, &meta, rsp);
--
2.54.0
next reply other threads:[~2026-07-07 18:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-07 18:39 Luiz Augusto von Dentz [this message]
2026-07-07 20:36 ` [BlueZ,v1] shared/bap: Use util_ltv_foreach to process metadata bluez.test.bot
2026-07-09 15:30 ` [PATCH BlueZ v1] " 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=20260707183944.1215551-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