diff options
| author | goueslati <[email protected]> | 2023-07-13 15:48:15 +0100 |
|---|---|---|
| committer | goueslati <[email protected]> | 2023-07-13 15:48:15 +0100 |
| commit | 68792bb9188b69c1e7629425a0d39110c602b9b2 (patch) | |
| tree | bdf9e0e31e51052987d7b8f97b8b29b7e6c2afb3 /embassy-stm32-wpan | |
| parent | 3f0c8bafb060fdf81a677f0ec37d4db11e732266 (diff) | |
final structs
unchecked
Diffstat (limited to 'embassy-stm32-wpan')
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/indications.rs | 23 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/responses.rs | 31 | ||||
| -rw-r--r-- | embassy-stm32-wpan/src/sub/mac/typedefs.rs | 17 |
3 files changed, 66 insertions, 5 deletions
diff --git a/embassy-stm32-wpan/src/sub/mac/indications.rs b/embassy-stm32-wpan/src/sub/mac/indications.rs index b67f0a686..6df4aa23a 100644 --- a/embassy-stm32-wpan/src/sub/mac/indications.rs +++ b/embassy-stm32-wpan/src/sub/mac/indications.rs | |||
| @@ -96,12 +96,31 @@ pub struct BeaconNotifyIndication { | |||
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | impl ParseableMacEvent for BeaconNotifyIndication { | 98 | impl ParseableMacEvent for BeaconNotifyIndication { |
| 99 | const SIZE: usize = 12; | 99 | const SIZE: usize = 88; |
| 100 | 100 | ||
| 101 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { | 101 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { |
| 102 | // TODO: this is unchecked | ||
| 103 | |||
| 102 | Self::validate(buf)?; | 104 | Self::validate(buf)?; |
| 103 | 105 | ||
| 104 | todo!() | 106 | let addr_list = [ |
| 107 | MacAddress::try_from(&buf[26..34])?, | ||
| 108 | MacAddress::try_from(&buf[34..42])?, | ||
| 109 | MacAddress::try_from(&buf[42..50])?, | ||
| 110 | MacAddress::try_from(&buf[50..58])?, | ||
| 111 | MacAddress::try_from(&buf[58..66])?, | ||
| 112 | MacAddress::try_from(&buf[66..74])?, | ||
| 113 | MacAddress::try_from(&buf[74..82])?, | ||
| 114 | ]; | ||
| 115 | |||
| 116 | Ok(Self { | ||
| 117 | sdu_ptr: to_u32(&buf[0..4]) as *const u8, | ||
| 118 | pan_descriptor: PanDescriptor::try_from(&buf[4..26])?, | ||
| 119 | addr_list, | ||
| 120 | bsn: buf[82], | ||
| 121 | pend_addr_spec: buf[83], | ||
| 122 | sdu_length: buf[83], | ||
| 123 | }) | ||
| 105 | } | 124 | } |
| 106 | } | 125 | } |
| 107 | 126 | ||
diff --git a/embassy-stm32-wpan/src/sub/mac/responses.rs b/embassy-stm32-wpan/src/sub/mac/responses.rs index 2b90ccdc6..0d3c09869 100644 --- a/embassy-stm32-wpan/src/sub/mac/responses.rs +++ b/embassy-stm32-wpan/src/sub/mac/responses.rs | |||
| @@ -199,12 +199,39 @@ pub struct ScanConfirm { | |||
| 199 | } | 199 | } |
| 200 | 200 | ||
| 201 | impl ParseableMacEvent for ScanConfirm { | 201 | impl ParseableMacEvent for ScanConfirm { |
| 202 | const SIZE: usize = 9; | 202 | const SIZE: usize = 185; |
| 203 | 203 | ||
| 204 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { | 204 | fn try_parse(buf: &[u8]) -> Result<Self, ()> { |
| 205 | // TODO: this is unchecked | ||
| 206 | |||
| 205 | Self::validate(buf)?; | 207 | Self::validate(buf)?; |
| 206 | 208 | ||
| 207 | todo!() | 209 | let mut energy_detect_list = [0; MAX_ED_SCAN_RESULTS_SUPPORTED]; |
| 210 | energy_detect_list.copy_from_slice(&buf[8..24]); | ||
| 211 | |||
| 212 | let pan_descriptor_list = [ | ||
| 213 | PanDescriptor::try_from(&buf[24..46])?, | ||
| 214 | PanDescriptor::try_from(&buf[46..68])?, | ||
| 215 | PanDescriptor::try_from(&buf[68..90])?, | ||
| 216 | PanDescriptor::try_from(&buf[90..102])?, | ||
| 217 | PanDescriptor::try_from(&buf[102..124])?, | ||
| 218 | PanDescriptor::try_from(&buf[124..146])?, | ||
| 219 | ]; | ||
| 220 | |||
| 221 | let mut uwb_energy_detect_list = [0; MAX_ED_SCAN_RESULTS_SUPPORTED]; | ||
| 222 | uwb_energy_detect_list.copy_from_slice(&buf[147..163]); | ||
| 223 | |||
| 224 | Ok(Self { | ||
| 225 | status: MacStatus::try_from(buf[0])?, | ||
| 226 | scan_type: ScanType::try_from(buf[1])?, | ||
| 227 | channel_page: buf[2], | ||
| 228 | unscanned_channels: [buf[3], buf[4], buf[5], buf[6]], | ||
| 229 | result_list_size: buf[7], | ||
| 230 | energy_detect_list, | ||
| 231 | pan_descriptor_list, | ||
| 232 | detected_category: buf[146], | ||
| 233 | uwb_energy_detect_list, | ||
| 234 | }) | ||
| 208 | } | 235 | } |
| 209 | } | 236 | } |
| 210 | 237 | ||
diff --git a/embassy-stm32-wpan/src/sub/mac/typedefs.rs b/embassy-stm32-wpan/src/sub/mac/typedefs.rs index 5ff051c97..30c7731b2 100644 --- a/embassy-stm32-wpan/src/sub/mac/typedefs.rs +++ b/embassy-stm32-wpan/src/sub/mac/typedefs.rs | |||
| @@ -135,6 +135,21 @@ impl MacAddress { | |||
| 135 | pub const BROADCAST: Self = Self { short: [0xFF, 0xFF] }; | 135 | pub const BROADCAST: Self = Self { short: [0xFF, 0xFF] }; |
| 136 | } | 136 | } |
| 137 | 137 | ||
| 138 | impl TryFrom<&[u8]> for MacAddress { | ||
| 139 | type Error = (); | ||
| 140 | |||
| 141 | fn try_from(buf: &[u8]) -> Result<Self, Self::Error> { | ||
| 142 | const SIZE: usize = 8; | ||
| 143 | if buf.len() < SIZE { | ||
| 144 | return Err(()); | ||
| 145 | } | ||
| 146 | |||
| 147 | Ok(Self { | ||
| 148 | extended: [buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]], | ||
| 149 | }) | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 138 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] | 153 | #[cfg_attr(feature = "defmt", derive(defmt::Format))] |
| 139 | pub struct GtsCharacteristics { | 154 | pub struct GtsCharacteristics { |
| 140 | pub fields: u8, | 155 | pub fields: u8, |
| @@ -171,7 +186,7 @@ impl TryFrom<&[u8]> for PanDescriptor { | |||
| 171 | type Error = (); | 186 | type Error = (); |
| 172 | 187 | ||
| 173 | fn try_from(buf: &[u8]) -> Result<Self, Self::Error> { | 188 | fn try_from(buf: &[u8]) -> Result<Self, Self::Error> { |
| 174 | const SIZE: usize = 24; | 189 | const SIZE: usize = 22; |
| 175 | if buf.len() < SIZE { | 190 | if buf.len() < SIZE { |
| 176 | return Err(()); | 191 | return Err(()); |
| 177 | } | 192 | } |
