diff --git a/Cargo.lock b/Cargo.lock index 2e935be..3ea3490 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,12 +59,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "anstream" version = "0.6.11" @@ -133,7 +127,7 @@ checksum = "b1d056f38f3e98ffe9808e6a482d1527e4ded46e72b3dbe77305f5508e76c5f6" dependencies = [ "bitvec", "clap", - "env_logger 0.10.2", + "env_logger", "heck", "lazy_static", "log", @@ -168,17 +162,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "autocfg" version = "1.1.0" @@ -255,15 +238,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "basic-toml" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2db21524cad41c5591204d22d75e1970a2d1f71060214ca931dc7d5afe2c14e5" -dependencies = [ - "serde", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -316,12 +290,6 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.0.83" @@ -352,33 +320,6 @@ dependencies = [ "windows-targets 0.52.0", ] -[[package]] -name = "ciborium" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" - -[[package]] -name = "ciborium-ll" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" -dependencies = [ - "ciborium-io", - "half", -] - [[package]] name = "clap" version = "4.5.0" @@ -446,73 +387,6 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19d374276b40fb8bbdee95aef7c7fa6b5316ec764510eb64b8dd0e2ed0d7e7f5" -[[package]] -name = "criterion" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" -dependencies = [ - "anes", - "cast", - "ciborium", - "clap", - "criterion-plot", - "is-terminal", - "itertools", - "num-traits", - "once_cell", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" - -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "darling" version = "0.14.4" @@ -583,25 +457,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "either" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" - -[[package]] -name = "env_logger" -version = "0.9.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7" -dependencies = [ - "atty", - "humantime", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.10.2" @@ -716,12 +571,6 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - [[package]] name = "h2" version = "0.4.2" @@ -741,16 +590,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc52e53916c08643f1b56ec082790d1e86a32e58dc5268f897f313fbae7b4872" -dependencies = [ - "cfg-if", - "crunchy", -] - [[package]] name = "hashbrown" version = "0.14.3" @@ -767,27 +606,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d3d0e0f38255e7fa3cf31335b3a56f05febd18025f4db5ef7a0cfb4f8da651f" -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "http" version = "1.0.0" @@ -939,20 +763,11 @@ version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ - "hermit-abi 0.3.4", + "hermit-abi", "rustix", "windows-sys 0.52.0", ] -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.10" @@ -961,9 +776,9 @@ checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" [[package]] name = "js-sys" -version = "0.3.68" +version = "0.3.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "406cda4b368d531c842222cf9d2600a9a4acce8d29423695379c6868a143a9ee" +checksum = "9a1d36f1235bc969acba30b7f5990b864423a6068a10f7c90ae8f0112e3a59d1" dependencies = [ "wasm-bindgen", ] @@ -1022,12 +837,9 @@ dependencies = [ "asn1-compiler", "asn1_codecs_derive", "bitvec", - "criterion", - "env_logger 0.9.3", - "hex", "log", "serde", - "trybuild", + "thiserror", ] [[package]] @@ -1093,7 +905,7 @@ version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.3.4", + "hermit-abi", "libc", ] @@ -1112,12 +924,6 @@ version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - [[package]] name = "parking_lot" version = "0.12.1" @@ -1196,34 +1002,6 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2900ede94e305130c13ddd391e0ab7cbaeb783945ae07a279c268cb05109c6cb" -[[package]] -name = "plotters" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" - -[[package]] -name = "plotters-svg" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" -dependencies = [ - "plotters-backend", -] - [[package]] name = "proc-macro-crate" version = "1.3.1" @@ -1294,9 +1072,10 @@ dependencies = [ "chrono", "crc", "deku", - "env_logger 0.10.2", + "env_logger", "libc", "log", + "lte-parser", "pcap-file", "thiserror", ] @@ -1307,7 +1086,7 @@ version = "0.1.0" dependencies = [ "axum", "chrono", - "env_logger 0.10.2", + "env_logger", "futures-core", "futures-macro", "include_dir", @@ -1322,26 +1101,6 @@ dependencies = [ "toml", ] -[[package]] -name = "rayon" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7237101a77a10773db45d62004a272517633fbcc3df19d96455ede1122e051" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" -dependencies = [ - "crossbeam-deque", - "crossbeam-utils", -] - [[package]] name = "rdrand" version = "0.4.0" @@ -1443,15 +1202,6 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "scopeguard" version = "1.2.0" @@ -1646,16 +1396,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tokio" version = "1.35.1" @@ -1801,21 +1541,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "trybuild" -version = "1.0.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a9d3ba662913483d6722303f619e75ea10b7855b0f8e0d72799cf8621bb488f" -dependencies = [ - "basic-toml", - "glob", - "once_cell", - "serde", - "serde_derive", - "serde_json", - "termcolor", -] - [[package]] name = "unicase" version = "2.7.0" @@ -1849,16 +1574,6 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "walkdir" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" -dependencies = [ - "same-file", - "winapi-util", -] - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1867,9 +1582,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.91" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e124130aee3fb58c5bdd6b639a0509486b0338acaaae0c84a5124b0f588b7f" +checksum = "b1223296a201415c7fad14792dbefaace9bd52b62d33453ade1c5b5f07555406" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1877,9 +1592,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.91" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e7e1900c352b609c8488ad12639a311045f40a35491fb69ba8c12f758af70b" +checksum = "fcdc935b63408d58a32f8cc9738a0bffd8f05cc7c002086c6ef20b7312ad9dcd" dependencies = [ "bumpalo", "log", @@ -1892,9 +1607,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.91" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30af9e2d358182b5c7449424f017eba305ed32a7010509ede96cdc4696c46ed" +checksum = "3e4c238561b2d428924c49815533a8b9121c664599558a5d9ec51f8a1740a999" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1902,9 +1617,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.91" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "642f325be6301eb8107a83d12a8ac6c1e1c54345a7ef1a9261962dfefda09e66" +checksum = "bae1abb6806dc1ad9e560ed242107c0f6c84335f1749dd4e8ddb012ebd5e25a7" dependencies = [ "proc-macro2", "quote", @@ -1915,19 +1630,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.91" +version = "0.2.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f186bd2dcf04330886ce82d6f33dd75a7bfcf69ecf5763b89fcde53b6ac9838" - -[[package]] -name = "web-sys" -version = "0.3.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96565907687f7aceb35bc5fc03770a8a0471d82e479f25832f54a0e3f4b28446" -dependencies = [ - "js-sys", - "wasm-bindgen", -] +checksum = "4d91413b1c31d7539ba5ef2451af3f0b833a005eb27a631cec32bc0635a8602b" [[package]] name = "winapi" diff --git a/lib/Cargo.toml b/lib/Cargo.toml index a3228a1..4ba867d 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -14,3 +14,4 @@ libc = "0.2.150" log = "0.4.20" pcap-file = "2.0.0" thiserror = "1.0.50" +lte-parser = { path = "../lte-parser" } diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 61de5e9..807585e 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -7,3 +7,4 @@ pub mod log_codes; pub mod gsmtap; pub mod gsmtap_parser; pub mod pcap; +pub mod lte_rrc; diff --git a/lib/src/lte_rrc.rs b/lib/src/lte_rrc.rs new file mode 100644 index 0000000..e40314d --- /dev/null +++ b/lib/src/lte_rrc.rs @@ -0,0 +1,71 @@ +use lte_parser::{decode, lte_rrc}; +use thiserror::Error; +use super::gsmtap::{GsmtapType, LteRrcSubtype, GsmtapMessage}; + +#[derive(Error, Debug)] +pub enum MessageParsingError { + #[error("Failed decoding")] + DecodingError(#[from] lte_parser::ParsingError), + #[error("Unknown Gsmtap message type {0:?}")] + UnknownGsmtapType(GsmtapType), + #[error("Unsupported LTE RRC subtype {0:?}")] + UnsupportedLteRrcSubtype(LteRrcSubtype), +} + +#[derive(Debug, Clone, PartialEq)] +pub enum Message { + DlCcch(lte_rrc::DL_CCCH_Message), + DlDcch(lte_rrc::DL_DCCH_Message), + UlCcch(lte_rrc::UL_CCCH_Message), + UlDcch(lte_rrc::UL_DCCH_Message), + BcchBch(lte_rrc::BCCH_BCH_Message), + BcchDlSch(lte_rrc::BCCH_DL_SCH_Message), + PCCH(lte_rrc::PCCH_Message), + MCCH(lte_rrc::MCCH_Message), + ScMcch(lte_rrc::SC_MCCH_Message_r13), + BcchBchMbms(lte_rrc::BCCH_BCH_Message_MBMS), + BcchDlSchBr(lte_rrc::BCCH_DL_SCH_Message_BR), + BcchDlSchMbms(lte_rrc::BCCH_DL_SCH_Message_MBMS), + SbcchSlBch(lte_rrc::SBCCH_SL_BCH_Message), + SbcchSlBchV2x(lte_rrc::SBCCH_SL_BCH_Message_V2X_r14), + + // FIXME: unclear which message these "NB" types map to + //DlCcchNb(), + //DlDcchNb(), + //UlCcchNb(), + //UlDcchNb(), + //BcchBchNb(), + //BcchBchTddNb(), + //BcchDlSchNb(), + //PcchNb(), + //ScMcchNb(), +} + +impl TryFrom<&GsmtapMessage> for Message { + type Error = MessageParsingError; + + fn try_from(gsmtap_msg: &GsmtapMessage) -> Result { + if let GsmtapType::LteRrc(lte_rrc_subtype) = gsmtap_msg.header.gsmtap_type { + use LteRrcSubtype as L; + use Message as R; + return match lte_rrc_subtype { + L::DlCcch => Ok(R::DlCcch(decode(&gsmtap_msg.payload)?)), + L::DlDcch => Ok(R::DlDcch(decode(&gsmtap_msg.payload)?)), + L::UlCcch => Ok(R::UlCcch(decode(&gsmtap_msg.payload)?)), + L::UlDcch => Ok(R::UlDcch(decode(&gsmtap_msg.payload)?)), + L::BcchBch => Ok(R::BcchBch(decode(&gsmtap_msg.payload)?)), + L::BcchDlSch => Ok(R::BcchDlSch(decode(&gsmtap_msg.payload)?)), + L::PCCH => Ok(R::PCCH(decode(&gsmtap_msg.payload)?)), + L::MCCH => Ok(R::MCCH(decode(&gsmtap_msg.payload)?)), + L::ScMcch => Ok(R::ScMcch(decode(&gsmtap_msg.payload)?)), + L::BcchBchMbms => Ok(R::BcchBchMbms(decode(&gsmtap_msg.payload)?)), + L::BcchDlSchBr => Ok(R::BcchDlSchBr(decode(&gsmtap_msg.payload)?)), + L::BcchDlSchMbms => Ok(R::BcchDlSchMbms(decode(&gsmtap_msg.payload)?)), + L::SbcchSlBch => Ok(R::SbcchSlBch(decode(&gsmtap_msg.payload)?)), + L::SbcchSlBchV2x => Ok(R::SbcchSlBchV2x(decode(&gsmtap_msg.payload)?)), + subtype => Err(MessageParsingError::UnsupportedLteRrcSubtype(subtype)), + }; + } + Err(MessageParsingError::UnknownGsmtapType(gsmtap_msg.header.gsmtap_type)) + } +} diff --git a/lte-parser/Cargo.toml b/lte-parser/Cargo.toml index 8946dbf..45cf572 100644 --- a/lte-parser/Cargo.toml +++ b/lte-parser/Cargo.toml @@ -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"] } diff --git a/lte-parser/README.md b/lte-parser/README.md index dbc4a17..4819499 100644 --- a/lte-parser/README.md +++ b/lte-parser/README.md @@ -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 diff --git a/lte-parser/src/lib.rs b/lte-parser/src/lib.rs index 3e62906..2e59dd5 100644 --- a/lte-parser/src/lib.rs +++ b/lte-parser/src/lib.rs @@ -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(data: &[u8]) -> Result + where T: UperCodec +{ + let mut asn_data = PerCodecData::from_slice_uper(data); + T::uper_decode(&mut asn_data) + .map_err(|e| ParsingError::UperDecodeError(e)) +}