mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-23 23:12:04 +08:00
check vin validity (#25199)
This commit is contained in:
@@ -7,7 +7,7 @@ from common.basedir import BASEDIR
|
||||
from system.version import is_comma_remote, is_tested_branch
|
||||
from selfdrive.car.interfaces import get_interface_attr
|
||||
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 system.swaglog import cloudlog
|
||||
import cereal.messaging as messaging
|
||||
@@ -106,7 +106,7 @@ def fingerprint(logcan, sendcan):
|
||||
vin, vin_rx_addr = VIN_UNKNOWN, 0
|
||||
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)
|
||||
vin = VIN_UNKNOWN
|
||||
cloudlog.warning("VIN %s", vin)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
import re
|
||||
import struct
|
||||
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)
|
||||
|
||||
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):
|
||||
|
||||
Reference in New Issue
Block a user