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 big_endian;
11pub mod bss;
12pub mod buffer_reader;
13pub mod buffer_writer;
14pub mod capabilities;
15pub mod channel;
16pub mod data_writer;
17pub mod energy;
18pub mod error;
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::{Cbw, Channel};
39use zerocopy::{Ref, Unalign};
40use {fidl_fuchsia_wlan_common as fidl_common, fidl_fuchsia_wlan_sme as fidl_sme};
41
42pub use time::TimeUnit;
43
44#[derive(Clone, Debug, PartialEq)]
45pub struct RadioConfig {
46    pub phy: fidl_common::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_common::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>>;