3.4.3. UDS Communication¶
The UDS (Unified Diagnostic Services) application layer sits above the transport layer and implements the request-response protocol defined in ISO 14229. It handles service payload construction, response matching, negative response code processing, tester present session keepalive, and functional group communication.
Communication parameters control timing, retry behavior, and tester present generation. These are sourced from the diagnostic database (MDD files) and may vary per logical link.
3.4.3.1. Communication Parameters¶
The UDS application layer is parameterized through a set of communication parameters (COM parameters) that control response timeouts, NRC handling policies, and tester present behavior. These parameters are sourced from the diagnostic database (MDD files) and can vary per logical link. Response Timing Parameters
NRC Handling Parameters
Tester Present Parameters
Note When these parameters are sourced from MDD files, multiple files could define different values for the same logical address due to duplicated logical addresses. |
3.4.3.2. Request-Response Flow¶
The UDS application layer implements the request-response flow using per-ECU semaphores for serialization, a SID-specific lookup table for response matching, and a layered retry strategy split between the UDS and transport layers. Per-ECU Semaphore A semaphore with a permit count of 1 is allocated per ECU logical address. Because the key is the logical address, ECUs that share a logical address (e.g., before variant detection) implicitly share the same semaphore. The semaphore is acquired before the request is sent and held for the entire send-and-receive cycle, including any NRC-driven waiting or retransmission. It is released only after the final response is received or an error occurs. Request Transmission The UDS layer constructs a payload containing the tester source address, target ECU address, and UDS request data. This payload is passed to the selected transport for transmission. Transport-specific transmission failures are returned to the UDS layer. Response Matching Algorithm Before sending, the UDS layer extracts a prefix of the request payload whose length is determined by a SID-to-length lookup table. This prefix is used to match the eventual response:
For a positive response, the first byte equals the sent SID plus NRC 0x78, 0x21, and 0x94 are classified at the transport boundary by the shared
Timeout and Retry Strategy The caller may optionally override the default response timeout. When NRC 0x78 is
received, the active timeout switches from Each application-layer attempt uses a fresh response channel. When an attempt is retried (transmission error, receive error, or plain timeout with no response), the previous attempt’s channel is dropped, which signals the gateway’s per-request task to stop. This ensures a retry is gated solely by that attempt’s own timeout: a late response or error from a prior, superseded attempt can no longer leak into the current attempt and trigger an immediate (sub-timeout) retry. Dropping the previous attempt’s channel only signals its gateway task to stop; it
does not by itself guarantee that task has finished releasing whatever per-ECU
resource it holds (e.g. a DoIP connection mutex, or - for CAN, which has no
equivalent per-connection lock - an ISO-TP socket bound to the same CAN ID pair).
To close that gap,
UDS Request-Response Flow¶ |
3.4.3.3. NRC Handling¶
The UDS application layer implements a dual-loop architecture for handling Negative Response Codes (NRCs). The outer loop handles retransmission (for NRC 0x21 and 0x94), while the inner loop handles continued waiting (for NRC 0x78). Each NRC type has an independent handling policy and timing configuration. Dual-Loop Architecture
NRC 0x78 – Response Pending When the ECU signals NRC 0x78, it has accepted the request but needs more time. The
CDA switches to the enhanced timeout
NRC 0x21 – Busy, Repeat Request When the ECU signals NRC 0x21, it is temporarily busy. The CDA waits for
NRC 0x94 – Temporarily Not Available When the ECU signals NRC 0x94, the requested resource is temporarily unavailable. The
CDA waits for
NRC Classification NRC 0x78, 0x21, and 0x94 are classified at the transport boundary by the shared
NRC Data Flow – End-to-End Classification Pipeline¶ Policy Validation Before acting on any NRC, the CDA validates the handling policy and checks the elapsed time against the configured completion timeout. If the policy is disabled or the timeout has been exceeded, the NRC is reported to the caller as a terminal negative response.
UDS NRC Handling – Dual-Loop Architecture¶ The following diagram shows the complete lifecycle of a UDS response byte from the ECU, through the transport classification, through the UDS retry logic, and finally to the service-layer NRC interpretation:
Complete NRC Response Lifecycle¶ |
3.4.3.4. Tester Present¶
The CDA maintains active diagnostic sessions with ECUs by periodically sending UDS
Tester Present ( Lock-Driven Lifecycle Tester present tasks are tied to the SOVD lock mechanism:
If When a lock is released, the associated tester present tasks are stopped and the ECU’s session and security access state are reset. Duplicate Prevention Active tester present tasks are tracked in a HashMap keyed by ECU name. Before starting a new task, the system checks whether a task already exists for that ECU. Only one tester present task (physical or functional) can be active per ECU at any time. Task Implementation Each tester present task is a background async task that runs a periodic loop:
The interval uses a delay-on-miss strategy: if a tick is missed (e.g., due to slow sending), the next tick is delayed rather than bursting to catch up. Message Format The tester present message is constructed from The target address depends on the tester present type:
Functional Group Resolution When starting functional tester present, the system resolves the functional group to its member ECUs and starts individual tester present tasks for each gateway ECU in the group (ECUs whose logical address equals their gateway address). Each gateway receives its own dedicated background task sending to that gateway’s functional address. Error Handling
COM Parameter Usage All tester present COM parameters are loaded from the diagnostic database per ECU. The tester present task evaluates them as follows:
Note The current implementation uses only
Tester Present – Component Lock¶
Tester Present – Functional Group Lock¶ |
3.4.3.5. Functional Communication¶
The CDA supports functional group communication, where a single UDS request is sent to multiple ECUs simultaneously using functional addressing. ECUs are grouped by their gateway, and each gateway receives one functional request with responses collected from all ECUs behind it in parallel. Functional Group Resolution A functional group is resolved to its member ECUs from the diagnostic database. The following filters are applied:
Grouping by Gateway ECUs in the functional group are grouped by their gateway logical address:
Each gateway group produces one diagnostic request targeted at the gateway’s functional
address (e.g., Parallel Gateway Communication When a functional group spans multiple gateways, the CDA sends to all gateways in parallel. For each gateway, the flow is:
Response Collection After the gateway forwards the functional request, the transport layer
demultiplexes incoming responses by source address. Each ECU behind the gateway has its
own receive channel, allowing responses to be collected concurrently. ECUs that do not
respond within No NRC Handling on Functional Path Unlike physical (unicast) communication, the functional communication path does not implement UDS-level NRC 0x21/0x78/0x94 handling. NRC responses on the functional path are returned as-is to the caller.
UDS Functional Communication Flow¶ |