check vin validity (#25199)

old-commit-hash: 6b74be53ae
taco
Adeeb Shihadeh 3 years ago committed by GitHub
parent 92d21da552
commit 3e260b0a73
  1. 4
      selfdrive/car/car_helpers.py
  2. 6
      selfdrive/car/vin.py

@ -7,7 +7,7 @@ from common.basedir import BASEDIR
from system.version import is_comma_remote, is_tested_branch from system.version import is_comma_remote, is_tested_branch
from selfdrive.car.interfaces import get_interface_attr from selfdrive.car.interfaces import get_interface_attr
from selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars from selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars
from selfdrive.car.vin import get_vin, VIN_UNKNOWN from selfdrive.car.vin import get_vin, is_valid_vin, VIN_UNKNOWN
from selfdrive.car.fw_versions import get_fw_versions_ordered, match_fw_to_car, get_present_ecus from selfdrive.car.fw_versions import get_fw_versions_ordered, match_fw_to_car, get_present_ecus
from system.swaglog import cloudlog from system.swaglog import cloudlog
import cereal.messaging as messaging import cereal.messaging as messaging
@ -106,7 +106,7 @@ def fingerprint(logcan, sendcan):
vin, vin_rx_addr = VIN_UNKNOWN, 0 vin, vin_rx_addr = VIN_UNKNOWN, 0
exact_fw_match, fw_candidates, car_fw = True, set(), [] exact_fw_match, fw_candidates, car_fw = True, set(), []
if len(vin) != 17: if not is_valid_vin(vin):
cloudlog.event("Malformed VIN", vin=vin, error=True) cloudlog.event("Malformed VIN", vin=vin, error=True)
vin = VIN_UNKNOWN vin = VIN_UNKNOWN
cloudlog.warning("VIN %s", vin) cloudlog.warning("VIN %s", vin)

@ -1,4 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import re
import struct import struct
import traceback import traceback
@ -15,6 +16,11 @@ UDS_VIN_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + struct.pac
UDS_VIN_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + struct.pack("!H", uds.DATA_IDENTIFIER_TYPE.VIN) UDS_VIN_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + struct.pack("!H", uds.DATA_IDENTIFIER_TYPE.VIN)
VIN_UNKNOWN = "0" * 17 VIN_UNKNOWN = "0" * 17
VIN_RE = "[A-HJ-NPR-Z0-9]{17}"
def is_valid_vin(vin: str):
return re.fullmatch(VIN_RE, vin) is not None
def get_vin(logcan, sendcan, bus, timeout=0.1, retry=5, debug=False): def get_vin(logcan, sendcan, bus, timeout=0.1, retry=5, debug=False):

Loading…
Cancel
Save