From 85d7a851fb70589a76eecdf1f256ebf7c99b1729 Mon Sep 17 00:00:00 2001 From: David Rupprecht Date: Tue, 8 Jun 2021 09:54:57 +0200 Subject: [PATCH] Added 5G NAS PCAP support --- lib/examples/npdsch_ue.c | 4 ++-- lib/examples/pssch_ue.c | 4 ++-- lib/include/srsran/common/nas_pcap.h | 3 ++- lib/include/srsran/common/pcap.h | 5 +++-- lib/src/common/mac_pcap.cc | 4 ++-- lib/src/common/nas_pcap.cc | 12 ++++++++---- lib/src/common/pcap.c | 4 ++-- lib/src/common/rlc_pcap.cc | 4 ++-- lib/src/common/s1ap_pcap.cc | 4 ++-- 9 files changed, 25 insertions(+), 19 deletions(-) diff --git a/lib/examples/npdsch_ue.c b/lib/examples/npdsch_ue.c index e301f2071..fb1c17a94 100644 --- a/lib/examples/npdsch_ue.c +++ b/lib/examples/npdsch_ue.c @@ -330,7 +330,7 @@ int main(int argc, char** argv) parse_args(&prog_args, argc, argv); #if HAVE_PCAP - FILE* pcap_file = LTE_PCAP_Open(MAC_LTE_DLT, "/tmp/npdsch.pcap"); + FILE* pcap_file = DLT_PCAP_Open(MAC_LTE_DLT, "/tmp/npdsch.pcap"); #endif sigset_t sigset; @@ -856,7 +856,7 @@ int main(int argc, char** argv) #if HAVE_PCAP printf("Saving PCAP file\n"); - LTE_PCAP_Close(pcap_file); + DLT_PCAP_Close(pcap_file); #endif #ifndef DISABLE_RF diff --git a/lib/examples/pssch_ue.c b/lib/examples/pssch_ue.c index a7524bba4..f96ddc182 100644 --- a/lib/examples/pssch_ue.c +++ b/lib/examples/pssch_ue.c @@ -223,7 +223,7 @@ int main(int argc, char** argv) parse_args(&prog_args, argc, argv); - FILE* pcap_file = LTE_PCAP_Open(MAC_LTE_DLT, PCAP_FILENAME); + FILE* pcap_file = DLT_PCAP_Open(MAC_LTE_DLT, PCAP_FILENAME); srsran_use_standard_symbol_size(prog_args.use_standard_lte_rates); @@ -537,7 +537,7 @@ clean_exit: if (pcap_file != NULL) { printf("Saving PCAP file to %s\n", PCAP_FILENAME); - LTE_PCAP_Close(pcap_file); + DLT_PCAP_Close(pcap_file); } #ifdef ENABLE_GUI diff --git a/lib/include/srsran/common/nas_pcap.h b/lib/include/srsran/common/nas_pcap.h index 30b85adbe..c1bc5fd76 100644 --- a/lib/include/srsran/common/nas_pcap.h +++ b/lib/include/srsran/common/nas_pcap.h @@ -13,6 +13,7 @@ #ifndef SRSRAN_NAS_PCAP_H #define SRSRAN_NAS_PCAP_H +#include "srsran/common/common.h" #include "srsran/common/pcap.h" #include @@ -28,7 +29,7 @@ public: pcap_file = NULL; } void enable(); - uint32_t open(std::string filename_, uint32_t ue_id = 0); + uint32_t open(std::string filename_, uint32_t ue_id = 0, srsran_rat_t rat_type = srsran_rat_t::lte); void close(); void write_nas(uint8_t* pdu, uint32_t pdu_len_bytes); diff --git a/lib/include/srsran/common/pcap.h b/lib/include/srsran/common/pcap.h index d3c709d04..10bcef01d 100644 --- a/lib/include/srsran/common/pcap.h +++ b/lib/include/srsran/common/pcap.h @@ -23,6 +23,7 @@ #define NAS_LTE_DLT 148 #define UDP_DLT 149 // UDP needs to be selected as protocol #define S1AP_LTE_DLT 150 +#define NAS_5G_DLT 151 /* This structure gets written to the start of the file */ typedef struct pcap_hdr_s { @@ -184,10 +185,10 @@ extern "C" { #endif /* Open the file and write file header */ -FILE* LTE_PCAP_Open(uint32_t DLT, const char* fileName); +FILE* DLT_PCAP_Open(uint32_t DLT, const char* fileName); /* Close the PCAP file */ -void LTE_PCAP_Close(FILE* fd); +void DLT_PCAP_Close(FILE* fd); /* Write an individual MAC PDU (PCAP packet header + mac-context + mac-pdu) */ int LTE_PCAP_MAC_WritePDU(FILE* fd, MAC_Context_Info_t* context, const unsigned char* PDU, unsigned int length); diff --git a/lib/src/common/mac_pcap.cc b/lib/src/common/mac_pcap.cc index a258f1059..3a909d397 100644 --- a/lib/src/common/mac_pcap.cc +++ b/lib/src/common/mac_pcap.cc @@ -32,7 +32,7 @@ uint32_t mac_pcap::open(std::string filename_, uint32_t ue_id_) // set DLT for selected RAT dlt = UDP_DLT; - pcap_file = LTE_PCAP_Open(dlt, filename_.c_str()); + pcap_file = DLT_PCAP_Open(dlt, filename_.c_str()); if (pcap_file == nullptr) { logger.error("Couldn't open %s to write PCAP", filename_.c_str()); return SRSRAN_ERROR; @@ -68,7 +68,7 @@ uint32_t mac_pcap::close() { std::lock_guard lock(mutex); srsran::console("Saving MAC PCAP (DLT=%d) to %s\n", dlt, filename.c_str()); - LTE_PCAP_Close(pcap_file); + DLT_PCAP_Close(pcap_file); pcap_file = nullptr; } diff --git a/lib/src/common/nas_pcap.cc b/lib/src/common/nas_pcap.cc index 05ff76ca5..6d45d2a09 100644 --- a/lib/src/common/nas_pcap.cc +++ b/lib/src/common/nas_pcap.cc @@ -22,10 +22,14 @@ void nas_pcap::enable() enable_write = true; } -uint32_t nas_pcap::open(std::string filename_, uint32_t ue_id_) +uint32_t nas_pcap::open(std::string filename_, uint32_t ue_id_, srsran_rat_t rat_type) { - filename = filename_; - pcap_file = LTE_PCAP_Open(NAS_LTE_DLT, filename.c_str()); + filename = filename_; + if (rat_type == srsran_rat_t::nr) { + pcap_file = DLT_PCAP_Open(NAS_5G_DLT, filename.c_str()); + } else { + pcap_file = DLT_PCAP_Open(NAS_LTE_DLT, filename.c_str()); + } if (pcap_file == nullptr) { return SRSRAN_ERROR; } @@ -37,7 +41,7 @@ uint32_t nas_pcap::open(std::string filename_, uint32_t ue_id_) void nas_pcap::close() { fprintf(stdout, "Saving NAS PCAP file (DLT=%d) to %s \n", NAS_LTE_DLT, filename.c_str()); - LTE_PCAP_Close(pcap_file); + DLT_PCAP_Close(pcap_file); } void nas_pcap::write_nas(uint8_t* pdu, uint32_t pdu_len_bytes) diff --git a/lib/src/common/pcap.c b/lib/src/common/pcap.c index d51727551..fcb44f0bf 100644 --- a/lib/src/common/pcap.c +++ b/lib/src/common/pcap.c @@ -18,7 +18,7 @@ #include /* Open the file and write file header */ -FILE* LTE_PCAP_Open(uint32_t DLT, const char* fileName) +FILE* DLT_PCAP_Open(uint32_t DLT, const char* fileName) { pcap_hdr_t file_header = { 0xa1b2c3d4, /* magic number */ @@ -43,7 +43,7 @@ FILE* LTE_PCAP_Open(uint32_t DLT, const char* fileName) } /* Close the PCAP file */ -void LTE_PCAP_Close(FILE* fd) +void DLT_PCAP_Close(FILE* fd) { if (fd) { fclose(fd); diff --git a/lib/src/common/rlc_pcap.cc b/lib/src/common/rlc_pcap.cc index a0878bb76..9a5aa8230 100644 --- a/lib/src/common/rlc_pcap.cc +++ b/lib/src/common/rlc_pcap.cc @@ -25,7 +25,7 @@ void rlc_pcap::enable(bool en) void rlc_pcap::open(const char* filename, rlc_config_t config) { fprintf(stdout, "Opening RLC PCAP with DLT=%d\n", UDP_DLT); - pcap_file = LTE_PCAP_Open(UDP_DLT, filename); + pcap_file = DLT_PCAP_Open(UDP_DLT, filename); enable_write = true; if (config.rlc_mode == rlc_mode_t::am) { @@ -45,7 +45,7 @@ void rlc_pcap::open(const char* filename, rlc_config_t config) void rlc_pcap::close() { fprintf(stdout, "Saving RLC PCAP file\n"); - LTE_PCAP_Close(pcap_file); + DLT_PCAP_Close(pcap_file); } void rlc_pcap::set_ue_id(uint16_t ue_id_) diff --git a/lib/src/common/s1ap_pcap.cc b/lib/src/common/s1ap_pcap.cc index fd192344b..b6a91c1e3 100644 --- a/lib/src/common/s1ap_pcap.cc +++ b/lib/src/common/s1ap_pcap.cc @@ -23,13 +23,13 @@ void s1ap_pcap::enable() } void s1ap_pcap::open(const char* filename) { - pcap_file = LTE_PCAP_Open(S1AP_LTE_DLT, filename); + pcap_file = DLT_PCAP_Open(S1AP_LTE_DLT, filename); enable_write = true; } void s1ap_pcap::close() { fprintf(stdout, "Saving S1AP PCAP file\n"); - LTE_PCAP_Close(pcap_file); + DLT_PCAP_Close(pcap_file); } void s1ap_pcap::write_s1ap(uint8_t* pdu, uint32_t pdu_len_bytes)