Added 5G NAS PCAP support

This commit is contained in:
David Rupprecht 2021-06-08 09:54:57 +02:00 committed by David Rupprecht
parent 78acf81cf0
commit 85d7a851fb
9 changed files with 25 additions and 19 deletions

View File

@ -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

View File

@ -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

View File

@ -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 <string>
@ -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);

View File

@ -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);

View File

@ -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<std::mutex> 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;
}

View File

@ -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)

View File

@ -18,7 +18,7 @@
#include <sys/time.h>
/* 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);

View File

@ -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_)

View File

@ -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)