From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796400265; b=MgWa/SxHpgyKg9tGh712XryggbWEGB8PClz4xsQYd8fpNs+hMDMqxO8YJBleYe+Bt2Q2 uit4X6NxzJ7z1zs+HKO/pp4QOqoGHEjvc2v/zVhuiVUmBRlCt3UxYYmYXMZH7ReTD7+zK 0msafezdcaw8XP1Koh8Qz8EO+KpLze/8Y4qbUeAJgnVynsRyw2cSlTQjhcr2Slx0PZWrU rN9rXEL24csh68+8BRxJb/Ft7tan5Om8Dy+oAXmGyJY8nXI3vTjPHfEMtxxwA6I2veohr H8guY3D1GoQ1q3BNmlUPR2KbNhzdFvS4btNShkv9hthRF3uujB/cdpvb4FwG1TEV2Aw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796400265; h=DMARC-Filter:DKIM-Signature:Received:From:To:Subject:Date:Message-ID: X-Mailer:MIME-Version:Content-Type:Content-Type: Content-Transfer-Encoding; bh=q54RJUyi+kLwbJBMC2fvT76JFSP+jY69vKBHxLbVe20=; b=kQmR0qy9W5j7o6zmZX4NZeRFA18Qhf+z/J1mBrKUCd0XXyCJKOwFABDKBU/gpbMki+cN ZVOJYlytly1js8ur5v/0YipU3aDn47TCzynka88ZgQQbGdxXpINoEoMeDEwTnwP+V0aNK poZ/kuQmqo1H7iB2KxSGj1Qgu14gqqcoCoglG47FhhIpVpvwSIuq5j/Vsf3DWerqBzx4Z jtESUpUsh00k/UdJZ+F/wgkeOZ6EwsKh5ma00OuVTebgu3j8ZPg6W3wRH85LcstFxJ429 qonD4x+0oZ+vEGd+btbcAlfWMBexN+20TE5SC+HbWGydZ0cJhPOEl5hwKT7g1NFzUpA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=J3Ynxojr; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C56BC606A32D for ; Fri, 4 Dec 2026 16:04:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C56BC606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=J3Ynxojr DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796400261; bh=KPj9bM2uq+IHJbAxr7aY9GCPfSVc15CUkSgvut7h7dM=; h=From:To:Subject:Date:From; b=J3YnxojrwS/MrgiKalopRRiKqwiT+Tuu2gDAtMN4hGkWBMNnjffzYKhcBsnepEiPC zWFQ2m/0doIZo1p6shB1v0c8MKdvk9vybgDeCnb/4Wgl4VSHwHKP0DP8JAtgI4KpEw +jFpDj5pc9Ft8Q46nx5oRGvFb6MMScOR/ommQJ4EbjmgI3doaO81CED53wVUaZfkcF +pb40e9vfKLsdSfT5rLRpmT20LCHIUBzJ1rtTo/ezLQigAg1nxYqEky8h7P3vTdcvg QAT8zh9l446vaUGQe3gR4oTtvg6lvuj7wZkwsW9wkmQCajOe69fvBgr5rIVkoGJ56w rLxK9PdPbf3iw== Received: from fdanis-ThinkPad-X1.. (unknown [100.64.1.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by bali.collaboradmins.com (Postfix) with ESMTPSA id 4BF3817E054F for ; Fri, 04 Dec 2026 17:04:21 +0100 (CET) From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v8 0/6] monitor: Add an OBEX protocol decoder to btmon Date: Fri, 4 Dec 2026 17:04:10 +0100 Message-ID: <20261204160416.1254097-1-frederic.danis@collabora.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 strips the trailing L2CAP FCS of ERTM/Streaming mode frames, which was passed to the upper layer dissectors as payload. Patch 2 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 3 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 4 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'). Each SDU is decoded from the frame completing it, so the output follows the capture order, while the payload of fragments still being buffered is hexdumped so no bytes are lost from the trace. Patch 5 fixes the RFCOMM frame length and FCS handling. Patch 6 reassembles OBEX PDUs split across several RFCOMM UIH frames. 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. v4->v5: Address review feedback: - Patch 1 (L2CAP FCS): discard a pending requested FCS value when its Config Request is rejected with Unknown Options, so a later unrelated successful Config Response doesn't apply it. - Patch 2 (OBEX protocol decoder): use the processed frame's data/size, not the original pre-FCS-strip/pre-reassembly packet parameters, in the default-PSM hexdump fallback. - Patch 4 (L2CAP SDU reassembly): track the TxSeq of the Start fragment that began the in-progress SDU and compare a new Start fragment against it, so a retransmitted duplicate of that Start fragment doesn't needlessly discard the already-buffered Continuation fragments. - Patch 5 (RFCOMM UIH length/credit handling): bound the payload handed to uih_frame()/mcc_frame() by the UIH frame's own declared hdr.length, so an L2CAP PDU carrying more than one multiplexed RFCOMM frame doesn't leak the next frame's bytes into this frame's payload. - Patch 6 (OBEX PDU reassembly over RFCOMM): hexdump an incomplete, still-buffered PDU's own payload instead of showing nothing, key the reassembly buffer and OBEX session state on the full DLCI instead of just the server channel number, clear every data channel's OBEX state on a DLCI 0 (multiplexer) or RFCOMM L2CAP transport teardown, and bounds-check a chan_list[] index derived from an unresolved CID before dereferencing it. v5->v6: Address review feedback: - Patch 1 (L2CAP FCS): only apply a Config Response's FCS option on a definitively successful result instead of on any response, and extend discarding a pending requested FCS value to any final failure result (not just Unknown Options), leaving it alone while the result is Pending or the response is a non-final fragment. - Patch 2 (OBEX protocol decoder): special-case the SDP Nil type to a zero data length in obex_de_next(), instead of the 1 byte it shares with 8-bit Int/UInt, so scanning a Nil-valued attribute doesn't desync. - Patch 4 (L2CAP SDU reassembly): replace the "only check the immediately preceding TxSeq" duplicate check with a wraparound-aware range check covering every already-received fragment, so a retransmission of an earlier (not just the most recent) fragment doesn't wrongly discard the buffered SDU. - Patch 6 (OBEX PDU reassembly over RFCOMM): track which device sent the DLCI 0 SABM establishing each ACL's RFCOMM multiplexer session, and have obex_channel()/obex_add_channel() skip a channel-number match whose stored role disagrees with the live session's, so a server channel number reused independently by each peer isn't confused between them; add l2cap_remove_handle() to release a handle's chan_list[] entries (and SAR reassembly buffers) on HCI Disconnection Complete without a per-channel L2CAP Disconnection Response. v6->v7: Address review feedback: - Patch 1 (L2CAP FCS): compare the Config Response result against le16_to_cpu(pdu->result) instead of the raw wire value, so a big-endian host no longer misreads e.g. a Pending response as a final failure, and stage a Config Response's own FCS option instead of applying it as soon as a fragment's result reads Success, committing it only once the final fragment's result is known. - Patch 4 (L2CAP SDU reassembly): track the uncapped fragment count received since the Start segment and measure the duplicate/gap check as a window of that size ending at the last received sequence number, instead of a span reduced mod seq_mod, so the check no longer wraps to an ambiguous zero once a full window's worth of fragments has been received. - Patch 6 (OBEX PDU reassembly over RFCOMM): pass the DLCI into rfcomm_local_is_server() and derive the server role from both the mux initiator/responder tracking and the DLCI's direction bit, instead of always treating the mux responder as server. v7->v8: Address review feedback: - Patch 1 (L2CAP FCS): track the FCS option per direction, and discard the staged FCS values once committed or on Unknown Options. - Patch 4 (L2CAP SDU reassembly): rework the reassembly to keep out-of-order fragments, so ERTM retransmissions complete the SDU, decode each SDU from the frame completing it, and bound the fragments kept per direction. - Patch 5 (RFCOMM UIH length/credit handling): read the FCS right after each frame's declared length, and decode all RFCOMM frames carried in the same L2CAP SDU. - Patch 6 (OBEX PDU reassembly over RFCOMM): fix the inverted server role derived from the DLCI direction bit, check the server role of L2CAP PSM mappings too, and keep the SDP mappings across ACL reconnection, matched by peer address. - All patches: trim comments and commit messages. 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 | 995 +++++++++++++++++++++++++++-- monitor/l2cap.h | 4 + monitor/obex.c | 1549 ++++++++++++++++++++++++++++++++++++++++++++++ monitor/obex.h | 123 ++++ monitor/packet.c | 7 +- monitor/rfcomm.c | 340 +++++++++- monitor/sdp.c | 12 +- 8 files changed, 2949 insertions(+), 82 deletions(-) create mode 100644 monitor/obex.c create mode 100644 monitor/obex.h -- 2.43.0