wlan_common/
data_writer.rs
1use crate::big_endian::BigEndianU16;
6use crate::mac::{self, FixedDataHdrFields, FrameControl, SequenceControl};
7use ieee80211::{Bssid, MacAddr};
8
9pub fn data_hdr_client_to_ap(
10 mut frame_ctrl: FrameControl,
11 bssid: Bssid,
12 client_addr: MacAddr,
13 seq_ctrl: SequenceControl,
14) -> FixedDataHdrFields {
15 frame_ctrl.set_to_ds(true);
16 frame_ctrl.set_from_ds(false);
17 FixedDataHdrFields {
18 frame_ctrl,
19 duration: 0,
20 addr1: bssid.into(),
21 addr2: client_addr,
22 addr3: bssid.into(),
23 seq_ctrl,
24 }
25}
26
27pub fn make_snap_llc_hdr(protocol_id: u16) -> mac::LlcHdr {
28 mac::LlcHdr {
29 dsap: mac::LLC_SNAP_EXTENSION,
30 ssap: mac::LLC_SNAP_EXTENSION,
31 control: mac::LLC_SNAP_UNNUMBERED_INFO,
32 oui: mac::LLC_SNAP_OUI,
33 protocol_id: BigEndianU16::from_native(protocol_id),
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 use super::*;
40
41 #[test]
42 fn client_to_ap() {
43 let got = data_hdr_client_to_ap(
44 FrameControl(0b00110000_00110000),
45 Bssid::from([1; 6]),
46 MacAddr::from([2; 6]),
47 SequenceControl(4321),
48 );
49 let expected = FixedDataHdrFields {
50 frame_ctrl: FrameControl(0b00110001_00110000),
51 duration: 0,
52 addr1: MacAddr::from([1; 6]),
53 addr2: MacAddr::from([2; 6]),
54 addr3: MacAddr::from([1; 6]),
55 seq_ctrl: SequenceControl(4321),
56 };
57 assert_eq!(got, expected);
58 }
59}