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