From 7831c5085ed435a300d906a1f940781059b0daf9 Mon Sep 17 00:00:00 2001 From: Will Greenberg Date: Thu, 25 Jun 2026 07:36:23 -0700 Subject: [PATCH] If a Message isn't convertable to GSMTAP, don't try This also removes the pseudo GSMTAP packets added for measurement results, since they add a ton of noise to PCAPs. Eventually, we should keep track of the latest signal for a given PCI, and annotate actual packets with that value. --- lib/src/diag/mod.rs | 14 ++++++++++++++ lib/src/gsmtap/parser.rs | 17 +++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/src/diag/mod.rs b/lib/src/diag/mod.rs index 6a1ca3b..4443983 100644 --- a/lib/src/diag/mod.rs +++ b/lib/src/diag/mod.rs @@ -156,6 +156,20 @@ impl Message { Err(err) => Err(DiagParsingError::HdlcDecapsulationError(err, data.to_vec())), } } + + /// Returns whether this message should be parsed into a GSMTAP packet for + /// display in pcap files + pub fn is_gsmtap_message(&self) -> bool { + let Message::Log { body, .. } = self else { + return false; + }; + match body { + LogBody::LteRrcOtaMessage { .. } => true, + LogBody::LteMacRachResponse { .. } => true, + LogBody::Nas4GMessage { .. } => true, + _ => false + } + } } #[derive(Debug, Clone, PartialEq, DekuRead, DekuWrite)] diff --git a/lib/src/gsmtap/parser.rs b/lib/src/gsmtap/parser.rs index 837d22b..e33f91c 100644 --- a/lib/src/gsmtap/parser.rs +++ b/lib/src/gsmtap/parser.rs @@ -17,6 +17,9 @@ pub enum GsmtapParserError { } pub fn parse(msg: Message) -> Result, GsmtapParserError> { + if !msg.is_gsmtap_message() { + return Ok(None); + } if let Message::Log { timestamp, body, .. } = msg @@ -31,6 +34,8 @@ pub fn parse(msg: Message) -> Result, GsmtapP } fn log_to_gsmtap(value: LogBody) -> Result, GsmtapParserError> { + // Note: if support for another LogBody variant is added here, it should + // also be added to Message::is_gsmtap_message match value { LogBody::LteRrcOtaMessage { ext_header_version, @@ -156,18 +161,6 @@ fn log_to_gsmtap(value: LogBody) -> Result, GsmtapParserEr payload: msg, })) } - LogBody::LteMl1ServingCellMeasurementAndEvaluation { data, .. } => { - // frame_number reused for PCI (normally SFN in RRC frames) so all three - // serving-cell fields are accessible in Wireshark as gsmtap.* columns. - let mut header = GsmtapHeader::new(GsmtapType::QcDiag); - header.signal_dbm = data.get_meas_rsrp() as i8; - header.arfcn = data.get_earfcn().try_into().unwrap_or(0); - header.frame_number = data.get_pci() as u32; - Ok(Some(GsmtapMessage { - header, - payload: vec![], - })) - } LogBody::LteMacRachResponse { packet } => { if packet.subpackets.len() > 1 { warn!(