Skip to main content

wlan_common/
lib.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
5//! Crate wlan-common hosts common libraries
6//! to be used for WLAN SME, MLME, and binaries written in Rust.
7
8#![cfg_attr(feature = "benchmark", feature(test))]
9pub mod append;
10pub mod bss;
11pub mod buffer_reader;
12pub mod buffer_writer;
13pub mod capabilities;
14pub mod channel;
15pub mod data_writer;
16pub mod energy;
17pub mod error;
18pub mod historical_list;
19pub mod ie;
20pub mod mac;
21pub mod mgmt_writer;
22pub mod organization;
23pub mod scan;
24pub mod security;
25pub mod sequence;
26pub mod sequestered;
27pub mod sink;
28pub mod stats;
29#[cfg(target_os = "fuchsia")]
30pub mod test_utils;
31pub mod tim;
32pub mod time;
33#[cfg(target_os = "fuchsia")]
34pub mod timer;
35pub mod tx_vector;
36pub mod wmm;
37
38use channel::{Bandwidth, Channel};
39use fidl_fuchsia_wlan_ieee80211 as fidl_ieee80211;
40use fidl_fuchsia_wlan_sme as fidl_sme;
41use zerocopy::{Ref, Unalign};
42
43pub use time::TimeUnit;
44
45#[derive(Clone, Debug, PartialEq)]
46pub struct RadioConfig {
47    pub phy: fidl_ieee80211::WlanPhyType,
48    pub channel: Channel,
49}
50
51impl From<RadioConfig> for fidl_sme::RadioConfig {
52    fn from(radio_cfg: RadioConfig) -> fidl_sme::RadioConfig {
53        let (cbw, _) = radio_cfg.channel.bandwidth.to_fidl();
54        fidl_sme::RadioConfig {
55            phy: radio_cfg.phy,
56            primary: radio_cfg.channel.into(),
57            bandwidth: cbw,
58        }
59    }
60}
61
62impl TryFrom<fidl_sme::RadioConfig> for RadioConfig {
63    type Error = anyhow::Error;
64    fn try_from(fidl_radio_cfg: fidl_sme::RadioConfig) -> Result<RadioConfig, Self::Error> {
65        let cbw = Bandwidth::from_fidl(fidl_radio_cfg.bandwidth, 0)?;
66        Ok(RadioConfig {
67            phy: fidl_radio_cfg.phy,
68            channel: Channel::new(fidl_radio_cfg.primary.number, cbw, fidl_radio_cfg.primary.band),
69        })
70    }
71}
72
73impl RadioConfig {
74    pub fn new(
75        phy: fidl_ieee80211::WlanPhyType,
76        bandwidth: Bandwidth,
77        primary_channel: u8,
78        band: fidl_ieee80211::WlanBand,
79    ) -> Self {
80        RadioConfig { phy, channel: Channel::new(primary_channel, bandwidth, band) }
81    }
82}
83
84pub type UnalignedView<B, T> = Ref<B, Unalign<T>>;