Skip to main content

ace_doip/payload/
routing_activation.rs

1use crate::error::DoipError;
2use ace_macros::FrameCodec;
3use ace_proto::doip::constants::{
4    DOIP_ROUTING_ACTIVATION_REQ_ISO_LEN, DOIP_ROUTING_ACTIVATION_REQ_OEM_LEN,
5    DOIP_ROUTING_ACTIVATION_REQ_SRC_LEN, DOIP_ROUTING_ACTIVATION_RES_ENTITY_LEN,
6    DOIP_ROUTING_ACTIVATION_RES_ISO_LEN, DOIP_ROUTING_ACTIVATION_RES_TESTER_LEN,
7};
8
9#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, FrameCodec)]
10#[frame(error = DoipError)]
11pub struct RoutingActivationRequest {
12    pub source_address: [u8; DOIP_ROUTING_ACTIVATION_REQ_SRC_LEN],
13    pub activation_type: ActivationType,
14    pub reserved: [u8; DOIP_ROUTING_ACTIVATION_REQ_ISO_LEN],
15    pub reserved_for_oem: [u8; DOIP_ROUTING_ACTIVATION_REQ_OEM_LEN],
16}
17
18#[repr(u8)]
19#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, FrameCodec)]
20#[frame(error = DoipError)]
21pub enum ActivationType {
22    #[frame(id = 0x00)]
23    Default,
24    #[frame(id = 0x01)]
25    WwhObd,
26    #[frame(id_pat = "0x02..=0xDF")]
27    Reserved(u8),
28    #[frame(id = 0xE0)]
29    CentralSecurity,
30    #[frame(id_pat = "0xE1..=0xFF")]
31    ReservedForOem(u8),
32}
33
34#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, FrameCodec)]
35#[frame(error = DoipError)]
36pub struct RoutingActivationResponse {
37    pub logical_address: [u8; DOIP_ROUTING_ACTIVATION_RES_TESTER_LEN],
38    pub source_address: [u8; DOIP_ROUTING_ACTIVATION_RES_ENTITY_LEN],
39    pub activation_code: ActivationCode,
40    pub reserved: [u8; DOIP_ROUTING_ACTIVATION_RES_ISO_LEN],
41    pub reserved_for_oem: Option<[u8; DOIP_ROUTING_ACTIVATION_REQ_OEM_LEN]>,
42}
43
44#[repr(u8)]
45#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, FrameCodec)]
46#[frame(error = DoipError)]
47pub enum ActivationCode {
48    #[frame(id = 0x00)]
49    DeniedUnknownSourceAddress,
50    #[frame(id = 0x01)]
51    DeniedTcpSocketsFull,
52    #[frame(id = 0x02)]
53    DeniedTcpSocketAlreadyConnected,
54    #[frame(id = 0x03)]
55    DeniedSourceIsAlreadyActive,
56    #[frame(id = 0x04)]
57    DeniedMissingAuthentication,
58    #[frame(id = 0x05)]
59    DeniedRejectedConfirmation,
60    #[frame(id = 0x06)]
61    DeniedUnsupportedRoutingActivationType,
62    #[frame(id = 0x07)]
63    DeniedRequestEncryptedTlsConnection,
64    #[frame(id = 0x08)]
65    DeniedVehicleInCriticalState,
66    #[frame(id_pat = "0x09..=0x0F | 0x12..=0xDF | 0xFF")]
67    Reserved(u8),
68    #[frame(id = 0x10)]
69    SuccessfullyActivated,
70    #[frame(id = 0x11)]
71    ActivatedConfirmationRequired,
72    #[frame(id_pat = "0xE0..=0xFE")]
73    ReservedForOem(u8),
74}
75
76impl From<ActivationCode> for u8 {
77    fn from(value: ActivationCode) -> Self {
78        match value {
79            ActivationCode::DeniedUnknownSourceAddress => 0x00,
80            ActivationCode::DeniedTcpSocketsFull => 0x01,
81            ActivationCode::DeniedTcpSocketAlreadyConnected => 0x02,
82            ActivationCode::DeniedSourceIsAlreadyActive => 0x03,
83            ActivationCode::DeniedMissingAuthentication => 0x04,
84            ActivationCode::DeniedRejectedConfirmation => 0x05,
85            ActivationCode::DeniedUnsupportedRoutingActivationType => 0x06,
86            ActivationCode::DeniedRequestEncryptedTlsConnection => 0x07,
87            ActivationCode::DeniedVehicleInCriticalState => 0x08,
88            ActivationCode::Reserved(b) => b,
89            ActivationCode::SuccessfullyActivated => 0x10,
90            ActivationCode::ActivatedConfirmationRequired => 0x11,
91            ActivationCode::ReservedForOem(b) => b,
92        }
93    }
94}