esp_radio/wifi/sta/
mod.rs1use procmacros::BuilderLite;
4
5use super::{AuthenticationMethod, DisconnectReason, Protocols, Ssid};
6use crate::{WifiError, wifi::AuthenticationMethodConfig};
7
8unstable_module!(
9 #[cfg(feature = "wifi-eap")]
10 #[cfg_attr(docsrs, doc(cfg(feature = "wifi-eap")))]
11 pub mod eap;
12);
13
14#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
16#[cfg_attr(feature = "defmt", derive(defmt::Format))]
17#[non_exhaustive]
18#[repr(u8)]
19#[instability::unstable]
20pub enum ScanMethod {
21 Fast,
23 AllChannels,
25}
26
27#[derive(BuilderLite, Clone, Eq, PartialEq, Hash, Debug)]
29#[cfg_attr(feature = "defmt", derive(defmt::Format))]
30pub struct StationConfig {
31 pub(crate) ssid: Ssid,
33 pub(crate) bssid: Option<[u8; 6]>,
35 pub(crate) authentication: AuthenticationMethodConfig,
37 pub(crate) channel: Option<u8>,
39 pub(crate) protocols: Protocols,
41 #[builder_lite(unstable)]
47 pub(crate) listen_interval: u16,
48 #[builder_lite(unstable)]
52 pub(crate) beacon_timeout: u16,
53 #[builder_lite(unstable)]
60 pub(crate) failure_retry_cnt: u8,
61 #[builder_lite(unstable)]
63 pub(crate) scan_method: ScanMethod,
64}
65
66impl StationConfig {
67 pub(crate) fn validate(&self) -> Result<(), WifiError> {
68 if !(6..=31).contains(&self.beacon_timeout) {
69 return Err(WifiError::InvalidArguments);
70 }
71
72 Ok(())
73 }
74}
75
76impl Default for StationConfig {
77 fn default() -> Self {
78 StationConfig {
79 ssid: Ssid::default(),
80 bssid: None,
81 authentication: AuthenticationMethodConfig::Wpa2Personal(
82 "".try_into().expect("Password length is valid"),
83 ),
84 channel: None,
85 protocols: Protocols::default(),
86 listen_interval: 3,
87 beacon_timeout: 6,
88 failure_retry_cnt: 1,
89 scan_method: ScanMethod::Fast,
90 }
91 }
92}
93
94#[derive(Debug, Clone, PartialEq, Eq, Hash)]
96#[cfg_attr(feature = "defmt", derive(defmt::Format))]
97#[non_exhaustive]
98pub struct ConnectedInfo {
99 pub ssid: Ssid,
101 pub bssid: [u8; 6],
103 pub channel: u8,
105 pub authmode: AuthenticationMethod,
107 pub aid: u16,
109}
110
111#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
113#[cfg_attr(feature = "defmt", derive(defmt::Format))]
114#[non_exhaustive]
115pub struct DisconnectedInfo {
116 pub ssid: Ssid,
118 pub bssid: [u8; 6],
120 pub reason: DisconnectReason,
122 pub rssi: i8,
124}