1use super::config::ConfigError;
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug)]
6pub struct Status {
7 pub state: String,
8 pub phy: String,
9 pub freq: u32,
10 pub num_sta_non_erp: Option<u64>,
14 pub num_sta_no_short_slot_time: Option<u64>,
15 pub num_sta_no_short_preamble: Option<u64>,
16 pub olbc: Option<u64>,
17 pub num_sta_ht_no_gf: Option<u64>,
18 pub num_sta_no_ht: Option<u64>,
19 pub num_sta_ht_20_mhz: Option<u64>,
20 pub num_sta_ht40_intolerant: Option<u64>,
21 pub olbc_ht: Option<u64>,
22 pub ht_op_mode: Option<String>,
23 pub cac_time_seconds: Option<u64>,
24 pub cac_time_left_seconds: Option<u64>,
25 pub channel: Option<u64>,
26 pub secondary_channel: Option<u64>,
27 pub ieee80211n: Option<u64>,
28 pub ieee80211ac: Option<u64>,
29 pub ieee80211ax: Option<u64>,
30 pub beacon_int: Option<u64>,
31 pub dtim_period: Option<u64>,
32 pub ht_caps_info: Option<String>,
33 pub ht_mcs_bitmask: Option<String>,
34 #[serde(default)] pub supported_rates: String,
36 pub max_txpower: Option<u64>,
37 #[serde(default)]
38 pub bss: Vec<String>,
39 #[serde(default)]
40 pub bssid: Vec<String>,
41 #[serde(default)]
42 pub ssid: Vec<String>,
43 #[serde(default)]
44 pub num_sta: Vec<u32>,
45}
46
47impl Status {
48 pub fn from_response(response: &str) -> Result<Self, ConfigError> {
94 crate::config::from_str(response)
95 }
96}
97
98#[derive(Serialize, Deserialize, Debug)]
100pub struct Config {
101 pub bssid: String,
102 pub ssid: String,
103 pub wps_state: String,
104 #[serde(default)] pub wpa: i32,
106 pub key_mgmt: Option<String>,
108 pub group_cipher: Option<String>,
109 pub rsn_pairwise_cipher: Option<String>,
110 pub wpa_pairwise_cipher: Option<String>,
111}
112
113impl Config {
114 pub fn from_response(response: &str) -> Result<Self, ConfigError> {
133 crate::config::from_str(response)
134 }
135}
136
137#[cfg(test)]
138mod tests {
139 use super::*;
140
141 #[test]
142 fn test_config_wpa_psk() {
143 let resp = r#"
144bssid=cc:7b:5c:1a:d2:21
145ssid=\xc2\xaf\\_(\xe3\x83\x84)_/\xc2\xaf
146wps_state=disabled
147wpa=2
148key_mgmt=WPA-PSK
149group_cipher=CCMP
150rsn_pairwise_cipher=CCMP
151 "#;
152 let config = Config::from_response(resp).unwrap();
153 assert_eq!(config.wpa, 2);
154 assert_eq!(config.wps_state, "disabled");
155 assert_eq!(config.ssid, r#"¯\_(ツ)_/¯"#);
156 }
157
158 #[test]
159 fn test_config_wsp_1() {
160 let resp = r#"
161bssid=cc:7b:5c:1a:d2:21
162ssid=MY_SSID
163wps_state=not configured
164passphrase=MY_PASSPHRASE
165psk=8dbbe42cb44f21088fbb9cfbf24dc9b39787d6026d436b01b3ac7d34afb4416d
166wpa=2
167key_mgmt=WPA-PSK
168group_cipher=CCMP
169rsn_pairwise_cipher=CCMP
170 "#;
171 let config = Config::from_response(resp).unwrap();
172 assert_eq!(config.wpa, 2);
173 assert_eq!(config.wps_state, "not configured");
174 assert_eq!(config.ssid, "MY_SSID");
175 }
176
177 #[test]
178 fn test_config_wsp_2() {
179 let resp = r#"
180bssid=cc:7b:5c:1a:d2:21
181ssid=MY_SSID
182wps_state=configured
183passphrase=MY_PASSPHRASE
184psk=8dbbe42cb44f21088fbb9cfbf24dc9b39787d6026d436b01b3ac7d34afb4416d
185wpa=2
186key_mgmt=WPA-PSK
187group_cipher=CCMP
188rsn_pairwise_cipher=CCMP
189 "#;
190 let config = Config::from_response(resp).unwrap();
191 assert_eq!(config.wpa, 2);
192 assert_eq!(config.wps_state, "configured");
193 assert_eq!(config.ssid, "MY_SSID");
194 }
195
196 #[test]
197 fn test_config_open() {
198 let resp = r#"
199bssid=cc:7b:5c:1a:d2:21
200ssid=Wi-Fi
201wps_state=disabled
202 "#;
203 let config = Config::from_response(resp).unwrap();
204 assert_eq!(config.wpa, 0);
205 assert_eq!(config.ssid, "Wi-Fi");
206 }
207}