Repository navigation
automotive, j1939: scanning for CAs - #5164
BenGardiner wants to merge 4 commits into
Conversation
|
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. |
fbcb5a9 to
4757249
Compare
|
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... |
97acab8 to
f664c8a
Compare
|
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 Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #5164 +/- ##
==========================================
+ Coverage 81.17% 81.33% +0.15%
==========================================
Files 394 399 +5
Lines 98770 99844 +1074
==========================================
+ Hits 80178 81205 +1027
- Misses 18592 18639 +47
🚀 New features to boost your workflow:
|
3b5967c to
4d7cb29
Compare
|
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 |
35d5188 to
625c334
Compare
|
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 |
625c334 to
58adda4
Compare
|
no sorry. skipped due to a typo. |
58adda4 to
811dfd9
Compare
|
ok... ok well that was a journey... over to you then @polybassa |
10747a6 to
3a0469e
Compare
|
ok @polybassa this is maybe good enough now. please have a look |
…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)
AI-Assisted: yes (Gemini 3.8 Flash)
…939-81) AI-Assisted: yes (Gemini 3.8 Flash)
|
@polybassa this is rebased onto the latest scapy master that has all the CI fixes I've proposed |
polybassa
left a comment
There was a problem hiding this comment.
Didn't went into all details, yet, but here are already some remarks which may lead to a more simple code.
I really appreciate the progress on the code quality. Improved quite a lot compared to the earlier versions
| else: | ||
| items = [(pgn, pgn) for pgn in pgns] | ||
|
|
||
| results = {} # type: Dict[Any, J1939PgnScanResult] |
There was a problem hiding this comment.
To be even more compatible to the enumerators, you could use the result storing mechanism from the service enumerator. This also has the advantage that the memory is optimised internally.
However, the basic idea there was to store request response pairs and let the enumerator do the representation aka the conversation a result, depending on the type of enumerator.
The main execute function just takes care about running through the list of specified initial requests. The evaluate response Methode allows to break from the enumeration loop. So maybe you can also use these mechanism and align your execute loop even more.
Appreciate that you are reusing enumerators here.
| bitrate = kwargs.get("bitrate", J1939_DEFAULT_BITRATE) | ||
| busload = kwargs.get("busload", J1939_DEFAULT_BUSLOAD) | ||
| reset_handler = kwargs.get("reset_handler") | ||
| reconnect_handler = kwargs.get("reconnect_handler") |
There was a problem hiding this comment.
You could use default values here, then you don't need to provide them later as ...=None
| ) | ||
| return [req] | ||
|
|
||
| def match_resp(rcv): |
There was a problem hiding this comment.
Couldn't this be in an answers() function? Which would maybe allow to use sr or sr1 wherever this function is used
| def clone_with(self, payload=None, **kargs): | ||
| # type: (Optional[Any], **Any) -> J1939 | ||
| pkt = super(J1939, self).clone_with(payload=payload, **kargs) | ||
| pkt.priority = kargs.get('priority', self.priority) | ||
| pkt.pgn = kargs.get('pgn', self.pgn) | ||
| pkt.src = kargs.get('src', self.src) | ||
| pkt.dst = kargs.get('dst', self.dst) | ||
| return pkt | ||
|
|
||
| def copy(self): | ||
| # type: () -> J1939 | ||
| clone = super(J1939, self).copy() | ||
| clone.priority = self.priority | ||
| clone.pgn = self.pgn | ||
| clone.src = self.src | ||
| clone.dst = self.dst | ||
| return clone |
There was a problem hiding this comment.
We can only store these information in slots, if they are not on the wore and only given by the socket or some other environment. Same for ISOTP addresses.
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.