From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 1/4] monitor: Strip trailing L2CAP FCS before upper layer dissectors
Date: Mon, 23 Nov 2026 11:25:45 +0100 [thread overview]
Message-ID: <20261123102548.61362-2-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>
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
next prev 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 ` Frédéric Danis [this message]
2026-11-23 10:25 ` [PATCH BlueZ 2/4] monitor: Add OBEX protocol decoder Frédéric Danis
2026-11-23 10:25 ` [PATCH BlueZ 3/4] monitor: Decode PBAP/MAP/BIP Application Parameters tags Frédéric Danis
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-2-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