DoIP

Discover vehicles with await discover() and connect using await vehicle.connect(). For known ECUs, use await DoIP.connect("192.168.0.10", 0x1000). DoIP implements the same Transport used by UDSClient; it needs no CAN adapter.

from automotive.protocols.uds import DataIdentifier, UDSClient
from automotive.transports.doip import discover

for vehicle in await discover():
    async with await vehicle.connect() as transport:
        print(await UDSClient(transport).read_data_by_identifier(DataIdentifier.VIN))

Defaults trigger IPv4 identification, collect unique vehicles for two seconds per request, and use tester address 0x0E00. Incomplete VIN/GID synchronization with a valid VIN or GID starts a five-second per-vehicle timer. After expiry, discovery sends another identification request and collects fresh responses. Duplicate responses do not restart the timer; DiscoveryConfig.timeout controls each response window, so synchronization can extend the total discovery time. DoIPConfig and DiscoveryConfig provide optional overrides. Discovery uses version 255; connections to discovered vehicles adopt the advertised version, while direct connections default to version 2.

For passive announcements, use async with await Discovery.listen() as listener and await listener.recv(). This binds port 13400 and sends no request. Discovery.bind() instead uses a dynamic source port; request() triggers identification and recv() receives replies. Bind before sending or powering up an ECU. Passive IPv4 reception binds all adapters by default.

IPv6 multicast requires DiscoveryConfig.ipv6(interface_index); numeric IPv6 interface indices work on Windows and Unix. Link-local endpoints retain their scope ID (fe80::1%7). Ordinary TCP connections follow OS routing, with optional source-IP binding through DoIPConfig.local_address. Active IPv4 discovery can bind a source endpoint and target a subnet-directed broadcast on multihomed hosts. Neither raw sockets nor administrator privileges are required.

For a real ECU bench on Linux, sudo scripts/set_up_doip.sh eth0 configures temporary static tester addresses 169.254.0.1/16 and fe80::1/64. Its positional arguments accept another adapter and IPv4/IPv6 CIDRs; choose unique tester addresses and the ECU’s IPv4 subnet. From python/, run uv run examples/doip.py --ipv4 --discovery active --local-address 169.254.0.1/16 to read VIN through UDS DID 0xF190. Substitute --ipv6 --adapter eth0 and/or --discovery passive to exercise the other combinations. Passive mode keeps listening until Ctrl+C; start it before powering up the ECU. Active IPv4 requires --local-address, e.g. 169.254.0.1/16, to select its source IP and derive the broadcast. Passive IPv4 needs no local address: it uses wildcard reception and TCP follows OS routing. Allow incoming UDP port 13400 on each interface receiving announcements; the setup script’s firewall rules apply only to its selected adapter. IPv4 needs no adapter name; IPv6 requires --adapter for link-local multicast. These examples default to tester address 0x0E89 (override with --source-address); the API default remains 0x0E00. The blocking examples/sync/doip.py and Rust examples/doip.rs take the same arguments. The setup script marks the adapter unmanaged when NetworkManager is running; restore it after testing with sudo nmcli device set eth0 managed yes. It also adds adapter-specific iptables/ip6tables rules, when available, for UDP announcement port 13400 and active reply ports 49152–65535. These rules are needed when a stateful firewall drops unicast replies to multicast/broadcast requests; they last until firewall reload/reboot.

Alive checks are answered in the background, even when UDS is idle. Serialize UDS exchanges on each connection. After a transport timeout, malformed TCP message, or cancellation with a UDS reply outstanding, reconnect before issuing another exchange. Requests are never automatically replayed. DoIPError.code preserves routing activation and NACK wire codes, separately from UDS NRCs.

The transport supports unsecured TCP and physical ECU addressing. TLS, manufacturer authentication/confirmation workflows, entity-status/power-mode queries, periodic payload 0x8004, and functional response collection are not implemented. A routing activation response requiring TLS or confirmation raises DoIPError instead of opening an incomplete diagnostic session.

Asynchronous API

DoIP discovery and UDS transport over IPv4 or IPv6, implemented in Rust.

await discover() triggers vehicle identification with no configuration. Connect to a result with await vehicle.connect() or use await DoIP.connect("192.168.0.10", 0x1000) for a known ECU.

class automotive.transports.doip.Discovery(native: R)[source]

Bound UDP socket for passive announcements or explicitly triggered requests.

Use bind() for an active socket, or listen() for passive announcements on port 13400. request() sends identification; recv() waits without transmitting. Closing wakes pending operations. Context management releases the socket.

async classmethod bind(config: DiscoveryConfig | None = None) → Self[source]

Open a discovery socket before sending; defaults to an ephemeral IPv4 port.

async classmethod listen(config: DiscoveryConfig | None = None) → Self[source]

Listen on announcement port 13400, sending no request; IPv4 by default.

property local_address: str

Bound local IP/port, including the dynamically assigned request port.

async request() → None[source]

Send the configured all-vehicle, VIN, or EID identification request.

async recv() → VehicleAnnouncement[source]

Receive one announcement indefinitely; cancellation safely resumes later.

async aclose() → None

Release hardware and wake pending operations; repeated calls are safe.

property closed: bool

Whether this resource or its owning parent has been closed.

class automotive.transports.doip.DiscoveryConfig(*, bind_address: str = '0.0.0.0:0', destination: str = '255.255.255.255:13400', interface_index: int | None = None, protocol_version: int = 255, vin: bytes | None = None, eid: bytes | None = None, timeout: float = 2.0, reuse_address: bool = False)[source]

Optional discovery overrides, using IP endpoints with explicit ports.

Defaults send IPv4 limited broadcast from an ephemeral source port and collect responses for two seconds per request. Incomplete VIN/GID synchronization with a valid VIN or GID adds a five-second per-vehicle wait, then another request and collection window. Duplicate responses do not restart that timer. Set bind_address to select a local source IP; a subnet-directed broadcast destination can select the route on a multihomed host. Passive IPv4 reception normally binds 0.0.0.0:13400 to receive announcements from all adapters. IPv6 multicast requires an OS interface index, supplied by ipv6(index). Both work on Windows and Unix.

vin (17 raw bytes) and eid (six bytes) select identification request variants and filter replies; they are mutually exclusive. Version 255 discovers all supported versions. timeout is the response collection window in seconds after each request. Socket sharing is opt-in; Windows may distribute unicast packets among shared listeners.

classmethod ipv6(interface_index: int) → Self[source]

Use ff02::1 multicast on an explicitly selected IPv6 adapter.

passive() → Self[source]

Return settings binding announcement port 13400 instead of port zero.

class automotive.transports.doip.DoIP(native: R)[source]

A routed TCP connection carrying complete UDS PDUs.

Alive checks are handled even while idle. send() waits for a matching DoIP ACK; UDS replies arrive through recv(). Create raw receivers before sending. Serialize UDS exchanges on each connection. Reconnect after a transport timeout, malformed TCP message, or cancellation with a response outstanding; diagnostic requests are never replayed automatically. A subscription that falls behind raises DoIPError instead of silently losing responses.

async classmethod connect(host: str, target_address: int, *, port: int = 13400, config: DoIPConfig | None = None) → Self[source]

Connect and activate routing; only host and ECU logical address are required.

Host can be an IPv4/IPv6 address or DNS name. Use a numeric scope on link-local IPv6, e.g. fe80::1%7. OS routing selects the adapter unless config.local_address binds a source endpoint.

async aclose() → None

Release hardware and wake pending operations; repeated calls are safe.

property closed: bool

Whether this resource or its owning parent has been closed.

recv() → Receiver[bytes]

Subscribe immediately to complete received PDUs as bytes.

Returns:

An async iterator with aclose and async context management.

Subscribe before sending. Closing this receiver releases its subscription. A receive deadline raises TimeoutError; another anext may continue.

async send(data: bytes | bytearray | memoryview) → None

Transmit one complete PDU using the transport’s framing and limits.

Parameters:

data – Bytes, bytearray, or contiguous byte-oriented memoryview.

Transport failures raise the corresponding protocol or connection error. A transmission deadline raises TimeoutError.

class automotive.transports.doip.DoIPConfig(*, source_address: int = 3584, protocol_version: int = 2, activation_type: int = 0, activation_oem: bytes | None = None, local_address: str | None = None, connect_timeout: float = 2.0, activation_timeout: float = 2.0, ack_timeout: float = 2.0, max_payload_size: int = 4194304)[source]

Optional TCP overrides; the target ECU address is supplied to connect().

local_address selects a source IP/port, e.g. 192.168.0.2:0 or [fe80::2%7]:0. Omit it to follow OS routing. IPv6 link-local endpoints need their numeric interface scope. Default tester address is 0x0E00. protocol_version supports 2, 3, and 4; 2 favors deployed-ECU compatibility. Timeouts are seconds; activation and ACK waits default to ISO’s two seconds. activation_oem is an optional four-byte manufacturer record. max_payload_size includes logical addresses and bounds peer allocation. TLS and manufacturer-specific authentication are not implemented.

class automotive.transports.doip.VehicleAnnouncement(*, address: str, protocol_version: int, vin: bytes, logical_address: int, eid: bytes, gid: bytes, further_action: int, vin_gid_sync_status: int | None)[source]

Vehicle announcement or identification response, preserving raw VIN/GID.

address is the UDP sender endpoint, with any IPv6 scope retained. Its source port may differ from the TCP diagnostic port. logical_address is the announcing entity; a downstream ECU may have another logical address. vin_gid_sync_status is None when the optional field was omitted.

property host: str

IP address, including the scope ID for a link-local IPv6 sender.

async connect(config: DoIPConfig | None = None, *, port: int = 13400) → DoIP[source]

Connect to this entity, using its advertised protocol version by default.

Uses central-security activation when further_action is 0x10. Supply a config to override activation, tester address, or advertised version. For a downstream ECU, call DoIP.connect(host, target_address) directly.

async automotive.transports.doip.discover(config: DiscoveryConfig | None = None) → list[VehicleAnnouncement][source]

Collect unique vehicles, waiting and requesting again for incomplete VIN/GID synchronization.

Response windows default to two seconds. A valid VIN or GID with incomplete synchronization adds a five-second per-vehicle wait before another request.

Synchronous API

The blocking API has the same defaults, config classes, announcement fields, and helper methods. Omit await and use ordinary context managers:

from automotive.sync.protocols.uds import UDSClient
from automotive.sync.transports.doip import discover

for vehicle in discover():
    with vehicle.connect() as transport:
        print(UDSClient(transport).read_data_by_identifier(0xF190))

Blocking DoIP discovery and UDS transport, using the same Rust implementation.

class automotive.sync.transports.doip.Discovery(resource: R)[source]

Blocking UDP discovery socket; request() triggers, recv() only listens.

Context management releases the socket. IPv6 multicast requires an explicit interface index through DiscoveryConfig.ipv6(index), on Windows and Unix.

classmethod bind(config: DiscoveryConfig | None = None) → Self[source]

Bind before sending; defaults to an ephemeral IPv4 request port.

classmethod listen(config: DiscoveryConfig | None = None) → Self[source]

Listen passively on announcement port 13400 without sending requests.

property local_address: str

Bound local IP/port, including the assigned request port.

request() → None[source]

Trigger the configured identification request on this socket.

recv() → VehicleAnnouncement[source]

Block for one announcement or response, preserving any IPv6 scope ID.

close() → None

Release the resource and wake pending operations; idempotent.

property closed: bool

Whether this resource or its owning parent has been closed.

class automotive.sync.transports.doip.DiscoveryConfig(*, bind_address: str = '0.0.0.0:0', destination: str = '255.255.255.255:13400', interface_index: int | None = None, protocol_version: int = 255, vin: bytes | None = None, eid: bytes | None = None, timeout: float = 2.0, reuse_address: bool = False)[source]

Optional discovery overrides, using IP endpoints with explicit ports.

Defaults send IPv4 limited broadcast from an ephemeral source port and collect responses for two seconds per request. Incomplete VIN/GID synchronization with a valid VIN or GID adds a five-second per-vehicle wait, then another request and collection window. Duplicate responses do not restart that timer. Set bind_address to select a local source IP; a subnet-directed broadcast destination can select the route on a multihomed host. Passive IPv4 reception normally binds 0.0.0.0:13400 to receive announcements from all adapters. IPv6 multicast requires an OS interface index, supplied by ipv6(index). Both work on Windows and Unix.

vin (17 raw bytes) and eid (six bytes) select identification request variants and filter replies; they are mutually exclusive. Version 255 discovers all supported versions. timeout is the response collection window in seconds after each request. Socket sharing is opt-in; Windows may distribute unicast packets among shared listeners.

classmethod ipv6(interface_index: int) → Self[source]

Use ff02::1 multicast on an explicitly selected IPv6 adapter.

passive() → Self[source]

Return settings binding announcement port 13400 instead of port zero.

class automotive.sync.transports.doip.DoIP(resource: R)[source]

Blocking routed TCP connection; alive checks continue in the background.

send() waits for a DoIP ACK. Subscribe with recv() before raw sends and serialize UDS exchanges. Reconnect after transport timeouts, malformed TCP messages, or cancellation with a response outstanding. No automatic replay. Context management closes the connection and wakes pending operations.

classmethod connect(host: str, target_address: int, *, port: int = 13400, config: DoIPConfig | None = None) → Self[source]

Connect and activate routing, with default tester address 0x0E00.

Supports IPv4, IPv6, and DNS. Include a numeric scope on link-local IPv6 hosts (fe80::1%7). Optional settings match the async DoIPConfig.

close() → None

Release the resource and wake pending operations; idempotent.

property closed: bool

Whether this resource or its owning parent has been closed.

recv() → Receiver[bytes]

Subscribe immediately to complete received PDUs as bytes.

Returns:

A blocking iterator supporting with and close(). Subscribe before sending. A receive deadline raises TimeoutError; next() can resume.

send(data: bytes | bytearray | memoryview) → None

Transmit one complete PDU, blocking until the transport completes it.

Parameters:

data – Bytes, bytearray, or contiguous byte-oriented memoryview.

Transport failures raise the corresponding protocol or connection error. A transmission deadline raises TimeoutError.

class automotive.sync.transports.doip.DoIPConfig(*, source_address: int = 3584, protocol_version: int = 2, activation_type: int = 0, activation_oem: bytes | None = None, local_address: str | None = None, connect_timeout: float = 2.0, activation_timeout: float = 2.0, ack_timeout: float = 2.0, max_payload_size: int = 4194304)[source]

Optional TCP overrides; the target ECU address is supplied to connect().

local_address selects a source IP/port, e.g. 192.168.0.2:0 or [fe80::2%7]:0. Omit it to follow OS routing. IPv6 link-local endpoints need their numeric interface scope. Default tester address is 0x0E00. protocol_version supports 2, 3, and 4; 2 favors deployed-ECU compatibility. Timeouts are seconds; activation and ACK waits default to ISO’s two seconds. activation_oem is an optional four-byte manufacturer record. max_payload_size includes logical addresses and bounds peer allocation. TLS and manufacturer-specific authentication are not implemented.

class automotive.sync.transports.doip.VehicleAnnouncement(*, address: str, protocol_version: int, vin: bytes, logical_address: int, eid: bytes, gid: bytes, further_action: int, vin_gid_sync_status: int | None)[source]

Discovered vehicle with raw VIN/EID/GID and a blocking connect helper.

Fields and host property match the async VehicleAnnouncement. UDP source ports are independent of the diagnostic TCP port, which defaults to 13400.

property host: str

IP address with any link-local IPv6 scope ID retained.

connect(config: DoIPConfig | None = None, *, port: int = 13400) → DoIP[source]

Connect with the advertised version and default activation/tester address.

automotive.sync.transports.doip.discover(config: DiscoveryConfig | None = None) → list[VehicleAnnouncement][source]

Collect unique vehicles, waiting and requesting again for incomplete VIN/GID synchronization.

Defaults to IPv4 with two-second response windows. A valid VIN or GID with incomplete synchronization adds a five-second per-vehicle wait and another request.