Skip to content

J1939SoftSocket: expand edge-case unit tests, soft↔native interop coverage, and pgn filter#33

Draft
Copilot wants to merge 4 commits into
masterfrom
copilot/add-j1939-softsocket-class
Draft

J1939SoftSocket: expand edge-case unit tests, soft↔native interop coverage, and pgn filter#33
Copilot wants to merge 4 commits into
masterfrom
copilot/add-j1939-softsocket-class

Conversation

Copy link
Copy Markdown

Copilot AI commented May 14, 2026

Extends the J1939SoftSocket test suite with boundary/error edge cases and richer interoperability scenarios against NativeJ1939Socket. Also incorporates a pgn filter parameter inspired by BenGardiner's rx_pgn from PR #4961.

New feature: pgn filter parameter

Adds a pgn keyword argument to both J1939TPImplementation and J1939SoftSocket (default 0 = accept all PGNs). When set to a non-zero value, only messages whose PGN matches are delivered — covering single-frame, BAM, and RTS/CTS sessions. Inspired by BenGardiner's rx_pgn parameter.

Edge-case unit tests (TestSocket, no root)

  • Single-frame boundary – 8-byte payload goes as one CAN frame; no TP.CM emitted
  • TP boundary – 9-byte payload triggers BAM with exactly 2 DT frames; 14-byte payload fills both DT fields with no padding
  • Session overwrite – new BAM from same peer resets an incomplete in-progress session
  • Wrong-SA filtering – TP.DT frames from a different SA than the BAM initiator are dropped; correct-SA DT still accepted
  • Priority preservationJ1939.priority (0/3/6/7) maps 1-to-1 to the CAN ID priority bits on the wire
  • data_page=1 PGN – PGNs > 0xFFFF (e.g. 0x1FECA) encoded in BAM payload pgn field; TP.CM CAN ID keeps data_page=0 per spec
  • Sequential messages – three back-to-back messages (mix of single-frame and BAM) delivered in order through one socket
  • CTS holdCTS(num_packets=0) pauses sender; no DT emitted until a releasing CTS(count>0) arrives
  • TX timeout – after T3 (1.25 s) without CTS the TX state machine resets to IDLE and accepts new messages
  • 255-byte BAM – 37 TP.DT frames encoded and reassembled end-to-end
  • Large RTS/CTS (49 bytes) – full 7-DT unicast session between two soft sockets
  • Loopback suppression – frames carrying own SA are silently discarded
  • recv() after close – returns None, does not raise
  • pgn filter – matching PGN delivered; non-matching single-frame and BAM silently dropped; pgn=0 accepts all PGNs

Interoperability tests (vcan, needs_root)

  • PDU1 unicast short frame – soft→native and native→soft, both sides bound to specific SAs; dst field verified
  • RTS/CTS unicast (20 bytes) soft→native – kernel J1939 stack completes the handshake and delivers one reassembled message
  • Large BAM (100 bytes) in both directions – soft socket reassembles 15 DT frames from kernel; kernel reassembles 15 DT frames from soft socket
  • CAN-level priority verification – two frames sent at priorities 3 and 6; confirmed in CAN ID via NativeCANSocket(basecls=J1939_CAN)
  • Concurrent ping-pong – soft and native sockets exchange 3 messages simultaneously in both directions; payload and source address verified on both ends

Copilot AI and others added 2 commits May 1, 2026 05:25
@polybassa
Copy link
Copy Markdown
Owner

@copilot Analyze the J1939 SoftSocket implementation from BenGardiner:j1939_scanning https://github.com/secdev/scapy/pull/4961/changes#diff-5d6504c729d8bfec31ff30aec28e76f32ae70eba914b2338540fe2b13a221f34

Check for useful modifications

Copilot AI and others added 2 commits May 16, 2026 20:10
Copy link
Copy Markdown
Author

Copilot AI commented May 16, 2026

@copilot Analyze the J1939 SoftSocket implementation from BenGardiner:j1939_scanning https://github.com/secdev/scapy/pull/4961/changes#diff-5d6504c729d8bfec31ff30aec28e76f32ae70eba914b2338540fe2b13a22...

Analyzed PR secdev#4961. Summary of what BenGardiner's implementation adds over ours, and what we incorporated:

Already in our implementation (confirmed equivalent):

  • listen_only parameter – identical concept, fully implemented and tested
  • Timeout extension factor (TP_DT_TIMEOUT_EXTENSION_FACTOR = 10) – we have _J1939_TP_DT_TIMEOUT_EXTENSION = 10 with the same total-elapsed-time logic; I clarified the comments to accurately describe the wall-clock ceiling approach (commit 63faffb)

Incorporated from BenGardiner's approach:

  • pgn filter parameter (rx_pgn in his code) – added pgn_filter to J1939TPImplementation and pgn to J1939SoftSocket; pgn=0 accepts all PGNs (identical semantics to his rx_pgn=0); filters single-frame, BAM, and RTS/CTS sessions. Three new tests added (commit ea28d5a).

Not incorporated (out of scope / too complex for this PR):

  • Configurable CMDT block size (bs parameter) – requires multi-block CTS state tracking
  • J1939-81 address claiming (name parameter) – separate feature, significant complexity

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/secdev/scapy/pulls/4961/files
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (http block)
    • Triggering command: `/usr/bin/python3 python3 -c
      import urllib.request

Try different URL formats for BenGardiner's PR

urls = [
'REDACTED',
'REDACTED',
]
for url i iptables -w -t security ndor/bin/bash -nxv` (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title J1939SoftSocket: expand edge-case unit tests and soft↔native interop coverage J1939SoftSocket: expand edge-case unit tests, soft↔native interop coverage, and pgn filter May 16, 2026
Copilot AI requested a review from polybassa May 16, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants