From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v6 3/6] monitor: Decode PBAP/MAP/BIP Application Parameters tags
Date: Mon, 30 Nov 2026 10:10:49 +0100 [thread overview]
Message-ID: <20261130091052.383139-4-frederic.danis@collabora.com> (raw)
In-Reply-To: <20261130091052.383139-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.
The matching obex_profile_list entries are cleared from
obex_remove_channel(), obex_remove_session() and
obex_disconnect_handle() whenever a session, channel, or handle goes
away, and on every CONNECT request, so a later session reusing the
same index/handle/channel triplet cannot inherit a profile learned by
an unrelated earlier session.
Assisted-by: Claude:claude-sonnet-5
---
v2->v3:
- Clear the learned profile classification from
obex_remove_channel(), obex_remove_session() and
obex_disconnect_handle() on session/channel/handle teardown, and
also reset it on every CONNECT, so a later session reusing the same
index/handle/channel triplet can't inherit a stale profile from an
unrelated earlier session.
v3->v4:
- Explain in a comment above obex_remove_channel() why the
SDP-learned obex_chan_list mapping itself is kept across RFCOMM
teardown (a reconnect on the same ACL link must still resolve the
channel), and bail out early when called with a zero channel.
- Use a channel-zero check (!channel) instead of an explicit
handle == 0x0000 comparison to detect free obex_profile_list
slots.
monitor/obex.c | 365 +++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 352 insertions(+), 13 deletions(-)
diff --git a/monitor/obex.c b/monitor/obex.c
index b11267e2e..e024f4109 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;
@@ -202,17 +214,59 @@ static void obex_clear_request(uint16_t index, uint16_t handle,
}
}
+/* 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_clear_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].index == index &&
+ obex_profile_list[i].handle == handle &&
+ obex_profile_list[i].channel == channel)
+ memset(&obex_profile_list[i], 0,
+ sizeof(obex_profile_list[i]));
+ }
+}
+
+/* The RFCOMM channel is being torn down (DISC/DM), but the SDP-learned
+ * service-to-channel mapping in obex_chan_list is kept: a peer can
+ * reopen the same RFCOMM service on the still-up ACL link without
+ * repeating SDP, and obex_channel() needs the mapping to still resolve
+ * for that reconnection. Only the per-session request/profile state is
+ * cleared here; the mapping itself is only dropped by a later SDP
+ * update (via obex_add_channel()) or when the ACL handle disconnects
+ * (obex_disconnect_handle()).
+ */
void obex_remove_channel(uint16_t index, uint16_t handle, uint8_t channel)
{
if (!channel)
return;
obex_clear_request(index, handle, channel);
+ obex_clear_profile(index, handle, channel);
}
void obex_remove_session(uint16_t index, uint16_t handle, uint16_t channel)
{
obex_clear_request(index, handle, channel);
+ obex_clear_profile(index, handle, channel);
}
void obex_disconnect_handle(uint16_t index, uint16_t handle)
@@ -244,6 +298,16 @@ void obex_disconnect_handle(uint16_t index, uint16_t handle)
memset(&obex_psm_list[i], 0,
sizeof(obex_psm_list[i]));
}
+
+ for (i = 0; i < MAX_OBEX_PROFILE; i++) {
+ if (!obex_profile_list[i].channel)
+ continue;
+
+ if (obex_profile_list[i].index == index &&
+ obex_profile_list[i].handle == handle)
+ memset(&obex_profile_list[i], 0,
+ sizeof(obex_profile_list[i]));
+ }
}
static void obex_set_last_request(uint16_t index, uint16_t handle,
@@ -291,6 +355,52 @@ static bool obex_last_request_is(uint16_t index, uint16_t handle,
return false;
}
+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].channel && 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
@@ -792,24 +902,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 },
{ }
};
@@ -828,6 +945,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)
{
@@ -889,8 +1022,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;
@@ -903,15 +1228,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;
@@ -952,6 +1277,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);
@@ -972,7 +1301,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);
}
@@ -1093,6 +1425,13 @@ void obex_packet(const struct l2cap_frame *frame, uint16_t channel)
(opcode & OBEX_FINAL_BIT) ? 1 : 0, length);
if (is_request && code == OBEX_OP_CONNECT) {
+ /* A new CONNECT drops any profile classification learned
+ * from a previous session reusing this index/handle/channel
+ * key, in case this CONNECT's Target/Who header (if any)
+ * doesn't repeat it.
+ */
+ obex_clear_profile(frame->index, frame->handle, channel);
+
if (!obex_connect_fields(f, indent))
goto fail;
} else if (!is_request && obex_last_request_is(frame->index,
@@ -1105,7 +1444,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
next prev parent reply other threads:[~2026-11-30 9:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 9:10 [PATCH BlueZ v6 0/6] monitor: Add an OBEX protocol decoder to btmon Frédéric Danis
2026-11-30 9:10 ` [PATCH BlueZ v6 1/6] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
2026-11-30 10:44 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
2026-12-01 15:52 ` Luiz Augusto von Dentz
2026-11-30 9:10 ` [PATCH BlueZ v6 2/6] monitor: Add OBEX protocol decoder Frédéric Danis
2026-11-30 9:10 ` Frédéric Danis [this message]
2026-11-30 9:10 ` [PATCH BlueZ v6 4/6] monitor: Reassemble L2CAP ERTM/Streaming SDUs Frédéric Danis
2026-11-30 9:10 ` [PATCH BlueZ v6 5/6] monitor: Fix RFCOMM UIH frame length and credit-only handling Frédéric Danis
2026-11-30 9:10 ` [PATCH BlueZ v6 6/6] monitor: Reassemble OBEX PDUs split across RFCOMM UIH frames 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=20261130091052.383139-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.