Starting to add s1ap_pcap class.

master
Pedro Alvarez 6 years ago
parent 32a5c6a92f
commit ff49e56871

@ -35,7 +35,7 @@
#define MAC_LTE_DLT 147
#define NAS_LTE_DLT 148
#define RLC_LTE_DLT 149 // UDP needs to be selected as protocol
#define S1AP_LTE_DLT 150 // UDP needs to be selected as protocol
/* This structure gets written to the start of the file */
typedef struct pcap_hdr_s {
@ -165,6 +165,10 @@ typedef struct {
#define RLC_LTE_PAYLOAD_TAG 0x01
/* Context information for every S1AP PDU that will be logged */
typedef struct S1AP_Context_Info_s {
// No Context yet
} S1AP_Context_Info_t;
/**************************************************************************
* API functions for opening/closing LTE PCAP files *
@ -398,4 +402,37 @@ inline int LTE_PCAP_RLC_WritePDU(FILE *fd, RLC_Context_Info_t *context,
return 1;
}
/**************************************************************************
* API functions for writing S1AP PCAP files *
**************************************************************************/
/* Write an individual PDU (PCAP packet header + s1ap-context + s1ap-pdu) */
inline int LTE_PCAP_S1AP_WritePDU(FILE *fd, S1AP_Context_Info_t *context,
const unsigned char *PDU, unsigned int length)
{
pcaprec_hdr_t packet_header;
/* Can't write if file wasn't successfully opened */
if (fd == NULL) {
printf("Error: Can't write to empty file handle\n");
return 0;
}
/****************************************************************/
/* PCAP Header */
struct timeval t;
gettimeofday(&t, NULL);
packet_header.ts_sec = t.tv_sec;
packet_header.ts_usec = t.tv_usec;
packet_header.incl_len = length;
packet_header.orig_len = length;
/***************************************************************/
/* Now write everything to the file */
fwrite(&packet_header, sizeof(pcaprec_hdr_t), 1, fd);
fwrite(PDU, 1, length, fd);
return 1;
}
#endif // SRSLTE_PCAP_H

@ -0,0 +1,23 @@
#ifndef SRSLTE_S1AP_PCAP_H
#define SRSLTE_S1AP_PCAP_H
#include "srslte/common/pcap.h"
namespace srslte {
class s1ap_pcap
{
public:
s1ap_pcap() {enable_write=false; pcap_file = NULL; }
void enable();
void open(const char *filename);
void close();
void write_s1ap(uint8_t *pdu, uint32_t pdu_len_bytes);
private:
bool enable_write;
FILE *pcap_file;
};
} //namespace srslte
#endif // SRSLTE_NAS_PCAP_H

@ -1,33 +1,32 @@
#include <stdint.h>
#include "srslte/srslte.h"
#include "srslte/common/pcap.h"
#include "srslte/common/nas_pcap.h"
#include "srslte/common/s1ap_pcap.h"
namespace srslte {
void nas_pcap::enable()
void s1ap_pcap::enable()
{
enable_write = true;
}
void nas_pcap::open(const char* filename, uint32_t ue_id)
void s1ap_pcap::open(const char* filename)
{
pcap_file = LTE_PCAP_Open(NAS_LTE_DLT, filename);
ue_id = ue_id;
pcap_file = LTE_PCAP_Open(S1AP_LTE_DLT, filename);
enable_write = true;
}
void nas_pcap::close()
void s1ap_pcap::close()
{
fprintf(stdout, "Saving NAS PCAP file\n");
fprintf(stdout, "Saving S1AP PCAP file\n");
LTE_PCAP_Close(pcap_file);
}
void nas_pcap::write_nas(uint8_t *pdu, uint32_t pdu_len_bytes)
void s1ap_pcap::write_s1ap(uint8_t *pdu, uint32_t pdu_len_bytes)
{
if (enable_write) {
NAS_Context_Info_t context;
S1AP_Context_Info_t context;
if (pdu) {
LTE_PCAP_NAS_WritePDU(pcap_file, &context, pdu, pdu_len_bytes);
LTE_PCAP_S1AP_WritePDU(pcap_file, &context, pdu, pdu_len_bytes);
}
}
}

Loading…
Cancel
Save