UDS fingerprinting development tool updates (#681)

* WIP for UDS FP development

* WIP for UDS FP development

* WIP for UDS FP development

* propitiate mypy

* Update examples/query_fw_versions.py

* Update examples/query_fw_versions.py

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
This commit is contained in:
Jason Young 2021-07-11 03:44:25 -04:00 committed by GitHub
parent 7f12eb87b7
commit afd999b283
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 47 deletions

View File

@ -1,15 +1,38 @@
#!/usr/bin/env python3
import argparse
from tqdm import tqdm
from panda import Panda
from panda.python.uds import UdsClient, MessageTimeoutError, NegativeResponseError, SESSION_TYPE, DATA_IDENTIFIER_TYPE
if __name__ == "__main__":
addrs = [0x700 + i for i in range(256)]
addrs += [0x18da0000 + (i << 8) + 0xf1 for i in range(256)]
parser = argparse.ArgumentParser()
parser.add_argument('--rxoffset', default="0x8")
parser.add_argument('--nonstandard', action='store_true')
parser.add_argument('--debug', action='store_true')
parser.add_argument('--addr')
args = parser.parse_args()
if args.addr:
addrs = [int(args.addr, base=16)]
else:
addrs = [0x700 + i for i in range(256)]
addrs += [0x18da0000 + (i << 8) + 0xf1 for i in range(256)]
results = {}
uds_data_ids = {}
for std_id in DATA_IDENTIFIER_TYPE:
uds_data_ids[std_id.value] = std_id.name
if args.nonstandard:
for uds_id in range(0xf100,0xf180):
uds_data_ids[uds_id] = "IDENTIFICATION_OPTION_VEHICLE_MANUFACTURER_SPECIFIC_DATA_IDENTIFIER"
for uds_id in range(0xf1a0,0xf1f0):
uds_data_ids[uds_id] = "IDENTIFICATION_OPTION_VEHICLE_MANUFACTURER_SPECIFIC"
for uds_id in range(0xf1f0,0xf200):
uds_data_ids[uds_id] = "IDENTIFICATION_OPTION_SYSTEM_SUPPLIER_SPECIFIC"
panda = Panda()
panda.set_safety_mode(Panda.SAFETY_ELM327)
panda.set_power_save(0)
print("querying addresses ...")
with tqdm(addrs) as t:
for addr in t:
@ -18,66 +41,36 @@ if __name__ == "__main__":
continue
t.set_description(hex(addr))
uds_client = UdsClient(panda, addr, bus=1 if panda.has_obd() else 0, timeout=0.1, debug=False)
uds_client = UdsClient(panda, addr, addr + int(args.rxoffset, base=16), bus=1 if panda.has_obd() else 0, timeout=0.2, debug=args.debug)
# Check for anything alive at this address, and switch to the highest
# available diagnostic session without security access
try:
uds_client.tester_present()
uds_client.diagnostic_session_control(SESSION_TYPE.DEFAULT)
uds_client.diagnostic_session_control(SESSION_TYPE.EXTENDED_DIAGNOSTIC)
except NegativeResponseError:
pass
except MessageTimeoutError:
continue
# Run queries against all standard UDS data identifiers, plus selected
# non-standardized identifier ranges if requested
resp = {}
try:
data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.BOOT_SOFTWARE_IDENTIFICATION)
if data:
resp[DATA_IDENTIFIER_TYPE.BOOT_SOFTWARE_IDENTIFICATION] = data
except NegativeResponseError:
pass
try:
data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_IDENTIFICATION)
if data:
resp[DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_IDENTIFICATION] = data
except NegativeResponseError:
pass
try:
data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_DATA_IDENTIFICATION)
if data:
resp[DATA_IDENTIFIER_TYPE.APPLICATION_DATA_IDENTIFICATION] = data
except NegativeResponseError:
pass
try:
data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.BOOT_SOFTWARE_FINGERPRINT)
if data:
resp[DATA_IDENTIFIER_TYPE.BOOT_SOFTWARE_FINGERPRINT] = data
except NegativeResponseError:
pass
try:
data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_FINGERPRINT)
if data:
resp[DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_FINGERPRINT] = data
except NegativeResponseError:
pass
try:
data = uds_client.read_data_by_identifier(DATA_IDENTIFIER_TYPE.APPLICATION_DATA_FINGERPRINT)
if data:
resp[DATA_IDENTIFIER_TYPE.APPLICATION_DATA_FINGERPRINT] = data
except NegativeResponseError:
pass
for uds_data_id in sorted(uds_data_ids):
try:
data = uds_client.read_data_by_identifier(uds_data_id) # type: ignore
if data:
resp[uds_data_id] = data
except (NegativeResponseError, MessageTimeoutError):
pass
if resp.keys():
results[addr] = resp
print("results:")
if len(results.items()):
for addr, resp in results.items():
print(f"\n\n*** Results for address 0x{addr:X} ***\n\n")
for rid, dat in resp.items():
print(hex(addr), hex(rid), dat.decode())
print(f"0x{rid:02X} {uds_data_ids[rid]}: {dat}")
else:
print("no fw versions found!")