1use crate::mac::*;
6use ieee80211::{MacAddr, MacAddrBytes};
7
8pub const EAPOL_PDU: &[u8] = &[5, 5, 5, 5, 5, 5, 5, 5];
9
10pub fn make_mgmt_frame(ht_ctrl: bool) -> Vec<u8> {
11 #[rustfmt::skip]
12 let mut bytes = vec![
13 1, if ht_ctrl { 128 } else { 1 }, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, ];
20 if ht_ctrl {
21 bytes.extend_from_slice(&[8, 8, 8, 8]);
22 }
23 bytes.extend_from_slice(&[9, 9, 9]);
24 bytes
25}
26
27pub fn make_data_hdr(
28 addr4: Option<MacAddr>,
29 qos_ctrl: [u8; 2],
30 ht_ctrl: Option<[u8; 4]>,
31) -> Vec<u8> {
32 let mut fc = FrameControl(0);
33 fc.set_frame_type(FrameType::DATA);
34 fc.set_data_subtype(DataSubtype(0).with_qos(true));
35 fc.set_from_ds(addr4.is_some());
36 fc.set_to_ds(addr4.is_some());
37 fc.set_htc_order(ht_ctrl.is_some());
38 let fc = fc.0.to_le_bytes();
39
40 #[rustfmt::skip]
41 let mut bytes = vec![
42 fc[0], fc[1], 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, ];
50
51 if let Some(addr4) = addr4 {
52 bytes.extend_from_slice(addr4.as_slice());
53 }
54
55 bytes.extend_from_slice(&qos_ctrl);
56
57 if let Some(ht_ctrl) = ht_ctrl {
58 bytes.extend_from_slice(&ht_ctrl);
59 }
60 bytes
61}
62
63pub fn make_data_frame_single_llc(addr4: Option<MacAddr>, ht_ctrl: Option<[u8; 4]>) -> Vec<u8> {
64 make_data_frame_single_llc_payload(addr4, ht_ctrl, &[11, 11, 11][..])
65}
66
67pub fn make_data_frame_single_llc_payload(
68 addr4: Option<MacAddr>,
69 ht_ctrl: Option<[u8; 4]>,
70 payload: &[u8],
71) -> Vec<u8> {
72 let qos_ctrl = [1, 1];
73 let mut bytes = make_data_hdr(addr4, qos_ctrl, ht_ctrl);
74 #[rustfmt::skip]
75 bytes.extend_from_slice(&[
76 7, 7, 7, 8, 8, 8, 9, 10, ]);
81 bytes.extend_from_slice(payload);
82 bytes
83}
84
85pub fn make_null_data_frame() -> Vec<u8> {
86 let fc = FrameControl(0)
87 .with_frame_type(FrameType::DATA)
88 .with_data_subtype(DataSubtype(0).with_null(true))
89 .with_to_ds(true);
90 let fc = fc.0.to_le_bytes();
91
92 #[rustfmt::skip]
93 let bytes = vec![
94 fc[0], fc[1], 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, ];
101 bytes
102}
103
104pub fn make_data_frame_with_padding() -> Vec<u8> {
105 let mut bytes = make_data_hdr(None, [1, 1], None);
106 #[rustfmt::skip]
107 bytes.extend(vec![
108 2, 2,
110 7, 7, 7, 8, 8, 8, 9, 10, 11, 11, 11, 11, 11, ]);
116 bytes
117}
118
119#[rustfmt::skip]
120pub const MSDU_1_LLC_HDR : &[u8] = &[
121 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00,
122];
123
124#[rustfmt::skip]
125pub const MSDU_1_PAYLOAD : &[u8] = &[
126 0x33, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
127 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
128 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
129 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
130 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
131 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
132 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
133 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
134 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
135 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
136 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
137 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
138 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
139 0x01, 0x02, 0x03, 0x04,
140];
141
142#[rustfmt::skip]
143pub const MSDU_2_LLC_HDR : &[u8] = &[
144 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x01,
145];
146
147#[rustfmt::skip]
148pub const MSDU_2_PAYLOAD : &[u8] = &[
149 0x99, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
151 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
152 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
153 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
154 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
155 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
156 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
157 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
158 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
159 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
160 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
161 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
162];
163
164pub fn make_data_frame_amsdu() -> Vec<u8> {
165 let mut qos_ctrl = QosControl(0);
166 qos_ctrl.set_amsdu_present(true);
167 let mut amsdu_data_frame = make_data_hdr(None, qos_ctrl.0.to_le_bytes(), None);
168 #[rustfmt::skip]
169 amsdu_data_frame.extend(&[
170 0x78, 0x8a, 0x20, 0x0d, 0x67, 0x03, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xab, 0x00, 0x74, ]);
175 amsdu_data_frame.extend(MSDU_1_LLC_HDR);
176 amsdu_data_frame.extend(MSDU_1_PAYLOAD);
177
178 #[rustfmt::skip]
179 amsdu_data_frame.extend(&[
180 0x00, 0x00,
182 0x78, 0x8a, 0x20, 0x0d, 0x67, 0x04, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xac, 0x00, 0x66, ]);
187 amsdu_data_frame.extend(MSDU_2_LLC_HDR);
188 amsdu_data_frame.extend(MSDU_2_PAYLOAD);
189 amsdu_data_frame
190}
191
192pub fn make_eapol_frame(addr1: MacAddr) -> (MacAddr, MacAddr, Vec<u8>) {
193 #[rustfmt::skip]
194 let mut frame = vec![
195 0b0000_10_00, 0b000000_1_0, 0, 0, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 0x10, 0, 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8E, ];
207 frame[4..10].copy_from_slice(addr1.as_array());
209 frame.extend(EAPOL_PDU);
211
212 (MacAddr::from([7; 6]), addr1, frame)
214}
215
216pub fn make_data_frame_amsdu_padding_too_short() -> Vec<u8> {
217 let mut qos_ctrl = QosControl(0);
218 qos_ctrl.set_amsdu_present(true);
219 let mut amsdu_data_frame = make_data_hdr(None, qos_ctrl.0.to_le_bytes(), None);
220 #[rustfmt::skip]
221 amsdu_data_frame.extend(&[
222 0x78, 0x8a, 0x20, 0x0d, 0x67, 0x03, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xab, 0x00, 0x74, ]);
227 amsdu_data_frame.extend(MSDU_1_LLC_HDR);
228 amsdu_data_frame.extend(MSDU_1_PAYLOAD);
229
230 #[rustfmt::skip]
231 amsdu_data_frame.extend(&[
232 0x00,
234 0x78, 0x8a, 0x20, 0x0d, 0x67, 0x04, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xac, 0x00, 0x66, ]);
239 amsdu_data_frame.extend(MSDU_2_LLC_HDR);
240 amsdu_data_frame.extend(MSDU_2_PAYLOAD);
241 amsdu_data_frame
242}
243
244pub fn fake_wpa1_ie_body(enhanced: bool) -> Vec<u8> {
245 let cipher = if enhanced { 0x4 } else { 0x2 }; vec![
247 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, cipher, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, ]
252}
253
254pub fn fake_wpa1_ie(enhanced: bool) -> Vec<u8> {
255 let mut ie = vec![
256 0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, ];
259 ie.append(&mut fake_wpa1_ie_body(enhanced));
260 ie
261}
262
263fn attach_rsne_header(rsne_body: &[u8]) -> Vec<u8> {
264 let mut ies = vec![48, rsne_body.len() as u8]; ies.extend_from_slice(&rsne_body[..]);
266 ies
267}
268
269pub fn fake_wpa2_rsne() -> Vec<u8> {
270 attach_rsne_header(&[
271 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, ])
276}
277
278pub fn fake_wpa2_mfpc_rsne() -> Vec<u8> {
279 attach_rsne_header(&[
280 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, 0x8C, 0x00, ])
286}
287
288pub fn fake_wpa2_mfpr_rsne() -> Vec<u8> {
289 attach_rsne_header(&[
290 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, 0xCC, 0x00, ])
296}
297
298pub fn fake_wpa2_tkip_only_rsne() -> Vec<u8> {
299 attach_rsne_header(&[
300 1, 0, 0x00, 0x0F, 0xAC, 2, 1, 0, 0x00, 0x0F, 0xAC, 2, 1, 0, 0x00, 0x0F, 0xAC, 2, ])
305}
306
307pub fn fake_wpa2_tkip_ccmp_rsne() -> Vec<u8> {
308 attach_rsne_header(&[
309 1, 0, 0x00, 0x0F, 0xAC, 2, 2, 0, 0x00, 0x0F, 0xAC, 2, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, ])
314}
315
316pub fn fake_wpa2_wpa3_rsne() -> Vec<u8> {
317 attach_rsne_header(&[
318 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 2, 0, 0x00, 0x0F, 0xAC, 8, 0x00, 0x0F, 0xAC, 2, 0x8C, 0x00, ])
324}
325
326pub fn fake_wpa2_wpa3_mfpr_rsne() -> Vec<u8> {
328 attach_rsne_header(&[
329 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 2, 0, 0x00, 0x0F, 0xAC, 8, 0x00, 0x0F, 0xAC, 2, 0xCC, 0x00, ])
335}
336
337pub fn fake_wpa2_wpa3_no_mfp_rsne() -> Vec<u8> {
339 attach_rsne_header(&[
340 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 2, 0, 0x00, 0x0F, 0xAC, 8, 0x00, 0x0F, 0xAC, 2, ])
345}
346
347pub fn fake_wpa3_rsne() -> Vec<u8> {
348 attach_rsne_header(&[
349 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 8, 0xCC, 0x00, ])
355}
356
357pub fn fake_wpa3_transition_rsne() -> Vec<u8> {
358 attach_rsne_header(&[
359 1, 0, 0x00, 0x0F, 0xAC, 2, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 8, 0xCC, 0x00, ])
365}
366
367pub fn invalid_wpa3_rsne() -> Vec<u8> {
369 attach_rsne_header(&[
370 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 8, 0x8C, 0x00, ])
376}
377
378pub fn fake_wpa2_enterprise_rsne() -> Vec<u8> {
379 attach_rsne_header(&[
380 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 1, ])
385}
386
387pub fn fake_wpa3_enterprise_192_bit_rsne() -> Vec<u8> {
388 attach_rsne_header(&[
389 1, 0, 0x00, 0x0F, 0xAC, 9, 1, 0, 0x00, 0x0F, 0xAC, 9, 1, 0, 0x00, 0x0F, 0xAC, 12, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xAC,
396 12, ])
398}
399
400pub fn invalid_wpa3_enterprise_192_bit_rsne() -> Vec<u8> {
403 attach_rsne_header(&[
404 1, 0, 0x00, 0x0F, 0xAC, 9, 1, 0, 0x00, 0x0F, 0xAC, 9, 1, 0, 0x00, 0x0F, 0xAC, 12, 0xCC, 0x00, ])
410}
411
412pub fn fake_eap_rsne() -> Vec<u8> {
413 attach_rsne_header(&[
414 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 1, ])
419}
420
421pub fn fake_unknown_rsne() -> Vec<u8> {
423 attach_rsne_header(&[
424 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 7, ])
429}
430
431pub fn fake_wmm_param_header() -> Vec<u8> {
432 vec![
433 0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, ]
438}
439
440pub fn fake_wmm_param_body() -> Vec<u8> {
441 vec![
442 0x80, 0x00, 0x03, 0xa4, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00, ]
449}