aboutsummaryrefslogtreecommitdiff
path: root/cyw43/src/structs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cyw43/src/structs.rs')
-rw-r--r--cyw43/src/structs.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/cyw43/src/structs.rs b/cyw43/src/structs.rs
index 5ba633c74..5ea62d95b 100644
--- a/cyw43/src/structs.rs
+++ b/cyw43/src/structs.rs
@@ -4,13 +4,16 @@ use crate::fmt::Bytes;
4macro_rules! impl_bytes { 4macro_rules! impl_bytes {
5 ($t:ident) => { 5 ($t:ident) => {
6 impl $t { 6 impl $t {
7 /// Bytes consumed by this type.
7 pub const SIZE: usize = core::mem::size_of::<Self>(); 8 pub const SIZE: usize = core::mem::size_of::<Self>();
8 9
10 /// Convert to byte array.
9 #[allow(unused)] 11 #[allow(unused)]
10 pub fn to_bytes(&self) -> [u8; Self::SIZE] { 12 pub fn to_bytes(&self) -> [u8; Self::SIZE] {
11 unsafe { core::mem::transmute(*self) } 13 unsafe { core::mem::transmute(*self) }
12 } 14 }
13 15
16 /// Create from byte array.
14 #[allow(unused)] 17 #[allow(unused)]
15 pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> &Self { 18 pub fn from_bytes(bytes: &[u8; Self::SIZE]) -> &Self {
16 let alignment = core::mem::align_of::<Self>(); 19 let alignment = core::mem::align_of::<Self>();
@@ -23,6 +26,7 @@ macro_rules! impl_bytes {
23 unsafe { core::mem::transmute(bytes) } 26 unsafe { core::mem::transmute(bytes) }
24 } 27 }
25 28
29 /// Create from mutable byte array.
26 #[allow(unused)] 30 #[allow(unused)]
27 pub fn from_bytes_mut(bytes: &mut [u8; Self::SIZE]) -> &mut Self { 31 pub fn from_bytes_mut(bytes: &mut [u8; Self::SIZE]) -> &mut Self {
28 let alignment = core::mem::align_of::<Self>(); 32 let alignment = core::mem::align_of::<Self>();
@@ -204,6 +208,7 @@ pub struct EthernetHeader {
204} 208}
205 209
206impl EthernetHeader { 210impl EthernetHeader {
211 /// Swap endianness.
207 pub fn byteswap(&mut self) { 212 pub fn byteswap(&mut self) {
208 self.ether_type = self.ether_type.to_be(); 213 self.ether_type = self.ether_type.to_be();
209 } 214 }
@@ -472,19 +477,26 @@ impl ScanResults {
472#[repr(C, packed(2))] 477#[repr(C, packed(2))]
473#[non_exhaustive] 478#[non_exhaustive]
474pub struct BssInfo { 479pub struct BssInfo {
480 /// Version.
475 pub version: u32, 481 pub version: u32,
482 /// Length.
476 pub length: u32, 483 pub length: u32,
484 /// BSSID.
477 pub bssid: [u8; 6], 485 pub bssid: [u8; 6],
486 /// Beacon period.
478 pub beacon_period: u16, 487 pub beacon_period: u16,
488 /// Capability.
479 pub capability: u16, 489 pub capability: u16,
490 /// SSID length.
480 pub ssid_len: u8, 491 pub ssid_len: u8,
492 /// SSID.
481 pub ssid: [u8; 32], 493 pub ssid: [u8; 32],
482 // there will be more stuff here 494 // there will be more stuff here
483} 495}
484impl_bytes!(BssInfo); 496impl_bytes!(BssInfo);
485 497
486impl BssInfo { 498impl BssInfo {
487 pub fn parse(packet: &mut [u8]) -> Option<&mut Self> { 499 pub(crate) fn parse(packet: &mut [u8]) -> Option<&mut Self> {
488 if packet.len() < BssInfo::SIZE { 500 if packet.len() < BssInfo::SIZE {
489 return None; 501 return None;
490 } 502 }