2019-11-17 10:54:15 +08:00
|
|
|
#!/usr/bin/env python3
|
2021-07-11 15:44:25 +08:00
|
|
|
import argparse
|
2023-06-23 11:15:42 +08:00
|
|
|
from typing import List, Optional
|
2019-11-17 10:54:15 +08:00
|
|
|
from tqdm import tqdm
|
|
|
|
from panda import Panda
|
2023-06-24 07:33:12 +08:00
|
|
|
from panda.python.uds import UdsClient, MessageTimeoutError, NegativeResponseError, InvalidSubAddressError, \
|
|
|
|
SESSION_TYPE, DATA_IDENTIFIER_TYPE
|
2019-11-17 10:54:15 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-07-11 15:44:25 +08:00
|
|
|
parser = argparse.ArgumentParser()
|
2023-01-14 07:20:42 +08:00
|
|
|
parser.add_argument("--rxoffset", default="")
|
|
|
|
parser.add_argument("--nonstandard", action="store_true")
|
|
|
|
parser.add_argument("--no-obd", action="store_true", help="Bus 1 will not be multiplexed to the OBD-II port")
|
|
|
|
parser.add_argument("--debug", action="store_true")
|
|
|
|
parser.add_argument("--addr")
|
2023-06-23 11:15:42 +08:00
|
|
|
parser.add_argument("--sub_addr", "--subaddr", help="A hex sub-address or `scan` to scan the full sub-address range")
|
2023-01-14 07:20:42 +08:00
|
|
|
parser.add_argument("--bus")
|
2023-01-14 07:24:25 +08:00
|
|
|
parser.add_argument('-s', '--serial', help="Serial number of panda to use")
|
2021-07-11 15:44:25 +08:00
|
|
|
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)]
|
2019-11-17 10:54:15 +08:00
|
|
|
results = {}
|
|
|
|
|
2023-06-23 11:15:42 +08:00
|
|
|
sub_addrs: List[Optional[int]] = [None]
|
|
|
|
if args.sub_addr:
|
|
|
|
if args.sub_addr == "scan":
|
|
|
|
sub_addrs = list(range(0xff + 1))
|
|
|
|
else:
|
|
|
|
sub_addrs = [int(args.sub_addr, base=16)]
|
|
|
|
if sub_addrs[0] > 0xff: # type: ignore
|
|
|
|
print(f"Invalid sub-address: 0x{sub_addrs[0]:X}, needs to be in range 0x0 to 0xff")
|
|
|
|
parser.print_help()
|
|
|
|
exit()
|
|
|
|
|
2021-07-11 15:44:25 +08:00
|
|
|
uds_data_ids = {}
|
|
|
|
for std_id in DATA_IDENTIFIER_TYPE:
|
|
|
|
uds_data_ids[std_id.value] = std_id.name
|
|
|
|
if args.nonstandard:
|
2023-01-14 07:20:42 +08:00
|
|
|
for uds_id in range(0xf100, 0xf180):
|
2021-07-11 15:44:25 +08:00
|
|
|
uds_data_ids[uds_id] = "IDENTIFICATION_OPTION_VEHICLE_MANUFACTURER_SPECIFIC_DATA_IDENTIFIER"
|
2023-01-14 07:20:42 +08:00
|
|
|
for uds_id in range(0xf1a0, 0xf1f0):
|
2021-07-11 15:44:25 +08:00
|
|
|
uds_data_ids[uds_id] = "IDENTIFICATION_OPTION_VEHICLE_MANUFACTURER_SPECIFIC"
|
2023-01-14 07:20:42 +08:00
|
|
|
for uds_id in range(0xf1f0, 0xf200):
|
2021-07-11 15:44:25 +08:00
|
|
|
uds_data_ids[uds_id] = "IDENTIFICATION_OPTION_SYSTEM_SUPPLIER_SPECIFIC"
|
|
|
|
|
2023-01-14 07:24:25 +08:00
|
|
|
panda_serials = Panda.list()
|
|
|
|
if args.serial is None and len(panda_serials) > 1:
|
|
|
|
print("\nMultiple pandas found, choose one:")
|
|
|
|
for serial in panda_serials:
|
2023-01-14 08:17:20 +08:00
|
|
|
with Panda(serial) as panda:
|
|
|
|
print(f" {serial}: internal={panda.is_internal()}")
|
2023-01-14 07:24:25 +08:00
|
|
|
print()
|
|
|
|
parser.print_help()
|
|
|
|
exit()
|
|
|
|
|
|
|
|
panda = Panda(serial=args.serial)
|
|
|
|
panda.set_safety_mode(Panda.SAFETY_ELM327, 1 if args.no_obd else 0)
|
2019-11-17 10:54:15 +08:00
|
|
|
print("querying addresses ...")
|
2019-11-18 01:30:01 +08:00
|
|
|
with tqdm(addrs) as t:
|
|
|
|
for addr in t:
|
|
|
|
# skip functional broadcast addrs
|
|
|
|
if addr == 0x7df or addr == 0x18db33f1:
|
|
|
|
continue
|
2019-11-17 10:54:15 +08:00
|
|
|
|
2022-08-18 06:55:49 +08:00
|
|
|
if args.bus:
|
|
|
|
bus = int(args.bus)
|
|
|
|
else:
|
|
|
|
bus = 1 if panda.has_obd() else 0
|
2021-09-24 09:21:21 +08:00
|
|
|
rx_addr = addr + int(args.rxoffset, base=16) if args.rxoffset else None
|
2019-11-17 10:54:15 +08:00
|
|
|
|
2023-06-23 11:15:42 +08:00
|
|
|
# Try all sub-addresses for addr. By default, this is None
|
|
|
|
for sub_addr in sub_addrs:
|
|
|
|
sub_addr_str = hex(sub_addr) if sub_addr is not None else None
|
|
|
|
t.set_description(f"{hex(addr)}, {sub_addr_str}")
|
|
|
|
uds_client = UdsClient(panda, addr, rx_addr, bus, sub_addr=sub_addr, timeout=0.2, debug=args.debug)
|
|
|
|
# Check for anything alive at this address, and switch to the highest
|
|
|
|
# available diagnostic session without security access
|
2021-07-11 15:44:25 +08:00
|
|
|
try:
|
2023-06-23 11:15:42 +08:00
|
|
|
uds_client.tester_present()
|
|
|
|
uds_client.diagnostic_session_control(SESSION_TYPE.DEFAULT)
|
|
|
|
uds_client.diagnostic_session_control(SESSION_TYPE.EXTENDED_DIAGNOSTIC)
|
|
|
|
except NegativeResponseError:
|
2021-07-11 15:44:25 +08:00
|
|
|
pass
|
2023-06-23 11:15:42 +08:00
|
|
|
except MessageTimeoutError:
|
|
|
|
continue
|
2023-06-24 07:33:12 +08:00
|
|
|
except InvalidSubAddressError:
|
|
|
|
break
|
2023-06-23 11:15:42 +08:00
|
|
|
|
|
|
|
# Run queries against all standard UDS data identifiers, plus selected
|
|
|
|
# non-standardized identifier ranges if requested
|
|
|
|
resp = {}
|
|
|
|
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
|
2023-06-24 07:33:12 +08:00
|
|
|
except (NegativeResponseError, MessageTimeoutError, InvalidSubAddressError):
|
2023-06-23 11:15:42 +08:00
|
|
|
pass
|
2019-11-17 10:54:15 +08:00
|
|
|
|
2023-06-23 11:15:42 +08:00
|
|
|
if resp.keys():
|
|
|
|
results[(addr, sub_addr)] = resp
|
2019-11-17 10:54:15 +08:00
|
|
|
|
2019-11-18 01:30:01 +08:00
|
|
|
if len(results.items()):
|
2023-06-23 11:15:42 +08:00
|
|
|
for (addr, sub_addr), resp in results.items():
|
|
|
|
sub_addr_str = f", sub-address 0x{sub_addr:X}" if sub_addr is not None else ""
|
|
|
|
print(f"\n\n*** Results for address 0x{addr:X}{sub_addr_str} ***\n\n")
|
2019-11-18 03:19:59 +08:00
|
|
|
for rid, dat in resp.items():
|
2021-07-11 15:44:25 +08:00
|
|
|
print(f"0x{rid:02X} {uds_data_ids[rid]}: {dat}")
|
2019-11-18 01:30:01 +08:00
|
|
|
else:
|
2019-11-18 03:19:59 +08:00
|
|
|
print("no fw versions found!")
|