Skip to contentSkip to conversation

shared/bap: Use util_ltv_foreach to process metadata

PATCH Applied Luiz Augusto von Dentz 3 participants 3 messages Jul 7 – Jul 9 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shared/bap: Use util_ltv_foreach to process metadata

From: Luiz Augusto von Dentz <[email protected]>

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(-)
src/shared/bap.c +61 -27
index f2be7c07ba5d..db6f4f204787 100644
@@ -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);
Signature · 1 line
2.54.0
#1 lore raw

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=1123298

---Test result---

Test Summary:

CheckPatch                    PASS      0.51 seconds
GitLint                       PASS      0.34 seconds
BuildEll                      PASS      20.12 seconds
BluezMake                     PASS      503.93 seconds
MakeCheck                     PASS      12.82 seconds
MakeDistcheck                 PASS      152.61 seconds
CheckValgrind                 PASS      200.09 seconds
CheckSmatch                   WARNING   293.70 seconds
bluezmakeextell               PASS      94.10 seconds
IncrementalBuild              PASS      521.50 seconds
ScanBuild                     PASS      866.97 seconds

Details
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/bap.c:318:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:318:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:318:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structures

https://github.com/bluez/bluez/pull/2279

---
Regards,
Linux Bluetooth

#2 lore raw
In reply to Luiz Augusto von Dentz
This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Hello:

This patch was applied to bluetooth/bluez.git (master) by Luiz Augusto von Dentz <[email protected]>:

Quoted 8 lines · On Tue, 7 Jul 2026 14:39:44 -0400 you wrote:

From: Luiz Augusto von Dentz <[email protected]>

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(-)

Here is the summary with links:
- [BlueZ,v1] shared/bap: Use util_ltv_foreach to process metadata

    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=13b14db95089

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html