Skip to main content

Crate uds_protocol

Crate uds_protocol 

Source
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.

Crates.io Docs.rs MIT License APACHE License

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) and uds_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 NameRequest SIDResponse SIDSupport
DiagnosticSessionControl0x100x50✓
EcuReset0x110x51✓
ClearDiagnosticInformation0x140x54✓
ReadDTCInformation0x190x59Partial
ReadDataByIdentifier0x220x62✓
ReadMemoryByAddress0x230x63
ReadScalingDataByIdentifier0x240x64
SecurityAccess0x270x67✓
CommunicationControl0x280x68✓
Authentication0x290x69
ReadDataByPeriodicIdentifier0x2A0x6A
DynamicallyDefineDataIdentifier0x2C0x6C
WriteDataByIdentifier0x2E0x6E✓
InputOutputControlByIdentifier0x2F0x6F
RoutineControl0x310x71✓
RequestDownload0x340x74✓
RequestUpload0x350x75✓
TransferData0x360x76✓
RequestTransferExit0x370x77✓
RequestFileTransfer0x380x78✓
WriteMemoryByAddress0x3D0x7D
TesterPresent0x3E0x7E✓
AccessTimingParameters10x830xC3
SecuredDataTransmission0x840xC4
ControlDtcSetting0x850xC5✓
ResponseOnEvent0x860xC6
LinkControl0x870xC7

§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.

FeatureImpliesWhat it gives you
std (default)allocstd::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.
utoipastd, serdeToSchema for OpenAPI generation.
clapstdValueEnum on the sub-function enums, for building a CLI tester.

Two implications are worth knowing about:

  • utoipa implies serde because a ToSchema here describes the serde representation. Several types serialize as a single protocol byte rather than as their Rust shape — a DataFormatIdentifier is 33, not {"compression_method":2,"encryption_method":1} — and the schemas are written to match. Without serde the schema would describe a wire format that build cannot produce.
  • utoipa and clap imply std because their derive macros expand to std::, String and Vec paths 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 with encoded_size(), via SliceSink).

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.


  1. AccessTimingParameters (0x83) was defined in ISO 14229-1:2013 and removed in the 2020 edition. UdsServiceType still names it so a 2013-era service byte round-trips rather than becoming an unrecognized Other, but it is not part of the standard this crate targets. ↩

Structs§

AddressAndLengthFormatIdentifier
How many bytes the memoryAddress and memorySize parameters occupy on the wire.
ClearDiagnosticInfoRequest
Request for the server to clear diagnostic information
ClearDiagnosticInfoResponse
Positive response to ClearDiagnosticInformation. Carries no payload.
CommunicationControlRequest
Request for the server to change communication behavior
CommunicationControlResponse
Positive response from the server to change communication behavior
ControlDtcSettingRequest
The ControlDtcSetting service is used to control the DTC settings of the ECU.
ControlDtcSettingResponse
Positive response to a ControlDtcSettingRequest
DataFormatIdentifier
The compression method (high nibble) and encryption method (low nibble) a client asks the server to use for a transfer.
DiagnosticSessionControlRequest
Request for the server to change diagnostic session type
DiagnosticSessionControlResponse
Positive response to a DiagnosticSessionControlRequest
DirSizePayload
Used to inform the client of the size of the directory to be transferred
DtcAndStatusIter
Lazy iterator over (DtcRecord, DtcStatusMask) pairs from raw bytes.
DtcFaultDetectionCounterRecord
A DTC paired with its fault detection counter value
DtcFaultDetectionIter
Lazy iterator over DtcFaultDetectionCounterRecord from raw bytes.
DtcRecord
A 3-byte Diagnostic Trouble Code number (high, middle, low bytes).
DtcSeverityMask
GTR DTC Class Information
DtcStatusMask
Bit-packed DTC status information used by the ReadDTCInformation service
DtcStoredDataRecordNumber
Identifies which DTCStoredDataRecord is being requested.
EcuResetRequest
Request for the server to reset the ECU
EcuResetResponse
Positive response to an EcuResetRequest
FileSizePayload
Used to inform the client of the size of the file to be transferred
Incomplete
A read ran out of bytes: needed were required, only available present.
InvalidWidth
A variable-width read/write was requested with an out-of-range byte width.
NamePayload
Payload used for all RequestFileTransferRequest requests.
NegativeResponse
A negative response from the server indicating a request could not be fulfilled.
P2StarServerMax
P2*Server_max, the enhanced response timeout that applies after a NegativeResponseCode::RequestCorrectlyReceivedResponsePending, held as Table 29’s wire count of 10 ms units.
PositionPayload
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
ReadDataByIdentifierRequest
Read-DID request: a list of 16-bit Data Identifiers. Built from native &[u16] or borrowed from the wire as big-endian bytes; dids() yields u16 either way.
ReadDataByIdentifierResponse
Positive response to ReadDataByIdentifier: raw [DID][data record]… bytes.
ReadDtcInfoRequest
Request for the server to report diagnostic trouble code information
RequestDownloadRequest
A request to the server for it to download data from the client.
RequestDownloadResponse
Zero-alloc positive response to a RequestDownloadRequest, indicating the server is ready to receive data. Borrows from the caller.
RequestTransferExitRequest
Request to exit a transfer, carrying an optional parameter record.
RequestTransferExitResponse
Positive response to RequestTransferExit, carrying an optional parameter record.
RequestUploadRequest
A request to the server for it to upload data to the client.
RequestUploadResponse
Zero-alloc positive response to a RequestUploadRequest, indicating the server is ready to transmit data. Borrows from the caller.
RoutineControlRequest
Used by a client to execute a defined sequence of events and obtain any relevant results.
RoutineControlResponse
RoutineControlResponse is a variable-length response that can contain routine status.
SecurityAccessLevel
One vehicle-manufacturer security level: the requestSeed/sendKey pair of ISO 14229-1:2020 Table 42, named by its requestSeed sub-function.
SecurityAccessRequest
Client request to access a security level
SecurityAccessResponse
Zero-alloc response for security access. Borrows from the caller.
SentDataPayload
Sent by the server to inform the client of the maximum number of bytes to include in each TransferData request message
SizePayload
Holds the sizes of the file to be transferred (if applicable) Used for both RequestFileTransferRequest and RequestFileTransferResponse
TesterPresentRequest
Request to indicate the client is still connected
TesterPresentResponse
Positive response to a TesterPresentRequest
TrailingBytes
Bytes remained after a decode_exact that should have consumed the whole buffer.
TransferDataRequest
A request to the server to transfer data (either upload or download)
TransferDataResponse
Zero-alloc response for transfer data. Borrows from the caller.
WriteDataByIdentifierRequest
Zero-alloc request to write data by identifier. Borrows the data record from the caller.
WriteDataByIdentifierResponse
Positive response to WriteDataByIdentifier: echoes the DID that was written.
WwhObdDtcSeverityIter
Lazy iterator over the WWH-OBD (DtcSeverityMask, DtcRecord, DtcStatusMask) triples of a ReadDtcInfoResponse::WwhObdDtcByMaskRecord (sub-function 0x42).

Enums§

CommunicationControlType
CommunicationControlType is used to specify the type of communication behavior to be modified
CommunicationType
Which messages the control applies to — the low nibble (bits 3-0) of the communicationType byte.
DiagnosticSessionType
DiagnosticSessionType is used to specify or describe the session type of the server
DtcCountReport
The report types whose response is a DTC count (ISO 14229-1:2020 Table 319).
DtcExtDataRecordNumber
The DtcExtDataRecordNumber is used in the request message to get a stored DTCExtDataRecord It’s used to specify the type of DTCExtDataRecord to be reported.
DtcFormatIdentifier
Specifies the format of the DTC reported by the server.
DtcListReport
The report types whose response is a list of DTCs and their status (ISO 14229-1:2020 Table 320).
DtcSettingType
Controls whether the server should enable or disable DTC status-bit updates.
DtcSeverityReport
The report types whose response is a list of DTC severity records (ISO 14229-1:2020 Table 325).
DtcSnapshotRecordNumber
Identifies which DTC snapshot record is being requested or reported.
Error
Errors that can occur during UDS message encoding, decoding, or validation.
FileOperationMode
Mode of operation for file transfer requests
FunctionalGroupIdentifier
Used to distinguish commands sent by the test equipment between different functional system groups within an electrical architecture which consists of many different servers.
NegativeResponseCode
A negative response code: ISO 14229-1:2020 Table A.1, every byte of it.
ReadDtcInfoReportType
A ReadDTCInformation report type, without the parameters it carries.
ReadDtcInfoResponse
Zero-copy parsed response for ReadDTCInformation (0x19).
ReadDtcInfoSubFunction
Subfunctions for the ReadDTCInformation service
Request
Zero-copy parsed request. Borrows from the wire buffer.
RequestFileTransferRequest
A request to the server to transfer a file, either upload or download.
RequestFileTransferResponse
Response to a RequestFileTransferRequest from the server
ResetType
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.
RoutineControlSubFunction
What type of routine control to perform for a RoutineControlRequest.
SecurityAccessType
Security Access Type allows for multiple different security challenges within an ECU.
SubnetNumber
Which network the communicationType byte applies to — its high nibble (bits 7-4).
UdsIdentifier
C.1 DID - Diagnostic Data Identifier specified in ISO 14229-1
UdsRoutineIdentifier
Standard UDS Routine Identifier for the RoutineControl (0x31, 0x71) service
UdsServiceType
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 as buf lives.
DecodeIter
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 self into a Sink.