use super::config::ConfigError;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub struct Status {
pub state: String,
pub phy: String,
pub freq: u32,
pub num_sta_non_erp: Option<u64>,
pub num_sta_no_short_slot_time: Option<u64>,
pub num_sta_no_short_preamble: Option<u64>,
pub olbc: Option<u64>,
pub num_sta_ht_no_gf: Option<u64>,
pub num_sta_no_ht: Option<u64>,
pub num_sta_ht_20_mhz: Option<u64>,
pub num_sta_ht40_intolerant: Option<u64>,
pub olbc_ht: Option<u64>,
pub ht_op_mode: Option<String>,
pub cac_time_seconds: Option<u64>,
pub cac_time_left_seconds: Option<u64>,
pub channel: Option<u64>,
pub secondary_channel: Option<u64>,
pub ieee80211n: Option<u64>,
pub ieee80211ac: Option<u64>,
pub ieee80211ax: Option<u64>,
pub beacon_int: Option<u64>,
pub dtim_period: Option<u64>,
pub ht_caps_info: Option<String>,
pub ht_mcs_bitmask: Option<String>,
#[serde(default)] pub supported_rates: String,
pub max_txpower: Option<u64>,
#[serde(default)]
pub bss: Vec<String>,
#[serde(default)]
pub bssid: Vec<String>,
#[serde(default)]
pub ssid: Vec<String>,
#[serde(default)]
pub num_sta: Vec<u32>,
}
impl Status {
pub fn from_response(response: &str) -> Result<Self, ConfigError> {
crate::config::from_str(response)
}
}
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub bssid: String,
pub ssid: String,
pub wps_state: String,
#[serde(default)] pub wpa: i32,
pub key_mgmt: Option<String>,
pub group_cipher: Option<String>,
pub rsn_pairwise_cipher: Option<String>,
pub wpa_pairwise_cipher: Option<String>,
}
impl Config {
pub fn from_response(response: &str) -> Result<Self, ConfigError> {
crate::config::from_str(response)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_wpa_psk() {
let resp = r#"
bssid=cc:7b:5c:1a:d2:21
ssid=\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf
wps_state=disabled
wpa=2
key_mgmt=WPA-PSK
group_cipher=CCMP
rsn_pairwise_cipher=CCMP
"#;
let config = Config::from_response(resp).unwrap();
assert_eq!(config.wpa, 2);
assert_eq!(config.wps_state, "disabled");
assert_eq!(config.ssid, r#"¯\_(ツ)_/¯"#);
}
#[test]
fn test_config_wsp_1() {
let resp = r#"
bssid=cc:7b:5c:1a:d2:21
ssid=MY_SSID
wps_state=not configured
passphrase=MY_PASSPHRASE
psk=8dbbe42cb44f21088fbb9cfbf24dc9b39787d6026d436b01b3ac7d34afb4416d
wpa=2
key_mgmt=WPA-PSK
group_cipher=CCMP
rsn_pairwise_cipher=CCMP
"#;
let config = Config::from_response(resp).unwrap();
assert_eq!(config.wpa, 2);
assert_eq!(config.wps_state, "not configured");
assert_eq!(config.ssid, "MY_SSID");
}
#[test]
fn test_config_wsp_2() {
let resp = r#"
bssid=cc:7b:5c:1a:d2:21
ssid=MY_SSID
wps_state=configured
passphrase=MY_PASSPHRASE
psk=8dbbe42cb44f21088fbb9cfbf24dc9b39787d6026d436b01b3ac7d34afb4416d
wpa=2
key_mgmt=WPA-PSK
group_cipher=CCMP
rsn_pairwise_cipher=CCMP
"#;
let config = Config::from_response(resp).unwrap();
assert_eq!(config.wpa, 2);
assert_eq!(config.wps_state, "configured");
assert_eq!(config.ssid, "MY_SSID");
}
#[test]
fn test_config_open() {
let resp = r#"
bssid=cc:7b:5c:1a:d2:21
ssid=Wi-Fi
wps_state=disabled
"#;
let config = Config::from_response(resp).unwrap();
assert_eq!(config.wpa, 0);
assert_eq!(config.ssid, "Wi-Fi");
}
}