From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v8 5/6] monitor: Fix RFCOMM UIH frame length and credit-only handling
Date: Fri, 4 Dec 2026 17:04:15 +0100 [thread overview]
Message-ID: <20261204160416.1254097-6-frederic.danis@collabora.com> (raw)
In-Reply-To: <20261204160416.1254097-1-frederic.danis@collabora.com>
The RFCOMM FCS byte was read but left in the payload passed to
uih_frame()/mcc_frame(); remove it, and adjust the mcc_test() and
mcc_msc() size checks which accounted for it.
Bound the payload of each RFCOMM frame by its declared length (plus the
credit octet), read its FCS right after it, and decode the following
RFCOMM frames carried in the same L2CAP SDU, instead of treating them as
part of the payload of the first one.
Don't pass credit-only UIH frames, which have no payload, to the OBEX
decoder.
Assisted-by: Claude:claude-sonnet-5
Assisted-by: Claude:claude-opus-5-5
---
v2->v3: New in v3.
v4->v5:
- Bound rfcomm_packet()'s payload by the UIH frame's own declared
hdr.length (plus the leading credit octet, when present), instead
of handing uih_frame()/mcc_frame() the whole remaining L2CAP PDU,
so an L2CAP PDU carrying more than one multiplexed RFCOMM frame
doesn't leak the next frame's bytes into this frame's payload.
v7->v8:
- Read the FCS right after the frame's declared length instead of
from the last byte of the L2CAP SDU, and decode all RFCOMM frames
carried in the same L2CAP SDU.
- Adjust the mcc_test() and mcc_msc() size checks, which still
accounted for the FCS byte.
- Trim commit message.
monitor/rfcomm.c | 63 ++++++++++++++++++++++++++++++++++++++----------
1 file changed, 50 insertions(+), 13 deletions(-)
diff --git a/monitor/rfcomm.c b/monitor/rfcomm.c
index 747c771fa..ca5deeba2 100644
--- a/monitor/rfcomm.c
+++ b/monitor/rfcomm.c
@@ -142,7 +142,7 @@ static inline bool mcc_test(struct rfcomm_frame *rfcomm_frame, uint8_t indent)
display_printf("%*cTest Data: 0x ", indent, ' ');
- while (frame->size > 1) {
+ while (frame->size > 0) {
if (!l2cap_frame_get_u8(frame, &data))
return false;
display_printf("%2.2x ", data);
@@ -171,7 +171,7 @@ static inline bool mcc_msc(struct rfcomm_frame *rfcomm_frame, uint8_t indent)
GET_V24_RTR(msc.v24_sig), GET_V24_IC(msc.v24_sig),
GET_V24_DV(msc.v24_sig));
- if (frame->size < 2)
+ if (frame->size < 1)
goto done;
/*
@@ -404,6 +404,9 @@ static bool uih_frame(struct rfcomm_frame *rfcomm_frame, uint8_t indent)
print_field("%*cCredits: %d", indent, ' ', hdr->credits);
}
+ if (!frame->size)
+ return true;
+
if (obex_channel(frame->index, frame->handle, channel, NULL))
obex_packet(frame, channel, frame->size);
else
@@ -426,14 +429,17 @@ static const struct rfcomm_data rfcomm_table[] = {
{ }
};
-void rfcomm_packet(const struct l2cap_frame *frame)
+/* Decode the RFCOMM frame at the start of frame and return its size */
+static uint16_t rfcomm_frame_packet(const struct l2cap_frame *frame)
{
uint8_t ctype, length, ex_length, indent = 1;
const char *frame_str, *frame_color;
- struct l2cap_frame *l2cap_frame, tmp_frame;
+ struct l2cap_frame *l2cap_frame;
struct rfcomm_frame rfcomm_frame;
struct rfcomm_lhdr hdr;
const struct rfcomm_data *rfcomm_data = NULL;
+ uint32_t max_size, hdr_len;
+ uint16_t consumed;
int i;
l2cap_frame_pull(&rfcomm_frame.l2cap_frame, frame, 0);
@@ -462,14 +468,29 @@ void rfcomm_packet(const struct l2cap_frame *frame)
if (!l2cap_frame->size)
goto fail;
- l2cap_frame_pull(&tmp_frame, l2cap_frame, l2cap_frame->size-1);
-
- if (!l2cap_frame_get_u8(&tmp_frame, &hdr.fcs))
- goto fail;
+ hdr_len = frame->size - l2cap_frame->size;
/* Decoding frame type */
ctype = RFCOMM_GET_TYPE(hdr.control);
+ /* Credit octet */
+ if (ctype == 0xef && GET_PF(hdr.control))
+ max_size = (uint32_t) hdr.length + 1;
+ else
+ max_size = hdr.length;
+
+ /* An L2CAP SDU may carry several RFCOMM frames */
+ if (hdr_len + max_size + 1 <= frame->size) {
+ hdr.fcs = ((const uint8_t *) l2cap_frame->data)[max_size];
+ l2cap_frame->size = max_size;
+ consumed = hdr_len + max_size + 1;
+ } else {
+ hdr.fcs = ((const uint8_t *) l2cap_frame->data)
+ [l2cap_frame->size - 1];
+ l2cap_frame->size -= 1;
+ consumed = frame->size;
+ }
+
for (i = 0; rfcomm_table[i].str; i++) {
if (rfcomm_table[i].frame == ctype) {
rfcomm_data = &rfcomm_table[i];
@@ -489,8 +510,8 @@ void rfcomm_packet(const struct l2cap_frame *frame)
}
if (!rfcomm_data) {
- packet_hexdump(frame->data, frame->size);
- return;
+ packet_hexdump(frame->data, consumed);
+ return consumed;
}
print_indent(6, frame_color, "RFCOMM: ", frame_str, COLOR_OFF,
@@ -502,16 +523,32 @@ void rfcomm_packet(const struct l2cap_frame *frame)
/* UIH frame */
if (ctype == 0xef) {
if (!uih_frame(&rfcomm_frame, indent))
- goto fail;
+ goto fail_frame;
} else if (ctype == 0x43 || ctype == 0x0f) {
obex_remove_channel(frame->index, frame->handle,
RFCOMM_GET_CHANNEL(hdr.address));
}
- return;
+ return consumed;
+
+fail_frame:
+ print_text(COLOR_ERROR, "Frame too short");
+ packet_hexdump(frame->data, consumed);
+ return consumed;
fail:
print_text(COLOR_ERROR, "Frame too short");
packet_hexdump(frame->data, frame->size);
- return;
+ return frame->size;
+}
+
+void rfcomm_packet(const struct l2cap_frame *frame)
+{
+ struct l2cap_frame rfcomm;
+
+ l2cap_frame_pull(&rfcomm, frame, 0);
+
+ while (rfcomm.size)
+ l2cap_frame_pull(&rfcomm, &rfcomm,
+ rfcomm_frame_packet(&rfcomm));
}
--
2.43.0
next prev parent reply other threads:[~2026-12-04 16:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 16:04 [PATCH BlueZ v8 0/6] monitor: Add an OBEX protocol decoder to btmon Frédéric Danis
2026-12-04 16:04 ` [PATCH BlueZ v8 1/6] monitor: Strip trailing L2CAP FCS before upper layer dissectors Frédéric Danis
2026-12-04 17:12 ` monitor: Add an OBEX protocol decoder to btmon bluez.test.bot
2026-12-04 16:04 ` [PATCH BlueZ v8 2/6] monitor: Add OBEX protocol decoder Frédéric Danis
2026-12-04 16:04 ` [PATCH BlueZ v8 3/6] monitor: Decode PBAP/MAP/BIP Application Parameters tags Frédéric Danis
2026-12-04 16:04 ` [PATCH BlueZ v8 4/6] monitor: Reassemble L2CAP ERTM/Streaming SDUs Frédéric Danis
2026-12-04 16:04 ` Frédéric Danis [this message]
2026-12-04 16:04 ` [PATCH BlueZ v8 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=20261204160416.1254097-6-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