aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBailey Kuo <formosa@google.com>2023-12-14 19:46:14 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2023-12-14 19:46:14 +0000
commitd7a317ef1782d50274f733b7b918317c051c82c4 (patch)
treefed58f89b62b96c39437641c9570018f4f9ef29c
parentec216f7e95dfb31eb73bbf468fb6fbda33a4f201 (diff)
parentdc31f7319f01d20d89ffca886c4313ae54183ec1 (diff)
downloadnetsim-d7a317ef1782d50274f733b7b918317c051c82c4.tar.gz
Merge "Capture outgoing WiFi packets" into main
-rw-r--r--rust/daemon/src/wifi/frame.rs12
-rw-r--r--rust/daemon/src/wifi/medium.rs42
2 files changed, 47 insertions, 7 deletions
diff --git a/rust/daemon/src/wifi/frame.rs b/rust/daemon/src/wifi/frame.rs
index 9a19436..4b8f462 100644
--- a/rust/daemon/src/wifi/frame.rs
+++ b/rust/daemon/src/wifi/frame.rs
@@ -58,14 +58,14 @@ struct FrameBuilder {
#[derive(Debug)]
pub struct Frame {
- transmitter: [u8; 6],
+ transmitter: Option<[u8; 6]>,
receiver: Option<[u8; 6]>,
pub data: Vec<u8>,
pub ieee80211_hdr: Option<Ieee80211>,
- pub flags: u32,
+ pub flags: Option<u32>,
rx_rate_idx: Option<u32>,
pub signal: Option<u32>,
- cookie: u64,
+ cookie: Option<u64>,
pub freq: Option<u32>,
tx_rates: Option<Vec<TxRate>>,
tx_rate_flags: Option<Vec<TxRateFlag>>,
@@ -130,10 +130,10 @@ impl FrameBuilder {
let data = self.data.ok_or(anymsg("frame"))?;
let ieee80211_hdr = Ieee80211::parse(&data).ok();
Ok(Frame {
- transmitter: self.transmitter.ok_or(anymsg("transmitter"))?,
+ transmitter: self.transmitter,
receiver: self.receiver,
- cookie: self.cookie.ok_or(anymsg("cookie"))?,
- flags: self.flags.ok_or(anymsg("flags"))?,
+ cookie: self.cookie,
+ flags: self.flags,
rx_rate_idx: self.rx_rate_idx,
signal: self.signal,
data,
diff --git a/rust/daemon/src/wifi/medium.rs b/rust/daemon/src/wifi/medium.rs
index 29a4588..11454df 100644
--- a/rust/daemon/src/wifi/medium.rs
+++ b/rust/daemon/src/wifi/medium.rs
@@ -61,7 +61,47 @@ pub fn test_parse_hwsim_cmd() {
7, 0, 0, 1, 255, 0, 255, 0, 255, 0, 16, 0, 21, 0, 0, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0,
12, 0, 8, 0, 201, 0, 0, 0, 0, 0, 0, 0,
];
- parse_hwsim_cmd(&packet);
+ assert!(parse_hwsim_cmd(&packet).is_ok());
+
+ // missing transmitter attribute
+ let packet2: Vec<u8> = vec![
+ 132, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 10, 0, 1, 0, 2, 21, 178, 0,
+ 0, 0, 0, 0, 76, 0, 3, 0, 8, 2, 0, 0, 2, 21, 178, 0, 0, 0, 0, 19, 16, 133, 254, 1, 82, 85,
+ 10, 0, 2, 2, 0, 0, 170, 170, 3, 0, 0, 0, 8, 0, 69, 0, 0, 40, 0, 14, 0, 0, 64, 6, 177, 19,
+ 142, 251, 46, 164, 10, 0, 2, 16, 1, 187, 198, 28, 0, 0, 250, 220, 35, 200, 197, 208, 80,
+ 16, 255, 255, 57, 216, 0, 0, 8, 0, 5, 0, 1, 0, 0, 0, 8, 0, 6, 0, 206, 255, 255, 255, 8, 0,
+ 19, 0, 143, 9, 0, 0,
+ ];
+ assert!(parse_hwsim_cmd(&packet2).is_ok());
+
+ // missing cookie attribute
+ let packet3: Vec<u8> = vec![
+ 144, 1, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 10, 0, 1, 0, 2, 21, 178, 0,
+ 0, 0, 0, 0, 85, 1, 3, 0, 128, 0, 0, 0, 255, 255, 255, 255, 255, 255, 0, 19, 16, 133, 254,
+ 1, 0, 19, 16, 133, 254, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 232, 3, 1, 4, 0, 11, 65, 110, 100,
+ 114, 111, 105, 100, 87, 105, 102, 105, 1, 4, 130, 132, 139, 150, 3, 1, 8, 42, 1, 7, 45, 26,
+ 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 22, 8,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 4, 0, 0, 0, 2, 128, 0,
+ 0, 0, 255, 255, 255, 255, 255, 255, 0, 19, 16, 133, 254, 1, 0, 19, 16, 133, 254, 1, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 232, 3, 1, 4, 0, 11, 65, 110, 100, 114, 111, 105, 100, 87, 105,
+ 102, 105, 1, 4, 130, 132, 139, 150, 3, 1, 8, 42, 1, 7, 45, 26, 12, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 61, 22, 8, 0, 19, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 4, 0, 0, 0, 2, 16, 0, 0, 0, 2, 21, 178, 0, 0, 0,
+ 0, 19, 16, 133, 254, 1, 0, 19, 16, 133, 254, 1, 0, 0, 1, 4, 0, 0, 1, 192, 1, 4, 130, 132,
+ 139, 150, 45, 26, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 61, 22, 8, 0, 19, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 127, 4, 0,
+ 0, 0, 2, 90, 3, 36, 1, 0, 0, 0, 0, 8, 0, 5, 0, 1, 0, 0, 0, 8, 0, 6, 0, 206, 255, 255, 255,
+ 8, 0, 19, 0, 143, 9, 0, 0,
+ ];
+ assert!(parse_hwsim_cmd(&packet3).is_ok());
+
+ // HwsimkMsg cmd=TxInfoFrame packet
+ let packet3: Vec<u8> = vec![
+ 72, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 10, 0, 2, 0, 2, 21, 178, 0,
+ 0, 0, 0, 0, 8, 0, 4, 0, 4, 0, 0, 0, 12, 0, 8, 0, 60, 0, 0, 0, 0, 0, 0, 0, 8, 0, 6, 0, 206,
+ 255, 255, 255, 12, 0, 7, 0, 3, 0, 0, 0, 0, 0, 255, 0,
+ ];
+ assert!(parse_hwsim_cmd(&packet3).is_err());
}
#[cfg(test)]