mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-06-20 11:24:19 -07:00
lib: add lte-parser crate support
This'll let us convert a Gsmtap message into a fully parsed LTE message.
This commit is contained in:
+3
-20
@@ -5,28 +5,11 @@ edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[build-dependencies]
|
||||
asn1-compiler = "0.6.1"
|
||||
asn1-codecs = "0.6.1"
|
||||
asn1_codecs_derive = "0.6.1"
|
||||
serde = { version = "1.0" , features = ["derive"]}
|
||||
trybuild = { version = "1.0" }
|
||||
hex = { version = "0.4" }
|
||||
bitvec = { version = "1.0" , features = ["serde"]}
|
||||
log = { version = "0.4" }
|
||||
criterion = { version = "0.5" , features = ["rayon"]}
|
||||
env_logger = { version = "0.9" }
|
||||
|
||||
[dependencies]
|
||||
asn1-compiler = "0.6.1"
|
||||
asn1-codecs = "0.6.1"
|
||||
asn1_codecs_derive = "0.6.1"
|
||||
bitvec = "1.0"
|
||||
log = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
asn1-compiler = "0.6.1"
|
||||
asn1-codecs = "0.6.1"
|
||||
asn1_codecs_derive = "0.6.1"
|
||||
bitvec = "1.0"
|
||||
bitvec = { version = "1.0", features = ["serde"] }
|
||||
log = "0.4"
|
||||
thiserror = "1.0.56"
|
||||
serde = { version = "1.0.196", features = ["derive"] }
|
||||
|
||||
@@ -6,7 +6,7 @@ Rust code for parsing these messages. We're using [hampi](https://github.com/yst
|
||||
|
||||
## Generating the parser
|
||||
|
||||
To install the hampi tools, run:
|
||||
To install the hampi compiler, run:
|
||||
|
||||
```
|
||||
> cargo install asn1-compiler
|
||||
@@ -15,7 +15,7 @@ To install the hampi tools, run:
|
||||
To generate the parser, run:
|
||||
|
||||
```
|
||||
> ampi-rs-asn1c --codec uper --module src/lte_rrc.rs -- specs/*
|
||||
> hampi-rs-asn1c --codec uper --derive clone --derive partial-eq --derive serialize --module src/lte_rrc.rs -- specs/*
|
||||
```
|
||||
|
||||
## Sourcing the ASN.1 files
|
||||
|
||||
@@ -1,2 +1,18 @@
|
||||
use asn1_codecs::{uper::UperCodec, PerCodecData, PerCodecError};
|
||||
use thiserror::Error;
|
||||
#[allow(unreachable_patterns, non_camel_case_types)]
|
||||
pub mod lte_rrc;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum ParsingError {
|
||||
#[error("Failed to decode UPER data: {0}")]
|
||||
UperDecodeError(PerCodecError),
|
||||
}
|
||||
|
||||
pub fn decode<T>(data: &[u8]) -> Result<T, ParsingError>
|
||||
where T: UperCodec<Output = T>
|
||||
{
|
||||
let mut asn_data = PerCodecData::from_slice_uper(data);
|
||||
T::uper_decode(&mut asn_data)
|
||||
.map_err(|e| ParsingError::UperDecodeError(e))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user