1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2021 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//! Crate wlan-common hosts common libraries
//! to be used for WLAN SME, MLME, and binaries written in Rust.

#![cfg_attr(feature = "benchmark", feature(test))]
pub mod append;
pub mod big_endian;
pub mod bss;
pub mod buffer_reader;
pub mod buffer_writer;
pub mod capabilities;
pub mod channel;
pub mod data_writer;
pub mod energy;
pub mod error;
pub mod ie;
pub mod mac;
pub mod mgmt_writer;
pub mod organization;
pub mod scan;
pub mod security;
pub mod sequence;
pub mod sequestered;
pub mod sink;
pub mod stats;
#[cfg(target_os = "fuchsia")]
pub mod test_utils;
pub mod tim;
pub mod time;
#[cfg(target_os = "fuchsia")]
pub mod timer;
pub mod tx_vector;
pub mod wmm;

use channel::{Cbw, Channel};
use zerocopy::{Ref, Unalign};
use {fidl_fuchsia_wlan_common as fidl_common, fidl_fuchsia_wlan_sme as fidl_sme};

pub use time::TimeUnit;

#[derive(Clone, Debug, PartialEq)]
pub struct RadioConfig {
    pub phy: fidl_common::WlanPhyType,
    pub channel: Channel,
}

impl From<RadioConfig> for fidl_sme::RadioConfig {
    fn from(radio_cfg: RadioConfig) -> fidl_sme::RadioConfig {
        fidl_sme::RadioConfig { phy: radio_cfg.phy, channel: radio_cfg.channel.into() }
    }
}

impl TryFrom<fidl_sme::RadioConfig> for RadioConfig {
    type Error = anyhow::Error;
    fn try_from(fidl_radio_cfg: fidl_sme::RadioConfig) -> Result<RadioConfig, Self::Error> {
        Ok(RadioConfig { phy: fidl_radio_cfg.phy, channel: fidl_radio_cfg.channel.try_into()? })
    }
}

impl RadioConfig {
    pub fn new(phy: fidl_common::WlanPhyType, cbw: Cbw, primary_channel: u8) -> Self {
        RadioConfig { phy, channel: Channel::new(primary_channel, cbw) }
    }
}

pub type UnalignedView<B, T> = Ref<B, Unalign<T>>;