1#[derive(Clone, Copy, PartialEq)]
3pub enum Status {
4 Disconnected(DisconnectReason),
6 Started,
8 Stopped,
10 Initializing,
12 Connected,
14}
15
16impl From<u8> for Status {
17 fn from(value: u8) -> Self {
18 match value {
19 252 => Self::Started,
20 253 => Self::Stopped,
21 254 => Self::Initializing,
22 255 => Self::Connected,
23 _ => Self::Disconnected(DisconnectReason::from(value)),
24 }
25 }
26}
27
28impl From<Status> for u8 {
29 fn from(value: Status) -> Self {
30 match value {
31 Status::Disconnected(r) => r.into(),
32 Status::Started => 252,
33 Status::Stopped => 253,
34 Status::Initializing => 254,
35 Status::Connected => 255,
36 }
37 }
38}
39
40#[derive(Clone, Copy, PartialEq)]
41pub enum DisconnectReason {
42 Unspecified,
44 AuthExpire,
46 AuthLeave,
48 DisassocDueToInactivity,
50 AssocToomany,
52 Class2FrameFromNonauthSta,
54 Class3FrameFromNonassocSta,
56 AssocLeave,
58 AssocNotAuthed,
60 DisassocPwrcapBad,
62 DisassocSupchanBad,
64 BssTransitionDisassoc,
66 IeInvalid,
68 MicFailure,
70 FourWayHandshakeTimeout,
72 GroupKeyUpdateTimeout,
74 IeIn4wayDiffers,
76 GroupCipherInvalid,
78 PairwiseCipherInvalid,
80 AkmpInvalid,
82 UnsuppRsnIeVersion,
84 InvalidRsnIeCap,
86 AuthFailed,
88 CipherSuiteRejected,
90 TdlsPeerUnreachable,
92 TdlsUnspecified,
94 SspRequestedDisassoc,
96 NoSspRoamingAgreement,
98 BadCipherOrAkm,
100 NotAuthorizedThisLocation,
102 ServiceChangePercludesTs,
104 UnspecifiedQos,
106 NotEnoughBandwidth,
108 MissingAcks,
110 ExceededTxop,
112 StaLeaving,
114 EndBa,
116 UnknownBa,
118 Timeout,
120 PeerInitiated,
122 ApInitiated,
124 InvalidFtActionFrameCount,
126 InvalidPmkid,
128 InvalidMde,
130 InvalidFte,
132 TransmissionLinkEstablishFailed,
134 AlterativeChannelOccupied,
136
137 BeaconTimeout,
139 NoApFound,
141 AuthFail,
143 AssocFail,
145 HandshakeTimeout,
147 ConnectionFail,
149 ApTsfReset,
151 Roaming,
153 AssocComebackTimeTooLong,
155 SaQueryTimeout,
157 NoApFoundWCompatibleSecurity,
159 NoApFoundInAuthmodeThreshold,
161 NoApFoundInRssiThreshold,
163}
164
165impl DisconnectReason {
166 #[must_use]
171 pub const fn as_str(&self) -> &'static str {
172 match self {
173 Self::Unspecified => "unspecified reason",
174 Self::AuthExpire => "authentication expired",
175 Self::AuthLeave => "deauthentication due to leaving",
176 Self::DisassocDueToInactivity => "disassociated due to inactivity",
177 Self::AssocToomany => "too many associated stations",
178 Self::Class2FrameFromNonauthSta => "class 2 frame received from nonauthenticated STA",
179 Self::Class3FrameFromNonassocSta => "class 3 frame received from nonassociated STA",
180 Self::AssocLeave => "deassociated due to leaving",
181 Self::AssocNotAuthed => "association but not authenticated",
182 Self::DisassocPwrcapBad => "disassociated due to poor power capability",
183 Self::DisassocSupchanBad => "disassociated due to unsupported channel",
184 Self::BssTransitionDisassoc => "disassociated due to BSS transition",
185 Self::IeInvalid => "invalid Information Element (IE)",
186 Self::MicFailure => "MIC failure",
187 Self::FourWayHandshakeTimeout => "4-way handshake timeout",
188 Self::GroupKeyUpdateTimeout => "group key update timeout",
189 Self::IeIn4wayDiffers => "IE differs in 4-way handshake",
190 Self::GroupCipherInvalid => "invalid group cipher",
191 Self::PairwiseCipherInvalid => "invalid pairwise cipher",
192 Self::AkmpInvalid => "invalid AKMP",
193 Self::UnsuppRsnIeVersion => "unsupported RSN IE version",
194 Self::InvalidRsnIeCap => "invalid RSN IE capabilities",
195 Self::AuthFailed => "802.1X authentication failed",
196 Self::CipherSuiteRejected => "cipher suite rejected",
197 Self::TdlsPeerUnreachable => "TDLS peer unreachable",
198 Self::TdlsUnspecified => "TDLS unspecified",
199 Self::SspRequestedDisassoc => "SSP requested disassociation",
200 Self::NoSspRoamingAgreement => "no SSP roaming agreement",
201 Self::BadCipherOrAkm => "bad cipher or AKM",
202 Self::NotAuthorizedThisLocation => "not authorized in this location",
203 Self::ServiceChangePercludesTs => "service change precludes TS",
204 Self::UnspecifiedQos => "unspecified Quality of Service reason",
205 Self::NotEnoughBandwidth => "not enough bandwidth",
206 Self::MissingAcks => "missing ACKs",
207 Self::ExceededTxop => "exceeded TXOP",
208 Self::StaLeaving => "station leaving",
209 Self::EndBa => "end of Block Ack (BA)",
210 Self::UnknownBa => "unknown Block Ack (BA)",
211 Self::Timeout => "timeout",
212 Self::PeerInitiated => "peer initiated disassociation",
213 Self::ApInitiated => "AP initiated disassociation",
214 Self::InvalidFtActionFrameCount => "invalid FT action frame count",
215 Self::InvalidPmkid => "invalid PMKID",
216 Self::InvalidMde => "invalid MDE",
217 Self::InvalidFte => "invalid FTE",
218 Self::TransmissionLinkEstablishFailed => "transmission link establishment failed",
219 Self::AlterativeChannelOccupied => "alternative channel occupied",
220
221 Self::BeaconTimeout => "beacon timeout",
222 Self::NoApFound => "no AP found",
223 Self::AuthFail => "authentication failed",
224 Self::AssocFail => "association failed",
225 Self::HandshakeTimeout => "handshake timeout",
226 Self::ConnectionFail => "connection failed",
227 Self::ApTsfReset => "AP TSF reset",
228 Self::Roaming => "roaming",
229 Self::AssocComebackTimeTooLong => "association comeback time too long",
230 Self::SaQueryTimeout => "SA query timeout",
231 Self::NoApFoundWCompatibleSecurity => "no AP found with compatible security",
232 Self::NoApFoundInAuthmodeThreshold => "no AP found in auth mode threshold",
233 Self::NoApFoundInRssiThreshold => "no AP found in RSSI threshold",
234 }
235 }
236}
237
238impl From<u8> for DisconnectReason {
239 fn from(value: u8) -> Self {
240 match value {
242 2 => Self::AuthExpire,
244 3 => Self::AuthLeave,
245 4 => Self::DisassocDueToInactivity,
246 5 => Self::AssocToomany,
247 6 => Self::Class2FrameFromNonauthSta,
248 7 => Self::Class3FrameFromNonassocSta,
249 8 => Self::AssocLeave,
250 9 => Self::AssocNotAuthed,
251 10 => Self::DisassocPwrcapBad,
252 11 => Self::DisassocSupchanBad,
253 12 => Self::BssTransitionDisassoc,
254 13 => Self::IeInvalid,
255 14 => Self::MicFailure,
256 15 => Self::FourWayHandshakeTimeout,
257 16 => Self::GroupKeyUpdateTimeout,
258 17 => Self::IeIn4wayDiffers,
259 18 => Self::GroupCipherInvalid,
260 19 => Self::PairwiseCipherInvalid,
261 20 => Self::AkmpInvalid,
262 21 => Self::UnsuppRsnIeVersion,
263 22 => Self::InvalidRsnIeCap,
264 23 => Self::AuthFailed,
265 24 => Self::CipherSuiteRejected,
266 25 => Self::TdlsPeerUnreachable,
267 26 => Self::TdlsUnspecified,
268 27 => Self::SspRequestedDisassoc,
269 28 => Self::NoSspRoamingAgreement,
270 29 => Self::BadCipherOrAkm,
271 30 => Self::NotAuthorizedThisLocation,
272 31 => Self::ServiceChangePercludesTs,
273 32 => Self::UnspecifiedQos,
274 33 => Self::NotEnoughBandwidth,
275 34 => Self::MissingAcks,
276 35 => Self::ExceededTxop,
277 36 => Self::StaLeaving,
278 37 => Self::EndBa,
279 38 => Self::UnknownBa,
280 39 => Self::Timeout,
281 46 => Self::PeerInitiated,
282 47 => Self::ApInitiated,
283 48 => Self::InvalidFtActionFrameCount,
284 49 => Self::InvalidPmkid,
285 50 => Self::InvalidMde,
286 51 => Self::InvalidFte,
287 67 => Self::TransmissionLinkEstablishFailed,
288 68 => Self::AlterativeChannelOccupied,
289 200 => Self::BeaconTimeout,
290 201 => Self::NoApFound,
291 202 => Self::AuthFail,
292 203 => Self::AssocFail,
293 204 => Self::HandshakeTimeout,
294 205 => Self::ConnectionFail,
295 206 => Self::ApTsfReset,
296 207 => Self::Roaming,
297 208 => Self::AssocComebackTimeTooLong,
298 209 => Self::SaQueryTimeout,
299 210 => Self::NoApFoundWCompatibleSecurity,
300 211 => Self::NoApFoundInAuthmodeThreshold,
301 212 => Self::NoApFoundInRssiThreshold,
302 _ => Self::Unspecified,
303 }
304 }
305}
306
307impl From<DisconnectReason> for u8 {
308 fn from(value: DisconnectReason) -> Self {
309 match value {
310 DisconnectReason::Unspecified => 1,
311 DisconnectReason::AuthExpire => 2,
312 DisconnectReason::AuthLeave => 3,
313 DisconnectReason::DisassocDueToInactivity => 4,
314 DisconnectReason::AssocToomany => 5,
315 DisconnectReason::Class2FrameFromNonauthSta => 6,
316 DisconnectReason::Class3FrameFromNonassocSta => 7,
317 DisconnectReason::AssocLeave => 8,
318 DisconnectReason::AssocNotAuthed => 9,
319 DisconnectReason::DisassocPwrcapBad => 10,
320 DisconnectReason::DisassocSupchanBad => 11,
321 DisconnectReason::BssTransitionDisassoc => 12,
322 DisconnectReason::IeInvalid => 13,
323 DisconnectReason::MicFailure => 14,
324 DisconnectReason::FourWayHandshakeTimeout => 15,
325 DisconnectReason::GroupKeyUpdateTimeout => 16,
326 DisconnectReason::IeIn4wayDiffers => 17,
327 DisconnectReason::GroupCipherInvalid => 18,
328 DisconnectReason::PairwiseCipherInvalid => 19,
329 DisconnectReason::AkmpInvalid => 20,
330 DisconnectReason::UnsuppRsnIeVersion => 21,
331 DisconnectReason::InvalidRsnIeCap => 22,
332 DisconnectReason::AuthFailed => 23,
333 DisconnectReason::CipherSuiteRejected => 24,
334 DisconnectReason::TdlsPeerUnreachable => 25,
335 DisconnectReason::TdlsUnspecified => 26,
336 DisconnectReason::SspRequestedDisassoc => 27,
337 DisconnectReason::NoSspRoamingAgreement => 28,
338 DisconnectReason::BadCipherOrAkm => 29,
339 DisconnectReason::NotAuthorizedThisLocation => 30,
340 DisconnectReason::ServiceChangePercludesTs => 31,
341 DisconnectReason::UnspecifiedQos => 32,
342 DisconnectReason::NotEnoughBandwidth => 33,
343 DisconnectReason::MissingAcks => 34,
344 DisconnectReason::ExceededTxop => 35,
345 DisconnectReason::StaLeaving => 36,
346 DisconnectReason::EndBa => 37,
347 DisconnectReason::UnknownBa => 38,
348 DisconnectReason::Timeout => 39,
349 DisconnectReason::PeerInitiated => 46,
350 DisconnectReason::ApInitiated => 47,
351 DisconnectReason::InvalidFtActionFrameCount => 48,
352 DisconnectReason::InvalidPmkid => 49,
353 DisconnectReason::InvalidMde => 50,
354 DisconnectReason::InvalidFte => 51,
355 DisconnectReason::TransmissionLinkEstablishFailed => 67,
356 DisconnectReason::AlterativeChannelOccupied => 68,
357 DisconnectReason::BeaconTimeout => 200,
358 DisconnectReason::NoApFound => 201,
359 DisconnectReason::AuthFail => 202,
360 DisconnectReason::AssocFail => 203,
361 DisconnectReason::HandshakeTimeout => 204,
362 DisconnectReason::ConnectionFail => 205,
363 DisconnectReason::ApTsfReset => 206,
364 DisconnectReason::Roaming => 207,
365 DisconnectReason::AssocComebackTimeTooLong => 208,
366 DisconnectReason::SaQueryTimeout => 209,
367 DisconnectReason::NoApFoundWCompatibleSecurity => 210,
368 DisconnectReason::NoApFoundInAuthmodeThreshold => 211,
369 DisconnectReason::NoApFoundInRssiThreshold => 212,
370 }
371 }
372}