ace_doip/error.rs
1// region: DoipError
2
3use ace_core::DiagError;
4use ace_uds::UdsError;
5use heapless::format;
6
7use crate::header::ProtocolVersion;
8
9#[derive(Debug, PartialEq, Eq)]
10pub enum DoipValidationError {
11 /// Protocol version byte did not match 0x02 (ISO 13400-2:2019) or 0x01 (ISO 13400-2:2012)
12 UnsupportedProtocolVersion(u8),
13 /// Inverse protocol version byte did not match the bitwise complement of the version byte
14 InvalidInverseProtocolVersion {
15 version: ProtocolVersion,
16 inverse: u8,
17 },
18 /// Payload type is not defined in ISO 13400-2
19 UnknownPayloadType(u16),
20 /// Payload length field does not match the actual number of bytes following the header
21 PayloadLengthMismatch { declared: u32, actual: usize },
22 /// Frame is shorter than the minimum DoIP header length (8 bytes)
23 FrameTooShort { actual: usize },
24 /// Source address is not valid in this context (e.g. zero on a response)
25 InvalidSourceAddress(u16),
26 /// Target address is not valid in this context
27 InvalidTargetAddress(u16),
28 /// Activation type is not recognised
29 UnknownActivationType(u8),
30 /// NACK code is not recognised
31 UnknownNackCode(u8),
32}
33
34#[derive(Debug)]
35pub enum DoipError {
36 /// Underlying transport or framing error
37 Transport(DiagError),
38 /// Frame structure violated ISO 13400-2 constraints
39 Validation(DoipValidationError),
40 /// Frame was structurally valid but could not be parsed
41 Parse(heapless::String<64>),
42}
43
44impl From<DiagError> for DoipError {
45 fn from(e: DiagError) -> Self {
46 DoipError::Transport(e)
47 }
48}
49
50impl From<DoipValidationError> for DoipError {
51 fn from(e: DoipValidationError) -> Self {
52 DoipError::Validation(e)
53 }
54}
55
56impl From<UdsError> for DoipError {
57 fn from(e: UdsError) -> Self {
58 DoipError::Parse(format!("{:?}", e).unwrap_or_default())
59 }
60}
61
62// DoipError does NOT implement Into<DiagError> - the two error domains are
63// parallel. DiagError is transport-layer, DoipError is protocol-layer.
64
65// endregion: DoipError