wlan_mlme/ap/frame_writer/
mod.rs

1// Copyright 2019 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::error::Error;
6use anyhow::format_err;
7use wlan_common::mac;
8use zerocopy::Ref;
9
10pub fn set_more_data(buffer: &mut [u8]) -> Result<(), Error> {
11    let (frame_ctrl, _) = Ref::<&mut [u8], mac::FrameControl>::from_prefix(buffer)
12        .map_err(|_| format_err!("could not parse frame control header"))?;
13    let frame_ctrl = Ref::into_mut(frame_ctrl);
14    frame_ctrl.set_more_data(true);
15    Ok(())
16}
17
18#[cfg(test)]
19mod tests {
20    use super::*;
21
22    #[test]
23    fn more_data() {
24        let mut buffer = vec![
25            // Mgmt header
26            0b00001000, 0b00000010, // Frame Control
27            0, 0, // Duration
28            3, 3, 3, 3, 3, 3, // addr1
29            2, 2, 2, 2, 2, 2, // addr2
30            1, 1, 1, 1, 1, 1, // addr3
31            0x10, 0, // Sequence Control
32            0xAA, 0xAA, 0x03, // DSAP, SSAP, Control, OUI
33            0, 0, 0, // OUI
34            0x12, 0x34, // Protocol ID
35            // Data
36            1, 2, 3, 4, 5,
37        ];
38        set_more_data(&mut buffer[..]).expect("expected set more data OK");
39        assert_eq!(
40            &[
41                // Mgmt header
42                0b00001000, 0b00100010, // Frame Control
43                0, 0, // Duration
44                3, 3, 3, 3, 3, 3, // addr1
45                2, 2, 2, 2, 2, 2, // addr2
46                1, 1, 1, 1, 1, 1, // addr3
47                0x10, 0, // Sequence Control
48                0xAA, 0xAA, 0x03, // DSAP, SSAP, Control, OUI
49                0, 0, 0, // OUI
50                0x12, 0x34, // Protocol ID
51                // Data
52                1, 2, 3, 4, 5,
53            ][..],
54            &buffer[..]
55        );
56    }
57}