From d1bb29f6c269e472f42ffd914b075a6ae69d0150 Mon Sep 17 00:00:00 2001 From: Will Greenberg Date: Thu, 14 Dec 2023 12:29:00 -0800 Subject: [PATCH] some minor cleanups, comments --- src/diag.rs | 5 +++-- src/pcap.rs | 15 +++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/diag.rs b/src/diag.rs index dc172f0..8d8ebfa 100644 --- a/src/diag.rs +++ b/src/diag.rs @@ -68,7 +68,6 @@ pub enum Message { inner_length: u16, log_type: u16, timestamp: Timestamp, - //#[deku(count = "inner_length - 12")] #[deku(ctx = "*log_type, *inner_length - 12")] body: LogBody, }, @@ -126,11 +125,13 @@ pub enum LogBody { rrc_rel: u8, rrc_version_minor: u8, rrc_version_major: u8, - #[deku(count = "hdr_len - 4")] // is this right?? + // is this right?? based on https://github.com/fgsect/scat/blob/97442580e628de414c9f7c2a185f4e28d0ee7523/src/scat/parsers/qualcomm/diagltelogparser.py#L1327 + #[deku(count = "hdr_len - 4")] msg: Vec, }, #[deku(id = "0x11eb")] IpTraffic { + // is this right?? based on https://github.com/P1sec/QCSuper/blob/81dbaeee15ec7747e899daa8e3495e27cdcc1264/src/modules/pcap_dump.py#L378 #[deku(count = "hdr_len - 8")] // is this right??? msg: Vec, }, diff --git a/src/pcap.rs b/src/pcap.rs index 95c4e0a..66cf7ba 100644 --- a/src/pcap.rs +++ b/src/pcap.rs @@ -27,6 +27,7 @@ pub struct PcapFile { ip_id: u16, } +const IP_HEADER_LEN: u16 = 20; #[derive(DekuWrite)] #[deku(endian = "big")] struct IpHeader { @@ -43,6 +44,8 @@ struct IpHeader { dst_addr: u32, } +const UDP_HEADER_LEN: u16 = 8; +const GSMTAP_PORT: u16 = 4729; #[derive(DekuWrite)] #[deku(endian = "big")] struct UdpHeader { @@ -74,12 +77,16 @@ impl PcapFile { pub fn write_gsmtap_message(&mut self, msg: GsmtapMessage, timestamp: Timestamp) -> Result<(), PcapFileError> { let time_since_epoch = timestamp.to_datetime().signed_duration_since(DateTime::UNIX_EPOCH); - let duration = std::time::Duration::new(time_since_epoch.num_seconds() as u64, time_since_epoch.num_nanoseconds().unwrap() as u32); + let secs_since_epoch = time_since_epoch.num_seconds() as u64; + let nsecs_since_epoch = time_since_epoch.num_nanoseconds().unwrap_or(0) as u32; + // FIXME: although the duration value is correct here, when it shows up in + // the pcap it's WAY off, like in the year 55920 + let duration = std::time::Duration::new(secs_since_epoch, nsecs_since_epoch); let msg_bytes = msg.to_bytes()?; let ip_header = IpHeader { version_and_ihl: 0x45, dscp: 0, - total_len: msg_bytes.len() as u16 + 20 + 8, + total_len: msg_bytes.len() as u16 + IP_HEADER_LEN + UDP_HEADER_LEN, identification: self.ip_id, flags_and_frag_offset: 0x40, idk: 0, @@ -91,8 +98,8 @@ impl PcapFile { }; let udp_header = UdpHeader { src_port: 13337, - dst_port: 4729, - length: msg_bytes.len() as u16 + 8, + dst_port: GSMTAP_PORT, + length: msg_bytes.len() as u16 + UDP_HEADER_LEN, checksum: 0xffff, }; let mut data: Vec = Vec::new();