wlan_common/test_utils/
fake_capabilities.rs

1// Copyright 2021 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::capabilities::{ClientCapabilities, StaCapabilities};
6use crate::ie;
7use crate::mac::CapabilityInfo;
8use zerocopy::IntoBytes;
9use {fidl_fuchsia_wlan_ieee80211 as fidl_ieee80211, fidl_fuchsia_wlan_mlme as fidl_mlme};
10
11pub fn fake_ht_capabilities_cbw(chanwidth: ie::ChanWidthSet) -> ie::HtCapabilities {
12    let mut ht_cap = ie::fake_ht_capabilities();
13    ht_cap.ht_cap_info = ht_cap.ht_cap_info.with_chan_width_set(chanwidth);
14    ht_cap
15}
16
17pub fn fake_capability_info() -> CapabilityInfo {
18    CapabilityInfo(0)
19        .with_ess(false)
20        .with_ibss(false)
21        .with_cf_pollable(false)
22        .with_cf_poll_req(false)
23        .with_privacy(false)
24        .with_short_preamble(true)
25        .with_spectrum_mgmt(false)
26        .with_qos(false)
27        .with_short_slot_time(false)
28        .with_apsd(false)
29        .with_radio_measurement(false)
30        .with_delayed_block_ack(false)
31        .with_immediate_block_ack(false)
32}
33
34pub fn fake_5ghz_band_capability() -> fidl_mlme::BandCapability {
35    fidl_mlme::BandCapability {
36        band: fidl_ieee80211::WlanBand::FiveGhz,
37        basic_rates: vec![0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c],
38        operating_channels: vec![
39            36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140,
40            144, 149, 153, 157, 161, 165,
41        ],
42        ht_cap: None,
43        vht_cap: None,
44    }
45}
46
47pub fn fake_5ghz_band_capability_ht(chanwidth: ie::ChanWidthSet) -> fidl_mlme::BandCapability {
48    let bc = fake_5ghz_band_capability();
49    fidl_mlme::BandCapability {
50        ht_cap: Some(Box::new(fidl_ieee80211::HtCapabilities {
51            bytes: fake_ht_capabilities_cbw(chanwidth).as_bytes().try_into().unwrap(),
52        })),
53        ..bc
54    }
55}
56
57pub fn fake_5ghz_band_capability_vht() -> fidl_mlme::BandCapability {
58    let bc = fake_5ghz_band_capability();
59    fidl_mlme::BandCapability {
60        ht_cap: Some(Box::new(fidl_ieee80211::HtCapabilities {
61            bytes: fake_ht_capabilities_cbw(ie::ChanWidthSet::TWENTY_FORTY)
62                .as_bytes()
63                .try_into()
64                .unwrap(),
65        })),
66        vht_cap: Some(Box::new(fidl_ieee80211::VhtCapabilities {
67            bytes: ie::fake_vht_capabilities().as_bytes().try_into().unwrap(),
68        })),
69        ..bc
70    }
71}
72
73pub fn fake_2ghz_band_capability() -> fidl_mlme::BandCapability {
74    fidl_mlme::BandCapability {
75        band: fidl_ieee80211::WlanBand::TwoGhz,
76        basic_rates: vec![0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c],
77        operating_channels: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
78        ht_cap: None,
79        vht_cap: None,
80    }
81}
82
83pub fn fake_2ghz_band_capability_ht() -> fidl_mlme::BandCapability {
84    fidl_mlme::BandCapability {
85        ht_cap: Some(Box::new(fidl_ieee80211::HtCapabilities {
86            bytes: fake_ht_capabilities_cbw(ie::ChanWidthSet::TWENTY_FORTY)
87                .as_bytes()
88                .try_into()
89                .unwrap(),
90        })),
91        ..fake_2ghz_band_capability()
92    }
93}
94
95pub fn fake_client_capabilities() -> ClientCapabilities {
96    let rates = vec![0x02, 0x04, 0x0b, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6c];
97    ClientCapabilities(StaCapabilities {
98        capability_info: fake_capability_info(),
99        rates: rates.into_iter().map(ie::SupportedRate).collect(),
100        ht_cap: Some(ie::fake_ht_capabilities()),
101        vht_cap: Some(ie::fake_vht_capabilities()),
102    })
103}