-
Notifications
You must be signed in to change notification settings - Fork 10.4k
firmware fingerprinting: order brand requests #23311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
71dcc34
eliminate brands based on ECUs that respond to tester present
gregjhogan 43bc6a6
make it work
gregjhogan 5d0a470
Add type hint for can message
sshane ad40d47
Only query for addresses in fingerprints, and account for different b…
sshane 55b837a
These need to be addresses, not response addresses
sshane 8e54436
We need to listen to response addresses, not query addresses
sshane e981add
add to files_common
sshane 03ec08c
Unused Optional
sshane 10d68a0
add logging
sshane 250a89c
only query essential ecus
sshane 6fea1b1
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 2ee55ae
simplify get_brand_candidates(), keep track of multiple request varia…
sshane 5793a1e
fixes
sshane c4ffd70
(addr, subaddr, bus) can be common across brands, add a match to each…
sshane c445b98
fix length
sshane 48e9651
query subaddrs in sequence
sshane a240774
fix
sshane 9cad5c2
candidate if a platform is a subset of responding ecu addresses
sshane 08d2058
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 5a77da3
do logging for shadow mode
sshane e539787
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 947f9de
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane dee85a4
query fw using most likely brands first, break when match
sshane 82f6012
fix crash
sshane ff782b1
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 0e09112
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 9abf7f9
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 7a1a237
clean up
sshane 09d0c7f
add brand filtering for debug script
sshane ac97188
no cache
sshane f87b809
fix that
sshane 4a96ad3
fixes
sshane 3a2b635
same name
sshane 0ea9749
this likely isn't needed, we vin and get tester present responses bef…
sshane b53be8b
cache
sshane a742300
fix type annotation
sshane 345bef9
no enumerate
sshane a969049
fix
sshane e2c5109
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 420e173
make sure matching function checks for multiple matches across brands
sshane 15c57a3
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 428581c
this can be the same again
sshane 3976923
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane 4651349
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane ab03234
Merge remote-tracking branch 'upstream/master' into fast-fw-fp
sshane b87c3a0
clean up some functions/names
sshane af9ac2e
self explanetory with rework
sshane 572f1b7
names
sshane f6936cc
better ordering of func vars, fix typing
sshane 2b311cc
better yet
sshane 27eeb6e
unused dict
sshane 3720950
more accurate comment
sshane File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env python3 | ||
| import capnp | ||
| import time | ||
| import traceback | ||
| from typing import Dict, Set | ||
|
|
||
| import cereal.messaging as messaging | ||
| from panda.python.uds import SERVICE_TYPE | ||
| from selfdrive.car import make_can_msg | ||
| from selfdrive.boardd.boardd import can_list_to_can_capnp | ||
| from selfdrive.swaglog import cloudlog | ||
|
|
||
| TESTER_PRESENT_DAT = bytes([0x02, SERVICE_TYPE.TESTER_PRESENT, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]) | ||
|
|
||
|
|
||
| def is_tester_present_response(msg: capnp.lib.capnp._DynamicStructReader) -> bool: | ||
| # ISO-TP messages are always padded to 8 bytes | ||
| # tester present response is always a single frame | ||
| if len(msg.dat) == 8 and 1 <= msg.dat[0] <= 7: | ||
| # success response | ||
| if msg.dat[1] == (SERVICE_TYPE.TESTER_PRESENT + 0x40): | ||
| return True | ||
| # error response | ||
| if msg.dat[1] == 0x7F and msg.dat[2] == SERVICE_TYPE.TESTER_PRESENT: | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def get_all_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, bus: int, timeout: float = 1, debug: bool = True) -> Set[int]: | ||
| addr_list = [0x700 + i for i in range(256)] + [0x18da00f1 + (i << 8) for i in range(256)] | ||
| query_addrs = response_addrs = {addr: bus for addr in addr_list} | ||
| return get_ecu_addrs(logcan, sendcan, query_addrs, response_addrs, timeout=timeout, debug=debug) | ||
|
|
||
|
|
||
| def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, query_addrs: Dict[int, int], response_addrs: Dict[int, int], timeout: float = 1, debug: bool = True) -> Set[int]: | ||
| ecu_addrs = set() | ||
| try: | ||
| msgs = [make_can_msg(addr, TESTER_PRESENT_DAT, bus) for addr, bus in query_addrs.items()] | ||
|
|
||
| messaging.drain_sock_raw(logcan) | ||
| sendcan.send(can_list_to_can_capnp(msgs, msgtype='sendcan')) | ||
| start_time = time.monotonic() | ||
| while time.monotonic() - start_time < timeout: | ||
| can_packets = messaging.drain_sock(logcan, wait_for_one=True) | ||
| for packet in can_packets: | ||
| for msg in packet.can: | ||
| if msg.address in response_addrs and msg.src == response_addrs[msg.address] and is_tester_present_response(msg): | ||
| if debug: | ||
| print(f"CAN-RX: {hex(msg.address)} - 0x{bytes.hex(msg.dat)}") | ||
| if msg.address in ecu_addrs: | ||
| print(f"Duplicate ECU address: {hex(msg.address)}") | ||
| ecu_addrs.add(msg.address) | ||
| except Exception: | ||
| cloudlog.warning(f"ECU addr scan exception: {traceback.format_exc()}") | ||
| return ecu_addrs | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| import argparse | ||
|
|
||
| parser = argparse.ArgumentParser(description='Get addresses of all ECUs') | ||
| parser.add_argument('--debug', action='store_true') | ||
| args = parser.parse_args() | ||
|
|
||
| logcan = messaging.sub_sock('can') | ||
| sendcan = messaging.pub_sock('sendcan') | ||
|
|
||
| time.sleep(1.0) | ||
|
|
||
| print("Getting ECU addresses ...") | ||
| ecu_addrs = get_all_ecu_addrs(logcan, sendcan, 1, debug=args.debug) | ||
|
|
||
| print() | ||
| print("Found ECUs on addresses:") | ||
| for addr in ecu_addrs: | ||
| print(f" {hex(addr)}") | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.