Skip to content
File

Blob: firmware/vendor/sctp-proto/src/param/param_type.rs

rust165 lines
1use core::fmt;
2 
3/// paramType represents a SCTP INIT/INITACK parameter
4#[derive(Debug, Copy, Clone, PartialEq)]
5#[repr(C)]
6pub(crate) enum ParamType {
7 HeartbeatInfo,
8 /// Heartbeat Info [RFCRFC4960]
9 Ipv4Addr,
10 /// IPv4 IP [RFCRFC4960]
11 Ipv6Addr,
12 /// IPv6 IP [RFCRFC4960]
13 StateCookie,
14 /// State Cookie [RFCRFC4960]
15 UnrecognizedParam,
16 /// Unrecognized Parameters [RFCRFC4960]
17 CookiePreservative,
18 /// Cookie Preservative [RFCRFC4960]
19 HostNameAddr,
20 /// Host Name IP [RFCRFC4960]
21 SupportedAddrTypes,
22 /// Supported IP Types [RFCRFC4960]
23 OutSsnResetReq,
24 /// Outgoing SSN Reset Request Parameter [RFCRFC6525]
25 IncSsnResetReq,
26 /// Incoming SSN Reset Request Parameter [RFCRFC6525]
27 SsnTsnResetReq,
28 /// SSN/TSN Reset Request Parameter [RFCRFC6525]
29 ReconfigResp,
30 /// Re-configuration Response Parameter [RFCRFC6525]
31 AddOutStreamsReq,
32 /// Add Outgoing Streams Request Parameter [RFCRFC6525]
33 AddIncStreamsReq,
34 /// Add Incoming Streams Request Parameter [RFCRFC6525]
35 Random,
36 /// Random (0x8002) [RFCRFC4805]
37 ChunkList,
38 /// Chunk List (0x8003) [RFCRFC4895]
39 ReqHmacAlgo,
40 /// Requested HMAC Algorithm Parameter (0x8004) [RFCRFC4895]
41 Padding,
42 /// Padding (0x8005)
43 SupportedExt,
44 /// Supported Extensions (0x8008) [RFCRFC5061]
45 ForwardTsnSupp,
46 /// Forward TSN supported (0xC000) [RFCRFC3758]
47 AddIpAddr,
48 /// Add IP IP (0xC001) [RFCRFC5061]
49 DelIpaddr,
50 /// Delete IP IP (0xC002) [RFCRFC5061]
51 ErrClauseInd,
52 /// Error Cause Indication (0xC003) [RFCRFC5061]
53 SetPriAddr,
54 /// Set Primary IP (0xC004) [RFCRFC5061]
55 SuccessInd,
56 /// Success Indication (0xC005) [RFCRFC5061]
57 AdaptLayerInd,
58 /// Adaptation Layer Indication (0xC006) [RFCRFC5061]
59 Unknown {
60 param_type: u16,
61 },
62}
63 
64impl fmt::Display for ParamType {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 let s = match *self {
67 ParamType::HeartbeatInfo => "Heartbeat Info",
68 ParamType::Ipv4Addr => "IPv4 IP",
69 ParamType::Ipv6Addr => "IPv6 IP",
70 ParamType::StateCookie => "State Cookie",
71 ParamType::UnrecognizedParam => "Unrecognized Parameters",
72 ParamType::CookiePreservative => "Cookie Preservative",
73 ParamType::HostNameAddr => "Host Name IP",
74 ParamType::SupportedAddrTypes => "Supported IP Types",
75 ParamType::OutSsnResetReq => "Outgoing SSN Reset Request Parameter",
76 ParamType::IncSsnResetReq => "Incoming SSN Reset Request Parameter",
77 ParamType::SsnTsnResetReq => "SSN/TSN Reset Request Parameter",
78 ParamType::ReconfigResp => "Re-configuration Response Parameter",
79 ParamType::AddOutStreamsReq => "Add Outgoing Streams Request Parameter",
80 ParamType::AddIncStreamsReq => "Add Incoming Streams Request Parameter",
81 ParamType::Random => "Random",
82 ParamType::ChunkList => "Chunk List",
83 ParamType::ReqHmacAlgo => "Requested HMAC Algorithm Parameter",
84 ParamType::Padding => "Padding",
85 ParamType::SupportedExt => "Supported Extensions",
86 ParamType::ForwardTsnSupp => "Forward TSN supported",
87 ParamType::AddIpAddr => "Add IP IP",
88 ParamType::DelIpaddr => "Delete IP IP",
89 ParamType::ErrClauseInd => "Error Cause Indication",
90 ParamType::SetPriAddr => "Set Primary IP",
91 ParamType::SuccessInd => "Success Indication",
92 ParamType::AdaptLayerInd => "Adaptation Layer Indication",
93 _ => "Unknown ParamType",
94 };
95 write!(f, "{}", s)
96 }
97}
98 
99impl From<u16> for ParamType {
100 fn from(v: u16) -> ParamType {
101 match v {
102 1 => ParamType::HeartbeatInfo,
103 5 => ParamType::Ipv4Addr,
104 6 => ParamType::Ipv6Addr,
105 7 => ParamType::StateCookie,
106 8 => ParamType::UnrecognizedParam,
107 9 => ParamType::CookiePreservative,
108 11 => ParamType::HostNameAddr,
109 12 => ParamType::SupportedAddrTypes,
110 13 => ParamType::OutSsnResetReq,
111 14 => ParamType::IncSsnResetReq,
112 15 => ParamType::SsnTsnResetReq,
113 16 => ParamType::ReconfigResp,
114 17 => ParamType::AddOutStreamsReq,
115 18 => ParamType::AddIncStreamsReq,
116 32770 => ParamType::Random,
117 32771 => ParamType::ChunkList,
118 32772 => ParamType::ReqHmacAlgo,
119 32773 => ParamType::Padding,
120 32776 => ParamType::SupportedExt,
121 49152 => ParamType::ForwardTsnSupp,
122 49153 => ParamType::AddIpAddr,
123 49154 => ParamType::DelIpaddr,
124 49155 => ParamType::ErrClauseInd,
125 49156 => ParamType::SetPriAddr,
126 49157 => ParamType::SuccessInd,
127 _ => ParamType::Unknown { param_type: v },
128 }
129 }
130}
131 
132impl From<ParamType> for u16 {
133 fn from(v: ParamType) -> u16 {
134 match v {
135 ParamType::HeartbeatInfo => 1,
136 ParamType::Ipv4Addr => 5,
137 ParamType::Ipv6Addr => 6,
138 ParamType::StateCookie => 7,
139 ParamType::UnrecognizedParam => 8,
140 ParamType::CookiePreservative => 9,
141 ParamType::HostNameAddr => 11,
142 ParamType::SupportedAddrTypes => 12,
143 ParamType::OutSsnResetReq => 13,
144 ParamType::IncSsnResetReq => 14,
145 ParamType::SsnTsnResetReq => 15,
146 ParamType::ReconfigResp => 16,
147 ParamType::AddOutStreamsReq => 17,
148 ParamType::AddIncStreamsReq => 18,
149 ParamType::Random => 32770,
150 ParamType::ChunkList => 32771,
151 ParamType::ReqHmacAlgo => 32772,
152 ParamType::Padding => 32773,
153 ParamType::SupportedExt => 32776,
154 ParamType::ForwardTsnSupp => 49152,
155 ParamType::AddIpAddr => 49153,
156 ParamType::DelIpaddr => 49154,
157 ParamType::ErrClauseInd => 49155,
158 ParamType::SetPriAddr => 49156,
159 ParamType::SuccessInd => 49157,
160 ParamType::AdaptLayerInd => 49158,
161 ParamType::Unknown { param_type, .. } => param_type,
162 }
163 }
164}