Commit 16d9d33d authored by Laurent THOMAS's avatar Laurent THOMAS

Fix minor bugs and wrong reported trace

parent 1a8c9a56
......@@ -434,6 +434,7 @@ int32_t write_file_matlab(const char *fname, const char *vname, void *data, int
# define LOG_M(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format, 0);} while(0)
# define LOG_VAR(A,B) A B
# define T_ACTIVE(a) (0)
# endif /* T_TRACER */
/* avoid warnings for variables only used in LOG macro's but set outside debug section */
#define GCC_NOTUSED __attribute__((unused))
......
......@@ -73,7 +73,6 @@ int sync_var=-1; //!< protected by mutex \ref sync_mutex.
int config_sync_var=-1;
volatile int oai_exit = 0;
double cpuf;
msc_interface_t msc_interface;
THREAD_STRUCT thread_struct;
uint16_t sf_ahead=4;
......
......@@ -355,8 +355,8 @@ nr_rrc_pdcp_config_security(
if (print_keys == 1 ) {
print_keys =0;
LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, ue_context_pP->ue_context.kgnb, 32,"\nKgNB:" );
LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, kRRCenc, 32,"\nKRRCenc:" );
LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, kRRCint, 32,"\nKRRCint:" );
LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, kRRCenc, 16,"\nKRRCenc:" );
LOG_DUMPMSG(NR_RRC, DEBUG_SECURITY, kRRCint, 16,"\nKRRCint:" );
}
}
......
How to configure wireshark for dissecting LTE protocols:
How to configure wireshark for dissecting LTE/NR protocols:
- start the wireshark as a sudoers
- goto analyze->enabled prototols
=> enable mac_lte_udp and rlc_lte_udp
=> enable mac_xxx_udp and rlc_xxx_udp (xxx is lte or nr)
- goto edit/preferences and expand Protocols
- select UDP and check "try heuristic sub-dissectors first"
- select MAC-LTE, and check all the options (checkboxes), and set the "which layer info to show in info column" to "MAC info"
- select RLC-LTE, and check all the options except the "May see RLC headers only", and
- select MAC-LTE (or MAC-NR), and check all the options (checkboxes), and set the "which layer info to show in info column" to "MAC info"
- select RLC-LTE (or NR), and check all the options except the "May see RLC headers only", and
set the "call PDCP dissector for DRB PDUs" to "12-bit SN". Optionally you may select the sequence analysis for RLC AM/UM.
- select PDCP-LTE (or NR)
How to use
- start eNB or UE with option --opt.type wireshark
......
......@@ -60,6 +60,12 @@ typedef uint32_t guint32;
typedef guint8 gboolean;
#include "packet-mac-lte.h"
#include "packet-rlc-lte.h"
#include "packet-pdcp-lte.h"
#include "packet-mac-nr.h"
#include "packet-rlc-nr.h"
#include "packet-pdcp-nr.h"
#include "mac_pcap.h"
/* OPT parameters definitions */
......@@ -107,9 +113,10 @@ typedef enum radio_type_e {
*/
extern int opt_enabled;
#define trace_pdu(x...) if (opt_enabled) trace_pdu_implementation(x)
#define trace_pdu(x...) if (opt_enabled) trace_pdu_implementation(0, x)
#define trace_NRpdu(x...) if (opt_enabled) trace_pdu_implementation(1, x)
void trace_pdu_implementation(int direction, uint8_t *pdu_buffer, unsigned int pdu_buffer_size,
void trace_pdu_implementation(int nr, int direction, uint8_t *pdu_buffer, unsigned int pdu_buffer_size,
int ueid, int rntiType, int rnti, uint16_t sysFrame, uint8_t subframe,
int oob_event, int oob_event_value);
......
......@@ -114,6 +114,7 @@ typedef struct mac_lte_info
/* Timing info */
guint16 sysframeNumber;
guint16 subframeNumber;
gboolean sfnSfInfoPresent;
/* Optional field. More interesting for TDD (FDD is always -4 subframeNumber) */
gboolean subframeNumberOfGrantPresent;
......@@ -197,37 +198,15 @@ typedef struct mac_lte_info
guint16 oob_rnti[MAX_SRs];
} mac_lte_info;
/* 0 to 10 and 32 to 38 */
#define MAC_LTE_DATA_LCID_COUNT_MAX 18
typedef struct mac_lte_tap_info {
/* Info from context */
guint16 rnti;
guint16 ueid;
guint8 rntiType;
guint8 isPredefinedData;
gboolean crcStatusValid;
mac_lte_crc_status crcStatus;
guint8 direction;
guint8 isPHYRetx;
guint16 ueInTTI;
nstime_t mac_lte_time;
/* Number of bytes (which part is used depends upon context settings) */
guint32 single_number_of_bytes;
guint32 bytes_for_lcid[11];
guint32 sdus_for_lcid[11];
guint8 number_of_rars;
guint8 number_of_paging_ids;
/* Number of padding bytes includes padding subheaders and trailing padding */
guint16 padding_bytes;
guint16 raw_length;
} mac_lte_tap_info;
/* Accessor function to check if a frame was considered to be ReTx */
/*****************************************************************/
/**********************************************************************/
/* UDP framing format */
/* ----------------------- */
/* Several people have asked about dissecting MAC by framing */
......@@ -235,11 +214,11 @@ typedef struct mac_lte_tap_info {
/* and implemented by this dissector, using the definitions */
/* below. A link to an example program showing you how to encode */
/* these headers and send LTE MAC PDUs on a UDP socket is */
/* provided at https://wiki.wireshark.org/MAC-LTE */
/* provided at https://gitlab.com/wireshark/wireshark/-/wikis/MAC-LTE */
/* */
/* A heuristic dissector (enabled by a preference) will */
/* recognise a signature at the beginning of these frames. */
/*****************************************************************/
/**********************************************************************/
/* Signature. Rather than try to define a port for this, or make the
......@@ -317,66 +296,4 @@ typedef struct mac_lte_tap_info {
continues until the end of the frame) */
#define MAC_LTE_PAYLOAD_TAG 0x01
/* Type to store parameters for configuring LCID->RLC channel settings for DRB */
/* Some are optional, and may not be seen (e.g. on reestablishment) */
typedef struct drb_mapping_t
{
guint16 ueid; /* Mandatory */
guint8 drbid; /* Mandatory */
gboolean lcid_present;
guint8 lcid; /* Part of LogicalChannelConfig - optional */
gboolean rlcMode_present;
guint8 rlcMode; /* Part of RLC config - optional */
gboolean rlc_ul_ext_li_field; /* Part of RLC config - optional */
gboolean rlc_dl_ext_li_field; /* Part of RLC config - optional */
gboolean rlc_ul_ext_am_sn; /* Part of RLC config - optional */
gboolean rlc_dl_ext_am_sn; /* Part of RLC config - optional */
gboolean um_sn_length_present;
guint8 um_sn_length; /* Part of RLC config - optional */
gboolean ul_priority_present;
guint8 ul_priority; /* Part of LogicalChannelConfig - optional */
gboolean pdcp_sn_size_present;
guint8 pdcp_sn_size; /* Part of pdcp-Config - optional */
} drb_mapping_t;
/* Dedicated DRX config. Used to verify that a sensible config is given.
Also, beginning to configure MAC with this config and (optionally) show
DRX config and state (cycles/timers) attached to each UL/DL PDU! */
typedef struct drx_config_t {
gboolean configured;
guint32 frameNum;
guint32 previousFrameNum;
guint32 onDurationTimer;
guint32 inactivityTimer;
guint32 retransmissionTimer;
guint32 longCycle;
guint32 cycleOffset;
/* Optional Short cycle */
gboolean shortCycleConfigured;
guint32 shortCycle;
guint32 shortCycleTimer;
} drx_config_t;
/* RRC can indicate whether simultaneous PUCCH/PUSCH is used */
typedef enum {
SIMULT_PUCCH_PUSCH_PCELL = 0,
SIMULT_PUCCH_PUSCH_PSCELL
} simult_pucch_pusch_cell_type;
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
#endif
......@@ -128,12 +128,6 @@ typedef struct {
opt_listener_t opt_listener;
static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
guint16 rnti, guint16 ueid, guint16 sysframeNumber,
guint8 isPredefinedData, guint8 retx, guint8 crcStatus,
guint8 oob_event, guint8 oob_event_value,
uint8_t *pdu_buffer, unsigned int pdu_buffer_size);
unsigned short checksum(unsigned short *ptr, int length) {
int sum = 0;
u_short answer = 0;
......@@ -152,7 +146,7 @@ unsigned short checksum(unsigned short *ptr, int length) {
}
/* Write an individual PDU (PCAP packet header + mac-context + mac-pdu) */
static int MAC_LTE_PCAP_WritePDU(const uint8_t *PDU,
static int PCAP_WritePDU(const uint8_t *PDU,
unsigned int length) {
pcaprec_hdr_t packet_header;
// IPv4 header
......@@ -288,7 +282,7 @@ int opt_create_listener_socket(char *ip_address, uint16_t port) {
*/
/* Add framing header to MAC PDU and send. */
static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
guint16 rnti, guint16 ueid, guint16 sfnSf,
guint16 rnti, guint16 ueid, guint16 frame, guint16 subframe,
guint8 isPredefinedData, guint8 retx, guint8 crcStatus,
guint8 oob_event, guint8 oob_event_value,
uint8_t *pdu_buffer, unsigned int pdu_buffer_size) {
......@@ -319,7 +313,7 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
frameOffset += 2;
/* Subframe number */
frameBuffer[frameOffset++] = MAC_LTE_FRAME_SUBFRAME_TAG;
tmp16 = htons(sfnSf); // frame counter : this will give an expert info as wireshark expects SF and not F
tmp16 = htons((frame<<4)+subframe); // frame counter : this will give an expert info as wireshark expects SF and not F
memcpy(frameBuffer+frameOffset, &tmp16, 2);
frameOffset += 2;
frameBuffer[frameOffset++] = MAC_LTE_CRC_STATUS_TAG;
......@@ -400,7 +394,72 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
bytesSent = sendto(g_socksd, frameBuffer, frameOffset, 0,
(const struct sockaddr *)&g_serv_addr, sizeof(g_serv_addr));
else
bytesSent = MAC_LTE_PCAP_WritePDU(frameBuffer, frameOffset);
bytesSent = PCAP_WritePDU(frameBuffer, frameOffset);
if (bytesSent != frameOffset) {
LOG_W(OPT, "trace_pdu expected %d bytes, got %ld (errno=%d)\n",
frameOffset, bytesSent, errno);
//exit(1);
}
}
static void SendFrameNR(guint8 radioType, guint8 direction, guint8 rntiType,
guint16 rnti, guint16 ueid, guint16 frame, guint16 subframe,
guint8 isPredefinedData, guint8 retx, guint8 crcStatus,
guint8 oob_event, guint8 oob_event_value,
uint8_t *pdu_buffer, unsigned int pdu_buffer_size) {
unsigned char frameBuffer[9000];
unsigned int frameOffset;
ssize_t bytesSent;
frameOffset = 0;
uint16_t tmp16;
memcpy(frameBuffer+frameOffset, MAC_NR_START_STRING,
strlen(MAC_NR_START_STRING));
frameOffset += strlen(MAC_NR_START_STRING);
/******************************************************************************/
/* Now write out fixed fields (the mandatory elements of struct mac_lte_info) */
frameBuffer[frameOffset++] = radioType;
frameBuffer[frameOffset++] = direction;
frameBuffer[frameOffset++] = rntiType;
/*************************************/
/* Now optional fields */
/* RNTI */
frameBuffer[frameOffset++] = MAC_NR_RNTI_TAG;
tmp16 = htons(rnti);
memcpy(frameBuffer+frameOffset, &tmp16, 2);
frameOffset += 2;
/* UEId */
frameBuffer[frameOffset++] = MAC_NR_UEID_TAG;
tmp16 = htons(ueid);
memcpy(frameBuffer+frameOffset, &tmp16, 2);
frameOffset += 2;
/* Subframe number */
frameBuffer[frameOffset++] = MAC_NR_FRAME_SLOT_TAG;
tmp16 = htons(frame); // frame counter : this will give an expert info as wireshark expects SF and not F
memcpy(frameBuffer+frameOffset, &tmp16, 2);
frameOffset += 2;
tmp16 = htons(subframe); // frame counter : this will give an expert info as wireshark expects SF and not F
memcpy(frameBuffer+frameOffset, &tmp16, 2);
frameOffset += 2;
/***************************************/
/* Now write the MAC PDU */
frameBuffer[frameOffset++] = MAC_NR_PAYLOAD_TAG;
/* Append actual PDU */
//memcpy(frameBuffer+frameOffset, g_PDUBuffer, g_PDUOffset);
//frameOffset += g_PDUOffset;
if (pdu_buffer != NULL) {
memcpy(frameBuffer+frameOffset, (void *)pdu_buffer, pdu_buffer_size);
frameOffset += pdu_buffer_size;
}
if ( opt_type == OPT_WIRESHARK )
/* Send out the data over the UDP socket */
bytesSent = sendto(g_socksd, frameBuffer, frameOffset, 0,
(const struct sockaddr *)&g_serv_addr, sizeof(g_serv_addr));
else
bytesSent = PCAP_WritePDU(frameBuffer, frameOffset);
if (bytesSent != frameOffset) {
LOG_W(OPT, "trace_pdu expected %d bytes, got %ld (errno=%d)\n",
......@@ -413,20 +472,23 @@ static void SendFrame(guint8 radioType, guint8 direction, guint8 rntiType,
extern RAN_CONTEXT_t RC;
#include <openair1/PHY/phy_extern_ue.h>
/* Remote serveraddress (where Wireshark is running) */
void trace_pdu_implementation(int direction, uint8_t *pdu_buffer, unsigned int pdu_buffer_size,
void trace_pdu_implementation(int nr, int direction, uint8_t *pdu_buffer, unsigned int pdu_buffer_size,
int ueid, int rntiType, int rnti, uint16_t sysFrameNumber, uint8_t subFrameNumber, int oob_event,
int oob_event_value) {
int radioType=FDD_RADIO;
LOG_D(OPT,"sending packet to wireshark: direction=%s, size: %d, ueid: %d, rnti: %x, frame/sf: %d.%d\n",
direction?"DL":"UL", pdu_buffer_size, ueid, rnti, sysFrameNumber,subFrameNumber);
if (nr) {
radioType=TDD_RADIO;
} else {
if (RC.eNB && RC.eNB[0][0]!=NULL)
radioType=RC.eNB[0][0]->frame_parms.frame_type== FDD ? FDD_RADIO:TDD_RADIO;
else if (PHY_vars_UE_g && PHY_vars_UE_g[0][0] != NULL)
radioType=PHY_vars_UE_g[0][0]->frame_parms.frame_type== FDD ? FDD_RADIO:TDD_RADIO;
else {
LOG_E(OPT,"not a eNB neither a UE!!! \n");
return;
LOG_E(OPT,"not a 4G eNB neither a 4G UE!!! \n");
}
}
switch (opt_type) {
......@@ -448,9 +510,17 @@ void trace_pdu_implementation(int direction, uint8_t *pdu_buffer, unsigned int p
break;
}
if (nr)
SendFrameNR( radioType,
(direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK : DIRECTION_UPLINK,
rntiType, rnti, ueid, sysFrameNumber, subFrameNumber,
1, 0, 1, //guint8 isPredefinedData, guint8 retx, guint8 crcStatus
oob_event,oob_event_value,
pdu_buffer, pdu_buffer_size);
else
SendFrame( radioType,
(direction == DIRECTION_DOWNLINK) ? DIRECTION_DOWNLINK : DIRECTION_UPLINK,
rntiType, rnti, ueid, (sysFrameNumber<<4) + subFrameNumber,
rntiType, rnti, ueid, sysFrameNumber, subFrameNumber,
1, 0, 1, //guint8 isPredefinedData, guint8 retx, guint8 crcStatus
oob_event,oob_event_value,
pdu_buffer, pdu_buffer_size);
......
......@@ -142,7 +142,11 @@ extern int asn1_xer_print;
} \
} \
if (ie == NULL ) { \
NGAP_ERROR("NGAP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL\n",__FILE__,__LINE__);\
if (mandatory) {\
NGAP_ERROR("NGAP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL (searching for ie: %ld)\n",__FILE__,__LINE__, IE_ID);\
abort();\
}\
else NGAP_INFO("NGAP_FIND_PROTOCOLIE_BY_ID: %s %d: ie is NULL (searching for ie: %ld)\n",__FILE__,__LINE__, IE_ID);\
} \
} while(0)
/** \brief Function callback prototype.
......
......@@ -657,6 +657,7 @@ int ngap_gNB_handle_error_indication(uint32_t assoc_id,
case NGAP_CauseRadioNetwork_up_integrity_protection_not_possible:
NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_up_integrity_protection_not_possible\n");
break;
case NGAP_CauseRadioNetwork_up_confidentiality_protection_not_possible:
NGAP_WARN("Received NG Error indication NGAP_CauseRadioNetwork_up_confidentiality_protection_not_possible\n");
break;
......@@ -1070,12 +1071,13 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
//if (ie != NULL) { /* checked by macro but cppcheck doesn't see it */
NGAP_AllowedNSSAI_Item_t *allow_nssai_item_p = NULL;
NGAP_WARN("AllowedNSSAI.list.count %d\n", ie != NULL ? ie->value.choice.AllowedNSSAI.list.count : 2);
//NGAP_DEBUG("AllowedNSSAI.list.count %d\n", ie->value.choice.AllowedNSSAI.list.count);
//DevAssert(ie->value.choice.AllowedNSSAI.list.count > 0);
//DevAssert(ie->value.choice.AllowedNSSAI.list.count <= NGAP_maxnoofAllowedS_NSSAIs);
if (ie == NULL) {
NGAP_WARN("AllowedNSSAI not present, forging 2 NSSAI\n");
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_allowed_nssais = 2;
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[0].sST = 01;
......@@ -1092,7 +1094,7 @@ int ngap_gNB_handle_initial_context_request(uint32_t assoc_id,
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[1].sD[1] = 00;//22;
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).allowed_nssai[1].sD[2] = 01;//33;
} else {
NGAP_INFO("AllowedNSSAI.list.count %d\n", ie->value.choice.AllowedNSSAI.list.count);
NGAP_INITIAL_CONTEXT_SETUP_REQ(message_p).nb_allowed_nssais = ie->value.choice.AllowedNSSAI.list.count;
for(i = 0; i < ie->value.choice.AllowedNSSAI.list.count; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment