xref: /webrtc/sctp/src/param/param_type.rs (revision 5d8fe953)
1 use std::fmt;
2 
3 /// paramType represents a SCTP INIT/INITACK parameter
4 #[derive(Debug, Copy, Clone, PartialEq)]
5 #[repr(C)]
6 pub(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 
64 impl fmt::Display for ParamType {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result65     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 
99 impl From<u16> for ParamType {
from(v: u16) -> ParamType100     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             49158 => ParamType::AdaptLayerInd,
128             unknown => ParamType::Unknown {
129                 param_type: unknown,
130             },
131         }
132     }
133 }
134 
135 impl From<ParamType> for u16 {
from(v: ParamType) -> u16136     fn from(v: ParamType) -> u16 {
137         match v {
138             ParamType::HeartbeatInfo => 1,
139             ParamType::Ipv4Addr => 5,
140             ParamType::Ipv6Addr => 6,
141             ParamType::StateCookie => 7,
142             ParamType::UnrecognizedParam => 8,
143             ParamType::CookiePreservative => 9,
144             ParamType::HostNameAddr => 11,
145             ParamType::SupportedAddrTypes => 12,
146             ParamType::OutSsnResetReq => 13,
147             ParamType::IncSsnResetReq => 14,
148             ParamType::SsnTsnResetReq => 15,
149             ParamType::ReconfigResp => 16,
150             ParamType::AddOutStreamsReq => 17,
151             ParamType::AddIncStreamsReq => 18,
152             ParamType::Random => 32770,
153             ParamType::ChunkList => 32771,
154             ParamType::ReqHmacAlgo => 32772,
155             ParamType::Padding => 32773,
156             ParamType::SupportedExt => 32776,
157             ParamType::ForwardTsnSupp => 49152,
158             ParamType::AddIpAddr => 49153,
159             ParamType::DelIpaddr => 49154,
160             ParamType::ErrClauseInd => 49155,
161             ParamType::SetPriAddr => 49156,
162             ParamType::SuccessInd => 49157,
163             ParamType::AdaptLayerInd => 49158,
164             ParamType::Unknown { param_type, .. } => param_type,
165         }
166     }
167 }
168