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        fidl_sme::RadioConfig { phy: radio_cfg.phy, channel: radio_cfg.channel.into() }
53    }
54}
55
56impl TryFrom<fidl_sme::RadioConfig> for RadioConfig {
57    type Error = anyhow::Error;
58    fn try_from(fidl_radio_cfg: fidl_sme::RadioConfig) -> Result<RadioConfig, Self::Error> {
59        Ok(RadioConfig { phy: fidl_radio_cfg.phy, channel: fidl_radio_cfg.channel.try_into()? })
60    }
61}
62
63impl RadioConfig {
64    pub fn new(phy: fidl_ieee80211::WlanPhyType, cbw: Cbw, primary_channel: u8) -> Self {
65        RadioConfig { phy, channel: Channel::new(primary_channel, cbw) }
66    }
67}
68
69pub type UnalignedView<B, T> = Ref<B, Unalign<T>>;