Skip to main content

doip_definitions/doip_payload/
activation_code.rs

1use crate::error::{Error, Result};
2
3/// Used in Routing Activation Response for results from a Routing Activation
4/// Request.
5///
6/// Used to understand the result of a Routing Activation Request to understand
7/// which logical route to take.
8#[cfg_attr(feature = "python-bindings", pyo3::pyclass(eq, eq_int))]
9#[derive(Clone, Copy, Debug, PartialEq)]
10pub enum ActivationCode {
11    /// Denied Unknown Source Address
12    DeniedUnknownSourceAddress = 0x00,
13
14    /// Denied TCP Sockets Full
15    DeniedTCPSocketsFull = 0x01,
16
17    /// Denied TCP Socket Already Connected
18    DeniedTCPSocketAlreadyConnected = 0x02,
19
20    /// Denied Source Is Already Active
21    DeniedSourceIsAlreadyActive = 0x03,
22
23    /// Denied Missing Authentication
24    DeniedMissingAuthentication = 0x04,
25
26    /// Denied Rejected Confirmation
27    DeniedRejectedConfirmation = 0x05,
28
29    /// Denied Unsupported Routing `ActivationType`
30    DeniedUnsupportedRoutingActivationType = 0x06,
31
32    /// Denied Request Encrypted TLS Connection
33    DeniedRequestEncryptedTLSConnection = 0x07,
34
35    /// Reserved By ISO-13400 for bytes value `08`
36    ReservedByIso13400_08 = 0x08,
37
38    /// Reserved By ISO-13400 for bytes value `09`
39    ReservedByIso13400_09 = 0x09,
40
41    /// Reserved By ISO-13400 for bytes value `0A`
42    ReservedByIso13400_0A = 0x0A,
43
44    /// Reserved By ISO-13400 for bytes value `0B`
45    ReservedByIso13400_0B = 0x0B,
46
47    /// Reserved By ISO-13400 for bytes value `0C`
48    ReservedByIso13400_0C = 0x0C,
49
50    /// Reserved By ISO-13400 for bytes value `0D`
51    ReservedByIso13400_0D = 0x0D,
52
53    /// Reserved By ISO-13400 for bytes value `0E`
54    ReservedByIso13400_0E = 0x0E,
55
56    /// Reserved By ISO-13400 for bytes value `0F`
57    ReservedByIso13400_0F = 0x0F,
58
59    /// Successfully Activated
60    SuccessfullyActivated = 0x10,
61
62    /// Activated Confirmation Required
63    ActivatedConfirmationRequired = 0x11,
64}
65
66impl TryFrom<&u8> for ActivationCode {
67    type Error = Error;
68
69    fn try_from(value: &u8) -> Result<Self> {
70        let val = *value;
71
72        match val {
73            v if v == ActivationCode::DeniedUnknownSourceAddress as u8 => {
74                Ok(ActivationCode::DeniedUnknownSourceAddress)
75            }
76            v if v == ActivationCode::DeniedTCPSocketsFull as u8 => {
77                Ok(ActivationCode::DeniedTCPSocketsFull)
78            }
79            v if v == ActivationCode::DeniedTCPSocketAlreadyConnected as u8 => {
80                Ok(ActivationCode::DeniedTCPSocketAlreadyConnected)
81            }
82            v if v == ActivationCode::DeniedSourceIsAlreadyActive as u8 => {
83                Ok(ActivationCode::DeniedSourceIsAlreadyActive)
84            }
85            v if v == ActivationCode::DeniedMissingAuthentication as u8 => {
86                Ok(ActivationCode::DeniedMissingAuthentication)
87            }
88            v if v == ActivationCode::DeniedRejectedConfirmation as u8 => {
89                Ok(ActivationCode::DeniedRejectedConfirmation)
90            }
91            v if v == ActivationCode::DeniedUnsupportedRoutingActivationType as u8 => {
92                Ok(ActivationCode::DeniedUnsupportedRoutingActivationType)
93            }
94            v if v == ActivationCode::DeniedRequestEncryptedTLSConnection as u8 => {
95                Ok(ActivationCode::DeniedRequestEncryptedTLSConnection)
96            }
97            v if v == ActivationCode::ReservedByIso13400_08 as u8 => {
98                Ok(ActivationCode::ReservedByIso13400_08)
99            }
100            v if v == ActivationCode::ReservedByIso13400_09 as u8 => {
101                Ok(ActivationCode::ReservedByIso13400_09)
102            }
103            v if v == ActivationCode::ReservedByIso13400_0A as u8 => {
104                Ok(ActivationCode::ReservedByIso13400_0A)
105            }
106            v if v == ActivationCode::ReservedByIso13400_0B as u8 => {
107                Ok(ActivationCode::ReservedByIso13400_0B)
108            }
109            v if v == ActivationCode::ReservedByIso13400_0C as u8 => {
110                Ok(ActivationCode::ReservedByIso13400_0C)
111            }
112            v if v == ActivationCode::ReservedByIso13400_0D as u8 => {
113                Ok(ActivationCode::ReservedByIso13400_0D)
114            }
115            v if v == ActivationCode::ReservedByIso13400_0E as u8 => {
116                Ok(ActivationCode::ReservedByIso13400_0E)
117            }
118            v if v == ActivationCode::ReservedByIso13400_0F as u8 => {
119                Ok(ActivationCode::ReservedByIso13400_0F)
120            }
121            v if v == ActivationCode::SuccessfullyActivated as u8 => {
122                Ok(ActivationCode::SuccessfullyActivated)
123            }
124            v if v == ActivationCode::ActivatedConfirmationRequired as u8 => {
125                Ok(ActivationCode::ActivatedConfirmationRequired)
126            }
127            v => Err(Error::InvalidActivationCode { value: v }),
128        }
129    }
130}
131
132impl From<ActivationCode> for u8 {
133    fn from(value: ActivationCode) -> Self {
134        value as u8
135    }
136}