use crate::mac::*;
use ieee80211::{MacAddr, MacAddrBytes};
pub const EAPOL_PDU: &[u8] = &[5, 5, 5, 5, 5, 5, 5, 5];
pub fn make_mgmt_frame(ht_ctrl: bool) -> Vec<u8> {
#[rustfmt::skip]
let mut bytes = vec![
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, ];
if ht_ctrl {
bytes.extend_from_slice(&[8, 8, 8, 8]);
}
bytes.extend_from_slice(&[9, 9, 9]);
bytes
}
pub fn make_data_hdr(
addr4: Option<MacAddr>,
qos_ctrl: [u8; 2],
ht_ctrl: Option<[u8; 4]>,
) -> Vec<u8> {
let mut fc = FrameControl(0);
fc.set_frame_type(FrameType::DATA);
fc.set_data_subtype(DataSubtype(0).with_qos(true));
fc.set_from_ds(addr4.is_some());
fc.set_to_ds(addr4.is_some());
fc.set_htc_order(ht_ctrl.is_some());
let fc = fc.0.to_le_bytes();
#[rustfmt::skip]
let mut bytes = vec![
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, ];
if let Some(addr4) = addr4 {
bytes.extend_from_slice(addr4.as_slice());
}
bytes.extend_from_slice(&qos_ctrl);
if let Some(ht_ctrl) = ht_ctrl {
bytes.extend_from_slice(&ht_ctrl);
}
bytes
}
pub fn make_data_frame_single_llc(addr4: Option<MacAddr>, ht_ctrl: Option<[u8; 4]>) -> Vec<u8> {
make_data_frame_single_llc_payload(addr4, ht_ctrl, &[11, 11, 11][..])
}
pub fn make_data_frame_single_llc_payload(
addr4: Option<MacAddr>,
ht_ctrl: Option<[u8; 4]>,
payload: &[u8],
) -> Vec<u8> {
let qos_ctrl = [1, 1];
let mut bytes = make_data_hdr(addr4, qos_ctrl, ht_ctrl);
#[rustfmt::skip]
bytes.extend_from_slice(&[
7, 7, 7, 8, 8, 8, 9, 10, ]);
bytes.extend_from_slice(payload);
bytes
}
pub fn make_null_data_frame() -> Vec<u8> {
let fc = FrameControl(0)
.with_frame_type(FrameType::DATA)
.with_data_subtype(DataSubtype(0).with_null(true))
.with_to_ds(true);
let fc = fc.0.to_le_bytes();
#[rustfmt::skip]
let bytes = vec![
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, ];
bytes
}
pub fn make_data_frame_with_padding() -> Vec<u8> {
let mut bytes = make_data_hdr(None, [1, 1], None);
#[rustfmt::skip]
bytes.extend(vec![
2, 2,
7, 7, 7, 8, 8, 8, 9, 10, 11, 11, 11, 11, 11, ]);
bytes
}
#[rustfmt::skip]
pub const MSDU_1_LLC_HDR : &[u8] = &[
0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00,
];
#[rustfmt::skip]
pub const MSDU_1_PAYLOAD : &[u8] = &[
0x33, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04,
];
#[rustfmt::skip]
pub const MSDU_2_LLC_HDR : &[u8] = &[
0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x01,
];
#[rustfmt::skip]
pub const MSDU_2_PAYLOAD : &[u8] = &[
0x99, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
];
pub fn make_data_frame_amsdu() -> Vec<u8> {
let mut qos_ctrl = QosControl(0);
qos_ctrl.set_amsdu_present(true);
let mut amsdu_data_frame = make_data_hdr(None, qos_ctrl.0.to_le_bytes(), None);
#[rustfmt::skip]
amsdu_data_frame.extend(&[
0x78, 0x8a, 0x20, 0x0d, 0x67, 0x03, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xab, 0x00, 0x74, ]);
amsdu_data_frame.extend(MSDU_1_LLC_HDR);
amsdu_data_frame.extend(MSDU_1_PAYLOAD);
#[rustfmt::skip]
amsdu_data_frame.extend(&[
0x00, 0x00,
0x78, 0x8a, 0x20, 0x0d, 0x67, 0x04, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xac, 0x00, 0x66, ]);
amsdu_data_frame.extend(MSDU_2_LLC_HDR);
amsdu_data_frame.extend(MSDU_2_PAYLOAD);
amsdu_data_frame
}
pub fn make_eapol_frame(addr1: MacAddr) -> (MacAddr, MacAddr, Vec<u8>) {
#[rustfmt::skip]
let mut frame = vec![
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, ];
frame[4..10].copy_from_slice(addr1.as_array());
frame.extend(EAPOL_PDU);
(MacAddr::from([7; 6]), addr1, frame)
}
pub fn make_data_frame_amsdu_padding_too_short() -> Vec<u8> {
let mut qos_ctrl = QosControl(0);
qos_ctrl.set_amsdu_present(true);
let mut amsdu_data_frame = make_data_hdr(None, qos_ctrl.0.to_le_bytes(), None);
#[rustfmt::skip]
amsdu_data_frame.extend(&[
0x78, 0x8a, 0x20, 0x0d, 0x67, 0x03, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xab, 0x00, 0x74, ]);
amsdu_data_frame.extend(MSDU_1_LLC_HDR);
amsdu_data_frame.extend(MSDU_1_PAYLOAD);
#[rustfmt::skip]
amsdu_data_frame.extend(&[
0x00,
0x78, 0x8a, 0x20, 0x0d, 0x67, 0x04, 0xb4, 0xf7, 0xa1, 0xbe, 0xb9, 0xac, 0x00, 0x66, ]);
amsdu_data_frame.extend(MSDU_2_LLC_HDR);
amsdu_data_frame.extend(MSDU_2_PAYLOAD);
amsdu_data_frame
}
pub fn fake_wpa1_ie_body(enhanced: bool) -> Vec<u8> {
let cipher = if enhanced { 0x4 } else { 0x2 }; vec![
0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, cipher, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, ]
}
pub fn fake_wpa1_ie(enhanced: bool) -> Vec<u8> {
let mut ie = vec![
0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, ];
ie.append(&mut fake_wpa1_ie_body(enhanced));
ie
}
fn attach_rsne_header(rsne_body: &[u8]) -> Vec<u8> {
let mut ies = vec![48, rsne_body.len() as u8]; ies.extend_from_slice(&rsne_body[..]);
ies
}
pub fn fake_wpa2_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, ])
}
pub fn fake_wpa2_mfpc_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, 0x8C, 0x00, ])
}
pub fn fake_wpa2_mfpr_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, 0xCC, 0x00, ])
}
pub fn fake_wpa2_tkip_only_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 2, 1, 0, 0x00, 0x0F, 0xAC, 2, 1, 0, 0x00, 0x0F, 0xAC, 2, ])
}
pub fn fake_wpa2_tkip_ccmp_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 2, 2, 0, 0x00, 0x0F, 0xAC, 2, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 2, ])
}
pub fn fake_wpa2_wpa3_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 2, 0, 0x00, 0x0F, 0xAC, 8, 0x00, 0x0F, 0xAC, 2, 0x8C, 0x00, ])
}
pub fn fake_wpa2_wpa3_mfpr_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 2, 0, 0x00, 0x0F, 0xAC, 8, 0x00, 0x0F, 0xAC, 2, 0xCC, 0x00, ])
}
pub fn fake_wpa2_wpa3_no_mfp_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 2, 0, 0x00, 0x0F, 0xAC, 8, 0x00, 0x0F, 0xAC, 2, ])
}
pub fn fake_wpa3_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 8, 0xCC, 0x00, ])
}
pub fn fake_wpa3_transition_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 2, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 8, 0xCC, 0x00, ])
}
pub fn invalid_wpa3_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 8, 0x8C, 0x00, ])
}
pub fn fake_wpa2_enterprise_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 1, ])
}
pub fn fake_wpa3_enterprise_192_bit_rsne() -> Vec<u8> {
attach_rsne_header(&[
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,
12, ])
}
pub fn invalid_wpa3_enterprise_192_bit_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 9, 1, 0, 0x00, 0x0F, 0xAC, 9, 1, 0, 0x00, 0x0F, 0xAC, 12, 0xCC, 0x00, ])
}
pub fn fake_eap_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 1, ])
}
pub fn fake_unknown_rsne() -> Vec<u8> {
attach_rsne_header(&[
1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 4, 1, 0, 0x00, 0x0F, 0xAC, 7, ])
}
pub fn fake_wmm_param_header() -> Vec<u8> {
vec![
0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, ]
}
pub fn fake_wmm_param_body() -> Vec<u8> {
vec![
0x80, 0x00, 0x03, 0xa4, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00, ]
}