aboutsummaryrefslogtreecommitdiff
path: root/src/structs.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/structs.rs
parentc19de2984751ba6fa2972ee66cfa2a6310d5f0c1 (diff)
wifi scan ioctl
Diffstat (limited to 'src/structs.rs')
-rw-r--r--src/structs.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/structs.rs b/src/structs.rs
index f54ec7fcf..d01d5a65c 100644
--- a/src/structs.rs
+++ b/src/structs.rs
@@ -404,3 +404,84 @@ impl EventMask {
404 self.events[evt / 8] &= !(1 << (evt % 8)); 404 self.events[evt / 8] &= !(1 << (evt % 8));
405 } 405 }
406} 406}
407
408/// Parameters for a wifi scan
409#[derive(Clone, Copy)]
410#[cfg_attr(feature = "defmt", derive(defmt::Format))]
411#[repr(C)]
412pub struct ScanParams {
413 pub version: u32,
414 pub action: u16,
415 pub sync_id: u16,
416 pub ssid_len: u32,
417 pub ssid: [u8; 32],
418 pub bssid: [u8; 6],
419 pub bss_type: u8,
420 pub scan_type: u8,
421 pub nprobes: u32,
422 pub active_time: u32,
423 pub passive_time: u32,
424 pub home_time: u32,
425 pub channel_num: u32,
426 pub channel_list: [u16; 1],
427}
428impl_bytes!(ScanParams);
429
430/// Wifi Scan Results Header, followed by `bss_count` `BssInfo`
431#[derive(Clone, Copy)]
432// #[cfg_attr(feature = "defmt", derive(defmt::Format))]
433#[repr(C, packed(2))]
434pub struct ScanResults {
435 pub buflen: u32,
436 pub version: u32,
437 pub sync_id: u16,
438 pub bss_count: u16,
439}
440impl_bytes!(ScanResults);
441
442impl ScanResults {
443 pub fn parse(packet: &mut [u8]) -> Option<(&mut ScanResults, &mut [u8])> {
444 if packet.len() < ScanResults::SIZE {
445 return None;
446 }
447
448 let (scan_results, bssinfo) = packet.split_at_mut(ScanResults::SIZE);
449 let scan_results = ScanResults::from_bytes_mut(scan_results.try_into().unwrap());
450
451 if scan_results.bss_count > 0 && bssinfo.len() < BssInfo::SIZE {
452 warn!("Scan result, incomplete BssInfo");
453 return None;
454 }
455
456 Some((scan_results, bssinfo))
457 }
458}
459
460/// Wifi Scan Result
461#[derive(Clone, Copy)]
462// #[cfg_attr(feature = "defmt", derive(defmt::Format))]
463#[repr(C, packed(2))]
464#[non_exhaustive]
465pub struct BssInfo {
466 pub version: u32,
467 pub length: u32,
468 pub bssid: [u8; 6],
469 pub beacon_period: u16,
470 pub capability: u16,
471 pub ssid_len: u8,
472 pub ssid: [u8; 32],
473 // there will be more stuff here
474}
475impl_bytes!(BssInfo);
476
477impl BssInfo {
478 pub fn parse(packet: &mut [u8]) -> Option<&mut Self> {
479 if packet.len() < BssInfo::SIZE {
480 return None;
481 }
482
483 Some(BssInfo::from_bytes_mut(
484 packet[..BssInfo::SIZE].as_mut().try_into().unwrap(),
485 ))
486 }
487}