From b219be2e6d8c319d310aa04005dffa7b03956875 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Thu, 10 Aug 2017 07:56:30 -0700
Subject: [PATCH] added RRU configuration file and more L2 cleanup

---
 openair2/ENB_APP/enb_config.h                 | 179 ------------------
 openair2/LAYER2/MAC/eNB_scheduler.c           |  44 ++---
 openair2/LAYER2/MAC/eNB_scheduler_RA.c        |  11 +-
 openair2/LAYER2/MAC/eNB_scheduler_bch.c       |   4 +
 openair2/LAYER2/MAC/eNB_scheduler_dlsch.c     |  38 ++++
 .../LAYER2/MAC/eNB_scheduler_primitives.c     |  63 ++++++
 openair2/LAYER2/MAC/eNB_scheduler_ulsch.c     | 109 ++++++++---
 openair2/LAYER2/MAC/proto.h                   |  17 +-
 openair2/PHY_INTERFACE/IF_Module.c            |   1 -
 openair3/GTPV1-U/gtpv1u_eNB.c                 |   2 +-
 openair3/UDP/udp_eNB_task.c                   |   6 +-
 openair3/UDP/udp_eNB_task.h                   |   2 +-
 12 files changed, 230 insertions(+), 246 deletions(-)

diff --git a/openair2/ENB_APP/enb_config.h b/openair2/ENB_APP/enb_config.h
index 8e1180a1f5..a3f0cc786b 100644
--- a/openair2/ENB_APP/enb_config.h
+++ b/openair2/ENB_APP/enb_config.h
@@ -91,189 +91,10 @@ typedef struct ru_config_s {
   uint8_t   if_compress;
 } ru_config_t;
 
-typedef struct Enb_properties_s {
-  /* Unique eNB_id to identify the eNB within EPC.
-   * For macro eNB ids this field should be 20 bits long.
-   * For home eNB ids this field should be 28 bits long.
-   */
-  uint32_t            eNB_id;
 
-  /* The type of the cell */
-  enum cell_type_e    cell_type;
-
-  /* Optional name for the cell
-   * NOTE: the name can be NULL (i.e no name) and will be cropped to 150
-   * characters.
-   */
-  char               *eNB_name;
-
-
-  /* Tracking area code */
-  uint16_t            tac;
-
-  /* Mobile Country Code
-   * Mobile Network Code
-   */
-  uint16_t            mcc;
-  uint16_t            mnc;
-  uint8_t             mnc_digit_length;
-
-
-
-  /* Physical parameters */
-  int16_t                 nb_cc;
-#ifndef OCP_FRAMEWORK
-  node_function_t         cc_node_function[1+MAX_NUM_CCs];
-  node_timing_t           cc_node_timing[1+MAX_NUM_CCs];
-  int16_t                 cc_node_synch_ref[1+MAX_NUM_CCs];
-  lte_frame_type_t        frame_type[1+MAX_NUM_CCs];
-  uint8_t                 tdd_config[1+MAX_NUM_CCs];
-  uint8_t                 tdd_config_s[1+MAX_NUM_CCs];
-  lte_prefix_type_t       prefix_type[1+MAX_NUM_CCs];
-  int16_t                 eutra_band[1+MAX_NUM_CCs];
-  uint64_t                downlink_frequency[1+MAX_NUM_CCs];
-  int32_t                 uplink_frequency_offset[1+MAX_NUM_CCs];
-
-  int16_t                 Nid_cell[1+MAX_NUM_CCs];// for testing, change later
-  int16_t                 N_RB_DL[1+MAX_NUM_CCs];// for testing, change later
-  int                     nb_antenna_ports[1+MAX_NUM_CCs];
-  int                     nb_antennas_tx[1+MAX_NUM_CCs];
-  int                     nb_antennas_rx[1+MAX_NUM_CCs];
-  int                     tx_gain[1+MAX_NUM_CCs];
-  int                     rx_gain[1+MAX_NUM_CCs];
-  long                    prach_root[1+MAX_NUM_CCs];
-  long                    prach_config_index[1+MAX_NUM_CCs];
-  BOOLEAN_t               prach_high_speed[1+MAX_NUM_CCs];
-  long                    prach_zero_correlation[1+MAX_NUM_CCs];
-  long                    prach_freq_offset[1+MAX_NUM_CCs];
-  long                    pucch_delta_shift[1+MAX_NUM_CCs];
-  long                    pucch_nRB_CQI[1+MAX_NUM_CCs];
-  long                    pucch_nCS_AN[1+MAX_NUM_CCs];
-#if !defined(Rel10) && !defined(Rel14)
-  long                    pucch_n1_AN[1+MAX_NUM_CCs];
-#endif
-  long                    pdsch_referenceSignalPower[1+MAX_NUM_CCs];
-  long                    pdsch_p_b[1+MAX_NUM_CCs];
-  long                    pusch_n_SB[1+MAX_NUM_CCs];
-  long                    pusch_hoppingMode[1+MAX_NUM_CCs];
-  long                    pusch_hoppingOffset[1+MAX_NUM_CCs];
-  BOOLEAN_t               pusch_enable64QAM[1+MAX_NUM_CCs];
-  BOOLEAN_t               pusch_groupHoppingEnabled[1+MAX_NUM_CCs];
-  long                    pusch_groupAssignment[1+MAX_NUM_CCs];
-  BOOLEAN_t               pusch_sequenceHoppingEnabled[1+MAX_NUM_CCs];
-  long                    pusch_nDMRS1[1+MAX_NUM_CCs];
-  long                    phich_duration[1+MAX_NUM_CCs];
-  long                    phich_resource[1+MAX_NUM_CCs];
-  BOOLEAN_t               srs_enable[1+MAX_NUM_CCs];
-  long                    srs_BandwidthConfig[1+MAX_NUM_CCs];
-  long                    srs_SubframeConfig[1+MAX_NUM_CCs];
-  BOOLEAN_t               srs_ackNackST[1+MAX_NUM_CCs];
-  BOOLEAN_t               srs_MaxUpPts[1+MAX_NUM_CCs];
-  long                    pusch_p0_Nominal[1+MAX_NUM_CCs];
-  long                    pusch_alpha[1+MAX_NUM_CCs];
-  long                    pucch_p0_Nominal[1+MAX_NUM_CCs];
-  long                    msg3_delta_Preamble[1+MAX_NUM_CCs];
-  long                    ul_CyclicPrefixLength[1+MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format1                    pucch_deltaF_Format1[1+MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format1b                   pucch_deltaF_Format1b[1+MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format2                    pucch_deltaF_Format2[1+MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format2a                   pucch_deltaF_Format2a[1+MAX_NUM_CCs];
-  e_DeltaFList_PUCCH__deltaF_PUCCH_Format2b                   pucch_deltaF_Format2b[1+MAX_NUM_CCs];
-  long                    rach_numberOfRA_Preambles[1+MAX_NUM_CCs];
-  BOOLEAN_t               rach_preamblesGroupAConfig[1+MAX_NUM_CCs];
-  long                    rach_sizeOfRA_PreamblesGroupA[1+MAX_NUM_CCs];
-  long                    rach_messageSizeGroupA[1+MAX_NUM_CCs];
-  e_RACH_ConfigCommon__preambleInfo__preamblesGroupAConfig__messagePowerOffsetGroupB                    rach_messagePowerOffsetGroupB[1+MAX_NUM_CCs];
-  long                    rach_powerRampingStep[1+MAX_NUM_CCs];
-  long                    rach_preambleInitialReceivedTargetPower[1+MAX_NUM_CCs];
-  long                    rach_preambleTransMax[1+MAX_NUM_CCs];
-  long                    rach_raResponseWindowSize[1+MAX_NUM_CCs];
-  long                    rach_macContentionResolutionTimer[1+MAX_NUM_CCs];
-  long                    rach_maxHARQ_Msg3Tx[1+MAX_NUM_CCs];
-  long                    bcch_modificationPeriodCoeff[1+MAX_NUM_CCs];
-  long                    pcch_defaultPagingCycle[1+MAX_NUM_CCs];
-  long                    pcch_nB[1+MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t300[1+MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t301[1+MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t310[1+MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_t311[1+MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_n310[1+MAX_NUM_CCs];
-  long                    ue_TimersAndConstants_n311[1+MAX_NUM_CCs];
-#else
-   RrcConfigurationReq    RrcReq;
-#endif
-  long                    ue_TransmissionMode[1+MAX_NUM_CCs];
-  long                    srb1_timer_poll_retransmit;
-  long                    srb1_timer_reordering;
-  long                    srb1_timer_status_prohibit;
-  long                    srb1_poll_pdu;
-  long                    srb1_poll_byte;
-  long                    srb1_max_retx_threshold;
-  /* Nb of MME to connect to */
-  uint8_t             nb_mme;
-  /* List of MME to connect to */
-  mme_ip_address_t    mme_ip_address[S1AP_MAX_NB_MME_IP_ADDRESS];
-
-  int                 sctp_in_streams;
-  int                 sctp_out_streams;
-
-  char               *enb_interface_name_for_S1U;
-  in_addr_t           enb_ipv4_address_for_S1U;
-  tcp_udp_port_t      enb_port_for_S1U;
-
-  char               *enb_interface_name_for_S1_MME;
-  in_addr_t           enb_ipv4_address_for_S1_MME;
-
-  char               *flexran_agent_interface_name;
-  in_addr_t           flexran_agent_ipv4_address;
-  tcp_udp_port_t      flexran_agent_port;
-  char               *flexran_agent_cache;
-
-
-#ifndef OCP_FRAMEWORK
-  // otg config
-  /* Nb of OTG elements */
-  uint8_t            num_otg_elements;
-  /* element config*/
-  uint16_t          otg_ue_id[NB_MODULES_MAX+1];
-  uint8_t          otg_app_type[NB_MODULES_MAX+1];
-  uint8_t            otg_bg_traffic[NB_MODULES_MAX+1];
-  // log config
-  int16_t           glog_level;
-  int16_t           glog_verbosity;
-  int16_t           hw_log_level;
-  int16_t           hw_log_verbosity;
-  int16_t           phy_log_level;
-  int16_t           phy_log_verbosity;
-  int16_t           mac_log_level;
-  int16_t           mac_log_verbosity;
-  int16_t           rlc_log_level;
-  int16_t           rlc_log_verbosity;
-  int16_t           pdcp_log_level;
-  int16_t           pdcp_log_verbosity;
-  int16_t           rrc_log_level;
-  int16_t           rrc_log_verbosity;
-  int16_t           gtpu_log_level;
-  int16_t           gtpu_log_verbosity;
-  int16_t           udp_log_level;
-  int16_t           udp_log_verbosity;
-  int16_t           osa_log_level;
-  int16_t           osa_log_verbosity;
-#endif
-} Enb_properties_t;
-
-typedef struct Enb_properties_array_s {
-  int                  number;
-  Enb_properties_t    *properties[MAX_ENB];
-  int                  nb_ru;
-  ru_config_t         *ru_config[NUMBER_OF_RU_MAX];
-} Enb_properties_array_t;
 
 void                          enb_config_display(void);
 void                          ru_config_display(void);
-const Enb_properties_array_t *enb_config_init(char* lib_config_file_name_pP);
-
-const Enb_properties_array_t *enb_config_get(void);
 
 #endif /* ENB_CONFIG_H_ */
 /** @} */
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index 39f54e0856..e9dcec4b21 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -130,7 +130,7 @@ void check_ul_failure(module_id_t module_idP,int CC_id,int UE_id,
   
 }
 
-void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
+void eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP)  
 {
 
   int mbsfn_status[MAX_NUM_CCs];
@@ -213,14 +213,7 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 
     RC.mac[module_idP]->UE_list.UE_sched_ctrl[i].cqi_req_timer++;
 
-    // was this before: 
-    //    eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
-
-    
-    // eNB_UE_stats is never NULL now
-
-    /*    if (eNB_UE_stats==NULL) {
-	//mac_remove_ue(module_idP, i, frameP, subframeP);
+    /*
       //Inform the controller about the UE deactivation. Should be moved to RRC agent in the future
 #if defined(FLEXRAN_AGENT_S_IF)
       if (mac_agent_registered[module_idP]) {
@@ -314,6 +307,22 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 
 #endif
 
+  // This schedules MIB
+  if ((subframeP==0) && (frameP&3) == 0) schedule_mib(module_idP,frameP,subframeP);
+
+  // This schedules SI for LTE and eMTC
+  schedule_SI(module_idP,frameP,subframeP);
+
+  // This schedules Random-Access
+  schedule_RA(module_idP,frameP,subframeP,1);
+
+  // This schedules ULSCH in subframe+
+  schedule_ulsch(module_idP,frameP,subframeP);
+
+  // This schedules DLSCH in
+  schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
+
+  /*
   switch (subframeP) {
   case 0:
 
@@ -322,12 +331,11 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
     // Schedule Normal DLSCH
 
 
-    //    schedule_RA(module_idP,frameP,subframeP,2);
-    LOG_D(MAC,"Scheduling MIB\n");
-    if ((frameP&3) == 0) schedule_mib(module_idP,frameP,subframeP);
+
     LOG_D(MAC,"NFAPI: number_of_pdus %d, number_of_TX_req %d\n",
 	  DL_req[0].dl_config_request_body.number_pdu,
 	  TX_req[0].tx_request_body.number_of_pdus);
+
     if (cc[0].tdd_Config == NULL) {  //FDD
       schedule_ulsch(module_idP,frameP,cooperation_flag,0,4);//,calibration_flag);
     } else if  ((cc[0].tdd_Config->subframeAssignment == 0) ||
@@ -509,7 +517,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
     if (cc[0].tdd_Config != NULL) { // TDD
       switch (cc[0].tdd_Config->subframeAssignment) {
       case 1:
-        //        schedule_RA(module_idP,frameP,subframeP);
         schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,8);
 
         // no break here!
@@ -579,11 +586,9 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
     // TDD Config 0,6 ULSCH for subframes 9,3 resp.
     // TDD normal DLSCH
     // FDD normal UL/DLSCH
-    schedule_SI(module_idP,frameP,subframeP);
 
-    //schedule_RA(module_idP,frameP,subframeP,5);
+
     if (cc[0].tdd_Config == NULL) {
-      schedule_RA(module_idP,frameP,subframeP,1);
       schedule_ulsch(module_idP,frameP,cooperation_flag,5,9);
 #ifndef FLEXRAN_AGENT_SB_IF
       schedule_ue_spec(module_idP, frameP, subframeP,  mbsfn_status);
@@ -663,7 +668,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
         break;
 
       case 5:
-        schedule_RA(module_idP,frameP,subframeP,2);
 #ifndef FLEXRAN_AGENT_SB_IF
         schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
         fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
@@ -747,7 +751,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
       switch (cc[0].tdd_Config->subframeAssignment) {
       case 3:
       case 4:
-        schedule_RA(module_idP,frameP,subframeP,3);  // 3 = Msg3 subframeP, not
 #ifndef FLEXRAN_AGENT_SB_IF
         schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
         fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
@@ -834,7 +837,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
       case 4:
       case 5:
 
-        //  schedule_RA(module_idP,subframeP);
         schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,2);
 #ifndef FLEXRAN_AGENT_SB_IF
         schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
@@ -894,7 +896,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
       switch (cc[0].tdd_Config->subframeAssignment) {
       case 1:
         schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,3);
-        schedule_RA(module_idP,frameP,subframeP,7);  // 7 = Msg3 subframeP, not
 #ifndef FLEXRAN_AGENT_SB_IF
         schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
         fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
@@ -944,7 +945,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 
       case 6:
         schedule_ulsch(module_idP,frameP,cooperation_flag,subframeP,4);
-        //schedule_RA(module_idP,frameP,subframeP);
 #ifndef FLEXRAN_AGENT_SB_IF
         schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
         fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
@@ -969,7 +969,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 
       case 2:
       case 5:
-        //schedule_RA(module_idP,frameP,subframeP);
 #ifndef FLEXRAN_AGENT_SB_IF
         schedule_ue_spec(module_idP,frameP,subframeP,mbsfn_status);
         fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_status);
@@ -1022,6 +1021,7 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
     break;
 
   }
+  */
 
   // Allocate CCEs and Msg3 for good after scheduling is done
   for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++) {
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 47a809f032..abe098c0c8 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -199,9 +199,14 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
   }
 #endif
 
+  
   start_meas(&eNB->schedule_ra);
 
+ 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+    // skip UL component carriers
+    if (is_UL_sf(&cc[CC_id],subframeP)==1) continue;
+
     vrb_map       = cc[CC_id].vrb_map;
 
     dl_req        = &eNB->DL_req[CC_id].dl_config_request_body;
@@ -224,7 +229,7 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 
 	    // This uses an MPDCCH Type 2 allocation according to Section 9.1.5 36-213
 	    // Parameters:
-	    //    p=2+4 PRB set (number of PRB pairs 6)
+	    //    p=2+4 PRB set (number of PRB pairs 3)
 	    //    rmax = mpdcch-NumRepetition-RA-r13 => Table 9.1.5-3
 	    //    if CELevel = 0,1 => Table 9.1.5-1b for MPDCCH candidates
 	    //    if CELevel = 2,3 => Table 9.1.5-2b for MPDCCH candidates
@@ -568,9 +573,9 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 		}
 	      } // mpdcch_repetition_count == reps
 	      if ((RA_template->Msg4_frame == frameP) && (RA_template->Msg4_subframe == subframeP)) {
+
 		// Program PDSCH
-		RA_template->generate_rar = 0;	 
-		
+
 		LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Generating Msg4 BR with RRC Piggyback (RA proc %d, RNTI %x)\n",
 		      module_idP, CC_id, frameP, subframeP,i,RA_template->rnti);
 		
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
index 7f4fd19db3..a400bb3ccd 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_bch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
@@ -550,8 +550,12 @@ schedule_SI(
   nfapi_dl_config_request_pdu_t  *dl_config_pdu;
   nfapi_tx_request_pdu_t         *TX_req;
   nfapi_dl_config_request_body_t *dl_req;
+
   start_meas(&eNB->schedule_si);
 
+  // Only schedule System Information in subframe 5
+  if (subframeP != 5) return;
+
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
 
     cc              = &eNB->common_channels[CC_id];
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
index 7b6a9f0ec8..825d0fa8b6 100755
--- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
@@ -456,6 +456,7 @@ schedule_ue_spec(
   nfapi_dl_config_request_body_t *dl_req;
   nfapi_dl_config_request_pdu_t  *dl_config_pdu;
   nfapi_tx_request_pdu_t         *TX_req;
+  int                            tdd_sfa;
 
 #if 0
   if (UE_list->head==-1) {
@@ -466,6 +467,41 @@ schedule_ue_spec(
   start_meas(&eNB->schedule_dlsch);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH,VCD_FUNCTION_IN);
 
+
+  // for TDD: check that we have to act here, otherwise return
+  if (cc[0].tdd_Config) {
+    tdd_sfa = cc[0].tdd_Config->subframeAssignment;
+    switch (subframeP) {
+    case 0:
+      // always continue
+       break;
+    case 1:
+      return;
+	break;
+    case 2:
+      return;
+      break;
+    case 3:
+      if ((tdd_sfa!=2) && (tdd_sfa!=5)) return;
+      break;
+    case 4:
+      if ((tdd_sfa!=1)&&(tdd_sfa!=2)&&(tdd_sfa!=4)&&(tdd_sfa!=5)) return;
+      break;
+    case 5:
+      break;
+    case 6:
+    case 7:
+      if ((tdd_sfa!=1)&&(tdd_sfa!=2)&&(tdd_sfa!=4)&&(tdd_sfa!=5)) return;
+      break;
+    case 8:
+      if ((tdd_sfa!=2)&&(tdd_sfa!=3)&&(tdd_sfa!=4)&&(tdd_sfa!=5)) return;
+      break;
+    case 9:
+      if ((tdd_sfa!=1)&&(tdd_sfa!=3)&&(tdd_sfa!=4)&&(tdd_sfa!=6)) return;
+      break;
+   
+    }
+  }
   //weight = get_ue_weight(module_idP,UE_id);
   aggregation = 2; 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
@@ -1181,6 +1217,8 @@ schedule_ue_spec(
     } // UE_id loop
   }  // CC_id loop
 
+     
+  fill_DLSCH_dci(module_idP,frameP,subframeP,mbsfn_flag);
 
   stop_meas(&eNB->schedule_dlsch);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_SCHEDULE_DLSCH,VCD_FUNCTION_OUT);
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index dceff068d3..45d7c582f1 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -403,6 +403,69 @@ uint8_t get_Msg3harqpid(COMMON_channels_t *cc,
 
 }
 
+int is_UL_subframe(COMMON_channels_t *ccP,uint8_t subframeP)
+{
+
+  // if FDD return dummy value
+  if (ccP->tdd_Config == NULL)
+    return(0);
+
+  switch (ccP->tdd_Config->subframeAssignment) {
+
+  case 1:
+    switch (subframeP) {
+    case 0:
+    case 4:
+    case 5:
+    case 9:
+      return(0);
+      break;
+
+    case 2:
+    case 3:
+    case 7:
+    case 8:
+      return(1);
+      break;
+
+    default:
+      return(0);
+      break;
+    }
+    break;
+
+  case 3:
+    if  ((subframeP<=1) || (subframeP>=5))
+      return(0);
+    else if ((subframeP>1) && (subframeP < 5))
+      return(1);
+    else AssertFatal(1==0,"Unknown subframe number\n");
+    break;
+
+  case 4:
+    if  ((subframeP<=1) || (subframeP>=4))
+      return(0);
+    else if ((subframeP>1) && (subframeP < 4))
+      return(1);
+    else AssertFatal(1==0,"Unknown subframe number\n");
+    break;
+    
+  case 5:
+    if  ((subframeP<=1) || (subframeP>=3))
+      return(0);
+    else if ((subframeP>1) && (subframeP < 3))
+      return(1);
+    else AssertFatal(1==0,"Unknown subframe number\n");
+    break;
+
+  default:
+    AssertFatal(1==0,"subframe %d Unsupported TDD configuration %d\n",
+		subframeP,ccP->tdd_Config->subframeAssignment);
+    break;
+
+  }
+}
+
 #ifdef Rel14
 
 int get_numnarrowbands(long dl_Bandwidth) {
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index 660bd80adb..2851c91db6 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -126,7 +126,7 @@ void rx_sdu(const module_id_t enb_mod_idP,
       return;
     }
   }
-  else {
+  else { // Check if this is an RA process for the rnti
     AssertFatal((RA_id = find_RA_id(enb_mod_idP,CC_idP,rntiP))!=-1,
 		"Cannot find rnti %x in RA list\n",rntiP);
     AssertFatal(eNB->common_channels[CC_idP].radioResourceConfigCommon->rach_ConfigCommon.maxHARQ_Msg3Tx>1,
@@ -353,27 +353,29 @@ void rx_sdu(const module_id_t enb_mod_idP,
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC,1);
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_TERMINATE_RA_PROC,0);
       for (ii=0; ii<NB_RA_PROC_MAX; ii++) {
+	RA_TEMPLATE *RA_template = &eNB->common_channels[CC_idP].RA_template[ii];
+
         LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Checking proc %d : rnti (%x, %x), active %d\n",
               enb_mod_idP, CC_idP, ii,
-              eNB->common_channels[CC_idP].RA_template[ii].rnti, rntiP,
-              eNB->common_channels[CC_idP].RA_template[ii].RA_active);
+              RA_template->rnti, rntiP,
+              RA_template->RA_active);
 
-        if ((eNB->common_channels[CC_idP].RA_template[ii].rnti==rntiP) &&
-            (eNB->common_channels[CC_idP].RA_template[ii].RA_active==TRUE)) {
+        if ((RA_template->rnti==rntiP) &&
+            (RA_template->RA_active==TRUE)) {
 
           //payload_ptr = parse_ulsch_header(msg3,&num_ce,&num_sdu,rx_ces,rx_lcids,rx_lengths,msg3_len);
 
           if (UE_id < 0) {
-            memcpy(&eNB->common_channels[CC_idP].RA_template[ii].cont_res_id[0],payload_ptr,6);
+            memcpy(&RA_template->cont_res_id[0],payload_ptr,6);
             LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3: length %d, offset %ld\n",
                   enb_mod_idP,CC_idP,frameP,rx_lengths[i],payload_ptr-sduP);
 
-            if ((UE_id=add_new_ue(enb_mod_idP,CC_idP,eNB->common_channels[CC_idP].RA_template[ii].rnti,harq_pid)) == -1 ) {
+            if ((UE_id=add_new_ue(enb_mod_idP,CC_idP,RA_template->rnti,harq_pid)) == -1 ) {
               AssertFatal(1==0,"[MAC][eNB] Max user count reached\n");
 	      // kill RA procedure
             } else
               LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d Added user with rnti %x => UE %d\n",
-                    enb_mod_idP,CC_idP,frameP,eNB->common_channels[CC_idP].RA_template[ii].rnti,UE_id);
+                    enb_mod_idP,CC_idP,frameP,RA_template->rnti,UE_id);
           } else {
             LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d CCCH: Received Msg3 from already registered UE %d: length %d, offset %ld\n",
                   enb_mod_idP,CC_idP,frameP,UE_id,rx_lengths[i],payload_ptr-sduP);
@@ -397,9 +399,14 @@ void rx_sdu(const module_id_t enb_mod_idP,
             //  process_ra_message(msg3,num_ce,rx_lcids,rx_ces);
           }
 
-          eNB->common_channels[CC_idP].RA_template[ii].generate_Msg4 = 1;
-          eNB->common_channels[CC_idP].RA_template[ii].wait_ack_Msg4 = 0;
-
+	  // prepare transmission of Msg4
+          RA_template->generate_Msg4 = 1;
+          RA_template->wait_ack_Msg4 = 0;
+	  
+	  // Program Msg4 PDCCH+DLSCH/MPDCCH transmission 4 subframes from now
+	  RA_template->Msg4_frame    = frameP + ((subframeP>5) ? 1 : 0);
+	  RA_template->Msg4_subframe = (subframeP+4)%10;
+	  
         } // if process is active
       } // loop on RA processes
       
@@ -656,23 +663,82 @@ void set_msg3_subframe(module_id_t Mod_id,
   }
 }
 
+
 void schedule_ulsch(module_id_t module_idP, 
 		    frame_t frameP,
-		    unsigned char cooperation_flag,
-		    sub_frame_t subframeP, 
-		    unsigned char sched_subframe) {
+		    sub_frame_t subframeP) { 
+
+
 
 
 
   uint16_t first_rb[MAX_NUM_CCs],i;
   int CC_id;
   eNB_MAC_INST *eNB=RC.mac[module_idP];
+  COMMON_channels_t *cc;
 
   start_meas(&eNB->schedule_ulsch);
 
 
+  int sched_subframe = (subframeP+4)%10;
+
+  cc = &eNB->common_channels[0];
+  int tdd_sfa;
+  // for TDD: check subframes where we have to act and return if nothing should be done now
+  if (cc->tdd_Config) {
+    tdd_sfa = cc->tdd_Config->subframeAssignment;
+    switch (subframeP) {
+    case 0:
+      if ((tdd_sfa == 0)||
+	  (tdd_sfa == 3)||
+	  (tdd_sfa == 6)) sched_subframe = 4;
+      else return;
+      break;
+    case 1:
+      if ((tdd_sfa==0)||
+	  (tdd_sfa==1)) sched_subframe = 7;
+      else if (tdd_sfa==6) sched_subframe = 8;
+      break;
+    default:
+      return;
+
+    case 2: // Don't schedule UL in subframe 2 for TDD
+      return;
+    case 3:
+      if (tdd_sfa==2) sched_subframe = 7;
+      else return;
+      break;
+    case 4:
+      if (tdd_sfa==1) sched_subframe = 8;
+      else return;
+      break;
+    case 5:
+      if (tdd_sfa==0)      sched_subframe = 9;
+      else if (tdd_sfa==6) sched_subframe = 3;
+      else return;
+      break;
+    case 6:
+      if (tdd_sfa==1)      sched_subframe = 2;
+      else if (tdd_sfa==6) sched_subframe = 3;
+      else return;
+      break;
+    case 7:
+      return;
+    case 8:
+      if ((tdd_sfa>=2) || (tdd_sfa<=5)) sched_subframe=2;
+      else return;
+      break;
+    case 9:
+      if ((tdd_sfa==1) || (tdd_sfa==3) || (tdd_sfa==4)) sched_subframe=3;
+      else if (tdd_sfa==6) sched_subframe=4;
+      else return;
+      break;
+    }
+  }
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
 
+
+
     //leave out first RB for PUCCH
     first_rb[CC_id] = 1;
 
@@ -691,19 +757,19 @@ void schedule_ulsch(module_id_t module_idP,
 
     
     for (i=0; i<NB_RA_PROC_MAX; i++) {
-      if ((eNB->common_channels[CC_id].RA_template[i].RA_active == TRUE) &&
-          (eNB->common_channels[CC_id].RA_template[i].generate_rar == 0) &&
-          (eNB->common_channels[CC_id].RA_template[i].generate_Msg4 == 0) &&
-          (eNB->common_channels[CC_id].RA_template[i].wait_ack_Msg4 == 0) &&
-          (eNB->common_channels[CC_id].RA_template[i].Msg3_subframe == sched_subframe)) {
+      if ((cc->RA_template[i].RA_active == TRUE) &&
+          (cc->RA_template[i].generate_rar == 0) &&
+          (cc->RA_template[i].generate_Msg4 == 0) &&
+          (cc->RA_template[i].wait_ack_Msg4 == 0) &&
+          (cc->RA_template[i].Msg3_subframe == sched_subframe)) {
         first_rb[CC_id]++;
-	//    eNB->common_channels[CC_id].RA_template[i].Msg3_subframe = -1;
+	//    cc->RA_template[i].Msg3_subframe = -1;
         break;
       }
     }
   }
 
-  schedule_ulsch_rnti(module_idP, cooperation_flag, frameP, subframeP, sched_subframe,first_rb);
+  schedule_ulsch_rnti(module_idP, frameP, subframeP, sched_subframe,first_rb);
 
 
   stop_meas(&eNB->schedule_ulsch);
@@ -713,7 +779,6 @@ void schedule_ulsch(module_id_t module_idP,
 
 
 void schedule_ulsch_rnti(module_id_t   module_idP,
-                         unsigned char cooperation_flag,
                          frame_t       frameP,
                          sub_frame_t   subframeP,
                          unsigned char sched_subframe,
diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h
index 63e717f90e..7cdd3f3ddd 100644
--- a/openair2/LAYER2/MAC/proto.h
+++ b/openair2/LAYER2/MAC/proto.h
@@ -78,9 +78,8 @@ int8_t ue_get_mbsfn_sf_alloction (module_id_t module_idP, uint8_t mbsfn_sync_are
 @param Mod_id Instance ID of eNB
 @param frame Frame index
 @param subframe Subframe number on which to act
-@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup)
 */
-void schedule_ulsch(module_id_t module_idP,frame_t frameP,unsigned char cooperation_flag,sub_frame_t subframe,unsigned char sched_subframe);
+void schedule_ulsch(module_id_t module_idP,frame_t frameP,sub_frame_t subframe);
 
 /** \brief ULSCH Scheduling per RNTI
 @param Mod_id Instance ID of eNB
@@ -88,15 +87,7 @@ void schedule_ulsch(module_id_t module_idP,frame_t frameP,unsigned char cooperat
 @param subframe Subframe number on which to act
 @param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup)
 */
-void schedule_ulsch_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframe, unsigned char sched_subframe, uint16_t *first_rb);
-
-/** \brief ULSCH Scheduling for CBA  RNTI
-@param Mod_id Instance ID of eNB
-@param frame Frame index
-@param subframe Subframe number on which to act
-@param sched_subframe Subframe number where PUSCH is transmitted (for DAI lookup)
-*/
-void schedule_ulsch_cba_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframe, unsigned char sched_subframe, uint16_t *first_rb);
+void schedule_ulsch_rnti(module_id_t module_idP, frame_t frameP, sub_frame_t subframe, unsigned char sched_subframe, uint16_t *first_rb);
 
 /** \brief Second stage of DLSCH scheduling, after schedule_SI, schedule_RA and schedule_dlsch have been called.  This routine first allocates random frequency assignments for SI and RA SDUs using distributed VRB allocations and adds the corresponding DCI SDU to the DCI buffer for PHY.  It then loops over the UE specific DCIs previously allocated and fills in the remaining DCI fields related to frequency allocation.  It assumes localized allocation of type 0 (DCI.rah=0).  The allocation is done for tranmission modes 1,2,4.
 @param Mod_id Instance of eNB
@@ -194,12 +185,10 @@ void dlsch_scheduler_pre_processor_allocate (module_id_t   Mod_id,
 /* \brief Function to trigger the eNB scheduling procedure.  It is called by PHY at the beginning of each subframe, \f$n$\f
    and generates all DLSCH allocations for subframe \f$n\f$ and ULSCH allocations for subframe \f$n+k$\f. 
 @param Mod_id Instance ID of eNB
-@param cooperation_flag Flag to indicated that this cell has cooperating nodes (i.e. that there are collaborative transport channels that
-can be scheduled.
 @param subframe Index of current subframe
 @param calibration_flag Flag to indicate that eNB scheduler should schedule TDD auto-calibration PUSCH.
 */
-void eNB_dlsch_ulsch_scheduler(module_id_t module_idP, uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP);//, int calibration_flag);
+void eNB_dlsch_ulsch_scheduler(module_id_t module_idP, frame_t frameP, sub_frame_t subframeP);//, int calibration_flag);
 
 /* \brief Function to indicate a received preamble on PRACH.  It initiates the RA procedure.
 @param Mod_id Instance ID of eNB
diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c
index bac5878ece..70104e8331 100644
--- a/openair2/PHY_INTERFACE/IF_Module.c
+++ b/openair2/PHY_INTERFACE/IF_Module.c
@@ -132,7 +132,6 @@ void UL_indication(UL_IND_t *UL_info)
   if (ifi->CC_mask == ((1<<MAX_NUM_CCs)-1)) {
 
     eNB_dlsch_ulsch_scheduler(module_id,
-			      0,
 			      UL_info->frame+((UL_info->subframe>5)?1:0),
 			      (UL_info->subframe+4)%10);
 
diff --git a/openair3/GTPV1-U/gtpv1u_eNB.c b/openair3/GTPV1-U/gtpv1u_eNB.c
index b665f12738..bafc8d2e86 100644
--- a/openair3/GTPV1-U/gtpv1u_eNB.c
+++ b/openair3/GTPV1-U/gtpv1u_eNB.c
@@ -906,7 +906,7 @@ static int gtpv1u_eNB_init(void)
   NwGtpv1uUdpEntityT      udp;
   NwGtpv1uLogMgrEntityT   log;
   NwGtpv1uTimerMgrEntityT tmr;
-  Enb_properties_t       *enb_properties_p  = NULL;
+
 
   //  enb_properties_p = enb_config_get()->properties[0];
   RC.gtpv1u_data_g = (gtpv1u_data_t*)malloc(sizeof(gtpv1u_data_t));
diff --git a/openair3/UDP/udp_eNB_task.c b/openair3/UDP/udp_eNB_task.c
index b8b6b897a7..b63eef9c7e 100644
--- a/openair3/UDP/udp_eNB_task.c
+++ b/openair3/UDP/udp_eNB_task.c
@@ -99,7 +99,7 @@ void udp_eNB_receiver(struct udp_socket_desc_s *udp_sock_pP);
 
 void *udp_eNB_task(void *args_p);
 
-int udp_enb_init(const Enb_properties_t *enb_config_p);
+int udp_enb_init();
 /* @brief Retrieve the descriptor associated with the task_id
  */
 static
@@ -295,7 +295,7 @@ void *udp_eNB_task(void *args_p)
   MessageDef         *received_message_p    = NULL;
   //const char         *msg_name = NULL;
   //instance_t          instance  = 0;
-  udp_enb_init(NULL);
+  udp_enb_init();
 
   itti_mark_task_ready(TASK_UDP);
   MSC_START_USE();
@@ -427,7 +427,7 @@ on_error:
   return NULL;
 }
 
-int udp_enb_init(const Enb_properties_t *enb_config_p)
+int udp_enb_init()
 {
   LOG_I(UDP_, "Initializing UDP task interface\n");
   STAILQ_INIT(&udp_socket_list);
diff --git a/openair3/UDP/udp_eNB_task.h b/openair3/UDP/udp_eNB_task.h
index d8a22417c0..0f6461dda7 100644
--- a/openair3/UDP/udp_eNB_task.h
+++ b/openair3/UDP/udp_eNB_task.h
@@ -93,6 +93,6 @@ void *udp_eNB_task(void *args_p);
  *  \param enb_config_p configuration of eNB
  *  @returns always 0
  */
-int udp_enb_init(const Enb_properties_t *enb_config_p);
+int udp_enb_init();
 
 #endif /* UDP_ENB_TASK_H_ */
-- 
GitLab