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