Commit c3c02bbd authored by frtabu's avatar frtabu

Use same port number for source and destination number in new gtp implementation.

parent 9707cb99
......@@ -219,7 +219,7 @@ gNBs =
GNB_IPV4_ADDRESS_FOR_NG_AMF = "CI_GNB_IP_ADDR";
GNB_INTERFACE_NAME_FOR_NGU = "eth0";
GNB_IPV4_ADDRESS_FOR_NGU = "CI_GNB_IP_ADDR";
GNB_PORT_FOR_S1U = 2152; # Spec 2152
GNB_PORT_FOR_NGU = 2152; # Spec 2152
};
}
......
......@@ -681,9 +681,6 @@ void run_telnetclt(void) {
struct sockaddr_in name;
pthread_setname_np(pthread_self(), "telnetclt");
set_sched(pthread_self(),0,telnetparams.priority);
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
fprintf(stderr,"[TELNETSRV] Error %s on socket call\n",strerror(errno));
char prompt[sizeof(TELNET_PROMPT_PREFIX)+10];
sprintf(prompt,"%s_%s> ",TELNET_PROMPT_PREFIX,get_softmodem_function(NULL));
name.sin_family = AF_INET;
......@@ -691,6 +688,10 @@ void run_telnetclt(void) {
inet_aton("127.0.0.1", &addr) ;
name.sin_addr.s_addr = addr.s_addr;
name.sin_port = htons((unsigned short)(telnetparams.listenport));
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0)
fprintf(stderr,"[TELNETSRV] Error %s on socket call\n",strerror(errno));
if(connect(sock, (void *) &name, sizeof(name)))
fprintf(stderr,"[TELNETSRV] Error %s on connect call\n",strerror(errno));
......@@ -875,7 +876,7 @@ int add_telnetcmd(char *modulename, telnetshell_vardef_t *var, telnetshell_cmdde
/* function which will be called by the shared lib loader, to check shared lib version
against main exec version. version mismatch no considered as fatal (interfaces not supposed to change)
against main exec version. version mismatch not considered as fatal (interfaces not supposed to change)
*/
int telnetsrv_checkbuildver(char *mainexec_buildversion, char **shlib_buildversion) {
#ifndef PACKAGE_VERSION
......
......@@ -205,13 +205,13 @@ int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt) {
int badcmd=1;
if (debug > 0)
prnt(" measurcmd_show received %s\n",buf);
prnt(" measurcmd_cpustats received %s\n",buf);
int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2);
if (s>0) {
if ( strcmp(subcmd,"enable") == 0) {
cpumeas(CPUMEAS_ENABLE);
badcmd=0;
} else if ( strcmp(subcmd,"disable") == 0) {
cpumeas(CPUMEAS_DISABLE);
......@@ -226,6 +226,64 @@ int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt) {
free(subcmd);
return CMDSTATUS_FOUND;
}
void measurcmd_async_help(telnet_printfunc_t prnt) {
}
int measurcmd_async(char *buf, int debug, telnet_printfunc_t prnt) {
char *subcmd=NULL;
int idx1, idx2;
int okcmd=0;
if buff == NULL) {
measurcmd_async_help();
return CMDSTATUS_FOUND;
}
if (debug > 0)
prnt(" measurcmd_async received %s\n",buf);
int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2);
if (s==1) {
if ( strcmp(subcmd,"enable") == 0) {
init_meas();
okcmd=1;
} else if ( strcmp(subcmd,"disable") == 0) {
end_meas();
okcmd=1;
}
} else if ( s == 3 ) {
int msgid;
if ( strcmp(subcmd,"enable") == 0) {
msgid = TIMESTAT_MSGID_ENABLE;
okcmd=1;
} else if ( strcmp(subcmd,"disable") == 0) {
msgid = TIMESTAT_MSGID_DISABLE;
okcmd=1;
} else if ( strcmp(subcmd,"display") == 0) {
msgid = TIMESTAT_MSGID_DISPLAY;
okcmd=1;
}
if (okcmd) {
notifiedFIFO_elt_t *nfe = newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
time_stats_msg_t *msg = (time_stats_msg_t *)NotifiedFifoData(nfe);
msg->msgid = msgid ;
msg->displayFunc = prnt;
for(int i=idx1; i<idx2; i++) {
msg->timestat_id =i;
pushNotifiedFIFO(&measur_fifo, nfe);
}
}
}
if (!(okcmd)) {
prnt("Unknown command: %s\n",buf);
}
free(subcmd);
return CMDSTATUS_FOUND;
}
/*-------------------------------------------------------------------------------------*/
/* function called at telnet server init to add the measur command */
......
......@@ -83,9 +83,11 @@ typedef struct mesurgroupdef {
#ifdef TELNETSRV_MEASURMENTS_MAIN
int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt);
int measurcmd_cpustats(char *buf, int debug, telnet_printfunc_t prnt);
int measurcmd_async(char *buf, int debug, telnet_printfunc_t prnt);
telnetshell_cmddef_t measur_cmdarray[] = {
{"show", "groups | <group name> | inq" , measurcmd_show},
{"cpustats","[enable | disable]",measurcmd_cpustats},
{"async","[enable | disable]",measurcmd_async},
{"","",NULL}
};
......
......@@ -145,9 +145,11 @@ double get_time_meas_us(time_stats_t *ts)
}
#ifndef PHYSIM
/* function for the asynchronous measurment module: cpu stat are sent to a dedicated thread
* which is in charge of computing the cpu time spent in a given function/algorithm...
*/
int register_meas(char *name, time_stats_t *dst_ts)
time_stats_t *register_meas(char *name)
{
for (int i=0; i<max_cpumeasur; i++) {
if (measur_table[i] == NULL) {
......@@ -155,10 +157,23 @@ int register_meas(char *name, time_stats_t *dst_ts)
memset(measur_table[i] ,0,sizeof(time_stats_t));
measur_table[i]->meas_name = strdup(name);
measur_table[i]->meas_index = i;
return i;
measur_table[i]->tpoolmsg =newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
measur_table[i]->tstatptr = (time_stats_msg_t *)NotifiedFifoData(measur_table[i]->tpoolmsg);
return measur_table[i];
}
}
return NULL;
}
void free_measurtbl(void) {
for (int i=0; i<max_cpumeasur; i++) {
if (measur_table[i] != NULL) {
free(measur_table[i]->meas_name);
delNotifiedFIFO_elt(measur_table[i]->tpoolmsg);
free(measur_table[i]);
}
}
return -1;
//free the fifo...
}
void run_cpumeasur(void) {
......@@ -183,7 +198,7 @@ void run_cpumeasur(void) {
if ( measur_table[tsm->timestat_id]->p_time > measur_table[tsm->timestat_id]->max )
measur_table[tsm->timestat_id]->max = measur_table[tsm->timestat_id]->p_time;
break;
case TIMESTAT_MSGID_DISPLAY:
case TIMESTAT_MSGID_DISPLAY:
{
char aline[256];
int start, stop;
......@@ -204,17 +219,21 @@ void run_cpumeasur(void) {
}
}
}
break;
default:
break;
break;
case TIMESTAT_MSGID_END:
free_measurtbl();
delNotifiedFIFO_elt(msg);
pthread_exit(NULL);
break;
default:
break;
}
delNotifiedFIFO_elt(msg);
}
}
void init_meas(void)
{
void init_meas(void) {
pthread_t thid;
paramdef_t cpumeasur_params[] = CPUMEASUR_PARAMS_DESC;
int numparams=sizeof(cpumeasur_params)/sizeof(paramdef_t);
......@@ -225,4 +244,11 @@ void init_meas(void)
rt=pthread_create(&thid,NULL, (void *(*)(void *))run_cpumeasur, NULL);
AssertFatal(rt==0, "couldn't create cpu measurment thread: %s\n",strerror(errno));
}
void end_meas(void) {
notifiedFIFO_elt_t *nfe = newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
time_stats_msg_t *msg = (time_stats_msg_t *)NotifiedFifoData(nfe);
msg->msgid = TIMESTAT_MSGID_END ;
pushNotifiedFIFO(&measur_fifo, nfe);
}
#endif
......@@ -45,8 +45,23 @@ extern double cpu_freq_GHz __attribute__ ((aligned(32)));;
#else
#error "building on unsupported CPU architecture"
#endif
#define TIMESTAT_MSGID_START 0 /*!< \brief send time at measure starting point */
#define TIMESTAT_MSGID_STOP 1 /*!< \brief send time at measure end point */
#define TIMESTAT_MSGID_ENABLE 2 /*!< \brief enable measure point */
#define TIMESTAT_MSGID_DISABLE 3 /*!< \brief disable measure point */
#define TIMESTAT_MSGID_DISPLAY 10 /*!< \brief display measure */
#define TIMESTAT_MSGID_END 11 /*!< \brief stops the measure threads and free assocated resources */
typedef struct {
int msgid; /*!< \brief message id, as defined by TIMESTAT_MSGID_X macros */
int timestat_id; /*!< \brief points to the time_stats_t entry in cpumeas table */
OAI_CPUTIME_TYPE ts; /*!< \brief time stamp */
void (*displayFunc)(void *); /*!< \brief function to call when DISPLAY message is received*/
} time_stats_msg_t;
typedef struct {
OAI_CPUTIME_TYPE in; /*!< \brief time at measue starting point */
OAI_CPUTIME_TYPE in; /*!< \brief time at measure starting point */
OAI_CPUTIME_TYPE diff; /*!< \brief average difference between time at starting point and time at endpoint*/
OAI_CPUTIME_TYPE p_time; /*!< \brief absolute process duration */
OAI_CPUTIME_TYPE diff_square; /*!< \brief process duration square */
......@@ -55,17 +70,13 @@ typedef struct {
int meas_flag; /*!< \brief 1: stop_meas not called (consecutive calls of start_meas) */
char *meas_name; /*!< \brief name to use when printing the measure (not used for PHY simulators)*/
int meas_index; /*!< \brief index of this measure in the measure array (not used for PHY simulators)*/
bool meas_enabled; /*!< \brief per measure enablement flag. send_meas tests this flag, unused today in start_meas and stop_meas*/
notifiedFIFO_elt_t *tpoolmsg; /*!< \brief message pushed to the cpu measurment queue to report a measure START or STOP */
time_stats_msg_t *tstatptr; /*!< \brief pointer to the time_stats_msg_t data in the tpoolmsg, stored here for perf considerations*/
} time_stats_t;
#define MEASURE_ENABLED(X) (X->meas_enabled)
#define TIMESTAT_MSGID_START 0
#define TIMESTAT_MSGID_STOP 1
#define TIMESTAT_MSGID_DISPLAY 2
typedef struct {
int msgid; /*!< \brief message id, as defined by TIMESTAT_MSGID_X macros */
int timestat_id; /*!< \brief points to the time_stats_t entry in cpumeas table */
OAI_CPUTIME_TYPE ts; /*!< \brief time stamp */
void (*displayFunc)(void *); /*!< \brief function to call when DISPLAY message is received*/
} time_stats_msg_t;
static inline void start_meas(time_stats_t *ts) __attribute__((always_inline));
......@@ -159,15 +170,18 @@ extern notifiedFIFO_t measur_fifo;
}
void init_meas(void);
int register_meas(char *name, time_stats_t *ts);
static inline void send_meas(int measur_idx) {
if (opp_enabled) {
notifiedFIFO_elt_t *msg =newNotifiedFIFO_elt(sizeof(time_stats_msg_t),0,NULL,NULL);
time_stats_msg_t *tsm = (time_stats_msg_t *)NotifiedFifoData(msg);
tsm->ts = rdtsc_oai();
pushNotifiedFIFO(&measur_fifo, msg);
time_stats_t *register_meas(char *name);
#define START_MEAS(X) send_meas(X, TIMESTAT_MSGID_START)
#define STOP_MEAS(X) send_meas(X, TIMESTAT_MSGID_STOP)
static inline void send_meas(time_stats_t *ts, int msgid) {
if (MEASURE_ENABLED(ts) ) {
ts->tstatptr->timestat_id=ts->meas_index;
ts->tstatptr->msgid = msgid ;
ts->tstatptr->ts = rdtsc_oai();
pushNotifiedFIFO(&measur_fifo, ts->tpoolmsg);
}
}
void end_meas(void);
#endif //ifndef PHYSIM
#endif
......@@ -421,7 +421,7 @@ typedef struct NRRrcConfigurationReq_s {
// UE: NAS -> RRC messages
typedef kenb_refresh_req_t NasKenbRefreshReq;
typedef cell_info_req_t NasCellSelectionReq;
typedef cell_info_req_t NasCellSelectionReq __attribute__ (( aligned (__alignof__(char)) ));
typedef nas_establish_req_t NasConnEstabliReq;
typedef ul_info_transfer_req_t NasUlDataReq;
......
......@@ -483,7 +483,7 @@ typedef struct {
uint8_t status;
PC5SignallingMessage pc5_signalling_message;
} pc5sPrimitive;
} __attribute__((__packed__)) sidelink_pc5s_element;
} __attribute__((__packed__, aligned (__alignof__(char)))) sidelink_pc5s_element;
/*
......
......@@ -603,7 +603,7 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const ctxt_pP)
//int optval;
int bytes_received;
sidelink_pc5s_element *sl_pc5s_msg_send = NULL;
pc5s_header_t *pc5s_header = NULL;
pc5s_header_t *pc5s_header = NULL;
rb_id_t rab_id = 0;
//TTN for D2D (PC5S)
// receive a message from ProSe App
......@@ -704,6 +704,12 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const ctxt_pP)
pc5s_header->rb_id,
rab_id,
pc5s_header->data_size);
/* pointers to pc5s_header fields possibly not aligned because pc5s_header points to a packed structure
* Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
* gcc, from v9, now warns about it. fix these warnings by using local variables
*/
uint32_t sourceL2Id = pc5s_header->sourceL2Id;
uint32_t destinationL2Id = pc5s_header->destinationL2Id;
pdcp_data_req(
&ctxt,
SRB_FLAG_NO,
......@@ -713,9 +719,11 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const ctxt_pP)
pc5s_header->data_size,
(unsigned char *)receive_buf,
PDCP_TRANSMISSION_MODE_DATA,
&pc5s_header->sourceL2Id,
&pc5s_header->destinationL2Id
&sourceL2Id,
&destinationL2Id
);
pc5s_header->sourceL2Id = sourceL2Id;
pc5s_header->destinationL2Id=destinationL2Id;
} else { /* else of h_rc == HASH_TABLE_OK */
MSC_LOG_RX_DISCARDED_MESSAGE(
(ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE,
......@@ -759,6 +767,12 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const ctxt_pP)
pc5s_header->rb_id,
DEFAULT_RAB_ID,
pc5s_header->data_size);
/* pointers to pc5s_header fields possibly not aligned because pc5s_header points to a packed structure
* Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
* gcc, from v9, now warns about it. fix these warnings by using local variables
*/
uint32_t sourceL2Id = pc5s_header->sourceL2Id;
uint32_t destinationL2Id = pc5s_header->destinationL2Id;
pdcp_data_req (
&ctxt,
SRB_FLAG_NO,
......@@ -768,9 +782,11 @@ void pdcp_fifo_read_input_sdus_frompc5s (const protocol_ctxt_t *const ctxt_pP)
pc5s_header->data_size,
(unsigned char *)receive_buf,
PDCP_TRANSMISSION_MODE_DATA,
&pc5s_header->sourceL2Id,
&pc5s_header->destinationL2Id
&sourceL2Id,
&destinationL2Id
);
pc5s_header->sourceL2Id = sourceL2Id;
pc5s_header->destinationL2Id=destinationL2Id;
}
} /* end of !ctxt.enb_flag */
......
......@@ -2969,6 +2969,12 @@ int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,
UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize = siWindowLength_int[sib1->si_WindowLength];
LOG_I( RRC, "[FRAME unknown][RRC_UE][MOD %02"PRIu8"][][--- MAC_CONFIG_REQ (SIB1 params eNB %"PRIu8") --->][MAC_UE][MOD %02"PRIu8"][]\n",
ctxt_pP->module_id, eNB_index, ctxt_pP->module_id );
/* pointers to SIperiod inthe Info struct points to a packed structure
* Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
* gcc, from v9, now warns about it. fix these warnings by removing the indirection on data
* Not sure if SiPeriod can be modified, reassign after function call for security
*/
uint16_t Aligned_SIperiod = UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod;
rrc_mac_config_req_ue(ctxt_pP->module_id, 0, eNB_index,
(LTE_RadioResourceConfigCommonSIB_t *)NULL,
(struct LTE_PhysicalConfigDedicated *)NULL,
......@@ -2981,7 +2987,7 @@ int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,
UE_rrc_inst[ctxt_pP->module_id].sib1[eNB_index]->tdd_Config,
(LTE_MobilityControlInfo_t *) NULL,
&UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIwindowsize,
&UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod ,
&Aligned_SIperiod,
NULL,
NULL,
NULL,
......@@ -2995,6 +3001,7 @@ int decode_SIB1( const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index,
(struct LTE_NonMBSFN_SubframeConfig_r14 *)NULL,
(LTE_MBSFN_AreaInfoList_r9_t *)NULL
);
UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIperiod=Aligned_SIperiod;
LOG_I(RRC,"Setting SIStatus bit 0 to 1\n");
UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIStatus = 1;
UE_rrc_inst[ctxt_pP->module_id].Info[eNB_index].SIB1systemInfoValueTag = sib1->systemInfoValueTag;
......
......@@ -376,7 +376,7 @@ typedef struct UE_RRC_INFO_s {
uint32_t N310_cnt;
uint32_t N311_cnt;
rnti_t rnti;
} __attribute__ ((__packed__)) __attribute__ ((aligned (1))) UE_RRC_INFO;
} __attribute__ ((__packed__)) UE_RRC_INFO;
typedef struct UE_S_TMSI_s {
boolean_t presence;
......
......@@ -81,7 +81,12 @@ int as_message_decode(const char* buffer, as_message_t* msg, int length)
LOG_FUNC_IN;
int bytes;
Byte_t** data = NULL;
/* pointers to msg fields possibly not aligned because msg points to a packed structure
* Using these possibly unaligned pointers in a function call may trigger alignment errors at run time and
* gcc, from v9, now warns about it. fix these warnings by removing the indirection on data
* (in fact i don't understand this code data seems to be useless...)
*/
Byte_t *data = NULL;
/* Get the message type */
msg->msgID = *(uint16_t*)(buffer);
......@@ -91,49 +96,49 @@ int as_message_decode(const char* buffer, as_message_t* msg, int length)
case AS_NAS_ESTABLISH_REQ:
/* NAS signalling connection establish request */
bytes += sizeof(nas_establish_req_t) - sizeof(Byte_t*);
data = &msg->msg.nas_establish_req.initialNasMsg.data;
data = msg->msg.nas_establish_req.initialNasMsg.data;
break;
case AS_NAS_ESTABLISH_IND:
/* NAS signalling connection establishment indication */
bytes += sizeof(nas_establish_ind_t) - sizeof(Byte_t*);
data = &msg->msg.nas_establish_ind.initialNasMsg.data;
data = msg->msg.nas_establish_ind.initialNasMsg.data;
break;
case AS_NAS_ESTABLISH_RSP:
/* NAS signalling connection establishment response */
bytes += sizeof(nas_establish_rsp_t) - sizeof(Byte_t*);
data = &msg->msg.nas_establish_rsp.nasMsg.data;
data = msg->msg.nas_establish_rsp.nasMsg.data;
break;
case AS_NAS_ESTABLISH_CNF:
/* NAS signalling connection establishment confirm */
bytes += sizeof(nas_establish_cnf_t) - sizeof(Byte_t*);
data = &msg->msg.nas_establish_cnf.nasMsg.data;
data = msg->msg.nas_establish_cnf.nasMsg.data;
break;
case AS_UL_INFO_TRANSFER_REQ:
/* Uplink L3 data transfer request */
bytes += sizeof(ul_info_transfer_req_t) - sizeof(Byte_t*);
data = &msg->msg.ul_info_transfer_req.nasMsg.data;
data = msg->msg.ul_info_transfer_req.nasMsg.data;
break;
case AS_UL_INFO_TRANSFER_IND:
/* Uplink L3 data transfer indication */
bytes += sizeof(ul_info_transfer_ind_t) - sizeof(Byte_t*);
data = &msg->msg.ul_info_transfer_ind.nasMsg.data;
data = msg->msg.ul_info_transfer_ind.nasMsg.data;
break;
case AS_DL_INFO_TRANSFER_REQ:
/* Downlink L3 data transfer request */
bytes += sizeof(dl_info_transfer_req_t) - sizeof(Byte_t*);
data = &msg->msg.dl_info_transfer_req.nasMsg.data;
data = msg->msg.dl_info_transfer_req.nasMsg.data;
break;
case AS_DL_INFO_TRANSFER_IND:
/* Downlink L3 data transfer indication */
bytes += sizeof(dl_info_transfer_ind_t) - sizeof(Byte_t*);
data = &msg->msg.dl_info_transfer_ind.nasMsg.data;
data = msg->msg.dl_info_transfer_ind.nasMsg.data;
break;
case AS_BROADCAST_INFO_IND:
......@@ -166,7 +171,8 @@ int as_message_decode(const char* buffer, as_message_t* msg, int length)
if (bytes > 0) {
if (data) {
/* Set the pointer to dedicated NAS information */
*data = (Byte_t*)(buffer + bytes);
/* wasn't data already computed above for specific cases here we override ?? */
data = (Byte_t *)buffer + bytes;
}
/* Decode the message */
......@@ -201,8 +207,10 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
LOG_FUNC_IN;
int bytes = sizeof(msg->msgID);
as_nas_info_t* nas_msg = NULL;
as_nas_info_t nas_msg;
Byte_t *dataptr=NULL;
uint32_t len=0;
switch (msg->msgID) {
case AS_BROADCAST_INFO_IND:
/* Broadcast information */
......@@ -237,25 +245,30 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
case AS_NAS_ESTABLISH_REQ:
/* NAS signalling connection establish request */
bytes += sizeof(nas_establish_req_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.nas_establish_req.initialNasMsg;
nas_msg = msg->msg.nas_establish_req.initialNasMsg;
break;
case AS_NAS_ESTABLISH_IND:
/* NAS signalling connection establish indication */
bytes += sizeof(nas_establish_ind_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.nas_establish_ind.initialNasMsg;
nas_msg = msg->msg.nas_establish_ind.initialNasMsg;
dataptr=(Byte_t *)&(msg->msg.nas_establish_ind.initialNasMsg.data);
len=msg->msg.nas_establish_ind.initialNasMsg.length;
break;
case AS_NAS_ESTABLISH_RSP:
/* NAS signalling connection establish response */
bytes += sizeof(nas_establish_rsp_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.nas_establish_rsp.nasMsg;
nas_msg = msg->msg.nas_establish_rsp.nasMsg;
break;
case AS_NAS_ESTABLISH_CNF:
/* NAS signalling connection establish confirm */
bytes += sizeof(nas_establish_cnf_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.nas_establish_cnf.nasMsg;
nas_msg = msg->msg.nas_establish_cnf.nasMsg;
dataptr=(Byte_t *)&(msg->msg.nas_establish_cnf.nasMsg.data);
len=msg->msg.nas_establish_ind.initialNasMsg.length;
break;
case AS_NAS_RELEASE_REQ:
......@@ -271,7 +284,7 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
case AS_UL_INFO_TRANSFER_REQ:
/* Uplink L3 data transfer request */
bytes += sizeof(ul_info_transfer_req_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.ul_info_transfer_req.nasMsg;
nas_msg = msg->msg.ul_info_transfer_req.nasMsg;
break;
case AS_UL_INFO_TRANSFER_CNF:
......@@ -282,13 +295,13 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
case AS_UL_INFO_TRANSFER_IND:
/* Uplink L3 data transfer indication */
bytes += sizeof(ul_info_transfer_ind_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.ul_info_transfer_ind.nasMsg;
nas_msg = msg->msg.ul_info_transfer_ind.nasMsg;
break;
case AS_DL_INFO_TRANSFER_REQ:
/* Downlink L3 data transfer */
bytes += sizeof(dl_info_transfer_req_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.dl_info_transfer_req.nasMsg;
nas_msg = msg->msg.dl_info_transfer_req.nasMsg;
break;
case AS_DL_INFO_TRANSFER_CNF:
......@@ -299,7 +312,8 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
case AS_DL_INFO_TRANSFER_IND:
/* Downlink L3 data transfer indication */
bytes += sizeof(dl_info_transfer_ind_t) - sizeof(Byte_t*);
nas_msg = &msg->msg.dl_info_transfer_ind.nasMsg;
nas_msg = msg->msg.dl_info_transfer_ind.nasMsg;
break;
case AS_RAB_ESTABLISH_REQ:
......@@ -343,14 +357,14 @@ int as_message_encode(char* buffer, as_message_t* msg, int length)
/* Encode the AS message */
memcpy(buffer, (unsigned char*)msg, bytes);
if ( nas_msg && (nas_msg->length > 0) ) {
if ( (dataptr!=NULL) && (len > 0) ) {
/* Copy the NAS message */
memcpy(buffer + bytes, nas_msg->data, nas_msg->length);
bytes += nas_msg->length;
memcpy(buffer + bytes, nas_msg.data, nas_msg.length);
bytes += len;
/* Release NAS message memory */
free(nas_msg->data);
nas_msg->length = 0;
nas_msg->data = NULL;
free(nas_msg.data);
len=0;
dataptr = NULL;
}
LOG_FUNC_RETURN (bytes);
......
......@@ -136,17 +136,25 @@ static int _emm_as_encrypt(
static int _emm_as_send(const nas_user_t *user, const emm_as_t *msg);
static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_security_t *,
ul_info_transfer_req_t *);
static int _emm_as_establish_req(const emm_data_t *emm_data, const emm_as_establish_t *,
nas_establish_req_t *);
static int _emm_as_cell_info_req(const emm_as_cell_info_t *, cell_info_req_t *);
static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg, ul_info_transfer_req_t *);
static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t *, ul_info_transfer_req_t *);
static int _emm_as_release_req(const emm_as_release_t *, nas_release_req_t *);
static int _emm_as_cell_info_req(const emm_as_cell_info_t *, cell_info_req_t *);
/* prototyping of the following function modified: the last parameter turned to a void pointer
* instead of a ponter to the union field of the as_msg packed structure. This is to avoid new warnings introduced
* from gcc V9 which warns when accessing fields in a packed structure which may result in an alignment problem
* at run time. Modifications allow gcc to know at compile time that it cannot assume any alignment for those pointers.
* On X86 this is not fatal, as at run time the problem can be fixed (but it's better for perf to avoid). On other
* processor as Arm i think it can end in seg fault
*/
static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_security_t *,
void *ul_info_transfer_req_unaligned);
static int _emm_as_establish_req(const emm_data_t *emm_data, const emm_as_establish_t *,
void *nas_establish_req_unaligned);
static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg, void *ul_info_transfer_req_unaligned);
static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t *, void *ul_info_transfer_req_unaligned);
static int _emm_as_release_req(const emm_as_release_t *, void *nas_release_req_unaligned);
/****************************************************************************/
/****************** E X P O R T E D F U N C T I O N S ******************/
......@@ -938,32 +946,32 @@ static int _emm_as_send(const nas_user_t *user, const emm_as_t *msg)
case _EMMAS_DATA_REQ:
as_msg.msgID = _emm_as_data_req(user->emm_data,
&msg->u.data,
&as_msg.msg.ul_info_transfer_req);
(void *)(&as_msg.msg.ul_info_transfer_req));
break;
case _EMMAS_STATUS_IND:
as_msg.msgID = _emm_as_status_ind(user->emm_data,
&msg->u.status,
&as_msg.msg.ul_info_transfer_req);
(void *)(&as_msg.msg.ul_info_transfer_req));
break;
case _EMMAS_RELEASE_REQ:
as_msg.msgID = _emm_as_release_req(
&msg->u.release,
&as_msg.msg.nas_release_req);
(void *)(&as_msg.msg.nas_release_req));
break;
case _EMMAS_SECURITY_RES:
as_msg.msgID = _emm_as_security_res(user->emm_data,
&msg->u.security,
&as_msg.msg.ul_info_transfer_req);
(void *)(&as_msg.msg.ul_info_transfer_req));
break;
case _EMMAS_ESTABLISH_REQ:
as_msg.msgID = _emm_as_establish_req(user->emm_data,
&msg->u.establish,
&as_msg.msg.nas_establish_req);
(void *)(&as_msg.msg.nas_establish_req));
break;
......@@ -1069,10 +1077,10 @@ static int _emm_as_send(const nas_user_t *user, const emm_as_t *msg)
** **
***************************************************************************/
static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg,
ul_info_transfer_req_t *as_msg)
void *ul_info_transfer_req_unaligned)
{
LOG_FUNC_IN;
ul_info_transfer_req_t *as_msg = (ul_info_transfer_req_t *)ul_info_transfer_req_unaligned;
int size = 0;
int is_encoded = FALSE;
......@@ -1165,12 +1173,12 @@ static int _emm_as_data_req(const emm_data_t *emm_data, const emm_as_data_t *msg
** **
***************************************************************************/
static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t *msg,
ul_info_transfer_req_t *as_msg)
void *ul_info_transfer_req_unaligned)
{
LOG_FUNC_IN;
int size = 0;
ul_info_transfer_req_t *as_msg = (ul_info_transfer_req_t *)ul_info_transfer_req_unaligned;
LOG_TRACE(INFO, "EMMAS-SAP - Send AS status indication (cause=%d)",
msg->emm_cause);
......@@ -1239,12 +1247,12 @@ static int _emm_as_status_ind(const emm_data_t *emm_data, const emm_as_status_t
** **
***************************************************************************/
static int _emm_as_release_req(const emm_as_release_t *msg,
nas_release_req_t *as_msg)
void *nas_release_req_unaligned)
{
LOG_FUNC_IN;
LOG_TRACE(INFO, "EMMAS-SAP - Send AS release request");
nas_release_req_t *as_msg = (nas_release_req_t *)nas_release_req_unaligned;
/* Setup the AS message */
if (msg->guti) {
as_msg->s_tmsi.MMEcode = msg->guti->gummei.MMEcode;
......@@ -1279,10 +1287,10 @@ static int _emm_as_release_req(const emm_as_release_t *msg,
** **
***************************************************************************/
static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_security_t *msg,
ul_info_transfer_req_t *as_msg)
void *ul_info_transfer_req_unaligned)
{
LOG_FUNC_IN;
ul_info_transfer_req_t *as_msg=(ul_info_transfer_req_t *)ul_info_transfer_req_unaligned;
int size = 0;
LOG_TRACE(INFO, "EMMAS-SAP - Send AS security response");
......@@ -1373,12 +1381,12 @@ static int _emm_as_security_res(const emm_data_t *emm_data, const emm_as_securit
** **
***************************************************************************/
static int _emm_as_establish_req(const emm_data_t *emm_data, const emm_as_establish_t *msg,
nas_establish_req_t *as_msg)
void *nas_establish_req_unaligned)
{
LOG_FUNC_IN;
int size = 0;
nas_establish_req_t *as_msg = (nas_establish_req_t *)nas_establish_req_unaligned;
LOG_TRACE(INFO, "EMMAS-SAP - Send AS connection establish request");
nas_message_t nas_msg;
......
......@@ -141,11 +141,11 @@ int nas_network_process_data(nas_user_t *user, int msg_id, const void *data)
case AS_CELL_INFO_CNF: {
/* Received cell information confirm */
const cell_info_cnf_t *info = &msg->msg.cell_info_cnf;
int cell_found = (info->errCode == AS_SUCCESS);
rc = nas_proc_cell_info(user, cell_found, info->tac,
info->cellID, info->rat,
info->rsrp, info->rsrq);
/* remove using pointers to fiels of the packed structure msg as it
* triggers warnings with gcc version 9 */
const cell_info_cnf_t info = msg->msg.cell_info_cnf;
int cell_found = (info.errCode == AS_SUCCESS);
rc = nas_proc_cell_info(user, cell_found, info.tac, info.cellID, info.rat, info.rsrp, info.rsrq);
break;
}
......@@ -157,12 +157,12 @@ int nas_network_process_data(nas_user_t *user, int msg_id, const void *data)
case AS_NAS_ESTABLISH_CNF: {
/* Received NAS signalling connection establishment confirm */
const nas_establish_cnf_t *confirm = &msg->msg.nas_establish_cnf;
const nas_establish_cnf_t confirm = msg->msg.nas_establish_cnf;
if ( (confirm->errCode == AS_SUCCESS) ||
(confirm->errCode == AS_TERMINATED_NAS) ) {
rc = nas_proc_establish_cnf(user, confirm->nasMsg.data,
confirm->nasMsg.length);
if ( (confirm.errCode == AS_SUCCESS) ||
(confirm.errCode == AS_TERMINATED_NAS) ) {
rc = nas_proc_establish_cnf(user, confirm.nasMsg.data,
confirm.nasMsg.length);
} else {
LOG_TRACE(WARNING, "NET-MAIN - "
"Initial NAS message not delivered");
......@@ -191,10 +191,10 @@ int nas_network_process_data(nas_user_t *user, int msg_id, const void *data)
break;
case AS_DL_INFO_TRANSFER_IND: {
const dl_info_transfer_ind_t *info = &msg->msg.dl_info_transfer_ind;
const dl_info_transfer_ind_t info = msg->msg.dl_info_transfer_ind;
/* Received downlink data transfer indication */
rc = nas_proc_dl_transfer_ind(user, info->nasMsg.data,
info->nasMsg.length);
rc = nas_proc_dl_transfer_ind(user, info.nasMsg.data,
info.nasMsg.length);
break;
}
......
......@@ -74,6 +74,12 @@ class gtpEndPoint {
int ipVersion;
map<int,teidData_t> ue2te_mapping;
map<int,rntiData_t> te2ue_mapping;
// we use the same port number for source and destination address
// this allow using non standard gtp port number (different from 2152)
// and so, for example tu run 4G and 5G cores on one system
tcp_udp_port_t get_dstport() {
return (tcp_udp_port_t)atol(addr.destinationService);
}
};
class gtpEndPoints {
......@@ -99,6 +105,8 @@ int legacyInstanceMapping=0;
#define compatInst(a) ((a)==0 || (a)==INSTANCE_DEFAULT?legacyInstanceMapping:a)
#define GTPV1U_HEADER_SIZE (8)
static int gtpv1uCreateAndSendMsg(int h, uint32_t peerIp, uint16_t peerPort, teid_t teid, uint8_t *Msg,int msgLen,
bool seqNumFlag, bool npduNumFlag, bool extHdrFlag, int seqNum, int npduNum, int extHdrType) {
AssertFatal(extHdrFlag==false,"Not developped");
......@@ -299,7 +307,6 @@ static int udpServerSocket(openAddr_s addr) {
LOG_E(GTPU,"getaddrinfo error: %s\n", gai_strerror(status));
return -1;
}
int sockfd=-1;
// loop through all the results and bind to the first we can
......@@ -459,17 +466,18 @@ int ocp_gtpv1u_create_s1u_tunnel(instance_t instance,
create_tunnel_req->rnti,
create_tunnel_req->num_tunnels,
create_tunnel_req->sgw_S1u_teid[0]);
tcp_udp_port_t dstport=globGtp.instances[compatInst(instance)].get_dstport();
for (int i = 0; i < create_tunnel_req->num_tunnels; i++) {
AssertFatal(create_tunnel_req->eps_bearer_id[i] > 4,
"From legacy code not clear, seems impossible (bearer=%d)\n",
create_tunnel_req->eps_bearer_id[i]);
int incoming_rb_id=create_tunnel_req->eps_bearer_id[i]-4;
teid_t teid=newGtpuCreateTunnel(compatInst(instance), create_tunnel_req->rnti,
incoming_rb_id,
create_tunnel_req->eps_bearer_id[i],
create_tunnel_req->sgw_S1u_teid[i],
create_tunnel_req->sgw_addr[i], 2152,
create_tunnel_req->sgw_addr[i], dstport,
pdcp_data_req);
create_tunnel_resp->status=0;
create_tunnel_resp->rnti=create_tunnel_req->rnti;
......@@ -525,13 +533,13 @@ int gtpv1u_create_ngu_tunnel( const instance_t instance,
create_tunnel_req->rnti,
create_tunnel_req->num_tunnels,
create_tunnel_req->upf_NGu_teid[0]);
tcp_udp_port_t dstport=globGtp.instances[compatInst(instance)].get_dstport();
for (int i = 0; i < create_tunnel_req->num_tunnels; i++) {
teid_t teid=newGtpuCreateTunnel(compatInst(instance), create_tunnel_req->rnti,
create_tunnel_req->incoming_rb_id[i],
create_tunnel_req->pdusession_id[i],
create_tunnel_req->upf_NGu_teid[i],
create_tunnel_req->upf_addr[i], 2152,
create_tunnel_req->upf_addr[i], dstport,
pdcp_data_req);
create_tunnel_resp->status=0;
create_tunnel_resp->rnti=create_tunnel_req->rnti;
......@@ -869,6 +877,7 @@ void *ocp_gtpv1uTask(void *args) {
// to be dev: should be removed, to use API
strcpy(addr.originHost, GTPV1U_ENB_S1_REQ(message_p).addrStr);
strcpy(addr.originService, GTPV1U_ENB_S1_REQ(message_p).portStr);
strcpy(addr.destinationService,addr.originService);
AssertFatal((legacyInstanceMapping=ocp_gtpv1Init(addr))!=0,"Instance 0 reserved for legacy\n");
break;
......@@ -876,6 +885,7 @@ void *ocp_gtpv1uTask(void *args) {
// to be dev: should be removed, to use API
strcpy(addr.originHost, GTPV1U_ENB_S1_REQ(message_p).addrStr);
strcpy(addr.originService, GTPV1U_ENB_S1_REQ(message_p).portStr);
strcpy(addr.destinationService,addr.originService);
AssertFatal((legacyInstanceMapping=ocp_gtpv1Init(addr))!=0,"Instance 0 reserved for legacy\n");
break;
......
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