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 ie;
19pub mod mac;
20pub mod mgmt_writer;
21pub mod organization;
22pub mod scan;
23pub mod security;
24pub mod sequence;
25pub mod sequestered;
26pub mod sink;
27pub mod stats;
28#[cfg(target_os = "fuchsia")]
29pub mod test_utils;
30pub mod tim;
31pub mod time;
32#[cfg(target_os = "fuchsia")]
33pub mod timer;
34pub mod tx_vector;
35pub mod wmm;
36
37use channel::{Cbw, Channel};
38use fidl_fuchsia_wlan_ieee80211 as fidl_ieee80211;
39use fidl_fuchsia_wlan_sme as fidl_sme;
40use zerocopy::{Ref, Unalign};
41
42pub use time::TimeUnit;
43
44#[derive(Clone, Debug, PartialEq)]
45pub struct RadioConfig {
46    pub phy: fidl_ieee80211::WlanPhyType,
47    pub channel: Channel,
48}
49
50impl From<RadioConfig> for fidl_sme::RadioConfig {
51    fn from(radio_cfg: RadioConfig) -> fidl_sme::RadioConfig {
52        let (cbw, _) = radio_cfg.channel.cbw.to_fidl();
53        fidl_sme::RadioConfig {
54            phy: radio_cfg.phy,
55            primary: radio_cfg.channel.into(),
56            bandwidth: cbw,
57        }
58    }
59}
60
61impl TryFrom<fidl_sme::RadioConfig> for RadioConfig {
62    type Error = anyhow::Error;
63    fn try_from(fidl_radio_cfg: fidl_sme::RadioConfig) -> Result<RadioConfig, Self::Error> {
64        let cbw = Cbw::from_fidl(fidl_radio_cfg.bandwidth, 0)?;
65        Ok(RadioConfig {
66            phy: fidl_radio_cfg.phy,
67            channel: Channel::new(fidl_radio_cfg.primary.number, cbw, fidl_radio_cfg.primary.band),
68        })
69    }
70}
71
72impl RadioConfig {
73    pub fn new(
74        phy: fidl_ieee80211::WlanPhyType,
75        cbw: Cbw,
76        primary_channel: u8,
77        band: fidl_ieee80211::WlanBand,
78    ) -> Self {
79        RadioConfig { phy, channel: Channel::new(primary_channel, cbw, band) }
80    }
81}
82
83pub type UnalignedView<B, T> = Ref<B, Unalign<T>>;