πŸ— Wiki

UDS

Unified Diagonistic Services

UDS: Unified Diagonistic Services

Unified Diagnostic Services (UDS) is a diagnostic communication protocol used in electronic control units (ECUs) within automotive electronics

Not all ECUs with CAN or Ethernet have UDS services. And UDS is standardized by ISO-14229-1, but sometimes there are non standard features. It really depends on car manufacturers, projects and car models.

1. Standard

1.1. Services

SID; Service ID Service Name

0x10

Diagnostic Session Control

0x11

ECU Reset

0x14

Clear Diagnostic Information

0x19

Read DTC Information

0x22

Read Data By Identifier

0x23

Read Memory By Address

0x24

Read Scaling Data By Identifier

0x27

Security Access

0x28

Communication Control

0x2A

Read Data by Periodic ID

0x2E

Write Data By Identifier

0x2F

Input Output Control By Identifier

0x31

Routine Control

0x34

Request Download

0x35

Request Upload

0x36

Transfer Data

0x37

Transfer Exit

0x3D

Write Memory By Address

0x3E

Tester Present

0x85

Control DTC Setting

0x87

Link Control

1.2. NRCs

NRC is the abbreviation for Negative Response Code.

NRC Code Description

0x10

General reject

0x11

Service not supported

0x12

Subfunction not supported

0x13

Incorrect message length or invalid format

0x14

Response too long

0x21

Busy, repeat request

0x22

Conditions not correct

0x24

Request sequence error

0x26

Failure prevents execution of requested action

0x31

Request out of range

0x33

Security access denied

0x34

Authentication failed

0x35

Invalid key

0x36

Exceeded number of attempts

0x37

Required time delay not expired

0x78

Request correctly received, response pending

0x7E

Subfunction not supported in active session

0x7F

Service not supported in active session

0x81

RPM too high

0x82

RPM too low

0x83

Engine is running

0x84

Engine is not running

0x85

Engine run time too low

0x86

Temperature too high

0x87

Temperature too low

0x88

Vehicle speed too high

0x89

Vehicle speed too low

0x8A

Throttle/pedal too high

0x8B

Throttle/pedal too low

0x8C

Transmission range not in neutral

0x8D

Transmission range not in gear

0x8F

Brake switch not closed

0x90

Shifter lever not in park

0x91

Torque converter clutch locked

0x92

Voltage too high

0x93

Voltage too low

0x94

Resource temporary unavailable

2. Programming libraries

2.1. Dissecting UDS data using python-udsoncan

I wanted to know which data will be transfered when one have to diagnose cars. In this example, I’ll use python-udsoncan.

pip install python-udsoncan

Let’s find out the session control.

import udsoncan
from udsoncan.services import DiagnosticSessionControl

paylaod = udsoncan.Request(service=DiagnosticSessionControl, subfunction=DiagnosticSessionControl.Session.extendedDiagnosticSession).get_payload()
print(payload)  # b'\x10\x03'

To request to control the session, the service name 'Diagnostic Session Control, the SID should be 0x10.

Some services require a subfunction number, which is 3, an extended diagnostic session, in this case.

It is even possible to dissect raw data, a trail of bytes, using Response.from_payload() or Request.from_payload().

import udsoncan

udsoncan.Request.from_payload(b'\x10\x03')
# <Request: [DiagnosticSessionControl] (subfunction=3) - 0 data bytes at 0x2458eb0d160>

udsoncan.Response.from_payload(b'\x50\x03\x00\x11\x22\x33\x44')
# <PositiveResponse: [DiagnosticSessionControl] - 6 data bytes at 0x2458ec6b800>

3. Simulator

This clever and smart guy invented simple and useful UDS simulators:

Both UDSim and uds-server have limited protocol emulation. But in UDSim you can write a configuration file to extend it.

3.1. Setting up a SocketCAN interface in Linux

sudo modprobe can
sudo modprobe vcan

sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0

4. Reference