From 9a4d1e81d7bbceca9127de29395dbb2dd8520ba7 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Mon, 16 Dec 2019 16:17:35 +0100 Subject: [PATCH 01/73] nr-rlc: add function mac_rlc_get_buffer_occupancy_ind Fix also value passed to buffer_status in mac_rlc_status_ind to be aligned with 38.321 (instead of 36.321). --- openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 61 +++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index b56e8b11e9..bac62a186c 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -178,11 +178,11 @@ mac_rlc_status_resp_t mac_rlc_status_ind( if (rb != NULL) { nr_rlc_entity_buffer_status_t buf_stat; rb->set_time(rb, nr_rlc_current_time); - /* 36.321 deals with BSR values up to 3000000 bytes, after what it - * reports '> 3000000' (table 6.1.3.1-2). Passing 4000000 is thus + /* 38.321 deals with BSR values up to 81338368 bytes, after what it + * reports '> 81338368' (table 6.1.3.1-2). Passing 100000000 is thus * more than enough. */ - buf_stat = rb->buffer_status(rb, 4000000); + buf_stat = rb->buffer_status(rb, 100000000); ret.bytes_in_buffer = buf_stat.status_size + buf_stat.retx_size + buf_stat.tx_size; @@ -201,6 +201,61 @@ mac_rlc_status_resp_t mac_rlc_status_ind( return ret; } +rlc_buffer_occupancy_t mac_rlc_get_buffer_occupancy_ind( + const module_id_t module_idP, + const rnti_t rntiP, + const eNB_index_t eNB_index, + const frame_t frameP, + const sub_frame_t subframeP, + const eNB_flag_t enb_flagP, + const logical_chan_id_t channel_idP) +{ + nr_rlc_ue_t *ue; + rlc_buffer_occupancy_t ret; + nr_rlc_entity_t *rb; + + if (enb_flagP) { + LOG_E(RLC, "Tx mac_rlc_get_buffer_occupancy_ind function is not implemented for eNB LcId=%u\n", channel_idP); + exit(1); + } + + /* TODO: handle time a bit more properly */ + if (nr_rlc_current_time_last_frame != frameP || + nr_rlc_current_time_last_subframe != subframeP) { + nr_rlc_current_time++; + nr_rlc_current_time_last_frame = frameP; + nr_rlc_current_time_last_subframe = subframeP; + } + + nr_rlc_manager_lock(nr_rlc_ue_manager); + ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); + + switch (channel_idP) { + case 1 ... 2: rb = ue->srb[channel_idP - 1]; break; + case 3 ... 7: rb = ue->drb[channel_idP - 3]; break; + default: rb = NULL; break; + } + + if (rb != NULL) { + nr_rlc_entity_buffer_status_t buf_stat; + rb->set_time(rb, nr_rlc_current_time); + /* 38.321 deals with BSR values up to 81338368 bytes, after what it + * reports '> 81338368' (table 6.1.3.1-2). Passing 100000000 is thus + * more than enough. + */ + buf_stat = rb->buffer_status(rb, 100000000); + ret = buf_stat.status_size + + buf_stat.retx_size + + buf_stat.tx_size; + } else { + ret = 0; + } + + nr_rlc_manager_unlock(nr_rlc_ue_manager); + + return ret; +} + int oai_emulation; rlc_op_status_t rlc_data_req (const protocol_ctxt_t *const ctxt_pP, From 35fda01e862bc639c143c1d3600ad9ee940b0e77 Mon Sep 17 00:00:00 2001 From: Cedric Roux Date: Mon, 16 Dec 2019 16:19:23 +0100 Subject: [PATCH 02/73] nr-rlc: fix some compilation warnings --- openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index bac62a186c..2d51e5c7f0 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -276,7 +276,7 @@ rlc_op_status_t rlc_data_req (const protocol_ctxt_t *const ctxt_pP, nr_rlc_ue_t *ue; nr_rlc_entity_t *rb; - LOG_D(RLC, "%s rnti %d srb_flag %d rb_id %d mui %d confirm %d sdu_size %d MBMS_flag %d\n", + LOG_D(RLC, "%s rnti %d srb_flag %d rb_id %ld mui %d confirm %d sdu_size %d MBMS_flag %d\n", __FUNCTION__, rnti, srb_flagP, rb_idP, muiP, confirmP, sdu_sizeP, MBMS_flagP); @@ -879,24 +879,24 @@ rlc_op_status_t rrc_rlc_config_req ( } if ((srb_flagP && !(rb_idP >= 1 && rb_idP <= 2)) || (!srb_flagP && !(rb_idP >= 1 && rb_idP <= 5))) { - LOG_E(RLC, "%s:%d:%s: bad rb_id (%d) (is_srb %d)\n", __FILE__, __LINE__, __FUNCTION__, rb_idP, srb_flagP); + LOG_E(RLC, "%s:%d:%s: bad rb_id (%ld) (is_srb %d)\n", __FILE__, __LINE__, __FUNCTION__, rb_idP, srb_flagP); exit(1); } nr_rlc_manager_lock(nr_rlc_ue_manager); - LOG_D(RLC, "%s:%d:%s: remove rb %d (is_srb %d) for UE %d\n", __FILE__, __LINE__, __FUNCTION__, rb_idP, srb_flagP, ctxt_pP->rnti); + LOG_D(RLC, "%s:%d:%s: remove rb %ld (is_srb %d) for UE %d\n", __FILE__, __LINE__, __FUNCTION__, rb_idP, srb_flagP, ctxt_pP->rnti); ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, ctxt_pP->rnti); if (srb_flagP) { if (ue->srb[rb_idP-1] != NULL) { ue->srb[rb_idP-1]->delete(ue->srb[rb_idP-1]); ue->srb[rb_idP-1] = NULL; } else - LOG_W(RLC, "removing non allocated SRB %d, do nothing\n", rb_idP); + LOG_W(RLC, "removing non allocated SRB %ld, do nothing\n", rb_idP); } else { if (ue->drb[rb_idP-1] != NULL) { ue->drb[rb_idP-1]->delete(ue->drb[rb_idP-1]); ue->drb[rb_idP-1] = NULL; } else - LOG_W(RLC, "removing non allocated DRB %d, do nothing\n", rb_idP); + LOG_W(RLC, "removing non allocated DRB %ld, do nothing\n", rb_idP); } /* remove UE if it has no more RB configured */ for (i = 0; i < 2; i++) From 5b5a25a93274c5f5cd54f0385eff5cc9f61ca157 Mon Sep 17 00:00:00 2001 From: matzakos Date: Mon, 20 Jan 2020 17:55:16 +0100 Subject: [PATCH 03/73] nr-ip noS1 uplink integration (testing with RFSIMULATOR only): Uplink IP packets received at the gNB and reaching at pdcp layer. Asserion error at pdcp_fifo_flush_sdus when trying to write on the nas socket --- executables/nr-uesoftmodem.c | 1 + openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c | 15 +- .../NR_UE_TRANSPORT/nr_transport_proto_ue.h | 3 +- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 58 +- openair1/SCHED_NR/fapi_nr_l1.h | 2 + openair1/SCHED_NR/phy_procedures_nr_gNB.c | 71 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 10 +- openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 1 + openair2/LAYER2/NR_MAC_UE/mac_proto.h | 4 + openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 620 ++++++++++++++++++ .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 208 ++++++ openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 11 + openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c | 1 + openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 6 +- openair2/NR_PHY_INTERFACE/NR_IF_Module.c | 6 +- 15 files changed, 975 insertions(+), 42 deletions(-) diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index 7e2ffebb35..0438e4df21 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -124,6 +124,7 @@ int threequarter_fs=0; uint32_t downlink_frequency[MAX_NUM_CCs][4]; int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; +//int32_t uplink_counter = 0; extern int16_t nr_dlsch_demod_shift; diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c index db0c601b25..1d3e62714b 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -593,16 +593,16 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, p_procTime); if (check_crc((uint8_t*)llrProcBuf,length_dec,harq_process->F,crc_type)) { - #ifdef PRINT_CRC_CHECK + //#ifdef PRINT_CRC_CHECK //if (prnt_crc_cnt % 10 == 0) LOG_I(PHY, "Segment %d CRC OK\n",r); - #endif + //#endif ret = no_iteration_ldpc; } else { - #ifdef PRINT_CRC_CHECK + //#ifdef PRINT_CRC_CHECK //if (prnt_crc_cnt%10 == 0) LOG_I(PHY, "CRC NOK\n"); - #endif + //#endif ret = ulsch->max_ldpc_iterations + 1; } @@ -719,6 +719,13 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, } + LOG_I(PHY, "output encoder: \n"); + for (i = 0; i < harq_process->TBS / 8; i++) { + //harq_process_ul_ue->a[i] = (unsigned char) rand(); + //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); + printf("0x%02x",harq_process->b[i]); + } + ulsch->last_iteration_cnt = ret; return(ret); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h index 7559115a29..513ce6cc20 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1076,8 +1076,9 @@ void nr_pusch_codeword_scrambling(uint8_t *in, - transform precoding */ -void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, +uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, unsigned char harq_pid, + uint8_t frame, uint8_t slot, uint8_t thread_id, int gNB_id); diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index d2dbd6fef2..a5c747bbba 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -41,10 +41,13 @@ #include "PHY/NR_TRANSPORT/nr_sch_dmrs.h" #include "PHY/defs_nr_common.h" #include "PHY/TOOLS/tools_defs.h" +#include "executables/nr-softmodem.h" //#define DEBUG_SCFDMA //#define DEBUG_PUSCH_MAPPING +//extern int32_t uplink_counter; + void nr_pusch_codeword_scrambling(uint8_t *in, uint32_t size, uint32_t Nid, @@ -84,8 +87,9 @@ void nr_pusch_codeword_scrambling(uint8_t *in, } -void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, +uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, unsigned char harq_pid, + uint8_t frame, uint8_t slot, uint8_t thread_id, int gNB_id) { @@ -104,11 +108,13 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, int ap, start_symbol, Nid_cell, i; int sample_offsetF, N_RE_prime, N_PRB_oh; uint16_t n_rnti; + uint8_t data_existing =0; NR_UE_ULSCH_t *ulsch_ue; NR_UL_UE_HARQ_t *harq_process_ul_ue; NR_DL_FRAME_PARMS *frame_parms = &UE->frame_parms; NR_UE_PUSCH *pusch_ue = UE->pusch_vars[thread_id][gNB_id]; + uint8_t ulsch_input_buffer[MAX_ULSCH_PAYLOAD_BYTES]; num_of_codewords = 1; // tmp assumption length_dmrs = 1; @@ -141,17 +147,41 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, 0, harq_process_ul_ue->Nl); + uint8_t access_mode = SCHEDULED_ACCESS; + //-----------------------------------------------------// // to be removed later when MAC is ready if (harq_process_ul_ue != NULL){ - for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { - harq_process_ul_ue->a[i] = (unsigned char) rand(); - //printf("input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); - } + + if (IS_SOFTMODEM_NOS1){ + data_existing = nr_ue_get_sdu(UE->Mod_id, UE->CC_id, frame, + slot, 0, ulsch_input_buffer, harq_process_ul_ue->TBS/8, &access_mode); + if(data_existing){ + //harq_process_ul_ue->a = (unsigned char*)calloc(harq_process_ul_ue->TBS/8, sizeof(unsigned char)); + memcpy(harq_process_ul_ue->a, ulsch_input_buffer, harq_process_ul_ue->TBS/8); + LOG_I(PHY, "input encoder: \n"); + for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { + //harq_process_ul_ue->a[i] = (unsigned char) rand(); + //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); + //printf("0x%02x",harq_process_ul_ue->a[i]); + printf("0x%02x",harq_process_ul_ue->b[i]); + } + } + } + //else if(uplink_counter == 0){ //if(!IS_SOFTMODEM_NOS1){ + else{ + LOG_E(PHY, "Random data to be tranmsitted: \n"); + for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { + harq_process_ul_ue->a[i] = (unsigned char) rand(); + //printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); + } + data_existing = 1; + //uplink_counter++; + } } else { LOG_E(PHY, "[phy_procedures_nrUE_TX] harq_process_ul_ue is NULL !!\n"); - return; + return 0; } //-----------------------------------------------------// @@ -159,6 +189,8 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, /////////////////////////ULSCH coding///////////////////////// /////////// + + //if(data_existing){ nr_ulsch_encoding(ulsch_ue, frame_parms, harq_pid); /////////// @@ -203,8 +235,10 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, //////////////////////////////////////////////////////////////////////// + //} } + //if(data_existing){ start_symbol = 14 - harq_process_ul_ue->number_of_symbols; /////////////////////////DMRS Modulation///////////////////////// @@ -335,10 +369,13 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, } } + //} + /////////// //////////////////////////////////////////////////////////////////////// - return; + LOG_I(PHY, "Is data existing ?: %d \n", data_existing); + return data_existing; } @@ -369,6 +406,13 @@ uint8_t nr_ue_pusch_common_procedures(PHY_VARS_NR_UE *UE, if (tx_offset < 0) tx_offset += frame_parms->samples_per_frame; + // clear the transmit data array for the current subframe + /*for (int aa=0; aaframe_parms.nb_antennas_tx; aa++) { + memset(&UE->common_vars.txdata[aa][tx_offset],0,UE->frame_parms.samples_per_slot*sizeof(int32_t)); + //memset(&UE->common_vars.txdataF[aa][tx_offset],0,UE->frame_parms.samples_per_slot*sizeof(int32_t)); + }*/ + + txdata = UE->common_vars.txdata; txdataF = UE->common_vars.txdataF; diff --git a/openair1/SCHED_NR/fapi_nr_l1.h b/openair1/SCHED_NR/fapi_nr_l1.h index 51169660bf..4a4aeb796b 100644 --- a/openair1/SCHED_NR/fapi_nr_l1.h +++ b/openair1/SCHED_NR/fapi_nr_l1.h @@ -46,3 +46,5 @@ void handle_nr_nfapi_dlsch_pdu(PHY_VARS_gNB *gNB,int frame,int slot, uint8_t *sdu); void nr_fill_rx_indication(PHY_VARS_gNB *gNB, int frame, int slot_rx, int UE_id, uint8_t harq_pid); + +void nr_fill_crc_indication (PHY_VARS_gNB *gNB, int UE_id, int frame, int slot_rx, uint8_t crc_flag); diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index a665a14112..a849e3c2d9 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -260,8 +260,12 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int UE_id if (ret > gNB->ulsch[UE_id][0]->max_ldpc_iterations) LOG_I(PHY, "ULSCH in error\n"); - else - LOG_I(PHY, "ULSCH received ok\n"); + //gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b + else if(gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b!=NULL){ + LOG_I(PHY, "ULSCH received ok, number of iterations: %d \n", ret); + nr_fill_crc_indication (gNB, UE_id, frame_rx, slot_rx, 0); + nr_fill_rx_indication(gNB, frame_rx, slot_rx, UE_id, harq_pid); + } } @@ -272,25 +276,28 @@ void nr_fill_rx_indication(PHY_VARS_gNB *gNB, int frame, int slot_rx, int UE_id, // [hna] TO BE CLEANED // -------------------- - // nfapi_rx_indication_pdu_t *pdu; + nfapi_rx_indication_pdu_t *pdu; int timing_advance_update; int sync_pos; - // pthread_mutex_lock(&gNB->UL_INFO_mutex); + NR_gNB_ULSCH_t *ulsch = gNB->ulsch[UE_id][0]; + NR_UL_gNB_HARQ_t *harq_process = ulsch->harq_processes[harq_pid]; - // gNB->UL_INFO.rx_ind.sfn_sf = frame<<4| slot_rx; - // gNB->UL_INFO.rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG; + pthread_mutex_lock(&gNB->UL_INFO_mutex); - // pdu = &gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list[gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus]; + gNB->UL_INFO.rx_ind.sfn_sf = frame<<4| slot_rx; + gNB->UL_INFO.rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG; - // pdu->rx_ue_information.handle = gNB->ulsch[UE_id+1][0]->handle; - // pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG; - // pdu->rx_ue_information.rnti = gNB->ulsch[UE_id+1][0]->rnti; - // pdu->rx_indication_rel8.tl.tag = NFAPI_RX_INDICATION_REL8_TAG; - // pdu->rx_indication_rel8.length = gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->TBS>>3; - // pdu->rx_indication_rel8.offset = 1; // DJP - I dont understand - but broken unless 1 ???? 0; // filled in at the end of the UL_INFO formation - // pdu->data = gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b; + pdu = &gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list[gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus]; + + //pdu->rx_ue_information.handle = gNB->ulsch[UE_id+1][0]->handle; + pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG; + pdu->rx_ue_information.rnti = gNB->ulsch[UE_id][0]->rnti; + pdu->rx_indication_rel8.tl.tag = NFAPI_RX_INDICATION_REL8_TAG; + pdu->rx_indication_rel8.length = gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->TBS>>3; + pdu->rx_indication_rel8.offset = 1; // DJP - I dont understand - but broken unless 1 ???? 0; // filled in at the end of the UL_INFO formation + pdu->data = harq_process->b;//gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b; // estimate timing advance for MAC sync_pos = nr_est_timing_advance_pusch(gNB, UE_id); timing_advance_update = sync_pos; // - gNB->frame_parms.nb_prefix_samples/4; //to check @@ -314,23 +321,40 @@ void nr_fill_rx_indication(PHY_VARS_gNB *gNB, int frame, int slot_rx, int UE_id, if (timing_advance_update < 0) timing_advance_update = 0; if (timing_advance_update > 63) timing_advance_update = 63; - // pdu->rx_indication_rel8.timing_advance = timing_advance_update; + pdu->rx_indication_rel8.timing_advance = timing_advance_update; // estimate UL_CQI for MAC (from antenna port 0 only) - // int SNRtimes10 = dB_fixed_times10(gNB->pusch_vars[UE_id]->ulsch_power[0]) - 300;//(10*gNB->measurements.n0_power_dB[0]); + int SNRtimes10 = dB_fixed_times10(gNB->pusch_vars[UE_id]->ulsch_power[0]) - 300;//(10*gNB->measurements.n0_power_dB[0]); - // if (SNRtimes10 < -640) pdu->rx_indication_rel8.ul_cqi=0; - // else if (SNRtimes10 > 635) pdu->rx_indication_rel8.ul_cqi=255; - // else pdu->rx_indication_rel8.ul_cqi=(640+SNRtimes10)/5; + if (SNRtimes10 < -640) pdu->rx_indication_rel8.ul_cqi=0; + else if (SNRtimes10 > 635) pdu->rx_indication_rel8.ul_cqi=255; + else pdu->rx_indication_rel8.ul_cqi=(640+SNRtimes10)/5; // LOG_D(PHY,"[PUSCH %d] Frame %d Subframe %d Filling RX_indication with SNR %d (%d), timing_advance %d (update %d)\n", // harq_pid,frame,slot_rx,SNRtimes10,pdu->rx_indication_rel8.ul_cqi,pdu->rx_indication_rel8.timing_advance, // timing_advance_update); - // gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus++; - // gNB->UL_INFO.rx_ind.sfn_sf = frame<<4 | slot_rx; + gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus++; + gNB->UL_INFO.rx_ind.sfn_sf = frame<<4 | slot_rx; - // pthread_mutex_unlock(&gNB->UL_INFO_mutex); + pthread_mutex_unlock(&gNB->UL_INFO_mutex); +} + +void nr_fill_crc_indication (PHY_VARS_gNB *gNB, int UE_id, int frame, int slot_rx, uint8_t crc_flag) { + pthread_mutex_lock(&gNB->UL_INFO_mutex); + nfapi_crc_indication_pdu_t *pdu = &gNB->UL_INFO. crc_ind.crc_indication_body.crc_pdu_list[gNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs]; + gNB->UL_INFO.crc_ind.sfn_sf = frame<<4 | slot_rx; + gNB->UL_INFO.crc_ind.header.message_id = NFAPI_CRC_INDICATION; + gNB->UL_INFO.crc_ind.crc_indication_body.tl.tag = NFAPI_CRC_INDICATION_BODY_TAG; + pdu->instance_length = 0; // don't know what to do with this + // pdu->rx_ue_information.handle = handle; + pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG; + pdu->rx_ue_information.rnti = gNB->ulsch[UE_id][0]->rnti; + pdu->crc_indication_rel8.tl.tag = NFAPI_CRC_INDICATION_REL8_TAG; + pdu->crc_indication_rel8.crc_flag = crc_flag; + gNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs++; + //LOG_D(PHY, "%s() rnti:%04x crcs:%d crc_flag:%d\n", __FUNCTION__, pdu->rx_ue_information.rnti, eNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs, crc_flag); + pthread_mutex_unlock(&gNB->UL_INFO_mutex); } @@ -382,7 +406,8 @@ void phy_procedures_gNB_uespec_RX(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx) //LOG_M("rxdataF_comp.m","rxF_comp",gNB->pusch_vars[UE_id]->rxdataF_comp[0],6900,1,1); //LOG_M("rxdataF_ext.m","rxF_ext",gNB->pusch_vars[UE_id]->rxdataF_ext[0],6900,1,1); nr_ulsch_procedures(gNB, frame_rx, slot_rx, UE_id, harq_pid); - nr_fill_rx_indication(gNB, frame_rx, slot_rx, UE_id, harq_pid); // indicate SDU to MAC + /*nr_fill_crc_indication (gNB, UE_id, frame_rx, slot_rx, 1); + nr_fill_rx_indication(gNB, frame_rx, slot_rx, UE_id, harq_pid); // indicate SDU to MAC*/ } } } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 60378d81fc..96c4e837ab 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2481,9 +2481,11 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, #endif uint8_t harq_pid = 0; //temporary implementation + uint8_t data_existing = 0; - nr_ue_ulsch_procedures(ue, + data_existing = nr_ue_ulsch_procedures(ue, harq_pid, + frame_tx, slot_tx, thread_id, gNB_id); @@ -2498,13 +2500,15 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, } // UE_mode==PUSCH */ - - nr_ue_pusch_common_procedures(ue, + //if(data_existing){ + LOG_I(PHY, "Sending data \n"); + nr_ue_pusch_common_procedures(ue, harq_pid, slot_tx, thread_id, gNB_id, &ue->frame_parms); + //} diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index e3b74d388c..af7aa43fcc 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -945,6 +945,7 @@ rx_sdu(const module_id_t enb_mod_idP, stop_meas(&mac->rx_ulsch_sdu); } + //----------------------------------------------------------------------------- /* * Return the BSR table index corresponding to the number of bytes in input diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 98389ddcfd..c33d624469 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -136,5 +136,9 @@ int8_t nr_ue_process_dlsch(module_id_t module_id, int cc_id, uint8_t gNB_index, void nr_ue_send_sdu(module_id_t module_idP, uint8_t CC_id, frame_t frameP, sub_frame_t subframeP, uint8_t * sdu, uint16_t sdu_len, uint8_t eNB_index); +uint8_t nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, + sub_frame_t subframe, uint8_t eNB_index, + uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode); + #endif /** @}*/ diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index ef94d5db7e..c0c8a9ec24 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -37,6 +37,8 @@ #include "PHY/defs_nr_UE.h" #include "common/utils/LOG/log.h" #include "openair2/LAYER2/MAC/mac.h" +#include "openair2/LAYER2/RLC/rlc.h" +#include "SIMULATION/TOOLS/sim.h" // for taus #include #include @@ -2317,7 +2319,287 @@ unsigned char *parse_header(unsigned char *mac_header, return (mac_header_ptr); } +unsigned char +generate_ulsch_header(uint8_t *mac_header, + uint8_t num_sdus, + uint8_t short_padding, + uint16_t *sdu_lengths, + uint8_t *sdu_lcids, + POWER_HEADROOM_CMD *power_headroom, + uint16_t *crnti, + BSR_SHORT *truncated_bsr, + BSR_SHORT *short_bsr, + BSR_LONG *long_bsr, unsigned short post_padding) { + SCH_SUBHEADER_FIXED *mac_header_ptr = + (SCH_SUBHEADER_FIXED *) mac_header; + unsigned char first_element = 0, last_size = 0, i; + unsigned char mac_header_control_elements[16], *ce_ptr; + LOG_D(MAC, "[UE] Generate ULSCH : num_sdus %d\n", num_sdus); +#ifdef DEBUG_HEADER_PARSING + for (i = 0; i < num_sdus; i++) { + LOG_T(MAC, "[UE] sdu %d : lcid %d length %d", i, sdu_lcids[i], + sdu_lengths[i]); + } + + LOG_T(MAC, "\n"); +#endif + ce_ptr = &mac_header_control_elements[0]; + + if ((short_padding == 1) || (short_padding == 2)) { + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + first_element = 1; + last_size = 1; + } + + if (short_padding == 2) { + mac_header_ptr->E = 1; + mac_header_ptr++; + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + last_size = 1; + } + + if (power_headroom) { + if (first_element > 0) { + mac_header_ptr->E = 1; + mac_header_ptr++; + } else { + first_element = 1; + } + + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = POWER_HEADROOM; + last_size = 1; + *((POWER_HEADROOM_CMD *) ce_ptr) = (*power_headroom); + ce_ptr += sizeof(POWER_HEADROOM_CMD); + LOG_D(MAC, "phr header size %zu\n", sizeof(POWER_HEADROOM_CMD)); + } + + if (crnti) { +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] CRNTI : %x (first_element %d)\n", *crnti, + first_element); +#endif + + if (first_element > 0) { + mac_header_ptr->E = 1; + mac_header_ptr++; + } else { + first_element = 1; + } + + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = CRNTI; + last_size = 1; + *((uint16_t *) ce_ptr) = (*crnti); + ce_ptr += sizeof(uint16_t); + // printf("offset %d\n",ce_ptr-mac_header_control_elements); + } + + if (truncated_bsr) { + if (first_element > 0) { + mac_header_ptr->E = 1; + /* + printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); + */ + mac_header_ptr++; + } else { + first_element = 1; + } + +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] Scheduler Truncated BSR Header\n"); +#endif + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = TRUNCATED_BSR; + last_size = 1; + *((BSR_TRUNCATED *) ce_ptr) = (*truncated_bsr); + ce_ptr += sizeof(BSR_TRUNCATED); + // printf("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); + } else if (short_bsr) { + if (first_element > 0) { + mac_header_ptr->E = 1; + /* + printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); + */ + mac_header_ptr++; + } else { + first_element = 1; + } + +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] Scheduler SHORT BSR Header\n"); +#endif + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_BSR; + last_size = 1; + *((BSR_SHORT *) ce_ptr) = (*short_bsr); + ce_ptr += sizeof(BSR_SHORT); + // printf("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); + } else if (long_bsr) { + if (first_element > 0) { + mac_header_ptr->E = 1; + /* + printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); + */ + mac_header_ptr++; + } else { + first_element = 1; + } + +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] Scheduler Long BSR Header\n"); +#endif + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = LONG_BSR; + last_size = 1; + *(ce_ptr) = + (long_bsr-> + Buffer_size0 << 2) | ((long_bsr->Buffer_size1 & 0x30) >> 4); + *(ce_ptr + 1) = + ((long_bsr->Buffer_size1 & 0x0F) << 4) | ((long_bsr-> + Buffer_size2 & 0x3C) + >> 2); + *(ce_ptr + 2) = + ((long_bsr-> + Buffer_size2 & 0x03) << 2) | (long_bsr->Buffer_size3 & 0x3F); + ce_ptr += BSR_LONG_SIZE; + // printf("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); + } + + // printf("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); + + for (i = 0; i < num_sdus; i++) { +#ifdef DEBUG_HEADER_PARSING + LOG_T(MAC, "[UE] sdu subheader %d (lcid %d, %d bytes)\n", i, + sdu_lcids[i], sdu_lengths[i]); +#endif + + if ((i == (num_sdus - 1)) + && ((short_padding) || (post_padding == 0))) { + if (first_element > 0) { + mac_header_ptr->E = 1; +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] last subheader : %x (R%d,E%d,LCID%d)\n", + *(unsigned char *) mac_header_ptr, + ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->LCID); +#endif + mac_header_ptr += last_size; + } + + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = sdu_lcids[i]; + } else { + if ((first_element > 0)) { + mac_header_ptr->E = 1; +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] last subheader : %x (R%d,E%d,LCID%d)\n", + *(unsigned char *) mac_header_ptr, + ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->R, + ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E, + ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->LCID); +#endif + mac_header_ptr += last_size; + // printf("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); + } else { + first_element = 1; + } + + if (sdu_lengths[i] < 128) { + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->R = 0; // 3 + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F = 0; + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->LCID = + sdu_lcids[i]; + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L = + (unsigned char) sdu_lengths[i]; + last_size = 2; +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] short sdu\n"); + LOG_T(MAC, + "[UE] last subheader : %x (R%d,E%d,LCID%d,F%d,L%d)\n", + ((uint16_t *) mac_header_ptr)[0], + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->R, + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->E, + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->LCID, + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F, + ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L); +#endif + } else { + ((SCH_SUBHEADER_LONG *) mac_header_ptr)->R = 0; + ((SCH_SUBHEADER_LONG *) mac_header_ptr)->E = 0; + ((SCH_SUBHEADER_LONG *) mac_header_ptr)->F = 1; + ((SCH_SUBHEADER_LONG *) mac_header_ptr)->LCID = + sdu_lcids[i]; + ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB = + ((unsigned short) sdu_lengths[i] >> 8) & 0x7f; + ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB = + (unsigned short) sdu_lengths[i] & 0xff; + ((SCH_SUBHEADER_LONG *) mac_header_ptr)->padding = 0x00; + last_size = 3; +#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] long sdu\n"); +#endif + } + } + } + + if (post_padding > 0) { // we have lots of padding at the end of the packet + mac_header_ptr->E = 1; + mac_header_ptr += last_size; + // add a padding element + mac_header_ptr->R = 0; + mac_header_ptr->E = 0; + mac_header_ptr->LCID = SHORT_PADDING; + mac_header_ptr++; + } else { // no end of packet padding + // last SDU subhead is of fixed type (sdu length implicitly to be computed at UE) + mac_header_ptr++; + //mac_header_ptr=last_size; // FIXME: should be ++ + } + + if ((ce_ptr - mac_header_control_elements) > 0) { + memcpy((void *) mac_header_ptr, mac_header_control_elements, + ce_ptr - mac_header_control_elements); + mac_header_ptr += + (unsigned char) (ce_ptr - mac_header_control_elements); + } + +#ifdef DEBUG_HEADER_PARSING + LOG_T(MAC, " [UE] header : "); + + for (i = 0; i < ((unsigned char *) mac_header_ptr - mac_header); i++) { + LOG_T(MAC, "%2x.", mac_header[i]); + } + + LOG_T(MAC, "\n"); +#endif + return ((unsigned char *) mac_header_ptr - mac_header); +} + + +/* LTE based function to be substituted once NR version is ready */ //------------------------------------------------------------------------------ void nr_ue_send_sdu(module_id_t module_idP, @@ -2413,5 +2695,343 @@ nr_ue_send_sdu(module_id_t module_idP, } +/* LTE based function to be substituted once NR version is ready */ +uint8_t +nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, + sub_frame_t subframe, uint8_t eNB_index, + uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) + +{ + uint8_t total_rlc_pdu_header_len = 0, rlc_pdu_header_len_last = 0; + uint16_t buflen_remain = 0; + uint8_t bsr_len = 0, bsr_ce_len = 0, bsr_header_len = 0; + uint8_t phr_header_len = 0, phr_ce_len = 0, phr_len = 0; + uint8_t lcid = 0, lcid_rlc_pdu_count = 0; + boolean_t is_lcid_processed = FALSE; + boolean_t is_all_lcid_processed = FALSE; + uint16_t sdu_lengths[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + uint8_t sdu_lcids[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + uint8_t payload_offset = 0, num_sdus = 0; + uint8_t ulsch_buff[MAX_ULSCH_PAYLOAD_BYTES]; + uint16_t sdu_length_total = 0; + BSR_SHORT bsr_short, bsr_truncated; + BSR_LONG bsr_long; + BSR_SHORT *bsr_s = &bsr_short; + BSR_LONG *bsr_l = &bsr_long; + BSR_SHORT *bsr_t = &bsr_truncated; + POWER_HEADROOM_CMD phr; + POWER_HEADROOM_CMD *phr_p = &phr; + unsigned short short_padding = 0, post_padding = 0, padding_len = 0; + int j; // used for padding + // Compute header length + int lcg_id = 0; + int lcg_id_bsr_trunc = 0; + int highest_priority = 16; + int num_lcg_id_with_data = 0; + rlc_buffer_occupancy_t lcid_buffer_occupancy_old = + 0, lcid_buffer_occupancy_new = 0; + + NR_UE_MAC_INST_t *nr_ue_mac_inst = get_mac_inst(0); + + + LOG_D(MAC, + "[UE %d] MAC PROCESS UL TRANSPORT BLOCK at frame%d subframe %d TBS=%d\n", + module_idP, frameP, subframe, buflen); + AssertFatal(CC_id == 0, + "Transmission on secondary CCs is not supported yet\n"); + + bsr_header_len = 0; + phr_header_len = 0; // 1; //sizeof(SCH_SUBHEADER_FIXED); + + rlc_buffer_occupancy_t buffer_occupancy = mac_rlc_get_buffer_occupancy_ind( module_idP, 0x1234, eNB_index, frameP, subframe,ENB_FLAG_NO,DTCH); + + // Check for DCCH first + // TO DO: Multiplex in the order defined by the logical channel prioritization + for (lcid = DTCH; + (lcid < MAX_NUM_LCID) && (is_all_lcid_processed == FALSE); lcid++) { + lcid_buffer_occupancy_old = mac_rlc_get_buffer_occupancy_ind( module_idP, 0x1234, eNB_index, frameP, subframe,ENB_FLAG_NO,lcid); + if (lcid_buffer_occupancy_old > 0) { + lcid_rlc_pdu_count = 0; + is_lcid_processed = FALSE; + + lcid_buffer_occupancy_new = lcid_buffer_occupancy_old; + + + //Multiplex all available DCCH RLC PDUs considering to multiplex the last PDU each time for maximize the data + //Adjust at the end of the loop + while ((!is_lcid_processed) && (lcid_buffer_occupancy_new) + && (bsr_len + phr_len + total_rlc_pdu_header_len + + sdu_length_total + MIN_MAC_HDR_RLC_SIZE <= buflen)) { + + buflen_remain = + buflen - (bsr_len + phr_len + + total_rlc_pdu_header_len + sdu_length_total + + 1); + LOG_I(MAC, + "[UE %d] Frame %d : UL-DXCH -> ULSCH, RLC %d has %d bytes to " + "send (Transport Block size %d BSR size=%d PHR=%d SDU Length Total %d , mac header len %d BSR byte before Tx=%d)\n", + module_idP, frameP, lcid, lcid_buffer_occupancy_new, + buflen, bsr_len, phr_len, sdu_length_total, + total_rlc_pdu_header_len); + + sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, + 0x1234, eNB_index, + frameP, + ENB_FLAG_NO, + MBMS_FLAG_NO, + lcid, + buflen_remain, + (char *)&ulsch_buff[sdu_length_total],0, + 0 + ); + AssertFatal(buflen_remain >= sdu_lengths[num_sdus], + "LCID=%d RLC has segmented %d bytes but MAC has max=%d\n", + lcid, sdu_lengths[num_sdus], buflen_remain); + + if (sdu_lengths[num_sdus]) { + sdu_length_total += sdu_lengths[num_sdus]; + sdu_lcids[num_sdus] = lcid; + LOG_I(MAC, + "[UE %d] TX Multiplex RLC PDU TX Got %d bytes for LcId%d\n", + module_idP, sdu_lengths[num_sdus], lcid); + + if (buflen == + (bsr_len + phr_len + total_rlc_pdu_header_len + + sdu_length_total + 1)) { + //No more remaining TBS after this PDU + //exit the function + rlc_pdu_header_len_last = 1; + is_lcid_processed = TRUE; + is_all_lcid_processed = TRUE; + } else { + rlc_pdu_header_len_last = + (sdu_lengths[num_sdus] > 128) ? 3 : 2; + + //Change to 1 byte if it does not fit in the TBS, ie last PDU + if (buflen <= + (bsr_len + phr_len + total_rlc_pdu_header_len + + rlc_pdu_header_len_last + sdu_length_total)) { + rlc_pdu_header_len_last = 1; + is_lcid_processed = TRUE; + is_all_lcid_processed = TRUE; + } + } + + //Update number of SDU + num_sdus++; + //Update total MAC Header size for RLC PDUs and save last one + total_rlc_pdu_header_len += rlc_pdu_header_len_last; + lcid_rlc_pdu_count++; + } else { + /* avoid infinite loop ... */ + is_lcid_processed = TRUE; + } + + /* Get updated BO after multiplexing this PDU */ + lcid_buffer_occupancy_new = + mac_rlc_get_buffer_occupancy_ind( module_idP, + 0x1234, + eNB_index, + frameP, + subframe, + ENB_FLAG_NO, + lcid); + is_lcid_processed = (is_lcid_processed) + || (lcid_buffer_occupancy_new <= 0); + } + + //Update Buffer remain and BSR bytes after transmission + AssertFatal(lcid_buffer_occupancy_new <= + lcid_buffer_occupancy_old, + "MAC UE Tx error : Buffer Occupancy After Tx=%d greater than before=%d BO! for LCID=%d RLC PDU nb=%d Frame %d Subrame %d\n", + lcid_buffer_occupancy_new, + lcid_buffer_occupancy_old, lcid, + lcid_rlc_pdu_count, frameP, subframe); + } + } + + + // build PHR and update the timers + /*if (phr_ce_len == sizeof(POWER_HEADROOM_CMD)) { + if(NFAPI_MODE==NFAPI_UE_STUB_PNF) { + //Substitute with a static value for the MAC layer abstraction (phy_stub mode) + phr_p->PH = 40; + } else { + phr_p->PH = get_phr_mapping(module_idP, CC_id, eNB_index); + } + + phr_p->R = 0; + LOG_D(MAC, + "[UE %d] Frame %d report PHR with mapping (%d->%d) for LCID %d\n", + module_idP, frameP, get_PHR(module_idP, CC_id, eNB_index), + phr_p->PH, POWER_HEADROOM); + update_phr(module_idP, CC_id); + } else { + phr_p = NULL; + }*/ + + + // Check BSR padding: it is done after PHR according to Logical Channel Prioritization order + // Check for max padding size, ie MAC Hdr for last RLC PDU = 1 + /* For Padding BSR: + - if the number of padding bits is equal to or larger than the size of the Short BSR plus its subheader but smaller than the size of the Long BSR plus its subheader: + - if more than one LCG has data available for transmission in the TTI where the BSR is transmitted: report Truncated BSR of the LCG with the highest priority logical channel with data available for transmission; + - else report Short BSR. + - else if the number of padding bits is equal to or larger than the size of the Long BSR plus its subheader, report Long BSR. + */ + if (sdu_length_total) { + padding_len = + buflen - (bsr_len + phr_len + total_rlc_pdu_header_len - + rlc_pdu_header_len_last + sdu_length_total + 1); + } else { + padding_len = buflen - (bsr_len + phr_len); + } + + /* if ((padding_len) && (bsr_len == 0)) { + // if the number of padding bits is equal to or larger than the size of the Long BSR plus its subheader, report Long BSR + if (padding_len >= (1 + BSR_LONG_SIZE)) { + bsr_ce_len = BSR_LONG_SIZE; + bsr_header_len = 1; + // Trigger BSR Padding + UE_mac_inst[module_idP].BSR_reporting_active |= + BSR_TRIGGER_PADDING; + } else if (padding_len >= (1 + sizeof(BSR_SHORT))) { + bsr_ce_len = sizeof(BSR_SHORT); + bsr_header_len = 1; + + if (num_lcg_id_with_data > 1) { + // REPORT TRUNCATED BSR + //Get LCGID of highest priority LCID with data + for (lcid = DCCH; lcid < MAX_NUM_LCID; lcid++) { + if (UE_mac_inst[module_idP]. + logicalChannelConfig[lcid] != NULL) { + lcg_id = + UE_mac_inst[module_idP].scheduling_info. + LCGID[lcid]; + + if ((lcg_id < MAX_NUM_LCGID) + && (UE_mac_inst[module_idP]. + scheduling_info.BSR_bytes[lcg_id]) + && + (UE_mac_inst[module_idP].logicalChannelConfig + [lcid]->ul_SpecificParameters->priority <= + highest_priority)) { + highest_priority = + UE_mac_inst[module_idP]. + logicalChannelConfig[lcid]-> + ul_SpecificParameters->priority; + lcg_id_bsr_trunc = lcg_id; + } + } + } + } else { + //Report SHORT BSR, clear bsr_t + bsr_t = NULL; + } + + // Trigger BSR Padding + UE_mac_inst[module_idP].BSR_reporting_active |= + BSR_TRIGGER_PADDING; + } + + bsr_len = bsr_header_len + bsr_ce_len; + }*/ + + //Fill BSR Infos + if (bsr_ce_len == 0) { + bsr_s = NULL; + bsr_l = NULL; + bsr_t = NULL; + } + else { + LOG_W(MAC, "BSR not null \n"); + } + + // 1-bit padding or 2-bit padding special padding subheader + // Check for max padding size, ie MAC Hdr for last RLC PDU = 1 + if (sdu_length_total) { + padding_len = + buflen - (bsr_len + phr_len + total_rlc_pdu_header_len - + rlc_pdu_header_len_last + sdu_length_total + 1); + } else { + padding_len = buflen - (bsr_len + phr_len); + } + + if (padding_len <= 2) { + short_padding = padding_len; + // only add padding header + post_padding = 0; + + //update total MAC Hdr size for RLC data + if (sdu_length_total) { + total_rlc_pdu_header_len = + total_rlc_pdu_header_len - rlc_pdu_header_len_last + 1; + rlc_pdu_header_len_last = 1; + } + } else if (sdu_length_total) { + post_padding = + buflen - (bsr_len + phr_len + total_rlc_pdu_header_len + + sdu_length_total + 1); + + // If by adding MAC Hdr for last RLC PDU the padding is 0 then set MAC Hdr for last RLC PDU = 1 and compute 1 or 2 byte padding + if (post_padding == 0) { + total_rlc_pdu_header_len -= rlc_pdu_header_len_last; + padding_len = + buflen - (bsr_len + phr_len + total_rlc_pdu_header_len + + sdu_length_total + 1); + short_padding = padding_len; + total_rlc_pdu_header_len++; + } + } else { + if (padding_len == buflen) { // nona mac pdu + *access_mode = CANCELED_ACCESS; + } + + short_padding = 0; + post_padding = + buflen - (bsr_len + phr_len + total_rlc_pdu_header_len + + sdu_length_total + 1); + } + + // Generate header + // if (num_sdus>0) { + + payload_offset = generate_ulsch_header(ulsch_buffer, // mac header + num_sdus, // num sdus + short_padding, // short pading + sdu_lengths, // sdu length + sdu_lcids, // sdu lcid + phr_p, // power headroom + NULL, // crnti + bsr_t, // truncated bsr + bsr_s, // short bsr + bsr_l, post_padding); // long_bsr + LOG_D(MAC, + "[UE %d] Generate header :bufflen %d sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d, total_rlc_pdu_header_len %d, padding %d,post_padding %d, bsr len %d, phr len %d, reminder %d \n", + module_idP, buflen, sdu_length_total, num_sdus, sdu_lengths[0], + sdu_lcids[0], payload_offset, total_rlc_pdu_header_len, + short_padding, post_padding, bsr_len, phr_len, + buflen - sdu_length_total - payload_offset); + + // cycle through SDUs and place in ulsch_buffer + if (sdu_length_total) { + memcpy(&ulsch_buffer[payload_offset], ulsch_buff, + sdu_length_total); + } + else + return 0; + + // fill remainder of DLSCH with random data + if (post_padding) { + for (j = 0; j < (buflen - sdu_length_total - payload_offset); j++) { + ulsch_buffer[payload_offset + sdu_length_total + j] = + (char) (taus() & 0xff); + } + } + return 1; + +} + + diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index ea3ee86db1..f0a8545141 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -548,3 +548,211 @@ void nr_schedule_uss_ulsch_phytest(nfapi_nr_ul_tti_request_t *UL_tti_req, //pusch_pdu->beamforming; //not used for now } } + +void +nr_rx_sdu(const module_id_t enb_mod_idP, + const int CC_idP, + const frame_t frameP, + const sub_frame_t subframeP, + const rnti_t rntiP, + uint8_t *sduP, + const uint16_t sdu_lenP, + const uint16_t timing_advance, + const uint8_t ul_cqi) +//----------------------------------------------------------------------------- +{ + int current_rnti = 0; + int UE_id = -1; + int RA_id = 0; + int old_rnti = -1; + int old_UE_id = -1; + int crnti_rx = 0; + //int harq_pid = 0; + int first_rb = 0; + unsigned char num_ce = 0; + unsigned char num_sdu = 0; + unsigned char *payload_ptr = NULL; + unsigned char rx_ces[MAX_NUM_CE]; + unsigned char rx_lcids[NB_RB_MAX]; + unsigned short rx_lengths[NB_RB_MAX]; + uint8_t lcgid = 0; + int lcgid_updated[4] = {0, 0, 0, 0}; + //eNB_MAC_INST *mac = NULL; + UE_list_t *UE_list = NULL; + rrc_eNB_ue_context_t *ue_contextP = NULL; + UE_sched_ctrl_t *UE_scheduling_control = NULL; + UE_TEMPLATE *UE_template_ptr = NULL; + /* Init */ + current_rnti = rntiP; + UE_id = 0; //find_UE_id(enb_mod_idP, current_rnti); + //mac = RC.mac[enb_mod_idP]; + //harq_pid = subframe2harqpid(&mac->common_channels[CC_idP], frameP, subframeP); + //UE_list = &mac->UE_list; + memset(rx_ces, 0, MAX_NUM_CE * sizeof(unsigned char)); + memset(rx_lcids, 0, NB_RB_MAX * sizeof(unsigned char)); + memset(rx_lengths, 0, NB_RB_MAX * sizeof(unsigned short)); + //start_meas(&mac->rx_ulsch_sdu); + + payload_ptr = parse_ulsch_header(sduP, &num_ce, &num_sdu, rx_ces, rx_lcids, rx_lengths, sdu_lenP); + + if (payload_ptr == NULL) { + LOG_E(MAC,"[eNB %d] CC_id %d ulsch header unknown lcid(rnti %x, UE_id %d)\n", + enb_mod_idP, + CC_idP, + current_rnti, + UE_id); + return; + } + + /* Control element */ + for (int i = 0; i < num_ce; i++) { + + switch (rx_ces[i]) { // implement and process PHR + CRNTI + BSR + case POWER_HEADROOM: + + break; + + case CRNTI: + break; + + case TRUNCATED_BSR: + case SHORT_BSR: + + break; + + case LONG_BSR: + + break; + + default: + LOG_E(MAC, "[eNB %d] CC_id %d Received unknown MAC header (0x%02x)\n", + enb_mod_idP, + CC_idP, + rx_ces[i]); + break; + } // end switch on control element + } // end for loop on control element + + for (int i = 0; i < num_sdu; i++) { + LOG_I(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n", + i, + rx_lcids[i], + rx_lengths[i]); + T(T_ENB_MAC_UE_UL_SDU, + T_INT(enb_mod_idP), + T_INT(CC_idP), + T_INT(current_rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(rx_lcids[i]), + T_INT(rx_lengths[i])); + T(T_ENB_MAC_UE_UL_SDU_WITH_DATA, + T_INT(enb_mod_idP), + T_INT(CC_idP), + T_INT(current_rnti), + T_INT(frameP), + T_INT(subframeP), + T_INT(rx_lcids[i]), + T_INT(rx_lengths[i]), + T_BUFFER(payload_ptr, rx_lengths[i])); + + switch (rx_lcids[i]) { + case CCCH: + + break; + + case DCCH: + case DCCH1: + + break; + + // all the DRBS + case DTCH: + default: +#if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_T(MAC, "offset: %d\n", + (unsigned char) ((unsigned char *) payload_ptr - sduP)); + + for (int j = 0; j < 32; j++) { + LOG_T(MAC, "%x ", payload_ptr[j]); + } + + LOG_T(MAC, "\n"); +#endif + + if (rx_lcids[i] < NB_RB_MAX) { + LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d\n", + enb_mod_idP, + CC_idP, + frameP, + rx_lengths[i], + UE_id, + rx_lcids[i]); + + if (UE_id != -1) { + /* Adjust buffer occupancy of the correponding logical channel group */ + LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d \n", + enb_mod_idP, + CC_idP, + frameP, + rx_lengths[i], + UE_id, + rx_lcids[i]); + + + if ((rx_lengths[i] < SCH_PAYLOAD_SIZE_MAX) && (rx_lengths[i] > 0)) { // MAX SIZE OF transport block + mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL); + } else { /* rx_length[i] Max size */ + UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1; + LOG_E(MAC, "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ", + enb_mod_idP, + CC_idP, + frameP, + rx_lcids[i], + UE_id); + } + } else { // end if (UE_id != -1) + LOG_E(MAC,"[eNB %d] CC_id %d Frame %d : received unsupported or unknown LCID %d from UE %d ", + enb_mod_idP, + CC_idP, + frameP, + rx_lcids[i], + UE_id); + } + } + + break; + } + + payload_ptr += rx_lengths[i]; + } + + /* Program ACK for PHICH */ + + /*LOG_D(MAC, "Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n", + current_rnti, + harq_pid, + first_rb); + nfapi_hi_dci0_request_t *hi_dci0_req; + uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP); + hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10]; + nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body; + nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + + hi_dci0_req_body->number_of_hi]; + memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t)); + hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE; + hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu); + hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG; + hi_dci0_pdu->hi_pdu.hi_pdu_rel8.resource_block_start = first_rb; + hi_dci0_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = 0; + hi_dci0_pdu->hi_pdu.hi_pdu_rel8.hi_value = 1; + hi_dci0_req_body->number_of_hi++; + hi_dci0_req_body->sfnsf = sfnsf_add_subframe(frameP,subframeP, 0); + hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG; + hi_dci0_req->sfn_sf = sfnsf_add_subframe(frameP,subframeP, sf_ahead_dl); + hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;*/ + + /* NN--> FK: we could either check the payload, or use a phy helper to detect a false msg3 */ + +} + diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index d56d5d28c1..95abba549a 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -145,4 +145,15 @@ void config_nr_mib(int Mod_idP, int cellBarred, int intraFreqReselection); +void +nr_rx_sdu(const module_id_t enb_mod_idP, + const int CC_idP, + const frame_t frameP, + const sub_frame_t subframeP, + const rnti_t rntiP, + uint8_t *sduP, + const uint16_t sdu_lenP, + const uint16_t timing_advance, + const uint8_t ul_cqi); + #endif /*__LAYER2_NR_MAC_PROTO_H__*/ diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c index 9e873379b1..260e7c3ba3 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c @@ -128,6 +128,7 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) { ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); } else if (ENB_NAS_USE_TUN) { ret = write(nas_sock_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); + LOG_I(PDCP, "ENB_NAS_USE_TUN is enabled, ret: %d, ctxt_pP->module_id:%d, sizeToWrite:%d, header size:%d \n", ctxt_pP->module_id, ret, sizeToWrite, sizeof (pdcp_data_ind_header_t)); } else if (PDCP_USE_NETLINK) { memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) sdu_p->data, sizeToWrite); nas_nlh_tx->nlmsg_len = sizeToWrite; diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index 2d51e5c7f0..35b2980d41 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -65,6 +65,9 @@ void mac_rlc_data_ind ( nr_rlc_manager_lock(nr_rlc_ue_manager); ue = nr_rlc_manager_get_ue(nr_rlc_ue_manager, rntiP); + if(ue == NULL) + LOG_I(RLC, "RLC instance for the given UE was not found \n"); + switch (channel_idP) { case 1 ... 2: rb = ue->srb[channel_idP - 1]; break; case 3 ... 7: rb = ue->drb[channel_idP - 3]; break; @@ -72,12 +75,13 @@ void mac_rlc_data_ind ( } if (rb != NULL) { + LOG_W(RLC, "RB found! (channel ID %d) \n", channel_idP); rb->set_time(rb, nr_rlc_current_time); rb->recv_pdu(rb, buffer_pP, tb_sizeP); } else { LOG_E(RLC, "%s:%d:%s: fatal: no RB found (channel ID %d)\n", __FILE__, __LINE__, __FUNCTION__, channel_idP); - exit(1); + //exit(1); } nr_rlc_manager_unlock(nr_rlc_ue_manager); diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c index 4c9804bdc0..94aa458b96 100644 --- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c @@ -182,7 +182,7 @@ void handle_nr_ulsch(NR_UL_IND_t *UL_info) { if (UL_info->crc_ind.crc_indication_body.crc_pdu_list[j].crc_indication_rel8.crc_flag == 1) { // CRC error indication LOG_D(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC error) \n",UL_info->frame,UL_info->slot); - rx_sdu(UL_info->module_id, + nr_rx_sdu(UL_info->module_id, UL_info->CC_id, NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf), //UL_info->frame, NFAPI_SFNSF2SF(UL_info->rx_ind.sfn_sf), //UL_info->slot, @@ -192,8 +192,8 @@ void handle_nr_ulsch(NR_UL_IND_t *UL_info) { UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi); } else { - LOG_D(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok) \n",UL_info->frame,UL_info->slot); - rx_sdu(UL_info->module_id, + LOG_I(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok) \n",UL_info->frame,UL_info->slot); + nr_rx_sdu(UL_info->module_id, UL_info->CC_id, NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf), //UL_info->frame, NFAPI_SFNSF2SF(UL_info->rx_ind.sfn_sf), //UL_info->slot, From 99fce8a3599b31d20c067b82b5e08b3c66b15dd2 Mon Sep 17 00:00:00 2001 From: matzakos Date: Wed, 22 Jan 2020 13:05:10 +0100 Subject: [PATCH 04/73] nr-ip noS1 uplink: Uplink IP traffic successfully received at the IP TUN interface of the gNB now. Logs cleanup. --- executables/nr-softmodem.c | 1 + executables/nr-ue.c | 1 - openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c | 12 ++++--- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 25 ++++++++++---- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 12 ++++--- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 10 ++++++ .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 13 ++++++-- openair2/LAYER2/PDCP_v10.1.0/pdcp.c | 1 - openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c | 33 ++++++++++++++++--- openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 2 +- openair2/NR_PHY_INTERFACE/NR_IF_Module.c | 2 +- 11 files changed, 85 insertions(+), 27 deletions(-) diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index 0a638f7265..62383b6dc9 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -910,6 +910,7 @@ init_opt(); #ifdef PDCP_USE_NETLINK +if(!IS_SOFTMODEM_NOS1) netlink_init(); #if defined(PDCP_USE_NETLINK_QUEUES) pdcp_netlink_init(); diff --git a/executables/nr-ue.c b/executables/nr-ue.c index 24288d76d3..fde6e24398 100644 --- a/executables/nr-ue.c +++ b/executables/nr-ue.c @@ -420,7 +420,6 @@ void processSlotRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) { 0x1234, proc->frame_rx, proc->nr_tti_rx, 0); pdcp_run(&ctxt); - pdcp_fifo_flush_sdus(&ctxt); } } diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c index 1d3e62714b..4a90523fd1 100644 --- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c +++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c @@ -593,16 +593,16 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, p_procTime); if (check_crc((uint8_t*)llrProcBuf,length_dec,harq_process->F,crc_type)) { - //#ifdef PRINT_CRC_CHECK + #ifdef PRINT_CRC_CHECK //if (prnt_crc_cnt % 10 == 0) LOG_I(PHY, "Segment %d CRC OK\n",r); - //#endif + #endif ret = no_iteration_ldpc; } else { - //#ifdef PRINT_CRC_CHECK + #ifdef PRINT_CRC_CHECK //if (prnt_crc_cnt%10 == 0) LOG_I(PHY, "CRC NOK\n"); - //#endif + #endif ret = ulsch->max_ldpc_iterations + 1; } @@ -719,12 +719,14 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB, } - LOG_I(PHY, "output encoder: \n"); +#ifdef DEBUG_ULSCH_DECODING + LOG_I(PHY, "Decoder output (payload): \n"); for (i = 0; i < harq_process->TBS / 8; i++) { //harq_process_ul_ue->a[i] = (unsigned char) rand(); //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); printf("0x%02x",harq_process->b[i]); } +#endif ulsch->last_iteration_cnt = ret; diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index a5c747bbba..fd0eb3f996 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -45,6 +45,7 @@ //#define DEBUG_SCFDMA //#define DEBUG_PUSCH_MAPPING +#define DEBUG_MAC_PDU //extern int32_t uplink_counter; @@ -160,13 +161,25 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, if(data_existing){ //harq_process_ul_ue->a = (unsigned char*)calloc(harq_process_ul_ue->TBS/8, sizeof(unsigned char)); memcpy(harq_process_ul_ue->a, ulsch_input_buffer, harq_process_ul_ue->TBS/8); - LOG_I(PHY, "input encoder: \n"); + + #ifdef DEBUG_MAC_PDU + LOG_I(PHY, "Printing MAC PDU to be encoded: \n"); + for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { + printf("0x%02x",harq_process_ul_ue->a[i]); + } + printf("\n"); + #endif + } + else{ + //Use different rnti for the random (non-IP traffic) in noS1 mode, in order to use it as a filter + //to block this traffic from being forwarded to the MAC layer of the gNB + ulsch_ue->rnti = 0x1111; + LOG_E(PHY, "Random data to be tranmsitted: \n"); for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { - //harq_process_ul_ue->a[i] = (unsigned char) rand(); - //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); - //printf("0x%02x",harq_process_ul_ue->a[i]); - printf("0x%02x",harq_process_ul_ue->b[i]); - } + harq_process_ul_ue->a[i] = (unsigned char) rand(); + //printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); + } + data_existing = 1; } } //else if(uplink_counter == 0){ //if(!IS_SOFTMODEM_NOS1){ diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index a849e3c2d9..7f43c02fcb 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -38,6 +38,7 @@ #include "PHY/INIT/phy_init.h" #include "PHY/MODULATION/nr_modulation.h" #include "T.h" +#include "executables/nr-softmodem.h" #include "assertions.h" #include "msc.h" @@ -261,10 +262,12 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int UE_id if (ret > gNB->ulsch[UE_id][0]->max_ldpc_iterations) LOG_I(PHY, "ULSCH in error\n"); //gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b - else if(gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b!=NULL){ - LOG_I(PHY, "ULSCH received ok, number of iterations: %d \n", ret); - nr_fill_crc_indication (gNB, UE_id, frame_rx, slot_rx, 0); - nr_fill_rx_indication(gNB, frame_rx, slot_rx, UE_id, harq_pid); + else if(gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->b!=NULL){ + LOG_D(PHY, "ULSCH received ok \n"); + if(IS_SOFTMODEM_NOS1 && gNB->ulsch[UE_id][0]->rnti == 0x1234){ + nr_fill_crc_indication (gNB, UE_id, frame_rx, slot_rx, 0); + nr_fill_rx_indication(gNB, frame_rx, slot_rx, UE_id, harq_pid); + } } } @@ -295,7 +298,6 @@ void nr_fill_rx_indication(PHY_VARS_gNB *gNB, int frame, int slot_rx, int UE_id, pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG; pdu->rx_ue_information.rnti = gNB->ulsch[UE_id][0]->rnti; pdu->rx_indication_rel8.tl.tag = NFAPI_RX_INDICATION_REL8_TAG; - pdu->rx_indication_rel8.length = gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->TBS>>3; pdu->rx_indication_rel8.offset = 1; // DJP - I dont understand - but broken unless 1 ???? 0; // filled in at the end of the UL_INFO formation pdu->data = harq_process->b;//gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b; // estimate timing advance for MAC diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index c0c8a9ec24..11bb2ee69f 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -3028,6 +3028,16 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, (char) (taus() & 0xff); } } +#if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_D(MAC, "Printing UL MAC payload without the header UE side: \n"); + for (int i = payload_offset; i < sdu_length_total ; i++) { + //harq_process_ul_ue->a[i] = (unsigned char) rand(); + //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); + printf("%02x ",(unsigned char)ulsch_buffer[i]); + } + printf("\n"); +#endif + return 1; } diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index f0a8545141..d9e6b0d583 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -634,7 +634,7 @@ nr_rx_sdu(const module_id_t enb_mod_idP, } // end for loop on control element for (int i = 0; i < num_sdu; i++) { - LOG_I(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n", + LOG_D(MAC, "SDU Number %d MAC Subheader SDU_LCID %d, length %d\n", i, rx_lcids[i], rx_lengths[i]); @@ -701,9 +701,16 @@ nr_rx_sdu(const module_id_t enb_mod_idP, if ((rx_lengths[i] < SCH_PAYLOAD_SIZE_MAX) && (rx_lengths[i] > 0)) { // MAX SIZE OF transport block - mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr, rx_lengths[i], 1, NULL); +#if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_I(MAC, "Printing UL MAC payload after removing the header: \n"); + for (int j = 0; j < rx_lengths[i] ; j++) { + printf("%02x ",(unsigned char) *(payload_ptr+j)); + } + pritnf("\n"); +#endif + mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr+1, rx_lengths[i], 1, NULL); } else { /* rx_length[i] Max size */ - UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1; + //UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1; LOG_E(MAC, "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ", enb_mod_idP, CC_idP, diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c index f234e02c04..c2ebf8d1ea 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c @@ -2171,7 +2171,6 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask ) { if(UE_NAS_USE_TUN) { int num_if = (NFAPI_MODE == NFAPI_UE_STUB_PNF || IS_SOFTMODEM_SIML1 )?MAX_NUMBER_NETIF:1; netlink_init_tun("ue",num_if); - //Add --nr-ip-over-lte option check for next line if (IS_SOFTMODEM_NOS1) nas_config(1, 1, 2, "ue"); LOG_I(PDCP, "UE pdcp will use tun interface\n"); diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c index 260e7c3ba3..8a87dad1be 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c @@ -124,18 +124,34 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const ctxt_pP) { ret = sendto(pdcp_pc5_sockfd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), sizeof(sidelink_pc5s_element), 0, (struct sockaddr *)&prose_pdcp_addr,sizeof(prose_pdcp_addr) ); + } else if (UE_NAS_USE_TUN) { - ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); + #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) + LOG_I(PHY, "PDCP output to be sent to TUN interface: \n"); + for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) { + printf("%02x ",(unsigned char)sdu_p->data[i]); + } + printf("\n"); + #endif + ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); + } else if (ENB_NAS_USE_TUN) { - ret = write(nas_sock_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite ); - LOG_I(PDCP, "ENB_NAS_USE_TUN is enabled, ret: %d, ctxt_pP->module_id:%d, sizeToWrite:%d, header size:%d \n", ctxt_pP->module_id, ret, sizeToWrite, sizeof (pdcp_data_ind_header_t)); + #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) + LOG_I(PHY, "PDCP output to be sent to TUN interface: \n"); + for (int i = sizeof(pdcp_data_ind_header_t); i < sizeToWrite; i++) { + printf("%02x ",(unsigned char)sdu_p->data[i]); + } + printf("\n"); + #endif + ret = write(nas_sock_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]), sizeToWrite); + } else if (PDCP_USE_NETLINK) { memcpy(NLMSG_DATA(nas_nlh_tx), (uint8_t *) sdu_p->data, sizeToWrite); nas_nlh_tx->nlmsg_len = sizeToWrite; ret = sendmsg(nas_sock_fd[0],&nas_msg_tx,0); } // PDCP_USE_NETLINK - AssertFatal(ret >= 0,"[PDCP_FIFOS] pdcp_fifo_flush_sdus (errno: %d %s)\n", errno, strerror(errno)); + AssertFatal(ret >= 0,"[PDCP_FIFOS] pdcp_fifo_flush_sdus (errno: %d %s), nas_sock_fd[0]: %d\n", errno, strerror(errno), nas_sock_fd[0]); #if defined(ENABLE_PDCP_PAYLOAD_DEBUG) LOG_I(PDCP, "Printing first bytes of PDCP SDU before removing it from the list: \n"); @@ -187,6 +203,15 @@ int pdcp_fifo_read_input_sdus_fromtun (const protocol_ctxt_t *const ctxt_pP) { LOG_D(PDCP, "[FRAME %5u][UE][IP][INSTANCE %u][RB %ld][--- PDCP_DATA_REQ / %d Bytes --->][PDCP][MOD %u][UE %04x][RB %ld]\n", ctxt.frame, ctxt.instance, rab_id, len, ctxt.module_id, ctxt.rnti, rab_id); + +#if defined ENABLE_PDCP_PAYLOAD_DEBUG + LOG_I(PHY, "TUN interface output received from PDCP: \n"); + for (int i = 0; i < 128; i++) { + printf("%02x ",(unsigned char)nl_rx_buf[i]); + } + printf("\n"); +#endif + pdcp_data_req(&ctxt, SRB_FLAG_NO, rab_id, RLC_MUI_UNDEFINED, RLC_SDU_CONFIRM_NO, len, (unsigned char *)nl_rx_buf, PDCP_TRANSMISSION_MODE_DATA diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index 35b2980d41..67931f22a9 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -81,7 +81,7 @@ void mac_rlc_data_ind ( } else { LOG_E(RLC, "%s:%d:%s: fatal: no RB found (channel ID %d)\n", __FILE__, __LINE__, __FUNCTION__, channel_idP); - //exit(1); + exit(1); } nr_rlc_manager_unlock(nr_rlc_ue_manager); diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c index 94aa458b96..2094b3517e 100644 --- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c @@ -192,7 +192,7 @@ void handle_nr_ulsch(NR_UL_IND_t *UL_info) { UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi); } else { - LOG_I(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok) \n",UL_info->frame,UL_info->slot); + LOG_D(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok) \n",UL_info->frame,UL_info->slot); nr_rx_sdu(UL_info->module_id, UL_info->CC_id, NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf), //UL_info->frame, From 8a6f346ec49e7ce0521501cff45fff40b697b84d Mon Sep 17 00:00:00 2001 From: matzakos Date: Fri, 24 Jan 2020 20:04:00 +0100 Subject: [PATCH 05/73] nr-ip-ul nos1: Small modification to be able to block the random traffic (which is generated when there is no Uplink IP traffic at the UE) at the MAC layer of the gNB --- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 19 +++++++++++-------- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 2 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 3 +-- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 5 +++-- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index 077f417a99..1d4fdcd538 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -45,7 +45,7 @@ //#define DEBUG_SCFDMA //#define DEBUG_PUSCH_MAPPING -#define DEBUG_MAC_PDU +//#define DEBUG_MAC_PDU //extern int32_t uplink_counter; @@ -174,6 +174,7 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, if (IS_SOFTMODEM_NOS1){ data_existing = nr_ue_get_sdu(UE->Mod_id, UE->CC_id, frame, slot, 0, ulsch_input_buffer, harq_process_ul_ue->TBS/8, &access_mode); + //IP traffic to be transmitted if(data_existing){ //harq_process_ul_ue->a = (unsigned char*)calloc(harq_process_ul_ue->TBS/8, sizeof(unsigned char)); memcpy(harq_process_ul_ue->a, ulsch_input_buffer, harq_process_ul_ue->TBS/8); @@ -186,16 +187,20 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, printf("\n"); #endif } + //Random traffic to be transmitted if there is no IP traffic available for this Tx opportunity else{ - //Use different rnti for the random (non-IP traffic) in noS1 mode, in order to use it as a filter - //to block this traffic from being forwarded to the MAC layer of the gNB - ulsch_ue->rnti = 0x1111; + //Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid + //and block this traffic from being forwarded to the upper layers at the gNB + uint16_t payload_offset = 5; LOG_E(PHY, "Random data to be tranmsitted: \n"); - for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { + //Give the header bytes some dummy value in order to block the random packet at the MAC layer of the receiver + for (i = 0; ia[i] = 0; + + for (i = payload_offset; i < harq_process_ul_ue->TBS / 8; i++) { harq_process_ul_ue->a[i] = (unsigned char) rand(); //printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); } - data_existing = 1; } } //else if(uplink_counter == 0){ //if(!IS_SOFTMODEM_NOS1){ @@ -205,7 +210,6 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, harq_process_ul_ue->a[i] = (unsigned char) rand(); //printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); } - data_existing = 1; //uplink_counter++; } } else { @@ -219,7 +223,6 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, /////////// - //if(data_existing){ nr_ulsch_encoding(ulsch_ue, frame_parms, harq_pid); /////////// diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 2f30b6af39..3c727738cf 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -289,7 +289,7 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int UE_id //gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b else if(gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->b!=NULL){ LOG_D(PHY, "ULSCH received ok \n"); - if(IS_SOFTMODEM_NOS1 && gNB->ulsch[UE_id][0]->rnti == 0x1234){ + if(IS_SOFTMODEM_NOS1){ //&& gNB->ulsch[UE_id][0]->rnti == 0x1234 nr_fill_crc_indication (gNB, UE_id, frame_rx, slot_rx, 0); nr_fill_rx_indication(gNB, frame_rx, slot_rx, UE_id, harq_pid); } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index a116e7b8ca..568ef5f736 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2502,7 +2502,6 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, } // UE_mode==PUSCH */ - //if(data_existing){ LOG_I(PHY, "Sending data \n"); nr_ue_pusch_common_procedures(ue, harq_pid, @@ -2510,7 +2509,7 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, thread_id, gNB_id, &ue->frame_parms); - //} + diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 8010a1f714..4b966fd7b1 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -2995,6 +2995,8 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, // Generate header // if (num_sdus>0) { + // cycle through SDUs and place in ulsch_buffer + if (sdu_length_total) { payload_offset = nr_generate_ulsch_header(ulsch_buffer, // mac header num_sdus, // num sdus short_padding, // short pading @@ -3012,8 +3014,7 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, short_padding, post_padding, bsr_len, phr_len, buflen - sdu_length_total - payload_offset); - // cycle through SDUs and place in ulsch_buffer - if (sdu_length_total) { + memcpy(&ulsch_buffer[payload_offset], ulsch_buff, sdu_length_total); } From bb7a78880955a596c15f1ddc87789559d0270b51 Mon Sep 17 00:00:00 2001 From: matzakos Date: Wed, 5 Feb 2020 18:47:02 +0100 Subject: [PATCH 06/73] nr-ip-UL-nos1: Integrate NR MAC PDU structures for the Uplink. Currently supporting only data SDUs, Control Elements to be added. --- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 2 +- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 1 + openair2/LAYER2/MAC/mac_proto.h | 11 - openair2/LAYER2/NR_MAC_COMMON/nr_mac.h | 138 ++++ openair2/LAYER2/NR_MAC_UE/mac_defs.h | 95 +++ openair2/LAYER2/NR_MAC_UE/mac_proto.h | 9 + openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 638 +++--------------- .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 223 +++++- openair2/LAYER2/NR_MAC_gNB/mac_proto.h | 26 +- openair2/NR_PHY_INTERFACE/NR_IF_Module.c | 2 +- 10 files changed, 549 insertions(+), 596 deletions(-) create mode 100644 openair2/LAYER2/NR_MAC_COMMON/nr_mac.h diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index 1d4fdcd538..5717b32805 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -180,7 +180,7 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, memcpy(harq_process_ul_ue->a, ulsch_input_buffer, harq_process_ul_ue->TBS/8); #ifdef DEBUG_MAC_PDU - LOG_I(PHY, "Printing MAC PDU to be encoded: \n"); + LOG_I(PHY, "Printing MAC PDU to be encoded, TBS is: %d \n", harq_process_ul_ue->TBS/8); for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { printf("0x%02x",harq_process_ul_ue->a[i]); } diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 3c727738cf..4dd67d373f 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -316,6 +316,7 @@ void nr_fill_rx_indication(PHY_VARS_gNB *gNB, int frame, int slot_rx, int UE_id, gNB->UL_INFO.rx_ind.sfn_sf = frame<<4| slot_rx; gNB->UL_INFO.rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG; + gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list->rx_indication_rel8.length = gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->TBS>>3; pdu = &gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list[gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus]; diff --git a/openair2/LAYER2/MAC/mac_proto.h b/openair2/LAYER2/MAC/mac_proto.h index 564899ddcc..476fb68584 100644 --- a/openair2/LAYER2/MAC/mac_proto.h +++ b/openair2/LAYER2/MAC/mac_proto.h @@ -1295,14 +1295,3 @@ uint8_t ul_subframe2_k_phich(COMMON_channels_t *cc, sub_frame_t ul_subframe); /* Main loop of MAC itti message handling */ void *mac_enb_task(void *arg); -unsigned char -nr_generate_ulsch_header(uint8_t *mac_header, - uint8_t num_sdus, - uint8_t short_padding, - uint16_t *sdu_lengths, - uint8_t *sdu_lcids, - POWER_HEADROOM_CMD *power_headroom, - uint16_t *crnti, - BSR_SHORT *truncated_bsr, - BSR_SHORT *short_bsr, - BSR_LONG *long_bsr, unsigned short post_padding); diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h new file mode 100644 index 0000000000..cb004e0c23 --- /dev/null +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h @@ -0,0 +1,138 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/* \file nr_mac.h + * \brief common MAC data structures, constant, and function prototype + * \author R. Knopp, K.H. HSU, G. Casati + * \date 2019 + * \version 0.1 + * \company Eurecom / NTUST / Fraunhofer IIS + * \email: knopp@eurecom.fr, kai-hsiang.hsu@eurecom.fr, guido.casati@iis.fraunhofer.de + * \note + * \warning + */ + +#ifndef __LAYER2_NR_MAC_H__ +#define __LAYER2_NR_MAC_H__ + +#include +#include +#include + +#define NR_BCCH_DL_SCH 3 // SI + +#define NR_BCCH_BCH 5 // MIB + +// For both DL/UL-SCH +// Except: +// - UL/DL-SCH: fixed-size MAC CE(known by LCID) +// - UL/DL-SCH: padding +// - UL-SCH: MSG3 48-bits +// |0|1|2|3|4|5|6|7| bit-wise +// |R|F| LCID | +// | L | +// |0|1|2|3|4|5|6|7| bit-wise +// |R|F| LCID | +// | L | +// | L | + +// For both DL/UL-SCH +// For: +// - UL/DL-SCH: fixed-size MAC CE(known by LCID) +// - UL/DL-SCH: padding, for single/multiple 1-oct padding CE(s) +// - UL-SCH: MSG3 48-bits +// |0|1|2|3|4|5|6|7| bit-wise +// |R|R| LCID | +// LCID: The Logical Channel ID field identifies the logical channel instance of the corresponding MAC SDU or the type of the corresponding MAC CE or padding as described in Tables 6.2.1-1 and 6.2.1-2 for the DL-SCH and UL-SCH respectively. There is one LCID field per MAC subheader. The LCID field size is 6 bits; +// L: The Length field indicates the length of the corresponding MAC SDU or variable-sized MAC CE in bytes. There is one L field per MAC subheader except for subheaders corresponding to fixed-sized MAC CEs and padding. The size of the L field is indicated by the F field; +// F: lenght of L is 0:8 or 1:16 bits wide +// R: Reserved bit, set to zero. + +typedef struct { + uint8_t LCID:6; // octet 1 [5:0] + uint8_t F:1; // octet 1 [6] + uint8_t R:1; // octet 1 [7] + uint8_t L:8; // octet 2 [7:0] +} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_SHORT; + +typedef struct { + uint8_t LCID:6; // octet 1 [5:0] + uint8_t F:1; // octet 1 [6] + uint8_t R:1; // octet 1 [7] + uint8_t L1:8; // octet 2 [7:0] + uint8_t L2:8; // octet 3 [7:0] +} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_LONG; + +typedef struct { + uint8_t LCID:6; // octet 1 [5:0] + uint8_t R:2; // octet 1 [7:6] +} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_FIXED; + +// 38.321 ch. 6.1.3.4 +typedef struct { + uint8_t TA_COMMAND:6; // octet 1 [5:0] + uint8_t TAGID:2; // octet 1 [7:6] +} __attribute__ ((__packed__)) NR_MAC_CE_TA; + +// 38.321 ch6.2.1, 38.331 +#define DL_SCH_LCID_CCCH 0x00 +#define DL_SCH_LCID_DCCH 0x01 +#define DL_SCH_LCID_DCCH1 0x02 +#define DL_SCH_LCID_DTCH 0x03 +#define DL_SCH_LCID_RECOMMENDED_BITRATE 0x2F +#define DL_SCH_LCID_SP_ZP_CSI_RS_RES_SET_ACT 0x30 +#define DL_SCH_LCID_PUCCH_SPATIAL_RELATION_ACT 0x31 +#define DL_SCH_LCID_SP_SRS_ACTIVATION 0x32 +#define DL_SCH_LCID_SP_CSI_REP_PUCCH_ACT 0x33 +#define DL_SCH_LCID_TCI_STATE_IND_UE_SPEC_PDCCH 0x34 +#define DL_SCH_LCID_TCI_STATE_ACT_UE_SPEC_PDSCH 0x35 +#define DL_SCH_LCID_APERIODIC_CSI_TRI_STATE_SUBSEL 0x36 +#define DL_SCH_LCID_SP_CSI_RS_CSI_IM_RES_SET_ACT 0X37 +#define DL_SCH_LCID_DUPLICATION_ACT 0X38 +#define DL_SCH_LCID_SCell_ACT_4_OCT 0X39 +#define DL_SCH_LCID_SCell_ACT_1_OCT 0X3A +#define DL_SCH_LCID_L_DRX 0x3B +#define DL_SCH_LCID_DRX 0x3C +#define DL_SCH_LCID_TA_COMMAND 0x3D +#define DL_SCH_LCID_CON_RES_ID 0x3E +#define DL_SCH_LCID_PADDING 0x3F + +#define UL_SCH_LCID_CCCH 0x00 +#define UL_SCH_LCID_SRB1 0x01 +#define UL_SCH_LCID_SRB2 0x02 +#define UL_SCH_LCID_DTCH 0x03 +#define UL_SCH_LCID_SRB3 0x04 +#define UL_SCH_LCID_CCCH_MSG3 0x21 +#define UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY 0x35 +#define UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT 0x36 +#define UL_SCH_LCID_CONFIGURED_GRANT_CONFIRMATION 0x37 +#define UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT 0x38 +#define UL_SCH_LCID_SINGLE_ENTRY_PHR 0x39 +#define UL_SCH_LCID_C_RNTI 0x3A +#define UL_SCH_LCID_S_TRUNCATED_BSR 0x3B +#define UL_SCH_LCID_L_TRUNCATED_BSR 0x3C +#define UL_SCH_LCID_S_BSR 0x3D +#define UL_SCH_LCID_L_BSR 0x3E +#define UL_SCH_LCID_PADDING 0x3F + + +#endif /*__LAYER2_MAC_H__ */ + diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 9d75b06fa5..534f3bf9c3 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -53,6 +53,13 @@ #include "PHY/defs_nr_common.h" #define NB_NR_UE_MAC_INST 1 +/*!\brief Maximum number of logical channl group IDs */ +#define MAX_NUM_LCGID 4 +/*!\brief Maximum number of logical chanels */ +#define MAX_NUM_LCID 11 + +/*!\brief value for indicating BSR Timer is not running */ +#define NR_MAC_UE_BSR_TIMER_NOT_RUNNING (0xFFFF) typedef enum { SFN_C_MOD_2_EQ_0, @@ -60,6 +67,86 @@ typedef enum { SFN_C_IMPOSSIBLE } SFN_C_TYPE; +#define UL_SCH_LCID_CCCH 0x00 +#define UL_SCH_LCID_SRB1 0x01 +#define UL_SCH_LCID_SRB2 0x02 +#define UL_SCH_LCID_DTCH 0x03 +#define UL_SCH_LCID_SRB3 0x04 +#define UL_SCH_LCID_CCCH_MSG3 0x21 +#define UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY 0x35 +#define UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT 0x36 +#define UL_SCH_LCID_CONFIGURED_GRANT_CONFIRMATION 0x37 +#define UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT 0x38 +#define UL_SCH_LCID_SINGLE_ENTRY_PHR 0x39 +#define UL_SCH_LCID_C_RNTI 0x3A +#define UL_SCH_LCID_S_TRUNCATED_BSR 0x3B +#define UL_SCH_LCID_L_TRUNCATED_BSR 0x3C +#define UL_SCH_LCID_S_BSR 0x3D +#define UL_SCH_LCID_L_BSR 0x3E +#define UL_SCH_LCID_PADDING 0x3F + +// LTE structure, might need to be adapted for NR +typedef struct { + /// buffer status for each lcgid + uint8_t BSR[MAX_NUM_LCGID]; // should be more for mesh topology + /// keep the number of bytes in rlc buffer for each lcgid + int32_t BSR_bytes[MAX_NUM_LCGID]; + /// after multiplexing buffer remain for each lcid + int32_t LCID_buffer_remain[MAX_NUM_LCID]; + /// sum of all lcid buffer size + uint16_t All_lcid_buffer_size_lastTTI; + /// buffer status for each lcid + uint8_t LCID_status[MAX_NUM_LCID]; + /// SR pending as defined in 36.321 + uint8_t SR_pending; + /// SR_COUNTER as defined in 36.321 + uint16_t SR_COUNTER; + /// logical channel group ide for each LCID + uint8_t LCGID[MAX_NUM_LCID]; + /// retxBSR-Timer, default value is sf2560 + uint16_t retxBSR_Timer; + /// retxBSR_SF, number of subframe before triggering a regular BSR + uint16_t retxBSR_SF; + /// periodicBSR-Timer, default to infinity + uint16_t periodicBSR_Timer; + /// periodicBSR_SF, number of subframe before triggering a periodic BSR + uint16_t periodicBSR_SF; + /// default value is 0: not configured + uint16_t sr_ProhibitTimer; + /// sr ProhibitTime running + uint8_t sr_ProhibitTimer_Running; + /// default value to n5 + uint16_t maxHARQ_Tx; + /// default value is false + uint16_t ttiBundling; + /// default value is release + struct DRX_Config *drx_config; + /// default value is release + struct MAC_MainConfig__phr_Config *phr_config; + ///timer before triggering a periodic PHR + uint16_t periodicPHR_Timer; + ///timer before triggering a prohibit PHR + uint16_t prohibitPHR_Timer; + ///DL Pathloss change value + uint16_t PathlossChange; + ///number of subframe before triggering a periodic PHR + int16_t periodicPHR_SF; + ///number of subframe before triggering a prohibit PHR + int16_t prohibitPHR_SF; + ///DL Pathloss Change in db + uint16_t PathlossChange_db; + + /// default value is false + uint16_t extendedBSR_Sizes_r10; + /// default value is false + uint16_t extendedPHR_r10; + + //Bj bucket usage per lcid + int16_t Bj[MAX_NUM_LCID]; + // Bucket size per lcid + int16_t bucket_size[MAX_NUM_LCID]; +} NR_UE_SCHEDULING_INFO; + /*!\brief Top level UE MAC structure */ typedef struct { @@ -82,6 +169,7 @@ typedef struct { /// Random access parameter uint16_t ra_rnti; + uint16_t crnti; //BWP params NR_BWP_PARMS initial_bwp_dl; @@ -96,6 +184,13 @@ typedef struct { nr_ue_if_module_t *if_module; nr_scheduled_response_t scheduled_response; nr_phy_config_t phy_config; + + /// BSR report flag management + uint8_t BSR_reporting_active; + NR_UE_SCHEDULING_INFO scheduling_info; + + /// PHR + uint8_t PHR_reporting_active; } NR_UE_MAC_INST_t; typedef enum seach_space_mask_e { diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index c33d624469..9ddb47601d 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -140,5 +140,14 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t subframe, uint8_t eNB_index, uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode); +unsigned char +nr_generate_ulsch_pdu(uint8_t *mac_pdu, + uint8_t *sdus_payload, + uint8_t num_sdus, + uint16_t *sdu_lengths, + uint8_t *sdu_lcids, + uint16_t *crnti, + uint16_t buflen); + #endif /** @}*/ diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 4b966fd7b1..ceff5baaa7 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -2319,282 +2319,63 @@ unsigned char *nr_parse_header(unsigned char *mac_header, } unsigned char -nr_generate_ulsch_header(uint8_t *mac_header, +nr_generate_ulsch_pdu(uint8_t *mac_pdu, + uint8_t *sdus_payload, uint8_t num_sdus, - uint8_t short_padding, uint16_t *sdu_lengths, uint8_t *sdu_lcids, - POWER_HEADROOM_CMD *power_headroom, uint16_t *crnti, - BSR_SHORT *truncated_bsr, - BSR_SHORT *short_bsr, - BSR_LONG *long_bsr, unsigned short post_padding) { - SCH_SUBHEADER_FIXED *mac_header_ptr = - (SCH_SUBHEADER_FIXED *) mac_header; - unsigned char first_element = 0, last_size = 0, i; - unsigned char mac_header_control_elements[16], *ce_ptr; - LOG_D(MAC, "[UE] Generate ULSCH : num_sdus %d\n", num_sdus); -#ifdef DEBUG_HEADER_PARSING + uint16_t buflen) { - for (i = 0; i < num_sdus; i++) { - LOG_T(MAC, "[UE] sdu %d : lcid %d length %d", i, sdu_lcids[i], - sdu_lengths[i]); - } + NR_MAC_SUBHEADER_FIXED *mac_pdu_ptr = (NR_MAC_SUBHEADER_FIXED *) mac_pdu; + unsigned char * ulsch_buffer_ptr = sdus_payload; + uint8_t last_size=0; + uint16_t sdu_length_total; + int i; + int offset=0; - LOG_T(MAC, "\n"); -#endif - ce_ptr = &mac_header_control_elements[0]; + // 2) Generation of ULSCH MAC SDU subheaders + for (i = 0; i < num_sdus; i++) { + LOG_D(MAC, "[gNB] Generate ULSCH header num sdu %d len sdu %d\n", num_sdus, sdu_lengths[i]); - if ((short_padding == 1) || (short_padding == 2)) { - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - first_element = 1; - last_size = 1; - } + if (sdu_lengths[i] < 128) { + ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->R = 0; + ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->F = 0; + ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->LCID = sdu_lcids[i]; + ((NR_MAC_SUBHEADER_SHORT *) mac_pdu_ptr)->L = (unsigned char) sdu_lengths[i]; + last_size = 2; + } else { + ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->R = 0; + ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->F = 1; + ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->LCID = sdu_lcids[i]; + ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L1 = ((unsigned short) sdu_lengths[i] >> 8) & 0x7f; + ((NR_MAC_SUBHEADER_LONG *) mac_pdu_ptr)->L2 = (unsigned short) sdu_lengths[i] & 0xff; + last_size = 3; + } - if (short_padding == 2) { - mac_header_ptr->E = 1; - mac_header_ptr++; - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - last_size = 1; - } + mac_pdu_ptr += last_size; - if (power_headroom) { - if (first_element > 0) { - mac_header_ptr->E = 1; - mac_header_ptr++; - } else { - first_element = 1; - } + // 3) cycle through SDUs, compute each relevant and place dlsch_buffer in + memcpy((void *) mac_pdu_ptr, (void *) ulsch_buffer_ptr, sdu_lengths[i]); + ulsch_buffer_ptr+= sdu_lengths[i]; + mac_pdu_ptr += sdu_lengths[i]; + } - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = POWER_HEADROOM; - last_size = 1; - *((POWER_HEADROOM_CMD *) ce_ptr) = (*power_headroom); - ce_ptr += sizeof(POWER_HEADROOM_CMD); - LOG_D(MAC, "phr header size %zu\n", sizeof(POWER_HEADROOM_CMD)); - } + // 4) Compute final offset for padding + uint16_t padding_bytes = buflen - sdu_length_total; + if (padding_bytes > 0) { + ((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->R = 0; + ((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->LCID = UL_SCH_LCID_PADDING; + mac_pdu_ptr++; - if (crnti) { -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] CRNTI : %x (first_element %d)\n", *crnti, - first_element); -#endif + } else { + // no MAC subPDU with padding + } - if (first_element > 0) { - mac_header_ptr->E = 1; - mac_header_ptr++; - } else { - first_element = 1; - } + offset = ((unsigned char *) mac_pdu_ptr - mac_pdu); - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = CRNTI; - last_size = 1; - *((uint16_t *) ce_ptr) = (*crnti); - ce_ptr += sizeof(uint16_t); - // printf("offset %d\n",ce_ptr-mac_header_control_elements); - } - if (truncated_bsr) { - if (first_element > 0) { - mac_header_ptr->E = 1; - /* - printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); - */ - mac_header_ptr++; - } else { - first_element = 1; - } - -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] Scheduler Truncated BSR Header\n"); -#endif - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = TRUNCATED_BSR; - last_size = 1; - *((BSR_TRUNCATED *) ce_ptr) = (*truncated_bsr); - ce_ptr += sizeof(BSR_TRUNCATED); - // printf("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); - } else if (short_bsr) { - if (first_element > 0) { - mac_header_ptr->E = 1; - /* - printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); - */ - mac_header_ptr++; - } else { - first_element = 1; - } - -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] Scheduler SHORT BSR Header\n"); -#endif - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_BSR; - last_size = 1; - *((BSR_SHORT *) ce_ptr) = (*short_bsr); - ce_ptr += sizeof(BSR_SHORT); - // printf("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); - } else if (long_bsr) { - if (first_element > 0) { - mac_header_ptr->E = 1; - /* - printf("last subheader : %x (R%d,E%d,LCID%d)\n",*(unsigned char*)mac_header_ptr, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *)mac_header_ptr)->LCID); - */ - mac_header_ptr++; - } else { - first_element = 1; - } - -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] Scheduler Long BSR Header\n"); -#endif - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = LONG_BSR; - last_size = 1; - *(ce_ptr) = - (long_bsr-> - Buffer_size0 << 2) | ((long_bsr->Buffer_size1 & 0x30) >> 4); - *(ce_ptr + 1) = - ((long_bsr->Buffer_size1 & 0x0F) << 4) | ((long_bsr-> - Buffer_size2 & 0x3C) - >> 2); - *(ce_ptr + 2) = - ((long_bsr-> - Buffer_size2 & 0x03) << 2) | (long_bsr->Buffer_size3 & 0x3F); - ce_ptr += BSR_LONG_SIZE; - // printf("(cont_res) : offset %d\n",ce_ptr-mac_header_control_elements); - } - - // printf("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); - - for (i = 0; i < num_sdus; i++) { -#ifdef DEBUG_HEADER_PARSING - LOG_T(MAC, "[UE] sdu subheader %d (lcid %d, %d bytes)\n", i, - sdu_lcids[i], sdu_lengths[i]); -#endif - - if ((i == (num_sdus - 1)) - && ((short_padding) || (post_padding == 0))) { - if (first_element > 0) { - mac_header_ptr->E = 1; -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] last subheader : %x (R%d,E%d,LCID%d)\n", - *(unsigned char *) mac_header_ptr, - ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->LCID); -#endif - mac_header_ptr += last_size; - } - - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = sdu_lcids[i]; - } else { - if ((first_element > 0)) { - mac_header_ptr->E = 1; -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] last subheader : %x (R%d,E%d,LCID%d)\n", - *(unsigned char *) mac_header_ptr, - ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->R, - ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->E, - ((SCH_SUBHEADER_FIXED *) mac_header_ptr)->LCID); -#endif - mac_header_ptr += last_size; - // printf("last_size %d,mac_header_ptr %p\n",last_size,mac_header_ptr); - } else { - first_element = 1; - } - - if (sdu_lengths[i] < 128) { - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->R = 0; // 3 - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F = 0; - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->LCID = - sdu_lcids[i]; - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L = - (unsigned char) sdu_lengths[i]; - last_size = 2; -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] short sdu\n"); - LOG_T(MAC, - "[UE] last subheader : %x (R%d,E%d,LCID%d,F%d,L%d)\n", - ((uint16_t *) mac_header_ptr)[0], - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->R, - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->E, - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->LCID, - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->F, - ((SCH_SUBHEADER_SHORT *) mac_header_ptr)->L); -#endif - } else { - ((SCH_SUBHEADER_LONG *) mac_header_ptr)->R = 0; - ((SCH_SUBHEADER_LONG *) mac_header_ptr)->E = 0; - ((SCH_SUBHEADER_LONG *) mac_header_ptr)->F = 1; - ((SCH_SUBHEADER_LONG *) mac_header_ptr)->LCID = - sdu_lcids[i]; - ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_MSB = - ((unsigned short) sdu_lengths[i] >> 8) & 0x7f; - ((SCH_SUBHEADER_LONG *) mac_header_ptr)->L_LSB = - (unsigned short) sdu_lengths[i] & 0xff; - ((SCH_SUBHEADER_LONG *) mac_header_ptr)->padding = 0x00; - last_size = 3; -#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] long sdu\n"); -#endif - } - } - } - - if (post_padding > 0) { // we have lots of padding at the end of the packet - mac_header_ptr->E = 1; - mac_header_ptr += last_size; - // add a padding element - mac_header_ptr->R = 0; - mac_header_ptr->E = 0; - mac_header_ptr->LCID = SHORT_PADDING; - mac_header_ptr++; - } else { // no end of packet padding - // last SDU subhead is of fixed type (sdu length implicitly to be computed at UE) - mac_header_ptr++; - //mac_header_ptr=last_size; // FIXME: should be ++ - } - - if ((ce_ptr - mac_header_control_elements) > 0) { - memcpy((void *) mac_header_ptr, mac_header_control_elements, - ce_ptr - mac_header_control_elements); - mac_header_ptr += - (unsigned char) (ce_ptr - mac_header_control_elements); - } - -#ifdef DEBUG_HEADER_PARSING - LOG_T(MAC, " [UE] header : "); - - for (i = 0; i < ((unsigned char *) mac_header_ptr - mac_header); i++) { - LOG_T(MAC, "%2x.", mac_header[i]); - } - - LOG_T(MAC, "\n"); -#endif - return ((unsigned char *) mac_header_ptr - mac_header); + return offset; } @@ -2694,93 +2475,68 @@ nr_ue_send_sdu(module_id_t module_idP, } -/* LTE based function to be substituted once NR version is ready */ + uint8_t nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t subframe, uint8_t eNB_index, - uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) - -{ + uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) { uint8_t total_rlc_pdu_header_len = 0, rlc_pdu_header_len_last = 0; uint16_t buflen_remain = 0; - uint8_t bsr_len = 0, bsr_ce_len = 0, bsr_header_len = 0; - uint8_t phr_header_len = 0, phr_ce_len = 0, phr_len = 0; - uint8_t lcid = 0, lcid_rlc_pdu_count = 0; - boolean_t is_lcid_processed = FALSE; - boolean_t is_all_lcid_processed = FALSE; + uint8_t lcid = 0; uint16_t sdu_lengths[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; uint8_t sdu_lcids[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; uint8_t payload_offset = 0, num_sdus = 0; - uint8_t ulsch_buff[MAX_ULSCH_PAYLOAD_BYTES]; + uint8_t ulsch_sdus[MAX_ULSCH_PAYLOAD_BYTES]; uint16_t sdu_length_total = 0; - BSR_SHORT bsr_short, bsr_truncated; - BSR_LONG bsr_long; - BSR_SHORT *bsr_s = &bsr_short; - BSR_LONG *bsr_l = &bsr_long; - BSR_SHORT *bsr_t = &bsr_truncated; - POWER_HEADROOM_CMD phr; - POWER_HEADROOM_CMD *phr_p = &phr; - unsigned short short_padding = 0, post_padding = 0, padding_len = 0; + unsigned short post_padding = 0, padding_len = 0; int j; // used for padding - // Compute header length - int lcg_id = 0; - int lcg_id_bsr_trunc = 0; - int highest_priority = 16; - int num_lcg_id_with_data = 0; + rlc_buffer_occupancy_t lcid_buffer_occupancy_old = 0, lcid_buffer_occupancy_new = 0; - - NR_UE_MAC_INST_t *nr_ue_mac_inst = get_mac_inst(0); - - LOG_D(MAC, "[UE %d] MAC PROCESS UL TRANSPORT BLOCK at frame%d subframe %d TBS=%d\n", module_idP, frameP, subframe, buflen); AssertFatal(CC_id == 0, "Transmission on secondary CCs is not supported yet\n"); +#if UE_TIMING_TRACE + start_meas(&UE_mac_inst[module_idP].tx_ulsch_sdu); +#endif - bsr_header_len = 0; - phr_header_len = 0; // 1; //sizeof(SCH_SUBHEADER_FIXED); - - rlc_buffer_occupancy_t buffer_occupancy = mac_rlc_get_buffer_occupancy_ind( module_idP, 0x1234, eNB_index, frameP, subframe,ENB_FLAG_NO,DTCH); + NR_UE_MAC_INST_t *nr_ue_mac_inst = get_mac_inst(0); // Check for DCCH first // TO DO: Multiplex in the order defined by the logical channel prioritization - for (lcid = DTCH; - (lcid < MAX_NUM_LCID) && (is_all_lcid_processed == FALSE); lcid++) { - lcid_buffer_occupancy_old = mac_rlc_get_buffer_occupancy_ind( module_idP, 0x1234, eNB_index, frameP, subframe,ENB_FLAG_NO,lcid); - if (lcid_buffer_occupancy_old > 0) { - lcid_rlc_pdu_count = 0; - is_lcid_processed = FALSE; + for (lcid = DCCH; + lcid < MAX_NUM_LCID; lcid++) { + lcid_buffer_occupancy_old = + //TODO: Replace static value with CRNTI + mac_rlc_get_buffer_occupancy_ind(module_idP, + 0x1234, eNB_index, frameP, //nr_ue_mac_inst->crnti + subframe, ENB_FLAG_NO, + lcid); lcid_buffer_occupancy_new = lcid_buffer_occupancy_old; - - //Multiplex all available DCCH RLC PDUs considering to multiplex the last PDU each time for maximize the data - //Adjust at the end of the loop - while ((!is_lcid_processed) && (lcid_buffer_occupancy_new) - && (bsr_len + phr_len + total_rlc_pdu_header_len + - sdu_length_total + MIN_MAC_HDR_RLC_SIZE <= buflen)) { + if(lcid_buffer_occupancy_new){ buflen_remain = - buflen - (bsr_len + phr_len + - total_rlc_pdu_header_len + sdu_length_total + - 1); - LOG_I(MAC, + buflen - (total_rlc_pdu_header_len + sdu_length_total + MIN_MAC_HDR_RLC_SIZE); + LOG_D(MAC, "[UE %d] Frame %d : UL-DXCH -> ULSCH, RLC %d has %d bytes to " - "send (Transport Block size %d BSR size=%d PHR=%d SDU Length Total %d , mac header len %d BSR byte before Tx=%d)\n", + "send (Transport Block size %d SDU Length Total %d , mac header len %d )\n", //BSR byte before Tx=%d module_idP, frameP, lcid, lcid_buffer_occupancy_new, - buflen, bsr_len, phr_len, sdu_length_total, - total_rlc_pdu_header_len); + buflen, sdu_length_total, + total_rlc_pdu_header_len); // ,nr_ue_mac_inst->scheduling_info.BSR_bytes[nr_ue_mac_inst->scheduling_info.LCGID[lcid]] + //TODO: Replace static value with CRNTI sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, - 0x1234, eNB_index, + 0x1234, eNB_index, //nr_ue_mac_inst->crnti frameP, ENB_FLAG_NO, MBMS_FLAG_NO, lcid, buflen_remain, - (char *)&ulsch_buff[sdu_length_total],0, + (char *)&ulsch_sdus[sdu_length_total],0, 0 ); AssertFatal(buflen_remain >= sdu_lengths[num_sdus], @@ -2790,247 +2546,58 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, if (sdu_lengths[num_sdus]) { sdu_length_total += sdu_lengths[num_sdus]; sdu_lcids[num_sdus] = lcid; - LOG_I(MAC, - "[UE %d] TX Multiplex RLC PDU TX Got %d bytes for LcId%d\n", - module_idP, sdu_lengths[num_sdus], lcid); - - if (buflen == - (bsr_len + phr_len + total_rlc_pdu_header_len + - sdu_length_total + 1)) { - //No more remaining TBS after this PDU - //exit the function - rlc_pdu_header_len_last = 1; - is_lcid_processed = TRUE; - is_all_lcid_processed = TRUE; - } else { - rlc_pdu_header_len_last = - (sdu_lengths[num_sdus] > 128) ? 3 : 2; - - //Change to 1 byte if it does not fit in the TBS, ie last PDU - if (buflen <= - (bsr_len + phr_len + total_rlc_pdu_header_len + - rlc_pdu_header_len_last + sdu_length_total)) { - rlc_pdu_header_len_last = 1; - is_lcid_processed = TRUE; - is_all_lcid_processed = TRUE; - } - } + //LOG_I(MAC, + // "[UE %d] TX Multiplex RLC PDU TX Got %d bytes for LcId%d\n", + // module_idP, sdu_lengths[num_sdus], lcid); //Update number of SDU num_sdus++; //Update total MAC Header size for RLC PDUs and save last one total_rlc_pdu_header_len += rlc_pdu_header_len_last; - lcid_rlc_pdu_count++; - } else { - /* avoid infinite loop ... */ - is_lcid_processed = TRUE; } /* Get updated BO after multiplexing this PDU */ - lcid_buffer_occupancy_new = - mac_rlc_get_buffer_occupancy_ind( module_idP, - 0x1234, - eNB_index, - frameP, - subframe, - ENB_FLAG_NO, - lcid); + //TODO: Replace static value with CRNTI + + /*lcid_buffer_occupancy_new = + mac_rlc_get_buffer_occupancy_ind(module_idP, + 0x1234, //nr_ue_mac_inst->crnti + eNB_index, frameP, + subframe, ENB_FLAG_NO, + lcid); is_lcid_processed = (is_lcid_processed) - || (lcid_buffer_occupancy_new <= 0); - } - - //Update Buffer remain and BSR bytes after transmission - AssertFatal(lcid_buffer_occupancy_new <= - lcid_buffer_occupancy_old, - "MAC UE Tx error : Buffer Occupancy After Tx=%d greater than before=%d BO! for LCID=%d RLC PDU nb=%d Frame %d Subrame %d\n", - lcid_buffer_occupancy_new, - lcid_buffer_occupancy_old, lcid, - lcid_rlc_pdu_count, frameP, subframe); - } + || (lcid_buffer_occupancy_new <= 0);*/ } +} - // build PHR and update the timers - /*if (phr_ce_len == sizeof(POWER_HEADROOM_CMD)) { - if(NFAPI_MODE==NFAPI_UE_STUB_PNF) { - //Substitute with a static value for the MAC layer abstraction (phy_stub mode) - phr_p->PH = 40; - } else { - phr_p->PH = get_phr_mapping(module_idP, CC_id, eNB_index); - } - - phr_p->R = 0; - LOG_D(MAC, - "[UE %d] Frame %d report PHR with mapping (%d->%d) for LCID %d\n", - module_idP, frameP, get_PHR(module_idP, CC_id, eNB_index), - phr_p->PH, POWER_HEADROOM); - update_phr(module_idP, CC_id); - } else { - phr_p = NULL; - }*/ - - - // Check BSR padding: it is done after PHR according to Logical Channel Prioritization order - // Check for max padding size, ie MAC Hdr for last RLC PDU = 1 - /* For Padding BSR: - - if the number of padding bits is equal to or larger than the size of the Short BSR plus its subheader but smaller than the size of the Long BSR plus its subheader: - - if more than one LCG has data available for transmission in the TTI where the BSR is transmitted: report Truncated BSR of the LCG with the highest priority logical channel with data available for transmission; - - else report Short BSR. - - else if the number of padding bits is equal to or larger than the size of the Long BSR plus its subheader, report Long BSR. - */ - if (sdu_length_total) { - padding_len = - buflen - (bsr_len + phr_len + total_rlc_pdu_header_len - - rlc_pdu_header_len_last + sdu_length_total + 1); - } else { - padding_len = buflen - (bsr_len + phr_len); - } - - /* if ((padding_len) && (bsr_len == 0)) { - // if the number of padding bits is equal to or larger than the size of the Long BSR plus its subheader, report Long BSR - if (padding_len >= (1 + BSR_LONG_SIZE)) { - bsr_ce_len = BSR_LONG_SIZE; - bsr_header_len = 1; - // Trigger BSR Padding - UE_mac_inst[module_idP].BSR_reporting_active |= - BSR_TRIGGER_PADDING; - } else if (padding_len >= (1 + sizeof(BSR_SHORT))) { - bsr_ce_len = sizeof(BSR_SHORT); - bsr_header_len = 1; - - if (num_lcg_id_with_data > 1) { - // REPORT TRUNCATED BSR - //Get LCGID of highest priority LCID with data - for (lcid = DCCH; lcid < MAX_NUM_LCID; lcid++) { - if (UE_mac_inst[module_idP]. - logicalChannelConfig[lcid] != NULL) { - lcg_id = - UE_mac_inst[module_idP].scheduling_info. - LCGID[lcid]; - - if ((lcg_id < MAX_NUM_LCGID) - && (UE_mac_inst[module_idP]. - scheduling_info.BSR_bytes[lcg_id]) - && - (UE_mac_inst[module_idP].logicalChannelConfig - [lcid]->ul_SpecificParameters->priority <= - highest_priority)) { - highest_priority = - UE_mac_inst[module_idP]. - logicalChannelConfig[lcid]-> - ul_SpecificParameters->priority; - lcg_id_bsr_trunc = lcg_id; - } - } - } - } else { - //Report SHORT BSR, clear bsr_t - bsr_t = NULL; - } - - // Trigger BSR Padding - UE_mac_inst[module_idP].BSR_reporting_active |= - BSR_TRIGGER_PADDING; - } - - bsr_len = bsr_header_len + bsr_ce_len; - }*/ - - //Fill BSR Infos - if (bsr_ce_len == 0) { - bsr_s = NULL; - bsr_l = NULL; - bsr_t = NULL; - } - else { - LOG_W(MAC, "BSR not null \n"); - } - - // 1-bit padding or 2-bit padding special padding subheader - // Check for max padding size, ie MAC Hdr for last RLC PDU = 1 - if (sdu_length_total) { - padding_len = - buflen - (bsr_len + phr_len + total_rlc_pdu_header_len - - rlc_pdu_header_len_last + sdu_length_total + 1); - } else { - padding_len = buflen - (bsr_len + phr_len); - } - - if (padding_len <= 2) { - short_padding = padding_len; - // only add padding header - post_padding = 0; - - //update total MAC Hdr size for RLC data - if (sdu_length_total) { - total_rlc_pdu_header_len = - total_rlc_pdu_header_len - rlc_pdu_header_len_last + 1; - rlc_pdu_header_len_last = 1; - } - } else if (sdu_length_total) { - post_padding = - buflen - (bsr_len + phr_len + total_rlc_pdu_header_len + - sdu_length_total + 1); - - // If by adding MAC Hdr for last RLC PDU the padding is 0 then set MAC Hdr for last RLC PDU = 1 and compute 1 or 2 byte padding - if (post_padding == 0) { - total_rlc_pdu_header_len -= rlc_pdu_header_len_last; - padding_len = - buflen - (bsr_len + phr_len + total_rlc_pdu_header_len + - sdu_length_total + 1); - short_padding = padding_len; - total_rlc_pdu_header_len++; - } - } else { - if (padding_len == buflen) { // nona mac pdu - *access_mode = CANCELED_ACCESS; - } - - short_padding = 0; - post_padding = - buflen - (bsr_len + phr_len + total_rlc_pdu_header_len + - sdu_length_total + 1); - } - - // Generate header - // if (num_sdus>0) { - - // cycle through SDUs and place in ulsch_buffer - if (sdu_length_total) { - payload_offset = nr_generate_ulsch_header(ulsch_buffer, // mac header + // Generate ULSCH PDU + if (num_sdus>0) { + payload_offset = nr_generate_ulsch_pdu(ulsch_buffer, // mac header + ulsch_sdus, num_sdus, // num sdus - short_padding, // short pading sdu_lengths, // sdu length sdu_lcids, // sdu lcid - phr_p, // power headroom NULL, // crnti - bsr_t, // truncated bsr - bsr_s, // short bsr - bsr_l, post_padding); // long_bsr - LOG_D(MAC, - "[UE %d] Generate header :bufflen %d sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d, total_rlc_pdu_header_len %d, padding %d,post_padding %d, bsr len %d, phr len %d, reminder %d \n", - module_idP, buflen, sdu_length_total, num_sdus, sdu_lengths[0], - sdu_lcids[0], payload_offset, total_rlc_pdu_header_len, - short_padding, post_padding, bsr_len, phr_len, - buflen - sdu_length_total - payload_offset); - - - memcpy(&ulsch_buffer[payload_offset], ulsch_buff, - sdu_length_total); + buflen); // long_bsr } else return 0; + LOG_D(MAC, + "[UE %d] Generate header :bufflen %d sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d, total_rlc_pdu_header_len %d, post_padding %d, remainder %d \n", + module_idP, buflen, sdu_length_total, num_sdus, sdu_lengths[0], + sdu_lcids[0], payload_offset, total_rlc_pdu_header_len, + post_padding, buflen - sdu_length_total - payload_offset); - // fill remainder of DLSCH with random data - if (post_padding) { - for (j = 0; j < (buflen - sdu_length_total - payload_offset); j++) { - ulsch_buffer[payload_offset + sdu_length_total + j] = - (char) (taus() & 0xff); - } + // Padding: fill remainder of ULSCH with 0 + if (buflen - payload_offset > 0){ + for (int j = 0; j < (buflen - payload_offset); j++) + ulsch_buffer[payload_offset + j] = 0; } + #if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_D(MAC, "Printing UL MAC payload without the header UE side: \n"); - for (int i = payload_offset; i < sdu_length_total ; i++) { + LOG_I(MAC, "Printing UL MAC payload without the header UE side, payload_offset: %d \n", payload_offset); + for (int i = 0; i < sdu_length_total ; i++) { //harq_process_ul_ue->a[i] = (unsigned char) rand(); //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); printf("%02x ",(unsigned char)ulsch_buffer[i]); @@ -3039,9 +2606,4 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, #endif return 1; - } - - - - diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index 1615a8e687..a041f7cce3 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -34,6 +34,7 @@ #include "PHY/NR_TRANSPORT/nr_dlsch.h" #include "PHY/NR_TRANSPORT/nr_dci.h" #include "executables/nr-softmodem.h" +#include "LAYER2/NR_MAC_COMMON/nr_mac.h" extern RAN_CONTEXT_t RC; //#define ENABLE_MAC_PAYLOAD_DEBUG 1 @@ -549,7 +550,185 @@ void nr_schedule_uss_ulsch_phytest(nfapi_nr_ul_tti_request_t *UL_tti_req, } } -void +void nr_process_mac_pdu( + module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t *pduP, + uint16_t mac_pdu_len) +{ + + // This function is adapting code from the old + // parse_header(...) and ue_send_sdu(...) functions of OAI LTE + + uint8_t *pdu_ptr = pduP, rx_lcid, done = 0, i; + int pdu_len = mac_pdu_len; + uint16_t mac_ce_len, mac_subheader_len, mac_sdu_len; + + rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID; + + LOG_I(MAC, "LCID received at gNB side: %d \n", rx_lcid); + + // For both DL/UL-SCH + // Except: + // - UL/DL-SCH: fixed-size MAC CE(known by LCID) + // - UL/DL-SCH: padding + // - UL-SCH: MSG3 48-bits + // |0|1|2|3|4|5|6|7| bit-wise + // |R|F| LCID | + // | L | + // |0|1|2|3|4|5|6|7| bit-wise + // |R|F| LCID | + // | L | + // | L | + + // For both DL/UL-SCH + // For: + // - UL/DL-SCH: fixed-size MAC CE(known by LCID) + // - UL/DL-SCH: padding, for single/multiple 1-oct padding CE(s) + // - UL-SCH: MSG3 48-bits + // |0|1|2|3|4|5|6|7| bit-wise + // |R|R| LCID | + // LCID: The Logical Channel ID field identifies the logical channel instance of the corresponding MAC SDU or the type of the corresponding MAC CE or padding as described in Tables 6.2.1-1 and 6.2.1-2 for the DL-SCH and UL-SCH respectively. There is one LCID field per MAC subheader. The LCID field size is 6 bits; + // L: The Length field indicates the length of the corresponding MAC SDU or variable-sized MAC CE in bytes. There is one L field per MAC subheader except for subheaders corresponding to fixed-sized MAC CEs and padding. The size of the L field is indicated by the F field; + // F: lenght of L is 0:8 or 1:16 bits wide + // R: Reserved bit, set to zero. + + while (!done && pdu_len > 0){ + mac_ce_len = 0; + mac_subheader_len = 1; // default to fixed-length subheader = 1-oct + mac_sdu_len = 0; + rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID; + + LOG_I(MAC, "LCID received at gNB side: %d \n", rx_lcid); + + switch(rx_lcid){ + // MAC CE + + /*#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID, pdu_len); + #endif*/ + + case UL_SCH_LCID_PADDING: + done = 1; + // end of MAC PDU, can ignore the rest. + break; + + case UL_SCH_LCID_DTCH: + // check if LCID is valid at current time. + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + //mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L1 & 0x7f) << 8) + | ((uint16_t)((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L2 & 0xff); + + } else { + mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + } + + LOG_D(MAC, "[UE %d] Frame %d : DLSCH -> DL-DTCH %d (gNB %d, %d bytes)\n", module_idP, frameP, rx_lcid, module_idP, mac_sdu_len); + + #if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP); + + for (i = 0; i < 32; i++) + LOG_T(MAC, "%x.", (pdu_ptr + mac_subheader_len)[i]); + + LOG_T(MAC, "\n"); + #endif + + if (IS_SOFTMODEM_NOS1){ + if (rx_lcid < NB_RB_MAX && rx_lcid >= UL_SCH_LCID_DTCH) { + + mac_rlc_data_ind(module_idP, + 0x1234, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + rx_lcid, + (char *) (pdu_ptr + mac_subheader_len), + mac_sdu_len, + 1, + NULL); + } else { + LOG_E(MAC, "[UE %d] Frame %d : unknown LCID %d (gNB %d)\n", module_idP, frameP, rx_lcid, module_idP); + } + } + + break; + + default: + return; + break; + } + pdu_ptr += ( mac_subheader_len + mac_ce_len + mac_sdu_len ); + pdu_len -= ( mac_subheader_len + mac_ce_len + mac_sdu_len ); + + AssertFatal(pdu_len >= 0, "[MAC] nr_process_mac_pdu, residual mac pdu length < 0!\n"); + } +} + +void nr_rx_sdu(module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t ttiP, + const rnti_t rntiP, + uint8_t * pdu, + const uint16_t pdu_len, + const uint16_t timing_advance, + const uint8_t ul_cqi) +{ + + LOG_I(MAC, "Handling PDU frame %d slot %d pdu_len: %d \n", frameP, ttiP, pdu_len); + + uint8_t * pduP = pdu; + + + /*if (opt_enabled) { + trace_pdu(DIRECTION_DOWNLINK, pduP, pdu_len, module_idP, WS_C_RNTI, + UE_mac_inst[module_idP].cs_RNTI, frameP, ttiP, 0, 0); //subframeP + LOG_D(OPT, "[UE %d][DLSCH] Frame %d trace pdu for rnti %x with size %d\n", + module_idP, frameP, UE_mac_inst[module_idP].cs_RNTI, pdu_len); + }*/ + + /* + #ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE %d] ue_send_sdu : Frame %d gNB_index %d : num_ce %d num_sdu %d\n", + module_idP, frameP, gNB_index, num_ce, num_sdu); + #endif + */ + + /* + #if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP); + for (i = 0; i < 32; i++) { + LOG_T(MAC, "%x.", sdu[i]); + } + LOG_T(MAC, "\n"); + #endif + */ + + // Processing MAC PDU + // it parses MAC CEs subheaders, MAC CEs, SDU subheaderds and SDUs + if (pduP != NULL){ + LOG_I(MAC, "Received PDU at MAC gNB \n"); + nr_process_mac_pdu(module_idP, CC_id, frameP, pduP, pdu_len); + } + + //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SEND_SDU, VCD_FUNCTION_OUT); + + /* + #if UE_TIMING_TRACE + stop_meas(&UE_mac_inst[module_idP].rx_dlsch_sdu); + #endif + */ +} + + +/* LTE based function to be substituted once NR version is ready */ +/*void nr_rx_sdu(const module_id_t enb_mod_idP, const int CC_idP, const frame_t frameP, @@ -582,7 +761,7 @@ nr_rx_sdu(const module_id_t enb_mod_idP, rrc_eNB_ue_context_t *ue_contextP = NULL; UE_sched_ctrl_t *UE_scheduling_control = NULL; UE_TEMPLATE *UE_template_ptr = NULL; - /* Init */ + // Init current_rnti = rntiP; UE_id = 0; //find_UE_id(enb_mod_idP, current_rnti); //mac = RC.mac[enb_mod_idP]; @@ -604,7 +783,7 @@ nr_rx_sdu(const module_id_t enb_mod_idP, return; } - /* Control element */ + // Control element for (int i = 0; i < num_ce; i++) { switch (rx_ces[i]) { // implement and process PHR + CRNTI + BSR @@ -690,7 +869,7 @@ nr_rx_sdu(const module_id_t enb_mod_idP, rx_lcids[i]); if (UE_id != -1) { - /* Adjust buffer occupancy of the correponding logical channel group */ + // Adjust buffer occupancy of the correponding logical channel group LOG_D(MAC, "[eNB %d] CC_id %d Frame %d : ULSCH -> UL-DTCH, received %d bytes from UE %d for lcid %d \n", enb_mod_idP, CC_idP, @@ -709,14 +888,15 @@ nr_rx_sdu(const module_id_t enb_mod_idP, pritnf("\n"); #endif mac_rlc_data_ind(enb_mod_idP, current_rnti, enb_mod_idP, frameP, ENB_FLAG_YES, MBMS_FLAG_NO, rx_lcids[i], (char *) payload_ptr+1, rx_lengths[i], 1, NULL); - } else { /* rx_length[i] Max size */ + } else { // rx_length[i] Max size //UE_list->eNB_UE_stats[CC_idP][UE_id].num_errors_rx += 1; - LOG_E(MAC, "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d ", + LOG_E(MAC, "[eNB %d] CC_id %d Frame %d : Max size of transport block reached LCID %d from UE %d. Size of received payload: %d \n", enb_mod_idP, CC_idP, frameP, rx_lcids[i], - UE_id); + UE_id, + rx_lengths[i]); } } else { // end if (UE_id != -1) LOG_E(MAC,"[eNB %d] CC_id %d Frame %d : received unsupported or unknown LCID %d from UE %d ", @@ -734,32 +914,5 @@ nr_rx_sdu(const module_id_t enb_mod_idP, payload_ptr += rx_lengths[i]; } - /* Program ACK for PHICH */ - - /*LOG_D(MAC, "Programming PHICH ACK for rnti %x harq_pid %d (first_rb %d)\n", - current_rnti, - harq_pid, - first_rb); - nfapi_hi_dci0_request_t *hi_dci0_req; - uint8_t sf_ahead_dl = ul_subframe2_k_phich(&mac->common_channels[CC_idP], subframeP); - hi_dci0_req = &mac->HI_DCI0_req[CC_idP][(subframeP+sf_ahead_dl)%10]; - nfapi_hi_dci0_request_body_t *hi_dci0_req_body = &hi_dci0_req->hi_dci0_request_body; - nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu = &hi_dci0_req_body->hi_dci0_pdu_list[hi_dci0_req_body->number_of_dci + - hi_dci0_req_body->number_of_hi]; - memset((void *) hi_dci0_pdu, 0, sizeof(nfapi_hi_dci0_request_pdu_t)); - hi_dci0_pdu->pdu_type = NFAPI_HI_DCI0_HI_PDU_TYPE; - hi_dci0_pdu->pdu_size = 2 + sizeof(nfapi_hi_dci0_hi_pdu); - hi_dci0_pdu->hi_pdu.hi_pdu_rel8.tl.tag = NFAPI_HI_DCI0_REQUEST_HI_PDU_REL8_TAG; - hi_dci0_pdu->hi_pdu.hi_pdu_rel8.resource_block_start = first_rb; - hi_dci0_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms = 0; - hi_dci0_pdu->hi_pdu.hi_pdu_rel8.hi_value = 1; - hi_dci0_req_body->number_of_hi++; - hi_dci0_req_body->sfnsf = sfnsf_add_subframe(frameP,subframeP, 0); - hi_dci0_req_body->tl.tag = NFAPI_HI_DCI0_REQUEST_BODY_TAG; - hi_dci0_req->sfn_sf = sfnsf_add_subframe(frameP,subframeP, sf_ahead_dl); - hi_dci0_req->header.message_id = NFAPI_HI_DCI0_REQUEST;*/ - - /* NN--> FK: we could either check the payload, or use a phy helper to detect a false msg3 */ - -} +}*/ diff --git a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h index 95abba549a..77d6053a35 100644 --- a/openair2/LAYER2/NR_MAC_gNB/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_gNB/mac_proto.h @@ -145,15 +145,21 @@ void config_nr_mib(int Mod_idP, int cellBarred, int intraFreqReselection); -void -nr_rx_sdu(const module_id_t enb_mod_idP, - const int CC_idP, - const frame_t frameP, - const sub_frame_t subframeP, - const rnti_t rntiP, - uint8_t *sduP, - const uint16_t sdu_lenP, - const uint16_t timing_advance, - const uint8_t ul_cqi); +void nr_rx_sdu(module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t ttiP, + const rnti_t rntiP, + uint8_t * pdu, + uint16_t pdu_len, + const uint16_t timing_advance, + const uint8_t ul_cqi); + +void nr_process_mac_pdu( + module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t *pduP, + uint16_t mac_pdu_len); #endif /*__LAYER2_NR_MAC_PROTO_H__*/ diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c index 2094b3517e..6a6dc74695 100644 --- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c @@ -192,7 +192,7 @@ void handle_nr_ulsch(NR_UL_IND_t *UL_info) { UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi); } else { - LOG_D(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok) \n",UL_info->frame,UL_info->slot); + LOG_I(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok), received length: %d \n",UL_info->frame,UL_info->slot, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length); nr_rx_sdu(UL_info->module_id, UL_info->CC_id, NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf), //UL_info->frame, From 93ac6bd4261b457ed8feb4d16477be90b3ae71b9 Mon Sep 17 00:00:00 2001 From: matzakos Date: Thu, 6 Feb 2020 18:21:12 +0100 Subject: [PATCH 07/73] nr-ip-UL-nos1: Substitute LTE macros in new NR functions and data structures + logs cleanup --- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 4 +- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 2 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 2 +- openair2/LAYER2/NR_MAC_COMMON/nr_mac.h | 3 + openair2/LAYER2/NR_MAC_UE/mac.h | 61 ------------------- openair2/LAYER2/NR_MAC_UE/mac_defs.h | 37 +++-------- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 11 ++-- .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 41 +------------ openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c | 2 +- openair2/NR_PHY_INTERFACE/NR_IF_Module.c | 2 +- 10 files changed, 27 insertions(+), 138 deletions(-) diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index 5717b32805..547dd523ca 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -192,7 +192,7 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, //Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid //and block this traffic from being forwarded to the upper layers at the gNB uint16_t payload_offset = 5; - LOG_E(PHY, "Random data to be tranmsitted: \n"); + LOG_D(PHY, "Random data to be tranmsitted: \n"); //Give the header bytes some dummy value in order to block the random packet at the MAC layer of the receiver for (i = 0; ia[i] = 0; @@ -426,7 +426,7 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, /////////// //////////////////////////////////////////////////////////////////////// - LOG_I(PHY, "Is data existing ?: %d \n", data_existing); + LOG_D(PHY, "Is data existing ?: %d \n", data_existing); return data_existing; } diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 4dd67d373f..2d92f63e6b 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -288,7 +288,7 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int UE_id LOG_I(PHY, "ULSCH in error\n"); //gNB->ulsch[UE_id+1][0]->harq_processes[harq_pid]->b else if(gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->b!=NULL){ - LOG_D(PHY, "ULSCH received ok \n"); + LOG_I(PHY, "ULSCH received ok \n"); if(IS_SOFTMODEM_NOS1){ //&& gNB->ulsch[UE_id][0]->rnti == 0x1234 nr_fill_crc_indication (gNB, UE_id, frame_rx, slot_rx, 0); nr_fill_rx_indication(gNB, frame_rx, slot_rx, UE_id, harq_pid); diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 568ef5f736..6282e81066 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2502,7 +2502,7 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, } // UE_mode==PUSCH */ - LOG_I(PHY, "Sending data \n"); + LOG_D(PHY, "Sending data \n"); nr_ue_pusch_common_procedures(ue, harq_pid, slot_tx, diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h index cb004e0c23..80bfec6cf9 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h @@ -133,6 +133,9 @@ typedef struct { #define UL_SCH_LCID_L_BSR 0x3E #define UL_SCH_LCID_PADDING 0x3F +#define NR_MAX_NUM_LCID 32 +#define NR_MAX_NUM_LCGID 8 + #endif /*__LAYER2_MAC_H__ */ diff --git a/openair2/LAYER2/NR_MAC_UE/mac.h b/openair2/LAYER2/NR_MAC_UE/mac.h index fe8e91500a..25e5ded996 100644 --- a/openair2/LAYER2/NR_MAC_UE/mac.h +++ b/openair2/LAYER2/NR_MAC_UE/mac.h @@ -49,65 +49,4 @@ typedef enum { UE_PHY_HO_PRACH } NR_UE_L2_STATE_t; -typedef struct { - uint8_t LCID:6; // octet 1 [5:0] - uint8_t F:1; // octet 1 [6] - uint8_t R:1; // octet 1 [7] - uint8_t L:8; // octet 2 [7:0] -} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_SHORT; - -typedef struct { - uint8_t LCID:6; // octet 1 [5:0] - uint8_t F:1; // octet 1 [6] - uint8_t R:1; // octet 1 [7] - uint8_t L1:8; // octet 2 [7:0] - uint8_t L2:8; // octet 3 [7:0] -} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_LONG; - -typedef struct { - uint8_t LCID:6; // octet 1 [5:0] - uint8_t R:2; // octet 1 [7:6] -} __attribute__ ((__packed__)) NR_MAC_SUBHEADER_FIXED; - -// 38.321 ch6.2.1, 38.331 -#define DL_SCH_LCID_CCCH 0x00 -#define DL_SCH_LCID_SRB1 0x01 -#define DL_SCH_LCID_SRB2 0x02 -#define DL_SCH_LCID_SRB3 0x03 -#define DL_SCH_LCID_RECOMMENDED_BITRATE 0x2F -#define DL_SCH_LCID_SP_ZP_CSI_RS_RES_SET_ACT 0x30 -#define DL_SCH_LCID_PUCCH_SPATIAL_RELATION_ACT 0x31 -#define DL_SCH_LCID_SP_SRS_ACTIVATION 0x32 -#define DL_SCH_LCID_SP_CSI_REP_PUCCH_ACT 0x33 -#define DL_SCH_LCID_TCI_STATE_IND_UE_SPEC_PDCCH 0x34 -#define DL_SCH_LCID_TCI_STATE_ACT_UE_SPEC_PDSCH 0x35 -#define DL_SCH_LCID_APERIODIC_CSI_TRI_STATE_SUBSEL 0x36 -#define DL_SCH_LCID_SP_CSI_RS_CSI_IM_RES_SET_ACT 0X37 -#define DL_SCH_LCID_DUPLICATION_ACT 0X38 -#define DL_SCH_LCID_SCell_ACT_4_OCT 0X39 -#define DL_SCH_LCID_SCell_ACT_1_OCT 0X3A -#define DL_SCH_LCID_L_DRX 0x3B -#define DL_SCH_LCID_DRX 0x3C -#define DL_SCH_LCID_TA_COMMAND 0x3D -#define DL_SCH_LCID_CON_RES_ID 0x3E -#define DL_SCH_LCID_PADDING 0x3F - -#define UL_SCH_LCID_CCCH 0x00 -#define UL_SCH_LCID_SRB1 0x01 -#define UL_SCH_LCID_SRB2 0x02 -#define UL_SCH_LCID_SRB3 0x03 -#define UL_SCH_LCID_CCCH_MSG3 0x21 -#define UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY 0x35 -#define UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT 0x36 -#define UL_SCH_LCID_CONFIGURED_GRANT_CONFIRMATION 0x37 -#define UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT 0x38 -#define UL_SCH_LCID_SINGLE_ENTRY_PHR 0x39 -#define UL_SCH_LCID_C_RNTI 0x3A -#define UL_SCH_LCID_S_TRUNCATED_BSR 0x3B -#define UL_SCH_LCID_L_TRUNCATED_BSR 0x3C -#define UL_SCH_LCID_S_BSR 0x3D -#define UL_SCH_LCID_L_BSR 0x3E -#define UL_SCH_LCID_PADDING 0x3F - - #endif /*__LAYER2_MAC_DEFS_H__ */ diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h index 534f3bf9c3..b97d4696e7 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h @@ -51,12 +51,11 @@ #include "fapi_nr_ue_interface.h" #include "NR_IF_Module.h" #include "PHY/defs_nr_common.h" +#include "openair2/LAYER2/NR_MAC_COMMON/nr_mac.h" #define NB_NR_UE_MAC_INST 1 /*!\brief Maximum number of logical channl group IDs */ -#define MAX_NUM_LCGID 4 -/*!\brief Maximum number of logical chanels */ -#define MAX_NUM_LCID 11 + /*!\brief value for indicating BSR Timer is not running */ #define NR_MAC_UE_BSR_TIMER_NOT_RUNNING (0xFFFF) @@ -67,42 +66,24 @@ typedef enum { SFN_C_IMPOSSIBLE } SFN_C_TYPE; -#define UL_SCH_LCID_CCCH 0x00 -#define UL_SCH_LCID_SRB1 0x01 -#define UL_SCH_LCID_SRB2 0x02 -#define UL_SCH_LCID_DTCH 0x03 -#define UL_SCH_LCID_SRB3 0x04 -#define UL_SCH_LCID_CCCH_MSG3 0x21 -#define UL_SCH_LCID_RECOMMENDED_BITRATE_QUERY 0x35 -#define UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT 0x36 -#define UL_SCH_LCID_CONFIGURED_GRANT_CONFIRMATION 0x37 -#define UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT 0x38 -#define UL_SCH_LCID_SINGLE_ENTRY_PHR 0x39 -#define UL_SCH_LCID_C_RNTI 0x3A -#define UL_SCH_LCID_S_TRUNCATED_BSR 0x3B -#define UL_SCH_LCID_L_TRUNCATED_BSR 0x3C -#define UL_SCH_LCID_S_BSR 0x3D -#define UL_SCH_LCID_L_BSR 0x3E -#define UL_SCH_LCID_PADDING 0x3F - // LTE structure, might need to be adapted for NR typedef struct { /// buffer status for each lcgid - uint8_t BSR[MAX_NUM_LCGID]; // should be more for mesh topology + uint8_t BSR[NR_MAX_NUM_LCGID]; // should be more for mesh topology /// keep the number of bytes in rlc buffer for each lcgid - int32_t BSR_bytes[MAX_NUM_LCGID]; + int32_t BSR_bytes[NR_MAX_NUM_LCGID]; /// after multiplexing buffer remain for each lcid - int32_t LCID_buffer_remain[MAX_NUM_LCID]; + int32_t LCID_buffer_remain[NR_MAX_NUM_LCID]; /// sum of all lcid buffer size uint16_t All_lcid_buffer_size_lastTTI; /// buffer status for each lcid - uint8_t LCID_status[MAX_NUM_LCID]; + uint8_t LCID_status[NR_MAX_NUM_LCID]; /// SR pending as defined in 36.321 uint8_t SR_pending; /// SR_COUNTER as defined in 36.321 uint16_t SR_COUNTER; /// logical channel group ide for each LCID - uint8_t LCGID[MAX_NUM_LCID]; + uint8_t LCGID[NR_MAX_NUM_LCID]; /// retxBSR-Timer, default value is sf2560 uint16_t retxBSR_Timer; /// retxBSR_SF, number of subframe before triggering a regular BSR @@ -142,9 +123,9 @@ typedef struct { uint16_t extendedPHR_r10; //Bj bucket usage per lcid - int16_t Bj[MAX_NUM_LCID]; + int16_t Bj[NR_MAX_NUM_LCID]; // Bucket size per lcid - int16_t bucket_size[MAX_NUM_LCID]; + int16_t bucket_size[NR_MAX_NUM_LCID]; } NR_UE_SCHEDULING_INFO; diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index ceff5baaa7..df27f5b8db 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -36,9 +36,10 @@ #include "assertions.h" #include "PHY/defs_nr_UE.h" #include "common/utils/LOG/log.h" -#include "openair2/LAYER2/MAC/mac.h" -#include "openair2/LAYER2/RLC/rlc.h" +//#include "openair2/LAYER2/MAC/mac.h" +//#include "openair2/LAYER2/RLC/rlc.h" #include "SIMULATION/TOOLS/sim.h" // for taus +#include "openair2/LAYER2/NR_MAC_COMMON/nr_mac.h" #include #include @@ -2184,7 +2185,7 @@ void nr_ue_process_mac_pdu( break; // MAC SDU - case DL_SCH_LCID_SRB1: + case DL_SCH_LCID_DCCH: // check if LCID is valid at current time. case UL_SCH_LCID_SRB2: // check if LCID is valid at current time. @@ -2506,8 +2507,8 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, // Check for DCCH first // TO DO: Multiplex in the order defined by the logical channel prioritization - for (lcid = DCCH; - lcid < MAX_NUM_LCID; lcid++) { + for (lcid = UL_SCH_LCID_SRB1; + lcid < NR_MAX_NUM_LCID; lcid++) { lcid_buffer_occupancy_old = //TODO: Replace static value with CRNTI diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index a041f7cce3..cabaee7b5c 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -565,9 +565,6 @@ void nr_process_mac_pdu( int pdu_len = mac_pdu_len; uint16_t mac_ce_len, mac_subheader_len, mac_sdu_len; - rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID; - - LOG_I(MAC, "LCID received at gNB side: %d \n", rx_lcid); // For both DL/UL-SCH // Except: @@ -600,7 +597,7 @@ void nr_process_mac_pdu( mac_sdu_len = 0; rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID; - LOG_I(MAC, "LCID received at gNB side: %d \n", rx_lcid); + LOG_D(MAC, "LCID received at gNB side: %d \n", rx_lcid); switch(rx_lcid){ // MAC CE @@ -681,49 +678,17 @@ void nr_rx_sdu(module_id_t module_idP, const uint8_t ul_cqi) { - LOG_I(MAC, "Handling PDU frame %d slot %d pdu_len: %d \n", frameP, ttiP, pdu_len); + LOG_D(MAC, "Handling PDU frame %d slot %d pdu_len: %d \n", frameP, ttiP, pdu_len); uint8_t * pduP = pdu; - - /*if (opt_enabled) { - trace_pdu(DIRECTION_DOWNLINK, pduP, pdu_len, module_idP, WS_C_RNTI, - UE_mac_inst[module_idP].cs_RNTI, frameP, ttiP, 0, 0); //subframeP - LOG_D(OPT, "[UE %d][DLSCH] Frame %d trace pdu for rnti %x with size %d\n", - module_idP, frameP, UE_mac_inst[module_idP].cs_RNTI, pdu_len); - }*/ - - /* - #ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE %d] ue_send_sdu : Frame %d gNB_index %d : num_ce %d num_sdu %d\n", - module_idP, frameP, gNB_index, num_ce, num_sdu); - #endif - */ - - /* - #if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP); - for (i = 0; i < 32; i++) { - LOG_T(MAC, "%x.", sdu[i]); - } - LOG_T(MAC, "\n"); - #endif - */ - // Processing MAC PDU // it parses MAC CEs subheaders, MAC CEs, SDU subheaderds and SDUs if (pduP != NULL){ - LOG_I(MAC, "Received PDU at MAC gNB \n"); + LOG_D(MAC, "Received PDU at MAC gNB \n"); nr_process_mac_pdu(module_idP, CC_id, frameP, pduP, pdu_len); } - //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SEND_SDU, VCD_FUNCTION_OUT); - - /* - #if UE_TIMING_TRACE - stop_meas(&UE_mac_inst[module_idP].rx_dlsch_sdu); - #endif - */ } diff --git a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c index 5305dd6f50..84260acbd1 100644 --- a/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c +++ b/openair2/LAYER2/nr_rlc/nr_rlc_oai_api.c @@ -78,7 +78,7 @@ void mac_rlc_data_ind ( } if (rb != NULL) { - LOG_W(RLC, "RB found! (channel ID %d) \n", channel_idP); + LOG_D(RLC, "RB found! (channel ID %d) \n", channel_idP); rb->set_time(rb, nr_rlc_current_time); rb->recv_pdu(rb, buffer_pP, tb_sizeP); } else { diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c index 6a6dc74695..cc52648ff0 100644 --- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c @@ -192,7 +192,7 @@ void handle_nr_ulsch(NR_UL_IND_t *UL_info) { UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi); } else { - LOG_I(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok), received length: %d \n",UL_info->frame,UL_info->slot, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length); + LOG_D(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok), received length: %d \n",UL_info->frame,UL_info->slot, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length); nr_rx_sdu(UL_info->module_id, UL_info->CC_id, NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf), //UL_info->frame, From 626daecfa5acc6180fbc30e149e92aeda7a03967 Mon Sep 17 00:00:00 2001 From: matzakos Date: Fri, 7 Feb 2020 19:51:19 +0100 Subject: [PATCH 08/73] nr-ip-UL-nos1: Fix packet corruption issue appearing with larger packet sizes based on iperf testing for the uplink --- openair2/LAYER2/NR_MAC_COMMON/nr_mac.h | 1 + openair2/LAYER2/NR_MAC_UE/mac_proto.h | 2 +- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 60 ++++++++++++-------- 3 files changed, 39 insertions(+), 24 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h index 80bfec6cf9..5801fabcfb 100644 --- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h +++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h @@ -135,6 +135,7 @@ typedef struct { #define NR_MAX_NUM_LCID 32 #define NR_MAX_NUM_LCGID 8 +#define MAX_RLC_SDU_SUBHEADER_SIZE 3 #endif /*__LAYER2_MAC_H__ */ diff --git a/openair2/LAYER2/NR_MAC_UE/mac_proto.h b/openair2/LAYER2/NR_MAC_UE/mac_proto.h index 9ddb47601d..ea9ead80c3 100755 --- a/openair2/LAYER2/NR_MAC_UE/mac_proto.h +++ b/openair2/LAYER2/NR_MAC_UE/mac_proto.h @@ -140,7 +140,7 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t subframe, uint8_t eNB_index, uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode); -unsigned char +uint16_t nr_generate_ulsch_pdu(uint8_t *mac_pdu, uint8_t *sdus_payload, uint8_t num_sdus, diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index df27f5b8db..02749a70dd 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -2319,7 +2319,7 @@ unsigned char *nr_parse_header(unsigned char *mac_header, return (mac_header_ptr); } -unsigned char +uint16_t nr_generate_ulsch_pdu(uint8_t *mac_pdu, uint8_t *sdus_payload, uint8_t num_sdus, @@ -2331,7 +2331,7 @@ nr_generate_ulsch_pdu(uint8_t *mac_pdu, NR_MAC_SUBHEADER_FIXED *mac_pdu_ptr = (NR_MAC_SUBHEADER_FIXED *) mac_pdu; unsigned char * ulsch_buffer_ptr = sdus_payload; uint8_t last_size=0; - uint16_t sdu_length_total; + uint16_t sdu_length_total=0; int i; int offset=0; @@ -2359,11 +2359,15 @@ nr_generate_ulsch_pdu(uint8_t *mac_pdu, // 3) cycle through SDUs, compute each relevant and place dlsch_buffer in memcpy((void *) mac_pdu_ptr, (void *) ulsch_buffer_ptr, sdu_lengths[i]); ulsch_buffer_ptr+= sdu_lengths[i]; + sdu_length_total+= sdu_lengths[i]; mac_pdu_ptr += sdu_lengths[i]; } + offset = ((unsigned char *) mac_pdu_ptr - mac_pdu); + // 4) Compute final offset for padding - uint16_t padding_bytes = buflen - sdu_length_total; + uint16_t padding_bytes = buflen - offset; + LOG_D(MAC, "Number of padding bytes: %d \n", padding_bytes); if (padding_bytes > 0) { ((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->R = 0; ((NR_MAC_SUBHEADER_FIXED *) mac_pdu_ptr)->LCID = UL_SCH_LCID_PADDING; @@ -2373,9 +2377,6 @@ nr_generate_ulsch_pdu(uint8_t *mac_pdu, // no MAC subPDU with padding } - offset = ((unsigned char *) mac_pdu_ptr - mac_pdu); - - return offset; } @@ -2482,11 +2483,11 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t subframe, uint8_t eNB_index, uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) { uint8_t total_rlc_pdu_header_len = 0, rlc_pdu_header_len_last = 0; - uint16_t buflen_remain = 0; + int16_t buflen_remain = 0; uint8_t lcid = 0; uint16_t sdu_lengths[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; uint8_t sdu_lcids[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - uint8_t payload_offset = 0, num_sdus = 0; + uint16_t payload_offset = 0, num_sdus = 0; uint8_t ulsch_sdus[MAX_ULSCH_PAYLOAD_BYTES]; uint16_t sdu_length_total = 0; unsigned short post_padding = 0, padding_len = 0; @@ -2521,13 +2522,15 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, if(lcid_buffer_occupancy_new){ buflen_remain = - buflen - (total_rlc_pdu_header_len + sdu_length_total + MIN_MAC_HDR_RLC_SIZE); + buflen - (total_rlc_pdu_header_len + sdu_length_total + MAX_RLC_SDU_SUBHEADER_SIZE); LOG_D(MAC, - "[UE %d] Frame %d : UL-DXCH -> ULSCH, RLC %d has %d bytes to " - "send (Transport Block size %d SDU Length Total %d , mac header len %d )\n", //BSR byte before Tx=%d + "[UE %d] Frame %d : Before while loop UL-DXCH -> ULSCH, RLC %d has %d bytes to " + "send (Transport Block size %d SDU Length Total %d , mac header len %d, buflen_remain %d )\n", //BSR byte before Tx=%d module_idP, frameP, lcid, lcid_buffer_occupancy_new, buflen, sdu_length_total, - total_rlc_pdu_header_len); // ,nr_ue_mac_inst->scheduling_info.BSR_bytes[nr_ue_mac_inst->scheduling_info.LCGID[lcid]] + total_rlc_pdu_header_len, buflen_remain); // ,nr_ue_mac_inst->scheduling_info.BSR_bytes[nr_ue_mac_inst->scheduling_info.LCGID[lcid]] + + while(buflen_remain > 0 && lcid_buffer_occupancy_new){ //TODO: Replace static value with CRNTI sdu_lengths[num_sdus] = mac_rlc_data_req(module_idP, @@ -2547,27 +2550,38 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, if (sdu_lengths[num_sdus]) { sdu_length_total += sdu_lengths[num_sdus]; sdu_lcids[num_sdus] = lcid; - //LOG_I(MAC, - // "[UE %d] TX Multiplex RLC PDU TX Got %d bytes for LcId%d\n", - // module_idP, sdu_lengths[num_sdus], lcid); + + + //Update total MAC Header size for RLC PDUs + /*if(sdu_lengths[num_sdus]<128) + total_rlc_pdu_header_len += 2; + else + total_rlc_pdu_header_len += 3;*/ + + total_rlc_pdu_header_len += MAX_RLC_SDU_SUBHEADER_SIZE; //rlc_pdu_header_len_last; //Update number of SDU num_sdus++; - //Update total MAC Header size for RLC PDUs and save last one - total_rlc_pdu_header_len += rlc_pdu_header_len_last; } /* Get updated BO after multiplexing this PDU */ //TODO: Replace static value with CRNTI - /*lcid_buffer_occupancy_new = + lcid_buffer_occupancy_new = mac_rlc_get_buffer_occupancy_ind(module_idP, 0x1234, //nr_ue_mac_inst->crnti eNB_index, frameP, subframe, ENB_FLAG_NO, lcid); - is_lcid_processed = (is_lcid_processed) - || (lcid_buffer_occupancy_new <= 0);*/ + buflen_remain = + buflen - (total_rlc_pdu_header_len + sdu_length_total + MAX_RLC_SDU_SUBHEADER_SIZE); + LOG_D(MAC, + "[UE %d] Frame %d : UL-DXCH -> ULSCH, RLC %d has %d bytes to " + "send (Transport Block size %d SDU Length Total %d , mac header len %d, buflen_remain %d )\n", //BSR byte before Tx=%d + module_idP, frameP, lcid, lcid_buffer_occupancy_new, + buflen, sdu_length_total, + total_rlc_pdu_header_len, buflen_remain); + } } } @@ -2592,13 +2606,13 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, // Padding: fill remainder of ULSCH with 0 if (buflen - payload_offset > 0){ - for (int j = 0; j < (buflen - payload_offset); j++) - ulsch_buffer[payload_offset + j] = 0; + for (int j = payload_offset; j < buflen; j++) + ulsch_buffer[j] = 0; } #if defined(ENABLE_MAC_PAYLOAD_DEBUG) LOG_I(MAC, "Printing UL MAC payload without the header UE side, payload_offset: %d \n", payload_offset); - for (int i = 0; i < sdu_length_total ; i++) { + for (int i = 0; i < buflen ; i++) { //harq_process_ul_ue->a[i] = (unsigned char) rand(); //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); printf("%02x ",(unsigned char)ulsch_buffer[i]); From 2520a922112749ae43713895b8f63a0c07b45172 Mon Sep 17 00:00:00 2001 From: frtabu Date: Mon, 10 Feb 2020 08:59:16 +0100 Subject: [PATCH 09/73] modify telnet serveur build to support all exec's --- common/utils/telnetsrv/telnetsrv.c | 3 + .../utils/telnetsrv/telnetsrv_CMakeLists.txt | 26 +++- .../utils/telnetsrv/telnetsrv_measurements.c | 136 ++--------------- .../utils/telnetsrv/telnetsrv_measurements.h | 23 ++- common/utils/telnetsrv/telnetsrv_phycmd.c | 142 ------------------ 5 files changed, 55 insertions(+), 275 deletions(-) delete mode 100644 common/utils/telnetsrv/telnetsrv_phycmd.c diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c index 44ab07a49b..6626c8103b 100644 --- a/common/utils/telnetsrv/telnetsrv.c +++ b/common/utils/telnetsrv/telnetsrv.c @@ -709,6 +709,9 @@ int add_sharedmodules(void) { return ret; } +/* autoinit functions is called by the loader when the telnet shared library is + dynamically loaded +*/ int telnetsrv_autoinit(void) { memset(&telnetparams,0,sizeof(telnetparams)); config_get( telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t),"telnetsrv"); diff --git a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt index 05c99aabb8..519a1a72ff 100644 --- a/common/utils/telnetsrv/telnetsrv_CMakeLists.txt +++ b/common/utils/telnetsrv/telnetsrv_CMakeLists.txt @@ -2,20 +2,32 @@ set(TELNETROOT ${OPENAIR_DIR}/common/utils/telnetsrv ) set(TELNETSRV_SOURCE ${TELNETROOT}/telnetsrv.c - ${TELNETROOT}/telnetsrv_phycmd.c ${TELNETROOT}/telnetsrv_proccmd.c ${TELNETROOT}/telnetsrv_loader.c ${TELNETROOT}/telnetsrv_measurements.c ) - -#set(TELNETSRV_ETHDEVCMD_SOURCE -# ${APPROOT}/telnetsrv/telnetsrv_ethdevcmd.c -# ) - + add_library(telnetsrv MODULE ${TELNETSRV_SOURCE} ) -#add_library(telnetsrv_ethdevcmd MODULE ${TELNETSRV_ETHDEVCMD_SOURCE} ) target_link_libraries(telnetsrv PRIVATE history) +foreach(TELNETLIB enb gnb 4gUE 5gUE) + set(TELNETLIB_SRCS "") + foreach(TELNETLIB_ASRC measurements phycmd) + set(TELNETLIB_SRC ${OPENAIR_DIR}/common/utils/telnetsrv/telnetsrv_${TELNETLIB}_${TELNETLIB_ASRC}.c) + if (EXISTS ${TELNETLIB_SRC}) + set( TELNETLIB_SRCS "${TELNETLIB_SRC};${TELNETLIB_SRCS}") + endif() + endforeach() + if(NOT "${TELNETLIB_SRCS}" STREQUAL "") + message("Add ${TELNETLIB} specific telnet functions in libtelnetsrv_${TELNETLIB}.so") + add_library(telnetsrv_${TELNETLIB} MODULE ${TELNETLIB_SRCS} ) + add_dependencies(telnetsrv telnetsrv_${TELNETLIB}) + install(TARGETS telnetsrv_${TELNETLIB} DESTINATION bin) + else() + message("No specific telnet functions for ${TELNETLIB}") + endif() +endforeach() + install(TARGETS telnetsrv DESTINATION bin) if (EXISTS "${OPENAIR_BUILD_DIR}/ran_build/build" AND IS_DIRECTORY "${OPENAIR_BUILD_DIR}/ran_build/build") diff --git a/common/utils/telnetsrv/telnetsrv_measurements.c b/common/utils/telnetsrv/telnetsrv_measurements.c index 7cfc656225..4a11e7c2dd 100644 --- a/common/utils/telnetsrv/telnetsrv_measurements.c +++ b/common/utils/telnetsrv/telnetsrv_measurements.c @@ -20,9 +20,9 @@ */ /*! \file common/utils/telnetsrv/telnetsrv_measurements.c - * \brief: implementation of telnet commands related to measurments + * \brief: implementation of telnet measurement functions common to all softmodems * \author Francois TABURET - * \date 2019 + * \date 2020 * \version 0.1 * \company NOKIA BellLabs France * \email: francois.taburet@nokia-bell-labs.com @@ -47,40 +47,18 @@ #include "common/utils/LOG/log.h" #include "common/config/config_userapi.h" #include "telnetsrv_measurements.h" -#include "telnetsrv_ltemeasur_def.h" -#include "telnetsrv_cpumeasur_def.h" -#include "openair2/LAYER2/MAC/mac.h" -#include "openair1/PHY/phy_extern.h" - -void measurcmd_display_macstats(telnet_printfunc_t prnt); -void measurcmd_display_macstats_ue(telnet_printfunc_t prnt); -void measurcmd_display_rlcstats(telnet_printfunc_t prnt); -void measurcmd_display_phycpu(telnet_printfunc_t prnt); -void measurcmd_display_maccpu(telnet_printfunc_t prnt); -void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt); -static telnet_measurgroupdef_t measurgroups[] = { - {"enb", GROUP_LTESTATS,0, measurcmd_display_macstats, {NULL}}, - {"enbues",GROUP_LTESTATS,0, measurcmd_display_macstats_ue,{NULL}}, - {"rlc", GROUP_LTESTATS,0, measurcmd_display_rlcstats, {NULL}}, - {"phycpu",GROUP_CPUSTATS,0, measurcmd_display_phycpu, {NULL}}, - {"maccpu",GROUP_CPUSTATS,0, measurcmd_display_maccpu, {NULL}}, - {"pdcpcpu",GROUP_CPUSTATS,0, measurcmd_display_pdcpcpu, {NULL}}, -}; -#define TELNET_NUM_MEASURGROUPS (sizeof(measurgroups)/sizeof(telnet_measurgroupdef_t)) - -static int eNB_id =0; static char *grouptypes[] = {"ltestats","cpustats"}; static double cpufreq; #define TELNET_NUM_MEASURTYPES (sizeof(grouptypes)/sizeof(char *)) #define HDR "---------------------------------" -void measurcmd_display_groups(telnet_printfunc_t prnt) { +void measurcmd_display_groups(telnet_printfunc_t prnt,telnet_measurgroupdef_t *measurgroups,int groups_size) { prnt(" %*s %10s %s\n",TELNET_MAXMEASURNAME_LEN-1,"name","type","nombre de mesures"); - for(int i=0; iUE_list); - for (int UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { - for (int i=0; inumactiveCCs[UE_id]; i++) { - int CC_id = UE_list->ordered_CCids[i][UE_id]; - prnt("%s UE %i Id %i CCid %i %s\n",HDR,i,UE_id,CC_id,HDR); - eNB_UE_STATS *macuestatptr = &(UE_list->eNB_UE_stats[CC_id][UE_id]); - telnet_ltemeasurdef_t statsptr[]=LTEMAC_UEMEASURE; - measurcmd_display_measures(prnt, statsptr, sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t)); - } - } -} /* measurcmd_display_macstats_ue */ - -void measurcmd_display_macstats(telnet_printfunc_t prnt) { - for (int CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) { - eNB_STATS *macstatptr=&(RC.mac[eNB_id]->eNB_stats[CC_id]); - telnet_ltemeasurdef_t statsptr[]=LTEMAC_MEASURE; - prnt("%s eNB %i mac stats CC %i frame %u %s\n", - HDR, eNB_id, CC_id, RC.mac[eNB_id]->frame,HDR); - measurcmd_display_measures(prnt,statsptr,sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t)); - } -} /* measurcmd_display_macstats */ - - -void measurcmd_display_one_rlcstat(telnet_printfunc_t prnt, int UE_id, telnet_ltemeasurdef_t *statsptr, int num_rlcmeasure, unsigned int *rlcstats, - char *rbid_str, protocol_ctxt_t *ctxt, const srb_flag_t srb_flagP, const rb_id_t rb_idP) - -{ - int rlc_status = rlc_stat_req(ctxt,srb_flagP,rb_idP, - rlcstats, rlcstats+1, rlcstats+2, rlcstats+3, rlcstats+4, rlcstats+5, - rlcstats+6, rlcstats+7, rlcstats+8, rlcstats+9, rlcstats+10, rlcstats+11, - rlcstats+12, rlcstats+13, rlcstats+14, rlcstats+15, rlcstats+16, rlcstats+17, - rlcstats+18, rlcstats+19, rlcstats+20, rlcstats+21, rlcstats+22, rlcstats+23, - rlcstats+24, rlcstats+25, rlcstats+26, rlcstats+27); - - if (rlc_status == RLC_OP_STATUS_OK) { - prnt("%s UE %i RLC %s mode %s %s\n",HDR,UE_id, rbid_str, - (rlcstats[0]==RLC_MODE_AM)? "AM": (rlcstats[0]==RLC_MODE_UM)?"UM":"NONE",HDR); - measurcmd_display_measures(prnt, statsptr, num_rlcmeasure); - } -} /* status measurcmd_rlc_stat_req */ - - -void measurcmd_display_rlcstats(telnet_printfunc_t prnt) { - protocol_ctxt_t ctxt; - UE_list_t *UE_list = &(RC.mac[eNB_id]->UE_list); - telnet_ltemeasurdef_t statsptr[]=LTE_RLCMEASURE; - int num_rlcmeasure = sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t ); - unsigned int *rlcstats = malloc(num_rlcmeasure*sizeof(unsigned int)); - eNB_MAC_INST *eNB = RC.mac[eNB_id]; - - for(int i=0; i head; UE_id>=0; UE_id=UE_list->next[UE_id]) { -#define NB_eNB_INST 1 - PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,eNB_id, ENB_FLAG_YES,UE_list->eNB_UE_stats[0][UE_id].crnti, - eNB->frame,eNB->subframe,eNB_id); - measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DCCH", &ctxt, SRB_FLAG_YES, DCCH); - measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DTCH", &ctxt, SRB_FLAG_NO, DTCH-2); - } -} /* measurcmd_display_macstats_ue */ /*------------------------------------------------------------------------------------------------------------------------*/ /* function called by the telnet server when measur command is entered */ @@ -238,20 +130,24 @@ int measurcmd_show(char *buf, int debug, telnet_printfunc_t prnt) { if (debug > 0) prnt(" measurcmd_show received %s\n",buf); - - // char tmp[20480]; - // dump_eNB_l2_stats(tmp, 0); - // prnt("%s\n",tmp); + int (*fptr)(telnet_measurgroupdef_t **) = dlsym(RTLD_DEFAULT,"get_measurgroups"); + if ( fptr == NULL) { + prnt("No measures available for this softmodem\n"); + return 0; + } + telnet_measurgroupdef_t *measurgroups; + int num_measurgroups = fptr( &measurgroups); + int s = sscanf(buf,"%ms %i-%i\n",&subcmd, &idx1,&idx2); if (s>0) { if ( strcmp(subcmd,"groups") == 0) { - measurcmd_display_groups(prnt); + measurcmd_display_groups(prnt,measurgroups,num_measurgroups); badcmd=0; } else { for (int i=0; i #include "telnetsrv.h" #include "openair1/PHY/defs_eNB.h" -#ifdef TELNETSRV_MEASURMENTS_MAIN + #define TELNET_MAXMEASURNAME_LEN 30 #define TELNET_MAXMEASURGROUPS 10 -telnetshell_vardef_t measur_vardef[] = { - {"",0,NULL} -}; - +#define PRINT_CPUMEAS_STATE ((cpumeas(CPUMEAS_GETSTATE))?"enabled":"disabled") typedef struct cpumeasurdef { char statname[TELNET_MAXMEASURNAME_LEN]; time_stats_t *astatptr; @@ -75,6 +72,7 @@ typedef struct mesurgroupdef { #define LTEMAC_MEASURGROUP_NAME "ltemac" #define PHYCPU_MEASURGROUP_NAME "phycpu" +#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); telnetshell_cmddef_t measur_cmdarray[] = { @@ -83,6 +81,19 @@ telnetshell_cmddef_t measur_cmdarray[] = { {"","",NULL} }; +telnetshell_vardef_t measur_vardef[] = { + {"",0,NULL} +}; +/* function to be implemented in any telnetsrv_xxx_measurements.c sources + to allow common measurment code to access measurments data */ +extern int get_measurgroups(telnet_measurgroupdef_t **measurgroups); +/* */ + #else -extern void add_measur_cmds(void); +extern void add_measur_cmds(void); +extern void measurcmd_display_groups(telnet_printfunc_t prnt,telnet_measurgroupdef_t *measurgroups,int groups_size); +extern void measurcmd_display_cpumeasures(telnet_printfunc_t prnt, telnet_cpumeasurdef_t *cpumeasure, int cpumeasure_size) ; +extern uint64_t measurcmd_getstatvalue(telnet_ltemeasurdef_t *measur,telnet_printfunc_t prnt); +extern void measurcmd_display_measures(telnet_printfunc_t prnt, telnet_ltemeasurdef_t *statsptr, int stats_size); + #endif /* TELNETSRV_MEASURCMD_MAIN */ diff --git a/common/utils/telnetsrv/telnetsrv_phycmd.c b/common/utils/telnetsrv/telnetsrv_phycmd.c deleted file mode 100644 index c60126f1c7..0000000000 --- a/common/utils/telnetsrv/telnetsrv_phycmd.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file common/utils/telnetsrv/telnetsrv_phycmd.c - * \brief: implementation of telnet commands related to softmodem linux process - * \author Francois TABURET - * \date 2017 - * \version 0.1 - * \company NOKIA BellLabs France - * \email: francois.taburet@nokia-bell-labs.com - * \note - * \warning - */ -#define _GNU_SOURCE -#include -#include - - -#define TELNETSERVERCODE -#include "telnetsrv.h" -#define TELNETSRV_PHYCMD_MAIN -#include "telnetsrv_phycmd.h" -char *prnbuff; -extern int dump_eNB_stats(PHY_VARS_eNB *eNB, char* buffer, int length); - -void init_phytelnet(void) -{ -prnbuff=malloc(get_phybsize() ); -if (prnbuff == NULL) - { - fprintf(stderr,"Error %s on malloc in init_phytelnet()\n",strerror(errno)); - } -} - -void display_uestatshead( telnet_printfunc_t prnt) -{ -prnt("cc ue rnti Dmcs Umcs tao tau Dbr Dtb \n"); -} - -void dump_uestats(int debug, telnet_printfunc_t prnt, uint8_t prntflag) -{ - -int p; - - p=dump_eNB_l2_stats( prnbuff, 0); - if(prntflag>=1) - prnt("%s\n",prnbuff); - if(debug>=1) - prnt("%i bytes printed\n",p); - - -} - -void display_uestats(int debug, telnet_printfunc_t prnt, int ue) -{ - for (int cc=0; cc<1 ; cc++) - { - - - } -} - -void display_phycounters(char *buf, int debug, telnet_printfunc_t prnt) -{ - prnt(" DLSCH kb DLSCH kb/s\n"); - - dump_uestats(debug, prnt,0); - -} - -int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt) -{ - - - - if (debug > 0) - prnt("phy interface module received %s\n",buf); - if (strcasestr(buf,"phycnt") != NULL) - { - display_phycounters(buf, debug, prnt); - } - if (strcasestr(buf,"uestat") != NULL) - { - char *cptr=strcasestr(buf+sizeof("uestat"),"UE"); - display_uestatshead(prnt); - if (cptr != NULL) - { - int ueidx = strtol( cptr+sizeof("UE"), NULL, 10); - if (ueidx < NUMBER_OF_UE_MAX && ueidx >= 0) - { - display_uestats(debug, prnt,ueidx); - } - } /* if cptr != NULL */ - else - { - for (int ue=0; ue]", dump_phyvars}, - - {"","",NULL}, -}; - - -/*-------------------------------------------------------------------------------------*/ -void add_phy_cmds(void) -{ - - init_phytelnet(); - add_telnetcmd("phy", phy_vardef, phy_cmdarray); -} From 69721198af3eb4ad1d93a49aacdbefac9fbf16ad Mon Sep 17 00:00:00 2001 From: Raymond Knopp Date: Mon, 10 Feb 2020 12:54:00 +0100 Subject: [PATCH 10/73] nr MAC uplink: aDD identification of MAC uplink PDU CEs at gNB (receiver) side --- .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 94 ++++++++++++++++++- 1 file changed, 91 insertions(+), 3 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index cabaee7b5c..4a8602d272 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -606,10 +606,87 @@ void nr_process_mac_pdu( LOG_D(MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID, pdu_len); #endif*/ + case UL_SCH_LCID_S_BSR: + //38.321 section 6.1.3.1 + //fixed length + mac_ce_len =1; + /* Extract short BSR value */ + break; + + case UL_SCH_LCID_S_TRUNCATED_BSR: + //38.321 section 6.1.3.1 + //fixed length + mac_ce_len =1; + /* Extract short truncated BSR value */ + break; + + case UL_SCH_LCID_L_BSR: + //38.321 section 6.1.3.1 + //variable length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract long BSR value */ + break; + + case UL_SCH_LCID_L_TRUNCATED_BSR: + //38.321 section 6.1.3.1 + //variable length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract long truncated BSR value */ + break; + + + case UL_SCH_LCID_C_RNTI: + //38.321 section 6.1.3.2 + //fixed length + mac_ce_len = 2; + /* Extract CRNTI value */ + break; + + case UL_SCH_LCID_SINGLE_ENTRY_PHR: + //38.321 section 6.1.3.8 + //fixed length + mac_ce_len = 2; + /* Extract SINGLE ENTRY PHR elements for PHR calculation */ + break; + + case UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT: + //38.321 section 6.1.3.9 + // varialbe length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract MULTI ENTRY PHR elements from single octet bitmap for PHR calculation */ + break; + + case UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT: + //38.321 section 6.1.3.9 + // varialbe length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract MULTI ENTRY PHR elements from four octets bitmap for PHR calculation */ + break; + case UL_SCH_LCID_PADDING: - done = 1; - // end of MAC PDU, can ignore the rest. - break; + done = 1; + // end of MAC PDU, can ignore the rest. + break; case UL_SCH_LCID_DTCH: // check if LCID is valid at current time. @@ -682,6 +759,17 @@ void nr_rx_sdu(module_id_t module_idP, uint8_t * pduP = pdu; + +#if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_I(MAC, "Printing received UL MAC payload at gNB side: %d \n"); + for (int i = 0; i < pdu_len ; i++) { + //harq_process_ul_ue->a[i] = (unsigned char) rand(); + //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); + printf("%02x ",(unsigned char)pduP[i]); + } + printf("\n"); +#endif + // Processing MAC PDU // it parses MAC CEs subheaders, MAC CEs, SDU subheaderds and SDUs if (pduP != NULL){ From 9e6b6ef9650cb5b2a99a154f44a414847eac5e8e Mon Sep 17 00:00:00 2001 From: matzakos Date: Tue, 11 Feb 2020 18:45:35 +0100 Subject: [PATCH 11/73] nr-ip-ul-nos1: Remove warnings --- cmake_targets/CMakeLists.txt | 1 - openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h | 2 +- openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 8 ++++---- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 3 +-- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 8 ++++---- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 2 +- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 0699bb08c5..350a2a1f50 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -1723,7 +1723,6 @@ set(NR_L2_SRC_UE ${NR_UE_RRC_DIR}/L2_interface_ue.c ${NR_UE_RRC_DIR}/main_ue.c ${NR_UE_RRC_DIR}/rrc_UE.c - ${LTE_RLC_SRC} ) set (MAC_SRC diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h index be504a1587..348774b08a 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h @@ -1076,7 +1076,7 @@ void nr_pusch_codeword_scrambling(uint8_t *in, - transform precoding */ -uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, +void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, unsigned char harq_pid, uint8_t frame, uint8_t slot, diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c index 547dd523ca..4360149e60 100644 --- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c +++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c @@ -42,6 +42,7 @@ #include "PHY/defs_nr_common.h" #include "PHY/TOOLS/tools_defs.h" #include "executables/nr-softmodem.h" +#include "LAYER2/NR_MAC_UE/mac_proto.h" //#define DEBUG_SCFDMA //#define DEBUG_PUSCH_MAPPING @@ -88,7 +89,7 @@ void nr_pusch_codeword_scrambling(uint8_t *in, } -uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, +void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, unsigned char harq_pid, uint8_t frame, uint8_t slot, @@ -205,7 +206,7 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, } //else if(uplink_counter == 0){ //if(!IS_SOFTMODEM_NOS1){ else{ - LOG_E(PHY, "Random data to be tranmsitted: \n"); + LOG_D(PHY, "Random data to be tranmsitted: \n"); for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) { harq_process_ul_ue->a[i] = (unsigned char) rand(); //printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); @@ -214,7 +215,7 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, } } else { LOG_E(PHY, "[phy_procedures_nrUE_TX] harq_process_ul_ue is NULL !!\n"); - return 0; + return; } //-----------------------------------------------------// @@ -427,7 +428,6 @@ uint8_t nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE, //////////////////////////////////////////////////////////////////////// LOG_D(PHY, "Is data existing ?: %d \n", data_existing); - return data_existing; } diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 6282e81066..1b62cb8731 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -2483,9 +2483,8 @@ void phy_procedures_nrUE_TX(PHY_VARS_NR_UE *ue, #endif uint8_t harq_pid = 0; //temporary implementation - uint8_t data_existing = 0; - data_existing = nr_ue_ulsch_procedures(ue, + nr_ue_ulsch_procedures(ue, harq_pid, frame_tx, slot_tx, diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 02749a70dd..bfbec72981 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -43,6 +43,7 @@ #include #include +//int mbms_rab_id = 2047; //#define ENABLE_MAC_PAYLOAD_DEBUG 1 @@ -2482,7 +2483,7 @@ uint8_t nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, sub_frame_t subframe, uint8_t eNB_index, uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) { - uint8_t total_rlc_pdu_header_len = 0, rlc_pdu_header_len_last = 0; + uint8_t total_rlc_pdu_header_len = 0; int16_t buflen_remain = 0; uint8_t lcid = 0; uint16_t sdu_lengths[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -2490,8 +2491,7 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, uint16_t payload_offset = 0, num_sdus = 0; uint8_t ulsch_sdus[MAX_ULSCH_PAYLOAD_BYTES]; uint16_t sdu_length_total = 0; - unsigned short post_padding = 0, padding_len = 0; - int j; // used for padding + unsigned short post_padding = 0; rlc_buffer_occupancy_t lcid_buffer_occupancy_old = 0, lcid_buffer_occupancy_new = 0; @@ -2504,7 +2504,7 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, start_meas(&UE_mac_inst[module_idP].tx_ulsch_sdu); #endif - NR_UE_MAC_INST_t *nr_ue_mac_inst = get_mac_inst(0); + //NR_UE_MAC_INST_t *nr_ue_mac_inst = get_mac_inst(0); // Check for DCCH first // TO DO: Multiplex in the order defined by the logical channel prioritization diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index 4a8602d272..99f893506f 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -561,7 +561,7 @@ void nr_process_mac_pdu( // This function is adapting code from the old // parse_header(...) and ue_send_sdu(...) functions of OAI LTE - uint8_t *pdu_ptr = pduP, rx_lcid, done = 0, i; + uint8_t *pdu_ptr = pduP, rx_lcid, done = 0; int pdu_len = mac_pdu_len; uint16_t mac_ce_len, mac_subheader_len, mac_sdu_len; From 295923d540f0f303a5b528cd77496ea79d134bd3 Mon Sep 17 00:00:00 2001 From: matzakos Date: Wed, 12 Feb 2020 17:58:06 +0100 Subject: [PATCH 12/73] nr-ip-ul-nos1: Logs cleanup and some code rearrangement --- openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c | 11 +- .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 229 ------------------ .../LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c | 196 +++++++++++++++ openair2/NR_PHY_INTERFACE/NR_IF_Module.c | 2 +- 4 files changed, 199 insertions(+), 239 deletions(-) diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c index 72daf0ee39..2df700e031 100644 --- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c +++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c @@ -51,8 +51,6 @@ #include "executables/softmodem-common.h" /* log utils */ #include "common/utils/LOG/log.h" -//#include "openair2/LAYER2/MAC/mac.h" -//#include "openair2/LAYER2/RLC/rlc.h" #include "SIMULATION/TOOLS/sim.h" // for taus #include "openair2/LAYER2/NR_MAC_COMMON/nr_mac.h" #include "common/utils/LOG/vcd_signal_dumper.h" @@ -2426,7 +2424,7 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, uint16_t payload_offset = 0, num_sdus = 0; uint8_t ulsch_sdus[MAX_ULSCH_PAYLOAD_BYTES]; uint16_t sdu_length_total = 0; - unsigned short post_padding = 0; + //unsigned short post_padding = 0; rlc_buffer_occupancy_t lcid_buffer_occupancy_old = 0, lcid_buffer_occupancy_new = 0; @@ -2527,11 +2525,6 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, } else return 0; - LOG_D(MAC, - "[UE %d] Generate header :bufflen %d sdu_length_total %d, num_sdus %d, sdu_lengths[0] %d, sdu_lcids[0] %d => payload offset %d, total_rlc_pdu_header_len %d, post_padding %d, remainder %d \n", - module_idP, buflen, sdu_length_total, num_sdus, sdu_lengths[0], - sdu_lcids[0], payload_offset, total_rlc_pdu_header_len, - post_padding, buflen - sdu_length_total - payload_offset); // Padding: fill remainder of ULSCH with 0 if (buflen - payload_offset > 0){ @@ -2540,7 +2533,7 @@ nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP, } #if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_I(MAC, "Printing UL MAC payload without the header UE side, payload_offset: %d \n", payload_offset); + LOG_I(MAC, "Printing UL MAC payload UE side, payload_offset: %d \n", payload_offset); for (int i = 0; i < buflen ; i++) { //harq_process_ul_ue->a[i] = (unsigned char) rand(); //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c index 50de63c11c..03795a8c09 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c @@ -532,232 +532,3 @@ void nr_schedule_uss_ulsch_phytest(nfapi_nr_ul_tti_request_t *UL_tti_req, } } -void nr_process_mac_pdu( - module_id_t module_idP, - uint8_t CC_id, - frame_t frameP, - uint8_t *pduP, - uint16_t mac_pdu_len) -{ - - // This function is adapting code from the old - // parse_header(...) and ue_send_sdu(...) functions of OAI LTE - - uint8_t *pdu_ptr = pduP, rx_lcid, done = 0; - int pdu_len = mac_pdu_len; - uint16_t mac_ce_len, mac_subheader_len, mac_sdu_len; - - - // For both DL/UL-SCH - // Except: - // - UL/DL-SCH: fixed-size MAC CE(known by LCID) - // - UL/DL-SCH: padding - // - UL-SCH: MSG3 48-bits - // |0|1|2|3|4|5|6|7| bit-wise - // |R|F| LCID | - // | L | - // |0|1|2|3|4|5|6|7| bit-wise - // |R|F| LCID | - // | L | - // | L | - - // For both DL/UL-SCH - // For: - // - UL/DL-SCH: fixed-size MAC CE(known by LCID) - // - UL/DL-SCH: padding, for single/multiple 1-oct padding CE(s) - // - UL-SCH: MSG3 48-bits - // |0|1|2|3|4|5|6|7| bit-wise - // |R|R| LCID | - // LCID: The Logical Channel ID field identifies the logical channel instance of the corresponding MAC SDU or the type of the corresponding MAC CE or padding as described in Tables 6.2.1-1 and 6.2.1-2 for the DL-SCH and UL-SCH respectively. There is one LCID field per MAC subheader. The LCID field size is 6 bits; - // L: The Length field indicates the length of the corresponding MAC SDU or variable-sized MAC CE in bytes. There is one L field per MAC subheader except for subheaders corresponding to fixed-sized MAC CEs and padding. The size of the L field is indicated by the F field; - // F: lenght of L is 0:8 or 1:16 bits wide - // R: Reserved bit, set to zero. - - while (!done && pdu_len > 0){ - mac_ce_len = 0; - mac_subheader_len = 1; // default to fixed-length subheader = 1-oct - mac_sdu_len = 0; - rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID; - - LOG_D(MAC, "LCID received at gNB side: %d \n", rx_lcid); - - switch(rx_lcid){ - // MAC CE - - /*#ifdef DEBUG_HEADER_PARSING - LOG_D(MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID, pdu_len); - #endif*/ - - case UL_SCH_LCID_S_BSR: - //38.321 section 6.1.3.1 - //fixed length - mac_ce_len =1; - /* Extract short BSR value */ - break; - - case UL_SCH_LCID_S_TRUNCATED_BSR: - //38.321 section 6.1.3.1 - //fixed length - mac_ce_len =1; - /* Extract short truncated BSR value */ - break; - - case UL_SCH_LCID_L_BSR: - //38.321 section 6.1.3.1 - //variable length - mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; - mac_subheader_len = 2; - if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ - mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; - mac_subheader_len = 3; - } - /* Extract long BSR value */ - break; - - case UL_SCH_LCID_L_TRUNCATED_BSR: - //38.321 section 6.1.3.1 - //variable length - mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; - mac_subheader_len = 2; - if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ - mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; - mac_subheader_len = 3; - } - /* Extract long truncated BSR value */ - break; - - - case UL_SCH_LCID_C_RNTI: - //38.321 section 6.1.3.2 - //fixed length - mac_ce_len = 2; - /* Extract CRNTI value */ - break; - - case UL_SCH_LCID_SINGLE_ENTRY_PHR: - //38.321 section 6.1.3.8 - //fixed length - mac_ce_len = 2; - /* Extract SINGLE ENTRY PHR elements for PHR calculation */ - break; - - case UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT: - //38.321 section 6.1.3.9 - // varialbe length - mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; - mac_subheader_len = 2; - if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ - mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; - mac_subheader_len = 3; - } - /* Extract MULTI ENTRY PHR elements from single octet bitmap for PHR calculation */ - break; - - case UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT: - //38.321 section 6.1.3.9 - // varialbe length - mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; - mac_subheader_len = 2; - if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ - mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; - mac_subheader_len = 3; - } - /* Extract MULTI ENTRY PHR elements from four octets bitmap for PHR calculation */ - break; - - case UL_SCH_LCID_PADDING: - done = 1; - // end of MAC PDU, can ignore the rest. - break; - - case UL_SCH_LCID_DTCH: - // check if LCID is valid at current time. - if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ - //mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; - mac_subheader_len = 3; - mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L1 & 0x7f) << 8) - | ((uint16_t)((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L2 & 0xff); - - } else { - mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; - mac_subheader_len = 2; - } - - LOG_D(MAC, "[UE %d] Frame %d : DLSCH -> DL-DTCH %d (gNB %d, %d bytes)\n", module_idP, frameP, rx_lcid, module_idP, mac_sdu_len); - - #if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP); - - for (i = 0; i < 32; i++) - LOG_T(MAC, "%x.", (pdu_ptr + mac_subheader_len)[i]); - - LOG_T(MAC, "\n"); - #endif - - if (IS_SOFTMODEM_NOS1){ - if (rx_lcid < NB_RB_MAX && rx_lcid >= UL_SCH_LCID_DTCH) { - - mac_rlc_data_ind(module_idP, - 0x1234, - module_idP, - frameP, - ENB_FLAG_YES, - MBMS_FLAG_NO, - rx_lcid, - (char *) (pdu_ptr + mac_subheader_len), - mac_sdu_len, - 1, - NULL); - } else { - LOG_E(MAC, "[UE %d] Frame %d : unknown LCID %d (gNB %d)\n", module_idP, frameP, rx_lcid, module_idP); - } - } - - break; - - default: - return; - break; - } - pdu_ptr += ( mac_subheader_len + mac_ce_len + mac_sdu_len ); - pdu_len -= ( mac_subheader_len + mac_ce_len + mac_sdu_len ); - - AssertFatal(pdu_len >= 0, "[MAC] nr_process_mac_pdu, residual mac pdu length < 0!\n"); - } -} - -/*void nr_rx_sdu(module_id_t module_idP, - uint8_t CC_id, - frame_t frameP, - uint8_t ttiP, - const rnti_t rntiP, - uint8_t * pdu, - const uint16_t pdu_len, - const uint16_t timing_advance, - const uint8_t ul_cqi) -{ - - LOG_D(MAC, "Handling PDU frame %d slot %d pdu_len: %d \n", frameP, ttiP, pdu_len); - - uint8_t * pduP = pdu; - - -#if defined(ENABLE_MAC_PAYLOAD_DEBUG) - LOG_I(MAC, "Printing received UL MAC payload at gNB side: %d \n"); - for (int i = 0; i < pdu_len ; i++) { - //harq_process_ul_ue->a[i] = (unsigned char) rand(); - //printf("a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]); - printf("%02x ",(unsigned char)pduP[i]); - } - printf("\n"); -#endif - - // Processing MAC PDU - // it parses MAC CEs subheaders, MAC CEs, SDU subheaderds and SDUs - if (pduP != NULL){ - LOG_D(MAC, "Received PDU at MAC gNB \n"); - nr_process_mac_pdu(module_idP, CC_id, frameP, pduP, pdu_len); - } - -}*/ - diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c index c6f1520671..95ae4a8e30 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c @@ -29,6 +29,202 @@ */ #include "LAYER2/NR_MAC_gNB/mac_proto.h" +#include "executables/softmodem-common.h" +//#define ENABLE_MAC_PAYLOAD_DEBUG 1 + +void nr_process_mac_pdu( + module_id_t module_idP, + uint8_t CC_id, + frame_t frameP, + uint8_t *pduP, + uint16_t mac_pdu_len) +{ + + // This function is adapting code from the old + // parse_header(...) and ue_send_sdu(...) functions of OAI LTE + + uint8_t *pdu_ptr = pduP, rx_lcid, done = 0; + int pdu_len = mac_pdu_len; + uint16_t mac_ce_len, mac_subheader_len, mac_sdu_len; + + + // For both DL/UL-SCH + // Except: + // - UL/DL-SCH: fixed-size MAC CE(known by LCID) + // - UL/DL-SCH: padding + // - UL-SCH: MSG3 48-bits + // |0|1|2|3|4|5|6|7| bit-wise + // |R|F| LCID | + // | L | + // |0|1|2|3|4|5|6|7| bit-wise + // |R|F| LCID | + // | L | + // | L | + + // For both DL/UL-SCH + // For: + // - UL/DL-SCH: fixed-size MAC CE(known by LCID) + // - UL/DL-SCH: padding, for single/multiple 1-oct padding CE(s) + // - UL-SCH: MSG3 48-bits + // |0|1|2|3|4|5|6|7| bit-wise + // |R|R| LCID | + // LCID: The Logical Channel ID field identifies the logical channel instance of the corresponding MAC SDU or the type of the corresponding MAC CE or padding as described in Tables 6.2.1-1 and 6.2.1-2 for the DL-SCH and UL-SCH respectively. There is one LCID field per MAC subheader. The LCID field size is 6 bits; + // L: The Length field indicates the length of the corresponding MAC SDU or variable-sized MAC CE in bytes. There is one L field per MAC subheader except for subheaders corresponding to fixed-sized MAC CEs and padding. The size of the L field is indicated by the F field; + // F: lenght of L is 0:8 or 1:16 bits wide + // R: Reserved bit, set to zero. + + while (!done && pdu_len > 0){ + mac_ce_len = 0; + mac_subheader_len = 1; // default to fixed-length subheader = 1-oct + mac_sdu_len = 0; + rx_lcid = ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID; + + LOG_D(MAC, "LCID received at gNB side: %d \n", rx_lcid); + + switch(rx_lcid){ + // MAC CE + + /*#ifdef DEBUG_HEADER_PARSING + LOG_D(MAC, "[UE] LCID %d, PDU length %d\n", ((NR_MAC_SUBHEADER_FIXED *)pdu_ptr)->LCID, pdu_len); + #endif*/ + + case UL_SCH_LCID_S_BSR: + //38.321 section 6.1.3.1 + //fixed length + mac_ce_len =1; + /* Extract short BSR value */ + break; + + case UL_SCH_LCID_S_TRUNCATED_BSR: + //38.321 section 6.1.3.1 + //fixed length + mac_ce_len =1; + /* Extract short truncated BSR value */ + break; + + case UL_SCH_LCID_L_BSR: + //38.321 section 6.1.3.1 + //variable length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract long BSR value */ + break; + + case UL_SCH_LCID_L_TRUNCATED_BSR: + //38.321 section 6.1.3.1 + //variable length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract long truncated BSR value */ + break; + + + case UL_SCH_LCID_C_RNTI: + //38.321 section 6.1.3.2 + //fixed length + mac_ce_len = 2; + /* Extract CRNTI value */ + break; + + case UL_SCH_LCID_SINGLE_ENTRY_PHR: + //38.321 section 6.1.3.8 + //fixed length + mac_ce_len = 2; + /* Extract SINGLE ENTRY PHR elements for PHR calculation */ + break; + + case UL_SCH_LCID_MULTI_ENTRY_PHR_1_OCT: + //38.321 section 6.1.3.9 + // varialbe length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract MULTI ENTRY PHR elements from single octet bitmap for PHR calculation */ + break; + + case UL_SCH_LCID_MULTI_ENTRY_PHR_4_OCT: + //38.321 section 6.1.3.9 + // varialbe length + mac_ce_len |= (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + mac_ce_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + } + /* Extract MULTI ENTRY PHR elements from four octets bitmap for PHR calculation */ + break; + + case UL_SCH_LCID_PADDING: + done = 1; + // end of MAC PDU, can ignore the rest. + break; + + case UL_SCH_LCID_DTCH: + // check if LCID is valid at current time. + if(((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->F){ + //mac_sdu_len |= (uint16_t)(((NR_MAC_SUBHEADER_LONG *)pdu_ptr)->L2)<<8; + mac_subheader_len = 3; + mac_sdu_len = ((uint16_t)(((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L1 & 0x7f) << 8) + | ((uint16_t)((NR_MAC_SUBHEADER_LONG *) pdu_ptr)->L2 & 0xff); + + } else { + mac_sdu_len = (uint16_t)((NR_MAC_SUBHEADER_SHORT *)pdu_ptr)->L; + mac_subheader_len = 2; + } + + LOG_D(MAC, "[UE %d] Frame %d : DLSCH -> DL-DTCH %d (gNB %d, %d bytes)\n", module_idP, frameP, rx_lcid, module_idP, mac_sdu_len); + + #if defined(ENABLE_MAC_PAYLOAD_DEBUG) + LOG_T(MAC, "[UE %d] First 32 bytes of DLSCH : \n", module_idP); + + for (i = 0; i < 32; i++) + LOG_T(MAC, "%x.", (pdu_ptr + mac_subheader_len)[i]); + + LOG_T(MAC, "\n"); + #endif + + if (IS_SOFTMODEM_NOS1){ + if (rx_lcid < NB_RB_MAX && rx_lcid >= UL_SCH_LCID_DTCH) { + + mac_rlc_data_ind(module_idP, + 0x1234, + module_idP, + frameP, + ENB_FLAG_YES, + MBMS_FLAG_NO, + rx_lcid, + (char *) (pdu_ptr + mac_subheader_len), + mac_sdu_len, + 1, + NULL); + } else { + LOG_E(MAC, "[UE %d] Frame %d : unknown LCID %d (gNB %d)\n", module_idP, frameP, rx_lcid, module_idP); + } + } + + break; + + default: + return; + break; + } + pdu_ptr += ( mac_subheader_len + mac_ce_len + mac_sdu_len ); + pdu_len -= ( mac_subheader_len + mac_ce_len + mac_sdu_len ); + + AssertFatal(pdu_len >= 0, "[MAC] nr_process_mac_pdu, residual mac pdu length < 0!\n"); + } +} /* diff --git a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c index 71fffa84fb..3ca64f9648 100644 --- a/openair2/NR_PHY_INTERFACE/NR_IF_Module.c +++ b/openair2/NR_PHY_INTERFACE/NR_IF_Module.c @@ -193,7 +193,7 @@ void handle_nr_ulsch(NR_UL_IND_t *UL_info) { UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.timing_advance, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.ul_cqi); } else { - LOG_I(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok), received length: %d \n",UL_info->frame,UL_info->slot, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length); + LOG_D(MAC,"Frame %d, Slot %d Calling rx_sdu (CRC ok), received length: %d \n",UL_info->frame,UL_info->slot, UL_info->rx_ind.rx_indication_body.rx_pdu_list[i].rx_indication_rel8.length); nr_rx_sdu(UL_info->module_id, UL_info->CC_id, NFAPI_SFNSF2SFN(UL_info->rx_ind.sfn_sf), //UL_info->frame, From 6014ca42ac136151d77787a1372fff84e651e0f5 Mon Sep 17 00:00:00 2001 From: frtabu Date: Wed, 12 Feb 2020 19:05:44 +0100 Subject: [PATCH 13/73] ENABLE_ITTI macro removal, modified telnet server to support all executables, modified record player to finalize switch to run-time option and allow usage with any device --- cmake_targets/CMakeLists.txt | 26 +- common/utils/LOG/log.h | 10 - common/utils/LOG/vcd_signal_dumper.c | 5 - common/utils/T/local_tracer.c | 18 +- common/utils/telnetsrv/telnetsrv.c | 17 +- common/utils/telnetsrv/telnetsrv.h | 2 +- .../telnetsrv/telnetsrv_enb_measurements.c | 179 ++ common/utils/telnetsrv/telnetsrv_enb_phycmd.c | 123 ++ executables/nr-gnb.c | 8 +- executables/nr-softmodem-common.h | 6 +- executables/nr-softmodem.c | 32 +- executables/nr-uesoftmodem.c | 6 +- executables/softmodem-common.c | 25 +- executables/softmodem-common.h | 18 +- openair1/PHY/LTE_TRANSPORT/pucch.c | 21 +- openair1/SCHED/prach_procedures.c | 4 +- openair1/SCHED_NR/phy_procedures_nr_gNB.c | 4 +- openair1/SCHED_NR_UE/phy_procedures_nr_ue.c | 10 +- openair1/SCHED_UE/phy_procedures_lte_ue.c | 13 +- openair2/GNB_APP/gnb_paramdef.h | 2 - openair2/LAYER2/MAC/eNB_scheduler.c | 4 +- openair2/LAYER2/MAC/eNB_scheduler_RA.c | 45 +- openair2/LAYER2/MAC/eNB_scheduler_bch.c | 4 +- openair2/LAYER2/MAC/eNB_scheduler_dlsch.c | 4 +- openair2/LAYER2/MAC/eNB_scheduler_mch.c | 4 - .../LAYER2/MAC/eNB_scheduler_primitives.c | 11 +- openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 4 +- openair2/LAYER2/MAC/ue_procedures.c | 9 +- openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 2 - .../LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c | 2 - .../NR_MAC_gNB/gNB_scheduler_primitives.c | 2 - openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c | 40 +- .../RLC/AM_v9.3.0/rlc_am_status_report.c | 4 +- openair2/RRC/LTE/L2_interface.c | 4 +- openair2/RRC/LTE/L2_interface_common.c | 12 +- openair2/RRC/LTE/L2_interface_ue.c | 66 +- openair2/RRC/LTE/MESSAGES/asn1_msg.c | 398 +--- openair2/RRC/LTE/MESSAGES/asn1_msg.h | 12 +- openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c | 64 +- openair2/RRC/LTE/rrc_eNB.c | 23 +- openair2/RRC/LTE/rrc_eNB_GTPV1U.c | 12 +- openair2/RRC/LTE/rrc_eNB_S1AP.c | 7 +- openair2/RRC/NR/L2_nr_interface.c | 4 +- openair2/RRC/NR/MESSAGES/asn1_msg.c | 46 +- openair2/RRC/NR/MESSAGES/asn1_msg.h | 8 +- openair2/RRC/NR/nr_rrc_config.c | 8 +- openair2/RRC/NR/nr_rrc_config.h | 8 +- openair2/RRC/NR/nr_rrc_defs.h | 12 +- openair2/RRC/NR/nr_rrc_proto.h | 2 - openair2/RRC/NR/rrc_gNB.c | 50 +- openair2/UTIL/LOG/log.c | 1832 ----------------- openair3/NAS/COMMON/UTIL/nas_timer.c | 121 +- openair3/NAS/UE/ESM/PdnConnectivity.c | 2 - openair3/NAS/UE/nas_ue_task.c | 2 - openair3/NAS/UE/nas_ue_task.h | 2 - targets/ARCH/COMMON/common_lib.c | 62 +- targets/ARCH/COMMON/common_lib.h | 37 +- targets/ARCH/COMMON/record_player.c | 115 ++ .../LIB/usrp_lib.h => COMMON/record_player.h} | 63 +- targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp | 983 ++++----- .../ARCH/USRP/USERSPACE/LIB/usrp_lib_config.c | 73 - targets/ARCH/iqplayer/iqplayer_lib.c | 307 +++ targets/COMMON/create_nr_tasks.h | 2 - targets/COMMON/create_tasks.h | 2 - targets/COMMON/create_tasks_mbms.h | 2 - targets/RT/USER/lte-softmodem.c | 2 +- targets/RT/USER/lte-uesoftmodem.c | 15 +- 67 files changed, 1408 insertions(+), 3614 deletions(-) create mode 100644 common/utils/telnetsrv/telnetsrv_enb_measurements.c create mode 100644 common/utils/telnetsrv/telnetsrv_enb_phycmd.c delete mode 100644 openair2/UTIL/LOG/log.c create mode 100644 targets/ARCH/COMMON/record_player.c rename targets/ARCH/{USRP/USERSPACE/LIB/usrp_lib.h => COMMON/record_player.h} (81%) delete mode 100644 targets/ARCH/USRP/USERSPACE/LIB/usrp_lib_config.c create mode 100644 targets/ARCH/iqplayer/iqplayer_lib.c diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index bb7cc25ec0..01b1d6c273 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -247,22 +247,18 @@ add_boolean_option(T_TRACER True "Activate the T tracer, a debugging add_boolean_option(UE_AUTOTEST_TRACE False "Activate UE autotest specific logs") add_boolean_option(UE_DEBUG_TRACE False "Activate UE debug trace") add_boolean_option(UE_TIMING_TRACE False "Activate UE timing trace") -add_boolean_option(USRP_REC_PLAY False "Enable USRP record playback mode") -add_boolean_option(BASIC_SIMULATOR False "Has to be True when building the basic simulator, False otherwise") add_boolean_option(DEBUG_CONSOLE False "makes debugging easier, disables stdout/stderr buffering") -add_boolean_option(ENABLE_ITTI True "ITTI is internal messaging, should remain enabled for most targets") set (OCP_ITTI ${OPENAIR_DIR}/common/utils/ocp_itti) -if (${ENABLE_ITTI}) - add_library(ITTI - ${OCP_ITTI}/intertask_interface.cpp - ${OPENAIR_DIR}/common/utils/backtrace.c - ${OPENAIR_DIR}/common/utils/memory_pools.c - ) +add_library(ITTI + ${OCP_ITTI}/intertask_interface.cpp + ${OPENAIR_DIR}/common/utils/backtrace.c + ${OPENAIR_DIR}/common/utils/memory_pools.c + ) add_dependencies(ITTI rrc_flag) set(ITTI_LIB ITTI) set(GTPU_need_ITTI ${OPENAIR3_DIR}/GTPV1-U/gtpv1u_eNB.c) -endif (${ENABLE_ITTI}) + ################################################## # ASN.1 grammar C code generation & dependencies # @@ -660,7 +656,6 @@ set (SHLIB_LOADER_SOURCES include_directories("${OPENAIR_TARGETS}/ARCH/USRP/USERSPACE/LIB/") set(HWLIB_USRP_SOURCE ${OPENAIR_TARGETS}/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp - ${OPENAIR_TARGETS}/ARCH/USRP/USERSPACE/LIB/usrp_lib_config.c ) add_library(oai_usrpdevif MODULE ${HWLIB_USRP_SOURCE} ) target_link_libraries(oai_usrpdevif uhd) @@ -2369,6 +2364,9 @@ add_library(rfsimulator MODULE ) target_link_libraries(rfsimulator SIMU ${ATLAS_LIBRARIES}) +add_library(oai_iqplayer MODULE + ${OPENAIR_TARGETS}/ARCH/iqplayer/iqplayer_lib.c + ) set(CMAKE_MODULE_PATH "${OPENAIR_DIR}/cmake_targets/tools/MODULES" "${CMAKE_MODULE_PATH}") #include T directory even if the T is off because T macros are in the code @@ -2448,6 +2446,7 @@ add_executable(lte-softmodem ${OPENAIR_TARGETS}/COMMON/create_tasks.c ${OPENAIR_TARGETS}/COMMON/create_tasks_mbms.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c + ${OPENAIR_TARGETS}/ARCH/COMMON/record_player.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${OPENAIR2_DIR}/RRC/NAS/rb_config.c ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c @@ -2462,7 +2461,7 @@ add_executable(lte-softmodem ${CONFIG_SOURCES} ${SHLIB_LOADER_SOURCES} ) -add_dependencies(lte-softmodem rrc_flag s1ap_flag x2_flag) +add_dependencies(lte-softmodem rrc_flag s1ap_flag x2_flag oai_iqplayer) target_link_libraries (lte-softmodem -Wl,--start-group @@ -2517,6 +2516,7 @@ add_executable(lte-uesoftmodem ${OPENAIR_TARGETS}/RT/USER/rfsim.c ${OPENAIR_TARGETS}/COMMON/create_tasks_ue.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c + ${OPENAIR_TARGETS}/ARCH/COMMON/record_player.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${OPENAIR2_DIR}/RRC/NAS/rb_config.c ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c @@ -2563,6 +2563,7 @@ add_executable(nr-softmodem ${OPENAIR_DIR}/executables/softmodem-common.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c + ${OPENAIR_TARGETS}/ARCH/COMMON/record_player.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${OPENAIR2_DIR}/RRC/NAS/rb_config.c ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c @@ -2602,6 +2603,7 @@ add_executable(nr-uesoftmodem ${OPENAIR_DIR}/executables/softmodem-common.c ${OPENAIR1_DIR}/SIMULATION/TOOLS/taus.c ${OPENAIR_TARGETS}/ARCH/COMMON/common_lib.c + ${OPENAIR_TARGETS}/ARCH/COMMON/record_player.c ${OPENAIR2_DIR}/RRC/NAS/nas_config.c ${OPENAIR2_DIR}/RRC/NAS/rb_config.c ${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c diff --git a/common/utils/LOG/log.h b/common/utils/LOG/log.h index 6baec7dfeb..8e74f4148c 100644 --- a/common/utils/LOG/log.h +++ b/common/utils/LOG/log.h @@ -274,16 +274,6 @@ typedef struct { } log_t; -#if defined(ENABLE_ITTI) -typedef enum log_instance_type_e { - LOG_INSTANCE_UNKNOWN, - LOG_INSTANCE_ENB, - LOG_INSTANCE_UE, -} log_instance_type_t; - -void log_set_instance_type (log_instance_type_t instance); -#endif - #ifdef LOG_MAIN log_t *g_log; diff --git a/common/utils/LOG/vcd_signal_dumper.c b/common/utils/LOG/vcd_signal_dumper.c index 103cf1cd94..9327b6e77a 100644 --- a/common/utils/LOG/vcd_signal_dumper.c +++ b/common/utils/LOG/vcd_signal_dumper.c @@ -633,9 +633,6 @@ inline static uint32_t vcd_get_write_index(void) return write_index; } -#if defined(ENABLE_ITTI) -int signal_mask(void); -#endif void *vcd_dumper_thread_rt(void *args) { @@ -644,9 +641,7 @@ void *vcd_dumper_thread_rt(void *args) struct sched_param sched_param; uint32_t data_ready_wait; -# if defined(ENABLE_ITTI) return 0; //signal_mask(); //function defined at common/utils/ocp_itti/intertask_interface.cpp -# endif sched_param.sched_priority = sched_get_priority_min(SCHED_FIFO) + 1; sched_setscheduler(0, SCHED_FIFO, &sched_param); diff --git a/common/utils/T/local_tracer.c b/common/utils/T/local_tracer.c index 4be0b35d16..8cbd06490d 100644 --- a/common/utils/T/local_tracer.c +++ b/common/utils/T/local_tracer.c @@ -15,7 +15,7 @@ #include "T_messages.txt.h" #include "T_defs.h" #include "T_IDs.h" - +#include "softmodem-common.h" static T_cache_t *T_local_cache; static int T_busylist_head; @@ -357,24 +357,22 @@ static void forward(void *_forwarder, char *buf, int size) { if (f->tail != NULL) f->tail->next = new; f->tail = new; -#if BASIC_SIMULATOR - + if( IS_SOFTMODEM_BASICSIM){ /* When runnng the basic simulator, the tracer may be too slow. * Let's not take too much memory in the tracee and * wait if there is too much data to send. 200MB is * arbitrary. */ - while (f->memusage > 200 * 1024 * 1024) { - if (pthread_cond_signal(&f->cond)) abort(); + while (f->memusage > 200 * 1024 * 1024) { + if (pthread_cond_signal(&f->cond)) abort(); - if (pthread_mutex_unlock(&f->lock)) abort(); + if (pthread_mutex_unlock(&f->lock)) abort(); - usleep(1000); + usleep(1000); - if (pthread_mutex_lock(&f->lock)) abort(); + if (pthread_mutex_lock(&f->lock)) abort(); + } } - -#endif /* BASIC_SIMULATOR */ f->memusage += size+4; /* warn every 100MB */ diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c index 6626c8103b..10163b22b5 100644 --- a/common/utils/telnetsrv/telnetsrv.c +++ b/common/utils/telnetsrv/telnetsrv.c @@ -53,6 +53,7 @@ #include #include "common/utils/load_module_shlib.h" #include "common/config/config_userapi.h" +#include "executables/softmodem-common.h" #include @@ -546,6 +547,7 @@ void run_telnetsrv(void) { int readc, filled; int status; int optval = 1; + char prompt[sizeof(TELNET_PROMPT_PREFIX)+10]; pthread_setname_np(pthread_self(), "telnet"); set_sched(pthread_self(),0,telnetparams.priority); sock = socket(AF_INET, SOCK_STREAM, 0); @@ -570,6 +572,7 @@ void run_telnetsrv(void) { fprintf(stderr,"[TELNETSRV] Error %s on listen call\n",strerror(errno)); using_history(); + int plen=sprintf(prompt,"%s_%s> ",TELNET_PROMPT_PREFIX,get_softmodem_function(NULL)); printf("\nInitializing telnet server...\n"); while( (telnetparams.new_socket = accept(sock, &cli_addr, &cli_len)) ) { @@ -613,9 +616,9 @@ void run_telnetsrv(void) { HIST_ENTRY *hisentry = history_get(strtol(buf+1,NULL,0)); if (hisentry) { - char msg[TELNET_MAX_MSGLENGTH + sizeof(TELNET_PROMPT) +10]; + char msg[TELNET_MAX_MSGLENGTH + plen +10]; sprintf(buf,"%s",hisentry->line); - sprintf(msg,"%s %s\n",TELNET_PROMPT, hisentry->line); + sprintf(msg,"%s %s\n",prompt, hisentry->line); send(telnetparams.new_socket, msg, strlen(msg), MSG_NOSIGNAL); } } @@ -635,7 +638,7 @@ void run_telnetsrv(void) { add_history(buf); } - send(telnetparams.new_socket, TELNET_PROMPT, sizeof(TELNET_PROMPT), MSG_NOSIGNAL); + send(telnetparams.new_socket, prompt, strlen(prompt), MSG_NOSIGNAL); } else { printf ("[TELNETSRV] Closing telnet connection...\n"); break; @@ -653,7 +656,7 @@ void run_telnetsrv(void) { } /*------------------------------------------------------------------------------------------------*/ -/* set_telnetmodule loads the commands delivered with the telnet server +/* load the commands delivered with the telnet server * * * @@ -715,7 +718,11 @@ int add_sharedmodules(void) { int telnetsrv_autoinit(void) { memset(&telnetparams,0,sizeof(telnetparams)); config_get( telnetoptions,sizeof(telnetoptions)/sizeof(paramdef_t),"telnetsrv"); - + /* possibly load a exec specific shared lib */ + char *execfunc=get_softmodem_function(NULL); + char libname[64]; + sprintf(libname,"telnetsrv_%s",execfunc); + load_module_shlib(libname,NULL,0,NULL); if(pthread_create(&telnetparams.telnet_pthread,NULL, (void *(*)(void *))run_telnetsrv, NULL) != 0) { fprintf(stderr,"[TELNETSRV] Error %s on pthread_create call\n",strerror(errno)); return -1; diff --git a/common/utils/telnetsrv/telnetsrv.h b/common/utils/telnetsrv/telnetsrv.h index 89f6a8dda1..debb9f02ec 100644 --- a/common/utils/telnetsrv/telnetsrv.h +++ b/common/utils/telnetsrv/telnetsrv.h @@ -35,7 +35,7 @@ #define TELNET_PORT 9090 #define TELNET_MAX_MSGLENGTH 2048 -#define TELNET_PROMPT "softmodem> " +#define TELNET_PROMPT_PREFIX "softmodem" #define TELNET_MAXCMD 20 #define TELNET_CMD_MAXSIZE 20 #define TELNET_HELPSTR_SIZE 80 diff --git a/common/utils/telnetsrv/telnetsrv_enb_measurements.c b/common/utils/telnetsrv/telnetsrv_enb_measurements.c new file mode 100644 index 0000000000..9c5c5b675b --- /dev/null +++ b/common/utils/telnetsrv/telnetsrv_enb_measurements.c @@ -0,0 +1,179 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file common/utils/telnetsrv/telnetsrv_measurements.c + * \brief: implementation of telnet commands related to eNB measurments + * \author Francois TABURET + * \date 2019 + * \version 0.1 + * \company NOKIA BellLabs France + * \email: francois.taburet@nokia-bell-labs.com + * \note + * \warning + */ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + + + + +#define TELNETSERVERCODE +#include "telnetsrv.h" + +#include "common/utils/LOG/log.h" +#include "common/config/config_userapi.h" +#include "telnetsrv_measurements.h" +#include "telnetsrv_ltemeasur_def.h" +#include "telnetsrv_cpumeasur_def.h" +#include "openair2/LAYER2/MAC/mac.h" +#include "openair1/PHY/phy_extern.h" + +void measurcmd_display_macstats(telnet_printfunc_t prnt); +void measurcmd_display_macstats_ue(telnet_printfunc_t prnt); +void measurcmd_display_rlcstats(telnet_printfunc_t prnt); +void measurcmd_display_phycpu(telnet_printfunc_t prnt); +void measurcmd_display_maccpu(telnet_printfunc_t prnt); +void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt); + + +static telnet_measurgroupdef_t enbmeasurgroups[] = { + {"enb", GROUP_LTESTATS,0, measurcmd_display_macstats, {NULL}}, + {"enbues",GROUP_LTESTATS,0, measurcmd_display_macstats_ue,{NULL}}, + {"rlc", GROUP_LTESTATS,0, measurcmd_display_rlcstats, {NULL}}, + {"phycpu",GROUP_CPUSTATS,0, measurcmd_display_phycpu, {NULL}}, + {"maccpu",GROUP_CPUSTATS,0, measurcmd_display_maccpu, {NULL}}, + {"pdcpcpu",GROUP_CPUSTATS,0, measurcmd_display_pdcpcpu, {NULL}}, +}; +#define TELNET_NUM_ENBMEASURGROUPS (sizeof(enbmeasurgroups)/sizeof(telnet_measurgroupdef_t)) + +static int eNB_id =0; +static double cpufreq; + + +#define HDR "---------------------------------" + + +int get_measurgroups(telnet_measurgroupdef_t **measurgroups) { + *measurgroups = enbmeasurgroups; + return TELNET_NUM_ENBMEASURGROUPS; +} + + +void measurcmd_display_phycpu(telnet_printfunc_t prnt) { + PHY_VARS_eNB *phyvars = RC.eNB[eNB_id][0]; + telnet_cpumeasurdef_t cpumeasur[]=CPU_PHYENB_MEASURE; + prnt("%s cpu (%1.1g GHz) measurements: PHY (cpustats %s) %s\n",HDR,cpufreq, + PRINT_CPUMEAS_STATE,HDR); + measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t)); +} + +void measurcmd_display_maccpu(telnet_printfunc_t prnt) { + eNB_MAC_INST *macvars = RC.mac[eNB_id]; + telnet_cpumeasurdef_t cpumeasur[]=CPU_MACENB_MEASURE; + prnt("%s cpu (%1.1g GHz) measurements: MAC (cpustats %s) %s\n",HDR,cpufreq, + PRINT_CPUMEAS_STATE,HDR); + measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t)); +} + +void measurcmd_display_pdcpcpu(telnet_printfunc_t prnt) { + pdcp_stats_t *pdcpvars = &(eNB_pdcp_stats[eNB_id]); + telnet_cpumeasurdef_t cpumeasur[]=CPU_PDCPENB_MEASURE; + prnt("%s cpu (%1.1g GHz) measurements: PDCP (cpustats %s) %s \n",HDR,cpufreq, + PRINT_CPUMEAS_STATE,HDR); + measurcmd_display_cpumeasures(prnt, cpumeasur, sizeof(cpumeasur)/sizeof(telnet_cpumeasurdef_t)); +} +/*----------------------------------------------------------------------------------------------------*/ + + +void measurcmd_display_macstats_ue(telnet_printfunc_t prnt) { + UE_list_t *UE_list = &(RC.mac[eNB_id]->UE_list); + + for (int UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) { + for (int i=0; inumactiveCCs[UE_id]; i++) { + int CC_id = UE_list->ordered_CCids[i][UE_id]; + prnt("%s UE %i Id %i CCid %i %s\n",HDR,i,UE_id,CC_id,HDR); + eNB_UE_STATS *macuestatptr = &(UE_list->eNB_UE_stats[CC_id][UE_id]); + telnet_ltemeasurdef_t statsptr[]=LTEMAC_UEMEASURE; + measurcmd_display_measures(prnt, statsptr, sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t)); + } + } +} /* measurcmd_display_macstats_ue */ + +void measurcmd_display_macstats(telnet_printfunc_t prnt) { + for (int CC_id=0 ; CC_id < MAX_NUM_CCs; CC_id++) { + eNB_STATS *macstatptr=&(RC.mac[eNB_id]->eNB_stats[CC_id]); + telnet_ltemeasurdef_t statsptr[]=LTEMAC_MEASURE; + prnt("%s eNB %i mac stats CC %i frame %u %s\n", + HDR, eNB_id, CC_id, RC.mac[eNB_id]->frame,HDR); + measurcmd_display_measures(prnt,statsptr,sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t)); + } +} /* measurcmd_display_macstats */ + + +void measurcmd_display_one_rlcstat(telnet_printfunc_t prnt, int UE_id, telnet_ltemeasurdef_t *statsptr, int num_rlcmeasure, unsigned int *rlcstats, + char *rbid_str, protocol_ctxt_t *ctxt, const srb_flag_t srb_flagP, const rb_id_t rb_idP) + +{ + int rlc_status = rlc_stat_req(ctxt,srb_flagP,rb_idP, + rlcstats, rlcstats+1, rlcstats+2, rlcstats+3, rlcstats+4, rlcstats+5, + rlcstats+6, rlcstats+7, rlcstats+8, rlcstats+9, rlcstats+10, rlcstats+11, + rlcstats+12, rlcstats+13, rlcstats+14, rlcstats+15, rlcstats+16, rlcstats+17, + rlcstats+18, rlcstats+19, rlcstats+20, rlcstats+21, rlcstats+22, rlcstats+23, + rlcstats+24, rlcstats+25, rlcstats+26, rlcstats+27); + + if (rlc_status == RLC_OP_STATUS_OK) { + prnt("%s UE %i RLC %s mode %s %s\n",HDR,UE_id, rbid_str, + (rlcstats[0]==RLC_MODE_AM)? "AM": (rlcstats[0]==RLC_MODE_UM)?"UM":"NONE",HDR); + measurcmd_display_measures(prnt, statsptr, num_rlcmeasure); + } +} /* status measurcmd_rlc_stat_req */ + + +void measurcmd_display_rlcstats(telnet_printfunc_t prnt) { + protocol_ctxt_t ctxt; + UE_list_t *UE_list = &(RC.mac[eNB_id]->UE_list); + telnet_ltemeasurdef_t statsptr[]=LTE_RLCMEASURE; + int num_rlcmeasure = sizeof(statsptr)/sizeof(telnet_ltemeasurdef_t ); + unsigned int *rlcstats = malloc(num_rlcmeasure*sizeof(unsigned int)); + eNB_MAC_INST *eNB = RC.mac[eNB_id]; + + for(int i=0; i head; UE_id>=0; UE_id=UE_list->next[UE_id]) { +#define NB_eNB_INST 1 + PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt,eNB_id, ENB_FLAG_YES,UE_list->eNB_UE_stats[0][UE_id].crnti, + eNB->frame,eNB->subframe,eNB_id); + measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DCCH", &ctxt, SRB_FLAG_YES, DCCH); + measurcmd_display_one_rlcstat(prnt, UE_id, statsptr, num_rlcmeasure, rlcstats, "DTCH", &ctxt, SRB_FLAG_NO, DTCH-2); + } +} /* measurcmd_display_macstats_ue */ + + + + diff --git a/common/utils/telnetsrv/telnetsrv_enb_phycmd.c b/common/utils/telnetsrv/telnetsrv_enb_phycmd.c new file mode 100644 index 0000000000..f7deec1801 --- /dev/null +++ b/common/utils/telnetsrv/telnetsrv_enb_phycmd.c @@ -0,0 +1,123 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/*! \file common/utils/telnetsrv/telnetsrv_phycmd.c + * \brief: implementation of telnet commands related to softmodem linux process + * \author Francois TABURET + * \date 2017 + * \version 0.1 + * \company NOKIA BellLabs France + * \email: francois.taburet@nokia-bell-labs.com + * \note + * \warning + */ +#define _GNU_SOURCE +#include +#include + + +#define TELNETSERVERCODE +#include "telnetsrv.h" +#define TELNETSRV_PHYCMD_MAIN +#include "telnetsrv_phycmd.h" +char *prnbuff; +extern int dump_eNB_stats(PHY_VARS_eNB *eNB, char *buffer, int length); + +void init_phytelnet(void) { + prnbuff=malloc(get_phybsize() ); + + if (prnbuff == NULL) { + fprintf(stderr,"Error %s on malloc in init_phytelnet()\n",strerror(errno)); + } +} + +void display_uestatshead( telnet_printfunc_t prnt) { + prnt("cc ue rnti Dmcs Umcs tao tau Dbr Dtb \n"); +} + +void dump_uestats(int debug, telnet_printfunc_t prnt, uint8_t prntflag) { + int p; + p=dump_eNB_l2_stats( prnbuff, 0); + + if(prntflag>=1) + prnt("%s\n",prnbuff); + + if(debug>=1) + prnt("%i bytes printed\n",p); +} + +void display_uestats(int debug, telnet_printfunc_t prnt, int ue) { + for (int cc=0; cc<1 ; cc++) { + } +} + +void display_phycounters(char *buf, int debug, telnet_printfunc_t prnt) { + prnt(" DLSCH kb DLSCH kb/s\n"); + dump_uestats(debug, prnt,0); +} + +int dump_phyvars(char *buf, int debug, telnet_printfunc_t prnt) { + if (debug > 0) + prnt("phy interface module received %s\n",buf); + + if (strcasestr(buf,"phycnt") != NULL) { + display_phycounters(buf, debug, prnt); + } + + if (strcasestr(buf,"uestat") != NULL) { + char *cptr=strcasestr(buf+sizeof("uestat"),"UE"); + display_uestatshead(prnt); + + if (cptr != NULL) { + int ueidx = strtol( cptr+sizeof("UE"), NULL, 10); + + if (ueidx < NUMBER_OF_UE_MAX && ueidx >= 0) { + display_uestats(debug, prnt,ueidx); + } + } /* if cptr != NULL */ + else { + for (int ue=0; ue]", dump_phyvars}, + + {"","",NULL}, +}; + + +/*-------------------------------------------------------------------------------------*/ +void add_phy_cmds(void) { + init_phytelnet(); + add_telnetcmd("phy", phy_vardef, phy_cmdarray); +} diff --git a/executables/nr-gnb.c b/executables/nr-gnb.c index 46689b137a..fc012b0ab2 100644 --- a/executables/nr-gnb.c +++ b/executables/nr-gnb.c @@ -93,10 +93,8 @@ // extern openair0_device openair0; -#if defined(ENABLE_ITTI) - extern volatile int start_gNB; - extern volatile int start_UE; -#endif +extern volatile int start_gNB; +extern volatile int start_UE; extern volatile int oai_exit; extern openair0_config_t openair0_cfg[MAX_CARDS]; @@ -360,7 +358,7 @@ static void *gNB_L1_thread( void *param ) { } -#if 0 //defined(ENABLE_ITTI) && defined(ENABLE_USE_MME) +#if 0 // Wait for gNB application initialization to be complete (gNB registration to MME) static void wait_system_ready (char *message, volatile int *start_flag) { static char *indicator[] = {". ", ".. ", "... ", ".... ", ".....", diff --git a/executables/nr-softmodem-common.h b/executables/nr-softmodem-common.h index e014eaf93f..e6aafafeb9 100644 --- a/executables/nr-softmodem-common.h +++ b/executables/nr-softmodem-common.h @@ -142,9 +142,7 @@ extern int sync_var; extern int transmission_mode; extern double cpuf; -#if defined(ENABLE_ITTI) - extern volatile int start_eNB; - extern volatile int start_UE; -#endif +extern volatile int start_eNB; +extern volatile int start_UE; #endif diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c index 6b72562033..d8cb4da267 100644 --- a/executables/nr-softmodem.c +++ b/executables/nr-softmodem.c @@ -71,9 +71,7 @@ unsigned short config_frames[4] = {2,9,11,13}; #include "UTIL/OTG/otg_vars.h" #endif -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "PHY/INIT/phy_init.h" @@ -101,9 +99,7 @@ pthread_mutex_t sync_mutex; int sync_var=-1; //!< protected by mutex \ref sync_mutex. int config_sync_var=-1; -#if defined(ENABLE_ITTI) - volatile int start_gNB = 0; -#endif +volatile int start_gNB = 0; volatile int oai_exit = 0; static int wait_for_sync = 0; @@ -119,9 +115,7 @@ int32_t uplink_frequency_offset[MAX_NUM_CCs][4]; //Temp fix for inexistent NR upper layer unsigned char NB_gNB_INST = 1; -#if defined(ENABLE_ITTI) - static char *itti_dump_file = NULL; -#endif +static char *itti_dump_file = NULL; int UE_scan = 1; int UE_scan_carrier = 0; @@ -302,7 +296,7 @@ void exit_function(const char *file, const char *function, const int line, const exit(1); } -#if defined(ENABLE_ITTI) + void *l2l1_task(void *arg) { MessageDef *message_p = NULL; int result; @@ -375,7 +369,6 @@ void *l2l1_task(void *arg) { */ return NULL; } -#endif int create_gNB_tasks(uint32_t gnb_nb) { LOG_D(GNB_APP, "%s(gnb_nb:%d)\n", __FUNCTION__, gnb_nb); @@ -638,7 +631,6 @@ void wait_gNBs(void) { printf("gNB L1 are configured\n"); } -#if defined(ENABLE_ITTI) /* * helper function to terminate a certain ITTI task */ @@ -756,7 +748,6 @@ int restart_L1L2(module_id_t gnb_id) { pthread_mutex_unlock(&sync_mutex); return 0; } -#endif static void wait_nfapi_init(char *thread_name) { printf( "waiting for NFAPI PNF connection and population of global structure (%s)\n",thread_name); @@ -814,7 +805,7 @@ int main( int argc, char **argv ) configure_linux(); printf("Reading in command-line options\n"); get_options (); - get_common_options(); + get_common_options(SOFTMODEM_GNB_BIT ); if (CONFIG_ISFLAGSET(CONFIG_ABORT) ) { fprintf(stderr,"Getting configuration failed\n"); @@ -835,11 +826,10 @@ int main( int argc, char **argv ) } cpuf=get_cpu_freq_GHz(); -#if defined(ENABLE_ITTI) itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info); // initialize mscgen log after ITTI MSC_INIT(MSC_E_UTRAN, THREAD_MAX+TASK_MAX); -#endif + init_opt(); @@ -859,8 +849,6 @@ init_opt(); if(IS_SOFTMODEM_NOS1) init_pdcp(); -#if defined(ENABLE_ITTI) - if (RC.nb_nr_inst > 0) { // don't create if node doesn't connect to RRC/S1/GTP AssertFatal(create_gNB_tasks(1) == 0,"cannot create ITTI tasks\n"); @@ -869,7 +857,6 @@ init_opt(); RCconfig_L1(); } -#endif /* Start the agent. If it is turned off in the configuration, it won't start */ RCconfig_nr_flexran(); @@ -1004,19 +991,12 @@ init_opt(); // wait for end of program printf("TYPE TO TERMINATE\n"); //getchar(); -#if defined(ENABLE_ITTI) printf("Entering ITTI signals handler\n"); itti_wait_tasks_end(); printf("Returned from ITTI signal handler\n"); oai_exit=1; printf("oai_exit=%d\n",oai_exit); -#else - while (oai_exit==0) - sleep(1); - - printf("Terminating application - oai_exit=%d\n",oai_exit); -#endif // stop threads /*#ifdef XFORMS diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c index 1781ed0d8d..de01240537 100644 --- a/executables/nr-uesoftmodem.c +++ b/executables/nr-uesoftmodem.c @@ -332,8 +332,6 @@ void init_scope(void) { } - -#if defined(ENABLE_ITTI) void *l2l1_task(void *arg) { MessageDef *message_p = NULL; int result; @@ -373,7 +371,7 @@ void *l2l1_task(void *arg) { return NULL; } -#endif + int16_t dlsch_demod_shift; @@ -650,7 +648,7 @@ int main( int argc, char **argv ) { logInit(); // get options and fill parameters from configuration file get_options (); //Command-line options, enb_properties - get_common_options(); + get_common_options(SOFTMODEM_5GUE_BIT ); #if T_TRACER T_Config_Init(); #endif diff --git a/executables/softmodem-common.c b/executables/softmodem-common.c index 00b974e3ae..0c4032c41b 100644 --- a/executables/softmodem-common.c +++ b/executables/softmodem-common.c @@ -37,6 +37,7 @@ #include "common/utils/load_module_shlib.h" #include "common/utils/telnetsrv/telnetsrv.h" #include "executables/thread-common.h" +#include "common/utils/LOG/log.h" #include "softmodem-common.h" static softmodem_params_t softmodem_params; @@ -44,7 +45,7 @@ char *parallel_config=NULL; char *worker_config=NULL; - +static mapping softmodem_funcs[] = MAPPING_SOFTMODEM_FUNCTIONS; static struct timespec start; uint64_t get_softmodem_optmask(void) { @@ -60,7 +61,26 @@ softmodem_params_t *get_softmodem_params(void) { return &softmodem_params; } -void get_common_options(void) { +int32_t check_execmask(uint64_t execmask) { + char *softmodemfunc=map_int_to_str(softmodem_funcs, execmask); + if (softmodemfunc != NULL) { + set_softmodem_optmask(execmask); + return 0; + } + return -1; +} +char *get_softmodem_function(uint64_t *sofmodemfunc_mask_ptr) { + uint64_t fmask=(get_softmodem_optmask()&SOFTMODEM_FUNC_BITS); + char *softmodemfunc=map_int_to_str(softmodem_funcs, fmask); + if (sofmodemfunc_mask_ptr != NULL) + *sofmodemfunc_mask_ptr=fmask; + if (softmodemfunc != NULL) { + return softmodemfunc; + } + return "???"; +} + +void get_common_options(uint32_t execmask) { uint32_t online_log_messages; uint32_t glog_level ; uint32_t start_telnetsrv = 0; @@ -70,6 +90,7 @@ void get_common_options(void) { paramdef_t cmdline_params[] =CMDLINE_PARAMS_DESC ; paramdef_t cmdline_logparams[] =CMDLINE_LOGPARAMS_DESC ; checkedparam_t cmdline_log_CheckParams[] = CMDLINE_LOGPARAMS_CHECK_DESC; + check_execmask(execmask); config_get( cmdline_params,sizeof(cmdline_params)/sizeof(paramdef_t),NULL); config_set_checkfunctions(cmdline_logparams, cmdline_log_CheckParams, sizeof(cmdline_logparams)/sizeof(paramdef_t)); diff --git a/executables/softmodem-common.h b/executables/softmodem-common.h index 69ed98635b..c9a24577dc 100644 --- a/executables/softmodem-common.h +++ b/executables/softmodem-common.h @@ -31,6 +31,7 @@ */ #ifndef SOFTMODEM_COMMON_H #define SOFTMODEM_COMMON_H +#include "openair1/PHY/defs_common.h" #ifdef __cplusplus extern "C" { @@ -164,6 +165,14 @@ extern "C" #define SOFTMODEM_BASICSIM_BIT (1<<11) #define SOFTMODEM_SIML1_BIT (1<<12) #define SOFTMODEM_DOFORMS_BIT (1<<15) +#define SOFTMODEM_RECPLAY_BIT (1<<16) +#define SOFTMODEM_ENB_BIT (1<<20) +#define SOFTMODEM_GNB_BIT (1<<21) +#define SOFTMODEM_4GUE_BIT (1<<22) +#define SOFTMODEM_5GUE_BIT (1<<23) +#define SOFTMODEM_FUNC_BITS (SOFTMODEM_ENB_BIT | SOFTMODEM_GNB_BIT | SOFTMODEM_5GUE_BIT | SOFTMODEM_4GUE_BIT) +#define MAPPING_SOFTMODEM_FUNCTIONS {{"enb",SOFTMODEM_ENB_BIT},{"gnb",SOFTMODEM_GNB_BIT},{"4Gue",SOFTMODEM_4GUE_BIT},{"5Gue",SOFTMODEM_5GUE_BIT}} + #define IS_SOFTMODEM_NOS1 ( get_softmodem_optmask() & SOFTMODEM_NOS1_BIT) #define IS_SOFTMODEM_NOKRNMOD ( get_softmodem_optmask() & SOFTMODEM_NOKRNMOD_BIT) @@ -172,7 +181,11 @@ extern "C" #define IS_SOFTMODEM_BASICSIM ( get_softmodem_optmask() & SOFTMODEM_BASICSIM_BIT) #define IS_SOFTMODEM_SIML1 ( get_softmodem_optmask() & SOFTMODEM_SIML1_BIT) #define IS_SOFTMODEM_DOFORMS ( get_softmodem_optmask() & SOFTMODEM_DOFORMS_BIT) - +#define IS_SOFTMODEM_IQPLAYER ( get_softmodem_optmask() & SOFTMODEM_RECPLAY_BIT) +#define IS_SOFTMODEM_ENB_BIT ( get_softmodem_optmask() & SOFTMODEM_ENB_BIT) +#define IS_SOFTMODEM_GNB_BIT ( get_softmodem_optmask() & SOFTMODEM_GNB_BIT) +#define IS_SOFTMODEM_4GUE_BIT ( get_softmodem_optmask() & SOFTMODEM_4GUE_BIT) +#define IS_SOFTMODEM_5GUE_BIT ( get_softmodem_optmask() & SOFTMODEM_5GUE_BIT) typedef struct { uint64_t optmask; @@ -195,7 +208,8 @@ typedef struct { extern uint64_t get_softmodem_optmask(void); extern uint64_t set_softmodem_optmask(uint64_t bitmask); extern softmodem_params_t *get_softmodem_params(void); -extern void get_common_options(void); +extern void get_common_options(uint32_t execmask); +extern char *get_softmodem_function(uint64_t *sofmodemfunc_mask_ptr); #define SOFTMODEM_RTSIGNAL (SIGRTMIN+1) extern void set_softmodem_sighandler(void); extern uint32_t downlink_frequency[MAX_NUM_CCs][4]; diff --git a/openair1/PHY/LTE_TRANSPORT/pucch.c b/openair1/PHY/LTE_TRANSPORT/pucch.c index 8c19f44d2f..e142d2f29f 100644 --- a/openair1/PHY/LTE_TRANSPORT/pucch.c +++ b/openair1/PHY/LTE_TRANSPORT/pucch.c @@ -36,7 +36,7 @@ #include "common/utils/LOG/log.h" #include "common/utils/LOG/vcd_signal_dumper.h" - +#include "executables/softmodem-common.h" //uint8_t ncs_cell[20][7]; //#define DEBUG_PUCCH_TXS @@ -801,9 +801,8 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB, for (j=0; jpucch1_stats_cnt[j][i]=0; eNB->pucch1ab_stats_cnt[j][i]=0; -#if defined(USRP_REC_PLAY) // not 100% sure - eNB->pucch1_stats_thres[j][i]=0; -#endif + if ( IS_SOFTMODEM_IQPLAYER) + eNB->pucch1_stats_thres[j][i]=0; } } @@ -1193,15 +1192,13 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB, stat_re=0; stat_im=0; // Do detection now -#if defined(USRP_REC_PLAY) - // It looks like the value is a bit messy when RF is replayed. + + // It looks like the pucch1_thres value is a bit messy when RF is replayed. // For instance i assume to skip pucch1_thres from the test below. // Not 100% sure - if (sigma2_dB<(dB_fixed(stat_max))) {// -#else - if (sigma2_dB<(dB_fixed(stat_max)-pucch1_thres)) {// -#endif + + if (sigma2_dB<(dB_fixed(stat_max) - (IS_SOFTMODEM_IQPLAYER?0:pucch1_thres)) ) {// chL = (nsymb>>1)-4; chest_mag=0; cfo = (frame_parms->Ncp==0) ? &cfo_pucch_np[14*phase_max] : &cfo_pucch_ep[12*phase_max]; @@ -1339,11 +1336,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB, if (fmt==pucch_format1b) *(1+payload) = (stat_im<0) ? 1 : 2; } else { // insufficient energy on PUCCH so NAK -#if defined(USRP_REC_PLAY) - LOG_D(PHY,"PUCCH 1a/b: NAK subframe %d : sigma2_dB %d, stat_max %d, pucch1_thres %d\n",subframe,sigma2_dB,dB_fixed(stat_max),pucch1_thres); -#else LOG_D(PHY,"In pucch.c PUCCH 1a/b: NAK subframe %d : sigma2_dB %d, stat_max %d, pucch1_thres %d\n",subframe,sigma2_dB,dB_fixed(stat_max),pucch1_thres); -#endif *payload = 4; // DTX ((int16_t *)&eNB->pucch1ab_stats[UE_id][(subframe<<10) + (eNB->pucch1ab_stats_cnt[UE_id][subframe])])[0] = (int16_t)(stat_re); ((int16_t *)&eNB->pucch1ab_stats[UE_id][(subframe<<10) + (eNB->pucch1ab_stats_cnt[UE_id][subframe])])[1] = (int16_t)(stat_im); diff --git a/openair1/SCHED/prach_procedures.c b/openair1/SCHED/prach_procedures.c index 4f2d05ef50..eb9a2922c5 100644 --- a/openair1/SCHED/prach_procedures.c +++ b/openair1/SCHED/prach_procedures.c @@ -46,9 +46,7 @@ #include -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" extern int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind); diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c index 1bb544d204..95dc539ef4 100644 --- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c +++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c @@ -45,9 +45,7 @@ #include -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" extern uint8_t nfapi_mode; /* diff --git a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c index 0067efb4d9..430a3ee0b5 100644 --- a/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c +++ b/openair1/SCHED_NR_UE/phy_procedures_nr_ue.c @@ -74,15 +74,7 @@ fifo_dump_emos_UE emos_dump_UE; #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" - -#if defined(ENABLE_ITTI) -# include "intertask_interface.h" -#endif - -//#include "PHY/defs.h" - -//#include "PHY/CODING/extern.h" - +#include "intertask_interface.h" #include "T.h" #define DLSCH_RB_ALLOC 0x1fbf // skip DC RB (total 23/25 RBs) diff --git a/openair1/SCHED_UE/phy_procedures_lte_ue.c b/openair1/SCHED_UE/phy_procedures_lte_ue.c index 8ca533c146..6d92beaddf 100644 --- a/openair1/SCHED_UE/phy_procedures_lte_ue.c +++ b/openair1/SCHED_UE/phy_procedures_lte_ue.c @@ -53,11 +53,7 @@ #include "common/utils/LOG/vcd_signal_dumper.h" #include "UTIL/OPT/opt.h" - -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif - +#include "intertask_interface.h" #include "PHY/defs_UE.h" #include "PHY/CODING/coding_extern.h" @@ -4885,10 +4881,8 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue, uint8_t abstraction_flag, uint8_t do_pdcch_flag, runmode_t mode) { -#if defined(ENABLE_ITTI) MessageDef *msg_p; int result; -#endif int frame_rx = proc->frame_rx; int frame_tx = proc->frame_tx; int subframe_rx = proc->subframe_rx; @@ -4905,9 +4899,6 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue, if ( LOG_DEBUGFLAG(UE_TIMING)) { start_meas(&ue->phy_proc[ue->current_thread_id[subframe_rx]]); } - -#if defined(ENABLE_ITTI) - do { // Checks if a message has been sent to PHY sub-task itti_poll_msg (TASK_PHY_UE, &msg_p); @@ -4929,8 +4920,6 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue, } } while(msg_p != NULL); -#endif - for (slot=0; slot<2; slot++) { if ((subframe_select(&ue->frame_parms,subframe_tx)==SF_UL)|| (ue->frame_parms.frame_type == FDD)) { diff --git a/openair2/GNB_APP/gnb_paramdef.h b/openair2/GNB_APP/gnb_paramdef.h index 76d24f75f3..5b97796f8a 100644 --- a/openair2/GNB_APP/gnb_paramdef.h +++ b/openair2/GNB_APP/gnb_paramdef.h @@ -45,10 +45,8 @@ #define GNB_CONF_STRING_OTG_APP_TYPE "app_type" #define GNB_CONF_STRING_OTG_BG_TRAFFIC "bg_traffic" -#if defined(ENABLE_ITTI) && defined(ENABLE_USE_MME) extern int asn_debug; extern int asn1_xer_print; -#endif #ifdef LIBCONFIG_LONG #define libconfig_int long diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c index 8d497c80d3..eef1f9c976 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler.c +++ b/openair2/LAYER2/MAC/eNB_scheduler.c @@ -57,9 +57,7 @@ /* for fair round robin SCHED */ #include "eNB_scheduler_fairRR.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "assertions.h" diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c index e85255e8ce..fb765e6dac 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c @@ -55,14 +55,12 @@ //#include "LAYER2/MAC/pre_processor.c" #include "pdcp.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "SIMULATION/TOOLS/sim.h" // for taus #include "T.h" - +#include "executables/softmodem-common.h" #include "common/ran_context.h" #include "LAYER2/MAC/eNB_scheduler_fairRR.h" @@ -1353,28 +1351,31 @@ initiate_ra_proc(module_id_t module_idP, /* TODO: find better procedure to allocate RNTI */ do { -#if defined(USRP_REC_PLAY) // deterministic rnti in usrp record/playback mode - static int drnti[MAX_MOBILES_PER_ENB] = { 0xbda7, 0x71da, 0x9c40, 0xc350, 0x2710, 0x4e20, 0x7530, 0x1388, 0x3a98, 0x61a8, 0x88b8, 0xafc8, 0xd6d8, 0x1b58, 0x4268, 0x6978 }; - int j = 0; - int nb_ue = 0; + if (IS_SOFTMODEM_IQPLAYER) { /* iq player mode, use deterministic rnti */ + static int drnti[MAX_MOBILES_PER_ENB]; + static int drnti_def[]={ 0xbda7, 0x71da, 0x9c40, 0xc350, 0x2710, 0x4e20, 0x7530, 0x1388, 0x3a98, 0x61a8, 0x88b8, 0xafc8, 0xd6d8, 0x1b58, 0x4268, 0x6978 }; + for (int j=0; j 0) { - nb_ue++; - } else { - break; + for (int j = 0; j < MAX_MOBILES_PER_ENB; j++) { + if (UE_RNTI(module_idP, j) > 0) { + nb_ue++; + } else { + break; + } } - } - if (nb_ue >= MAX_MOBILES_PER_ENB) { - printf("No more free RNTI available, increase MAX_MOBILES_PER_ENB\n"); - abort(); - } + if (nb_ue >= MAX_MOBILES_PER_ENB || nb_ue >= (sizeof(drnti_def)/sizeof(int))) { + printf("No more free RNTI available, increase MAX_MOBILES_PER_ENB\n"); + abort(); + } - ra[i].rnti = drnti[nb_ue]; -#else - ra[i].rnti = taus(); -#endif + ra[i].rnti = drnti[nb_ue]; + } else { + ra[i].rnti = taus(); + } loop++; } while (loop != 100 && /* TODO: this is not correct, the rnti may be in use without diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c index f5cd3a0753..5b99578d57 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_bch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c @@ -44,9 +44,7 @@ //#include "LAYER2/MAC/pre_processor.c" #include "pdcp.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #define ENABLE_MAC_PAYLOAD_DEBUG #define DEBUG_eNB_SCHEDULER 1 diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c index 2a56c61a68..eba4bdcee9 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c @@ -53,9 +53,7 @@ #include "assertions.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include diff --git a/openair2/LAYER2/MAC/eNB_scheduler_mch.c b/openair2/LAYER2/MAC/eNB_scheduler_mch.c index e351b69bb0..2953c8e70b 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_mch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_mch.c @@ -48,10 +48,6 @@ #include "pdcp.h" #include "assertions.h" -//#if defined(ENABLE_ITTI) -//#include "intertask_interface.h" -//#endif -// #include "SIMULATION/TOOLS/sim.h" // for taus #define ENABLE_MAC_PAYLOAD_DEBUG diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c index 5189e76975..e76e6b24ba 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c @@ -48,10 +48,8 @@ //#include "LAYER2/MAC/pre_processor.c" #include "pdcp.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif - +#include "intertask_interface.h" +#include "executables/softmodem-common.h" #include "T.h" #define ENABLE_MAC_PAYLOAD_DEBUG @@ -2184,9 +2182,8 @@ add_new_ue(module_id_t mod_idP, UE_list->ordered_ULCCids[0][UE_id] = cc_idP; UE_list->num_UEs++; UE_list->active[UE_id] = TRUE; -#if defined(USRP_REC_PLAY) // not specific to record/playback ? - UE_list->UE_template[cc_idP][UE_id].pre_assigned_mcs_ul = 0; -#endif + if (IS_SOFTMODEM_IQPLAYER)// not specific to record/playback ? + UE_list->UE_template[cc_idP][UE_id].pre_assigned_mcs_ul = 0; UE_list->UE_template[cc_idP][UE_id].rach_resource_type = rach_resource_type; memset((void *) &UE_list->UE_sched_ctrl[UE_id], 0, diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c index 430f73cd9d..6c19ad6a46 100644 --- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c +++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c @@ -48,9 +48,7 @@ #include "assertions.h" #include "pdcp.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "ENB_APP/flexran_agent_defs.h" #include "flexran_agent_ran_api.h" diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c index 1244125bb6..8518cba14c 100644 --- a/openair2/LAYER2/MAC/ue_procedures.c +++ b/openair2/LAYER2/MAC/ue_procedures.c @@ -56,9 +56,7 @@ #include "pdcp.h" #include "targets/RT/USER/lte-softmodem.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "assertions.h" @@ -2455,10 +2453,8 @@ ue_scheduler(const module_id_t module_idP, struct LTE_RACH_ConfigCommon *rach_ConfigCommon = (struct LTE_RACH_ConfigCommon *) NULL; protocol_ctxt_t ctxt; -#if defined(ENABLE_ITTI) MessageDef *msg_p; int result; -#endif #if UE_TIMING_TRACE start_meas(&UE_mac_inst[module_idP].ue_scheduler); #endif @@ -2467,7 +2463,6 @@ ue_scheduler(const module_id_t module_idP, PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_NO, UE_mac_inst[module_idP].crnti, txFrameP, txSubframeP, eNB_indexP); -#if defined(ENABLE_ITTI) if(module_idP == 0) { do { @@ -2497,8 +2492,6 @@ ue_scheduler(const module_id_t module_idP, } while (msg_p != NULL); } -#endif - //Mac_rlc_xface->frameP=frameP; //Rrc_xface->Frame_index=Mac_rlc_xface->frameP; //if (subframe%5 == 0) diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c index ab7757164f..d08b8211ee 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c @@ -55,9 +55,7 @@ #include "flexran_agent_extern.h" #include "flexran_agent_mac.h" -#if defined(ENABLE_ITTI) #include "intertask_interface.h" -#endif #include "assertions.h" #include diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c index df3e04dccf..409ba1d6d2 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_bch.c @@ -46,9 +46,7 @@ //#include "LAYER2/MAC/pre_processor.c" #include "pdcp.h" -#if defined(ENABLE_ITTI) #include "intertask_interface.h" -#endif #define ENABLE_MAC_PAYLOAD_DEBUG #define DEBUG_eNB_SCHEDULER 1 diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c index f3a1b3e7fd..d95819d1e7 100644 --- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c +++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c @@ -50,9 +50,7 @@ //#include "LAYER2/MAC/pre_processor.c" #include "pdcp.h" -#if defined(ENABLE_ITTI) #include "intertask_interface.h" -#endif #include "T.h" diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c index 8f9ee0af18..cb108f5d26 100644 --- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c +++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_security.c @@ -33,7 +33,7 @@ #include "UTIL/OSA/osa_defs.h" #include "common/utils/LOG/vcd_signal_dumper.h" - +#include "executables/softmodem-common.h" #include "LAYER2/MAC/mac_extern.h" #include "pdcp.h" @@ -213,28 +213,28 @@ pdcp_validate_security( stream_decrypt(pdcp_pP->cipheringAlgorithm, &decrypt_params, &buffer_decrypted); -#if !defined(USRP_REC_PLAY) - if (srb_flagP) { + if (!IS_SOFTMODEM_IQPLAYER) { + if (srb_flagP) { /* Now check the integrity of the complete PDU */ - decrypt_params.message = pdcp_pdu_buffer; - decrypt_params.blength = sdu_buffer_size << 3; - decrypt_params.key = pdcp_pP->kRRCint + 16;// 128; + decrypt_params.message = pdcp_pdu_buffer; + decrypt_params.blength = sdu_buffer_size << 3; + decrypt_params.key = pdcp_pP->kRRCint + 16;// 128; - if (stream_check_integrity(pdcp_pP->integrityProtAlgorithm, - &decrypt_params, - &pdcp_pdu_buffer[sdu_buffer_size]) != 0) { - MSC_LOG_EVENT( - (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE, - " Security: failed MAC-I Algo %X UE %"PRIx16" ", - pdcp_pP->integrityProtAlgorithm, - ctxt_pP->rnti); - LOG_E(PDCP, "[OSA][RB %ld] %s failed to validate MAC-I (key %llx) of incoming PDU\n", - rb_id, (pdcp_pP->is_ue != 0) ? "UE" : "eNB",((long long unsigned int*)decrypt_params.key)[0]); - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_VALIDATE_SECURITY, VCD_FUNCTION_OUT); - return -1; + if (stream_check_integrity(pdcp_pP->integrityProtAlgorithm, + &decrypt_params, + &pdcp_pdu_buffer[sdu_buffer_size]) != 0) { + MSC_LOG_EVENT( + (ctxt_pP->enb_flag == ENB_FLAG_YES) ? MSC_PDCP_ENB:MSC_PDCP_UE, + " Security: failed MAC-I Algo %X UE %"PRIx16" ", + pdcp_pP->integrityProtAlgorithm, + ctxt_pP->rnti); + LOG_E(PDCP, "[OSA][RB %ld] %s failed to validate MAC-I (key %llx) of incoming PDU\n", + rb_id, (pdcp_pP->is_ue != 0) ? "UE" : "eNB",((long long unsigned int*)decrypt_params.key)[0]); + VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_VALIDATE_SECURITY, VCD_FUNCTION_OUT); + return -1; + } } - } -#endif + } /* !IQPLAYER */ VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_VALIDATE_SECURITY, VCD_FUNCTION_OUT); return 0; diff --git a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c index ddff2cc3d1..02a0247a03 100644 --- a/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c +++ b/openair2/LAYER2/RLC/AM_v9.3.0/rlc_am_status_report.c @@ -26,9 +26,7 @@ //----------------------------------------------------------------------------- #include "platform_types.h" //----------------------------------------------------------------------------- -#if ENABLE_ITTI - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "assertions.h" #include "list.h" #include "rlc_am.h" diff --git a/openair2/RRC/LTE/L2_interface.c b/openair2/RRC/LTE/L2_interface.c index 356dd2e481..68017be85b 100644 --- a/openair2/RRC/LTE/L2_interface.c +++ b/openair2/RRC/LTE/L2_interface.c @@ -37,9 +37,7 @@ #include "msc.h" #include "common/ran_context.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "flexran_agent_extern.h" #undef C_RNTI // C_RNTI is used in F1AP generated code, prevent preprocessor replace diff --git a/openair2/RRC/LTE/L2_interface_common.c b/openair2/RRC/LTE/L2_interface_common.c index 20df462938..fa332b5be1 100644 --- a/openair2/RRC/LTE/L2_interface_common.c +++ b/openair2/RRC/LTE/L2_interface_common.c @@ -37,9 +37,7 @@ #include "msc.h" #include "common/ran_context.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" //#define RRC_DATA_REQ_DEBUG //#define DEBUG_RRC 1 @@ -135,7 +133,6 @@ rrc_data_ind( ctxt_pP->rnti); } -#if defined(ENABLE_ITTI) { MessageDef *message_p; // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). @@ -152,11 +149,4 @@ rrc_data_ind( RRC_DCCH_DATA_IND (message_p).eNB_index = ctxt_pP->eNB_index; itti_send_msg_to_task (ctxt_pP->enb_flag ? TASK_RRC_ENB : TASK_RRC_UE, ctxt_pP->instance, message_p); } -#else - rrc_eNB_decode_dcch( - ctxt_pP, - DCCH_index, - buffer_pP, - sdu_sizeP); -#endif } diff --git a/openair2/RRC/LTE/L2_interface_ue.c b/openair2/RRC/LTE/L2_interface_ue.c index c9d4e61d0a..61ab63955d 100644 --- a/openair2/RRC/LTE/L2_interface_ue.c +++ b/openair2/RRC/LTE/L2_interface_ue.c @@ -37,9 +37,7 @@ #include "msc.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" //#define RRC_DATA_REQ_DEBUG @@ -76,7 +74,6 @@ mac_rrc_data_req_ue( LOG_D(RRC,"[UE %d] Frame %d buffer_pP status %d,\n",Mod_idP,frameP, UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size); if( (UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size > 0) ) { -#if defined(ENABLE_ITTI) { MessageDef *message_p; int ccch_size = UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size; @@ -96,7 +93,6 @@ mac_rrc_data_req_ue( itti_send_msg_to_task (TASK_MAC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p); } -#endif memcpy(&buffer_pP[0],&UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.Payload[0],UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size); uint8_t Ret_size=UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size; // UE_rrc_inst[Mod_id].Srb0[eNB_index].Tx_buffer.payload_size=0; @@ -138,7 +134,6 @@ mac_rrc_data_ind_ue( if(srb_idP == BCCH_SI_MBMS) { LOG_D(RRC,"[UE %d] Received SDU for BCCH on MBMS SRB %ld from eNB %d\n",module_idP,srb_idP,eNB_indexP); -#if defined(ENABLE_ITTI) { MessageDef *message_p; int msg_sdu_size = sizeof(RRC_MAC_BCCH_MBMS_DATA_IND (message_p).sdu); @@ -161,14 +156,10 @@ mac_rrc_data_ind_ue( RRC_MAC_BCCH_MBMS_DATA_IND (message_p).rsrp = 45 /* TODO change phy to report rspp */; itti_send_msg_to_task (TASK_RRC_UE, ctxt.instance, message_p); } -#else - decode_BCCH_MBMS_DLSCH_Message(&ctxt,eNB_indexP,(uint8_t *)sduP,sdu_lenP, 0, 0); -#endif } if(srb_idP == BCCH) { LOG_D(RRC,"[UE %d] Received SDU for BCCH on SRB %ld from eNB %d\n",module_idP,srb_idP,eNB_indexP); -#if defined(ENABLE_ITTI) { MessageDef *message_p; int msg_sdu_size = sizeof(RRC_MAC_BCCH_DATA_IND (message_p).sdu); @@ -191,9 +182,6 @@ mac_rrc_data_ind_ue( RRC_MAC_BCCH_DATA_IND (message_p).rsrp = 45 /* TODO change phy to report rspp */; itti_send_msg_to_task (TASK_RRC_UE, ctxt.instance, message_p); } -#else - decode_BCCH_DLSCH_Message(&ctxt,eNB_indexP,(uint8_t *)sduP,sdu_lenP, 0, 0); -#endif } if(srb_idP == PCCH) { @@ -204,7 +192,6 @@ mac_rrc_data_ind_ue( if((srb_idP & RAB_OFFSET) == CCCH) { if (sdu_lenP>0) { LOG_T(RRC,"[UE %d] Received SDU for CCCH on SRB %ld from eNB %d\n",module_idP,srb_idP & RAB_OFFSET,eNB_indexP); -#if defined(ENABLE_ITTI) { MessageDef *message_p; int msg_sdu_size = CCCH_SDU_SIZE; @@ -226,20 +213,12 @@ mac_rrc_data_ind_ue( RRC_MAC_CCCH_DATA_IND (message_p).rnti = rntiP; itti_send_msg_to_task (TASK_RRC_UE, ctxt.instance, message_p); } -#else - SRB_INFO *Srb_info; - Srb_info = &UE_rrc_inst[module_idP].Srb0[eNB_indexP]; - memcpy(Srb_info->Rx_buffer.Payload,sduP,sdu_lenP); - Srb_info->Rx_buffer.payload_size = sdu_lenP; - rrc_ue_decode_ccch(&ctxt, Srb_info, eNB_indexP); -#endif } } if ((srb_idP & RAB_OFFSET) == MCCH) { LOG_T(RRC,"[UE %d] Frame %d: Received SDU on MBSFN sync area %d for MCCH on SRB %ld from eNB %d\n", module_idP,frameP, mbsfn_sync_areaP, srb_idP & RAB_OFFSET,eNB_indexP); -#if defined(ENABLE_ITTI) { MessageDef *message_p; int msg_sdu_size = sizeof(RRC_MAC_MCCH_DATA_IND (message_p).sdu); @@ -259,9 +238,6 @@ mac_rrc_data_ind_ue( RRC_MAC_MCCH_DATA_IND (message_p).mbsfn_sync_area = mbsfn_sync_areaP; itti_send_msg_to_task (TASK_RRC_UE, ctxt.instance, message_p); } -#else - decode_MCCH_Message(&ctxt, eNB_indexP, sduP, sdu_lenP, mbsfn_sync_areaP); -#endif } //TTN (for D2D) @@ -297,7 +273,6 @@ rrc_data_req_ue( ctxt_pP->rnti, muiP, sdu_sizeP); -#if defined(ENABLE_ITTI) { MessageDef *message_p; // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). @@ -325,18 +300,6 @@ rrc_data_req_ue( message_p); return TRUE; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway. } -#else - return pdcp_data_req ( - ctxt_pP, - SRB_FLAG_YES, - rb_idP, - muiP, - confirmP, - sdu_sizeP, - buffer_pP, - modeP,NULL, NULL - ); -#endif } //------------------------------------------------------------------------------ @@ -352,7 +315,6 @@ rrc_data_ind_ue( rb_id_t DCCH_index = Srb_id; LOG_I(RRC, "[UE %x] Frame %d: received a DCCH %ld message on SRB %ld with Size %d from eNB %d\n", ctxt_pP->module_id, ctxt_pP->frame, DCCH_index,Srb_id,sdu_sizeP, ctxt_pP->eNB_index); -#if defined(ENABLE_ITTI) { MessageDef *message_p; // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). @@ -369,20 +331,11 @@ rrc_data_ind_ue( RRC_DCCH_DATA_IND (message_p).eNB_index = ctxt_pP->eNB_index; itti_send_msg_to_task (TASK_RRC_UE, ctxt_pP->instance, message_p); } -#else - //#warning "LG put 0 to arg4 that is eNB index" - rrc_ue_decode_dcch( - ctxt_pP, - DCCH_index, - buffer_pP, - 0); -#endif } //-------------------------------------------------------------------------------------------// void rrc_in_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index) { //-------------------------------------------------------------------------------------------// -#if defined(ENABLE_ITTI) { MessageDef *message_p; //LOG_I(RRC,"sending a message to task_mac_ue\n"); @@ -391,14 +344,6 @@ void rrc_in_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index) { RRC_MAC_IN_SYNC_IND (message_p).enb_index = eNB_index; itti_send_msg_to_task (TASK_RRC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p); } -#else - UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt=0; - - if (UE_rrc_inst[Mod_idP].Info[eNB_index].T310_active==1) { - UE_rrc_inst[Mod_idP].Info[eNB_index].N311_cnt++; - } - -#endif } //-------------------------------------------------------------------------------------------// @@ -412,7 +357,6 @@ void rrc_out_of_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt, UE_rrc_inst[Mod_idP].Info[eNB_index].N311_cnt); -#if defined(ENABLE_ITTI) { MessageDef *message_p; message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_OUT_OF_SYNC_IND); @@ -420,9 +364,6 @@ void rrc_out_of_sync_ind(module_id_t Mod_idP, frame_t frameP, uint16_t eNB_index RRC_MAC_OUT_OF_SYNC_IND (message_p).enb_index = eNB_index; itti_send_msg_to_task (TASK_RRC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p); } -#else - UE_rrc_inst[Mod_idP].Info[eNB_index].N310_cnt++; -#endif } //------------------------------------------------------------------------------ @@ -442,16 +383,11 @@ mac_UE_get_rrc_status( //-------------------------------------------------------------------------------------------// int mac_ue_ccch_success_ind(module_id_t Mod_idP, uint8_t eNB_index) { //-------------------------------------------------------------------------------------------// -#if defined(ENABLE_ITTI) { MessageDef *message_p; message_p = itti_alloc_new_message (TASK_MAC_UE, RRC_MAC_CCCH_DATA_CNF); RRC_MAC_CCCH_DATA_CNF (message_p).enb_index = eNB_index; itti_send_msg_to_task (TASK_RRC_UE, UE_MODULE_ID_TO_INSTANCE(Mod_idP), message_p); } -#else - // reset the tx buffer to indicate RRC that ccch was successfully transmitted (for example if contention resolution succeeds) - UE_rrc_inst[Mod_idP].Srb0[eNB_index].Tx_buffer.payload_size=0; -#endif return 0; } diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.c b/openair2/RRC/LTE/MESSAGES/asn1_msg.c index c9071806d2..d8f6ac145d 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.c +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.c @@ -89,9 +89,9 @@ #include "LTE_MeasIdToAddModList.h" #include "enb_config.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif + +#include "intertask_interface.h" + #include "common/ran_context.h" #include "secu_defs.h" @@ -381,17 +381,12 @@ uint8_t do_MIB_SL(const protocol_ctxt_t *const ctxt_pP, const uint8_t eNB_index, } uint8_t do_SIB1_MBMS(rrc_eNB_carrier_data_t *carrier, - int Mod_id,int CC_id -#if defined(ENABLE_ITTI) - , RrcConfigurationReq *configuration -#endif + int Mod_id,int CC_id, + RrcConfigurationReq *configuration ) { // SystemInformation_t systemInformation; -#if defined(ENABLE_ITTI) int num_plmn = configuration->num_plmn; -#else - int num_plmn = 1; -#endif + LTE_PLMN_IdentityInfo_t *PLMN_identity_info; LTE_MCC_MNC_Digit_t *dummy_mcc_0; LTE_MCC_MNC_Digit_t *dummy_mcc_1; @@ -438,16 +433,10 @@ uint8_t do_SIB1_MBMS(rrc_eNB_carrier_data_t *carrier, if (dummy_mcc_0 == NULL || dummy_mcc_1 == NULL || dummy_mcc_2 == NULL) exit(1); - -#if defined(ENABLE_ITTI) *dummy_mcc_0 = (configuration->mcc[i] / 100) % 10; *dummy_mcc_1 = (configuration->mcc[i] / 10) % 10; *dummy_mcc_2 = (configuration->mcc[i] / 1) % 10; -#else - *dummy_mcc_0 = 0; - *dummy_mcc_1 = 0; - *dummy_mcc_2 = 1; -#endif + ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list, dummy_mcc_0); ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list, dummy_mcc_1); ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list, dummy_mcc_2); @@ -460,8 +449,6 @@ uint8_t do_SIB1_MBMS(rrc_eNB_carrier_data_t *carrier, if (dummy_mnc_0 == NULL || dummy_mnc_1 == NULL || dummy_mnc_2 == NULL) exit(1); -#if defined(ENABLE_ITTI) - if (configuration->mnc[i] >= 100) { *dummy_mnc_0 = (configuration->mnc[i] / 100) % 10; *dummy_mnc_1 = (configuration->mnc[i] / 10) % 10; @@ -478,11 +465,6 @@ uint8_t do_SIB1_MBMS(rrc_eNB_carrier_data_t *carrier, } } -#else - *dummy_mnc[i][0] = 0; - *dummy_mnc[i][1] = 1; - *dummy_mnc[i][2] = 0xf; -#endif ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mnc.list, dummy_mnc_0); ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mnc.list, dummy_mnc_1); @@ -499,36 +481,20 @@ uint8_t do_SIB1_MBMS(rrc_eNB_carrier_data_t *carrier, // 16 bits (*sib1_MBMS)->cellAccessRelatedInfo_r14.trackingAreaCode_r14.buf = MALLOC(2); -#if defined(ENABLE_ITTI) (*sib1_MBMS)->cellAccessRelatedInfo_r14.trackingAreaCode_r14.buf[0] = (configuration->tac >> 8) & 0xff; (*sib1_MBMS)->cellAccessRelatedInfo_r14.trackingAreaCode_r14.buf[1] = (configuration->tac >> 0) & 0xff; -#else - (*sib1_MBMS)->cellAccessRelatedInfo_r14.trackingAreaCode_r14.buf[0] = 0x00; - (*sib1_MBMS)->cellAccessRelatedInfo_r14.trackingAreaCode_r14.buf[1] = 0x01; -#endif (*sib1_MBMS)->cellAccessRelatedInfo_r14.trackingAreaCode_r14.size=2; (*sib1_MBMS)->cellAccessRelatedInfo_r14.trackingAreaCode_r14.bits_unused=0; // 28 bits (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf = MALLOC(8); -#if defined(ENABLE_ITTI) (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[0] = (configuration->cell_identity >> 20) & 0xff; (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[1] = (configuration->cell_identity >> 12) & 0xff; (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[2] = (configuration->cell_identity >> 4) & 0xff; (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[3] = (configuration->cell_identity << 4) & 0xf0; -#else - (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[0] = 0x00; - (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[1] = 0x00; - (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[2] = 0x00; - (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.buf[3] = 0x10; -#endif (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.size=4; (*sib1_MBMS)->cellAccessRelatedInfo_r14.cellIdentity_r14.bits_unused=4; - (*sib1_MBMS)->freqBandIndicator_r14 = -#if defined(ENABLE_ITTI) - configuration->eutra_band[CC_id]; -#else - 7; -#endif + (*sib1_MBMS)->freqBandIndicator_r14 = configuration->eutra_band[CC_id]; + schedulingInfo->si_Periodicity_r14=LTE_SchedulingInfo__si_Periodicity_rf16; *sib_type = LTE_SIB_Type_MBMS_r14_sibType13_v920; ASN_SEQUENCE_ADD(&schedulingInfo->sib_MappingInfo_r14.list, sib_type); @@ -827,17 +793,11 @@ LTE_DRX_Config_t *do_DrxConfig(int CC_id, } uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, - int Mod_id,int CC_id, BOOLEAN_t brOption -#if defined(ENABLE_ITTI) - , RrcConfigurationReq *configuration -#endif + int Mod_id,int CC_id, BOOLEAN_t brOption, + RrcConfigurationReq *configuration ) { // SystemInformation_t systemInformation; -#if defined(ENABLE_ITTI) int num_plmn = configuration->num_plmn; -#else - int num_plmn = 1; -#endif LTE_PLMN_IdentityInfo_t *PLMN_identity_info; LTE_MCC_MNC_Digit_t *dummy_mcc_0; LTE_MCC_MNC_Digit_t *dummy_mcc_1; @@ -892,15 +852,10 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, if (dummy_mcc_0 == NULL || dummy_mcc_1 == NULL || dummy_mcc_2 == NULL) exit(1); -#if defined(ENABLE_ITTI) + *dummy_mcc_0 = (configuration->mcc[i] / 100) % 10; *dummy_mcc_1 = (configuration->mcc[i] / 10) % 10; *dummy_mcc_2 = (configuration->mcc[i] / 1) % 10; -#else - *dummy_mcc_0 = 0; - *dummy_mcc_1 = 0; - *dummy_mcc_2 = 1; -#endif ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list, dummy_mcc_0); ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list, dummy_mcc_1); ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mcc->list, dummy_mcc_2); @@ -913,7 +868,6 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, if (dummy_mnc_0 == NULL || dummy_mnc_1 == NULL || dummy_mnc_2 == NULL) exit(1); -#if defined(ENABLE_ITTI) if (configuration->mnc[i] >= 100) { *dummy_mnc_0 = (configuration->mnc[i] / 100) % 10; @@ -930,12 +884,6 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, *dummy_mnc_2 = (configuration->mnc[i] / 1) % 10; } } - -#else - *dummy_mnc_0 = 0; - *dummy_mnc_1 = 1; - *dummy_mnc_2 = 0xf; -#endif ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mnc.list, dummy_mnc_0); ASN_SEQUENCE_ADD(&PLMN_identity_info[i].plmn_Identity.mnc.list, dummy_mnc_1); @@ -952,28 +900,16 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, // 16 bits (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf = MALLOC(2); -#if defined(ENABLE_ITTI) (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf[0] = (configuration->tac >> 8) & 0xff; (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf[1] = (configuration->tac >> 0) & 0xff; -#else - (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf[0] = 0x00; - (*sib1)->cellAccessRelatedInfo.trackingAreaCode.buf[1] = 0x01; -#endif (*sib1)->cellAccessRelatedInfo.trackingAreaCode.size = 2; (*sib1)->cellAccessRelatedInfo.trackingAreaCode.bits_unused = 0; // 28 bits (*sib1)->cellAccessRelatedInfo.cellIdentity.buf = MALLOC(8); -#if defined(ENABLE_ITTI) (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[0] = (configuration->cell_identity >> 20) & 0xff; (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[1] = (configuration->cell_identity >> 12) & 0xff; (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[2] = (configuration->cell_identity >> 4) & 0xff; (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[3] = (configuration->cell_identity << 4) & 0xf0; -#else - (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[0] = 0x00; - (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[1] = 0x00; - (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[2] = 0x00; - (*sib1)->cellAccessRelatedInfo.cellIdentity.buf[3] = 0x10; -#endif (*sib1)->cellAccessRelatedInfo.cellIdentity.size=4; (*sib1)->cellAccessRelatedInfo.cellIdentity.bits_unused=4; // assign_enum(&(*sib1)->cellAccessRelatedInfo.cellBarred,SystemInformationBlockType1__cellAccessRelatedInfo__cellBarred_notBarred); @@ -985,12 +921,7 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, (*sib1)->cellSelectionInfo.q_RxLevMinOffset=NULL; //(*sib1)->p_Max = CALLOC(1, sizeof(P_Max_t)); // *((*sib1)->p_Max) = 23; - (*sib1)->freqBandIndicator = -#if defined(ENABLE_ITTI) - configuration->eutra_band[CC_id]; -#else - 7; -#endif + (*sib1)->freqBandIndicator = configuration->eutra_band[CC_id]; schedulingInfo.si_Periodicity=LTE_SchedulingInfo__si_Periodicity_rf8; if(configuration->eMBMS_M2_configured){ schedulingInfo2.si_Periodicity=LTE_SchedulingInfo__si_Periodicity_rf8; @@ -1005,24 +936,12 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, ASN_SEQUENCE_ADD(&(*sib1)->schedulingInfoList.list,&schedulingInfo2); } // ASN_SEQUENCE_ADD(&schedulingInfo.sib_MappingInfo.list,NULL); -#if defined(ENABLE_ITTI) if (configuration->frame_type[CC_id] == TDD) -#endif { (*sib1)->tdd_Config = CALLOC(1,sizeof(struct LTE_TDD_Config)); - (*sib1)->tdd_Config->subframeAssignment = -#if defined(ENABLE_ITTI) - configuration->tdd_config[CC_id]; -#else - 3; // +kogo this was frame_parms->tdd_config -#endif - (*sib1)->tdd_Config->specialSubframePatterns = -#if defined(ENABLE_ITTI) - configuration->tdd_config_s[CC_id]; -#else - 0; -#endif + (*sib1)->tdd_Config->subframeAssignment = configuration->tdd_config[CC_id]; + (*sib1)->tdd_Config->specialSubframePatterns = configuration->tdd_config_s[CC_id]; } (*sib1)->si_WindowLength = LTE_SystemInformationBlockType1__si_WindowLength_ms20; @@ -1050,8 +969,6 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, sib1_1250->freqBandIndicatorPriority_r12 = 0; // long* // FIXME sib1_1250->nonCriticalExtension = NULL; ////Rel1310 -#if defined(ENABLE_ITTI) - if ((configuration->schedulingInfoSIB1_BR_r13[CC_id] != 0) && (brOption==TRUE)) { sib1_1250->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1310_IEs_t)); @@ -1245,89 +1162,6 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, sib1_1320->nonCriticalExtension = NULL; } -#else - sib1_1250->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1310_IEs_t)); - memset(sib1_1250->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1310_IEs_t)); - SystemInformationBlockType1_v1310_IEs_t *sib1_1310 = sib1_1250->nonCriticalExtension; - sib1_1310->hyperSFN_r13 = calloc(1, sizeof(BIT_STRING_t)); // type - memset(sib1_1310->hyperSFN_r13, 0, sizeof(BIT_STRING_t)); - sib1_1310->hyperSFN_r13->buf = calloc(2, sizeof(uint8_t)); - memset(sib1_1310->hyperSFN_r13->buf, 0, 2*sizeof(uint8_t)); - sib1_1310->hyperSFN_r13->size = 2; - sib1_1310->hyperSFN_r13->bits_unused = 6; - sib1_1310->eDRX_Allowed_r13 = NULL; // long* - sib1_1310->cellSelectionInfoCE_r13 = calloc(1, sizeof(LTE_CellSelectionInfoCE_r13_t)); - memset(sib1_1310->cellSelectionInfoCE_r13, 0, sizeof(LTE_CellSelectionInfoCE_r13_t)); - sib1_1310->cellSelectionInfoCE_r13->q_RxLevMinCE_r13 = -70; // (Q_RxLevMin_t) long - sib1_1310->cellSelectionInfoCE_r13->q_QualMinRSRQ_CE_r13 = NULL; // (Q_RxLevMin_t) *long - sib1_1310->bandwidthReducedAccessRelatedInfo_r13 - = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13)); - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_WindowLength_BR_r13 - = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_WindowLength_BR_r13_ms20; // 0 - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_RepetitionPattern_r13 - = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_RepetitionPattern_r13_everyRF; // 0 - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13 = calloc(1, sizeof(LTE_SchedulingInfoList_BR_r13_t)); - SchedulingInfo_BR_r13_t *schedulinginfo_br_13 = calloc(1, sizeof(LTE_SchedulingInfo_BR_r13_t)); - memset(schedulinginfo_br_13, 0, sizeof(LTE_SchedulingInfo_BR_r13_t)); - schedulinginfo_br_13->si_Narrowband_r13 = 1; - schedulinginfo_br_13->si_TBS_r13 = LTE_SchedulingInfo_BR_r13__si_TBS_r13_b152; - ASN_SEQUENCE_ADD(&sib1_1310->bandwidthReducedAccessRelatedInfo_r13->schedulingInfoList_BR_r13->list, schedulinginfo_br_13); - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13 - = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13)); - memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13, 0, - sizeof(struct LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13)); - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->present - = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__fdd_DownlinkOrTddSubframeBitmapBR_r13_PR_subframePattern10_r13; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.buf = calloc(2, sizeof(uint8_t)); - memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.buf, 0, 2 * sizeof(uint8_t)); - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.size = 2; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_DownlinkOrTddSubframeBitmapBR_r13->choice.subframePattern10_r13.bits_unused = 6; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13 = calloc(1, sizeof(BIT_STRING_t)); - memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13, 0, sizeof(BIT_STRING_t)); - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->buf = calloc(2, sizeof(uint8_t)); - memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->buf, 0, - 2 * sizeof(uint8_t)); - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->size = 2; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->fdd_UplinkSubframeBitmapBR_r13->bits_unused = 6; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->startSymbolBR_r13 = 1; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_HoppingConfigCommon_r13 - = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_HoppingConfigCommon_r13_on; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13 = calloc(1, sizeof(long)); - memset(sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13, 0, sizeof(long)); - *sib1_1310->bandwidthReducedAccessRelatedInfo_r13->si_ValidityTime_r13 - = LTE_SystemInformationBlockType1_v1310_IEs__bandwidthReducedAccessRelatedInfo_r13__si_ValidityTime_r13_true; - sib1_1310->bandwidthReducedAccessRelatedInfo_r13->systemInfoValueTagList_r13 = calloc(1, sizeof(LTE_SystemInfoValueTagList_r13_t)); - LTE_SystemInfoValueTagSI_r13_t *systemInfoValueTagSi_r13 = CALLOC(1, sizeof(LTE_SystemInfoValueTagSI_r13_t)); - *systemInfoValueTagSi_r13 = 0; - ASN_SEQUENCE_ADD(&sib1_1310->bandwidthReducedAccessRelatedInfo_r13->systemInfoValueTagList_r13->list, systemInfoValueTagSi_r13); - sib1_1310->nonCriticalExtension = calloc(1, sizeof(LTE_SystemInformationBlockType1_v1320_IEs_t)); - memset(sib1_1310->nonCriticalExtension, 0, sizeof(LTE_SystemInformationBlockType1_v1320_IEs_t)); - /////Rel1320 - LTE_SystemInformationBlockType1_v1320_IEs_t *sib1_1320 = sib1_1310->nonCriticalExtension; - sib1_1320->freqHoppingParametersDL_r13 = calloc(1, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13)); - memset(sib1_1320->freqHoppingParametersDL_r13, 0, sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13)); - sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingNB_r13 = calloc(1, sizeof(long)); - *sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingNB_r13 = LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__mpdcch_pdsch_HoppingNB_r13_nb2; - sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13 = calloc(1, - sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13)); - memset(sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13, 0, - sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13)); - sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->present = - LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13_PR_interval_FDD_r13; - sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeA_r13->choice.interval_FDD_r13 = - LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeA_r13__interval_FDD_r13_int1; - sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13 = calloc(1, - sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13)); - memset(sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13, 0, - sizeof(struct LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13)); - sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->present = - LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13_PR_interval_FDD_r13; - sib1_1320->freqHoppingParametersDL_r13->interval_DLHoppingConfigCommonModeB_r13->choice.interval_FDD_r13 = - LTE_SystemInformationBlockType1_v1320_IEs__freqHoppingParametersDL_r13__interval_DLHoppingConfigCommonModeB_r13__interval_FDD_r13_int2; - sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingOffset_r13 = calloc(1, sizeof(long)); - *sib1_1320->freqHoppingParametersDL_r13->mpdcch_pdsch_HoppingOffset_r13 = 1; - sib1_1320->nonCriticalExtension = NULL; -#endif (*sib1)->si_WindowLength=LTE_SystemInformationBlockType1__si_WindowLength_ms20; (*sib1)->systemInfoValueTag=0; // (*sib1).nonCriticalExtension = calloc(1,sizeof(*(*sib1).nonCriticalExtension)); @@ -1358,10 +1192,8 @@ uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier, uint8_t do_SIB23(uint8_t Mod_id, - int CC_id, BOOLEAN_t brOption -#if defined(ENABLE_ITTI) - , RrcConfigurationReq *configuration -#endif + int CC_id, BOOLEAN_t brOption, + RrcConfigurationReq *configuration ) { struct LTE_SystemInformation_r8_IEs__sib_TypeAndInfo__Member *sib2_part,*sib3_part; int eMTC_configured = configuration->eMTC_configured; @@ -1455,7 +1287,6 @@ uint8_t do_SIB23(uint8_t Mod_id, (*sib2)->ac_BarringInfo = NULL; (*sib2)->ext1 = NULL; (*sib2)->ext2 = NULL; -#if defined(ENABLE_ITTI) (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles = rrconfig->rach_numberOfRA_Preambles; (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig = NULL; @@ -1846,121 +1677,7 @@ uint8_t do_SIB23(uint8_t Mod_id, = rrconfig->ue_TimersAndConstants_t311; (*sib2)->ue_TimersAndConstants.n311 = rrconfig->ue_TimersAndConstants_n311; -#else - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.numberOfRA_Preambles=LTE_RACH_ConfigCommon__preambleInfo__numberOfRA_Preambles_n64; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.preambleInfo.preamblesGroupAConfig = NULL; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.powerRampingStep=LTE_RACH_ConfigCommon__powerRampingParameters__powerRampingStep_dB2; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.powerRampingParameters.preambleInitialReceivedTargetPower= - RACH_ConfigCommon__powerRampingParameters__preambleInitialReceivedTargetPower_dBm_100; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.preambleTransMax=LTE_RACH_ConfigCommon__ra_SupervisionInfo__preambleTransMax_n10; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.ra_ResponseWindowSize=LTE_RACH_ConfigCommon__ra_SupervisionInfo__ra_ResponseWindowSize_sf10; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ra_SupervisionInfo.mac_ContentionResolutionTimer= - LTE_RACH_ConfigCommon__ra_SupervisionInfo__mac_ContentionResolutionTimer_sf48; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.maxHARQ_Msg3Tx = 4; - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1 = calloc(1, sizeof(struct LTE_RACH_ConfigCommon__ext1)); - memset((*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1, 0, sizeof(struct LTE_RACH_ConfigCommon__ext1)); - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->preambleTransMax_CE_r13 = calloc(1, sizeof(LTE_PreambleTransMax_t)); - *(*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->preambleTransMax_CE_r13 = LTE_PreambleTransMax_n5; // to be re-initialized when we find the enum - (*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13 = calloc(1, sizeof(LTE_RACH_CE_LevelInfoList_r13_t)); - memset((*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13, 0, sizeof(LTE_RACH_CE_LevelInfoList_r13_t)); - LTE_RACH_CE_LevelInfo_r13_t *rach_ce_levelinfo_r13 = calloc(1, sizeof(LTE_RACH_CE_LevelInfo_r13_t)); - memset(rach_ce_levelinfo_r13, 0, sizeof(LTE_RACH_CE_LevelInfo_r13_t)); - rach_ce_levelinfo_r13->preambleMappingInfo_r13.firstPreamble_r13 = 0; - rach_ce_levelinfo_r13->preambleMappingInfo_r13.lastPreamble_r13 = 63; - rach_ce_levelinfo_r13->ra_ResponseWindowSize_r13 = LTE_RACH_CE_LevelInfo_r13__ra_ResponseWindowSize_r13_sf80; - rach_ce_levelinfo_r13->mac_ContentionResolutionTimer_r13 = LTE_RACH_CE_LevelInfo_r13__mac_ContentionResolutionTimer_r13_sf200; - rach_ce_levelinfo_r13->rar_HoppingConfig_r13 = LTE_RACH_CE_LevelInfo_r13__rar_HoppingConfig_r13_off; - ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.rach_ConfigCommon.ext1->rach_CE_LevelInfoList_r13->list, rach_ce_levelinfo_r13); - // BCCH-Config - (*sib2)->radioResourceConfigCommon.bcch_Config.modificationPeriodCoeff=LTE_BCCH_Config__modificationPeriodCoeff_n2; - // PCCH-Config - (*sib2)->radioResourceConfigCommon.pcch_Config.defaultPagingCycle = LTE_PCCH_Config__defaultPagingCycle_rf128; - (*sib2)->radioResourceConfigCommon.pcch_Config.nB=LTE_PCCH_Config__nB_oneT; - // PRACH-Config - (*sib2)->radioResourceConfigCommon.prach_Config.rootSequenceIndex = Mod_id;//0;//384; - (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_ConfigIndex = 0;//3; - (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.highSpeedFlag = 0; - (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig = 1;//12; - (*sib2)->radioResourceConfigCommon.prach_Config.prach_ConfigInfo.prach_FreqOffset = 2; - // PDSCH-Config - (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.referenceSignalPower=0; // corresponds to 24.7 dBm 5 MHz/ 27.7 10 MHz/ 30.7 20 MHz - (*sib2)->radioResourceConfigCommon.pdsch_ConfigCommon.p_b=0; - // PUSCH-Config - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.n_SB=1; - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode=LTE_PUSCH_ConfigCommon__pusch_ConfigBasic__hoppingMode_interSubFrame; - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset=0; - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM=0; - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled=1; - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH=0; - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled=0; - (*sib2)->radioResourceConfigCommon.pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift=0; - // PUCCH-Config - (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.deltaPUCCH_Shift=LTE_PUCCH_ConfigCommon__deltaPUCCH_Shift_ds1; - (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.nRB_CQI = 1; - (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.nCS_AN = 0; - (*sib2)->radioResourceConfigCommon.pucch_ConfigCommon.n1PUCCH_AN = 32; - (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.present=LTE_SoundingRS_UL_ConfigCommon_PR_release; - (*sib2)->radioResourceConfigCommon.soundingRS_UL_ConfigCommon.choice.release=0; - // uplinkPowerControlCommon - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUSCH = -108; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.p0_NominalPUCCH = -108; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.alpha=LTE_UplinkPowerControlCommon__alpha_al1; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1_deltaF2; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format1b=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format1b_deltaF3; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2_deltaF0; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2a=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2a_deltaF0; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaFList_PUCCH.deltaF_PUCCH_Format2b=LTE_DeltaFList_PUCCH__deltaF_PUCCH_Format2b_deltaF0; - (*sib2)->radioResourceConfigCommon.uplinkPowerControlCommon.deltaPreambleMsg3 = 6; - (*sib2)->radioResourceConfigCommon.ul_CyclicPrefixLength=UL_CyclicPrefixLength_len1; - (*sib2)->radioResourceConfigCommon.ext4 = calloc(1, sizeof(struct LTE_RadioResourceConfigCommonSIB__ext4)); - memset((*sib2)->radioResourceConfigCommon.ext4, 0, sizeof(struct LTE_RadioResourceConfigCommonSIB__ext4)); - (*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310 = calloc(1, sizeof(LTE_BCCH_Config_v1310_t)); - memset((*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310, 0, sizeof(LTE_BCCH_Config_v1310_t)); - (*sib2)->radioResourceConfigCommon.ext4->bcch_Config_v1310->modificationPeriodCoeff_v1310 = LTE_BCCH_Config_v1310__modificationPeriodCoeff_v1310_n64; - (*sib2)->radioResourceConfigCommon.ext4->pcch_Config_v1310 = NULL; - (*sib2)->radioResourceConfigCommon.ext4->freqHoppingParameters_r13 = NULL; - (*sib2)->radioResourceConfigCommon.ext4->pdsch_ConfigCommon_v1310 = NULL; - (*sib2)->radioResourceConfigCommon.ext4->pusch_ConfigCommon_v1310 = NULL; - (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310 = calloc(1, sizeof(LTE_PRACH_ConfigSIB_v1310_t)); - memset((*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310, 0, sizeof(PRACH_ConfigSIB_v1310_t)); - LTE_RSRP_Range_t rsrp_range = 60; - ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->rsrp_ThresholdsPrachInfoList_r13.list, &rsrp_range); - (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13 = calloc(1, sizeof(struct LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13)); - memset((*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13, 0, sizeof(struct LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13)); - (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->present = LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13_PR_fdd_r13; - (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->mpdcch_startSF_CSS_RA_r13->choice.fdd_r13 = LTE_PRACH_ConfigSIB_v1310__mpdcch_startSF_CSS_RA_r13__fdd_r13_v5; - (*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_HoppingOffset_r13 = NULL; - LTE_PRACH_ParametersCE_r13_t *prach_parametersce_r13 = calloc(1, sizeof(LTE_PRACH_ParametersCE_r13_t)); - memset(prach_parametersce_r13, 0, sizeof(LTE_PRACH_ParametersCE_r13_t)); - prach_parametersce_r13->prach_ConfigIndex_r13 = 3; - prach_parametersce_r13->prach_FreqOffset_r13 = 1; - prach_parametersce_r13->prach_StartingSubframe_r13 = NULL; - prach_parametersce_r13->maxNumPreambleAttemptCE_r13 = calloc(1, sizeof(long)); - *prach_parametersce_r13->maxNumPreambleAttemptCE_r13 = LTE_PRACH_ParametersCE_r13__maxNumPreambleAttemptCE_r13_n3; - prach_parametersce_r13->numRepetitionPerPreambleAttempt_r13 = LTE_PRACH_ParametersCE_r13__numRepetitionPerPreambleAttempt_r13_n1; - long maxavailablenarrowband = 2; - ASN_SEQUENCE_ADD(&prach_parametersce_r13->mpdcch_NarrowbandsToMonitor_r13.list, &maxavailablenarrowband); - prach_parametersce_r13->mpdcch_NumRepetition_RA_r13 = LTE_PRACH_ParametersCE_r13__mpdcch_NumRepetition_RA_r13_r1; - prach_parametersce_r13->prach_HoppingConfig_r13 = LTE_PRACH_ParametersCE_r13__prach_HoppingConfig_r13_off; - ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->prach_ConfigCommon_v1310->prach_ParametersListCE_r13.list, prach_parametersce_r13); - (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310 = calloc(1, sizeof(LTE_PUCCH_ConfigCommon_v1310_t)); - memset((*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310, 0, sizeof(LTE_PUCCH_ConfigCommon_v1310_t)); - (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13 = calloc(1, sizeof(LTE_N1PUCCH_AN_InfoList_r13_t)); - long pucch_info_value1 = 0; - long pucch_info_value2 = 2; - ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13->list, &pucch_info_value1); - ASN_SEQUENCE_ADD(&(*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->n1PUCCH_AN_InfoList_r13->list, &pucch_info_value2); - (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level0_r13 = NULL; - (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level1_r13 = NULL; - (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level2_r13 = NULL; - (*sib2)->radioResourceConfigCommon.ext4->pucch_ConfigCommon_v1310->pucch_NumRepetitionCE_Msg4_Level3_r13 = NULL; - (*sib2)->ue_TimersAndConstants.t300=UE_TimersAndConstants__t300_ms1000; - (*sib2)->ue_TimersAndConstants.t301=UE_TimersAndConstants__t301_ms1000; - (*sib2)->ue_TimersAndConstants.t310=UE_TimersAndConstants__t310_ms1000; - (*sib2)->ue_TimersAndConstants.n310=UE_TimersAndConstants__n310_n20; - (*sib2)->ue_TimersAndConstants.t311=UE_TimersAndConstants__t311_ms10000; - (*sib2)->ue_TimersAndConstants.n311=UE_TimersAndConstants__n311_n1; -#endif + (*sib2)->freqInfo.additionalSpectrumEmission = 1; (*sib2)->freqInfo.ul_CarrierFreq = NULL; (*sib2)->freqInfo.ul_Bandwidth = NULL; @@ -2724,21 +2441,12 @@ do_RRCConnectionSetup( SRB1_config->rlc_Config = SRB1_rlc_config; SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue; SRB1_rlc_config->choice.explicitValue.present=LTE_RLC_Config_PR_am; -#if defined(ENABLE_ITTI) SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = rrc->srb1_timer_poll_retransmit; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = rrc->srb1_poll_pdu; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = rrc->srb1_poll_byte; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = rrc->srb1_max_retx_threshold; SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = rrc->srb1_timer_reordering; SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = rrc->srb1_timer_status_prohibit; -#else - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms20;; - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p4;; - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity; - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8; - SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35; - SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms0; -#endif SRB1_lchan_config = CALLOC(1,sizeof(*SRB1_lchan_config)); SRB1_config->logicalChannelConfig = SRB1_lchan_config; SRB1_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue; @@ -3099,21 +2807,12 @@ uint8_t do_RRCConnectionSetup_BR( SRB1_config->rlc_Config = SRB1_rlc_config; // check this SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue; SRB1_rlc_config->choice.explicitValue.present = LTE_RLC_Config_PR_am; -#if defined(ENABLE_ITTI) SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = rrc->srb1_timer_poll_retransmit; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = rrc->srb1_poll_pdu; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = rrc->srb1_poll_byte; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = rrc->srb1_max_retx_threshold; SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = rrc->srb1_timer_reordering; SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = rrc->srb1_timer_status_prohibit; -#else - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms20; // FIXME should be 80 - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p4; // FIXME should be infinity - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity; - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8; - SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35; - SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms0; -#endif SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config)); SRB1_config->logicalChannelConfig = SRB1_lchan_config; SRB1_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue; @@ -3403,9 +3102,9 @@ uint8_t do_RRCConnectionSetup_BR( rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.sps_Config = NULL; rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.physicalConfigDedicated = physicalConfigDedicated2; // rrcConnectionSetup->criticalExtensions.choice.c1.choice.rrcConnectionSetup_r8.radioResourceConfigDedicated.mac_MainConfig = NULL; -#ifdef XER_PRINT - xer_fprint(stdout, &asn_DEF_DL_CCCH_Message, (void *)&dl_ccch_msg); -#endif + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout, &asn_DEF_LTE_DL_CCCH_Message, (void *)&dl_ccch_msg); + } enc_rval = uper_encode_to_buffer(&asn_DEF_LTE_DL_CCCH_Message, NULL, (void *)&dl_ccch_msg, @@ -3413,31 +3112,8 @@ uint8_t do_RRCConnectionSetup_BR( 100); AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", enc_rval.failed_type->name, enc_rval.encoded); -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[20000]; - size_t message_string_size; - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_CCCH_Message, (void *) &dl_ccch_msg)) > 0) { - MessageDef *msg_p; - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_CCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_ccch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_ccch.text, message_string, message_string_size); - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } - } -# endif -#endif -#ifdef USER_MODE - LOG_D(RRC,"RRCConnectionSetup_BR Encoded %d bits (%d bytes), ecause %d\n", - enc_rval.encoded,(enc_rval.encoded+7)/8,ecause); -#endif - // FREEMEM(SRB_list); - // free(SRB1_config); - // free(SRB1_rlc_config); - // free(SRB1_lchan_config); - // free(SRB1_ul_SpecificParameters); + return((enc_rval.encoded+7)/8); } @@ -3661,25 +3337,10 @@ uint16_t do_RRCConnectionReconfiguration_BR(const protocol_ctxt_t *const RRC_BUF_SIZE); AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed %s, %lu!\n", enc_rval.failed_type->name, enc_rval.encoded); -#ifdef XER_PRINT - xer_fprint(stdout,&asn_DEF_DL_DCCH_Message,(void *)&dl_dcch_msg); -#endif -#if defined(ENABLE_ITTI) -# if !defined(DISABLE_XER_SPRINT) - { - char message_string[30000]; - size_t message_string_size; - - if ((message_string_size = xer_sprint(message_string, sizeof(message_string), &asn_DEF_LTE_DL_DCCH_Message, (void *) &dl_dcch_msg)) > 0) { - MessageDef *msg_p; - msg_p = itti_alloc_new_message_sized (TASK_RRC_ENB, RRC_DL_DCCH, message_string_size + sizeof (IttiMsgText)); - msg_p->ittiMsg.rrc_dl_dcch.size = message_string_size; - memcpy(&msg_p->ittiMsg.rrc_dl_dcch.text, message_string, message_string_size); - itti_send_msg_to_task(TASK_UNKNOWN, ctxt_pP->instance, msg_p); - } + if ( LOG_DEBUGFLAG(DEBUG_ASN1) ) { + xer_fprint(stdout,&asn_DEF_LTE_DL_DCCH_Message,(void *)&dl_dcch_msg); } -# endif -#endif + LOG_I(RRC,"RRCConnectionReconfiguration Encoded %d bits (%d bytes)\n",(int)enc_rval.encoded,(int)(enc_rval.encoded+7)/8); return((enc_rval.encoded+7)/8); } @@ -3933,21 +3594,12 @@ do_RRCConnectionReestablishment( SRB1_config->rlc_Config = SRB1_rlc_config; SRB1_rlc_config->present = LTE_SRB_ToAddMod__rlc_Config_PR_explicitValue; SRB1_rlc_config->choice.explicitValue.present=LTE_RLC_Config_PR_am; -#if defined(ENABLE_ITTI) SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = rrc->srb1_timer_poll_retransmit; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = rrc->srb1_poll_pdu; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = rrc->srb1_poll_byte; SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = rrc->srb1_max_retx_threshold; SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = rrc->srb1_timer_reordering; SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = rrc->srb1_timer_status_prohibit; -#else - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.t_PollRetransmit = LTE_T_PollRetransmit_ms20;; - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollPDU = LTE_PollPDU_p4;; - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.pollByte = LTE_PollByte_kBinfinity; - SRB1_rlc_config->choice.explicitValue.choice.am.ul_AM_RLC.maxRetxThreshold = LTE_UL_AM_RLC__maxRetxThreshold_t8; - SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_Reordering = LTE_T_Reordering_ms35; - SRB1_rlc_config->choice.explicitValue.choice.am.dl_AM_RLC.t_StatusProhibit = LTE_T_StatusProhibit_ms0; -#endif SRB1_lchan_config = CALLOC(1, sizeof(*SRB1_lchan_config)); SRB1_config->logicalChannelConfig = SRB1_lchan_config; SRB1_lchan_config->present = LTE_SRB_ToAddMod__logicalChannelConfig_PR_explicitValue; diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg.h b/openair2/RRC/LTE/MESSAGES/asn1_msg.h index 925f09416e..ccd5e1c537 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg.h +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg.h @@ -91,10 +91,8 @@ LTE_DRX_Config_t *do_DrxConfig(int CC_id, RrcConfigurationReq *configuration, LT @param br_flag Do for BL/CE UE configuration @return size of encoded bit stream in bytes*/ -uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,int Mod_id,int CC_id, BOOLEAN_t brOption -#if defined(ENABLE_ITTI) - ,RrcConfigurationReq *configuration -#endif +uint8_t do_SIB1(rrc_eNB_carrier_data_t *carrier,int Mod_id,int CC_id, BOOLEAN_t brOption, + RrcConfigurationReq *configuration ); /** @@ -120,10 +118,8 @@ uint8_t do_SIB1_MBMS(rrc_eNB_carrier_data_t *carrier,int Mod_id,int CC_id, RrcCo @param MBMS_flag Indicates presence of MBMS system information (when 1) @return size of encoded bit stream in bytes*/ -uint8_t do_SIB23(uint8_t Mod_id,int CC_id, BOOLEAN_t brOption -#if defined(ENABLE_ITTI) - , RrcConfigurationReq *configuration -#endif +uint8_t do_SIB23(uint8_t Mod_id,int CC_id, BOOLEAN_t brOption, + RrcConfigurationReq *configuration ); /** diff --git a/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c b/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c index 480f5c3516..350a8baf77 100644 --- a/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c +++ b/openair2/RRC/LTE/MESSAGES/asn1_msg_NB_IoT.c @@ -68,10 +68,8 @@ //#include "PHY/defs.h" #include "enb_config.h" +#include "intertask_interface.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif @@ -178,21 +176,15 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id, memset(PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc,0,sizeof(*PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc)); asn_set_empty(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list);//.size=0; //left as it is??? -#if defined(ENABLE_ITTI) + dummy_mcc[0] = (configuration->mcc / 100) % 10; dummy_mcc[1] = (configuration->mcc / 10) % 10; dummy_mcc[2] = (configuration->mcc / 1) % 10; -#else - dummy_mcc[0] = 0; - dummy_mcc[1] = 0; - dummy_mcc[2] = 1; -#endif ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[0]); ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[1]); ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mcc->list,&dummy_mcc[2]); PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.size=0; PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list.count=0; -#if defined(ENABLE_ITTI) if (configuration->mnc >= 100) { dummy_mnc[0] = (configuration->mnc / 100) % 10; @@ -210,11 +202,6 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id, } } -#else - dummy_mnc[0] = 0; - dummy_mnc[1] = 1; - dummy_mnc[2] = 0xf; -#endif ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[0]); ASN_SEQUENCE_ADD(&PLMN_identity_info_NB_IoT.plmn_Identity_r13.mnc.list,&dummy_mnc[1]); @@ -230,28 +217,16 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id, // 16 bits = 2 byte (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf = MALLOC(2); //MALLOC works in byte //lefts as it is? -#if defined(ENABLE_ITTI) (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = (configuration->tac >> 8) & 0xff; (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = (configuration->tac >> 0) & 0xff; -#else - (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[0] = 0x00; - (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.buf[1] = 0x01; -#endif (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.size=2; (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.trackingAreaCode_r13.bits_unused=0; // 28 bits --> i have to use 32 bits = 4 byte (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf = MALLOC(8); // why allocate 8 byte? -#if defined(ENABLE_ITTI) (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = (configuration->cell_identity >> 20) & 0xff; (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = (configuration->cell_identity >> 12) & 0xff; (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = (configuration->cell_identity >> 4) & 0xff; (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = (configuration->cell_identity << 4) & 0xf0; -#else - (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[0] = 0x00; - (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[1] = 0x00; - (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[2] = 0x00; - (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.buf[3] = 0x10; -#endif (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.size=4; (*sib1_NB_IoT)->cellAccessRelatedInfo_r13.cellIdentity_r13.bits_unused=4; //Still set to "notBarred" as in the previous case @@ -264,11 +239,8 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id, *((*sib1_NB_IoT)->p_Max_r13) = 23; //FIXME (*sib1_NB_IoT)->freqBandIndicator_r13 = -#if defined(ENABLE_ITTI) configuration->eutra_band; -#else - 5; //if not configured we use band 5 (UL: 824 MHz - 849MHz / DL: 869 MHz - 894 MHz FDD mode) -#endif + //OPTIONAL new parameters, to be used? /* * freqBandInfo_r13 @@ -305,10 +277,8 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id, ASN_SEQUENCE_ADD(&schedulingInfo_NB_IoT[0].sib_MappingInfo_r13.list,&sib_type_NB_IoT[0]); ASN_SEQUENCE_ADD(&(*sib1_NB_IoT)->schedulingInfoList_r13.list,&schedulingInfo_NB_IoT[0]); //printf("[ASN Debug] SI P: %ld\n",(*sib1_NB_IoT)->schedulingInfoList_r13.list.array[0]->si_Periodicity_r13); -#if defined(ENABLE_ITTI) if (configuration->frame_type == TDD) -#endif { //FIXME in NB-IoT mandatory to be FDD --> so must give an error LOG_E(RRC,"[NB-IoT %d] Frame Type is TDD --> not supported by NB-IoT, exiting\n", Mod_id); //correct? @@ -342,9 +312,7 @@ uint8_t do_SIB1_NB_IoT(uint8_t Mod_id, int CC_id, enc_rval.failed_type->name, enc_rval.encoded); } -#ifdef USER_MODE LOG_D(RRC,"[NB-IoT] SystemInformationBlockType1-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); -#endif if (enc_rval.encoded==-1) { return(-1); @@ -563,10 +531,9 @@ uint8_t do_SIB23_NB_IoT(uint8_t Mod_id, 900); // AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n", // enc_rval.failed_type->name, enc_rval.encoded); - //#if defined(ENABLE_ITTI)..... -#ifdef USER_MODE + LOG_D(RRC,"[NB-IoT] SystemInformation-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); -#endif + if (enc_rval.encoded==-1) { msg("[RRC] ASN1 : SI-NB encoding failed for SIB23_NB_IoT\n"); @@ -748,10 +715,8 @@ uint8_t do_RRCConnectionSetup_NB_IoT( enc_rval.failed_type->name, enc_rval.encoded); } -#ifdef USER_MODE - LOG_D(RRC,"RRCConnectionSetup-NB Encoded %zd bits (%zd bytes), ecause %d\n", - enc_rval.encoded,(enc_rval.encoded+7)/8,ecause); -#endif + LOG_D(RRC,"RRCConnectionSetup-NB Encoded %zd bits (%zd bytes)\n", + enc_rval.encoded,(enc_rval.encoded+7)/8); return((enc_rval.encoded+7)/8); } @@ -793,15 +758,11 @@ uint8_t do_SecurityModeCommand_NB_IoT( enc_rval.failed_type->name, enc_rval.encoded); } - //#if defined(ENABLE_ITTI) - //# if !defined(DISABLE_XER_SPRINT).... -#ifdef USER_MODE LOG_D(RRC,"[NB-IoT %d] securityModeCommand-NB for UE %x Encoded %zd bits (%zd bytes)\n", ctxt_pP->module_id, ctxt_pP->rnti, enc_rval.encoded, (enc_rval.encoded+7)/8); -#endif if (enc_rval.encoded==-1) { LOG_E(RRC,"[NB-IoT %d] ASN1 : securityModeCommand-NB encoding failed for UE %x\n", @@ -850,15 +811,12 @@ uint8_t do_UECapabilityEnquiry_NB_IoT( enc_rval.failed_type->name, enc_rval.encoded); } - //#if defined(ENABLE_ITTI) - //# if !defined(DISABLE_XER_SPRINT).... -#ifdef USER_MODE LOG_D(RRC,"[NB-IoT %d] UECapabilityEnquiry-NB for UE %x Encoded %zd bits (%zd bytes)\n", ctxt_pP->module_id, ctxt_pP->rnti, enc_rval.encoded, (enc_rval.encoded+7)/8); -#endif + if (enc_rval.encoded==-1) { LOG_E(RRC,"[NB-IoT %d] ASN1 : UECapabilityEnquiry-NB encoding failed for UE %x\n", @@ -940,8 +898,6 @@ uint16_t do_RRCConnectionReconfiguration_NB_IoT( xer_fprint(stdout,&asn_DEF_LTE_DL_DCCH_Message_NB,(void *)&dl_dcch_msg_NB_IoT); } - //#if defined(ENABLE_ITTI) - //# if !defined(DISABLE_XER_SPRINT)... LOG_I(RRC,"RRCConnectionReconfiguration-NB Encoded %zd bits (%zd bytes)\n",enc_rval.encoded,(enc_rval.encoded+7)/8); return((enc_rval.encoded+7)/8); } @@ -977,10 +933,8 @@ uint8_t do_RRCConnectionReestablishmentReject_NB_IoT( } //Only change in "asn_DEF_DL_CCCH_Message_NB" -#ifdef USER_MODE LOG_D(RRC,"RRCConnectionReestablishmentReject Encoded %zd bits (%zd bytes)\n", enc_rval.encoded,(enc_rval.encoded+7)/8); -#endif return((enc_rval.encoded+7)/8); } @@ -1025,10 +979,8 @@ uint8_t do_RRCConnectionReject_NB_IoT( enc_rval.failed_type->name, enc_rval.encoded); } -#ifdef USER_MODE LOG_D(RRC,"RRCConnectionReject-NB Encoded %zd bits (%zd bytes)\n", enc_rval.encoded,(enc_rval.encoded+7)/8); -#endif return((enc_rval.encoded+7)/8); } diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c index bf62fc3df2..a91e6fcd00 100644 --- a/openair2/RRC/LTE/rrc_eNB.c +++ b/openair2/RRC/LTE/rrc_eNB.c @@ -152,21 +152,15 @@ init_SI( (int)configuration->N_RB_DL[CC_id]); RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB_FeMBMS = (uint8_t *) malloc16(4); do_MIB_FeMBMS(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id], -#ifdef ENABLE_ITTI configuration->N_RB_DL[CC_id], - 0 //additionalNonMBSFN -#else - 50,0 -#endif - ,0); + 0, //additionalNonMBSFN + 0); RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_MBMS = 0; RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_MBMS = (uint8_t *) malloc16(32); AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1_MBMS!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1_MBMS allocated\n", PROTOCOL_RRC_CTXT_ARGS(ctxt_pP)); - RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_MBMS = do_SIB1_MBMS(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id -#if defined(ENABLE_ITTI) - , configuration -#endif + RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1_MBMS = do_SIB1_MBMS(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id, + configuration ); LOG_I(RRC, PROTOCOL_RRC_CTXT_FMT" Contents of SIB1-MBMS\n", PROTOCOL_RRC_CTXT_ARGS(ctxt_pP) @@ -892,7 +886,6 @@ rrc_eNB_free_mem_UE_context( //uint8_t Status; //rnti_t rnti; //uint64_t random_ue_identity; -#if defined(ENABLE_ITTI) //UE_S_TMSI Initialue_identity_s_TMSI; //EstablishmentCause_t establishment_cause; //ReestablishmentCause_t reestablishment_cause; @@ -905,7 +898,6 @@ rrc_eNB_free_mem_UE_context( //transport_layer_addr_t enb_gtp_addrs[S1AP_MAX_E_RAB]; //rb_id_t enb_gtp_ebi[S1AP_MAX_E_RAB]; #endif -#endif } //----------------------------------------------------------------------------- @@ -4758,7 +4750,6 @@ check_handovers( if (ue_context_p->ue_context.Status == RRC_RECONFIGURED && ue_context_p->ue_context.handover_info != NULL && ue_context_p->ue_context.handover_info->forwarding_state == FORWARDING_NO_EMPTY ) { -#if defined(ENABLE_ITTI) MessageDef *msg_p; int result; protocol_ctxt_t ctxt; @@ -4889,7 +4880,6 @@ check_handovers( ue_context_p->ue_context.handover_info->endmark_state = ENDMARK_EMPTY; ue_context_p->ue_context.handover_info->state = HO_FORWARDING_COMPLETE; -#endif } } } @@ -5805,7 +5795,6 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct securityConfigHO->handoverType.choice.intraLTE.securityAlgorithmConfig = NULL; /* TODO: to be checked */ securityConfigHO->handoverType.choice.intraLTE.keyChangeIndicator = 0; securityConfigHO->handoverType.choice.intraLTE.nextHopChainingCount = 0; -#if defined(ENABLE_ITTI) /* Initialize NAS list */ dedicatedInfoNASList = CALLOC(1, sizeof(struct LTE_RRCConnectionReconfiguration_r8_IEs__dedicatedInfoNASList)); @@ -5838,7 +5827,6 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct dedicatedInfoNASList = NULL; } -#endif measurements_enabled = RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_x2 || RC.rrc[ENB_INSTANCE_TO_MODULE_ID(ctxt_pP->instance)]->configuration.enable_measurement_reports; memset(buffer, 0, RRC_BUF_SIZE); @@ -5887,7 +5875,6 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct *_size = size = ho_size; LOG_DUMPMSG(RRC,DEBUG_RRC,(char *)buffer,size, "[MSG] RRC Connection Reconfiguration handover\n"); -#if defined(ENABLE_ITTI) /* Free all NAS PDUs */ for (i = 0; i < ue_context_pP->ue_context.nb_of_e_rabs; i++) { @@ -5897,8 +5884,6 @@ rrc_eNB_generate_HO_RRCConnectionReconfiguration(const protocol_ctxt_t *const ct ue_context_pP->ue_context.e_rab[i].param.nas_pdu.buffer = NULL; } } - -#endif LOG_I(RRC, "[eNB %d] Frame %d, Logical Channel DL-DCCH, Generate RRCConnectionReconfiguration handover (bytes %d, UE id %x)\n", ctxt_pP->module_id, ctxt_pP->frame, size, ue_context_pP->ue_context.rnti); diff --git a/openair2/RRC/LTE/rrc_eNB_GTPV1U.c b/openair2/RRC/LTE/rrc_eNB_GTPV1U.c index 749dff3ace..6bbdef181b 100644 --- a/openair2/RRC/LTE/rrc_eNB_GTPV1U.c +++ b/openair2/RRC/LTE/rrc_eNB_GTPV1U.c @@ -27,7 +27,6 @@ * \email: lionel.gauthier@eurecom.fr */ -//#if defined(ENABLE_USE_MME) # include "rrc_defs.h" # include "rrc_extern.h" # include "RRC/LTE/MESSAGES/asn1_msg.h" @@ -35,10 +34,10 @@ # include "rrc_eNB_UE_context.h" # include "msc.h" -//# if defined(ENABLE_ITTI) -# include "asn1_conversions.h" -# include "intertask_interface.h" -//#endif + +#include "asn1_conversions.h" +#include "intertask_interface.h" + # include "common/ran_context.h" @@ -113,7 +112,6 @@ gtpv_data_req( return FALSE; } LOG_D(GTPU,"gtpv_data_req ue rnti %x sdu_sizeP %d rb id %ld", ctxt_pP->rnti, sdu_sizeP, rb_idP); -#if defined(ENABLE_ITTI) { MessageDef *message_p; // Uses a new buffer to avoid issue with PDCP buffer content that could be changed by PDCP (asynchronous message handling). @@ -167,8 +165,6 @@ gtpv_data_req( return TRUE; // TODO should be changed to a CNF message later, currently RRC lite does not used the returned value anyway. } } -#endif - return TRUE; } diff --git a/openair2/RRC/LTE/rrc_eNB_S1AP.c b/openair2/RRC/LTE/rrc_eNB_S1AP.c index 11c6d27f5f..59998cebcc 100644 --- a/openair2/RRC/LTE/rrc_eNB_S1AP.c +++ b/openair2/RRC/LTE/rrc_eNB_S1AP.c @@ -58,7 +58,7 @@ #include "TLVDecoder.h" #include "S1AP_NAS-PDU.h" #include "flexran_agent_common_internal.h" - +#include "executables/softmodem-common.h" extern RAN_CONTEXT_t RC; extern int @@ -540,9 +540,10 @@ rrc_pdcp_config_security( derive_key_rrc_int(ue_context_pP->ue_context.integrity_algorithm, ue_context_pP->ue_context.kenb, &kRRCint); -#if !defined(USRP_REC_PLAY) + if (!IS_SOFTMODEM_IQPLAYER) { SET_LOG_DUMP(DEBUG_SECURITY) ; -#endif + } + if ( LOG_DUMPFLAG( DEBUG_SECURITY ) ) { if (print_keys ==1 ) { diff --git a/openair2/RRC/NR/L2_nr_interface.c b/openair2/RRC/NR/L2_nr_interface.c index 86cff69517..2a9448218a 100644 --- a/openair2/RRC/NR/L2_nr_interface.c +++ b/openair2/RRC/NR/L2_nr_interface.c @@ -36,9 +36,7 @@ #include "msc.h" #include "common/ran_context.h" -#if defined(ENABLE_ITTI) -# include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "NR_MIB.h" #include "NR_BCCH-BCH-Message.h" diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.c b/openair2/RRC/NR/MESSAGES/asn1_msg.c index a3bdffb5f6..b321aa3e4f 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.c +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.c @@ -99,9 +99,7 @@ #include "gnb_config.h" #endif -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" #include "common/ran_context.h" @@ -289,23 +287,18 @@ uint8_t do_MIB_NR(rrc_gNB_carrier_data_t *carrier, } -uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier -#if defined(ENABLE_ITTI) - , gNB_RrcConfigurationReq *configuration -#endif +uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier, + gNB_RrcConfigurationReq *configuration ) { asn_enc_rval_t enc_rval; NR_BCCH_DL_SCH_Message_t *sib1_message ; struct NR_SIB1 *sib1 ; int i; struct NR_PLMN_IdentityInfo nr_plmn_info; -#if defined(ENABLE_ITTI) + // TODO : Add support for more than one PLMN //int num_plmn = configuration->num_plmn; int num_plmn = 1; -#else - int num_plmn = 1; -#endif struct NR_PLMN_Identity nr_plmn[num_plmn]; NR_MCC_MNC_Digit_t nr_mcc_digit[num_plmn][3]; NR_MCC_MNC_Digit_t nr_mnc_digit[num_plmn][3]; @@ -329,30 +322,18 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier memset(nr_plmn,0,num_plmn*sizeof(struct NR_PLMN_Identity)); for (i = 0; i < num_plmn; ++i) { -#ifdef ENABLE_ITTI nr_mcc_digit[i][0] = (configuration->mcc[i]/100)%10; nr_mcc_digit[i][1] = (configuration->mcc[i]/10)%10; nr_mcc_digit[i][2] = (configuration->mcc[i])%10; -#else - nr_mcc_digit[i][0] = 0; - nr_mcc_digit[i][1] = 0; - nr_mcc_digit[i][2] = 1; -#endif nr_plmn[i].mcc = CALLOC(1,sizeof(struct NR_MCC)); memset(nr_plmn[i].mcc,0,sizeof(struct NR_MCC)); asn_set_empty(&nr_plmn[i].mcc->list); ASN_SEQUENCE_ADD(&nr_plmn[i].mcc->list, &nr_mcc_digit[i][0]); ASN_SEQUENCE_ADD(&nr_plmn[i].mcc->list, &nr_mcc_digit[i][1]); ASN_SEQUENCE_ADD(&nr_plmn[i].mcc->list, &nr_mcc_digit[i][2]); -#ifdef ENABLE_ITTI nr_mnc_digit[i][0] = (configuration->mnc[i]/100)%10; nr_mnc_digit[i][1] = (configuration->mnc[i]/10)%10; nr_mnc_digit[i][2] = (configuration->mnc[i])%10; -#else - nr_mnc_digit[i][0] = 0; - nr_mnc_digit[i][1] = 0; - nr_mnc_digit[i][2] = 1; -#endif memset(&nr_plmn[i].mnc,0,sizeof(NR_MNC_t)); nr_plmn[i].mnc.list.size=0; nr_plmn[i].mnc.list.count=0; @@ -364,17 +345,10 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier nr_plmn_info.cellIdentity.buf = MALLOC(8); memset(nr_plmn_info.cellIdentity.buf,0,8); -#ifdef ENABLE_ITTI nr_plmn_info.cellIdentity.buf[0]= (configuration->cell_identity >> 20) & 0xff; nr_plmn_info.cellIdentity.buf[1]= (configuration->cell_identity >> 12) & 0xff; nr_plmn_info.cellIdentity.buf[2]= (configuration->cell_identity >> 4) & 0xff; nr_plmn_info.cellIdentity.buf[3]= (configuration->cell_identity << 4) & 0xff; -#else - nr_plmn_info.cellIdentity.buf[0]= 0x00; - nr_plmn_info.cellIdentity.buf[1]= 0x00; - nr_plmn_info.cellIdentity.buf[2]= 0x00; - nr_plmn_info.cellIdentity.buf[3]= 0x10; -#endif nr_plmn_info.cellIdentity.size= 4; nr_plmn_info.cellIdentity.bits_unused= 4; nr_plmn_info.cellReservedForOperatorUse = 0; @@ -410,9 +384,7 @@ uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier void do_SERVINGCELLCONFIGCOMMON(uint8_t Mod_id, int CC_id, -#if defined(ENABLE_ITTI) - gNB_RrcConfigurationReq *configuration, -#endif + gNB_RrcConfigurationReq *configuration, int initial_flag ) { NR_ServingCellConfigCommon_t **servingcellconfigcommon = &RC.nrrrc[Mod_id]->carrier[CC_id].servingcellconfigcommon; @@ -1143,17 +1115,13 @@ void do_SpCellConfig(uint8_t Mod_id, common_configuration = CALLOC(1,sizeof(gNB_RrcConfigurationReq)); //Fill servingcellconfigcommon config value rrc_config_servingcellconfigcommon(Mod_id, - CC_id -#if defined(ENABLE_ITTI) - ,common_configuration -#endif + CC_id, + common_configuration ); //Fill common config to structure do_SERVINGCELLCONFIGCOMMON(Mod_id, CC_id, -#if defined(ENABLE_ITTI) common_configuration, -#endif 0 ); spconfig->reconfigurationWithSync = CALLOC(1,sizeof(struct NR_ReconfigurationWithSync)); diff --git a/openair2/RRC/NR/MESSAGES/asn1_msg.h b/openair2/RRC/NR/MESSAGES/asn1_msg.h index c3154b708e..69ce650b23 100644 --- a/openair2/RRC/NR/MESSAGES/asn1_msg.h +++ b/openair2/RRC/NR/MESSAGES/asn1_msg.h @@ -76,17 +76,13 @@ uint8_t do_MIB_NR(rrc_gNB_carrier_data_t *carrier, @param carrier pointer to Carrier information @param configuration Pointer Configuration Request structure @return size of encoded bit stream in bytes*/ -uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier -#if defined(ENABLE_ITTI) - , gNB_RrcConfigurationReq *configuration -#endif +uint8_t do_SIB1_NR(rrc_gNB_carrier_data_t *carrier, + gNB_RrcConfigurationReq *configuration ); void do_SERVINGCELLCONFIGCOMMON(uint8_t Mod_id, int CC_id, -#if defined(ENABLE_ITTI) gNB_RrcConfigurationReq *configuration, -#endif int initial_flag); void do_RLC_BEARER(uint8_t Mod_id, diff --git a/openair2/RRC/NR/nr_rrc_config.c b/openair2/RRC/NR/nr_rrc_config.c index 80008d9af2..e09b1e6055 100644 --- a/openair2/RRC/NR/nr_rrc_config.c +++ b/openair2/RRC/NR/nr_rrc_config.c @@ -31,10 +31,8 @@ #include "nr_rrc_config.h" void rrc_config_servingcellconfigcommon(uint8_t Mod_id, - int CC_id - #if defined(ENABLE_ITTI) - ,gNB_RrcConfigurationReq *common_configuration - #endif + int CC_id, + gNB_RrcConfigurationReq *common_configuration ){ common_configuration->MIB_subCarrierSpacingCommon[CC_id] = 0; @@ -259,4 +257,4 @@ void rrc_config_rachdedicated(uint8_t Mod_id, physicalcellgroup_t *physicalcellgroup_config ){ -} \ No newline at end of file +} diff --git a/openair2/RRC/NR/nr_rrc_config.h b/openair2/RRC/NR/nr_rrc_config.h index c30478f0b0..e19d94b341 100644 --- a/openair2/RRC/NR/nr_rrc_config.h +++ b/openair2/RRC/NR/nr_rrc_config.h @@ -117,10 +117,8 @@ typedef struct rach_dedicated_s{ }rach_dedicated_t; void rrc_config_servingcellconfigcommon(uint8_t Mod_id, - int CC_id - #if defined(ENABLE_ITTI) - ,gNB_RrcConfigurationReq *common_configuration - #endif + int CC_id, + gNB_RrcConfigurationReq *common_configuration ); void rrc_config_rlc_bearer(uint8_t Mod_id, @@ -138,4 +136,4 @@ void rrc_config_physicalcellgroup(uint8_t Mod_id, physicalcellgroup_t *physicalcellgroup_config ); -#endif \ No newline at end of file +#endif diff --git a/openair2/RRC/NR/nr_rrc_defs.h b/openair2/RRC/NR/nr_rrc_defs.h index e9d4b4bf59..6b4a9864c7 100644 --- a/openair2/RRC/NR/nr_rrc_defs.h +++ b/openair2/RRC/NR/nr_rrc_defs.h @@ -72,21 +72,15 @@ #include "NR_EstablishmentCause.h" //------------------- -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" /* TODO: be sure this include is correct. * It solves a problem of compilation of the RRH GW, * issue #186. */ -#if !defined(ENABLE_ITTI) #include "as_message.h" -#endif -#if defined(ENABLE_USE_MME) #include "commonDef.h" -#endif /*I will change the name of the structure for compile purposes--> hope not to undo this process*/ @@ -295,7 +289,6 @@ typedef struct gNB_RRC_UE_s { rnti_t rnti; uint64_t random_ue_identity; -#if defined(ENABLE_ITTI) /* Information from UE RRC ConnectionRequest */ UE_S_TMSI Initialue_identity_s_TMSI; NR_EstablishmentCause_t establishment_cause; @@ -328,7 +321,6 @@ typedef struct gNB_RRC_UE_s { uint32_t enb_gtp_teid[S1AP_MAX_E_RAB]; transport_layer_addr_t enb_gtp_addrs[S1AP_MAX_E_RAB]; rb_id_t enb_gtp_ebi[S1AP_MAX_E_RAB]; -#endif uint32_t ul_failure_timer; uint32_t ue_release_timer; uint32_t ue_release_timer_thres; @@ -420,9 +412,7 @@ typedef struct gNB_RRC_INST_s { hash_table_t *s1ap_id2_s1ap_ids ; // key is content is rrc_ue_s1ap_ids_t //RRC configuration -#if defined(ENABLE_ITTI) gNB_RrcConfigurationReq configuration;//rrc_messages_types.h -#endif // other PLMN parameters /// Mobile country code diff --git a/openair2/RRC/NR/nr_rrc_proto.h b/openair2/RRC/NR/nr_rrc_proto.h index 67b5c34db9..ce90ee46fb 100644 --- a/openair2/RRC/NR/nr_rrc_proto.h +++ b/openair2/RRC/NR/nr_rrc_proto.h @@ -58,9 +58,7 @@ void rrc_gNB_generate_SgNBAdditionRequestAcknowledge( ); -#if defined(ENABLE_ITTI) /**\brief RRC eNB task. \param void *args_p Pointer on arguments to start the task. */ void *rrc_gnb_task(void *args_p); -#endif \ No newline at end of file diff --git a/openair2/RRC/NR/rrc_gNB.c b/openair2/RRC/NR/rrc_gNB.c index 3d42190887..586fcd3492 100644 --- a/openair2/RRC/NR/rrc_gNB.c +++ b/openair2/RRC/NR/rrc_gNB.c @@ -67,21 +67,15 @@ #include "UTIL/OSA/osa_defs.h" #endif -#if defined(ENABLE_USE_MME) - #include "rrc_eNB_S1AP.h" - #include "rrc_eNB_GTPV1U.h" - #if defined(ENABLE_ITTI) - #else - #include "../../S1AP/s1ap_eNB.h" - #endif -#endif +#include "rrc_eNB_S1AP.h" +#include "rrc_eNB_GTPV1U.h" + #include "pdcp.h" #include "gtpv1u_eNB_task.h" -#if defined(ENABLE_ITTI) - #include "intertask_interface.h" -#endif +#include "intertask_interface.h" + #if ENABLE_RAL #include "rrc_eNB_ral.h" @@ -200,11 +194,9 @@ void rrc_gNB_generate_SgNBAdditionRequestAcknowledge( ///---------------------------------------------------------------------------------------------------------------/// static void init_NR_SI(const protocol_ctxt_t *const ctxt_pP, - const int CC_id -#if defined(ENABLE_ITTI) - , - gNB_RrcConfigurationReq *configuration -#endif + const int CC_id, + gNB_RrcConfigurationReq *configuration + ) { //int i; LOG_D(RRC,"%s()\n\n\n\n",__FUNCTION__); @@ -219,20 +211,14 @@ static void init_NR_SI(const protocol_ctxt_t *const ctxt_pP, RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_MIB = 0; RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].MIB = (uint8_t *) malloc16(4); RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_MIB = do_MIB_NR(&RC.nrrrc[ctxt_pP->module_id]->carrier[CC_id],0, -#ifdef ENABLE_ITTI - configuration->MIB_ssb_SubcarrierOffset[CC_id], - configuration->pdcch_ConfigSIB1[CC_id], - configuration->MIB_subCarrierSpacingCommon[CC_id], - configuration->MIB_dmrs_TypeA_Position[CC_id] -#else - 0,0,15,2 -#endif + configuration->MIB_ssb_SubcarrierOffset[CC_id], + configuration->pdcch_ConfigSIB1[CC_id], + configuration->MIB_subCarrierSpacingCommon[CC_id], + configuration->MIB_dmrs_TypeA_Position[CC_id] ); do_SERVINGCELLCONFIGCOMMON(ctxt_pP->module_id, CC_id, -#if defined(ENABLE_ITTI) configuration, -#endif 1 ); LOG_I(NR_RRC,"Done init_NR_SI\n"); @@ -268,9 +254,8 @@ char openair_rrc_gNB_configuration(const module_id_t gnb_mod_idP, gNB_RrcConfigu #endif AssertFatal(RC.nrrrc[gnb_mod_idP] != NULL, "RC.nrrrc not initialized!"); AssertFatal(NUMBER_OF_UE_MAX < (module_id_t)0xFFFFFFFFFFFFFFFF, " variable overflow"); -#ifdef ENABLE_ITTI AssertFatal(configuration!=NULL,"configuration input is null\n"); -#endif + RC.nrrrc[ctxt.module_id]->Nb_ue = 0; for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { @@ -287,10 +272,8 @@ char openair_rrc_gNB_configuration(const module_id_t gnb_mod_idP, gNB_RrcConfigu for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) { init_NR_SI(&ctxt, - CC_id -#if defined(ENABLE_ITTI) - ,configuration -#endif + CC_id, + configuration ); }//END for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++) @@ -302,7 +285,7 @@ char openair_rrc_gNB_configuration(const module_id_t gnb_mod_idP, gNB_RrcConfigu ///---------------------------------------------------------------------------------------------------------------/// ///---------------------------------------------------------------------------------------------------------------/// -#if defined(ENABLE_ITTI) + void *rrc_gnb_task(void *args_p) { MessageDef *msg_p; @@ -408,4 +391,3 @@ void *rrc_gnb_task(void *args_p) { } } -#endif //END #if defined(ENABLE_ITTI) diff --git a/openair2/UTIL/LOG/log.c b/openair2/UTIL/LOG/log.c deleted file mode 100644 index faff4fcfb9..0000000000 --- a/openair2/UTIL/LOG/log.c +++ /dev/null @@ -1,1832 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/*! \file log.c -* \brief log implementaion -* \author Navid Nikaein -* \date 2009 - 2014 -* \version 0.5 -* @ingroup util - -*/ - -#define _GNU_SOURCE /* required for pthread_getname_np */ -//#define LOG_TEST 1 - -#define COMPONENT_LOG -#define COMPONENT_LOG_IF -#include -#define LOG_MAIN -#include "log.h" -#include "vcd_signal_dumper.h" -#include "assertions.h" - -#if defined(ENABLE_ITTI) -# include "intertask_interface.h" -#endif - -# include -# include -#include "common/config/config_userapi.h" -// main log variables - - -mapping log_level_names[] = { - {"emerg", LOG_EMERG}, - {"alert", LOG_ALERT}, - {"crit", LOG_CRIT}, - {"error", LOG_ERR}, - {"warn", LOG_WARNING}, - {"notice", LOG_NOTICE}, - {"info", LOG_INFO}, - {"debug", LOG_DEBUG}, - {"file", LOG_FILE}, - {"trace", LOG_TRACE}, - {NULL, -1} -}; -mapping log_verbosity_names[] = { - {"none", 0x0}, - {"low", 0x5}, - {"medium", 0x15}, - {"high", 0x35}, - {"full", 0x75}, - {NULL, -1} -}; - -// vars for the log thread -LOG_params log_list[2000]; -int log_list_tail = 0; -int log_list_nb_elements = 0; - -pthread_mutex_t log_lock; -pthread_cond_t log_notify; - - -#if !defined(LOG_NO_THREAD) -int log_list_head = 0; -int log_shutdown; -#endif - -static int gfd; - -static char *log_level_highlight_start[] = {LOG_RED, LOG_RED, LOG_RED, LOG_RED, LOG_ORANGE, LOG_BLUE, "", ""}; /*!< \brief Optional start-format strings for highlighting */ -static char *log_level_highlight_end[] = {LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET,LOG_RESET, "",""}; /*!< \brief Optional end-format strings for highlighting */ - -#if defined(ENABLE_ITTI) -static log_instance_type_t log_instance_type; -#endif - -/* get log parameters from configuration file */ -void log_getconfig(log_t *g_log) { - char *gloglevel = NULL; - char *glogverbo = NULL; - int level,verbosity; - paramdef_t logparams_defaults[] = LOG_GLOBALPARAMS_DESC; - paramdef_t logparams_level[MAX_LOG_COMPONENTS]; - paramdef_t logparams_verbosity[MAX_LOG_COMPONENTS]; - paramdef_t logparams_logfile[MAX_LOG_COMPONENTS]; - - int ret = config_get( logparams_defaults,sizeof(logparams_defaults)/sizeof(paramdef_t),CONFIG_STRING_LOG_PREFIX); - if (ret <0) { - fprintf(stderr,"[LOG] init aborted, configuration couldn't be performed"); - return; - } - memset(logparams_level, 0, sizeof(paramdef_t)*MAX_LOG_COMPONENTS); - memset(logparams_verbosity,0, sizeof(paramdef_t)*MAX_LOG_COMPONENTS); - memset(logparams_logfile, 0, sizeof(paramdef_t)*MAX_LOG_COMPONENTS); - for (int i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - if(g_log->log_component[i].name == NULL) { - g_log->log_component[i].name = malloc(16); - sprintf((char *)g_log->log_component[i].name,"comp%i?",i); - logparams_logfile[i].paramflags = PARAMFLAG_DONOTREAD; - logparams_level[i].paramflags = PARAMFLAG_DONOTREAD; - logparams_verbosity[i].paramflags = PARAMFLAG_DONOTREAD; - } - sprintf(logparams_level[i].optname, LOG_CONFIG_LEVEL_FORMAT, g_log->log_component[i].name); - sprintf(logparams_verbosity[i].optname,LOG_CONFIG_VERBOSITY_FORMAT, g_log->log_component[i].name); - sprintf(logparams_logfile[i].optname, LOG_CONFIG_LOGFILE_FORMAT, g_log->log_component[i].name); -/* workaround: all log options in existing configuration files use lower case component names - where component names include uppercase char in log.h.... */ - for (int j=0 ; jlog_component[PHY].name = "PHY"; - g_log->log_component[PHY].level = LOG_EMERG; - g_log->log_component[PHY].flag = LOG_MED; - g_log->log_component[PHY].interval = 1; - g_log->log_component[PHY].fd = 0; - g_log->log_component[PHY].filelog = 0; - g_log->log_component[PHY].filelog_name = "/tmp/phy.log"; - - g_log->log_component[MAC].name = "MAC"; - g_log->log_component[MAC].level = LOG_EMERG; - g_log->log_component[MAC].flag = LOG_MED; - g_log->log_component[MAC].interval = 1; - g_log->log_component[MAC].fd = 0; - g_log->log_component[MAC].filelog = 0; - g_log->log_component[MAC].filelog_name = "/tmp/mac.log"; - - g_log->log_component[OPT].name = "OPT"; - g_log->log_component[OPT].level = LOG_EMERG; - g_log->log_component[OPT].flag = LOG_MED; - g_log->log_component[OPT].interval = 1; - g_log->log_component[OPT].fd = 0; - g_log->log_component[OPT].filelog = 0; - g_log->log_component[OPT].filelog_name = ""; - - g_log->log_component[RLC].name = "RLC"; - g_log->log_component[RLC].level = LOG_INFO; - g_log->log_component[RLC].flag = LOG_MED; - g_log->log_component[RLC].interval = 1; - g_log->log_component[RLC].fd = 0; - g_log->log_component[RLC].filelog = 0; - g_log->log_component[RLC].filelog_name = "/tmp/rlc.log"; - - g_log->log_component[PDCP].name = "PDCP"; - g_log->log_component[PDCP].level = LOG_INFO; - g_log->log_component[PDCP].flag = LOG_MED; - g_log->log_component[PDCP].interval = 1; - g_log->log_component[PDCP].fd = 0; - g_log->log_component[PDCP].filelog = 0; - g_log->log_component[PDCP].filelog_name = "/tmp/pdcp.log"; - - g_log->log_component[RRC].name = "RRC"; - g_log->log_component[RRC].level = LOG_TRACE; - g_log->log_component[RRC].flag = LOG_MED; - g_log->log_component[RRC].interval = 1; - g_log->log_component[RRC].fd = 0; - g_log->log_component[RRC].filelog = 0; - g_log->log_component[RRC].filelog_name = "/tmp/rrc.log"; - - g_log->log_component[EMU].name = "EMU"; - g_log->log_component[EMU].level = LOG_EMERG; - g_log->log_component[EMU].flag = LOG_MED; - g_log->log_component[EMU].interval = 1; - g_log->log_component[EMU].fd = 0; - g_log->log_component[EMU].filelog = 0; - g_log->log_component[EMU].filelog_name = ""; - - g_log->log_component[OMG].name = "OMG"; - g_log->log_component[OMG].level = LOG_EMERG; - g_log->log_component[OMG].flag = LOG_MED; - g_log->log_component[OMG].interval = 1; - g_log->log_component[OMG].fd = 0; - g_log->log_component[OMG].filelog = 0; - g_log->log_component[OMG].filelog_name = "/tmp/omg.csv"; - - g_log->log_component[OTG].name = "OTG"; - g_log->log_component[OTG].level = LOG_EMERG; - g_log->log_component[OTG].flag = LOG_MED; - g_log->log_component[OTG].interval = 1; - g_log->log_component[OTG].fd = 0; - g_log->log_component[OTG].filelog = 0; - g_log->log_component[OTG].filelog_name = "/tmp/otg.log"; - - g_log->log_component[OTG_LATENCY].name = "OTG_LATENCY"; - g_log->log_component[OTG_LATENCY].level = LOG_EMERG; - g_log->log_component[OTG_LATENCY].flag = LOG_MED; - g_log->log_component[OTG_LATENCY].interval = 1; - g_log->log_component[OTG_LATENCY].fd = 0; - g_log->log_component[OTG_LATENCY].filelog = 0; - g_log->log_component[OTG_LATENCY].filelog_name = "/tmp/otg_latency.dat"; - - g_log->log_component[OTG_LATENCY_BG].name = "OTG_LATENCY_BG"; - g_log->log_component[OTG_LATENCY_BG].level = LOG_EMERG; - g_log->log_component[OTG_LATENCY_BG].flag = LOG_MED; - g_log->log_component[OTG_LATENCY_BG].interval = 1; - g_log->log_component[OTG_LATENCY_BG].fd = 0; - g_log->log_component[OTG_LATENCY_BG].filelog = 0; - g_log->log_component[OTG_LATENCY_BG].filelog_name = "/tmp/otg_latency_bg.dat"; - - g_log->log_component[OTG_GP].name = "OTG_GP"; - g_log->log_component[OTG_GP].level = LOG_EMERG; - g_log->log_component[OTG_GP].flag = LOG_MED; - g_log->log_component[OTG_GP].interval = 1; - g_log->log_component[OTG_GP].fd = 0; - g_log->log_component[OTG_GP].filelog = 0; - g_log->log_component[OTG_GP].filelog_name = "/tmp/otg_goodput.dat"; - - g_log->log_component[OTG_GP_BG].name = "OTG_GP_BG"; - g_log->log_component[OTG_GP_BG].level = LOG_EMERG; - g_log->log_component[OTG_GP_BG].flag = LOG_MED; - g_log->log_component[OTG_GP_BG].interval = 1; - g_log->log_component[OTG_GP_BG].fd = 0; - g_log->log_component[OTG_GP_BG].filelog = 0; - g_log->log_component[OTG_GP_BG].filelog_name = "/tmp/otg_goodput_bg.dat"; - - g_log->log_component[OTG_JITTER].name = "OTG_JITTER"; - g_log->log_component[OTG_JITTER].level = LOG_EMERG; - g_log->log_component[OTG_JITTER].flag = LOG_MED; - g_log->log_component[OTG_JITTER].interval = 1; - g_log->log_component[OTG_JITTER].fd = 0; - g_log->log_component[OTG_JITTER].filelog = 0; - g_log->log_component[OTG_JITTER].filelog_name = "/tmp/otg_jitter.dat"; - - g_log->log_component[OCG].name = "OCG"; - g_log->log_component[OCG].level = LOG_EMERG; - g_log->log_component[OCG].flag = LOG_MED; - g_log->log_component[OCG].interval = 1; - g_log->log_component[OCG].fd = 0; - g_log->log_component[OCG].filelog = 0; - g_log->log_component[OCG].filelog_name = ""; - - g_log->log_component[PERF].name = "PERF"; - g_log->log_component[PERF].level = LOG_EMERG; - g_log->log_component[PERF].flag = LOG_MED; - g_log->log_component[PERF].interval = 1; - g_log->log_component[PERF].fd = 0; - g_log->log_component[PERF].filelog = 0; - g_log->log_component[PERF].filelog_name = ""; - - g_log->log_component[OIP].name = "OIP"; - g_log->log_component[OIP].level = LOG_EMERG; - g_log->log_component[OIP].flag = LOG_MED; - g_log->log_component[OIP].interval = 1; - g_log->log_component[OIP].fd = 0; - g_log->log_component[OIP].filelog = 0; - g_log->log_component[OIP].filelog_name = ""; - - g_log->log_component[CLI].name = "CLI"; - g_log->log_component[CLI].level = LOG_EMERG; - g_log->log_component[CLI].flag = LOG_MED; - g_log->log_component[CLI].interval = 1; - g_log->log_component[CLI].fd = 0; - g_log->log_component[CLI].filelog = 0; - g_log->log_component[CLI].filelog_name = ""; - - g_log->log_component[MSC].name = "MSC"; - g_log->log_component[MSC].level = LOG_EMERG; - g_log->log_component[MSC].flag = LOG_MED; - g_log->log_component[MSC].interval = 1; - g_log->log_component[MSC].fd = 0; - g_log->log_component[MSC].filelog = 0; - g_log->log_component[MSC].filelog_name = "/tmp/msc.log"; - - g_log->log_component[PROTO_AGENT].name = "PROTO_AGENT"; - g_log->log_component[PROTO_AGENT].level = LOG_EMERG; - g_log->log_component[PROTO_AGENT].flag = LOG_MED; - g_log->log_component[PROTO_AGENT].interval = 1; - g_log->log_component[PROTO_AGENT].fd = 0; - g_log->log_component[PROTO_AGENT].filelog = 0; - g_log->log_component[PROTO_AGENT].filelog_name = "/tmp/proto_agent.log"; - - - - g_log->log_component[PROTO_AGENT].name = "PROTO_AGENT"; - g_log->log_component[PROTO_AGENT].level = LOG_EMERG; - g_log->log_component[PROTO_AGENT].flag = LOG_MED; - g_log->log_component[PROTO_AGENT].interval = 1; - g_log->log_component[PROTO_AGENT].fd = 0; - g_log->log_component[PROTO_AGENT].filelog = 0; - g_log->log_component[PROTO_AGENT].filelog_name = "/tmp/proto_agent.log"; - - g_log->log_component[F1U].name = "F1U"; - g_log->log_component[F1U].level = LOG_EMERG; - g_log->log_component[F1U].flag = LOG_MED; - g_log->log_component[F1U].interval = 1; - g_log->log_component[F1U].fd = 0; - g_log->log_component[F1U].filelog = 0; - g_log->log_component[F1U].filelog_name = "/tmp/f1u.log"; - - g_log->log_component[OCM].name = "OCM"; - g_log->log_component[OCM].level = LOG_EMERG; - g_log->log_component[OCM].flag = LOG_MED; - g_log->log_component[OCM].interval = 1; - g_log->log_component[OCM].fd = 0; - g_log->log_component[OCM].filelog = 0; - g_log->log_component[OCM].filelog_name = "/tmp/ocm.log"; - - g_log->log_component[HW].name = "HW"; - g_log->log_component[HW].level = LOG_EMERG; - g_log->log_component[HW].flag = LOG_MED; - g_log->log_component[HW].interval = 1; - g_log->log_component[HW].fd = 0; - g_log->log_component[HW].filelog = 0; - g_log->log_component[HW].filelog_name = ""; - - g_log->log_component[OSA].name = "OSA"; - g_log->log_component[OSA].level = LOG_EMERG; - g_log->log_component[OSA].flag = LOG_MED; - g_log->log_component[OSA].interval = 1; - g_log->log_component[OSA].fd = 0; - g_log->log_component[OSA].filelog = 0; - g_log->log_component[OSA].filelog_name = ""; - - g_log->log_component[RAL_ENB].name = "eRAL"; - g_log->log_component[RAL_ENB].level = LOG_EMERG; - g_log->log_component[RAL_ENB].flag = LOG_MED; - g_log->log_component[RAL_ENB].interval = 1; - g_log->log_component[RAL_ENB].fd = 0; - g_log->log_component[RAL_ENB].filelog = 0; - g_log->log_component[RAL_ENB].filelog_name = ""; - - g_log->log_component[RAL_UE].name = "mRAL"; - g_log->log_component[RAL_UE].level = LOG_EMERG; - g_log->log_component[RAL_UE].flag = LOG_MED; - g_log->log_component[RAL_UE].interval = 1; - g_log->log_component[RAL_UE].fd = 0; - g_log->log_component[RAL_UE].filelog = 0; - g_log->log_component[RAL_UE].filelog_name = ""; - - g_log->log_component[ENB_APP].name = "ENB_APP"; - g_log->log_component[ENB_APP].level = LOG_EMERG; - g_log->log_component[ENB_APP].flag = LOG_MED; - g_log->log_component[ENB_APP].interval = 1; - g_log->log_component[ENB_APP].fd = 0; - g_log->log_component[ENB_APP].filelog = 0; - g_log->log_component[ENB_APP].filelog_name = ""; - - g_log->log_component[FLEXRAN_AGENT].name = "FLEXRAN_AGENT"; - g_log->log_component[FLEXRAN_AGENT].level = LOG_DEBUG; - g_log->log_component[FLEXRAN_AGENT].flag = LOG_MED; - g_log->log_component[FLEXRAN_AGENT].interval = 1; - g_log->log_component[FLEXRAN_AGENT].fd = 0; - g_log->log_component[FLEXRAN_AGENT].filelog = 0; - g_log->log_component[FLEXRAN_AGENT].filelog_name = ""; - - g_log->log_component[TMR].name = "TMR"; - g_log->log_component[TMR].level = LOG_EMERG; - g_log->log_component[TMR].flag = LOG_MED; - g_log->log_component[TMR].interval = 1; - g_log->log_component[TMR].fd = 0; - g_log->log_component[TMR].filelog = 0; - g_log->log_component[TMR].filelog_name = ""; - - g_log->log_component[USIM].name = "USIM"; - g_log->log_component[USIM].level = LOG_DEBUG; - g_log->log_component[USIM].flag = LOG_NONE; - g_log->log_component[USIM].interval = 1; - g_log->log_component[USIM].fd = 0; - g_log->log_component[USIM].filelog = 0; - g_log->log_component[USIM].filelog_name = "/tmp/usim.txt"; - - /* following log component are used for the localization*/ - g_log->log_component[LOCALIZE].name = "LOCALIZE"; - g_log->log_component[LOCALIZE].level = LOG_EMERG; - g_log->log_component[LOCALIZE].flag = LOG_MED; - g_log->log_component[LOCALIZE].interval = 1; - g_log->log_component[LOCALIZE].fd = 0; - g_log->log_component[LOCALIZE].filelog = 0; - g_log->log_component[LOCALIZE].filelog_name = "/tmp/localize.log"; -#endif // ! defined(CN_BUILD) - - g_log->log_component[NAS].name = "NAS"; - g_log->log_component[NAS].level = LOG_TRACE; - g_log->log_component[NAS].flag = LOG_MED; - g_log->log_component[NAS].interval = 1; - g_log->log_component[NAS].fd = 0; - g_log->log_component[NAS].filelog = 0; - g_log->log_component[NAS].filelog_name = "/tmp/nas.log"; - - g_log->log_component[UDP_].name = "UDP"; - g_log->log_component[UDP_].level = LOG_EMERG; - g_log->log_component[UDP_].flag = LOG_FULL; - g_log->log_component[UDP_].interval = 1; - g_log->log_component[UDP_].fd = 0; - g_log->log_component[UDP_].filelog = 0; - g_log->log_component[UDP_].filelog_name = ""; - - g_log->log_component[GTPU].name = "GTPV1U"; - g_log->log_component[GTPU].level = LOG_EMERG; - g_log->log_component[GTPU].flag = LOG_FULL; - g_log->log_component[GTPU].interval = 1; - g_log->log_component[GTPU].fd = 0; - g_log->log_component[GTPU].filelog = 0; - g_log->log_component[GTPU].filelog_name = ""; - - g_log->log_component[S1AP].name = "S1AP"; - g_log->log_component[S1AP].level = LOG_EMERG; - g_log->log_component[S1AP].flag = LOG_FULL; - g_log->log_component[S1AP].interval = 1; - g_log->log_component[S1AP].fd = 0; - g_log->log_component[S1AP].filelog = 0; - g_log->log_component[S1AP].filelog_name = ""; - - g_log->log_component[SCTP].name = "SCTP"; - g_log->log_component[SCTP].level = LOG_EMERG; - g_log->log_component[SCTP].flag = LOG_MED; - g_log->log_component[SCTP].interval = 1; - g_log->log_component[SCTP].fd = 0; - g_log->log_component[SCTP].filelog = 0; - g_log->log_component[SCTP].filelog_name = ""; - - g_log->log_component[RRH].name = "RRH"; - g_log->log_component[RRH].level = LOG_EMERG; - g_log->log_component[RRH].flag = LOG_MED; - g_log->log_component[RRH].interval = 1; - g_log->log_component[RRH].fd = 0; - g_log->log_component[RRH].filelog = 0; - g_log->log_component[RRH].filelog_name = ""; - - g_log->level2string[LOG_EMERG] = "G"; //EMERG - g_log->level2string[LOG_ALERT] = "A"; // ALERT - g_log->level2string[LOG_CRIT] = "C"; // CRITIC - g_log->level2string[LOG_ERR] = "E"; // ERROR - g_log->level2string[LOG_WARNING] = "W"; // WARNING - g_log->level2string[LOG_NOTICE] = "N"; // NOTICE - g_log->level2string[LOG_INFO] = "I"; //INFO - g_log->level2string[LOG_DEBUG] = "D"; // DEBUG - g_log->level2string[LOG_FILE] = "F"; // file - g_log->level2string[LOG_TRACE] = "T"; // TRACE - - g_log->onlinelog = 1; //online log file - g_log->syslog = 0; - g_log->filelog = 0; - g_log->level = LOG_TRACE; - g_log->flag = LOG_LOW; - - g_log->config.remote_ip = 0; - g_log->config.remote_level = LOG_EMERG; - g_log->config.facility = LOG_LOCAL7; - g_log->config.audit_ip = 0; - g_log->config.audit_facility = LOG_LOCAL6; - g_log->config.format = 0x00; // online debug inactive - - g_log->filelog_name = "/tmp/openair.log"; - - if (g_log->syslog) { -#if ! defined(CN_BUILD) - openlog(g_log->log_component[EMU].name, LOG_PID, g_log->config.facility); -#endif // ! defined(CN_BUILD) - } - log_getconfig(g_log); - if (g_log->filelog) { - gfd = open(g_log->filelog_name, O_WRONLY | O_CREAT, 0666); - } - - // could put a loop here to check for all comps - for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - if (g_log->log_component[i].filelog == 1 ) { - g_log->log_component[i].fd = open(g_log->log_component[i].filelog_name, - O_WRONLY | O_CREAT | O_APPEND, 0666); - } - } - - printf("log init done\n"); - - return 0; -} - -void nfapi_log(char *file, char *func, int line, int comp, int level, const char* format, va_list args) -{ - //logRecord_mt(file,func,line, pthread_self(), comp, level, format, ##args) - int len = 0; - log_component_t *c; - char *log_start; - char *log_end; - /* The main difference with the version above is the use of this local log_buffer. - * The other difference is the return value of snprintf which was not used - * correctly. It was not a big problem because in practice MAX_LOG_TOTAL is - * big enough so that the buffer is never full. - */ - char log_buffer[MAX_LOG_TOTAL]; - - /* for no gcc warnings */ - (void)log_start; - (void)log_end; - - c = &g_log->log_component[comp]; - - // do not apply filtering for LOG_F - // only log messages which are enabled and are below the global log level and component's level threshold - if ((level != LOG_FILE) && ((level > c->level) || (level > g_log->level))) { - /* if ((level != LOG_FILE) && - ((level > c->level) || - (level > g_log->level) || - ( c->level > g_log->level))) { - */ - return; - } - - //VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, VCD_FUNCTION_IN); - - // adjust syslog level for TRACE messages - if (g_log->syslog) { - if (g_log->level > LOG_DEBUG) { - g_log->level = LOG_DEBUG; - } - } - - // make sure that for log trace the extra info is only printed once, reset when the level changes - if ((level == LOG_FILE) || (c->flag == LOG_NONE) || (level == LOG_TRACE)) { - log_start = log_buffer; - len = vsnprintf(log_buffer, MAX_LOG_TOTAL, format, args); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - log_end = log_buffer + len; - } else { - if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "%s", - log_level_highlight_start[level]); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - log_start = log_buffer + len; - - if ( (g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", - g_log->log_component[comp].name); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - if ( (g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", - g_log->level2string[level]); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - if ( (g_log->flag & FLAG_THREAD) || (c->flag & FLAG_THREAD) ) { -# define THREAD_NAME_LEN 128 - char threadname[THREAD_NAME_LEN]; - if (pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN) != 0) - { - perror("pthread_getname_np : "); - } else { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", threadname); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } -# undef THREAD_NAME_LEN - } - - if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s] ", - func); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s:%d]", - file, line); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - //len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%08lx]", thread_id); - //if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - - len += vsnprintf(&log_buffer[len], MAX_LOG_TOTAL - len, format, args); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - log_end = log_buffer + len; - - if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "%s", - log_level_highlight_end[level]); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - } - - va_end(args); - - // OAI printf compatibility - if ((g_log->onlinelog == 1) && (level != LOG_FILE)) -#ifdef RTAI - if (len > MAX_LOG_TOTAL) { - rt_printk ("[OPENAIR] FIFO_PRINTF WROTE OUTSIDE ITS MEMORY BOUNDARY : ERRORS WILL OCCUR\n"); - } - - if (len > 0) { - rtf_put (FIFO_PRINTF_NO, log_buffer, len); - } - -#else - fwrite(log_buffer, len, 1, stdout); -#endif - -#ifndef RTAI - - if (g_log->syslog) { - syslog(g_log->level, "%s", log_buffer); - } - - if (g_log->filelog) { - if (write(gfd, log_buffer, len) < len) { - // TODO assert ? - } - } - - if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) { - if (write(g_log->log_component[comp].fd, log_buffer, len) < len) { - // TODO assert ? - } - } - -#else - - // online print messges - if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) { - printf(log_buffer); - } - -#endif - -#if defined(ENABLE_ITTI) - - if (level <= LOG_DEBUG) { - task_id_t origin_task_id = TASK_UNKNOWN; - MessagesIds messages_id; - MessageDef *message_p; - size_t message_string_size; - char *message_msg_p; - - message_string_size = log_end - log_start; - -#if !defined(DISABLE_ITTI_DETECT_SUB_TASK_ID) - - /* Try to identify sub task ID from log information (comp, log_instance_type) */ - switch (comp) { - case PHY: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_PHY_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_PHY_UE; - break; - - default: - break; - } - - break; - - case MAC: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_MAC_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_MAC_UE; - - default: - break; - } - - break; - - case RLC: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_RLC_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_RLC_UE; - - default: - break; - } - - break; - - case PDCP: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_PDCP_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_PDCP_UE; - - default: - break; - } - - break; - - default: - break; - } - -#endif - - switch (level) { - case LOG_EMERG: - case LOG_ALERT: - case LOG_CRIT: - case LOG_ERR: - messages_id = ERROR_LOG; - break; - - case LOG_WARNING: - messages_id = WARNING_LOG; - break; - - case LOG_NOTICE: - messages_id = NOTICE_LOG; - break; - - case LOG_INFO: - messages_id = INFO_LOG; - break; - - default: - messages_id = DEBUG_LOG; - break; - } - - message_p = itti_alloc_new_message_sized(origin_task_id, messages_id, message_string_size); - - switch (level) { - case LOG_EMERG: - case LOG_ALERT: - case LOG_CRIT: - case LOG_ERR: - message_msg_p = (char *) &message_p->ittiMsg.error_log; - break; - - case LOG_WARNING: - message_msg_p = (char *) &message_p->ittiMsg.warning_log; - break; - - case LOG_NOTICE: - message_msg_p = (char *) &message_p->ittiMsg.notice_log; - break; - - case LOG_INFO: - message_msg_p = (char *) &message_p->ittiMsg.info_log; - break; - - default: - message_msg_p = (char *) &message_p->ittiMsg.debug_log; - break; - } - - memcpy(message_msg_p, log_start, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p); - } - -#endif -#if 0 - LOG_params log_params; - int len; - - len = vsnprintf(log_params.l_buff_info, MAX_LOG_INFO-1, format, args); - - //2 first parameters must be passed as 'const' to the thread function - log_params.file = strdup(file); - log_params.func = strdup(func); - log_params.line = line; - log_params.comp = PHY;//comp; - log_params.level = 6; // INFO - level; - log_params.format = format; - log_params.len = len; - - if (pthread_mutex_lock(&log_lock) != 0) { - return; - } - - log_list_tail++; - log_list[log_list_tail - 1] = log_params; - - if (log_list_tail >= 1000) { - log_list_tail = 0; - } - - if (log_list_nb_elements < 1000) { - log_list_nb_elements++; - } - - if(pthread_cond_signal(&log_notify) != 0) { - pthread_mutex_unlock(&log_lock); - return; - } - - if(pthread_mutex_unlock(&log_lock) != 0) { - return; - } - -#endif -} - -//log record: add to a list -void logRecord(const char *file, const char *func, int line, int comp, - int level, const char *format, ...) -{ - va_list args; - LOG_params log_params; - int len; - - va_start(args, format); - len = vsnprintf(log_params.l_buff_info, MAX_LOG_INFO-1, format, args); - va_end(args); - - //2 first parameters must be passed as 'const' to the thread function - log_params.file = strdup(file); - log_params.func = strdup(func); - log_params.line = line; - log_params.comp = comp; - log_params.level = level; - log_params.format = format; - log_params.len = len; - - if (pthread_mutex_lock(&log_lock) != 0) { - return; - } - - log_list_tail++; - log_list[log_list_tail - 1] = log_params; - - if (log_list_tail >= 1000) { - log_list_tail = 0; - } - - if (log_list_nb_elements < 1000) { - log_list_nb_elements++; - } - - if(pthread_cond_signal(&log_notify) != 0) { - pthread_mutex_unlock(&log_lock); - return; - } - - if(pthread_mutex_unlock(&log_lock) != 0) { - return; - } - - //log = malloc(sizeof(LOG_elt)); - //log->next = NULL; - //log->log_params = log_params; - /* Add log task to queue */ - //log_list_add_tail_eurecom(log, &log_list); - -} - -void logRecord_thread_safe(const char *file, const char *func, - int line, int comp, int level, - int len, const char *params_string) -{ - log_component_t *c; - int total_len = 0; - char log_buffer[MAX_LOG_TOTAL]; - - c = &g_log->log_component[comp]; - - // do not apply filtering for LOG_F - // only log messages which are enabled and are below the global log level and component's level threshold - if ((level != LOG_FILE) && ((c->level > g_log->level) || - (level > c->level) || (level > g_log->level))) { - return; - } - - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, - VCD_FUNCTION_IN); - - // adjust syslog level for TRACE messages - if (g_log->syslog) { - if (g_log->level > LOG_DEBUG) { - g_log->level = LOG_DEBUG; - } - } - - // make sure that for log trace the extra info is only printed once, reset when the level changes - if ((level == LOG_FILE) || (c->flag == LOG_NONE) || (level ==LOG_TRACE )) { - total_len = snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - 1, "%s", - params_string); - } else { - if ((g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR)) { - total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "%s", - log_level_highlight_start[level]); - } - - if ((g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ) { - total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s]", - g_log->log_component[comp].name); - } - - if ((g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL)) { - total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s]", - g_log->level2string[level]); - } - - if ((g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT)) { - total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s] ", - func); - } - - if ((g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) { - total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "[%s:%d]", - file, line); - } - - len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - len, "%s", - params_string); - - if ((g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR)) { - total_len += snprintf(&log_buffer[total_len], MAX_LOG_TOTAL - total_len, "%s", - log_level_highlight_end[level]); - } - } - - // OAI printf compatibility - if ((g_log->onlinelog == 1) && (level != LOG_FILE)) { - fprintf(stdout, "%s", log_buffer); - } - - if (g_log->syslog) { - syslog(g_log->level, "%s", log_buffer); - } - - if (g_log->filelog) { - if (write(gfd, log_buffer, total_len) < total_len) { - // TODO assert ? - } - } - - if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) { - if (write(g_log->log_component[comp].fd, log_buffer, total_len) < total_len) { - // TODO assert ? - } - } - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, - VCD_FUNCTION_OUT); -} - -#if !defined(LOG_NO_THREAD) -void *log_thread_function(void *list) -{ - - LOG_params log_params; - - for(;;) { - - //log_elt = NULL; - - /* Lock must be taken to wait on conditional variable */ - pthread_mutex_lock(&log_lock); - - /* Wait on condition variable, check for spurious wakeups. - When returning from pthread_cond_wait(), we own the lock. */ - - // sleep - while((log_list_nb_elements == 0) && (log_shutdown == 0)) { - pthread_cond_wait(&log_notify, &log_lock); - } - - // exit - if ((log_shutdown==1) && (log_list_nb_elements == 0)) { - break; - } - - /* Grab our task */ - //log_elt = log_list_remove_head(&log_list); - log_params = log_list[log_list_head]; - log_list_head++; - log_list_nb_elements--; - - if (log_list_head >= 1000) { - log_list_head = 0; - } - - - /* Unlock */ - pthread_mutex_unlock(&log_lock); - - /* Get to work */ - logRecord_thread_safe(log_params.file, - log_params.func, - log_params.line, - log_params.comp, - log_params.level, - log_params.len, - log_params.l_buff_info); - - //free(log_elt); - } -} -#endif - -#if 0 -/* This function does not work. When multiple threads call it at the same time - * for the same component, both threads end up using the same buffer. - * The output is the completely messed up/wrong. - * Kept in case the fix below is not correct or acceptable. - */ -//log record, format, and print: executed in the main thread (mt) -void logRecord_mt(const char *file, const char *func, int line, int comp, - int level, const char *format, ...) -{ - int len = 0; - va_list args; - log_component_t *c; - char *log_start; - char *log_end; - - /* for no gcc warnings */ - (void)log_start; - (void)log_end; - - c = &g_log->log_component[comp]; - - // do not apply filtering for LOG_F - // only log messages which are enabled and are below the global log level and component's level threshold - if ((level != LOG_FILE) && ((level > c->level) || (level > g_log->level))) { - /* if ((level != LOG_FILE) && - ((level > c->level) || - (level > g_log->level) || - ( c->level > g_log->level))) { - */ - return; - } - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, - VCD_FUNCTION_IN); - - va_start(args, format); - - // adjust syslog level for TRACE messages - if (g_log->syslog) { - if (g_log->level > LOG_DEBUG) { - g_log->level = LOG_DEBUG; - } - } - - // make sure that for log trace the extra info is only printed once, reset when the level changes - if ((level == LOG_FILE) || (c->flag == LOG_NONE) || (level == LOG_TRACE)) { - log_start = c->log_buffer; - len = vsnprintf(c->log_buffer, MAX_LOG_TOTAL-1, format, args); - log_end = c->log_buffer + len; - } else { - if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { - len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "%s", - log_level_highlight_start[level]); - } - - log_start = c->log_buffer + len; - - if ( (g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ) { - len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", - g_log->log_component[comp].name); - } - - if ( (g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL) ) { - len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", - g_log->level2string[level]); - } - - if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) { - len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s] ", - func); - } - - if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) { - len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "[%s:%d]", - file, line); - } - - len += vsnprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, format, args); - log_end = c->log_buffer + len; - - if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { - len += snprintf(&c->log_buffer[len], MAX_LOG_TOTAL - len, "%s", - log_level_highlight_end[level]); - } - } - - va_end(args); - - // OAI printf compatibility - if ((g_log->onlinelog == 1) && (level != LOG_FILE)) - fwrite(c->log_buffer, len, 1, stdout); - - if (g_log->syslog) { - syslog(g_log->level, "%s", c->log_buffer); - } - - if (g_log->filelog) { - if (write(gfd, c->log_buffer, len) < len) { - // TODO assert ? - } - } - - if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) { - if (write(g_log->log_component[comp].fd, c->log_buffer, len) < len) { - // TODO assert ? - } - } - -#if defined(ENABLE_ITTI) - - if (level <= LOG_DEBUG) { - task_id_t origin_task_id = TASK_UNKNOWN; - MessagesIds messages_id; - MessageDef *message_p; - size_t message_string_size; - char *message_msg_p; - - message_string_size = log_end - log_start; - -#if !defined(DISABLE_ITTI_DETECT_SUB_TASK_ID) - - /* Try to identify sub task ID from log information (comp, log_instance_type) */ - switch (comp) { - case PHY: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_PHY_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_PHY_UE; - break; - - default: - break; - } - - break; - - case MAC: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_MAC_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_MAC_UE; - - default: - break; - } - - break; - - case RLC: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_RLC_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_RLC_UE; - - default: - break; - } - - break; - - case PDCP: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_PDCP_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_PDCP_UE; - - default: - break; - } - - break; - - default: - break; - } - -#endif - - switch (level) { - case LOG_EMERG: - case LOG_ALERT: - case LOG_CRIT: - case LOG_ERR: - messages_id = ERROR_LOG; - break; - - case LOG_WARNING: - messages_id = WARNING_LOG; - break; - - case LOG_NOTICE: - messages_id = NOTICE_LOG; - break; - - case LOG_INFO: - messages_id = INFO_LOG; - break; - - default: - messages_id = DEBUG_LOG; - break; - } - - message_p = itti_alloc_new_message_sized(origin_task_id, messages_id, message_string_size); - - switch (level) { - case LOG_EMERG: - case LOG_ALERT: - case LOG_CRIT: - case LOG_ERR: - message_msg_p = (char *) &message_p->ittiMsg.error_log; - break; - - case LOG_WARNING: - message_msg_p = (char *) &message_p->ittiMsg.warning_log; - break; - - case LOG_NOTICE: - message_msg_p = (char *) &message_p->ittiMsg.notice_log; - break; - - case LOG_INFO: - message_msg_p = (char *) &message_p->ittiMsg.info_log; - break; - - default: - message_msg_p = (char *) &message_p->ittiMsg.debug_log; - break; - } - - memcpy(message_msg_p, log_start, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p); - } - -#endif - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, - VCD_FUNCTION_OUT); -} -#endif /* #if 0 */ - -//log record, format, and print: executed in the main thread (mt) -void logRecord_mt(const char *file, const char *func, int line, int comp, - int level, const char *format, ...) -{ - int len = 0; - va_list args; - log_component_t *c; - char *log_start; - char *log_end; - /* The main difference with the version above is the use of this local log_buffer. - * The other difference is the return value of snprintf which was not used - * correctly. It was not a big problem because in practice MAX_LOG_TOTAL is - * big enough so that the buffer is never full. - */ - char log_buffer[MAX_LOG_TOTAL]; - - /* for no gcc warnings */ - (void)log_start; - (void)log_end; - - c = &g_log->log_component[comp]; - - // do not apply filtering for LOG_F - // only log messages which are enabled and are below the global log level and component's level threshold - if ((level != LOG_FILE) && ((level > c->level) || (level > g_log->level))) { - /* if ((level != LOG_FILE) && - ((level > c->level) || - (level > g_log->level) || - ( c->level > g_log->level))) { - */ - return; - } - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, - VCD_FUNCTION_IN); - - va_start(args, format); - - // adjust syslog level for TRACE messages - if (g_log->syslog) { - if (g_log->level > LOG_DEBUG) { - g_log->level = LOG_DEBUG; - } - } - - // make sure that for log trace the extra info is only printed once, reset when the level changes - if ((level == LOG_FILE) || (c->flag == LOG_NONE) || (level == LOG_TRACE)) { - log_start = log_buffer; - len = vsnprintf(log_buffer, MAX_LOG_TOTAL, format, args); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - log_end = log_buffer + len; - } else { - if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "%s", - log_level_highlight_start[level]); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - log_start = log_buffer + len; - - if ( (g_log->flag & FLAG_COMP) || (c->flag & FLAG_COMP) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", - g_log->log_component[comp].name); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - if ( (g_log->flag & FLAG_LEVEL) || (c->flag & FLAG_LEVEL) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", - g_log->level2string[level]); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - if ( (g_log->flag & FLAG_THREAD) || (c->flag & FLAG_THREAD) ) { -# define THREAD_NAME_LEN 128 - char threadname[THREAD_NAME_LEN]; - if (pthread_getname_np(pthread_self(), threadname, THREAD_NAME_LEN) != 0) - { - perror("pthread_getname_np : "); - } else { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s]", threadname); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } -# undef THREAD_NAME_LEN - } - - if ( (g_log->flag & FLAG_FUNCT) || (c->flag & FLAG_FUNCT) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s] ", - func); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - if ( (g_log->flag & FLAG_FILE_LINE) || (c->flag & FLAG_FILE_LINE) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "[%s:%d]", - file, line); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - - len += vsnprintf(&log_buffer[len], MAX_LOG_TOTAL - len, format, args); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - log_end = log_buffer + len; - - if ( (g_log->flag & FLAG_COLOR) || (c->flag & FLAG_COLOR) ) { - len += snprintf(&log_buffer[len], MAX_LOG_TOTAL - len, "%s", - log_level_highlight_end[level]); - if (len > MAX_LOG_TOTAL) len = MAX_LOG_TOTAL; - } - } - - va_end(args); - - // OAI printf compatibility - if ((g_log->onlinelog == 1) && (level != LOG_FILE)) - fwrite(log_buffer, len, 1, stdout); - - if (g_log->syslog) { - syslog(g_log->level, "%s", log_buffer); - } - - if (g_log->filelog) { - if (write(gfd, log_buffer, len) < len) { - // TODO assert ? - } - } - - if ((g_log->log_component[comp].filelog) && (level == LOG_FILE)) { - if (write(g_log->log_component[comp].fd, log_buffer, len) < len) { - // TODO assert ? - } - } - -#if defined(ENABLE_ITTI) - - if (level <= LOG_DEBUG) { - task_id_t origin_task_id = TASK_UNKNOWN; - MessagesIds messages_id; - MessageDef *message_p; - size_t message_string_size; - char *message_msg_p; - - message_string_size = log_end - log_start; - -#if !defined(DISABLE_ITTI_DETECT_SUB_TASK_ID) - - /* Try to identify sub task ID from log information (comp, log_instance_type) */ - switch (comp) { - case PHY: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_PHY_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_PHY_UE; - break; - - default: - break; - } - - break; - - case MAC: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_MAC_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_MAC_UE; - - default: - break; - } - - break; - - case RLC: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_RLC_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_RLC_UE; - - default: - break; - } - - break; - - case PDCP: - switch (log_instance_type) { - case LOG_INSTANCE_ENB: - origin_task_id = TASK_PDCP_ENB; - break; - - case LOG_INSTANCE_UE: - origin_task_id = TASK_PDCP_UE; - - default: - break; - } - - break; - - default: - break; - } - -#endif - - switch (level) { - case LOG_EMERG: - case LOG_ALERT: - case LOG_CRIT: - case LOG_ERR: - messages_id = ERROR_LOG; - break; - - case LOG_WARNING: - messages_id = WARNING_LOG; - break; - - case LOG_NOTICE: - messages_id = NOTICE_LOG; - break; - - case LOG_INFO: - messages_id = INFO_LOG; - break; - - default: - messages_id = DEBUG_LOG; - break; - } - - message_p = itti_alloc_new_message_sized(origin_task_id, messages_id, message_string_size); - - switch (level) { - case LOG_EMERG: - case LOG_ALERT: - case LOG_CRIT: - case LOG_ERR: - message_msg_p = (char *) &message_p->ittiMsg.error_log; - break; - - case LOG_WARNING: - message_msg_p = (char *) &message_p->ittiMsg.warning_log; - break; - - case LOG_NOTICE: - message_msg_p = (char *) &message_p->ittiMsg.notice_log; - break; - - case LOG_INFO: - message_msg_p = (char *) &message_p->ittiMsg.info_log; - break; - - default: - message_msg_p = (char *) &message_p->ittiMsg.debug_log; - break; - } - - memcpy(message_msg_p, log_start, message_string_size); - - itti_send_msg_to_task(TASK_UNKNOWN, INSTANCE_DEFAULT, message_p); - } - -#endif - - VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_LOG_RECORD, - VCD_FUNCTION_OUT); -} - -int set_log(int component, int level, int interval) -{ - /* Checking parameters */ - DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS), - component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS); - DevCheck((level <= LOG_TRACE) && (level >= LOG_EMERG), level, LOG_TRACE, - LOG_EMERG); - DevCheck((interval >= 0) && (interval <= 0xFF), interval, 0, 0xFF); - - g_log->log_component[component].level = level; - - switch (level) { - case LOG_TRACE: - g_log->log_component[component].flag = LOG_MED ; - break; - - case LOG_DEBUG: - g_log->log_component[component].flag = LOG_MED ; - break; - - case LOG_INFO: - g_log->log_component[component].flag = LOG_LOW ; - break; - - default: - g_log->log_component[component].flag = LOG_NONE ; - break; - } - - g_log->log_component[component].interval = interval; - - return 0; -} - -int set_comp_log(int component, int level, int verbosity, int interval) -{ - /* Checking parameters */ - DevCheck((component >= MIN_LOG_COMPONENTS) && (component < MAX_LOG_COMPONENTS), - component, MIN_LOG_COMPONENTS, MAX_LOG_COMPONENTS); - DevCheck((level <= LOG_TRACE) && (level >= LOG_EMERG), level, LOG_TRACE, - LOG_EMERG); - DevCheck((interval >= 0) && (interval <= 0xFF), interval, 0, 0xFF); - -#if 0 - if ((verbosity == LOG_NONE) || (verbosity == LOG_LOW) || - (verbosity == LOG_MED) || (verbosity == LOG_FULL) || - (verbosity == LOG_HIGH)) { - g_log->log_component[component].flag = verbosity; - } -#else - g_log->log_component[component].flag = verbosity; -#endif - - g_log->log_component[component].level = level; - g_log->log_component[component].interval = interval; - - return 0; -} - -void set_glog(int level, int verbosity) -{ - if( g_log->level >= 0) g_log->level = level; - if( g_log->flag >= 0) g_log->flag = verbosity; -} -void set_glog_syslog(int enable) -{ - g_log->syslog = enable; -} -void set_glog_onlinelog(int enable) -{ - g_log->onlinelog = enable; -} -void set_glog_filelog(int enable) -{ - g_log->filelog = enable; -} - -void set_component_filelog(int comp) -{ - if (g_log->log_component[comp].filelog == 0) { - g_log->log_component[comp].filelog = 1; - - if (g_log->log_component[comp].fd == 0) { - g_log->log_component[comp].fd = open(g_log->log_component[comp].filelog_name, - O_WRONLY | O_CREAT | O_TRUNC, 0666); - } - } -} - -/* - * for the two functions below, the passed array must have a final entry - * with string value NULL - */ -/* map a string to an int. Takes a mapping array and a string as arg */ -int map_str_to_int(mapping *map, const char *str) -{ - while (1) { - if (map->name == NULL) { - return(-1); - } - - if (!strcmp(map->name, str)) { - return(map->value); - } - - map++; - } -} - -/* map an int to a string. Takes a mapping array and a value */ -char *map_int_to_str(mapping *map, int val) -{ - while (1) { - if (map->name == NULL) { - return NULL; - } - - if (map->value == val) { - return map->name; - } - - map++; - } -} - -int is_newline( char *str, int size) -{ - int i; - - for ( i = 0; i < size; i++ ) { - if ( str[i] == '\n' ) { - return 1; - } - } - - /* if we get all the way to here, there must not have been a newline! */ - return 0; -} - -void logClean (void) -{ - int i; - - if (g_log->syslog) { - closelog(); - } - - if (g_log->filelog) { - close(gfd); - } - - for (i=MIN_LOG_COMPONENTS; i < MAX_LOG_COMPONENTS; i++) { - if (g_log->log_component[i].filelog) { - close(g_log->log_component[i].fd); - } - } -} - -#if defined(ENABLE_ITTI) -void log_set_instance_type (log_instance_type_t instance) -{ - log_instance_type = instance; -} -#endif - -#ifdef LOG_TEST - -int main(int argc, char *argv[]) -{ - - logInit(); - - //set_log_syslog(1); - test_log(); - - return 1; -} - -int test_log(void) -{ - LOG_ENTER(MAC); // because the default level is DEBUG - LOG_I(EMU, "1 Starting OAI logs version %s Build date: %s on %s\n", - BUILD_VERSION, BUILD_DATE, BUILD_HOST); - LOG_D(MAC, "1 debug MAC \n"); - LOG_N(MAC, "1 notice MAC \n"); - LOG_W(MAC, "1 warning MAC \n"); - - set_comp_log(EMU, LOG_INFO, FLAG_ONLINE); - set_comp_log(MAC, LOG_WARNING, 0); - - LOG_I(EMU, "2 Starting OAI logs version %s Build date: %s on %s\n", - BUILD_VERSION, BUILD_DATE, BUILD_HOST); - LOG_E(MAC, "2 emerge MAC\n"); - LOG_D(MAC, "2 debug MAC \n"); - LOG_N(MAC, "2 notice MAC \n"); - LOG_W(MAC, "2 warning MAC \n"); - LOG_I(MAC, "2 info MAC \n"); - - - set_comp_log(MAC, LOG_NOTICE, 1); - - LOG_ENTER(MAC); - LOG_I(EMU, "3 Starting OAI logs version %s Build date: %s on %s\n", - BUILD_VERSION, BUILD_DATE, BUILD_HOST); - LOG_D(MAC, "3 debug MAC \n"); - LOG_N(MAC, "3 notice MAC \n"); - LOG_W(MAC, "3 warning MAC \n"); - LOG_I(MAC, "3 info MAC \n"); - - set_comp_log(MAC, LOG_DEBUG,1); - set_comp_log(EMU, LOG_DEBUG,1); - - LOG_ENTER(MAC); - LOG_I(EMU, "4 Starting OAI logs version %s Build date: %s on %s\n", - BUILD_VERSION, BUILD_DATE, BUILD_HOST); - LOG_D(MAC, "4 debug MAC \n"); - LOG_N(MAC, "4 notice MAC \n"); - LOG_W(MAC, "4 warning MAC \n"); - LOG_I(MAC, "4 info MAC \n"); - - - set_comp_log(MAC, LOG_DEBUG,0); - set_comp_log(EMU, LOG_DEBUG,0); - - LOG_I(LOG, "5 Starting OAI logs version %s Build date: %s on %s\n", - BUILD_VERSION, BUILD_DATE, BUILD_HOST); - LOG_D(MAC, "5 debug MAC \n"); - LOG_N(MAC, "5 notice MAC \n"); - LOG_W(MAC, "5 warning MAC \n"); - LOG_I(MAC, "5 info MAC \n"); - - - set_comp_log(MAC, LOG_TRACE,0X07F); - set_comp_log(EMU, LOG_TRACE,0X07F); - - LOG_ENTER(MAC); - LOG_I(LOG, "6 Starting OAI logs version %s Build date: %s on %s\n", - BUILD_VERSION, BUILD_DATE, BUILD_HOST); - LOG_D(MAC, "6 debug MAC \n"); - LOG_N(MAC, "6 notice MAC \n"); - LOG_W(MAC, "6 warning MAC \n"); - LOG_I(MAC, "6 info MAC \n"); - LOG_EXIT(MAC); - - return 0; -} -#endif diff --git a/openair3/NAS/COMMON/UTIL/nas_timer.c b/openair3/NAS/COMMON/UTIL/nas_timer.c index 7ddcb61d1d..9ccca12520 100644 --- a/openair3/NAS/COMMON/UTIL/nas_timer.c +++ b/openair3/NAS/COMMON/UTIL/nas_timer.c @@ -43,13 +43,7 @@ Description Timer utilities #include // memset #include // malloc, free #include // setitimer - -#if defined(ENABLE_ITTI) -# include "intertask_interface.h" -#else -# include -# include // clock_gettime -#endif +#include "intertask_interface.h" #include "nas_timer.h" #include "commonDef.h" #include "msc.h" @@ -69,11 +63,7 @@ Description Timer utilities * value when the timer entry was allocated. */ typedef struct { -#if defined(ENABLE_ITTI) - long timer_id; /* Timer id returned by the timer API from ITTI */ -#else - pthread_t pid; /* Thread identifier of the callback */ -#endif +long timer_id; /* Timer id returned by the timer API from ITTI */ struct timeval itv; /* Initial interval timer value */ struct timeval tv; /* Interval timer value */ @@ -105,10 +95,6 @@ typedef struct { #define TIMER_DATABASE_SIZE 256 timer_queue_t tq[TIMER_DATABASE_SIZE]; timer_queue_t *head;/* Pointer to the first timer entry to be fired */ - -#if !defined(ENABLE_ITTI) - pthread_mutex_t mutex; -#endif } nas_timer_database_t; /* @@ -118,25 +104,15 @@ static nas_timer_database_t _nas_timer_db = { 0, {}, NULL -#if !defined(ENABLE_ITTI) - , PTHREAD_MUTEX_INITIALIZER -#endif }; -#if defined(ENABLE_ITTI) #define nas_timer_lock_db() #define nas_timer_unlock_db() -#else -#define nas_timer_lock_db() pthread_mutex_lock(&_nas_timer_db.mutex) -#define nas_timer_unlock_db() pthread_mutex_unlock(&_nas_timer_db.mutex) -#endif /* * The handler executed whenever the system timer expires */ -#if !defined(ENABLE_ITTI) -static void _nas_timer_handler(int signal); -#endif + /* * ----------------------------------------------------------------------------- @@ -191,33 +167,6 @@ int nas_timer_init(void) /* Initialize the timer database */ _nas_timer_db_init(); -#if !defined(ENABLE_ITTI) - /* Setup the timer database handler */ - struct sigaction act; - - (void) memset (&act, 0, sizeof (act)); - (void) sigfillset (&act.sa_mask); - (void) sigdelset (&act.sa_mask, SIGHUP); - (void) sigdelset (&act.sa_mask, SIGINT); - (void) sigdelset (&act.sa_mask, SIGTERM); - (void) sigdelset (&act.sa_mask, SIGILL); - (void) sigdelset (&act.sa_mask, SIGTRAP); - (void) sigdelset (&act.sa_mask, SIGIOT); -# ifndef LINUX - (void) sigdelset (&act.sa_mask, SIGEMT); -# endif - (void) sigdelset (&act.sa_mask, SIGFPE); - (void) sigdelset (&act.sa_mask, SIGBUS); - (void) sigdelset (&act.sa_mask, SIGSEGV); - (void) sigdelset (&act.sa_mask, SIGSYS); - - act.sa_handler = _nas_timer_handler; - - if ( sigaction (SIGALRM, &act, 0) < 0 ) { - return (RETURNerror); - } - -#endif return (RETURNok); } @@ -243,10 +192,8 @@ int nas_timer_start(long sec, nas_timer_callback_t cb, void *args) { int id; nas_timer_entry_t *te; -#if defined(ENABLE_ITTI) int ret; long timer_id; -#endif /* Do not start null timer */ if (sec == 0) { @@ -270,7 +217,6 @@ int nas_timer_start(long sec, nas_timer_callback_t cb, void *args) /* Insert the new entry into the timer queue */ _nas_timer_db_insert_entry(id, te); -#if defined(ENABLE_ITTI) # if defined(NAS_MME) ret = timer_setup(sec, 0, TASK_NAS_MME, INSTANCE_DEFAULT, TIMER_PERIODIC, args, &timer_id); # else @@ -280,10 +226,7 @@ int nas_timer_start(long sec, nas_timer_callback_t cb, void *args) if (ret == -1) { return NAS_TIMER_INACTIVE_ID; } - te->timer_id = timer_id; -#endif - return (id); } @@ -309,11 +252,7 @@ int nas_timer_stop(int id) nas_timer_entry_t *entry; /* Remove the entry from the timer queue */ entry = _nas_timer_db_remove_entry(id); -#if defined(ENABLE_ITTI) timer_remove(entry->timer_id); -#else - (void)entry; -#endif /* Delete the timer entry */ _nas_timer_db_delete_entry(id); return (NAS_TIMER_INACTIVE_ID); @@ -380,7 +319,7 @@ int nas_timer_restart(int id) ** Others: _nas_timer_db ** ** ** ***************************************************************************/ -#if defined(ENABLE_ITTI) + void nas_timer_handle_signal_expiry(long timer_id, void *arg_p) { /* Get the timer entry for which the system timer expired */ @@ -388,25 +327,7 @@ void nas_timer_handle_signal_expiry(long timer_id, void *arg_p) te->cb(te->args); } -#else -static void _nas_timer_handler(int signal) -{ - /* At least one timer has been started */ - assert( (_nas_timer_db.head != NULL) && (_nas_timer_db.head->entry != NULL) ); - /* Get the timer entry for which the system timer expired */ - nas_timer_entry_t *te = _nas_timer_db.head->entry; - - threadCreate (&te->pid, te->cb, te->args, "nas-timer", -1, OAI_PRIORITY_RT_LOW); - - void *result = NULL; - (void) pthread_join(te->pid, &result); - - if (result) { - free(result); - } -} -#endif /* * ----------------------------------------------------------------------------- @@ -605,17 +526,7 @@ static void _nas_timer_db_insert_entry(int id, nas_timer_entry_t *te) restart = _nas_timer_db_insert(&_nas_timer_db.tq[id]); nas_timer_unlock_db(); -#if !defined(ENABLE_ITTI) - - if (restart) { - /* The new entry is the first entry of the list; - * restart the system timer */ - setitimer(ITIMER_REAL, &it, 0); - } - -#else (void)(restart); -#endif } static int _nas_timer_db_insert(timer_queue_t *entry) @@ -704,21 +615,8 @@ static nas_timer_entry_t *_nas_timer_db_remove_entry(int id) tv.tv_usec = ts.tv_nsec/1000; /* tv = tv - time() */ rc = _nas_timer_sub(&_nas_timer_db.head->entry->tv, &tv, &it.it_value); - -#if defined(ENABLE_ITTI) timer_remove(_nas_timer_db.head->entry->timer_id); (void) (rc); -#else - - if (rc < 0) { - /* The system timer should have already expired */ - _nas_timer_handler(SIGALRM); - } else { - /* Restart the system timer */ - setitimer(ITIMER_REAL, &it, 0); - } - -#endif } /* Return a pointer to the removed entry */ @@ -749,17 +647,6 @@ static int _nas_timer_db_remove(timer_queue_t *entry) /* Other timers are scheduled to expire */ return TRUE; } - -#if !defined(ENABLE_ITTI) - { - /* No more timer is scheduled to expire; stop the system timer */ - struct itimerval it; - it.it_interval.tv_sec = it.it_interval.tv_usec = 0; - it.it_value.tv_sec = it.it_value.tv_usec = 0; - setitimer(ITIMER_REAL, &it, 0); - return FALSE; - } -#endif } /* The entry was NOT the first entry of the list */ diff --git a/openair3/NAS/UE/ESM/PdnConnectivity.c b/openair3/NAS/UE/ESM/PdnConnectivity.c index 48730f2ca9..3b5bad7529 100644 --- a/openair3/NAS/UE/ESM/PdnConnectivity.c +++ b/openair3/NAS/UE/ESM/PdnConnectivity.c @@ -61,9 +61,7 @@ Description Defines the PDN connectivity ESM procedure executed by the #include "emm_sap.h" -#if defined(ENABLE_ITTI) # include "assertions.h" -#endif /****************************************************************************/ /**************** E X T E R N A L D E F I N I T I O N S ****************/ diff --git a/openair3/NAS/UE/nas_ue_task.c b/openair3/NAS/UE/nas_ue_task.c index 6df6666638..d712a7b7f0 100644 --- a/openair3/NAS/UE/nas_ue_task.c +++ b/openair3/NAS/UE/nas_ue_task.c @@ -20,7 +20,6 @@ */ #include "utils.h" -#if defined(ENABLE_ITTI) # include "assertions.h" # include "intertask_interface.h" # include "nas_ue_task.h" @@ -301,4 +300,3 @@ char *make_port_str_from_ueid(const char *base_port_str, int ueid) { return itoa(port); } -#endif diff --git a/openair3/NAS/UE/nas_ue_task.h b/openair3/NAS/UE/nas_ue_task.h index c9890719cb..5615f366b7 100644 --- a/openair3/NAS/UE/nas_ue_task.h +++ b/openair3/NAS/UE/nas_ue_task.h @@ -33,8 +33,6 @@ typedef struct { nas_user_t *find_user_from_fd(nas_user_container_t *users, int fd); -# if defined(ENABLE_ITTI) void *nas_ue_task(void *args_p); -# endif #endif /* NAS_TASK_H_ */ diff --git a/targets/ARCH/COMMON/common_lib.c b/targets/ARCH/COMMON/common_lib.c index 16b86cfd64..757ad6f75d 100644 --- a/targets/ARCH/COMMON/common_lib.c +++ b/targets/ARCH/COMMON/common_lib.c @@ -41,49 +41,22 @@ #include "common/utils/LOG/log.h" #include "targets/RT/USER/lte-softmodem.h" +char *get_devname(int devtype) { +char *devnames[MAX_RF_DEV_TYPE]=DEVTYPE_NAMES; + if (devtype < MAX_RF_DEV_TYPE && devtype !=MIN_RF_DEV_TYPE ) + return devnames[devtype]; + return "none"; +} + int set_device(openair0_device *device) { - switch (device->type) { - case EXMIMO_DEV: - LOG_I(HW,"[%s] has loaded EXPRESS MIMO device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case USRP_B200_DEV: - LOG_I(HW,"[%s] has loaded USRP B200 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case USRP_X300_DEV: - LOG_I(HW,"[%s] has loaded USRP X300 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case BLADERF_DEV: - LOG_I(HW,"[%s] has loaded BLADERF device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case LMSSDR_DEV: - LOG_I(HW,"[%s] has loaded LMSSDR device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case IRIS_DEV: - LOG_I(HW,"[%s] has loaded Iris device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case ADRV9371_ZC706_DEV: - LOG_I(HW,"[%s] has loaded ADRV9371_ZC706 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case UEDv2_DEV: - LOG_I(HW,"[%s] has loaded UEDv2 device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - case NONE_DEV: - LOG_I(HW,"[%s] has not loaded a HW device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); - break; - - default: + char *devname = get_devname(device->type); + if (strcmp(devname,"none") != 0) { + LOG_I(HW,"[%s] has loaded %s device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU"),devname); + } else { LOG_E(HW,"[%s] invalid HW device.\n",((device->host_type == RAU_HOST) ? "RAU": "RRU")); return -1; - } + } return 0; } @@ -108,7 +81,7 @@ int set_transport(openair0_device *device) } typedef int(*devfunc_t)(openair0_device *, openair0_config_t *, eth_params_t *); -//loader_shlibfunc_t shlib_fdesc[2]; + /* look for the interface library and load it */ int load_lib(openair0_device *device, @@ -119,7 +92,14 @@ int load_lib(openair0_device *device, loader_shlibfunc_t shlib_fdesc[1]; int ret=0; char *libname; - if ( IS_SOFTMODEM_BASICSIM ) { + + openair0_cfg->recplay_mode = read_recplayconfig(&(openair0_cfg->recplay_conf),&(device->recplay_state)); + + if ( openair0_cfg->recplay_mode == RECPLAY_REPLAYMODE ) { + libname=OAI_IQPLAYER_LIBNAME; + shlib_fdesc[0].fname="device_init"; + set_softmodem_optmask(SOFTMODEM_RECPLAY_BIT); // softmodem has to know we use the iqplayer to workaround randomized algorithms + } else if ( IS_SOFTMODEM_BASICSIM ) { libname=OAI_BASICSIM_LIBNAME; shlib_fdesc[0].fname="device_init"; } else if (IS_SOFTMODEM_RFSIM && flag == RAU_LOCAL_RADIO_HEAD) { diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h index 03ab4da5f9..7e51bdc81a 100644 --- a/targets/ARCH/COMMON/common_lib.h +++ b/targets/ARCH/COMMON/common_lib.h @@ -35,15 +35,19 @@ #include #include #include +#include "record_player.h" -/* name of shared library implementing the radio front end */ +/* default name of shared library implementing the radio front end */ #define OAI_RF_LIBNAME "oai_device" /* name of shared library implementing the transport */ #define OAI_TP_LIBNAME "oai_transpro" -/* name of shared library implementing the basic/rf simulator */ +/* name of shared library implementing the rf simulator */ #define OAI_RFSIM_LIBNAME "rfsimulator" -/* name of shared library implementing the basic/rf simulator */ +/* name of shared library implementing the basic simulator */ #define OAI_BASICSIM_LIBNAME "tcp_bridge_oai" +/* name of shared library implementing the iq player */ +#define OAI_IQPLAYER_LIBNAME "oai_iqplayer" + /* flags for BBU to determine whether the attached radio head is local or remote */ #define RAU_LOCAL_RADIO_HEAD 0 #define RAU_REMOTE_RADIO_HEAD 1 @@ -101,7 +105,7 @@ typedef enum { UEDv2_DEV, MAX_RF_DEV_TYPE } dev_type_t; - +#define DEVTYPE_NAMES {"","EXMIMO","USRP B200","USRP X300","BLADERF","LMSSDR","IRIS","No HW","ADRV9371_ZC706","UEDv2"} /*!\brief transport protocol types */ typedef enum { @@ -145,6 +149,7 @@ typedef enum { gpsdo=2 } clock_source_t; + /*! \brief RF frontend parameters set by application */ typedef struct { //! Module ID for this configuration @@ -219,15 +224,9 @@ typedef struct { char *my_addr; //! local port number for Ethernet interface (eNB/BBU, UE) unsigned int my_port; -#if defined(USRP_REC_PLAY) - unsigned short sf_mode; // 1=record, 2=replay - char sf_filename[1024]; // subframes file path - unsigned int sf_max; // max number of recorded subframes - unsigned int sf_loops; // number of loops in replay mode - unsigned int sf_read_delay; // read delay in replay mode - unsigned int sf_write_delay; // write delay in replay mode - unsigned int eth_mtu; // ethernet MTU -#endif + //! record player configuration, definition in record_player.h + uint32_t recplay_mode; + recplay_conf_t *recplay_conf; //! number of samples per tti unsigned int samples_per_tti; //! the sample rate for receive. @@ -298,7 +297,8 @@ struct openair0_device_t { /* !brief ETH params set by application */ eth_params_t *eth_params; - + //! record player data, definition in record_player.h + recplay_state_t *recplay_state; /* !brief Indicates if device already initialized */ int is_init; @@ -443,11 +443,13 @@ typedef struct { #define OPTION_LZ4 0x00000001 // LZ4 compression (option_value is set to compressed size) + #ifdef __cplusplus extern "C" { #endif - +/*! \brief get device name from device type */ +char *get_devname(int devtype); /*! \brief Initialize openair RF target. It returns 0 if OK */ int openair0_device_load(openair0_device *device, openair0_config_t *openair0_cfg); /*! \brief Initialize transport protocol . It returns 0 if OK */ @@ -465,6 +467,11 @@ openair0_timestamp get_usrp_time(openair0_device *device); * \returns 0 in success */ int openair0_set_rx_frequencies(openair0_device *device, openair0_config_t *openair0_cfg); +/*! \brief read the iq record/player configuration */ +extern int read_recplayconfig(recplay_conf_t **recplay_conf, recplay_state_t **recplay_state); +/*! \brief store recorded iqs from memory to file. */ +extern void iqrecorder_end(openair0_device *device); + #define gettid() syscall(__NR_gettid) /*@}*/ diff --git a/targets/ARCH/COMMON/record_player.c b/targets/ARCH/COMMON/record_player.c new file mode 100644 index 0000000000..2dcd61e479 --- /dev/null +++ b/targets/ARCH/COMMON/record_player.c @@ -0,0 +1,115 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/** record_player.c + * + * \author: Nokia bellLabs B. Mongazon F. Taburet + * + */ + +#include +#include +#include +#include +#include +#include "common/utils/LOG/log.h" +#include "assertions.h" +#include "common_lib.h" +#include "record_player.h" + +/*! \brief read the oai recorder or player configuration, called from common device code + * \param recplay_conf: store parameters + * recplay_state: store recorder or player data while the device runs + */ +int read_recplayconfig(recplay_conf_t **recplay_conf, recplay_state_t **recplay_state) { + unsigned int u_sf_record = 0; // record mode + unsigned int u_sf_replay = 0; // replay mode + *recplay_conf = calloc(sizeof(recplay_conf_t),1); + paramdef_t device_recplay_params[]=DEVICE_RECPLAY_PARAMS_DESC ; + config_get(device_recplay_params,sizeof(device_recplay_params)/sizeof(paramdef_t),DEVICE_RECPLAY_SECTION); + + if (u_sf_record || u_sf_replay ) { + struct sysinfo systeminfo; + *recplay_state = calloc(sizeof(recplay_state_t),1); + + if ( *recplay_state == NULL) { + LOG_E(HW,"calloc error in %s\n", __FILE__); + return -1; + } + + // Use mmap for IQ files for systems with less than 6GB total RAM + sysinfo(&systeminfo); + + if (systeminfo.totalram < 6144000000) { + (*recplay_state)->use_mmap = 0; + } else { + (*recplay_state)->use_mmap = 1; + } + } else { /* record player enabled */ + free(*recplay_conf); + *recplay_conf=NULL; + } + + if (u_sf_replay == 1) return RECPLAY_REPLAYMODE; + else if (u_sf_record == 1) return RECPLAY_RECORDMODE; + + return 0; +} + +/*! \brief Terminate operation of the oai iq recorder. to be called by any device + * used in record mode + * \param device, the hardware used + */ +void iqrecorder_end(openair0_device *device) { + if (device->recplay_state != NULL) { // subframes store + iqfile_header_t fh = {device->type,device->openair0_cfg->tx_sample_advance, device->openair0_cfg->rx_bw,OAIIQFILE_ID}; + recplay_state_t *rs = device->recplay_state; + recplay_conf_t *rc = device->openair0_cfg[0].recplay_conf; + rs->pFile = fopen (rc->u_sf_filename,"wb+"); + + if (rs->pFile == NULL) { + LOG_E(HW,"Cannot open %s\n", rc->u_sf_filename); + } else { + unsigned int i = 0; + unsigned int modu = 0; + + if ((modu = rs->nb_samples % 10) != 0) { + rs->nb_samples -= modu; // store entire number of frames + } + + LOG_I(HW,"Writing file header to %s \n", rc->u_sf_filename ); + fwrite(&fh, sizeof(fh), 1, rs->pFile); + LOG_UI(HW,"Writing %u subframes to %s \n",rs->nb_samples, rc->u_sf_filename ); + + for (i = 0; i < rs->nb_samples; i++) { + fwrite(rs->ms_sample+i, sizeof(unsigned char), sizeof(iqrec_t), rs->pFile); + } + + fclose (rs->pFile); + LOG_UI(HW,"File %s closed\n",rc->u_sf_filename ); + } + + if (rs->ms_sample != NULL) { + free((void *)rs->ms_sample); + rs->ms_sample = NULL; + } + } +} \ No newline at end of file diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.h b/targets/ARCH/COMMON/record_player.h similarity index 81% rename from targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.h rename to targets/ARCH/COMMON/record_player.h index d29cf41db2..903dda006b 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.h +++ b/targets/ARCH/COMMON/record_player.h @@ -1,5 +1,5 @@ -#ifndef __USRP_LIB_H -#define __USRP_LIB_H +#ifndef __RECORD_PLAYER_H +#define __RECORD_PLAYER_H /* * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more * contributor license agreements. See the NOTICE file distributed with @@ -21,7 +21,7 @@ * contact@openairinterface.org */ -/** usrp_lib.h +/** targets/ARCH/COMMON/record-player.h * * \author: bruno.mongazon-cazavet@nokia-bell-labs.com */ @@ -46,7 +46,7 @@ extern "C" /* command line parameters for USRP record/playback */ /* optname helpstr paramflags XXXptr defXXXval type numelt */ /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define USRP_DEVICE_PARAMS_DESC { \ +#define DEVICE_PARAMS_DESC { \ {CONFIG_OPT_RECPLAY, CONFIG_HLP_RECPLAY, PARAMFLAG_BOOL, uptr:&enable_recplay, defuintval:0, TYPE_UINT, 0} \ } @@ -59,6 +59,15 @@ extern "C" #define BELL_LABS_IQ_HEADER 0xabababababababab #define BELL_LABS_IQ_PER_SF 7680 // Up to 5MHz bw for now #define BELL_LABS_IQ_BYTES_PER_SF (BELL_LABS_IQ_PER_SF * 4) + +#define OAIIQFILE_ID "OIQF" +typedef struct { + uint64_t devtype; + uint64_t tx_sample_advance; + double bw; + char oaiid[4]; +} iqfile_header_t; + typedef struct { int64_t header; int64_t ts; @@ -75,8 +84,8 @@ typedef struct { /* help strings definition for config options, used in CMDLINE_XXX_DESC macros and printed when -h option is used */ #define CONFIG_HLP_SF_FILE "Path of the file used for subframes record or replay" -#define CONFIG_HLP_SF_REC "Record subframes from USRP driver into a file for later replay" -#define CONFIG_HLP_SF_REP "Replay subframes into USRP driver from a file" +#define CONFIG_HLP_SF_REC "Record subframes from device driver into a file for later replay" +#define CONFIG_HLP_SF_REP "Replay subframes from a file using the oai replay driver" #define CONFIG_HLP_SF_MAX "Maximum count of subframes to be recorded in subframe file" #define CONFIG_HLP_SF_LOOPS "Number of loops to replay of the entire subframes file" #define CONFIG_HLP_SF_RDELAY "Delay in microseconds to read a subframe in replay mode" @@ -91,41 +100,43 @@ typedef struct { #define CONFIG_OPT_SF_RDELAY "subframes-read-delay" #define CONFIG_OPT_SF_WDELAY "subframes-write-delay" -#define USRP_RECPLAY_SECTION "device.recplay" +#define DEVICE_RECPLAY_SECTION "device.recplay" /* For information only - the macro is not usable in C++ */ /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ /* command line parameters for USRP record/playback */ -/* optname helpstr paramflags XXXptr defXXXval type numelt */ +/* optname helpstr paramflags XXXptr defXXXval type numelt */ /*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/ -#define USRP_RECPLAY_PARAMS_DESC { \ - {CONFIG_OPT_SF_FILE, CONFIG_HLP_SF_FILE, 0, strptr:(char **)((*recplay_state)->u_sf_filename), defstrval:DEF_SF_FILE, TYPE_STRING, 1024}, \ - {CONFIG_OPT_SF_REC, CONFIG_HLP_SF_REC, PARAMFLAG_BOOL, uptr:&(u_sf_record), defuintval:0, TYPE_UINT, 0}, \ - {CONFIG_OPT_SF_REP, CONFIG_HLP_SF_REP, PARAMFLAG_BOOL, uptr:&(u_sf_replay), defuintval:0, TYPE_UINT, 0}, \ - {CONFIG_OPT_SF_MAX, CONFIG_HLP_SF_MAX, 0, uptr:&((*recplay_state)->u_sf_max), defintval:DEF_NB_SF, TYPE_UINT, 0}, \ - {CONFIG_OPT_SF_LOOPS, CONFIG_HLP_SF_LOOPS, 0, uptr:&((*recplay_state)->u_sf_loops), defintval:DEF_SF_NB_LOOP, TYPE_UINT, 0}, \ - {CONFIG_OPT_SF_RDELAY, CONFIG_HLP_SF_RDELAY, 0, uptr:&((*recplay_state)->u_sf_read_delay), defintval:DEF_SF_DELAY_READ, TYPE_UINT, 0}, \ - {CONFIG_OPT_SF_WDELAY, CONFIG_HLP_SF_WDELAY, 0, uptr:&((*recplay_state)->u_sf_write_delay), defintval:DEF_SF_DELAY_WRITE, TYPE_UINT, 0}, \ +#define DEVICE_RECPLAY_PARAMS_DESC { \ + {CONFIG_OPT_SF_FILE, CONFIG_HLP_SF_FILE, 0, strptr:(char **)((*recplay_conf)->u_sf_filename), defstrval:DEF_SF_FILE, TYPE_STRING, 1024}, \ + {CONFIG_OPT_SF_REC, CONFIG_HLP_SF_REC, PARAMFLAG_BOOL, uptr:&(u_sf_record), defuintval:0, TYPE_UINT, 0}, \ + {CONFIG_OPT_SF_REP, CONFIG_HLP_SF_REP, PARAMFLAG_BOOL, uptr:&(u_sf_replay), defuintval:0, TYPE_UINT, 0}, \ + {CONFIG_OPT_SF_MAX, CONFIG_HLP_SF_MAX, 0, uptr:&((*recplay_conf)->u_sf_max), defintval:DEF_NB_SF, TYPE_UINT, 0}, \ + {CONFIG_OPT_SF_LOOPS, CONFIG_HLP_SF_LOOPS, 0, uptr:&((*recplay_conf)->u_sf_loops), defintval:DEF_SF_NB_LOOP, TYPE_UINT, 0}, \ + {CONFIG_OPT_SF_RDELAY, CONFIG_HLP_SF_RDELAY, 0, uptr:&((*recplay_conf)->u_sf_read_delay), defintval:DEF_SF_DELAY_READ, TYPE_UINT, 0}, \ + {CONFIG_OPT_SF_WDELAY, CONFIG_HLP_SF_WDELAY, 0, uptr:&((*recplay_conf)->u_sf_write_delay), defintval:DEF_SF_DELAY_WRITE, TYPE_UINT, 0}, \ }/*! \brief USRP Configuration and state */ - typedef struct { - FILE *pFile; - int mmapfd; - int iqfd; - int use_mmap; // default is to use mmap - size_t mapsize; - iqrec_t *ms_sample; // memory for all subframes - unsigned int nb_samples; char u_sf_filename[1024]; // subframes file path unsigned int u_sf_max ; // max number of recorded subframes unsigned int u_sf_loops ; // number of loops in replay mode unsigned int u_sf_read_delay; // read delay in replay mode unsigned int u_sf_write_delay ; // write delay in replay mode +} recplay_conf_t; + +typedef struct { + int use_mmap; // default is to use mmap + size_t mapsize; + FILE *pFile; + int mmapfd; + int iqfd; + iqrec_t *ms_sample; // memory for all subframes + unsigned int nb_samples; } recplay_state_t; -extern int read_usrpconfig(uint32_t *recplay_mode, recplay_state_t **recplay_state); + #ifdef __cplusplus } #endif -#endif // __USRP_LIB_H +#endif // __RECORD_PLAYER_H diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp index eb8c6ec010..5135be0cd4 100644 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp +++ b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib.cpp @@ -23,7 +23,8 @@ * * \author: HongliangXU : hong-liang-xu@agilent.com */ - +#define _LARGEFILE_SOURCE +#define _FILE_OFFSET_BITS 64 #include #include #include @@ -51,8 +52,6 @@ #include -#include "usrp_lib.h" - #ifdef __SSE4_1__ #include #endif @@ -108,8 +107,6 @@ typedef struct { int first_tx; //! timestamp of RX packet openair0_timestamp rx_timestamp; - uint32_t recplay_mode; - recplay_state_t *recplay_state; } usrp_state_t; //void print_notes(void) @@ -271,9 +268,6 @@ static int sync_to_gps(openair0_device *device) { static int trx_usrp_start(openair0_device *device) { usrp_state_t *s = (usrp_state_t *)device->priv; - if ( s->recplay_mode == RECPLAY_REPLAYMODE) - return 0; - // setup GPIO for TDD, GPIO(4) = ATR_RX //set data direction register (DDR) to output s->usrp->set_gpio_attr("FP0", "DDR", 0x7f, 0x7f); @@ -316,86 +310,14 @@ static void trx_usrp_end(openair0_device *device) { return; usrp_state_t *s = (usrp_state_t *)device->priv; - + if (s == NULL) return; + iqrecorder_end(device); - if (s->recplay_mode != RECPLAY_REPLAYMODE) { // not subframes replay - s->rx_stream->issue_stream_cmd(uhd::stream_cmd_t::STREAM_MODE_STOP_CONTINUOUS); - //send a mini EOB packet - s->tx_md.end_of_burst = true; - s->tx_stream->send("", 0, s->tx_md); - s->tx_md.end_of_burst = false; - sleep(1); - } - if (s->recplay_mode == RECPLAY_RECORDMODE) { // subframes store - s->recplay_state->pFile = fopen (s->recplay_state->u_sf_filename,"wb+"); - - if (s->recplay_state->pFile == NULL) { - std::cerr << "Cannot open " << s->recplay_state->u_sf_filename << std::endl; - } else { - unsigned int i = 0; - unsigned int modu = 0; - - if ((modu = s->recplay_state->nb_samples % 10) != 0) { - s->recplay_state->nb_samples -= modu; // store entire number of frames - } - - std::cerr << "Writing " << s->recplay_state->nb_samples << " subframes to " << s->recplay_state->u_sf_filename << " ..." << std::endl; - - for (i = 0; i < s->recplay_state->nb_samples; i++) { - fwrite(s->recplay_state->ms_sample+i, sizeof(unsigned char), sizeof(iqrec_t), s->recplay_state->pFile); - } - - fclose (s->recplay_state->pFile); - std::cerr << "File " << s->recplay_state->u_sf_filename << " closed." << std::endl; - } - - if (s->recplay_state->ms_sample != NULL) { - free((void *)s->recplay_state->ms_sample); - s->recplay_state->ms_sample = NULL; - } - } else if (s->recplay_mode == RECPLAY_REPLAYMODE) { // replay - if (s->recplay_state->use_mmap) { - if (s->recplay_state->ms_sample != MAP_FAILED) { - munmap(s->recplay_state->ms_sample, s->recplay_state->mapsize); - s->recplay_state->ms_sample = NULL; - } - - if (s->recplay_state->mmapfd != 0) { - close(s->recplay_state->mmapfd); - s->recplay_state->mmapfd = 0; - } - } else { - if (s->recplay_state->ms_sample != NULL) { - free(s->recplay_state->ms_sample); - s->recplay_state->ms_sample = NULL; - } - - if (s->recplay_state->iqfd != 0) { - close(s->recplay_state->iqfd); - s->recplay_state->iqfd = 0; - } - } - } -} -/*! \brief Write iqs function when in replay mode, just introduce a delay, as configured at init time, - @param device pointer to the device structure specific to the RF hardware target - @param timestamp The timestamp at which the first sample MUST be sent - @param buff Buffer which holds the samples - @param nsamps number of samples to be sent - @param antenna_id index of the antenna if the device has multiple antennas - @param flags flags must be set to TRUE if timestamp parameter needs to be applied -*/ -static int trx_usrp_write_recplay(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags) { - struct timespec req; - usrp_state_t *s = (usrp_state_t *)device->priv; - req.tv_sec = 0; - req.tv_nsec = s->recplay_state->u_sf_write_delay * 1000; - nanosleep(&req, NULL); - return nsamps; } + /*! \brief Called to send samples to the USRP RF target @param device pointer to the device structure specific to the RF hardware target @param timestamp The timestamp at which the first sample MUST be sent @@ -488,106 +410,6 @@ static int trx_usrp_write(openair0_device *device, openair0_timestamp timestamp, return ret; } -/*! \brief Receive samples from iq file. - * Read \ref nsamps samples from each channel to buffers. buff[0] is the array for - * the first channel. *ptimestamp is the time at which the first sample - * was received. - * \param device the hardware to use - * \param[out] ptimestamp the time at which the first sample was received. - * \param[out] buff An array of pointers to buffers for received samples. The buffers must be large enough to hold the number of samples \ref nsamps. - * \param nsamps Number of samples. One sample is 2 byte I + 2 byte Q => 4 byte. - * \param antenna_id Index of antenna for which to receive samples - * \returns the number of sample read -*/ -static int trx_usrp_read_recplay(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) { - int samples_received=0; - static unsigned int cur_samples; - static int64_t wrap_count; - static int64_t wrap_ts; - usrp_state_t *s = (usrp_state_t *)device->priv; - - - if (cur_samples == s->recplay_state->nb_samples) { - cur_samples = 0; - wrap_count++; - if (wrap_count == s->recplay_state->u_sf_loops) { - std::cerr << "USRP device terminating subframes replay mode after " << s->recplay_state->u_sf_loops << " loops." << std::endl; - exit_function(__FILE__, __FUNCTION__, __LINE__,"replay ended, triggering process termination\n"); - } - - wrap_ts = wrap_count * (s->recplay_state->nb_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000)); - - if (!s->recplay_state->use_mmap) { - if (lseek(s->recplay_state->iqfd, 0, SEEK_SET) == 0) { - std::cerr << "Seeking at the beginning of IQ file" << std::endl; - } else { - std::cerr << "Problem seeking at the beginning of IQ file" << std::endl; - } - } - } - - if (s->recplay_state->use_mmap) { - if (cur_samples < s->recplay_state->nb_samples) { - *ptimestamp = (s->recplay_state->ms_sample[0].ts + (cur_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000))) + wrap_ts; - - if (cur_samples == 0) { - std::cerr << "starting subframes file with wrap_count=" << wrap_count << " wrap_ts=" << wrap_ts - << " ts=" << *ptimestamp << std::endl; - } - - memcpy(buff[0], &s->recplay_state->ms_sample[cur_samples].samples[0], nsamps*4); - cur_samples++; - } - } else { - // read sample from file - if (read(s->recplay_state->iqfd, s->recplay_state->ms_sample, sizeof(iqrec_t)) != sizeof(iqrec_t)) { - std::cerr << "pb reading iqfile at index " << sizeof(iqrec_t)*cur_samples << std::endl; - close(s->recplay_state->iqfd); - free(s->recplay_state->ms_sample); - s->recplay_state->ms_sample = NULL; - s->recplay_state->iqfd = 0; - exit(-1); - } - - if (cur_samples < s->recplay_state->nb_samples) { - static int64_t ts0 = 0; - - if ((cur_samples == 0) && (wrap_count == 0)) { - ts0 = s->recplay_state->ms_sample->ts; - } - - *ptimestamp = ts0 + (cur_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000)) + wrap_ts; - - if (cur_samples == 0) { - std::cerr << "starting subframes file with wrap_count=" << wrap_count << " wrap_ts=" << wrap_ts - << " ts=" << *ptimestamp << std::endl; - } - - memcpy(buff[0], &s->recplay_state->ms_sample->samples[0], nsamps*4); - cur_samples++; - // Prepare for next read - off_t where = lseek(s->recplay_state->iqfd, cur_samples * sizeof(iqrec_t), SEEK_SET); - - if (where < 0) { - LOG_E(HW,"Cannot lseek in iqfile: %s\n",strerror(errno)); - } - } - } - - struct timespec req; - - req.tv_sec = 0; - - req.tv_nsec = s->recplay_state->u_sf_read_delay * 1000; - - nanosleep(&req, NULL); - - return nsamps; - - return samples_received; -} - - /*! \brief Receive samples from hardware. * Read \ref nsamps samples from each channel to buffers. buff[0] is the array for * the first channel. *ptimestamp is the time at which the first sample @@ -689,13 +511,13 @@ static int trx_usrp_read(openair0_device *device, openair0_timestamp *ptimestamp s->rx_timestamp = s->rx_md.time_spec.to_ticks(s->sample_rate); *ptimestamp = s->rx_timestamp; - if (s->recplay_mode == RECPLAY_RECORDMODE) { // record mode + if (device->recplay_state != NULL) { // record mode // Copy subframes to memory (later dump on a file) - if (s->recplay_state->nb_samples < s->recplay_state->u_sf_max) { - (s->recplay_state->ms_sample+s->recplay_state->nb_samples)->header = BELL_LABS_IQ_HEADER; - (s->recplay_state->ms_sample+s->recplay_state->nb_samples)->ts = *ptimestamp; - memcpy((s->recplay_state->ms_sample+s->recplay_state->nb_samples)->samples, buff[0], nsamps*4); - s->recplay_state->nb_samples++; + if (device->recplay_state->nb_samples < device->openair0_cfg->recplay_conf->u_sf_max) { + (device->recplay_state->ms_sample+device->recplay_state->nb_samples)->header = BELL_LABS_IQ_HEADER; + (device->recplay_state->ms_sample+device->recplay_state->nb_samples)->ts = *ptimestamp; + memcpy((device->recplay_state->ms_sample+device->recplay_state->nb_samples)->samples, buff[0], nsamps*4); + device->recplay_state->nb_samples++; } else exit_function(__FILE__, __FUNCTION__, __LINE__,"Recording reaches max iq limit\n"); } @@ -909,7 +731,6 @@ extern "C" { } device->openair0_cfg = openair0_cfg; - read_usrpconfig(&(s->recplay_mode), &(s->recplay_state)); device->trx_start_func = trx_usrp_start; device->trx_get_stats_func = trx_usrp_get_stats; device->trx_reset_stats_func = trx_usrp_reset_stats; @@ -918,90 +739,74 @@ extern "C" { device->trx_set_freq_func = trx_usrp_set_freq; device->trx_set_gains_func = trx_usrp_set_gains; - if ( s->recplay_mode == RECPLAY_REPLAYMODE) { - // Replay subframes from from file - int bw_gain_adjust=0; - device->type = USRP_B200_DEV; - openair0_cfg[0].rx_gain_calib_table = calib_table_b210_38; - bw_gain_adjust=1; - openair0_cfg[0].tx_sample_advance = 80; - openair0_cfg[0].tx_bw = 20e6; - openair0_cfg[0].rx_bw = 20e6; - openair0_cfg[0].iq_txshift = 4;//shift - openair0_cfg[0].iq_rxrescale = 15;//rescale iqs - set_rx_gain_offset(&openair0_cfg[0],0,bw_gain_adjust); - device->trx_write_func = trx_usrp_write_recplay; - device->trx_read_func = trx_usrp_read_recplay; - std::cerr << "USRP device initialized in subframes replay mode for " << s->recplay_state->u_sf_loops << " loops. Use mmap=" - << s->recplay_state->use_mmap << std::endl; + + // hotfix! to be checked later + uhd::set_thread_priority_safe(1.0); + // Initialize USRP device + int vers=0,subvers=0,subsubvers=0; + int bw_gain_adjust=0; + + if (device->openair0_cfg->recplay_mode == RECPLAY_RECORDMODE) { + std::cerr << "USRP device initialized in subframes record mode" << std::endl; + } + + sscanf(uhd::get_version_string().c_str(),"%d.%d.%d",&vers,&subvers,&subsubvers); + LOG_I(HW,"UHD version %s (%d.%d.%d)\n", + uhd::get_version_string().c_str(),vers,subvers,subsubvers); + std::string args; + + if (openair0_cfg[0].sdr_addrs == NULL) { + args = "type=b200"; } else { - // hotfix! to be checked later - uhd::set_thread_priority_safe(1.0); - // Initialize USRP device - int vers=0,subvers=0,subsubvers=0; - int bw_gain_adjust=0; - - if (s->recplay_mode == RECPLAY_RECORDMODE) { - std::cerr << "USRP device initialized in subframes record mode" << std::endl; - } - - sscanf(uhd::get_version_string().c_str(),"%d.%d.%d",&vers,&subvers,&subsubvers); - LOG_I(HW,"UHD version %s (%d.%d.%d)\n", - uhd::get_version_string().c_str(),vers,subvers,subsubvers); - std::string args; - - if (openair0_cfg[0].sdr_addrs == NULL) { - args = "type=b200"; - } else { - args = openair0_cfg[0].sdr_addrs; - LOG_I(HW,"Checking for USRP with args %s\n",openair0_cfg[0].sdr_addrs); - } - - uhd::device_addrs_t device_adds = uhd::device::find(args); - - if (device_adds.size() == 0) { - LOG_E(HW,"No USRP Device Found.\n "); - free(s); - return -1; - } else if (device_adds.size() > 1) { - LOG_E(HW,"More than one USRP Device Found. Please specify device more precisely in config file.\n"); - free(s); - return -1; - } - - LOG_I(HW,"Found USRP %s\n", device_adds[0].get("type").c_str()); - double usrp_master_clock; - - if (device_adds[0].get("type") == "b200") { - printf("Found USRP b200\n"); - device->type = USRP_B200_DEV; - usrp_master_clock = 30.72e6; - args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); - args += ",num_send_frames=256,num_recv_frames=256, send_frame_size=7680, recv_frame_size=7680" ; - } - - if (device_adds[0].get("type") == "n3xx") { - printf("Found USRP n300\n"); - device->type=USRP_X300_DEV; //treat it as X300 for now - usrp_master_clock = 122.88e6; - args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); - //args += ", send_buff_size=33554432"; - } - - if (device_adds[0].get("type") == "x300") { - printf("Found USRP x300\n"); - device->type=USRP_X300_DEV; - usrp_master_clock = 184.32e6; - args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); - - // USRP recommended: https://files.ettus.com/manual/page_usrp_x3x0_config.html - if ( 0 != system("sysctl -w net.core.rmem_max=33554432 net.core.wmem_max=33554432") ) - LOG_W(HW,"Can't set kernel parameters for X3xx\n"); - } - - s->usrp = uhd::usrp::multi_usrp::make(args); - - if (args.find("clock_source")==std::string::npos) { + args = openair0_cfg[0].sdr_addrs; + LOG_I(HW,"Checking for USRP with args %s\n",openair0_cfg[0].sdr_addrs); + } + + uhd::device_addrs_t device_adds = uhd::device::find(args); + + if (device_adds.size() == 0) { + LOG_E(HW,"No USRP Device Found.\n "); + free(s); + return -1; + } else if (device_adds.size() > 1) { + LOG_E(HW,"More than one USRP Device Found. Please specify device more precisely in config file.\n"); + free(s); + return -1; + } + + LOG_I(HW,"Found USRP %s\n", device_adds[0].get("type").c_str()); + double usrp_master_clock; + + if (device_adds[0].get("type") == "b200") { + printf("Found USRP b200\n"); + device->type = USRP_B200_DEV; + usrp_master_clock = 30.72e6; + args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); + args += ",num_send_frames=256,num_recv_frames=256, send_frame_size=7680, recv_frame_size=7680" ; + } + + if (device_adds[0].get("type") == "n3xx") { + printf("Found USRP n300\n"); + device->type=USRP_X300_DEV; //treat it as X300 for now + usrp_master_clock = 122.88e6; + args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); + //args += ", send_buff_size=33554432"; + } + + if (device_adds[0].get("type") == "x300") { + printf("Found USRP x300\n"); + device->type=USRP_X300_DEV; + usrp_master_clock = 184.32e6; + args += boost::str(boost::format(",master_clock_rate=%f") % usrp_master_clock); + + // USRP recommended: https://files.ettus.com/manual/page_usrp_x3x0_config.html + if ( 0 != system("sysctl -w net.core.rmem_max=33554432 net.core.wmem_max=33554432") ) + LOG_W(HW,"Can't set kernel parameters for X3xx\n"); + } + + s->usrp = uhd::usrp::multi_usrp::make(args); + + if (args.find("clock_source")==std::string::npos) { if (openair0_cfg[0].clock_source == internal) { //in UHD 3.14 we could use //s->usrp->set_sync_source("clock_source=internal","time_source=internal"); @@ -1023,358 +828,292 @@ extern "C" { else { LOG_W(HW,"Clock source set neither in usrp_args nor on command line, using default!\n"); } - } - else { + } + else { if (openair0_cfg[0].clock_source != unset) { LOG_W(HW,"Clock source set in both usrp_args and in clock_source, ingnoring the latter!\n"); } - } - - if (s->usrp->get_clock_source(0) == "gpsdo") { - s->use_gps = 1; - - if (sync_to_gps(device)==EXIT_SUCCESS) { - LOG_I(HW,"USRP synced with GPS!\n"); - } else { - LOG_I(HW,"USRP fails to sync with GPS. Exiting.\n"); - exit(EXIT_FAILURE); - } - } else if (s->usrp->get_clock_source(0) == "external") { - if (check_ref_locked(s,0)) { - LOG_I(HW,"USRP locked to external reference!\n"); - } else { - LOG_I(HW,"Failed to lock to external reference. Exiting.\n"); - exit(EXIT_FAILURE); - } - } - - if (device->type==USRP_X300_DEV) { - openair0_cfg[0].rx_gain_calib_table = calib_table_x310; - std::cerr << "-- Using calibration table: calib_table_x310" << std::endl; // Bell Labs info - LOG_I(HW,"%s() sample_rate:%u\n", __FUNCTION__, (int)openair0_cfg[0].sample_rate); - - switch ((int)openair0_cfg[0].sample_rate) { - case 122880000: - // from usrp_time_offset - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 15; //to be checked - openair0_cfg[0].tx_bw = 80e6; - openair0_cfg[0].rx_bw = 80e6; - break; - - case 92160000: - // from usrp_time_offset - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 15; //to be checked - openair0_cfg[0].tx_bw = 80e6; - openair0_cfg[0].rx_bw = 80e6; - break; - - case 61440000: - // from usrp_time_offset - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 15; - openair0_cfg[0].tx_bw = 40e6; - openair0_cfg[0].rx_bw = 40e6; - break; - - case 46080000: - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 15; - openair0_cfg[0].tx_bw = 40e6; - openair0_cfg[0].rx_bw = 40e6; - break; - - case 30720000: - // from usrp_time_offset - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 15; - openair0_cfg[0].tx_bw = 20e6; - openair0_cfg[0].rx_bw = 20e6; - break; - - case 15360000: - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 45; - openair0_cfg[0].tx_bw = 10e6; - openair0_cfg[0].rx_bw = 10e6; - break; - - case 7680000: - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 50; - openair0_cfg[0].tx_bw = 5e6; - openair0_cfg[0].rx_bw = 5e6; - break; - - case 1920000: - //openair0_cfg[0].samples_per_packet = 2048; - openair0_cfg[0].tx_sample_advance = 50; - openair0_cfg[0].tx_bw = 1.25e6; - openair0_cfg[0].rx_bw = 1.25e6; - break; - - default: - LOG_E(HW,"Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); - exit(-1); - break; - } - } - - if (device->type == USRP_B200_DEV) { - if ((vers == 3) && (subvers == 9) && (subsubvers>=2)) { - openair0_cfg[0].rx_gain_calib_table = calib_table_b210; - bw_gain_adjust=0; - std::cerr << "-- Using calibration table: calib_table_b210" << std::endl; // Bell Labs info - } else { - openair0_cfg[0].rx_gain_calib_table = calib_table_b210_38; - bw_gain_adjust=1; - std::cerr << "-- Using calibration table: calib_table_b210_38" << std::endl; // Bell Labs info - } - - switch ((int)openair0_cfg[0].sample_rate) { - case 46080000: - s->usrp->set_master_clock_rate(46.08e6); - //openair0_cfg[0].samples_per_packet = 1024; - openair0_cfg[0].tx_sample_advance = 115; - openair0_cfg[0].tx_bw = 40e6; - openair0_cfg[0].rx_bw = 40e6; - break; - - case 30720000: - s->usrp->set_master_clock_rate(30.72e6); - //openair0_cfg[0].samples_per_packet = 1024; - openair0_cfg[0].tx_sample_advance = 115; - openair0_cfg[0].tx_bw = 20e6; - openair0_cfg[0].rx_bw = 20e6; - break; - - case 23040000: - s->usrp->set_master_clock_rate(23.04e6); //to be checked - //openair0_cfg[0].samples_per_packet = 1024; - openair0_cfg[0].tx_sample_advance = 113; - openair0_cfg[0].tx_bw = 20e6; - openair0_cfg[0].rx_bw = 20e6; - break; - - case 15360000: - s->usrp->set_master_clock_rate(30.72e06); - //openair0_cfg[0].samples_per_packet = 1024; - openair0_cfg[0].tx_sample_advance = 103; - openair0_cfg[0].tx_bw = 20e6; - openair0_cfg[0].rx_bw = 20e6; - break; - - case 7680000: - s->usrp->set_master_clock_rate(30.72e6); - //openair0_cfg[0].samples_per_packet = 1024; - openair0_cfg[0].tx_sample_advance = 80; - openair0_cfg[0].tx_bw = 20e6; - openair0_cfg[0].rx_bw = 20e6; - break; - - case 1920000: - s->usrp->set_master_clock_rate(30.72e6); - //openair0_cfg[0].samples_per_packet = 1024; - openair0_cfg[0].tx_sample_advance = 40; - openair0_cfg[0].tx_bw = 20e6; - openair0_cfg[0].rx_bw = 20e6; - break; - - default: - LOG_E(HW,"Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); - exit(-1); - break; - } - } - - /* device specific */ - //openair0_cfg[0].txlaunch_wait = 1;//manage when TX processing is triggered - //openair0_cfg[0].txlaunch_wait_slotcount = 1; //manage when TX processing is triggered - openair0_cfg[0].iq_txshift = 4;//shift - openair0_cfg[0].iq_rxrescale = 15;//rescale iqs - - for(int i=0; i<((int) s->usrp->get_rx_num_channels()); i++) { - if (iusrp->set_rx_rate(openair0_cfg[0].sample_rate,i); - s->usrp->set_rx_freq(openair0_cfg[0].rx_freq[i],i); - set_rx_gain_offset(&openair0_cfg[0],i,bw_gain_adjust); - ::uhd::gain_range_t gain_range = s->usrp->get_rx_gain_range(i); - // limit to maximum gain - AssertFatal( openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i] <= gain_range.stop(), - "RX Gain too high, lower by %f dB\n", - openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i] - gain_range.stop()); - s->usrp->set_rx_gain(openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i],i); - LOG_I(HW,"RX Gain %d %f (%f) => %f (max %f)\n",i, - openair0_cfg[0].rx_gain[i],openair0_cfg[0].rx_gain_offset[i], - openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i],gain_range.stop()); - } - } - - LOG_D(HW, "usrp->get_tx_num_channels() == %zd\n", s->usrp->get_tx_num_channels()); - LOG_D(HW, "openair0_cfg[0].tx_num_channels == %d\n", openair0_cfg[0].tx_num_channels); - - for(int i=0; i<((int) s->usrp->get_tx_num_channels()); i++) { - ::uhd::gain_range_t gain_range_tx = s->usrp->get_tx_gain_range(i); - - if (iusrp->set_tx_rate(openair0_cfg[0].sample_rate,i); - s->usrp->set_tx_freq(openair0_cfg[0].tx_freq[i],i); - s->usrp->set_tx_gain(gain_range_tx.stop()-openair0_cfg[0].tx_gain[i],i); - LOG_I(HW,"USRP TX_GAIN:%3.2lf gain_range:%3.2lf tx_gain:%3.2lf\n", gain_range_tx.stop()-openair0_cfg[0].tx_gain[i], gain_range_tx.stop(), openair0_cfg[0].tx_gain[i]); - } - } - - //s->usrp->set_clock_source("external"); - //s->usrp->set_time_source("external"); - // display USRP settings - LOG_I(HW,"Actual master clock: %fMHz...\n",s->usrp->get_master_clock_rate()/1e6); - sleep(1); - // create tx & rx streamer - uhd::stream_args_t stream_args_rx("sc16", "sc16"); - int samples=openair0_cfg[0].sample_rate; - int max=s->usrp->get_rx_stream(stream_args_rx)->get_max_num_samps(); - samples/=10000; - LOG_I(HW,"RF board max packet size %u, size for 100µs jitter %d \n", max, samples); - - if ( samples < max ) { - stream_args_rx.args["spp"] = str(boost::format("%d") % samples ); - } - - LOG_I(HW,"rx_max_num_samps %zu\n", - s->usrp->get_rx_stream(stream_args_rx)->get_max_num_samps()); - - for (int i = 0; irx_stream = s->usrp->get_rx_stream(stream_args_rx); - uhd::stream_args_t stream_args_tx("sc16", "sc16"); - - for (int i = 0; itx_stream = s->usrp->get_tx_stream(stream_args_tx); - - /* Setting TX/RX BW after streamers are created due to USRP calibration issue */ - for(int i=0; i<((int) s->usrp->get_tx_num_channels()) && iusrp->set_tx_bandwidth(openair0_cfg[0].tx_bw,i); - - for(int i=0; i<((int) s->usrp->get_rx_num_channels()) && iusrp->set_rx_bandwidth(openair0_cfg[0].rx_bw,i); - - for (int i=0; iusrp->get_rx_rate(i)/1e6); - LOG_I(HW," Actual RX frequency: %fGHz...\n", s->usrp->get_rx_freq(i)/1e9); - LOG_I(HW," Actual RX gain: %f...\n", s->usrp->get_rx_gain(i)); - LOG_I(HW," Actual RX bandwidth: %fM...\n", s->usrp->get_rx_bandwidth(i)/1e6); - LOG_I(HW," Actual RX antenna: %s...\n", s->usrp->get_rx_antenna(i).c_str()); - } - - for (int i=0; iusrp->get_tx_rate(i)/1e6); - LOG_I(HW," Actual TX frequency: %fGHz...\n", s->usrp->get_tx_freq(i)/1e9); - LOG_I(HW," Actual TX gain: %f...\n", s->usrp->get_tx_gain(i)); - LOG_I(HW," Actual TX bandwidth: %fM...\n", s->usrp->get_tx_bandwidth(i)/1e6); - LOG_I(HW," Actual TX antenna: %s...\n", s->usrp->get_tx_antenna(i).c_str()); - LOG_I(HW," Actual TX packet size: %lu\n",s->tx_stream->get_max_num_samps()); - } - - LOG_I(HW,"Device timestamp: %f...\n", s->usrp->get_time_now().get_real_secs()); - device->trx_write_func = trx_usrp_write; - device->trx_read_func = trx_usrp_read; - s->sample_rate = openair0_cfg[0].sample_rate; - - // TODO: - // init tx_forward_nsamps based usrp_time_offset ex - if(is_equal(s->sample_rate, (double)30.72e6)) - s->tx_forward_nsamps = 176; - - if(is_equal(s->sample_rate, (double)15.36e6)) - s->tx_forward_nsamps = 90; - - if(is_equal(s->sample_rate, (double)7.68e6)) - s->tx_forward_nsamps = 50; - } - - if (s->recplay_mode == RECPLAY_RECORDMODE) { // record mode - s->recplay_state->ms_sample = (iqrec_t *) malloc(s->recplay_state->u_sf_max * sizeof(iqrec_t)); - - if (s->recplay_state->ms_sample == NULL) { - std::cerr<< "Memory allocation failed for subframe record or replay mode." << std::endl; - exit(-1); - } - - memset(s->recplay_state->ms_sample, 0, s->recplay_state->u_sf_max * BELL_LABS_IQ_BYTES_PER_SF); - } else if (s->recplay_mode == RECPLAY_REPLAYMODE) { - if (s->recplay_state->use_mmap) { - // use mmap - s->recplay_state->mmapfd = open(s->recplay_state->u_sf_filename, O_RDONLY | O_LARGEFILE); - - if (s->recplay_state->mmapfd != 0) { - struct stat sb; - fstat(s->recplay_state->mmapfd, &sb); - s->recplay_state->mapsize=sb.st_size; - std::cerr << "Loading subframes using mmap() from " << s->recplay_state->u_sf_filename << " size=" << (uint64_t)sb.st_size << " bytes ..." << std::endl; - s->recplay_state->ms_sample = (iqrec_t *) mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, s->recplay_state->mmapfd, 0); - - if (s->recplay_state->ms_sample != MAP_FAILED) { - s->recplay_state->nb_samples = (sb.st_size / sizeof(iqrec_t)); - int aligned = (((unsigned long)s->recplay_state->ms_sample & 31) == 0)? 1:0; - std::cerr<< "Loaded "<< s->recplay_state->nb_samples << " subframes." << std::endl; - - if (aligned == 0) { - std::cerr<< "mmap address is not 32 bytes aligned, exiting." << std::endl; - close(s->recplay_state->mmapfd); - exit(-1); - } - } else { - std::cerr << "Cannot mmap file, exiting." << std::endl; - close(s->recplay_state->mmapfd); - exit(-1); - } - } else { - std::cerr << "Cannot open " << s->recplay_state->u_sf_filename << " , exiting." << std::endl; - exit(-1); - } - } else { - s->recplay_state->iqfd = open(s->recplay_state->u_sf_filename, O_RDONLY | O_LARGEFILE); - - if (s->recplay_state->iqfd != 0) { - struct stat sb; - fstat(s->recplay_state->iqfd, &sb); - s->recplay_state->mapsize=sb.st_size; - s->recplay_state->nb_samples = (sb.st_size / sizeof(iqrec_t)); - std::cerr << "Loading " << s->recplay_state->nb_samples << " subframes from " << s->recplay_state->u_sf_filename - << " size=" << (uint64_t)sb.st_size << " bytes ..." << std::endl; - // allocate buffer for 1 sample at a time - s->recplay_state->ms_sample = (iqrec_t *) malloc(sizeof(iqrec_t)); - - if (s->recplay_state->ms_sample == NULL) { - std::cerr<< "Memory allocation failed for individual subframe replay mode." << std::endl; - close(s->recplay_state->iqfd); - exit(-1); - } - - memset(s->recplay_state->ms_sample, 0, sizeof(iqrec_t)); - - // point at beginning of file - if (lseek(s->recplay_state->iqfd, 0, SEEK_SET) == 0) { - std::cerr << "Initial seek at beginning of the file" << std::endl; - } else { - std::cerr << "Problem initial seek at beginning of the file" << std::endl; - } - } else { - std::cerr << "Cannot open " << s->recplay_state->u_sf_filename << " , exiting." << std::endl; - exit(-1); - } - } - } - - return 0; } - - + + if (s->usrp->get_clock_source(0) == "gpsdo") { + s->use_gps = 1; + + if (sync_to_gps(device)==EXIT_SUCCESS) { + LOG_I(HW,"USRP synced with GPS!\n"); + } else { + LOG_I(HW,"USRP fails to sync with GPS. Exiting.\n"); + exit(EXIT_FAILURE); + } + } else if (s->usrp->get_clock_source(0) == "external") { + if (check_ref_locked(s,0)) { + LOG_I(HW,"USRP locked to external reference!\n"); + } else { + LOG_I(HW,"Failed to lock to external reference. Exiting.\n"); + exit(EXIT_FAILURE); + } + } + + if (device->type==USRP_X300_DEV) { + openair0_cfg[0].rx_gain_calib_table = calib_table_x310; + std::cerr << "-- Using calibration table: calib_table_x310" << std::endl; // Bell Labs info + LOG_I(HW,"%s() sample_rate:%u\n", __FUNCTION__, (int)openair0_cfg[0].sample_rate); + + switch ((int)openair0_cfg[0].sample_rate) { + case 122880000: + // from usrp_time_offset + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 15; //to be checked + openair0_cfg[0].tx_bw = 80e6; + openair0_cfg[0].rx_bw = 80e6; + break; + + case 92160000: + // from usrp_time_offset + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 15; //to be checked + openair0_cfg[0].tx_bw = 80e6; + openair0_cfg[0].rx_bw = 80e6; + break; + + case 61440000: + // from usrp_time_offset + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 15; + openair0_cfg[0].tx_bw = 40e6; + openair0_cfg[0].rx_bw = 40e6; + break; + + case 46080000: + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 15; + openair0_cfg[0].tx_bw = 40e6; + openair0_cfg[0].rx_bw = 40e6; + break; + + case 30720000: + // from usrp_time_offset + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 15; + openair0_cfg[0].tx_bw = 20e6; + openair0_cfg[0].rx_bw = 20e6; + break; + + case 15360000: + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 45; + openair0_cfg[0].tx_bw = 10e6; + openair0_cfg[0].rx_bw = 10e6; + break; + + case 7680000: + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 50; + openair0_cfg[0].tx_bw = 5e6; + openair0_cfg[0].rx_bw = 5e6; + break; + + case 1920000: + //openair0_cfg[0].samples_per_packet = 2048; + openair0_cfg[0].tx_sample_advance = 50; + openair0_cfg[0].tx_bw = 1.25e6; + openair0_cfg[0].rx_bw = 1.25e6; + break; + + default: + LOG_E(HW,"Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); + exit(-1); + break; + } + } + + if (device->type == USRP_B200_DEV) { + if ((vers == 3) && (subvers == 9) && (subsubvers>=2)) { + openair0_cfg[0].rx_gain_calib_table = calib_table_b210; + bw_gain_adjust=0; + std::cerr << "-- Using calibration table: calib_table_b210" << std::endl; // Bell Labs info + } else { + openair0_cfg[0].rx_gain_calib_table = calib_table_b210_38; + bw_gain_adjust=1; + std::cerr << "-- Using calibration table: calib_table_b210_38" << std::endl; // Bell Labs info + } + + switch ((int)openair0_cfg[0].sample_rate) { + case 46080000: + s->usrp->set_master_clock_rate(46.08e6); + //openair0_cfg[0].samples_per_packet = 1024; + openair0_cfg[0].tx_sample_advance = 115; + openair0_cfg[0].tx_bw = 40e6; + openair0_cfg[0].rx_bw = 40e6; + break; + + case 30720000: + s->usrp->set_master_clock_rate(30.72e6); + //openair0_cfg[0].samples_per_packet = 1024; + openair0_cfg[0].tx_sample_advance = 115; + openair0_cfg[0].tx_bw = 20e6; + openair0_cfg[0].rx_bw = 20e6; + break; + + case 23040000: + s->usrp->set_master_clock_rate(23.04e6); //to be checked + //openair0_cfg[0].samples_per_packet = 1024; + openair0_cfg[0].tx_sample_advance = 113; + openair0_cfg[0].tx_bw = 20e6; + openair0_cfg[0].rx_bw = 20e6; + break; + + case 15360000: + s->usrp->set_master_clock_rate(30.72e06); + //openair0_cfg[0].samples_per_packet = 1024; + openair0_cfg[0].tx_sample_advance = 103; + openair0_cfg[0].tx_bw = 20e6; + openair0_cfg[0].rx_bw = 20e6; + break; + + case 7680000: + s->usrp->set_master_clock_rate(30.72e6); + //openair0_cfg[0].samples_per_packet = 1024; + openair0_cfg[0].tx_sample_advance = 80; + openair0_cfg[0].tx_bw = 20e6; + openair0_cfg[0].rx_bw = 20e6; + break; + + case 1920000: + s->usrp->set_master_clock_rate(30.72e6); + //openair0_cfg[0].samples_per_packet = 1024; + openair0_cfg[0].tx_sample_advance = 40; + openair0_cfg[0].tx_bw = 20e6; + openair0_cfg[0].rx_bw = 20e6; + break; + + default: + LOG_E(HW,"Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate); + exit(-1); + break; + } + } + + /* device specific */ + //openair0_cfg[0].txlaunch_wait = 1;//manage when TX processing is triggered + //openair0_cfg[0].txlaunch_wait_slotcount = 1; //manage when TX processing is triggered + openair0_cfg[0].iq_txshift = 4;//shift + openair0_cfg[0].iq_rxrescale = 15;//rescale iqs + + for(int i=0; i<((int) s->usrp->get_rx_num_channels()); i++) { + if (iusrp->set_rx_rate(openair0_cfg[0].sample_rate,i); + s->usrp->set_rx_freq(openair0_cfg[0].rx_freq[i],i); + set_rx_gain_offset(&openair0_cfg[0],i,bw_gain_adjust); + ::uhd::gain_range_t gain_range = s->usrp->get_rx_gain_range(i); + // limit to maximum gain + AssertFatal( openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i] <= gain_range.stop(), + "RX Gain too high, lower by %f dB\n", + openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i] - gain_range.stop()); + s->usrp->set_rx_gain(openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i],i); + LOG_I(HW,"RX Gain %d %f (%f) => %f (max %f)\n",i, + openair0_cfg[0].rx_gain[i],openair0_cfg[0].rx_gain_offset[i], + openair0_cfg[0].rx_gain[i]-openair0_cfg[0].rx_gain_offset[i],gain_range.stop()); + } + } + + LOG_D(HW, "usrp->get_tx_num_channels() == %zd\n", s->usrp->get_tx_num_channels()); + LOG_D(HW, "openair0_cfg[0].tx_num_channels == %d\n", openair0_cfg[0].tx_num_channels); + + for(int i=0; i<((int) s->usrp->get_tx_num_channels()); i++) { + ::uhd::gain_range_t gain_range_tx = s->usrp->get_tx_gain_range(i); + + if (iusrp->set_tx_rate(openair0_cfg[0].sample_rate,i); + s->usrp->set_tx_freq(openair0_cfg[0].tx_freq[i],i); + s->usrp->set_tx_gain(gain_range_tx.stop()-openair0_cfg[0].tx_gain[i],i); + LOG_I(HW,"USRP TX_GAIN:%3.2lf gain_range:%3.2lf tx_gain:%3.2lf\n", gain_range_tx.stop()-openair0_cfg[0].tx_gain[i], gain_range_tx.stop(), openair0_cfg[0].tx_gain[i]); + } + } + + //s->usrp->set_clock_source("external"); + //s->usrp->set_time_source("external"); + // display USRP settings + LOG_I(HW,"Actual master clock: %fMHz...\n",s->usrp->get_master_clock_rate()/1e6); + sleep(1); + // create tx & rx streamer + uhd::stream_args_t stream_args_rx("sc16", "sc16"); + int samples=openair0_cfg[0].sample_rate; + int max=s->usrp->get_rx_stream(stream_args_rx)->get_max_num_samps(); + samples/=10000; + LOG_I(HW,"RF board max packet size %u, size for 100µs jitter %d \n", max, samples); + + if ( samples < max ) { + stream_args_rx.args["spp"] = str(boost::format("%d") % samples ); + } + + LOG_I(HW,"rx_max_num_samps %zu\n", + s->usrp->get_rx_stream(stream_args_rx)->get_max_num_samps()); + + for (int i = 0; irx_stream = s->usrp->get_rx_stream(stream_args_rx); + uhd::stream_args_t stream_args_tx("sc16", "sc16"); + + for (int i = 0; itx_stream = s->usrp->get_tx_stream(stream_args_tx); + + /* Setting TX/RX BW after streamers are created due to USRP calibration issue */ + for(int i=0; i<((int) s->usrp->get_tx_num_channels()) && iusrp->set_tx_bandwidth(openair0_cfg[0].tx_bw,i); + + for(int i=0; i<((int) s->usrp->get_rx_num_channels()) && iusrp->set_rx_bandwidth(openair0_cfg[0].rx_bw,i); + + for (int i=0; iusrp->get_rx_rate(i)/1e6); + LOG_I(HW," Actual RX frequency: %fGHz...\n", s->usrp->get_rx_freq(i)/1e9); + LOG_I(HW," Actual RX gain: %f...\n", s->usrp->get_rx_gain(i)); + LOG_I(HW," Actual RX bandwidth: %fM...\n", s->usrp->get_rx_bandwidth(i)/1e6); + LOG_I(HW," Actual RX antenna: %s...\n", s->usrp->get_rx_antenna(i).c_str()); + } + + for (int i=0; iusrp->get_tx_rate(i)/1e6); + LOG_I(HW," Actual TX frequency: %fGHz...\n", s->usrp->get_tx_freq(i)/1e9); + LOG_I(HW," Actual TX gain: %f...\n", s->usrp->get_tx_gain(i)); + LOG_I(HW," Actual TX bandwidth: %fM...\n", s->usrp->get_tx_bandwidth(i)/1e6); + LOG_I(HW," Actual TX antenna: %s...\n", s->usrp->get_tx_antenna(i).c_str()); + LOG_I(HW," Actual TX packet size: %lu\n",s->tx_stream->get_max_num_samps()); + } + + LOG_I(HW,"Device timestamp: %f...\n", s->usrp->get_time_now().get_real_secs()); + device->trx_write_func = trx_usrp_write; + device->trx_read_func = trx_usrp_read; + s->sample_rate = openair0_cfg[0].sample_rate; + + // TODO: + // init tx_forward_nsamps based usrp_time_offset ex + if(is_equal(s->sample_rate, (double)30.72e6)) + s->tx_forward_nsamps = 176; + + if(is_equal(s->sample_rate, (double)15.36e6)) + s->tx_forward_nsamps = 90; + + if(is_equal(s->sample_rate, (double)7.68e6)) + s->tx_forward_nsamps = 50; + + + if (device->recplay_state != NULL) { // record mode + device->recplay_state->ms_sample = (iqrec_t *) malloc(openair0_cfg[0].recplay_conf->u_sf_max * sizeof(iqrec_t)); + + if (device->recplay_state->ms_sample == NULL) { + std::cerr<< "Memory allocation failed for subframe record or replay mode." << std::endl; + exit(-1); + } + + memset(device->recplay_state->ms_sample, 0, openair0_cfg[0].recplay_conf->u_sf_max * BELL_LABS_IQ_BYTES_PER_SF); + } + return 0; } /*@}*/ +}/* extern c */ \ No newline at end of file diff --git a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib_config.c b/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib_config.c deleted file mode 100644 index ebf1d61eed..0000000000 --- a/targets/ARCH/USRP/USERSPACE/LIB/usrp_lib_config.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The OpenAirInterface Software Alliance licenses this file to You under - * the OAI Public License, Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.openairinterface.org/?page_id=698 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *------------------------------------------------------------------------------- - * For more information about the OpenAirInterface (OAI) Software Alliance: - * contact@openairinterface.org - */ - -/** usrp_lib_config.c - * - * \author: HongliangXU : hong-liang-xu@agilent.com - */ - -#include -#include -#include -#include -#include -#include "common/utils/LOG/log.h" -#include "assertions.h" -#include "common_lib.h" -#include "usrp_lib.h" - - -int read_usrpconfig(uint32_t *recplay_mode, recplay_state_t **recplay_state) { -unsigned int u_sf_record = 0; // record mode -unsigned int u_sf_replay = 0; // replay mode -uint32_t enable_recplay; - - paramdef_t usrp_params[] = USRP_DEVICE_PARAMS_DESC; - config_get(usrp_params,sizeof(usrp_params)/sizeof(paramdef_t),USRP_SECTION); - if (enable_recplay) { - *recplay_state = calloc(sizeof(recplay_state_t),1); - paramdef_t usrp_recplay_params[]=USRP_RECPLAY_PARAMS_DESC ; - struct sysinfo systeminfo; - - // Use mmap for IQ files for systems with less than 6GB total RAM - sysinfo(&systeminfo); - - if (systeminfo.totalram < 6144000000) { - (*recplay_state)->use_mmap = 0; - } else { - (*recplay_state)->use_mmap = 1; - } - - memset((*recplay_state)->u_sf_filename, 0, 1024); - config_get(usrp_recplay_params,sizeof(usrp_recplay_params)/sizeof(paramdef_t),USRP_RECPLAY_SECTION); - - if (strlen((*recplay_state)->u_sf_filename) == 0) { - (void) strcpy(( - *recplay_state)->u_sf_filename, DEF_SF_FILE); - } - } /* record player enabled */ - if (u_sf_replay == 1) *recplay_mode = RECPLAY_REPLAYMODE; - - if (u_sf_record == 1) *recplay_mode = RECPLAY_RECORDMODE; - - - return 0; - } \ No newline at end of file diff --git a/targets/ARCH/iqplayer/iqplayer_lib.c b/targets/ARCH/iqplayer/iqplayer_lib.c new file mode 100644 index 0000000000..beb05de3fd --- /dev/null +++ b/targets/ARCH/iqplayer/iqplayer_lib.c @@ -0,0 +1,307 @@ +/* + * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The OpenAirInterface Software Alliance licenses this file to You under + * the OAI Public License, Version 1.1 (the "License"); you may not use this file + * except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.openairinterface.org/?page_id=698 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *------------------------------------------------------------------------------- + * For more information about the OpenAirInterface (OAI) Software Alliance: + * contact@openairinterface.org + */ + +/** iqplayer_lib.cpp + * + * \author:FrancoisTaburet: francois.taburet@nokia-bell-labs.com + */ +#define _LARGEFILE_SOURCE +#define _FILE_OFFSET_BITS 64 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "common_lib.h" +#include "assertions.h" +#include "common/utils/LOG/log.h" + + + + + + +static void parse_iqfile_header(openair0_device *device, iqfile_header_t *iq_fh) { + AssertFatal((memcmp(iq_fh->oaiid,OAIIQFILE_ID,sizeof(OAIIQFILE_ID)) == 0),"iqfile doesn't seem to be compatible with oai (invalid id in header)\n"); + device->type = iq_fh->devtype; + device->openair0_cfg[0].tx_sample_advance=iq_fh->tx_sample_advance; + device->openair0_cfg[0].tx_bw = device->openair0_cfg[0].rx_bw = iq_fh->bw; + LOG_UI(HW,"Replay iqs from %s device, bandwidth %e\n",get_devname(iq_fh->devtype),iq_fh->bw); +} + + +/*! \brief Called to start the iqplayer device. Return 0 if OK, < 0 if error + @param device pointer to the device structure specific to the RF hardware target +*/ +static int iqplayer_loadfile(openair0_device *device, openair0_config_t *openair0_cfg) { + recplay_state_t *s = device->recplay_state; + recplay_conf_t *c = openair0_cfg->recplay_conf; + + if (s->use_mmap) { + // use mmap + s->mmapfd = open(c->u_sf_filename, O_RDONLY ); + + if (s->mmapfd != 0) { + struct stat sb; + fstat(s->mmapfd, &sb); + s->mapsize=sb.st_size; + LOG_I(HW,"Loading subframes using mmap() from %s size=%lu bytes ...\n",c->u_sf_filename, (uint64_t)sb.st_size ); + void *mptr = mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, s->mmapfd, 0) ; + s->ms_sample = (iqrec_t *) ( mmap(NULL, sb.st_size, PROT_WRITE, MAP_PRIVATE, s->mmapfd, 0) + sizeof(iqfile_header_t)); + + if (mptr != MAP_FAILED) { + parse_iqfile_header(device, (iqfile_header_t *)mptr); + s->ms_sample = (iqrec_t *)((char *)mptr + sizeof(iqfile_header_t)); + s->nb_samples = ((sb.st_size-sizeof(iqfile_header_t)) / sizeof(iqrec_t)); + int aligned = (((unsigned long)s->ms_sample & 31) == 0)? 1:0; + LOG_I(HW,"Loaded %u subframes.\n",s->nb_samples ); + + if (aligned == 0) { + LOG_E(HW, "mmap address is not 32 bytes aligned, exiting.\n" ); + close(s->mmapfd); + exit(-1); + } + } else { + LOG_E(HW,"Cannot mmap file, exiting.\n"); + close(s->mmapfd); + exit(-1); + } + } else { + LOG_E( HW,"Cannot open %s exiting.\n", c->u_sf_filename ); + exit(-1); + } + } else { + s->iqfd = open(c->u_sf_filename, O_RDONLY); + + if (s->iqfd != 0) { + struct stat sb; + iqfile_header_t fh; + size_t hs = read(s->iqfd,&fh,sizeof(fh)); + + if (hs == sizeof(fh)) { + parse_iqfile_header(device, &fh); + fstat(s->iqfd, &sb); + s->mapsize=sb.st_size; + s->nb_samples = ((sb.st_size-sizeof(iqfile_header_t))/ sizeof(iqrec_t)); + LOG_I(HW, "Loading %u subframes from %s,size=%lu bytes ...\n",s->nb_samples, c->u_sf_filename,(uint64_t)sb.st_size); + // allocate buffer for 1 sample at a time + s->ms_sample = (iqrec_t *) malloc(sizeof(iqrec_t)); + + if (s->ms_sample == NULL) { + LOG_E(HW,"Memory allocation failed for individual subframe replay mode.\n" ); + close(s->iqfd); + exit(-1); + } + + memset(s->ms_sample, 0, sizeof(iqrec_t)); + + // point at beginning of iqs in file + if (lseek(s->iqfd,sizeof(iqfile_header_t), SEEK_SET) == 0) { + LOG_I(HW,"Initial seek at beginning of the file\n" ); + } else { + LOG_I(HW,"Problem initial seek at beginning of the file\n"); + } + } else { + LOG_E(HW,"Cannot read header in %s exiting.\n",c->u_sf_filename ); + close(s->iqfd); + exit(-1); + } + } else { + LOG_E(HW,"Cannot open %s exiting.\n",c->u_sf_filename ); + exit(-1); + } + } + + return 0; +} + +/*! \brief Terminate operation of the oai iq player + * \param device, the hardware used + */ +static void trx_iqplayer_end(openair0_device *device) { + if (device == NULL) + return; + + if (device->recplay_state == NULL) + return; + + if (device->recplay_state->use_mmap) { + if (device->recplay_state->ms_sample != MAP_FAILED) { + munmap(device->recplay_state->ms_sample, device->recplay_state->mapsize); + device->recplay_state->ms_sample = NULL; + } + + if (device->recplay_state->mmapfd != 0) { + close(device->recplay_state->mmapfd); + device->recplay_state->mmapfd = 0; + } + } else { + if (device->recplay_state->ms_sample != NULL) { + free(device->recplay_state->ms_sample); + device->recplay_state->ms_sample = NULL; + } + + if (device->recplay_state->iqfd != 0) { + close(device->recplay_state->iqfd); + device->recplay_state->iqfd = 0; + } + } +} +/*! \brief Write iqs function when in replay mode, just introduce a delay, as configured at init time, + @param device pointer to the device structure specific to the RF hardware target + @param timestamp The timestamp at which the first sample MUST be sent + @param buff Buffer which holds the samples + @param nsamps number of samples to be sent + @param antenna_id index of the antenna if the device has multiple antennas + @param flags flags must be set to TRUE if timestamp parameter needs to be applied +*/ +static int trx_iqplayer_write(openair0_device *device, openair0_timestamp timestamp, void **buff, int nsamps, int cc, int flags) { + struct timespec req; + req.tv_sec = 0; + req.tv_nsec = device->openair0_cfg->recplay_conf->u_sf_write_delay * 1000; + nanosleep(&req, NULL); + return nsamps; +} + +/*! \brief Receive samples from iq file. + * Read \ref nsamps samples from each channel to buffers. buff[0] is the array for + * the first channel. *ptimestamp is the time at which the first sample + * was received. + * \param device the hardware to use + * \param[out] ptimestamp the time at which the first sample was received. + * \param[out] buff An array of pointers to buffers for received samples. The buffers must be large enough to hold the number of samples \ref nsamps. + * \param nsamps Number of samples. One sample is 2 byte I + 2 byte Q => 4 byte. + * \param antenna_id Index of antenna for which to receive samples + * \returns the number of sample read +*/ +static int trx_iqplayer_read(openair0_device *device, openair0_timestamp *ptimestamp, void **buff, int nsamps, int cc) { + int samples_received=0; + static unsigned int cur_samples; + static int64_t wrap_count; + static int64_t wrap_ts; + recplay_state_t *s = device->recplay_state; + + if (cur_samples == s->nb_samples) { + cur_samples = 0; + wrap_count++; + + if (wrap_count == device->openair0_cfg->recplay_conf->u_sf_loops) { + LOG_W(HW, "iqplayer device terminating subframes replay after %u iteration\n",device->openair0_cfg->recplay_conf->u_sf_loops); + exit_function(__FILE__, __FUNCTION__, __LINE__,"replay ended, triggering process termination\n"); + } + + wrap_ts = wrap_count * (s->nb_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000)); + + if (!device->recplay_state->use_mmap) { + if (lseek(device->recplay_state->iqfd, 0, SEEK_SET) == 0) { + LOG_I(HW,"Seeking at the beginning of IQ file"); + } else { + LOG_I(HW, "Problem seeking at the beginning of IQ file"); + } + } + } + + if (s->use_mmap) { + if (cur_samples < s->nb_samples) { + *ptimestamp = (s->ms_sample[0].ts + (cur_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000))) + wrap_ts; + + if (cur_samples == 0) { + LOG_I(HW,"starting subframes file with wrap_count=%lu wrap_ts=%lu ts=%lu\n", wrap_count,wrap_ts,*ptimestamp); + } + + memcpy(buff[0], &s->ms_sample[cur_samples].samples[0], nsamps*4); + cur_samples++; + } + } else { + // read sample from file + if (read(s->iqfd, s->ms_sample, sizeof(iqrec_t)) != sizeof(iqrec_t)) { + LOG_E(HW,"pb reading iqfile at index %lu\n",sizeof(iqrec_t)*cur_samples ); + close(s->iqfd); + free(s->ms_sample); + s->ms_sample = NULL; + s->iqfd = 0; + exit(-1); + } + + if (cur_samples < s->nb_samples) { + static int64_t ts0 = 0; + + if ((cur_samples == 0) && (wrap_count == 0)) { + ts0 = s->ms_sample->ts; + } + + *ptimestamp = ts0 + (cur_samples * (((int)(device->openair0_cfg[0].sample_rate)) / 1000)) + wrap_ts; + + if (cur_samples == 0) { + LOG_I(HW, "starting subframes file with wrap_count=%lu wrap_ts=%lu ts=%lu ",wrap_count,wrap_ts, *ptimestamp); + } + + memcpy(buff[0], &s->ms_sample->samples[0], nsamps*4); + cur_samples++; + // Prepare for next read + off_t where = lseek(s->iqfd, cur_samples * sizeof(iqrec_t), SEEK_SET); + + if (where < 0) { + LOG_E(HW,"Cannot lseek in iqfile: %s\n",strerror(errno)); + exit(-1); + } + } + } + + struct timespec req; + + req.tv_sec = 0; + + req.tv_nsec = (device->openair0_cfg[0].recplay_conf->u_sf_read_delay) * 1000; + + nanosleep(&req, NULL); + + return nsamps; + + return samples_received; +} + + +int device_init(openair0_device *device, openair0_config_t *openair0_cfg) { + device->openair0_cfg = openair0_cfg; + device->trx_start_func = NULL; + device->trx_get_stats_func = NULL; + device->trx_reset_stats_func = NULL; + device->trx_end_func = trx_iqplayer_end; + device->trx_stop_func = NULL; + device->trx_set_freq_func = NULL; + device->trx_set_gains_func = NULL; + // Replay subframes from from file + // openair0_cfg[0].rx_gain_calib_table = calib_table_b210_38; + // bw_gain_adjust=1; + device->trx_write_func = trx_iqplayer_write; + device->trx_read_func = trx_iqplayer_read; + iqplayer_loadfile(device, openair0_cfg); + LOG_UI(HW,"iqplayer device initialized, replay %s for %i iterations",openair0_cfg->recplay_conf->u_sf_filename,openair0_cfg->recplay_conf->u_sf_loops); + return 0; +} + +/*@}*/ diff --git a/targets/COMMON/create_nr_tasks.h b/targets/COMMON/create_nr_tasks.h index 7f5961f5ae..ca259a2b34 100644 --- a/targets/COMMON/create_nr_tasks.h +++ b/targets/COMMON/create_nr_tasks.h @@ -22,12 +22,10 @@ #ifndef CREATE_NR_TASKS_H_ #define CREATE_NR_TASKS_H_ -#if defined(ENABLE_ITTI) /* External declaration of L2L1 task that depend on the target */ extern void *l2l1_task(void *arg); int create_gNB_tasks(uint32_t gnb_nb); -#endif #endif /* CREATE_TASKS_H_ */ diff --git a/targets/COMMON/create_tasks.h b/targets/COMMON/create_tasks.h index 339f4aaa8f..843897cefb 100644 --- a/targets/COMMON/create_tasks.h +++ b/targets/COMMON/create_tasks.h @@ -22,13 +22,11 @@ #ifndef CREATE_TASKS_H_ #define CREATE_TASKS_H_ -#if defined(ENABLE_ITTI) /* External declaration of L2L1 task that depend on the target */ extern void *l2l1_task(void *arg); int create_tasks(uint32_t enb_nb); int create_tasks_ue(uint32_t ue_nb); int create_tasks_mbms(uint32_t enb_nb); -#endif #endif /* CREATE_TASKS_H_ */ diff --git a/targets/COMMON/create_tasks_mbms.h b/targets/COMMON/create_tasks_mbms.h index 339f4aaa8f..843897cefb 100644 --- a/targets/COMMON/create_tasks_mbms.h +++ b/targets/COMMON/create_tasks_mbms.h @@ -22,13 +22,11 @@ #ifndef CREATE_TASKS_H_ #define CREATE_TASKS_H_ -#if defined(ENABLE_ITTI) /* External declaration of L2L1 task that depend on the target */ extern void *l2l1_task(void *arg); int create_tasks(uint32_t enb_nb); int create_tasks_ue(uint32_t ue_nb); int create_tasks_mbms(uint32_t enb_nb); -#endif #endif /* CREATE_TASKS_H_ */ diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c index eccece02ca..c08ab2a77b 100644 --- a/targets/RT/USER/lte-softmodem.c +++ b/targets/RT/USER/lte-softmodem.c @@ -265,7 +265,7 @@ void exit_function(const char *file, const char *function, const int line, const static void get_options(void) { CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP); - get_common_options(); + get_common_options(SOFTMODEM_ENB_BIT ); CONFIG_CLEARRTFLAG(CONFIG_NOEXITONHELP); if ( !(CONFIG_ISFLAGSET(CONFIG_ABORT)) ) { diff --git a/targets/RT/USER/lte-uesoftmodem.c b/targets/RT/USER/lte-uesoftmodem.c index b468ff12d4..d0014b5e8a 100644 --- a/targets/RT/USER/lte-uesoftmodem.c +++ b/targets/RT/USER/lte-uesoftmodem.c @@ -79,10 +79,7 @@ #include "UTIL/OTG/otg_vars.h" #endif -#if defined(ENABLE_ITTI) - #include "create_tasks.h" -#endif - +#include "create_tasks.h" #include "system.h" @@ -300,7 +297,7 @@ static void get_options(void) { CONFIG_SETRTFLAG(CONFIG_NOEXITONHELP); /* unknown parameters on command line will be checked in main after all init have been performed */ - get_common_options(); + get_common_options(SOFTMODEM_4GUE_BIT ); get_uethreads_params(); paramdef_t cmdline_uemodeparams[] =CMDLINE_UEMODEPARAMS_DESC; paramdef_t cmdline_ueparams[] =CMDLINE_UEPARAMS_DESC; @@ -780,19 +777,11 @@ int main( int argc, char **argv ) { // wait for end of program printf("TYPE TO TERMINATE\n"); //getchar(); -#if defined(ENABLE_ITTI) printf("Entering ITTI signals handler\n"); itti_wait_tasks_end(); printf("Returned from ITTI signal handler\n"); oai_exit=1; printf("oai_exit=%d\n",oai_exit); -#else - - while (oai_exit==0) - rt_sleep_ns(100000000ULL); - - printf("Terminating application - oai_exit=%d\n",oai_exit); -#endif // stop threads if(IS_SOFTMODEM_DOFORMS) From e091f94ae786253ff232b9bba751f28c8d1af935 Mon Sep 17 00:00:00 2001 From: frtabu Date: Wed, 12 Feb 2020 19:29:53 +0100 Subject: [PATCH 14/73] fix T_IDs.h build problem --- cmake_targets/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt index 01b1d6c273..80ea64700e 100644 --- a/cmake_targets/CMakeLists.txt +++ b/cmake_targets/CMakeLists.txt @@ -2866,7 +2866,7 @@ if (${T_TRACER}) nr_ulschsim ldpctest polartest smallblocktest cu_test du_test #all "add_library" definitions ITTI RRC_LIB NR_RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB X2AP_ENB M2AP_LIB M2AP_ENB M3AP_LIB M3AP_ENB F1AP_LIB F1AP - params_libconfig oai_exmimodevif oai_usrpdevif oai_bladerfdevif oai_lmssdrdevif + params_libconfig oai_exmimodevif oai_usrpdevif oai_bladerfdevif oai_lmssdrdevif oai_iqplayer oai_eth_transpro oai_mobipass tcp_bridge tcp_bridge_oai coding FLPT_MSG ASYNC_IF FLEXRAN_AGENT HASHTABLE MSC UTIL OMG_SUMO SECU_OSA SECU_CN SCHED_LIB SCHED_NR_LIB SCHED_RU_LIB SCHED_UE_LIB SCHED_NR_UE_LIB default_sched remote_sched RAL From ff4829284b84592005364ad79ae4a72dcf80b4b4 Mon Sep 17 00:00:00 2001 From: frtabu Date: Wed, 12 Feb 2020 20:29:51 +0100 Subject: [PATCH 15/73] --amend --- common/utils/T/local_tracer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/utils/T/local_tracer.c b/common/utils/T/local_tracer.c index 8cbd06490d..539e72b223 100644 --- a/common/utils/T/local_tracer.c +++ b/common/utils/T/local_tracer.c @@ -15,7 +15,7 @@ #include "T_messages.txt.h" #include "T_defs.h" #include "T_IDs.h" -#include "softmodem-common.h" + static T_cache_t *T_local_cache; static int T_busylist_head; @@ -357,7 +357,7 @@ static void forward(void *_forwarder, char *buf, int size) { if (f->tail != NULL) f->tail->next = new; f->tail = new; - if( IS_SOFTMODEM_BASICSIM){ +#if BASIC_SIMULATOR /* When runnng the basic simulator, the tracer may be too slow. * Let's not take too much memory in the tracee and * wait if there is too much data to send. 200MB is @@ -372,7 +372,7 @@ static void forward(void *_forwarder, char *buf, int size) { if (pthread_mutex_lock(&f->lock)) abort(); } - } +#endif f->memusage += size+4; /* warn every 100MB */ From 1e38ef5fde292229e97f780e6e43e0bfb9d1cdc7 Mon Sep 17 00:00:00 2001 From: Thomas Dreibholz Date: Thu, 13 Feb 2020 11:33:46 +0100 Subject: [PATCH 16/73] Using "--allow-unauthenticated" with apt-get disables package verification, allowing to install untrusted/modified packages into the development system. Fixed calls to apt-get to make sure that packages are verified. --- cmake_targets/tools/build_helper | 10 +++++----- .../ADRV9371_ZC706/SYRTEM_IQ_uninstall_previous_SW.sh | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmake_targets/tools/build_helper b/cmake_targets/tools/build_helper index cdb7885945..6ed17649cc 100755 --- a/cmake_targets/tools/build_helper +++ b/cmake_targets/tools/build_helper @@ -296,8 +296,8 @@ check_install_usrp_uhd_driver(){ x=$((x + 1)) done $SUDO apt-get update - $SUDO apt-get -y --allow-unauthenticated install python python-tk libboost-all-dev libusb-1.0-0-dev - $SUDO apt-get -y --allow-unauthenticated install libuhd-dev libuhd003 uhd-host + $SUDO apt-get -y install python python-tk libboost-all-dev libusb-1.0-0-dev + $SUDO apt-get -y install libuhd-dev libuhd003 uhd-host elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then $SUDO $INSTALLER -y install python boost libusb-devel libusbx-devel boost-devel python-mako python-docutils cmake $SUDO -H pip install requests @@ -367,9 +367,9 @@ check_install_bladerf_driver(){ $SUDO add-apt-repository -y ppa:bladerf/bladerf $SUDO apt-get update fi - $SUDO apt-get install -y --allow-unauthenticated bladerf libbladerf-dev - $SUDO apt-get install -y --allow-unauthenticated bladerf-firmware-fx3 - $SUDO apt-get install -y --allow-unauthenticated bladerf-fpga-hostedx40 + $SUDO apt-get install -y bladerf libbladerf-dev + $SUDO apt-get install -y bladerf-firmware-fx3 + $SUDO apt-get install -y bladerf-fpga-hostedx40 elif [[ "$OS_BASEDISTRO" == "fedora" ]]; then install_bladerf_driver_from_source else diff --git a/targets/ARCH/ADRV9371_ZC706/SYRTEM_IQ_uninstall_previous_SW.sh b/targets/ARCH/ADRV9371_ZC706/SYRTEM_IQ_uninstall_previous_SW.sh index 6651a3beb8..e0d5289f00 100755 --- a/targets/ARCH/ADRV9371_ZC706/SYRTEM_IQ_uninstall_previous_SW.sh +++ b/targets/ARCH/ADRV9371_ZC706/SYRTEM_IQ_uninstall_previous_SW.sh @@ -4,7 +4,7 @@ MODULE="riffa" KERNEL_VERSION=$(uname -r) RHR=/etc/redhat-release -sudo apt-get install -y --allow-unauthenticated linux-headers-`uname -r` +sudo apt-get install -y linux-headers-`uname -r` if lsmod | grep "$MODULE" &> /dev/null ; then echo "Previous SYRIQ is loaded!" From 9f1350805c351cde3e98d20e58db89619c8c7224 Mon Sep 17 00:00:00 2001 From: matzakos Date: Thu, 13 Feb 2020 13:25:23 +0100 Subject: [PATCH 17/73] nr-ip-ul-nos1: Resolve some dependency issues to make the phy simulators compile --- openair1/SIMULATION/NR_PHY/dlsim.c | 51 ++++------------------------ openair1/SIMULATION/NR_PHY/pbchsim.c | 1 + openair1/SIMULATION/NR_PHY/ulsim.c | 49 +++----------------------- 3 files changed, 11 insertions(+), 90 deletions(-) diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c index 2974c4634a..60b79c17c2 100644 --- a/openair1/SIMULATION/NR_PHY/dlsim.c +++ b/openair1/SIMULATION/NR_PHY/dlsim.c @@ -68,58 +68,19 @@ uint16_t NB_UE_INST = 1; //Dummy Functions lte_subframe_t subframe_select(LTE_DL_FRAME_PARMS *frame_parms, unsigned char subframe) {return(SF_DL);} -int rlc_module_init (int enb) {return(0);} +//int rlc_module_init (int enb) {return(0);} void pdcp_layer_init (void) {} +boolean_t pdcp_data_ind( const protocol_ctxt_t *const ctxt_pP, const srb_flag_t srb_flagP, const MBMS_flag_t MBMS_flagP, const rb_id_t rb_idP, + const sdu_size_t sdu_buffer_sizeP, mem_block_t *const sdu_buffer_pP) +{return (0);} + int rrc_init_nr_global_param (void) {return(0);} void config_common(int Mod_idP,int CC_idP,int Nid_cell,int nr_bandP,uint64_t SSB_positions,uint16_t ssb_periodicity,uint64_t dl_CarrierFreqP,uint32_t dl_BandwidthP); int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, const int CC_id, const uint8_t gNB_index, const int8_t channel, const uint8_t* pduP, const sdu_size_t pdu_len) {return(0);} uint64_t get_softmodem_optmask(void) {return 0;} -mac_rlc_status_resp_t mac_rlc_status_ind(const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const sub_frame_t subframeP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - const tb_size_t tb_sizeP, - const uint32_t sourceL2Id, - const uint32_t destinationL2Id) {mac_rlc_status_resp_t mac_rlc_status_resp = {0}; return mac_rlc_status_resp;} -tbs_size_t mac_rlc_data_req(const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - const tb_size_t tb_sizeP, - char *buffer_pP, - const uint32_t sourceL2Id, - const uint32_t destinationL2Id) {return 0;} -int generate_dlsch_header(unsigned char *mac_header, - unsigned char num_sdus, - unsigned short *sdu_lengths, - unsigned char *sdu_lcids, - unsigned char drx_cmd, - unsigned short timing_advance_cmd, - unsigned char *ue_cont_res_id, - unsigned char short_padding, - unsigned short post_padding){return 0;} void nr_ip_over_LTE_DRB_preconfiguration(void){} -void mac_rlc_data_ind ( - const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - char *buffer_pP, - const tb_size_t tb_sizeP, - num_tb_t num_tbP, - crc_t *crcs_pP) -{} + // needed for some functions openair0_config_t openair0_cfg[MAX_CARDS]; diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c index 33bfc02f33..58bf213e3a 100644 --- a/openair1/SIMULATION/NR_PHY/pbchsim.c +++ b/openair1/SIMULATION/NR_PHY/pbchsim.c @@ -60,6 +60,7 @@ uint16_t NB_UE_INST = 1; // needed for some functions openair0_config_t openair0_cfg[MAX_CARDS]; +uint64_t get_softmodem_optmask(void) {return 0;} int main(int argc, char **argv) { diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c index dcc1b82426..adfb09ea6e 100644 --- a/openair1/SIMULATION/NR_PHY/ulsim.c +++ b/openair1/SIMULATION/NR_PHY/ulsim.c @@ -70,53 +70,12 @@ uint16_t NB_UE_INST = 1; // dummy functions int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, const int CC_id, const uint8_t gNB_index, const int8_t channel, const uint8_t* pduP, const sdu_size_t pdu_len) { return 0; } -void mac_rlc_data_ind ( const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - char *buffer_pP, - const tb_size_t tb_sizeP, - num_tb_t num_tbP, - crc_t *crcs_pP){} -mac_rlc_status_resp_t mac_rlc_status_ind( const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const sub_frame_t subframeP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - const tb_size_t tb_sizeP, - const uint32_t sourceL2Id, - const uint32_t destinationL2Id) -{mac_rlc_status_resp_t mac_rlc_status_resp = {0}; return mac_rlc_status_resp;} -tbs_size_t mac_rlc_data_req( const module_id_t module_idP, - const rnti_t rntiP, - const eNB_index_t eNB_index, - const frame_t frameP, - const eNB_flag_t enb_flagP, - const MBMS_flag_t MBMS_flagP, - const logical_chan_id_t channel_idP, - const tb_size_t tb_sizeP, - char *buffer_pP, - const uint32_t sourceL2Id, - const uint32_t destinationL2Id ) -{return 0;} -int generate_dlsch_header(unsigned char *mac_header, - unsigned char num_sdus, - unsigned short *sdu_lengths, - unsigned char *sdu_lcids, - unsigned char drx_cmd, - unsigned short timing_advance_cmd, - unsigned char *ue_cont_res_id, - unsigned char short_padding, - unsigned short post_padding){return 0;} uint64_t get_softmodem_optmask(void) {return 0;} -int rlc_module_init (int enb) {return(0);} +//int rlc_module_init (int enb) {return(0);} void pdcp_layer_init (void) {} +boolean_t pdcp_data_ind( const protocol_ctxt_t *const ctxt_pP, const srb_flag_t srb_flagP, const MBMS_flag_t MBMS_flagP, const rb_id_t rb_idP, + const sdu_size_t sdu_buffer_sizeP, mem_block_t *const sdu_buffer_pP) +{return (0);} void nr_ip_over_LTE_DRB_preconfiguration(void){} // needed for some functions From 0d6fabb9b6c7d9e62da3be44838856f46c1572d1 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Fri, 14 Feb 2020 15:46:40 +0100 Subject: [PATCH 18/73] CI: fixed the iperf analysis in 5G-RF-SIM now that we have UL also added the UL test for 5G-RF-SIM Signed-off-by: Raphael Defosseux --- ci-scripts/reportTestLocally.sh | 4 ++-- ci-scripts/runTestOnVM.sh | 38 ++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/ci-scripts/reportTestLocally.sh b/ci-scripts/reportTestLocally.sh index c4236a4e0e..72779e3824 100755 --- a/ci-scripts/reportTestLocally.sh +++ b/ci-scripts/reportTestLocally.sh @@ -730,8 +730,8 @@ function report_test { IPERF_TESTS=`ls $ARCHIVES_LOC/${TMODE}_${BW}prb_${CN_CONFIG}_iperf_dl*client*txt 2> /dev/null` analyzeIperfFiles - #IPERF_TESTS=`ls $ARCHIVES_LOC/${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_iperf_ul*client*txt 2> /dev/null` - #analyzeIperfFiles + IPERF_TESTS=`ls $ARCHIVES_LOC/${TMODE}_${BW}prb_${CN_CONFIG}_iperf_ul*client*txt 2> /dev/null` + analyzeIperfFiles done done done diff --git a/ci-scripts/runTestOnVM.sh b/ci-scripts/runTestOnVM.sh index e6440ffef9..d46ed07bbb 100755 --- a/ci-scripts/runTestOnVM.sh +++ b/ci-scripts/runTestOnVM.sh @@ -342,6 +342,7 @@ function check_iperf { local FILE_COMPLETE=`egrep -c "Server Report" ${LOC_BASE_LOG}_client.txt` if [ $FILE_COMPLETE -eq 0 ] then + # This part will become obsolete once we have UL if [[ $LOC_IS_RF_SIM -eq 1 ]] && [[ $LOC_IS_NR -eq 1 ]] then echo "no UL integration right now --> normal to have no server report" @@ -350,11 +351,11 @@ function check_iperf { local EFFECTIVE_BANDWIDTH=`tail -n1 ${LOC_BASE_LOG}_server.txt | sed -e "s#^.*MBytes *##" -e "s#^.*KBytes *##" -e "s#sec.*#sec#"` if [[ $2 =~ .*K.* ]] then - local BW_SUFFIX="K" + local BW_PREFIX="K" else - local BW_SUFFIX="M" + local BW_PREFIX="M" fi - if [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW}.*${BW_SUFFIX}bits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_ONE}.*${BW_SUFFIX}bits.* ]] + if [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW}.*${BW_PREFIX}bits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_ONE}.*${BW_PREFIX}bits.* ]] then echo "got requested DL bandwidth: $EFFECTIVE_BANDWIDTH" else @@ -370,10 +371,19 @@ function check_iperf { echo "File Report not found" fi else - local EFFECTIVE_BANDWIDTH=`tail -n3 ${LOC_BASE_LOG}_client.txt | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"` + if [ `egrep -c "Mbits/sec" ${LOC_BASE_LOG}_client.txt` -ne 0 ] + then + local EFFECTIVE_BANDWIDTH=`tail -n3 ${LOC_BASE_LOG}_client.txt | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"` + local BW_PREFIX="M" + fi + if [ `egrep -c "Kbits/sec" ${LOC_BASE_LOG}_client.txt` -ne 0 ] + then + local EFFECTIVE_BANDWIDTH=`tail -n3 ${LOC_BASE_LOG}_client.txt | egrep "Kbits/sec" | sed -e "s#^.*KBytes *##" -e "s#sec.*#sec#"` + local BW_PREFIX="K" + fi if [ $LOC_IS_DL -eq 1 ] && [ $LOC_IS_BASIC_SIM -eq 1 ] then - if [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW}.*Mbits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_ONE}.*Mbits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_TWO}.*Mbits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_THREE}.*Mbits.* ]] + if [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW}.*${BW_PREFIX}bits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_ONE}.*${BW_PREFIX}bits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_TWO}.*${BW_PREFIX}bits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_THREE}.*${BW_PREFIX}bits.* ]] then echo "got requested DL bandwidth: $EFFECTIVE_BANDWIDTH" else @@ -381,7 +391,7 @@ function check_iperf { IPERF_STATUS=-1 fi else - if [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW}.*Mbits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_ONE}.*Mbits.* ]] + if [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW}.*${BW_PREFIX}bits.* ]] || [[ $EFFECTIVE_BANDWIDTH =~ .*${LOC_REQ_BW_MINUS_ONE}.*${BW_PREFIX}bits.* ]] then if [ $LOC_IS_DL -eq 1 ] then @@ -390,7 +400,7 @@ function check_iperf { echo "got requested UL bandwidth: $EFFECTIVE_BANDWIDTH" fi else - echo "not basic-sim got LESS than requested DL bandwidth: $EFFECTIVE_BANDWIDTH" + echo "got LESS than requested DL bandwidth: $EFFECTIVE_BANDWIDTH" IPERF_STATUS=-1 fi fi @@ -2067,7 +2077,7 @@ function run_test_on_vm { fi echo "############################################################" - echo "${CN_CONFIG} : iperf DL -- UE is server and eNB is client" + echo "${CN_CONFIG} : iperf DL -- NR-UE is server and gNB is client" echo "############################################################" THROUGHPUT="30K" CURR_IPERF_LOG_BASE=tdd_${PRB}prb_${CN_CONFIG}_iperf_dl @@ -2078,6 +2088,18 @@ function run_test_on_vm { scp -o StrictHostKeyChecking=no ubuntu@$NR_UE_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE $THROUGHPUT + echo "############################################################" + echo "${CN_CONFIG} : iperf UL -- gNB is server and NR-UE is client" + echo "############################################################" + THROUGHPUT="30K" + CURR_IPERF_LOG_BASE=tdd_${PRB}prb_${CN_CONFIG}_iperf_ul + get_enb_noS1_ip_addr $GNB_VM_CMDS $GNB_VM_IP_ADDR + get_ue_ip_addr $NR_UE_VM_CMDS $NR_UE_VM_IP_ADDR 1 + generic_iperf $GNB_VM_CMDS $GNB_VM_IP_ADDR $ENB_IP_ADDR $NR_UE_VM_CMDS $NR_UE_VM_IP_ADDR $UE_IP_ADDR $THROUGHPUT $CURR_IPERF_LOG_BASE 1 0 + scp -o StrictHostKeyChecking=no ubuntu@$GNB_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_server.txt $ARCHIVES_LOC + scp -o StrictHostKeyChecking=no ubuntu@$NR_UE_VM_IP_ADDR:/home/ubuntu/${CURR_IPERF_LOG_BASE}_client.txt $ARCHIVES_LOC + check_iperf $ARCHIVES_LOC/$CURR_IPERF_LOG_BASE $THROUGHPUT + echo "############################################################" echo "${CN_CONFIG} : Terminate gNB/NR-UE simulators" echo "############################################################" From e454e59f614dc7e03cccdfcb04c125305e432fe6 Mon Sep 17 00:00:00 2001 From: Raphael Defosseux Date: Mon, 24 Feb 2020 15:21:37 +0100 Subject: [PATCH 19/73] CI: fixing the report on 5G NR RF simulation Signed-off-by: Raphael Defosseux --- ci-scripts/reportTestLocally.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci-scripts/reportTestLocally.sh b/ci-scripts/reportTestLocally.sh index 72779e3824..b74fe93a1f 100755 --- a/ci-scripts/reportTestLocally.sh +++ b/ci-scripts/reportTestLocally.sh @@ -112,7 +112,7 @@ function analyzeIperfFiles { echo " OK" >> ./test_simulator_results.html fi else - EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"` + EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "bits/sec" | sed -e "s#^.*Bytes *##" -e "s#sec.*#sec#"` if [[ $EFFECTIVE_BITRATE =~ .*Kbits/sec.* ]] then EFFECTIVE_BITRATE=`echo $EFFECTIVE_BITRATE | sed -e "s# *Kbits/sec.*##"` @@ -136,9 +136,9 @@ function analyzeIperfFiles { else echo " OK" >> ./test_simulator_results.html fi - EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*MBytes *##" -e "s#sec.*#sec#"` - JITTER=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*Mbits/sec *##" -e "s#ms.*#ms#"` - PACKETLOSS=`tail -n3 $IPERF_CASE | egrep "Mbits/sec" | sed -e "s#^.*(##" -e "s#).*##"` + EFFECTIVE_BITRATE=`tail -n3 $IPERF_CASE | egrep "bits/sec" | sed -e "s#^.*Bytes *##" -e "s#sec.*#sec#"` + JITTER=`tail -n3 $IPERF_CASE | egrep "bits/sec" | sed -e "s#^.*bits/sec *##" -e "s#ms.*#ms#"` + PACKETLOSS=`tail -n3 $IPERF_CASE | egrep "bits/sec" | sed -e "s#^.*(##" -e "s#).*##"` fi echo " " >> ./test_simulator_results.html echo "
" >> ./test_simulator_results.html

From 2c35740122ad94a3b5102544fd01029bf51d8142 Mon Sep 17 00:00:00 2001
From: frtabu 
Date: Tue, 25 Feb 2020 11:31:40 +0100
Subject: [PATCH 20/73] telnet server and iq record player documentation update

---
 common/utils/telnetsrv/DOC/telnetarch.md      |  18 +-
 common/utils/telnetsrv/DOC/telnetusage.md     |   2 +-
 .../ARCH/iqplayer/DOC/iqrecordplayer_usage.md | 161 ++++++++++++++++++
 3 files changed, 176 insertions(+), 5 deletions(-)
 create mode 100644 targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md

diff --git a/common/utils/telnetsrv/DOC/telnetarch.md b/common/utils/telnetsrv/DOC/telnetarch.md
index ebb2342c22..683b14a1b8 100644
--- a/common/utils/telnetsrv/DOC/telnetarch.md
+++ b/common/utils/telnetsrv/DOC/telnetarch.md
@@ -1,6 +1,15 @@
 # telnet server principles
 
-The oai telnet server is implemented in a shared library to be loaded by the [oai shared library loader](loader). The implementation includes a `telnetsrv_autoinit` function which is automatically called at load time, starts the telnet server and registers a first set of commands, which are delivered with the server (telnet, softmodem, loader).
+The oai telnet server is implemented in shared libraries to be loaded by the [oai shared library loader](loader). `libtelnetsrv.so ` contains the code common to all oai softmodem executables, where `libtelnetsrv_.so` contains the code specific to the executable identified by `app`. 
+
+| `` |    executable     |
+| :-----: | :---------------: |
+|   enb   |  `lte-softmodem`  |
+|   gnb   |  `nr-softmodem`   |
+|  4Gue   | `lte-uesoftmodem` |
+|  5Gue   | `nr-uesoftmodem`  |
+
+The implementation includes a `telnetsrv_autoinit` function which is automatically called at load time, starts the telnet server and registers a first set of commands, which are delivered with the server (telnet, softmodem, loader). it also uses the `get_softmodem_function` call to retrieve the running executable id and possibly loads the corresponding `libtelnetsrv_.so`library.
 
 Currently the telnet server only supports one user connection. The same dedicated thread is used to wait for a user connection and process the input received from this connection.
 
@@ -12,10 +21,11 @@ The telnet server provides an API which can be used by any oai component to add
 
 telnet server source files are located in [common/utils/telnetsrv](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/telnetsrv)
 
-1. [telnetsrv.c](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/telnetsrv/telnetsrv.c) contains the telnet server implementation, including the implementation of the telnet CLI command.
+1. [telnetsrv.c](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/telnetsrv/telnetsrv.c) contains the telnet server implementation, including the implementation of the `telnet` CLI command. This implementation is compatible with all softmodem executables and is in charge of loading any additional `libtelnetsrv_ .so` containing code specific to the running executables.
 1.  [telnetsrv.h](https://gitlab.eurecom.fr/oai/openairinterface5g/tree/develop/common/utils/telnetsrv/telnetsrv.h) is the telnet server include file containing both private and public data type definitions. It also contains API prototypes for functions that are used to register a new command in the server.
-1.  `telnetsrv\_\.c`: implementation of \ CLI command which are delivered with the telnet server.
-1.  `telnetsrv\_\.h`: include file for the implementation of XXX CLI command. Usually included only in the corresponding `.c`file
+1.  `telnetsrv_.c`: implementation of \ CLI command which are delivered with the telnet server and are common to all softmodem executables. 
+1. `telnetsrv_.h`: include file for the implementation of XXX CLI command. Usually included only in the corresponding `.c`file
+1.  `telnetsrv__.c`: implementation of \ CLI command specific to the executable identified by \.These sources are used to create `libtelnetsrv_.so` at build time.
 1.  [telnetsrv_CMakeLists.txt](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/common/utils/telnetsrv/telnetsrv_CMakeLists.txt): CMakelists file containing the cmake instructions to build the telnet server. this file is included in the [global oai CMakelists](https://gitlab.eurecom.fr/oai/openairinterface5g/blob/develop/cmake_targets/CMakeLists.txt).
 
 [oai telnet server home](telnetsrv.md)
diff --git a/common/utils/telnetsrv/DOC/telnetusage.md b/common/utils/telnetsrv/DOC/telnetusage.md
index ec49deec73..c4777ce0d8 100644
--- a/common/utils/telnetsrv/DOC/telnetusage.md
+++ b/common/utils/telnetsrv/DOC/telnetusage.md
@@ -8,7 +8,7 @@ By default the embedded telnet server, which is implemented in a shared library,
  ./build_oai  --build-lib telnetsrv
 ```
 
-This will create the `libtelnetsrv.so` file in the `targets/bin` and `cmake_targets/ran_build/build` sub directories of the oai repository.
+This will create the `libtelnetsrv.so` and `libtelnetsrv_ file in the `targets/bin` and `cmake_targets/ran_build/build` sub directories of the oai repository.  can be "enb", "gnb", "4GUE" or "5GUE", each library containing functions specific to a given executable.
 
 When starting the softmodem, you must specify the **_\-\-telnetsrv_** option to load and start the telnet server. The telnet server is loaded via the [oai shared library loader](loader).
 
diff --git a/targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md b/targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md
new file mode 100644
index 0000000000..856e2ea27c
--- /dev/null
+++ b/targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md
@@ -0,0 +1,161 @@
+#I/Q record-playback
+## using the iq recorder or iq player
+
+This feature provides I/Q record-playback as presented in the 4th OAI workshop. Tests have only been performed with a eNB, but the implementation should allow any softmodem executable to use the iq's record/player.
+The I/Q record/playback feature is briefly described hereafter, it allows you to:
+* record subframes received by the USRP board in a file while the system is operating (for example you can record a full UE connection/traffic/ disconnection sequence). Today the oai USRP device is the only one supporting the recording feature. 
+* replay subframes from a file to operate the system (possibly in multiple loops if the recorded sequence is convenient from the logical point of view). 
+
+The record/replay  are activated and configured using oai configuration parameters
+
+###Record mode
+options for record mode are:
+* `subframes-record` Activate record mode
+* `subframes-file` Path of the file used for subframes recording (default is `/tmp/iqfile`)
+* `subframes-max` Maximum count of subframes to be recorded in subframe file (default is 120000)
+
+Note that the value of --subframes-max parameter needs to be tuned according to your RAM capabilities. The default value is 120000, which allows for 120 seconds of record/replay but will require ~3.6GB of RAM and disk space. If RAM does not allow for the parameter value, an error message will be displayed and the run will be aborted. In record mode, subframes are copied in specific memory records not to disrupt regular behavior. When you estimate the recorded sequence is achieved, you should terminate the eNB/RRU by typing `CTRL-C`. At that time, up to the value of --subframes-max parameter will be written on disk. The eNB/RRU will indicate the exact count of subframes written to disk, which may be less (but not higher) that the value of --subframes-max parameter (120000 by default). The number of subframes written to disk is rounded to an integral number of frames. When replaying a file you should always specify the exact number of subframes, and thus use the exact number of subframes written during recording. You might experiment unexpected behavior if the number of subframes to be replayed does not match the number of subframes recorded. This might be improved in the future.
+Although it is possible to perform recording with a fronthaul setup, it is suggested to perform recording in full eNB mode and then replay in either full or split eNB.
+The option can be used while operating full eNB or RCC/RRU linked by NGFI IF5/IF4p5 fronthaul techniques. One of the advantage of the record/replay technique is that you can replay on a fronthauling setup a file that has been recorded in full eNB mode. This can easily asserts that the fronthauling underlying set up or technique is correct.
+
+>recording session example:
+```bash
+ ./lte-softmodem -O libconfig:/usr/local/oai/conf/enb.band7.tm1.20PRB.usrpb210.conf:dbgl5    --log_config.global_log_options level,thread   --device.recplay.subframes-record 1
+............................................
+............................................
+[CONFIG] device.recplay.subframes-file set to default value "/tmp/iqfile"
+[CONFIG] subframes-record: 0
+[CONFIG] device.recplay.subframes-record set to default value
+[CONFIG] subframes-replay: 0
+[CONFIG] device.recplay.subframes-replay set to default value
+[CONFIG] subframes-max: 120000
+[CONFIG] device.recplay.subframes-max set to default value
+[CONFIG] subframes-loops: 5
+[CONFIG] device.recplay.subframes-loops set to default value
+[CONFIG] subframes-read-delay: 700
+[CONFIG] device.recplay.subframes-read-delay set to default value
+[CONFIG] subframes-write-delay: 15
+[CONFIG] device.recplay.subframes-write-delay set to default value
+[LIBCONFIG] device.recplay: 7/7 parameters successfully set, (7 to default value)
+[CONFIG] subframes-record: 1
+[CONFIG] device.recplay 1 options set from command line
+[CONFIG] loader.oai_device.shlibversion set to default value ""
+[LIBCONFIG] loader.oai_device: 2/2 parameters successfully set, (1 to default value)
+[CONFIG] loader.oai_device 0 options set from command line
+[LOADER] library liboai_device.so successfully loaded
+USRP device initialized in subframes record mode
+[HW]I lte-softmodem UHD version 3.14.1.1-release (3.14.1)
+...................................................
+...................................................
+[PHY]I lte-softmodem prach_I0 = 0.0 dB
+[PHY]I ru thread max_I0 18, min_I0 12
+^C
+Run time: 0h 26s
+	Time executing user inst.: 1s 865251us
+	Time executing system inst.: 2s 805162us
+	Max. Phy. memory usage: 4068328kB
+	Page fault number (no io): 1008741
+	Page fault number (requiring io): 15
+	Number of file system read: 97672
+	Number of filesystem write: 0
+	Number of context switch (process origin, io...): 562871
+	Number of context switch (os origin, priority...): 112
+Linux signal Interrupt...
+/usr/local/oai/develop/openairinterface5g/executables/softmodem-common.c:188 signal_handler() Exiting OAI softmodem: softmodem starting exit procedure
+Exiting ru_thread 
+U[HW]I ru thread Writing file header to /tmp/iqfile 
+[HW]I lte-softmodem Writing file header to /tmp/iqfile 
+[HW]I ru thread Writing 19730 subframes to /tmp/iqfile 
+[HW]I lte-softmodem Writing 19730 subframes to /tmp/iqfile 
+[HW]I lte-softmodem File /tmp/iqfile closed
+[HW]I ru thread File /tmp/iqfile closed
+[PHY]I ru thread RU 0 rf device stopped
+```
+
+###Playback/replay mode
+The option works only for 5MHz bandwidth because the information stored in the iq's file header regarding bandwidth is not yet properly processed. 
+ In this version,  mismatch between file content and run time parameters might lead to unpredictable results. In addition a file recorded on a AVX2-capable processor cannot be replayed on a non-AVX2-capable processor (this is to be further investigated).
+options for replay mode are:
+* `subframes-replay` Activate replay mode
+* `subframes-file` Path of the file used for subframes replay (default is `/tmp/iqfile`)
+* `subframes-loops` Number of iterations to replay the entire subframes file (default is 5)
+* `subframes-read-delay` Delay in microseconds to read a subframe in replay mode (default 200)
+* `subframes-write-delay` Delay in milliseconds to write a subframe in replay mode (default 15)
+
+>iq player session example:
+```bash
+./lte-softmodem -O libconfig:/usr/local/oai/conf/enb.nbiot.band7.tm1.50PRB.usrpb210.conf:dbgl5  --T_stdout 1   --log_config.global_log_options level,thread --eNBs.[0].component_carriers.[0].N_RB_DL 25   --device.recplay.subframes-replay 1
+[CONFIG] get parameters from libconfig /usr/local/oai/conf/enb.nbiot.band7.tm1.50PRB.usrpb210.conf , debug flags: 0x00000005
+................................
+..................................
+[PHY]I lte-softmodem rxdataF[0] 0x55f52df52f40 for RU 0
+[CONFIG] device.recplay.subframes-file set to default value "/tmp/iqfile"
+[CONFIG] subframes-record: 0
+[CONFIG] device.recplay.subframes-record set to default value
+[CONFIG] subframes-replay: 0
+[CONFIG] device.recplay.subframes-replay set to default value
+[CONFIG] subframes-max: 120000
+[CONFIG] device.recplay.subframes-max set to default value
+[CONFIG] subframes-loops: 5
+[CONFIG] device.recplay.subframes-loops set to default value
+[CONFIG] subframes-read-delay: 700
+[CONFIG] device.recplay.subframes-read-delay set to default value
+[CONFIG] subframes-write-delay: 15
+[CONFIG] device.recplay.subframes-write-delay set to default value
+[LIBCONFIG] device.recplay: 7/7 parameters successfully set, (7 to default value)
+[CONFIG] subframes-replay: 1
+[CONFIG] device.recplay 1 options set from command line
+[CONFIG] loader.oai_iqplayer.shlibversion set to default value ""
+[LIBCONFIG] loader.oai_iqplayer: 2/2 parameters successfully set, (1 to default value)
+[CONFIG] loader.oai_iqplayer 0 options set from command line
+[LOADER] library liboai_iqplayer.so successfully loaded
+[HW]I lte-softmodem Loading subframes using mmap() from /tmp/iqfile size=324433632 bytes ...
+[HW]I lte-softmodem Replay iqs from USRP B200 device, bandwidth 5.000000e+06
+[HW]I lte-softmodem Loaded 10550 subframes.
+[HW]I lte-softmodem iqplayer device initialized, replay /tmp/iqfile  for 5 iterations[HW]I lte-softmodem [RAU] has loaded USRP B200 device.
+.............................................
+.............................................
+[PHY]I ru thread max_I0 18, min_I0 12
+[PHY]I lte-softmodem prach_I0 = 0.0 dB
+[PHY]I ru thread max_I0 18, min_I0 0
+[HW]I ru thread starting subframes file with wrap_count=1 wrap_ts=81024000 ts=107616555
+[PHY]I lte-softmodem prach_I0 = 0.0 dB
+[PHY]I ru thread max_I0 18, min_I0 12
+[HW]I ru thread starting subframes file with wrap_count=2 wrap_ts=162048000 ts=188640555
+[PHY]I lte-softmodem prach_I0 = 0.0 dB
+[PHY]I ru thread max_I0 18, min_I0 0
+[HW]I ru thread starting subframes file with wrap_count=3 wrap_ts=243072000 ts=269664555
+[PHY]I lte-softmodem prach_I0 = 0.0 dB
+[PHY]I ru thread max_I0 19, min_I0 12
+[HW]I ru thread starting subframes file with wrap_count=4 wrap_ts=324096000 ts=350688555
+[PHY]I lte-softmodem prach_I0 = 0.0 dB
+[PHY]I ru thread max_I0 18, min_I0 12
+[HW]W ru thread iqplayer device terminating subframes replay  after 5 iteration
+/usr/local/oai/develop/openairinterface5g/targets/ARCH/iqplayer/iqplayer_lib.c:222 trx_iqplayer_read() Exiting OAI softmodem: replay ended, triggering process termination
+```
+
+## iq recorder and iq player implementation overview
+
+###configuration
+The iq's record/player is using the [configuration module](../../../../common/config/DOC/config.md). Configuration parameters supported by the record player are defined in the [record_player.h](../../COMMON/record_player.h) include file.
+ There are no specific sections for the recorder or the replayer, parameters are defined under the `device.recplay`section and the `read_recplayconfig` function is common to both the recorder and the player. `device.recplay` configuration section is read from oai code common to all devices:
+Implemented in [record_player.c](../../COMMON/record_player.c), the `read_recplayconfig` function is called from `load_lib` and reads the configuration parameters, saving them in a `recplay_conf_t` sub-structure of the oai device. It also allocates a `recplay_state_t` structure which will save the recorder or player data. 
+3GPP authentication algorithm doesn't allow session establishment via replaying iq's. When using the replayer, a softmodem parameter is set (`SOFTMODEM_RECPLAY_BIT` in the `optmask` bitmask of the `softmodem_params_t` structure. It allows bypassing or activating specific code in the softmodem to allow session establishment replay. This mechanism only works if in parallel specific code is also activated in the EPC, which is supported by the NOKIA LTE box.
+An easiest scenario is to use the record player in parallel with the noS1 mode, as described [here](../../../../doc/RUNMODEM.md) 
+
+### iq recorder
+most of the implementation is now located in the oai device common code:
+* The`load_lib` function in [common-lib.c](../../COMMON/common_lib.c) reads the record player parameters. 
+* Recorder specific functions are implemented in  `iqrecorder_end` saves the cached iq's to disk, it has to be called by the oai device in it's end function.
+* When recording is enabled, the device must implement iq's caching in it's read function. It also has to call the `iqrecorder_end ` function when  terminating to write iqs to a file on disk. Look at the USRP device ( [../usrp_lib.cpp](../../USRP/USERSPACE/LIB/usrp_lib.cpp) ) for  details.
+
+### iq player
+The replay feature is implemented as a oai device. 
+* The`load_lib` function in [common-lib.c](../../COMMON/common_lib.c) reads the record player parameters, this code is common with the recorder.
+* The player device is implemented in  [iqplayer_lib.c](../iqplayer_lib.c) which at build time creates the `liboai_iqplayer.so` shared library. Thi
+* s device is automatically, dynamicaly loaded when the player feature is activated at runtime when the boolean  `device.recplay.subframes-replay` option is set.
+
+### iq's file format
+The recorder adds a header containing the device type, the bandwith and a format identifier. Using these information when replaying a file has not yet been implemented, so the player only supports USRP B2xx device and 5MHz bandwith. 
+
+[oai Wikis home](https://gitlab.eurecom.fr/oai/openairinterface5g/wikis/home)

From dd7e48ca694a112dcc2e29b66352d9ccb8ded986 Mon Sep 17 00:00:00 2001
From: Francois TABURET 
Date: Tue, 25 Feb 2020 16:06:37 +0100
Subject: [PATCH 21/73] Fixes typo discovered when reviewing from gitlab

---
 targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md b/targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md
index 856e2ea27c..a6e4138e8e 100644
--- a/targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md
+++ b/targets/ARCH/iqplayer/DOC/iqrecordplayer_usage.md
@@ -1,4 +1,4 @@
-#I/Q record-playback
+# I/Q record-playback
 ## using the iq recorder or iq player
 
 This feature provides I/Q record-playback as presented in the 4th OAI workshop. Tests have only been performed with a eNB, but the implementation should allow any softmodem executable to use the iq's record/player.
@@ -8,14 +8,16 @@ The I/Q record/playback feature is briefly described hereafter, it allows you to
 
 The record/replay  are activated and configured using oai configuration parameters
 
-###Record mode
+### Record mode
 options for record mode are:
 * `subframes-record` Activate record mode
 * `subframes-file` Path of the file used for subframes recording (default is `/tmp/iqfile`)
 * `subframes-max` Maximum count of subframes to be recorded in subframe file (default is 120000)
 
-Note that the value of --subframes-max parameter needs to be tuned according to your RAM capabilities. The default value is 120000, which allows for 120 seconds of record/replay but will require ~3.6GB of RAM and disk space. If RAM does not allow for the parameter value, an error message will be displayed and the run will be aborted. In record mode, subframes are copied in specific memory records not to disrupt regular behavior. When you estimate the recorded sequence is achieved, you should terminate the eNB/RRU by typing `CTRL-C`. At that time, up to the value of --subframes-max parameter will be written on disk. The eNB/RRU will indicate the exact count of subframes written to disk, which may be less (but not higher) that the value of --subframes-max parameter (120000 by default). The number of subframes written to disk is rounded to an integral number of frames. When replaying a file you should always specify the exact number of subframes, and thus use the exact number of subframes written during recording. You might experiment unexpected behavior if the number of subframes to be replayed does not match the number of subframes recorded. This might be improved in the future.
-Although it is possible to perform recording with a fronthaul setup, it is suggested to perform recording in full eNB mode and then replay in either full or split eNB.
+Note that the value of `--subframes-max` parameter needs to be tuned according to your RAM capabilities. The default value is 120000, which allows for 120 seconds of record/replay but will require ~3.6GB of RAM and disk space. 
+If RAM does not allow for the parameter value, an error message will be displayed and the run will be aborted. In record mode, to minimize pzerformance impact, 
+subframes are saved into memory and written to disk when the process is terminating . When you estimate the recorded sequence is achieved, you should terminate the eNB/RRU by typing `CTRL-C`. At that time, up to the value of `--subframes-max` subframes will be written on disk. The eNB/RRU will indicate the exact count of subframes written to disk, which may be less (but not higher) that the value of `--subframes-max` parameter (120000 by default). The number of subframes written to disk is rounded to an integral number of frames. 
+Although it is possible to perform recording with a fronthaul setup, it is suggested to perform recording in full eNB mode and then replay in either monolithic or split eNB.
 The option can be used while operating full eNB or RCC/RRU linked by NGFI IF5/IF4p5 fronthaul techniques. One of the advantage of the record/replay technique is that you can replay on a fronthauling setup a file that has been recorded in full eNB mode. This can easily asserts that the fronthauling underlying set up or technique is correct.
 
 >recording session example:
@@ -72,7 +74,7 @@ U[HW]I ru thread Writing file header to /tmp/iqfile
 [PHY]I ru thread RU 0 rf device stopped
 ```
 
-###Playback/replay mode
+### Playback/replay mode
 The option works only for 5MHz bandwidth because the information stored in the iq's file header regarding bandwidth is not yet properly processed. 
  In this version,  mismatch between file content and run time parameters might lead to unpredictable results. In addition a file recorded on a AVX2-capable processor cannot be replayed on a non-AVX2-capable processor (this is to be further investigated).
 options for replay mode are:
@@ -136,7 +138,7 @@ options for replay mode are:
 
 ## iq recorder and iq player implementation overview
 
-###configuration
+### configuration
 The iq's record/player is using the [configuration module](../../../../common/config/DOC/config.md). Configuration parameters supported by the record player are defined in the [record_player.h](../../COMMON/record_player.h) include file.
  There are no specific sections for the recorder or the replayer, parameters are defined under the `device.recplay`section and the `read_recplayconfig` function is common to both the recorder and the player. `device.recplay` configuration section is read from oai code common to all devices:
 Implemented in [record_player.c](../../COMMON/record_player.c), the `read_recplayconfig` function is called from `load_lib` and reads the configuration parameters, saving them in a `recplay_conf_t` sub-structure of the oai device. It also allocates a `recplay_state_t` structure which will save the recorder or player data. 

From 795f25bb17c238fb4ba8fdb0508cc45b82a7bf44 Mon Sep 17 00:00:00 2001
From: Raphael Defosseux 
Date: Mon, 2 Mar 2020 14:38:26 +0100
Subject: [PATCH 22/73] CI: new new method to run simulated HSS

Signed-off-by: Raphael Defosseux 
---
 ci-scripts/main.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/ci-scripts/main.py b/ci-scripts/main.py
index e122339269..95360cae8f 100644
--- a/ci-scripts/main.py
+++ b/ci-scripts/main.py
@@ -674,7 +674,8 @@ class SSHConnection():
 			self.command('mkdir -p ' + self.EPCSourceCodePath + '/scripts', '\$', 5)
 			self.command('cd /opt/hss_sim0609', '\$', 5)
 			self.command('echo ' + self.EPCPassword + ' | sudo -S rm -f hss.log daemon.log', '\$', 5)
-			self.command('echo ' + self.EPCPassword + ' | sudo -S echo "Starting sudo session" && sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real  ', '\$', 5)
+			# based on Robert's feedback, new method to run simulated HSS
+			self.command('sudo su -c "cd /opt/hss_sim0609 && screen -dm -S simulated_hss ./starthss_real"', '\$', 5)
 		else:
 			logging.error('This option should not occur!')
 		self.close()

From a07a830a0fcabf08e4c831cb1a7f9ac6a7080022 Mon Sep 17 00:00:00 2001
From: Thomas Dreibholz 
Date: Tue, 3 Mar 2020 10:26:14 +0100
Subject: [PATCH 23/73] Check result of openair0_device_load() and exit when
 loading the device fails.

---
 targets/RT/USER/lte-ru.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index f88d98536d..aa359b28a9 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -2342,7 +2342,11 @@ void init_RU_proc(RU_t *ru) {
     init_frame_parms(ru->frame_parms,1);
     ru->frame_parms->nb_antennas_rx = ru->nb_rx;
     phy_init_RU(ru);
-    openair0_device_load(&ru->rfdevice,&ru->openair0_cfg);
+    ret = openair0_device_load(&ru->rfdevice,&ru->openair0_cfg);
+    if (ret < 0) {
+       LOG_I(PHY,"Exiting, cannot load device\n");
+       exit(1);
+    }
 
     if (setup_RU_buffers(ru)!=0) {
       printf("Exiting, cannot initialize RU Buffers\n");

From 04789ff9f50c2250707280bfa588b2360a082884 Mon Sep 17 00:00:00 2001
From: Thomas Dreibholz 
Date: Tue, 3 Mar 2020 10:37:38 +0100
Subject: [PATCH 24/73] Made error message more informative.

---
 targets/RT/USER/lte-ru.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index aa359b28a9..43cb414bd3 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -2344,7 +2344,7 @@ void init_RU_proc(RU_t *ru) {
     phy_init_RU(ru);
     ret = openair0_device_load(&ru->rfdevice,&ru->openair0_cfg);
     if (ret < 0) {
-       LOG_I(PHY,"Exiting, cannot load device\n");
+       LOG_I(PHY,"Exiting, cannot load device. Make sure that your SDR board is connected!\n");
        exit(1);
     }
 

From 34c118c03e75059b0c6fd5207c403eec708e63ec Mon Sep 17 00:00:00 2001
From: Thomas Dreibholz 
Date: Tue, 3 Mar 2020 10:29:29 +0100
Subject: [PATCH 25/73] Error should create a log entry, not use printf().

---
 targets/RT/USER/lte-ru.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index 43cb414bd3..fa08d96b5f 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -2349,8 +2349,8 @@ void init_RU_proc(RU_t *ru) {
     }
 
     if (setup_RU_buffers(ru)!=0) {
-      printf("Exiting, cannot initialize RU Buffers\n");
-      exit(-1);
+      LOG_I(PHY,"Exiting, cannot initialize RU Buffers\n");
+      exit(1);
     }
   }
 

From a51dc94e8bed5a8cf6839ced6bbddceb5e9374cc Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Tue, 3 Mar 2020 19:18:49 +0100
Subject: [PATCH 26/73] Set correct UE ID in Kenb Refresh Req

NAS triggered the Kenb Refresh Req always for (hardcoded) UE 0. This
fixes this by setting the correct UE ID.

An effect of this was that the Kenb would always be set for UE 0,
regardless for which UE it was actually intended. This led for integrity
check failures for every UE with ID > 0.
---
 openair3/NAS/UE/EMM/SecurityModeControl.c | 2 +-
 openair3/NAS/UE/nas_itti_messaging.c      | 4 ++--
 openair3/NAS/UE/nas_itti_messaging.h      | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/openair3/NAS/UE/EMM/SecurityModeControl.c b/openair3/NAS/UE/EMM/SecurityModeControl.c
index 7bdd21572e..67bfaf784e 100644
--- a/openair3/NAS/UE/EMM/SecurityModeControl.c
+++ b/openair3/NAS/UE/EMM/SecurityModeControl.c
@@ -286,7 +286,7 @@ int emm_proc_security_mode_command(nas_user_t *user, int native_ksi, int ksi,
       user->emm_data->security->selected_algorithms.encryption = seea;
       user->emm_data->security->selected_algorithms.integrity  = seia;
 #if  defined(NAS_BUILT_IN_UE)
-      nas_itti_kenb_refresh_req(security_data->kenb.value);
+      nas_itti_kenb_refresh_req(security_data->kenb.value, user->ueid);
 #endif
 
     }
diff --git a/openair3/NAS/UE/nas_itti_messaging.c b/openair3/NAS/UE/nas_itti_messaging.c
index 55566700d7..885ebbdd81 100644
--- a/openair3/NAS/UE/nas_itti_messaging.c
+++ b/openair3/NAS/UE/nas_itti_messaging.c
@@ -100,7 +100,7 @@ int nas_itti_protected_msg(const char *buffer, const nas_message_t *msg, const i
 
 extern unsigned char NB_eNB_INST;
 
-int nas_itti_kenb_refresh_req(const Byte_t kenb[32]) {
+int nas_itti_kenb_refresh_req(const Byte_t kenb[32], int user_id) {
   MessageDef *message_p;
   message_p = itti_alloc_new_message(TASK_NAS_UE, NAS_KENB_REFRESH_REQ);
   memcpy(NAS_KENB_REFRESH_REQ(message_p).kenb, kenb, sizeof(NAS_KENB_REFRESH_REQ(message_p).kenb));
@@ -125,7 +125,7 @@ int nas_itti_kenb_refresh_req(const Byte_t kenb[32]) {
     kenb[20], kenb[21], kenb[22], kenb[23],
     kenb[24], kenb[25], kenb[26], kenb[27],
     kenb[28], kenb[29], kenb[30], kenb[31]);
-  return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + 0 /* TODO to be virtualized */, message_p);
+  return itti_send_msg_to_task(TASK_RRC_UE, NB_eNB_INST + user_id, message_p);
 }
 
 int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id) {
diff --git a/openair3/NAS/UE/nas_itti_messaging.h b/openair3/NAS/UE/nas_itti_messaging.h
index d958317e5a..967bbb3059 100644
--- a/openair3/NAS/UE/nas_itti_messaging.h
+++ b/openair3/NAS/UE/nas_itti_messaging.h
@@ -48,7 +48,7 @@ int nas_itti_protected_msg(
 
 # if defined(NAS_BUILT_IN_UE)
 
-int nas_itti_kenb_refresh_req(const Byte_t kenb[32]);
+int nas_itti_kenb_refresh_req(const Byte_t kenb[32], int user_id);
 
 int nas_itti_cell_info_req(const plmn_t plmnID, const Byte_t rat, int user_id);
 

From 05577be422c3324c6cdfe40ea9f9807ba9c5ae89 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Wed, 4 Mar 2020 09:58:00 +0100
Subject: [PATCH 27/73] Reduce logging verbosity and levels

---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 8 ++++----
 openair3/NAS/COMMON/UTIL/nas_log.h   | 9 +++++----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 14974c2e15..4b331c1cb0 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -209,8 +209,8 @@ void fill_rach_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL
 	    UL_INFO->rach_ind.rach_indication_body.preamble_list[0].instance_length					 = 0;
 
 
-	          LOG_E(PHY,"\n\n\n\nDJP - this needs to be sent to VNF **********************************************\n\n\n\n");
-	          LOG_E(PHY,"UE Filling NFAPI indication for RACH : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
+	          //LOG_E(PHY,"\n\n\n\nDJP - this needs to be sent to VNF **********************************************\n\n\n\n");
+	          LOG_I(PHY,"UE Filling NFAPI indication for RACH : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
 	        	  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.timing_advance,
 	        	  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.preamble,
 	        	  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.rnti,
@@ -685,7 +685,7 @@ int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) //,
 				if((dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index >= 0) &&(dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index <= tx_req_num_elems -1)){
 				//if(tx_request_pdu_list + dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index!= NULL){
 
-					LOG_E(MAC, "dl_config_req_UE_MAC 2 Received data: sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d, tx_req_num_elems: %d \n", NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size, dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_num_elems);
+					LOG_I(MAC, "dl_config_req_UE_MAC 2 Received data: sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d, tx_req_num_elems: %d \n", NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size, dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_num_elems);
 
 					ue_send_sdu(Mod_id, 0, sfn, sf,
 							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data,
@@ -699,7 +699,7 @@ int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) //,
 				}
 			}
 			else {
-				LOG_E(MAC,"[UE %d] Frame %d, subframe %d : DLSCH PDU from NFAPI not for this UE \n",Mod_id, sfn,sf);
+				LOG_W(MAC,"[UE %d] Frame %d, subframe %d : DLSCH PDU from NFAPI not for this UE \n",Mod_id, sfn,sf);
 				i++;
 			}
 		}
diff --git a/openair3/NAS/COMMON/UTIL/nas_log.h b/openair3/NAS/COMMON/UTIL/nas_log.h
index b41e34c51b..d1531fa6db 100644
--- a/openair3/NAS/COMMON/UTIL/nas_log.h
+++ b/openair3/NAS/COMMON/UTIL/nas_log.h
@@ -95,14 +95,15 @@ typedef enum {
 /******************  E X P O R T E D    F U N C T I O N S  ******************/
 /****************************************************************************/
 
+#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
 #ifdef LOG_E
 # define LOG_TRACE(s, x, args...)                               \
 do {                                                            \
     switch (s) {                                                \
-        case ERROR:     LOG_E(NAS, " %s:%d  " x "\n", __FILE__, __LINE__, ##args); break;  \
-        case WARNING:   LOG_W(NAS, " %s:%d  " x "\n", __FILE__, __LINE__, ##args); break;  \
-        case INFO:      LOG_I(NAS, " %s:%d  " x "\n", __FILE__, __LINE__, ##args); break;  \
-        default:        LOG_D(NAS, " %s:%d  " x "\n", __FILE__, __LINE__, ##args); break;  \
+        case ERROR:     LOG_E(NAS, " %s:%d  " x "\n", __FILENAME__, __LINE__, ##args); break;  \
+        case WARNING:   LOG_W(NAS, " %s:%d  " x "\n", __FILENAME__, __LINE__, ##args); break;  \
+        case INFO:      LOG_I(NAS, " %s:%d  " x "\n", __FILENAME__, __LINE__, ##args); break;  \
+        default:        LOG_D(NAS, " %s:%d  " x "\n", __FILENAME__, __LINE__, ##args); break;  \
     }                                                           \
 } while (0)
 

From e72e1d87f2b45f0f22cf152b255f1c451a994a7c Mon Sep 17 00:00:00 2001
From: adk 
Date: Mon, 3 Feb 2020 17:02:30 +0100
Subject: [PATCH 28/73] added PUSCH PTRS structs (UE + gNB) and parameters
 initialization

---
 openair1/PHY/INIT/nr_init.c                   | 19 ++++++++++--
 openair1/PHY/INIT/nr_init_ue.c                | 25 ++++++++++++++--
 .../NR_ESTIMATION/nr_ul_channel_estimation.c  |  2 +-
 openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c    |  2 +-
 .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c  | 10 +++----
 openair1/PHY/NR_UE_TRANSPORT/dci_nr.c         |  2 +-
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c    | 12 ++++----
 openair1/PHY/defs_gNB.h                       |  5 ++--
 openair1/PHY/defs_nr_UE.h                     |  4 ++-
 openair1/PHY/impl_defs_nr.h                   | 30 +++++++++++++++++--
 openair1/SCHED_NR/phy_procedures_nr_gNB.c     |  4 +--
 11 files changed, 87 insertions(+), 28 deletions(-)

diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index f0ad3cbaae..f10a7426dd 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -85,6 +85,8 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
   nfapi_nr_config_request_t *cfg    = &gNB->gNB_config;
   NR_gNB_COMMON *const common_vars  = &gNB->common_vars;
   NR_gNB_PUSCH **const pusch_vars   = gNB->pusch_vars;
+  dmrs_UplinkConfig_t *dmrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig;
+  ptrs_UplinkConfig_t *ptrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
   /*LTE_eNB_SRS *const srs_vars       = gNB->srs_vars;
   LTE_eNB_PRACH *const prach_vars   = &gNB->prach_vars;*/
 
@@ -154,9 +156,9 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
   }
 
   //------------- config PUSCH DMRS parameters(to be updated from RRC)--------------//
-  gNB->dmrs_UplinkConfig.pusch_dmrs_type = pusch_dmrs_type1;
-  gNB->dmrs_UplinkConfig.pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
-  gNB->dmrs_UplinkConfig.pusch_maxLength = pusch_len1;
+  dmrs_Uplink_Config->pusch_dmrs_type = pusch_dmrs_type1;
+  dmrs_Uplink_Config->pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
+  dmrs_Uplink_Config->pusch_maxLength = pusch_len1;
   //--------------------------------------------------------------------------------//
 
   nr_init_pdsch_dmrs(gNB, cfg->sch_config.physical_cell_id.value);
@@ -168,6 +170,17 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
     gNB->pusch_config.pusch_TimeDomainResourceAllocation[i]->mappingType = typeB;
   }
 
+  gNB->ptrs_configured = 0;
+
+  //------------- config PUSCH PTRS parameters(to be updated from RRC)--------------//
+  ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
+  ptrs_Uplink_Config->timeDensity.ptrs_mcs2 = 0;
+  ptrs_Uplink_Config->timeDensity.ptrs_mcs3 = 0;
+  ptrs_Uplink_Config->frequencyDensity.n_rb0 = 0;     // setting N_RB values to 0 indicate abscence of frequency_density field in the configuration
+  ptrs_Uplink_Config->frequencyDensity.n_rb1 = 0;
+  ptrs_Uplink_Config->resourceElementOffset = 0;
+  //--------------------------------------------------------------------------------//
+
   /// Transport init necessary for NR synchro
   init_nr_transport(gNB);
 
diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index 461f441b2c..7b7954583d 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -659,6 +659,8 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
   abstraction_flag = 0;
   fp->nb_antennas_tx = 1;
   fp->nb_antennas_rx=1;
+  dmrs_UplinkConfig_t *dmrs_Uplink_Config = &ue->pusch_config.dmrs_UplinkConfig;
+  ptrs_UplinkConfig_t *ptrs_Uplink_Config = &ue->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
   printf("Initializing UE vars (abstraction %"PRIu8") for eNB TXant %"PRIu8", UE RXant %"PRIu8"\n",abstraction_flag,fp->nb_antennas_tx,fp->nb_antennas_rx);
   //LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_UE][MOD %02u][]\n", ue->Mod_id+NB_eNB_INST);
   nr_init_frame_parms_ue(fp,NR_MU_1,NORMAL,fp->N_RB_DL,n_ssb_crb,k_ssb);
@@ -711,9 +713,9 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
   }
 
   //------------- config DMRS parameters--------------//
-  ue->dmrs_UplinkConfig.pusch_dmrs_type = pusch_dmrs_type1;
-  ue->dmrs_UplinkConfig.pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
-  ue->dmrs_UplinkConfig.pusch_maxLength = pusch_len1;
+  dmrs_Uplink_Config->pusch_dmrs_type = pusch_dmrs_type1;
+  dmrs_Uplink_Config->pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
+  dmrs_Uplink_Config->pusch_maxLength = pusch_len1;
   //-------------------------------------------------//
   ue->dmrs_DownlinkConfig.pdsch_dmrs_type = pdsch_dmrs_type1;
   ue->dmrs_DownlinkConfig.pdsch_dmrs_AdditionalPosition = pdsch_dmrs_pos0;
@@ -743,6 +745,23 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
   ///////////
   ////////////////////////////////////////////////////////////////////////////////////////////
 
+  /////////////////////////PUSCH PTRS init/////////////////////////
+  ///////////
+
+  ue->ptrs_configured = 0; // flag to be toggled by RCC
+
+  //------------- config PTRS parameters--------------//
+  ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
+  ptrs_Uplink_Config->timeDensity.ptrs_mcs2 = 0;
+  ptrs_Uplink_Config->timeDensity.ptrs_mcs3 = 0;
+  ptrs_Uplink_Config->frequencyDensity.n_rb0 = 0;     // setting N_RB values to 0 indicate abscence of frequency_density field in the configuration
+  ptrs_Uplink_Config->frequencyDensity.n_rb1 = 0;
+  ptrs_Uplink_Config->resourceElementOffset = 0;
+  //-------------------------------------------------//
+
+  ///////////
+  ////////////////////////////////////////////////////////////////////////////////////////////
+
   for (i=0; i<10; i++)
     ue->tx_power_dBm[i]=-127;
 
diff --git a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
index ab6ccd929b..83c6f054cd 100644
--- a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
+++ b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
@@ -117,7 +117,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
 
   //------------------generate DMRS------------------//
 
-  length_dmrs = gNB->dmrs_UplinkConfig.pusch_maxLength;
+  length_dmrs = dmrs_UplinkConfig->pusch_maxLength;
 
   nr_gold_pusch(gNB, symbol, n_idDMRS, length_dmrs);
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
index 9736e97e34..a158d5bf62 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
@@ -338,7 +338,7 @@ void nr_fill_ulsch(PHY_VARS_gNB *gNB,
   rel15_ul->ulsch_pdu_rel15.number_rbs     = ulsch_pdu->rb_size;
   rel15_ul->ulsch_pdu_rel15.start_symbol   = ulsch_pdu->start_symbol_index;
   rel15_ul->ulsch_pdu_rel15.number_symbols = ulsch_pdu->nr_of_symbols;
-  rel15_ul->ulsch_pdu_rel15.length_dmrs    = gNB->dmrs_UplinkConfig.pusch_maxLength;
+  rel15_ul->ulsch_pdu_rel15.length_dmrs    = gNB->pusch_config.dmrs_UplinkConfig.pusch_maxLength;
   rel15_ul->ulsch_pdu_rel15.Qm             = ulsch_pdu->qam_mod_order;
   rel15_ul->ulsch_pdu_rel15.mcs            = ulsch_pdu->mcs_index;
   rel15_ul->ulsch_pdu_rel15.rv             = ulsch_pdu->pusch_data.rv_index;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
index eb35fd7dc6..1def3d5033 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
@@ -1030,12 +1030,12 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
                                       0,
                                       0,
                                       rel15_ul->number_symbols,
-                                      &gNB->dmrs_UplinkConfig,
+                                      &gNB->pusch_config.dmrs_UplinkConfig,
                                       mapping_type,
                                       frame_parms->ofdm_symbol_size);
 
     if (dmrs_symbol_flag == 1){
-      nb_re_pusch = rel15_ul->number_rbs * ((gNB->dmrs_UplinkConfig.pusch_dmrs_type==pusch_dmrs_type1)?6:8);
+      nb_re_pusch = rel15_ul->number_rbs * ((gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type==pusch_dmrs_type1)?6:8);
       gNB->pusch_vars[UE_id]->dmrs_symbol = symbol;
     } else {
         nb_re_pusch = rel15_ul->number_rbs * NR_NB_SC_PER_RB;
@@ -1054,7 +1054,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
                                   symbol,
                                   bwp_start_subcarrier,
                                   rel15_ul->number_rbs,
-                                  &gNB->dmrs_UplinkConfig);
+                                  &gNB->pusch_config.dmrs_UplinkConfig);
 
     //----------------------------------------------------------
     //--------------------- RBs extraction ---------------------
@@ -1073,7 +1073,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
                                 gNB->pusch_vars[UE_id]->dmrs_symbol,
                                 rel15_ul->number_symbols,
                                 mapping_type,
-                                &gNB->dmrs_UplinkConfig);
+                                &gNB->pusch_config.dmrs_UplinkConfig);
 
     nr_ulsch_scale_channel(gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
                            frame_parms,
@@ -1081,7 +1081,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
                            symbol,
                            dmrs_symbol_flag,
                            rel15_ul->number_rbs,
-                           gNB->dmrs_UplinkConfig.pusch_dmrs_type);
+                           gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type);
 
     if (first_symbol_flag==1) {
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
index 69077f0276..162ab6958f 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
@@ -1975,7 +1975,7 @@ uint16_t nr_dci_format_size (PHY_VARS_NR_UE *ue,
   PUSCH_Config_t pusch_config       = ue->pusch_config;
   PUCCH_Config_t pucch_config_dedicated       = ue->pucch_config_dedicated_nr[eNB_id];
   crossCarrierSchedulingConfig_t crossCarrierSchedulingConfig = ue->crossCarrierSchedulingConfig;
-  dmrs_UplinkConfig_t dmrs_UplinkConfig = ue->dmrs_UplinkConfig;
+  dmrs_UplinkConfig_t dmrs_UplinkConfig = ue->pusch_config.dmrs_UplinkConfig;
   dmrs_DownlinkConfig_t dmrs_DownlinkConfig = ue->dmrs_DownlinkConfig;
   csi_MeasConfig_t csi_MeasConfig = ue->csi_MeasConfig;
   PUSCH_ServingCellConfig_t PUSCH_ServingCellConfig= ue->PUSCH_ServingCellConfig;
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index b912834f9d..bdcbe3327a 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -142,14 +142,14 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                             0,
                                             0,
                                             harq_process_ul_ue->number_of_symbols,
-                                            &UE->dmrs_UplinkConfig,
+                                            &UE->pusch_config.dmrs_UplinkConfig,
                                             mapping_type,
                                             frame_parms->ofdm_symbol_size);
 
-    ulsch_ue->length_dmrs = UE->dmrs_UplinkConfig.pusch_maxLength;
+    ulsch_ue->length_dmrs = UE->pusch_config.dmrs_UplinkConfig.pusch_maxLength;
     ulsch_ue->rnti        = n_rnti;
     ulsch_ue->Nid_cell    = Nid_cell;
-    ulsch_ue->nb_re_dmrs  = ((UE->dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
+    ulsch_ue->nb_re_dmrs  = ((UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
 
     N_RE_prime = NR_NB_SC_PER_RB*harq_process_ul_ue->number_of_symbols - ulsch_ue->nb_re_dmrs - N_PRB_oh;
 
@@ -277,7 +277,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
   pusch_dmrs = UE->nr_gold_pusch_dmrs[slot];
   n_dmrs = (harq_process_ul_ue->nb_rb*ulsch_ue->nb_re_dmrs);
   int16_t mod_dmrs[n_dmrs<<1];
-  dmrs_type = UE->dmrs_UplinkConfig.pusch_dmrs_type;
+  dmrs_type = UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type;
   ///////////
   ////////////////////////////////////////////////////////////////////////
 
@@ -313,7 +313,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                              0,
                              0,
                              harq_process_ul_ue->number_of_symbols,
-                             &UE->dmrs_UplinkConfig,
+                             &UE->pusch_config.dmrs_UplinkConfig,
                              mapping_type,
                              frame_parms->ofdm_symbol_size);
 
@@ -379,7 +379,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                  n,
                                  delta,
                                  harq_process_ul_ue->number_of_symbols,
-                                 &UE->dmrs_UplinkConfig,
+                                 &UE->pusch_config.dmrs_UplinkConfig,
                                  mapping_type,
                                  frame_parms->ofdm_symbol_size);
 
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index 3c0f0db8da..91a50d7361 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -669,6 +669,9 @@ typedef struct PHY_VARS_gNB_s {
 
   /// PDSCH DMRS sequence
   uint32_t ****nr_gold_pdsch_dmrs;
+
+  /// flag to indicate if PTRS is configured
+  uint8_t ptrs_configured;
   
   /// PUSCH DMRS
   uint32_t nr_gold_pusch[2][20][2][NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD];
@@ -727,8 +730,6 @@ typedef struct PHY_VARS_gNB_s {
   // SRS Variables
   SOUNDINGRS_UL_CONFIG_DEDICATED soundingrs_ul_config_dedicated[NUMBER_OF_UE_MAX];
 
-  dmrs_UplinkConfig_t dmrs_UplinkConfig;
-
   dmrs_DownlinkConfig_t dmrs_DownlinkConfig;
 
   uint8_t ncs_cell[20][7];
diff --git a/openair1/PHY/defs_nr_UE.h b/openair1/PHY/defs_nr_UE.h
index d72979262c..de4f886903 100644
--- a/openair1/PHY/defs_nr_UE.h
+++ b/openair1/PHY/defs_nr_UE.h
@@ -1012,6 +1012,9 @@ typedef struct {
   /// PUSCH DMRS sequence
   uint32_t ****nr_gold_pusch_dmrs;
 
+  /// flag to indicate if PTRS is configured
+  uint8_t ptrs_configured;
+
   uint32_t X_u[64][839];
 
   uint32_t high_speed_flag;
@@ -1143,7 +1146,6 @@ typedef struct {
 
   crossCarrierSchedulingConfig_t crossCarrierSchedulingConfig;
   supplementaryUplink_t supplementaryUplink;
-  dmrs_UplinkConfig_t dmrs_UplinkConfig;
   dmrs_DownlinkConfig_t dmrs_DownlinkConfig;
   csi_MeasConfig_t csi_MeasConfig;
   PUSCH_ServingCellConfig_t PUSCH_ServingCellConfig;
diff --git a/openair1/PHY/impl_defs_nr.h b/openair1/PHY/impl_defs_nr.h
index 6e13973dd9..3519b97278 100644
--- a/openair1/PHY/impl_defs_nr.h
+++ b/openair1/PHY/impl_defs_nr.h
@@ -510,9 +510,6 @@ typedef struct {
   uint8_t         startSymbolAndLength;
 } PUSCH_TimeDomainResourceAllocation_t;
 ////////////////////////////////////////////////////////////////////////////////################################
-typedef struct { // The IE PTRS-UplinkConfig is used to configure uplink Phase-Tracking-Reference-Signals (PTRS)
-
-} ptrs_UplinkConfig_t;
 typedef enum{
   maxCodeBlockGroupsPerTransportBlock_n2 = 2,
   maxCodeBlockGroupsPerTransportBlock_n4 = 4,
@@ -544,6 +541,12 @@ typedef enum {
   pusch_dmrs_pos2 = 2,
   pusch_dmrs_pos3 = 3,
 } pusch_dmrs_AdditionalPosition_t;
+typedef enum {
+  offset00 = 0,
+  offset01 = 1,
+  offset10 = 2,
+  offset11 = 3,
+} ptrs_resource_elementoffset_t;
 typedef enum {
   pdsch_len1 = 1,
   pdsch_len2 = 2
@@ -552,6 +555,22 @@ typedef enum {
   pusch_len1 = 1,
   pusch_len2 = 2
 } pusch_maxLength_t;
+typedef struct {
+  uint8_t ptrs_mcs1;
+  uint8_t ptrs_mcs2;
+  uint8_t ptrs_mcs3;
+} ptrs_time_density_t;
+typedef struct {
+  uint16_t n_rb0;
+  uint16_t n_rb1;
+} ptrs_frequency_density_t;
+typedef struct { // The IE PTRS-UplinkConfig is used to configure uplink Phase-Tracking-Reference-Signals (PTRS)
+  uint8_t  num_ptrs_ports;
+  ptrs_resource_elementoffset_t resourceElementOffset;
+  ptrs_time_density_t  timeDensity;
+  ptrs_frequency_density_t  frequencyDensity;
+  uint32_t  ul_ptrs_power;
+} ptrs_UplinkConfig_t;
 typedef struct { // The IE DMRS-DownlinkConfig is used to configure downlink demodulation reference signals for PDSCH
   pdsch_dmrs_type_t pdsch_dmrs_type;
   pdsch_dmrs_AdditionalPosition_t pdsch_dmrs_AdditionalPosition;
@@ -563,6 +582,7 @@ typedef struct { // The IE DMRS-UplinkConfig is used to configure uplink demodul
   pusch_dmrs_type_t pusch_dmrs_type;
   pusch_dmrs_AdditionalPosition_t pusch_dmrs_AdditionalPosition;
   pusch_maxLength_t pusch_maxLength;
+  ptrs_UplinkConfig_t ptrs_UplinkConfig;
   uint16_t scramblingID0;
   uint16_t scramblingID1;
 } dmrs_UplinkConfig_t;
@@ -647,6 +667,10 @@ typedef struct {
  * resourceAllocation
  */
   ul_resourceAllocation_t ul_resourceAllocation;
+/*
+ * DMRS-Uplinkconfig
+ */
+  dmrs_UplinkConfig_t dmrs_UplinkConfig;
 /*
  * rgb_Size
  */
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index fb6d1a6c37..40bbe7322d 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -244,11 +244,11 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int UE_id
                                             0,
                                             0,
                                             number_symbols,
-                                            &gNB->dmrs_UplinkConfig,
+                                            &gNB->pusch_config.dmrs_UplinkConfig,
                                             mapping_type,
                                             frame_parms->ofdm_symbol_size);
 
-  nb_re_dmrs = ((gNB->dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
+  nb_re_dmrs = ((gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
 
   G = nr_get_G(nfapi_ulsch_pdu_rel15->number_rbs,
                number_symbols,

From 505d06e945856ad1e13e832957ae366dda7b1e86 Mon Sep 17 00:00:00 2001
From: adk 
Date: Thu, 13 Feb 2020 18:24:55 +0100
Subject: [PATCH 29/73] PUSCH PTRS generation

---
 cmake_targets/CMakeLists.txt                  |   2 +
 openair1/PHY/NR_REFSIG/ptrs_nr.c              | 429 ++++++++++++++++++
 openair1/PHY/NR_REFSIG/ptrs_nr.h              |  82 ++++
 .../PHY/NR_UE_TRANSPORT/nr_transport_ue.h     |   2 +
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c    |  74 ++-
 5 files changed, 583 insertions(+), 6 deletions(-)
 create mode 100644 openair1/PHY/NR_REFSIG/ptrs_nr.c
 create mode 100644 openair1/PHY/NR_REFSIG/ptrs_nr.h

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index c4d3d7e62e..6a0f6e1538 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -1467,6 +1467,7 @@ set(PHY_SRC_UE
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_dmrs_rx.c
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_gold.c
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/dmrs_nr.c
+  ${OPENAIR1_DIR}/PHY/NR_REFSIG/ptrs_nr.c
   ${OPENAIR1_DIR}/PHY/NR_UE_ESTIMATION/filt16a_32.c
   ${OPENAIR1_DIR}/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
   ${OPENAIR1_DIR}/PHY/NR_ESTIMATION/nr_adjust_sync_gNB.c
@@ -1513,6 +1514,7 @@ set(PHY_SRC_UE
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/ul_ref_seq_nr.c
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_dmrs_rx.c
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/dmrs_nr.c
+  ${OPENAIR1_DIR}/PHY/NR_REFSIG/ptrs_nr.c
   ${OPENAIR1_DIR}/PHY/NR_REFSIG/nr_gold_ue.c
   ${OPENAIR1_DIR}/PHY/NR_UE_ESTIMATION/filt16a_32.c
   ${OPENAIR1_DIR}/PHY/NR_UE_ESTIMATION/nr_dl_channel_estimation.c
diff --git a/openair1/PHY/NR_REFSIG/ptrs_nr.c b/openair1/PHY/NR_REFSIG/ptrs_nr.c
new file mode 100644
index 0000000000..9be37d2d95
--- /dev/null
+++ b/openair1/PHY/NR_REFSIG/ptrs_nr.c
@@ -0,0 +1,429 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/**********************************************************************
+*
+* FILENAME    :  ptrs_nr.c
+*
+* MODULE      :  phase tracking reference signals
+*
+* DESCRIPTION :  resource element mapping of ptrs sequences
+*                3GPP TS 38.211 and 3GPP TS 38.214
+*
+************************************************************************/
+
+#include 
+#include 
+#include "dmrs_nr.h"
+#include "PHY/NR_REFSIG/ptrs_nr.h"
+
+/***********************************************************************/
+
+
+ //#define max(a,b) (((a) > (b)) ? (a) : (b))
+
+// TS 38.211 Table 6.4.1.2.2.1-1: The parameter kRE_ref.
+// The first 4 colomns are DM-RS Configuration type 1 and the last 4 colomns are DM-RS Configuration type 2.
+
+int16_t table_6_4_1_2_2_1_1_pusch_ptrs_kRE_ref [6][8] = {
+{ 0,            2,           6,          8,          0,          1,         6,         7},
+{ 2,            4,           8,         10,          1,          6,         7,         0},
+{ 1,            3,           7,          9,          2,          3,         8,         9},
+{ 3,            5,           9,         11,          3,          8,         9,         2},
+{-1,           -1,          -1,         -1,          4,          5,        10,        11},
+{-1,           -1,          -1,         -1,          5,         10,        11,         4},
+};
+
+
+/*******************************************************************
+*
+* NAME :         get_kRE_ref
+*
+* PARAMETERS :   dmrs_antenna_port      DMRS antenna port
+*                pusch_dmrs_type        PUSCH DMRS type
+*                resourceElementOffset  the parameter resourceElementOffset
+*
+* RETURN :       the parameter k_RE_ref
+*
+* DESCRIPTION :  3GPP TS 38.211 Table 6.4.1.2.2.1-1
+*
+*********************************************************************/
+
+int16_t get_kRE_ref(uint8_t dmrs_antenna_port, uint8_t pusch_dmrs_type, uint8_t resourceElementOffset) {
+
+  uint8_t colomn;
+  int16_t k_RE_ref;
+
+  colomn = resourceElementOffset;
+
+  if (pusch_dmrs_type == 2)
+    colomn += 4;
+
+  k_RE_ref = table_6_4_1_2_2_1_1_pusch_ptrs_kRE_ref[dmrs_antenna_port][colomn];
+
+  AssertFatal(k_RE_ref>=0,"invalid k_RE_ref < 0. Check PTRS Configuration\n");
+
+  return k_RE_ref;
+}
+
+
+/*******************************************************************
+*
+* NAME :         get_K_ptrs
+*
+* PARAMETERS :   ptrs_UplinkConfig      PTRS uplink configuration
+*                N_RB                   number of RBs scheduled for PUSCH
+*
+* RETURN :       the parameter K_ptrs
+*
+* DESCRIPTION :  3GPP TS 38.214 6.2.3 Table 6.2.3.1-2
+*
+*********************************************************************/
+
+uint8_t get_K_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint16_t N_RB){
+
+	uint16_t nrb0, nrb1;
+
+	nrb0 = ptrs_UplinkConfig->frequencyDensity.n_rb0;
+	nrb1 = ptrs_UplinkConfig->frequencyDensity.n_rb1;
+
+	if (nrb0 == 0 || nrb0 == 0)
+		return 2;
+
+	if (N_RB < nrb0){
+		LOG_I(PHY,"PUSH PT-RS is not present.\n");
+		return 0;
+	}
+	else if (N_RB >= nrb0 && N_RB < nrb1)
+		return 2;
+	else
+		return 4;
+}
+
+/*******************************************************************
+*
+* NAME :         set_ptrs_symb_idx
+*
+* PARAMETERS :   ptrs_symbols           PTRS OFDM symbol indicies bit mask
+*                ptrs_UplinkConfig      PTRS uplink configuration
+*                dmrs_UplinkConfig      DMRS uplink configuration
+*                mapping_type           PUSCH time domain mapping type
+*                duration_in_symbols    number of scheduled PUSCH ofdm symbols
+*                start_symbol           first ofdm symbol of PUSCH within slot
+*                L_ptrs                 the parameter L_ptrs
+*                ofdm_symbol_size       FFT size
+*
+* RETURN :       sets the bit map of PTRS ofdm symbol indicies
+*
+* DESCRIPTION :  3GPP TS 38.211 6.4.1.2.2.1
+*
+*********************************************************************/
+
+void set_ptrs_symb_idx(uint16_t *ptrs_symbols,
+                       ptrs_UplinkConfig_t *ptrs_UplinkConfig,
+                       dmrs_UplinkConfig_t *dmrs_UplinkConfig,
+                       uint8_t mapping_type,
+                       uint8_t duration_in_symbols,
+                       uint8_t start_symbol,
+                       uint8_t L_ptrs,
+                       uint16_t ofdm_symbol_size) {
+
+	uint8_t i, last_symbol, is_dmrs_symbol1, is_dmrs_symbol2;
+	int16_t l_ref;
+
+	*ptrs_symbols = 0;
+	i = 0;
+	is_dmrs_symbol1 = 0;
+	is_dmrs_symbol2 = 0;
+	l_ref = start_symbol;
+	last_symbol = start_symbol + duration_in_symbols - 1;
+
+	while ( (l_ref + i*L_ptrs) <= last_symbol) {
+
+		is_dmrs_symbol1 = is_dmrs_symbol(max((l_ref + (i-1)*L_ptrs + 1), l_ref),
+                                         0,
+                                         0,
+                                         0,
+                                         0,
+                                         0,
+                                         duration_in_symbols,
+                                         dmrs_UplinkConfig,
+                                         mapping_type,
+                                         ofdm_symbol_size);
+
+		is_dmrs_symbol2 = is_dmrs_symbol(l_ref + i*L_ptrs,
+                                         0,
+                                         0,
+                                         0,
+                                         0,
+                                         0,
+                                         duration_in_symbols,
+                                         dmrs_UplinkConfig,
+                                         mapping_type,
+                                         ofdm_symbol_size);
+
+		if ( is_dmrs_symbol1 + is_dmrs_symbol2 > 0 ) {
+
+			if (dmrs_UplinkConfig->pusch_maxLength == 2)
+				l_ref = l_ref + i*L_ptrs + 1;
+			else
+				l_ref = l_ref + i*L_ptrs;
+
+			i = 1;
+
+			continue;
+
+		}
+
+		*ptrs_symbols = *ptrs_symbols | (1<<(l_ref + i*L_ptrs));
+		i++;
+	}
+}
+
+/*******************************************************************
+*
+* NAME :         get_L_ptrs
+*
+* PARAMETERS :   ptrs_UplinkConfig      PTRS uplink configuration
+*                I_mcs                  MCS index used for PUSCH
+*
+* RETURN :       the parameter L_ptrs
+*
+* DESCRIPTION :  3GPP TS 38.214 6.2.3 Table 6.2.3.1-1
+*
+*********************************************************************/
+
+uint8_t get_L_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint8_t I_mcs) {
+
+	uint8_t mcs1, mcs2, mcs3;
+
+	mcs1 = ptrs_UplinkConfig->timeDensity.ptrs_mcs1;
+	mcs2 = ptrs_UplinkConfig->timeDensity.ptrs_mcs2;
+	mcs3 = ptrs_UplinkConfig->timeDensity.ptrs_mcs3;
+
+	if (mcs1 == 0 || mcs2 == 0 || mcs3 == 0)
+		return 1;
+
+	if (I_mcs < mcs1){
+		LOG_I(PHY,"PUSH PT-RS is not present.\n");
+		return 0;
+	}
+	else if (I_mcs >= mcs1 && I_mcs < mcs2)
+		return 4;
+	else if (I_mcs >= mcs2 && I_mcs < mcs3)
+		return 2;
+	else
+		return 1;
+}
+
+/*******************************************************************
+*
+* NAME :         is_ptrs_subcarrier
+*
+* PARAMETERS : k                      subcarrier index
+*              K_ptrs                 the parameter K_ptrs
+*              n_rnti                 UE CRNTI
+*              N_RB                   number of RBs scheduled for PUSCH
+*              k_RE_ref               the parameter k_RE_ref
+*              start_sc               first subcarrier index
+*              ofdm_symbol_size       FFT size
+*
+* RETURN :       1 if subcarrier k is PTRS, or 0 otherwise
+*
+* DESCRIPTION :  3GPP TS 38.211 6.4.1.2 Phase-tracking reference signal for PUSCH
+*
+*********************************************************************/
+
+uint8_t is_ptrs_subcarrier(uint16_t k, uint8_t K_ptrs, uint16_t n_rnti, uint16_t N_RB, int16_t k_RE_ref, uint16_t start_sc, uint16_t ofdm_symbol_size) {
+
+	uint16_t k_RB_ref, i, sc;
+
+	i = 0;
+	sc = 0;
+	k_RB_ref = 0;
+
+	if (N_RB % K_ptrs == 0)
+		k_RB_ref = n_rnti % K_ptrs;
+	else
+		k_RB_ref = n_rnti % (N_RB % K_ptrs);
+
+	while (k > sc){
+
+		sc = (start_sc + k_RE_ref + (i*K_ptrs + k_RB_ref)*NR_NB_SC_PER_RB)%ofdm_symbol_size;
+		i++;
+
+	}
+
+	if (k == sc)
+        return 1;
+	else
+        return 0;
+
+}
+
+/*******************************************************************
+*
+* NAME :         is_ptrs_symbol
+*
+* PARAMETERS : l                      ofdm symbol index within slot
+*              k                      subcarrier index
+*              n_rnti                 UE CRNTI
+*              N_RB                   number of RBs scheduled for PUSCH
+*              duration_in_symbols    number of scheduled PUSCH ofdm symbols
+*              dmrs_antenna_port      DMRS antenna port
+*              K_ptrs                 the parameter K_ptrs
+*              ptrs_symbols           bit mask of ptrs
+*              start_sc               first subcarrier index
+*              ofdm_symbol_size       FFT size
+*              pusch_dmrs_type        PUSCH DMRS type (1 or 2)
+*              ptrs_UplinkConfig      PTRS uplink configuration
+*
+* RETURN :       0 if symbol(k,l) is data, or 1 if symbol(k,l) is ptrs
+*
+* DESCRIPTION :  3GPP TS 38.211 6.4.1.2 Phase-tracking reference signal for PUSCH
+*
+*********************************************************************/
+
+uint8_t is_ptrs_symbol(uint8_t l,
+                       uint16_t k,
+                       uint16_t n_rnti,
+                       uint16_t N_RB,
+                       uint8_t duration_in_symbols,
+                       uint8_t dmrs_antenna_port,
+                       uint8_t K_ptrs,
+                       uint16_t ptrs_symbols,
+                       uint16_t start_sc,
+                       uint16_t ofdm_symbol_size,
+                       pusch_dmrs_type_t pusch_dmrs_type,
+                       ptrs_UplinkConfig_t *ptrs_UplinkConfig) {
+
+  uint8_t is_ptrs_freq, is_ptrs_time;
+  int16_t k_RE_ref;
+
+  is_ptrs_freq = 0;
+  is_ptrs_time = 0;
+
+  k_RE_ref = get_kRE_ref(dmrs_antenna_port, pusch_dmrs_type, ptrs_UplinkConfig->resourceElementOffset);
+
+  is_ptrs_freq = is_ptrs_subcarrier(k, K_ptrs, n_rnti, N_RB, k_RE_ref, start_sc, ofdm_symbol_size);
+
+  if (is_ptrs_freq == 0)
+    return 0;
+
+  if (((ptrs_symbols>>l)&1) == 1)
+    is_ptrs_time = 1;
+
+  if (is_ptrs_time && is_ptrs_freq)
+    return 1;
+  else
+    return 0;
+
+}
+
+/*
+int main(int argc, char const *argv[])
+{
+
+	dmrs_UplinkConfig_t dmrs_Uplink_Config;
+	ptrs_UplinkConfig_t ptrs_Uplink_Config;
+	uint8_t resourceElementOffset;
+	uint8_t dmrs_antenna_port;
+	uint8_t L_ptrs, K_ptrs;
+	int16_t k_RE_ref;
+	uint16_t N_RB, ptrs_symbols, ofdm_symbol_size, k;
+	uint8_t duration_in_symbols, I_mcs;
+	uint8_t start_symbol, l;
+	uint8_t ptrs_symbol_flag;
+	uint16_t n_rnti;
+
+    dmrs_Uplink_Config.pusch_dmrs_type = pusch_dmrs_type1;
+    dmrs_Uplink_Config.pusch_dmrs_AdditionalPosition = pusch_dmrs_pos1;
+    dmrs_Uplink_Config.pusch_maxLength = pusch_len2;
+
+    ptrs_Uplink_Config.timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
+    ptrs_Uplink_Config.timeDensity.ptrs_mcs2 = 0;
+    ptrs_Uplink_Config.timeDensity.ptrs_mcs3 = 0;
+    ptrs_Uplink_Config.frequencyDensity.n_rb0 = 0;     // setting N_RB values to 0 indicate abscence of frequency_density field in the configuration
+    ptrs_Uplink_Config.frequencyDensity.n_rb1 = 0;
+    ptrs_Uplink_Config.resourceElementOffset = 0;
+
+    n_rnti = 0x1234;
+    resourceElementOffset = 0;
+    ptrs_symbols = 0;
+	dmrs_antenna_port = 0;
+	N_RB = 50;
+	duration_in_symbols = 14;
+	ofdm_symbol_size = 2048;
+	I_mcs = 9;
+	start_symbol = 0;
+	ptrs_symbol_flag = 0;
+
+    k_RE_ref = get_kRE_ref(dmrs_antenna_port, dmrs_Uplink_Config.pusch_dmrs_type, resourceElementOffset);
+
+    K_ptrs = get_K_ptrs(&ptrs_Uplink_Config, N_RB);
+
+    L_ptrs = get_L_ptrs(&ptrs_Uplink_Config, I_mcs);
+
+    set_ptrs_symb_idx(&ptrs_symbols,
+                      &ptrs_Uplink_Config,
+                      &dmrs_Uplink_Config,
+                      1,
+                      duration_in_symbols,
+                      start_symbol,
+                      L_ptrs,
+                      ofdm_symbol_size);
+
+    printf("PTRS OFDM symbol indicies: ");
+
+    for (l = start_symbol; l < start_symbol + duration_in_symbols; l++){
+
+        ptrs_symbol_flag = is_ptrs_symbol(l,
+                                          0,
+                                          n_rnti,
+                                          N_RB,
+                                          duration_in_symbols,
+                                          dmrs_antenna_port,
+                                          K_ptrs,
+                                          ptrs_symbols,
+                                          dmrs_Uplink_Config.pusch_dmrs_type,
+                                          &ptrs_Uplink_Config);
+
+        if (ptrs_symbol_flag == 1)
+            printf(" %d ", l);
+
+    }
+
+    printf("\n");
+
+    printf("PTRS subcarrier indicies: ");
+
+    for (k = 0; k < N_RB*12; k++){
+
+        if (is_ptrs_subcarrier(k, K_ptrs, n_rnti, N_RB, k_RE_ref) == 1)
+            printf(" %d ", k);
+
+    }
+
+    printf("\n");
+
+	return 0;
+}
+*/
\ No newline at end of file
diff --git a/openair1/PHY/NR_REFSIG/ptrs_nr.h b/openair1/PHY/NR_REFSIG/ptrs_nr.h
new file mode 100644
index 0000000000..f3b42fff30
--- /dev/null
+++ b/openair1/PHY/NR_REFSIG/ptrs_nr.h
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/**********************************************************************
+*
+* FILENAME    :  dmrs.h
+*
+* MODULE      :  demodulation reference signals
+*
+* DESCRIPTION :  generation of dmrs sequences for NR 5G
+*                3GPP TS 38.211
+*
+************************************************************************/
+
+#ifndef PTRS_NR_H
+#define PTRS_NR_H
+
+#include "PHY/defs_nr_UE.h"
+
+/************** CODE GENERATION ***********************************/
+
+/************** DEFINE ********************************************/
+
+
+/************* STRUCTURES *****************************************/
+
+
+/************** VARIABLES *****************************************/
+
+/************** FUNCTION ******************************************/
+
+int16_t get_kRE_ref(uint8_t dmrs_antenna_port, uint8_t pusch_dmrs_type, uint8_t resourceElementOffset);
+
+uint8_t get_K_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint16_t N_RB);
+
+void set_ptrs_symb_idx(uint16_t *ptrs_symbols,
+                       ptrs_UplinkConfig_t *ptrs_UplinkConfig,
+                       dmrs_UplinkConfig_t *dmrs_UplinkConfig,
+                       uint8_t mapping_type,
+                       uint8_t duration_in_symbols,
+                       uint8_t start_symbol,
+                       uint8_t L_ptrs,
+                       uint16_t ofdm_symbol_size);
+
+uint8_t get_L_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint8_t I_mcs);
+
+uint8_t is_ptrs_subcarrier(uint16_t k, uint8_t K_ptrs, uint16_t n_rnti, uint16_t N_RB, int16_t k_RE_ref, uint16_t start_sc, uint16_t ofdm_symbol_size);
+
+uint8_t is_ptrs_symbol(uint8_t l,
+                       uint16_t k,
+                       uint16_t n_rnti,
+                       uint16_t N_RB,
+                       uint8_t duration_in_symbols,
+                       uint8_t dmrs_antenna_port,
+                       uint8_t K_ptrs,
+                       uint16_t ptrs_symbols,
+                       uint16_t start_sc,
+                       uint16_t ofdm_symbol_size,
+                       pusch_dmrs_type_t pusch_dmrs_type,
+                       ptrs_UplinkConfig_t *ptrs_UplinkConfig);
+
+
+
+#endif /* PTRS_NR_H */
\ No newline at end of file
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h
index 39b037a600..a10b6231a0 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_transport_ue.h
@@ -240,6 +240,8 @@ typedef struct {
   int16_t Po_SRS;
   /// num active cba group
   uint8_t num_active_cba_groups;
+  /// bit mask of PT-RS ofdm symbol indicies
+  uint16_t ptrs_symbols;
   /// num dci found for cba
   //uint8_t num_cba_dci[10];
   /// allocated CBA RNTI
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index bdcbe3327a..3caaa6c99f 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -31,6 +31,7 @@
 */
 #include 
 #include "PHY/NR_REFSIG/dmrs_nr.h"
+#include "PHY/NR_REFSIG/ptrs_nr.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_proto_ue.h"
 #include "PHY/MODULATION/nr_modulation.h"
@@ -105,19 +106,22 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
   int32_t **txdataF;
   uint16_t start_sc, start_rb;
   int8_t Wf[2], Wt[2], l_prime[2], delta;
-  uint16_t n_dmrs, code_rate, number_dmrs_symbols;
+  uint16_t n_dmrs, code_rate, number_dmrs_symbols, k;
   uint8_t dmrs_type;
   uint8_t mapping_type;
   int ap, start_symbol, Nid_cell, i;
   int sample_offsetF, N_RE_prime, N_PRB_oh;
   uint16_t n_rnti;
   uint8_t data_existing =0;
+  uint8_t L_ptrs, K_ptrs; // PTRS parameters
+  uint16_t beta_ptrs; // PTRS parameter related to power control
 
   NR_UE_ULSCH_t *ulsch_ue;
   NR_UL_UE_HARQ_t *harq_process_ul_ue;
   NR_DL_FRAME_PARMS *frame_parms = &UE->frame_parms;
   NR_UE_PUSCH *pusch_ue = UE->pusch_vars[thread_id][gNB_id];
   uint8_t ulsch_input_buffer[MAX_ULSCH_PAYLOAD_BYTES];
+  ptrs_UplinkConfig_t *ptrs_Uplink_Config = &UE->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
 
   num_of_codewords = 1; // tmp assumption
   n_rnti = 0x1234;
@@ -281,6 +285,36 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
   ///////////
   ////////////////////////////////////////////////////////////////////////
 
+
+  /////////////////////////PTRS parameters' initialization/////////////////////////
+  ///////////
+
+  int16_t mod_ptrs[(harq_process_ul_ue->nb_rb/2)*(NR_SYMBOLS_PER_SLOT-1)*2]; // assume maximum number of PTRS per pusch allocation
+  K_ptrs = 0; // just to avoid a warning
+
+  if (UE->ptrs_configured == 1) {
+
+    K_ptrs = get_K_ptrs(ptrs_Uplink_Config, harq_process_ul_ue->nb_rb);
+
+    L_ptrs = get_L_ptrs(ptrs_Uplink_Config, harq_process_ul_ue->mcs);
+
+    beta_ptrs = 1; // temp value until power control is implemented
+
+    ulsch_ue->ptrs_symbols = 0;
+
+    set_ptrs_symb_idx(&ulsch_ue->ptrs_symbols,
+                      ptrs_Uplink_Config,
+                      &UE->pusch_config.dmrs_UplinkConfig,
+                      1,
+                      harq_process_ul_ue->number_of_symbols,
+                      start_symbol,
+                      L_ptrs,
+                      frame_parms->ofdm_symbol_size);
+  }
+
+  ///////////
+  ////////////////////////////////////////////////////////////////////////////////
+
   /////////////////////////ULSCH layer mapping/////////////////////////
   ///////////
 
@@ -357,8 +391,8 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
     
 
     uint8_t k_prime=0;
-    uint8_t is_dmrs;
-    uint16_t m=0, n=0, dmrs_idx=0, k=0;
+    uint8_t is_dmrs, is_ptrs;
+    uint16_t m=0, n=0, dmrs_idx=0, ptrs_idx = 0;
 
     for (l=start_symbol; lnumber_of_symbols; l++) {
 
@@ -371,6 +405,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
         sample_offsetF = l*frame_parms->ofdm_symbol_size + k;
 
         is_dmrs = 0;
+        is_ptrs = 0;
 
         is_dmrs = is_dmrs_symbol(l,
                                  k,
@@ -383,9 +418,26 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                  mapping_type,
                                  frame_parms->ofdm_symbol_size);
 
+        if (UE->ptrs_configured == 1){
+          is_ptrs = is_ptrs_symbol(l,
+                                   k,
+                                   ulsch_ue->rnti,
+                                   harq_process_ul_ue->nb_rb,
+                                   harq_process_ul_ue->number_of_symbols,
+                                   ap,
+                                   K_ptrs,
+                                   ulsch_ue->ptrs_symbols,
+                                   start_sc,
+                                   frame_parms->ofdm_symbol_size,
+                                   UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type,
+                                   ptrs_Uplink_Config);
+        }
+
         if (is_dmrs == 1) {
 
-          nr_modulation(pusch_dmrs[l][0], n_dmrs*2, DMRS_MOD_ORDER, mod_dmrs); // currently only codeword 0 is modulated. Qm = 2 as DMRS is QPSK modulated
+          if (k == start_sc){
+            nr_modulation(pusch_dmrs[l][0], n_dmrs*2, DMRS_MOD_ORDER, mod_dmrs); // currently only codeword 0 is modulated. Qm = 2 as DMRS is QPSK modulated
+          }
 
           ((int16_t*)txdataF[ap])[(sample_offsetF)<<1] = (Wt[l_prime[0]]*Wf[k_prime]*AMP*mod_dmrs[dmrs_idx<<1]) >> 15;
           ((int16_t*)txdataF[ap])[((sample_offsetF)<<1) + 1] = (Wt[l_prime[0]]*Wf[k_prime]*AMP*mod_dmrs[(dmrs_idx<<1) + 1]) >> 15;
@@ -401,9 +453,19 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
           k_prime++;
           k_prime&=1;
           n+=(k_prime)?0:1;
-        }
 
-        else {
+        }  else if (is_ptrs == 1) {
+
+          if (k == start_sc){
+            nr_modulation(pusch_dmrs[l][0], harq_process_ul_ue->nb_rb/2, DMRS_MOD_ORDER, mod_ptrs);
+          }
+
+          ((int16_t*)txdataF[ap])[(sample_offsetF)<<1] = (beta_ptrs*AMP*mod_ptrs[ptrs_idx<<1]) >> 15;
+          ((int16_t*)txdataF[ap])[((sample_offsetF)<<1) + 1] = (beta_ptrs*AMP*mod_ptrs[(ptrs_idx<<1) + 1]) >> 15;
+
+          ptrs_idx++;
+
+          } else {
 
           ((int16_t*)txdataF[ap])[(sample_offsetF)<<1]       = ((int16_t *) ulsch_ue->y)[m<<1];
           ((int16_t*)txdataF[ap])[((sample_offsetF)<<1) + 1] = ((int16_t *) ulsch_ue->y)[(m<<1) + 1];

From 00ff5e8a5cfe7fc8ee634a3af1cdc9daf82529be Mon Sep 17 00:00:00 2001
From: adk 
Date: Tue, 3 Mar 2020 11:33:07 +0100
Subject: [PATCH 30/73] PUSCH PTRS extraction and fixing nr_ulsim

---
 openair1/PHY/INIT/nr_init.c                   |  54 ++++----
 openair1/PHY/INIT/nr_init_ue.c                |   2 +-
 .../PHY/NR_TRANSPORT/nr_transport_proto.h     |  14 +-
 .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c  | 123 ++++++++++++++----
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c    |   1 +
 openair1/PHY/defs_gNB.h                       |  14 ++
 openair1/SIMULATION/NR_PHY/ulsim.c            |   6 +-
 7 files changed, 153 insertions(+), 61 deletions(-)

diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index f10a7426dd..00fd616aa0 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -170,7 +170,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
     gNB->pusch_config.pusch_TimeDomainResourceAllocation[i]->mappingType = typeB;
   }
 
-  gNB->ptrs_configured = 0;
+  gNB->ptrs_configured = 1;
 
   //------------- config PUSCH PTRS parameters(to be updated from RRC)--------------//
   ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
@@ -234,32 +234,36 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
   for (int UE_id=0; UE_idrxdataF_ext           = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->rxdataF_ext2          = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_estimates       = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_estimates_ext   = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_estimates_time  = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->rxdataF_comp          = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_mag0             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_magb0            = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_mag             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_magb            = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->rho                   = (int32_t **)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) );
+    pusch_vars[UE_id]->rxdataF_ext              = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->rxdataF_ext2             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_estimates          = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_estimates_ext      = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_ptrs_estimates     = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_estimates_time     = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->rxdataF_comp             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_mag0               = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_magb0              = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_mag                = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->ul_ch_magb               = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
+    pusch_vars[UE_id]->rho                      = (int32_t **)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) );
 
     for (i=0; inb_antennas_rx; i++) {
       // RK 2 times because of output format of FFT!
       // FIXME We should get rid of this
-      pusch_vars[UE_id]->rxdataF_ext[i]           = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->rxdataF_ext2[i]          = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_estimates_time[i]  = (int32_t *)malloc16_clear( 2*sizeof(int32_t)*fp->ofdm_symbol_size );
-      pusch_vars[UE_id]->rxdataF_comp[i]          = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_mag0[i]             = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->ul_ch_magb0[i]            = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->ul_ch_mag[i]             = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->ul_ch_magb[i]            = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->rho[i]                   = (int32_t *)malloc16_clear( sizeof(int32_t)*(fp->N_RB_UL*12*7*2) );
+      pusch_vars[UE_id]->rxdataF_ext[i]                = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
+      pusch_vars[UE_id]->rxdataF_ext2[i]               = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
+      pusch_vars[UE_id]->ul_ch_estimates[i]            = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
+      pusch_vars[UE_id]->ul_ch_estimates_ext[i]        = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
+      pusch_vars[UE_id]->ul_ch_ptrs_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*2*fp->symbols_per_slot ); // max intensity in freq is 1 sc every 2 RBs
+      pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*2*fp->symbols_per_slot );
+      pusch_vars[UE_id]->ul_ch_estimates_time[i]       = (int32_t *)malloc16_clear( 2*sizeof(int32_t)*fp->ofdm_symbol_size );
+      pusch_vars[UE_id]->rxdataF_comp[i]               = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
+      pusch_vars[UE_id]->ul_ch_mag0[i]                 = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
+      pusch_vars[UE_id]->ul_ch_magb0[i]                = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
+      pusch_vars[UE_id]->ul_ch_mag[i]                  = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
+      pusch_vars[UE_id]->ul_ch_magb[i]                 = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
+      pusch_vars[UE_id]->rho[i]                        = (int32_t *)malloc16_clear( sizeof(int32_t)*(fp->N_RB_UL*12*7*2) );
     }
 
     pusch_vars[UE_id]->llr = (int16_t *)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) ); // [hna] 6144 is LTE and (8*((3*8*6144)+12)) is not clear 
@@ -363,6 +367,8 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
       free_and_zero(pusch_vars[UE_id]->rxdataF_ext2[i]);
       free_and_zero(pusch_vars[UE_id]->ul_ch_estimates[i]);
       free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_ext[i]);
+      free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates[i]);
+      free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext[i]);
       free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_time[i]);
       free_and_zero(pusch_vars[UE_id]->rxdataF_comp[i]);
       free_and_zero(pusch_vars[UE_id]->ul_ch_mag0[i]);
@@ -376,6 +382,8 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
     free_and_zero(pusch_vars[UE_id]->rxdataF_ext2);
     free_and_zero(pusch_vars[UE_id]->ul_ch_estimates);
     free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_ext);
+    free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates);
+    free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext);
     free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_time);
     free_and_zero(pusch_vars[UE_id]->rxdataF_comp);
     free_and_zero(pusch_vars[UE_id]->ul_ch_mag0);
diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index 7b7954583d..773d048942 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -748,7 +748,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
   /////////////////////////PUSCH PTRS init/////////////////////////
   ///////////
 
-  ue->ptrs_configured = 0; // flag to be toggled by RCC
+  ue->ptrs_configured = 1; // flag to be toggled by RCC
 
   //------------- config PTRS parameters--------------//
   ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
diff --git a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
index 4c8d8650e3..d3985bfd8b 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
@@ -65,20 +65,18 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
     @param is_dmrs_symbol, flag to indicate wether this OFDM symbol contains DMRS symbols or not.
 
 */
-void nr_ulsch_extract_rbs_single(int **rxdataF,
-                                 int **ul_ch_estimates,
-                                 int **rxdataF_ext,
-                                 int **ul_ch_estimates_ext,
-                                 uint32_t rxdataF_ext_offset,
-                                 // unsigned int *rb_alloc, [hna] Resource Allocation Type 1 is assumed only for the moment
+void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
+                                 NR_gNB_PUSCH *pusch_vars,
                                  unsigned char symbol,
                                  unsigned short start_rb,
                                  unsigned short nb_rb_pusch,
+                                 uint16_t n_rnti,
                                  NR_DL_FRAME_PARMS *frame_parms,
-                                 uint8_t dmrs_symbol,
                                  uint16_t number_symbols,
                                  uint8_t mapping_type,
-                                 dmrs_UplinkConfig_t *dmrs_UplinkConfig);
+                                 uint8_t ptrs_configured,
+                                 dmrs_UplinkConfig_t *dmrs_UplinkConfig,
+                                 ptrs_UplinkConfig_t *ptrs_Uplink_Config);
 
 void nr_ulsch_scale_channel(int32_t **ul_ch_estimates_ext,
                             NR_DL_FRAME_PARMS *frame_parms,
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
index 1def3d5033..93cb721f36 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
@@ -4,6 +4,7 @@
 #include "PHY/impl_defs_top.h"
 #include "PHY/NR_TRANSPORT/nr_sch_dmrs.h"
 #include "PHY/NR_REFSIG/dmrs_nr.h"
+#include "PHY/NR_REFSIG/ptrs_nr.h"
 #include "PHY/NR_ESTIMATION/nr_ul_estimation.h"
 #include "PHY/defs_nr_common.h"
 
@@ -221,31 +222,32 @@ void nr_idft(uint32_t *z, uint32_t Msc_PUSCH)
 
 }
 
-void nr_ulsch_extract_rbs_single(int **rxdataF,
-                                 int **ul_ch_estimates,
-                                 int **rxdataF_ext,
-                                 int **ul_ch_estimates_ext,
-                                 uint32_t rxdataF_ext_offset,
-                                 // unsigned int *rb_alloc, [hna] Resource Allocation Type 1 is assumed only for the moment
+void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
+                                 NR_gNB_PUSCH *pusch_vars,
                                  unsigned char symbol,
                                  unsigned short start_rb,
                                  unsigned short nb_rb_pusch,
+                                 uint16_t n_rnti,
                                  NR_DL_FRAME_PARMS *frame_parms,
-                                 uint8_t dmrs_symbol,
                                  uint16_t number_symbols,
                                  uint8_t mapping_type,
-                                 dmrs_UplinkConfig_t *dmrs_UplinkConfig)
+                                 uint8_t ptrs_configured,
+                                 dmrs_UplinkConfig_t *dmrs_UplinkConfig,
+                                 ptrs_UplinkConfig_t *ptrs_Uplink_Config)
 {
   unsigned short start_re, re, nb_re_pusch;
   unsigned char aarx;
+  uint8_t K_ptrs;
   uint32_t rxF_ext_index = 0;
   uint32_t ul_ch0_ext_index = 0;
   uint32_t ul_ch0_index = 0;
-  uint8_t is_dmrs_symbol_flag, k_prime;
-  uint16_t n=0;
-
+  uint32_t ul_ch0_ptrs_ext_index = 0;
+  uint32_t ul_ch0_ptrs_index = 0;
+  uint8_t is_dmrs_symbol_flag, is_ptrs_symbol_flag,k_prime;
+  uint16_t n=0, num_ptrs_symbols;
   int16_t *rxF,*rxF_ext;
   int *ul_ch0,*ul_ch0_ext;
+  int *ul_ch0_ptrs,*ul_ch0_ptrs_ext;
 
 #ifdef DEBUG_RB_EXT
 
@@ -258,15 +260,23 @@ void nr_ulsch_extract_rbs_single(int **rxdataF,
   
   nb_re_pusch = NR_NB_SC_PER_RB * nb_rb_pusch;
   is_dmrs_symbol_flag = 0;
+  is_ptrs_symbol_flag = 0;
+  num_ptrs_symbols = 0;
+
+  K_ptrs = get_K_ptrs(ptrs_Uplink_Config, nb_rb_pusch);
 
   for (aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) {
     
     rxF       = (int16_t *)&rxdataF[aarx][symbol * frame_parms->ofdm_symbol_size];
-    rxF_ext   = (int16_t *)&rxdataF_ext[aarx][symbol * nb_re_pusch]; // [hna] rxdataF_ext isn't contiguous in order to solve an alignment problem ib llr computation in case of mod_order = 4, 6
+    rxF_ext   = (int16_t *)&pusch_vars->rxdataF_ext[aarx][symbol * nb_re_pusch]; // [hna] rxdataF_ext isn't contiguous in order to solve an alignment problem ib llr computation in case of mod_order = 4, 6
 
-    ul_ch0     = &ul_ch_estimates[aarx][dmrs_symbol*frame_parms->ofdm_symbol_size]; // update channel estimates if new dmrs symbol are available
+    ul_ch0     = &pusch_vars->ul_ch_estimates[aarx][pusch_vars->dmrs_symbol*frame_parms->ofdm_symbol_size]; // update channel estimates if new dmrs symbol are available
 
-    ul_ch0_ext = &ul_ch_estimates_ext[aarx][symbol*nb_re_pusch];
+    ul_ch0_ext = &pusch_vars->ul_ch_estimates_ext[aarx][symbol*nb_re_pusch];
+
+    ul_ch0_ptrs     = &pusch_vars->ul_ch_ptrs_estimates[aarx][pusch_vars->ptrs_symbol_index*frame_parms->ofdm_symbol_size]; // update channel estimates if new dmrs symbol are available
+
+    ul_ch0_ptrs_ext = &pusch_vars->ul_ch_ptrs_estimates_ext[aarx][symbol*nb_re_pusch];
 
     n = 0;
     k_prime = 0;
@@ -283,15 +293,36 @@ void nr_ulsch_extract_rbs_single(int **rxdataF,
                                             dmrs_UplinkConfig,
                                             mapping_type,
                                             frame_parms->ofdm_symbol_size);
+
+      if (ptrs_configured == 1){
+        is_ptrs_symbol_flag = is_ptrs_symbol(symbol,
+                                             (start_re + re)%frame_parms->ofdm_symbol_size,
+                                             n_rnti,
+                                             nb_rb_pusch,
+                                             number_symbols,
+                                             aarx,
+                                             K_ptrs,
+                                             pusch_vars->ptrs_symbols,
+                                             start_re,
+                                             frame_parms->ofdm_symbol_size,
+                                             dmrs_UplinkConfig->pusch_dmrs_type,
+                                             ptrs_Uplink_Config);
+
+        if (is_ptrs_symbol_flag == 1)
+          num_ptrs_symbols++;
+
+      }
+
   #ifdef DEBUG_RB_EXT
       printf("re = %d, is_dmrs_symbol_flag = %d, symbol = %d\n", re, is_dmrs_symbol_flag, symbol);
   #endif
 
-      if ( is_dmrs_symbol_flag == 0 ) {
+      if ( is_dmrs_symbol_flag == 0 && is_ptrs_symbol_flag == 0) {
 
         rxF_ext[rxF_ext_index]     = (rxF[ ((start_re + re)*2)      % (frame_parms->ofdm_symbol_size*2)]);
         rxF_ext[rxF_ext_index + 1] = (rxF[(((start_re + re)*2) + 1) % (frame_parms->ofdm_symbol_size*2)]);
         ul_ch0_ext[ul_ch0_ext_index] = ul_ch0[ul_ch0_index];
+        ul_ch0_ptrs_ext[ul_ch0_ptrs_ext_index] = ul_ch0_ptrs[ul_ch0_ptrs_index];
 
   #ifdef DEBUG_RB_EXT
         printf("rxF_ext[%d] = %d\n", rxF_ext_index, rxF_ext[rxF_ext_index]);
@@ -299,6 +330,7 @@ void nr_ulsch_extract_rbs_single(int **rxdataF,
   #endif
 
         ul_ch0_ext_index++;
+        ul_ch0_ptrs_ext_index++;
         rxF_ext_index +=2;
       } else {
         k_prime++;
@@ -306,8 +338,12 @@ void nr_ulsch_extract_rbs_single(int **rxdataF,
         n+=(k_prime)?0:1;
       }
       ul_ch0_index++;
+      ul_ch0_ptrs_index++;
     }
   }
+
+  pusch_vars->ptrs_sc_per_ofdm_symbol = num_ptrs_symbols;
+
 }
 
 void nr_ulsch_scale_channel(int **ul_ch_estimates_ext,
@@ -1001,17 +1037,21 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
                  unsigned char harq_pid)
 {
 
-  uint8_t first_symbol_flag, aarx, aatx, dmrs_symbol_flag; // dmrs_symbol_flag, a flag to indicate DMRS REs in current symbol
-  NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms;
-  nfapi_nr_ul_config_ulsch_pdu_rel15_t *rel15_ul = &gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu.ulsch_pdu_rel15;
+  uint8_t first_symbol_flag, aarx, aatx, dmrs_symbol_flag, ptrs_symbol_flag; // dmrs_symbol_flag, a flag to indicate DMRS REs in current symbol
   uint32_t nb_re_pusch, bwp_start_subcarrier;
   uint8_t mapping_type;
+  uint8_t L_ptrs = 0; // PTRS parameter
   int avgs;
   int avg[4];
+  NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms;
+  nfapi_nr_ul_config_ulsch_pdu_rel15_t *rel15_ul = &gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu.ulsch_pdu_rel15;
+  ptrs_UplinkConfig_t *ptrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
 
   dmrs_symbol_flag = 0;
+  ptrs_symbol_flag = 0;
   first_symbol_flag = 0;
   mapping_type = gNB->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType;
+  gNB->pusch_vars[UE_id]->ptrs_sc_per_ofdm_symbol = 0;
 
   if (mapping_type == typeB) {
 
@@ -1019,6 +1059,20 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
       gNB->pusch_vars[UE_id]->rxdataF_ext_offset = 0;
       gNB->pusch_vars[UE_id]->dmrs_symbol = 0;
       first_symbol_flag = 1;
+
+      L_ptrs = get_L_ptrs(ptrs_Uplink_Config, rel15_ul->mcs);
+
+      gNB->pusch_vars[UE_id]->ptrs_symbols = 0;
+
+      set_ptrs_symb_idx(&gNB->pusch_vars[UE_id]->ptrs_symbols,
+                        ptrs_Uplink_Config,
+                        &gNB->pusch_config.dmrs_UplinkConfig,
+                        1,
+                        rel15_ul->number_symbols,
+                        rel15_ul->start_symbol,
+                        L_ptrs,
+                        frame_parms->ofdm_symbol_size);
+
     }
 
     bwp_start_subcarrier = (rel15_ul->start_rb*NR_NB_SC_PER_RB + frame_parms->first_carrier_offset) % frame_parms->ofdm_symbol_size;
@@ -1041,6 +1095,25 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
         nb_re_pusch = rel15_ul->number_rbs * NR_NB_SC_PER_RB;
     }
 
+    if (gNB->ptrs_configured == 1)
+        ptrs_symbol_flag = is_ptrs_symbol(symbol,
+                                          0,
+                                          gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu.rnti,
+                                          rel15_ul->number_rbs,
+                                          rel15_ul->number_symbols,
+                                          0,
+                                          get_K_ptrs(ptrs_Uplink_Config, rel15_ul->number_rbs),
+                                          gNB->pusch_vars[UE_id]->ptrs_symbols,
+                                          0,
+                                          frame_parms->ofdm_symbol_size,
+                                          gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type,
+                                          ptrs_Uplink_Config);
+
+
+    if (ptrs_symbol_flag == 1){
+      gNB->pusch_vars[UE_id]->ptrs_symbol_index = symbol;
+    }
+
 
     //----------------------------------------------------------
     //--------------------- Channel estimation ---------------------
@@ -1061,19 +1134,17 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
     //----------------------------------------------------------
 
     nr_ulsch_extract_rbs_single(gNB->common_vars.rxdataF,
-                                gNB->pusch_vars[UE_id]->ul_ch_estimates,
-                                gNB->pusch_vars[UE_id]->rxdataF_ext,
-                                gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
-                                gNB->pusch_vars[UE_id]->rxdataF_ext_offset,
-                                // rb_alloc, [hna] Resource Allocation Type 1 is assumed only for the moment
+                                gNB->pusch_vars[UE_id],
                                 symbol,
                                 rel15_ul->start_rb,
                                 rel15_ul->number_rbs,
+                                gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu.rnti,
                                 frame_parms,
-                                gNB->pusch_vars[UE_id]->dmrs_symbol,
                                 rel15_ul->number_symbols,
                                 mapping_type,
-                                &gNB->pusch_config.dmrs_UplinkConfig);
+                                gNB->ptrs_configured,
+                                &gNB->pusch_config.dmrs_UplinkConfig,
+                                ptrs_Uplink_Config);
 
     nr_ulsch_scale_channel(gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
                            frame_parms,
@@ -1131,7 +1202,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
                          symbol,
                          rel15_ul->Qm);
 
-    gNB->pusch_vars[UE_id]->rxdataF_ext_offset = gNB->pusch_vars[UE_id]->rxdataF_ext_offset +  nb_re_pusch;
+    gNB->pusch_vars[UE_id]->rxdataF_ext_offset = gNB->pusch_vars[UE_id]->rxdataF_ext_offset +  nb_re_pusch - gNB->pusch_vars[UE_id]->ptrs_sc_per_ofdm_symbol;
   } else {
     LOG_E(PHY, "PUSCH mapping type A is not supported \n");
   }
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 3caaa6c99f..26800ed584 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -546,6 +546,7 @@ uint8_t nr_ue_pusch_common_procedures(PHY_VARS_NR_UE *UE,
            frame_parms);
       }
     }
+
   ///////////
   ////////////////////////////////////////////////////
   return 0;
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index 91a50d7361..3bca1138c0 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -375,6 +375,14 @@ typedef struct {
   /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
   /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
   int32_t **ul_ch_estimates_ext;
+  /// \brief Hold the PTRS phase estimates in frequency domain.
+  /// - first index: rx antenna id [0..nb_antennas_rx[
+  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
+  int32_t **ul_ch_ptrs_estimates;
+  /// \brief Uplink phase estimates extracted in PRBS.
+  /// - first index: ? [0..7] (hard coded) FIXME! accessed via \c nb_antennas_rx
+  /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
+  int32_t **ul_ch_ptrs_estimates_ext;
   /// \brief Holds the compensated signal.
   /// - first index: rx antenna id [0..nb_antennas_rx[
   /// - second index: ? [0..12*N_RB_UL*frame_parms->symbols_per_tti[
@@ -416,6 +424,12 @@ typedef struct {
   int16_t *llr;
   // DMRS symbol index, to be updated every DMRS symbol within a slot.
   uint8_t dmrs_symbol;
+  // PTRS symbol index, to be updated every PTRS symbol within a slot.
+  uint8_t ptrs_symbol_index;
+  /// bit mask of PT-RS ofdm symbol indicies
+  uint16_t ptrs_symbols;
+  // PTRS subcarriers per OFDM symbol
+  uint16_t ptrs_sc_per_ofdm_symbol;
 } NR_gNB_PUSCH;
 
 
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index adfb09ea6e..36603c2ec0 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -428,7 +428,7 @@ int main(int argc, char **argv)
   uint16_t number_dmrs_symbols = 0;
   unsigned int available_bits;
   uint8_t nb_re_dmrs;
-  uint8_t length_dmrs = UE->dmrs_UplinkConfig.pusch_maxLength;
+  uint8_t length_dmrs = UE->pusch_config.dmrs_UplinkConfig.pusch_maxLength;
   unsigned char mod_order;
   uint16_t code_rate;
 
@@ -440,12 +440,12 @@ int main(int argc, char **argv)
                                             0,
                                             0,
                                             nb_symb_sch,
-                                            &UE->dmrs_UplinkConfig,
+                                            &UE->pusch_config.dmrs_UplinkConfig,
                                             UE->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType,
                                             frame_parms->ofdm_symbol_size);
 
   mod_order      = nr_get_Qm_ul(Imcs, 0);
-  nb_re_dmrs     = ((UE->dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1) ? 6 : 4) * number_dmrs_symbols;
+  nb_re_dmrs     = ((UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1) ? 6 : 4) * number_dmrs_symbols;
   code_rate      = nr_get_code_rate_ul(Imcs, 0);
   available_bits = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, mod_order, 1);
   TBS            = nr_compute_tbs(mod_order, code_rate, nb_rb, nb_symb_sch, nb_re_dmrs*length_dmrs, 0, precod_nbr_layers);

From 8fbdfa39ec6051b29f65ee8a5beb273bd4a7e84f Mon Sep 17 00:00:00 2001
From: Thomas Schlichter 
Date: Thu, 5 Mar 2020 10:27:35 +0100
Subject: [PATCH 31/73] disable PUSCH PTRS for now

As adding PTRS leads to shortening of the coded data, redudandency is removed and the performance decreases on a pure AWGN channel.
So PTRS should only be enabled if phase noise is present.
---
 openair1/PHY/INIT/nr_init.c    | 2 +-
 openair1/PHY/INIT/nr_init_ue.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index 00fd616aa0..bf8f857a04 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -170,7 +170,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
     gNB->pusch_config.pusch_TimeDomainResourceAllocation[i]->mappingType = typeB;
   }
 
-  gNB->ptrs_configured = 1;
+  gNB->ptrs_configured = 0;
 
   //------------- config PUSCH PTRS parameters(to be updated from RRC)--------------//
   ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index 773d048942..7b7954583d 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -748,7 +748,7 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
   /////////////////////////PUSCH PTRS init/////////////////////////
   ///////////
 
-  ue->ptrs_configured = 1; // flag to be toggled by RCC
+  ue->ptrs_configured = 0; // flag to be toggled by RCC
 
   //------------- config PTRS parameters--------------//
   ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration

From 5f851d45b32b91b68412338503dc4aa52fb26b91 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Wed, 4 Mar 2020 15:45:16 +0100
Subject: [PATCH 32/73] Fill UE RX Indication Rel9 to prevent error message

---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 4b331c1cb0..bff50310b4 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -71,6 +71,8 @@ void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND
 	  //pdu->rx_indication_rel8.length         = eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3;
 	  pdu->rx_indication_rel8.length         = buflen;
 	  pdu->rx_indication_rel8.offset         = 1;   // DJP - I dont understand - but broken unless 1 ????  0;  // filled in at the end of the UL_INFO formation
+	  pdu->rx_indication_rel9.tl.tag = NFAPI_RX_INDICATION_REL9_TAG;
+	  pdu->rx_indication_rel9.timing_advance_r9 = 0;
 
 	  // ulsch_buffer is necessary to keep its value.
 	  //pdu->data                              = ulsch_buffer;

From c321f9b5a351d2c4c8073a3136d3a74cb3418cba Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 10:18:03 +0100
Subject: [PATCH 33/73] Make UE mem alloc for UL_INFO only once in PHY stub
 mode

---
 targets/RT/USER/lte-ue.c | 67 +++++++++++++++++-----------------------
 1 file changed, 29 insertions(+), 38 deletions(-)

diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 5a8afc2358..940d65282d 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -992,6 +992,19 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
   phy_stub_ticking->num_single_thread[ue_thread_id] = -1;
   UE = rtd->UE;
 
+  UL_INFO = (UL_IND_t *)malloc(sizeof(UL_IND_t));
+  UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = calloc(NB_UE_INST, sizeof(nfapi_rx_indication_pdu_t));
+  UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0;
+  UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = calloc(NB_UE_INST, sizeof(nfapi_crc_indication_pdu_t));
+  UL_INFO->crc_ind.crc_indication_body.number_of_crcs = 0;
+  UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = calloc(NB_UE_INST, sizeof(nfapi_harq_indication_pdu_t));
+  UL_INFO->harq_ind.harq_indication_body.number_of_harqs = 0;
+  UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = calloc(NB_UE_INST, sizeof(nfapi_sr_indication_pdu_t));
+  UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0;
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list =  calloc(NB_UE_INST, sizeof(nfapi_cqi_indication_pdu_t));
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = calloc(NB_UE_INST, sizeof(nfapi_cqi_indication_raw_pdu_t));
+  UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis = 0;
+
   if(ue_thread_id == 0) {
     phy_stub_ticking->ticking_var = -1;
     proc->subframe_rx=proc->sub_frame_start;
@@ -1064,20 +1077,6 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
         initRefTimes(t3);
         pickTime(current);
         updateTimes(proc->gotIQs, &t2, 10000, "Delay to wake up UE_Thread_Rx (case 2)");*/
-      // Not sure whether we should put the memory allocation here and not sure how much memory
-      //we should allocate for each subframe cycle.
-      UL_INFO = (UL_IND_t *)malloc(sizeof(UL_IND_t));
-      UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = (nfapi_rx_indication_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_rx_indication_pdu_t));
-      UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0;
-      UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = (nfapi_crc_indication_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_crc_indication_pdu_t));
-      UL_INFO->crc_ind.crc_indication_body.number_of_crcs = 0;
-      UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = (nfapi_harq_indication_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_harq_indication_pdu_t));
-      UL_INFO->harq_ind.harq_indication_body.number_of_harqs = 0;
-      UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = (nfapi_sr_indication_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_sr_indication_pdu_t));
-      UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0;
-      UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list =  (nfapi_cqi_indication_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_cqi_indication_pdu_t));
-      UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = (nfapi_cqi_indication_raw_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_cqi_indication_raw_pdu_t));
-      UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis = 0;
 
       if (pthread_mutex_lock(&phy_stub_ticking->mutex_single_thread) != 0) {
         LOG_E( MAC, "[SCHED][UE] error locking mutex for ue_thread_id %d (mutex_single_thread)\n",ue_thread_id);
@@ -1267,30 +1266,6 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
         UL_INFO->sr_ind.sr_indication_body.number_of_srs = 0;
       }
 
-      // Free UL_INFO messages
-      //if(UL_INFO->crc_ind.crc_indication_body.crc_pdu_list != NULL){
-      free(UL_INFO->crc_ind.crc_indication_body.crc_pdu_list);
-      UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = NULL;
-      //}
-      //if(UL_INFO->rx_ind.rx_indication_body.rx_pdu_list != NULL){
-      free(UL_INFO->rx_ind.rx_indication_body.rx_pdu_list);
-      UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = NULL;
-      //}
-      //if(UL_INFO->harq_ind.harq_indication_body.harq_pdu_list !=NULL){
-      free(UL_INFO->harq_ind.harq_indication_body.harq_pdu_list);
-      UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = NULL;
-      //}
-      //if(UL_INFO->sr_ind.sr_indication_body.sr_pdu_list!=NULL){
-      free(UL_INFO->sr_ind.sr_indication_body.sr_pdu_list);
-      UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = NULL;
-      //}
-      free(UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list);
-      UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list = NULL;
-      free(UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list);
-      UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = NULL;
-      free(UL_INFO);
-      UL_INFO = NULL;
-
       // De-allocate memory of nfapi requests copies before next subframe round
       if(dl_config_req!=NULL) {
         if(dl_config_req->vendor_extension!=NULL) {
@@ -1334,6 +1309,22 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
     }
   }
 
+  // Free UL_INFO messages
+  free(UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list);
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list = NULL;
+  free(UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list);
+  UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list = NULL;
+  free(UL_INFO->sr_ind.sr_indication_body.sr_pdu_list);
+  UL_INFO->sr_ind.sr_indication_body.sr_pdu_list = NULL;
+  free(UL_INFO->harq_ind.harq_indication_body.harq_pdu_list);
+  UL_INFO->harq_ind.harq_indication_body.harq_pdu_list = NULL;
+  free(UL_INFO->crc_ind.crc_indication_body.crc_pdu_list);
+  UL_INFO->crc_ind.crc_indication_body.crc_pdu_list = NULL;
+  free(UL_INFO->rx_ind.rx_indication_body.rx_pdu_list);
+  UL_INFO->rx_ind.rx_indication_body.rx_pdu_list = NULL;
+  free(UL_INFO);
+  UL_INFO = NULL;
+
   // thread finished
   free(arg);
   return &UE_thread_rxtx_retval;

From 15a2767562fc6e3eba71c2776e67c6cd497636f6 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 11:39:38 +0100
Subject: [PATCH 34/73] Don't call fill_ulsch_cqi_indication_UE_MAC()

This functions fills the ULSCH CQI indication message incorrectly. Also,
it should only be triggered when the eNB requests CSI. We disable it
here and a subsequent commit enables it again.
---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index bff50310b4..6ba238aa75 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -489,7 +489,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
 			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_buffer,buflen, rnti, index);
 		  }
 	  }
-	  fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
+	  //fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
 
   }
   else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) {
@@ -519,7 +519,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
 
 	  if(ulsch_harq_information!=NULL)
 		  fill_ulsch_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
-	  fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
+	  //fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
 
   }
   else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) {

From 8af8836c4beb8db31a57c8cdfbe0de859acb1c8c Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Wed, 4 Mar 2020 18:21:46 +0100
Subject: [PATCH 35/73] Call oai_nfapi_cqi_indication() to send cqi_indications

---
 targets/RT/USER/lte-ue.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 940d65282d..0b2f14d384 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -88,7 +88,7 @@ extern void oai_subframe_ind(uint16_t sfn, uint16_t sf);
 extern void multicast_link_start(void (*rx_handlerP) (unsigned int, char *),
                                  unsigned char _multicast_group, char *multicast_ifname);
 extern int oai_nfapi_crc_indication(nfapi_crc_indication_t *crc_ind);
-extern int oai_nfapi_crc_indication(nfapi_crc_indication_t *crc_ind);
+extern int oai_nfapi_cqi_indication(nfapi_cqi_indication_t *cqi_ind);
 extern int oai_nfapi_harq_indication(nfapi_harq_indication_t *harq_ind);
 extern int oai_nfapi_sr_indication(nfapi_sr_indication_t *ind);
 extern int oai_nfapi_rx_ind(nfapi_rx_indication_t *ind);
@@ -1252,6 +1252,11 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
         UL_INFO->rx_ind.rx_indication_body.number_of_pdus = 0;
       }
 
+      if (UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis > 0) {
+        oai_nfapi_cqi_indication(&UL_INFO->cqi_ind);
+        UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis = 0;
+      }
+
       if(UL_INFO->harq_ind.harq_indication_body.number_of_harqs>0) {
         //LOG_D(MAC, "ul_config_req_UE_MAC 2.4, SFN/SF of PNF counter:%d.%d, number_of_harqs: %d \n", timer_frame, timer_subframe, UL_INFO->harq_ind.harq_indication_body.number_of_harqs);
         oai_nfapi_harq_indication(&UL_INFO->harq_ind);

From b34a0e2f54e382a8e3f4fee776ffe325af4e782d Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 10:18:32 +0100
Subject: [PATCH 36/73] Increase (fixed) PHR for UE phy stub mode (L2 sim)

---
 openair2/LAYER2/MAC/ue_procedures.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c
index 8518cba14c..1205851915 100644
--- a/openair2/LAYER2/MAC/ue_procedures.c
+++ b/openair2/LAYER2/MAC/ue_procedures.c
@@ -2158,7 +2158,7 @@ ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
   if (phr_ce_len == sizeof(POWER_HEADROOM_CMD)) {
     if(NFAPI_MODE==NFAPI_UE_STUB_PNF) {
       //Substitute with a static value for the MAC layer abstraction (phy_stub mode)
-      phr_p->PH = 40;
+      phr_p->PH = 60;
     } else {
       phr_p->PH = get_phr_mapping(module_idP, CC_id, eNB_index);
     }

From c85d0878c1e128c4556cd00758fd6eac965328e6 Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani 
Date: Fri, 6 Mar 2020 13:40:03 +0100
Subject: [PATCH 37/73] Reverting the changes made in fo calculation While
 fixing bug in PSS index calculation in
 334519d16a9da34118c5568859eab6f68ae93ca9, I made changes in FO calculation as
 well. This is not nedeed and caused the FO to misbehave. Hence, reverting it.

---
 openair1/PHY/NR_UE_TRANSPORT/pss_nr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
index 070d01b5a3..09358e615c 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
@@ -914,13 +914,13 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain
 	  int64_t result1,result2;
 	  // Computing cross-correlation at peak on half the symbol size for first half of data
 	  result1  = dot_product64((short*)primary_synchro_time_nr[pss_source], 
-				  (short*) &(rxdata[0][peak_position+is*frame_parms->samples_per_frame]), 
+				  (short*) &(rxdata[0][peak_position])+(is*frame_parms->samples_per_frame), 
 				  frame_parms->ofdm_symbol_size>>1, 
 				  shift);
 	  // Computing cross-correlation at peak on half the symbol size for data shifted by half symbol size 
 	  // as it is real and complex it is necessary to shift by a value equal to symbol size to obtain such shift
 	  result2  = dot_product64((short*)primary_synchro_time_nr[pss_source]+(frame_parms->ofdm_symbol_size), 
-				  (short*) &(rxdata[0][peak_position+frame_parms->ofdm_symbol_size+(is*frame_parms->samples_per_frame)]), 
+				  (short*) &(rxdata[0][peak_position])+(frame_parms->ofdm_symbol_size+(is*frame_parms->samples_per_frame)), 
 				  frame_parms->ofdm_symbol_size>>1, 
 				  shift);
 

From fcb211b014c0181c485e3d9591b4c78b2e445856 Mon Sep 17 00:00:00 2001
From: Raymond Knopp 
Date: Fri, 6 Mar 2020 17:15:28 +0100
Subject: [PATCH 38/73] Fixing FO compensation in UE Actually there was a bug
 in FO compensation which I overlooked in last commit.

---
 openair1/PHY/NR_UE_TRANSPORT/pss_nr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
index 09358e615c..e8eceb77a6 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/pss_nr.c
@@ -914,13 +914,13 @@ int pss_search_time_nr(int **rxdata, ///rx data in time domain
 	  int64_t result1,result2;
 	  // Computing cross-correlation at peak on half the symbol size for first half of data
 	  result1  = dot_product64((short*)primary_synchro_time_nr[pss_source], 
-				  (short*) &(rxdata[0][peak_position])+(is*frame_parms->samples_per_frame), 
+				  (short*) &(rxdata[0][peak_position+is*frame_parms->samples_per_frame]), 
 				  frame_parms->ofdm_symbol_size>>1, 
 				  shift);
 	  // Computing cross-correlation at peak on half the symbol size for data shifted by half symbol size 
 	  // as it is real and complex it is necessary to shift by a value equal to symbol size to obtain such shift
 	  result2  = dot_product64((short*)primary_synchro_time_nr[pss_source]+(frame_parms->ofdm_symbol_size), 
-				  (short*) &(rxdata[0][peak_position])+(frame_parms->ofdm_symbol_size+(is*frame_parms->samples_per_frame)), 
+				  (short*) &(rxdata[0][peak_position+is*frame_parms->samples_per_frame])+frame_parms->ofdm_symbol_size, 
 				  frame_parms->ofdm_symbol_size>>1, 
 				  shift);
 

From 943f907ae1d3dc66b271c540fadf068413d6a429 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 16:02:52 +0100
Subject: [PATCH 39/73] Send correct ULSCH CQI indication message in L2 sim

---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 29 ++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 6ba238aa75..9aa3400a33 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -241,27 +241,32 @@ void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, uint16_t frame,uint8_t subfram
 	nfapi_cqi_indication_pdu_t *pdu         = &UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list[UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis];
 	nfapi_cqi_indication_raw_pdu_t *raw_pdu = &UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list[UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis];
 
+	UL_INFO->cqi_ind.sfn_sf = frame << 4 | subframe;
+        // because of nfapi_vnf.c:733, set message id to 0, not NFAPI_RX_CQI_INDICATION;
+	UL_INFO->cqi_ind.header.message_id = 0;
+	UL_INFO->cqi_ind.cqi_indication_body.tl.tag = NFAPI_CQI_INDICATION_BODY_TAG;
+
 	pdu->rx_ue_information.tl.tag          = NFAPI_RX_UE_INFORMATION_TAG;
 	pdu->rx_ue_information.rnti = rnti;
 	// Since we assume that CRC flag is always 0 (ACK) I guess that data_offset should always be 0.
-	pdu->cqi_indication_rel9.data_offset = 0;
+	pdu->cqi_indication_rel8.data_offset = 0;
 
 	// by default set O to rank 1 value
-	//pdu->cqi_indication_rel9.length = (ulsch_harq->Or1>>3) + ((ulsch_harq->Or1&7) > 0 ? 1 : 0);
+	//pdu->cqi_indication_rel8.length = (ulsch_harq->Or1>>3) + ((ulsch_harq->Or1&7) > 0 ? 1 : 0);
 	//  Not useful field for our case
-	pdu->cqi_indication_rel9.tl.tag = NFAPI_CQI_INDICATION_REL9_TAG;
-	pdu->cqi_indication_rel9.length = 0;
-	pdu->cqi_indication_rel9.ri[0]  = 0;
+	pdu->cqi_indication_rel8.tl.tag = NFAPI_CQI_INDICATION_REL8_TAG;
+	pdu->cqi_indication_rel8.length = 1;
+	pdu->cqi_indication_rel8.ri  = 0;
 
 
-	pdu->cqi_indication_rel9.timing_advance = 0;
-  pdu->cqi_indication_rel9.number_of_cc_reported = 1;
-  pdu->ul_cqi_information.channel = 1; // PUSCH
+	pdu->cqi_indication_rel8.timing_advance = 0;
+	//pdu->cqi_indication_rel8.number_of_cc_reported = 1;
+	pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
+	pdu->ul_cqi_information.channel = 1; // PUSCH
 
-  // Not sure how to substitute this. This should be the actual CQI value? So can
-  // we hardcode it to a specific value?
-  //memcpy((void*)raw_pdu->pdu,ulsch_harq->o,pdu->cqi_indication_rel9.length);
-  raw_pdu->pdu[0] = 7;
+	// eNB_scheduler_primitives.c:4839: the upper four bits seem to be the CQI
+	const int cqi = 15;
+	raw_pdu->pdu[0] = cqi << 4;
 
 
 

From 6866be7175ca86af7ab229c695ec475730589cca Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 15:28:36 +0100
Subject: [PATCH 40/73] Trigger ULSCH CQI ind only when instructed

---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 9aa3400a33..9357e354d4 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -494,8 +494,6 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
 			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_buffer,buflen, rnti, index);
 		  }
 	  }
-	  //fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
-
   }
   else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) {
 
@@ -524,8 +522,6 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
 
 	  if(ulsch_harq_information!=NULL)
 		  fill_ulsch_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
-	  //fill_ulsch_cqi_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
-
   }
   else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) {
 
@@ -812,8 +808,18 @@ int hi_dci0_req_UE_MAC(nfapi_hi_dci0_request_t* req, module_id_t Mod_id)
 
     if (req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE)
     {
-      LOG_D(PHY,"[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d] - NFAPI_HI_DCI0_DCI_PDU_TYPE not used \n", NFAPI_SFNSF2DEC(req->sfn_sf), i);
-
+      LOG_D(PHY,
+            "[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d] - "
+            "NFAPI_HI_DCI0_DCI_PDU_TYPE\n",
+            NFAPI_SFNSF2DEC(req->sfn_sf),
+            i);
+      const nfapi_hi_dci0_dci_pdu_rel8_t *dci = &req->hi_dci0_request_body.hi_dci0_pdu_list[i].dci_pdu.dci_pdu_rel8;
+      if (dci->rnti != UE_mac_inst[Mod_id].crnti)
+        continue;
+      const int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
+      const int sf = NFAPI_SFNSF2SF(req->sfn_sf);
+      if (dci->cqi_csi_request)
+        fill_ulsch_cqi_indication_UE_MAC(Mod_id, sfn, sf, UL_INFO, dci->rnti);
     }
     else if (req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type == NFAPI_HI_DCI0_HI_PDU_TYPE)
     {

From 6ec6c8b261f99427724c0c428502638daeea6fbf Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 16:02:22 +0100
Subject: [PATCH 41/73] Request CQI in all NFAPI modes (i.e., also for L2 sim)

---
 openair2/LAYER2/MAC/eNB_scheduler_ulsch.c | 49 ++++++++++-------------
 1 file changed, 22 insertions(+), 27 deletions(-)

diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index d240e35a87..7c3b536de2 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -1496,38 +1496,33 @@ schedule_ulsch_rnti(module_id_t   module_idP,
 
           if (status >= RRC_CONNECTED && UE_sched_ctrl_ptr->cqi_req_timer > 30) {
             if (UE_sched_ctrl_ptr->cqi_received == 0) {
-              if (NFAPI_MODE != NFAPI_MONOLITHIC) {
-                cqi_req = 0;
-              } else {
-                cqi_req = 1;
-                LOG_D(MAC,"Setting CQI_REQ (timer %d)\n",UE_sched_ctrl_ptr->cqi_req_timer);
+              cqi_req = 1;
+              LOG_D(MAC,
+                    "Setting CQI_REQ (timer %d)\n",
+                    UE_sched_ctrl_ptr->cqi_req_timer);
 
-                /* TDD: to be safe, do not ask CQI in special Subframes:36.213/7.2.3 CQI definition */
-                if (cc[CC_id].tdd_Config) {
-                  switch (cc[CC_id].tdd_Config->subframeAssignment) {
-                    case 1:
-                      if(subframeP == 1 || subframeP == 6) {
-                        cqi_req=0;
-                      }
+              /* TDD: to be safe, do not ask CQI in special
+               * Subframes:36.213/7.2.3 CQI definition */
+              if (cc[CC_id].tdd_Config) {
+                switch (cc[CC_id].tdd_Config->subframeAssignment) {
+                  case 1:
+                    if (subframeP == 1 || subframeP == 6)
+                      cqi_req = 0;
+                    break;
 
-                      break;
+                  case 3:
+                    if (subframeP == 1)
+                      cqi_req = 0;
+                    break;
 
-                    case 3:
-                      if(subframeP == 1) {
-                        cqi_req=0;
-                      }
-
-                      break;
-
-                    default:
-                      LOG_E(MAC," TDD config not supported\n");
-                      break;
-                  }
+                  default:
+                    LOG_E(MAC, " TDD config not supported\n");
+                    break;
                 }
+              }
 
-                if(cqi_req == 1) {
-                  UE_sched_ctrl_ptr->cqi_req_flag |= 1 << sched_subframeP;
-                }
+              if (cqi_req == 1) {
+                UE_sched_ctrl_ptr->cqi_req_flag |= 1 << sched_subframeP;
               }
             } else {
               LOG_D(MAC,"Clearing CQI request timer\n");

From 719667895c58bb691599707df0676f18d32c6a6a Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 18:24:49 +0100
Subject: [PATCH 42/73] Prevent memory leak in L2 sim due to NFAPI

---
 targets/RT/USER/lte-ue.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 0b2f14d384..75ed018434 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -1288,6 +1288,13 @@ static void *UE_phy_stub_single_thread_rxn_txnp4(void *arg)
       }
 
       if(tx_request_pdu_list!=NULL) {
+        for (int i = 0; i < tx_req_num_elems; i++) {
+          for (int j = 0; j < tx_request_pdu_list[i].num_segments; j++) {
+            free(tx_request_pdu_list[i].segments[j].segment_data);
+            tx_request_pdu_list[i].segments[j].segment_data = NULL;
+          }
+        }
+        tx_req_num_elems = 0;
         free(tx_request_pdu_list);
         tx_request_pdu_list = NULL;
       }

From 34e7952944542212e0f2043afc2889a45d3a0eb9 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Thu, 5 Mar 2020 18:49:08 +0100
Subject: [PATCH 43/73] CI: Multi. UEs handled by 1 thread (no races) in l2sim

---
 ci-scripts/runTestOnVM.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/ci-scripts/runTestOnVM.sh b/ci-scripts/runTestOnVM.sh
index d46ed07bbb..4e1734da63 100755
--- a/ci-scripts/runTestOnVM.sh
+++ b/ci-scripts/runTestOnVM.sh
@@ -870,9 +870,9 @@ function start_l2_sim_ue {
     echo "cd /home/ubuntu/tmp/cmake_targets/ran_build/build/" >> $1
     if [ $LOC_S1_CONFIGURATION -eq 0 ]
     then
-        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread $LOC_NB_UES --nokrnmod 1 --log_config.global_log_options level,nocolor --noS1\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread 1 --nokrnmod 1 --log_config.global_log_options level,nocolor --noS1\" > ./my-lte-softmodem-run.sh " >> $1
     else
-        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread $LOC_NB_UES --nokrnmod 1 --log_config.global_log_options level,nocolor\" > ./my-lte-softmodem-run.sh " >> $1
+        echo "echo \"ulimit -c unlimited && ./lte-uesoftmodem -O /home/ubuntu/tmp/ci-scripts/conf_files/ci-$LOC_CONF_FILE --L2-emul 3 --num-ues $LOC_NB_UES --nums_ue_thread 1 --nokrnmod 1 --log_config.global_log_options level,nocolor\" > ./my-lte-softmodem-run.sh " >> $1
     fi
     echo "chmod 775 ./my-lte-softmodem-run.sh" >> $1
     echo "cat ./my-lte-softmodem-run.sh" >> $1

From fa7ace4b1d69ef904875246c649dae29ef1c63b3 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Fri, 6 Mar 2020 19:40:38 +0100
Subject: [PATCH 44/73] Reimplement dl_config_req_UE_MAC() more concisely

---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 256 ++++++++++++---------------
 1 file changed, 118 insertions(+), 138 deletions(-)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 9357e354d4..075ea30d00 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -644,154 +644,134 @@ int tx_req_UE_MAC(nfapi_tx_request_t* req)
 }
 
 
-int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) //, nfapi_tx_request_pdu_t* tx_request_pdu_list)
-{
-	//if (req!=NULL && tx_request_pdu_list!=NULL){
+int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) {
   int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
   int sf = NFAPI_SFNSF2SF(req->sfn_sf);
-  //Mod_id = 0; // Currently static (only for one UE) but this should change.
 
-  /*struct PHY_VARS_eNB_s *eNB = RC.eNB[0][0];
-  L1_rxtx_proc_t *proc = &eNB->proc.L1_proc;*/
   nfapi_dl_config_request_pdu_t* dl_config_pdu_list = req->dl_config_request_body.dl_config_pdu_list;
-  nfapi_dl_config_request_pdu_t *dl_config_pdu_tmp;
 
-  //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() TX:%d/%d RX:%d/%d sfn_sf:%d DCI:%d PDU:%d\n", __FUNCTION__, proc->frame_tx, proc->subframe_tx, proc->frame_rx, proc->subframe_rx, NFAPI_SFNSF2DEC(req->sfn_sf), req->dl_config_request_body.number_dci, req->dl_config_request_body.number_pdu);
+  for (int i = 0; i < req->dl_config_request_body.number_pdu; i++) {
+    if (dl_config_pdu_list[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE) {
+      const rnti_t rnti = dl_config_pdu_list[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti;
+      const int rnti_type = dl_config_pdu_list[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type;
+      /* We assume the DCI DL PDU is followed by the DLSCH (the standard is
+       * more free), so advance by one more and directly process the
+       * following DLSCH PDU */
+      i++;
+      AssertFatal(i < req->dl_config_request_body.number_pdu,
+                  "Need PDU following DCI at index %d, but not found\n",
+                  i);
+      nfapi_dl_config_request_pdu_t *dl_config_pdu_tmp = &dl_config_pdu_list[i];
+      if (dl_config_pdu_tmp->pdu_type != NFAPI_DL_CONFIG_DLSCH_PDU_TYPE) {
+        LOG_E(MAC, "expected DLSCH PDU at index %d\n", i);
+        continue;
+      }
+      if (rnti != dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti) {
+        LOG_I(MAC,
+              "%s(): sfn/sf %d DLSCH PDU RNTI %x does not match DCI RNTI %x\n",
+              __func__,
+              NFAPI_SFNSF2DEC(req->sfn_sf),
+              rnti,
+              dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti);
+        continue;
+      }
+      const int pdu_index = dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index;
+      if (pdu_index < 0 && pdu_index >= tx_req_num_elems) {
+        LOG_E(MAC,
+              "dl_config_req_UE_MAC 2: Problem with receiving data: "
+              "sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d\n",
+              NFAPI_SFNSF2DEC(req->sfn_sf),
+              i,
+              dl_config_pdu_list[i].pdu_size,
+              dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index);
+        continue;
+      }
+      if (rnti_type == 1) {
+        // C-RNTI (Normal DLSCH case)
+        if (UE_mac_inst[Mod_id].crnti != rnti) {
+          LOG_D(MAC,
+                "sfn/sf %d/%d DCI not for UE %d/RNTI %x but for RNTI %x, "
+                "skipping\n",
+                sfn, sf, Mod_id, UE_mac_inst[Mod_id].crnti, rnti);
+          continue;
+        }
 
+        LOG_D(MAC,
+              "%s() Received data: sfn/sf:%d PDU[%d] "
+              "size:%d, TX_PDU index: %d, tx_req_num_elems: %d \n",
+              __func__,
+              NFAPI_SFNSF2DEC(req->sfn_sf),
+              i,
+              dl_config_pdu_list[i].pdu_size,
+              dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index,
+              tx_req_num_elems);
+        ue_send_sdu(Mod_id, 0, sfn, sf,
+            tx_request_pdu_list[pdu_index].segments[0].segment_data,
+            tx_request_pdu_list[pdu_index].segments[0].segment_length,
+            0);
+      } else if (rnti_type == 2) {
+        if (rnti == 0xFFFF) { /* SI-RNTI */
+          if (UE_mac_inst[Mod_id].UE_mode[0] == NOT_SYNCHED) {
+            /* this check is in the code before refactoring, but I don't know
+             * why. Leave it in here for the moment */
+            continue;
+          }
 
-
-  //LOG_D(PHY,"NFAPI: Sched_INFO:SFN/SF:%d%d dl_pdu:%d tx_req:%d hi_dci0:%d ul_cfg:%d num_pdcch_symbols:%d\n",
-  //	frame,subframe,number_dl_pdu,TX_req->tx_request_body.number_of_pdus,number_hi_dci0_pdu,number_ul_pdu, eNB->pdcch_vars[subframe&1].num_pdcch_symbols);
-
-  for (int i=0;idl_config_request_body.number_pdu;i++)
-  {
-    //NFAPI_TRACE(NFAPI_TRACE_INFO, "%s() sfn/sf:%d PDU[%d] size:%d\n", __FUNCTION__, NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size);
-	  //LOG_E(MAC, "dl_config_req_UE_MAC 2 Received real ones: sfn/sf:%d.%d PDU[%d] size:%d\n", sfn, sf, i, dl_config_pdu_list[i].pdu_size);
-
-    if (dl_config_pdu_list[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
-    {
-		if (dl_config_pdu_list[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == 1) {
-			// C-RNTI (Normal DLSCH case)
-			dl_config_pdu_tmp = &dl_config_pdu_list[i+1];
-			if (dl_config_pdu_tmp->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE && UE_mac_inst[Mod_id].crnti == dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti){
-
-				/*nfapi_tx_request_pdu_t *ptr = tx_request_pdu_list;
-				ptr += dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index*(sizeof(nfapi_tx_request_pdu_t));
-				nfapi_tx_request_pdu_t temp;
-				memset(&temp, 0, sizeof(nfapi_tx_request_pdu_t));
-				//if (!memcmp(&temp, ptr, sizeof(temp)) ...
-				if( *(char*)ptr != 0){
-				//if(tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data!= NULL && tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_length >0){
-				*/
-
-				// to avoid unexpected error , add check pdu_index is more than 0.
-				if((dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index >= 0) &&(dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index <= tx_req_num_elems -1)){
-				//if(tx_request_pdu_list + dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index!= NULL){
-
-					LOG_I(MAC, "dl_config_req_UE_MAC 2 Received data: sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d, tx_req_num_elems: %d \n", NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size, dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index, tx_req_num_elems);
-
-					ue_send_sdu(Mod_id, 0, sfn, sf,
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data,
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_length,
-							0);
-					i++;
-				}
-				else{
-					LOG_E(MAC,"dl_config_req_UE_MAC 2: Problem with receiving data: sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d\n", NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size, dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index);
-					i++;
-				}
-			}
-			else {
-				LOG_W(MAC,"[UE %d] Frame %d, subframe %d : DLSCH PDU from NFAPI not for this UE \n",Mod_id, sfn,sf);
-				i++;
-			}
-		}
-		else if (dl_config_pdu_list[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type == 2) {
-			dl_config_pdu_tmp = &dl_config_pdu_list[i+1];
-			if(dl_config_pdu_tmp->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE && dl_config_pdu_list[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti == 0xFFFF && UE_mac_inst[Mod_id].UE_mode[0] != NOT_SYNCHED){ //&& UE_mac_inst[Mod_id].UE_mode[0] != NOT_SYNCHED
-
-				if(dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index <= tx_req_num_elems -1){
-				//if(tx_request_pdu_list + dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index!= NULL){
-					ue_decode_si(Mod_id, 0, sfn, 0,
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data,
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_length);
-					i++;
-				}
-				else{
-					LOG_E(MAC,"dl_config_req_UE_MAC 3: Problem with receiving SI: sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d\n", NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size, dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index);
-					i++;
-				}
-			}
-			else if(dl_config_pdu_tmp->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE && dl_config_pdu_list[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti == 0xFFFE){
-				// P_RNTI case
-				//pdu = Tx_req->tx_request_body.tx_pdu_list[dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data;
-
-				if (dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index <= tx_req_num_elems -1){
-				//if(tx_request_pdu_list + dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index!= NULL){
-					ue_decode_p(Mod_id, 0, sfn, 0,
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data,
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_length);
-					i++;
-				}
-				else{
-					LOG_E(MAC,"dl_config_req_UE_MAC: Problem with receiving Paging: sfn/sf:%d PDU[%d] size:%d, TX_PDU index: %d\n", NFAPI_SFNSF2DEC(req->sfn_sf), i, dl_config_pdu_list[i].pdu_size, dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index);
-					i++;
-				}
-			}
-			else if(dl_config_pdu_tmp->pdu_type == NFAPI_DL_CONFIG_DLSCH_PDU_TYPE) {
-				// RA-RNTI case
-				LOG_E(MAC,"dl_config_req_UE_MAC 4 Received RAR? \n");
-				// RNTI parameter not actually used. Provided only to comply with existing function definition.
-				// Not sure about parameters to fill the preamble index.
-				//rnti_t c_rnti = UE_mac_inst[Mod_id].crnti;
-				rnti_t ra_rnti = UE_mac_inst[Mod_id].RA_prach_resources.ra_RNTI;
-				if ((UE_mac_inst[Mod_id].UE_mode[0] != PUSCH) &&
-				  (UE_mac_inst[Mod_id].RA_prach_resources.Msg3!=NULL) && (ra_rnti== dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti) &&
-				  //(tx_request_pdu_list + dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index!= NULL)) {
-				  (dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index <= tx_req_num_elems -1)) {
-					LOG_E(MAC,"dl_config_req_UE_MAC 5 Received RAR, PreambleIndex: %d \n", UE_mac_inst[Mod_id].RA_prach_resources.ra_PreambleIndex);
-					ue_process_rar(Mod_id, 0, sfn,
-							ra_rnti, //RA-RNTI
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data,
-							&dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti, //t-crnti
-							UE_mac_inst[Mod_id].RA_prach_resources.ra_PreambleIndex,
-							tx_request_pdu_list[dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data);
-					UE_mac_inst[Mod_id].UE_mode[0] = RA_RESPONSE;
-					UE_mac_inst[Mod_id].first_ULSCH_Tx = 1; //Expecting an UL_CONFIG_ULSCH_PDU to enable Msg3 Txon (first ULSCH Txon for the UE)
-				}
-				i++;
-			}
-			else {
-				LOG_E(MAC,"[UE %d] Frame %d, subframe %d : Cannot extract DLSCH PDU from NFAPI 2\n",Mod_id, sfn, sf);
-				i++;
-			}
-
-		}
-    }
-    else if (dl_config_pdu_list[i].pdu_type == NFAPI_DL_CONFIG_BCH_PDU_TYPE)
-    {
-    	// BCH case
-    	// Last parameter is 1 if first time synchronization and zero otherwise. Not sure which value to put
-    	// for our case.
-    	//LOG_E(MAC,"dl_config_req_UE_MAC 4 Received MIB: sfn/sf: %d.%d \n", sfn, sf);
-    	if(UE_mac_inst[Mod_id].UE_mode[0] == NOT_SYNCHED){
-    		dl_phy_sync_success(Mod_id,sfn,0, 1);
-    		LOG_E(MAC,"dl_config_req_UE_MAC 5 Received MIB: UE_mode: %d, sfn/sf: %d.%d\n", UE_mac_inst[Mod_id].UE_mode[0], sfn, sf);
-    		UE_mac_inst[Mod_id].UE_mode[0]=PRACH;
-    	}
-    	else
-    		dl_phy_sync_success(Mod_id,sfn,0, 0);
-
-    }
-
-    else
-    {
-      //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() UNKNOWN:%d\n", __FUNCTION__, dl_config_pdu_list[i].pdu_type);
+          ue_decode_si(Mod_id, 0, sfn, 0,
+              tx_request_pdu_list[pdu_index].segments[0].segment_data,
+              tx_request_pdu_list[pdu_index].segments[0].segment_length);
+        } else if (rnti == 0xFFFE) { /* PI-RNTI */
+          LOG_I(MAC, "%s() Received paging message: sfn/sf:%d PDU[%d]\n",
+                __func__, NFAPI_SFNSF2DEC(req->sfn_sf), i);
+          ue_decode_p(Mod_id, 0, sfn, 0,
+                      tx_request_pdu_list[pdu_index].segments[0].segment_data,
+                      tx_request_pdu_list[pdu_index].segments[0].segment_length);
+        } else if (rnti == 0x0002) { /* RA-RNTI */
+          LOG_E(MAC, "%s(): Received RAR?\n", __func__);
+          // RNTI parameter not actually used. Provided only to comply with
+          // existing function definition.  Not sure about parameters to fill
+          // the preamble index.
+          const rnti_t ra_rnti = UE_mac_inst[Mod_id].RA_prach_resources.ra_RNTI;
+          DevAssert(ra_rnti == 0x0002);
+          if (UE_mac_inst[Mod_id].UE_mode[0] != PUSCH
+              && UE_mac_inst[Mod_id].RA_prach_resources.Msg3 != NULL
+              && ra_rnti == dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti) {
+            LOG_E(MAC,
+                  "dl_config_req_UE_MAC 5 Received RAR, PreambleIndex: %d \n",
+                  UE_mac_inst[Mod_id].RA_prach_resources.ra_PreambleIndex);
+            ue_process_rar(Mod_id, 0, sfn,
+                ra_rnti, //RA-RNTI
+                tx_request_pdu_list[pdu_index].segments[0].segment_data,
+                &dl_config_pdu_tmp->dlsch_pdu.dlsch_pdu_rel8.rnti, //t-crnti
+                UE_mac_inst[Mod_id].RA_prach_resources.ra_PreambleIndex,
+                tx_request_pdu_list[pdu_index].segments[0].segment_data);
+            UE_mac_inst[Mod_id].UE_mode[0] = RA_RESPONSE;
+            // Expecting an UL_CONFIG_ULSCH_PDU to enable Msg3 Txon (first
+            // ULSCH Txon for the UE)
+            UE_mac_inst[Mod_id].first_ULSCH_Tx = 1;
+          }
+        } else {
+          LOG_W(MAC, "can not handle special RNTI %x\n", rnti);
+        }
+      }
+    } else if (dl_config_pdu_list[i].pdu_type == NFAPI_DL_CONFIG_BCH_PDU_TYPE) {
+      // BCH case: Last parameter is 1 if first time synchronization and zero
+      // otherwise.  Not sure which value to put for our case.
+      if (UE_mac_inst[Mod_id].UE_mode[0] == NOT_SYNCHED){
+        dl_phy_sync_success(Mod_id, sfn, 0, 1);
+        LOG_E(MAC,
+              "%s(): Received MIB: UE_mode: %d, sfn/sf: %d.%d\n",
+              __func__,
+              UE_mac_inst[Mod_id].UE_mode[0],
+              sfn,
+              sf);
+        UE_mac_inst[Mod_id].UE_mode[0] = PRACH;
+      } else {
+        dl_phy_sync_success(Mod_id, sfn, 0, 0);
+      }
     }
   }
-
   return 0;
-
 }
 
 

From 84482489e4b393f4442747c2b766fe87c2bed761 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Sun, 8 Mar 2020 18:22:53 +0100
Subject: [PATCH 45/73] Reformat phy_stub_UE.c with clang-format

---
 openair2/PHY_INTERFACE/phy_stub_UE.c | 1418 ++++++++++++++------------
 1 file changed, 743 insertions(+), 675 deletions(-)

diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index 075ea30d00..bf2bbf7429 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -1,14 +1,29 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
 
-//#include "openair1/PHY/defs.h"
-//#include "openair2/PHY_INTERFACE/IF_Module.h"
-//#include "openair1/PHY/extern.h"
 #include "openair2/LAYER2/MAC/mac_extern.h"
 #include "openair2/LAYER2/MAC/mac.h"
 #include "openair2/LAYER2/MAC/mac_proto.h"
-//#include "openair2/LAYER2/MAC/vars.h"
 #include "openair1/SCHED_UE/sched_UE.h"
 #include "nfapi/open-nFAPI/nfapi/public_inc/nfapi_interface.h"
-//#include "common/ran_context.h"
 #include "openair2/PHY_INTERFACE/phy_stub_UE.h"
 #include "openair2/ENB_APP/L1_paramdef.h"
 #include "openair2/ENB_APP/enb_paramdef.h"
@@ -16,14 +31,12 @@
 #include "common/config/config_load_configmodule.h"
 #include "common/config/config_userapi.h"
 
-//#define DEADLINE_SCHEDULER 1
-
-
-extern int oai_nfapi_crc_indication(nfapi_crc_indication_t *crc_ind);
-extern int oai_nfapi_rx_ind(nfapi_rx_indication_t *ind);
 extern int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind);
-void configure_nfapi_pnf(char *vnf_ip_addr, int vnf_p5_port, char *pnf_ip_addr, int pnf_p7_port, int vnf_p7_port);
-
+void configure_nfapi_pnf(char *vnf_ip_addr,
+                         int vnf_p5_port,
+                         char *pnf_ip_addr,
+                         int pnf_p7_port,
+                         int vnf_p7_port);
 
 UL_IND_t *UL_INFO = NULL;
 nfapi_tx_request_pdu_t* tx_request_pdu_list = NULL;
@@ -31,8 +44,6 @@ nfapi_dl_config_request_t* dl_config_req = NULL;
 nfapi_ul_config_request_t* ul_config_req = NULL;
 nfapi_hi_dci0_request_t* hi_dci0_req = NULL;
 
-//extern uint8_t nfapi_pnf;
-//UL_IND_t *UL_INFO;
 extern nfapi_tx_request_pdu_t* tx_request_pdu[1023][10][10];
 //extern int timer_subframe;
 //extern int timer_frame;
@@ -42,608 +53,661 @@ extern uint16_t sf_ahead;
 void Msg1_transmitted(module_id_t module_idP,uint8_t CC_id,frame_t frameP, uint8_t eNB_id);
 void Msg3_transmitted(module_id_t module_idP,uint8_t CC_id,frame_t frameP, uint8_t eNB_id);
 
+void fill_rx_indication_UE_MAC(module_id_t Mod_id,
+                               int frame,
+                               int subframe,
+                               UL_IND_t *UL_INFO,
+                               uint8_t *ulsch_buffer,
+                               uint16_t buflen,
+                               uint16_t rnti,
+                               int index) {
+  nfapi_rx_indication_pdu_t *pdu;
+  int timing_advance_update;
 
+  pthread_mutex_lock(&fill_ul_mutex.rx_mutex);
 
-void fill_rx_indication_UE_MAC(module_id_t Mod_id,int frame,int subframe, UL_IND_t* UL_INFO, uint8_t *ulsch_buffer, uint16_t buflen, uint16_t rnti, int index)
-{
-	  nfapi_rx_indication_pdu_t *pdu;
+  UL_INFO->rx_ind.sfn_sf = frame << 4 | subframe;
+  UL_INFO->rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG;
+  UL_INFO->rx_ind.vendor_extension = ul_config_req->vendor_extension;
 
-	  int timing_advance_update;
+  pdu = &UL_INFO->rx_ind.rx_indication_body
+             .rx_pdu_list[UL_INFO->rx_ind.rx_indication_body.number_of_pdus];
+  // pdu = &UL_INFO->rx_ind.rx_indication_body.rx_pdu_list[index];
 
+  // pdu->rx_ue_information.handle          = eNB->ulsch[UE_id]->handle;
+  pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG;
+  pdu->rx_ue_information.rnti = rnti;
+  pdu->rx_indication_rel8.tl.tag = NFAPI_RX_INDICATION_REL8_TAG;
+  pdu->rx_indication_rel8.length = buflen;
+  pdu->rx_indication_rel8.offset = 1;
+  pdu->rx_indication_rel9.tl.tag = NFAPI_RX_INDICATION_REL9_TAG;
+  pdu->rx_indication_rel9.timing_advance_r9 = 0;
 
-	  // pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-	  // change for mutiple UE's simulation.
-	  pthread_mutex_lock(&fill_ul_mutex.rx_mutex);
+  // ulsch_buffer is necessary to keep its value.
+  pdu->data = malloc(buflen);
+  memcpy(pdu->data, ulsch_buffer, buflen);
+  // estimate timing advance for MAC
+  timing_advance_update = 0; // Don't know what to put here
+  pdu->rx_indication_rel8.timing_advance = timing_advance_update;
 
+  int SNRtimes10 = 640;
 
-	  UL_INFO->rx_ind.sfn_sf                    = frame<<4| subframe;
-	  UL_INFO->rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG;
-	  UL_INFO->rx_ind.vendor_extension		     = ul_config_req->vendor_extension;
-
-
-	  pdu                                    = &UL_INFO->rx_ind.rx_indication_body.rx_pdu_list[UL_INFO->rx_ind.rx_indication_body.number_of_pdus];
-	  //pdu                                    = &UL_INFO->rx_ind.rx_indication_body.rx_pdu_list[index];
-
-	  //  pdu->rx_ue_information.handle          = eNB->ulsch[UE_id]->handle;
-	  pdu->rx_ue_information.tl.tag          = NFAPI_RX_UE_INFORMATION_TAG;
-	  pdu->rx_ue_information.rnti            = rnti;
-	  pdu->rx_indication_rel8.tl.tag         = NFAPI_RX_INDICATION_REL8_TAG;
-	  //pdu->rx_indication_rel8.length         = eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3;
-	  pdu->rx_indication_rel8.length         = buflen;
-	  pdu->rx_indication_rel8.offset         = 1;   // DJP - I dont understand - but broken unless 1 ????  0;  // filled in at the end of the UL_INFO formation
-	  pdu->rx_indication_rel9.tl.tag = NFAPI_RX_INDICATION_REL9_TAG;
-	  pdu->rx_indication_rel9.timing_advance_r9 = 0;
-
-	  // ulsch_buffer is necessary to keep its value.
-	  //pdu->data                              = ulsch_buffer;
-	  pdu->data = malloc(buflen);
-	  memcpy(pdu->data,ulsch_buffer,buflen);
-	  // estimate timing advance for MAC
-	  //sync_pos                               = lte_est_timing_advance_pusch(eNB,UE_id);
-	  timing_advance_update                  = 0;  // Don't know what to put here
-	  pdu->rx_indication_rel8.timing_advance = timing_advance_update;
-
-		  int SNRtimes10 = 640;
-
-	  if      (SNRtimes10 < -640) pdu->rx_indication_rel8.ul_cqi=0;
-	  else if (SNRtimes10 >  635) pdu->rx_indication_rel8.ul_cqi=255;
-	  else                        pdu->rx_indication_rel8.ul_cqi=(640+SNRtimes10)/5;
-
-
-	  UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
-	  UL_INFO->rx_ind.sfn_sf = frame<<4 | subframe;
-	  // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-	  // change for mutiple UE's simulation.
-	  pthread_mutex_unlock(&fill_ul_mutex.rx_mutex);
-
+  if (SNRtimes10 < -640)
+    pdu->rx_indication_rel8.ul_cqi = 0;
+  else if (SNRtimes10 > 635)
+    pdu->rx_indication_rel8.ul_cqi = 255;
+  else
+    pdu->rx_indication_rel8.ul_cqi = (640 + SNRtimes10) / 5;
 
+  UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
+  UL_INFO->rx_ind.sfn_sf = frame << 4 | subframe;
+  pthread_mutex_unlock(&fill_ul_mutex.rx_mutex);
 }
 
-void fill_sr_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint16_t rnti) {
-
-
-  // change for mutiple UE's simulation.
-  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+void fill_sr_indication_UE_MAC(int Mod_id,
+                               int frame,
+                               int subframe,
+                               UL_IND_t *UL_INFO,
+                               uint16_t rnti) {
   pthread_mutex_lock(&fill_ul_mutex.sr_mutex);
 
-  nfapi_sr_indication_t       *sr_ind = &UL_INFO->sr_ind;
-  nfapi_sr_indication_body_t  *sr_ind_body =    &sr_ind->sr_indication_body;
-  nfapi_sr_indication_pdu_t *pdu =   &sr_ind_body->sr_pdu_list[sr_ind_body->number_of_srs];
-  UL_INFO->sr_ind.vendor_extension		     = ul_config_req->vendor_extension;
+  nfapi_sr_indication_t *sr_ind = &UL_INFO->sr_ind;
+  nfapi_sr_indication_body_t *sr_ind_body = &sr_ind->sr_indication_body;
+  nfapi_sr_indication_pdu_t *pdu = &sr_ind_body->sr_pdu_list[sr_ind_body->number_of_srs];
+  UL_INFO->sr_ind.vendor_extension = ul_config_req->vendor_extension;
 
-  //nfapi_sr_indication_pdu_t *pdu =   &UL_INFO->sr_ind.sr_indication_body.sr_pdu_list[UL_INFO->rx_ind.rx_indication_body.number_of_pdus];
-
-  sr_ind->sfn_sf = frame<<4|subframe;
+  sr_ind->sfn_sf = frame << 4 | subframe;
   sr_ind->header.message_id = NFAPI_RX_SR_INDICATION;
 
   sr_ind_body->tl.tag = NFAPI_SR_INDICATION_BODY_TAG;
 
-  pdu->instance_length                                = 0; // don't know what to do with this
+  pdu->instance_length = 0; // don't know what to do with this
   //  pdu->rx_ue_information.handle                       = handle;
-  pdu->rx_ue_information.tl.tag                       = NFAPI_RX_UE_INFORMATION_TAG;
-  pdu->rx_ue_information.rnti                         = rnti; //UE_mac_inst[Mod_id].crnti
-
-
-  // dependency from PHY not sure how to substitute this. Should we hardcode it?
-  //int SNRtimes10 = dB_fixed_times10(stat) - 200;//(10*eNB->measurements.n0_power_dB[0]);
-  int SNRtimes10 = 640;
+  pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG;
+  pdu->rx_ue_information.rnti = rnti; // UE_mac_inst[Mod_id].crnti
 
   pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
-
-
-  if      (SNRtimes10 < -640) pdu->ul_cqi_information.ul_cqi=0;
-  else if (SNRtimes10 >  635) pdu->ul_cqi_information.ul_cqi=255;
-  else                        pdu->ul_cqi_information.ul_cqi=(640+SNRtimes10)/5;
   pdu->ul_cqi_information.channel = 0;
 
-  //UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
+  int SNRtimes10 = 640;
+  if (SNRtimes10 < -640)
+    pdu->ul_cqi_information.ul_cqi = 0;
+  else if (SNRtimes10 > 635)
+    pdu->ul_cqi_information.ul_cqi = 255;
+  else
+    pdu->ul_cqi_information.ul_cqi = (640 + SNRtimes10) / 5;
+
+  // UL_INFO->rx_ind.rx_indication_body.number_of_pdus++;
   sr_ind_body->number_of_srs++;
-  // change for mutiple UE's simulation.
-  // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
   pthread_mutex_unlock(&fill_ul_mutex.sr_mutex);
 }
 
-
-void fill_crc_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint8_t crc_flag, int index, uint16_t rnti) {
-
-  // change for mutiple UE's simulation.
-  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+void fill_crc_indication_UE_MAC(int Mod_id,
+                                int frame,
+                                int subframe,
+                                UL_IND_t *UL_INFO,
+                                uint8_t crc_flag,
+                                int index,
+                                uint16_t rnti) {
   pthread_mutex_lock(&fill_ul_mutex.crc_mutex);
 
-  // REMEMBER HAVE EXCHANGED THE FOLLOWING TWO LINES HERE!
-  nfapi_crc_indication_pdu_t *pdu =   &UL_INFO->crc_ind.crc_indication_body.crc_pdu_list[UL_INFO->crc_ind.crc_indication_body.number_of_crcs];
+  nfapi_crc_indication_pdu_t *pdu =
+      &UL_INFO->crc_ind.crc_indication_body
+           .crc_pdu_list[UL_INFO->crc_ind.crc_indication_body.number_of_crcs];
 
-  UL_INFO->crc_ind.sfn_sf                    = frame<<4| subframe;
-  UL_INFO->crc_ind.vendor_extension		     = ul_config_req->vendor_extension;
-  UL_INFO->crc_ind.header.message_id              = NFAPI_CRC_INDICATION;
+  UL_INFO->crc_ind.sfn_sf = frame << 4 | subframe;
+  UL_INFO->crc_ind.vendor_extension = ul_config_req->vendor_extension;
+  UL_INFO->crc_ind.header.message_id = NFAPI_CRC_INDICATION;
   UL_INFO->crc_ind.crc_indication_body.tl.tag = NFAPI_CRC_INDICATION_BODY_TAG;
 
-  pdu->instance_length                                = 0; // don't know what to do with this
-  //  pdu->rx_ue_information.handle                       = handle;
-  pdu->rx_ue_information.tl.tag                       = NFAPI_RX_UE_INFORMATION_TAG;
+  pdu->instance_length = 0;
+  pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG;
 
-  //pdu->rx_ue_information.rnti                         = UE_mac_inst[Mod_id].crnti;
-  pdu->rx_ue_information.rnti                         = rnti;
-  pdu->crc_indication_rel8.tl.tag                     = NFAPI_CRC_INDICATION_REL8_TAG;
-  pdu->crc_indication_rel8.crc_flag                   = crc_flag;
+  pdu->rx_ue_information.rnti = rnti;
+  pdu->crc_indication_rel8.tl.tag = NFAPI_CRC_INDICATION_REL8_TAG;
+  pdu->crc_indication_rel8.crc_flag = crc_flag;
 
   UL_INFO->crc_ind.crc_indication_body.number_of_crcs++;
 
-  LOG_D(PHY, "%s() rnti:%04x pdus:%d\n", __FUNCTION__, pdu->rx_ue_information.rnti, UL_INFO->crc_ind.crc_indication_body.number_of_crcs);
+  LOG_D(PHY,
+        "%s() rnti:%04x pdus:%d\n",
+        __FUNCTION__,
+        pdu->rx_ue_information.rnti,
+        UL_INFO->crc_ind.crc_indication_body.number_of_crcs);
 
-  // change for mutiple UE's simulation.
-  // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
   pthread_mutex_unlock(&fill_ul_mutex.crc_mutex);
 }
 
-void fill_rach_indication_UE_MAC(int Mod_id,int frame,int subframe, UL_IND_t *UL_INFO, uint8_t ra_PreambleIndex, uint16_t ra_RNTI) {
+void fill_rach_indication_UE_MAC(int Mod_id,
+                                 int frame,
+                                 int subframe,
+                                 UL_IND_t *UL_INFO,
+                                 uint8_t ra_PreambleIndex,
+                                 uint16_t ra_RNTI) {
+  LOG_D(MAC, "fill_rach_indication_UE_MAC 1 \n");
 
-	LOG_D(MAC, "fill_rach_indication_UE_MAC 1 \n");
+  pthread_mutex_lock(&fill_ul_mutex.rach_mutex);
 
-	// change for mutiple UE's simulation.
-	// pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-	pthread_mutex_lock(&fill_ul_mutex.rach_mutex);
+  UL_INFO->rach_ind.rach_indication_body.number_of_preambles = 1;
 
-	// memory allocation and free memory of UL_INFO are done in UE_phy_stub_single_thread_rxn_txnp4.
-	// UL_INFO = (UL_IND_t*)malloc(sizeof(UL_IND_t));
+  UL_INFO->rach_ind.header.message_id = NFAPI_RACH_INDICATION;
+  UL_INFO->rach_ind.sfn_sf = frame << 4 | subframe;
+  UL_INFO->rach_ind.vendor_extension = NULL;
 
-	    UL_INFO->rach_ind.rach_indication_body.number_of_preambles                 = 1;
+  UL_INFO->rach_ind.rach_indication_body.tl.tag = NFAPI_RACH_INDICATION_BODY_TAG;
 
-	    //eNB->UL_INFO.rach_ind.preamble_list                       = &eNB->preamble_list[0];
-	    UL_INFO->rach_ind.header.message_id                         = NFAPI_RACH_INDICATION;
-	    UL_INFO->rach_ind.sfn_sf                                    = frame<<4 | subframe;
-	    UL_INFO->rach_ind.vendor_extension							= NULL;
+  const int np = UL_INFO->rach_ind.rach_indication_body.number_of_preambles;
+  UL_INFO->rach_ind.rach_indication_body.preamble_list =
+      calloc(np, sizeof(nfapi_preamble_pdu_t));
+  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.tl.tag =
+      NFAPI_PREAMBLE_REL8_TAG;
+  UL_INFO->rach_ind.rach_indication_body.preamble_list[0]
+      .preamble_rel8.timing_advance = 0; // Not sure about that
 
-	    UL_INFO->rach_ind.rach_indication_body.tl.tag                              = NFAPI_RACH_INDICATION_BODY_TAG;
+  // The two following should get extracted from the call to
+  // get_prach_resources().
+  UL_INFO->rach_ind.rach_indication_body.preamble_list[0]
+      .preamble_rel8.preamble = ra_PreambleIndex;
+  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.rnti =
+      ra_RNTI;
+  // UL_INFO->rach_ind.rach_indication_body.number_of_preambles++;
 
+  UL_INFO->rach_ind.rach_indication_body.preamble_list[0]
+      .preamble_rel13.rach_resource_type = 0;
+  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].instance_length = 0;
 
-	    UL_INFO->rach_ind.rach_indication_body.preamble_list = (nfapi_preamble_pdu_t*)malloc(UL_INFO->rach_ind.rach_indication_body.number_of_preambles*sizeof(nfapi_preamble_pdu_t));
-	    UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.tl.tag   		= NFAPI_PREAMBLE_REL8_TAG;
-	    UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.timing_advance = 0; // Not sure about that
+  LOG_I(PHY,
+        "UE Filling NFAPI indication for RACH : TA %d, Preamble %d, rnti %x, "
+        "rach_resource_type %d\n",
+        UL_INFO->rach_ind.rach_indication_body.preamble_list[0]
+            .preamble_rel8.timing_advance,
+        UL_INFO->rach_ind.rach_indication_body.preamble_list[0]
+            .preamble_rel8.preamble,
+        UL_INFO->rach_ind.rach_indication_body.preamble_list[0]
+            .preamble_rel8.rnti,
+        UL_INFO->rach_ind.rach_indication_body.preamble_list[0]
+            .preamble_rel13.rach_resource_type);
 
-	    //The two following should get extracted from the call to get_prach_resources().
-	    UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.preamble = ra_PreambleIndex;
-	    UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.rnti 	  = ra_RNTI;
-	    //UL_INFO->rach_ind.rach_indication_body.number_of_preambles++;
-
-
-	    UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel13.rach_resource_type = 0;
-	    UL_INFO->rach_ind.rach_indication_body.preamble_list[0].instance_length					 = 0;
-
-
-	          //LOG_E(PHY,"\n\n\n\nDJP - this needs to be sent to VNF **********************************************\n\n\n\n");
-	          LOG_I(PHY,"UE Filling NFAPI indication for RACH : TA %d, Preamble %d, rnti %x, rach_resource_type %d\n",
-	        	  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.timing_advance,
-	        	  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.preamble,
-	        	  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel8.rnti,
-	        	  UL_INFO->rach_ind.rach_indication_body.preamble_list[0].preamble_rel13.rach_resource_type);
-
-	          // This function is currently defined only in the nfapi-RU-RAU-split so we should call it when we merge
-	          // with that branch.
-	          oai_nfapi_rach_ind(&UL_INFO->rach_ind);
-	          free(UL_INFO->rach_ind.rach_indication_body.preamble_list);
-
-	         // memory allocation and free memory of UL_INFO are done in UE_phy_stub_single_thread_rxn_txnp4.
-	          //free(UL_INFO);
-
-	        //}
-	      // change for mutiple UE's simulation.
-	      // pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-	      pthread_mutex_unlock(&fill_ul_mutex.rach_mutex);
+  // This function is currently defined only in the nfapi-RU-RAU-split so we
+  // should call it when we merge with that branch.
+  oai_nfapi_rach_ind(&UL_INFO->rach_ind);
+  free(UL_INFO->rach_ind.rach_indication_body.preamble_list);
 
+  pthread_mutex_unlock(&fill_ul_mutex.rach_mutex);
 }
 
-void fill_ulsch_cqi_indication_UE_MAC(int Mod_id, uint16_t frame,uint8_t subframe, UL_IND_t *UL_INFO, uint16_t rnti) {
+void fill_ulsch_cqi_indication_UE_MAC(int Mod_id,
+                                      uint16_t frame,
+                                      uint8_t subframe,
+                                      UL_IND_t *UL_INFO,
+                                      uint16_t rnti) {
+  pthread_mutex_lock(&fill_ul_mutex.cqi_mutex);
+  nfapi_cqi_indication_pdu_t *pdu =
+      &UL_INFO->cqi_ind.cqi_indication_body
+           .cqi_pdu_list[UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis];
+  nfapi_cqi_indication_raw_pdu_t *raw_pdu =
+      &UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list
+           [UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis];
 
-	// change for mutiple UE's simulation.
-	//pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-	pthread_mutex_lock(&fill_ul_mutex.cqi_mutex);
-	nfapi_cqi_indication_pdu_t *pdu         = &UL_INFO->cqi_ind.cqi_indication_body.cqi_pdu_list[UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis];
-	nfapi_cqi_indication_raw_pdu_t *raw_pdu = &UL_INFO->cqi_ind.cqi_indication_body.cqi_raw_pdu_list[UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis];
+  UL_INFO->cqi_ind.sfn_sf = frame << 4 | subframe;
+  // because of nfapi_vnf.c:733, set message id to 0, not
+  // NFAPI_RX_CQI_INDICATION;
+  UL_INFO->cqi_ind.header.message_id = 0;
+  UL_INFO->cqi_ind.cqi_indication_body.tl.tag = NFAPI_CQI_INDICATION_BODY_TAG;
 
-	UL_INFO->cqi_ind.sfn_sf = frame << 4 | subframe;
-        // because of nfapi_vnf.c:733, set message id to 0, not NFAPI_RX_CQI_INDICATION;
-	UL_INFO->cqi_ind.header.message_id = 0;
-	UL_INFO->cqi_ind.cqi_indication_body.tl.tag = NFAPI_CQI_INDICATION_BODY_TAG;
+  pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG;
+  pdu->rx_ue_information.rnti = rnti;
+  // Since we assume that CRC flag is always 0 (ACK) I guess that data_offset
+  // should always be 0.
+  pdu->cqi_indication_rel8.data_offset = 0;
 
-	pdu->rx_ue_information.tl.tag          = NFAPI_RX_UE_INFORMATION_TAG;
-	pdu->rx_ue_information.rnti = rnti;
-	// Since we assume that CRC flag is always 0 (ACK) I guess that data_offset should always be 0.
-	pdu->cqi_indication_rel8.data_offset = 0;
-
-	// by default set O to rank 1 value
-	//pdu->cqi_indication_rel8.length = (ulsch_harq->Or1>>3) + ((ulsch_harq->Or1&7) > 0 ? 1 : 0);
-	//  Not useful field for our case
-	pdu->cqi_indication_rel8.tl.tag = NFAPI_CQI_INDICATION_REL8_TAG;
-	pdu->cqi_indication_rel8.length = 1;
-	pdu->cqi_indication_rel8.ri  = 0;
-
-
-	pdu->cqi_indication_rel8.timing_advance = 0;
-	//pdu->cqi_indication_rel8.number_of_cc_reported = 1;
-	pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
-	pdu->ul_cqi_information.channel = 1; // PUSCH
-
-	// eNB_scheduler_primitives.c:4839: the upper four bits seem to be the CQI
-	const int cqi = 15;
-	raw_pdu->pdu[0] = cqi << 4;
+  pdu->cqi_indication_rel8.tl.tag = NFAPI_CQI_INDICATION_REL8_TAG;
+  pdu->cqi_indication_rel8.length = 1;
+  pdu->cqi_indication_rel8.ri = 0;
 
+  pdu->cqi_indication_rel8.timing_advance = 0;
+  // pdu->cqi_indication_rel8.number_of_cc_reported = 1;
+  pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
+  pdu->ul_cqi_information.channel = 1; // PUSCH
 
+  // eNB_scheduler_primitives.c:4839: the upper four bits seem to be the CQI
+  const int cqi = 15;
+  raw_pdu->pdu[0] = cqi << 4;
 
   UL_INFO->cqi_ind.cqi_indication_body.number_of_cqis++;
-  // change for mutiple UE's simulation.
-  //pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
   pthread_mutex_unlock(&fill_ul_mutex.cqi_mutex);
 }
 
-void fill_ulsch_harq_indication_UE_MAC(int Mod_id, int frame,int subframe, UL_IND_t *UL_INFO, nfapi_ul_config_ulsch_harq_information *harq_information, uint16_t rnti)
-{
-
-  // change for mutiple UE's simulation.
-  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+void fill_ulsch_harq_indication_UE_MAC(
+    int Mod_id,
+    int frame,
+    int subframe,
+    UL_IND_t *UL_INFO,
+    nfapi_ul_config_ulsch_harq_information *harq_information,
+    uint16_t rnti) {
   pthread_mutex_lock(&fill_ul_mutex.harq_mutex);
 
-  nfapi_harq_indication_pdu_t *pdu =   &UL_INFO->harq_ind.harq_indication_body.harq_pdu_list[UL_INFO->harq_ind.harq_indication_body.number_of_harqs];
-  int i;
+  nfapi_harq_indication_pdu_t *pdu =
+      &UL_INFO->harq_ind.harq_indication_body.harq_pdu_list
+           [UL_INFO->harq_ind.harq_indication_body.number_of_harqs];
 
   UL_INFO->harq_ind.header.message_id = NFAPI_HARQ_INDICATION;
-  UL_INFO->harq_ind.sfn_sf = frame<<4|subframe;
-  UL_INFO->harq_ind.vendor_extension		     = ul_config_req->vendor_extension;
+  UL_INFO->harq_ind.sfn_sf = frame << 4 | subframe;
+  UL_INFO->harq_ind.vendor_extension = ul_config_req->vendor_extension;
 
-  UL_INFO->harq_ind.harq_indication_body.tl.tag = NFAPI_HARQ_INDICATION_BODY_TAG;
+  UL_INFO->harq_ind.harq_indication_body.tl.tag =
+      NFAPI_HARQ_INDICATION_BODY_TAG;
 
-  pdu->instance_length                                = 0; // don't know what to do with this
+  pdu->instance_length = 0; // don't know what to do with this
   //  pdu->rx_ue_information.handle                       = handle;
-  pdu->rx_ue_information.tl.tag                       = NFAPI_RX_UE_INFORMATION_TAG;
-  pdu->rx_ue_information.rnti                         = rnti;
+  pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG;
+  pdu->rx_ue_information.rnti = rnti;
 
   // For now we consider only FDD
-  //if (eNB->frame_parms.frame_type == FDD) {
-    pdu->harq_indication_fdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_FDD_REL13_TAG;
-    pdu->harq_indication_fdd_rel13.mode = 0;
-    pdu->harq_indication_fdd_rel13.number_of_ack_nack = harq_information->harq_information_rel10.harq_size;
+  // if (eNB->frame_parms.frame_type == FDD) {
+  pdu->harq_indication_fdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_FDD_REL13_TAG;
+  pdu->harq_indication_fdd_rel13.mode = 0;
+  pdu->harq_indication_fdd_rel13.number_of_ack_nack =
+      harq_information->harq_information_rel10.harq_size;
 
-    // Could this be wrong? Is the number_of_ack_nack field equivalent to O_ACK?
-    //pdu->harq_indication_fdd_rel13.number_of_ack_nack = ulsch_harq->O_ACK;
+  // Could this be wrong? Is the number_of_ack_nack field equivalent to O_ACK?
+  // pdu->harq_indication_fdd_rel13.number_of_ack_nack = ulsch_harq->O_ACK;
 
-    for (i=0;iharq_information_rel10.harq_size;i++) {
-
-      pdu->harq_indication_fdd_rel13.harq_tb_n[i] = 1; // Assuming always an ACK (No NACK or DTX)
-
-    }
+  for (int i = 0; i < harq_information->harq_information_rel10.harq_size; i++) {
+    pdu->harq_indication_fdd_rel13.harq_tb_n[i] = 1; // Assume always ACK (No NACK or DTX)
+  }
 
   UL_INFO->harq_ind.harq_indication_body.number_of_harqs++;
-  // change for mutiple UE's simulation.
-  //pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
-  pthread_mutex_unlock(&fill_ul_mutex.harq_mutex);}
-
+  pthread_mutex_unlock(&fill_ul_mutex.harq_mutex);
+}
 
 void fill_uci_harq_indication_UE_MAC(int Mod_id,
 			      int frame,
 			      int subframe,
 			      UL_IND_t *UL_INFO,
 			      nfapi_ul_config_harq_information *harq_information,
-			      uint16_t rnti
-			      /*uint8_t tdd_mapping_mode,
-			      uint16_t tdd_multiplexing_mask*/) {
-
-
-  // change for mutiple UE's simulation.
-  //pthread_mutex_lock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+			      uint16_t rnti) {
   pthread_mutex_lock(&fill_ul_mutex.harq_mutex);
 
-  nfapi_harq_indication_t *ind       = &UL_INFO->harq_ind;
+  nfapi_harq_indication_t *ind = &UL_INFO->harq_ind;
   nfapi_harq_indication_body_t *body = &ind->harq_indication_body;
-  nfapi_harq_indication_pdu_t *pdu =   &body->harq_pdu_list[UL_INFO->harq_ind.harq_indication_body.number_of_harqs];
+  nfapi_harq_indication_pdu_t *pdu =
+      &body->harq_pdu_list[UL_INFO->harq_ind.harq_indication_body
+                               .number_of_harqs];
 
-  UL_INFO->harq_ind.vendor_extension		     = ul_config_req->vendor_extension;
+  UL_INFO->harq_ind.vendor_extension = ul_config_req->vendor_extension;
 
-  ind->sfn_sf = frame<<4|subframe;
+  ind->sfn_sf = frame << 4 | subframe;
   ind->header.message_id = NFAPI_HARQ_INDICATION;
 
   body->tl.tag = NFAPI_HARQ_INDICATION_BODY_TAG;
-  pdu->rx_ue_information.tl.tag                       = NFAPI_RX_UE_INFORMATION_TAG;
+  pdu->rx_ue_information.tl.tag = NFAPI_RX_UE_INFORMATION_TAG;
 
-  pdu->instance_length                                = 0; // don't know what to do with this
-  //  pdu->rx_ue_information.handle                       = handle;
-  pdu->rx_ue_information.rnti                         = rnti;
+  pdu->instance_length = 0; // don't know what to do with this
+  pdu->rx_ue_information.rnti = rnti;
 
   pdu->ul_cqi_information.tl.tag = NFAPI_UL_CQI_INFORMATION_TAG;
 
   int SNRtimes10 = 640;
 
-
-  if      (SNRtimes10 < -640) pdu->ul_cqi_information.ul_cqi=0;
-  else if (SNRtimes10 >  635) pdu->ul_cqi_information.ul_cqi=255;
-  else                        pdu->ul_cqi_information.ul_cqi=(640+SNRtimes10)/5;
+  if (SNRtimes10 < -640)
+    pdu->ul_cqi_information.ul_cqi = 0;
+  else if (SNRtimes10 > 635)
+    pdu->ul_cqi_information.ul_cqi = 255;
+  else
+    pdu->ul_cqi_information.ul_cqi = (640 + SNRtimes10) / 5;
   pdu->ul_cqi_information.channel = 0;
-  if(harq_information->harq_information_rel9_fdd.tl.tag == NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG){
-      if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0) &&
-          (harq_information->harq_information_rel9_fdd.harq_size == 1)) {
-
-      pdu->harq_indication_fdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_FDD_REL13_TAG;
+  if (harq_information->harq_information_rel9_fdd.tl.tag
+      == NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL9_FDD_TAG) {
+    if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0)
+        && (harq_information->harq_information_rel9_fdd.harq_size == 1)) {
+      pdu->harq_indication_fdd_rel13.tl.tag =
+          NFAPI_HARQ_INDICATION_FDD_REL13_TAG;
       pdu->harq_indication_fdd_rel13.mode = 0;
       pdu->harq_indication_fdd_rel13.number_of_ack_nack = 1;
 
-      //AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[0] == 4, "harq_ack[0] is %d, should be 1,2 or 4\n",harq_ack[0]);
-      pdu->harq_indication_fdd_rel13.harq_tb_n[0] = 1; // Assuming always an ACK (No NACK or DTX)
+      // AssertFatal(harq_ack[0] == 1 || harq_ack[0] == 2 || harq_ack[0] == 4,
+      // "harq_ack[0] is %d, should be 1,2 or 4\n",harq_ack[0]);
+      pdu->harq_indication_fdd_rel13.harq_tb_n[0] =
+          1; // Assuming always an ACK (No NACK or DTX)
 
-
-    }
-    else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0) &&
-                 (harq_information->harq_information_rel9_fdd.harq_size == 2)) {
-      pdu->harq_indication_fdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_FDD_REL13_TAG;
+    } else if ((harq_information->harq_information_rel9_fdd.ack_nack_mode == 0)
+               && (harq_information->harq_information_rel9_fdd.harq_size
+                   == 2)) {
+      pdu->harq_indication_fdd_rel13.tl.tag =
+          NFAPI_HARQ_INDICATION_FDD_REL13_TAG;
       pdu->harq_indication_fdd_rel13.mode = 0;
       pdu->harq_indication_fdd_rel13.number_of_ack_nack = 2;
-      pdu->harq_indication_fdd_rel13.harq_tb_n[0] = 1; // Assuming always an ACK (No NACK or DTX)
-      pdu->harq_indication_fdd_rel13.harq_tb_n[1] = 1; // Assuming always an ACK (No NACK or DTX)
-
+      pdu->harq_indication_fdd_rel13.harq_tb_n[0] =
+          1; // Assuming always an ACK (No NACK or DTX)
+      pdu->harq_indication_fdd_rel13.harq_tb_n[1] =
+          1; // Assuming always an ACK (No NACK or DTX)
     }
-  }else if(harq_information->harq_information_rel10_tdd.tl.tag == NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG ){
-      if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 0) &&
-          (harq_information->harq_information_rel10_tdd.harq_size == 1)) {
-        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
-        pdu->harq_indication_tdd_rel13.mode = 0;
-        pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;
-        pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
-
-      }  else if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 1) &&
-                  (harq_information->harq_information_rel10_tdd.harq_size == 2)) {
-        pdu->harq_indication_tdd_rel13.tl.tag = NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
-        pdu->harq_indication_tdd_rel13.mode = 0;
-        pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;
-        pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
-        pdu->harq_indication_tdd_rel13.harq_data[1].bundling.value_0 = 1;
-
-      }
-  } else AssertFatal(1==0,"only format 1a/b for now, received \n");
+  } else if (harq_information->harq_information_rel10_tdd.tl.tag
+             == NFAPI_UL_CONFIG_REQUEST_HARQ_INFORMATION_REL10_TDD_TAG) {
+    if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 0)
+        && (harq_information->harq_information_rel10_tdd.harq_size == 1)) {
+      pdu->harq_indication_tdd_rel13.tl.tag =
+          NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+      pdu->harq_indication_tdd_rel13.mode = 0;
+      pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;
+      pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
 
+    } else if ((harq_information->harq_information_rel10_tdd.ack_nack_mode == 1)
+               && (harq_information->harq_information_rel10_tdd.harq_size
+                   == 2)) {
+      pdu->harq_indication_tdd_rel13.tl.tag =
+          NFAPI_HARQ_INDICATION_TDD_REL13_TAG;
+      pdu->harq_indication_tdd_rel13.mode = 0;
+      pdu->harq_indication_tdd_rel13.number_of_ack_nack = 1;
+      pdu->harq_indication_tdd_rel13.harq_data[0].bundling.value_0 = 1;
+      pdu->harq_indication_tdd_rel13.harq_data[1].bundling.value_0 = 1;
+    }
+  } else
+    AssertFatal(1 == 0, "only format 1a/b for now, received \n");
 
   UL_INFO->harq_ind.harq_indication_body.number_of_harqs++;
-  LOG_D(PHY,"Incremented eNB->UL_INFO.harq_ind.number_of_harqs:%d\n", UL_INFO->harq_ind.harq_indication_body.number_of_harqs);
-  // change for mutiple UE's simulation.
-  //pthread_mutex_unlock(&UE_mac_inst[Mod_id].UL_INFO_mutex);
+  LOG_D(PHY,
+        "Incremented eNB->UL_INFO.harq_ind.number_of_harqs:%d\n",
+        UL_INFO->harq_ind.harq_indication_body.number_of_harqs);
   pthread_mutex_unlock(&fill_ul_mutex.harq_mutex);
-
 }
 
-
 void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
-                         nfapi_ul_config_request_pdu_t *ul_config_pdu,
-                         uint16_t frame,uint8_t subframe,uint8_t srs_present, int index)
-{
-
+                                nfapi_ul_config_request_pdu_t *ul_config_pdu,
+                                uint16_t frame,
+                                uint8_t subframe,
+                                uint8_t srs_present,
+                                int index) {
   if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE) {
-    LOG_D(PHY,"Applying UL config for UE, rnti %x for frame %d, subframe %d\n",
-         (ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8).rnti,frame,subframe);
-    uint8_t ulsch_buffer[5477] __attribute__ ((aligned(32)));
+    LOG_D(PHY,
+          "Applying UL config for UE, rnti %x for frame %d, subframe %d\n",
+          (ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8).rnti,
+          frame,
+          subframe);
+    uint8_t ulsch_buffer[5477] __attribute__((aligned(32)));
     uint16_t buflen = ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.size;
 
     uint16_t rnti = ul_config_pdu->ulsch_pdu.ulsch_pdu_rel8.rnti;
-    uint8_t access_mode=SCHEDULED_ACCESS;
-    if(buflen>0){
-    	if(UE_mac_inst[Mod_id].first_ULSCH_Tx == 1){ // Msg3 case
-    		LOG_D(MAC, "handle_nfapi_ul_pdu_UE_MAC 2.2, Mod_id:%d, SFN/SF: %d/%d \n", Mod_id, frame, subframe);
-    		fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-    		fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, UE_mac_inst[Mod_id].RA_prach_resources.Msg3,buflen, rnti, index);
-    		Msg3_transmitted(Mod_id, 0, frame, 0);
-    		//  Modification
-    		UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
-    		UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+    uint8_t access_mode = SCHEDULED_ACCESS;
+    if (buflen > 0) {
+      if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) { // Msg3 case
+        LOG_D(MAC,
+              "handle_nfapi_ul_pdu_UE_MAC 2.2, Mod_id:%d, SFN/SF: %d/%d \n",
+              Mod_id,
+              frame,
+              subframe);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
+                                  buflen,
+                                  rnti,
+                                  index);
+        Msg3_transmitted(Mod_id, 0, frame, 0);
+        //  Modification
+        UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
+        UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
 
-    		// This should be done after the reception of the respective hi_dci0
-    		//UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
-    	}
-    	else {
-    		ue_get_sdu( Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-    		fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-    		fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_buffer,buflen, rnti, index);
-    	}
+        // This should be done after the reception of the respective hi_dci0
+        // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+      } else {
+        ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  ulsch_buffer,
+                                  buflen,
+                                  rnti,
+                                  index);
+      }
     }
   }
 
   else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE) {
+    // AssertFatal((UE_id =
+    // find_ulsch(ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE))>=0,
+    //            "No available UE ULSCH for rnti
+    //            %x\n",ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti);
+    uint8_t ulsch_buffer[5477] __attribute__((aligned(32)));
+    uint16_t buflen =
+        ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.size;
+    nfapi_ul_config_ulsch_harq_information *ulsch_harq_information =
+        &ul_config_pdu->ulsch_harq_pdu.harq_information;
+    uint16_t rnti = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
+    uint8_t access_mode = SCHEDULED_ACCESS;
+    if (buflen > 0) {
+      if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) { // Msg3 case
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
+                                  buflen,
+                                  rnti,
+                                  index);
+        Msg3_transmitted(Mod_id, 0, frame, 0);
+        // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+        // Modification
+        UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
+        UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+      } else {
+        ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  ulsch_buffer,
+                                  buflen,
+                                  rnti,
+                                  index);
+      }
+    }
+    if (ulsch_harq_information != NULL)
+      fill_ulsch_harq_indication_UE_MAC(
+          Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
 
-	  //AssertFatal((UE_id = find_ulsch(ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti,eNB,SEARCH_EXIST_OR_FREE))>=0,
-    //            "No available UE ULSCH for rnti %x\n",ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti);
-	  uint8_t ulsch_buffer[5477] __attribute__ ((aligned(32)));
-	  uint16_t buflen = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.size;
-	  nfapi_ul_config_ulsch_harq_information *ulsch_harq_information = &ul_config_pdu->ulsch_harq_pdu.harq_information;
-	  uint16_t rnti = ul_config_pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
-	  uint8_t access_mode=SCHEDULED_ACCESS;
-	  if(buflen>0){
-		  if(UE_mac_inst[Mod_id].first_ULSCH_Tx == 1){ // Msg3 case
-			  fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, UE_mac_inst[Mod_id].RA_prach_resources.Msg3,buflen, rnti, index);
-			  Msg3_transmitted(Mod_id, 0, frame, 0);
-			  //UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
-			  // Modification
-			  UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
-			  UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
-		  }
-		  else {
-			  ue_get_sdu( Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-			  fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_buffer,buflen, rnti, index);
-		  }
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE) {
+    uint8_t ulsch_buffer[5477] __attribute__((aligned(32)));
+    uint16_t buflen = ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.size;
 
-	  }
-	  if(ulsch_harq_information!=NULL)
-		  fill_ulsch_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
+    uint16_t rnti = ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
+    uint8_t access_mode = SCHEDULED_ACCESS;
+    if (buflen > 0) {
+      if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) { // Msg3 case
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
+                                  buflen,
+                                  rnti,
+                                  index);
+        Msg3_transmitted(Mod_id, 0, frame, 0);
+        // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+        // Modification
+        UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
+        UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+      } else {
+        ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  ulsch_buffer,
+                                  buflen,
+                                  rnti,
+                                  index);
+      }
+    }
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) {
+    uint8_t ulsch_buffer[5477] __attribute__((aligned(32)));
+    uint16_t buflen = ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.size;
+    nfapi_ul_config_ulsch_harq_information *ulsch_harq_information =
+        &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information;
 
+    uint16_t rnti = ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
+    uint8_t access_mode = SCHEDULED_ACCESS;
+    if (buflen > 0) {
+      if (UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) { // Msg3 case
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  UE_mac_inst[Mod_id].RA_prach_resources.Msg3,
+                                  buflen,
+                                  rnti,
+                                  index);
+        Msg3_transmitted(Mod_id, 0, frame, 0);
+        // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+        // Modification
+        UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
+        UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+      } else {
+        ue_get_sdu(Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
+        fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
+        fill_rx_indication_UE_MAC(Mod_id,
+                                  frame,
+                                  subframe,
+                                  UL_INFO,
+                                  ulsch_buffer,
+                                  buflen,
+                                  rnti,
+                                  index);
+      }
+    }
+
+    if (ulsch_harq_information != NULL)
+      fill_ulsch_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) {
+    uint16_t rnti = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti;
+
+    nfapi_ul_config_harq_information *ulsch_harq_information = &ul_config_pdu->uci_harq_pdu.harq_information;
+    if (ulsch_harq_information != NULL)
+      fill_uci_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) {
+    AssertFatal(1 == 0, "NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE not handled yet\n");
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE) {
+    AssertFatal(1 == 0,
+                "NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE not handled yet\n");
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE) {
+    AssertFatal(1 == 0,
+                "NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE not handled yet\n");
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE) {
+    uint16_t rnti =
+        ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti;
+
+    if (ue_get_SR(Mod_id, 0, frame, 0, rnti, subframe))
+      fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
+
+  } else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE) {
+    // AssertFatal((UE_id =
+    // find_uci(rel8->rnti,proc->frame_tx,proc->subframe_tx,eNB,SEARCH_EXIST_OR_FREE))>=0,
+    //            "No available UE UCI for rnti
+    //            %x\n",ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti);
+
+    uint16_t rnti =
+        ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti;
+
+    // We fill the sr_indication only if ue_get_sr() would normally instruct PHY
+    // to send a SR.
+    if (ue_get_SR(Mod_id, 0, frame, 0, rnti, subframe))
+      fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
+
+    nfapi_ul_config_harq_information *ulsch_harq_information =
+        &ul_config_pdu->uci_sr_harq_pdu.harq_information;
+    if (ulsch_harq_information != NULL)
+      fill_uci_harq_indication_UE_MAC(
+          Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
   }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE) {
-	 uint8_t ulsch_buffer[5477] __attribute__ ((aligned(32)));
-	  uint16_t buflen = ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.size;
-
-	  uint16_t rnti = ul_config_pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
-	  uint8_t access_mode=SCHEDULED_ACCESS;
-	  if(buflen>0){
-		  if(UE_mac_inst[Mod_id].first_ULSCH_Tx == 1){ // Msg3 case
-			  fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, UE_mac_inst[Mod_id].RA_prach_resources.Msg3,buflen, rnti, index);
-			  Msg3_transmitted(Mod_id, 0, frame, 0);
-			  //UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
-			  // Modification
-			  UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
-			  UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
-		  }
-		  else {
-			  ue_get_sdu( Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-			  fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_buffer,buflen, rnti, index);
-		  }
-	  }
-  }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE) {
-
-	  uint8_t ulsch_buffer[5477] __attribute__ ((aligned(32)));
-	  uint16_t buflen = ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.size;
-	  nfapi_ul_config_ulsch_harq_information *ulsch_harq_information = &ul_config_pdu->ulsch_cqi_harq_ri_pdu.harq_information;
-
-	  uint16_t rnti = ul_config_pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti;
-	  uint8_t access_mode=SCHEDULED_ACCESS;
-	  if(buflen>0){
-		  if(UE_mac_inst[Mod_id].first_ULSCH_Tx == 1){ // Msg3 case
-			  fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, UE_mac_inst[Mod_id].RA_prach_resources.Msg3,buflen, rnti, index);
-			  Msg3_transmitted(Mod_id, 0, frame, 0);
-			  //UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
-			  // Modification
-			  UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
-			  UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
-		  }
-		  else {
-			  ue_get_sdu( Mod_id, 0, frame, subframe, 0, ulsch_buffer, buflen, &access_mode);
-			  fill_crc_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, 0, index, rnti);
-			  fill_rx_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_buffer,buflen, rnti, index);
-		  }
-	  }
-
-	  if(ulsch_harq_information!=NULL)
-		  fill_ulsch_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, ulsch_harq_information, rnti);
-  }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE) {
-
-	  uint16_t rnti = ul_config_pdu->uci_harq_pdu.ue_information.ue_information_rel8.rnti;
-
-	  nfapi_ul_config_harq_information *ulsch_harq_information = &ul_config_pdu->uci_harq_pdu.harq_information;
-	  if(ulsch_harq_information != NULL)
-		  fill_uci_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO,ulsch_harq_information, rnti);
-  }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE) {
-    AssertFatal(1==0,"NFAPI_UL_CONFIG_UCI_CQI_PDU_TYPE not handled yet\n");
-  }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE) {
-    AssertFatal(1==0,"NFAPI_UL_CONFIG_UCI_CQI_HARQ_PDU_TYPE not handled yet\n");
-  }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE) {
-    AssertFatal(1==0,"NFAPI_UL_CONFIG_UCI_CQI_SR_PDU_TYPE not handled yet\n");
-  }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE) {
-
-	  uint16_t rnti = ul_config_pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti;
-
-	  if (ue_get_SR(Mod_id ,0,frame, 0, rnti, subframe))
-		  fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO, rnti);
-
-  }
-  else if (ul_config_pdu->pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE) {
-    //AssertFatal((UE_id = find_uci(rel8->rnti,proc->frame_tx,proc->subframe_tx,eNB,SEARCH_EXIST_OR_FREE))>=0,
-    //            "No available UE UCI for rnti %x\n",ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti);
-
-	  uint16_t rnti = ul_config_pdu->uci_sr_harq_pdu.ue_information.ue_information_rel8.rnti;
-
-	  // We fill the sr_indication only if ue_get_sr() would normally instruct PHY to send a SR.
-	  if (ue_get_SR(Mod_id ,0,frame, 0, rnti, subframe))
-		  fill_sr_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO,rnti);
-
-	  nfapi_ul_config_harq_information *ulsch_harq_information = &ul_config_pdu->uci_sr_harq_pdu.harq_information;
-	  if (ulsch_harq_information != NULL)
-		  fill_uci_harq_indication_UE_MAC(Mod_id, frame, subframe, UL_INFO,ulsch_harq_information, rnti);
-
-  }
-
 }
 
-
-
-
-
-
-int ul_config_req_UE_MAC(nfapi_ul_config_request_t* req, int timer_frame, int timer_subframe, module_id_t Mod_id)
-{
-	//if (req!=NULL){ // && req->ul_config_request_body.ul_config_pdu_list !=NULL){
-  LOG_D(PHY,"[PNF] UL_CONFIG_REQ %s() sfn_sf:%d pdu:%d rach_prach_frequency_resources:%d srs_present:%u\n",
-      __FUNCTION__,
-      NFAPI_SFNSF2DEC(req->sfn_sf),
-      req->ul_config_request_body.number_of_pdus,
-      req->ul_config_request_body.rach_prach_frequency_resources,
-      req->ul_config_request_body.srs_present
-      );
+int ul_config_req_UE_MAC(nfapi_ul_config_request_t *req,
+                         int timer_frame,
+                         int timer_subframe,
+                         module_id_t Mod_id) {
+  LOG_D(PHY,
+        "[PNF] UL_CONFIG_REQ %s() sfn_sf:%d pdu:%d "
+        "rach_prach_frequency_resources:%d srs_present:%u\n",
+        __FUNCTION__,
+        NFAPI_SFNSF2DEC(req->sfn_sf),
+        req->ul_config_request_body.number_of_pdus,
+        req->ul_config_request_body.rach_prach_frequency_resources,
+        req->ul_config_request_body.srs_present);
 
   int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
   int sf = NFAPI_SFNSF2SF(req->sfn_sf);
 
+  LOG_D(MAC,
+        "ul_config_req_UE_MAC() TOTAL NUMBER OF UL_CONFIG PDUs: %d, SFN/SF: "
+        "%d/%d \n",
+        req->ul_config_request_body.number_of_pdus,
+        timer_frame,
+        timer_subframe);
 
-  LOG_D(MAC, "ul_config_req_UE_MAC() TOTAL NUMBER OF UL_CONFIG PDUs: %d, SFN/SF: %d/%d \n", req->ul_config_request_body.number_of_pdus, timer_frame, timer_subframe);
-
-
-
-  for (int i=0;iul_config_request_body.number_of_pdus;i++)
-  {
-
-    if (
-    		(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE && req->ul_config_request_body.ul_config_pdu_list[i].ulsch_pdu.ulsch_pdu_rel8.rnti == UE_mac_inst[Mod_id].crnti) ||
-    		(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE && req->ul_config_request_body.ul_config_pdu_list[i].ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == UE_mac_inst[Mod_id].crnti) ||
-    		(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE && req->ul_config_request_body.ul_config_pdu_list[i].ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == UE_mac_inst[Mod_id].crnti) ||
-    		(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE && req->ul_config_request_body.ul_config_pdu_list[i].ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == UE_mac_inst[Mod_id].crnti) ||
-    		(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE && req->ul_config_request_body.ul_config_pdu_list[i].uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == UE_mac_inst[Mod_id].crnti) ||
-    		(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE && req->ul_config_request_body.ul_config_pdu_list[i].uci_sr_pdu.ue_information.ue_information_rel8.rnti == UE_mac_inst[Mod_id].crnti) ||
-    		(req->ul_config_request_body.ul_config_pdu_list[i].pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE && req->ul_config_request_body.ul_config_pdu_list[i].uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == UE_mac_inst[Mod_id].crnti)
-       )
-    {
-
-      handle_nfapi_ul_pdu_UE_MAC(Mod_id,&req->ul_config_request_body.ul_config_pdu_list[i],sfn,sf,req->ul_config_request_body.srs_present, i);
-
-    }
-    else
-    {
-      //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() PDU:%i UNKNOWN type :%d\n", __FUNCTION__, i, ul_config_pdu_list[i].pdu_type);
+  const rnti_t rnti = UE_mac_inst[Mod_id].crnti;
+  for (int i = 0; i < req->ul_config_request_body.number_of_pdus; i++) {
+    nfapi_ul_config_request_pdu_t* pdu = &req->ul_config_request_body.ul_config_pdu_list[i];
+    const int pdu_type = pdu->pdu_type;
+    if (   (pdu_type == NFAPI_UL_CONFIG_ULSCH_PDU_TYPE
+            && pdu->ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)
+        || (pdu_type == NFAPI_UL_CONFIG_ULSCH_HARQ_PDU_TYPE
+            && pdu->ulsch_harq_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)
+        || (pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_RI_PDU_TYPE
+            && pdu->ulsch_cqi_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)
+        || (pdu_type == NFAPI_UL_CONFIG_ULSCH_CQI_HARQ_RI_PDU_TYPE
+            && pdu->ulsch_cqi_harq_ri_pdu.ulsch_pdu.ulsch_pdu_rel8.rnti == rnti)
+        || (pdu_type == NFAPI_UL_CONFIG_UCI_HARQ_PDU_TYPE
+            && pdu->uci_cqi_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)
+        || (pdu_type == NFAPI_UL_CONFIG_UCI_SR_PDU_TYPE
+            && pdu->uci_sr_pdu.ue_information.ue_information_rel8.rnti == rnti)
+        || (pdu_type == NFAPI_UL_CONFIG_UCI_SR_HARQ_PDU_TYPE
+            && pdu->uci_cqi_sr_harq_pdu.ue_information.ue_information_rel8.rnti == rnti)) {
+      handle_nfapi_ul_pdu_UE_MAC(
+          Mod_id, pdu, sfn, sf, req->ul_config_request_body.srs_present, i);
+    } else {
+      // NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() PDU:%i UNKNOWN type :%d\n",
+      // __FUNCTION__, i, ul_config_pdu_list[i].pdu_type);
     }
   }
 
-//	}
-
   return 0;
 }
 
+int tx_req_UE_MAC(nfapi_tx_request_t *req) {
+  LOG_D(PHY,
+        "%s() SFN/SF:%d/%d PDUs:%d\n",
+        __FUNCTION__,
+        NFAPI_SFNSF2SFN(req->sfn_sf),
+        NFAPI_SFNSF2SF(req->sfn_sf),
+        req->tx_request_body.number_of_pdus);
 
-
-int tx_req_UE_MAC(nfapi_tx_request_t* req)
-{
-
-  LOG_D(PHY,"%s() SFN/SF:%d/%d PDUs:%d\n", __FUNCTION__, NFAPI_SFNSF2SFN(req->sfn_sf), NFAPI_SFNSF2SF(req->sfn_sf), req->tx_request_body.number_of_pdus);
-
-
-    for (int i=0; itx_request_body.number_of_pdus; i++)
-    {
-      LOG_D(PHY,"%s() SFN/SF:%d/%d number_of_pdus:%d [PDU:%d] pdu_length:%d pdu_index:%d num_segments:%d\n",
+  for (int i = 0; i < req->tx_request_body.number_of_pdus; i++) {
+    LOG_D(PHY,
+          "%s() SFN/SF:%d/%d number_of_pdus:%d [PDU:%d] pdu_length:%d "
+          "pdu_index:%d num_segments:%d\n",
           __FUNCTION__,
-          NFAPI_SFNSF2SFN(req->sfn_sf), NFAPI_SFNSF2SF(req->sfn_sf),
+          NFAPI_SFNSF2SFN(req->sfn_sf),
+          NFAPI_SFNSF2SF(req->sfn_sf),
           req->tx_request_body.number_of_pdus,
           i,
           req->tx_request_body.tx_pdu_list[i].pdu_length,
           req->tx_request_body.tx_pdu_list[i].pdu_index,
-          req->tx_request_body.tx_pdu_list[i].num_segments
-          );
-
-    }
+          req->tx_request_body.tx_pdu_list[i].num_segments);
+  }
 
   return 0;
 }
 
-
 int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) {
   int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
   int sf = NFAPI_SFNSF2SF(req->sfn_sf);
@@ -774,271 +838,272 @@ int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req, module_id_t Mod_id) {
   return 0;
 }
 
+int hi_dci0_req_UE_MAC(nfapi_hi_dci0_request_t *req, module_id_t Mod_id) {
+  if (req != NULL && req->hi_dci0_request_body.hi_dci0_pdu_list != NULL) {
+    LOG_D(PHY,
+          "[UE-PHY_STUB] hi dci0 request sfn_sf:%d number_of_dci:%d "
+          "number_of_hi:%d\n",
+          NFAPI_SFNSF2DEC(req->sfn_sf),
+          req->hi_dci0_request_body.number_of_dci,
+          req->hi_dci0_request_body.number_of_hi);
 
-int hi_dci0_req_UE_MAC(nfapi_hi_dci0_request_t* req, module_id_t Mod_id)
-{
-	if (req!=NULL && req->hi_dci0_request_body.hi_dci0_pdu_list!=NULL){
-  LOG_D(PHY,"[UE-PHY_STUB] hi dci0 request sfn_sf:%d number_of_dci:%d number_of_hi:%d\n", NFAPI_SFNSF2DEC(req->sfn_sf), req->hi_dci0_request_body.number_of_dci, req->hi_dci0_request_body.number_of_hi);
-
-
-
-  for (int i=0; ihi_dci0_request_body.number_of_dci + req->hi_dci0_request_body.number_of_hi; i++)
-  {
-    LOG_D(PHY,"[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d]\n", NFAPI_SFNSF2DEC(req->sfn_sf), i);
-
-    if (req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE)
-    {
+    for (int i = 0; i < req->hi_dci0_request_body.number_of_dci
+                            + req->hi_dci0_request_body.number_of_hi;
+         i++) {
       LOG_D(PHY,
-            "[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d] - "
-            "NFAPI_HI_DCI0_DCI_PDU_TYPE\n",
+            "[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d]\n",
             NFAPI_SFNSF2DEC(req->sfn_sf),
             i);
-      const nfapi_hi_dci0_dci_pdu_rel8_t *dci = &req->hi_dci0_request_body.hi_dci0_pdu_list[i].dci_pdu.dci_pdu_rel8;
-      if (dci->rnti != UE_mac_inst[Mod_id].crnti)
-        continue;
-      const int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
-      const int sf = NFAPI_SFNSF2SF(req->sfn_sf);
-      if (dci->cqi_csi_request)
-        fill_ulsch_cqi_indication_UE_MAC(Mod_id, sfn, sf, UL_INFO, dci->rnti);
-    }
-    else if (req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type == NFAPI_HI_DCI0_HI_PDU_TYPE)
-    {
-      //LOG_I(MAC,"[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d] - NFAPI_HI_DCI0_HI_PDU_TYPE\n", NFAPI_SFNSF2DEC(req->sfn_sf), i);
 
-      nfapi_hi_dci0_request_pdu_t *hi_dci0_req_pdu = &req->hi_dci0_request_body.hi_dci0_pdu_list[i];
+      if (req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type
+          == NFAPI_HI_DCI0_DCI_PDU_TYPE) {
+        LOG_D(PHY,
+              "[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d] - "
+              "NFAPI_HI_DCI0_DCI_PDU_TYPE\n",
+              NFAPI_SFNSF2DEC(req->sfn_sf),
+              i);
+        const nfapi_hi_dci0_dci_pdu_rel8_t *dci =
+            &req->hi_dci0_request_body.hi_dci0_pdu_list[i].dci_pdu.dci_pdu_rel8;
+        if (dci->rnti != UE_mac_inst[Mod_id].crnti)
+          continue;
+        const int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
+        const int sf = NFAPI_SFNSF2SF(req->sfn_sf);
+        if (dci->cqi_csi_request)
+          fill_ulsch_cqi_indication_UE_MAC(Mod_id, sfn, sf, UL_INFO, dci->rnti);
+      } else if (req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type
+                 == NFAPI_HI_DCI0_HI_PDU_TYPE) {
+        nfapi_hi_dci0_request_pdu_t *hi_dci0_req_pdu =
+            &req->hi_dci0_request_body.hi_dci0_pdu_list[i];
 
-      // This is meaningful only after ACKnowledging the first ULSCH Txon (i.e. Msg3)
-      if(hi_dci0_req_pdu->hi_pdu.hi_pdu_rel8.hi_value == 1 && UE_mac_inst[Mod_id].first_ULSCH_Tx == 1){
-    	  //LOG_I(MAC,"[UE-PHY_STUB] HI_DCI0_REQ 2 sfn_sf:%d PDU[%d] - NFAPI_HI_DCI0_HI_PDU_TYPE\n", NFAPI_SFNSF2DEC(req->sfn_sf), i);
-    	  //UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
-    	  //UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+        // This is meaningful only after ACKnowledging the first ULSCH Txon
+        // (i.e. Msg3)
+        if (hi_dci0_req_pdu->hi_pdu.hi_pdu_rel8.hi_value == 1
+            && UE_mac_inst[Mod_id].first_ULSCH_Tx == 1) {
+          // LOG_I(MAC,"[UE-PHY_STUB] HI_DCI0_REQ 2 sfn_sf:%d PDU[%d] -
+          // NFAPI_HI_DCI0_HI_PDU_TYPE\n", NFAPI_SFNSF2DEC(req->sfn_sf), i);
+          // UE_mac_inst[Mod_id].UE_mode[0] = PUSCH;
+          // UE_mac_inst[Mod_id].first_ULSCH_Tx = 0;
+        }
+
+      } else {
+        LOG_E(PHY,
+              "[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d] - unknown pdu "
+              "type:%d\n",
+              NFAPI_SFNSF2DEC(req->sfn_sf),
+              i,
+              req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type);
       }
-
-    }
-    else
-    {
-      LOG_E(PHY,"[UE-PHY_STUB] HI_DCI0_REQ sfn_sf:%d PDU[%d] - unknown pdu type:%d\n", NFAPI_SFNSF2DEC(req->sfn_sf), i, req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type);
     }
   }
 
-  }
-
-
   return 0;
 }
 
+// The following set of memcpy functions should be getting called as callback
+// functions from pnf_p7_subframe_ind.
+int memcpy_dl_config_req(nfapi_pnf_p7_config_t *pnf_p7,
+                         nfapi_dl_config_request_t *req) {
+  dl_config_req = (nfapi_dl_config_request_t *)malloc(sizeof(nfapi_dl_config_request_t));
 
+  // UE_mac_inst[Mod_id].dl_config_req->header = req->header;
+  dl_config_req->sfn_sf = req->sfn_sf;
 
+  dl_config_req->vendor_extension = req->vendor_extension;
 
+  dl_config_req->dl_config_request_body.number_dci = req->dl_config_request_body.number_dci;
+  dl_config_req->dl_config_request_body.number_pdcch_ofdm_symbols = req->dl_config_request_body.number_pdcch_ofdm_symbols;
+  dl_config_req->dl_config_request_body.number_pdsch_rnti = req->dl_config_request_body.number_pdsch_rnti;
+  dl_config_req->dl_config_request_body.number_pdu = req->dl_config_request_body.number_pdu;
 
-// The following set of memcpy functions should be getting called as callback functions from
-// pnf_p7_subframe_ind.
-int memcpy_dl_config_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request_t* req)
-{
+  dl_config_req->dl_config_request_body.tl.tag = req->dl_config_request_body.tl.tag;
+  dl_config_req->dl_config_request_body.tl.length = req->dl_config_request_body.tl.length;
 
-	//for (Mod_id=0; Mod_idheader = req->header;
-	dl_config_req->sfn_sf = req->sfn_sf;
-
-	dl_config_req->vendor_extension = req->vendor_extension;
-
-	dl_config_req->dl_config_request_body.number_dci = req->dl_config_request_body.number_dci;
-	dl_config_req->dl_config_request_body.number_pdcch_ofdm_symbols = req->dl_config_request_body.number_pdcch_ofdm_symbols;
-	dl_config_req->dl_config_request_body.number_pdsch_rnti = req->dl_config_request_body.number_pdsch_rnti;
-	dl_config_req->dl_config_request_body.number_pdu = req->dl_config_request_body.number_pdu;
-
-	dl_config_req->dl_config_request_body.tl.tag = req->dl_config_request_body.tl.tag;
-	dl_config_req->dl_config_request_body.tl.length = req->dl_config_request_body.tl.length;
-
-	dl_config_req->dl_config_request_body.dl_config_pdu_list = (nfapi_dl_config_request_pdu_t*) calloc(req->dl_config_request_body.number_pdu, sizeof(nfapi_dl_config_request_pdu_t));
-	for(int i=0; idl_config_request_body.number_pdu; i++) {
-		dl_config_req->dl_config_request_body.dl_config_pdu_list[i] = req->dl_config_request_body.dl_config_pdu_list[i];
-	}
-
-	//}
-
-	return 0;
+  dl_config_req->dl_config_request_body.dl_config_pdu_list =
+      calloc(req->dl_config_request_body.number_pdu,
+             sizeof(nfapi_dl_config_request_pdu_t));
+  for (int i = 0; i < dl_config_req->dl_config_request_body.number_pdu; i++) {
+    dl_config_req->dl_config_request_body.dl_config_pdu_list[i] =
+        req->dl_config_request_body.dl_config_pdu_list[i];
+  }
 
+  return 0;
 }
 
-int memcpy_ul_config_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req)
-{
+int memcpy_ul_config_req(nfapi_pnf_p7_config_t *pnf_p7,
+                         nfapi_ul_config_request_t *req) {
+  ul_config_req = malloc(sizeof(nfapi_ul_config_request_t));
 
-	//for (Mod_id=0; Mod_idsfn_sf = req->sfn_sf;
+  ul_config_req->vendor_extension = req->vendor_extension;
 
-		ul_config_req = (nfapi_ul_config_request_t*)malloc(sizeof(nfapi_ul_config_request_t));
+  ul_config_req->ul_config_request_body.number_of_pdus = req->ul_config_request_body.number_of_pdus;
+  ul_config_req->ul_config_request_body.rach_prach_frequency_resources = req->ul_config_request_body.rach_prach_frequency_resources;
+  ul_config_req->ul_config_request_body.srs_present = req->ul_config_request_body.srs_present;
 
-	ul_config_req->sfn_sf = req->sfn_sf;
-	ul_config_req->vendor_extension = req->vendor_extension;
+  ul_config_req->ul_config_request_body.tl.tag = req->ul_config_request_body.tl.tag;
+  ul_config_req->ul_config_request_body.tl.length = req->ul_config_request_body.tl.length;
 
+  ul_config_req->ul_config_request_body.ul_config_pdu_list =
+      calloc(req->ul_config_request_body.number_of_pdus,
+             sizeof(nfapi_ul_config_request_pdu_t));
+  for (int i = 0; i < ul_config_req->ul_config_request_body.number_of_pdus; i++) {
+    ul_config_req->ul_config_request_body.ul_config_pdu_list[i] =
+        req->ul_config_request_body.ul_config_pdu_list[i];
+  }
 
-	ul_config_req->ul_config_request_body.number_of_pdus = req->ul_config_request_body.number_of_pdus;
-	ul_config_req->ul_config_request_body.rach_prach_frequency_resources = req->ul_config_request_body.rach_prach_frequency_resources;
-	ul_config_req->ul_config_request_body.srs_present = req->ul_config_request_body.srs_present;
-
-	ul_config_req->ul_config_request_body.tl.tag = req->ul_config_request_body.tl.tag;
-	ul_config_req->ul_config_request_body.tl.length = req->ul_config_request_body.tl.length;
-
-	//LOG_D(MAC, "memcpy_ul_config_req 1 #ofULPDUs: %d \n", UE_mac_inst[Mod_id].ul_config_req->ul_config_request_body.number_of_pdus); //req->ul_config_request_body.number_of_pdus);
-	ul_config_req->ul_config_request_body.ul_config_pdu_list = (nfapi_ul_config_request_pdu_t*) malloc(req->ul_config_request_body.number_of_pdus*sizeof(nfapi_ul_config_request_pdu_t));
-	for(int i=0; iul_config_request_body.number_of_pdus; i++) {
-			ul_config_req->ul_config_request_body.ul_config_pdu_list[i] = req->ul_config_request_body.ul_config_pdu_list[i];
-		}
-	//}
-
-	return 0;
+  return 0;
 }
 
+int memcpy_tx_req(nfapi_pnf_p7_config_t *pnf_p7, nfapi_tx_request_t *req) {
+  tx_req_num_elems = req->tx_request_body.number_of_pdus;
+  tx_request_pdu_list = calloc(tx_req_num_elems, sizeof(nfapi_tx_request_pdu_t));
+  for (int i = 0; i < tx_req_num_elems; i++) {
+    tx_request_pdu_list[i].num_segments = req->tx_request_body.tx_pdu_list[i].num_segments;
+    tx_request_pdu_list[i].pdu_index = req->tx_request_body.tx_pdu_list[i].pdu_index;
+    tx_request_pdu_list[i].pdu_length = req->tx_request_body.tx_pdu_list[i].pdu_length;
+    for (int j = 0; j < req->tx_request_body.tx_pdu_list[i].num_segments; j++) {
+      tx_request_pdu_list[i].segments[j].segment_length = req->tx_request_body.tx_pdu_list[i].segments[j].segment_length;
+      if (tx_request_pdu_list[i].segments[j].segment_length > 0) {
+        tx_request_pdu_list[i].segments[j].segment_data = calloc(
+            tx_request_pdu_list[i].segments[j].segment_length, sizeof(uint8_t));
+        memcpy(tx_request_pdu_list[i].segments[j].segment_data,
+               req->tx_request_body.tx_pdu_list[i].segments[j].segment_data,
+               tx_request_pdu_list[i].segments[j].segment_length);
+      }
+    }
+  }
 
-
-
-int memcpy_tx_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_tx_request_t* req)
-{
-
-	tx_req_num_elems = req->tx_request_body.number_of_pdus;
-	tx_request_pdu_list = (nfapi_tx_request_pdu_t*) calloc(tx_req_num_elems, sizeof(nfapi_tx_request_pdu_t));
-	for (int i=0; itx_request_body.tx_pdu_list[i].num_segments;
-		tx_request_pdu_list[i].pdu_index = req->tx_request_body.tx_pdu_list[i].pdu_index;
-		tx_request_pdu_list[i].pdu_length = req->tx_request_body.tx_pdu_list[i].pdu_length;
-		for (int j=0; jtx_request_body.tx_pdu_list[i].num_segments; j++){
-			//*tx_request_pdu_list[i].segments[j].segment_data = *req->tx_request_body.tx_pdu_list[i].segments[j].segment_data;
-			tx_request_pdu_list[i].segments[j].segment_length = req->tx_request_body.tx_pdu_list[i].segments[j].segment_length;
-			if(tx_request_pdu_list[i].segments[j].segment_length > 0){
-				tx_request_pdu_list[i].segments[j].segment_data = (uint8_t*)malloc(tx_request_pdu_list[i].segments[j].segment_length*sizeof (uint8_t));
-			memcpy(tx_request_pdu_list[i].segments[j].segment_data, req->tx_request_body.tx_pdu_list[i].segments[j].segment_data, tx_request_pdu_list[i].segments[j].segment_length);
-			}
-		}
-
-	}
-
-	return 0;
+  return 0;
 }
 
-int memcpy_hi_dci0_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* req)
-{
+int memcpy_hi_dci0_req(nfapi_pnf_p7_config_t *pnf_p7,
+                       nfapi_hi_dci0_request_t *req) {
+  hi_dci0_req = (nfapi_hi_dci0_request_t *)malloc(sizeof(nfapi_hi_dci0_request_t));
 
-	//if(req!=0){
+  hi_dci0_req->sfn_sf = req->sfn_sf;
+  hi_dci0_req->vendor_extension = req->vendor_extension;
 
-	//for (Mod_id=0; Mod_idhi_dci0_request_body.number_of_dci = req->hi_dci0_request_body.number_of_dci;
+  hi_dci0_req->hi_dci0_request_body.number_of_hi = req->hi_dci0_request_body.number_of_hi;
+  hi_dci0_req->hi_dci0_request_body.sfnsf = req->hi_dci0_request_body.sfnsf;
 
-	hi_dci0_req->sfn_sf = req->sfn_sf;
-	hi_dci0_req->vendor_extension = req->vendor_extension;
+  // UE_mac_inst[Mod_id].hi_dci0_req->hi_dci0_request_body.tl =
+  // req->hi_dci0_request_body.tl;
+  hi_dci0_req->hi_dci0_request_body.tl.tag = req->hi_dci0_request_body.tl.tag;
+  hi_dci0_req->hi_dci0_request_body.tl.length = req->hi_dci0_request_body.tl.length;
 
-	hi_dci0_req->hi_dci0_request_body.number_of_dci = req->hi_dci0_request_body.number_of_dci;
-	hi_dci0_req->hi_dci0_request_body.number_of_hi = req->hi_dci0_request_body.number_of_hi;
-	hi_dci0_req->hi_dci0_request_body.sfnsf = req->hi_dci0_request_body.sfnsf;
+  int total_pdus = hi_dci0_req->hi_dci0_request_body.number_of_dci
+                   + hi_dci0_req->hi_dci0_request_body.number_of_hi;
 
-	//UE_mac_inst[Mod_id].hi_dci0_req->hi_dci0_request_body.tl = req->hi_dci0_request_body.tl;
-	hi_dci0_req->hi_dci0_request_body.tl.tag = req->hi_dci0_request_body.tl.tag;
-	hi_dci0_req->hi_dci0_request_body.tl.length = req->hi_dci0_request_body.tl.length;
+  hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list =
+      calloc(total_pdus, sizeof(nfapi_hi_dci0_request_pdu_t));
 
-	int total_pdus = hi_dci0_req->hi_dci0_request_body.number_of_dci + hi_dci0_req->hi_dci0_request_body.number_of_hi;
-
-	hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list = (nfapi_hi_dci0_request_pdu_t*) malloc(total_pdus*sizeof(nfapi_hi_dci0_request_pdu_t));
-
-	for(int i=0; ihi_dci0_request_body.hi_dci0_pdu_list[i] = req->hi_dci0_request_body.hi_dci0_pdu_list[i];
-		//LOG_I(MAC, "Original hi_dci0 req. type:%d, Copy type: %d \n",req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type, UE_mac_inst[Mod_id].hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type);
-	}
-
-	//}
-		return 0;
+  for (int i = 0; i < total_pdus; i++) {
+    hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list[i] = req->hi_dci0_request_body.hi_dci0_pdu_list[i];
+    // LOG_I(MAC, "Original hi_dci0 req. type:%d, Copy type: %d
+    // \n",req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type,
+    // UE_mac_inst[Mod_id].hi_dci0_req->hi_dci0_request_body.hi_dci0_pdu_list[i].pdu_type);
+  }
+  return 0;
 }
 
-
-
 void UE_config_stub_pnf(void) {
-  int               j;
+  int j;
   paramdef_t L1_Params[] = L1PARAMS_DESC;
-  paramlist_def_t L1_ParamList = {CONFIG_STRING_L1_LIST,NULL,0};
+  paramlist_def_t L1_ParamList = {CONFIG_STRING_L1_LIST, NULL, 0};
 
-  config_getlist( &L1_ParamList,L1_Params,sizeof(L1_Params)/sizeof(paramdef_t), NULL);
+  config_getlist(&L1_ParamList, L1_Params, sizeof(L1_Params) / sizeof(paramdef_t), NULL);
   if (L1_ParamList.numelt > 0) {
-	  for (j=0; j
Date: Fri, 6 Mar 2020 15:15:02 +0100
Subject: [PATCH 46/73] CI: adding back more testing (ping and iperf) to L2
 simulator

Signed-off-by: Raphael Defosseux 
---
 ci-scripts/runTestOnVM.sh | 86 ++++++++++++++++++++++++++++++++-------
 1 file changed, 72 insertions(+), 14 deletions(-)

diff --git a/ci-scripts/runTestOnVM.sh b/ci-scripts/runTestOnVM.sh
index 4e1734da63..09859133cc 100755
--- a/ci-scripts/runTestOnVM.sh
+++ b/ci-scripts/runTestOnVM.sh
@@ -613,8 +613,11 @@ function start_epc {
         echo "############################################################"
         echo "echo \"cd /opt/hss_sim0609\"" > $LOC_EPC_VM_CMDS
         echo "cd /opt/hss_sim0609" >> $LOC_EPC_VM_CMDS
-        echo "echo \"sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real\"" >> $LOC_EPC_VM_CMDS
-        echo "sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real" >> $LOC_EPC_VM_CMDS
+        echo "sudo rm -f hss.log" >> $LOC_EPC_VM_CMDS
+        #echo "echo \"sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real\"" >> $LOC_EPC_VM_CMDS
+        #echo "sudo daemon --unsafe --name=simulated_hss --chdir=/opt/hss_sim0609 ./starthss_real" >> $LOC_EPC_VM_CMDS
+        echo "echo \"screen -dm -S simulated_hss ./starthss_real\"" >> $LOC_EPC_VM_CMDS
+        echo "sudo su -c \"screen -dm -S simulated_hss ./starthss_real\"" >> $LOC_EPC_VM_CMDS
 
         echo "echo \"cd /opt/ltebox/tools/\"" >> $LOC_EPC_VM_CMDS
         echo "cd /opt/ltebox/tools/" >> $LOC_EPC_VM_CMDS
@@ -905,8 +908,9 @@ function start_l2_sim_ue {
     else
         echo "L2-SIM UE is sync'ed w/ eNB"
     fi
-    local max_interfaces_to_check=1
-    if [ $LOC_S1_CONFIGURATION -eq 0 ]; then max_interfaces_to_check=$LOC_NB_UES; fi
+    local max_interfaces_to_check=$LOC_NB_UES
+    #local max_interfaces_to_check=1
+    #if [ $LOC_S1_CONFIGURATION -eq 0 ]; then max_interfaces_to_check=$LOC_NB_UES; fi
     local j="1"
     while [ $j -le $max_interfaces_to_check ]
     do
@@ -2214,15 +2218,41 @@ function run_test_on_vm {
 
                 if [ $S1_NOS1_CFG -eq 1 ]
                 then
-                    get_ue_ip_addr $UE_VM_CMDS $UE_VM_IP_ADDR 1
 
                     echo "############################################################"
                     echo "${CN_CONFIG} : Pinging the EPC from UE(s)"
                     echo "############################################################"
-                    PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_epc.log
-                    ping_epc_ip_addr $UE_VM_CMDS $UE_VM_IP_ADDR $REAL_EPC_IP_ADDR $PING_LOG_FILE 1 0
-                    scp -o StrictHostKeyChecking=no ubuntu@$UE_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-                    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+                    echo " --- Sequentially ---"
+                    local j="1"
+                    while [ $j -le $INT_NB_UES ]
+                    do
+                        PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_epc_seq_from_ue${j}.log
+                        ping_epc_ip_addr $UE_VM_CMDS $UE_VM_IP_ADDR $REAL_EPC_IP_ADDR $PING_LOG_FILE ${j} 0
+                        scp -o StrictHostKeyChecking=no ubuntu@$UE_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+                        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+                        j=$[$j+1]
+                    done
+                    if [ $INT_NB_UES -gt 1 ]
+                    then
+                        echo " --- In parallel ---"
+                        j="1"
+                        while [ $j -le $INT_NB_UES ]
+                        do
+                            PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_epc_para_from_ue${j}.log
+                            ping_epc_ip_addr $UE_VM_CMDS $UE_VM_IP_ADDR $REAL_EPC_IP_ADDR $PING_LOG_FILE ${j} 1
+                            j=$[$j+1]
+                        done
+                        sleep 25
+                        j="1"
+                        while [ $j -le $INT_NB_UES ]
+                        do
+                            PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_epc_para_from_ue${j}.log
+                            scp -o StrictHostKeyChecking=no ubuntu@$UE_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+                            tail -3 $ARCHIVES_LOC/$PING_LOG_FILE
+                            check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+                            j=$[$j+1]
+                        done
+                    fi
                 else
                     get_enb_noS1_ip_addr $ENB_VM_CMDS $ENB_VM_IP_ADDR
 
@@ -2267,10 +2297,38 @@ function run_test_on_vm {
                     echo "############################################################"
                     echo "${CN_CONFIG} : Pinging the UE(s) from EPC"
                     echo "############################################################"
-                    PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_ue.log
-                    ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE 0
-                    scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
-                    check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+                    echo " --- Sequentially ---"
+                    local j="1"
+                    while [ $j -le $INT_NB_UES ]
+                    do
+                        get_ue_ip_addr $UE_VM_CMDS $UE_VM_IP_ADDR $j
+                        PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_from_epc_seq_ue${j}.log
+                        ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE 0
+                        scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+                        check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+                        j=$[$j+1]
+                    done
+                    if [ $INT_NB_UES -gt 1 ]
+                    then
+                        echo " --- In parallel ---"
+                        j="1"
+                        while [ $j -le $INT_NB_UES ]
+                        do
+                            get_ue_ip_addr $UE_VM_CMDS $UE_VM_IP_ADDR $j
+                            PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_from_epc_para_ue${j}.log
+                            ping_ue_ip_addr $EPC_VM_CMDS $EPC_VM_IP_ADDR $UE_IP_ADDR $PING_LOG_FILE 1
+                            j=$[$j+1]
+                        done
+                        sleep 25
+                        j="1"
+                        while [ $j -le $INT_NB_UES ]
+                        do
+                            PING_LOG_FILE=${TMODE}_${BW}MHz_${UES}users_${CN_CONFIG}_ping_from_epc_para_ue${j}.log
+                            scp -o StrictHostKeyChecking=no ubuntu@$EPC_VM_IP_ADDR:/home/ubuntu/$PING_LOG_FILE $ARCHIVES_LOC
+                            check_ping_result $ARCHIVES_LOC/$PING_LOG_FILE 20
+                            j=$[$j+1]
+                        done
+                    fi
                 else
                     echo "############################################################"
                     echo "${CN_CONFIG} : Pinging the UE(s) from eNB"
@@ -2310,7 +2368,7 @@ function run_test_on_vm {
                     fi
                 fi
 
-                if [ $S1_NOS1_CFG -eq 2 ]
+                if [ $S1_NOS1_CFG -eq 0 ]
                 then
                     get_enb_noS1_ip_addr $ENB_VM_CMDS $ENB_VM_IP_ADDR
                     echo "############################################################"

From c6182d3ee29af828deefa4aceb454dda6b21b99a Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani 
Date: Tue, 10 Mar 2020 12:26:00 +0100
Subject: [PATCH 47/73] updated frame_idx in UE

---
 executables/nr-ue.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index 67f6169868..f73807bdf2 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -665,6 +665,7 @@ void *UE_thread(void *arg) {
   int thread_idx=0;
   notifiedFIFO_t freeBlocks;
   initNotifiedFIFO_nothreadSafe(&freeBlocks);
+  NR_UE_MAC_INST_t *mac = get_mac_inst(0);
 
   for (int i=0; imsgData;
 
         if (tmp->proc.decoded_frame_rx != -1)
-          decoded_frame_rx=tmp->proc.decoded_frame_rx;
+          decoded_frame_rx=(((mac->mib->systemFrameNumber.buf[0] >> mac->mib->systemFrameNumber.bits_unused)<<4) | tmp->proc.decoded_frame_rx);
+          //decoded_frame_rx=tmp->proc.decoded_frame_rx;
 
         pushNotifiedFIFO_nothreadSafe(&freeBlocks,res);
       }
@@ -851,7 +853,8 @@ void *UE_thread(void *arg) {
       processingData_t *tmp=(processingData_t *)res->msgData;
 
       if (tmp->proc.decoded_frame_rx != -1)
-        decoded_frame_rx=tmp->proc.decoded_frame_rx;
+        decoded_frame_rx=(((mac->mib->systemFrameNumber.buf[0] >> mac->mib->systemFrameNumber.bits_unused)<<4) | tmp->proc.decoded_frame_rx);
+        //decoded_frame_rx=tmp->proc.decoded_frame_rx;
 
       pushNotifiedFIFO_nothreadSafe(&freeBlocks,res);
     }

From 0de3c7347527fcf28712a4cbf0277da35b4104f3 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Mon, 9 Mar 2020 14:25:19 +0100
Subject: [PATCH 48/73] Place MBMS tun fd into single int

---
 .../SIMULATION/ETH_TRANSPORT/netlink_init.c   | 20 +++++++++----------
 openair1/SIMULATION/ETH_TRANSPORT/proto.h     |  2 +-
 openair2/LAYER2/PDCP_v10.1.0/pdcp.c           |  6 +++---
 openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c      |  6 +++---
 4 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c b/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c
index dfb5578ba6..9b4aba46c3 100644
--- a/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c
+++ b/openair1/SIMULATION/ETH_TRANSPORT/netlink_init.c
@@ -58,7 +58,7 @@ struct iovec nas_iov_rx = {nl_rx_buf, sizeof(nl_rx_buf)};
 
 int nas_sock_fd[MAX_MOBILES_PER_ENB];
 
-int nas_sock_mbms_fd[8];
+int nas_sock_mbms_fd;
 
 struct msghdr nas_msg_tx;
 struct msghdr nas_msg_rx;
@@ -95,21 +95,20 @@ static int tun_alloc(char *dev) {
 }
 
 
-int netlink_init_mbms_tun(char *ifprefix, int num_if) {
+int netlink_init_mbms_tun(char *ifprefix) {
   int ret;
   char ifname[64];
 
-  int i= num_if-1;
-    sprintf(ifname, "oaitun_%.3s%d",ifprefix,i+1);
-    nas_sock_mbms_fd[i] = tun_alloc(ifname);
+    sprintf(ifname, "oaitun_%.3s1",ifprefix); // added "1": for historical reasons
+    nas_sock_mbms_fd = tun_alloc(ifname);
 
-    if (nas_sock_mbms_fd[i] == -1) {
+    if (nas_sock_mbms_fd == -1) {
       printf("[NETLINK] Error opening socket %s (%d:%s)\n",ifname,errno, strerror(errno));
       exit(1);
     }
 
-    printf("[NETLINK]Opened socket %s with fd %d\n",ifname,nas_sock_mbms_fd[i]);
-    ret = fcntl(nas_sock_mbms_fd[i],F_SETFL,O_NONBLOCK);
+    printf("[NETLINK]Opened socket %s with fd %d\n",ifname,nas_sock_mbms_fd);
+    ret = fcntl(nas_sock_mbms_fd,F_SETFL,O_NONBLOCK);
 
     if (ret == -1) {
       printf("[NETLINK] Error fcntl (%d:%s)\n",errno, strerror(errno));
@@ -123,7 +122,7 @@ int netlink_init_mbms_tun(char *ifprefix, int num_if) {
     nas_src_addr.nl_family = AF_NETLINK;
     nas_src_addr.nl_pid = 1;//getpid();  /* self pid */
     nas_src_addr.nl_groups = 0;  /* not in mcast groups */
-    ret = bind(nas_sock_mbms_fd[i], (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr));
+    ret = bind(nas_sock_mbms_fd, (struct sockaddr *)&nas_src_addr, sizeof(nas_src_addr));
     memset(&nas_dest_addr, 0, sizeof(nas_dest_addr));
     nas_dest_addr.nl_family = AF_NETLINK;
     nas_dest_addr.nl_pid = 0;   /* For Linux Kernel */
@@ -165,7 +164,8 @@ int netlink_init_tun(char *ifprefix, int num_if) {
       exit(1);
     }
 
-    printf("[NETLINK]Opened socket %s with fd %d\n",ifname,nas_sock_fd[i]);
+    printf("[NETLINK]Opened socket %s with fd nas_sock_fd[%d]=%d\n",
+           ifname, i, nas_sock_fd[i]);
     ret = fcntl(nas_sock_fd[i],F_SETFL,O_NONBLOCK);
 
     if (ret == -1) {
diff --git a/openair1/SIMULATION/ETH_TRANSPORT/proto.h b/openair1/SIMULATION/ETH_TRANSPORT/proto.h
index 02f7925d93..e6159199d4 100644
--- a/openair1/SIMULATION/ETH_TRANSPORT/proto.h
+++ b/openair1/SIMULATION/ETH_TRANSPORT/proto.h
@@ -63,6 +63,6 @@ void clear_eNB_transport_info(uint8_t);
 void clear_UE_transport_info(uint8_t);
 int netlink_init(void);
 int netlink_init_tun(char *ifsuffix, int num_if);
-int netlink_init_mbms_tun(char *ifsuffix, int num_if);
+int netlink_init_mbms_tun(char *ifsuffix);
 
 #endif /* EMU_PROTO_H_ */
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
index 254d741ae8..b0e6143de1 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
@@ -2299,14 +2299,14 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask ) {
       netlink_init_tun("ue",num_if);
       if (IS_SOFTMODEM_NOS1)
     	  nas_config(1, 1, 2, "ue");
-      netlink_init_mbms_tun("uem",num_if);
+      netlink_init_mbms_tun("uem");
       nas_config_mbms(1, 2, 2, "uem");
       LOG_I(PDCP, "UE pdcp will use tun interface\n");
     } else if(ENB_NAS_USE_TUN) {
       netlink_init_tun("enb",1);
       nas_config(1, 1, 1, "enb");
       if(pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT){
-      	netlink_init_mbms_tun("enm",1);
+        netlink_init_mbms_tun("enm");
       	nas_config_mbms(1, 2, 1, "enm"); 
       	LOG_I(PDCP, "ENB pdcp will use mbms tun interface\n");
       }
@@ -2318,7 +2318,7 @@ uint64_t pdcp_module_init( uint64_t pdcp_optmask ) {
   }else{
          if(pdcp_optmask & ENB_NAS_USE_TUN_W_MBMS_BIT){
              LOG_W(PDCP, "ENB pdcp will use tun interface for MBMS\n");
-            netlink_init_mbms_tun("enm",1);
+            netlink_init_mbms_tun("enm");
              nas_config_mbms_s1(1, 2, 1, "enm"); 
          }else
              LOG_E(PDCP, "ENB pdcp will not use tun interface\n");
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index a441ff220e..d203408e55 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -77,7 +77,7 @@ extern struct iovec nas_iov_rx;
 
 extern int nas_sock_fd[MAX_MOBILES_PER_ENB];
 
-extern int nas_sock_mbms_fd[8];
+extern int nas_sock_mbms_fd;
 
 extern int mbms_rab_id;
 
@@ -133,7 +133,7 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t *const  ctxt_pP) {
     } else if (UE_NAS_USE_TUN) {
       //ret = write(nas_sock_fd[ctxt_pP->module_id], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite );
        if(rb_id == mbms_rab_id){
-       ret = write(nas_sock_mbms_fd[0], &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite );
+       ret = write(nas_sock_mbms_fd, &(sdu_p->data[sizeof(pdcp_data_ind_header_t)]),sizeToWrite );
        LOG_I(PDCP,"[PDCP_FIFOS] ret %d TRIED TO PUSH MBMS DATA TO rb_id %d handle %d sizeToWrite %d\n",ret,rb_id,nas_sock_fd[ctxt_pP->module_id],sizeToWrite);
         }
        else
@@ -299,7 +299,7 @@ int pdcp_fifo_read_input_mbms_sdus_fromtun (const protocol_ctxt_t *const  ctxt_p
   do {
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_MBMS_FIFO_READ, 1 );
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_MBMS_FIFO_READ_BUFFER, 1 );
-    len = read(UE_NAS_USE_TUN?nas_sock_mbms_fd[0]:nas_sock_mbms_fd[0], &nl_rx_buf, NL_MAX_PAYLOAD);
+    len = read(nas_sock_mbms_fd, &nl_rx_buf, NL_MAX_PAYLOAD);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_PDCP_MBMS_FIFO_READ_BUFFER, 0 );
 
     if (len<=0) continue;

From 8928cfe57d9f7100c7902a44a6fa853cc24543c5 Mon Sep 17 00:00:00 2001
From: frtabu 
Date: Wed, 11 Mar 2020 17:32:13 +0100
Subject: [PATCH 49/73] move ldpc coder/decoder into a shared lib dymically
 loaded. Also fix a record player bug

---
 cmake_targets/CMakeLists.txt                  |  39 +-
 common/config/config_userapi.c                |   3 +-
 common/utils/telnetsrv/telnetsrv.c            |  20 +-
 openair1/PHY/CODING/TESTBENCH/ldpctest.c      |  22 +-
 .../CODING/nrLDPC_decoder/nrLDPC_decoder.c    |   4 +-
 .../PHY/CODING/nrLDPC_decoder/nrLDPC_init.h   |   2 +-
 .../CODING/nrLDPC_decoder/nrLDPC_init_mem.h   |   1 -
 .../PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h  |   2 +-
 .../PHY/CODING/nrLDPC_decoder/nrLDPC_types.h  |   5 +-
 .../{nrLDPC_defs.h => nrLDPCdecoder_defs.h}   |   2 +-
 openair1/PHY/CODING/nrLDPC_defs.h             |  59 ++
 openair1/PHY/CODING/nrLDPC_encoder/defs.h     |  54 --
 .../nrLDPC_encoder/ldpc_encode_parity_check.c | 201 ++++++
 .../PHY/CODING/nrLDPC_encoder/ldpc_encoder.c  | 252 +++++--
 .../PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c | 667 ------------------
 .../nrLDPC_encoder/ldpc_encoder_optim.c       | 146 ++++
 .../ldpc_generate_coefficient.c               | 244 +------
 .../nrLDPC_decoder.h => nrLDPC_extern.h}      |  39 +-
 openair1/PHY/CODING/nrLDPC_load.c             |  76 ++
 openair1/PHY/INIT/nr_init.c                   |   2 +
 openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c   |   9 +-
 openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c |   3 +-
 .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c   |   3 +-
 .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c     |   7 +-
 openair1/PHY/defs_gNB.h                       |   2 +-
 targets/ARCH/COMMON/common_lib.c              |  35 +-
 targets/ARCH/COMMON/common_lib.h              |  18 +
 targets/ARCH/COMMON/record_player.h           |  15 +-
 targets/ARCH/iqplayer/iqplayer_lib.c          |  14 +-
 targets/RT/USER/lte-ru.c                      |   4 +-
 30 files changed, 888 insertions(+), 1062 deletions(-)
 rename openair1/PHY/CODING/nrLDPC_decoder/{nrLDPC_defs.h => nrLDPCdecoder_defs.h} (99%)
 create mode 100644 openair1/PHY/CODING/nrLDPC_defs.h
 delete mode 100644 openair1/PHY/CODING/nrLDPC_encoder/defs.h
 create mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c
 delete mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
 create mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
 rename openair1/PHY/CODING/{nrLDPC_decoder/nrLDPC_decoder.h => nrLDPC_extern.h} (60%)
 create mode 100644 openair1/PHY/CODING/nrLDPC_load.c

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index c4d3d7e62e..496417936a 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -1298,14 +1298,35 @@ set(PHY_SMALLBLOCKSRC
 set(PHY_TURBOIF
   ${OPENAIR1_DIR}/PHY/CODING/coding_load.c
 )
-set(PHY_LDPCSRC
+
+set(PHY_LDPC_ORIG_SRC
   ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
   ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
 )
 
+set(PHY_LDPC_OPTIM_SRC
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
+)
+set(PHY_LDPC_OPTIM8SEG_SRC
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8seg.c
+)
+set(PHY_LDPC_OPTIM8SEGMULTI_SRC
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
+)
+set(PHY_NR_CODINGIF
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_load.c;
+)
+
+add_library(ldpc_orig MODULE ${PHY_LDPC_ORIG_SRC} )
+add_library(ldpc_optim MODULE ${PHY_LDPC_OPTIM_SRC} )
+add_library(ldpc_optim8seg MODULE ${PHY_LDPC_OPTIM8SEG_SRC} )
+add_library(ldpc MODULE ${PHY_LDPC_OPTIM8SEGMULTI_SRC} )
+
 add_library(coding MODULE ${PHY_TURBOSRC} )
+
 set(PHY_SRC_COMMON
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/dci_tools_common.c
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/lte_mcs.c
@@ -1484,10 +1505,9 @@ set(PHY_SRC_UE
   ${OPENAIR1_DIR}/PHY/TOOLS/lut.c
   ${PHY_POLARSRC}
   ${PHY_SMALLBLOCKSRC}
-  ${PHY_LDPCSRC}
+  ${PHY_NR_CODINGIF}
   ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/pucch_rx.c 
   )
-
   set(PHY_NR_UE_SRC
   ${OPENAIR1_DIR}/PHY/INIT/nr_parms.c
   ${OPENAIR1_DIR}/PHY/MODULATION/nr_modulation.c
@@ -1535,7 +1555,7 @@ set(PHY_SRC_UE
   #  ${OPENAIR1_DIR}/SIMULATION/NR_UE_PHY/unit_tests/src/pucch_uci_test.c
   ${PHY_POLARSRC}
   ${PHY_SMALLBLOCKSRC}
-  ${PHY_LDPCSRC}
+  ${PHY_NR_CODINGIF}
   )
 
 
@@ -2588,7 +2608,7 @@ target_link_libraries (nr-softmodem pthread m ${CONFIG_LIB} rt crypt ${CRYPTO_LI
 target_link_libraries (nr-softmodem ${LIB_LMS_LIBRARIES})
 target_link_libraries (nr-softmodem ${T_LIB})
 
-
+add_dependencies( nr-softmodem ldpc_orig ldpc_optim ldpc_optim8seg ldpc )
 # nr-uesoftmodem is  UE implementation
 #######################################
 
@@ -2629,7 +2649,7 @@ target_link_libraries (nr-uesoftmodem pthread m ${CONFIG_LIB} rt crypt ${CRYPTO_
 target_link_libraries (nr-uesoftmodem ${LIB_LMS_LIBRARIES})
 target_link_libraries (nr-uesoftmodem ${T_LIB})
 
-
+add_dependencies( nr-uesoftmodem ldpc_orig ldpc_optim ldpc_optim8seg ldpc )
 
 # USIM process
 #################
@@ -2696,10 +2716,13 @@ target_link_libraries(smallblocktest
   )
 
 add_executable(ldpctest  
+  ${PHY_NR_CODINGIF}
   ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/ldpctest.c
   ${T_SOURCE}
   ${SHLIB_LOADER_SOURCES}
   )
+add_dependencies( ldpctest ldpc_orig ldpc_optim ldpc_optim8seg ldpc ) 
+
 target_link_libraries(ldpctest
   -Wl,--start-group UTIL SIMU PHY_NR CONFIG_LIB -Wl,--end-group
   m pthread ${ATLAS_LIBRARIES} dl
diff --git a/common/config/config_userapi.c b/common/config/config_userapi.c
index 67fdc2c920..c951905101 100644
--- a/common/config/config_userapi.c
+++ b/common/config/config_userapi.c
@@ -45,7 +45,8 @@
 
 configmodule_interface_t *config_get_if(void) {
   if (cfgptr == NULL) {
-    CONFIG_PRINTF_ERROR("[CONFIG] %s %d config module not initialized\n",__FILE__,__LINE__);
+  	if (isLogInitDone())
+       LOG_W(ENB_APP,"[CONFIG] %s %d config module not initialized\n",__FILE__,__LINE__);
   }
 
   return cfgptr;
diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c
index 10163b22b5..06a5d350c7 100644
--- a/common/utils/telnetsrv/telnetsrv.c
+++ b/common/utils/telnetsrv/telnetsrv.c
@@ -377,6 +377,14 @@ int setgetvar(int moduleindex,char getorset,char *params) {
             client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
             break;
 
+          case TELNET_VARTYPE_INT8:
+            client_printf("%i\n",(int)(*(int8_t *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)));
+            break;
+            
+          case TELNET_VARTYPE_UINT:
+            client_printf("%u\n",*(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+            
           case TELNET_VARTYPE_DOUBLE:
             client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
             break;
@@ -405,7 +413,17 @@ int setgetvar(int moduleindex,char getorset,char *params) {
             *(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (short)strtol(varval,NULL,0);
             client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
             break;
-
+            
+          case TELNET_VARTYPE_INT8:
+            *(char *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (char)strtol(varval,NULL,0);
+            client_printf("%i\n",*(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+            
+          case TELNET_VARTYPE_UINT:
+            *(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (unsigned int)strtol(varval,NULL,0);
+            client_printf("%u\n",*(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+ 
           case TELNET_VARTYPE_DOUBLE:
             *(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = strtod(varval,NULL);
             client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
index 95ee3fed17..552af99c41 100644
--- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c
+++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
@@ -25,8 +25,7 @@
 #include 
 #include "assertions.h"
 #include "SIMULATION/TOOLS/sim.h"
-#include "PHY/CODING/nrLDPC_encoder/defs.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "openair1/SIMULATION/NR_PHY/nr_unitary_defs.h"
 
 #define MAX_NUM_DLSCH_SEGMENTS 16
@@ -85,6 +84,7 @@ typedef struct {
 RAN_CONTEXT_t RC;
 PHY_VARS_UE ***PHY_vars_UE_g;
 uint16_t NB_UE_INST = 1;
+nrLDPC_encoderfunc_t encoder_orig;
 
 short lift_size[51]= {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32,36,40,44,48,52,56,60,64,72,80,88,96,104,112,120,128,144,160,176,192,208,224,240,256,288,320,352,384};
 
@@ -286,16 +286,19 @@ int test_ldpc(short No_iteration,
   no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*(1/((float)nom_rate/(float)denom_rate)))/Zc;
   //  printf("puncture:%d\n",no_punctured_columns);
   removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length/((float)nom_rate/(float)denom_rate));
+  encoder_implemparams_t impp=INIT0_LDPCIMPLEMPARAMS;
+ 
+  impp.gen_code=1;
   if (ntrials==0)
-    ldpc_encoder_orig(test_input[0],channel_input[0], Zc, BG, block_length, BG, 1);
-
+    encoder_orig(test_input,channel_input, Zc, BG, block_length, BG, &impp);
+  impp.gen_code=0;
   for (trial=0; trial < ntrials; trial++)
   {
 	segment_bler = 0;
     //// encoder
     start_meas(&time);
     for(j=0;j
 #include 
-#include "nrLDPC_defs.h"
+#include "nrLDPCdecoder_defs.h"
 #include "nrLDPC_types.h"
 #include "nrLDPC_init.h"
 #include "nrLDPC_mPass.h"
@@ -47,7 +47,7 @@
 
 static inline uint32_t nrLDPC_decoder_core(int8_t* p_llr, int8_t* p_out, t_nrLDPC_procBuf* p_procBuf, uint32_t numLLR, t_nrLDPC_lut* p_lut, t_nrLDPC_dec_params* p_decParams, t_nrLDPC_time_stats* p_profiler);
 
-int32_t nrLDPC_decoder(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_out, t_nrLDPC_procBuf* p_procBuf, t_nrLDPC_time_stats* p_profiler)
+int32_t nrLDPC_decod(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_out, t_nrLDPC_procBuf* p_procBuf, t_nrLDPC_time_stats* p_profiler)
 {
     uint32_t numLLR;
     uint32_t numIter = 0;
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h
index 82462c6d95..ea031dc2da 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h
@@ -32,7 +32,7 @@
 #define __NR_LDPC_INIT__H__
 
 #include "nrLDPC_lut.h"
-#include "nrLDPC_defs.h"
+#include "nrLDPCdecoder_defs.h"
 
 /**
    \brief Initializes the decoder and sets correct LUTs
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h
index bdaa118e1f..3292c0debe 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h
@@ -32,7 +32,6 @@
 #define __NR_LDPC_INIT_MEM__H__
 
 #include 
-#include "nrLDPC_defs.h"
 #include "nrLDPC_types.h"
 
 #ifndef malloc32_clear
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h
index 66715618d0..7d0f5f077a 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h
@@ -32,7 +32,7 @@
 #define __NR_LDPC_MPASS__H__
 
 #include 
-#include "nrLDPC_defs.h"
+#include "nrLDPCdecoder_defs.h"
 
 /**
    \brief Circular memcpy
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h
index 34322a7780..e5b99246d5 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h
@@ -32,8 +32,7 @@
 #define __NR_LDPC_TYPES__H__
 
 #include "PHY/TOOLS/time_meas.h"
-#include "nrLDPC_defs.h"
-
+#include "nrLDPCdecoder_defs.h"
 // ==============================================================================
 // TYPES
 
@@ -103,4 +102,6 @@ typedef struct nrLDPC_procBuf {
     int8_t* llrProcBuf; /**< LLR processing buffer */
 } t_nrLDPC_procBuf;
 
+
+
 #endif
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_defs.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPCdecoder_defs.h
similarity index 99%
rename from openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_defs.h
rename to openair1/PHY/CODING/nrLDPC_decoder/nrLDPCdecoder_defs.h
index 940d842550..69fc88752f 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_defs.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPCdecoder_defs.h
@@ -19,7 +19,7 @@
  *      contact@openairinterface.org
  */
 
-/*!\file nrLDPC_defs.h
+/*!\file nrLDPCdecoder_defs.h
  * \brief Defines all constants and buffers for the LDPC decoder
  * \author Sebastian Wagner (TCL Communications) Email: 
  * \date 27-03-2018
diff --git a/openair1/PHY/CODING/nrLDPC_defs.h b/openair1/PHY/CODING/nrLDPC_defs.h
new file mode 100644
index 0000000000..b96067f4b6
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_defs.h
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+//============================================================================================================================
+// encoder interface
+#ifndef __NRLDPC_DEFS__H__
+#define __NRLDPC_DEFS__H__
+#include "openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
+/**
+   \brief LDPC encoder
+   \param 1 input
+   \param 2 channel_input
+   \param 3 int Zc
+   \param 4 int Kb
+   \param 5 short block_length
+   \param 6 short BG
+   \param 7 int n_segment
+   \param 8 unsigned int macro_num
+   \param 9-12 time_stats_t *tinput,*tprep, *tparity,*toutput
+*/
+typedef struct {
+	int n_segments;          // optim8seg
+	unsigned int macro_num; // optim8segmulti
+	unsigned char gen_code; //orig
+	time_stats_t *tinput;
+	time_stats_t *tprep;
+	time_stats_t *tparity;
+	time_stats_t *toutput;
+}encoder_implemparams_t;
+#define INIT0_LDPCIMPLEMPARAMS {0,0,0,NULL,NULL,NULL,NULL}
+typedef int(*nrLDPC_encoderfunc_t)(unsigned char **,unsigned char **,int,int,short, short, encoder_implemparams_t*);
+//============================================================================================================================
+// decoder interface
+/**
+   \brief LDPC decoder API type definition
+   \param p_decParams LDPC decoder parameters
+   \param p_llr Input LLRs
+   \param p_llrOut Output vector
+   \param p_profiler LDPC profiler statistics
+*/
+typedef int32_t(*nrLDPC_decoderfunc_t)(t_nrLDPC_dec_params* , int8_t*, int8_t* , t_nrLDPC_procBuf* , t_nrLDPC_time_stats* );
+#endif
\ No newline at end of file
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/defs.h b/openair1/PHY/CODING/nrLDPC_encoder/defs.h
deleted file mode 100644
index 85cb852fe5..0000000000
--- a/openair1/PHY/CODING/nrLDPC_encoder/defs.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*!\file defs.h
- * \brief LDPC encoder forward declarations
- * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
- * \email openair_tech@eurecom.fr
- * \date 27-03-2018
- * \version 1.0
- * \note
- * \warning
- */
-
-#include "PHY/TOOLS/time_meas.h"
-
-/*ldpc_encoder.c*/
-int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length);
-
-/*ldpc_encoder2.c*/
-void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,short Kb);
-int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length,short BG,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length,short BG,int n_segments,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-int ldpc_encoder_optim_8seg_multi(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, int n_segments,unsigned int macro_num, time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-
-/*ldpc_generate_coefficient.c*/
-int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length,short BG,unsigned char gen_code);
-
-/*
-int encode_parity_check_part(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb);
-int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length);
-int ldpc_encoder(unsigned char *test_input,unsigned char *channel_input,short block_length, double rate);
-int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,short block_length,int nom_rate,int denom_rate,unsigned char gen_code);
-int ldpc_encoder_multi_segment(unsigned char **test_input,unsigned char **channel_input,short block_length,double rate,uint8_t n_segments);
-int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,short block_length,int nom_rate,int denom_rate,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_input,short block_length,int nom_rate,int denom_rate,int n_segments,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-*/
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c
new file mode 100644
index 0000000000..738fd49b7d
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*!\file ldpc_encode_parity_check.c
+ * \brief Parity check function used by ldpc encoders
+ * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
+ * \email openair_tech@eurecom.fr
+ * \date 27-03-2018
+ * \version 1.0
+ * \note
+ * \warning
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+
+
+//#define DEBUG_LDPC
+
+#include "ldpc384_byte.c"
+#include "ldpc352_byte.c"
+#include "ldpc320_byte.c"
+#include "ldpc288_byte.c"
+#include "ldpc256_byte.c"
+#include "ldpc240_byte.c"
+#include "ldpc224_byte.c"
+#include "ldpc208_byte.c"
+#include "ldpc192_byte.c"
+#include "ldpc176_byte.c"
+#include "ldpc_BG2_Zc384_byte.c"
+#include "ldpc_BG2_Zc352_byte.c"
+#include "ldpc_BG2_Zc320_byte.c"
+#include "ldpc_BG2_Zc288_byte.c"
+#include "ldpc_BG2_Zc256_byte.c"
+#include "ldpc_BG2_Zc240_byte.c"
+#include "ldpc_BG2_Zc224_byte.c"
+#include "ldpc_BG2_Zc208_byte.c"
+#include "ldpc_BG2_Zc192_byte.c"
+#include "ldpc_BG2_Zc176_byte.c"
+#include "ldpc_BG2_Zc160_byte.c"
+#include "ldpc_BG2_Zc144_byte.c"
+#include "ldpc_BG2_Zc128_byte.c"
+#include "ldpc_BG2_Zc120_byte.c"
+#include "ldpc_BG2_Zc112_byte.c"
+#include "ldpc_BG2_Zc104_byte.c"
+#include "ldpc_BG2_Zc96_byte.c"
+#include "ldpc_BG2_Zc88_byte.c"
+#include "ldpc_BG2_Zc80_byte.c"
+#include "ldpc_BG2_Zc72_byte.c"
+
+
+
+static inline void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,short Kb)
+{
+
+  if (BG==1)
+  {
+    switch (Zc)
+    {
+    case 2: break;
+    case 3: break;
+    case 4: break;
+    case 5: break;
+    case 6: break;
+    case 7: break;
+    case 8: break;
+    case 9: break;
+    case 10: break;
+    case 11: break;
+    case 12: break;
+    case 13: break;
+    case 14: break;
+    case 15: break;
+    case 16: break;
+    case 18: break;
+    case 20: break;
+    case 22: break;
+    case 24: break;      
+    case 26: break;
+    case 28: break;
+    case 30: break;
+    case 32: break;
+    case 36: break;
+    case 40: break;
+    case 44: break;
+    case 48: break;
+    case 52: break;
+    case 56: break;
+    case 60: break;
+    case 64: break;
+    case 72: break;
+    case 80: break;   
+    case 88: break;   
+    case 96: break;
+    case 104: break;
+    case 112: break;
+    case 120: break;
+    case 128: break;
+    case 144: break;
+    case 160: break;
+    case 176: ldpc176_byte(c,d); break;
+    case 192: ldpc192_byte(c,d); break;
+    case 208: ldpc208_byte(c,d); break;
+    case 224: ldpc224_byte(c,d); break;
+    case 240: ldpc240_byte(c,d); break;
+    case 256: ldpc256_byte(c,d); break;
+    case 288: ldpc288_byte(c,d); break;
+    case 320: ldpc320_byte(c,d); break;
+    case 352: ldpc352_byte(c,d); break;
+    case 384: ldpc384_byte(c,d); break;
+    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
+    }
+  }
+  else if (BG==2) {
+    switch (Zc)
+    {
+    case 2: break;
+    case 3: break;
+    case 4: break;
+    case 5: break;
+    case 6: break;
+    case 7: break;
+    case 8: break;
+    case 9: break;
+    case 10: break;
+    case 11: break;
+    case 12: break;
+    case 13: break;
+    case 14: break;
+    case 15: break;
+    case 16: break;
+    case 18: break;
+    case 20: break;
+    case 22: break;
+    case 24: break;      
+    case 26: break;
+    case 28: break;
+    case 30: break;
+    case 32: break;
+    case 36: break;
+    case 40: break;
+    case 44: break;
+    case 48: break;
+    case 52: break;
+    case 56: break;
+    case 60: break;
+    case 64: break;
+    case 72: ldpc_BG2_Zc72_byte(c,d); break;
+    case 80: ldpc_BG2_Zc80_byte(c,d); break;   
+    case 88: ldpc_BG2_Zc88_byte(c,d); break;   
+    case 96: ldpc_BG2_Zc96_byte(c,d); break;
+    case 104: ldpc_BG2_Zc104_byte(c,d); break;
+    case 112: ldpc_BG2_Zc112_byte(c,d); break;
+    case 120: ldpc_BG2_Zc120_byte(c,d); break;
+    case 128: ldpc_BG2_Zc128_byte(c,d); break;
+    case 144: ldpc_BG2_Zc144_byte(c,d); break;
+    case 160: ldpc_BG2_Zc160_byte(c,d); break;
+    case 176: ldpc_BG2_Zc176_byte(c,d); break;
+    case 192: ldpc_BG2_Zc192_byte(c,d); break;
+    case 208: ldpc_BG2_Zc208_byte(c,d); break;
+    case 224: ldpc_BG2_Zc224_byte(c,d); break;
+    case 240: ldpc_BG2_Zc240_byte(c,d); break;
+    case 256: ldpc_BG2_Zc256_byte(c,d); break;
+    case 288: ldpc_BG2_Zc288_byte(c,d); break;
+    case 320: ldpc_BG2_Zc320_byte(c,d); break;
+    case 352: ldpc_BG2_Zc352_byte(c,d); break;
+    case 384: ldpc_BG2_Zc384_byte(c,d); break;
+    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
+    }
+  }
+  else {
+    AssertFatal(0,"BG %d is not supported yet\n",BG);
+  } 
+
+}
+
+
+
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
index 6ded22d8ca..76f92574ba 100644
--- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
@@ -37,77 +37,247 @@
 #include 
 #include 
 #include "defs.h"
+#include "assertions.h"
+#include "openair1/PHY/CODING/nrLDPC_defs.h"
+#include "ldpc_generate_coefficient.c"
 
-short *choose_generator_matrix(short BG,short Zc);
-extern short no_shift_values_BG1[1012],pointer_shift_values_BG1[1012],no_shift_values_BG2[2109],pointer_shift_values_BG2[2019];
 
-int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length)
+int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length, short BG,unsigned char gen_code)
 {
-  short *Gen_shift_values=choose_generator_matrix(BG,Zc);
-  short *no_shift_values, *pointer_shift_values;
-  int no_punctured_columns;
-  short nrows,ncols,rate=3;
-  int i1,i2,i3,i4,i5,temp_prime;
+  unsigned char c[22*384]; //padded input, unpacked, max size
+  unsigned char d[68*384]; //coded output, unpacked, max size
   unsigned char channel_temp,temp;
+  short *Gen_shift_values, *no_shift_values, *pointer_shift_values;
 
+  short nrows = 46;//parity check bits
+  short ncols = 22;//info bits
+
+
+  int i,i1,i2,i3,i4,i5,temp_prime,var;
+  int no_punctured_columns,removed_bit,rate=3;
+  int nind=0;
+  int indlist[1000];
+  int indlist2[1000];
+
+  //determine number of bits in codeword
+  //if (block_length>3840)
+     if (BG==1)
+       {
+         nrows=46; //parity check bits
+         ncols=22; //info bits
+         rate=3;
+       }
+       //else if (block_length<=3840)
+      else if	(BG==2)
+       {
+         //BG=2;
+         nrows=42; //parity check bits
+         ncols=10; // info bits
+         rate=5;
+         }
+
+  Gen_shift_values=choose_generator_matrix(BG,Zc);
+  if (Gen_shift_values==NULL) {
+    printf("ldpc_encoder_orig: could not find generator matrix\n");
+    return(-1);
+  }
+
+  //printf("ldpc_encoder_orig: BG %d, Zc %d, Kb %d\n",BG, Zc, Kb);
+
+  // load base graph of generator matrix
   if (BG==1)
   {
     no_shift_values=(short *) no_shift_values_BG1;
     pointer_shift_values=(short *) pointer_shift_values_BG1;
-      nrows=46; //parity check bits
-      ncols=22; //info bits
-      rate=3;
   }
   else if (BG==2)
   {
     no_shift_values=(short *) no_shift_values_BG2;
     pointer_shift_values=(short *) pointer_shift_values_BG2;
-      nrows=42; //parity check bits
-      ncols=10; //info bits
-      rate=5;
   }
   else {
-    printf("problem with BG\n");
-    return(-1);
+    AssertFatal(0,"BG %d is not supported yet\n",BG);
   }
-
-
+  
   no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
+  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(block_length*rate);
+  //printf("%d\n",no_punctured_columns);
+  //printf("%d\n",removed_bit);
+  // unpack input
+  memset(c,0,sizeof(unsigned char) * ncols * Zc);
+  memset(d,0,sizeof(unsigned char) * nrows * Zc);
 
-  //printf("no_punctured_columns = %d\n",no_punctured_columns);
-
-  for (i2=0; i2 < Zc; i2++)
+  for (i=0; i>7&1;
+    c[i]=(test_input[i/8]&(128>>(i&7)))>>(7-(i&7));
+  }
 
-    //rotate matrix here
-    for (i5=0; i5 < Kb; i5++)
-    {
-      temp = c[i5*Zc];
-      memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(unsigned char));
-      c[i5*Zc+Zc-1] = temp;
+  // parity check part
+
+  if (gen_code==1)
+  {
+    char fname[100];
+    sprintf(fname,"ldpc_BG%d_Zc%d_byte.c",BG,Zc);
+    FILE *fd=fopen(fname,"w");
+    AssertFatal(fd!=NULL,"cannot open %s\n",fname);
+    sprintf(fname,"ldpc_BG%d_Zc%d_16bit.c",BG,Zc);
+    FILE *fd2=fopen(fname,"w");
+    AssertFatal(fd2!=NULL,"cannot open %s\n",fname);
+
+    int shift;
+    char data_type[100];
+    char xor_command[100];
+    int mask;
+
+
+
+
+    fprintf(fd,"#include \"PHY/sse_intrin.h\"\n");
+    fprintf(fd2,"#include \"PHY/sse_intrin.h\"\n");
+
+    if ((Zc&31)==0) {
+      shift=5; // AVX2 - 256-bit SIMD
+      mask=31;
+      strcpy(data_type,"__m256i");
+      strcpy(xor_command,"_mm256_xor_si256");
     }
+    else if ((Zc&15)==0) {
+      shift=4; // SSE4 - 128-bit SIMD
+      mask=15;
+      strcpy(data_type,"__m128i");
+      strcpy(xor_command,"_mm_xor_si128");
 
-    // calculate each row in base graph
-    for (i1=0; i1 < nrows-no_punctured_columns; i1++)
+    }
+    else if ((Zc&7)==0) {
+      shift=3; // MMX  - 64-bit SIMD
+      mask=7;
+      strcpy(data_type,"__m64");
+      strcpy(xor_command,"_mm_xor_si64"); 
+    }
+    else {
+      shift=0;                 // no SIMD
+      mask=0;
+      strcpy(data_type,"uint8_t");
+      strcpy(xor_command,"scalar_xor");
+      fprintf(fd,"#define scalar_xor(a,b) ((a)^(b))\n");
+      fprintf(fd2,"#define scalar_xor(a,b) ((a)^(b))\n");
+    }
+    fprintf(fd,"// generated code for Zc=%d, byte encoding\n",Zc);
+    fprintf(fd2,"// generated code for Zc=%d, 16bit encoding\n",Zc);
+    fprintf(fd,"static inline void ldpc_BG%d_Zc%d_byte(uint8_t *c,uint8_t *d) {\n",BG,Zc);
+    fprintf(fd2,"static inline void ldpc_BG%d_Zc%d_16bit(uint16_t *c,uint16_t *d) {\n",BG,Zc);
+    fprintf(fd,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
+    fprintf(fd2,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
+    fprintf(fd,"  %s *c2,*d2;\n\n",data_type);
+    fprintf(fd2,"  %s *c2,*d2;\n\n",data_type);
+    fprintf(fd,"  int i2;\n");
+    fprintf(fd2,"  int i2;\n");
+    fprintf(fd,"  for (i2=0; i2<%d; i2++) {\n",Zc>>shift);
+    if (shift > 0)
+      fprintf(fd2,"  for (i2=0; i2<%d; i2++) {\n",Zc>>(shift-1));
+    for (i2=0; i2 < 1; i2++)
     {
-      channel_temp=0;
-      for (i3=0; i3 < Kb; i3++)
-      {
-        temp_prime=i1 * ncols + i3;
+      //t=Kb*Zc+i2;
+    
+      // calculate each row in base graph
+     
 
-        for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
+      fprintf(fd,"     c2=&csimd[i2];\n");
+      fprintf(fd,"     d2=&dsimd[i2];\n");
+      fprintf(fd2,"     c2=&csimd[i2];\n");
+      fprintf(fd2,"     d2=&dsimd[i2];\n");
+
+      for (i1=0; i1 < nrows; i1++)
+
+      {
+        channel_temp=0;
+        fprintf(fd,"\n//row: %d\n",i1);
+        fprintf(fd2,"\n//row: %d\n",i1);
+	fprintf(fd,"     d2[%d]=",(Zc*i1)>>shift);
+	fprintf(fd2,"     d2[%d]=",(Zc*i1)>>(shift-1));
+
+        nind=0;
+
+        for (i3=0; i3 < ncols; i3++)
         {
-          channel_temp = channel_temp ^ c[ i3*Zc + Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ] ];
+          temp_prime=i1 * ncols + i3;
+
+
+	  for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
+	    {
+	          
+	      var=(int)((i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc)/Zc);
+	      int index =var*2*Zc + (i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc) % Zc;
+	      
+	      indlist[nind] = ((index&mask)*((2*Zc)>>shift)*Kb)+(index>>shift);
+	      indlist2[nind++] = ((index&(mask>>1))*((2*Zc)>>(shift-1))*Kb)+(index>>(shift-1));
+	      
+	    }
+	  
+
         }
+	for (i4=0;i4gen_code);
+}
\ No newline at end of file
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
deleted file mode 100644
index ef207b6cdc..0000000000
--- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
+++ /dev/null
@@ -1,667 +0,0 @@
-/*
- * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*!\file ldpc_encoder2.c
- * \brief Defines the optimized LDPC encoder
- * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
- * \email openair_tech@eurecom.fr
- * \date 27-03-2018
- * \version 1.0
- * \note
- * \warning
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include "assertions.h"
-#include "common/utils/LOG/log.h"
-#include "PHY/TOOLS/time_meas.h"
-#include "defs.h"
-
-//#define DEBUG_LDPC
-
-#include "ldpc384_byte.c"
-#include "ldpc352_byte.c"
-#include "ldpc320_byte.c"
-#include "ldpc288_byte.c"
-#include "ldpc256_byte.c"
-#include "ldpc240_byte.c"
-#include "ldpc224_byte.c"
-#include "ldpc208_byte.c"
-#include "ldpc192_byte.c"
-#include "ldpc176_byte.c"
-#include "ldpc_BG2_Zc384_byte.c"
-#include "ldpc_BG2_Zc352_byte.c"
-#include "ldpc_BG2_Zc320_byte.c"
-#include "ldpc_BG2_Zc288_byte.c"
-#include "ldpc_BG2_Zc256_byte.c"
-#include "ldpc_BG2_Zc240_byte.c"
-#include "ldpc_BG2_Zc224_byte.c"
-#include "ldpc_BG2_Zc208_byte.c"
-#include "ldpc_BG2_Zc192_byte.c"
-#include "ldpc_BG2_Zc176_byte.c"
-#include "ldpc_BG2_Zc160_byte.c"
-#include "ldpc_BG2_Zc144_byte.c"
-#include "ldpc_BG2_Zc128_byte.c"
-#include "ldpc_BG2_Zc120_byte.c"
-#include "ldpc_BG2_Zc112_byte.c"
-#include "ldpc_BG2_Zc104_byte.c"
-#include "ldpc_BG2_Zc96_byte.c"
-#include "ldpc_BG2_Zc88_byte.c"
-#include "ldpc_BG2_Zc80_byte.c"
-#include "ldpc_BG2_Zc72_byte.c"
-
-
-
-void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,short Kb)
-{
-
-  if (BG==1)
-  {
-    switch (Zc)
-    {
-    case 2: break;
-    case 3: break;
-    case 4: break;
-    case 5: break;
-    case 6: break;
-    case 7: break;
-    case 8: break;
-    case 9: break;
-    case 10: break;
-    case 11: break;
-    case 12: break;
-    case 13: break;
-    case 14: break;
-    case 15: break;
-    case 16: break;
-    case 18: break;
-    case 20: break;
-    case 22: break;
-    case 24: break;      
-    case 26: break;
-    case 28: break;
-    case 30: break;
-    case 32: break;
-    case 36: break;
-    case 40: break;
-    case 44: break;
-    case 48: break;
-    case 52: break;
-    case 56: break;
-    case 60: break;
-    case 64: break;
-    case 72: break;
-    case 80: break;   
-    case 88: break;   
-    case 96: break;
-    case 104: break;
-    case 112: break;
-    case 120: break;
-    case 128: break;
-    case 144: break;
-    case 160: break;
-    case 176: ldpc176_byte(c,d); break;
-    case 192: ldpc192_byte(c,d); break;
-    case 208: ldpc208_byte(c,d); break;
-    case 224: ldpc224_byte(c,d); break;
-    case 240: ldpc240_byte(c,d); break;
-    case 256: ldpc256_byte(c,d); break;
-    case 288: ldpc288_byte(c,d); break;
-    case 320: ldpc320_byte(c,d); break;
-    case 352: ldpc352_byte(c,d); break;
-    case 384: ldpc384_byte(c,d); break;
-    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
-    }
-  }
-  else if (BG==2) {
-    switch (Zc)
-    {
-    case 2: break;
-    case 3: break;
-    case 4: break;
-    case 5: break;
-    case 6: break;
-    case 7: break;
-    case 8: break;
-    case 9: break;
-    case 10: break;
-    case 11: break;
-    case 12: break;
-    case 13: break;
-    case 14: break;
-    case 15: break;
-    case 16: break;
-    case 18: break;
-    case 20: break;
-    case 22: break;
-    case 24: break;      
-    case 26: break;
-    case 28: break;
-    case 30: break;
-    case 32: break;
-    case 36: break;
-    case 40: break;
-    case 44: break;
-    case 48: break;
-    case 52: break;
-    case 56: break;
-    case 60: break;
-    case 64: break;
-    case 72: ldpc_BG2_Zc72_byte(c,d); break;
-    case 80: ldpc_BG2_Zc80_byte(c,d); break;   
-    case 88: ldpc_BG2_Zc88_byte(c,d); break;   
-    case 96: ldpc_BG2_Zc96_byte(c,d); break;
-    case 104: ldpc_BG2_Zc104_byte(c,d); break;
-    case 112: ldpc_BG2_Zc112_byte(c,d); break;
-    case 120: ldpc_BG2_Zc120_byte(c,d); break;
-    case 128: ldpc_BG2_Zc128_byte(c,d); break;
-    case 144: ldpc_BG2_Zc144_byte(c,d); break;
-    case 160: ldpc_BG2_Zc160_byte(c,d); break;
-    case 176: ldpc_BG2_Zc176_byte(c,d); break;
-    case 192: ldpc_BG2_Zc192_byte(c,d); break;
-    case 208: ldpc_BG2_Zc208_byte(c,d); break;
-    case 224: ldpc_BG2_Zc224_byte(c,d); break;
-    case 240: ldpc_BG2_Zc240_byte(c,d); break;
-    case 256: ldpc_BG2_Zc256_byte(c,d); break;
-    case 288: ldpc_BG2_Zc288_byte(c,d); break;
-    case 320: ldpc_BG2_Zc320_byte(c,d); break;
-    case 352: ldpc_BG2_Zc352_byte(c,d); break;
-    case 384: ldpc_BG2_Zc384_byte(c,d); break;
-    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
-    }
-  }
-  else {
-    AssertFatal(0,"BG %d is not supported yet\n",BG);
-  } 
-
-}
-
-
-int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length,short BG,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput)
-{
-
-  short nrows=0,ncols=0;
-  int i,i1,rate=3;
-  int no_punctured_columns,removed_bit;
-
-  int simd_size;
-
-  //determine number of bits in codeword
-   //if (block_length>3840)
-   if (BG==1)
-     {
-       //BG=1;
-       nrows=46; //parity check bits
-       ncols=22; //info bits
-       rate=3;
-     }
-     //else if (block_length<=3840)
-    else if	(BG==2)
-     {
-       //BG=2;
-       nrows=42; //parity check bits
-       ncols=10; // info bits
-       rate=5;
-
-       }
-
-
-#ifdef DEBUG_LDPC
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d\n",BG,Zc,Kb,block_length);
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU %x %x %x %x\n",test_input[0],test_input[1],test_input[2],test_input[3]);
-#endif
-
-  if ((Zc&31) > 0) simd_size = 16;
-  else simd_size = 32;
-
-  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
-  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
-
-  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
-
-  // calculate number of punctured bits
-  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
-  // printf("%d\n",no_punctured_columns);
-  // printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
-
-  if(tinput != NULL) start_meas(tinput);
-  for (i=0; i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-    }
-
-  if(tinput != NULL) stop_meas(tinput);
-
-  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) { 
-    // extend matrix
-    if(tprep != NULL) start_meas(tprep);
-    for (i1=0; i1 < ncols; i1++)
-      {
-	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-      }
-    for (i1=1;i1 8 bytes, pattern repeats.
-  __m256i zero256   = _mm256_setzero_si256();
-  __m256i masks[8];
-  register __m256i c256;
-  masks[0] = _mm256_set1_epi8(0x1);
-  masks[1] = _mm256_set1_epi8(0x2);
-  masks[2] = _mm256_set1_epi8(0x4);
-  masks[3] = _mm256_set1_epi8(0x8);
-  masks[4] = _mm256_set1_epi8(0x10);
-  masks[5] = _mm256_set1_epi8(0x20);
-  masks[6] = _mm256_set1_epi8(0x40);
-  masks[7] = _mm256_set1_epi8(0x80);
-#endif
-
-  AssertFatal(n_segments>0&&n_segments<=8,"0 < n_segments %d <= 8\n",n_segments);
-
-  //determine number of bits in codeword
-  //if (block_length>3840)
-  if (BG==1)
-    {
-      nrows=46; //parity check bits
-      ncols=22; //info bits
-      rate=3;
-    }
-    //else if (block_length<=3840)
-   else if	(BG==2)
-    {
-      //BG=2;
-      nrows=42; //parity check bits
-      ncols=10; // info bits
-      rate=5;
-
-      }
-
-#ifdef DEBUG_LDPC
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d, segments %d\n",BG,Zc,Kb,block_length,n_segments);
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU (seg 0) %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
-#endif
-
-  AssertFatal(Zc>0,"no valid Zc found for block length %d\n",block_length);
-
-  if ((Zc&31) > 0) simd_size = 16;
-  else          simd_size = 32;
-
-  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
-  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
-
-  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
-
-  // calculate number of punctured bits
-  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
-  // printf("%d\n",no_punctured_columns);
-  // printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
-
-  if(tinput != NULL) start_meas(tinput);
-#if 0
-  for (i=0; i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << j);
-    }
-  }
-#else
-#ifdef __AVX2__
-  for (i=0; i>5; i++) {
-    c256 = _mm256_and_si256(_mm256_cmpeq_epi8(_mm256_andnot_si256(_mm256_shuffle_epi8(_mm256_set1_epi32(((uint32_t*)test_input[0])[i]), shufmask),andmask),zero256),masks[0]);
-    for (j=1; j>5)<<5;i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << j);
-    }
-  }
-#else
-  AssertFatal(1==0,"Need AVX2 for this\n");
-#endif
-#endif
-
-  if(tinput != NULL) stop_meas(tinput);
-
-  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) { 
-    // extend matrix
-    if(tprep != NULL) start_meas(tprep);
-    for (i1=0; i1 < ncols; i1++)
-      {
-	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-      }
-    for (i1=1;i1>5;
-    uint32_t l2 = ((nrows-no_punctured_columns) * Zc-removed_bit)>>5;
-    __m256i *c256p = (__m256i *)&c[2*Zc];
-    __m256i *d256p = (__m256i *)&d[0];
-    //  if (((block_length-(2*Zc))&31)>0) l1++;
-    
-    for (i=0;i0) l2++;
-    
-    for (i1=0;i1>j)&1;
-    for (i=0;i<((nrows-no_punctured_columns) * Zc-removed_bit);i++)
-      for (j=0; j>j)&1;
-    }
-
-#else
-    AssertFatal(1==0,"Need AVX2 for now\n");
-#endif
-
-  if(toutput != NULL) stop_meas(toutput);
-  return 0;
-}
-
-int ldpc_encoder_optim_8seg_multi(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, int n_segments,unsigned int macro_num, time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput)
-{
-
-  short nrows=0,ncols=0;
-  int i,i1,j,rate=3;
-  int no_punctured_columns,removed_bit;
-  //Table of possible lifting sizes
-  char temp;
-  int simd_size;
-  unsigned int macro_segment, macro_segment_end;
-
-  
-  macro_segment = 8*macro_num;
-  // macro_segment_end = (n_segments > 8*(macro_num+1)) ? 8*(macro_num+1) : n_segments;
-  macro_segment_end = macro_segment + (n_segments > 8 ? 8 : n_segments);
-  ///printf("macro_segment: %d\n", macro_segment);
-  ///printf("macro_segment_end: %d\n", macro_segment_end );
-
-#ifdef __AVX2__
-  __m256i shufmask = _mm256_set_epi64x(0x0303030303030303, 0x0202020202020202,0x0101010101010101, 0x0000000000000000);
-  __m256i andmask  = _mm256_set1_epi64x(0x0102040810204080);  // every 8 bits -> 8 bytes, pattern repeats.
-  __m256i zero256   = _mm256_setzero_si256();
-  __m256i masks[8];
-  register __m256i c256;
-  masks[0] = _mm256_set1_epi8(0x1);
-  masks[1] = _mm256_set1_epi8(0x2);
-  masks[2] = _mm256_set1_epi8(0x4);
-  masks[3] = _mm256_set1_epi8(0x8);
-  masks[4] = _mm256_set1_epi8(0x10);
-  masks[5] = _mm256_set1_epi8(0x20);
-  masks[6] = _mm256_set1_epi8(0x40);
-  masks[7] = _mm256_set1_epi8(0x80);
-#endif
-
-
-
-  //determine number of bits in codeword
-  if (BG==1)
-    {
-      nrows=46; //parity check bits
-      ncols=22; //info bits
-      rate=3;
-    }
-    else if (BG==2)
-    {
-      nrows=42; //parity check bits
-      ncols=10; // info bits
-      rate=5;
-    }
-
-#ifdef DEBUG_LDPC
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d, segments %d\n",BG,Zc,Kb,block_length,n_segments);
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU (seg 0) %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
-#endif
-
-  AssertFatal(Zc>0,"no valid Zc found for block length %d\n",block_length);
-
-  if ((Zc&31) > 0) simd_size = 16;
-  else          simd_size = 32;
-
-  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
-  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
-
-  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
-
-  // calculate number of punctured bits
-  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
-  //printf("%d\n",no_punctured_columns);
-  //printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
-
-  if(tinput != NULL) start_meas(tinput);
-#if 0
-  for (i=0; i>(i&7);
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << (j-macro_segment));
-    }
-  }
-#else
-#ifdef __AVX2__
-  for (i=0; i>5; i++) {
-    c256 = _mm256_and_si256(_mm256_cmpeq_epi8(_mm256_andnot_si256(_mm256_shuffle_epi8(_mm256_set1_epi32(((uint32_t*)test_input[macro_segment])[i]), shufmask),andmask),zero256),masks[0]);
-    //for (j=1; j>5)<<5;i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << (j-macro_segment));
-    }
-  }
-#else
-  AssertFatal(1==0,"Need AVX2 for this\n");
-#endif
-#endif
-
-  if(tinput != NULL) stop_meas(tinput);
-
-  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) {
-    // extend matrix
-    if(tprep != NULL) start_meas(tprep);
-    for (i1=0; i1 < ncols; i1++)
-      {
-	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-      }
-    for (i1=1;i1>5;
-    uint32_t l2 = ((nrows-no_punctured_columns) * Zc-removed_bit)>>5;
-    __m256i *c256p = (__m256i *)&c[2*Zc];
-    __m256i *d256p = (__m256i *)&d[0];
-    //  if (((block_length-(2*Zc))&31)>0) l1++;
-
-    for (i=0;i0) l2++;
-
-    for (i1=0;i1>(j-macro_segment))&1;
-    for (i=0;i<((nrows-no_punctured_columns) * Zc-removed_bit);i++)
-      //for (j=0; j>(j-macro_segment))&1;
-    }
-
-#else
-    AssertFatal(1==0,"Need AVX2 for now\n");
-#endif
-
-  if(toutput != NULL) stop_meas(toutput);
-  return 0;
-}
-
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
new file mode 100644
index 0000000000..7da265494a
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*!\file ldpc_encoder2.c
+ * \brief Defines the optimized LDPC encoder
+ * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
+ * \email openair_tech@eurecom.fr
+ * \date 27-03-2018
+ * \version 1.0
+ * \note
+ * \warning
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+#include "PHY/TOOLS/time_meas.h"
+#include "openair1/PHY/CODING/nrLDPC_defs.h"
+#include "ldpc_encode_parity_check.c"
+#include "ldpc_generate_coefficient.c"
+//#define DEBUG_LDPC
+
+
+
+
+
+int nrLDPC_encod(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, encoder_implemparams_t *impp)
+{
+
+  short nrows=0,ncols=0;
+  int i,i1,rate=3;
+  int no_punctured_columns,removed_bit;
+
+  int simd_size;
+
+  //determine number of bits in codeword
+   //if (block_length>3840)
+   if (BG==1)
+     {
+       //BG=1;
+       nrows=46; //parity check bits
+       ncols=22; //info bits
+       rate=3;
+     }
+     //else if (block_length<=3840)
+    else if	(BG==2)
+     {
+       //BG=2;
+       nrows=42; //parity check bits
+       ncols=10; // info bits
+       rate=5;
+
+       }
+
+
+#ifdef DEBUG_LDPC
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d\n",BG,Zc,Kb,block_length);
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
+#endif
+
+  if ((Zc&31) > 0) simd_size = 16;
+  else simd_size = 32;
+
+  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
+  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
+
+  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
+
+  // calculate number of punctured bits
+  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
+  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
+  // printf("%d\n",no_punctured_columns);
+  // printf("%d\n",removed_bit);
+  // unpack input
+  memset(c,0,sizeof(unsigned char) * ncols * Zc);
+  memset(d,0,sizeof(unsigned char) * nrows * Zc);
+
+  if(impp->tinput != NULL) start_meas(impp->tinput);
+  for (i=0; i>(i&7)))>>(7-(i&7));
+      //printf("c(%d,%d)=%d\n",j,i,temp);
+    }
+
+  if(impp->tinput != NULL) stop_meas(impp->tinput);
+
+  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) { 
+    // extend matrix
+    if(impp->tprep != NULL) start_meas(impp->tprep);
+    for (i1=0; i1 < ncols; i1++)
+      {
+	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+      }
+    for (i1=1;i1tprep != NULL) stop_meas(impp->tprep);
+    //parity check part
+    if(impp->tparity != NULL) start_meas(impp->tparity);
+    encode_parity_check_part_optim(c_extension, d, BG, Zc, Kb);
+    if(impp->tparity != NULL) stop_meas(impp->tparity);
+  }
+  else {
+    if (encode_parity_check_part_orig(c, d, BG, Zc, Kb, block_length)!=0) {
+      printf("Problem with encoder\n");
+      return(-1);
+    }
+  }
+  if(impp->toutput != NULL) start_meas(impp->toutput);
+  // information part and puncture columns
+  memcpy(&channel_input[0][0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char));
+  memcpy(&channel_input[0][block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char));
+
+  if(impp->toutput != NULL) stop_meas(impp->toutput);
+  return 0;
+}
+
+
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
index 5988c9067d..3d26a19063 100644
--- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
@@ -35,9 +35,8 @@
 #include 
 #include "Gen_shift_value.h"
 #include "assertions.h"
-#include "defs.h"
 
-short *choose_generator_matrix(short BG,short Zc)
+static inline short *choose_generator_matrix(short BG,short Zc)
 {
   short *Gen_shift_values = NULL;
 
@@ -361,237 +360,70 @@ short *choose_generator_matrix(short BG,short Zc)
   return Gen_shift_values;
 }
 
-int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length, short BG,unsigned char gen_code)
+static inline int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length)
 {
-  unsigned char c[22*384]; //padded input, unpacked, max size
-  unsigned char d[68*384]; //coded output, unpacked, max size
+  short *Gen_shift_values=choose_generator_matrix(BG,Zc);
+  short *no_shift_values, *pointer_shift_values;
+  int no_punctured_columns;
+  short nrows,ncols,rate=3;
+  int i1,i2,i3,i4,i5,temp_prime;
   unsigned char channel_temp,temp;
-  short *Gen_shift_values, *no_shift_values, *pointer_shift_values;
 
-  short nrows = 46;//parity check bits
-  short ncols = 22;//info bits
-
-
-  int i,i1,i2,i3,i4,i5,temp_prime,var;
-  int no_punctured_columns,removed_bit,rate=3;
-  int nind=0;
-  int indlist[1000];
-  int indlist2[1000];
-
-  //determine number of bits in codeword
-  //if (block_length>3840)
-     if (BG==1)
-       {
-         nrows=46; //parity check bits
-         ncols=22; //info bits
-         rate=3;
-       }
-       //else if (block_length<=3840)
-      else if	(BG==2)
-       {
-         //BG=2;
-         nrows=42; //parity check bits
-         ncols=10; // info bits
-         rate=5;
-         }
-
-  Gen_shift_values=choose_generator_matrix(BG,Zc);
-  if (Gen_shift_values==NULL) {
-    printf("ldpc_encoder_orig: could not find generator matrix\n");
-    return(-1);
-  }
-
-  //printf("ldpc_encoder_orig: BG %d, Zc %d, Kb %d\n",BG, Zc, Kb);
-
-  // load base graph of generator matrix
   if (BG==1)
   {
     no_shift_values=(short *) no_shift_values_BG1;
     pointer_shift_values=(short *) pointer_shift_values_BG1;
+      nrows=46; //parity check bits
+      ncols=22; //info bits
+      rate=3;
   }
   else if (BG==2)
   {
     no_shift_values=(short *) no_shift_values_BG2;
     pointer_shift_values=(short *) pointer_shift_values_BG2;
+      nrows=42; //parity check bits
+      ncols=10; //info bits
+      rate=5;
   }
   else {
-    AssertFatal(0,"BG %d is not supported yet\n",BG);
+    printf("problem with BG\n");
+    return(-1);
   }
-  
+
+
   no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(block_length*rate);
-  //printf("%d\n",no_punctured_columns);
-  //printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
 
-  for (i=0; i>7&1;
-    c[i]=(test_input[i/8]&(128>>(i&7)))>>(7-(i&7));
-  }
+    //t=Kb*Zc+i2;
 
-  // parity check part
-
-  if (gen_code==1)
-  {
-    char fname[100];
-    sprintf(fname,"ldpc_BG%d_Zc%d_byte.c",BG,Zc);
-    FILE *fd=fopen(fname,"w");
-    AssertFatal(fd!=NULL,"cannot open %s\n",fname);
-    sprintf(fname,"ldpc_BG%d_Zc%d_16bit.c",BG,Zc);
-    FILE *fd2=fopen(fname,"w");
-    AssertFatal(fd2!=NULL,"cannot open %s\n",fname);
-
-    int shift;
-    char data_type[100];
-    char xor_command[100];
-    int mask;
-
-
-
-
-    fprintf(fd,"#include \"PHY/sse_intrin.h\"\n");
-    fprintf(fd2,"#include \"PHY/sse_intrin.h\"\n");
-
-    if ((Zc&31)==0) {
-      shift=5; // AVX2 - 256-bit SIMD
-      mask=31;
-      strcpy(data_type,"__m256i");
-      strcpy(xor_command,"_mm256_xor_si256");
-    }
-    else if ((Zc&15)==0) {
-      shift=4; // SSE4 - 128-bit SIMD
-      mask=15;
-      strcpy(data_type,"__m128i");
-      strcpy(xor_command,"_mm_xor_si128");
-
-    }
-    else if ((Zc&7)==0) {
-      shift=3; // MMX  - 64-bit SIMD
-      mask=7;
-      strcpy(data_type,"__m64");
-      strcpy(xor_command,"_mm_xor_si64"); 
-    }
-    else {
-      shift=0;                 // no SIMD
-      mask=0;
-      strcpy(data_type,"uint8_t");
-      strcpy(xor_command,"scalar_xor");
-      fprintf(fd,"#define scalar_xor(a,b) ((a)^(b))\n");
-      fprintf(fd2,"#define scalar_xor(a,b) ((a)^(b))\n");
-    }
-    fprintf(fd,"// generated code for Zc=%d, byte encoding\n",Zc);
-    fprintf(fd2,"// generated code for Zc=%d, 16bit encoding\n",Zc);
-    fprintf(fd,"static inline void ldpc_BG%d_Zc%d_byte(uint8_t *c,uint8_t *d) {\n",BG,Zc);
-    fprintf(fd2,"static inline void ldpc_BG%d_Zc%d_16bit(uint16_t *c,uint16_t *d) {\n",BG,Zc);
-    fprintf(fd,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
-    fprintf(fd2,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
-    fprintf(fd,"  %s *c2,*d2;\n\n",data_type);
-    fprintf(fd2,"  %s *c2,*d2;\n\n",data_type);
-    fprintf(fd,"  int i2;\n");
-    fprintf(fd2,"  int i2;\n");
-    fprintf(fd,"  for (i2=0; i2<%d; i2++) {\n",Zc>>shift);
-    if (shift > 0)
-      fprintf(fd2,"  for (i2=0; i2<%d; i2++) {\n",Zc>>(shift-1));
-    for (i2=0; i2 < 1; i2++)
+    //rotate matrix here
+    for (i5=0; i5 < Kb; i5++)
     {
-      //t=Kb*Zc+i2;
-    
-      // calculate each row in base graph
-     
-
-      fprintf(fd,"     c2=&csimd[i2];\n");
-      fprintf(fd,"     d2=&dsimd[i2];\n");
-      fprintf(fd2,"     c2=&csimd[i2];\n");
-      fprintf(fd2,"     d2=&dsimd[i2];\n");
-
-      for (i1=0; i1 < nrows; i1++)
-
-      {
-        channel_temp=0;
-        fprintf(fd,"\n//row: %d\n",i1);
-        fprintf(fd2,"\n//row: %d\n",i1);
-	fprintf(fd,"     d2[%d]=",(Zc*i1)>>shift);
-	fprintf(fd2,"     d2[%d]=",(Zc*i1)>>(shift-1));
-
-        nind=0;
-
-        for (i3=0; i3 < ncols; i3++)
-        {
-          temp_prime=i1 * ncols + i3;
-
-
-	  for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
-	    {
-	          
-	      var=(int)((i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc)/Zc);
-	      int index =var*2*Zc + (i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc) % Zc;
-	      
-	      indlist[nind] = ((index&mask)*((2*Zc)>>shift)*Kb)+(index>>shift);
-	      indlist2[nind++] = ((index&(mask>>1))*((2*Zc)>>(shift-1))*Kb)+(index>>(shift-1));
-	      
-	    }
-	  
-
-        }
-	for (i4=0;i4
- * \date 27-03-2018
- * \version 1.0
- * \note
- * \warning
- */
-
-#ifndef __NR_LDPC_DECODER__H__
-#define __NR_LDPC_DECODER__H__
-
-#include "nrLDPC_types.h"
-#include "nrLDPC_init_mem.h"
-
-/**
-   \brief LDPC decoder
-   \param p_decParams LDPC decoder parameters
-   \param p_llr Input LLRs
-   \param p_llrOut Output vector
-   \param p_profiler LDPC profiler statistics
-*/
-int32_t nrLDPC_decoder(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_llrOut, t_nrLDPC_procBuf* p_procBuf, t_nrLDPC_time_stats* p_profiler);
-
-#endif
+#ifdef LDPC_LOADER
+nrLDPC_decoderfunc_t nrLDPC_decoder;
+nrLDPC_encoderfunc_t nrLDPC_encoder;
+#else
+/* functions to load the LDPC shared lib, implemented in openair1/PHY/CODING/nrLDPC_load.c */
+extern int load_nrLDPClib(void) ;
+extern int load_nrLDPClib_ref(char *libversion, nrLDPC_encoderfunc_t * nrLDPC_encoder_ptr); // for ldpctest
+/* ldpc coder/decoder functions, as loaded by load_nrLDPClib(). */
+extern nrLDPC_decoderfunc_t nrLDPC_decoder;
+extern nrLDPC_encoderfunc_t nrLDPC_encoder;
+// inline functions:
+#include "openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h"
+#endif
\ No newline at end of file
diff --git a/openair1/PHY/CODING/nrLDPC_load.c b/openair1/PHY/CODING/nrLDPC_load.c
new file mode 100644
index 0000000000..a74bdf7bd1
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_load.c
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file openair1/PHY/CODING/coding_nr_load.c
+ * \brief: load library implementing coding/decoding algorithms
+ * \author Francois TABURET
+ * \date 2020
+ * \version 0.1
+ * \company NOKIA BellLabs France
+ * \email: francois.taburet@nokia-bell-labs.com
+ * \note
+ * \warning
+ */
+#define _GNU_SOURCE 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+#define LDPC_LOADER
+#include "PHY/CODING/nrLDPC_extern.h"
+#include "common/config/config_userapi.h" 
+#include "common/utils/load_module_shlib.h" 
+
+
+/* function description array, to be used when loading the encoding/decoding shared lib */
+static loader_shlibfunc_t shlib_fdesc[2];
+
+char *arg[64]={"ldpctest","-O","cmdlineonly::dbgl0"};
+
+int load_nrLDPClib(void) {
+	 char *ptr = (char*)config_get_if();
+     if ( ptr==NULL )  {// phy simulators, config module possibly not loaded
+     	 load_configmodule(3,(char **)arg,CONFIG_ENABLECMDLINEONLY) ;
+     	 logInit();
+     }	 
+     shlib_fdesc[0].fname = "nrLDPC_decod";
+     shlib_fdesc[1].fname = "nrLDPC_encod";
+     int ret=load_module_shlib("ldpc",shlib_fdesc,sizeof(shlib_fdesc)/sizeof(loader_shlibfunc_t),NULL);
+     AssertFatal( (ret >= 0),"Error loading ldpc decoder");
+     nrLDPC_decoder = (nrLDPC_decoderfunc_t)shlib_fdesc[0].fptr;
+     nrLDPC_encoder = (nrLDPC_encoderfunc_t)shlib_fdesc[1].fptr;
+return 0;
+}
+
+int load_nrLDPClib_ref(char *libversion, nrLDPC_encoderfunc_t * nrLDPC_encoder_ptr) {
+	loader_shlibfunc_t shlib_encoder_fdesc;
+
+     shlib_encoder_fdesc.fname = "nrLDPC_encod";
+     char libpath[64];
+     sprintf(libpath,"ldpc%s",libversion);
+     int ret=load_module_shlib(libpath,&shlib_encoder_fdesc,1,NULL);
+     AssertFatal( (ret >= 0),"Error loading ldpc encoder %s\n",libpath);
+     *nrLDPC_encoder_ptr = (nrLDPC_encoderfunc_t)shlib_encoder_fdesc.fptr;
+return 0;
+}
+
+
diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index f0ad3cbaae..4798f9a9e4 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -31,6 +31,7 @@
 #include "TDD-Config.h"
 #include "MBSFN-SubframeConfigList.h"*/
 #include "openair1/PHY/defs_RU.h"
+#include "openair1/PHY/CODING/nrLDPC_extern.h"
 #include "LAYER2/NR_MAC_gNB/mac_proto.h"
 #include "assertions.h"
 #include 
@@ -115,6 +116,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
   LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_gNB][MOD %02"PRIu8"][]\n", gNB->Mod_id);
   crcTableInit();
   init_dfts();
+  load_nrLDPClib();
   // PBCH DMRS gold sequences generation
   nr_init_pbch_dmrs(gNB);
   //PDCCH DMRS init
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index dae5586224..17de9c02af 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -35,12 +35,11 @@
 #include "PHY/CODING/coding_extern.h"
 #include "PHY/CODING/coding_defs.h"
 #include "PHY/CODING/lte_interleaver_inline.h"
-#include "PHY/CODING/nrLDPC_encoder/defs.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/NR_TRANSPORT/nr_transport.h"
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/NR_TRANSPORT/nr_dlsch.h"
 #include "SCHED_NR/sched_nr.h"
-#include "defs.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "common/utils/LOG/log.h"
 #include 
@@ -404,9 +403,11 @@ int nr_dlsch_encoding(unsigned char *a,
       //ldpc_encoder_orig((unsigned char*)dlsch->harq_processes[harq_pid]->c[r],dlsch->harq_processes[harq_pid]->d[r],*Zc,Kb,Kr,BG,0);
       //ldpc_encoder_optim((unsigned char*)dlsch->harq_processes[harq_pid]->c[r],(unsigned char*)&dlsch->harq_processes[harq_pid]->d[r][0],*Zc,Kb,Kr,BG,NULL,NULL,NULL,NULL);
     }
-
+    encoder_implemparams_t impp;
+    impp.n_segments=dlsch->harq_processes[harq_pid]->C;
     for(int j=0;j<(dlsch->harq_processes[harq_pid]->C/8+1);j++) {
-      ldpc_encoder_optim_8seg_multi(dlsch->harq_processes[harq_pid]->c,dlsch->harq_processes[harq_pid]->d,*Zc,Kb,Kr,BG,dlsch->harq_processes[harq_pid]->C,j,NULL,NULL,NULL,NULL);
+      impp.macro_num=j;
+      nrLDPC_encoder(dlsch->harq_processes[harq_pid]->c,dlsch->harq_processes[harq_pid]->d,*Zc,Kb,Kr,BG,&impp);
     }
 
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
index 3945439a45..c58941b077 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
@@ -37,8 +37,7 @@
 #include "PHY/CODING/coding_extern.h"
 #include "PHY/CODING/coding_defs.h"
 #include "PHY/CODING/lte_interleaver_inline.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/NR_TRANSPORT/nr_ulsch.h"
 #include "PHY/NR_TRANSPORT/nr_dlsch.h"
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index b3a95e313e..b81c01114d 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -41,8 +41,7 @@
 #include "SCHED_NR_UE/defs.h"
 #include "SIMULATION/TOOLS/sim.h"
 #include "executables/nr-uesoftmodem.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 //#define DEBUG_DLSCH_DECODING
 //#define ENABLE_PHY_PAYLOAD_DEBUG 1
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
index 2eb6dcd7fe..8b80b1b219 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
@@ -36,7 +36,7 @@
 #include "PHY/CODING/coding_defs.h"
 #include "PHY/CODING/coding_extern.h"
 #include "PHY/CODING/lte_interleaver_inline.h"
-#include "PHY/CODING/nrLDPC_encoder/defs.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 
@@ -353,8 +353,11 @@ opp_enabled=0;
       printf("%d \n",  harq_process->d[0][cnt]);
       }
       printf("\n");*/
+    encoder_implemparams_t impp;
+    impp.n_segments=harq_process->C;
+    impp.macro_num=0;
 
-    ldpc_encoder_optim_8seg(harq_process->c,harq_process->d,*pz,Kb,Kr,BG,harq_process->C,NULL,NULL,NULL,NULL);
+    nrLDPC_encoder(harq_process->c,harq_process->d,*pz,Kb,Kr,BG,&impp);
 
     //stop_meas(te_stats);
     //printf("end ldpc encoder -- output\n");
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index 3c0f0db8da..fc81f4d74b 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -40,7 +40,7 @@
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/impl_defs_top.h"
 #include "PHY/defs_common.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
 
 #define MAX_NUM_RU_PER_gNB MAX_NUM_RU_PER_eNB
diff --git a/targets/ARCH/COMMON/common_lib.c b/targets/ARCH/COMMON/common_lib.c
index 757ad6f75d..3066f0906f 100644
--- a/targets/ARCH/COMMON/common_lib.c
+++ b/targets/ARCH/COMMON/common_lib.c
@@ -37,6 +37,7 @@
 #include 
 
 #include "common_lib.h"
+#include "assertions.h"
 #include "common/utils/load_module_shlib.h"
 #include "common/utils/LOG/log.h"
 #include "targets/RT/USER/lte-softmodem.h"
@@ -91,38 +92,44 @@ int load_lib(openair0_device *device,
 {
   loader_shlibfunc_t shlib_fdesc[1];
   int ret=0;
-  char *libname;
+  char *deflibname=OAI_RF_LIBNAME;
   
   openair0_cfg->recplay_mode = read_recplayconfig(&(openair0_cfg->recplay_conf),&(device->recplay_state));
 
   if ( openair0_cfg->recplay_mode == RECPLAY_REPLAYMODE ) {
-  	  libname=OAI_IQPLAYER_LIBNAME;
+  	  deflibname=OAI_IQPLAYER_LIBNAME;
   	  shlib_fdesc[0].fname="device_init";
   	  set_softmodem_optmask(SOFTMODEM_RECPLAY_BIT);  // softmodem has to know we use the iqplayer to workaround randomized algorithms
   } else  if ( IS_SOFTMODEM_BASICSIM ) {
-	  libname=OAI_BASICSIM_LIBNAME;
+	  deflibname=OAI_BASICSIM_LIBNAME;
 	  shlib_fdesc[0].fname="device_init";
   } else if (IS_SOFTMODEM_RFSIM && flag == RAU_LOCAL_RADIO_HEAD) {
-	  libname=OAI_RFSIM_LIBNAME;
+	  deflibname=OAI_RFSIM_LIBNAME;
 	  shlib_fdesc[0].fname="device_init";
   } else if (flag == RAU_LOCAL_RADIO_HEAD) {
 	  if (IS_SOFTMODEM_RFSIM)
-		  libname="rfsimulator";
+		  deflibname="rfsimulator";
 	  else
-          libname=OAI_RF_LIBNAME;
+          deflibname=OAI_RF_LIBNAME;
       shlib_fdesc[0].fname="device_init";
   } else {
-	  libname=OAI_TP_LIBNAME;
+	  deflibname=OAI_TP_LIBNAME;
 	  shlib_fdesc[0].fname="transport_init";
   }
-  ret=load_module_shlib(libname,shlib_fdesc,1,NULL);
+  
+  char *devname=NULL;
+  paramdef_t device_params[]=DEVICE_PARAMS_DESC ;
+  int numparams = sizeof(device_params)/sizeof(paramdef_t);
+  int devname_pidx = config_paramidx_fromname(device_params,numparams, CONFIG_DEVICEOPT_NAME);
+  device_params[devname_pidx].defstrval=deflibname;
+  
+  config_get(device_params,numparams,DEVICE_SECTION);
+  
+  ret=load_module_shlib(devname,shlib_fdesc,1,NULL);
+  AssertFatal( (ret >= 0),
+  	           "Library %s couldn't be loaded\n",devname);
 
-  if (ret < 0) {
-    LOG_E(HW,"Library %s couldn't be loaded\n",libname);
-  } else {
-    ret=((devfunc_t)shlib_fdesc[0].fptr)(device,openair0_cfg,cfg);
-  }
-  return ret;
+  return ((devfunc_t)shlib_fdesc[0].fptr)(device,openair0_cfg,cfg);
 }
 
 
diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h
index 7e51bdc81a..ecadb68c0c 100644
--- a/targets/ARCH/COMMON/common_lib.h
+++ b/targets/ARCH/COMMON/common_lib.h
@@ -448,6 +448,24 @@ typedef struct {
 extern "C"
 {
 #endif
+
+
+#define  DEVICE_SECTION   "device"
+#define  CONFIG_HLP_DEVICE  "Identifies the oai device (the interface to RF) to use, the shared lib \"lib_.so\" will be loaded"
+
+#define  CONFIG_DEVICEOPT_NAME "name"
+
+/* inclusion for device configuration */
+/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                            config parameters for oai device                                                                                               */
+/*   optname                     helpstr                paramflags                      XXXptr                  defXXXval                            type           numelt   */
+/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+#define DEVICE_PARAMS_DESC {\
+    { CONFIG_DEVICEOPT_NAME,      CONFIG_HLP_DEVICE,          0,                strptr:&devname,                 defstrval:NULL,         TYPE_STRING,     0}\
+}
+
+
+
 /*! \brief get device name from device type */
 char *get_devname(int devtype);
 /*! \brief Initialize openair RF target. It returns 0 if OK */
diff --git a/targets/ARCH/COMMON/record_player.h b/targets/ARCH/COMMON/record_player.h
index 903dda006b..500acdd709 100644
--- a/targets/ARCH/COMMON/record_player.h
+++ b/targets/ARCH/COMMON/record_player.h
@@ -37,19 +37,6 @@
 extern "C"
 {
 #endif
-#define CONFIG_OPT_RECPLAY "enable_recplay"
-
-#define  CONFIG_HLP_RECPLAY  "Allow record player"
-#define USRP_SECTION "device.usrp"
-/* inclusion for device configuration */
-/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-/*                                            command line parameters for USRP record/playback                                                                               */
-/*   optname                     helpstr                paramflags                      XXXptr                  defXXXval                            type           numelt   */
-/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-#define DEVICE_PARAMS_DESC {  \
-    {CONFIG_OPT_RECPLAY,      CONFIG_HLP_RECPLAY, PARAMFLAG_BOOL,   uptr:&enable_recplay,                 defuintval:0,                    TYPE_UINT,     0} \
-  }
-
 
 /* inclusions for record player */
 #define RECPLAY_DISABLED     0
@@ -114,7 +101,7 @@ typedef struct {
     {CONFIG_OPT_SF_LOOPS,     CONFIG_HLP_SF_LOOPS,  0,                uptr:&((*recplay_conf)->u_sf_loops),                defintval:DEF_SF_NB_LOOP,        TYPE_UINT,   0}, \
     {CONFIG_OPT_SF_RDELAY,    CONFIG_HLP_SF_RDELAY, 0,                uptr:&((*recplay_conf)->u_sf_read_delay),           defintval:DEF_SF_DELAY_READ,     TYPE_UINT,   0}, \
     {CONFIG_OPT_SF_WDELAY,    CONFIG_HLP_SF_WDELAY, 0,                uptr:&((*recplay_conf)->u_sf_write_delay),          defintval:DEF_SF_DELAY_WRITE,    TYPE_UINT,   0}, \
-  }/*! \brief USRP Configuration and state */
+  }/*! \brief Record Player Configuration and state */
 typedef struct {
   char            u_sf_filename[1024];              // subframes file path
   unsigned int    u_sf_max ;                  // max number of recorded subframes
diff --git a/targets/ARCH/iqplayer/iqplayer_lib.c b/targets/ARCH/iqplayer/iqplayer_lib.c
index beb05de3fd..c4133d1b11 100644
--- a/targets/ARCH/iqplayer/iqplayer_lib.c
+++ b/targets/ARCH/iqplayer/iqplayer_lib.c
@@ -25,6 +25,7 @@
  */
 #define _LARGEFILE_SOURCE
 #define _FILE_OFFSET_BITS 64
+#define NB_ANTENNAS_RX  2
 #include 
 #include 
 #include 
@@ -45,7 +46,9 @@
 
 
 static void parse_iqfile_header(openair0_device *device, iqfile_header_t *iq_fh) {
-  AssertFatal((memcmp(iq_fh->oaiid,OAIIQFILE_ID,sizeof(OAIIQFILE_ID)) == 0),"iqfile doesn't seem to be compatible with oai (invalid id in header)\n");
+  AssertFatal((memcmp(iq_fh->oaiid,OAIIQFILE_ID,sizeof(OAIIQFILE_ID)) == 0),
+  	           "iqfile doesn't seem to be compatible with oai (invalid id %.4s in header)\n",
+  	           iq_fh->oaiid);
   device->type = iq_fh->devtype;
   device->openair0_cfg[0].tx_sample_advance=iq_fh->tx_sample_advance;
   device->openair0_cfg[0].tx_bw =  device->openair0_cfg[0].rx_bw = iq_fh->bw;
@@ -138,6 +141,13 @@ static int iqplayer_loadfile(openair0_device *device, openair0_config_t *openair
   return 0;
 }
 
+/*! \brief start the oai iq player
+ * \param device, the hardware used
+ */
+static int trx_iqplayer_start(openair0_device *device){
+	return 0;
+}
+
 /*! \brief Terminate operation of the oai iq player
  * \param device, the hardware used
  */
@@ -287,7 +297,7 @@ static int trx_iqplayer_read(openair0_device *device, openair0_timestamp *ptimes
 
 int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
   device->openair0_cfg = openair0_cfg;
-  device->trx_start_func = NULL;
+  device->trx_start_func = trx_iqplayer_start;
   device->trx_get_stats_func = NULL;
   device->trx_reset_stats_func = NULL;
   device->trx_end_func   = trx_iqplayer_end;
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index f88d98536d..6d1a3b8cb2 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -2194,7 +2194,9 @@ int start_rf(RU_t *ru) {
 }
 
 int stop_rf(RU_t *ru) {
-  ru->rfdevice.trx_end_func(&ru->rfdevice);
+    if(ru->rfdevice.trx_end_func != NULL) {
+      ru->rfdevice.trx_end_func(&ru->rfdevice);
+    }
   return 0;
 }
 

From 3b3d2322141959cdaf5e97296b590cef7ff6ab9e Mon Sep 17 00:00:00 2001
From: frtabu 
Date: Wed, 11 Mar 2020 17:32:13 +0100
Subject: [PATCH 50/73] move ldpc coder/decoder into a shared lib dymically
 loaded. Also fix a record player bug

---
 cmake_targets/CMakeLists.txt                  |  39 +-
 common/config/config_userapi.c                |   3 +-
 common/utils/telnetsrv/telnetsrv.c            |  20 +-
 openair1/PHY/CODING/TESTBENCH/ldpctest.c      |  22 +-
 .../CODING/nrLDPC_decoder/nrLDPC_decoder.c    |   4 +-
 .../PHY/CODING/nrLDPC_decoder/nrLDPC_init.h   |   2 +-
 .../CODING/nrLDPC_decoder/nrLDPC_init_mem.h   |   1 -
 .../PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h  |   2 +-
 .../PHY/CODING/nrLDPC_decoder/nrLDPC_types.h  |   5 +-
 .../{nrLDPC_defs.h => nrLDPCdecoder_defs.h}   |   2 +-
 openair1/PHY/CODING/nrLDPC_defs.h             |  59 ++
 openair1/PHY/CODING/nrLDPC_encoder/defs.h     |  54 --
 .../nrLDPC_encoder/ldpc_encode_parity_check.c | 201 ++++++
 .../PHY/CODING/nrLDPC_encoder/ldpc_encoder.c  | 252 +++++--
 .../PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c | 667 ------------------
 .../nrLDPC_encoder/ldpc_encoder_optim.c       | 146 ++++
 .../nrLDPC_encoder/ldpc_encoder_optim8seg.c   | 225 ++++++
 .../ldpc_encoder_optim8segmulti.c             | 238 +++++++
 .../ldpc_generate_coefficient.c               | 244 +------
 .../nrLDPC_decoder.h => nrLDPC_extern.h}      |  39 +-
 openair1/PHY/CODING/nrLDPC_load.c             |  76 ++
 openair1/PHY/INIT/nr_init.c                   |   2 +
 openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c   |   9 +-
 openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c |   3 +-
 .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c   |   3 +-
 .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c     |   7 +-
 openair1/PHY/defs_gNB.h                       |   2 +-
 targets/ARCH/COMMON/common_lib.c              |  35 +-
 targets/ARCH/COMMON/common_lib.h              |  18 +
 targets/ARCH/COMMON/record_player.h           |  15 +-
 targets/ARCH/iqplayer/iqplayer_lib.c          |  14 +-
 targets/RT/USER/lte-ru.c                      |   4 +-
 32 files changed, 1351 insertions(+), 1062 deletions(-)
 rename openair1/PHY/CODING/nrLDPC_decoder/{nrLDPC_defs.h => nrLDPCdecoder_defs.h} (99%)
 create mode 100644 openair1/PHY/CODING/nrLDPC_defs.h
 delete mode 100644 openair1/PHY/CODING/nrLDPC_encoder/defs.h
 create mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c
 delete mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
 create mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
 create mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8seg.c
 create mode 100644 openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
 rename openair1/PHY/CODING/{nrLDPC_decoder/nrLDPC_decoder.h => nrLDPC_extern.h} (60%)
 create mode 100644 openair1/PHY/CODING/nrLDPC_load.c

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index c4d3d7e62e..496417936a 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -1298,14 +1298,35 @@ set(PHY_SMALLBLOCKSRC
 set(PHY_TURBOIF
   ${OPENAIR1_DIR}/PHY/CODING/coding_load.c
 )
-set(PHY_LDPCSRC
+
+set(PHY_LDPC_ORIG_SRC
   ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
   ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
-  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
 )
 
+set(PHY_LDPC_OPTIM_SRC
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
+)
+set(PHY_LDPC_OPTIM8SEG_SRC
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8seg.c
+)
+set(PHY_LDPC_OPTIM8SEGMULTI_SRC
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.c
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
+)
+set(PHY_NR_CODINGIF
+  ${OPENAIR1_DIR}/PHY/CODING/nrLDPC_load.c;
+)
+
+add_library(ldpc_orig MODULE ${PHY_LDPC_ORIG_SRC} )
+add_library(ldpc_optim MODULE ${PHY_LDPC_OPTIM_SRC} )
+add_library(ldpc_optim8seg MODULE ${PHY_LDPC_OPTIM8SEG_SRC} )
+add_library(ldpc MODULE ${PHY_LDPC_OPTIM8SEGMULTI_SRC} )
+
 add_library(coding MODULE ${PHY_TURBOSRC} )
+
 set(PHY_SRC_COMMON
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/dci_tools_common.c
   ${OPENAIR1_DIR}/PHY/LTE_TRANSPORT/lte_mcs.c
@@ -1484,10 +1505,9 @@ set(PHY_SRC_UE
   ${OPENAIR1_DIR}/PHY/TOOLS/lut.c
   ${PHY_POLARSRC}
   ${PHY_SMALLBLOCKSRC}
-  ${PHY_LDPCSRC}
+  ${PHY_NR_CODINGIF}
   ${OPENAIR1_DIR}/PHY/NR_TRANSPORT/pucch_rx.c 
   )
-
   set(PHY_NR_UE_SRC
   ${OPENAIR1_DIR}/PHY/INIT/nr_parms.c
   ${OPENAIR1_DIR}/PHY/MODULATION/nr_modulation.c
@@ -1535,7 +1555,7 @@ set(PHY_SRC_UE
   #  ${OPENAIR1_DIR}/SIMULATION/NR_UE_PHY/unit_tests/src/pucch_uci_test.c
   ${PHY_POLARSRC}
   ${PHY_SMALLBLOCKSRC}
-  ${PHY_LDPCSRC}
+  ${PHY_NR_CODINGIF}
   )
 
 
@@ -2588,7 +2608,7 @@ target_link_libraries (nr-softmodem pthread m ${CONFIG_LIB} rt crypt ${CRYPTO_LI
 target_link_libraries (nr-softmodem ${LIB_LMS_LIBRARIES})
 target_link_libraries (nr-softmodem ${T_LIB})
 
-
+add_dependencies( nr-softmodem ldpc_orig ldpc_optim ldpc_optim8seg ldpc )
 # nr-uesoftmodem is  UE implementation
 #######################################
 
@@ -2629,7 +2649,7 @@ target_link_libraries (nr-uesoftmodem pthread m ${CONFIG_LIB} rt crypt ${CRYPTO_
 target_link_libraries (nr-uesoftmodem ${LIB_LMS_LIBRARIES})
 target_link_libraries (nr-uesoftmodem ${T_LIB})
 
-
+add_dependencies( nr-uesoftmodem ldpc_orig ldpc_optim ldpc_optim8seg ldpc )
 
 # USIM process
 #################
@@ -2696,10 +2716,13 @@ target_link_libraries(smallblocktest
   )
 
 add_executable(ldpctest  
+  ${PHY_NR_CODINGIF}
   ${OPENAIR1_DIR}/PHY/CODING/TESTBENCH/ldpctest.c
   ${T_SOURCE}
   ${SHLIB_LOADER_SOURCES}
   )
+add_dependencies( ldpctest ldpc_orig ldpc_optim ldpc_optim8seg ldpc ) 
+
 target_link_libraries(ldpctest
   -Wl,--start-group UTIL SIMU PHY_NR CONFIG_LIB -Wl,--end-group
   m pthread ${ATLAS_LIBRARIES} dl
diff --git a/common/config/config_userapi.c b/common/config/config_userapi.c
index 67fdc2c920..c951905101 100644
--- a/common/config/config_userapi.c
+++ b/common/config/config_userapi.c
@@ -45,7 +45,8 @@
 
 configmodule_interface_t *config_get_if(void) {
   if (cfgptr == NULL) {
-    CONFIG_PRINTF_ERROR("[CONFIG] %s %d config module not initialized\n",__FILE__,__LINE__);
+  	if (isLogInitDone())
+       LOG_W(ENB_APP,"[CONFIG] %s %d config module not initialized\n",__FILE__,__LINE__);
   }
 
   return cfgptr;
diff --git a/common/utils/telnetsrv/telnetsrv.c b/common/utils/telnetsrv/telnetsrv.c
index 10163b22b5..06a5d350c7 100644
--- a/common/utils/telnetsrv/telnetsrv.c
+++ b/common/utils/telnetsrv/telnetsrv.c
@@ -377,6 +377,14 @@ int setgetvar(int moduleindex,char getorset,char *params) {
             client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
             break;
 
+          case TELNET_VARTYPE_INT8:
+            client_printf("%i\n",(int)(*(int8_t *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr)));
+            break;
+            
+          case TELNET_VARTYPE_UINT:
+            client_printf("%u\n",*(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+            
           case TELNET_VARTYPE_DOUBLE:
             client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
             break;
@@ -405,7 +413,17 @@ int setgetvar(int moduleindex,char getorset,char *params) {
             *(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (short)strtol(varval,NULL,0);
             client_printf("%hi\n",*(short *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
             break;
-
+            
+          case TELNET_VARTYPE_INT8:
+            *(char *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (char)strtol(varval,NULL,0);
+            client_printf("%i\n",*(int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+            
+          case TELNET_VARTYPE_UINT:
+            *(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = (unsigned int)strtol(varval,NULL,0);
+            client_printf("%u\n",*(unsigned int *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
+            break;
+ 
           case TELNET_VARTYPE_DOUBLE:
             *(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr) = strtod(varval,NULL);
             client_printf("%g\n",*(double *)(telnetparams.CmdParsers[moduleindex].var[i].varvalptr));
diff --git a/openair1/PHY/CODING/TESTBENCH/ldpctest.c b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
index 95ee3fed17..552af99c41 100644
--- a/openair1/PHY/CODING/TESTBENCH/ldpctest.c
+++ b/openair1/PHY/CODING/TESTBENCH/ldpctest.c
@@ -25,8 +25,7 @@
 #include 
 #include "assertions.h"
 #include "SIMULATION/TOOLS/sim.h"
-#include "PHY/CODING/nrLDPC_encoder/defs.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "openair1/SIMULATION/NR_PHY/nr_unitary_defs.h"
 
 #define MAX_NUM_DLSCH_SEGMENTS 16
@@ -85,6 +84,7 @@ typedef struct {
 RAN_CONTEXT_t RC;
 PHY_VARS_UE ***PHY_vars_UE_g;
 uint16_t NB_UE_INST = 1;
+nrLDPC_encoderfunc_t encoder_orig;
 
 short lift_size[51]= {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,20,22,24,26,28,30,32,36,40,44,48,52,56,60,64,72,80,88,96,104,112,120,128,144,160,176,192,208,224,240,256,288,320,352,384};
 
@@ -286,16 +286,19 @@ int test_ldpc(short No_iteration,
   no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*(1/((float)nom_rate/(float)denom_rate)))/Zc;
   //  printf("puncture:%d\n",no_punctured_columns);
   removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length/((float)nom_rate/(float)denom_rate));
+  encoder_implemparams_t impp=INIT0_LDPCIMPLEMPARAMS;
+ 
+  impp.gen_code=1;
   if (ntrials==0)
-    ldpc_encoder_orig(test_input[0],channel_input[0], Zc, BG, block_length, BG, 1);
-
+    encoder_orig(test_input,channel_input, Zc, BG, block_length, BG, &impp);
+  impp.gen_code=0;
   for (trial=0; trial < ntrials; trial++)
   {
 	segment_bler = 0;
     //// encoder
     start_meas(&time);
     for(j=0;j
 #include 
-#include "nrLDPC_defs.h"
+#include "nrLDPCdecoder_defs.h"
 #include "nrLDPC_types.h"
 #include "nrLDPC_init.h"
 #include "nrLDPC_mPass.h"
@@ -47,7 +47,7 @@
 
 static inline uint32_t nrLDPC_decoder_core(int8_t* p_llr, int8_t* p_out, t_nrLDPC_procBuf* p_procBuf, uint32_t numLLR, t_nrLDPC_lut* p_lut, t_nrLDPC_dec_params* p_decParams, t_nrLDPC_time_stats* p_profiler);
 
-int32_t nrLDPC_decoder(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_out, t_nrLDPC_procBuf* p_procBuf, t_nrLDPC_time_stats* p_profiler)
+int32_t nrLDPC_decod(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_out, t_nrLDPC_procBuf* p_procBuf, t_nrLDPC_time_stats* p_profiler)
 {
     uint32_t numLLR;
     uint32_t numIter = 0;
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h
index 82462c6d95..ea031dc2da 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init.h
@@ -32,7 +32,7 @@
 #define __NR_LDPC_INIT__H__
 
 #include "nrLDPC_lut.h"
-#include "nrLDPC_defs.h"
+#include "nrLDPCdecoder_defs.h"
 
 /**
    \brief Initializes the decoder and sets correct LUTs
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h
index bdaa118e1f..3292c0debe 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h
@@ -32,7 +32,6 @@
 #define __NR_LDPC_INIT_MEM__H__
 
 #include 
-#include "nrLDPC_defs.h"
 #include "nrLDPC_types.h"
 
 #ifndef malloc32_clear
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h
index 66715618d0..7d0f5f077a 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_mPass.h
@@ -32,7 +32,7 @@
 #define __NR_LDPC_MPASS__H__
 
 #include 
-#include "nrLDPC_defs.h"
+#include "nrLDPCdecoder_defs.h"
 
 /**
    \brief Circular memcpy
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h
index 34322a7780..e5b99246d5 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h
@@ -32,8 +32,7 @@
 #define __NR_LDPC_TYPES__H__
 
 #include "PHY/TOOLS/time_meas.h"
-#include "nrLDPC_defs.h"
-
+#include "nrLDPCdecoder_defs.h"
 // ==============================================================================
 // TYPES
 
@@ -103,4 +102,6 @@ typedef struct nrLDPC_procBuf {
     int8_t* llrProcBuf; /**< LLR processing buffer */
 } t_nrLDPC_procBuf;
 
+
+
 #endif
diff --git a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_defs.h b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPCdecoder_defs.h
similarity index 99%
rename from openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_defs.h
rename to openair1/PHY/CODING/nrLDPC_decoder/nrLDPCdecoder_defs.h
index 940d842550..69fc88752f 100644
--- a/openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_defs.h
+++ b/openair1/PHY/CODING/nrLDPC_decoder/nrLDPCdecoder_defs.h
@@ -19,7 +19,7 @@
  *      contact@openairinterface.org
  */
 
-/*!\file nrLDPC_defs.h
+/*!\file nrLDPCdecoder_defs.h
  * \brief Defines all constants and buffers for the LDPC decoder
  * \author Sebastian Wagner (TCL Communications) Email: 
  * \date 27-03-2018
diff --git a/openair1/PHY/CODING/nrLDPC_defs.h b/openair1/PHY/CODING/nrLDPC_defs.h
new file mode 100644
index 0000000000..b96067f4b6
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_defs.h
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+//============================================================================================================================
+// encoder interface
+#ifndef __NRLDPC_DEFS__H__
+#define __NRLDPC_DEFS__H__
+#include "openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
+/**
+   \brief LDPC encoder
+   \param 1 input
+   \param 2 channel_input
+   \param 3 int Zc
+   \param 4 int Kb
+   \param 5 short block_length
+   \param 6 short BG
+   \param 7 int n_segment
+   \param 8 unsigned int macro_num
+   \param 9-12 time_stats_t *tinput,*tprep, *tparity,*toutput
+*/
+typedef struct {
+	int n_segments;          // optim8seg
+	unsigned int macro_num; // optim8segmulti
+	unsigned char gen_code; //orig
+	time_stats_t *tinput;
+	time_stats_t *tprep;
+	time_stats_t *tparity;
+	time_stats_t *toutput;
+}encoder_implemparams_t;
+#define INIT0_LDPCIMPLEMPARAMS {0,0,0,NULL,NULL,NULL,NULL}
+typedef int(*nrLDPC_encoderfunc_t)(unsigned char **,unsigned char **,int,int,short, short, encoder_implemparams_t*);
+//============================================================================================================================
+// decoder interface
+/**
+   \brief LDPC decoder API type definition
+   \param p_decParams LDPC decoder parameters
+   \param p_llr Input LLRs
+   \param p_llrOut Output vector
+   \param p_profiler LDPC profiler statistics
+*/
+typedef int32_t(*nrLDPC_decoderfunc_t)(t_nrLDPC_dec_params* , int8_t*, int8_t* , t_nrLDPC_procBuf* , t_nrLDPC_time_stats* );
+#endif
\ No newline at end of file
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/defs.h b/openair1/PHY/CODING/nrLDPC_encoder/defs.h
deleted file mode 100644
index 85cb852fe5..0000000000
--- a/openair1/PHY/CODING/nrLDPC_encoder/defs.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*!\file defs.h
- * \brief LDPC encoder forward declarations
- * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
- * \email openair_tech@eurecom.fr
- * \date 27-03-2018
- * \version 1.0
- * \note
- * \warning
- */
-
-#include "PHY/TOOLS/time_meas.h"
-
-/*ldpc_encoder.c*/
-int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length);
-
-/*ldpc_encoder2.c*/
-void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,short Kb);
-int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length,short BG,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length,short BG,int n_segments,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-int ldpc_encoder_optim_8seg_multi(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, int n_segments,unsigned int macro_num, time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-
-/*ldpc_generate_coefficient.c*/
-int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length,short BG,unsigned char gen_code);
-
-/*
-int encode_parity_check_part(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb);
-int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length);
-int ldpc_encoder(unsigned char *test_input,unsigned char *channel_input,short block_length, double rate);
-int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,short block_length,int nom_rate,int denom_rate,unsigned char gen_code);
-int ldpc_encoder_multi_segment(unsigned char **test_input,unsigned char **channel_input,short block_length,double rate,uint8_t n_segments);
-int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,short block_length,int nom_rate,int denom_rate,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-int ldpc_encoder_optim_8seg(unsigned char **test_input,unsigned char **channel_input,short block_length,int nom_rate,int denom_rate,int n_segments,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput);
-*/
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c
new file mode 100644
index 0000000000..738fd49b7d
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encode_parity_check.c
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*!\file ldpc_encode_parity_check.c
+ * \brief Parity check function used by ldpc encoders
+ * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
+ * \email openair_tech@eurecom.fr
+ * \date 27-03-2018
+ * \version 1.0
+ * \note
+ * \warning
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+
+
+//#define DEBUG_LDPC
+
+#include "ldpc384_byte.c"
+#include "ldpc352_byte.c"
+#include "ldpc320_byte.c"
+#include "ldpc288_byte.c"
+#include "ldpc256_byte.c"
+#include "ldpc240_byte.c"
+#include "ldpc224_byte.c"
+#include "ldpc208_byte.c"
+#include "ldpc192_byte.c"
+#include "ldpc176_byte.c"
+#include "ldpc_BG2_Zc384_byte.c"
+#include "ldpc_BG2_Zc352_byte.c"
+#include "ldpc_BG2_Zc320_byte.c"
+#include "ldpc_BG2_Zc288_byte.c"
+#include "ldpc_BG2_Zc256_byte.c"
+#include "ldpc_BG2_Zc240_byte.c"
+#include "ldpc_BG2_Zc224_byte.c"
+#include "ldpc_BG2_Zc208_byte.c"
+#include "ldpc_BG2_Zc192_byte.c"
+#include "ldpc_BG2_Zc176_byte.c"
+#include "ldpc_BG2_Zc160_byte.c"
+#include "ldpc_BG2_Zc144_byte.c"
+#include "ldpc_BG2_Zc128_byte.c"
+#include "ldpc_BG2_Zc120_byte.c"
+#include "ldpc_BG2_Zc112_byte.c"
+#include "ldpc_BG2_Zc104_byte.c"
+#include "ldpc_BG2_Zc96_byte.c"
+#include "ldpc_BG2_Zc88_byte.c"
+#include "ldpc_BG2_Zc80_byte.c"
+#include "ldpc_BG2_Zc72_byte.c"
+
+
+
+static inline void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,short Kb)
+{
+
+  if (BG==1)
+  {
+    switch (Zc)
+    {
+    case 2: break;
+    case 3: break;
+    case 4: break;
+    case 5: break;
+    case 6: break;
+    case 7: break;
+    case 8: break;
+    case 9: break;
+    case 10: break;
+    case 11: break;
+    case 12: break;
+    case 13: break;
+    case 14: break;
+    case 15: break;
+    case 16: break;
+    case 18: break;
+    case 20: break;
+    case 22: break;
+    case 24: break;      
+    case 26: break;
+    case 28: break;
+    case 30: break;
+    case 32: break;
+    case 36: break;
+    case 40: break;
+    case 44: break;
+    case 48: break;
+    case 52: break;
+    case 56: break;
+    case 60: break;
+    case 64: break;
+    case 72: break;
+    case 80: break;   
+    case 88: break;   
+    case 96: break;
+    case 104: break;
+    case 112: break;
+    case 120: break;
+    case 128: break;
+    case 144: break;
+    case 160: break;
+    case 176: ldpc176_byte(c,d); break;
+    case 192: ldpc192_byte(c,d); break;
+    case 208: ldpc208_byte(c,d); break;
+    case 224: ldpc224_byte(c,d); break;
+    case 240: ldpc240_byte(c,d); break;
+    case 256: ldpc256_byte(c,d); break;
+    case 288: ldpc288_byte(c,d); break;
+    case 320: ldpc320_byte(c,d); break;
+    case 352: ldpc352_byte(c,d); break;
+    case 384: ldpc384_byte(c,d); break;
+    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
+    }
+  }
+  else if (BG==2) {
+    switch (Zc)
+    {
+    case 2: break;
+    case 3: break;
+    case 4: break;
+    case 5: break;
+    case 6: break;
+    case 7: break;
+    case 8: break;
+    case 9: break;
+    case 10: break;
+    case 11: break;
+    case 12: break;
+    case 13: break;
+    case 14: break;
+    case 15: break;
+    case 16: break;
+    case 18: break;
+    case 20: break;
+    case 22: break;
+    case 24: break;      
+    case 26: break;
+    case 28: break;
+    case 30: break;
+    case 32: break;
+    case 36: break;
+    case 40: break;
+    case 44: break;
+    case 48: break;
+    case 52: break;
+    case 56: break;
+    case 60: break;
+    case 64: break;
+    case 72: ldpc_BG2_Zc72_byte(c,d); break;
+    case 80: ldpc_BG2_Zc80_byte(c,d); break;   
+    case 88: ldpc_BG2_Zc88_byte(c,d); break;   
+    case 96: ldpc_BG2_Zc96_byte(c,d); break;
+    case 104: ldpc_BG2_Zc104_byte(c,d); break;
+    case 112: ldpc_BG2_Zc112_byte(c,d); break;
+    case 120: ldpc_BG2_Zc120_byte(c,d); break;
+    case 128: ldpc_BG2_Zc128_byte(c,d); break;
+    case 144: ldpc_BG2_Zc144_byte(c,d); break;
+    case 160: ldpc_BG2_Zc160_byte(c,d); break;
+    case 176: ldpc_BG2_Zc176_byte(c,d); break;
+    case 192: ldpc_BG2_Zc192_byte(c,d); break;
+    case 208: ldpc_BG2_Zc208_byte(c,d); break;
+    case 224: ldpc_BG2_Zc224_byte(c,d); break;
+    case 240: ldpc_BG2_Zc240_byte(c,d); break;
+    case 256: ldpc_BG2_Zc256_byte(c,d); break;
+    case 288: ldpc_BG2_Zc288_byte(c,d); break;
+    case 320: ldpc_BG2_Zc320_byte(c,d); break;
+    case 352: ldpc_BG2_Zc352_byte(c,d); break;
+    case 384: ldpc_BG2_Zc384_byte(c,d); break;
+    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
+    }
+  }
+  else {
+    AssertFatal(0,"BG %d is not supported yet\n",BG);
+  } 
+
+}
+
+
+
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
index 6ded22d8ca..76f92574ba 100644
--- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder.c
@@ -37,77 +37,247 @@
 #include 
 #include 
 #include "defs.h"
+#include "assertions.h"
+#include "openair1/PHY/CODING/nrLDPC_defs.h"
+#include "ldpc_generate_coefficient.c"
 
-short *choose_generator_matrix(short BG,short Zc);
-extern short no_shift_values_BG1[1012],pointer_shift_values_BG1[1012],no_shift_values_BG2[2109],pointer_shift_values_BG2[2019];
 
-int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length)
+int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length, short BG,unsigned char gen_code)
 {
-  short *Gen_shift_values=choose_generator_matrix(BG,Zc);
-  short *no_shift_values, *pointer_shift_values;
-  int no_punctured_columns;
-  short nrows,ncols,rate=3;
-  int i1,i2,i3,i4,i5,temp_prime;
+  unsigned char c[22*384]; //padded input, unpacked, max size
+  unsigned char d[68*384]; //coded output, unpacked, max size
   unsigned char channel_temp,temp;
+  short *Gen_shift_values, *no_shift_values, *pointer_shift_values;
 
+  short nrows = 46;//parity check bits
+  short ncols = 22;//info bits
+
+
+  int i,i1,i2,i3,i4,i5,temp_prime,var;
+  int no_punctured_columns,removed_bit,rate=3;
+  int nind=0;
+  int indlist[1000];
+  int indlist2[1000];
+
+  //determine number of bits in codeword
+  //if (block_length>3840)
+     if (BG==1)
+       {
+         nrows=46; //parity check bits
+         ncols=22; //info bits
+         rate=3;
+       }
+       //else if (block_length<=3840)
+      else if	(BG==2)
+       {
+         //BG=2;
+         nrows=42; //parity check bits
+         ncols=10; // info bits
+         rate=5;
+         }
+
+  Gen_shift_values=choose_generator_matrix(BG,Zc);
+  if (Gen_shift_values==NULL) {
+    printf("ldpc_encoder_orig: could not find generator matrix\n");
+    return(-1);
+  }
+
+  //printf("ldpc_encoder_orig: BG %d, Zc %d, Kb %d\n",BG, Zc, Kb);
+
+  // load base graph of generator matrix
   if (BG==1)
   {
     no_shift_values=(short *) no_shift_values_BG1;
     pointer_shift_values=(short *) pointer_shift_values_BG1;
-      nrows=46; //parity check bits
-      ncols=22; //info bits
-      rate=3;
   }
   else if (BG==2)
   {
     no_shift_values=(short *) no_shift_values_BG2;
     pointer_shift_values=(short *) pointer_shift_values_BG2;
-      nrows=42; //parity check bits
-      ncols=10; //info bits
-      rate=5;
   }
   else {
-    printf("problem with BG\n");
-    return(-1);
+    AssertFatal(0,"BG %d is not supported yet\n",BG);
   }
-
-
+  
   no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
+  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(block_length*rate);
+  //printf("%d\n",no_punctured_columns);
+  //printf("%d\n",removed_bit);
+  // unpack input
+  memset(c,0,sizeof(unsigned char) * ncols * Zc);
+  memset(d,0,sizeof(unsigned char) * nrows * Zc);
 
-  //printf("no_punctured_columns = %d\n",no_punctured_columns);
-
-  for (i2=0; i2 < Zc; i2++)
+  for (i=0; i>7&1;
+    c[i]=(test_input[i/8]&(128>>(i&7)))>>(7-(i&7));
+  }
 
-    //rotate matrix here
-    for (i5=0; i5 < Kb; i5++)
-    {
-      temp = c[i5*Zc];
-      memmove(&c[i5*Zc], &c[i5*Zc+1], (Zc-1)*sizeof(unsigned char));
-      c[i5*Zc+Zc-1] = temp;
+  // parity check part
+
+  if (gen_code==1)
+  {
+    char fname[100];
+    sprintf(fname,"ldpc_BG%d_Zc%d_byte.c",BG,Zc);
+    FILE *fd=fopen(fname,"w");
+    AssertFatal(fd!=NULL,"cannot open %s\n",fname);
+    sprintf(fname,"ldpc_BG%d_Zc%d_16bit.c",BG,Zc);
+    FILE *fd2=fopen(fname,"w");
+    AssertFatal(fd2!=NULL,"cannot open %s\n",fname);
+
+    int shift;
+    char data_type[100];
+    char xor_command[100];
+    int mask;
+
+
+
+
+    fprintf(fd,"#include \"PHY/sse_intrin.h\"\n");
+    fprintf(fd2,"#include \"PHY/sse_intrin.h\"\n");
+
+    if ((Zc&31)==0) {
+      shift=5; // AVX2 - 256-bit SIMD
+      mask=31;
+      strcpy(data_type,"__m256i");
+      strcpy(xor_command,"_mm256_xor_si256");
     }
+    else if ((Zc&15)==0) {
+      shift=4; // SSE4 - 128-bit SIMD
+      mask=15;
+      strcpy(data_type,"__m128i");
+      strcpy(xor_command,"_mm_xor_si128");
 
-    // calculate each row in base graph
-    for (i1=0; i1 < nrows-no_punctured_columns; i1++)
+    }
+    else if ((Zc&7)==0) {
+      shift=3; // MMX  - 64-bit SIMD
+      mask=7;
+      strcpy(data_type,"__m64");
+      strcpy(xor_command,"_mm_xor_si64"); 
+    }
+    else {
+      shift=0;                 // no SIMD
+      mask=0;
+      strcpy(data_type,"uint8_t");
+      strcpy(xor_command,"scalar_xor");
+      fprintf(fd,"#define scalar_xor(a,b) ((a)^(b))\n");
+      fprintf(fd2,"#define scalar_xor(a,b) ((a)^(b))\n");
+    }
+    fprintf(fd,"// generated code for Zc=%d, byte encoding\n",Zc);
+    fprintf(fd2,"// generated code for Zc=%d, 16bit encoding\n",Zc);
+    fprintf(fd,"static inline void ldpc_BG%d_Zc%d_byte(uint8_t *c,uint8_t *d) {\n",BG,Zc);
+    fprintf(fd2,"static inline void ldpc_BG%d_Zc%d_16bit(uint16_t *c,uint16_t *d) {\n",BG,Zc);
+    fprintf(fd,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
+    fprintf(fd2,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
+    fprintf(fd,"  %s *c2,*d2;\n\n",data_type);
+    fprintf(fd2,"  %s *c2,*d2;\n\n",data_type);
+    fprintf(fd,"  int i2;\n");
+    fprintf(fd2,"  int i2;\n");
+    fprintf(fd,"  for (i2=0; i2<%d; i2++) {\n",Zc>>shift);
+    if (shift > 0)
+      fprintf(fd2,"  for (i2=0; i2<%d; i2++) {\n",Zc>>(shift-1));
+    for (i2=0; i2 < 1; i2++)
     {
-      channel_temp=0;
-      for (i3=0; i3 < Kb; i3++)
-      {
-        temp_prime=i1 * ncols + i3;
+      //t=Kb*Zc+i2;
+    
+      // calculate each row in base graph
+     
 
-        for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
+      fprintf(fd,"     c2=&csimd[i2];\n");
+      fprintf(fd,"     d2=&dsimd[i2];\n");
+      fprintf(fd2,"     c2=&csimd[i2];\n");
+      fprintf(fd2,"     d2=&dsimd[i2];\n");
+
+      for (i1=0; i1 < nrows; i1++)
+
+      {
+        channel_temp=0;
+        fprintf(fd,"\n//row: %d\n",i1);
+        fprintf(fd2,"\n//row: %d\n",i1);
+	fprintf(fd,"     d2[%d]=",(Zc*i1)>>shift);
+	fprintf(fd2,"     d2[%d]=",(Zc*i1)>>(shift-1));
+
+        nind=0;
+
+        for (i3=0; i3 < ncols; i3++)
         {
-          channel_temp = channel_temp ^ c[ i3*Zc + Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ] ];
+          temp_prime=i1 * ncols + i3;
+
+
+	  for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
+	    {
+	          
+	      var=(int)((i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc)/Zc);
+	      int index =var*2*Zc + (i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc) % Zc;
+	      
+	      indlist[nind] = ((index&mask)*((2*Zc)>>shift)*Kb)+(index>>shift);
+	      indlist2[nind++] = ((index&(mask>>1))*((2*Zc)>>(shift-1))*Kb)+(index>>(shift-1));
+	      
+	    }
+	  
+
         }
+	for (i4=0;i4gen_code);
+}
\ No newline at end of file
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
deleted file mode 100644
index ef207b6cdc..0000000000
--- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder2.c
+++ /dev/null
@@ -1,667 +0,0 @@
-/*
- * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The OpenAirInterface Software Alliance licenses this file to You under
- * the OAI Public License, Version 1.1  (the "License"); you may not use this file
- * except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.openairinterface.org/?page_id=698
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *-------------------------------------------------------------------------------
- * For more information about the OpenAirInterface (OAI) Software Alliance:
- *      contact@openairinterface.org
- */
-
-/*!\file ldpc_encoder2.c
- * \brief Defines the optimized LDPC encoder
- * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
- * \email openair_tech@eurecom.fr
- * \date 27-03-2018
- * \version 1.0
- * \note
- * \warning
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include "assertions.h"
-#include "common/utils/LOG/log.h"
-#include "PHY/TOOLS/time_meas.h"
-#include "defs.h"
-
-//#define DEBUG_LDPC
-
-#include "ldpc384_byte.c"
-#include "ldpc352_byte.c"
-#include "ldpc320_byte.c"
-#include "ldpc288_byte.c"
-#include "ldpc256_byte.c"
-#include "ldpc240_byte.c"
-#include "ldpc224_byte.c"
-#include "ldpc208_byte.c"
-#include "ldpc192_byte.c"
-#include "ldpc176_byte.c"
-#include "ldpc_BG2_Zc384_byte.c"
-#include "ldpc_BG2_Zc352_byte.c"
-#include "ldpc_BG2_Zc320_byte.c"
-#include "ldpc_BG2_Zc288_byte.c"
-#include "ldpc_BG2_Zc256_byte.c"
-#include "ldpc_BG2_Zc240_byte.c"
-#include "ldpc_BG2_Zc224_byte.c"
-#include "ldpc_BG2_Zc208_byte.c"
-#include "ldpc_BG2_Zc192_byte.c"
-#include "ldpc_BG2_Zc176_byte.c"
-#include "ldpc_BG2_Zc160_byte.c"
-#include "ldpc_BG2_Zc144_byte.c"
-#include "ldpc_BG2_Zc128_byte.c"
-#include "ldpc_BG2_Zc120_byte.c"
-#include "ldpc_BG2_Zc112_byte.c"
-#include "ldpc_BG2_Zc104_byte.c"
-#include "ldpc_BG2_Zc96_byte.c"
-#include "ldpc_BG2_Zc88_byte.c"
-#include "ldpc_BG2_Zc80_byte.c"
-#include "ldpc_BG2_Zc72_byte.c"
-
-
-
-void encode_parity_check_part_optim(uint8_t *c,uint8_t *d, short BG,short Zc,short Kb)
-{
-
-  if (BG==1)
-  {
-    switch (Zc)
-    {
-    case 2: break;
-    case 3: break;
-    case 4: break;
-    case 5: break;
-    case 6: break;
-    case 7: break;
-    case 8: break;
-    case 9: break;
-    case 10: break;
-    case 11: break;
-    case 12: break;
-    case 13: break;
-    case 14: break;
-    case 15: break;
-    case 16: break;
-    case 18: break;
-    case 20: break;
-    case 22: break;
-    case 24: break;      
-    case 26: break;
-    case 28: break;
-    case 30: break;
-    case 32: break;
-    case 36: break;
-    case 40: break;
-    case 44: break;
-    case 48: break;
-    case 52: break;
-    case 56: break;
-    case 60: break;
-    case 64: break;
-    case 72: break;
-    case 80: break;   
-    case 88: break;   
-    case 96: break;
-    case 104: break;
-    case 112: break;
-    case 120: break;
-    case 128: break;
-    case 144: break;
-    case 160: break;
-    case 176: ldpc176_byte(c,d); break;
-    case 192: ldpc192_byte(c,d); break;
-    case 208: ldpc208_byte(c,d); break;
-    case 224: ldpc224_byte(c,d); break;
-    case 240: ldpc240_byte(c,d); break;
-    case 256: ldpc256_byte(c,d); break;
-    case 288: ldpc288_byte(c,d); break;
-    case 320: ldpc320_byte(c,d); break;
-    case 352: ldpc352_byte(c,d); break;
-    case 384: ldpc384_byte(c,d); break;
-    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
-    }
-  }
-  else if (BG==2) {
-    switch (Zc)
-    {
-    case 2: break;
-    case 3: break;
-    case 4: break;
-    case 5: break;
-    case 6: break;
-    case 7: break;
-    case 8: break;
-    case 9: break;
-    case 10: break;
-    case 11: break;
-    case 12: break;
-    case 13: break;
-    case 14: break;
-    case 15: break;
-    case 16: break;
-    case 18: break;
-    case 20: break;
-    case 22: break;
-    case 24: break;      
-    case 26: break;
-    case 28: break;
-    case 30: break;
-    case 32: break;
-    case 36: break;
-    case 40: break;
-    case 44: break;
-    case 48: break;
-    case 52: break;
-    case 56: break;
-    case 60: break;
-    case 64: break;
-    case 72: ldpc_BG2_Zc72_byte(c,d); break;
-    case 80: ldpc_BG2_Zc80_byte(c,d); break;   
-    case 88: ldpc_BG2_Zc88_byte(c,d); break;   
-    case 96: ldpc_BG2_Zc96_byte(c,d); break;
-    case 104: ldpc_BG2_Zc104_byte(c,d); break;
-    case 112: ldpc_BG2_Zc112_byte(c,d); break;
-    case 120: ldpc_BG2_Zc120_byte(c,d); break;
-    case 128: ldpc_BG2_Zc128_byte(c,d); break;
-    case 144: ldpc_BG2_Zc144_byte(c,d); break;
-    case 160: ldpc_BG2_Zc160_byte(c,d); break;
-    case 176: ldpc_BG2_Zc176_byte(c,d); break;
-    case 192: ldpc_BG2_Zc192_byte(c,d); break;
-    case 208: ldpc_BG2_Zc208_byte(c,d); break;
-    case 224: ldpc_BG2_Zc224_byte(c,d); break;
-    case 240: ldpc_BG2_Zc240_byte(c,d); break;
-    case 256: ldpc_BG2_Zc256_byte(c,d); break;
-    case 288: ldpc_BG2_Zc288_byte(c,d); break;
-    case 320: ldpc_BG2_Zc320_byte(c,d); break;
-    case 352: ldpc_BG2_Zc352_byte(c,d); break;
-    case 384: ldpc_BG2_Zc384_byte(c,d); break;
-    default: AssertFatal(0,"BG %d Zc %d is not supported yet\n",BG,Zc); break;
-    }
-  }
-  else {
-    AssertFatal(0,"BG %d is not supported yet\n",BG);
-  } 
-
-}
-
-
-int ldpc_encoder_optim(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length,short BG,time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput)
-{
-
-  short nrows=0,ncols=0;
-  int i,i1,rate=3;
-  int no_punctured_columns,removed_bit;
-
-  int simd_size;
-
-  //determine number of bits in codeword
-   //if (block_length>3840)
-   if (BG==1)
-     {
-       //BG=1;
-       nrows=46; //parity check bits
-       ncols=22; //info bits
-       rate=3;
-     }
-     //else if (block_length<=3840)
-    else if	(BG==2)
-     {
-       //BG=2;
-       nrows=42; //parity check bits
-       ncols=10; // info bits
-       rate=5;
-
-       }
-
-
-#ifdef DEBUG_LDPC
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d\n",BG,Zc,Kb,block_length);
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU %x %x %x %x\n",test_input[0],test_input[1],test_input[2],test_input[3]);
-#endif
-
-  if ((Zc&31) > 0) simd_size = 16;
-  else simd_size = 32;
-
-  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
-  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
-
-  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
-
-  // calculate number of punctured bits
-  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
-  // printf("%d\n",no_punctured_columns);
-  // printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
-
-  if(tinput != NULL) start_meas(tinput);
-  for (i=0; i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-    }
-
-  if(tinput != NULL) stop_meas(tinput);
-
-  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) { 
-    // extend matrix
-    if(tprep != NULL) start_meas(tprep);
-    for (i1=0; i1 < ncols; i1++)
-      {
-	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-      }
-    for (i1=1;i1 8 bytes, pattern repeats.
-  __m256i zero256   = _mm256_setzero_si256();
-  __m256i masks[8];
-  register __m256i c256;
-  masks[0] = _mm256_set1_epi8(0x1);
-  masks[1] = _mm256_set1_epi8(0x2);
-  masks[2] = _mm256_set1_epi8(0x4);
-  masks[3] = _mm256_set1_epi8(0x8);
-  masks[4] = _mm256_set1_epi8(0x10);
-  masks[5] = _mm256_set1_epi8(0x20);
-  masks[6] = _mm256_set1_epi8(0x40);
-  masks[7] = _mm256_set1_epi8(0x80);
-#endif
-
-  AssertFatal(n_segments>0&&n_segments<=8,"0 < n_segments %d <= 8\n",n_segments);
-
-  //determine number of bits in codeword
-  //if (block_length>3840)
-  if (BG==1)
-    {
-      nrows=46; //parity check bits
-      ncols=22; //info bits
-      rate=3;
-    }
-    //else if (block_length<=3840)
-   else if	(BG==2)
-    {
-      //BG=2;
-      nrows=42; //parity check bits
-      ncols=10; // info bits
-      rate=5;
-
-      }
-
-#ifdef DEBUG_LDPC
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d, segments %d\n",BG,Zc,Kb,block_length,n_segments);
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU (seg 0) %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
-#endif
-
-  AssertFatal(Zc>0,"no valid Zc found for block length %d\n",block_length);
-
-  if ((Zc&31) > 0) simd_size = 16;
-  else          simd_size = 32;
-
-  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
-  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
-
-  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
-
-  // calculate number of punctured bits
-  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
-  // printf("%d\n",no_punctured_columns);
-  // printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
-
-  if(tinput != NULL) start_meas(tinput);
-#if 0
-  for (i=0; i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << j);
-    }
-  }
-#else
-#ifdef __AVX2__
-  for (i=0; i>5; i++) {
-    c256 = _mm256_and_si256(_mm256_cmpeq_epi8(_mm256_andnot_si256(_mm256_shuffle_epi8(_mm256_set1_epi32(((uint32_t*)test_input[0])[i]), shufmask),andmask),zero256),masks[0]);
-    for (j=1; j>5)<<5;i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << j);
-    }
-  }
-#else
-  AssertFatal(1==0,"Need AVX2 for this\n");
-#endif
-#endif
-
-  if(tinput != NULL) stop_meas(tinput);
-
-  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) { 
-    // extend matrix
-    if(tprep != NULL) start_meas(tprep);
-    for (i1=0; i1 < ncols; i1++)
-      {
-	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-      }
-    for (i1=1;i1>5;
-    uint32_t l2 = ((nrows-no_punctured_columns) * Zc-removed_bit)>>5;
-    __m256i *c256p = (__m256i *)&c[2*Zc];
-    __m256i *d256p = (__m256i *)&d[0];
-    //  if (((block_length-(2*Zc))&31)>0) l1++;
-    
-    for (i=0;i0) l2++;
-    
-    for (i1=0;i1>j)&1;
-    for (i=0;i<((nrows-no_punctured_columns) * Zc-removed_bit);i++)
-      for (j=0; j>j)&1;
-    }
-
-#else
-    AssertFatal(1==0,"Need AVX2 for now\n");
-#endif
-
-  if(toutput != NULL) stop_meas(toutput);
-  return 0;
-}
-
-int ldpc_encoder_optim_8seg_multi(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, int n_segments,unsigned int macro_num, time_stats_t *tinput,time_stats_t *tprep,time_stats_t *tparity,time_stats_t *toutput)
-{
-
-  short nrows=0,ncols=0;
-  int i,i1,j,rate=3;
-  int no_punctured_columns,removed_bit;
-  //Table of possible lifting sizes
-  char temp;
-  int simd_size;
-  unsigned int macro_segment, macro_segment_end;
-
-  
-  macro_segment = 8*macro_num;
-  // macro_segment_end = (n_segments > 8*(macro_num+1)) ? 8*(macro_num+1) : n_segments;
-  macro_segment_end = macro_segment + (n_segments > 8 ? 8 : n_segments);
-  ///printf("macro_segment: %d\n", macro_segment);
-  ///printf("macro_segment_end: %d\n", macro_segment_end );
-
-#ifdef __AVX2__
-  __m256i shufmask = _mm256_set_epi64x(0x0303030303030303, 0x0202020202020202,0x0101010101010101, 0x0000000000000000);
-  __m256i andmask  = _mm256_set1_epi64x(0x0102040810204080);  // every 8 bits -> 8 bytes, pattern repeats.
-  __m256i zero256   = _mm256_setzero_si256();
-  __m256i masks[8];
-  register __m256i c256;
-  masks[0] = _mm256_set1_epi8(0x1);
-  masks[1] = _mm256_set1_epi8(0x2);
-  masks[2] = _mm256_set1_epi8(0x4);
-  masks[3] = _mm256_set1_epi8(0x8);
-  masks[4] = _mm256_set1_epi8(0x10);
-  masks[5] = _mm256_set1_epi8(0x20);
-  masks[6] = _mm256_set1_epi8(0x40);
-  masks[7] = _mm256_set1_epi8(0x80);
-#endif
-
-
-
-  //determine number of bits in codeword
-  if (BG==1)
-    {
-      nrows=46; //parity check bits
-      ncols=22; //info bits
-      rate=3;
-    }
-    else if (BG==2)
-    {
-      nrows=42; //parity check bits
-      ncols=10; // info bits
-      rate=5;
-    }
-
-#ifdef DEBUG_LDPC
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d, segments %d\n",BG,Zc,Kb,block_length,n_segments);
-  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU (seg 0) %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
-#endif
-
-  AssertFatal(Zc>0,"no valid Zc found for block length %d\n",block_length);
-
-  if ((Zc&31) > 0) simd_size = 16;
-  else          simd_size = 32;
-
-  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
-  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
-
-  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
-
-  // calculate number of punctured bits
-  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
-  //printf("%d\n",no_punctured_columns);
-  //printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
-
-  if(tinput != NULL) start_meas(tinput);
-#if 0
-  for (i=0; i>(i&7);
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << (j-macro_segment));
-    }
-  }
-#else
-#ifdef __AVX2__
-  for (i=0; i>5; i++) {
-    c256 = _mm256_and_si256(_mm256_cmpeq_epi8(_mm256_andnot_si256(_mm256_shuffle_epi8(_mm256_set1_epi32(((uint32_t*)test_input[macro_segment])[i]), shufmask),andmask),zero256),masks[0]);
-    //for (j=1; j>5)<<5;i>(i&7)))>>(7-(i&7));
-      //printf("c(%d,%d)=%d\n",j,i,temp);
-      c[i] |= (temp << (j-macro_segment));
-    }
-  }
-#else
-  AssertFatal(1==0,"Need AVX2 for this\n");
-#endif
-#endif
-
-  if(tinput != NULL) stop_meas(tinput);
-
-  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) {
-    // extend matrix
-    if(tprep != NULL) start_meas(tprep);
-    for (i1=0; i1 < ncols; i1++)
-      {
-	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
-      }
-    for (i1=1;i1>5;
-    uint32_t l2 = ((nrows-no_punctured_columns) * Zc-removed_bit)>>5;
-    __m256i *c256p = (__m256i *)&c[2*Zc];
-    __m256i *d256p = (__m256i *)&d[0];
-    //  if (((block_length-(2*Zc))&31)>0) l1++;
-
-    for (i=0;i0) l2++;
-
-    for (i1=0;i1>(j-macro_segment))&1;
-    for (i=0;i<((nrows-no_punctured_columns) * Zc-removed_bit);i++)
-      //for (j=0; j>(j-macro_segment))&1;
-    }
-
-#else
-    AssertFatal(1==0,"Need AVX2 for now\n");
-#endif
-
-  if(toutput != NULL) stop_meas(toutput);
-  return 0;
-}
-
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
new file mode 100644
index 0000000000..7da265494a
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim.c
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*!\file ldpc_encoder2.c
+ * \brief Defines the optimized LDPC encoder
+ * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
+ * \email openair_tech@eurecom.fr
+ * \date 27-03-2018
+ * \version 1.0
+ * \note
+ * \warning
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+#include "PHY/TOOLS/time_meas.h"
+#include "openair1/PHY/CODING/nrLDPC_defs.h"
+#include "ldpc_encode_parity_check.c"
+#include "ldpc_generate_coefficient.c"
+//#define DEBUG_LDPC
+
+
+
+
+
+int nrLDPC_encod(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, encoder_implemparams_t *impp)
+{
+
+  short nrows=0,ncols=0;
+  int i,i1,rate=3;
+  int no_punctured_columns,removed_bit;
+
+  int simd_size;
+
+  //determine number of bits in codeword
+   //if (block_length>3840)
+   if (BG==1)
+     {
+       //BG=1;
+       nrows=46; //parity check bits
+       ncols=22; //info bits
+       rate=3;
+     }
+     //else if (block_length<=3840)
+    else if	(BG==2)
+     {
+       //BG=2;
+       nrows=42; //parity check bits
+       ncols=10; // info bits
+       rate=5;
+
+       }
+
+
+#ifdef DEBUG_LDPC
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d\n",BG,Zc,Kb,block_length);
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
+#endif
+
+  if ((Zc&31) > 0) simd_size = 16;
+  else simd_size = 32;
+
+  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
+  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
+
+  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
+
+  // calculate number of punctured bits
+  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
+  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
+  // printf("%d\n",no_punctured_columns);
+  // printf("%d\n",removed_bit);
+  // unpack input
+  memset(c,0,sizeof(unsigned char) * ncols * Zc);
+  memset(d,0,sizeof(unsigned char) * nrows * Zc);
+
+  if(impp->tinput != NULL) start_meas(impp->tinput);
+  for (i=0; i>(i&7)))>>(7-(i&7));
+      //printf("c(%d,%d)=%d\n",j,i,temp);
+    }
+
+  if(impp->tinput != NULL) stop_meas(impp->tinput);
+
+  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) { 
+    // extend matrix
+    if(impp->tprep != NULL) start_meas(impp->tprep);
+    for (i1=0; i1 < ncols; i1++)
+      {
+	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+      }
+    for (i1=1;i1tprep != NULL) stop_meas(impp->tprep);
+    //parity check part
+    if(impp->tparity != NULL) start_meas(impp->tparity);
+    encode_parity_check_part_optim(c_extension, d, BG, Zc, Kb);
+    if(impp->tparity != NULL) stop_meas(impp->tparity);
+  }
+  else {
+    if (encode_parity_check_part_orig(c, d, BG, Zc, Kb, block_length)!=0) {
+      printf("Problem with encoder\n");
+      return(-1);
+    }
+  }
+  if(impp->toutput != NULL) start_meas(impp->toutput);
+  // information part and puncture columns
+  memcpy(&channel_input[0][0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char));
+  memcpy(&channel_input[0][block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char));
+
+  if(impp->toutput != NULL) stop_meas(impp->toutput);
+  return 0;
+}
+
+
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8seg.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8seg.c
new file mode 100644
index 0000000000..a974e86e27
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8seg.c
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*!\file ldpc_encoder2.c
+ * \brief Defines the optimized LDPC encoder
+ * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
+ * \email openair_tech@eurecom.fr
+ * \date 27-03-2018
+ * \version 1.0
+ * \note
+ * \warning
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+#include "PHY/TOOLS/time_meas.h"
+#include "openair1/PHY/CODING/nrLDPC_defs.h"
+//#define DEBUG_LDPC
+#include "ldpc_encode_parity_check.c" 
+#include "ldpc_generate_coefficient.c"
+
+
+
+int nrLDPC_encod(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, encoder_implemparams_t *impp)
+{
+
+  short nrows=0,ncols=0;
+  int i,i1,j,rate=3;
+  int no_punctured_columns,removed_bit;
+  char temp;
+  int simd_size;
+
+#ifdef __AVX2__
+  __m256i shufmask = _mm256_set_epi64x(0x0303030303030303, 0x0202020202020202,0x0101010101010101, 0x0000000000000000);
+  __m256i andmask  = _mm256_set1_epi64x(0x0102040810204080);  // every 8 bits -> 8 bytes, pattern repeats.
+  __m256i zero256   = _mm256_setzero_si256();
+  __m256i masks[8];
+  register __m256i c256;
+  masks[0] = _mm256_set1_epi8(0x1);
+  masks[1] = _mm256_set1_epi8(0x2);
+  masks[2] = _mm256_set1_epi8(0x4);
+  masks[3] = _mm256_set1_epi8(0x8);
+  masks[4] = _mm256_set1_epi8(0x10);
+  masks[5] = _mm256_set1_epi8(0x20);
+  masks[6] = _mm256_set1_epi8(0x40);
+  masks[7] = _mm256_set1_epi8(0x80);
+#endif
+
+  AssertFatal((impp->n_segments>0&&impp->n_segments<=8),"0 < n_segments %d <= 8\n",impp->n_segments);
+
+  //determine number of bits in codeword
+  //if (block_length>3840)
+  if (BG==1)
+    {
+      nrows=46; //parity check bits
+      ncols=22; //info bits
+      rate=3;
+    }
+    //else if (block_length<=3840)
+   else if	(BG==2)
+    {
+      //BG=2;
+      nrows=42; //parity check bits
+      ncols=10; // info bits
+      rate=5;
+
+      }
+
+#ifdef DEBUG_LDPC
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d, segments %d\n",BG,Zc,Kb,block_length,n_segments);
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU (seg 0) %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
+#endif
+
+  AssertFatal(Zc>0,"no valid Zc found for block length %d\n",block_length);
+
+  if ((Zc&31) > 0) simd_size = 16;
+  else          simd_size = 32;
+
+  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
+  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
+
+  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
+
+  // calculate number of punctured bits
+  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
+  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
+  // printf("%d\n",no_punctured_columns);
+  // printf("%d\n",removed_bit);
+  // unpack input
+  memset(c,0,sizeof(unsigned char) * ncols * Zc);
+  memset(d,0,sizeof(unsigned char) * nrows * Zc);
+
+  if(impp->tinput != NULL) start_meas(impp->tinput);
+#if 0
+  for (i=0; i>(i&7)))>>(7-(i&7));
+      //printf("c(%d,%d)=%d\n",j,i,temp);
+      c[i] |= (temp << j);
+    }
+  }
+#else
+#ifdef __AVX2__
+  for (i=0; i>5; i++) {
+    c256 = _mm256_and_si256(_mm256_cmpeq_epi8(_mm256_andnot_si256(_mm256_shuffle_epi8(_mm256_set1_epi32(((uint32_t*)test_input[0])[i]), shufmask),andmask),zero256),masks[0]);
+    for (j=1; jn_segments; j++) {
+      c256 = _mm256_or_si256(_mm256_and_si256(_mm256_cmpeq_epi8(_mm256_andnot_si256(_mm256_shuffle_epi8(_mm256_set1_epi32(((uint32_t*)test_input[j])[i]), shufmask),andmask),zero256),masks[j]),c256);
+    }
+    ((__m256i *)c)[i] = c256;
+  }
+
+  for (i=(block_length>>5)<<5;in_segments; j++) {
+
+      temp = (test_input[j][i/8]&(128>>(i&7)))>>(7-(i&7));
+      //printf("c(%d,%d)=%d\n",j,i,temp);
+      c[i] |= (temp << j);
+    }
+  }
+#else
+  AssertFatal(1==0,"Need AVX2 for this\n");
+#endif
+#endif
+
+  if(impp->tinput != NULL) stop_meas(impp->tinput);
+
+  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) { 
+    // extend matrix
+    if(impp->tprep != NULL) start_meas(impp->tprep);
+    for (i1=0; i1 < ncols; i1++)
+      {
+	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+      }
+    for (i1=1;i1tprep != NULL) stop_meas(impp->tprep);
+    //parity check part
+    if(impp->tparity != NULL) start_meas(impp->tparity);
+    encode_parity_check_part_optim(c_extension, d, BG, Zc, Kb);
+    if(impp->tparity != NULL) stop_meas(impp->tparity);
+  }
+  else {
+    if (encode_parity_check_part_orig(c, d, BG, Zc, Kb, block_length)!=0) {
+      printf("Problem with encoder\n");
+      return(-1);
+    }
+  }
+  if(impp->toutput != NULL) start_meas(impp->toutput);
+  // information part and puncture columns
+  /*
+  memcpy(&channel_input[0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char));
+  memcpy(&channel_input[block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char));
+  */
+#ifdef __AVX2__
+  if ((((2*Zc)&31) == 0) && (((block_length-(2*Zc))&31) == 0)) {
+    //AssertFatal(((2*Zc)&31) == 0,"2*Zc needs to be a multiple of 32 for now\n");
+    //AssertFatal(((block_length-(2*Zc))&31) == 0,"block_length-(2*Zc) needs to be a multiple of 32 for now\n");
+    uint32_t l1 = (block_length-(2*Zc))>>5;
+    uint32_t l2 = ((nrows-no_punctured_columns) * Zc-removed_bit)>>5;
+    __m256i *c256p = (__m256i *)&c[2*Zc];
+    __m256i *d256p = (__m256i *)&d[0];
+    //  if (((block_length-(2*Zc))&31)>0) l1++;
+    
+    for (i=0;in_segments;j++) ((__m256i *)channel_input[j])[i] = _mm256_and_si256(_mm256_srai_epi16(c256p[i],j),masks[0]);
+    
+    //  if ((((nrows-no_punctured_columns) * Zc-removed_bit)&31)>0) l2++;
+    
+    for (i1=0;i1n_segments;j++) ((__m256i *)channel_input[j])[i] = _mm256_and_si256(_mm256_srai_epi16(d256p[i1],j),masks[0]);
+  }
+  else {
+#ifdef DEBUG_LDPC
+  LOG_W(PHY,"using non-optimized version\n");
+#endif
+    // do non-SIMD version
+    for (i=0;i<(block_length-2*Zc);i++) 
+      for (j=0; jn_segments; j++)
+	channel_input[j][i] = (c[2*Zc+i]>>j)&1;
+    for (i=0;i<((nrows-no_punctured_columns) * Zc-removed_bit);i++)
+      for (j=0; jn_segments; j++)
+	channel_input[j][block_length-2*Zc+i] = (d[i]>>j)&1;
+    }
+
+#else
+    AssertFatal(1==0,"Need AVX2 for now\n");
+#endif
+
+  if(impp->toutput != NULL) stop_meas(impp->toutput);
+  return 0;
+}
+
+
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
new file mode 100644
index 0000000000..28ab5b5029
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
@@ -0,0 +1,238 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*!\file ldpc_encoder2.c
+ * \brief Defines the optimized LDPC encoder
+ * \author Florian Kaltenberger, Raymond Knopp, Kien le Trung (Eurecom)
+ * \email openair_tech@eurecom.fr
+ * \date 27-03-2018
+ * \version 1.0
+ * \note
+ * \warning
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+#include "PHY/TOOLS/time_meas.h"
+#include "openair1/PHY/CODING/nrLDPC_defs.h"
+
+//#define DEBUG_LDPC
+
+#include "ldpc_encode_parity_check.c"
+#include "ldpc_generate_coefficient.c"
+
+
+int nrLDPC_encod(unsigned char **test_input,unsigned char **channel_input,int Zc,int Kb,short block_length, short BG, encoder_implemparams_t *impp)
+{
+
+  short nrows=0,ncols=0;
+  int i,i1,j,rate=3;
+  int no_punctured_columns,removed_bit;
+  //Table of possible lifting sizes
+  char temp;
+  int simd_size;
+  unsigned int macro_segment, macro_segment_end;
+
+  
+  macro_segment = 8*impp->macro_num;
+  // macro_segment_end = (n_segments > 8*(macro_num+1)) ? 8*(macro_num+1) : n_segments;
+  macro_segment_end = macro_segment + (impp->n_segments > 8 ? 8 : impp->n_segments);
+  ///printf("macro_segment: %d\n", macro_segment);
+  ///printf("macro_segment_end: %d\n", macro_segment_end );
+
+#ifdef __AVX2__
+  __m256i shufmask = _mm256_set_epi64x(0x0303030303030303, 0x0202020202020202,0x0101010101010101, 0x0000000000000000);
+  __m256i andmask  = _mm256_set1_epi64x(0x0102040810204080);  // every 8 bits -> 8 bytes, pattern repeats.
+  __m256i zero256   = _mm256_setzero_si256();
+  __m256i masks[8];
+  register __m256i c256;
+  masks[0] = _mm256_set1_epi8(0x1);
+  masks[1] = _mm256_set1_epi8(0x2);
+  masks[2] = _mm256_set1_epi8(0x4);
+  masks[3] = _mm256_set1_epi8(0x8);
+  masks[4] = _mm256_set1_epi8(0x10);
+  masks[5] = _mm256_set1_epi8(0x20);
+  masks[6] = _mm256_set1_epi8(0x40);
+  masks[7] = _mm256_set1_epi8(0x80);
+#endif
+
+
+
+  //determine number of bits in codeword
+  if (BG==1)
+    {
+      nrows=46; //parity check bits
+      ncols=22; //info bits
+      rate=3;
+    }
+    else if (BG==2)
+    {
+      nrows=42; //parity check bits
+      ncols=10; // info bits
+      rate=5;
+    }
+
+#ifdef DEBUG_LDPC
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: BG %d, Zc %d, Kb %d, block_length %d, segments %d\n",BG,Zc,Kb,block_length,n_segments);
+  LOG_D(PHY,"ldpc_encoder_optim_8seg: PDU (seg 0) %x %x %x %x\n",test_input[0][0],test_input[0][1],test_input[0][2],test_input[0][3]);
+#endif
+
+  AssertFatal(Zc>0,"no valid Zc found for block length %d\n",block_length);
+
+  if ((Zc&31) > 0) simd_size = 16;
+  else          simd_size = 32;
+
+  unsigned char c[22*Zc] __attribute__((aligned(32))); //padded input, unpacked, max size
+  unsigned char d[46*Zc] __attribute__((aligned(32))); //coded parity part output, unpacked, max size
+
+  unsigned char c_extension[2*22*Zc*simd_size] __attribute__((aligned(32)));      //double size matrix of c
+
+  // calculate number of punctured bits
+  no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
+  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(int)(block_length*rate);
+  //printf("%d\n",no_punctured_columns);
+  //printf("%d\n",removed_bit);
+  // unpack input
+  memset(c,0,sizeof(unsigned char) * ncols * Zc);
+  memset(d,0,sizeof(unsigned char) * nrows * Zc);
+
+  if(impp->tinput != NULL) start_meas(impp->tinput);
+#if 0
+  for (i=0; i>(i&7);
+      //printf("c(%d,%d)=%d\n",j,i,temp);
+      c[i] |= (temp << (j-macro_segment));
+    }
+  }
+#else
+#ifdef __AVX2__
+  for (i=0; i>5; i++) {
+    c256 = _mm256_and_si256(_mm256_cmpeq_epi8(_mm256_andnot_si256(_mm256_shuffle_epi8(_mm256_set1_epi32(((uint32_t*)test_input[macro_segment])[i]), shufmask),andmask),zero256),masks[0]);
+    //for (j=1; j>5)<<5;i>(i&7)))>>(7-(i&7));
+      //printf("c(%d,%d)=%d\n",j,i,temp);
+      c[i] |= (temp << (j-macro_segment));
+    }
+  }
+#else
+  AssertFatal(1==0,"Need AVX2 for this\n");
+#endif
+#endif
+
+  if(impp->tinput != NULL) stop_meas(impp->tinput);
+
+  if ((BG==1 && Zc>176) || (BG==2 && Zc>64)) {
+    // extend matrix
+    if(impp->tprep != NULL) start_meas(impp->tprep);
+    for (i1=0; i1 < ncols; i1++)
+      {
+	memcpy(&c_extension[2*i1*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+	memcpy(&c_extension[(2*i1+1)*Zc], &c[i1*Zc], Zc*sizeof(unsigned char));
+      }
+    for (i1=1;i1tprep != NULL) stop_meas(impp->tprep);
+    //parity check part
+    if(impp->tparity != NULL) start_meas(impp->tparity);
+    encode_parity_check_part_optim(c_extension, d, BG, Zc, Kb);
+    if(impp->tparity != NULL) stop_meas(impp->tparity);
+  }
+  else {
+    if (encode_parity_check_part_orig(c, d, BG, Zc, Kb, block_length)!=0) {
+      printf("Problem with encoder\n");
+      return(-1);
+    }
+  }
+  if(impp->toutput != NULL) start_meas(impp->toutput);
+  // information part and puncture columns
+  /*
+  memcpy(&channel_input[0], &c[2*Zc], (block_length-2*Zc)*sizeof(unsigned char));
+  memcpy(&channel_input[block_length-2*Zc], &d[0], ((nrows-no_punctured_columns) * Zc-removed_bit)*sizeof(unsigned char));
+  */
+#ifdef __AVX2__
+  if ((((2*Zc)&31) == 0) && (((block_length-(2*Zc))&31) == 0)) {
+    //AssertFatal(((2*Zc)&31) == 0,"2*Zc needs to be a multiple of 32 for now\n");
+    //AssertFatal(((block_length-(2*Zc))&31) == 0,"block_length-(2*Zc) needs to be a multiple of 32 for now\n");
+    uint32_t l1 = (block_length-(2*Zc))>>5;
+    uint32_t l2 = ((nrows-no_punctured_columns) * Zc-removed_bit)>>5;
+    __m256i *c256p = (__m256i *)&c[2*Zc];
+    __m256i *d256p = (__m256i *)&d[0];
+    //  if (((block_length-(2*Zc))&31)>0) l1++;
+
+    for (i=0;i0) l2++;
+
+    for (i1=0;i1>(j-macro_segment))&1;
+    for (i=0;i<((nrows-no_punctured_columns) * Zc-removed_bit);i++)
+      //for (j=0; j>(j-macro_segment))&1;
+    }
+
+#else
+    AssertFatal(1==0,"Need AVX2 for now\n");
+#endif
+
+  if(impp->toutput != NULL) stop_meas(impp->toutput);
+  return 0;
+}
+
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
index 5988c9067d..3d26a19063 100644
--- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_generate_coefficient.c
@@ -35,9 +35,8 @@
 #include 
 #include "Gen_shift_value.h"
 #include "assertions.h"
-#include "defs.h"
 
-short *choose_generator_matrix(short BG,short Zc)
+static inline short *choose_generator_matrix(short BG,short Zc)
 {
   short *Gen_shift_values = NULL;
 
@@ -361,237 +360,70 @@ short *choose_generator_matrix(short BG,short Zc)
   return Gen_shift_values;
 }
 
-int ldpc_encoder_orig(unsigned char *test_input,unsigned char *channel_input,int Zc,int Kb,short block_length, short BG,unsigned char gen_code)
+static inline int encode_parity_check_part_orig(unsigned char *c,unsigned char *d, short BG,short Zc,short Kb,short block_length)
 {
-  unsigned char c[22*384]; //padded input, unpacked, max size
-  unsigned char d[68*384]; //coded output, unpacked, max size
+  short *Gen_shift_values=choose_generator_matrix(BG,Zc);
+  short *no_shift_values, *pointer_shift_values;
+  int no_punctured_columns;
+  short nrows,ncols,rate=3;
+  int i1,i2,i3,i4,i5,temp_prime;
   unsigned char channel_temp,temp;
-  short *Gen_shift_values, *no_shift_values, *pointer_shift_values;
 
-  short nrows = 46;//parity check bits
-  short ncols = 22;//info bits
-
-
-  int i,i1,i2,i3,i4,i5,temp_prime,var;
-  int no_punctured_columns,removed_bit,rate=3;
-  int nind=0;
-  int indlist[1000];
-  int indlist2[1000];
-
-  //determine number of bits in codeword
-  //if (block_length>3840)
-     if (BG==1)
-       {
-         nrows=46; //parity check bits
-         ncols=22; //info bits
-         rate=3;
-       }
-       //else if (block_length<=3840)
-      else if	(BG==2)
-       {
-         //BG=2;
-         nrows=42; //parity check bits
-         ncols=10; // info bits
-         rate=5;
-         }
-
-  Gen_shift_values=choose_generator_matrix(BG,Zc);
-  if (Gen_shift_values==NULL) {
-    printf("ldpc_encoder_orig: could not find generator matrix\n");
-    return(-1);
-  }
-
-  //printf("ldpc_encoder_orig: BG %d, Zc %d, Kb %d\n",BG, Zc, Kb);
-
-  // load base graph of generator matrix
   if (BG==1)
   {
     no_shift_values=(short *) no_shift_values_BG1;
     pointer_shift_values=(short *) pointer_shift_values_BG1;
+      nrows=46; //parity check bits
+      ncols=22; //info bits
+      rate=3;
   }
   else if (BG==2)
   {
     no_shift_values=(short *) no_shift_values_BG2;
     pointer_shift_values=(short *) pointer_shift_values_BG2;
+      nrows=42; //parity check bits
+      ncols=10; //info bits
+      rate=5;
   }
   else {
-    AssertFatal(0,"BG %d is not supported yet\n",BG);
+    printf("problem with BG\n");
+    return(-1);
   }
-  
+
+
   no_punctured_columns=(int)((nrows-2)*Zc+block_length-block_length*rate)/Zc;
-  removed_bit=(nrows-no_punctured_columns-2) * Zc+block_length-(block_length*rate);
-  //printf("%d\n",no_punctured_columns);
-  //printf("%d\n",removed_bit);
-  // unpack input
-  memset(c,0,sizeof(unsigned char) * ncols * Zc);
-  memset(d,0,sizeof(unsigned char) * nrows * Zc);
 
-  for (i=0; i>7&1;
-    c[i]=(test_input[i/8]&(128>>(i&7)))>>(7-(i&7));
-  }
+    //t=Kb*Zc+i2;
 
-  // parity check part
-
-  if (gen_code==1)
-  {
-    char fname[100];
-    sprintf(fname,"ldpc_BG%d_Zc%d_byte.c",BG,Zc);
-    FILE *fd=fopen(fname,"w");
-    AssertFatal(fd!=NULL,"cannot open %s\n",fname);
-    sprintf(fname,"ldpc_BG%d_Zc%d_16bit.c",BG,Zc);
-    FILE *fd2=fopen(fname,"w");
-    AssertFatal(fd2!=NULL,"cannot open %s\n",fname);
-
-    int shift;
-    char data_type[100];
-    char xor_command[100];
-    int mask;
-
-
-
-
-    fprintf(fd,"#include \"PHY/sse_intrin.h\"\n");
-    fprintf(fd2,"#include \"PHY/sse_intrin.h\"\n");
-
-    if ((Zc&31)==0) {
-      shift=5; // AVX2 - 256-bit SIMD
-      mask=31;
-      strcpy(data_type,"__m256i");
-      strcpy(xor_command,"_mm256_xor_si256");
-    }
-    else if ((Zc&15)==0) {
-      shift=4; // SSE4 - 128-bit SIMD
-      mask=15;
-      strcpy(data_type,"__m128i");
-      strcpy(xor_command,"_mm_xor_si128");
-
-    }
-    else if ((Zc&7)==0) {
-      shift=3; // MMX  - 64-bit SIMD
-      mask=7;
-      strcpy(data_type,"__m64");
-      strcpy(xor_command,"_mm_xor_si64"); 
-    }
-    else {
-      shift=0;                 // no SIMD
-      mask=0;
-      strcpy(data_type,"uint8_t");
-      strcpy(xor_command,"scalar_xor");
-      fprintf(fd,"#define scalar_xor(a,b) ((a)^(b))\n");
-      fprintf(fd2,"#define scalar_xor(a,b) ((a)^(b))\n");
-    }
-    fprintf(fd,"// generated code for Zc=%d, byte encoding\n",Zc);
-    fprintf(fd2,"// generated code for Zc=%d, 16bit encoding\n",Zc);
-    fprintf(fd,"static inline void ldpc_BG%d_Zc%d_byte(uint8_t *c,uint8_t *d) {\n",BG,Zc);
-    fprintf(fd2,"static inline void ldpc_BG%d_Zc%d_16bit(uint16_t *c,uint16_t *d) {\n",BG,Zc);
-    fprintf(fd,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
-    fprintf(fd2,"  %s *csimd=(%s *)c,*dsimd=(%s *)d;\n\n",data_type,data_type,data_type);
-    fprintf(fd,"  %s *c2,*d2;\n\n",data_type);
-    fprintf(fd2,"  %s *c2,*d2;\n\n",data_type);
-    fprintf(fd,"  int i2;\n");
-    fprintf(fd2,"  int i2;\n");
-    fprintf(fd,"  for (i2=0; i2<%d; i2++) {\n",Zc>>shift);
-    if (shift > 0)
-      fprintf(fd2,"  for (i2=0; i2<%d; i2++) {\n",Zc>>(shift-1));
-    for (i2=0; i2 < 1; i2++)
+    //rotate matrix here
+    for (i5=0; i5 < Kb; i5++)
     {
-      //t=Kb*Zc+i2;
-    
-      // calculate each row in base graph
-     
-
-      fprintf(fd,"     c2=&csimd[i2];\n");
-      fprintf(fd,"     d2=&dsimd[i2];\n");
-      fprintf(fd2,"     c2=&csimd[i2];\n");
-      fprintf(fd2,"     d2=&dsimd[i2];\n");
-
-      for (i1=0; i1 < nrows; i1++)
-
-      {
-        channel_temp=0;
-        fprintf(fd,"\n//row: %d\n",i1);
-        fprintf(fd2,"\n//row: %d\n",i1);
-	fprintf(fd,"     d2[%d]=",(Zc*i1)>>shift);
-	fprintf(fd2,"     d2[%d]=",(Zc*i1)>>(shift-1));
-
-        nind=0;
-
-        for (i3=0; i3 < ncols; i3++)
-        {
-          temp_prime=i1 * ncols + i3;
-
-
-	  for (i4=0; i4 < no_shift_values[temp_prime]; i4++)
-	    {
-	          
-	      var=(int)((i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc)/Zc);
-	      int index =var*2*Zc + (i3*Zc + (Gen_shift_values[ pointer_shift_values[temp_prime]+i4 ]+1)%Zc) % Zc;
-	      
-	      indlist[nind] = ((index&mask)*((2*Zc)>>shift)*Kb)+(index>>shift);
-	      indlist2[nind++] = ((index&(mask>>1))*((2*Zc)>>(shift-1))*Kb)+(index>>(shift-1));
-	      
-	    }
-	  
-
-        }
-	for (i4=0;i4
- * \date 27-03-2018
- * \version 1.0
- * \note
- * \warning
- */
-
-#ifndef __NR_LDPC_DECODER__H__
-#define __NR_LDPC_DECODER__H__
-
-#include "nrLDPC_types.h"
-#include "nrLDPC_init_mem.h"
-
-/**
-   \brief LDPC decoder
-   \param p_decParams LDPC decoder parameters
-   \param p_llr Input LLRs
-   \param p_llrOut Output vector
-   \param p_profiler LDPC profiler statistics
-*/
-int32_t nrLDPC_decoder(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_llrOut, t_nrLDPC_procBuf* p_procBuf, t_nrLDPC_time_stats* p_profiler);
-
-#endif
+#ifdef LDPC_LOADER
+nrLDPC_decoderfunc_t nrLDPC_decoder;
+nrLDPC_encoderfunc_t nrLDPC_encoder;
+#else
+/* functions to load the LDPC shared lib, implemented in openair1/PHY/CODING/nrLDPC_load.c */
+extern int load_nrLDPClib(void) ;
+extern int load_nrLDPClib_ref(char *libversion, nrLDPC_encoderfunc_t * nrLDPC_encoder_ptr); // for ldpctest
+/* ldpc coder/decoder functions, as loaded by load_nrLDPClib(). */
+extern nrLDPC_decoderfunc_t nrLDPC_decoder;
+extern nrLDPC_encoderfunc_t nrLDPC_encoder;
+// inline functions:
+#include "openair1/PHY/CODING/nrLDPC_decoder/nrLDPC_init_mem.h"
+#endif
\ No newline at end of file
diff --git a/openair1/PHY/CODING/nrLDPC_load.c b/openair1/PHY/CODING/nrLDPC_load.c
new file mode 100644
index 0000000000..a74bdf7bd1
--- /dev/null
+++ b/openair1/PHY/CODING/nrLDPC_load.c
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file openair1/PHY/CODING/coding_nr_load.c
+ * \brief: load library implementing coding/decoding algorithms
+ * \author Francois TABURET
+ * \date 2020
+ * \version 0.1
+ * \company NOKIA BellLabs France
+ * \email: francois.taburet@nokia-bell-labs.com
+ * \note
+ * \warning
+ */
+#define _GNU_SOURCE 
+#include 
+#include 
+#include 
+#include "assertions.h"
+#include "common/utils/LOG/log.h"
+#define LDPC_LOADER
+#include "PHY/CODING/nrLDPC_extern.h"
+#include "common/config/config_userapi.h" 
+#include "common/utils/load_module_shlib.h" 
+
+
+/* function description array, to be used when loading the encoding/decoding shared lib */
+static loader_shlibfunc_t shlib_fdesc[2];
+
+char *arg[64]={"ldpctest","-O","cmdlineonly::dbgl0"};
+
+int load_nrLDPClib(void) {
+	 char *ptr = (char*)config_get_if();
+     if ( ptr==NULL )  {// phy simulators, config module possibly not loaded
+     	 load_configmodule(3,(char **)arg,CONFIG_ENABLECMDLINEONLY) ;
+     	 logInit();
+     }	 
+     shlib_fdesc[0].fname = "nrLDPC_decod";
+     shlib_fdesc[1].fname = "nrLDPC_encod";
+     int ret=load_module_shlib("ldpc",shlib_fdesc,sizeof(shlib_fdesc)/sizeof(loader_shlibfunc_t),NULL);
+     AssertFatal( (ret >= 0),"Error loading ldpc decoder");
+     nrLDPC_decoder = (nrLDPC_decoderfunc_t)shlib_fdesc[0].fptr;
+     nrLDPC_encoder = (nrLDPC_encoderfunc_t)shlib_fdesc[1].fptr;
+return 0;
+}
+
+int load_nrLDPClib_ref(char *libversion, nrLDPC_encoderfunc_t * nrLDPC_encoder_ptr) {
+	loader_shlibfunc_t shlib_encoder_fdesc;
+
+     shlib_encoder_fdesc.fname = "nrLDPC_encod";
+     char libpath[64];
+     sprintf(libpath,"ldpc%s",libversion);
+     int ret=load_module_shlib(libpath,&shlib_encoder_fdesc,1,NULL);
+     AssertFatal( (ret >= 0),"Error loading ldpc encoder %s\n",libpath);
+     *nrLDPC_encoder_ptr = (nrLDPC_encoderfunc_t)shlib_encoder_fdesc.fptr;
+return 0;
+}
+
+
diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index f0ad3cbaae..4798f9a9e4 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -31,6 +31,7 @@
 #include "TDD-Config.h"
 #include "MBSFN-SubframeConfigList.h"*/
 #include "openair1/PHY/defs_RU.h"
+#include "openair1/PHY/CODING/nrLDPC_extern.h"
 #include "LAYER2/NR_MAC_gNB/mac_proto.h"
 #include "assertions.h"
 #include 
@@ -115,6 +116,7 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
   LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_gNB][MOD %02"PRIu8"][]\n", gNB->Mod_id);
   crcTableInit();
   init_dfts();
+  load_nrLDPClib();
   // PBCH DMRS gold sequences generation
   nr_init_pbch_dmrs(gNB);
   //PDCCH DMRS init
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index dae5586224..17de9c02af 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -35,12 +35,11 @@
 #include "PHY/CODING/coding_extern.h"
 #include "PHY/CODING/coding_defs.h"
 #include "PHY/CODING/lte_interleaver_inline.h"
-#include "PHY/CODING/nrLDPC_encoder/defs.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/NR_TRANSPORT/nr_transport.h"
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/NR_TRANSPORT/nr_dlsch.h"
 #include "SCHED_NR/sched_nr.h"
-#include "defs.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 #include "common/utils/LOG/log.h"
 #include 
@@ -404,9 +403,11 @@ int nr_dlsch_encoding(unsigned char *a,
       //ldpc_encoder_orig((unsigned char*)dlsch->harq_processes[harq_pid]->c[r],dlsch->harq_processes[harq_pid]->d[r],*Zc,Kb,Kr,BG,0);
       //ldpc_encoder_optim((unsigned char*)dlsch->harq_processes[harq_pid]->c[r],(unsigned char*)&dlsch->harq_processes[harq_pid]->d[r][0],*Zc,Kb,Kr,BG,NULL,NULL,NULL,NULL);
     }
-
+    encoder_implemparams_t impp;
+    impp.n_segments=dlsch->harq_processes[harq_pid]->C;
     for(int j=0;j<(dlsch->harq_processes[harq_pid]->C/8+1);j++) {
-      ldpc_encoder_optim_8seg_multi(dlsch->harq_processes[harq_pid]->c,dlsch->harq_processes[harq_pid]->d,*Zc,Kb,Kr,BG,dlsch->harq_processes[harq_pid]->C,j,NULL,NULL,NULL,NULL);
+      impp.macro_num=j;
+      nrLDPC_encoder(dlsch->harq_processes[harq_pid]->c,dlsch->harq_processes[harq_pid]->d,*Zc,Kb,Kr,BG,&impp);
     }
 
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
index 3945439a45..c58941b077 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
@@ -37,8 +37,7 @@
 #include "PHY/CODING/coding_extern.h"
 #include "PHY/CODING/coding_defs.h"
 #include "PHY/CODING/lte_interleaver_inline.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/NR_TRANSPORT/nr_ulsch.h"
 #include "PHY/NR_TRANSPORT/nr_dlsch.h"
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index b3a95e313e..b81c01114d 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -41,8 +41,7 @@
 #include "SCHED_NR_UE/defs.h"
 #include "SIMULATION/TOOLS/sim.h"
 #include "executables/nr-uesoftmodem.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 //#define DEBUG_DLSCH_DECODING
 //#define ENABLE_PHY_PAYLOAD_DEBUG 1
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
index 2eb6dcd7fe..8b80b1b219 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
@@ -36,7 +36,7 @@
 #include "PHY/CODING/coding_defs.h"
 #include "PHY/CODING/coding_extern.h"
 #include "PHY/CODING/lte_interleaver_inline.h"
-#include "PHY/CODING/nrLDPC_encoder/defs.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/NR_UE_TRANSPORT/nr_transport_ue.h"
 #include "common/utils/LOG/vcd_signal_dumper.h"
 
@@ -353,8 +353,11 @@ opp_enabled=0;
       printf("%d \n",  harq_process->d[0][cnt]);
       }
       printf("\n");*/
+    encoder_implemparams_t impp;
+    impp.n_segments=harq_process->C;
+    impp.macro_num=0;
 
-    ldpc_encoder_optim_8seg(harq_process->c,harq_process->d,*pz,Kb,Kr,BG,harq_process->C,NULL,NULL,NULL,NULL);
+    nrLDPC_encoder(harq_process->c,harq_process->d,*pz,Kb,Kr,BG,&impp);
 
     //stop_meas(te_stats);
     //printf("end ldpc encoder -- output\n");
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index 3c0f0db8da..fc81f4d74b 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -40,7 +40,7 @@
 #include "PHY/NR_TRANSPORT/nr_transport_common_proto.h"
 #include "PHY/impl_defs_top.h"
 #include "PHY/defs_common.h"
-#include "PHY/CODING/nrLDPC_decoder/nrLDPC_decoder.h"
+#include "PHY/CODING/nrLDPC_extern.h"
 #include "PHY/CODING/nrLDPC_decoder/nrLDPC_types.h"
 
 #define MAX_NUM_RU_PER_gNB MAX_NUM_RU_PER_eNB
diff --git a/targets/ARCH/COMMON/common_lib.c b/targets/ARCH/COMMON/common_lib.c
index 757ad6f75d..3066f0906f 100644
--- a/targets/ARCH/COMMON/common_lib.c
+++ b/targets/ARCH/COMMON/common_lib.c
@@ -37,6 +37,7 @@
 #include 
 
 #include "common_lib.h"
+#include "assertions.h"
 #include "common/utils/load_module_shlib.h"
 #include "common/utils/LOG/log.h"
 #include "targets/RT/USER/lte-softmodem.h"
@@ -91,38 +92,44 @@ int load_lib(openair0_device *device,
 {
   loader_shlibfunc_t shlib_fdesc[1];
   int ret=0;
-  char *libname;
+  char *deflibname=OAI_RF_LIBNAME;
   
   openair0_cfg->recplay_mode = read_recplayconfig(&(openair0_cfg->recplay_conf),&(device->recplay_state));
 
   if ( openair0_cfg->recplay_mode == RECPLAY_REPLAYMODE ) {
-  	  libname=OAI_IQPLAYER_LIBNAME;
+  	  deflibname=OAI_IQPLAYER_LIBNAME;
   	  shlib_fdesc[0].fname="device_init";
   	  set_softmodem_optmask(SOFTMODEM_RECPLAY_BIT);  // softmodem has to know we use the iqplayer to workaround randomized algorithms
   } else  if ( IS_SOFTMODEM_BASICSIM ) {
-	  libname=OAI_BASICSIM_LIBNAME;
+	  deflibname=OAI_BASICSIM_LIBNAME;
 	  shlib_fdesc[0].fname="device_init";
   } else if (IS_SOFTMODEM_RFSIM && flag == RAU_LOCAL_RADIO_HEAD) {
-	  libname=OAI_RFSIM_LIBNAME;
+	  deflibname=OAI_RFSIM_LIBNAME;
 	  shlib_fdesc[0].fname="device_init";
   } else if (flag == RAU_LOCAL_RADIO_HEAD) {
 	  if (IS_SOFTMODEM_RFSIM)
-		  libname="rfsimulator";
+		  deflibname="rfsimulator";
 	  else
-          libname=OAI_RF_LIBNAME;
+          deflibname=OAI_RF_LIBNAME;
       shlib_fdesc[0].fname="device_init";
   } else {
-	  libname=OAI_TP_LIBNAME;
+	  deflibname=OAI_TP_LIBNAME;
 	  shlib_fdesc[0].fname="transport_init";
   }
-  ret=load_module_shlib(libname,shlib_fdesc,1,NULL);
+  
+  char *devname=NULL;
+  paramdef_t device_params[]=DEVICE_PARAMS_DESC ;
+  int numparams = sizeof(device_params)/sizeof(paramdef_t);
+  int devname_pidx = config_paramidx_fromname(device_params,numparams, CONFIG_DEVICEOPT_NAME);
+  device_params[devname_pidx].defstrval=deflibname;
+  
+  config_get(device_params,numparams,DEVICE_SECTION);
+  
+  ret=load_module_shlib(devname,shlib_fdesc,1,NULL);
+  AssertFatal( (ret >= 0),
+  	           "Library %s couldn't be loaded\n",devname);
 
-  if (ret < 0) {
-    LOG_E(HW,"Library %s couldn't be loaded\n",libname);
-  } else {
-    ret=((devfunc_t)shlib_fdesc[0].fptr)(device,openair0_cfg,cfg);
-  }
-  return ret;
+  return ((devfunc_t)shlib_fdesc[0].fptr)(device,openair0_cfg,cfg);
 }
 
 
diff --git a/targets/ARCH/COMMON/common_lib.h b/targets/ARCH/COMMON/common_lib.h
index 7e51bdc81a..ecadb68c0c 100644
--- a/targets/ARCH/COMMON/common_lib.h
+++ b/targets/ARCH/COMMON/common_lib.h
@@ -448,6 +448,24 @@ typedef struct {
 extern "C"
 {
 #endif
+
+
+#define  DEVICE_SECTION   "device"
+#define  CONFIG_HLP_DEVICE  "Identifies the oai device (the interface to RF) to use, the shared lib \"lib_.so\" will be loaded"
+
+#define  CONFIG_DEVICEOPT_NAME "name"
+
+/* inclusion for device configuration */
+/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+/*                                            config parameters for oai device                                                                                               */
+/*   optname                     helpstr                paramflags                      XXXptr                  defXXXval                            type           numelt   */
+/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
+#define DEVICE_PARAMS_DESC {\
+    { CONFIG_DEVICEOPT_NAME,      CONFIG_HLP_DEVICE,          0,                strptr:&devname,                 defstrval:NULL,         TYPE_STRING,     0}\
+}
+
+
+
 /*! \brief get device name from device type */
 char *get_devname(int devtype);
 /*! \brief Initialize openair RF target. It returns 0 if OK */
diff --git a/targets/ARCH/COMMON/record_player.h b/targets/ARCH/COMMON/record_player.h
index 903dda006b..500acdd709 100644
--- a/targets/ARCH/COMMON/record_player.h
+++ b/targets/ARCH/COMMON/record_player.h
@@ -37,19 +37,6 @@
 extern "C"
 {
 #endif
-#define CONFIG_OPT_RECPLAY "enable_recplay"
-
-#define  CONFIG_HLP_RECPLAY  "Allow record player"
-#define USRP_SECTION "device.usrp"
-/* inclusion for device configuration */
-/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-/*                                            command line parameters for USRP record/playback                                                                               */
-/*   optname                     helpstr                paramflags                      XXXptr                  defXXXval                            type           numelt   */
-/*---------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
-#define DEVICE_PARAMS_DESC {  \
-    {CONFIG_OPT_RECPLAY,      CONFIG_HLP_RECPLAY, PARAMFLAG_BOOL,   uptr:&enable_recplay,                 defuintval:0,                    TYPE_UINT,     0} \
-  }
-
 
 /* inclusions for record player */
 #define RECPLAY_DISABLED     0
@@ -114,7 +101,7 @@ typedef struct {
     {CONFIG_OPT_SF_LOOPS,     CONFIG_HLP_SF_LOOPS,  0,                uptr:&((*recplay_conf)->u_sf_loops),                defintval:DEF_SF_NB_LOOP,        TYPE_UINT,   0}, \
     {CONFIG_OPT_SF_RDELAY,    CONFIG_HLP_SF_RDELAY, 0,                uptr:&((*recplay_conf)->u_sf_read_delay),           defintval:DEF_SF_DELAY_READ,     TYPE_UINT,   0}, \
     {CONFIG_OPT_SF_WDELAY,    CONFIG_HLP_SF_WDELAY, 0,                uptr:&((*recplay_conf)->u_sf_write_delay),          defintval:DEF_SF_DELAY_WRITE,    TYPE_UINT,   0}, \
-  }/*! \brief USRP Configuration and state */
+  }/*! \brief Record Player Configuration and state */
 typedef struct {
   char            u_sf_filename[1024];              // subframes file path
   unsigned int    u_sf_max ;                  // max number of recorded subframes
diff --git a/targets/ARCH/iqplayer/iqplayer_lib.c b/targets/ARCH/iqplayer/iqplayer_lib.c
index beb05de3fd..c4133d1b11 100644
--- a/targets/ARCH/iqplayer/iqplayer_lib.c
+++ b/targets/ARCH/iqplayer/iqplayer_lib.c
@@ -25,6 +25,7 @@
  */
 #define _LARGEFILE_SOURCE
 #define _FILE_OFFSET_BITS 64
+#define NB_ANTENNAS_RX  2
 #include 
 #include 
 #include 
@@ -45,7 +46,9 @@
 
 
 static void parse_iqfile_header(openair0_device *device, iqfile_header_t *iq_fh) {
-  AssertFatal((memcmp(iq_fh->oaiid,OAIIQFILE_ID,sizeof(OAIIQFILE_ID)) == 0),"iqfile doesn't seem to be compatible with oai (invalid id in header)\n");
+  AssertFatal((memcmp(iq_fh->oaiid,OAIIQFILE_ID,sizeof(OAIIQFILE_ID)) == 0),
+  	           "iqfile doesn't seem to be compatible with oai (invalid id %.4s in header)\n",
+  	           iq_fh->oaiid);
   device->type = iq_fh->devtype;
   device->openair0_cfg[0].tx_sample_advance=iq_fh->tx_sample_advance;
   device->openair0_cfg[0].tx_bw =  device->openair0_cfg[0].rx_bw = iq_fh->bw;
@@ -138,6 +141,13 @@ static int iqplayer_loadfile(openair0_device *device, openair0_config_t *openair
   return 0;
 }
 
+/*! \brief start the oai iq player
+ * \param device, the hardware used
+ */
+static int trx_iqplayer_start(openair0_device *device){
+	return 0;
+}
+
 /*! \brief Terminate operation of the oai iq player
  * \param device, the hardware used
  */
@@ -287,7 +297,7 @@ static int trx_iqplayer_read(openair0_device *device, openair0_timestamp *ptimes
 
 int device_init(openair0_device *device, openair0_config_t *openair0_cfg) {
   device->openair0_cfg = openair0_cfg;
-  device->trx_start_func = NULL;
+  device->trx_start_func = trx_iqplayer_start;
   device->trx_get_stats_func = NULL;
   device->trx_reset_stats_func = NULL;
   device->trx_end_func   = trx_iqplayer_end;
diff --git a/targets/RT/USER/lte-ru.c b/targets/RT/USER/lte-ru.c
index f88d98536d..6d1a3b8cb2 100644
--- a/targets/RT/USER/lte-ru.c
+++ b/targets/RT/USER/lte-ru.c
@@ -2194,7 +2194,9 @@ int start_rf(RU_t *ru) {
 }
 
 int stop_rf(RU_t *ru) {
-  ru->rfdevice.trx_end_func(&ru->rfdevice);
+    if(ru->rfdevice.trx_end_func != NULL) {
+      ru->rfdevice.trx_end_func(&ru->rfdevice);
+    }
   return 0;
 }
 

From d4a81bcc0f611b70fe77c6bdf6c00845de1578df Mon Sep 17 00:00:00 2001
From: Hongzhi Wang 
Date: Mon, 9 Mar 2020 16:12:23 +0100
Subject: [PATCH 51/73] update dlsch multi thread

---
 .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c   | 27 +++++++++++--------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index 7a23ce7167..b8b5ed7654 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -581,13 +581,13 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
 
       // Fixme: correct type is unsigned, but nrLDPC_decoder and all called behind use signed int
       if (check_crc((uint8_t*)llrProcBuf,length_dec,harq_process->F,crc_type)) {
-        LOG_D(PHY,"Segment %u CRC OK\n\033[0m",r);
+        LOG_I(PHY,"Segment %u CRC OK\n\033[0m",r);
         //Temporary hack
         no_iteration_ldpc = dlsch->max_ldpc_iterations;
         ret = no_iteration_ldpc;
       }
       else {
-        LOG_D(PHY,"CRC NOK\n\033[0m");
+        LOG_I(PHY,"CRC NOK\n\033[0m");
         ret = 1 + dlsch->max_ldpc_iterations;
       }
 
@@ -799,13 +799,12 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
   uint32_t Tbslbrm = 950984;
   uint16_t nb_rb = 30;
   double Coderate = 0.0;
-  nfapi_nr_dl_config_dlsch_pdu_rel15_t *dl_config_pdu = &harq_processes[harq_pid]->dl_config_pdu
-  uint8_t dmrs_type = dl_config_pdu->dmrsConfigType;
+  uint8_t dmrs_type = harq_process->dmrsConfigType;
   //nfapi_nr_config_request_t *cfg = &phy_vars_ue->nrUE_config;
   //uint8_t dmrs_type = cfg->pdsch_config.dmrs_type.value;
 
   uint8_t nb_re_dmrs = (dmrs_type==1)?6:4;
-  uint16_t length_dmrs = get_num_dmrs(dl_config_pdu->dlDmrsSymbPos); 
+  uint16_t length_dmrs = get_num_dmrs(harq_process->dlDmrsSymbPos); 
 
   uint32_t i,j;
 //  int nbDlProcessing =0;
@@ -861,7 +860,8 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
 
   A = harq_process->TBS;
 
-  ret = dlsch->max_ldpc_iterations;
+  ret = dlsch->max_ldpc_iterations + 1;
+  dlsch->last_iteration_cnt = ret;
 
   harq_process->G = nr_get_G(nb_rb, nb_symb_sch, nb_re_dmrs, length_dmrs, harq_process->Qm,harq_process->Nl);
 
@@ -929,9 +929,10 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
                       &harq_process->F,
                       p_decParams->BG);
 
-      p_decParams->Z = harq_process->Z;
 
     }
+    
+    p_decParams->Z = harq_process->Z;
 
   //printf("coderate %f kc %d \n", Coderate, kc);
   p_decParams->numMaxIter = dlsch->max_ldpc_iterations;
@@ -1149,11 +1150,13 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
         pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j]));
       }
 
-      for (i=Kr_bytes,j=K_bytes_F-((2*p_decParams->Z)>>3); i < ((kc*p_decParams->Z)>>3); i++, j++)
+      j+=(harq_process->F>>3);
+      //      for (i=Kr_bytes,j=K_bytes_F-((2*p_decParams->Z)>>3); i < ((kc*p_decParams->Z)>>3); i++, j++)
+      for (i=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++,j++)
       {
         pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j]));
       }
-
+      
       for (i=0, j=0; j < ((kc*p_decParams->Z)>>4);  i+=2, j++)
       {
         pl[j] = _mm_packs_epi16(pv[i],pv[i+1]);
@@ -1683,9 +1686,11 @@ void nr_dlsch_decoding_process(void *arg)
           pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j]));
         }
 
-        for (i=Kr_bytes,j=K_bytes_F-((2*p_decParams->Z)>>3); i < ((kc*p_decParams->Z)>>3); i++, j++)
+        j+=(harq_process->F>>3);
+        //      for (i=Kr_bytes,j=K_bytes_F-((2*p_decParams->Z)>>3); i < ((kc*p_decParams->Z)>>3); i++, j++)
+        for (i=Kr_bytes; i < ((kc*p_decParams->Z)>>3); i++,j++)
         {
-          pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j]));
+         pv[i]= _mm_loadu_si128((__m128i*)(&harq_process->d[r][8*j]));
         }
 
         for (i=0, j=0; j < ((kc*p_decParams->Z)>>4);  i+=2, j++)

From 7b9be8744da4354054c0c4e4479998b839691d64 Mon Sep 17 00:00:00 2001
From: magounak 
Date: Fri, 13 Mar 2020 10:46:40 +0100
Subject: [PATCH 52/73] bug fix ue dlsch thread

---
 openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index b8b5ed7654..d3003da094 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -1483,7 +1483,7 @@ void nr_dlsch_decoding_process(void *arg)
   }    
 
   harq_process->round  =0;
-  if (harq_process->round == 0) {
+ // if (harq_process->round == 0) {
     // This is a new packet, so compute quantities regarding segmentation
 	if (A > 3824)
 	  harq_process->B = A+24;
@@ -1501,7 +1501,7 @@ void nr_dlsch_decoding_process(void *arg)
 
     p_decParams->Z = harq_process->Z;
 
-    }
+   // }
     
     //printf("round %d Z %d K %d BG %d\n", harq_process->round, p_decParams->Z, harq_process->K, p_decParams->BG);
 

From 9cf9ea7c99edcf1c20f3b450c5c56709c00b3ac1 Mon Sep 17 00:00:00 2001
From: Raymond Knopp 
Date: Sat, 14 Mar 2020 13:50:07 +0100
Subject: [PATCH 53/73] remainder of merge

---
 executables/nr-softmodem.c                    | 15 -----
 executables/nr-ue.c                           | 13 +---
 executables/softmodem-common.c                | 64 -------------------
 openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c |  3 -
 openair1/PHY/TOOLS/Makefile                   |  4 --
 5 files changed, 1 insertion(+), 98 deletions(-)

diff --git a/executables/nr-softmodem.c b/executables/nr-softmodem.c
index 4534761d87..04c515e556 100644
--- a/executables/nr-softmodem.c
+++ b/executables/nr-softmodem.c
@@ -859,10 +859,6 @@ if(!IS_SOFTMODEM_NOS1)
   if(IS_SOFTMODEM_NOS1)
 	  init_pdcp();
 
-<<<<<<< HEAD
-
-=======
->>>>>>> origin/develop
   if (RC.nb_nr_inst > 0)  {
     // don't create if node doesn't connect to RRC/S1/GTP
     AssertFatal(create_gNB_tasks(1) == 0,"cannot create ITTI tasks\n");
@@ -871,11 +867,6 @@ if(!IS_SOFTMODEM_NOS1)
     RCconfig_L1();
   }
 
-<<<<<<< HEAD
-
-  
-=======
->>>>>>> origin/develop
   /* Start the agent. If it is turned off in the configuration, it won't start */
   /*
   RCconfig_nr_flexran();
@@ -995,11 +986,6 @@ if(!IS_SOFTMODEM_NOS1)
   oai_exit=1;
   printf("oai_exit=%d\n",oai_exit);
 
-<<<<<<< HEAD
-  printf("Terminating application - oai_exit=%d\n",oai_exit);
-#endif
-  // stop threads  
-=======
   // stop threads
 /*#ifdef XFORMS
 
@@ -1022,7 +1008,6 @@ if(!IS_SOFTMODEM_NOS1)
     }
 
 #endif*/
->>>>>>> origin/develop
   printf("stopping MODEM threads\n");
   // cleanup
   stop_gNB(NB_gNB_INST);
diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index d4ace2ce68..40d33b701e 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -460,7 +460,7 @@ void processSlotRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) {
     LOG_D(PHY,"phy_procedures_nrUE_RX: slot:%d, time %lu\n", proc->nr_tti_rx, (rdtsc()-a)/3500);
     //printf(">>> nr_ue_pdcch_procedures ended\n");
 #endif
-<<<<<<< HEAD
+
     if(IS_SOFTMODEM_NOS1){ //&& proc->nr_tti_rx==1
       //Hardcoded rnti value
       protocol_ctxt_t ctxt;
@@ -468,18 +468,7 @@ void processSlotRX( PHY_VARS_NR_UE *UE, UE_nr_rxtx_proc_t *proc) {
 				     0x1234, proc->frame_rx,
 				     proc->nr_tti_rx, 0);
       pdcp_run(&ctxt);
-      pdcp_fifo_flush_sdus(&ctxt);
     }
-=======
-  if(IS_SOFTMODEM_NOS1){ //&& proc->nr_tti_rx==1
-	  //Hardcoded rnti value
-	  protocol_ctxt_t ctxt;
-	  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, UE->Mod_id, ENB_FLAG_NO,
-                                   0x1234, proc->frame_rx,
-                                   proc->nr_tti_rx, 0);
-	  pdcp_run(&ctxt);
-  }
->>>>>>> origin/develop
   }
 
   
diff --git a/executables/softmodem-common.c b/executables/softmodem-common.c
index b901fe0c64..0a4e94571f 100644
--- a/executables/softmodem-common.c
+++ b/executables/softmodem-common.c
@@ -61,69 +61,6 @@ softmodem_params_t *get_softmodem_params(void) {
   return &softmodem_params;
 }
 
-<<<<<<< HEAD
-void softmodem_printresources(int sig, telnet_printfunc_t pf) {
-   struct rusage usage;
-   struct timespec stop;
-
-   clock_gettime(CLOCK_BOOTTIME, &stop);
-
-   uint64_t elapse = (stop.tv_sec - start.tv_sec) ;   // in seconds
-
-
-   int st = getrusage(RUSAGE_SELF,&usage);
-   if (!st) {
-   	 pf("\nRun time: %lluh %llus\n",(unsigned long long)elapse/3600,(unsigned long long)(elapse - (elapse/3600)));
-     pf("\tTime executing user inst.: %lds %ldus\n",(long)usage.ru_utime.tv_sec,(long)usage.ru_utime.tv_usec);
-     pf("\tTime executing system inst.: %lds %ldus\n",(long)usage.ru_stime.tv_sec,(long)usage.ru_stime.tv_usec);
-     pf("\tMax. Phy. memory usage: %ldkB\n",(long)usage.ru_maxrss);
-     pf("\tPage fault number (no io): %ld\n",(long)usage.ru_minflt);
-     pf("\tPage fault number (requiring io): %ld\n",(long)usage.ru_majflt);
-     pf("\tNumber of file system read: %ld\n",(long)usage.ru_inblock);
-     pf("\tNumber of filesystem write: %ld\n",(long)usage.ru_oublock);
-     pf("\tNumber of context switch (process origin, io...): %ld\n",(long)usage.ru_nvcsw);
-     pf("\tNumber of context switch (os origin, priority...): %ld\n",(long)usage.ru_nivcsw);
-   } 
-}
-
-void signal_handler(int sig) {
-  void *array[10];
-  size_t size;
-
-  if (sig==SIGSEGV) {
-    // get void*'s for all entries on the stack
-    size = backtrace(array, 10);
-    // print out all the frames to stderr
-    fprintf(stderr, "Error: signal %d:\n", sig);
-    backtrace_symbols_fd(array, size, 2);
-    exit(-1);
-  } else {
-  	if(sig==SIGINT ||sig==SOFTMODEM_RTSIGNAL)
-  		softmodem_printresources(sig,(telnet_printfunc_t)printf);
-  	if (sig != SOFTMODEM_RTSIGNAL) {
-      printf("Linux signal %s...\n",strsignal(sig));
-      exit_function(__FILE__, __FUNCTION__, __LINE__,"softmodem starting exit procedure\n");
-    }
-  }
-}
-
-
-
-void set_softmodem_sighandler(void) {
-  struct sigaction	act,oldact;
-  clock_gettime(CLOCK_BOOTTIME, &start);
-  memset(&act,0,sizeof(act));
-  act.sa_handler=signal_handler;
-  sigaction(SOFTMODEM_RTSIGNAL,&act,&oldact);
-  printf("Send signal %d to display resource usage...\n",SIGRTMIN+1);
-  signal(SIGSEGV, signal_handler);
-  signal(SIGINT,  signal_handler);
-  signal(SIGTERM, signal_handler);
-  signal(SIGABRT, signal_handler);	
-}
-#ifndef PHYSICAL_SIMULATOR
-void get_common_options(void) {
-=======
 int32_t check_execmask(uint64_t execmask) {
   char *softmodemfunc=map_int_to_str(softmodem_funcs, execmask);
   if (softmodemfunc != NULL) {
@@ -144,7 +81,6 @@ char *get_softmodem_function(uint64_t *sofmodemfunc_mask_ptr) {
 }
 
 void get_common_options(uint32_t execmask) {
->>>>>>> origin/develop
   uint32_t online_log_messages;
   uint32_t glog_level ;
   uint32_t start_telnetsrv = 0;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
index 3030a4b974..f56dd1757d 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
@@ -727,8 +727,6 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
       
     }
   }
-<<<<<<< HEAD
-=======
 
 #ifdef DEBUG_ULSCH_DECODING
   LOG_I(PHY, "Decoder output (payload): \n");
@@ -739,7 +737,6 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
   }
 #endif
 
->>>>>>> origin/develop
   ulsch->last_iteration_cnt = ret;
 
   return(ret);
diff --git a/openair1/PHY/TOOLS/Makefile b/openair1/PHY/TOOLS/Makefile
index db20bc834e..c71717dc87 100644
--- a/openair1/PHY/TOOLS/Makefile
+++ b/openair1/PHY/TOOLS/Makefile
@@ -1,9 +1,5 @@
 lte_dfts_sse4: lte_dfts.c
-<<<<<<< HEAD
-	gcc -O2 -std=gnu99 -msse4.1 -g -ggdb -o lte_dfts_sse4 lte_dfts.c time_meas.c  ../../SIMULATION/TOOLS/taus.c $$OPENAIR_HOME/common/utils/backtrace.c -I$$OPENAIR_HOME -I$$OPENAIR1_DIR -I$$OPENAIR_TARGETS -I$$OPENAIR2_DIR -I$$OPENAIR2_DIR/COMMON -I$$OPENAIR_HOME/common/utils -I$$OPENAIR_HOME/common/utils/T -DMR_MAIN -DNB_ANTENNAS_RX=1 -lm -lpthread # -DD256STATS #-DD64STATS
-=======
 	gcc-7 -O3 -std=gnu99 -msse4.1 -o lte_dfts_sse4 lte_dfts.c time_meas.c  ../../SIMULATION/TOOLS/taus.c -I$$OPENAIR_HOME -I$$OPENAIR1_DIR -I$$OPENAIR_TARGETS -I$$OPENAIR2_DIR -I$$OPENAIR2_DIR/COMMON -I$$OPENAIR_HOME/common/utils -I$$OPENAIR_HOME/common/utils/T -DMR_MAIN -DNB_ANTENNAS_RX=1 -lm -lpthread # -DD256STATS #-DD64STATS
->>>>>>> origin/develop-nr
 
 lte_dfts_avx2: lte_dfts.c
 	gcc -O2 -std=gnu99 -mavx2 -g -ggdb -o lte_dfts_avx2 lte_dfts.c time_meas.c ../../SIMULATION/TOOLS/taus.c $$OPENAIR_HOME/common/utils/backtrace.c -I$$OPENAIR_HOME -I$$OPENAIR1_DIR -I$$OPENAIR_TARGETS -I$$OPENAIR2_DIR -I$$OPENAIR2_DIR/COMMON -I$$OPENAIR_HOME/common/utils -I$$OPENAIR_HOME/common/utils/T -DMR_MAIN -DNB_ANTENNAS_RX=1 -lm -lpthread # -DD256STATS #-DD64STATS

From 6dff67430229834ec00098f17b50c57b528ebd0a Mon Sep 17 00:00:00 2001
From: Raymond Knopp 
Date: Sun, 15 Mar 2020 18:03:42 +0100
Subject: [PATCH 54/73] testing after merge with develo

---
 cmake_targets/autotests/test_case_list.xml    | 20 +++---
 executables/softmodem-common.c                | 61 ++++++++++++++++++-
 .../PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c   |  4 +-
 openair1/SCHED_NR_UE/fapi_nr_ue_l1.c          |  1 -
 openair1/SIMULATION/NR_PHY/dlsim.c            | 52 ++++------------
 openair1/SIMULATION/NR_PHY/prachsim.c         |  7 +++
 openair1/SIMULATION/NR_PHY/ulsim.c            | 53 +++++-----------
 openair2/LAYER2/NR_MAC_UE/mac_defs.h          |  2 -
 8 files changed, 104 insertions(+), 96 deletions(-)

diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml
index 3a02cfe30c..6e96bb3b99 100644
--- a/cmake_targets/autotests/test_case_list.xml
+++ b/cmake_targets/autotests/test_case_list.xml
@@ -1082,15 +1082,13 @@
       nr_dlsim Test cases. (Test1: 106 PRB),
                                  (Test2: 217 PRB),
                                  (Test3: 273 PRB),
-                                 (Test4: 106 PRB 12 CSET-Offset),
-                                 (Test5: 217 PRB 48 CSET-Offset),
-                                 (Test6: 106 PRB 25 PDSCH-Offset),
-                                 (Test7: 106 PRB 51 PDSCH-Offset),
-                                 (Test8: 217 PRB 100 PDSCH-PRBs),
-                                 (Test9: 217 PRB 80 PDSCH-Offset),
-                                 (Test10: 217 PRB 100 PDSCH-PRBs 110 PDSCH-Offset),
-                                 (Test11: 106 PRBs 50 PDSCH-PRBs MCS Index 27)
-                                 (Test12: 106 PRBs 50 PDSCH-PRBs MCS Index 16)
+                                 (Test4: 106 PRB 25 PDSCH-Offset),
+                                 (Test5: 106 PRB 51 PDSCH-Offset),
+                                 (Test6: 217 PRB 100 PDSCH-PRBs),
+                                 (Test7: 217 PRB 80 PDSCH-Offset),
+                                 (Test8: 217 PRB 100 PDSCH-PRBs 110 PDSCH-Offset),
+                                 (Test9: 106 PRBs 50 PDSCH-PRBs MCS Index 27)
+                                 (Test10: 106 PRBs 50 PDSCH-PRBs MCS Index 16)
       
       $OPENAIR_DIR/cmake_targets/build_oai
        --phy_simulators  -c 
@@ -1100,14 +1098,12 @@
       -n100 -R106 -b106 -s5
 		  -n100 -R217 -b217 -s5
 		  -n100 -R273 -b273 -s5
-                  -n100 -R106 -o12 -s5
-                  -n100 -R217 -o48 -s5
                   -n100 -R106 -a25 -s5
                   -n100 -R106 -a51 -s5
                   -n100 -R217 -b100 -s5
                   -n100 -R217 -a80 -s5
                   -n100 -R217 -a110 -s5 -b100
-                  -n100 -e27 -s20 
+                  -n100 -e27 -s30 
                   -n100 -e16 -s10 
       
       nr_dlsim.test1 nr_dlsim.test2 nr_dlsim.test3 nr_dlsim.test4 nr_dlsim.test5 nr_dlsim.test6 nr_dlsim.test7 nr_dlsim.test8 nr_dlsim.test9 nr_dlsim.test10 nr_dlsim.test11 nr_dlsim.test12
diff --git a/executables/softmodem-common.c b/executables/softmodem-common.c
index 0a4e94571f..f714fa2bd4 100644
--- a/executables/softmodem-common.c
+++ b/executables/softmodem-common.c
@@ -144,4 +144,63 @@ void get_common_options(uint32_t execmask) {
 
   if(worker_config != NULL)   set_worker_conf(worker_config);
 }
-#endif
+void softmodem_printresources(int sig, telnet_printfunc_t pf) {
+   struct rusage usage;
+   struct timespec stop;
+
+   clock_gettime(CLOCK_BOOTTIME, &stop);
+
+   uint64_t elapse = (stop.tv_sec - start.tv_sec) ;   // in seconds
+
+
+   int st = getrusage(RUSAGE_SELF,&usage);
+   if (!st) {
+   	 pf("\nRun time: %lluh %llus\n",(unsigned long long)elapse/3600,(unsigned long long)(elapse - (elapse/3600)));
+     pf("\tTime executing user inst.: %lds %ldus\n",(long)usage.ru_utime.tv_sec,(long)usage.ru_utime.tv_usec);
+     pf("\tTime executing system inst.: %lds %ldus\n",(long)usage.ru_stime.tv_sec,(long)usage.ru_stime.tv_usec);
+     pf("\tMax. Phy. memory usage: %ldkB\n",(long)usage.ru_maxrss);
+     pf("\tPage fault number (no io): %ld\n",(long)usage.ru_minflt);
+     pf("\tPage fault number (requiring io): %ld\n",(long)usage.ru_majflt);
+     pf("\tNumber of file system read: %ld\n",(long)usage.ru_inblock);
+     pf("\tNumber of filesystem write: %ld\n",(long)usage.ru_oublock);
+     pf("\tNumber of context switch (process origin, io...): %ld\n",(long)usage.ru_nvcsw);
+     pf("\tNumber of context switch (os origin, priority...): %ld\n",(long)usage.ru_nivcsw);
+   } 
+}
+
+void signal_handler(int sig) {
+  void *array[10];
+  size_t size;
+
+  if (sig==SIGSEGV) {
+    // get void*'s for all entries on the stack
+    size = backtrace(array, 10);
+    // print out all the frames to stderr
+    fprintf(stderr, "Error: signal %d:\n", sig);
+    backtrace_symbols_fd(array, size, 2);
+    exit(-1);
+  } else {
+  	if(sig==SIGINT ||sig==SOFTMODEM_RTSIGNAL)
+  		softmodem_printresources(sig,(telnet_printfunc_t)printf);
+  	if (sig != SOFTMODEM_RTSIGNAL) {
+      printf("Linux signal %s...\n",strsignal(sig));
+      exit_function(__FILE__, __FUNCTION__, __LINE__,"softmodem starting exit procedure\n");
+    }
+  }
+}
+
+
+
+void set_softmodem_sighandler(void) {
+  struct sigaction	act,oldact;
+  clock_gettime(CLOCK_BOOTTIME, &start);
+  memset(&act,0,sizeof(act));
+  act.sa_handler=signal_handler;
+  sigaction(SOFTMODEM_RTSIGNAL,&act,&oldact);
+  printf("Send signal %d to display resource usage...\n",SIGRTMIN+1);
+  signal(SIGSEGV, signal_handler);
+  signal(SIGINT,  signal_handler);
+  signal(SIGTERM, signal_handler);
+  signal(SIGABRT, signal_handler);	
+}
+
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index d3003da094..cfdae15b65 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -581,13 +581,13 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
 
       // Fixme: correct type is unsigned, but nrLDPC_decoder and all called behind use signed int
       if (check_crc((uint8_t*)llrProcBuf,length_dec,harq_process->F,crc_type)) {
-        LOG_I(PHY,"Segment %u CRC OK\n\033[0m",r);
+        LOG_D(PHY,"Segment %u CRC OK\n\033[0m",r);
         //Temporary hack
         no_iteration_ldpc = dlsch->max_ldpc_iterations;
         ret = no_iteration_ldpc;
       }
       else {
-        LOG_I(PHY,"CRC NOK\n\033[0m");
+        LOG_D(PHY,"CRC NOK\n\033[0m");
         ret = 1 + dlsch->max_ldpc_iterations;
       }
 
diff --git a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
index c6a830a8da..69876159d6 100644
--- a/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
+++ b/openair1/SCHED_NR_UE/fapi_nr_ue_l1.c
@@ -51,7 +51,6 @@ int8_t nr_ue_scheduled_response(nr_scheduled_response_t *scheduled_response)
     uint8_t cc_id = scheduled_response->CC_id;
     uint32_t i;
     int slot = scheduled_response->slot; 	
-    
     // Note: we have to handle the thread IDs for this. To be revisited completely.
     uint8_t thread_id = PHY_vars_UE_g[module_id][cc_id]->current_thread_id[slot];
     NR_UE_PDCCH *pdcch_vars = PHY_vars_UE_g[module_id][cc_id]->pdcch_vars[thread_id][0];
diff --git a/openair1/SIMULATION/NR_PHY/dlsim.c b/openair1/SIMULATION/NR_PHY/dlsim.c
index c0976d254f..ebcedbaeb0 100644
--- a/openair1/SIMULATION/NR_PHY/dlsim.c
+++ b/openair1/SIMULATION/NR_PHY/dlsim.c
@@ -80,6 +80,7 @@ int sf_ahead=4 ;
 int sl_ahead=0;
 uint8_t nfapi_mode = 0;
 uint16_t NB_UE_INST = 1;
+uint64_t downlink_frequency[MAX_NUM_CCs][4];
 
 // dummy functions
 int dummy_nr_ue_ul_indication(nr_uplink_indication_t *ul_info)              { return(0);  }
@@ -97,13 +98,17 @@ int8_t nr_mac_rrc_data_ind_ue(const module_id_t     module_id,
 }
 
 
-//Dummy Functions
-
-//lte_subframe_t subframe_select(LTE_DL_FRAME_PARMS *frame_parms, unsigned char subframe) {return(SF_DL);}
-int rlc_module_init (int eNB_id) {return(0);}
-
-
 void pdcp_layer_init(void) {}
+boolean_t
+pdcp_data_ind(
+  const protocol_ctxt_t *const ctxt_pP,
+  const srb_flag_t   srb_flagP,
+  const MBMS_flag_t  MBMS_flagP,
+  const rb_id_t      rb_idP,
+  const sdu_size_t   sdu_buffer_sizeP,
+  mem_block_t *const sdu_buffer_pP
+) { return(false);}
+
 int rrc_init_nr_global_param(void){return(0);}
 
 void config_common(int Mod_idP,
@@ -111,28 +116,6 @@ void config_common(int Mod_idP,
 		   NR_ServingCellConfigCommon_t *scc
 		   );
 
-mac_rlc_status_resp_t mac_rlc_status_ind(const module_id_t       module_idP,
-                                         const rnti_t            rntiP,
-                                         const eNB_index_t       eNB_index,
-                                         const frame_t           frameP,
-                                         const sub_frame_t       subframeP,
-                                         const eNB_flag_t        enb_flagP,
-                                         const MBMS_flag_t       MBMS_flagP,
-                                         const logical_chan_id_t channel_idP,
-                                         const tb_size_t         tb_sizeP,
-                                         const uint32_t          sourceL2Id,
-                                         const uint32_t          destinationL2Id) {mac_rlc_status_resp_t  mac_rlc_status_resp = {0}; return mac_rlc_status_resp;}
-tbs_size_t mac_rlc_data_req(const module_id_t       module_idP,
-                            const rnti_t            rntiP,
-                            const eNB_index_t       eNB_index,
-                            const frame_t           frameP,
-                            const eNB_flag_t        enb_flagP,
-                            const MBMS_flag_t       MBMS_flagP,
-                            const logical_chan_id_t channel_idP,
-                            const tb_size_t         tb_sizeP,
-                            char                    *buffer_pP,
-                            const uint32_t          sourceL2Id,
-                            const uint32_t          destinationL2Id) {return 0;}
 int generate_dlsch_header(unsigned char *mac_header,
                           unsigned char num_sdus,
                           unsigned short *sdu_lengths,
@@ -144,19 +127,6 @@ int generate_dlsch_header(unsigned char *mac_header,
                           unsigned short post_padding){return 0;}
 void nr_ip_over_LTE_DRB_preconfiguration(void){}
 
-void mac_rlc_data_ind     (
-  const module_id_t         module_idP,
-  const rnti_t              rntiP,
-  const eNB_index_t         eNB_index,
-  const frame_t             frameP,
-  const eNB_flag_t          enb_flagP,
-  const MBMS_flag_t         MBMS_flagP,
-  const logical_chan_id_t   channel_idP,
-  char                     *buffer_pP,
-  const tb_size_t           tb_sizeP,
-  num_tb_t                  num_tbP,
-  crc_t                    *crcs_pP)
-{}
 // needed for some functions
 openair0_config_t openair0_cfg[MAX_CARDS];
 
diff --git a/openair1/SIMULATION/NR_PHY/prachsim.c b/openair1/SIMULATION/NR_PHY/prachsim.c
index 1ec18858dc..5c00352515 100644
--- a/openair1/SIMULATION/NR_PHY/prachsim.c
+++ b/openair1/SIMULATION/NR_PHY/prachsim.c
@@ -73,6 +73,10 @@ int8_t nr_ue_get_SR(module_id_t module_idP, int CC_id, frame_t frameP, uint8_t e
   return 0;
 }
 
+uint8_t nr_ue_get_sdu(module_id_t module_idP, int CC_id, frame_t frameP,
+           sub_frame_t subframe, uint8_t eNB_index,
+           uint8_t *ulsch_buffer, uint16_t buflen, uint8_t *access_mode) {return(0);}
+
 int oai_nfapi_rach_ind(nfapi_rach_indication_t *rach_ind) {return(0);}
 
 openair0_config_t openair0_cfg[MAX_CARDS];
@@ -80,6 +84,9 @@ uint8_t nfapi_mode=0;
 NR_IF_Module_t *NR_IF_Module_init(int Mod_id){return(NULL);}
 int oai_nfapi_ul_config_req(nfapi_ul_config_request_t *ul_config_req) { return(0); }
 
+uint64_t get_softmodem_optmask(void) {
+  return 0;
+}
 
 int main(int argc, char **argv)
 {
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index f43709cac5..f98b9be7c6 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -67,44 +67,11 @@ int sl_ahead=0;
 double cpuf;
 uint8_t nfapi_mode = 0;
 uint16_t NB_UE_INST = 1;
+uint64_t downlink_frequency[MAX_NUM_CCs][4];
+
 
 int8_t nr_mac_rrc_data_ind_ue(const module_id_t module_id, const int CC_id, const uint8_t gNB_index,
                               const int8_t channel, const uint8_t* pduP, const sdu_size_t pdu_len) { return 0; }
-void mac_rlc_data_ind ( const module_id_t         module_idP,
-			const rnti_t              rntiP,
-			const eNB_index_t         eNB_index,
-			const frame_t             frameP,
-			const eNB_flag_t          enb_flagP,
-			const MBMS_flag_t         MBMS_flagP,
-			const logical_chan_id_t   channel_idP,
-			char                     *buffer_pP,
-			const tb_size_t           tb_sizeP,
-			num_tb_t                  num_tbP,
-			crc_t                    *crcs_pP){}
-mac_rlc_status_resp_t mac_rlc_status_ind( const module_id_t       module_idP,
-					  const rnti_t            rntiP,
-					  const eNB_index_t       eNB_index,
-					  const frame_t           frameP,
-					  const sub_frame_t 	  subframeP,
-					  const eNB_flag_t        enb_flagP,
-					  const MBMS_flag_t       MBMS_flagP,
-					  const logical_chan_id_t channel_idP,
-					  const tb_size_t         tb_sizeP,
-					  const uint32_t sourceL2Id,
-					  const uint32_t destinationL2Id)
-{mac_rlc_status_resp_t  mac_rlc_status_resp = {0}; return mac_rlc_status_resp;}
-tbs_size_t mac_rlc_data_req(  const module_id_t       module_idP,
-			      const rnti_t            rntiP,
-			      const eNB_index_t       eNB_index,
-			      const frame_t           frameP,
-			      const eNB_flag_t        enb_flagP,
-			      const MBMS_flag_t       MBMS_flagP,
-			      const logical_chan_id_t channel_idP,
-			      const tb_size_t         tb_sizeP,
-			      char             *buffer_pP,
-			      const uint32_t sourceL2Id,
-			      const uint32_t destinationL2Id )
-{return 0;}
 int generate_dlsch_header(unsigned char *mac_header,
                           unsigned char num_sdus,
                           unsigned short *sdu_lengths,
@@ -114,8 +81,16 @@ int generate_dlsch_header(unsigned char *mac_header,
                           unsigned char *ue_cont_res_id,
                           unsigned char short_padding,
                           unsigned short post_padding){return 0;}
-int rlc_module_init (int enb) {return(0);}
 void pdcp_layer_init (void) {}
+boolean_t pdcp_data_ind(
+  const protocol_ctxt_t *const ctxt_pP,
+  const srb_flag_t   srb_flagP,
+  const MBMS_flag_t  MBMS_flagP,
+  const rb_id_t      rb_idP,
+  const sdu_size_t   sdu_buffer_sizeP,
+  mem_block_t *const sdu_buffer_pP
+) { return(false);}
+
 void pdcp_run (const protocol_ctxt_t *const  ctxt_pP) { return;}
 void nr_ip_over_LTE_DRB_preconfiguration(void){}
 int rrc_init_nr_global_param(void){return(0);}
@@ -395,8 +370,9 @@ int main(int argc, char **argv)
 
   //memset((void *)&gNB->UL_INFO,0,sizeof(gNB->UL_INFO));
   gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list = (nfapi_rx_indication_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_rx_indication_pdu_t));
+  gNB->UL_INFO.crc_ind.crc_indication_body.crc_pdu_list = (nfapi_crc_indication_pdu_t *)malloc(NB_UE_INST*sizeof(nfapi_crc_indication_pdu_t));
   gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus = 0;
-
+  gNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs = 0;
   frame_parms = &gNB->frame_parms; //to be initialized I suppose (maybe not necessary for PBCH)
   frame_parms->nb_antennas_tx = n_tx;
   frame_parms->nb_antennas_rx = n_rx;
@@ -675,6 +651,9 @@ int main(int argc, char **argv)
         //----------------------------------------------------------
         //------------------- gNB phy procedures -------------------
         //----------------------------------------------------------
+        gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus = 0;
+        gNB->UL_INFO.crc_ind.crc_indication_body.number_of_crcs = 0;
+
         phy_procedures_gNB_common_RX(gNB, frame, slot);
 
 	if (n_trials==1)
diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
index 4cf39bcfdb..405ea95eb1 100755
--- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
@@ -167,8 +167,6 @@ typedef struct {
   RA_state_t ra_state;
   ///     RA-rnti
   uint16_t ra_rnti;
-  uint16_t crnti;
-
   ///     Temporary CRNTI
   uint16_t t_crnti;
   ///     CRNTI

From 93b4211d022f740efeee2c7966a3ccbd0b8484f4 Mon Sep 17 00:00:00 2001
From: Raymond Knopp 
Date: Sun, 15 Mar 2020 19:16:30 +0100
Subject: [PATCH 55/73] merge conflict removal

---
 openair1/PHY/INIT/nr_init.c    | 95 +++-------------------------------
 openair1/PHY/INIT/nr_init_ue.c |  3 --
 2 files changed, 8 insertions(+), 90 deletions(-)

diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index 216a83025f..d30c0dc874 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -154,19 +154,11 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
     }
   }
 
-<<<<<<< HEAD
   //------------- config PUSCH DMRS parameters(to be updated from RRC)--------------
   gNB->dmrs_UplinkConfig.pusch_dmrs_type = pusch_dmrs_type1;
   gNB->dmrs_UplinkConfig.pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
   gNB->dmrs_UplinkConfig.pusch_maxLength = pusch_len1;
   //--------------------------------------------------------------------------------
-=======
-  //------------- config PUSCH DMRS parameters(to be updated from RRC)--------------//
-  dmrs_Uplink_Config->pusch_dmrs_type = pusch_dmrs_type1;
-  dmrs_Uplink_Config->pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
-  dmrs_Uplink_Config->pusch_maxLength = pusch_len1;
-  //--------------------------------------------------------------------------------//
->>>>>>> origin/develop
 
   nr_init_pdsch_dmrs(gNB, cfg->cell_config.phy_cell_id.value);
 
@@ -234,7 +226,6 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
 */
   // PRACH
   prach_vars->prachF = (int16_t *)malloc16_clear( 1024*2*sizeof(int16_t) );
-<<<<<<< HEAD
   prach_vars->rxsigF = (int16_t **)malloc16_clear(Prx*sizeof(int16_t*));
   /* 
   for (i=0;irxdataF_ext2          = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_estimates       = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_estimates_ext   = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
+    pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates     = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
+    pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_estimates_time  = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->rxdataF_comp          = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
     pusch_vars[ULSCH_id]->ul_ch_mag0             = (int32_t **)malloc16(Prx*sizeof(int32_t *) );
@@ -268,55 +261,14 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
       pusch_vars[ULSCH_id]->ul_ch_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
       pusch_vars[ULSCH_id]->ul_ch_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
       pusch_vars[ULSCH_id]->ul_ch_estimates_time[i]  = (int32_t *)malloc16_clear( 2*sizeof(int32_t)*fp->ofdm_symbol_size );
+      pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2*fp->symbols_per_slot ); // max intensity in freq is 1 sc every 2 RBs
+      pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*fp->ofdm_symbol_size*2*fp->symbols_per_slot );
       pusch_vars[ULSCH_id]->rxdataF_comp[i]          = (int32_t *)malloc16_clear( sizeof(int32_t)*N_RB_UL*12*fp->symbols_per_slot );
       pusch_vars[ULSCH_id]->ul_ch_mag0[i]             = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
       pusch_vars[ULSCH_id]->ul_ch_magb0[i]            = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
       pusch_vars[ULSCH_id]->ul_ch_mag[i]             = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
       pusch_vars[ULSCH_id]->ul_ch_magb[i]            = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*N_RB_UL*12 );
       pusch_vars[ULSCH_id]->rho[i]                   = (int32_t *)malloc16_clear( sizeof(int32_t)*(fp->N_RB_UL*12*7*2) );
-=======
-  // assume maximum of 64 RX antennas for PRACH receiver
-  prach_vars->prach_ifft[0]    = (int32_t **)malloc16_clear(64*sizeof(int32_t *));
-
-  for (i=0; i<64; i++) prach_vars->prach_ifft[0][i]    = (int32_t *)malloc16_clear(1024*2*sizeof(int32_t));
-
-  prach_vars->rxsigF[0]        = (int16_t **)malloc16_clear(64*sizeof(int16_t *));
-*/
-
-  for (int UE_id=0; UE_idrxdataF_ext              = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->rxdataF_ext2             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_estimates          = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_estimates_ext      = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_ptrs_estimates     = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_estimates_time     = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->rxdataF_comp             = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_mag0               = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_magb0              = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_mag                = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->ul_ch_magb               = (int32_t **)malloc16( fp->nb_antennas_rx*sizeof(int32_t *) );
-    pusch_vars[UE_id]->rho                      = (int32_t **)malloc16_clear( fp->nb_antennas_rx*sizeof(int32_t*) );
-
-    for (i=0; inb_antennas_rx; i++) {
-      // RK 2 times because of output format of FFT!
-      // FIXME We should get rid of this
-      pusch_vars[UE_id]->rxdataF_ext[i]                = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->rxdataF_ext2[i]               = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_estimates[i]            = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_estimates_ext[i]        = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_ptrs_estimates[i]       = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*2*fp->symbols_per_slot ); // max intensity in freq is 1 sc every 2 RBs
-      pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext[i]   = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*2*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_estimates_time[i]       = (int32_t *)malloc16_clear( 2*sizeof(int32_t)*fp->ofdm_symbol_size );
-      pusch_vars[UE_id]->rxdataF_comp[i]               = (int32_t *)malloc16_clear( sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12*fp->symbols_per_slot );
-      pusch_vars[UE_id]->ul_ch_mag0[i]                 = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->ul_ch_magb0[i]                = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->ul_ch_mag[i]                  = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->ul_ch_magb[i]                 = (int32_t *)malloc16_clear( fp->symbols_per_slot*sizeof(int32_t)*cfg->rf_config.ul_carrier_bandwidth.value*12 );
-      pusch_vars[UE_id]->rho[i]                        = (int32_t *)malloc16_clear( sizeof(int32_t)*(fp->N_RB_UL*12*7*2) );
->>>>>>> origin/develop
     }
     printf("ULSCH_id %d (before llr alloc) : %p\n",ULSCH_id,gNB->dlsch[0][0]->harq_processes[0]);
     pusch_vars[ULSCH_id]->llr = (int16_t *)malloc16_clear( (8*((3*8*6144)+12))*sizeof(int16_t) ); // [hna] 6144 is LTE and (8*((3*8*6144)+12)) is not clear
@@ -374,12 +326,13 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
 */
   for (int ULSCH_id=0; ULSCH_idrxdataF_ext[i]);
       free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ext2[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_ext[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_time[i]);
+      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates[i]);
+      free_and_zero(pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext[i]);
       free_and_zero(pusch_vars[ULSCH_id]->rxdataF_comp[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag0[i]);
       free_and_zero(pusch_vars[ULSCH_id]->ul_ch_magb0[i]);
@@ -392,6 +345,8 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
     free_and_zero(pusch_vars[ULSCH_id]->rxdataF_ext2);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_ext);
+    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates);
+    free_and_zero(pusch_vars[ULSCH_id]->ul_ch_ptrs_estimates_ext);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_estimates_time);
     free_and_zero(pusch_vars[ULSCH_id]->rxdataF_comp);
     free_and_zero(pusch_vars[ULSCH_id]->ul_ch_mag0);
@@ -403,40 +358,6 @@ void phy_free_nr_gNB(PHY_VARS_gNB *gNB)
     free_and_zero(pusch_vars[ULSCH_id]->llr);
     free_and_zero(pusch_vars[ULSCH_id]);
   } //ULSCH_id
-=======
-      free_and_zero(pusch_vars[UE_id]->rxdataF_ext[i]);
-      free_and_zero(pusch_vars[UE_id]->rxdataF_ext2[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_estimates[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_ext[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_time[i]);
-      free_and_zero(pusch_vars[UE_id]->rxdataF_comp[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_mag0[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_magb0[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_mag[i]);
-      free_and_zero(pusch_vars[UE_id]->ul_ch_magb[i]);
-      free_and_zero(pusch_vars[UE_id]->rho[i]);
-    }
-
-    free_and_zero(pusch_vars[UE_id]->rxdataF_ext);
-    free_and_zero(pusch_vars[UE_id]->rxdataF_ext2);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_estimates);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_ext);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_ptrs_estimates_ext);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_estimates_time);
-    free_and_zero(pusch_vars[UE_id]->rxdataF_comp);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_mag0);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_magb0);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_mag);
-    free_and_zero(pusch_vars[UE_id]->ul_ch_magb);
-    free_and_zero(pusch_vars[UE_id]->rho);
-
-    free_and_zero(pusch_vars[UE_id]->llr);
-    free_and_zero(pusch_vars[UE_id]);
-  } //UE_id
->>>>>>> origin/develop
 /*
   for (UE_id = 0; UE_id < NUMBER_OF_UE_MAX; UE_id++) gNB->UE_stats_ptr[UE_id] = NULL;
 */
diff --git a/openair1/PHY/INIT/nr_init_ue.c b/openair1/PHY/INIT/nr_init_ue.c
index 60c8e1943d..4ed5be2119 100644
--- a/openair1/PHY/INIT/nr_init_ue.c
+++ b/openair1/PHY/INIT/nr_init_ue.c
@@ -655,13 +655,10 @@ int init_nr_ue_signal(PHY_VARS_NR_UE *ue,
   uint16_t N_n_scid[2] = {0,1}; // [HOTFIX] This is a temporary implementation of scramblingID0 and scramblingID1 which are given by DMRS-UplinkConfig
   int n_scid;
   abstraction_flag = 0;
-<<<<<<< HEAD
-=======
   fp->nb_antennas_tx = 1;
   fp->nb_antennas_rx=1;
   dmrs_UplinkConfig_t *dmrs_Uplink_Config = &ue->pusch_config.dmrs_UplinkConfig;
   ptrs_UplinkConfig_t *ptrs_Uplink_Config = &ue->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
->>>>>>> origin/develop
   printf("Initializing UE vars (abstraction %"PRIu8") for eNB TXant %"PRIu8", UE RXant %"PRIu8"\n",abstraction_flag,fp->nb_antennas_tx,fp->nb_antennas_rx);
   //LOG_D(PHY,"[MSC_NEW][FRAME 00000][PHY_UE][MOD %02u][]\n", ue->Mod_id+NB_eNB_INST);
   phy_init_nr_top(ue);

From e9fad1854059a1738661228726e8359eb17c78bf Mon Sep 17 00:00:00 2001
From: Raymond Knopp 
Date: Mon, 16 Mar 2020 01:26:12 +0100
Subject: [PATCH 56/73] temporary changes for nr_ulsim. To be removed when new
 branch with SCF NR FAPI for PUSCH is merged in.

---
 openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c | 5 +++++
 openair1/SIMULATION/NR_PHY/ulsim.c          | 4 ++++
 2 files changed, 9 insertions(+)

diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index 0238cb655f..05705a9fe9 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -442,6 +442,11 @@ int nr_dlsch_encoding(unsigned char *a,
     }
     encoder_implemparams_t impp;
     impp.n_segments=dlsch->harq_processes[harq_pid]->C;
+    impp.tprep = tprep;
+    impp.tinput = tinput;
+    impp.tparity = tparity;
+    impp.toutput = toutput;
+
     for(int j=0;j<(dlsch->harq_processes[harq_pid]->C/8+1);j++) {
       impp.macro_num=j;
       nrLDPC_encoder(dlsch->harq_processes[harq_pid]->c,dlsch->harq_processes[harq_pid]->d,*Zc,Kb,Kr,BG,&impp);
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index bd005d2331..477efac413 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -562,6 +562,10 @@ int main(int argc, char **argv)
       pusch_pdu->nrOfLayers = 1;
       pusch_pdu->ul_dmrs_symb_pos = 1;
       pusch_pdu->dmrs_config_type = 0;
+      // inserted to make simulation work 
+      // remove the next 2 lines when P7 is integrated from new branch
+      gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type=pusch_dmrs_type1;
+      gNB->pusch_config.dmrs_UplinkConfig.pusch_maxLength   = length_dmrs;
       pusch_pdu->ul_dmrs_scrambling_id =  0;
       pusch_pdu->scid = 0;
       pusch_pdu->resource_alloc = 1; 

From 1ddd729044d334bff0c97159c469e3a738a6c6f3 Mon Sep 17 00:00:00 2001
From: Raymond Knopp 
Date: Mon, 16 Mar 2020 09:32:50 +0100
Subject: [PATCH 57/73] bring back recent changes in ldpc encoder after merge
 with dynamic library implementation

---
 cmake_targets/autotests/test_case_list.xml                     | 2 +-
 .../PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c    | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/cmake_targets/autotests/test_case_list.xml b/cmake_targets/autotests/test_case_list.xml
index 6e96bb3b99..b3954db1fd 100644
--- a/cmake_targets/autotests/test_case_list.xml
+++ b/cmake_targets/autotests/test_case_list.xml
@@ -1106,7 +1106,7 @@
                   -n100 -e27 -s30 
                   -n100 -e16 -s10 
       
-      nr_dlsim.test1 nr_dlsim.test2 nr_dlsim.test3 nr_dlsim.test4 nr_dlsim.test5 nr_dlsim.test6 nr_dlsim.test7 nr_dlsim.test8 nr_dlsim.test9 nr_dlsim.test10 nr_dlsim.test11 nr_dlsim.test12
+      nr_dlsim.test1 nr_dlsim.test2 nr_dlsim.test3 nr_dlsim.test4 nr_dlsim.test5 nr_dlsim.test6 nr_dlsim.test7 nr_dlsim.test8 nr_dlsim.test9 nr_dlsim.test10 
       PDSCH test OK
       segmentation fault|assertion|exiting|fatal
       3
diff --git a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
index 28ab5b5029..b21f875b32 100644
--- a/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
+++ b/openair1/PHY/CODING/nrLDPC_encoder/ldpc_encoder_optim8segmulti.c
@@ -58,8 +58,7 @@ int nrLDPC_encod(unsigned char **test_input,unsigned char **channel_input,int Zc
 
   
   macro_segment = 8*impp->macro_num;
-  // macro_segment_end = (n_segments > 8*(macro_num+1)) ? 8*(macro_num+1) : n_segments;
-  macro_segment_end = macro_segment + (impp->n_segments > 8 ? 8 : impp->n_segments);
+  macro_segment_end = (impp->n_segments > 8*(impp->macro_num+1)) ? 8*(impp->macro_num+1) : impp->n_segments;
   ///printf("macro_segment: %d\n", macro_segment);
   ///printf("macro_segment_end: %d\n", macro_segment_end );
 

From 07a48f87e41b14fce9e65375ecab31b7918db25d Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani 
Date: Tue, 17 Mar 2020 19:06:22 +0100
Subject: [PATCH 58/73] loading LDPC libs for UE

---
 executables/nr-uesoftmodem.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/executables/nr-uesoftmodem.c b/executables/nr-uesoftmodem.c
index 64e0e03a05..53e407923f 100644
--- a/executables/nr-uesoftmodem.c
+++ b/executables/nr-uesoftmodem.c
@@ -688,6 +688,7 @@ int main( int argc, char **argv ) {
   itti_init(TASK_MAX, THREAD_MAX, MESSAGES_ID_MAX, tasks_info, messages_info);
 
   init_opt() ;
+  load_nrLDPClib();
 
   if (ouput_vcd) {
     vcd_signal_dumper_init("/tmp/openair_dump_nrUE.vcd");

From 57c993ce2613dd908580c25d5935fb05da0ce8b2 Mon Sep 17 00:00:00 2001
From: Francesco Mani 
Date: Wed, 18 Mar 2020 10:03:41 +0100
Subject: [PATCH 59/73] fix for some warnings

---
 openair1/PHY/MODULATION/modulation_UE.h            | 6 ++++++
 openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c        | 2 +-
 openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h      | 2 +-
 openair1/PHY/NR_UE_TRANSPORT/dci_nr.c              | 2 +-
 openair1/SIMULATION/NR_PHY/nr_unitary_defs.h       | 2 +-
 openair1/SIMULATION/NR_PHY/pbchsim.c               | 4 +++-
 openair1/SIMULATION/NR_PHY/ulsim.c                 | 1 +
 openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c       | 2 +-
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c         | 3 +--
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c | 2 +-
 openair2/RRC/NR/rrc_gNB_reconfig.c                 | 2 +-
 11 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/openair1/PHY/MODULATION/modulation_UE.h b/openair1/PHY/MODULATION/modulation_UE.h
index 1199a91baa..228299095f 100644
--- a/openair1/PHY/MODULATION/modulation_UE.h
+++ b/openair1/PHY/MODULATION/modulation_UE.h
@@ -54,6 +54,12 @@ int nr_slot_fep(PHY_VARS_NR_UE *phy_vars_ue,
              int sample_offset,
              int no_prefix);
 
+int nr_slot_fep_init_sync(PHY_VARS_NR_UE *ue,
+                          unsigned char symbol,
+                          unsigned char Ns,
+                          int sample_offset,
+                          int no_prefix);
+
 int slot_fep_mbsfn(PHY_VARS_UE *phy_vars_ue,
                    unsigned char l,
                    int subframe,
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index 05705a9fe9..856a7863f4 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -272,7 +272,7 @@ NR_gNB_DLSCH_t *new_gNB_dlsch(NR_DL_FRAME_PARMS *frame_parms,
   LOG_D(PHY,"new_gNB_dlsch exit flag %d, size of  %ld\n",
 	exit_flag, sizeof(NR_gNB_DLSCH_t));
 
-  free_gNB_dlsch(dlsch,N_RB);
+  free_gNB_dlsch(&dlsch,N_RB);
 
   return(NULL);
 
diff --git a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h
index 68b9e44d63..af06f9a98f 100644
--- a/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h
+++ b/openair1/PHY/NR_UE_ESTIMATION/nr_estimation.h
@@ -90,6 +90,6 @@ void phy_adjust_gain_nr(PHY_VARS_NR_UE *ue,
                         uint32_t rx_power_fil_dB,
                         uint8_t eNB_id);
 
-int16_t nr_get_PL(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index);
+int16_t get_nr_PL(PHY_VARS_NR_UE *ue,uint8_t gNB_index);
 
 #endif
diff --git a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
index 9921862c52..ef22b61260 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/dci_nr.c
@@ -702,7 +702,7 @@ int32_t nr_rx_pdcch(PHY_VARS_NR_UE *ue,
       for (aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++)
         avgs = cmax(avgs, avgP[aarx]);
 
-        log2_maxh = (log2_approx(avgs) / 2) + 5;  //+frame_parms->nb_antennas_rx;
+      log2_maxh = (log2_approx(avgs) / 2) + 5;  //+frame_parms->nb_antennas_rx;
 #ifdef UE_DEBUG_TRACE
       LOG_D(PHY,"slot %d: pdcch log2_maxh = %d (%d,%d)\n",slot,log2_maxh,avgP[0],avgs);
 #endif
diff --git a/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h b/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h
index 48fd49943b..c7a30f826e 100644
--- a/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h
+++ b/openair1/SIMULATION/NR_PHY/nr_unitary_defs.h
@@ -143,7 +143,7 @@ void fill_scc(NR_ServingCellConfigCommon_t *scc,uint64_t *ssb_bitmap,int N_RB_DL
   *scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->rsrp_ThresholdSSB=19;
   scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->prach_RootSequenceIndex.present=NR_RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139;
   scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->prach_RootSequenceIndex.choice.l139=0;
-  scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->restrictedSetConfig=NR_RACH_ConfigCommon__restrictedSetConfig_unrestrictedSet,TYPE_INT64;
+  scc->uplinkConfigCommon->initialUplinkBWP->rach_ConfigCommon->choice.setup->restrictedSetConfig=NR_RACH_ConfigCommon__restrictedSetConfig_unrestrictedSet;
   *scc->uplinkConfigCommon->initialUplinkBWP->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.array[0]->k2=2;
   scc->uplinkConfigCommon->initialUplinkBWP->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.array[0]->mappingType=NR_PUSCH_TimeDomainResourceAllocation__mappingType_typeB;
   scc->uplinkConfigCommon->initialUplinkBWP->pusch_ConfigCommon->choice.setup->pusch_TimeDomainAllocationList->list.array[0]->startSymbolAndLength=55;
diff --git a/openair1/SIMULATION/NR_PHY/pbchsim.c b/openair1/SIMULATION/NR_PHY/pbchsim.c
index f78210a0f8..99ca466fee 100644
--- a/openair1/SIMULATION/NR_PHY/pbchsim.c
+++ b/openair1/SIMULATION/NR_PHY/pbchsim.c
@@ -410,7 +410,9 @@ int main(int argc, char **argv)
   uint8_t n_hf = 0;
   int cyclic_prefix_type = NFAPI_CP_NORMAL;
 
-  double fs,bw,scs,eps;
+  double fs, eps;
+  double scs = 30000;
+  double bw = 100e6;
   
   switch (mu) {
     case 1:
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index 477efac413..1ca4a5a389 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -52,6 +52,7 @@
 #include "openair1/SIMULATION/TOOLS/sim.h"
 #include "openair1/SIMULATION/RF/rf.h"
 #include "openair1/SIMULATION/NR_PHY/nr_unitary_defs.h"
+#include "openair2/RRC/NR/MESSAGES/asn1_msg.h"
 #include "openair2/LAYER2/NR_MAC_UE/mac_proto.h"
 #include "openair2/LAYER2/NR_MAC_gNB/mac_proto.h"
 
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
index d62a763a22..58b312038a 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
@@ -2732,7 +2732,7 @@ void nr_extract_dci_info(NR_UE_MAC_INST_t *mac,
     NRRIV2BW(mac->ULbwp[0]->bwp_Common->genericParameters.locationAndBandwidth,275) :
     NRRIV2BW(mac->scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.locationAndBandwidth,275);
 
-  int pos;
+  int pos=0;
   int fsize=0;
   switch(dci_format) {
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
index 93de38060d..90c56c2ef5 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
@@ -308,10 +308,9 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   //printf("gNB_dlsch_ulsch_scheduler frameRX %d slotRX %d frameTX %d slotTX %d\n",frame_rxP,slot_rxP,frame_txP,slot_txP);
 			       
   protocol_ctxt_t   ctxt;
-  int CC_id, i = -1, UE_id = 0;
+  int CC_id, UE_id = 0;
   gNB_MAC_INST *gNB = RC.nrmac[module_idP];
   NR_UE_list_t *UE_list = &gNB->UE_list;
-  rnti_t rnti;
   UE_sched_ctrl_t *ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
   NR_COMMON_channels_t *cc = gNB->common_channels;
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
index 37808dec8d..85d0a04b54 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
@@ -37,7 +37,7 @@
 #include "executables/nr-softmodem.h"
 #include "LAYER2/NR_MAC_COMMON/nr_mac.h"
 #include "executables/softmodem-common.h"
-
+#include "common/utils/nr/nr_common.h"
 #include "NR_SCS-SpecificCarrier.h"
 #include "NR_TDD-UL-DL-ConfigCommon.h"
 #include "NR_FrequencyInfoUL.h"
diff --git a/openair2/RRC/NR/rrc_gNB_reconfig.c b/openair2/RRC/NR/rrc_gNB_reconfig.c
index faabbb1400..1df17a19aa 100644
--- a/openair2/RRC/NR/rrc_gNB_reconfig.c
+++ b/openair2/RRC/NR/rrc_gNB_reconfig.c
@@ -41,7 +41,7 @@
 #include "BOOLEAN.h"
 #include "assertions.h"
 #include "common/utils/nr/nr_common.h"
-
+#include "SIMULATION/TOOLS/sim.h"
 #include "executables/softmodem-common.h"
 
 #define false 0

From 6d058d306aa6adef383ca81d836ffc7eafb17530 Mon Sep 17 00:00:00 2001
From: Francesco Mani 
Date: Thu, 19 Mar 2020 18:07:12 +0100
Subject: [PATCH 60/73] SCF FAPI structures for PUSCH at gNB

---
 executables/nr-ue.c                           |   2 +-
 .../nfapi/public_inc/nfapi_nr_interface_scf.h |   4 +-
 openair1/PHY/CODING/nr_segmentation.c         |  14 +-
 openair1/PHY/INIT/nr_init.c                   |  39 +-
 .../NR_ESTIMATION/nr_ul_channel_estimation.c  |  34 +-
 openair1/PHY/NR_ESTIMATION/nr_ul_estimation.h |  14 +-
 openair1/PHY/NR_REFSIG/dmrs_nr.c              |  15 +-
 openair1/PHY/NR_REFSIG/dmrs_nr.h              |   3 +-
 openair1/PHY/NR_REFSIG/nr_gold.c              |  57 +--
 openair1/PHY/NR_REFSIG/nr_refsig.h            |   2 +-
 openair1/PHY/NR_REFSIG/ptrs_nr.c              |  92 +++--
 openair1/PHY/NR_REFSIG/ptrs_nr.h              |   9 +-
 openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c    |  16 +-
 .../PHY/NR_TRANSPORT/nr_transport_proto.h     |  11 +-
 openair1/PHY/NR_TRANSPORT/nr_ulsch.h          |   5 +-
 openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c |  93 +++--
 .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c  | 342 ++++++++----------
 .../PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c     |  36 +-
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c    |  19 +-
 openair1/PHY/defs_gNB.h                       |  17 +-
 openair1/PHY/impl_defs_nr.h                   |   4 +-
 openair1/SCHED_NR/phy_procedures_nr_gNB.c     |  49 ++-
 openair1/SIMULATION/NR_PHY/ulschsim.c         |  31 +-
 openair1/SIMULATION/NR_PHY/ulsim.c            |   9 +-
 .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c |   4 +-
 .../NR_MAC_gNB/gNB_scheduler_primitives.c     |  22 --
 26 files changed, 411 insertions(+), 532 deletions(-)

diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index 40d33b701e..653a97dc61 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -762,7 +762,7 @@ void *UE_thread(void *arg) {
     int firstSymSamp = get_firstSymSamp(slot_nr, &UE->frame_parms);
     for (int i=0; iframe_parms.nb_antennas_rx; i++)
       rxp[i] = (void *)&UE->common_vars.rxdata[i][firstSymSamp+
-               get_samples_slot_timestamp(slot_nr,&UE->frame_parms,0)];
+               UE->frame_parms.get_samples_slot_timestamp(slot_nr,&UE->frame_parms,0)];
 
     for (int i=0; iframe_parms.nb_antennas_tx; i++)
       txp[i] = (void *)&UE->common_vars.txdata[i][UE->frame_parms.get_samples_slot_timestamp(
diff --git a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
index ee1550a5bb..f69c928ed2 100644
--- a/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
+++ b/nfapi/open-nFAPI/nfapi/public_inc/nfapi_nr_interface_scf.h
@@ -1122,10 +1122,10 @@ typedef struct
   uint16_t data_scrambling_id;
   uint8_t  nrOfLayers;
   //DMRS
-  uint8_t  ul_dmrs_symb_pos;
+  uint16_t  ul_dmrs_symb_pos;
   uint8_t  dmrs_config_type;
   uint16_t ul_dmrs_scrambling_id;
-  uint8_t  scid;//
+  uint8_t  scid;
   uint8_t  num_dmrs_cdm_grps_no_data;
   uint16_t dmrs_ports;//DMRS ports. [TS38.212 7.3.1.1.2] provides description between DCI 0-1 content and DMRS ports. Bitmap occupying the 11 LSBs with: bit 0: antenna port 1000 bit 11: antenna port 1011 and for each bit 0: DMRS port not used 1: DMRS port used
   //Pusch Allocation in frequency domain [TS38.214, sec 6.1.2.2]
diff --git a/openair1/PHY/CODING/nr_segmentation.c b/openair1/PHY/CODING/nr_segmentation.c
index 462cdee1fc..1d80a83131 100644
--- a/openair1/PHY/CODING/nr_segmentation.c
+++ b/openair1/PHY/CODING/nr_segmentation.c
@@ -30,13 +30,13 @@
 //#define DEBUG_SEGMENTATION
 
 int32_t nr_segmentation(unsigned char *input_buffer,
-                     unsigned char **output_buffers,
-                     unsigned int B,
-                     unsigned int *C,
-                     unsigned int *K,
-                     unsigned int *Zout, // [hna] Zout is Zc
-                     unsigned int *F,
-                     uint8_t BG)
+                        unsigned char **output_buffers,
+                        unsigned int B,
+                        unsigned int *C,
+                        unsigned int *K,
+                        unsigned int *Zout, // [hna] Zout is Zc
+                        unsigned int *F,
+                        uint8_t BG)
 {
 
   unsigned int L,Bprime,Z,r,Kcb,Kb,k,s,crc,Kprime;
diff --git a/openair1/PHY/INIT/nr_init.c b/openair1/PHY/INIT/nr_init.c
index d30c0dc874..1c0d5a6aca 100644
--- a/openair1/PHY/INIT/nr_init.c
+++ b/openair1/PHY/INIT/nr_init.c
@@ -83,8 +83,6 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
   NR_gNB_COMMON *const common_vars  = &gNB->common_vars;
   NR_gNB_PRACH *const prach_vars   = &gNB->prach_vars;
   NR_gNB_PUSCH **const pusch_vars   = gNB->pusch_vars;
-  dmrs_UplinkConfig_t *dmrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig;
-  ptrs_UplinkConfig_t *ptrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
   /*LTE_eNB_SRS *const srs_vars       = gNB->srs_vars;
   LTE_eNB_PRACH *const prach_vars   = &gNB->prach_vars;*/
 
@@ -154,31 +152,30 @@ int phy_init_nr_gNB(PHY_VARS_gNB *gNB,
     }
   }
 
-  //------------- config PUSCH DMRS parameters(to be updated from RRC)--------------
-  gNB->dmrs_UplinkConfig.pusch_dmrs_type = pusch_dmrs_type1;
-  gNB->dmrs_UplinkConfig.pusch_dmrs_AdditionalPosition = pusch_dmrs_pos0;
-  gNB->dmrs_UplinkConfig.pusch_maxLength = pusch_len1;
-  //--------------------------------------------------------------------------------
 
   nr_init_pdsch_dmrs(gNB, cfg->cell_config.phy_cell_id.value);
 
-  // default values until overwritten by RRCConnectionReconfiguration
+  //PUSCH DMRS init
+  gNB->nr_gold_pusch_dmrs = (uint32_t ****)malloc16(2*sizeof(uint32_t ***));
+  uint32_t ****pusch_dmrs = gNB->nr_gold_pusch_dmrs;
 
-  for (i=0;ipusch_config.pusch_TimeDomainResourceAllocation[i] = (PUSCH_TimeDomainResourceAllocation_t *)malloc16(sizeof(PUSCH_TimeDomainResourceAllocation_t));
-    gNB->pusch_config.pusch_TimeDomainResourceAllocation[i]->mappingType = typeB;
+  for(int nscid=0; nscid<2; nscid++) {
+    pusch_dmrs[nscid] = (uint32_t ***)malloc16(fp->slots_per_frame*sizeof(uint32_t **));
+    AssertFatal(pusch_dmrs[nscid]!=NULL, "NR init: pusch_dmrs for nscid %d - malloc failed\n", nscid);
+
+    for (int slot=0; slotslots_per_frame; slot++) {
+      pusch_dmrs[nscid][slot] = (uint32_t **)malloc16(fp->symbols_per_slot*sizeof(uint32_t *));
+      AssertFatal(pusch_dmrs[nscid][slot]!=NULL, "NR init: pusch_dmrs for slot %d - malloc failed\n", slot);
+
+      for (int symb=0; symbsymbols_per_slot; symb++) {
+        pusch_dmrs[nscid][slot][symb] = (uint32_t *)malloc16(NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD*sizeof(uint32_t));
+        AssertFatal(pusch_dmrs[nscid][slot][symb]!=NULL, "NR init: pusch_dmrs for slot %d symbol %d - malloc failed\n", slot, symb);
+      }
+    }
   }
 
-  gNB->ptrs_configured = 0;
-
-  //------------- config PUSCH PTRS parameters(to be updated from RRC)--------------//
-  ptrs_Uplink_Config->timeDensity.ptrs_mcs1 = 0; // setting MCS values to 0 indicate abscence of time_density field in the configuration
-  ptrs_Uplink_Config->timeDensity.ptrs_mcs2 = 0;
-  ptrs_Uplink_Config->timeDensity.ptrs_mcs3 = 0;
-  ptrs_Uplink_Config->frequencyDensity.n_rb0 = 0;     // setting N_RB values to 0 indicate abscence of frequency_density field in the configuration
-  ptrs_Uplink_Config->frequencyDensity.n_rb1 = 0;
-  ptrs_Uplink_Config->resourceElementOffset = 0;
-  //--------------------------------------------------------------------------------//
+  uint32_t Nid_pusch[2] = {cfg->cell_config.phy_cell_id.value,cfg->cell_config.phy_cell_id.value};
+  nr_gold_pusch(gNB, &Nid_pusch[0]);
 
   /// Transport init necessary for NR synchro
   init_nr_transport(gNB);
diff --git a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
index 83c6f054cd..0d7732599f 100644
--- a/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
+++ b/openair1/PHY/NR_ESTIMATION/nr_ul_channel_estimation.c
@@ -31,22 +31,19 @@
 
 
 int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
-                                uint8_t gNB_offset,
                                 unsigned char Ns,
                                 unsigned short p,
                                 unsigned char symbol,
                                 unsigned short bwp_start_subcarrier,
-                                unsigned short nb_rb_pusch,
-                                dmrs_UplinkConfig_t *dmrs_UplinkConfig)
-{
+                                nfapi_nr_pusch_pdu_t *pusch_pdu) {
+
   int pilot[3280] __attribute__((aligned(16)));
   unsigned char aarx;
   unsigned short k;
   unsigned int pilot_cnt,re_cnt;
   int16_t ch[2],ch_r[2],ch_l[2],*pil,*rxF,*ul_ch;
   int16_t *fl,*fm,*fr,*fml,*fmr,*fmm,*fdcl,*fdcr,*fdclh,*fdcrh;
-  int ch_offset,symbol_offset, length_dmrs, UE_id = 0;
-  unsigned short n_idDMRS[2] = {0,1}; //to update from pusch config
+  int ch_offset,symbol_offset, UE_id = 0;
   int32_t **ul_ch_estimates_time =  gNB->pusch_vars[UE_id]->ul_ch_estimates_time;
   __m128i *ul_ch_128;
 
@@ -71,9 +68,11 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
   k = bwp_start_subcarrier;
   int re_offset = k;
 
+  uint16_t nb_rb_pusch = pusch_pdu->rb_size;
+
 /*
 #ifdef DEBUG_CH
-  printf("PUSCH Channel Estimation : gNB_offset %d ch_offset %d, symbol_offset %d OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n", gNB_offset,ch_offset,symbol_offset,gNB->frame_parms.ofdm_symbol_size,
+  printf("PUSCH Channel Estimation : ch_offset %d, symbol_offset %d OFDM size %d, Ncp=%d, l=%d, Ns=%d, k=%d symbol %d\n", ,ch_offset,symbol_offset,gNB->frame_parms.ofdm_symbol_size,
          gNB->frame_parms.Ncp,l,Ns,k, symbol);
 #endif
 */
@@ -117,21 +116,17 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
 
   //------------------generate DMRS------------------//
 
-  length_dmrs = dmrs_UplinkConfig->pusch_maxLength;
-
-  nr_gold_pusch(gNB, symbol, n_idDMRS, length_dmrs);
-
-  nr_pusch_dmrs_rx(gNB, Ns, gNB->nr_gold_pusch[gNB_offset][Ns][0], &pilot[0], 1000, 0, nb_rb_pusch, dmrs_UplinkConfig->pusch_dmrs_type);
+  nr_pusch_dmrs_rx(gNB, Ns, gNB->nr_gold_pusch_dmrs[pusch_pdu->scid][Ns][symbol], &pilot[0], 1000, 0, nb_rb_pusch, pusch_pdu->dmrs_config_type);
 
   //------------------------------------------------//
 
   for (aarx=0; aarxframe_parms.nb_antennas_rx; aarx++) {
 
-      pil   = (int16_t *)&pilot[0];
-      rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];
-      ul_ch = (int16_t *)&ul_ch_estimates[aarx][ch_offset];
+    pil   = (int16_t *)&pilot[0];
+    rxF   = (int16_t *)&rxdataF[aarx][(symbol_offset+k+nushift)];
+    ul_ch = (int16_t *)&ul_ch_estimates[aarx][ch_offset];
 
-      memset(ul_ch,0,4*(gNB->frame_parms.ofdm_symbol_size));
+    memset(ul_ch,0,4*(gNB->frame_parms.ofdm_symbol_size));
 
 #ifdef DEBUG_PUSCH
     printf("ch est pilot addr %p RB_DL %d\n",&pilot[0], gNB->frame_parms.N_RB_UL);
@@ -141,8 +136,7 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
 #endif
     //if ((gNB->frame_parms.N_RB_UL&1)==0) {
 
-
-    if (dmrs_UplinkConfig->pusch_dmrs_type == pusch_dmrs_type1){
+    if (pusch_pdu->dmrs_config_type == pusch_dmrs_type1){
 
       // Treat first 2 pilots specially (left edge)
       ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
@@ -237,10 +231,10 @@ int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
       }
       
       // Treat first 2 pilots specially (right edge)
-	  ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
+      ch[0] = (int16_t)(((int32_t)pil[0]*rxF[0] - (int32_t)pil[1]*rxF[1])>>15);
       ch[1] = (int16_t)(((int32_t)pil[0]*rxF[1] + (int32_t)pil[1]*rxF[0])>>15);
 #ifdef DEBUG_PUSCH
-    printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
+      printf("pilot %u : rxF - > (%d,%d) ch -> (%d,%d), pil -> (%d,%d) \n",pilot_cnt,rxF[0],rxF[1],ch[0],ch[1],pil[0],pil[1]);
 #endif
       multadd_real_vector_complex_scalar(fm,
                                          ch,
diff --git a/openair1/PHY/NR_ESTIMATION/nr_ul_estimation.h b/openair1/PHY/NR_ESTIMATION/nr_ul_estimation.h
index cc84f2292c..a7789c9224 100644
--- a/openair1/PHY/NR_ESTIMATION/nr_ul_estimation.h
+++ b/openair1/PHY/NR_ESTIMATION/nr_ul_estimation.h
@@ -39,14 +39,12 @@
 \param nb_rb_pusch, number of allocated RBs for this UE
 */
 
- int32_t nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
-                                     uint8_t gNB_offset,
-				                     unsigned char Ns,
-				                     unsigned short p,
-				                     unsigned char symbol,
-				                     unsigned short bwp_start_subcarrier,
-				                     unsigned short nb_rb_pusch,
-				                     dmrs_UplinkConfig_t *dmrs_UplinkConfig);
+int nr_pusch_channel_estimation(PHY_VARS_gNB *gNB,
+                                unsigned char Ns,
+                                unsigned short p,
+                                unsigned char symbol,
+                                unsigned short bwp_start_subcarrier,
+                                nfapi_nr_pusch_pdu_t *pusch_pdu);
 
 int nr_est_timing_advance_pusch(PHY_VARS_gNB* phy_vars_gNB, int UE_id);
 
diff --git a/openair1/PHY/NR_REFSIG/dmrs_nr.c b/openair1/PHY/NR_REFSIG/dmrs_nr.c
index 67118f35a9..ed37a79d0f 100644
--- a/openair1/PHY/NR_REFSIG/dmrs_nr.c
+++ b/openair1/PHY/NR_REFSIG/dmrs_nr.c
@@ -128,22 +128,21 @@ uint8_t is_dmrs_symbol(uint8_t l,
                        uint16_t n,
                        uint8_t delta,
                        uint8_t duration_in_symbols,
-                       dmrs_UplinkConfig_t *dmrs_UplinkConfig,
-                       uint8_t mapping_type,
+                       uint8_t dmrs_type,
                        uint16_t ofdm_symbol_size) {
 
-  uint8_t is_dmrs_freq, is_dmrs_time, dmrs_type, l0;
+  uint8_t is_dmrs_freq, is_dmrs_time, l0;
   int32_t l_prime_mask;
-  pusch_dmrs_AdditionalPosition_t additional_pos;
+  pusch_dmrs_AdditionalPosition_t additional_pos = pusch_dmrs_pos0;
+  pusch_maxLength_t pusch_maxLength = pusch_len1;
+  uint8_t mapping_type = typeB;
 
   is_dmrs_freq = 0;
   is_dmrs_time = 0;
-  dmrs_type = dmrs_UplinkConfig->pusch_dmrs_type;
-  additional_pos = dmrs_UplinkConfig->pusch_dmrs_AdditionalPosition;
 
 
   l0 = get_l0_ul(mapping_type, 2);
-  l_prime_mask = get_l_prime(duration_in_symbols, mapping_type, additional_pos, dmrs_UplinkConfig->pusch_maxLength);
+  l_prime_mask = get_l_prime(duration_in_symbols, mapping_type, additional_pos, pusch_maxLength);
 
   if (k == ((start_sc+get_dmrs_freq_idx_ul(n, k_prime, delta, dmrs_type))%ofdm_symbol_size))
     is_dmrs_freq = 1;
@@ -157,7 +156,7 @@ uint8_t is_dmrs_symbol(uint8_t l,
   } else if ( (l==l0) || (((l_prime_mask>>l)&1) == 1 && l!=0) )
     is_dmrs_time = 1;
 
-  if (dmrs_UplinkConfig->pusch_maxLength == pusch_len2){
+  if (pusch_maxLength == pusch_len2){
 
     if (((l_prime_mask>>(l-1))&1) == 1 && l!=0 && l!=1)
       is_dmrs_time = 1;
diff --git a/openair1/PHY/NR_REFSIG/dmrs_nr.h b/openair1/PHY/NR_REFSIG/dmrs_nr.h
index de77a8a6ce..f1dfffff8b 100644
--- a/openair1/PHY/NR_REFSIG/dmrs_nr.h
+++ b/openair1/PHY/NR_REFSIG/dmrs_nr.h
@@ -66,8 +66,7 @@ uint8_t is_dmrs_symbol(uint8_t l,
                        uint16_t n,
                        uint8_t delta,
                        uint8_t duration_in_symbols,
-                       dmrs_UplinkConfig_t *dmrs_UplinkConfig,
-                       uint8_t mapping_type,
+                       uint8_t dmrs_type,
                        uint16_t ofdm_symbol_size);
 
 #undef EXTERN
diff --git a/openair1/PHY/NR_REFSIG/nr_gold.c b/openair1/PHY/NR_REFSIG/nr_gold.c
index 7057adef21..472d03e649 100644
--- a/openair1/PHY/NR_REFSIG/nr_gold.c
+++ b/openair1/PHY/NR_REFSIG/nr_gold.c
@@ -104,56 +104,27 @@ void nr_init_pdsch_dmrs(PHY_VARS_gNB* gNB, uint32_t Nid)
 }
 
 
-void nr_gold_pusch(PHY_VARS_gNB* gNB, unsigned short lbar,unsigned short *n_idDMRS, unsigned short length_dmrs)
-{
+void nr_gold_pusch(PHY_VARS_gNB* gNB, uint32_t *Nid) {
 
-  unsigned char ns,l;
-  unsigned int n,x1,x2,x2tmp0;
-  int nscid;
+  unsigned char ns;
+  unsigned int n,x1,x2;
+  int nscid, reset;
   unsigned int nid;
-
-  /// to be updated from higher layer
-  //unsigned short lbar = 0;
+  NR_DL_FRAME_PARMS *fp = &gNB->frame_parms;
+  unsigned short l;
 
   for (nscid=0; nscid<2; nscid++) {
-    if (n_idDMRS)
-      nid = n_idDMRS[nscid];
-    else
-      nid = gNB->frame_parms.Nid_cell;
-      
-      //printf("gold pdsch nid %d lbar %d\n",nid,lbar);
-
-    for (ns=0; ns<20; ns++) {
-
-      for (l=0; l>1) ^ (x2>>2) ^ (x2>>3))<<31);
-
-        // skip first 50 double words (1600 bits)
-        for (n=1; n<50; n++) {
-          x1 = (x1>>1) ^ (x1>>4);
-          x1 = x1 ^ (x1<<31) ^ (x1<<28);
-          x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
-          x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
-            //printf("x1 : %x, x2 : %x\n",x1,x2);
-        }
+    nid = Nid[nscid];
+    for (ns=0; nsslots_per_frame; ns++) {
+      for (l=0; lsymbols_per_slot; l++) {
+        reset = 1;
+        x2 = ((1<<17) * (fp->symbols_per_slot*ns+l+1) * ((nid<<1)+1) +((nid<<1)+nscid));
+        LOG_D(PHY,"DMRS slot %d, symb %d x2 %x\n",ns,l,x2);
 
         for (n=0; n>1) ^ (x1>>4);
-          x1 = x1 ^ (x1<<31) ^ (x1<<28);
-          x2 = (x2>>1) ^ (x2>>2) ^ (x2>>3) ^ (x2>>4);
-          x2 = x2 ^ (x2<<31) ^ (x2<<30) ^ (x2<<29) ^ (x2<<28);
-          gNB->nr_gold_pusch[nscid][ns][l][n] = x1^x2;
-            // if ((ns==2)&&(l==0))
-            //printf("n=%d : c %x\n",n,x1^x2);
+          gNB->nr_gold_pusch_dmrs[nscid][ns][l][n] = lte_gold_generic(&x1, &x2, reset);
+          reset = 0;
         }
-
       }
     }
   }
diff --git a/openair1/PHY/NR_REFSIG/nr_refsig.h b/openair1/PHY/NR_REFSIG/nr_refsig.h
index 754edfef64..5af0e88099 100644
--- a/openair1/PHY/NR_REFSIG/nr_refsig.h
+++ b/openair1/PHY/NR_REFSIG/nr_refsig.h
@@ -39,7 +39,7 @@ void nr_init_pbch_dmrs(PHY_VARS_gNB* gNB);
 void nr_init_pdcch_dmrs(PHY_VARS_gNB* gNB, uint32_t Nid);
 void nr_init_pdsch_dmrs(PHY_VARS_gNB* gNB, uint32_t Nid);
 
-void nr_gold_pusch(PHY_VARS_gNB* gNB, unsigned short lbar,unsigned short *n_idDMRS, unsigned short length_dmrs);
+void nr_gold_pusch(PHY_VARS_gNB* gNB, uint32_t *Nid);
 
 int nr_pusch_dmrs_rx(PHY_VARS_gNB *gNB,
                      unsigned int Ns,
diff --git a/openair1/PHY/NR_REFSIG/ptrs_nr.c b/openair1/PHY/NR_REFSIG/ptrs_nr.c
index 9be37d2d95..12f76b950f 100644
--- a/openair1/PHY/NR_REFSIG/ptrs_nr.c
+++ b/openair1/PHY/NR_REFSIG/ptrs_nr.c
@@ -123,9 +123,6 @@ uint8_t get_K_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint16_t N_RB){
 * NAME :         set_ptrs_symb_idx
 *
 * PARAMETERS :   ptrs_symbols           PTRS OFDM symbol indicies bit mask
-*                ptrs_UplinkConfig      PTRS uplink configuration
-*                dmrs_UplinkConfig      DMRS uplink configuration
-*                mapping_type           PUSCH time domain mapping type
 *                duration_in_symbols    number of scheduled PUSCH ofdm symbols
 *                start_symbol           first ofdm symbol of PUSCH within slot
 *                L_ptrs                 the parameter L_ptrs
@@ -138,64 +135,61 @@ uint8_t get_K_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint16_t N_RB){
 *********************************************************************/
 
 void set_ptrs_symb_idx(uint16_t *ptrs_symbols,
-                       ptrs_UplinkConfig_t *ptrs_UplinkConfig,
-                       dmrs_UplinkConfig_t *dmrs_UplinkConfig,
-                       uint8_t mapping_type,
                        uint8_t duration_in_symbols,
                        uint8_t start_symbol,
+                       uint8_t dmrs_type,
                        uint8_t L_ptrs,
+                       uint8_t pusch_maxLength,
                        uint16_t ofdm_symbol_size) {
 
-	uint8_t i, last_symbol, is_dmrs_symbol1, is_dmrs_symbol2;
-	int16_t l_ref;
+  uint8_t i, last_symbol, is_dmrs_symbol1, is_dmrs_symbol2;
+  int16_t l_ref;
 
-	*ptrs_symbols = 0;
-	i = 0;
-	is_dmrs_symbol1 = 0;
-	is_dmrs_symbol2 = 0;
-	l_ref = start_symbol;
-	last_symbol = start_symbol + duration_in_symbols - 1;
+  *ptrs_symbols = 0;
+  i = 0;
+  is_dmrs_symbol1 = 0;
+  is_dmrs_symbol2 = 0;
+  l_ref = start_symbol;
+  last_symbol = start_symbol + duration_in_symbols - 1;
 
-	while ( (l_ref + i*L_ptrs) <= last_symbol) {
+  while ( (l_ref + i*L_ptrs) <= last_symbol) {
 
-		is_dmrs_symbol1 = is_dmrs_symbol(max((l_ref + (i-1)*L_ptrs + 1), l_ref),
-                                         0,
-                                         0,
-                                         0,
-                                         0,
-                                         0,
-                                         duration_in_symbols,
-                                         dmrs_UplinkConfig,
-                                         mapping_type,
-                                         ofdm_symbol_size);
+    is_dmrs_symbol1 = is_dmrs_symbol(max((l_ref + (i-1)*L_ptrs + 1), l_ref),
+                                     0,
+                                     0,
+                                     0,
+                                     0,
+                                     0,
+                                     duration_in_symbols,
+                                     dmrs_type,
+                                     ofdm_symbol_size);
 
-		is_dmrs_symbol2 = is_dmrs_symbol(l_ref + i*L_ptrs,
-                                         0,
-                                         0,
-                                         0,
-                                         0,
-                                         0,
-                                         duration_in_symbols,
-                                         dmrs_UplinkConfig,
-                                         mapping_type,
-                                         ofdm_symbol_size);
+    is_dmrs_symbol2 = is_dmrs_symbol(l_ref + i*L_ptrs,
+                                     0,
+                                     0,
+                                     0,
+                                     0,
+                                     0,
+                                     duration_in_symbols,
+                                     dmrs_type,
+                                     ofdm_symbol_size);
 
-		if ( is_dmrs_symbol1 + is_dmrs_symbol2 > 0 ) {
+    if ( is_dmrs_symbol1 + is_dmrs_symbol2 > 0 ) {
 
-			if (dmrs_UplinkConfig->pusch_maxLength == 2)
-				l_ref = l_ref + i*L_ptrs + 1;
-			else
-				l_ref = l_ref + i*L_ptrs;
+      if (pusch_maxLength == 2)
+        l_ref = l_ref + i*L_ptrs + 1;
+      else
+        l_ref = l_ref + i*L_ptrs;
 
-			i = 1;
+       i = 1;
 
-			continue;
+       continue;
 
-		}
+    }
 
-		*ptrs_symbols = *ptrs_symbols | (1<<(l_ref + i*L_ptrs));
-		i++;
-	}
+    *ptrs_symbols = *ptrs_symbols | (1<<(l_ref + i*L_ptrs));
+    i++;
+  }
 }
 
 /*******************************************************************
@@ -313,7 +307,7 @@ uint8_t is_ptrs_symbol(uint8_t l,
                        uint16_t start_sc,
                        uint16_t ofdm_symbol_size,
                        pusch_dmrs_type_t pusch_dmrs_type,
-                       ptrs_UplinkConfig_t *ptrs_UplinkConfig) {
+                       uint8_t resourceElementOffset) {
 
   uint8_t is_ptrs_freq, is_ptrs_time;
   int16_t k_RE_ref;
@@ -321,7 +315,7 @@ uint8_t is_ptrs_symbol(uint8_t l,
   is_ptrs_freq = 0;
   is_ptrs_time = 0;
 
-  k_RE_ref = get_kRE_ref(dmrs_antenna_port, pusch_dmrs_type, ptrs_UplinkConfig->resourceElementOffset);
+  k_RE_ref = get_kRE_ref(dmrs_antenna_port, pusch_dmrs_type, resourceElementOffset);
 
   is_ptrs_freq = is_ptrs_subcarrier(k, K_ptrs, n_rnti, N_RB, k_RE_ref, start_sc, ofdm_symbol_size);
 
@@ -426,4 +420,4 @@ int main(int argc, char const *argv[])
 
 	return 0;
 }
-*/
\ No newline at end of file
+*/
diff --git a/openair1/PHY/NR_REFSIG/ptrs_nr.h b/openair1/PHY/NR_REFSIG/ptrs_nr.h
index f3b42fff30..291ff4a555 100644
--- a/openair1/PHY/NR_REFSIG/ptrs_nr.h
+++ b/openair1/PHY/NR_REFSIG/ptrs_nr.h
@@ -52,12 +52,11 @@ int16_t get_kRE_ref(uint8_t dmrs_antenna_port, uint8_t pusch_dmrs_type, uint8_t
 uint8_t get_K_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint16_t N_RB);
 
 void set_ptrs_symb_idx(uint16_t *ptrs_symbols,
-                       ptrs_UplinkConfig_t *ptrs_UplinkConfig,
-                       dmrs_UplinkConfig_t *dmrs_UplinkConfig,
-                       uint8_t mapping_type,
                        uint8_t duration_in_symbols,
                        uint8_t start_symbol,
+                       uint8_t dmrs_type,
                        uint8_t L_ptrs,
+                       uint8_t pusch_maxLength,
                        uint16_t ofdm_symbol_size);
 
 uint8_t get_L_ptrs(ptrs_UplinkConfig_t *ptrs_UplinkConfig, uint8_t I_mcs);
@@ -75,8 +74,8 @@ uint8_t is_ptrs_symbol(uint8_t l,
                        uint16_t start_sc,
                        uint16_t ofdm_symbol_size,
                        pusch_dmrs_type_t pusch_dmrs_type,
-                       ptrs_UplinkConfig_t *ptrs_UplinkConfig);
+                       uint8_t resourceElementOffset);
 
 
 
-#endif /* PTRS_NR_H */
\ No newline at end of file
+#endif /* PTRS_NR_H */
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
index dd9f06d0f9..2e6fc707bd 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_tools.c
@@ -333,23 +333,9 @@ void nr_fill_ulsch(PHY_VARS_gNB *gNB,
   ulsch->harq_mask |= 1<harq_process_id[slot] = harq_pid;
 
-  nfapi_nr_ul_config_ulsch_pdu *rel15_ul = &ulsch->harq_processes[harq_pid]->ulsch_pdu;
+  memcpy((void*)&ulsch->harq_processes[harq_pid]->ulsch_pdu, (void*)ulsch_pdu, sizeof(nfapi_nr_pusch_pdu_t));
 
   LOG_D(PHY,"Initializing nFAPI for ULSCH, UE %d, harq_pid %d\n",ulsch_id,harq_pid);
- 
-  
-  //FK this is still a bad hack. We need to replace the L1 FAPI structures with the new scf ones as well.
-  rel15_ul->rnti                           = ulsch_pdu->rnti;
-  rel15_ul->ulsch_pdu_rel15.start_rb       = ulsch_pdu->rb_start;
-  rel15_ul->ulsch_pdu_rel15.number_rbs     = ulsch_pdu->rb_size;
-  rel15_ul->ulsch_pdu_rel15.start_symbol   = ulsch_pdu->start_symbol_index;
-  rel15_ul->ulsch_pdu_rel15.number_symbols = ulsch_pdu->nr_of_symbols;
-  rel15_ul->ulsch_pdu_rel15.length_dmrs    = gNB->pusch_config.dmrs_UplinkConfig.pusch_maxLength;
-  rel15_ul->ulsch_pdu_rel15.Qm             = ulsch_pdu->qam_mod_order;
-  rel15_ul->ulsch_pdu_rel15.mcs            = ulsch_pdu->mcs_index;
-  rel15_ul->ulsch_pdu_rel15.rv             = ulsch_pdu->pusch_data.rv_index;
-  rel15_ul->ulsch_pdu_rel15.n_layers       = ulsch_pdu->nrOfLayers;
-  rel15_ul->ulsch_pdu_rel15.R              = ulsch_pdu->target_code_rate;
 
 }
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
index 52f3fbb5f9..a6fcb874f4 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
@@ -68,15 +68,8 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
 void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
                                  NR_gNB_PUSCH *pusch_vars,
                                  unsigned char symbol,
-                                 unsigned short start_rb,
-                                 unsigned short nb_rb_pusch,
-                                 uint16_t n_rnti,
-                                 NR_DL_FRAME_PARMS *frame_parms,
-                                 uint16_t number_symbols,
-                                 uint8_t mapping_type,
-                                 uint8_t ptrs_configured,
-                                 dmrs_UplinkConfig_t *dmrs_UplinkConfig,
-                                 ptrs_UplinkConfig_t *ptrs_Uplink_Config);
+                                 nfapi_nr_pusch_pdu_t *pusch_pdu,
+                                 NR_DL_FRAME_PARMS *frame_parms);
 
 void nr_ulsch_scale_channel(int32_t **ul_ch_estimates_ext,
                             NR_DL_FRAME_PARMS *frame_parms,
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch.h b/openair1/PHY/NR_TRANSPORT/nr_ulsch.h
index b4ce29eedf..7ff52ae692 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch.h
@@ -53,12 +53,11 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
                            uint8_t UE_id,
                            short *ulsch_llr,
                            NR_DL_FRAME_PARMS *frame_parms,
+                           nfapi_nr_pusch_pdu_t *pusch_pdu,
                            uint32_t frame,
-                           uint16_t nb_symb_sch,
-                           uint16_t nb_re_dmrs,
                            uint8_t nr_tti_rx,
                            uint8_t harq_pid,
-                           uint8_t is_crnti);
+                           uint32_t G);
 
 
 /*! \brief Perform PUSCH unscrambling. TS 38.211 V15.4.0 subclause 6.3.1.1
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
index 0b9e919b25..e8a961360f 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
@@ -121,7 +121,7 @@ NR_gNB_ULSCH_t *new_gNB_ulsch(uint8_t max_ldpc_iterations,uint16_t N_RB_UL, uint
   if (N_RB_UL != 273) {
     a_segments = a_segments*N_RB_UL;
     a_segments = a_segments/273;
-  }  
+  }
 
   uint16_t ulsch_bytes = a_segments*1056;  // allocated bytes per segment
 
@@ -295,15 +295,13 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
                            uint8_t UE_id,
                            short *ulsch_llr,
                            NR_DL_FRAME_PARMS *frame_parms,
+                           nfapi_nr_pusch_pdu_t *pusch_pdu,
                            uint32_t frame,
-                           uint16_t nb_symb_sch,
-                           uint16_t nb_re_dmrs,
                            uint8_t nr_tti_rx,
                            uint8_t harq_pid,
-                           uint8_t is_crnti)
-{
+                           uint32_t G) {
+
   uint32_t A,E;
-  uint32_t G;
   uint32_t ret, offset;
   int32_t no_iteration_ldpc, length_dec;
   uint32_t r,r_offset=0,Kr=8424,Kr_bytes,K_bytes_F,err_flag=0;
@@ -317,7 +315,6 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
 
   NR_gNB_ULSCH_t                       *ulsch                 = phy_vars_gNB->ulsch[UE_id][0];
   NR_UL_gNB_HARQ_t                     *harq_process          = ulsch->harq_processes[harq_pid];
-  nfapi_nr_ul_config_ulsch_pdu_rel15_t *nfapi_ulsch_pdu_rel15 = &harq_process->ulsch_pdu.ulsch_pdu_rel15;
   
   t_nrLDPC_dec_params decParams;
   t_nrLDPC_dec_params* p_decParams    = &decParams;
@@ -337,13 +334,11 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
   double   Coderate = 0.0;
   
   // ------------------------------------------------------------------
-  uint16_t nb_rb          = nfapi_ulsch_pdu_rel15->number_rbs;
-  uint16_t number_symbols = nfapi_ulsch_pdu_rel15->number_symbols;
-  uint8_t Qm              = nfapi_ulsch_pdu_rel15->Qm;
-  uint16_t R               = nfapi_ulsch_pdu_rel15->R;
-  uint8_t mcs             = nfapi_ulsch_pdu_rel15->mcs;
-  uint8_t n_layers        = nfapi_ulsch_pdu_rel15->n_layers;
-  uint8_t length_dmrs     = nfapi_ulsch_pdu_rel15->length_dmrs;
+  uint16_t nb_rb          = pusch_pdu->rb_size;
+  uint8_t Qm              = pusch_pdu->qam_mod_order;
+  uint16_t R              = pusch_pdu->target_code_rate;
+  uint8_t mcs             = pusch_pdu->mcs_index;
+  uint8_t n_layers        = pusch_pdu->nrOfLayers;
   // ------------------------------------------------------------------
 
   uint32_t i,j;
@@ -363,19 +358,20 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
   }
 
   // harq_process->trials[nfapi_ulsch_pdu_rel15->round]++;
-  harq_process->TBS = nr_compute_tbs(Qm, R, nb_rb, number_symbols, nb_re_dmrs*length_dmrs, 0, n_layers);
+  harq_process->TBS = pusch_pdu->pusch_data.tb_size;
 
-  A   = harq_process->TBS;
+  A   = (harq_process->TBS)<<3;
   ret = ulsch->max_ldpc_iterations + 1;
 
-  G = nr_get_G(nb_rb, number_symbols, nb_re_dmrs, length_dmrs, Qm, n_layers);
-
-  LOG_D(PHY,"ULSCH Decoding, harq_pid %d TBS %d G %d mcs %d Nl %d nb_symb_sch %d nb_rb %d, nb_re_dmrs %d, Qm %d, n_layers %d\n",harq_pid,A,G, mcs, n_layers, nb_symb_sch,nb_rb, nb_re_dmrs, Qm, n_layers);
+  LOG_D(PHY,"ULSCH Decoding, harq_pid %d TBS %d G %d mcs %d Nl %d nb_rb %d, Qm %d, n_layers %d\n",harq_pid,A,G, mcs, n_layers, nb_rb, Qm, n_layers);
 
   if (harq_process->round == 0) {
 
     // This is a new packet, so compute quantities regarding segmentation
-    harq_process->B = A+24;
+    if (A > 3824)
+      harq_process->B = A+24;
+    else
+      harq_process->B = A+16;
 
     if (R<1024)
       Coderate = (float) R /(float) 1024;
@@ -412,20 +408,20 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
     }
   }
 
-    // [hna] Perform nr_segmenation with input and output set to NULL to calculate only (B, C, K, Z, F)
-    nr_segmentation(NULL,
-                    NULL,
-                    harq_process->B,
-                    &harq_process->C,
-                    &harq_process->K,
-                    &harq_process->Z, // [hna] Z is Zc
-                    &harq_process->F,
-                    p_decParams->BG);
+  // [hna] Perform nr_segmenation with input and output set to NULL to calculate only (B, C, K, Z, F)
+  nr_segmentation(NULL,
+                  NULL,
+                  harq_process->B,
+                  &harq_process->C,
+                  &harq_process->K,
+                  &harq_process->Z, // [hna] Z is Zc
+                  &harq_process->F,
+                  p_decParams->BG);
 
 #ifdef DEBUG_ULSCH_DECODING
     printf("ulsch decoding nr segmentation Z %d\n", harq_process->Z);
     if (!frame%100)
-      printf("K %d C %d Z %d nl %d \n", harq_process->K, harq_process->C, harq_process->Z, harq_process->Nl);
+      printf("K %d C %d Z %d\n", harq_process->K, harq_process->C, harq_process->Z);
 #endif
   }
   p_decParams->Z = harq_process->Z;
@@ -442,7 +438,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
   if (nb_rb != 273) {
     a_segments = a_segments*nb_rb;
     a_segments = a_segments/273;
-  }  
+  }
 
   if (harq_process->C > a_segments) {
     LOG_E(PHY,"Illegal harq_process->C %d > %d\n",harq_process->C,a_segments);
@@ -460,7 +456,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
   K_bytes_F = Kr_bytes-(harq_process->F>>3);
 
   for (r=0; rC; r++) {
-    E = nr_get_E(G, harq_process->C, nfapi_ulsch_pdu_rel15->Qm, nfapi_ulsch_pdu_rel15->n_layers, r);
+    E = nr_get_E(G, harq_process->C, Qm, n_layers, r);
 
 #if gNB_TIMING_TRACE
     start_meas(ulsch_deinterleaving_stats);
@@ -473,7 +469,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
     //////////////////////////// ulsch_llr =====> harq_process->e //////////////////////////////
 
     nr_deinterleaving_ldpc(E,
-                           nfapi_ulsch_pdu_rel15->Qm,
+                           Qm,
                            harq_process->e[r],
                            ulsch_llr+r_offset);
 
@@ -493,10 +489,10 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
           harq_pid,r, G,
           Kr*3,
           harq_process->TBS,
-          nfapi_ulsch_pdu_rel15->Qm,
-          nfapi_ulsch_pdu_rel15->number_rbs,
-          nfapi_ulsch_pdu_rel15->n_layers,
-          nfapi_ulsch_pdu_rel15->rv,
+          Qm,
+          nb_rb,
+          n_layers,
+          pusch_pdu->pusch_data.rv_index,
           harq_process->round);
 #endif
     //////////////////////////////////////////////////////////////////////////////////////////
@@ -508,7 +504,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
 
     ///////////////////////// harq_process->e =====> harq_process->d /////////////////////////
 
-    Tbslbrm = nr_compute_tbslbrm(0,nb_rb,nfapi_ulsch_pdu_rel15->n_layers,harq_process->C);
+    Tbslbrm = nr_compute_tbslbrm(0,nb_rb,n_layers,harq_process->C);
 
     if (nr_rate_matching_ldpc_rx(Ilbrm,
                                  Tbslbrm,
@@ -517,7 +513,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
                                  harq_process->d[r],
                                  harq_process->e[r],
                                  harq_process->C,
-                                 nfapi_ulsch_pdu_rel15->rv,
+                                 pusch_pdu->pusch_data.rv_index,
                                  (harq_process->round==0)?1:0,
                                  E,
 				 harq_process->F,
@@ -554,7 +550,11 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
 
     //    printf("done\n");
     if (harq_process->C == 1) {
-      crc_type = CRC24_A;
+      if (A > 3824)
+        crc_type = CRC24_A;
+      else
+        crc_type = CRC16;
+
       length_dec = harq_process->B;
     }
     else {
@@ -653,7 +653,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
   int32_t tti_rx_prev = nr_tti_rx - 1;
   if (tti_rx_prev < 0) {
     frame_rx_prev--;
-    tti_rx_prev += 10*frame_parms->ttis_per_subframe;
+    tti_rx_prev += frame_parms->slots_per_frame;
   }
   frame_rx_prev = frame_rx_prev%1024;
 
@@ -677,10 +677,8 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
       ulsch->harq_mask &= ~(1 << harq_pid);
     }
 
-    if(is_crnti) {
-      LOG_D(PHY,"[gNB %d] ULSCH: Setting NACK for nr_tti_rx %d (pid %d, pid status %d, round %d/Max %d, TBS %d)\n",
-            phy_vars_gNB->Mod_id,nr_tti_rx,harq_pid,harq_process->status,harq_process->round,ulsch->Mlimit,harq_process->TBS);
-    }
+    //  LOG_D(PHY,"[gNB %d] ULSCH: Setting NACK for nr_tti_rx %d (pid %d, pid status %d, round %d/Max %d, TBS %d)\n",
+       //     phy_vars_gNB->Mod_id,nr_tti_rx,harq_pid,harq_process->status,harq_process->round,ulsch->Mlimit,harq_process->TBS);
 
     harq_process->handled  = 1;
     ret = ulsch->max_ldpc_iterations + 1;
@@ -700,10 +698,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
     // harq_process->harq_ack.harq_id = harq_pid;
     // harq_process->harq_ack.send_harq_status = 1;
 
-    if(is_crnti)
-    {
-      LOG_D(PHY,"[gNB %d] ULSCH: Setting ACK for nr_tti_rx %d (pid %d, round %d, TBS %d)\n",phy_vars_gNB->Mod_id,nr_tti_rx,harq_pid,harq_process->round,harq_process->TBS);
-    }
+    //  LOG_D(PHY,"[gNB %d] ULSCH: Setting ACK for nr_tti_rx %d (pid %d, round %d, TBS %d)\n",phy_vars_gNB->Mod_id,nr_tti_rx,harq_pid,harq_process->round,harq_process->TBS);
 
     // Reassembly of Transport block here
     offset = 0;
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
index 8ca920359e..e02278d664 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
@@ -222,18 +222,12 @@ void nr_idft(uint32_t *z, uint32_t Msc_PUSCH)
 
 }
 
+
 void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
                                  NR_gNB_PUSCH *pusch_vars,
                                  unsigned char symbol,
-                                 unsigned short start_rb,
-                                 unsigned short nb_rb_pusch,
-                                 uint16_t n_rnti,
-                                 NR_DL_FRAME_PARMS *frame_parms,
-                                 uint16_t number_symbols,
-                                 uint8_t mapping_type,
-                                 uint8_t ptrs_configured,
-                                 dmrs_UplinkConfig_t *dmrs_UplinkConfig,
-                                 ptrs_UplinkConfig_t *ptrs_Uplink_Config)
+                                 nfapi_nr_pusch_pdu_t *pusch_pdu,
+                                 NR_DL_FRAME_PARMS *frame_parms)
 {
   unsigned short start_re, re, nb_re_pusch;
   unsigned char aarx;
@@ -248,22 +242,23 @@ void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
   int16_t *rxF,*rxF_ext;
   int *ul_ch0,*ul_ch0_ext;
   int *ul_ch0_ptrs,*ul_ch0_ptrs_ext;
+  uint16_t n_rnti = pusch_pdu->rnti;
 
 #ifdef DEBUG_RB_EXT
 
   printf("--------------------symbol = %d-----------------------\n", symbol);
-  printf("--------------------ch_ext_index = %d-----------------------\n", symbol*NR_NB_SC_PER_RB * nb_rb_pusch);
+  printf("--------------------ch_ext_index = %d-----------------------\n", symbol*NR_NB_SC_PER_RB * pusch_pdu->rb_size);
 
 #endif
   
-  start_re = (frame_parms->first_carrier_offset + (start_rb * NR_NB_SC_PER_RB))%frame_parms->ofdm_symbol_size;
+  start_re = (frame_parms->first_carrier_offset + (pusch_pdu->rb_start * NR_NB_SC_PER_RB))%frame_parms->ofdm_symbol_size;
   
-  nb_re_pusch = NR_NB_SC_PER_RB * nb_rb_pusch;
+  nb_re_pusch = NR_NB_SC_PER_RB * pusch_pdu->rb_size;
   is_dmrs_symbol_flag = 0;
   is_ptrs_symbol_flag = 0;
   num_ptrs_symbols = 0;
 
-  K_ptrs = get_K_ptrs(ptrs_Uplink_Config, nb_rb_pusch);
+  K_ptrs = (pusch_pdu->pusch_ptrs.ptrs_freq_density)?4:2;
 
   for (aarx = 0; aarx < frame_parms->nb_antennas_rx; aarx++) {
     
@@ -289,24 +284,23 @@ void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
                                             k_prime,
                                             n,
                                             0,
-                                            number_symbols,
-                                            dmrs_UplinkConfig,
-                                            mapping_type,
+                                            pusch_pdu->nr_of_symbols,
+                                            pusch_pdu->dmrs_config_type,
                                             frame_parms->ofdm_symbol_size);
 
-      if (ptrs_configured == 1){
+      if ( ((pusch_pdu->pdu_bit_map)>>2)& 0x01 ) {
         is_ptrs_symbol_flag = is_ptrs_symbol(symbol,
                                              (start_re + re)%frame_parms->ofdm_symbol_size,
                                              n_rnti,
-                                             nb_rb_pusch,
-                                             number_symbols,
+                                             pusch_pdu->rb_size,
+                                             pusch_pdu->nr_of_symbols,
                                              aarx,
                                              K_ptrs,
                                              pusch_vars->ptrs_symbols,
                                              start_re,
                                              frame_parms->ofdm_symbol_size,
-                                             dmrs_UplinkConfig->pusch_dmrs_type,
-                                             ptrs_Uplink_Config);
+                                             pusch_pdu->dmrs_config_type,
+                                             pusch_pdu->pusch_ptrs.ptrs_ports_list[0].ptrs_re_offset);
 
         if (is_ptrs_symbol_flag == 1)
           num_ptrs_symbols++;
@@ -505,18 +499,17 @@ void nr_ulsch_channel_level(int **ul_ch_estimates_ext,
 }
 
 void nr_ulsch_channel_compensation(int **rxdataF_ext,
-                                int **ul_ch_estimates_ext,
-                                int **ul_ch_mag,
-                                int **ul_ch_magb,
-                                int **rxdataF_comp,
-                                int **rho,
-                                NR_DL_FRAME_PARMS *frame_parms,
-                                unsigned char symbol,
-                                uint8_t is_dmrs_symbol,
-                                unsigned char mod_order,
-                                unsigned short nb_rb,
-                                unsigned char output_shift)
-{
+                                   int **ul_ch_estimates_ext,
+                                   int **ul_ch_mag,
+                                   int **ul_ch_magb,
+                                   int **rxdataF_comp,
+                                   int **rho,
+                                   NR_DL_FRAME_PARMS *frame_parms,
+                                   unsigned char symbol,
+                                   uint8_t is_dmrs_symbol,
+                                   unsigned char mod_order,
+                                   unsigned short nb_rb,
+                                   unsigned char output_shift) {
 
 #ifdef DEBUG_CH_COMP
   int16_t *rxF, *ul_ch;
@@ -1039,172 +1032,155 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
 
   uint8_t first_symbol_flag, aarx, aatx, dmrs_symbol_flag, ptrs_symbol_flag; // dmrs_symbol_flag, a flag to indicate DMRS REs in current symbol
   uint32_t nb_re_pusch, bwp_start_subcarrier;
-  uint8_t mapping_type;
   uint8_t L_ptrs = 0; // PTRS parameter
   int avgs;
   int avg[4];
   NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms;
-  nfapi_nr_ul_config_ulsch_pdu_rel15_t *rel15_ul = &gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu.ulsch_pdu_rel15;
-  ptrs_UplinkConfig_t *ptrs_Uplink_Config = &gNB->pusch_config.dmrs_UplinkConfig.ptrs_UplinkConfig;
+  nfapi_nr_pusch_pdu_t *rel15_ul = &gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu;
 
   dmrs_symbol_flag = 0;
   ptrs_symbol_flag = 0;
   first_symbol_flag = 0;
-  mapping_type = gNB->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType;
   gNB->pusch_vars[UE_id]->ptrs_sc_per_ofdm_symbol = 0;
 
-  if (mapping_type == typeB) {
+  if(symbol == rel15_ul->start_symbol_index){
+    gNB->pusch_vars[UE_id]->rxdataF_ext_offset = 0;
+    gNB->pusch_vars[UE_id]->dmrs_symbol = 0;
+    gNB->pusch_vars[UE_id]->cl_done = 0;
+    gNB->pusch_vars[UE_id]->ptrs_symbols = 0;
+    first_symbol_flag = 1;
 
-    if(symbol == rel15_ul->start_symbol){
-      gNB->pusch_vars[UE_id]->rxdataF_ext_offset = 0;
-      gNB->pusch_vars[UE_id]->dmrs_symbol = 0;
-      first_symbol_flag = 1;
-
-      L_ptrs = get_L_ptrs(ptrs_Uplink_Config, rel15_ul->mcs);
-
-      gNB->pusch_vars[UE_id]->ptrs_symbols = 0;
+    if ( ((rel15_ul->pdu_bit_map)>>2)& 0x01 ) {  // if there is ptrs pdu
+      L_ptrs = 1<<(rel15_ul->pusch_ptrs.ptrs_time_density);
 
       set_ptrs_symb_idx(&gNB->pusch_vars[UE_id]->ptrs_symbols,
-                        ptrs_Uplink_Config,
-                        &gNB->pusch_config.dmrs_UplinkConfig,
-                        1,
-                        rel15_ul->number_symbols,
-                        rel15_ul->start_symbol,
+                        rel15_ul->nr_of_symbols,
+                        rel15_ul->start_symbol_index,
+                        rel15_ul->dmrs_config_type,
                         L_ptrs,
+                        1, // only dmrs of length 1 is currently supported
                         frame_parms->ofdm_symbol_size);
-
     }
-
-    bwp_start_subcarrier = (rel15_ul->start_rb*NR_NB_SC_PER_RB + frame_parms->first_carrier_offset) % frame_parms->ofdm_symbol_size;
-
-    dmrs_symbol_flag = is_dmrs_symbol(symbol,
-                                      0,
-                                      0,
-                                      0,
-                                      0,
-                                      0,
-                                      rel15_ul->number_symbols,
-                                      &gNB->pusch_config.dmrs_UplinkConfig,
-                                      mapping_type,
-                                      frame_parms->ofdm_symbol_size);
-
-    if (dmrs_symbol_flag == 1){
-      nb_re_pusch = rel15_ul->number_rbs * ((gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type==pusch_dmrs_type1)?6:8);
-      gNB->pusch_vars[UE_id]->dmrs_symbol = symbol;
-    } else {
-        nb_re_pusch = rel15_ul->number_rbs * NR_NB_SC_PER_RB;
-    }
-
-    if (gNB->ptrs_configured == 1)
-        ptrs_symbol_flag = is_ptrs_symbol(symbol,
-                                          0,
-                                          gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu.rnti,
-                                          rel15_ul->number_rbs,
-                                          rel15_ul->number_symbols,
-                                          0,
-                                          get_K_ptrs(ptrs_Uplink_Config, rel15_ul->number_rbs),
-                                          gNB->pusch_vars[UE_id]->ptrs_symbols,
-                                          0,
-                                          frame_parms->ofdm_symbol_size,
-                                          gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type,
-                                          ptrs_Uplink_Config);
-
-
-    if (ptrs_symbol_flag == 1){
-      gNB->pusch_vars[UE_id]->ptrs_symbol_index = symbol;
-    }
-
-
-    //----------------------------------------------------------
-    //--------------------- Channel estimation ---------------------
-    //----------------------------------------------------------
-
-    if (dmrs_symbol_flag == 1)
-      nr_pusch_channel_estimation(gNB,
-                                  0,
-                                  nr_tti_rx,
-                                  0, // p
-                                  symbol,
-                                  bwp_start_subcarrier,
-                                  rel15_ul->number_rbs,
-                                  &gNB->pusch_config.dmrs_UplinkConfig);
-
-    //----------------------------------------------------------
-    //--------------------- RBs extraction ---------------------
-    //----------------------------------------------------------
-
-    nr_ulsch_extract_rbs_single(gNB->common_vars.rxdataF,
-                                gNB->pusch_vars[UE_id],
-                                symbol,
-                                rel15_ul->start_rb,
-                                rel15_ul->number_rbs,
-                                gNB->ulsch[UE_id][0]->harq_processes[harq_pid]->ulsch_pdu.rnti,
-                                frame_parms,
-                                rel15_ul->number_symbols,
-                                mapping_type,
-                                gNB->ptrs_configured,
-                                &gNB->pusch_config.dmrs_UplinkConfig,
-                                ptrs_Uplink_Config);
-
-    nr_ulsch_scale_channel(gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
-                           frame_parms,
-                           gNB->ulsch[UE_id],
-                           symbol,
-                           dmrs_symbol_flag,
-                           rel15_ul->number_rbs,
-                           gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type);
-
-    if (first_symbol_flag==1) {
-
-       nr_ulsch_channel_level(gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
-                             frame_parms,
-                             avg,
-                             symbol,
-                             nb_re_pusch,
-                             rel15_ul->number_rbs);
-       avgs = 0;
-
-       for (aatx=0;aatxnb_antennas_tx;aatx++)
-         for (aarx=0;aarxnb_antennas_rx;aarx++)
-           avgs = cmax(avgs,avg[(aatx<<1)+aarx]);
-
-       gNB->pusch_vars[UE_id]->log2_maxh = (log2_approx(avgs)/2)+1;
-
-    }
-
-    nr_ulsch_channel_compensation(gNB->pusch_vars[UE_id]->rxdataF_ext,
-                                  gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
-                                  gNB->pusch_vars[UE_id]->ul_ch_mag0,
-                                  gNB->pusch_vars[UE_id]->ul_ch_magb0,
-                                  gNB->pusch_vars[UE_id]->rxdataF_comp,
-                                  (frame_parms->nb_antennas_tx>1) ? gNB->pusch_vars[UE_id]->rho : NULL,
-                                  frame_parms,
-                                  symbol,
-                                  dmrs_symbol_flag,
-                                  rel15_ul->Qm,
-                                  rel15_ul->number_rbs,
-                                  gNB->pusch_vars[UE_id]->log2_maxh);
-
-  #ifdef NR_SC_FDMA
-    nr_idft(&((uint32_t*)gNB->pusch_vars[UE_id]->rxdataF_ext[0])[symbol * rel15_ul->number_rbs * NR_NB_SC_PER_RB], nb_re_pusch);
-  #endif
-
-    //----------------------------------------------------------
-    //-------------------- LLRs computation --------------------
-    //----------------------------------------------------------
-
-    nr_ulsch_compute_llr(&gNB->pusch_vars[UE_id]->rxdataF_comp[0][symbol * rel15_ul->number_rbs * NR_NB_SC_PER_RB],
-                         gNB->pusch_vars[UE_id]->ul_ch_mag0,
-                         gNB->pusch_vars[UE_id]->ul_ch_magb0,
-                         &gNB->pusch_vars[UE_id]->llr[gNB->pusch_vars[UE_id]->rxdataF_ext_offset * rel15_ul->Qm],
-                         rel15_ul->number_rbs,
-                         nb_re_pusch,
-                         symbol,
-                         rel15_ul->Qm);
-
-    gNB->pusch_vars[UE_id]->rxdataF_ext_offset = gNB->pusch_vars[UE_id]->rxdataF_ext_offset +  nb_re_pusch - gNB->pusch_vars[UE_id]->ptrs_sc_per_ofdm_symbol;
-  } else {
-    LOG_E(PHY, "PUSCH mapping type A is not supported \n");
   }
+
+  bwp_start_subcarrier = (rel15_ul->rb_start*NR_NB_SC_PER_RB + frame_parms->first_carrier_offset) % frame_parms->ofdm_symbol_size;
+
+  dmrs_symbol_flag = is_dmrs_symbol(symbol,
+                                    0,
+                                    0,
+                                    0,
+                                    0,
+                                    0,
+                                    rel15_ul->nr_of_symbols,
+                                    rel15_ul->dmrs_config_type,
+                                    frame_parms->ofdm_symbol_size);
+
+  if (dmrs_symbol_flag == 1){
+    nb_re_pusch = rel15_ul->rb_size * ((rel15_ul->dmrs_config_type==pusch_dmrs_type1)?6:8);
+    gNB->pusch_vars[UE_id]->dmrs_symbol = symbol;
+  } else {
+    nb_re_pusch = rel15_ul->rb_size * NR_NB_SC_PER_RB;
+  }
+
+  if ( ((rel15_ul->pdu_bit_map)>>2)& 0x01 ) {  // if there is ptrs pdu
+    ptrs_symbol_flag = is_ptrs_symbol(symbol,
+                                      0,
+                                      rel15_ul->rnti,
+                                      rel15_ul->rb_size,
+                                      rel15_ul->nr_of_symbols,
+                                      0,
+                                      (rel15_ul->pusch_ptrs.ptrs_freq_density)?4:2,
+                                      gNB->pusch_vars[UE_id]->ptrs_symbols,
+                                      0,
+                                      frame_parms->ofdm_symbol_size,
+                                      rel15_ul->dmrs_config_type,
+                                      rel15_ul->pusch_ptrs.ptrs_ports_list[0].ptrs_re_offset);
+  }
+
+  if (ptrs_symbol_flag == 1){
+    gNB->pusch_vars[UE_id]->ptrs_symbol_index = symbol;
+  }
+
+
+  //----------------------------------------------------------
+  //--------------------- Channel estimation ---------------------
+  //----------------------------------------------------------
+
+  if (dmrs_symbol_flag == 1)
+    nr_pusch_channel_estimation(gNB,
+                                nr_tti_rx,
+                                0, // p
+                                symbol,
+                                bwp_start_subcarrier,
+                                rel15_ul);
+
+  //----------------------------------------------------------
+  //--------------------- RBs extraction ---------------------
+  //----------------------------------------------------------
+
+  nr_ulsch_extract_rbs_single(gNB->common_vars.rxdataF,
+                              gNB->pusch_vars[UE_id],
+                              symbol,
+                              rel15_ul,
+                              frame_parms);
+
+  nr_ulsch_scale_channel(gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
+                         frame_parms,
+                         gNB->ulsch[UE_id],
+                         symbol,
+                         dmrs_symbol_flag,
+                         rel15_ul->rb_size,
+                         rel15_ul->dmrs_config_type);
+
+
+  if (first_symbol_flag==1) {
+
+    nr_ulsch_channel_level(gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
+                           frame_parms,
+                           avg,
+                           symbol,
+                           nb_re_pusch,
+                           rel15_ul->rb_size);
+     avgs = 0;
+
+     for (aatx=0;aatxnb_antennas_tx;aatx++)
+       for (aarx=0;aarxnb_antennas_rx;aarx++)
+         avgs = cmax(avgs,avg[(aatx<<1)+aarx]);
+
+     gNB->pusch_vars[UE_id]->log2_maxh = (log2_approx(avgs)/2)+1;
+
+  }
+
+  nr_ulsch_channel_compensation(gNB->pusch_vars[UE_id]->rxdataF_ext,
+                                gNB->pusch_vars[UE_id]->ul_ch_estimates_ext,
+                                gNB->pusch_vars[UE_id]->ul_ch_mag0,
+                                gNB->pusch_vars[UE_id]->ul_ch_magb0,
+                                gNB->pusch_vars[UE_id]->rxdataF_comp,
+                                (frame_parms->nb_antennas_tx>1) ? gNB->pusch_vars[UE_id]->rho : NULL,
+                                frame_parms,
+                                symbol,
+                                dmrs_symbol_flag,
+                                rel15_ul->qam_mod_order,
+                                rel15_ul->rb_size,
+                                gNB->pusch_vars[UE_id]->log2_maxh);
+
+#ifdef NR_SC_FDMA
+  nr_idft(&((uint32_t*)gNB->pusch_vars[UE_id]->rxdataF_ext[0])[symbol * rel15_ul->rb_size * NR_NB_SC_PER_RB], nb_re_pusch);
+#endif
+
+  //----------------------------------------------------------
+  //-------------------- LLRs computation --------------------
+  //----------------------------------------------------------
+
+  nr_ulsch_compute_llr(&gNB->pusch_vars[UE_id]->rxdataF_comp[0][symbol * rel15_ul->rb_size * NR_NB_SC_PER_RB],
+                       gNB->pusch_vars[UE_id]->ul_ch_mag0,
+                       gNB->pusch_vars[UE_id]->ul_ch_magb0,
+                       &gNB->pusch_vars[UE_id]->llr[gNB->pusch_vars[UE_id]->rxdataF_ext_offset * rel15_ul->qam_mod_order],
+                       rel15_ul->rb_size,
+                       nb_re_pusch,
+                       symbol,
+                       rel15_ul->qam_mod_order);
+
+  gNB->pusch_vars[UE_id]->rxdataF_ext_offset = gNB->pusch_vars[UE_id]->rxdataF_ext_offset +  nb_re_pusch - gNB->pusch_vars[UE_id]->ptrs_sc_per_ofdm_symbol;
   
 }
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
index 6bcaba4604..55bac90520 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
@@ -292,17 +292,35 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch,
       printf("%02x.",a[i]);
     printf("\n");
     */
-    // Add 24-bit crc (polynomial A) to payload
-    crc = crc24a(harq_process->a,A)>>8;
-    harq_process->a[A>>3] = ((uint8_t*)&crc)[2];
-    harq_process->a[1+(A>>3)] = ((uint8_t*)&crc)[1];
-    harq_process->a[2+(A>>3)] = ((uint8_t*)&crc)[0];
-    //printf("CRC %x (A %d)\n",crc,A);
-    //printf("a0 %d a1 %d a2 %d\n", a[A>>3], a[1+(A>>3)], a[2+(A>>3)]);
+    if (A > 3824) {
+      // Add 24-bit crc (polynomial A) to payload
+      crc = crc24a(harq_process->a,A)>>8;
+      harq_process->a[A>>3] = ((uint8_t*)&crc)[2];
+      harq_process->a[1+(A>>3)] = ((uint8_t*)&crc)[1];
+      harq_process->a[2+(A>>3)] = ((uint8_t*)&crc)[0];
+      //printf("CRC %x (A %d)\n",crc,A);
+      //printf("a0 %d a1 %d a2 %d\n", a[A>>3], a[1+(A>>3)], a[2+(A>>3)]);
 
-    harq_process->B = A+24;
+      harq_process->B = A+24;
 
-    memcpy(harq_process->b,harq_process->a,(A/8)+4);
+      AssertFatal((A/8)+4 <= MAX_NR_ULSCH_PAYLOAD_BYTES,"A %d is too big (A/8+4 = %d > %d)\n",A,(A/8)+4,MAX_NR_ULSCH_PAYLOAD_BYTES);
+
+      memcpy(harq_process->b,harq_process->a,(A/8)+4);
+    }
+    else {
+      // Add 16-bit crc (polynomial A) to payload
+      crc = crc16(harq_process->a,A)>>16;
+      harq_process->a[A>>3] = ((uint8_t*)&crc)[1];
+      harq_process->a[1+(A>>3)] = ((uint8_t*)&crc)[0];
+      //printf("CRC %x (A %d)\n",crc,A);
+      //printf("a0 %d a1 %d \n", a[A>>3], a[1+(A>>3)]);
+
+      harq_process->B = A+16;
+
+      AssertFatal((A/8)+3 <= MAX_NR_ULSCH_PAYLOAD_BYTES,"A %d is too big (A/8+3 = %d > %d)\n",A,(A/8)+3,MAX_NR_ULSCH_PAYLOAD_BYTES);
+
+      memcpy(harq_process->b,harq_process->a,(A/8)+3);  // using 3 bytes to mimic the case of 24 bit crc
+    }
 
 ///////////
 ///////////////////////////////////////////////////////////////////////////
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 1dd971fc90..bdd8ea8c24 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -108,7 +108,6 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
   int8_t Wf[2], Wt[2], l_prime[2], delta;
   uint16_t n_dmrs, code_rate, number_dmrs_symbols, k;
   uint8_t dmrs_type;
-  uint8_t mapping_type;
   int ap, start_symbol, Nid_cell, i;
   int sample_offsetF, N_RE_prime, N_PRB_oh;
   uint16_t n_rnti;
@@ -129,8 +128,6 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
   N_PRB_oh = 0; // higher layer (RRC) parameter xOverhead in PUSCH-ServingCellConfig
   number_dmrs_symbols = 0;
 
-  mapping_type = UE->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType;
-
   for (cwd_index = 0;cwd_index < num_of_codewords; cwd_index++) {
 
     ulsch_ue = UE->ulsch[thread_id][gNB_id][cwd_index];
@@ -146,8 +143,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                             0,
                                             0,
                                             harq_process_ul_ue->number_of_symbols,
-                                            &UE->pusch_config.dmrs_UplinkConfig,
-                                            mapping_type,
+                                            UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type,
                                             frame_parms->ofdm_symbol_size);
 
     ulsch_ue->length_dmrs = UE->pusch_config.dmrs_UplinkConfig.pusch_maxLength;
@@ -303,12 +299,11 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
     ulsch_ue->ptrs_symbols = 0;
 
     set_ptrs_symb_idx(&ulsch_ue->ptrs_symbols,
-                      ptrs_Uplink_Config,
-                      &UE->pusch_config.dmrs_UplinkConfig,
-                      1,
                       harq_process_ul_ue->number_of_symbols,
                       start_symbol,
+                      dmrs_type,
                       L_ptrs,
+                      ulsch_ue->length_dmrs,
                       frame_parms->ofdm_symbol_size);
   }
 
@@ -347,8 +342,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                              0,
                              0,
                              harq_process_ul_ue->number_of_symbols,
-                             &UE->pusch_config.dmrs_UplinkConfig,
-                             mapping_type,
+                             dmrs_type,
                              frame_parms->ofdm_symbol_size);
 
     if (is_dmrs == 1)
@@ -414,8 +408,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                  n,
                                  delta,
                                  harq_process_ul_ue->number_of_symbols,
-                                 &UE->pusch_config.dmrs_UplinkConfig,
-                                 mapping_type,
+                                 dmrs_type,
                                  frame_parms->ofdm_symbol_size);
 
         if (UE->ptrs_configured == 1){
@@ -430,7 +423,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                    start_sc,
                                    frame_parms->ofdm_symbol_size,
                                    UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type,
-                                   ptrs_Uplink_Config);
+                                   ptrs_Uplink_Config->resourceElementOffset);
         }
 
         if (is_dmrs == 1) {
diff --git a/openair1/PHY/defs_gNB.h b/openair1/PHY/defs_gNB.h
index 04351d6434..b5a24ca793 100644
--- a/openair1/PHY/defs_gNB.h
+++ b/openair1/PHY/defs_gNB.h
@@ -162,7 +162,7 @@ typedef struct {
 
 typedef struct {
   /// Nfapi ULSCH PDU
-  nfapi_nr_ul_config_ulsch_pdu ulsch_pdu;
+  nfapi_nr_pusch_pdu_t ulsch_pdu;
   /// Frame where current HARQ round was sent
   uint32_t frame;
   /// Subframe where current HARQ round was sent
@@ -410,7 +410,7 @@ typedef struct {
   /// \brief llr values.
   /// - first index: ? [0..1179743] (hard coded)
   int16_t *llr;
-  // DMRS symbol index, to be updated every DMRS symbol within a slot.
+  /// DMRS symbol index, to be updated every DMRS symbol within a slot.
   uint8_t dmrs_symbol;
   // PTRS symbol index, to be updated every PTRS symbol within a slot.
   uint8_t ptrs_symbol_index;
@@ -418,6 +418,8 @@ typedef struct {
   uint16_t ptrs_symbols;
   // PTRS subcarriers per OFDM symbol
   uint16_t ptrs_sc_per_ofdm_symbol;
+  /// flag to verify if channel level computation is done
+  uint8_t cl_done;
 } NR_gNB_PUSCH;
 
 
@@ -672,11 +674,8 @@ typedef struct PHY_VARS_gNB_s {
   /// PDSCH DMRS sequence
   uint32_t ****nr_gold_pdsch_dmrs;
 
-  /// flag to indicate if PTRS is configured
-  uint8_t ptrs_configured;
-  
   /// PUSCH DMRS
-  uint32_t nr_gold_pusch[2][20][2][NR_MAX_PUSCH_DMRS_INIT_LENGTH_DWORD];
+  uint32_t ****nr_gold_pusch_dmrs;
 
   /// Indicator set to 0 after first SR
   uint8_t first_sr[NUMBER_OF_NR_SR_MAX];
@@ -710,12 +709,6 @@ typedef struct PHY_VARS_gNB_s {
   /// counter to average prach energh over first 100 prach opportunities
   int prach_energy_counter;
 
-  PUSCH_Config_t pusch_config;
-
-  dmrs_UplinkConfig_t dmrs_UplinkConfig;
-
-  dmrs_DownlinkConfig_t dmrs_DownlinkConfig;
-
   /*
   time_stats_t phy_proc;
   */
diff --git a/openair1/PHY/impl_defs_nr.h b/openair1/PHY/impl_defs_nr.h
index bbb3da5d52..44f2e314ea 100644
--- a/openair1/PHY/impl_defs_nr.h
+++ b/openair1/PHY/impl_defs_nr.h
@@ -500,8 +500,8 @@ typedef enum {
   pdsch_dmrs_type2 = 2
 } pdsch_dmrs_type_t;
 typedef enum {
-  pusch_dmrs_type1 = 1,
-  pusch_dmrs_type2 = 2
+  pusch_dmrs_type1 = 0,
+  pusch_dmrs_type2 = 1
 } pusch_dmrs_type_t;
 typedef enum {
   pdsch_dmrs_pos0 = 0,
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index 909b91a81c..b28911b495 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -214,21 +214,16 @@ void phy_procedures_gNB_TX(PHY_VARS_gNB *gNB,
 
 void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int ULSCH_id, uint8_t harq_pid)
 {
-  NR_DL_FRAME_PARMS                    *frame_parms           = &gNB->frame_parms;
-  nfapi_nr_ul_config_ulsch_pdu         *rel15_ul              = &gNB->ulsch[ULSCH_id][0]->harq_processes[harq_pid]->ulsch_pdu;
-  nfapi_nr_ul_config_ulsch_pdu_rel15_t *nfapi_ulsch_pdu_rel15 = &rel15_ul->ulsch_pdu_rel15;
+  NR_DL_FRAME_PARMS *frame_parms = &gNB->frame_parms;
+  nfapi_nr_pusch_pdu_t *pusch_pdu = &gNB->ulsch[ULSCH_id][0]->harq_processes[harq_pid]->ulsch_pdu;
   
   uint8_t ret;
   uint8_t l, number_dmrs_symbols = 0;
-  uint8_t mapping_type;
   uint32_t G;
-  int Nid_cell = 0; // [hna] shouldn't be a local variable (should be signaled)
   uint16_t start_symbol, number_symbols, nb_re_dmrs;
 
-  mapping_type = gNB->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType;
-
-  start_symbol = nfapi_ulsch_pdu_rel15->start_symbol;
-  number_symbols = nfapi_ulsch_pdu_rel15->number_symbols;
+  start_symbol = pusch_pdu->start_symbol_index;
+  number_symbols = pusch_pdu->nr_of_symbols;
 
   for (l = start_symbol; l < start_symbol + number_symbols; l++)
       number_dmrs_symbols += is_dmrs_symbol(l,
@@ -238,18 +233,18 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int ULSCH
                                             0,
                                             0,
                                             number_symbols,
-                                            &gNB->pusch_config.dmrs_UplinkConfig,
-                                            mapping_type,
+                                            pusch_pdu->dmrs_config_type,
                                             frame_parms->ofdm_symbol_size);
 
-  nb_re_dmrs = ((gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
 
-  G = nr_get_G(nfapi_ulsch_pdu_rel15->number_rbs,
+  nb_re_dmrs = ((pusch_pdu->dmrs_config_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
+
+  G = nr_get_G(pusch_pdu->rb_size,
                number_symbols,
                nb_re_dmrs,
-               nfapi_ulsch_pdu_rel15->length_dmrs,
-               nfapi_ulsch_pdu_rel15->Qm,
-               nfapi_ulsch_pdu_rel15->n_layers);
+               1, // FIXME only single dmrs is implemented
+               pusch_pdu->qam_mod_order,
+               pusch_pdu->nrOfLayers);
 
 
   //----------------------------------------------------------
@@ -259,23 +254,23 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int ULSCH
   nr_ulsch_unscrambling(gNB->pusch_vars[ULSCH_id]->llr,
                         G,
                         0,
-                        Nid_cell,
-                        rel15_ul->rnti);
+                        pusch_pdu->data_scrambling_id,
+                        pusch_pdu->rnti);
 
   //----------------------------------------------------------
   //--------------------- ULSCH decoding ---------------------
   //----------------------------------------------------------
 
   ret = nr_ulsch_decoding(gNB,
-                    ULSCH_id,
-                    gNB->pusch_vars[ULSCH_id]->llr,
-                    frame_parms,
-                    frame_rx,
-                    number_symbols,
-                    nb_re_dmrs,
-                    slot_rx,
-                    harq_pid,
-                    0);
+                          ULSCH_id,
+                          gNB->pusch_vars[ULSCH_id]->llr,
+                          frame_parms,
+                          pusch_pdu,
+                          frame_rx,
+                          slot_rx,
+                          harq_pid,
+                          G);
+
         
   if (ret > gNB->ulsch[ULSCH_id][0]->max_ldpc_iterations)
     LOG_I(PHY, "ULSCH %d in error\n",ULSCH_id);
diff --git a/openair1/SIMULATION/NR_PHY/ulschsim.c b/openair1/SIMULATION/NR_PHY/ulschsim.c
index 0b9340debd..48ea26da8f 100644
--- a/openair1/SIMULATION/NR_PHY/ulschsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulschsim.c
@@ -371,7 +371,6 @@ int main(int argc, char **argv)
   }
 
   unsigned char harq_pid = 0;
-  uint8_t is_crnti = 0;
   unsigned int TBS = 8424;
   unsigned int available_bits;
   uint8_t nb_re_dmrs = 6;
@@ -385,7 +384,7 @@ int main(int argc, char **argv)
 
   NR_gNB_ULSCH_t *ulsch_gNB = gNB->ulsch[UE_id][0];
   NR_UL_gNB_HARQ_t *harq_process_gNB = ulsch_gNB->harq_processes[harq_pid];
-  nfapi_nr_ul_config_ulsch_pdu_rel15_t *rel15_ul = &harq_process_gNB->ulsch_pdu.ulsch_pdu_rel15;
+  nfapi_nr_pusch_pdu_t *rel15_ul = &harq_process_gNB->ulsch_pdu;
 
   NR_UE_ULSCH_t *ulsch_ue = UE->ulsch[0][0][0];
 
@@ -397,14 +396,15 @@ int main(int argc, char **argv)
   printf("\nAvailable bits %u TBS %u mod_order %d\n", available_bits, TBS, mod_order);
 
   /////////// setting rel15_ul parameters ///////////
-  rel15_ul->number_rbs     = nb_rb;
-  rel15_ul->number_symbols = nb_symb_sch;
-  rel15_ul->Qm             = mod_order;
-  rel15_ul->mcs            = Imcs;
-  rel15_ul->rv             = rvidx;
-  rel15_ul->n_layers       = Nl;
-  rel15_ul->length_dmrs    = length_dmrs;
-  rel15_ul->R              = code_rate;
+  rel15_ul->rb_size             = nb_rb;
+  rel15_ul->nr_of_symbols       = nb_symb_sch;
+  rel15_ul->qam_mod_order       = mod_order;
+  rel15_ul->mcs_index           = Imcs;
+  rel15_ul->pusch_data.rv_index = rvidx;
+  rel15_ul->nrOfLayers          = Nl;
+  //rel15_ul->length_dmrs       = length_dmrs;
+  rel15_ul->target_code_rate    = code_rate;
+  rel15_ul->pusch_data.tb_size  = TBS>>3;
   ///////////////////////////////////////////////////
 
   double *modulated_input = malloc16(sizeof(double) * 16 * 68 * 384); // [hna] 16 segments, 68*Zc
@@ -527,8 +527,15 @@ int main(int argc, char **argv)
       exit(-1);
 #endif
 
-      ret = nr_ulsch_decoding(gNB, UE_id, channel_output_fixed, frame_parms,
-                              frame, nb_symb_sch, nb_re_dmrs, subframe, harq_pid, is_crnti);
+     uint32_t G = nr_get_G(rel15_ul->rb_size,
+                           rel15_ul->nr_of_symbols,
+                           nb_re_dmrs,
+                           1, // FIXME only single dmrs is implemented 
+                           rel15_ul->qam_mod_order,
+                           rel15_ul->nrOfLayers);
+
+      ret = nr_ulsch_decoding(gNB, UE_id, channel_output_fixed, frame_parms, rel15_ul,
+                              frame, subframe, harq_pid, G);
 
       if (ret > ulsch_gNB->max_ldpc_iterations)
         n_errors++;
diff --git a/openair1/SIMULATION/NR_PHY/ulsim.c b/openair1/SIMULATION/NR_PHY/ulsim.c
index 1ca4a5a389..2adc67501a 100644
--- a/openair1/SIMULATION/NR_PHY/ulsim.c
+++ b/openair1/SIMULATION/NR_PHY/ulsim.c
@@ -511,8 +511,7 @@ int main(int argc, char **argv)
                                             0,
                                             0,
                                             nb_symb_sch,
-                                            &UE->pusch_config.dmrs_UplinkConfig,
-                                            UE->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType,
+                                            UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type,
                                             frame_parms->ofdm_symbol_size);
 
   mod_order      = nr_get_Qm_ul(Imcs, 0);
@@ -563,10 +562,6 @@ int main(int argc, char **argv)
       pusch_pdu->nrOfLayers = 1;
       pusch_pdu->ul_dmrs_symb_pos = 1;
       pusch_pdu->dmrs_config_type = 0;
-      // inserted to make simulation work 
-      // remove the next 2 lines when P7 is integrated from new branch
-      gNB->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type=pusch_dmrs_type1;
-      gNB->pusch_config.dmrs_UplinkConfig.pusch_maxLength   = length_dmrs;
       pusch_pdu->ul_dmrs_scrambling_id =  0;
       pusch_pdu->scid = 0;
       pusch_pdu->resource_alloc = 1; 
@@ -580,7 +575,7 @@ int main(int argc, char **argv)
       pusch_pdu->pusch_data.rv_index = 0;
       pusch_pdu->pusch_data.harq_process_id = 0;
       pusch_pdu->pusch_data.new_data_indicator = 0;
-      pusch_pdu->pusch_data.tb_size = TBS;
+      pusch_pdu->pusch_data.tb_size = TBS>>3;
       pusch_pdu->pusch_data.num_cb = 0;
 
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
index 85d0a04b54..f1e2e8e071 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
@@ -781,13 +781,13 @@ void nr_schedule_uss_ulsch_phytest(int Mod_idP,
   pusch_pdu->pusch_data.rv_index = 0;
   pusch_pdu->pusch_data.harq_process_id = 0;
   pusch_pdu->pusch_data.new_data_indicator = 0;
-  pusch_pdu->pusch_data.tb_size = nr_compute_tbs(pusch_pdu->mcs_index,
+  pusch_pdu->pusch_data.tb_size = nr_compute_tbs(pusch_pdu->qam_mod_order,
 						 pusch_pdu->target_code_rate,
 						 pusch_pdu->rb_size,
 						 pusch_pdu->nr_of_symbols,
 						 6, //nb_re_dmrs - not sure where this is coming from - its not in the FAPI
 						 0, //nb_rb_oh
-						 pusch_pdu->nrOfLayers = 1);
+						 pusch_pdu->nrOfLayers)>>3;
   pusch_pdu->pusch_data.num_cb = 0; //CBG not supported
   //pusch_pdu->pusch_data.cb_present_and_position;
   //pusch_pdu->pusch_uci;
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index c357f0071b..9376855882 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -921,28 +921,6 @@ int extract_length(int startSymbolAndLength) {
   if (tmp > 0 && tmp < (14-tmp2)) return(tmp);
   else                            return(15-tmp2);
 }
- 
-void fill_initialBWPDLtimeDomainAllocaion(nfapi_nr_config_request_t *cfg,int time_domain_assignment,int *k0,int *mappingType,int *start_symbol,int *length) {
-  AssertFatal(time_domain_assignment < cfg->pdsch_config.num_PDSCHTimeDomainResourceAllocations.value,"DL time_domain_assignment %d >= %d\n",
-	      time_domain_assignment,cfg->pdsch_config.num_PDSCHTimeDomainResourceAllocations.value);
-  *k0           = cfg->pdsch_config.PDSCHTimeDomainResourceAllocation_k0[time_domain_assignment].value;
-  *mappingType = cfg->pdsch_config.PDSCHTimeDomainResourceAllocation_mappingType[time_domain_assignment].value;
-  *start_symbol = extract_startSymbol(cfg->pdsch_config.PDSCHTimeDomainResourceAllocation_startSymbolAndLength[time_domain_assignment].value);
-  *length       = extract_length(cfg->pdsch_config.PDSCHTimeDomainResourceAllocation_startSymbolAndLength[time_domain_assignment].value);
-
-}
-
-
-
-void fill_initialBWPULtimeDomainAllocaion(nfapi_nr_config_request_t *cfg,int time_domain_assignment,int *k2, int *mappingType, int *start_symbol,int *length) {
-  AssertFatal(time_domain_assignment < cfg->pusch_config.num_PUSCHTimeDomainResourceAllocations.value,"UL time_domain_assignment %d >= %d\n",
-	      time_domain_assignment,cfg->pusch_config.num_PUSCHTimeDomainResourceAllocations.value);
-
-  *k2           = cfg->pusch_config.PUSCHTimeDomainResourceAllocation_k2[time_domain_assignment].value;
-  *mappingType = cfg->pusch_config.PUSCHTimeDomainResourceAllocation_mappingType[time_domain_assignment].value;
-  *start_symbol = extract_startSymbol(cfg->pusch_config.PUSCHTimeDomainResourceAllocation_startSymbolAndLength[time_domain_assignment].value);
-  *length       = extract_length(cfg->pusch_config.PUSCHTimeDomainResourceAllocation_startSymbolAndLength[time_domain_assignment].value);
-}
 
 /*
  * Dump the UL or DL UE_list into LOG_T(MAC)

From ad1a102f08faa5c50c068b7ffd60a8d128943028 Mon Sep 17 00:00:00 2001
From: Cedric Roux 
Date: Fri, 20 Mar 2020 11:13:51 +0100
Subject: [PATCH 61/73] fix for CU/DU split

---
 openair2/RRC/LTE/rrc_eNB.c      |   5 +-
 openair2/RRC/LTE/rrc_eNB_endc.c | 160 --------------------------------
 2 files changed, 1 insertion(+), 164 deletions(-)

diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index 7de5a2c64c..1d25bf180a 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -8510,7 +8510,7 @@ void rrc_eNB_process_AdditionResponseInformation(const module_id_t enb_mod_idP,
     unsigned char buffer[8192];
     int size;
 
-    ue_context = (rrc_eNB_ue_context_t *) get_first_ue_context(RC.rrc[enb_mod_idP]);
+    ue_context = rrc_eNB_get_ue_context(RC.rrc[enb_mod_idP], m->rnti);
 
     PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
                                     0,
@@ -8893,9 +8893,6 @@ rrc_enb_task(
 {
   rrc_enb_init();
 
-void rrc_endc_hack_init(void);
-rrc_endc_hack_init();
-
   itti_mark_task_ready(TASK_RRC_ENB);
   LOG_I(RRC,"Entering main loop of RRC message task\n");
 
diff --git a/openair2/RRC/LTE/rrc_eNB_endc.c b/openair2/RRC/LTE/rrc_eNB_endc.c
index d6fb910507..3d3d9787b5 100644
--- a/openair2/RRC/LTE/rrc_eNB_endc.c
+++ b/openair2/RRC/LTE/rrc_eNB_endc.c
@@ -241,163 +241,3 @@ printf("\n");
 
   return (enc_rval.encoded + 7) / 8;
 }
-
-volatile int go_nr;
-
-struct rrc_eNB_ue_context_s *
-get_first_ue_context(eNB_RRC_INST *rrc_instance_pP)
-{
-  struct rrc_eNB_ue_context_s   *ue_context_p = NULL;
-  RB_FOREACH(ue_context_p, rrc_ue_tree_s, &(rrc_instance_pP->rrc_ue_head)) {
-    return ue_context_p;
-  }
-  return NULL;
-}
-
-void rrc_go_nr(void)
-{
-  protocol_ctxt_t ctxt;
-  rrc_eNB_ue_context_t *ue_context;
-  unsigned char buffer[8192];
-  int size;
-
-  go_nr = 0;
-
-  ue_context = get_first_ue_context(RC.rrc[0]);
-
-  PROTOCOL_CTXT_SET_BY_INSTANCE(&ctxt,
-                                0,
-                                ENB_FLAG_YES,
-                                ue_context->ue_context.rnti,
-                                0, 0);
-
-  size = rrc_eNB_generate_RRCConnectionReconfiguration_endc(&ctxt, ue_context, buffer, 8192, NULL, NULL);
-
-  rrc_data_req(&ctxt,
-               DCCH,
-               rrc_eNB_mui++,
-               SDU_CONFIRM_NO,
-               size,
-               buffer,
-               PDCP_TRANSMISSION_MODE_CONTROL);
-}
-
-static void new_thread(void *(*f)(void *), void *data) {
-  pthread_t t;
-  pthread_attr_t att;
-
-  if (pthread_attr_init(&att)) {
-    fprintf(stderr, "pthread_attr_init err\n");
-    exit(1);
-  }
-
-  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) {
-    fprintf(stderr, "pthread_attr_setdetachstate err\n");
-    exit(1);
-  }
-
-  if (pthread_attr_setstacksize(&att, 10000000)) {
-    fprintf(stderr, "pthread_attr_setstacksize err\n");
-    exit(1);
-  }
-
-  if (pthread_create(&t, &att, f, data)) {
-    fprintf(stderr, "pthread_create err\n");
-    exit(1);
-  }
-
-  if (pthread_attr_destroy(&att)) {
-    fprintf(stderr, "pthread_attr_destroy err\n");
-    exit(1);
-  }
-}
-
-static int create_listen_socket(char *addr, int port) {
-  struct sockaddr_in a;
-  int s;
-  int v;
-  s = socket(AF_INET, SOCK_STREAM, 0);
-
-  if (s == -1) {
-    perror("socket");
-    exit(1);
-  }
-
-  v = 1;
-
-  if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &v, sizeof(int))) {
-    perror("setsockopt");
-    exit(1);
-  }
-
-  a.sin_family = AF_INET;
-  a.sin_port = htons(port);
-  a.sin_addr.s_addr = inet_addr(addr);
-
-  if (bind(s, (struct sockaddr *)&a, sizeof(a))) {
-    perror("bind");
-    exit(1);
-  }
-
-  if (listen(s, 5)) {
-    perror("listen");
-    exit(1);
-  }
-
-  return s;
-}
-
-static int socket_accept(int s) {
-  struct sockaddr_in a;
-  socklen_t alen;
-  alen = sizeof(a);
-  return accept(s, (struct sockaddr *)&a, &alen);
-}
-
-static int fullread(int fd, void *_buf, int count) {
-  char *buf = _buf;
-  int ret = 0;
-  int l;
-
-  while (count) {
-    l = read(fd, buf, count);
-
-    if (l <= 0) return -1;
-
-    count -= l;
-    buf += l;
-    ret += l;
-  }
-
-  return ret;
-}
-
-void *nr_hack(void *_)
-{
-  int s = create_listen_socket("0.0.0.0", 9001);
-  int t;
-
-over:
-  t = socket_accept(s);
-
-  while (1) {
-    char c;
-
-    if (fullread(t, &c, 1) != 1) {
-      close(t);
-      goto over;
-    }
-
-    if (c != '\n') continue;
-
-    printf("setting go_nr to 1\n");
-    go_nr = 1;
-  }
-
-  return 0;
-}
-
-void rrc_endc_hack_init(void)
-{
-  new_thread(nr_hack, NULL);
-}

From b904161f871b1a75a68f2b6b483360624737f4ae Mon Sep 17 00:00:00 2001
From: Francesco Mani 
Date: Fri, 20 Mar 2020 11:15:43 +0100
Subject: [PATCH 62/73] removing is_dmrs_symbol function from pusch in gNB

---
 .../PHY/NR_TRANSPORT/nr_transport_proto.h     |  1 +
 .../PHY/NR_TRANSPORT/nr_ulsch_demodulation.c  | 33 +++++++------------
 openair1/SCHED_NR/phy_procedures_nr_gNB.c     | 11 +------
 3 files changed, 13 insertions(+), 32 deletions(-)

diff --git a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
index a6fcb874f4..9ce56421fc 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
+++ b/openair1/PHY/NR_TRANSPORT/nr_transport_proto.h
@@ -68,6 +68,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
 void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
                                  NR_gNB_PUSCH *pusch_vars,
                                  unsigned char symbol,
+                                 uint8_t is_dmrs_symbol,
                                  nfapi_nr_pusch_pdu_t *pusch_pdu,
                                  NR_DL_FRAME_PARMS *frame_parms);
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
index e02278d664..bce8ddcc29 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_demodulation.c
@@ -226,6 +226,7 @@ void nr_idft(uint32_t *z, uint32_t Msc_PUSCH)
 void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
                                  NR_gNB_PUSCH *pusch_vars,
                                  unsigned char symbol,
+                                 uint8_t is_dmrs_symbol,
                                  nfapi_nr_pusch_pdu_t *pusch_pdu,
                                  NR_DL_FRAME_PARMS *frame_parms)
 {
@@ -237,12 +238,13 @@ void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
   uint32_t ul_ch0_index = 0;
   uint32_t ul_ch0_ptrs_ext_index = 0;
   uint32_t ul_ch0_ptrs_index = 0;
-  uint8_t is_dmrs_symbol_flag, is_ptrs_symbol_flag,k_prime;
+  uint8_t is_ptrs_symbol_flag,k_prime;
   uint16_t n=0, num_ptrs_symbols;
   int16_t *rxF,*rxF_ext;
   int *ul_ch0,*ul_ch0_ext;
   int *ul_ch0_ptrs,*ul_ch0_ptrs_ext;
   uint16_t n_rnti = pusch_pdu->rnti;
+  uint8_t delta = 0;
 
 #ifdef DEBUG_RB_EXT
 
@@ -251,10 +253,9 @@ void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
 
 #endif
   
+  uint8_t is_dmrs_re;
   start_re = (frame_parms->first_carrier_offset + (pusch_pdu->rb_start * NR_NB_SC_PER_RB))%frame_parms->ofdm_symbol_size;
-  
   nb_re_pusch = NR_NB_SC_PER_RB * pusch_pdu->rb_size;
-  is_dmrs_symbol_flag = 0;
   is_ptrs_symbol_flag = 0;
   num_ptrs_symbols = 0;
 
@@ -278,15 +279,10 @@ void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
 
     for (re = 0; re < nb_re_pusch; re++) {
 
-      is_dmrs_symbol_flag =  is_dmrs_symbol(symbol,
-                                            (start_re + re)%frame_parms->ofdm_symbol_size,
-                                            start_re,
-                                            k_prime,
-                                            n,
-                                            0,
-                                            pusch_pdu->nr_of_symbols,
-                                            pusch_pdu->dmrs_config_type,
-                                            frame_parms->ofdm_symbol_size);
+      if (is_dmrs_symbol)
+        is_dmrs_re = (re == get_dmrs_freq_idx_ul(n, k_prime, delta, pusch_pdu->dmrs_config_type));
+      else
+        is_dmrs_re = 0;
 
       if ( ((pusch_pdu->pdu_bit_map)>>2)& 0x01 ) {
         is_ptrs_symbol_flag = is_ptrs_symbol(symbol,
@@ -311,7 +307,7 @@ void nr_ulsch_extract_rbs_single(int32_t **rxdataF,
       printf("re = %d, is_dmrs_symbol_flag = %d, symbol = %d\n", re, is_dmrs_symbol_flag, symbol);
   #endif
 
-      if ( is_dmrs_symbol_flag == 0 && is_ptrs_symbol_flag == 0) {
+      if ( is_dmrs_re == 0 && is_ptrs_symbol_flag == 0) {
 
         rxF_ext[rxF_ext_index]     = (rxF[ ((start_re + re)*2)      % (frame_parms->ofdm_symbol_size*2)]);
         rxF_ext[rxF_ext_index + 1] = (rxF[(((start_re + re)*2) + 1) % (frame_parms->ofdm_symbol_size*2)]);
@@ -1065,15 +1061,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
 
   bwp_start_subcarrier = (rel15_ul->rb_start*NR_NB_SC_PER_RB + frame_parms->first_carrier_offset) % frame_parms->ofdm_symbol_size;
 
-  dmrs_symbol_flag = is_dmrs_symbol(symbol,
-                                    0,
-                                    0,
-                                    0,
-                                    0,
-                                    0,
-                                    rel15_ul->nr_of_symbols,
-                                    rel15_ul->dmrs_config_type,
-                                    frame_parms->ofdm_symbol_size);
+  dmrs_symbol_flag = ((rel15_ul->ul_dmrs_symb_pos)>>symbol)&0x01;
 
   if (dmrs_symbol_flag == 1){
     nb_re_pusch = rel15_ul->rb_size * ((rel15_ul->dmrs_config_type==pusch_dmrs_type1)?6:8);
@@ -1121,6 +1109,7 @@ void nr_rx_pusch(PHY_VARS_gNB *gNB,
   nr_ulsch_extract_rbs_single(gNB->common_vars.rxdataF,
                               gNB->pusch_vars[UE_id],
                               symbol,
+                              dmrs_symbol_flag,
                               rel15_ul,
                               frame_parms);
 
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index b28911b495..37a77b1d51 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -226,16 +226,7 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int ULSCH
   number_symbols = pusch_pdu->nr_of_symbols;
 
   for (l = start_symbol; l < start_symbol + number_symbols; l++)
-      number_dmrs_symbols += is_dmrs_symbol(l,
-                                            0,
-                                            0,
-                                            0,
-                                            0,
-                                            0,
-                                            number_symbols,
-                                            pusch_pdu->dmrs_config_type,
-                                            frame_parms->ofdm_symbol_size);
-
+      number_dmrs_symbols += ((pusch_pdu->ul_dmrs_symb_pos)>>l)&0x01;
 
   nb_re_dmrs = ((pusch_pdu->dmrs_config_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
 

From 1c2f9bb618831a33ab53e8264553d8b35a58c08f Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani 
Date: Fri, 20 Mar 2020 13:59:40 +0100
Subject: [PATCH 63/73] Fixed some bug in pusch dmrs an assertion fails in gnb
 (need to be fixed)

---
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c     | 18 +++++++++++-------
 openair1/SCHED_NR/phy_procedures_nr_gNB.c      |  4 ++--
 .../LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c  |  4 ++--
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index bdd8ea8c24..da289e86c2 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -127,6 +127,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
   Nid_cell = 0;
   N_PRB_oh = 0; // higher layer (RRC) parameter xOverhead in PUSCH-ServingCellConfig
   number_dmrs_symbols = 0;
+  uint8_t mapping_type = UE->pusch_config.pusch_TimeDomainResourceAllocation[0]->mappingType;
 
   for (cwd_index = 0;cwd_index < num_of_codewords; cwd_index++) {
 
@@ -136,7 +137,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
     start_symbol = harq_process_ul_ue->start_symbol;
 
     for (i = start_symbol; i < start_symbol + harq_process_ul_ue->number_of_symbols; i++)
-      number_dmrs_symbols += is_dmrs_symbol(i,
+      number_dmrs_symbols += is_dmrs_symbol((mapping_type)?i-start_symbol:i,
                                             0,
                                             0,
                                             0,
@@ -146,12 +147,13 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
                                             UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type,
                                             frame_parms->ofdm_symbol_size);
 
-    ulsch_ue->length_dmrs = UE->pusch_config.dmrs_UplinkConfig.pusch_maxLength;
+    ulsch_ue->length_dmrs = number_dmrs_symbols; // pusch.MaxLenght is redundant here as number_dmrs_symbols
+                                                 // contains all dmrs symbols even for double symbol dmrs
     ulsch_ue->rnti        = n_rnti;
     ulsch_ue->Nid_cell    = Nid_cell;
-    ulsch_ue->nb_re_dmrs  = ((UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
+    ulsch_ue->nb_re_dmrs  = ((UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type == pusch_dmrs_type1)?6:4);
 
-    N_RE_prime = NR_NB_SC_PER_RB*harq_process_ul_ue->number_of_symbols - ulsch_ue->nb_re_dmrs - N_PRB_oh;
+    N_RE_prime = NR_NB_SC_PER_RB*harq_process_ul_ue->number_of_symbols - ulsch_ue->nb_re_dmrs*number_dmrs_symbols - N_PRB_oh;
 
     harq_process_ul_ue->num_of_mod_symbols = N_RE_prime*harq_process_ul_ue->nb_rb*num_of_codewords;
 
@@ -275,7 +277,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
   /////////////////////////DMRS Modulation/////////////////////////
   ///////////
   pusch_dmrs = UE->nr_gold_pusch_dmrs[slot];
-  n_dmrs = (harq_process_ul_ue->nb_rb*ulsch_ue->nb_re_dmrs);
+  n_dmrs = (harq_process_ul_ue->nb_rb*ulsch_ue->nb_re_dmrs*ulsch_ue->length_dmrs);
   int16_t mod_dmrs[n_dmrs<<1];
   dmrs_type = UE->pusch_config.dmrs_UplinkConfig.pusch_dmrs_type;
   ///////////
@@ -335,7 +337,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
 
   for (l = start_symbol; l < start_symbol + harq_process_ul_ue->number_of_symbols; l++) {
 
-    is_dmrs = is_dmrs_symbol(l,
+    is_dmrs = is_dmrs_symbol((mapping_type)?l-start_symbol:l,
                              0,
                              0,
                              0,
@@ -386,6 +388,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
 
     uint8_t k_prime=0;
     uint8_t is_dmrs, is_ptrs;
+    uint8_t l_ref;
     uint16_t m=0, n=0, dmrs_idx=0, ptrs_idx = 0;
 
     for (l=start_symbol; lnumber_of_symbols; l++) {
@@ -393,6 +396,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
       k = start_sc;
       n = 0;
       dmrs_idx = 0;
+      l_ref = (mapping_type) ? l-start_symbol : l;
 
       for (i=0; inb_rb*NR_NB_SC_PER_RB; i++) {
 
@@ -401,7 +405,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
         is_dmrs = 0;
         is_ptrs = 0;
 
-        is_dmrs = is_dmrs_symbol(l,
+        is_dmrs = is_dmrs_symbol(l_ref,
                                  k,
                                  start_sc,
                                  k_prime,
diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index 37a77b1d51..292c8106ae 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -228,12 +228,12 @@ void nr_ulsch_procedures(PHY_VARS_gNB *gNB, int frame_rx, int slot_rx, int ULSCH
   for (l = start_symbol; l < start_symbol + number_symbols; l++)
       number_dmrs_symbols += ((pusch_pdu->ul_dmrs_symb_pos)>>l)&0x01;
 
-  nb_re_dmrs = ((pusch_pdu->dmrs_config_type == pusch_dmrs_type1)?6:4)*number_dmrs_symbols;
+  nb_re_dmrs = ((pusch_pdu->dmrs_config_type == pusch_dmrs_type1)?6:4);
 
   G = nr_get_G(pusch_pdu->rb_size,
                number_symbols,
                nb_re_dmrs,
-               1, // FIXME only single dmrs is implemented
+               number_dmrs_symbols, // number of dmrs symbols irrespective of single or double symbol dmrs
                pusch_pdu->qam_mod_order,
                pusch_pdu->nrOfLayers);
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
index f1e2e8e071..1e0fd8d9a2 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_phytest.c
@@ -759,7 +759,7 @@ void nr_schedule_uss_ulsch_phytest(int Mod_idP,
   pusch_pdu->data_scrambling_id = 0; //It equals the higher-layer parameter Data-scrambling-Identity if configured and the RNTI equals the C-RNTI, otherwise L2 needs to set it to physical cell id.;
   pusch_pdu->nrOfLayers = 1;
   //DMRS
-  pusch_pdu->ul_dmrs_symb_pos = 1;
+  pusch_pdu->ul_dmrs_symb_pos = 1<<2; //for now the gnb assumes dmrs in the first symbol of the scheduled pusch resource
   pusch_pdu->dmrs_config_type = 0;  //dmrs-type 1 (the one with a single DMRS symbol in the beginning)
   pusch_pdu->ul_dmrs_scrambling_id =  0; //If provided and the PUSCH is not a msg3 PUSCH, otherwise, L2 should set this to physical cell id.
   pusch_pdu->scid = 0; //DMRS sequence initialization [TS38.211, sec 6.4.1.1.1]. Should match what is sent in DCI 0_1, otherwise set to 0.
@@ -775,7 +775,7 @@ void nr_schedule_uss_ulsch_phytest(int Mod_idP,
   //pusch_pdu->tx_direct_current_location;//The uplink Tx Direct Current location for the carrier. Only values in the value range of this field between 0 and 3299, which indicate the subcarrier index within the carrier corresponding 1o the numerology of the corresponding uplink BWP and value 3300, which indicates "Outside the carrier" and value 3301, which indicates "Undetermined position within the carrier" are used. [TS38.331, UplinkTxDirectCurrentBWP IE]
   pusch_pdu->uplink_frequency_shift_7p5khz = 0;
   //Resource Allocation in time domain
-  pusch_pdu->start_symbol_index = 0;
+  pusch_pdu->start_symbol_index = 2;
   pusch_pdu->nr_of_symbols = 12;
   //Optional Data only included if indicated in pduBitmap
   pusch_pdu->pusch_data.rv_index = 0;

From c71edc21db03ce6b3ff3b2cf4703398d9bc823be Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani 
Date: Fri, 20 Mar 2020 17:08:30 +0100
Subject: [PATCH 64/73] Fixed the assertion in ulsch pdu header rfsim works

---
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index da289e86c2..586630aa66 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -209,8 +209,15 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
     	}
         //else if(uplink_counter == 0){ //if(!IS_SOFTMODEM_NOS1){
     	else{
-        	LOG_D(PHY, "Random data to be tranmsitted: \n");
-        	for (i = 0; i < harq_process_ul_ue->TBS / 8; i++) {
+          //Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid
+          //and block this traffic from being forwarded to the upper layers at the gNB
+          uint16_t payload_offset = 5;
+          LOG_D(PHY, "Random data to be tranmsitted: \n");
+          //Give the header bytes some dummy value in order to block the random packet at the MAC layer of the receiver
+          for (i = 0; ia[i] = 0;
+
+          for (i = payload_offset; i < harq_process_ul_ue->TBS / 8; i++) {
         		harq_process_ul_ue->a[i] = (unsigned char) rand();
         		//printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]);
         	}

From d90f8da36424f1af586397a9f86cb35e465a4c9e Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani 
Date: Sat, 21 Mar 2020 18:43:50 +0100
Subject: [PATCH 65/73] avoiding code duplication

---
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 45 ++++++++--------------
 1 file changed, 15 insertions(+), 30 deletions(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 586630aa66..3b6367e243 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -174,6 +174,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
     // to be removed later when MAC is ready
 
     if (harq_process_ul_ue != NULL){
+      data_existing = 0;
 
     	if (IS_SOFTMODEM_NOS1){
     		data_existing = nr_ue_get_sdu(UE->Mod_id, UE->CC_id, frame,
@@ -191,38 +192,22 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
     				printf("\n");
 				#endif
     		}
-    		//Random traffic to be transmitted if there is no IP traffic available for this Tx opportunity
-    		else{
-    			//Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid
-    			//and block this traffic from being forwarded to the upper layers at the gNB
-    			uint16_t payload_offset = 5;
-    			LOG_D(PHY, "Random data to be tranmsitted: \n");
-    			//Give the header bytes some dummy value in order to block the random packet at the MAC layer of the receiver
-    			for (i = 0; ia[i] = 0;
+      }
+      //Random traffic to be transmitted if there is no IP traffic available for this Tx opportunity
+      else if (!IS_SOFTMODEM_NOS1 || !data_existing) {
+        //Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid
+        //and block this traffic from being forwarded to the upper layers at the gNB
+        uint16_t payload_offset = 5;
+        LOG_D(PHY, "Random data to be tranmsitted: \n");
+        //Give the header bytes some dummy value in order to block the random packet at the MAC layer of the receiver
+        for (i = 0; ia[i] = 0;
 
-    			for (i = payload_offset; i < harq_process_ul_ue->TBS / 8; i++) {
-    				harq_process_ul_ue->a[i] = (unsigned char) rand();
-    				//printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]);
-    				}
-    		}
-    	}
-        //else if(uplink_counter == 0){ //if(!IS_SOFTMODEM_NOS1){
-    	else{
-          //Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid
-          //and block this traffic from being forwarded to the upper layers at the gNB
-          uint16_t payload_offset = 5;
-          LOG_D(PHY, "Random data to be tranmsitted: \n");
-          //Give the header bytes some dummy value in order to block the random packet at the MAC layer of the receiver
-          for (i = 0; ia[i] = 0;
-
-          for (i = payload_offset; i < harq_process_ul_ue->TBS / 8; i++) {
-        		harq_process_ul_ue->a[i] = (unsigned char) rand();
-        		//printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]);
-        	}
-        	//uplink_counter++;
+        for (i = payload_offset; i < harq_process_ul_ue->TBS / 8; i++) {
+          harq_process_ul_ue->a[i] = (unsigned char) rand();
+          //printf(" input encoder a[%d]=0x%02x\n",i,harq_process_ul_ue->a[i]);
         }
+      }
     } else {
       LOG_E(PHY, "[phy_procedures_nrUE_TX] harq_process_ul_ue is NULL !!\n");
       return;

From e21d6efaf56ecd8f775feea2e7c4cb9518ed014e Mon Sep 17 00:00:00 2001
From: Florian Kaltenberger 
Date: Mon, 23 Mar 2020 16:33:35 +0100
Subject: [PATCH 66/73] CI: adding --phy-test command line option to gNB
 real-time test

---
 ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml b/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml
index 30a8772df7..f3e80c576a 100644
--- a/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml
+++ b/ci-scripts/xml_files/gnb_nr_ue_usrp_run.xml
@@ -33,7 +33,7 @@
         
                 Initialize_eNB
                 Initialize gNB USRP
-		-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf
+		-O ci-scripts/conf_files/gnb.band78.tm1.106PRB.usrpn300.conf --phy-test
 		NR
         
 

From d6ce3a5a3147ccfa0ebd8129b70cd8d3dc4584d5 Mon Sep 17 00:00:00 2001
From: Cedric Roux 
Date: Mon, 23 Mar 2020 17:45:59 +0100
Subject: [PATCH 67/73] fix compilation of ldpc libraries - T must be processed
 before

---
 cmake_targets/CMakeLists.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index f29c014150..247bc9e073 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -2941,7 +2941,8 @@ if (${T_TRACER})
         NFAPI_COMMON_LIB NFAPI_LIB NFAPI_PNF_LIB NFAPI_VNF_LIB NFAPI_USER_LIB
         PHY_COMMON PHY PHY_UE PHY_NR PHY_NR_COMMON PHY_NR_UE PHY_RU PHY_MEX
         L2 L2_LTE L2_NR L2_UE NR_L2_UE MAC_NR_COMMON MAC_NR MAC_UE_NR
-        CN_UTILS GTPV1U SCTP_CLIENT MME_APP UDP LIB_NAS_UE NB_IoT LFDS LFDS7 SIMU SIMU_ETH OPENAIR0_LIB)
+        CN_UTILS GTPV1U SCTP_CLIENT MME_APP UDP LIB_NAS_UE NB_IoT LFDS LFDS7 SIMU SIMU_ETH OPENAIR0_LIB
+        ldpc_orig ldpc_optim ldpc_optim8seg ldpc)
     if (TARGET ${i})
       add_dependencies(${i} generate_T)
     endif()

From df0bc30e28733c2f97bac3c5c96775eeec087075 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Tue, 24 Mar 2020 15:41:51 +0100
Subject: [PATCH 68/73] Make function static inline, not inline

inline alone does only define a function without a corresponding
declaration. static solves this problem
---
 executables/nr-ue.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/executables/nr-ue.c b/executables/nr-ue.c
index 653a97dc61..131710ee02 100644
--- a/executables/nr-ue.c
+++ b/executables/nr-ue.c
@@ -633,7 +633,7 @@ int computeSamplesShift(PHY_VARS_NR_UE *UE) {
   return 0;
 }
 
-inline int get_firstSymSamp(uint16_t slot, NR_DL_FRAME_PARMS *fp) {
+static inline int get_firstSymSamp(uint16_t slot, NR_DL_FRAME_PARMS *fp) {
   if (fp->numerology_index == 0)
     return fp->nb_prefix_samples0 + fp->ofdm_symbol_size;
   int num_samples = (slot%(fp->slots_per_subframe/2)) ? fp->nb_prefix_samples : fp->nb_prefix_samples0;
@@ -641,7 +641,7 @@ inline int get_firstSymSamp(uint16_t slot, NR_DL_FRAME_PARMS *fp) {
   return num_samples;
 }
 
-inline int get_readBlockSize(uint16_t slot, NR_DL_FRAME_PARMS *fp) {
+static inline int get_readBlockSize(uint16_t slot, NR_DL_FRAME_PARMS *fp) {
   int rem_samples = fp->get_samples_per_slot(slot, fp) - get_firstSymSamp(slot, fp);
   int next_slot_first_symbol = 0;
   if (slot < (fp->slots_per_frame-1))

From 8a589f5b0886aeebdb77e794047ca9b16b857972 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Tue, 24 Mar 2020 15:54:45 +0100
Subject: [PATCH 69/73] Fix: rx_indication length is in bytes

---
 openair1/SCHED_NR/phy_procedures_nr_gNB.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openair1/SCHED_NR/phy_procedures_nr_gNB.c b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
index 292c8106ae..d9a7ee3c69 100644
--- a/openair1/SCHED_NR/phy_procedures_nr_gNB.c
+++ b/openair1/SCHED_NR/phy_procedures_nr_gNB.c
@@ -297,7 +297,7 @@ void nr_fill_rx_indication(PHY_VARS_gNB *gNB, int frame, int slot_rx, int ULSCH_
 
  gNB->UL_INFO.rx_ind.sfn_sf                    = frame<<4| slot_rx;
  gNB->UL_INFO.rx_ind.rx_indication_body.tl.tag = NFAPI_RX_INDICATION_BODY_TAG;
- gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list->rx_indication_rel8.length = gNB->ulsch[ULSCH_id][0]->harq_processes[harq_pid]->TBS>>3;
+ gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list->rx_indication_rel8.length = gNB->ulsch[ULSCH_id][0]->harq_processes[harq_pid]->TBS;
 
  pdu                                    = &gNB->UL_INFO.rx_ind.rx_indication_body.rx_pdu_list[gNB->UL_INFO.rx_ind.rx_indication_body.number_of_pdus];
 

From 2c21e8229c2548d51f7912c2299b6c94a53c863f Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Tue, 24 Mar 2020 15:55:41 +0100
Subject: [PATCH 70/73] Fix: correctly set context before calling pdcp_run()

---
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
index 90c56c2ef5..e5840d9cd1 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler.c
@@ -308,6 +308,7 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
   //printf("gNB_dlsch_ulsch_scheduler frameRX %d slotRX %d frameTX %d slotTX %d\n",frame_rxP,slot_rxP,frame_txP,slot_txP);
 			       
   protocol_ctxt_t   ctxt;
+  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frame_txP, slot_txP,module_idP);
   int CC_id, UE_id = 0;
   gNB_MAC_INST *gNB = RC.nrmac[module_idP];
   NR_UE_list_t *UE_list = &gNB->UE_list;
@@ -351,7 +352,6 @@ void gNB_dlsch_ulsch_scheduler(module_id_t module_idP,
     } //END if (UE_list->active[i])
   } //END for (i = 0; i < MAX_MOBILES_PER_GNB; i++)
   */
-  PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES,NOT_A_RNTI, frame_txP, slot_txP,module_idP);
   
   // This schedules MIB
   if((slot_txP == 0) && (frame_txP & 7) == 0){

From 69c16efe07986a207881b4aa1d338517ab647a91 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Tue, 24 Mar 2020 16:20:05 +0100
Subject: [PATCH 71/73] Fix: check that UE RRC config files are found

---
 openair2/RRC/NR_UE/rrc_UE.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/openair2/RRC/NR_UE/rrc_UE.c b/openair2/RRC/NR_UE/rrc_UE.c
index 1975bfba1a..87e899845e 100755
--- a/openair2/RRC/NR_UE/rrc_UE.c
+++ b/openair2/RRC/NR_UE/rrc_UE.c
@@ -329,6 +329,11 @@ NR_UE_RRC_INST_t* openair_rrc_top_init_ue_nr(char* rrc_config_path){
 	    sprintf(filename,"reconfig.raw");
 	  fd = fopen(filename,"r");
           char buffer[1024];
+	  AssertFatal(fd,
+	              "cannot read file %s: errno %d, %s\n",
+	              filename,
+	              errno,
+	              strerror(errno));
 	  int msg_len=fread(buffer,1,1024,fd);
 	  fclose(fd);
 	  process_nsa_message(NR_UE_rrc_inst, nr_SecondaryCellGroupConfig_r15, buffer,msg_len);
@@ -337,6 +342,11 @@ NR_UE_RRC_INST_t* openair_rrc_top_init_ue_nr(char* rrc_config_path){
 	  else
 	    sprintf(filename,"rbconfig.raw");
 	  fd = fopen(filename,"r");
+	  AssertFatal(fd,
+	              "cannot read file %s: errno %d, %s\n",
+	              filename,
+	              errno,
+	              strerror(errno));
 	  msg_len=fread(buffer,1,1024,fd);
 	  fclose(fd);
 	  process_nsa_message(NR_UE_rrc_inst, nr_RadioBearerConfigX_r15, buffer,msg_len); 

From daefb67c82e35a5468733306149736955b756c7c Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Tue, 24 Mar 2020 16:26:47 +0100
Subject: [PATCH 72/73] Fix: correct check for dummy-traffic

---
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
index 3b6367e243..f1d4a304f9 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_ue.c
@@ -194,7 +194,7 @@ void nr_ue_ulsch_procedures(PHY_VARS_NR_UE *UE,
     		}
       }
       //Random traffic to be transmitted if there is no IP traffic available for this Tx opportunity
-      else if (!IS_SOFTMODEM_NOS1 || !data_existing) {
+      if (!IS_SOFTMODEM_NOS1 || !data_existing) {
         //Use zeros for the header bytes in noS1 mode, in order to make sure that the LCID is not valid
         //and block this traffic from being forwarded to the upper layers at the gNB
         uint16_t payload_offset = 5;

From 8a47fa484cb30ae4c6faee4330cbdee2cfd6cd63 Mon Sep 17 00:00:00 2001
From: Robert Schmidt 
Date: Tue, 24 Mar 2020 16:32:14 +0100
Subject: [PATCH 73/73] Handle residual MAC PDU < 0 gracefully

---
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
index 34be2246b8..ade5200627 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
@@ -222,7 +222,10 @@ void nr_process_mac_pdu(
         pdu_ptr += ( mac_subheader_len + mac_ce_len + mac_sdu_len );
         pdu_len -= ( mac_subheader_len + mac_ce_len + mac_sdu_len );
 
-        AssertFatal(pdu_len >= 0, "[MAC] nr_process_mac_pdu, residual mac pdu length < 0!\n");
+        if (pdu_len < 0) {
+          LOG_E(MAC, "%s() residual mac pdu length < 0!\n", __func__);
+          return;
+        }
     }
 }