FW fingerprinting updates (#25088)

* Print brand along with ecu

* fix json decoding

* fw_versions updates

* add timeout handling back

* keep logging the same
This commit is contained in:
Shane Smiskol
2022-07-08 13:46:09 -07:00
committed by GitHub
parent 1d6623c609
commit 5f77451aec
2 changed files with 13 additions and 15 deletions
+3 -3
View File
@@ -79,7 +79,7 @@ interfaces = load_interfaces(interface_names)
def fingerprint(logcan, sendcan):
fixed_fingerprint = os.environ.get('FINGERPRINT', "")
skip_fw_query = os.environ.get('SKIP_FW_QUERY', False)
ecu_responses = set()
ecu_rx_addrs = set()
if not fixed_fingerprint and not skip_fw_query:
# Vin query only reliably works thorugh OBDII
@@ -98,7 +98,7 @@ def fingerprint(logcan, sendcan):
else:
cloudlog.warning("Getting VIN & FW versions")
_, vin = get_vin(logcan, sendcan, bus)
ecu_responses = get_present_ecus(logcan, sendcan)
ecu_rx_addrs = get_present_ecus(logcan, sendcan)
car_fw = get_fw_versions(logcan, sendcan)
exact_fw_match, fw_candidates = match_fw_to_car(car_fw)
@@ -166,7 +166,7 @@ def fingerprint(logcan, sendcan):
source = car.CarParams.FingerprintSource.fixed
cloudlog.event("fingerprinted", car_fingerprint=car_fingerprint, source=source, fuzzy=not exact_match,
fw_count=len(car_fw), ecu_responses=ecu_responses, error=True)
fw_count=len(car_fw), ecu_responses=list(ecu_rx_addrs), error=True)
return car_fingerprint, finger, vin, car_fw, source, exact_match
+10 -12
View File
@@ -290,24 +290,21 @@ def match_fw_to_car(fw_versions, allow_fuzzy=True):
versions = get_interface_attr('FW_VERSIONS', ignore_none=True)
# Try exact matching first
exact_matches = [True]
exact_matches = [(True, match_fw_to_car_exact)]
if allow_fuzzy:
exact_matches.append(False)
exact_matches.append((False, match_fw_to_car_fuzzy))
for exact_match in exact_matches:
for exact_match, match_func in exact_matches:
# For each brand, attempt to fingerprint using FW returned from its queries
matches = set()
for brand in versions.keys():
fw_versions_dict = build_fw_dict(fw_versions, filter_brand=brand)
matches |= match_func(fw_versions_dict)
if exact_match:
matches = match_fw_to_car_exact(fw_versions_dict)
else:
matches = match_fw_to_car_fuzzy(fw_versions_dict)
if len(matches):
return exact_match, matches
if len(matches) == 1:
return exact_match, matches
return True, []
return True, set()
def get_present_ecus(logcan, sendcan):
@@ -448,9 +445,10 @@ if __name__ == "__main__":
print()
print("Found FW versions")
print("{")
padding = max([len(fw.brand) for fw in fw_vers])
for version in fw_vers:
subaddr = None if version.subAddress == 0 else hex(version.subAddress)
print(f" (Ecu.{version.ecu}, {hex(version.address)}, {subaddr}): [{version.fwVersion}]")
print(f" Brand: {version.brand:{padding}} - (Ecu.{version.ecu}, {hex(version.address)}, {subaddr}): [{version.fwVersion}]")
print("}")
print()