Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ v4 0/6] monitor: Add an OBEX protocol decoder to btmon
@ 2026-11-24 14:56 Frédéric Danis
  2026-11-24 14:56 ` [PATCH BlueZ v4 1/6] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
                   ` (5 more replies)
  0 siblings, 6 replies; 12+ messages in thread
From: Frédéric Danis @ 2026-11-24 14:56 UTC (permalink / raw)
  To: linux-bluetooth

btmon currently hexdumps all OBEX traffic (RFCOMM and L2CAP GOEP), making
PBAP/MAP/BIP/OPP sessions hard to follow in a trace. This series adds a
dedicated OBEX dissector (monitor/obex.c) and wires it into the RFCOMM,
L2CAP and SDP monitors.

Patch 1 adds the core decoder: opcodes, response codes, CONNECT/SETPATH
fixed fields, all generic header IDs, BIP's IMG-Handle/IMG-Descriptor
extension headers, and Target/Who UUID recognition for the well known
OBEX profiles.
It tracks sessions on both RFCOMM (learned from SDP
ProtocolDescriptorList) and L2CAP (a dynamically negotiated PSM
learned from the GoepL2capPsm SDP attribute), keyed
direction-independently so CONNECT requests and responses are correctly
matched to the same session.

Patch 2 adds per-profile Application Parameters (Tag/Len/Value) decoding
for PBAP, MAP and BIP, replacing the generic 'Tag 0xNN len N' hexdump with
named, typed values, using the profile learned from each session's
Target/Who header.

Patch 3 adds SDU reassembly for L2CAP ERTM/Streaming mode, since OBEX PDUs
routinely span multiple SAR fragments; without it, any segmented PDU
failed to parse ('frame too short'). Reassembled PDUs are decoded once, on
the End fragment, while raw per-fragment hexdumps are kept for
Start/Continuation fragments so no bytes are lost from the trace.

Sample decode, a PBAP CONNECT followed by a GET with Application
Parameters:

OBEX: Connect (0x00) final 1 len 35
   Version: 1.0
   Flags: 0x00
   Max Packet Length: 8087
   Target: Phonebook Access (PBAP)
   Application Parameters: [len 6]
     Supported Features: 1023 (0x000003ff)
...
OBEX: Get (0x03) final 1 len 87
   Connection ID: 1 (0x00000001)
   Single Response Mode: 1 (0x01)
   Name: telecom/fav.vcf
   Type: x-bt/phonebook
   Application Parameters: [len 21]
     Format: 1 (0x01)
     Max List Count: 65535 (0xffff)
     Filter: 0x0000000018b111af
     List Start Offset: 0 (0x0000)

v1->v2: Fix commit title issue
v2->v3: Address review feedback:
  - Patch 2 (OBEX protocol decoder): fix a possible uint32_t overflow in
    the SDP element-length parsing, fix obex_de_uuid16() extracting the
    short value from the wrong half of a 32-bit UUID, and stop treating
    L2CAP PSM 0x1001 as always running OBEX.
  - Patch 3 (PBAP/MAP/BIP Application Parameters): clear the learned
    profile classification on session/channel/handle teardown and on a
    new CONNECT, so a later session can't inherit a stale profile.
  - Patch 4 (L2CAP SDU reassembly, retitled): track the expected TxSeq
    per direction to discard retransmitted/duplicate fragments and stop
    reassembling past a lost fragment, and fix l2cap_sdu_reassemble()
    reporting success on an End fragment with no buffered Start, which
    could free a borrowed packet buffer.
  - New patch 5: trim the trailing RFCOMM FCS byte from the payload
    handed to upper layer dissectors, and skip credit-only UIH frames.
  - New patch 6: reassemble OBEX PDUs split across several RFCOMM UIH
    frames, since the RFCOMM MTU is typically smaller than the maximum
    OBEX PDU length.
v3->v4: Address review feedback:
  - Patch 1 (L2CAP FCS): apply an FCS value requested by a Config
    Request on a successful, option-free Config Response too.
  - Patch 2 (OBEX protocol decoder): fix the disconnect handler's
    swapped SCID/DCID session resolution, stop obex_remove_channel()
    from dropping the SDP-learned channel mapping so a reconnect on
    the same ACL link doesn't need SDP repeated, validate 128-bit
    UUIDs against the Bluetooth Base UUID before treating them as
    16-bit assigned numbers, recognize OBEX running directly over a
    dedicated L2CAP PSM (e.g. BIP's AVRCP Cover Art), only trust a
    GOEP L2CAP PSM attribute once the record is confirmed to speak
    OBEX, and decode UTF-16 surrogate pairs correctly.
  - Patch 3 (PBAP/MAP/BIP Application Parameters): document why
    obex_remove_channel() keeps the channel mapping, and use a
    channel-zero check consistently to detect free profile slots.
  - Patch 6 (OBEX PDU reassembly over RFCOMM): free a handle's
    reassembly buffers when the ACL link itself is disconnected
    without a per-channel RFCOMM DISC/DM, and widen the reassembly
    length/position tracking to avoid truncating a malformed
    declared length's remaining byte count.

Frédéric Danis (6):
  monitor: Strip trailing L2CAP FCS before upper layer dissectors
  monitor: Add OBEX protocol decoder
  monitor: Decode PBAP/MAP/BIP Application Parameters tags
  monitor: Reassemble L2CAP ERTM/Streaming SDUs
  monitor: Fix RFCOMM UIH frame length and credit-only handling
  monitor: Reassemble OBEX PDUs split across RFCOMM UIH frames

 Makefile.tools   |    1 +
 monitor/l2cap.c  |  389 +++++++++++-
 monitor/l2cap.h  |    2 +
 monitor/obex.c   | 1512 ++++++++++++++++++++++++++++++++++++++++++++++
 monitor/obex.h   |  119 ++++
 monitor/packet.c |    6 +-
 monitor/rfcomm.c |  194 +++++-
 monitor/sdp.c    |   12 +-
 8 files changed, 2203 insertions(+), 32 deletions(-)
 create mode 100644 monitor/obex.c
 create mode 100644 monitor/obex.h

-- 
2.43.0


^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH BlueZ v3 1/6] monitor: Strip trailing L2CAP FCS before upper layer dissectors
@ 2026-11-24  9:22 Frédéric Danis
  2026-11-24 11:38 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
  0 siblings, 1 reply; 12+ messages in thread
From: Frédéric Danis @ 2026-11-24  9:22 UTC (permalink / raw)
  To: linux-bluetooth

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

ERTM/Streaming mode I-frames append a 2-byte FCS after the payload,
which was never stripped before handing the frame to protocol
dissectors (OBEX, RFCOMM, SDP, ...). OBEX's own PDU length enforcement
was masking this as spurious "Trailing data" on every ERTM frame, two
bytes that are actually the L2CAP checksum, not protocol payload.

Track the negotiated FCS option per channel (defaulting to the 16-bit
FCS enabled by the Core Spec unless a peer explicitly negotiates "No
FCS"), and trim the trailing 2 bytes off ERTM/Streaming mode frames
before dispatching to the PSM-specific dissector.

Verified against a real btsnoop capture: the spurious 2-byte "Trailing
data" hexdump after every OBEX PDU on an ERTM channel is gone, while
decode output is otherwise unchanged (109 OBEX PDUs decoded before and
after).

Assisted-by: Claude:claude-sonnet-5
---
 monitor/l2cap.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index ddc2388d5..a1c90af1d 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -100,6 +100,7 @@ struct chan_data {
 	uint8_t  ext_ctrl;
 	uint8_t  seq_num;
 	uint16_t sdu;
+	uint8_t  fcs;
 	struct packet_latency tx_l;
 };
 
@@ -158,6 +159,12 @@ static void assign_scid(const struct l2cap_frame *frame, uint16_t scid,
 	chan_list[n].ctrlid = ctrlid;
 	chan_list[n].mode = mode;
 
+	/* 16-bit FCS is the default for ERTM/Streaming mode unless the
+	 * peer explicitly negotiates "No FCS" via the FCS configuration
+	 * option (see assign_fcs()).
+	 */
+	chan_list[n].fcs = 1;
+
 	chan_list[n].seq_num = seq_num;
 }
 
@@ -255,6 +262,37 @@ static void assign_mode(const struct l2cap_frame *frame,
 	}
 }
 
+/* Record whether the peer negotiated "No FCS" (0x00) or "16-bit FCS"
+ * (0x01) via the FCS configuration option, so the trailing 2-byte FCS
+ * on ERTM/Streaming mode frames can be stripped before handing the
+ * payload to upper layer dissectors.
+ */
+static void assign_fcs(const struct l2cap_frame *frame,
+					uint8_t fcs, uint16_t dcid)
+{
+	int i;
+
+	for (i = 0; i < MAX_CHAN; i++) {
+		if (chan_list[i].index != frame->index)
+			continue;
+
+		if (chan_list[i].handle != frame->handle)
+			continue;
+
+		if (frame->in) {
+			if (chan_list[i].scid == dcid) {
+				chan_list[i].fcs = fcs;
+				break;
+			}
+		} else {
+			if (chan_list[i].dcid == dcid) {
+				chan_list[i].fcs = fcs;
+				break;
+			}
+		}
+	}
+}
+
 static int get_chan_data_index(const struct l2cap_frame *frame)
 {
 	int i;
@@ -882,6 +920,9 @@ static void print_config_options(const struct l2cap_frame *frame,
 					get_le16(data + consumed + 9));
 			break;
 		case 0x05:
+			if (response)
+				assign_fcs(frame, data[consumed + 2], cid);
+
 			switch (data[consumed + 2]) {
 			case 0x00:
 				str = "No FCS";
@@ -2740,6 +2781,16 @@ void l2cap_frame(uint16_t index, bool in, uint16_t handle, uint16_t cid,
 			}
 
 			display_printf("\n");
+
+			/* ERTM/Streaming mode frames carry a trailing 2-byte
+			 * FCS (unless explicitly negotiated off via the FCS
+			 * configuration option) that is not part of the
+			 * upper layer payload.
+			 */
+			chan = get_chan(&frame);
+			if (chan && chan->fcs && frame.size >= 2)
+				frame.size -= 2;
+
 			break;
 		}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH BlueZ v2 1/4] monitor: Strip trailing L2CAP FCS before upper layer dissectors
@ 2026-11-23 14:30 Frédéric Danis
  2026-11-24  2:05 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
  0 siblings, 1 reply; 12+ messages in thread
From: Frédéric Danis @ 2026-11-23 14:30 UTC (permalink / raw)
  To: linux-bluetooth

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

ERTM/Streaming mode I-frames append a 2-byte FCS after the payload,
which was never stripped before handing the frame to protocol
dissectors (OBEX, RFCOMM, SDP, ...). OBEX's own PDU length enforcement
was masking this as spurious "Trailing data" on every ERTM frame, two
bytes that are actually the L2CAP checksum, not protocol payload.

Track the negotiated FCS option per channel (defaulting to the 16-bit
FCS enabled by the Core Spec unless a peer explicitly negotiates "No
FCS"), and trim the trailing 2 bytes off ERTM/Streaming mode frames
before dispatching to the PSM-specific dissector.

Verified against a real btsnoop capture: the spurious 2-byte "Trailing
data" hexdump after every OBEX PDU on an ERTM channel is gone, while
decode output is otherwise unchanged (109 OBEX PDUs decoded before and
after).

Assisted-by: Claude:claude-sonnet-5
---
 monitor/l2cap.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index ddc2388d5..a1c90af1d 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -100,6 +100,7 @@ struct chan_data {
 	uint8_t  ext_ctrl;
 	uint8_t  seq_num;
 	uint16_t sdu;
+	uint8_t  fcs;
 	struct packet_latency tx_l;
 };
 
@@ -158,6 +159,12 @@ static void assign_scid(const struct l2cap_frame *frame, uint16_t scid,
 	chan_list[n].ctrlid = ctrlid;
 	chan_list[n].mode = mode;
 
+	/* 16-bit FCS is the default for ERTM/Streaming mode unless the
+	 * peer explicitly negotiates "No FCS" via the FCS configuration
+	 * option (see assign_fcs()).
+	 */
+	chan_list[n].fcs = 1;
+
 	chan_list[n].seq_num = seq_num;
 }
 
@@ -255,6 +262,37 @@ static void assign_mode(const struct l2cap_frame *frame,
 	}
 }
 
+/* Record whether the peer negotiated "No FCS" (0x00) or "16-bit FCS"
+ * (0x01) via the FCS configuration option, so the trailing 2-byte FCS
+ * on ERTM/Streaming mode frames can be stripped before handing the
+ * payload to upper layer dissectors.
+ */
+static void assign_fcs(const struct l2cap_frame *frame,
+					uint8_t fcs, uint16_t dcid)
+{
+	int i;
+
+	for (i = 0; i < MAX_CHAN; i++) {
+		if (chan_list[i].index != frame->index)
+			continue;
+
+		if (chan_list[i].handle != frame->handle)
+			continue;
+
+		if (frame->in) {
+			if (chan_list[i].scid == dcid) {
+				chan_list[i].fcs = fcs;
+				break;
+			}
+		} else {
+			if (chan_list[i].dcid == dcid) {
+				chan_list[i].fcs = fcs;
+				break;
+			}
+		}
+	}
+}
+
 static int get_chan_data_index(const struct l2cap_frame *frame)
 {
 	int i;
@@ -882,6 +920,9 @@ static void print_config_options(const struct l2cap_frame *frame,
 					get_le16(data + consumed + 9));
 			break;
 		case 0x05:
+			if (response)
+				assign_fcs(frame, data[consumed + 2], cid);
+
 			switch (data[consumed + 2]) {
 			case 0x00:
 				str = "No FCS";
@@ -2740,6 +2781,16 @@ void l2cap_frame(uint16_t index, bool in, uint16_t handle, uint16_t cid,
 			}
 
 			display_printf("\n");
+
+			/* ERTM/Streaming mode frames carry a trailing 2-byte
+			 * FCS (unless explicitly negotiated off via the FCS
+			 * configuration option) that is not part of the
+			 * upper layer payload.
+			 */
+			chan = get_chan(&frame);
+			if (chan && chan->fcs && frame.size >= 2)
+				frame.size -= 2;
+
 			break;
 		}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [PATCH BlueZ 1/4] monitor: Strip trailing L2CAP FCS before upper layer dissectors
@ 2026-11-23 10:25 Frédéric Danis
  2026-11-23 14:15 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
  0 siblings, 1 reply; 12+ messages in thread
From: Frédéric Danis @ 2026-11-23 10:25 UTC (permalink / raw)
  To: linux-bluetooth

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

ERTM/Streaming mode I-frames append a 2-byte FCS after the payload,
which was never stripped before handing the frame to protocol
dissectors (OBEX, RFCOMM, SDP, ...). OBEX's own PDU length enforcement
was masking this as spurious "Trailing data" on every ERTM frame, two
bytes that are actually the L2CAP checksum, not protocol payload.

Track the negotiated FCS option per channel (defaulting to the 16-bit
FCS enabled by the Core Spec unless a peer explicitly negotiates "No
FCS"), and trim the trailing 2 bytes off ERTM/Streaming mode frames
before dispatching to the PSM-specific dissector.

Verified against a real btsnoop capture: the spurious 2-byte "Trailing
data" hexdump after every OBEX PDU on an ERTM channel is gone, while
decode output is otherwise unchanged (109 OBEX PDUs decoded before and
after).

Assisted-by: Claude:claude-sonnet-5
---
 monitor/l2cap.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index ddc2388d5..a1c90af1d 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -100,6 +100,7 @@ struct chan_data {
 	uint8_t  ext_ctrl;
 	uint8_t  seq_num;
 	uint16_t sdu;
+	uint8_t  fcs;
 	struct packet_latency tx_l;
 };
 
@@ -158,6 +159,12 @@ static void assign_scid(const struct l2cap_frame *frame, uint16_t scid,
 	chan_list[n].ctrlid = ctrlid;
 	chan_list[n].mode = mode;
 
+	/* 16-bit FCS is the default for ERTM/Streaming mode unless the
+	 * peer explicitly negotiates "No FCS" via the FCS configuration
+	 * option (see assign_fcs()).
+	 */
+	chan_list[n].fcs = 1;
+
 	chan_list[n].seq_num = seq_num;
 }
 
@@ -255,6 +262,37 @@ static void assign_mode(const struct l2cap_frame *frame,
 	}
 }
 
+/* Record whether the peer negotiated "No FCS" (0x00) or "16-bit FCS"
+ * (0x01) via the FCS configuration option, so the trailing 2-byte FCS
+ * on ERTM/Streaming mode frames can be stripped before handing the
+ * payload to upper layer dissectors.
+ */
+static void assign_fcs(const struct l2cap_frame *frame,
+					uint8_t fcs, uint16_t dcid)
+{
+	int i;
+
+	for (i = 0; i < MAX_CHAN; i++) {
+		if (chan_list[i].index != frame->index)
+			continue;
+
+		if (chan_list[i].handle != frame->handle)
+			continue;
+
+		if (frame->in) {
+			if (chan_list[i].scid == dcid) {
+				chan_list[i].fcs = fcs;
+				break;
+			}
+		} else {
+			if (chan_list[i].dcid == dcid) {
+				chan_list[i].fcs = fcs;
+				break;
+			}
+		}
+	}
+}
+
 static int get_chan_data_index(const struct l2cap_frame *frame)
 {
 	int i;
@@ -882,6 +920,9 @@ static void print_config_options(const struct l2cap_frame *frame,
 					get_le16(data + consumed + 9));
 			break;
 		case 0x05:
+			if (response)
+				assign_fcs(frame, data[consumed + 2], cid);
+
 			switch (data[consumed + 2]) {
 			case 0x00:
 				str = "No FCS";
@@ -2740,6 +2781,16 @@ void l2cap_frame(uint16_t index, bool in, uint16_t handle, uint16_t cid,
 			}
 
 			display_printf("\n");
+
+			/* ERTM/Streaming mode frames carry a trailing 2-byte
+			 * FCS (unless explicitly negotiated off via the FCS
+			 * configuration option) that is not part of the
+			 * upper layer payload.
+			 */
+			chan = get_chan(&frame);
+			if (chan && chan->fcs && frame.size >= 2)
+				frame.size -= 2;
+
 			break;
 		}
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-24 20:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 14:56 [PATCH BlueZ v4 0/6] monitor: Add an OBEX protocol decoder to btmon Frédéric Danis
2026-11-24 14:56 ` [PATCH BlueZ v4 1/6] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
2026-11-24 20:45   ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
2026-11-24 14:56 ` [PATCH BlueZ v4 2/6] monitor: Add OBEX protocol decoder Frédéric Danis
2026-11-24 14:56 ` [PATCH BlueZ v4 3/6] monitor: Decode PBAP/MAP/BIP Application Parameters tags Frédéric Danis
2026-11-24 14:56 ` [PATCH BlueZ v4 4/6] monitor: Reassemble L2CAP ERTM/Streaming SDUs Frédéric Danis
2026-11-24 14:56 ` [PATCH BlueZ v4 5/6] monitor: Fix RFCOMM UIH frame length and credit-only handling Frédéric Danis
2026-11-24 14:56 ` [PATCH BlueZ v4 6/6] monitor: Reassemble OBEX PDUs split across RFCOMM UIH frames Frédéric Danis
  -- strict thread matches above, loose matches on Subject: below --
2026-11-24  9:22 [PATCH BlueZ v3 1/6] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
2026-11-24 11:38 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
2026-11-23 14:30 [PATCH BlueZ v2 1/4] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
2026-11-24  2:05 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
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 14:15 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
2026-11-23 15:00   ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox