Expand description
§uds_protocol
uds_protocol owns ISO 14229-1:2020’s message format: encoding and decoding UDS
requests and responses. It targets embedded ECU diagnostics and desktop
tooling alike — no_std and allocation-free at its core, with no required
allocator and no async runtime.
This library is built against ISO 14229-1:2020. In its documentation and source, a table, figure, clause or requirement cited with no document named is that one’s, and any other document is named where it is cited.
§Where this fits
uds_protocol is the bottom of the stack described in the
uds_stack workspace README: the
message format that everything above it builds on. It has no dependency on any
other crate in the stack.
uds_session(ISO 14229-2) sits beside it in the stack but does not depend on it — the session layer never reads a message’s content.uds_services(ISO 14229-1’s behaviour, to this crate’s format) anduds_on_ip(ISO 14229-5) both depend on this crate directly: they dispatch and transport the message types this crate encodes and decodes.
§What this crate does not do
It is a synchronous, allocation-free codec, and nothing more. It owns no
sockets, buffers, or async runtime; it does not dispatch a request to a
handler, choose a negative response code, or hold any session state. Driving
the I/O loop, over DoIP, UDSonIP, ISO-TP, or anything else, is a caller’s
job — see uds_services
for the layer that owns dispatch.
| Service Name | Request SID | Response SID | Support |
|---|---|---|---|
DiagnosticSessionControl | 0x10 | 0x50 | ✓ |
EcuReset | 0x11 | 0x51 | ✓ |
ClearDiagnosticInformation | 0x14 | 0x54 | ✓ |
ReadDTCInformation | 0x19 | 0x59 | Partial |
ReadDataByIdentifier | 0x22 | 0x62 | ✓ |
ReadMemoryByAddress | 0x23 | 0x63 | |
ReadScalingDataByIdentifier | 0x24 | 0x64 | |
SecurityAccess | 0x27 | 0x67 | ✓ |
CommunicationControl | 0x28 | 0x68 | ✓ |
Authentication | 0x29 | 0x69 | |
ReadDataByPeriodicIdentifier | 0x2A | 0x6A | |
DynamicallyDefineDataIdentifier | 0x2C | 0x6C | |
WriteDataByIdentifier | 0x2E | 0x6E | ✓ |
InputOutputControlByIdentifier | 0x2F | 0x6F | |
RoutineControl | 0x31 | 0x71 | ✓ |
RequestDownload | 0x34 | 0x74 | ✓ |
RequestUpload | 0x35 | 0x75 | ✓ |
TransferData | 0x36 | 0x76 | ✓ |
RequestTransferExit | 0x37 | 0x77 | ✓ |
RequestFileTransfer | 0x38 | 0x78 | ✓ |
WriteMemoryByAddress | 0x3D | 0x7D | |
TesterPresent | 0x3E | 0x7E | ✓ |
AccessTimingParameters1 | 0x83 | 0xC3 | |
SecuredDataTransmission | 0x84 | 0xC4 | |
ControlDtcSetting | 0x85 | 0xC5 | ✓ |
ResponseOnEvent | 0x86 | 0xC6 | |
LinkControl | 0x87 | 0xC7 |
§no_std support
The crate is no_std and allocation-free at its core; everything below is
additive. Encoding and decoding work with borrowed slices alone — no service in
the table above needs an allocator to be represented.
§Features
Default is std.
| Feature | Implies | What it gives you |
|---|---|---|
std (default) | alloc | std::error::Error for Error. Turn it off for bare metal. |
alloc | — | The alloc-only conveniences. Nothing in the wire codec needs it; encoding and decoding work with borrowed slices alone. |
serde | — | Serialize/Deserialize on the request, response and parameter types. The only optional integration usable on a bare-metal target: it is wired as a core-only dependency and picks up serde’s alloc/std layers only when this crate’s own are on. |
utoipa | std, serde | ToSchema for OpenAPI generation. |
clap | std | ValueEnum on the sub-function enums, for building a CLI tester. |
Two implications are worth knowing about:
utoipaimpliesserdebecause aToSchemahere describes theserderepresentation. Several types serialize as a single protocol byte rather than as their Rust shape — aDataFormatIdentifieris33, not{"compression_method":2,"encryption_method":1}— and the schemas are written to match. Withoutserdethe schema would describe a wire format that build cannot produce.utoipaandclapimplystdbecause their derive macros expand tostd::,StringandVecpaths inside this crate, which cannot compile under#![no_std].
With serde enabled, the types that carry a range invariant deserialize through the same
classifier the wire decoder uses, so a hand-written payload cannot construct a value that would
encode to an illegal byte.
§Usage
uds_protocol is a synchronous, allocation-free codec. It owns no sockets, buffers, or
async runtime. To use it over any transport (DoIP, UDSonIP, ISO-TP, …):
- Decode an inbound frame from the
&[u8]you received. - Encode an outbound frame into any
automotive_wire_codec::Sink(or a caller-owned buffer sized withencoded_size(), viaSliceSink).
Drive the I/O loop from your own sync or async layer — the crate never blocks or awaits.
§Encode (build a request)
use automotive_wire_codec::SliceSink;
use uds_protocol::{Encode, TesterPresentRequest};
let req = TesterPresentRequest::new(false);
let mut buf = [0u8; 8];
let mut sink = SliceSink::new(&mut buf);
let written = Encode::encode(&req, &mut sink).unwrap();
// `buf[..written]` is the wire frame, ready to hand to your transport.§Decode (parse a response)
use uds_protocol::{Decode, Response};
// `frame` is the &[u8] your transport handed you.
let frame = [0x7E, 0x00];
let (response, _rest) = Response::decode(&frame).unwrap();The decoded value borrows from frame: it points into that buffer (like a struct
overlaid on a char buf[]) and is valid only while frame lives. Copy out any fields
you need to keep before the buffer is reused.
§Service coverage
A checkmark in the table above means the service decodes into a typed
Request/Response variant; NegativeResponse is typed as well. Every
other service UdsServiceType enumerates decodes into Request::Other /
Response::Other, carrying the service type and the raw payload bytes for
pass-through — an unmodelled service is handed to you intact rather than
rejected.
§Wire codec dependency
uds_protocol builds its byte-level decoding on top of the automotive-wire-codec
crate, and re-exports its Incomplete, TrailingBytes and InvalidWidth types and its codec
traits (Encode, Decode, DecodeIter) at the crate root. These types are intentionally part of uds_protocol’s public API:
they are shared across the Luminar automotive protocol crates so that callers handling multiple
protocols see one consistent short-read/trailing-data error shape. Because of this, a semver-major
release of automotive-wire-codec is a breaking change for uds_protocol as well.
§Status
Under active development. Released in lockstep with the rest of the stack, at
one shared version. See the
workspace README for where
the other crates stand. The service coverage table above is the honest measure
of what is implemented today; a request without a checkmark decodes as
Request::Other rather than failing.
§Contributing
Pull requests, bug reports and questions are welcome — see
CONTRIBUTING.md.
Security reports go through GitHub’s private vulnerability reporting; see
SECURITY.md.
§Licence
Licensed under either of MIT or Apache-2.0 at your option. Both files are the workspace’s, shared by every crate here.
Neither licence grants any right in ISO 14229-1 itself, which remains ISO’s — see Relationship to the standards in the workspace README.
AccessTimingParameters(0x83) was defined in ISO 14229-1:2013 and removed in the 2020 edition.UdsServiceTypestill names it so a 2013-era service byte round-trips rather than becoming an unrecognizedOther, but it is not part of the standard this crate targets. ↩
Structs§
- Address
AndLength Format Identifier - How many bytes the
memoryAddressandmemorySizeparameters occupy on the wire. - Clear
Diagnostic Info Request - Request for the server to clear diagnostic information
- Clear
Diagnostic Info Response - Positive response to
ClearDiagnosticInformation. Carries no payload. - Communication
Control Request - Request for the server to change communication behavior
- Communication
Control Response - Positive response from the server to change communication behavior
- Control
DtcSetting Request - The
ControlDtcSettingservice is used to control the DTC settings of the ECU. - Control
DtcSetting Response - Positive response to a
ControlDtcSettingRequest - Data
Format Identifier - The compression method (high nibble) and encryption method (low nibble) a client asks the server to use for a transfer.
- Diagnostic
Session Control Request - Request for the server to change diagnostic session type
- Diagnostic
Session Control Response - Positive response to a
DiagnosticSessionControlRequest - DirSize
Payload - Used to inform the client of the size of the directory to be transferred
- DtcAnd
Status Iter - Lazy iterator over
(DtcRecord, DtcStatusMask)pairs from raw bytes. - DtcFault
Detection Counter Record - A DTC paired with its fault detection counter value
- DtcFault
Detection Iter - Lazy iterator over
DtcFaultDetectionCounterRecordfrom raw bytes. - DtcRecord
- A 3-byte Diagnostic Trouble Code number (high, middle, low bytes).
- DtcSeverity
Mask - GTR DTC Class Information
- DtcStatus
Mask - Bit-packed DTC status information used by the
ReadDTCInformationservice - DtcStored
Data Record Number - Identifies which
DTCStoredDataRecordis being requested. - EcuReset
Request - Request for the server to reset the ECU
- EcuReset
Response - Positive response to an
EcuResetRequest - File
Size Payload - Used to inform the client of the size of the file to be transferred
- Incomplete
- A read ran out of bytes:
neededwere required, onlyavailablepresent. - Invalid
Width - A variable-width read/write was requested with an out-of-range byte width.
- Name
Payload - Payload used for all
RequestFileTransferRequestrequests. - Negative
Response - A negative response from the server indicating a request could not be fulfilled.
- P2Star
Server Max P2*Server_max, the enhanced response timeout that applies after aNegativeResponseCode::RequestCorrectlyReceivedResponsePending, held as Table 29’s wire count of 10 ms units.- Position
Payload - Used to inform the client of the byte position within the file at which the Tester will resume downloading after an initial download is suspended
- Read
Data ByIdentifier Request - Read-DID request: a list of 16-bit Data Identifiers. Built from native
&[u16]or borrowed from the wire as big-endian bytes;dids()yieldsu16either way. - Read
Data ByIdentifier Response - Positive response to
ReadDataByIdentifier: raw[DID][data record]…bytes. - Read
DtcInfo Request - Request for the server to report diagnostic trouble code information
- Request
Download Request - A request to the server for it to download data from the client.
- Request
Download Response - Zero-alloc positive response to a
RequestDownloadRequest, indicating the server is ready to receive data. Borrows from the caller. - Request
Transfer Exit Request - Request to exit a transfer, carrying an optional parameter record.
- Request
Transfer Exit Response - Positive response to
RequestTransferExit, carrying an optional parameter record. - Request
Upload Request - A request to the server for it to upload data to the client.
- Request
Upload Response - Zero-alloc positive response to a
RequestUploadRequest, indicating the server is ready to transmit data. Borrows from the caller. - Routine
Control Request - Used by a client to execute a defined sequence of events and obtain any relevant results.
- Routine
Control Response RoutineControlResponseis a variable-length response that can contain routine status.- Security
Access Level - One vehicle-manufacturer security level: the
requestSeed/sendKeypair of ISO 14229-1:2020 Table 42, named by itsrequestSeedsub-function. - Security
Access Request - Client request to access a security level
- Security
Access Response - Zero-alloc response for security access. Borrows from the caller.
- Sent
Data Payload - Sent by the server to inform the client of the maximum number of bytes to include in
each
TransferDatarequest message - Size
Payload - Holds the sizes of the file to be transferred (if applicable)
Used for both
RequestFileTransferRequestandRequestFileTransferResponse - Tester
Present Request - Request to indicate the client is still connected
- Tester
Present Response - Positive response to a
TesterPresentRequest - Trailing
Bytes - Bytes remained after a
decode_exactthat should have consumed the whole buffer. - Transfer
Data Request - A request to the server to transfer data (either upload or download)
- Transfer
Data Response - Zero-alloc response for transfer data. Borrows from the caller.
- Write
Data ByIdentifier Request - Zero-alloc request to write data by identifier. Borrows the data record from the caller.
- Write
Data ByIdentifier Response - Positive response to
WriteDataByIdentifier: echoes the DID that was written. - WwhObd
DtcSeverity Iter - Lazy iterator over the WWH-OBD
(DtcSeverityMask, DtcRecord, DtcStatusMask)triples of aReadDtcInfoResponse::WwhObdDtcByMaskRecord(sub-function0x42).
Enums§
- Communication
Control Type CommunicationControlTypeis used to specify the type of communication behavior to be modified- Communication
Type - Which messages the control applies to — the low nibble (bits 3-0) of the
communicationTypebyte. - Diagnostic
Session Type DiagnosticSessionTypeis used to specify or describe the session type of the server- DtcCount
Report - The report types whose response is a DTC count (ISO 14229-1:2020 Table 319).
- DtcExt
Data Record Number - The
DtcExtDataRecordNumberis used in the request message to get a storedDTCExtDataRecordIt’s used to specify the type ofDTCExtDataRecordto be reported. - DtcFormat
Identifier - Specifies the format of the DTC reported by the server.
- DtcList
Report - The report types whose response is a list of DTCs and their status (ISO 14229-1:2020 Table 320).
- DtcSetting
Type - Controls whether the server should enable or disable DTC status-bit updates.
- DtcSeverity
Report - The report types whose response is a list of DTC severity records (ISO 14229-1:2020 Table 325).
- DtcSnapshot
Record Number - Identifies which DTC snapshot record is being requested or reported.
- Error
- Errors that can occur during UDS message encoding, decoding, or validation.
- File
Operation Mode - Mode of operation for file transfer requests
- Functional
Group Identifier - Used to distinguish commands sent by the test equipment between different functional system groups within an electrical architecture which consists of many different servers.
- Negative
Response Code - A negative response code: ISO 14229-1:2020 Table A.1, every byte of it.
- Read
DtcInfo Report Type - A
ReadDTCInformationreport type, without the parameters it carries. - Read
DtcInfo Response - Zero-copy parsed response for
ReadDTCInformation(0x19). - Read
DtcInfo SubFunction - Subfunctions for the
ReadDTCInformationservice - Request
- Zero-copy parsed request. Borrows from the wire buffer.
- Request
File Transfer Request - A request to the server to transfer a file, either upload or download.
- Request
File Transfer Response - Response to a
RequestFileTransferRequestfrom the server - Reset
Type - UDS defines a number of different types of resets that can be requested The reset type is used to specify the type of reset that the ECU should perform
- Response
- Parsed zero-copy UDS response. Borrows from the wire buffer.
- Routine
Control SubFunction - What type of routine control to perform for a
RoutineControlRequest. - Security
Access Type - Security Access Type allows for multiple different security challenges within an ECU.
- Subnet
Number - Which network the
communicationTypebyte applies to — its high nibble (bits 7-4). - UdsIdentifier
- C.1 DID - Diagnostic Data Identifier specified in ISO 14229-1
- UdsRoutine
Identifier - Standard UDS Routine Identifier for the
RoutineControl(0x31, 0x71) service - UdsService
Type - Identifies a UDS service (ISO 14229-1).
Constants§
- CLEAR_
ALL_ DTCS - Use to clear all DTCs in a
crate::ClearDiagnosticInfoRequest
Traits§
- Decode
- RX-side: zero-copy decode borrowing from
buf. The value is valid only as long asbuflives. - Decode
Iter - RX-side: decode a sequence of same-typed elements from a buffer. Implement this only for protocols that have repeated elements (e.g. a UDS DTC record list).
- Encode
- TX-side: serialize
selfinto aSink.