aboutsummaryrefslogtreecommitdiff
path: root/src/structs.rs
diff options
context:
space:
mode:
authorMattias Grönlund <[email protected]>2022-08-09 00:53:32 +0200
committerDario Nieuwenhuis <[email protected]>2022-08-13 15:25:34 +0200
commit3388b5cecf95d6b0bc9cf5c952e9f0aa1e019b8a (patch)
tree1c6f65c26f8b64620195b4a9fb7d708d076c341b /src/structs.rs
parentddfbfa0132285963382a4d7290d506186da31369 (diff)
Improve data checks for VHD events
For some reason I got strange events on channel 1 (ASYNCEVENT_HEADER): 0.647329 WARN unexpected ehternet type 0x0508, expected Qualcom ether type 0x886c This patch improves the validation of BCD WHD events to minimize the risk for panic.
Diffstat (limited to 'src/structs.rs')
-rw-r--r--src/structs.rs56
1 files changed, 54 insertions, 2 deletions
diff --git a/src/structs.rs b/src/structs.rs
index 060c2b060..7a7c25b26 100644
--- a/src/structs.rs
+++ b/src/structs.rs
@@ -67,7 +67,41 @@ impl_bytes!(BcdHeader);
67#[derive(Clone, Copy)] 67#[derive(Clone, Copy)]
68#[cfg_attr(feature = "defmt", derive(defmt::Format))] 68#[cfg_attr(feature = "defmt", derive(defmt::Format))]
69#[repr(C)] 69#[repr(C)]
70pub struct EthernetHeader {
71 pub destination_mac: [u8; 6],
72 pub source_mac: [u8; 6],
73 pub ether_type: u16,
74}
75
76impl EthernetHeader {
77 pub fn byteswap(&mut self) {
78 self.ether_type = self.ether_type.to_be();
79 }
80}
81
82#[derive(Clone, Copy)]
83#[cfg_attr(feature = "defmt", derive(defmt::Format))]
84#[repr(C)]
70pub struct EventHeader { 85pub struct EventHeader {
86 pub subtype: u16,
87 pub length: u16,
88 pub version: u8,
89 pub oui: [u8; 3],
90 pub user_subtype: u16,
91}
92
93impl EventHeader {
94 pub fn byteswap(&mut self) {
95 self.subtype = self.subtype.to_be();
96 self.length = self.length.to_be();
97 self.user_subtype = self.user_subtype.to_be();
98 }
99}
100
101#[derive(Clone, Copy)]
102#[cfg_attr(feature = "defmt", derive(defmt::Format))]
103#[repr(C)]
104pub struct EventMessage {
71 /// version 105 /// version
72 pub version: u16, 106 pub version: u16,
73 /// see flags below 107 /// see flags below
@@ -91,9 +125,9 @@ pub struct EventHeader {
91 /// source bsscfg index 125 /// source bsscfg index
92 pub bsscfgidx: u8, 126 pub bsscfgidx: u8,
93} 127}
94impl_bytes!(EventHeader); 128impl_bytes!(EventMessage);
95 129
96impl EventHeader { 130impl EventMessage {
97 pub fn byteswap(&mut self) { 131 pub fn byteswap(&mut self) {
98 self.version = self.version.to_be(); 132 self.version = self.version.to_be();
99 self.flags = self.flags.to_be(); 133 self.flags = self.flags.to_be();
@@ -106,6 +140,24 @@ impl EventHeader {
106} 140}
107 141
108#[derive(Clone, Copy)] 142#[derive(Clone, Copy)]
143#[cfg_attr(feature = "defmt", derive(defmt::Format))]
144#[repr(C)]
145pub struct EventPacket {
146 pub eth: EthernetHeader,
147 pub hdr: EventHeader,
148 pub msg: EventMessage,
149}
150impl_bytes!(EventPacket);
151
152impl EventPacket {
153 pub fn byteswap(&mut self) {
154 self.eth.byteswap();
155 self.hdr.byteswap();
156 self.msg.byteswap();
157 }
158}
159
160#[derive(Clone, Copy)]
109#[repr(C)] 161#[repr(C)]
110pub struct DownloadHeader { 162pub struct DownloadHeader {
111 pub flag: u16, // 163 pub flag: u16, //