Linux bluetooth development
 help / color / mirror / Atom feed
From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 3/4] monitor: Decode PBAP/MAP/BIP Application Parameters tags
Date: Mon, 23 Nov 2026 11:25:47 +0100	[thread overview]
Message-ID: <20261123102548.61362-4-frederic.danis@collabora.com> (raw)
In-Reply-To: <20261123102548.61362-1-frederic.danis@collabora.com>

From: Frédéric Danis <frederic.danis.oss@gmail.com>

Application Parameters (Tag/Len/Value) were only shown generically
as 'Tag 0xNN len N' plus a hexdump, with no knowledge of what each
tag means. Add per-profile tag tables (name + value type) for PBAP,
MAP and BIP, sourced from their respective specifications, and decode
known tag values as numbers/strings instead of a raw hexdump.

Since Application Parameters headers don't repeat which profile a
session belongs to, remember the profile classification learned from
a session's CONNECT Target/Who header (already decoded by the
existing Target/Who profile lookup) in a small per-session table,
keyed the same way as the existing last-request tracking. Sessions
with no recognized Target/Who (or none yet seen) keep today's
generic Tag/Len/Value dump.

Assisted-by: Claude:claude-sonnet-5
---
 monitor/obex.c | 323 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 310 insertions(+), 13 deletions(-)

diff --git a/monitor/obex.c b/monitor/obex.c
index c1ac76937..873e3b538 100644
--- a/monitor/obex.c
+++ b/monitor/obex.c
@@ -45,6 +45,18 @@
 #define MAX_OBEX_CHAN 64
 #define MAX_OBEX_REQ  32
 
+/* Profiles with a known Application Parameters tag set, used to
+ * select the right tag table when decoding the Application Parameters
+ * header. OBEX_PROFILE_UNKNOWN falls back to a generic Tag/Len/Value
+ * dump.
+ */
+enum obex_profile {
+	OBEX_PROFILE_UNKNOWN,
+	OBEX_PROFILE_PBAP,
+	OBEX_PROFILE_MAP,
+	OBEX_PROFILE_BIP,
+};
+
 struct obex_chan_data {
 	uint16_t index;
 	uint16_t handle;
@@ -303,6 +315,69 @@ static bool obex_last_request_is(uint16_t index, uint16_t handle,
 	return false;
 }
 
+/* Profile classification (PBAP/MAP/BIP/unknown) of an ongoing OBEX
+ * session, learned from a CONNECT's Target/Who header and remembered
+ * per session so that later Application Parameters headers (which
+ * don't repeat the Target/Who UUID) can be decoded using the right
+ * profile-specific tag table.
+ */
+#define MAX_OBEX_PROFILE 32
+
+struct obex_profile_data {
+	uint16_t index;
+	uint16_t handle;
+	uint16_t channel;
+	enum obex_profile profile;
+};
+
+static struct obex_profile_data obex_profile_list[MAX_OBEX_PROFILE];
+
+static void obex_set_profile(uint16_t index, uint16_t handle,
+					uint16_t channel,
+					enum obex_profile profile)
+{
+	int i, n = -1;
+
+	for (i = 0; i < MAX_OBEX_PROFILE; i++) {
+		if (obex_profile_list[i].handle == 0x0000 && n < 0) {
+			n = i;
+			continue;
+		}
+
+		if (obex_profile_list[i].index == index &&
+				obex_profile_list[i].handle == handle &&
+				obex_profile_list[i].channel == channel) {
+			n = i;
+			break;
+		}
+	}
+
+	if (n < 0)
+		return;
+
+	obex_profile_list[n].index = index;
+	obex_profile_list[n].handle = handle;
+	obex_profile_list[n].channel = channel;
+	obex_profile_list[n].profile = profile;
+}
+
+static enum obex_profile obex_get_profile(uint16_t index, uint16_t handle,
+							uint16_t channel)
+{
+	int i;
+
+	for (i = 0; i < MAX_OBEX_PROFILE; i++) {
+		if (obex_profile_list[i].handle != handle ||
+				obex_profile_list[i].index != index ||
+				obex_profile_list[i].channel != channel)
+			continue;
+
+		return obex_profile_list[i].profile;
+	}
+
+	return OBEX_PROFILE_UNKNOWN;
+}
+
 /*
  * Minimal SDP Data Element reader, mirroring monitor/sdp.c's
  * decode_data_elements() size/type decoding, but returning the decoded
@@ -739,24 +814,31 @@ static const struct {
 	const uint8_t uuid[16];
 	uint8_t len;
 	const char *str;
+	enum obex_profile profile;
 } obex_target_table[] = {
 	{ { 0x79, 0x61, 0x35, 0xf0, 0xf0, 0xc5, 0x11, 0xd8,
 	    0x09, 0x66, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 }, 16,
-					"Phonebook Access (PBAP)" },
+					"Phonebook Access (PBAP)",
+					OBEX_PROFILE_PBAP },
 	{ { 0xf9, 0xec, 0x7b, 0xc4, 0x95, 0x3c, 0x11, 0xd2,
 	    0x98, 0x4e, 0x52, 0x54, 0x00, 0xdc, 0x9e, 0x09 }, 16,
-					"File Transfer (FTP)" },
+					"File Transfer (FTP)",
+					OBEX_PROFILE_UNKNOWN },
 	{ { 0xbb, 0x58, 0x2b, 0x40, 0x42, 0x0c, 0x11, 0xdb,
 	    0xb0, 0xde, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 }, 16,
-					"Message Access (MAP)" },
+					"Message Access (MAP)",
+					OBEX_PROFILE_MAP },
 	{ { 0xbb, 0x58, 0x2b, 0x41, 0x42, 0x0c, 0x11, 0xdb,
 	    0xb0, 0xde, 0x08, 0x00, 0x20, 0x0c, 0x9a, 0x66 }, 16,
-					"Message Notification (MNS)" },
+					"Message Notification (MNS)",
+					OBEX_PROFILE_MAP },
 	{ { 0x71, 0x63, 0xdd, 0x54, 0x4a, 0x7e, 0x11, 0xe2,
 	    0xb4, 0x7c, 0x00, 0x50, 0xc2, 0x49, 0x00, 0x48 }, 16,
-				"Basic Imaging (BIP, AVRCP Cover Art)" },
+				"Basic Imaging (BIP, AVRCP Cover Art)",
+					OBEX_PROFILE_BIP },
 	{ { 'I', 'R', 'M', 'C', '-', 'S', 'Y', 'N', 'C' }, 9,
-					"Synchronization (IrMC/SyncML)" },
+					"Synchronization (IrMC/SyncML)",
+					OBEX_PROFILE_UNKNOWN },
 	{ }
 };
 
@@ -775,6 +857,22 @@ static const char *obex_target_str(const uint8_t *data, uint16_t len)
 	return NULL;
 }
 
+static enum obex_profile obex_target_profile(const uint8_t *data,
+							uint16_t len)
+{
+	int i;
+
+	for (i = 0; obex_target_table[i].len; i++) {
+		if (obex_target_table[i].len != len)
+			continue;
+
+		if (!memcmp(obex_target_table[i].uuid, data, len))
+			return obex_target_table[i].profile;
+	}
+
+	return OBEX_PROFILE_UNKNOWN;
+}
+
 static void print_unicode_header(const char *label, const uint8_t *data,
 						uint16_t len, uint8_t indent)
 {
@@ -805,8 +903,200 @@ static void print_unicode_header(const char *label, const uint8_t *data,
 	print_field("%*c%s: %s", indent, ' ', label, buf);
 }
 
+/* Application Parameters (Tag/Len/Value) tag tables for profiles whose
+ * tag assignments are known. Tag IDs and names are taken from the
+ * PBAP/MAP/BIP specifications; types indicate how to decode a tag's
+ * value when its length matches what the spec defines for it.
+ */
+enum obex_aparam_type {
+	OBEX_APARAM_U8,
+	OBEX_APARAM_U16,
+	OBEX_APARAM_U32,
+	OBEX_APARAM_U64,
+	OBEX_APARAM_U128,
+	OBEX_APARAM_STR,
+	OBEX_APARAM_BYTES,
+};
+
+struct obex_aparam_tag {
+	uint8_t tag;
+	const char *str;
+	enum obex_aparam_type type;
+};
+
+static const struct obex_aparam_tag obex_pbap_aparam_table[] = {
+	{ 0x01, "Order",			OBEX_APARAM_U8	},
+	{ 0x02, "Search Value",			OBEX_APARAM_STR	},
+	{ 0x03, "Search Attribute",		OBEX_APARAM_U8	},
+	{ 0x04, "Max List Count",		OBEX_APARAM_U16	},
+	{ 0x05, "List Start Offset",		OBEX_APARAM_U16	},
+	{ 0x06, "Filter",			OBEX_APARAM_U64	},
+	{ 0x07, "Format",			OBEX_APARAM_U8	},
+	{ 0x08, "Phonebook Size",		OBEX_APARAM_U16	},
+	{ 0x09, "New Missed Calls",		OBEX_APARAM_U8	},
+	{ 0x0a, "Primary Folder Version",	OBEX_APARAM_U128 },
+	{ 0x0b, "Secondary Folder Version",	OBEX_APARAM_U128 },
+	{ 0x0c, "vCard Selector",		OBEX_APARAM_U64	},
+	{ 0x0d, "Database Identifier",		OBEX_APARAM_U128 },
+	{ 0x0e, "vCard Selector Operator",	OBEX_APARAM_U8	},
+	{ 0x0f, "Reset New Missed Calls",	OBEX_APARAM_U8	},
+	{ 0x10, "Supported Features",		OBEX_APARAM_U32	},
+	{ }
+};
+
+static const struct obex_aparam_tag obex_map_aparam_table[] = {
+	{ 0x01, "Max List Count",			OBEX_APARAM_U16	},
+	{ 0x02, "List Start Offset",			OBEX_APARAM_U16	},
+	{ 0x03, "Filter Message Type",			OBEX_APARAM_U8	},
+	{ 0x04, "Filter Period Begin",			OBEX_APARAM_STR	},
+	{ 0x05, "Filter Period End",			OBEX_APARAM_STR	},
+	{ 0x06, "Filter Read Status",			OBEX_APARAM_U8	},
+	{ 0x07, "Filter Recipient",			OBEX_APARAM_STR	},
+	{ 0x08, "Filter Originator",			OBEX_APARAM_STR	},
+	{ 0x09, "Filter Priority",			OBEX_APARAM_U8	},
+	{ 0x0a, "Attachment",				OBEX_APARAM_U8	},
+	{ 0x0b, "Transparent",				OBEX_APARAM_U8	},
+	{ 0x0c, "Retry",				OBEX_APARAM_U8	},
+	{ 0x0d, "New Message",				OBEX_APARAM_U8	},
+	{ 0x0e, "Notification Status",			OBEX_APARAM_U8	},
+	{ 0x0f, "MAS Instance ID",			OBEX_APARAM_U8	},
+	{ 0x10, "Parameter Mask",			OBEX_APARAM_U32	},
+	{ 0x11, "Folder Listing Size",			OBEX_APARAM_U16	},
+	{ 0x12, "Listing Size",				OBEX_APARAM_U16	},
+	{ 0x13, "Subject Length",			OBEX_APARAM_U8	},
+	{ 0x14, "Charset",				OBEX_APARAM_U8	},
+	{ 0x15, "Fraction Request",			OBEX_APARAM_U8	},
+	{ 0x16, "Fraction Deliver",			OBEX_APARAM_U8	},
+	{ 0x17, "Status Indicator",			OBEX_APARAM_U8	},
+	{ 0x18, "Status Value",				OBEX_APARAM_U8	},
+	{ 0x19, "MSE Time",				OBEX_APARAM_STR	},
+	{ 0x1a, "Database Identifier",			OBEX_APARAM_BYTES },
+	{ 0x1b, "Conversation Listing Version Counter", OBEX_APARAM_BYTES },
+	{ 0x1c, "Presence Availability",		OBEX_APARAM_U8	},
+	{ 0x1d, "Presence Text",			OBEX_APARAM_STR	},
+	{ 0x1e, "Last Activity",			OBEX_APARAM_STR	},
+	{ 0x1f, "Filter Last Activity Begin",		OBEX_APARAM_STR	},
+	{ 0x20, "Filter Last Activity End",		OBEX_APARAM_STR	},
+	{ 0x21, "Chat State",				OBEX_APARAM_U8	},
+	{ 0x22, "Conversation ID",			OBEX_APARAM_BYTES },
+	{ 0x23, "Folder Version Counter",		OBEX_APARAM_BYTES },
+	{ 0x24, "Filter Message Handle",		OBEX_APARAM_STR	},
+	{ 0x25, "Notification Filter Mask",		OBEX_APARAM_U32	},
+	{ 0x26, "Conversation Parameter Mask",		OBEX_APARAM_U32	},
+	{ 0x27, "Filter Message Source Type",		OBEX_APARAM_U8	},
+	{ 0x29, "MAP Supported Features",		OBEX_APARAM_U32	},
+	{ }
+};
+
+static const struct obex_aparam_tag obex_bip_aparam_table[] = {
+	{ 0x01, "Number of Returned Handles",	OBEX_APARAM_U16	},
+	{ 0x02, "List Start Offset",		OBEX_APARAM_U16	},
+	{ 0x03, "Latest Captured Images",	OBEX_APARAM_U8	},
+	{ 0x04, "Partial File Length",		OBEX_APARAM_U32	},
+	{ 0x05, "Partial File Start Offset",	OBEX_APARAM_U32	},
+	{ 0x06, "Total File Size",		OBEX_APARAM_U32	},
+	{ 0x07, "End Flag",			OBEX_APARAM_U8	},
+	{ 0x08, "Remote Display",		OBEX_APARAM_U8	},
+	{ }
+};
+
+static void obex_print_apparam_tag(enum obex_profile profile, uint8_t tag,
+				const uint8_t *data, uint8_t len,
+				uint8_t indent)
+{
+	const struct obex_aparam_tag *table;
+	int i;
+
+	switch (profile) {
+	case OBEX_PROFILE_PBAP:
+		table = obex_pbap_aparam_table;
+		break;
+	case OBEX_PROFILE_MAP:
+		table = obex_map_aparam_table;
+		break;
+	case OBEX_PROFILE_BIP:
+		table = obex_bip_aparam_table;
+		break;
+	case OBEX_PROFILE_UNKNOWN:
+	default:
+		table = NULL;
+		break;
+	}
+
+	for (i = 0; table && table[i].str; i++) {
+		if (table[i].tag != tag)
+			continue;
+
+		switch (table[i].type) {
+		case OBEX_APARAM_U8:
+			if (len == 1) {
+				print_field("%*c%s: %d (0x%02x)", indent, ' ',
+						table[i].str, data[0],
+						data[0]);
+				return;
+			}
+			break;
+		case OBEX_APARAM_U16:
+			if (len == 2) {
+				uint16_t val = get_be16(data);
+
+				print_field("%*c%s: %u (0x%04x)", indent, ' ',
+						table[i].str, val, val);
+				return;
+			}
+			break;
+		case OBEX_APARAM_U32:
+			if (len == 4) {
+				uint32_t val = get_be32(data);
+
+				print_field("%*c%s: %u (0x%08x)", indent, ' ',
+						table[i].str, val, val);
+				return;
+			}
+			break;
+		case OBEX_APARAM_U64:
+			if (len == 8) {
+				print_field("%*c%s: 0x%016" PRIx64, indent,
+						' ', table[i].str,
+						get_be64(data));
+				return;
+			}
+			break;
+		case OBEX_APARAM_U128:
+			if (len == 16) {
+				print_field("%*c%s: 0x%016" PRIx64 "%016"
+						PRIx64, indent, ' ',
+						table[i].str, get_be64(data),
+						get_be64(data + 8));
+				return;
+			}
+			break;
+		case OBEX_APARAM_STR:
+			print_field("%*c%s: %.*s", indent, ' ', table[i].str,
+							len, data);
+			return;
+		case OBEX_APARAM_BYTES:
+			break;
+		}
+
+		/* Known tag but unexpected length (or a raw-bytes type):
+		 * still show the tag's name, with a length + hexdump
+		 * instead of a decoded value.
+		 */
+		print_field("%*c%s: [len %d]", indent, ' ', table[i].str,
+									len);
+		if (len)
+			packet_hexdump(data, len);
+		return;
+	}
+
+	print_field("%*cTag 0x%02x len %d", indent, ' ', tag, len);
+	if (len)
+		packet_hexdump(data, len);
+}
+
 static void obex_print_apparam(const uint8_t *data, uint16_t size,
-								uint8_t indent)
+				uint8_t indent, enum obex_profile profile)
 {
 	uint16_t pos = 0;
 
@@ -819,15 +1109,15 @@ static void obex_print_apparam(const uint8_t *data, uint16_t size,
 			break;
 		}
 
-		print_field("%*cTag 0x%02x len %d", indent, ' ', tag, len);
-		if (len)
-			packet_hexdump(data + pos + 2, len);
+		obex_print_apparam_tag(profile, tag, data + pos + 2, len,
+								indent);
 
 		pos += 2 + len;
 	}
 }
 
-static bool obex_print_headers(struct l2cap_frame *frame, uint8_t indent)
+static bool obex_print_headers(struct l2cap_frame *frame, uint8_t indent,
+							uint16_t channel)
 {
 	while (frame->size > 0) {
 		uint8_t hdr_id;
@@ -868,6 +1158,10 @@ static bool obex_print_headers(struct l2cap_frame *frame, uint8_t indent)
 				if (profile) {
 					print_field("%*c%s: %s", indent, ' ',
 							label, profile);
+					obex_set_profile(frame->index,
+						frame->handle, channel,
+						obex_target_profile(data,
+								vlen));
 				} else {
 					print_field("%*c%s: [len %d]", indent,
 							' ', label, vlen);
@@ -888,7 +1182,10 @@ static bool obex_print_headers(struct l2cap_frame *frame, uint8_t indent)
 
 				if (hdr_id == OBEX_HDR_APPARAM)
 					obex_print_apparam(data, vlen,
-								indent + 2);
+						indent + 2,
+						obex_get_profile(frame->index,
+							frame->handle,
+							channel));
 				else if (vlen)
 					packet_hexdump(data, vlen);
 			}
@@ -1021,7 +1318,7 @@ void obex_packet(const struct l2cap_frame *frame, uint16_t channel)
 			goto fail;
 	}
 
-	if (!obex_print_headers(f, indent))
+	if (!obex_print_headers(f, indent, channel))
 		goto fail;
 
 	if (is_request)
-- 
2.43.0


  parent reply	other threads:[~2026-11-23 10:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23 10:25 [PATCH BlueZ 0/4] monitor: Add an OBEX protocol decoder to btmon Frédéric Danis
2026-11-23 10:25 ` [PATCH BlueZ 1/4] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
2026-11-23 10:25 ` [PATCH BlueZ 2/4] monitor: Add OBEX protocol decoder Frédéric Danis
2026-11-23 10:25 ` Frédéric Danis [this message]
2026-11-23 10:25 ` [PATCH BlueZ 4/4] monitor: Reassemble L2CAP ERTM/Streaming SAR fragments before dissecting Frédéric Danis

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=20261123102548.61362-4-frederic.danis@collabora.com \
    --to=frederic.danis@collabora.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