doip_definitions/
lib.rs

1// region:      --- Configs
2#![cfg_attr(not(feature = "std"), no_std)] // Use no_std when the "std" feature is disabled
3#![warn(clippy::pedantic)]
4#![warn(missing_debug_implementations)]
5#![warn(missing_docs)]
6#![allow(clippy::module_name_repetitions)]
7// endregion:      --- Configs
8
9//! Diagnostics over Internet Protocol definition library
10//!
11//! This crate is built to act a definitive source for defintions of ISO-13400
12//! and `DoIP` protocol development. Using all the data structures provided one
13//! should be able to develop applications with certainty that they are abiding
14//! by regulatory standards.
15//!
16//! Each `DoIP` message contains a minimum length of 8 bytes of which is the
17//! [`header`], within this the header contains the length of the [`message`]
18//! and what type of payload the message is.
19
20// region:      --- Modules
21
22mod doip_header;
23mod doip_message;
24mod doip_payload;
25
26// -- Flatten
27
28// -- Public Modules
29/// Error pertaining to functionality of trait implementations.
30pub mod error;
31
32/// Contains header related logic and data structures.
33///
34/// The `DoIP` header contains 4 items:
35/// - Protocol Version
36/// - Inverse Protocol Version
37/// - Payload Type
38/// - Payload Length
39///
40/// By default this library provides users with the option to use a different
41/// protocol version than what is currently in use, this is for backwards and future
42/// compatability.
43///
44/// The Inverse Protocol Version is the flipped byte of the protocol
45/// version, this is to validate the packet.
46///
47/// The payload length is given in a `u32` but in this library is written in
48/// `[u8; 4]` to remain close-to-network as possible.
49///
50/// This module contains the relevant structs, enums, and traits for developers
51/// to create custom headers.
52pub mod header {
53    pub use crate::doip_header::payload_type::*;
54    pub use crate::doip_header::version::*;
55    pub use crate::doip_header::DoipHeader;
56}
57
58/// Contains message data structures and internal payload type dependant structures.
59pub mod payload {
60    pub use crate::doip_payload::action_code::*;
61    pub use crate::doip_payload::activation_code::*;
62    pub use crate::doip_payload::activation_type::*;
63    pub use crate::doip_payload::diagnostic_ack::*;
64    pub use crate::doip_payload::diagnostic_nack::*;
65    pub use crate::doip_payload::nack_code::*;
66    pub use crate::doip_payload::node_type::*;
67    pub use crate::doip_payload::power_mode::*;
68    pub use crate::doip_payload::sync_status::*;
69    pub use crate::doip_payload::DoipPayload;
70
71    pub use crate::doip_payload::alive_check_request::*;
72    pub use crate::doip_payload::alive_check_response::*;
73    pub use crate::doip_payload::diagnostic_message::*;
74    pub use crate::doip_payload::diagnostic_message_ack::*;
75    pub use crate::doip_payload::diagnostic_message_nack::*;
76    pub use crate::doip_payload::entity_status_request::*;
77    pub use crate::doip_payload::entity_status_response::*;
78    pub use crate::doip_payload::generic_nack::*;
79    pub use crate::doip_payload::power_information_request::*;
80    pub use crate::doip_payload::power_information_response::*;
81    pub use crate::doip_payload::routing_activation_request::*;
82    pub use crate::doip_payload::routing_activation_response::*;
83    pub use crate::doip_payload::vehicle_announcement_message::*;
84    pub use crate::doip_payload::vehicle_identification_request::*;
85    pub use crate::doip_payload::vehicle_identification_request_eid::*;
86    pub use crate::doip_payload::vehicle_identification_request_vin::*;
87}
88
89/// The definitions found here are originally from Wireshark's repository. Wireshark
90/// is a packet sniffing tool with an already supported `DoIP` and UDS packet disassembly
91/// and so their definitions were lifted so to support this crate.
92pub mod definitions;
93
94/// Contains the implementations for the overarching `DoIP Message` structure.
95pub mod message {
96    pub use crate::doip_message::DoipMessage;
97}
98
99/// # `DoIP` Message Builder Library
100///
101/// This module provides functionality to construct Diagnostic over IP (`DoIP`) messages used in automotive diagnostics
102/// in accordance with ISO 13400 standards.
103///
104/// It includes a builder pattern implementation (`DoipMessageBuilder`) that allows users to configure and construct
105/// valid `DoipMessage` instances with appropriate protocol headers and payloads. The builder ensures that metadata
106/// such as payload type and length are automatically derived from the provided payload content.
107///
108/// ## Features
109///
110/// - Typed and extensible `DoipPayload` variants for different message types
111/// - Automatic header field population (e.g., inverse protocol version, payload length)
112/// - Fluent, chainable builder interface
113/// - Safe default values for rapid prototyping
114///
115/// ## Example Usage
116///
117/// ```rust
118/// use doip_definitions::builder::DoipMessageBuilder;
119/// use doip_definitions::payload::AliveCheckRequest;
120/// use doip_definitions::payload::DoipPayload;
121/// use doip_definitions::header::ProtocolVersion;
122///
123/// let message = DoipMessageBuilder::new()
124///     .protocol_version(ProtocolVersion::Iso13400_2012)
125///     .payload(DoipPayload::AliveCheckRequest(AliveCheckRequest {}))
126///     .build();
127/// ```
128///
129/// ## Message Types Supported
130///
131/// - Alive Check (Request/Response)
132/// - Vehicle Identification (Generic, EID, VIN)
133/// - Vehicle Announcement
134/// - Routing Activation (Request/Response)
135/// - Entity Status (Request/Response)
136/// - Power Information (Request/Response)
137/// - Diagnostic Messages (Standard, ACK, NACK)
138///
139/// ## Intended Usage
140///
141/// This library is designed for integration into vehicle diagnostics applications,
142/// simulation tools, or any system that needs to generate or send valid `DoIP` messages over a network.
143///
144/// ## Compliance
145///
146/// The design adheres to the structural requirements defined in ISO 13400 and aims to maintain
147/// compatibility with UDS-on-IP diagnostic stacks and OEM-specific `DoIP` implementations.
148#[cfg(feature = "builder")]
149pub mod builder;
150
151// endregion:      --- Modules
152
153// Python bindings (only available when python-bindings is enabled)
154#[cfg(feature = "python-bindings")]
155#[cfg(any(not(test), rust_analyzer))]
156mod bindings;
157
158// Panic handler for `no_std` environments, but only when `std` is not enabled
159// #[cfg(not(feature = "std"))]
160// #[panic_handler]
161// fn panic(_info: &core::panic::PanicInfo) -> ! {
162//     loop {}
163// }