use ieee80211::{
elements::{
element_chain::{ChainElement, ElementChainEnd},
OWETransitionModeElement,
},
mgmt_frame::{body::BeaconBody, BeaconFrame},
ssid,
};
use mac_parser::MACAddress;
use scroll::{ctx::MeasureWith, Pread, Pwrite};
const INITIAL_BYTES: &[u8] = &[
0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0x41, 0xff, 0xff, 0xff, 0x00, 0x80, 0x41, 0x13, 0x37, 0x42, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x06, b'L', b'a', b'm', b'b', b'd', b'a', 0xdd, 0x0f, 0x50, 0x6f, 0x9a, 0x1c, 0x00, 0x80, 0x41, 0x13, 0x37, 0x43, 0x04, b'T', b'e', b's', b't',
];
const NEW_BYTES: &[u8] = &[
0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x80, 0x41, 0xff, 0xff, 0xff, 0x00, 0x80, 0x41, 0x13, 0x37, 0x42, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x04, b'T', b'e', b's', b't', 0xdd, 0x12, 0x50, 0x6f, 0x9a, 0x1c, 0x00, 0x80, 0x41, 0x13, 0x37, 0x43, 0x07, b'O', b'W', b'E', b'T', b'e', b's', b't',
];
fn main() {
let beacon = INITIAL_BYTES.pread::<BeaconFrame>(0).unwrap();
println!(
"BSSID: {:?}, SSID: {:#?}, OWE SSID: {}",
beacon.header.bssid,
beacon.ssid(),
beacon
.elements
.get_first_element::<OWETransitionModeElement>()
.unwrap()
.ssid
);
let beacon = BeaconFrame {
header: beacon.header,
body: BeaconBody {
capabilities_info: beacon.capabilities_info,
timestamp: beacon.timestamp,
beacon_interval: beacon.beacon_interval,
elements: ElementChainEnd::new(ssid!("Test")).append(OWETransitionModeElement {
bssid: MACAddress::new([0x00, 0x80, 0x41, 0x13, 0x37, 0x43]),
ssid: "OWETest",
..Default::default()
}),
..Default::default()
},
};
let mut buf = vec![0x00u8; beacon.measure_with(&false)];
buf.pwrite(beacon, 0).unwrap();
assert_eq!(buf, NEW_BYTES);
}