From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 3/5] shared/asha: Use util_iov helpers to parse characteristic values
Date: Wed, 11 Nov 2026 15:39:47 -0500 [thread overview]
Message-ID: <20261111203949.3874673-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261111203949.3874673-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
Parse the Read Only Properties and PSM values with util_iov_pull_*
instead of indexing the value at fixed offsets.
Assisted-by: OpenCode:claude-sonnet-5.5
---
src/shared/asha.c | 52 ++++++++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 16 deletions(-)
diff --git a/src/shared/asha.c b/src/shared/asha.c
index 07327cd4b8f1..2ce61fd13e96 100644
--- a/src/shared/asha.c
+++ b/src/shared/asha.c
@@ -368,19 +368,18 @@ static void read_psm(bool success,
void *user_data)
{
struct bt_asha *asha = user_data;
+ struct iovec iov = { (void *)value, length };
if (!success) {
DBG("Reading PSM failed with ATT error: %u", att_ecode);
return;
}
- if (length != 2) {
+ if (length != 2 || !util_iov_pull_le16(&iov, &asha->psm)) {
DBG("Reading PSM failed: unexpected length %u", length);
return;
}
- asha->psm = get_le16(value);
-
DBG("Got PSM: %u", asha->psm);
check_probe_done(asha);
@@ -393,41 +392,62 @@ static void read_rops(bool success,
void *user_data)
{
struct bt_asha *asha = user_data;
+ struct iovec iov = { (void *)value, length };
+ uint8_t version, caps, features;
+ uint16_t render_delay, codec_ids;
+ uint8_t *hisyncid;
if (!success) {
DBG("Reading ROPs failed with ATT error: %u", att_ecode);
return;
}
- if (length != 17) {
- DBG("Reading ROPs failed: unexpected length %u", length);
- return;
- }
+ if (length != 17)
+ goto invalid;
+
+ if (!util_iov_pull_u8(&iov, &version) ||
+ !util_iov_pull_u8(&iov, &caps))
+ goto invalid;
- if (value[0] != 0x01) {
- DBG("Unexpected ASHA version: %u", value[0]);
+ hisyncid = util_iov_pull_mem(&iov, 8);
+ if (!hisyncid)
+ goto invalid;
+
+ if (!util_iov_pull_u8(&iov, &features) ||
+ !util_iov_pull_le16(&iov, &render_delay) ||
+ !util_iov_pull(&iov, 2) ||
+ !util_iov_pull_le16(&iov, &codec_ids))
+ goto invalid;
+
+ if (version != 0x01) {
+ DBG("Unexpected ASHA version: %u", version);
return;
}
/* Device Capabilities */
- asha->right_side = (value[1] & 0x1) != 0;
- asha->binaural = (value[1] & 0x2) != 0;
- asha->csis_supported = (value[1] & 0x4) != 0;
+ asha->right_side = (caps & 0x1) != 0;
+ asha->binaural = (caps & 0x2) != 0;
+ asha->csis_supported = (caps & 0x4) != 0;
/* HiSyncId: 2 byte company id, 6 byte ID shared by left and right */
- memcpy(asha->hisyncid, &value[2], 8);
+ memcpy(asha->hisyncid, hisyncid, 8);
/* FeatureMap */
- asha->coc_streaming_supported = (value[10] & 0x1) != 0;
+ asha->coc_streaming_supported = (features & 0x1) != 0;
/* RenderDelay */
- asha->render_delay = get_le16(&value[11]);
+ asha->render_delay = render_delay;
/* byte 13 & 14 are reserved */
/* Codec IDs */
- asha->codec_ids = get_le16(&value[15]);
+ asha->codec_ids = codec_ids;
DBG("Got ROPS: side %u, binaural %u, csis: %u, delay %u, codecs: %u",
asha->right_side, asha->binaural, asha->csis_supported,
asha->render_delay, asha->codec_ids);
check_probe_done(asha);
+
+ return;
+
+invalid:
+ DBG("Reading ROPs failed: unexpected length %u", length);
}
static void audio_status_register(uint16_t att_ecode, void *user_data)
--
2.56.0
next prev parent reply other threads:[~2026-11-11 20:39 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 20:39 [PATCH BlueZ v2 0/5] shared: Use util_iov helpers in gatt-db, hog, asha and micp Luiz Augusto von Dentz
2026-11-11 20:39 ` [PATCH BlueZ v2 1/5] shared/gatt-db: Use util_iov helpers to build and parse values Luiz Augusto von Dentz
2026-11-12 2:09 ` shared: Use util_iov helpers in gatt-db, hog, asha and micp bluez.test.bot
2026-11-11 20:39 ` [PATCH BlueZ v2 2/5] shared/hog: Use util_iov helpers to parse characteristic values Luiz Augusto von Dentz
2026-11-11 20:39 ` Luiz Augusto von Dentz [this message]
2026-11-11 20:39 ` [PATCH BlueZ v2 4/5] shared/micp: Fix reading Mute State from an empty notification Luiz Augusto von Dentz
2026-11-11 20:39 ` [PATCH BlueZ v2 5/5] shared/micp: Use util_iov_pull_mem instead of a local helper Luiz Augusto von Dentz
2026-11-12 17:50 ` [PATCH BlueZ v2 0/5] shared: Use util_iov helpers in gatt-db, hog, asha and micp 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=20261111203949.3874673-4-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