1#![no_std]
2
3pub mod command;
4mod constants;
5
6use atat::{asynch::AtatClient, Error};
7use command::wlan::SecurityEapType as WlanEnterpriseEapType;
8use command::{
9 wlan::{Mode as WlanMode, SecurityType},
10 EmptyResponse,
11};
12pub use constants::*;
13
14pub struct Calypso<C: AtatClient> {
15 client: C,
16}
17
18impl<C: AtatClient> Calypso<C> {
19 pub fn new(client: C) -> Self {
20 Self { client }
21 }
22
23 pub async fn start(&mut self) -> Result<EmptyResponse, Error> {
25 self.client.send(&command::device::Start {}).await
26 }
27
28 pub async fn stop(&mut self) -> Result<EmptyResponse, Error> {
30 self.client
31 .send(&command::device::Stop { timeout: 0 })
32 .await
33 }
34
35 pub async fn test(&mut self) -> Result<EmptyResponse, Error> {
37 self.client.send(&command::device::Test {}).await
38 }
39
40 pub async fn reboot(&mut self) -> Result<EmptyResponse, Error> {
42 self.client.send(&command::device::Reboot {}).await
43 }
44
45 pub async fn factory_reset(&mut self) -> Result<EmptyResponse, Error> {
50 self.client.send(&command::device::FactoryReset {}).await
51 }
52
53 pub async fn sleep(
57 &mut self,
58 seconds: u32,
59 ) -> Result<EmptyResponse, Error> {
60 self.client
61 .send(&command::device::Sleep {
62 timeout_secs: seconds,
63 })
64 .await
65 }
66
67 pub async fn sleep_forever(&mut self) -> Result<EmptyResponse, Error> {
69 self.client
70 .send(&command::device::Sleep { timeout_secs: 0 })
71 .await
72 }
73
74 pub async fn powersave(&mut self) -> Result<EmptyResponse, Error> {
76 self.client.send(&command::device::PowerSave {}).await
77 }
78
79 pub async fn provisioning_start(&mut self) -> Result<EmptyResponse, Error> {
81 self.client
82 .send(&command::device::ProvisioningStart {})
83 .await
84 }
85
86 pub async fn provisioning_stop(&mut self) -> Result<EmptyResponse, Error> {
88 self.client
89 .send(&command::device::ProvisioningStop {})
90 .await
91 }
92
93 pub async fn wlan_set_mode(
95 &mut self,
96 mode: WlanMode,
97 ) -> Result<EmptyResponse, Error> {
98 self.client
99 .send(&command::wlan::SetMode { mode: mode.into() })
100 .await
101 }
102
103 pub async fn wlan_scan(
105 &mut self,
106 index: u8,
107 count: u8,
108 ) -> Result<EmptyResponse, Error> {
109 self.client
110 .send(&command::wlan::Scan { index, count })
111 .await
112 }
113
114 pub async fn wlan_connect_open(
116 &mut self,
117 ssid: &str,
118 bssid: Option<&str>,
119 ) -> Result<EmptyResponse, Error> {
120 self.client
121 .send(&command::wlan::Connect {
122 ssid: ssid.into(),
123 bssid: bssid.map(|inner| inner.into()),
124 security_type: SecurityType::Open.into(),
125 security_key: None,
126 security_ext_user: None,
127 security_ext_anon_user: None,
128 security_ext_eap_method: None,
129 })
130 .await
131 }
132
133 pub async fn wlan_connect_wep(
135 &mut self,
136 ssid: &str,
137 bssid: Option<&str>,
138 password: &str,
139 ) -> Result<EmptyResponse, Error> {
140 self.client
141 .send(&command::wlan::Connect {
142 ssid: ssid.into(),
143 bssid: bssid.map(|inner| inner.into()),
144 security_type: SecurityType::Wep.into(),
145 security_key: Some(password.into()),
146 security_ext_user: None,
147 security_ext_anon_user: None,
148 security_ext_eap_method: None,
149 })
150 .await
151 }
152
153 pub async fn wlan_connect_wep_shared(
155 &mut self,
156 ssid: &str,
157 bssid: Option<&str>,
158 password: &str,
159 ) -> Result<EmptyResponse, Error> {
160 self.client
161 .send(&command::wlan::Connect {
162 ssid: ssid.into(),
163 bssid: bssid.map(|inner| inner.into()),
164 security_type: SecurityType::WepShared.into(),
165 security_key: Some(password.into()),
166 security_ext_user: None,
167 security_ext_anon_user: None,
168 security_ext_eap_method: None,
169 })
170 .await
171 }
172
173 pub async fn wlan_connect_wpa_wpa2(
175 &mut self,
176 ssid: &str,
177 bssid: Option<&str>,
178 password: &str,
179 ) -> Result<EmptyResponse, Error> {
180 self.client
181 .send(&command::wlan::Connect {
182 ssid: ssid.into(),
183 bssid: bssid.map(|inner| inner.into()),
184 security_type: SecurityType::WpaWpa2.into(),
185 security_key: Some(password.into()),
186 security_ext_user: None,
187 security_ext_anon_user: None,
188 security_ext_eap_method: None,
189 })
190 .await
191 }
192
193 pub async fn wlan_connect_wpa2_plus(
195 &mut self,
196 ssid: &str,
197 bssid: Option<&str>,
198 password: &str,
199 ) -> Result<EmptyResponse, Error> {
200 self.client
201 .send(&command::wlan::Connect {
202 ssid: ssid.into(),
203 bssid: bssid.map(|inner| inner.into()),
204 security_type: SecurityType::Wpa2Plus.into(),
205 security_key: Some(password.into()),
206 security_ext_user: None,
207 security_ext_anon_user: None,
208 security_ext_eap_method: None,
209 })
210 .await
211 }
212
213 pub async fn wlan_connect_wpa3(
215 &mut self,
216 ssid: &str,
217 bssid: Option<&str>,
218 password: &str,
219 ) -> Result<EmptyResponse, Error> {
220 self.client
221 .send(&command::wlan::Connect {
222 ssid: ssid.into(),
223 bssid: bssid.map(|inner| inner.into()),
224 security_type: SecurityType::Wpa3.into(),
225 security_key: Some(password.into()),
226 security_ext_user: None,
227 security_ext_anon_user: None,
228 security_ext_eap_method: None,
229 })
230 .await
231 }
232
233 pub async fn wlan_connect_enterprise(
235 &mut self,
236 ssid: &str,
237 bssid: Option<&str>,
238 user: Option<&str>,
239 anon_user: Option<&str>,
240 password: &str,
241 eap_method: WlanEnterpriseEapType,
242 ) -> Result<EmptyResponse, Error> {
243 self.client
244 .send(&command::wlan::Connect {
245 ssid: ssid.into(),
246 bssid: bssid.map(|inner| inner.into()),
247 security_type: SecurityType::WpaEnt.into(),
248 security_key: Some(password.into()),
249 security_ext_user: user.map(|inner| inner.into()),
250 security_ext_anon_user: anon_user.map(|inner| inner.into()),
251 security_ext_eap_method: Some(eap_method.into()),
252 })
253 .await
254 }
255
256 pub async fn wlan_connect_wps_pbc(
258 &mut self,
259 ssid: &str,
260 bssid: Option<&str>,
261 ) -> Result<EmptyResponse, Error> {
262 self.client
263 .send(&command::wlan::Connect {
264 ssid: ssid.into(),
265 bssid: bssid.map(|inner| inner.into()),
266 security_type: SecurityType::WpsPbc.into(),
267 security_key: None,
268 security_ext_user: None,
269 security_ext_anon_user: None,
270 security_ext_eap_method: None,
271 })
272 .await
273 }
274
275 pub async fn wlan_connect_wps_pin(
277 &mut self,
278 ssid: &str,
279 bssid: Option<&str>,
280 ) -> Result<EmptyResponse, Error> {
281 self.client
282 .send(&command::wlan::Connect {
283 ssid: ssid.into(),
284 bssid: bssid.map(|inner| inner.into()),
285 security_type: SecurityType::WpsPin.into(),
286 security_key: None,
287 security_ext_user: None,
288 security_ext_anon_user: None,
289 security_ext_eap_method: None,
290 })
291 .await
292 }
293
294 pub async fn wifi_disconnect(&mut self) -> Result<EmptyResponse, Error> {
296 self.client.send(&command::wlan::Disconnect {}).await
297 }
298}