โ ๏ธ This project is not maintained anymore :( It is kept here only for reference. Thanks for the feedbacks :)
This Python tool simulates some vehicle diagnostic services. It can be used to test OBD-II dongles or tester tools that support the UDS (ISO 14229) and ISO-TP (ISO 15765-2) protocols.
This tool does NOT implement the ISO-TP protocol. It just simulates a couple of OBD and UDS services. The simulation consists in receiving a diagnostic request (e.g., Request DTCs (0x03)), and responding to it according to the protocol specifications. The data of some responses (e.g., VIN) must be defined in the ecu_config.json
file.
I created this project to learn more about the OBD and UDS protocols. I did my best to understand the specifications, however, if you suspect that something is implemented wrongly, please let me know. Any feedback will be very appreciated.
Service | PID | Description |
---|---|---|
0x01 | 0x00 | List of supported PIDs in service 0x01 |
0x01 | 0x05 | Engine coolant temperature |
0x01 | 0x0D | Vehicle speed |
0x01 | 0x2F | Fuel tank level input |
0x01 | 0x51 | Fuel type |
0x03 | - | Request DTCs |
0x09 | 0x00 | List of supported PIDs in service 0x09 |
0x09 | 0x02 | Vehicle Identification Number (VIN) |
0x09 | 0x0A | ECU name |
Service ID | Name | Supported sub-functions | Default parameters (response) |
---|---|---|---|
0x10 | DiagnosticSessionControl | session types 0x01 default 0x02 programming 0x03 extended 0x04 safety |
|
0x11 | ECUReset | reset types 0x01 hardReset 0x02 keyOffOnReset 0x03 softReset 0x04 enableRapidPowerShutDown 0x05 disableRapidPowerShutDown |
0x0F powerDownTime |
0x19 | ReadDTCInformation | report types 0x02 reportDTCByStatusMask |
0xFF DTCStatusAvailabilityMask 0x2F statusOfDTC |
OBD: Functional and physical. See options obd_broadcast_address
and obd_ecu_address
in ecu_config.json
.
UDS: Physical. See option uds_ecu_address
in ecu_config.json
.
In both cases, only ISO-TP normal addressing (only CAN arbitration ID is used) is supported.
- Python3
- SocketCAN Implementation of the CAN protocol. This kernel module is part of Linux.
- ISO-TP kernel module It is NOT part of linux. It needs to be loaded before running the
ecu-simulator
. Seeisotp_ko_file_path
inecu_config.json
. - isotp The
ecu-simulator
only uses isotp.socket, which is a wrapper for the ISO-TP kernel module. - python-can The
ecu-simulator
uses this library to log CAN messages (seeloggers\logger_can.py
). Note: The bus typesocketcan_native
is used.
The ecu-simulator
sets up the CAN interface and loads the ISO-TP linux kernel module (you need to configure can_interface
, can_interface_type
, can_bitrate
, and isotp_ko_file_path
in ecu_config.json
). To perform this task, the tool must be started with root privileges:
sudo python3 ecu-simulator.py
If you do not want to start the tool with root privileges, you can do the following:
# set up CAN hardware interface
sudo sh setup_can.sh <CAN interface e.g., can0> <CAN bitrate e.g., 500000> <can-isotp.ko file pyth e.g., /lib/modules/4.19.75-v7+/kernel/net/can/can-isotp.ko>
# or set up CAN virtual interface
sudo sh setup_vcan.sh <virtual CAN interface e.g., vcan0> <can-isotp.ko file pyth e.g., /lib/modules/4.19.75-v7+/kernel/net/can/can-isotp.ko>
# and then start the tool without sudo
python3 ecu_simulator.py
The ecu-simulator
provides 3 levels of logging: CAN, ISO-TP, and application level. For example, when the VIN is requested, the following is logged:
- In
can_[Timestamp].log
2020-02-05T13:08:39.188 can0 0x7df 0x0209020000000000
2020-02-05T13:08:39.192 can0 0x7e8 0x1014490200544553
2020-02-05T13:08:39.192 can0 0x7e0 0x3000050000000000
2020-02-05T13:08:39.198 can0 0x7e8 0x215456494e303132
2020-02-05T13:08:39.203 can0 0x7e8 0x2233343536373839
- In
isotp_[Timestamp].log
2020-02-05T13:08:39.498 can0 0x7df 0x0902
2020-02-05T13:08:39.499 can0 0x7e8 0x4902005445535456494e30313233343536373839
- In
ecu_simulator.log
2020-02-05T13:08:39.189 - ecu_simulator - INFO - Receiving on OBD address 0x7df from 0x7e8 Request: 0x0902
2020-02-05T13:08:39.190 - ecu_simulator - INFO - Requested OBD SID 0x9: Request vehicle information
2020-02-05T13:08:39.191 - ecu_simulator - INFO - Requested PID 0x2: Vehicle Identification Number(VIN)
2020-02-05T13:08:39.191 - ecu_simulator - INFO - Sending to 0x7e8 Response: 0x4902005445535456494e30313233343536373839
The log files have a max size of 1.5 M. A new log file is generated when this size is reached.
The ecu-simulator
was tested on a Raspberry Pi (Raspbian, Linux Kernel 4.19) with PiCAN and SBC-CAN01 (see pic below) as CAN-Bus board.
The OBD-II services were tested using a real OBD-II scanner.
To test the UDS services, the Caring Caribou tool was used.
MIT License
Copyright (c) 2020 Luis Alberto Benthin Sanguino
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.