wlan_hw_sim/
config.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 ieee80211::{MacAddr, MacAddrBytes};
6use wlan_common::ie::*;
7use zerocopy::IntoBytes;
8use {
9    fidl_fuchsia_wlan_common as fidl_common, fidl_fuchsia_wlan_device as fidl_device,
10    fidl_fuchsia_wlan_ieee80211 as fidl_ieee80211, fidl_fuchsia_wlan_softmac as fidl_softmac,
11    fidl_fuchsia_wlan_tap as wlantap,
12};
13
14pub(crate) fn create_wlantap_config(
15    name: String,
16    sta_addr: MacAddr,
17    mac_role: fidl_common::WlanMacRole,
18) -> wlantap::WlantapPhyConfig {
19    wlantap::WlantapPhyConfig {
20        // TODO(https://fxbug.dev/42143255): wlantap will configure all of its ifaces to use the same MAC address
21        sta_addr: sta_addr.to_array(),
22        factory_addr: sta_addr.to_array(),
23        supported_phys: vec![
24            fidl_common::WlanPhyType::Dsss,
25            fidl_common::WlanPhyType::Hr,
26            fidl_common::WlanPhyType::Ofdm,
27            fidl_common::WlanPhyType::Erp,
28            fidl_common::WlanPhyType::Ht,
29        ],
30        mac_role: mac_role,
31        hardware_capability: 0,
32        bands: vec![create_2_4_ghz_band_info()],
33        name,
34        quiet: false,
35        discovery_support: fidl_softmac::DiscoverySupport {
36            scan_offload: Some(fidl_softmac::ScanOffloadExtension {
37                supported: Some(true),
38                scan_cancel_supported: Some(false),
39                ..Default::default()
40            }),
41            probe_response_offload: Some(fidl_softmac::ProbeResponseOffloadExtension {
42                supported: Some(false),
43                ..Default::default()
44            }),
45            ..Default::default()
46        },
47        mac_sublayer_support: fidl_common::MacSublayerSupport {
48            rate_selection_offload: Some(fidl_common::RateSelectionOffloadExtension {
49                supported: Some(false),
50                ..Default::default()
51            }),
52            data_plane: Some(fidl_common::DataPlaneExtension {
53                data_plane_type: Some(fidl_common::DataPlaneType::EthernetDevice),
54                ..Default::default()
55            }),
56            device: Some(fidl_common::DeviceExtension {
57                is_synthetic: Some(true),
58                mac_implementation_type: Some(fidl_common::MacImplementationType::Softmac),
59                tx_status_report_supported: Some(true),
60                ..Default::default()
61            }),
62            ..Default::default()
63        },
64        security_support: fidl_common::SecuritySupport {
65            sae: Some(fidl_common::SaeFeature {
66                driver_handler_supported: Some(false),
67                sme_handler_supported: Some(true),
68                hash_to_element_supported: Some(false),
69                ..Default::default()
70            }),
71            mfp: Some(fidl_common::MfpFeature { supported: Some(true), ..Default::default() }),
72            owe: Some(fidl_common::OweFeature { supported: Some(true), ..Default::default() }),
73            ..Default::default()
74        },
75        spectrum_management_support: fidl_common::SpectrumManagementSupport {
76            dfs: Some(fidl_common::DfsFeature { supported: Some(false), ..Default::default() }),
77            ..Default::default()
78        },
79    }
80}
81
82fn create_2_4_ghz_band_info() -> fidl_device::BandInfo {
83    fidl_device::BandInfo {
84        band: fidl_ieee80211::WlanBand::TwoGhz,
85        ht_caps: Some(Box::new(fidl_ieee80211::HtCapabilities {
86            bytes: fake_ht_capabilities().as_bytes().try_into().unwrap(),
87        })),
88        vht_caps: None,
89        rates: vec![2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108],
90        operating_channels: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
91    }
92}