Skip to content

automotive, j1939: scanning for CAs - #5164

Open
BenGardiner wants to merge 5 commits into
secdev:masterfrom
BenGardiner:j1939-soft-sockets-again
Open

BenGardiner wants to merge 5 commits into
secdev:masterfrom
BenGardiner:j1939-soft-sockets-again

Conversation

@BenGardiner

@BenGardiner BenGardiner commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Description

This adds j1939 scanning for Controller Applications on-top-of the soft socket support.

The changes aim to introduce only those J1939 value enumeration definitions which can be sourced from freely available locations on the internet. As such, there is not a complete list of the values.

I don't intend any impacts on other parts of the libraries.

fixes missing sr1() functionality in J1939 soft socket on master

LLM coding tools were used in the development of this PR: copilot and gemini, various models.

@BenGardiner

Copy link
Copy Markdown
Contributor Author

@polybassa

Comment thread scapy/contrib/automotive/j1939/__init__.py Outdated
Comment thread scapy/contrib/automotive/j1939/__init__.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_dm_scanner.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_name.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_name.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_scanner.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_scanner.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_scanner.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_scanner.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_scanner.py Outdated
Comment thread scapy/contrib/automotive/j1939/j1939_scanner.py Outdated
@BenGardiner

Copy link
Copy Markdown
Contributor Author

thanks @polybassa for the review. I can do almost all of that right now. There's a couple things that are either answering your questions or require me to ask you questions first.

@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch from fbcb5a9 to 4757249 Compare September 14, 2026 13:12
@BenGardiner

Copy link
Copy Markdown
Contributor Author

I noticed that in the rebase of the scanner code to your replacement soft socket the scanners were no longer cleanly relying on sr() / sr1() via answers() logic. I'll work on bringing that back, fixing the things above I didn't have questions about and then refactoring the scanners to use the answers() logic...

@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch 3 times, most recently from 97acab8 to f664c8a Compare September 17, 2026 09:58
@BenGardiner

Copy link
Copy Markdown
Contributor Author

Hi @polybassa while I think this is ready for your next review, it might not be merged in this form. There are 'Feature' commits and then 'fixes' on them. e.g. FFfffFffFfffffFfff. To merge you would probably want the fixes squashed into the features. You may even want one squashed commit -- in which case you might consider merging the first commit separately since it is implementing missing sr1() functionality in the current J1939SoftSocket on master.

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.85%. Comparing base (5376fcc) to head (4e9d391).

Files with missing lines Patch % Lines
scapy/contrib/j1939.py 88.61% 41 Missing ⚠️
scapy/contrib/automotive/j1939/j1939_scanner.py 96.19% 19 Missing ⚠️
scapy/contrib/automotive/j1939/j1939_dm_scanner.py 94.25% 10 Missing ⚠️
scapy/contrib/automotive/j1939/j1939_dm.py 90.56% 5 Missing ⚠️
scapy/as_resolvers.py 83.33% 1 Missing ⚠️
scapy/contrib/automotive/j1939/j1939_name.py 98.14% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5164      +/-   ##
==========================================
- Coverage   80.89%   80.85%   -0.05%     
==========================================
  Files         394      399       +5     
  Lines       98710    99829    +1119     
==========================================
+ Hits        79853    80712     +859     
- Misses      18857    19117     +260     
Files with missing lines Coverage Δ
scapy/contrib/automotive/j1939/__init__.py 100.00% <100.00%> (ø)
scapy/layers/can.py 93.33% <100.00%> (+0.29%) ⬆️
scapy/layers/inet6.py 88.79% <100.00%> (ø)
scapy/as_resolvers.py 84.54% <83.33%> (-0.22%) ⬇️
scapy/contrib/automotive/j1939/j1939_name.py 98.14% <98.14%> (ø)
scapy/contrib/automotive/j1939/j1939_dm.py 90.56% <90.56%> (ø)
scapy/contrib/automotive/j1939/j1939_dm_scanner.py 94.25% <94.25%> (ø)
scapy/contrib/automotive/j1939/j1939_scanner.py 96.19% <96.19%> (ø)
scapy/contrib/j1939.py 90.30% <88.61%> (+0.58%) ⬆️

... and 37 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch 3 times, most recently from 3b5967c to 4d7cb29 Compare September 17, 2026 12:41
@BenGardiner

Copy link
Copy Markdown
Contributor Author

I'm going to look closer at https://github.com/secdev/scapy/actions/runs/35222531093/job/105206012569?pr=5164 -- that seems like there could be something wrong with the soft socket...

@BenGardiner

Copy link
Copy Markdown
Contributor Author

I'm going to look closer at https://github.com/secdev/scapy/actions/runs/35222531093/job/105206012569?pr=5164 -- that seems like there could be something wrong with the soft socket...

yep that was a race in close() of the soft socket -- just like we had in isotp soft socket.

I have a fix

@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch 5 times, most recently from 35d5188 to 625c334 Compare September 17, 2026 21:30
@BenGardiner

Copy link
Copy Markdown
Contributor Author

sorry the checks may be skipped now due to a rate limit...

I think I resolved them but pretty hard to tell locally without waiting for the github runners

@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch from 625c334 to 58adda4 Compare September 17, 2026 21:42
@BenGardiner

Copy link
Copy Markdown
Contributor Author

no sorry. skipped due to a typo.

@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch from 58adda4 to 811dfd9 Compare September 17, 2026 23:28
@BenGardiner

Copy link
Copy Markdown
Contributor Author

ok... ok well that was a journey... over to you then @polybassa

@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch from b5a0b46 to 2b54cd6 Compare October 11, 2026 17:49
AI-Assisted: Yes Kimi 2.7 / GPT 5.4 codex / Copilot
@BenGardiner
BenGardiner force-pushed the j1939-soft-sockets-again branch 22 times, most recently from 10747a6 to 3a0469e Compare October 13, 2026 18:38
@BenGardiner

Copy link
Copy Markdown
Contributor Author

note there is an intermittent failure in the windows tests on master:

The identical windows-latest 3.14 root -K scanner step fails intermittently on clean commits on secdev/scapy master:
• Run 38098954227 https://github.com/secdev/scapy/actions/runs/38098954227/job/114350702940 on commit 5376fcc failed in Run Tox (win) (run 38098954222 https://github.com/secdev/scapy/actions/runs/38098954222 on the same commit passed).
• Run 38049041842 https://github.com/secdev/scapy/actions/runs/38049041842/job/114204313478 on commit bef8877 failed in Run Tox (win) (run 38049041840 https://github.com/secdev/scapy/actions/runs/38049041840 on the same commit passed).
• Run 37982266328 https://github.com/secdev/scapy/actions/runs/37982266328/job/113995527868 on commit 6173a18 failed in Run Tox (win) (run 37982266163 https://github.com/secdev/scapy/actions/runs/37982266163 on the same commit passed).
• Run 37545407681 https://github.com/secdev/scapy/actions/runs/37545407681/job/112548150143 on commit d1bbdaf failed in Run Tox (win) (run 37545407607 https://github.com/secdev/scapy/actions/runs/37545407607 on the same commit passed).

@BenGardiner

Copy link
Copy Markdown
Contributor Author

note there is an intermittent failure in the windows tests on master:

The identical windows-latest 3.14 root -K scanner step fails intermittently on clean commits on secdev/scapy master: • Run 38098954227 https://github.com/secdev/scapy/actions/runs/38098954227/job/114350702940 on commit 5376fcc failed in Run Tox (win) (run 38098954222 https://github.com/secdev/scapy/actions/runs/38098954222 on the same commit passed). • Run 38049041842 https://github.com/secdev/scapy/actions/runs/38049041842/job/114204313478 on commit bef8877 failed in Run Tox (win) (run 38049041840 https://github.com/secdev/scapy/actions/runs/38049041840 on the same commit passed). • Run 37982266328 https://github.com/secdev/scapy/actions/runs/37982266328/job/113995527868 on commit 6173a18 failed in Run Tox (win) (run 37982266163 https://github.com/secdev/scapy/actions/runs/37982266163 on the same commit passed). • Run 37545407681 https://github.com/secdev/scapy/actions/runs/37545407681/job/112548150143 on commit d1bbdaf failed in Run Tox (win) (run 37545407607 https://github.com/secdev/scapy/actions/runs/37545407607 on the same commit passed).

these MIGHT be fixed by #5227

…allback (heuristic)

Implement answers(), clone_with(), and copy() on J1939 to support sr1()
for directed and broadcast requests with session tracking and fallback
heuristics.

Add identifier property and setter to J1939_CAN to satisfy the CAN
interface for python-can backends, and add a defensive fallback in
_can_send() converting to CAN on AttributeError.

AI-Assisted: yes (Gemini 3.8 Flash)
Adds a scanner to identify Controller Applications in a J1939 network,
various scanning techniques are provided including both broadcast and
unicast.

AI-Assisted: yes (Gemini 3.8 Flash)
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.

4 participants