diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-04-30 15:05:16 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-30 15:05:16 +0000 |
| commit | 5659269c8fb2f7d03d4a903e4ad48c8268668f0a (patch) | |
| tree | e35e59f37d50791029c2f88b3014b409ea802d39 /src/structs.rs | |
| parent | c19de2984751ba6fa2972ee66cfa2a6310d5f0c1 (diff) | |
| parent | 76b967a966677e570cc0a2942ed3ccd29b2d1017 (diff) | |
Merge pull request #70 from kbleeke/wifi-scanning-ioctl
Wifi scanning ioctl
Diffstat (limited to 'src/structs.rs')
| -rw-r--r-- | src/structs.rs | 81 |
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)] | ||
| 412 | pub 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 | } | ||
| 428 | impl_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))] | ||
| 434 | pub struct ScanResults { | ||
| 435 | pub buflen: u32, | ||
| 436 | pub version: u32, | ||
| 437 | pub sync_id: u16, | ||
| 438 | pub bss_count: u16, | ||
| 439 | } | ||
| 440 | impl_bytes!(ScanResults); | ||
| 441 | |||
| 442 | impl 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] | ||
| 465 | pub 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 | } | ||
| 475 | impl_bytes!(BssInfo); | ||
| 476 | |||
| 477 | impl 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 | } | ||
