doip_definitions/doip_payload/
activation_code.rs1use crate::error::{Error, Result};
2
3#[cfg_attr(feature = "python-bindings", pyo3::pyclass(eq, eq_int))]
9#[derive(Clone, Copy, Debug, PartialEq)]
10pub enum ActivationCode {
11 DeniedUnknownSourceAddress = 0x00,
13
14 DeniedTCPSocketsFull = 0x01,
16
17 DeniedTCPSocketAlreadyConnected = 0x02,
19
20 DeniedSourceIsAlreadyActive = 0x03,
22
23 DeniedMissingAuthentication = 0x04,
25
26 DeniedRejectedConfirmation = 0x05,
28
29 DeniedUnsupportedRoutingActivationType = 0x06,
31
32 DeniedRequestEncryptedTLSConnection = 0x07,
34
35 ReservedByIso13400_08 = 0x08,
37
38 ReservedByIso13400_09 = 0x09,
40
41 ReservedByIso13400_0A = 0x0A,
43
44 ReservedByIso13400_0B = 0x0B,
46
47 ReservedByIso13400_0C = 0x0C,
49
50 ReservedByIso13400_0D = 0x0D,
52
53 ReservedByIso13400_0E = 0x0E,
55
56 ReservedByIso13400_0F = 0x0F,
58
59 SuccessfullyActivated = 0x10,
61
62 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}