cargo fmt

This commit is contained in:
Cooper Quintin
2026-05-01 12:34:38 -07:00
parent ebc0ddb6b3
commit 1471bb6f0b
+54 -41
View File
@@ -7,13 +7,13 @@ use super::analyzer::{Analyzer, Event, EventType};
use super::information_element::{InformationElement, LteInformationElement}; use super::information_element::{InformationElement, LteInformationElement};
use log::debug; use log::debug;
use telcom_parser::lte_rrc::{
DL_DCCH_MessageType, DL_DCCH_MessageType_c1, UL_CCCH_MessageType, UL_CCCH_MessageType_c1,
};
use telcom_parser::lte_rrc::{BCCH_DL_SCH_MessageType, BCCH_DL_SCH_MessageType_c1};
use telcom_parser::lte_rrc::{PLMN_Identity, PLMN_IdentityList, MCC_MNC_Digit};
use pycrate_rs::nas::generated::emm::emm_attach_request::TAI;
use pycrate_rs::nas::generated::emm::emm_attach_reject::EMMCauseEMMCause as AttachRejectEMMCause; use pycrate_rs::nas::generated::emm::emm_attach_reject::EMMCauseEMMCause as AttachRejectEMMCause;
use pycrate_rs::nas::generated::emm::emm_attach_request::TAI;
use telcom_parser::lte_rrc::{BCCH_DL_SCH_MessageType, BCCH_DL_SCH_MessageType_c1};
use telcom_parser::lte_rrc::{
/* DL_DCCH_MessageType, DL_DCCH_MessageType_c1,*/ UL_CCCH_MessageType, UL_CCCH_MessageType_c1,
};
use telcom_parser::lte_rrc::{MCC_MNC_Digit, PLMN_Identity, PLMN_IdentityList};
const TIMEOUT_THRESHHOLD: usize = 50; const TIMEOUT_THRESHHOLD: usize = 50;
@@ -46,8 +46,8 @@ impl ImsiRequestedAnalyzer {
state: State::Unattached, state: State::Unattached,
timeout_counter: 0, timeout_counter: 0,
flag: None, flag: None,
// You will likely wonder why this isn't an Option<PLMN{mcc: u32, mnc: u32}> // You will likely wonder why this isn't an Option<PLMN{mcc: u32, mnc: u32}>
// The answer is that I like strings. // The answer is that I like strings.
likely_enb_plmn: "Unknown".to_string(), likely_enb_plmn: "Unknown".to_string(),
likely_ue_plmn: "Unknown".to_string(), likely_ue_plmn: "Unknown".to_string(),
} }
@@ -85,14 +85,18 @@ impl ImsiRequestedAnalyzer {
if self.likely_enb_plmn == self.likely_ue_plmn { if self.likely_enb_plmn == self.likely_ue_plmn {
self.flag = Some(Event { self.flag = Some(Event {
event_type: EventType::High, event_type: EventType::High,
message: format!("Disconnected after Identity Request without Auth Accept on home network!"), message: format!(
"Disconnected after Identity Request without Auth Accept on home network!"
),
}); });
} else { } else {
self.flag = Some(Event { self.flag = Some(Event {
event_type: EventType::Low, event_type: EventType::Low,
message: format!("Disconnected after Identity Request without Auth Accept, but this could be a false positive roaming issue - Tower PLMN: {}, UE PLMN: {}", self.likely_enb_plmn, self.likely_ue_plmn), message: format!(
"Disconnected after Identity Request without Auth Accept, but this could be a false positive roaming issue - Tower PLMN: {}, UE PLMN: {}",
self.likely_enb_plmn, self.likely_ue_plmn
),
}); });
} }
} }
@@ -113,33 +117,41 @@ impl ImsiRequestedAnalyzer {
// Sometimes an ENB can have multiple PLMNS // Sometimes an ENB can have multiple PLMNS
fn format_plmn_list(&mut self, plmn_list: &PLMN_IdentityList) -> String { fn format_plmn_list(&mut self, plmn_list: &PLMN_IdentityList) -> String {
plmn_list.0.iter() plmn_list
.0
.iter()
.map(|info| self.plmn_identity_to_str(&info.plmn_identity)) .map(|info| self.plmn_identity_to_str(&info.plmn_identity))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")
} }
// PLMN is represented in two very different ways in the LTE spec so we need // PLMN is represented in two very different ways in the LTE spec so we need
// two very different functions to decode them. I hate this. // two very different functions to decode them. I hate this.
fn plmn_identity_to_str(&mut self, plmn: &PLMN_Identity) -> String { fn plmn_identity_to_str(&mut self, plmn: &PLMN_Identity) -> String {
let mcc_digits: String = plmn.mcc let mcc_digits: String = plmn
.mcc
.as_ref() .as_ref()
.map(|mcc| mcc.0.iter() .map(|mcc| {
.filter_map(|d| match d { mcc.0
MCC_MNC_Digit(n) => Some(n.to_string()), .iter()
}) .filter_map(|d| match d {
.collect::<Vec<_>>() MCC_MNC_Digit(n) => Some(n.to_string()),
.join("")) })
.collect::<Vec<_>>()
.join("")
})
.unwrap_or_default(); .unwrap_or_default();
let mnc_digits: String = plmn.mnc let mnc_digits: String = plmn
.0.iter() .mnc
.0
.iter()
.filter_map(|d| match d { .filter_map(|d| match d {
MCC_MNC_Digit(n) => Some(n.to_string()), MCC_MNC_Digit(n) => Some(n.to_string()),
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(""); .join("");
format!("{}-{}", mcc_digits, mnc_digits) format!("{}-{}", mcc_digits, mnc_digits)
} }
@@ -158,7 +170,10 @@ impl ImsiRequestedAnalyzer {
let mnc_str = if mnc_digit3 == 0xF { let mnc_str = if mnc_digit3 == 0xF {
format!("{:02}", mnc_digit1 * 10 + mnc_digit2) format!("{:02}", mnc_digit1 * 10 + mnc_digit2)
} else { } else {
format!("{:03}", mnc_digit1 as u32 * 100 + mnc_digit2 as u32 * 10 + mnc_digit3 as u32) format!(
"{:03}",
mnc_digit1 as u32 * 100 + mnc_digit2 as u32 * 10 + mnc_digit3 as u32
)
}; };
format!("{}-{}", mcc_str, mnc_str) format!("{}-{}", mcc_str, mnc_str)
@@ -166,12 +181,9 @@ impl ImsiRequestedAnalyzer {
fn extract_plmn(&mut self, old_tai: &Option<TAI>) -> String { fn extract_plmn(&mut self, old_tai: &Option<TAI>) -> String {
match old_tai { match old_tai {
Some(t) => { Some(t) => self.plmn_vec_to_str(&t.plmn),
self.plmn_vec_to_str(&t.plmn) None => "Unknown".to_string(),
},
None => "Unknown".to_string()
} }
} }
} }
@@ -195,19 +207,18 @@ impl Analyzer for ImsiRequestedAnalyzer {
ie: &InformationElement, ie: &InformationElement,
packet_num: usize, packet_num: usize,
) -> Option<Event> { ) -> Option<Event> {
// Set the enodeb plmn to the last sib1 we got, we should improve this once we have PCI data, this // Set the enodeb plmn to the last sib1 we got, we should improve this once we have PCI data, this
// is a naive approach. // is a naive approach.
if let InformationElement::LTE(lte_ie) = ie if let InformationElement::LTE(lte_ie) = ie
&& let LteInformationElement::BcchDlSch(sch_msg) = &**lte_ie && let LteInformationElement::BcchDlSch(sch_msg) = &**lte_ie
&& let BCCH_DL_SCH_MessageType::C1(c1) = &sch_msg.message && let BCCH_DL_SCH_MessageType::C1(c1) = &sch_msg.message
&& let BCCH_DL_SCH_MessageType_c1::SystemInformationBlockType1(sib1) = c1 { && let BCCH_DL_SCH_MessageType_c1::SystemInformationBlockType1(sib1) = c1
{
let plmn = &sib1.cell_access_related_info.plmn_identity_list; let plmn = &sib1.cell_access_related_info.plmn_identity_list;
self.likely_enb_plmn = self.format_plmn_list(plmn); self.likely_enb_plmn = self.format_plmn_list(plmn);
return None;
}
return None;
}
if let InformationElement::LTE(inner) = ie { if let InformationElement::LTE(inner) = ie {
match &**inner { match &**inner {
@@ -236,7 +247,9 @@ impl Analyzer for ImsiRequestedAnalyzer {
} }
NASMessage::EMMMessage(EMMMessage::EMMAttachReject(reject)) => { NASMessage::EMMMessage(EMMMessage::EMMAttachReject(reject)) => {
self.transition(State::Disconnect, packet_num); self.transition(State::Disconnect, packet_num);
if reject.emm_cause.inner == AttachRejectEMMCause::EPSServicesAndNonEPSServicesNotAllowed { if reject.emm_cause.inner
== AttachRejectEMMCause::EPSServicesAndNonEPSServicesNotAllowed
{
self.flag = Some(Event { self.flag = Some(Event {
event_type: EventType::Low, event_type: EventType::Low,
message: "Identity requested without authentication but its likely a false positive unless your SIM card has an active plan".to_string(), message: "Identity requested without authentication but its likely a false positive unless your SIM card has an active plan".to_string(),
@@ -257,7 +270,7 @@ impl Analyzer for ImsiRequestedAnalyzer {
}, },
// This causes two messages in the event of a false positive when we should always get an attach reject anyway so // This causes two messages in the event of a false positive when we should always get an attach reject anyway so
// I'm commentingit out until I figure out a smarter way to deal with it. // I'm commentingit out until I figure out a smarter way to deal with it.
/* /*
LteInformationElement::DlDcch(rrc_payload) => { LteInformationElement::DlDcch(rrc_payload) => {
if let DL_DCCH_MessageType::C1(DL_DCCH_MessageType_c1::RrcConnectionRelease( if let DL_DCCH_MessageType::C1(DL_DCCH_MessageType_c1::RrcConnectionRelease(