run cargo fmt

This commit is contained in:
Will Greenberg
2026-06-18 13:47:12 -07:00
parent 338d41dceb
commit a5c86bc408
8 changed files with 97 additions and 61 deletions
+21 -9
View File
@@ -156,7 +156,7 @@ pub mod rach {
V32 {
#[deku(endian = "big")]
grant: u32,
}
},
}
#[derive(DekuRead, DekuWrite, Debug, Clone, PartialEq)]
@@ -204,21 +204,33 @@ pub mod rach {
#[cfg(test)]
pub(crate) mod test {
use crate::{diag::diaglog::mac::rach::Msg3Grant, test_util::unhexlify};
use super::*;
use crate::diag::diaglog::mac::rach::{AdditionalInfo, AttemptHeader, Msg1, Msg2, Msg3};
use crate::{diag::diaglog::mac::rach::Msg3Grant, test_util::unhexlify};
use std::io::Seek;
pub fn mac_rach_test_packets_from_scat() -> Vec<Packet> {
// test data from SCAT unit tests: https://github.com/fgsect/scat/blob/9763cb5b1dcd5ee980f5b0ead9a8d520c8c51a51/tests/test_diagltelogparser.py#L129
vec![
parse_rach_packet("0101a06906022400010001071BFF98FF000001231A0400181C010007000600465C80BD0648000000"),
parse_rach_packet("0101a0690603280001000100010718ffa4ff000001c6610b00b4a2000012000120061f423f8d95075800"),
parse_rach_packet("0101739e063134000100010000033f0098ff0000013c6b070058ac010007000000468f47e2d446000000644b0000180001000000d5040000"),
parse_rach_packet("01010000063134000100010001070aff98ff0000011c48070018e2000007000000523b7dfd69b6000000f5540000ff0001000000d6040000"),
parse_rach_packet("01010000063238000100010000032900a4ffeb000000000195b603000000a0b412000420061f425dc9be41b800885e000017000100000065050000"),
parse_rach_packet("010100000632380001000100010713ffa0ffeb0000000001ad5a0500000146b412000420061f425dc9be41b400665300001800010000001a050000"),
parse_rach_packet(
"0101a06906022400010001071BFF98FF000001231A0400181C010007000600465C80BD0648000000",
),
parse_rach_packet(
"0101a0690603280001000100010718ffa4ff000001c6610b00b4a2000012000120061f423f8d95075800",
),
parse_rach_packet(
"0101739e063134000100010000033f0098ff0000013c6b070058ac010007000000468f47e2d446000000644b0000180001000000d5040000",
),
parse_rach_packet(
"01010000063134000100010001070aff98ff0000011c48070018e2000007000000523b7dfd69b6000000f5540000ff0001000000d6040000",
),
parse_rach_packet(
"01010000063238000100010000032900a4ffeb000000000195b603000000a0b412000420061f425dc9be41b800885e000017000100000065050000",
),
parse_rach_packet(
"010100000632380001000100010713ffa0ffeb0000000001ad5a0500000146b412000420061f425dc9be41b400665300001800010000001a050000",
),
]
}
@@ -263,7 +275,7 @@ pub(crate) mod test {
* the changes in this commit for more info:
* https://github.com/wgreenberg/scat/commit/adb21575832b4f3b30c8f2aaca9ee843ef74f38b
*/
let test_packets = mac_rach_test_packets_from_scat();
let test_packets = mac_rach_test_packets_from_scat();
assert_rach_subpacket(
&test_packets[0],
rach::AttemptHeader::V2 {
+1 -1
View File
@@ -194,10 +194,10 @@ pub mod neighbor_cells {
#[cfg(test)]
mod test {
use crate::test_util::unhexlify;
use super::*;
use crate::diag::diaglog::LogBody;
use crate::log_codes::{LOG_LTE_ML1_NEIGHBOR_MEAS, LOG_LTE_ML1_SERVING_CELL_MEAS_AND_EVAL_C};
use crate::test_util::unhexlify;
use std::io::Seek;
fn parse_ncell_measurements(hexlified_bytes: &str) -> (u8, neighbor_cells::Measurements) {
+7 -13
View File
@@ -86,17 +86,11 @@ pub enum LogBody {
data: measurement::neighbor_cells::Measurements,
},
#[deku(id = "0xb062")]
LteMacRachResponse {
packet: mac::Packet,
},
LteMacRachResponse { packet: mac::Packet },
#[deku(id = "0xb063")]
LteMacDl {
packet: mac::Packet,
},
LteMacDl { packet: mac::Packet },
#[deku(id = "0xb064")]
LteMacUl {
packet: mac::Packet,
},
LteMacUl { packet: mac::Packet },
}
#[derive(Debug, Clone, PartialEq, DekuRead, DekuWrite)]
@@ -249,11 +243,11 @@ pub(crate) mod test {
log_type,
log_mask_bitsize: bitsize,
log_mask: vec![
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xc, 0x30, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0xc, 0x30,
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x80, 0x1, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0,
0x0, 0x80, 0x1, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
0x0, 0x0, 0x0, 0x0,
],
})
);
+2 -2
View File
@@ -62,8 +62,8 @@ pub const LOG_CODES_FOR_RAW_PACKET_LOGGING: [u32; 17] = [
log_codes::LOG_LTE_ML1_NEIGHBOR_MEAS, // 0xb180
// LTE MAC Random Access Channel response: contains Timing Advance
log_codes::LOG_LTE_MAC_RACH_RESPONSE_C, // 0xb062
log_codes::LOG_LTE_MAC_DL, // 0xb063
log_codes::LOG_LTE_MAC_UL, // 0xb064
log_codes::LOG_LTE_MAC_DL, // 0xb063
log_codes::LOG_LTE_MAC_UL, // 0xb064
];
const BUFFER_LEN: usize = 1024 * 1024 * 10;
+51 -27
View File
@@ -1,6 +1,9 @@
use deku::prelude::*;
use crate::{diag::diaglog::mac::SubpacketBody, gsmtap::{GsmtapHeader, GsmtapMessage, GsmtapType}};
use crate::{
diag::diaglog::mac::SubpacketBody,
gsmtap::{GsmtapHeader, GsmtapMessage, GsmtapType},
};
use deku::{DekuContainerWrite, DekuError};
// based primarily off of SCAT's gsmtap responses and https://www.sharetechnote.com/html/MAC_LTE.html#MAC_PDU_Structure_RAR
@@ -76,34 +79,47 @@ pub struct RACHResponse {
pub tc_rnti: u16,
}
pub fn mac_subpacket_to_gsmtap(subpacket: &SubpacketBody) -> Result<Option<GsmtapMessage>, DekuError> {
pub fn mac_subpacket_to_gsmtap(
subpacket: &SubpacketBody,
) -> Result<Option<GsmtapMessage>, DekuError> {
match subpacket {
SubpacketBody::RachAttempt(attempt) => {
let (Some(msg1), Some(msg2), Some(msg3)) = (attempt.get_msg1(), attempt.get_msg2(), attempt.get_msg3()) else {
let (Some(msg1), Some(msg2), Some(msg3)) =
(attempt.get_msg1(), attempt.get_msg2(), attempt.get_msg3())
else {
return Ok(None);
};
let mut payload = Vec::new();
payload.extend(Header {
radio_type: RadioType::Fdd,
direction: Direction::Downlink,
rnti_type: RntiType::RA,
}.to_bytes()?);
payload.extend(
Header {
radio_type: RadioType::Fdd,
direction: Direction::Downlink,
rnti_type: RntiType::RA,
}
.to_bytes()?,
);
payload.push(0x01); // MAC Payload Tag
payload.extend(ETRAPIDSubheader {
extended: false,
type_field: true,
rapid: msg1.get_preamble_index(),
}.to_bytes()?);
payload.extend(RACHResponse {
tac: msg2.ta,
ul_grant: msg3.get_grant(),
tc_rnti: msg2.tc_rnti,
}.to_bytes()?);
payload.extend(
ETRAPIDSubheader {
extended: false,
type_field: true,
rapid: msg1.get_preamble_index(),
}
.to_bytes()?,
);
payload.extend(
RACHResponse {
tac: msg2.ta,
ul_grant: msg3.get_grant(),
tc_rnti: msg2.tc_rnti,
}
.to_bytes()?,
);
Ok(Some(GsmtapMessage {
header: GsmtapHeader::new(GsmtapType::LteMacFramed),
payload,
header: GsmtapHeader::new(GsmtapType::LteMacFramed),
payload,
}))
},
}
_ => Ok(None),
}
}
@@ -127,10 +143,10 @@ mod tests {
// their GSMTAP header
let expected_bytes = &data.into_inner().into_inner()[34..];
assert_eq!(&msg.payload, expected_bytes);
},
}
(Some(msg), None) => panic!("expected no GSMTAP message, got {msg:?}"),
(None, Some(_)) => panic!("expected GSMTAP message, got None"),
_ => {},
_ => {}
}
}
@@ -140,21 +156,29 @@ mod tests {
let test_packets = mac_rach_test_packets_from_scat();
assert_mac_gsmtap(
&test_packets[0],
Some("03000009040000000000000c0000000012d53d80000000000002000400000000fffe010102015b00411c181a23"),
Some(
"03000009040000000000000c0000000012d53d80000000000002000400000000fffe010102015b00411c181a23",
),
);
assert_mac_gsmtap(
&test_packets[1],
Some("03000009040000000000000c0000000012d53d80000000000002000400000000fffe010102015800b0a2b461c6"),
Some(
"03000009040000000000000c0000000012d53d80000000000002000400000000fffe010102015800b0a2b461c6",
),
);
assert_mac_gsmtap(&test_packets[2], None);
assert_mac_gsmtap(
&test_packets[3],
Some("03000009040000000000000c0000000012d53d80000000000002000400000ea5fffe010102014a0070e218481c"),
Some(
"03000009040000000000000c0000000012d53d80000000000002000400000ea5fffe010102014a0070e218481c",
),
);
assert_mac_gsmtap(&test_packets[4], None);
assert_mac_gsmtap(
&test_packets[5],
Some("03000009040000000000000c0000000012d53d80000000000002000400000d16fffe0101020153005146b45aad"),
Some(
"03000009040000000000000c0000000012d53d80000000000002000400000d16fffe0101020153005146b45aad",
),
);
}
}
+1 -1
View File
@@ -3,8 +3,8 @@
use deku::prelude::*;
use num_enum::TryFromPrimitive;
pub mod parser;
mod mac;
pub mod parser;
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum GsmtapType {
+13 -7
View File
@@ -170,16 +170,22 @@ fn log_to_gsmtap(value: LogBody) -> Result<Option<GsmtapMessage>, GsmtapParserEr
}
LogBody::LteMacRachResponse { packet } => {
if packet.subpackets.len() > 1 {
warn!("expected 1 MAC subpacket for LogBody::LteMacRachResponse, but got {}! ignoring all but the first", packet.subpackets.len());
warn!(
"expected 1 MAC subpacket for LogBody::LteMacRachResponse, but got {}! ignoring all but the first",
packet.subpackets.len()
);
}
let Some(subpacket) = packet.subpackets.get(0) else {
return Err(GsmtapParserError::InvalidLteMacRachResponse(format!("no subpackets")));
return Err(GsmtapParserError::InvalidLteMacRachResponse(format!(
"no subpackets"
)));
};
mac_subpacket_to_gsmtap(&subpacket.body)
.map_err(|err| {
GsmtapParserError::InvalidLteMacRachResponse(format!("unable to serialize GSMTAP payload: {err:?}"))
})
},
mac_subpacket_to_gsmtap(&subpacket.body).map_err(|err| {
GsmtapParserError::InvalidLteMacRachResponse(format!(
"unable to serialize GSMTAP payload: {err:?}"
))
})
}
_ => {
debug!("gsmtap_sink: ignoring unhandled log type: {value:?}");
Ok(None)
+1 -1
View File
@@ -19,9 +19,9 @@ pub mod hdlc;
pub mod log_codes;
pub mod pcap;
pub mod qmdl;
pub mod util;
#[cfg(test)]
mod test_util;
pub mod util;
// bin/check.rs may target windows and does not use this mod
#[cfg(target_family = "unix")]