fullmac_helpers/
config.rs

1// Copyright 2024 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 test_realm_helpers::constants::DEFAULT_CLIENT_STA_ADDR;
6use wlan_common::ie::fake_ht_capabilities;
7use zerocopy::IntoBytes;
8use {
9    fidl_fuchsia_wlan_common as fidl_common, fidl_fuchsia_wlan_fullmac as fidl_fullmac,
10    fidl_fuchsia_wlan_ieee80211 as fidl_ieee80211, fidl_fuchsia_wlan_sme as fidl_sme,
11};
12
13/// Contains all the configuration required for the fullmac driver.
14/// These are primarily used to respond to SME query requests.
15/// By default, the configuration is a client with DEFAULT_CLIENT_STA_ADDR that
16/// supports 2.4 GHz bands and HT capabilities.
17#[derive(Debug, Clone)]
18pub struct FullmacDriverConfig {
19    pub query_info: fidl_fullmac::WlanFullmacImplQueryResponse,
20    pub mac_sublayer_support: fidl_common::MacSublayerSupport,
21    pub security_support: fidl_common::SecuritySupport,
22    pub spectrum_management_support: fidl_common::SpectrumManagementSupport,
23    pub sme_legacy_privacy_support: fidl_sme::LegacyPrivacySupport,
24}
25
26impl Default for FullmacDriverConfig {
27    /// By default, the driver is configured as a client.
28    fn default() -> Self {
29        Self {
30            query_info: default_fullmac_query_info(),
31            mac_sublayer_support: default_mac_sublayer_support(),
32            security_support: default_security_support(),
33            spectrum_management_support: default_spectrum_management_support(),
34            sme_legacy_privacy_support: default_sme_legacy_privacy_support(),
35        }
36    }
37}
38
39impl FullmacDriverConfig {
40    pub fn default_ap() -> Self {
41        Self {
42            query_info: fidl_fullmac::WlanFullmacImplQueryResponse {
43                role: Some(fidl_common::WlanMacRole::Ap),
44                ..default_fullmac_query_info()
45            },
46            ..Default::default()
47        }
48    }
49}
50
51pub fn default_fullmac_query_info() -> fidl_fullmac::WlanFullmacImplQueryResponse {
52    fidl_fullmac::WlanFullmacImplQueryResponse {
53        sta_addr: Some(DEFAULT_CLIENT_STA_ADDR),
54        factory_addr: Some(DEFAULT_CLIENT_STA_ADDR),
55        role: Some(fidl_common::WlanMacRole::Client),
56        band_caps: Some(vec![default_fullmac_band_capability()]),
57        ..Default::default()
58    }
59}
60
61pub fn default_mac_sublayer_support() -> fidl_common::MacSublayerSupport {
62    fidl_common::MacSublayerSupport {
63        rate_selection_offload: Some(fidl_common::RateSelectionOffloadExtension {
64            supported: Some(false),
65            ..Default::default()
66        }),
67        data_plane: Some(fidl_common::DataPlaneExtension {
68            data_plane_type: Some(fidl_common::DataPlaneType::GenericNetworkDevice),
69            ..Default::default()
70        }),
71        device: Some(fidl_common::DeviceExtension {
72            is_synthetic: Some(false),
73            mac_implementation_type: Some(fidl_common::MacImplementationType::Fullmac),
74            tx_status_report_supported: Some(false),
75            ..Default::default()
76        }),
77        ..Default::default()
78    }
79}
80
81pub fn default_security_support() -> fidl_common::SecuritySupport {
82    fidl_common::SecuritySupport {
83        sae: Some(fidl_common::SaeFeature {
84            driver_handler_supported: Some(false),
85            sme_handler_supported: Some(true),
86            hash_to_element_supported: Some(false),
87            ..Default::default()
88        }),
89        mfp: Some(fidl_common::MfpFeature { supported: Some(true), ..Default::default() }),
90        owe: Some(fidl_common::OweFeature { supported: Some(true), ..Default::default() }),
91        ..Default::default()
92    }
93}
94
95pub fn default_sme_legacy_privacy_support() -> fidl_sme::LegacyPrivacySupport {
96    fidl_sme::LegacyPrivacySupport { wep_supported: false, wpa1_supported: false }
97}
98
99fn default_spectrum_management_support() -> fidl_common::SpectrumManagementSupport {
100    fidl_common::SpectrumManagementSupport {
101        dfs: Some(fidl_common::DfsFeature { supported: Some(false), ..Default::default() }),
102        ..Default::default()
103    }
104}
105
106fn default_fullmac_band_capability() -> fidl_fullmac::BandCapability {
107    fidl_fullmac::BandCapability {
108        band: Some(fidl_ieee80211::WlanBand::TwoGhz),
109        basic_rates: Some(vec![2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108]),
110        ht_caps: Some(fidl_ieee80211::HtCapabilities {
111            bytes: fake_ht_capabilities().as_bytes().try_into().unwrap(),
112        }),
113        vht_caps: None,
114        // By default, the fullmac fake driver supports 2 GHz channels in the US.
115        // Specifically, channels 12-14 are avoided or not allowed in the US.
116        operating_channels: Some((1..11).collect()),
117        ..Default::default()
118    }
119}