aboutsummaryrefslogtreecommitdiff
path: root/src/control.rs
diff options
context:
space:
mode:
authorkbleeke <[email protected]>2023-03-30 17:05:29 +0200
committerkbleeke <[email protected]>2023-04-28 21:28:59 +0200
commit2c5d94493c25792435102680fe8e659cc7dad9df (patch)
treebac666dbe8b406d0c1f249de6a8f3c7dc4b94731 /src/control.rs
parentc19de2984751ba6fa2972ee66cfa2a6310d5f0c1 (diff)
wifi scan ioctl
Diffstat (limited to 'src/control.rs')
-rw-r--r--src/control.rs67
1 files changed, 64 insertions, 3 deletions
diff --git a/src/control.rs b/src/control.rs
index 0c06009b9..bcb449375 100644
--- a/src/control.rs
+++ b/src/control.rs
@@ -6,11 +6,11 @@ use embassy_time::{Duration, Timer};
6 6
7pub use crate::bus::SpiBusCyw43; 7pub use crate::bus::SpiBusCyw43;
8use crate::consts::*; 8use crate::consts::*;
9use crate::events::{Event, Events}; 9use crate::events::{Event, EventSubscriber, Events};
10use crate::fmt::Bytes; 10use crate::fmt::Bytes;
11use crate::ioctl::{IoctlState, IoctlType}; 11use crate::ioctl::{IoctlState, IoctlType};
12use crate::structs::*; 12use crate::structs::*;
13use crate::{countries, PowerManagementMode}; 13use crate::{countries, events, PowerManagementMode};
14 14
15pub struct Control<'a> { 15pub struct Control<'a> {
16 state_ch: ch::StateRunner<'a>, 16 state_ch: ch::StateRunner<'a>,
@@ -245,9 +245,13 @@ impl<'a> Control<'a> {
245 } 245 }
246 246
247 async fn set_iovar(&mut self, name: &str, val: &[u8]) { 247 async fn set_iovar(&mut self, name: &str, val: &[u8]) {
248 self.set_iovar_v::<64>(name, val).await
249 }
250
251 async fn set_iovar_v<const BUFSIZE: usize>(&mut self, name: &str, val: &[u8]) {
248 info!("set {} = {:02x}", name, Bytes(val)); 252 info!("set {} = {:02x}", name, Bytes(val));
249 253
250 let mut buf = [0; 64]; 254 let mut buf = [0; BUFSIZE];
251 buf[..name.len()].copy_from_slice(name.as_bytes()); 255 buf[..name.len()].copy_from_slice(name.as_bytes());
252 buf[name.len()] = 0; 256 buf[name.len()] = 0;
253 buf[name.len() + 1..][..val.len()].copy_from_slice(val); 257 buf[name.len() + 1..][..val.len()].copy_from_slice(val);
@@ -304,4 +308,61 @@ impl<'a> Control<'a> {
304 308
305 resp_len 309 resp_len
306 } 310 }
311
312 pub async fn scan(&mut self) -> Scanner<'_> {
313 const SCANTYPE_PASSIVE: u8 = 1;
314
315 let scan_params = ScanParams {
316 version: 1,
317 action: 1,
318 sync_id: 1,
319 ssid_len: 0,
320 ssid: [0; 32],
321 bssid: [0xff; 6],
322 bss_type: 2,
323 scan_type: SCANTYPE_PASSIVE,
324 nprobes: !0,
325 active_time: !0,
326 passive_time: !0,
327 home_time: !0,
328 channel_num: 0,
329 channel_list: [0; 1],
330 };
331
332 self.events.mask.enable(&[Event::ESCAN_RESULT]);
333 let subscriber = self.events.queue.subscriber().unwrap();
334 self.set_iovar_v::<256>("escan", &scan_params.to_bytes()).await;
335
336 Scanner {
337 subscriber,
338 events: &self.events,
339 }
340 }
341}
342
343pub struct Scanner<'a> {
344 subscriber: EventSubscriber<'a>,
345 events: &'a Events,
346}
347
348impl Scanner<'_> {
349 pub async fn next(&mut self) -> Option<BssInfo> {
350 let event = self.subscriber.next_message_pure().await;
351 if event.header.status != EStatus::PARTIAL {
352 self.events.mask.disable_all();
353 return None;
354 }
355
356 if let events::Payload::BssInfo(bss) = event.payload {
357 Some(bss)
358 } else {
359 None
360 }
361 }
362}
363
364impl Drop for Scanner<'_> {
365 fn drop(&mut self) {
366 self.events.mask.disable_all();
367 }
307} 368}