1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use crate::mac::{FrameControl, MgmtHdr, SequenceControl};
use ieee80211::{Bssid, MacAddr};

pub fn mgmt_hdr_to_ap(
    frame_ctrl: FrameControl,
    bssid: Bssid,
    client_addr: MacAddr,
    seq_ctrl: SequenceControl,
) -> MgmtHdr {
    MgmtHdr {
        frame_ctrl,
        duration: 0,
        addr1: bssid.into(),
        addr2: client_addr,
        addr3: bssid.into(),
        seq_ctrl,
    }
}

pub fn mgmt_hdr_from_ap(
    frame_ctrl: FrameControl,
    client_addr: MacAddr,
    bssid: Bssid,
    seq_ctrl: SequenceControl,
) -> MgmtHdr {
    MgmtHdr {
        frame_ctrl,
        duration: 0,
        addr1: client_addr,
        addr2: bssid.into(),
        addr3: bssid.into(),
        seq_ctrl,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn client_to_ap() {
        let got = mgmt_hdr_to_ap(
            FrameControl(1234),
            Bssid::from([1; 6]),
            MacAddr::from([2; 6]),
            SequenceControl(4321),
        );
        let expected = MgmtHdr {
            frame_ctrl: FrameControl(1234),
            duration: 0,
            addr1: MacAddr::from([1; 6]),
            addr2: MacAddr::from([2; 6]),
            addr3: MacAddr::from([1; 6]),
            seq_ctrl: SequenceControl(4321),
        };
        assert_eq!(got, expected);
    }
}