diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index 2965a4f8deae750986e75e217bc37cd36662b1eb..34f20929c5950966796d160dda88e81a613940f7 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -27,6 +27,7 @@ cmake_minimum_required (VERSION 2.8)
 # Base directories, compatible with legacy OAI building
 ################################################
 set (OPENAIR_DIR     $ENV{OPENAIR_DIR})
+set (NFAPI_DIR       $ENV{NFAPI_DIR})
 set (OPENAIR1_DIR    ${OPENAIR_DIR}/openair1)
 set (OPENAIR2_DIR    ${OPENAIR_DIR}/openair2)
 set (OPENAIR3_DIR    ${OPENAIR_DIR}/openair3)
@@ -725,6 +726,7 @@ else()
   include_directories("${OPENAIR2_DIR}/UTIL")
   include_directories("${OPENAIR2_DIR}/UTIL/LOG")
 endif()
+include_directories("${NFAPI_DIR}")
 include_directories("${OPENAIR1_DIR}")
 include_directories("${OPENAIR2_DIR}/NAS")
 include_directories("${OPENAIR2_DIR}")
@@ -958,7 +960,7 @@ set(SCHED_SRC
   ${OPENAIR1_DIR}/SCHED/phy_procedures_lte_ue.c
   ${OPENAIR1_DIR}/SCHED/phy_procedures_lte_common.c
   ${OPENAIR1_DIR}/SCHED/ru_procedures.c
-  ${OPENAIR1_DIR}/SCHED/phy_mac_stub.c
+#  ${OPENAIR1_DIR}/SCHED/phy_mac_stub.c
   ${OPENAIR1_DIR}/SCHED/pucch_pc.c
   ${OPENAIR1_DIR}/SCHED/pusch_pc.c
   ${OPENAIR1_DIR}/SCHED/srs_pc.c
@@ -1070,6 +1072,7 @@ add_library(PHY ${PHY_SRC})
 #Layer 2 library
 #####################
 set(MAC_DIR ${OPENAIR2_DIR}/LAYER2/MAC)
+set(PHY_INTERFACE_DIR ${OPENAIR2_DIR}/PHY_INTERFACE)
 set(RLC_DIR ${OPENAIR2_DIR}/LAYER2/RLC)
 set(RLC_UM_DIR ${OPENAIR2_DIR}/LAYER2/RLC/UM_v9.3.0)
 set(RLC_AM_DIR ${OPENAIR2_DIR}/LAYER2/RLC/AM_v9.3.0)
@@ -1120,7 +1123,7 @@ set(L2_SRC
   ${RRC_DIR}/L2_interface.c
   )
 set (MAC_SRC
-  ${MAC_DIR}/lte_transport_init.c
+  ${PHY_INTERFACE_DIR}/IF_Module.c
   ${MAC_DIR}/main.c
   ${MAC_DIR}/ue_procedures.c
   ${MAC_DIR}/ra_procedures.c
@@ -1555,6 +1558,7 @@ ${OPENAIR1_DIR}/SIMULATION/TOOLS/multipath_tv_channel.c
 ${OPENAIR1_DIR}/SIMULATION/RF/rf.c
 ${OPENAIR1_DIR}/SIMULATION/RF/dac.c
 ${OPENAIR1_DIR}/SIMULATION/RF/adc.c
+${OPENAIR1_DIR}/SIMULATION/ETH_TRANSPORT/netlink_init.c
 )
 
 add_library(SIMU_ETH
@@ -1843,7 +1847,7 @@ add_executable(oaisim
 target_include_directories(oaisim PUBLIC  ${OPENAIR_TARGETS}/SIMU/USER)
 target_link_libraries (oaisim
   -Wl,-ldl,--start-group
-  RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB GTPV1U SECU_CN UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS ${MSC_LIB} L2 ${RAL_LIB} LIB_NAS_UE SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
+  RRC_LIB S1AP_LIB S1AP_ENB X2AP_LIB GTPV1U SECU_CN UTIL HASHTABLE SCTP_CLIENT UDP SCHED_LIB PHY LFDS ${MSC_LIB} L2 ${RAL_LIB} LIB_NAS_UE SIMU SECU_OSA ${ITTI_LIB}  ${MIH_LIB}
   -Wl,--end-group )
 
 target_link_libraries (oaisim ${LIBXML2_LIBRARIES} ${LAPACK_LIBRARIES})
@@ -1884,7 +1888,7 @@ add_executable(oaisim_nos1
 target_include_directories(oaisim_nos1 PUBLIC  ${OPENAIR_TARGETS}/SIMU/USER)
 target_link_libraries (oaisim_nos1
   -Wl,--start-group
-  RRC_LIB X2AP_LIB SECU_CN UTIL HASHTABLE SCHED_LIB PHY LFDS ${MSC_LIB} L2 ${RAL_LIB} SIMU SIMU_ETH SECU_OSA ${ITTI_LIB}  ${MIH_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${FLEXRAN_AGENT_LIB} LFDS7
+  RRC_LIB X2AP_LIB SECU_CN UTIL HASHTABLE SCHED_LIB PHY LFDS ${MSC_LIB} L2 ${RAL_LIB} SIMU SECU_OSA ${ITTI_LIB}  ${MIH_LIB} ${FLPT_MSG_LIB} ${ASYNC_IF_LIB} ${FLEXRAN_AGENT_LIB} LFDS7
   -Wl,--end-group )
 
 target_link_libraries (oaisim_nos1 ${LIBXML2_LIBRARIES} ${LAPACK_LIBRARIES})
@@ -2001,7 +2005,7 @@ if (${T_TRACER})
         oai_eth_transpro
         FLPT_MSG ASYNC_IF FLEXRAN_AGENT HASHTABLE MSC UTIL OMG_SUMO SECU_OSA
         SECU_CN SCHED_LIB PHY L2 default_sched remote_sched RAL MIH CN_UTILS
-        GTPV1U SCTP_CLIENT UDP LIB_NAS_UE LFDS LFDS7 SIMU SIMU_ETH OPENAIR0_LIB)
+        GTPV1U SCTP_CLIENT UDP LIB_NAS_UE LFDS LFDS7 SIMU OPENAIR0_LIB)
     if (TARGET ${i})
       add_dependencies(${i} generate_T)
     endif()
diff --git a/common/ran_context.h b/common/ran_context.h
index c4822a50a4ff8e7f3ccdc9f081c8351fe91121d5..625e029382ed3bf222dad96eb2c64d53147c622c 100644
--- a/common/ran_context.h
+++ b/common/ran_context.h
@@ -50,11 +50,17 @@
 typedef struct {
   /// RAN context config file name
   char *config_file_name;
-  /// Number of eNB instances in this node
+  /// Number of RRC instances in this node
   int nb_inst;
   /// Number of Component Carriers per instance in this node
   int *nb_CC;
-  /// Number of radio units
+  /// Number of MACRLC instances in this node
+  int nb_macrlc_inst;
+  /// Number of L1 instances in this node
+  int nb_L1_inst;
+  /// Number of Component Carriers per instance in this node
+  int *nb_L1_CC;
+  /// Number of RU instances in this node
   int nb_RU;
   /// eNB context variables
   struct PHY_VARS_eNB_s ***eNB;
diff --git a/openair1/PHY/INIT/defs.h b/openair1/PHY/INIT/defs.h
index 1491dbd8b787e411ba1bf87372bb87da8ee58855..36d8aa00be4fcf51cb784903b5fde240535e0dae 100644
--- a/openair1/PHY/INIT/defs.h
+++ b/openair1/PHY/INIT/defs.h
@@ -39,6 +39,13 @@
  * @{
  */
 
+/*!
+\fn int l1_top_init_eNB(void)
+\brief Initialize north interface for L1
+@returns 0 on success
+ */
+int l1_north_init_eNB(void);
+
 /*!
 \fn int phy_init_top(LTE_DL_FRAME_PARMS *frame_parms)
 \brief Allocate and Initialize the PHY variables after receiving static configuration
@@ -347,6 +354,7 @@ void phy_config_dedicated_scell_eNB(uint8_t Mod_id,
 \brief Cleanup the PHY variables*/
 void phy_cleanup(void);
 
+void phy_config_request(PHY_Config_t *phy_config);
 
 int init_frame_parms(LTE_DL_FRAME_PARMS *frame_parms,uint8_t osf);
 void dump_frame_parms(LTE_DL_FRAME_PARMS *frame_parms);
diff --git a/openair1/PHY/INIT/lte_init.c b/openair1/PHY/INIT/lte_init.c
index 7516eb3e154dfdc442656d502c6134944832b2e6..03baf1a58b954b09bab3e312afd3d6c91506052b 100644
--- a/openair1/PHY/INIT/lte_init.c
+++ b/openair1/PHY/INIT/lte_init.c
@@ -39,40 +39,53 @@ uint8_t dmrs1_tab[8] = {0,2,3,4,6,8,9,10};
 
 int N_RB_DL_array[6] = {6,15,25,50,75,100};
 
-void phy_config_mib_eNB(int                 Mod_id,
-			int                 CC_id,
-			int                 eutra_band,  
-			int                 dl_Bandwidth,
-			PHICH_Config_t      *phich_config,
-			int                 Nid_cell,
-			int                 Ncp,
-			int                 p_eNB,
-			uint32_t            dl_CarrierFreq,
-			uint32_t            ul_CarrierFreq) {
+int l1_north_init_eNB() {
+
+  int i,j;
+  AssertFatal(RC.nb_L1_inst>0,"nb_L1_inst=%d\n",RC.nb_L1_inst);
+  AssertFatal(RC.nb_L1_CC!=NULL,"nb_L1_CC is null\n");
+  AssertFatal(RC.eNB!=NULL,"RC.eNB is null\n");
+  for (i=0;i<RC.nb_L1_inst;i++) {
+    AssertFatal(RC.eNB[i]!=NULL,"RC.eNB[%d] is null\n",i);
+    AssertFatal(RC.nb_L1_CC[i]>0,"RC.nb_L1_CC[%d]=%d\n",i,RC.nb_L1_CC[i]);
+    for (j=0;j<RC.nb_L1_CC[i];j++) {
+      AssertFatal(RC.eNB[i][j]!=NULL,"RC.eNB[%d][%d] is null\n",i,j);
+      if ((RC.eNB[i][j]->if_inst =  IF_Module_init(i))<0) return(-1); 
+      RC.eNB[i][j]->if_inst->PHY_config_req = phy_config_request;
+      RC.eNB[i][j]->if_inst->schedule_response = schedule_response;
+    }
+  }
+  return(0);
+}
+
+
+
+void phy_config_request(PHY_Config_t *phy_config) {
+
+  uint8_t Mod_id              = phy_config->Mod_id;
+  int CC_id                   = phy_config->CC_id;
+  nfapi_config_request_t *cfg = phy_config->cfg;
+
 
-  
   LTE_DL_FRAME_PARMS *fp;
   PHICH_RESOURCE_t phich_resource_table[4]={oneSixth,half,one,two};
+  int                 eutra_band     = cfg->nfapi_config.rf_bands.rf_band[0];  
+  int                 dl_Bandwidth   = cfg->rf_config.dl_channel_bandwidth.value;
+  int                 Nid_cell       = cfg->sch_config.physical_cell_id.value;
+  int                 Ncp            = cfg->subframe_config.dl_cyclic_prefix_type.value;
+  int                 p_eNB          = cfg->rf_config.tx_antenna_ports.value;
+  uint32_t            dl_CarrierFreq = cfg->nfapi_config.earfcn.value;
+
+  LOG_I(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d,Nid_cell %d,p %d,Ncp %d,DL freq %u,phich_config.resource %d, phich_config.duration %d)\n",
+	Mod_id, CC_id, eutra_band, N_RB_DL_array[dl_Bandwidth], Nid_cell, p_eNB,Ncp,dl_CarrierFreq,
+	cfg->phich_config.phich_resource.value,
+	cfg->phich_config.phich_duration.value);
+
+  AssertFatal(RC.eNB != NULL, "PHY instance pointer doesn't exist\n");
+  AssertFatal(RC.eNB[Mod_id] != NULL, "PHY instance %d doesn't exist\n",Mod_id);
+  AssertFatal(RC.eNB[Mod_id][CC_id] != NULL, "PHY instance %d, CCid %d doesn't exist\n",Mod_id,CC_id);
 
-  LOG_I(PHY,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d,Nid_cell %d,p %d,DL freq %u,phich_config.resource %d, phich_config.duration %d)\n",
-	Mod_id, CC_id, eutra_band, N_RB_DL_array[dl_Bandwidth], Nid_cell, p_eNB,dl_CarrierFreq,phich_config->phich_Resource,phich_config->phich_Duration);
 
-  if (RC.eNB == NULL) {
-    RC.eNB                               = (PHY_VARS_eNB ***)malloc((1+NUMBER_OF_eNB_MAX)*sizeof(PHY_VARS_eNB***));
-    LOG_I(PHY,"RC.eNB = %p\n",RC.eNB);
-    memset(RC.eNB,0,(1+NUMBER_OF_eNB_MAX)*sizeof(PHY_VARS_eNB***));
-  }
-  if (RC.eNB[Mod_id] == NULL) {
-    RC.eNB[Mod_id]                       = (PHY_VARS_eNB **)malloc((1+MAX_NUM_CCs)*sizeof(PHY_VARS_eNB**));
-    LOG_I(PHY,"RC.eNB[%d] = %p\n",Mod_id,RC.eNB[Mod_id]);
-    memset(RC.eNB[Mod_id],0,(1+MAX_NUM_CCs)*sizeof(PHY_VARS_eNB***));
-  }
-  if (RC.eNB[Mod_id][CC_id] == NULL) {
-    RC.eNB[Mod_id][CC_id] = (PHY_VARS_eNB *)malloc(sizeof(PHY_VARS_eNB));
-    LOG_I(PHY,"RC.eNB[%d][%d] = %p\n",Mod_id,CC_id,RC.eNB[Mod_id][CC_id]);
-    RC.eNB[Mod_id][CC_id]->Mod_id        = Mod_id;
-    RC.eNB[Mod_id][CC_id]->CC_id         = CC_id;
-  }
 
   RC.eNB[Mod_id][CC_id]->mac_enabled     = 1;
 
@@ -81,17 +94,18 @@ void phy_config_mib_eNB(int                 Mod_id,
   fp->N_RB_DL                            = N_RB_DL_array[dl_Bandwidth];
   fp->N_RB_UL                            = N_RB_DL_array[dl_Bandwidth];
   fp->Nid_cell                           = Nid_cell;
-  fp->nushift                            = Nid_cell%6;
+  fp->nushift                            = fp->Nid_cell%6;
   fp->eutra_band                         = eutra_band;
   fp->Ncp                                = Ncp;
   fp->nb_antenna_ports_eNB               = p_eNB;
 
-  AssertFatal(phich_config->phich_Resource < 4, "Illegal phich_Resource\n");
-  fp->phich_config_common.phich_resource = phich_resource_table[phich_config->phich_Resource];
-  fp->phich_config_common.phich_duration = phich_config->phich_Duration;
-  fp->dl_CarrierFreq                     = dl_CarrierFreq;
-  fp->ul_CarrierFreq                     = ul_CarrierFreq;
-  if (dl_CarrierFreq==ul_CarrierFreq)
+  AssertFatal(cfg->phich_config.phich_resource.value<4, "Illegal phich_Resource\n");
+
+  fp->phich_config_common.phich_resource = phich_resource_table[cfg->phich_config.phich_resource.value];
+  fp->phich_config_common.phich_duration = cfg->phich_config.phich_duration.value;
+  fp->dl_CarrierFreq                     = from_earfcn(eutra_band,dl_CarrierFreq);
+  fp->ul_CarrierFreq                     = fp->dl_CarrierFreq - get_uldl_offset(eutra_band);
+  if (fp->dl_CarrierFreq==fp->ul_CarrierFreq)
     fp->frame_type = TDD;
   else
     fp->frame_type = FDD;
@@ -99,27 +113,80 @@ void phy_config_mib_eNB(int                 Mod_id,
   init_frame_parms(fp,1);
   init_lte_top(fp);
 
-}
-
-void phy_config_sib1_eNB(uint8_t Mod_id,
-                         int CC_id,
-                         TDD_Config_t *tdd_Config,
-                         uint8_t SIwindowsize,
-                         uint16_t SIPeriod)
-{
-
-  LTE_DL_FRAME_PARMS *fp = &RC.eNB[Mod_id][CC_id]->frame_parms;
-
-  if (tdd_Config) {
-    fp->tdd_config    = tdd_Config->subframeAssignment;
-    fp->tdd_config_S  = tdd_Config->specialSubframePatterns;
+  if (cfg->subframe_config.duplex_mode.value == 0) {
+    fp->tdd_config    = cfg->tdd_frame_structure_config.subframe_assignment.value;
+    fp->tdd_config_S  = cfg->tdd_frame_structure_config.special_subframe_patterns.value;
     fp->frame_type    = TDD;
   }
   else {
     fp->frame_type    = FDD;
   }
-  fp->SIwindowsize  = SIwindowsize;
-  fp->SIPeriod      = SIPeriod;
+
+  fp->prach_config_common.rootSequenceIndex                          = cfg->prach_config.root_sequence_index.value;
+  LOG_I(PHY,"prach_config_common.rootSequenceIndex = %d\n",cfg->prach_config.root_sequence_index.value);
+
+  fp->prach_config_common.prach_Config_enabled=1;
+
+  fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex          =cfg->prach_config.configuration_index.value;
+  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.prach_ConfigIndex = %d\n",cfg->prach_config.configuration_index.value);
+
+  fp->prach_config_common.prach_ConfigInfo.highSpeedFlag              =cfg->prach_config.high_speed_flag.value;
+  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.highSpeedFlag = %d\n",cfg->prach_config.high_speed_flag.value);
+  fp->prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig  =cfg->prach_config.zero_correlation_zone_configuration.value;
+  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.zeroCorrelationZoneConfig = %d\n",cfg->prach_config.zero_correlation_zone_configuration.value);
+  fp->prach_config_common.prach_ConfigInfo.prach_FreqOffset           =cfg->prach_config.frequency_offset.value;
+  LOG_I(PHY,"prach_config_common.prach_ConfigInfo.prach_FreqOffset = %d\n",cfg->prach_config.frequency_offset.value);
+
+  init_prach_tables(839);
+  compute_prach_seq(&fp->prach_config_common,fp->frame_type,
+                    RC.eNB[Mod_id][CC_id]->X_u);
+
+  fp->pucch_config_common.deltaPUCCH_Shift = 1+cfg->pucch_config.delta_pucch_shift.value;
+  fp->pucch_config_common.nRB_CQI          = cfg->pucch_config.n_cqi_rb.value;
+  fp->pucch_config_common.nCS_AN           = cfg->pucch_config.n_an_cs.value;
+  fp->pucch_config_common.n1PUCCH_AN       = cfg->pucch_config.n1_pucch_an.value;
+
+  fp->pdsch_config_common.referenceSignalPower                         = cfg->rf_config.reference_signal_power.value;
+  fp->pdsch_config_common.p_b                                          = cfg->subframe_config.pb.value;
+
+  fp->pusch_config_common.n_SB                                         = cfg->pusch_config.number_of_subbands.value;
+  LOG_I(PHY,"pusch_config_common.n_SB = %d\n",fp->pusch_config_common.n_SB );
+
+  fp->pusch_config_common.hoppingMode                                  = cfg->pusch_config.hopping_mode.value;
+  LOG_I(PHY,"pusch_config_common.hoppingMode = %d\n",fp->pusch_config_common.hoppingMode);
+
+  fp->pusch_config_common.pusch_HoppingOffset                          = cfg->pusch_config.hopping_offset.value;
+  LOG_I(PHY,"pusch_config_common.pusch_HoppingOffset = %d\n",fp->pusch_config_common.pusch_HoppingOffset);
+
+  fp->pusch_config_common.enable64QAM                                  = 0;//radioResourceConfigCommon->pusch_ConfigCommon.pusch_ConfigBasic.enable64QAM;
+  LOG_I(PHY,"pusch_config_common.enable64QAM = %d\n",fp->pusch_config_common.enable64QAM );
+  fp->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled     = 0;
+  fp->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled  = 0;
+  if (cfg->uplink_reference_signal_config.uplink_rs_hopping.value == 1) 
+      fp->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = 1;
+  if (cfg->uplink_reference_signal_config.uplink_rs_hopping.value == 2) 
+      fp->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = 1;
+  LOG_I(PHY,"pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled = %d\n",fp->pusch_config_common.ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
+  fp->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH   =  cfg->uplink_reference_signal_config.group_assignment.value;
+  LOG_I(PHY,"pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH = %d\n",fp->pusch_config_common.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
+
+  LOG_I(PHY,"pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled = %d\n",fp->pusch_config_common.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
+
+  fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift            = dmrs1_tab[cfg->uplink_reference_signal_config.cyclic_shift_1_for_drms.value];
+  LOG_I(PHY,"pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift = %d\n",fp->pusch_config_common.ul_ReferenceSignalsPUSCH.cyclicShift);
+
+  init_ul_hopping(fp);
+
+  fp->soundingrs_ul_config_common.enabled_flag                        = 1;
+  fp->soundingrs_ul_config_common.srs_BandwidthConfig                 = cfg->srs_config.bandwidth_configuration.value;
+  fp->soundingrs_ul_config_common.srs_SubframeConfig                  = cfg->srs_config.srs_subframe_configuration.value;
+  fp->soundingrs_ul_config_common.ackNackSRS_SimultaneousTransmission = cfg->srs_config.srs_acknack_srs_simultaneous_transmission.value;
+  fp->soundingrs_ul_config_common.srs_MaxUpPts                        = cfg->srs_config.max_up_pts.value;
+
+  init_ncs_cell(fp,RC.eNB[Mod_id][CC_id]->ncs_cell);
+
+  init_ul_hopping(fp);
+
 }
 
 void phy_config_sib1_ue(uint8_t Mod_id,int CC_id,
@@ -140,6 +207,7 @@ void phy_config_sib1_ue(uint8_t Mod_id,int CC_id,
   fp->SIPeriod      = SIperiod;
 }
 
+/*
 void phy_config_sib2_eNB(uint8_t Mod_id,
                          int CC_id,
                          RadioResourceConfigCommonSIB_t *radioResourceConfigCommon,
@@ -157,7 +225,7 @@ void phy_config_sib2_eNB(uint8_t Mod_id,
   LOG_I(PHY,"[eNB%d] CCid %d: Applying radioResourceConfigCommon\n",Mod_id,CC_id);
 
 
-  fp->prach_config_common.rootSequenceIndex                           =radioResourceConfigCommon->prach_Config.rootSequenceIndex;
+  fp->prach_config_common.rootSequenceIndex                          = radioResourceConfigCommon->prach_Config.rootSequenceIndex;
   LOG_D(PHY,"prach_config_common.rootSequenceIndex = %d\n",fp->prach_config_common.rootSequenceIndex );
 
   fp->prach_config_common.prach_Config_enabled=1;
@@ -280,7 +348,7 @@ void phy_config_sib2_eNB(uint8_t Mod_id,
 
   //
 }
-
+*/
 
 void phy_config_sib2_ue(uint8_t Mod_id,int CC_id,
                         uint8_t eNB_id,
@@ -700,6 +768,7 @@ void phy_config_meas_ue(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index,uint8_t n
 
 }
 
+/*
 void phy_config_dedicated_eNB(uint8_t Mod_id,
                               int CC_id,
                               uint16_t rnti,
@@ -761,6 +830,8 @@ void phy_config_dedicated_eNB(uint8_t Mod_id,
   }
 
 }
+*/
+
 #if defined(Rel10) || defined(Rel14)
 void phy_config_dedicated_scell_ue(uint8_t Mod_id,
                                    uint8_t eNB_index,
@@ -769,6 +840,7 @@ void phy_config_dedicated_scell_ue(uint8_t Mod_id,
 {
 
 }
+/*
 void phy_config_dedicated_scell_eNB(uint8_t Mod_id,
                                     uint16_t rnti,
                                     SCellToAddMod_r10_t *sCellToAddMod_r10,
@@ -785,27 +857,41 @@ void phy_config_dedicated_scell_eNB(uint8_t Mod_id,
 
   if ((dl_CarrierFreq_r10>=36000) && (dl_CarrierFreq_r10<=36199)) {
     carrier_freq_local = 1900000000 + (dl_CarrierFreq_r10-36000)*100000; //band 33 from 3GPP 36.101 v 10.9 Table 5.7.3-1
-    LOG_I(PHY,"[eNB %d] Frame %d: Configured SCell %d to frequency %d (ARFCN %ld) for UE %d\n",Mod_id,/*eNB->frame*/0,CC_id,carrier_freq_local,dl_CarrierFreq_r10,UE_id);
+    LOG_I(PHY,"[eNB %d] Frame %d: Configured SCell %d to frequency %d (ARFCN %ld) for UE %d\n",Mod_id,
+	  //eNB->frame
+	  0,
+	  CC_id,carrier_freq_local,dl_CarrierFreq_r10,UE_id);
   } else if ((dl_CarrierFreq_r10>=6150) && (dl_CarrierFreq_r10<=6449)) {
     carrier_freq_local = 832000000 + (dl_CarrierFreq_r10-6150)*100000; //band 20 from 3GPP 36.101 v 10.9 Table 5.7.3-1
     // this is actually for the UL only, but we use it for DL too, since there is no TDD mode for this band
-    LOG_I(PHY,"[eNB %d] Frame %d: Configured SCell %d to frequency %d (ARFCN %ld) for UE %d\n",Mod_id,/*eNB->frame*/0,CC_id,carrier_freq_local,dl_CarrierFreq_r10,UE_id);
+    LOG_I(PHY,"[eNB %d] Frame %d: Configured SCell %d to frequency %d (ARFCN %ld) for UE %d\n",Mod_id,
+          //eNB->frame
+          0,CC_id,carrier_freq_local,dl_CarrierFreq_r10,UE_id);
   } else {
-    LOG_E(PHY,"[eNB %d] Frame %d: ARFCN %ld of SCell %d for UE %d not supported\n",Mod_id,/*eNB->frame*/0,dl_CarrierFreq_r10,CC_id,UE_id);
+    LOG_E(PHY,"[eNB %d] Frame %d: ARFCN %ld of SCell %d for UE %d not supported\n",Mod_id,
+	  //eNB->frame
+	  0,dl_CarrierFreq_r10,CC_id,UE_id);
   }
 
   if (physicalConfigDedicatedSCell_r10) {
 //#warning " eNB->physicalConfigDedicatedSCell_r10 does not exist in eNB"
     //  eNB->physicalConfigDedicatedSCell_r10[UE_id] = physicalConfigDedicatedSCell_r10;
-    LOG_I(PHY,"[eNB %d] Frame %d: Configured phyConfigDedicatedSCell with CC_id %d for UE %d\n",Mod_id,/*eNB->frame*/0,CC_id,UE_id);
+    LOG_I(PHY,"[eNB %d] Frame %d: Configured phyConfigDedicatedSCell with CC_id %d for UE %d\n",Mod_id,
+	  //eNB->frame
+          0,CC_id,UE_id);
   } else {
-    LOG_E(PHY,"[eNB %d] Frame %d: Received NULL radioResourceConfigDedicated (CC_id %d, UE %d)\n",Mod_id, /*eNB->frame*/0,CC_id,UE_id);
+    LOG_E(PHY,"[eNB %d] Frame %d: Received NULL radioResourceConfigDedicated (CC_id %d, UE %d)\n",Mod_id, 
+	  //eNB->frame
+	  0,CC_id,UE_id);
     return;
   }
 
 }
+*/
+
 #endif
 
+
 void phy_config_harq_ue(uint8_t Mod_id,int CC_id,uint8_t eNB_id,
                         uint16_t max_harq_tx )
 {
@@ -1533,6 +1619,7 @@ int phy_init_RU(RU_t *ru) {
   }
   ru->common.sync_corr = (uint32_t*)malloc16_clear( LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*sizeof(uint32_t)*fp->samples_per_tti );
 
+  return(0);
 }
   
 int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
@@ -1547,7 +1634,7 @@ int phy_init_lte_eNB(PHY_VARS_eNB *eNB,
   LTE_eNB_SRS* const srs_vars       = eNB->srs_vars;
   LTE_eNB_PRACH* const prach_vars   = &eNB->prach_vars;
 
-  int i, j, eNB_id, UE_id; 
+  int i,  eNB_id, UE_id; 
 
 
   eNB->total_dlsch_bitrate = 0;
diff --git a/openair1/PHY/INIT/lte_param_init.c b/openair1/PHY/INIT/lte_param_init.c
index 93dea096499177d03592e3589556b11c2489bc38..d982045c98afaf0ebcef1be99fc21f03946c9fb9 100644
--- a/openair1/PHY/INIT/lte_param_init.c
+++ b/openair1/PHY/INIT/lte_param_init.c
@@ -55,8 +55,7 @@ void lte_param_init(unsigned char N_tx_port_eNB,
   UE = malloc(sizeof(PHY_VARS_UE));
   memset((void*)eNB,0,sizeof(PHY_VARS_eNB));
   memset((void*)UE,0,sizeof(PHY_VARS_UE));
-  //PHY_config = malloc(sizeof(PHY_CONFIG));
-  mac_xface = malloc(sizeof(MAC_xface));
+
 
   srand(0);
   randominit(0);
diff --git a/openair1/PHY/LTE_ESTIMATION/defs.h b/openair1/PHY/LTE_ESTIMATION/defs.h
index 12408422e5712991508bfc2cb9a9e7a651181a58..20bdbc1f362019acc6f1621d536e72f70425aaa2 100644
--- a/openair1/PHY/LTE_ESTIMATION/defs.h
+++ b/openair1/PHY/LTE_ESTIMATION/defs.h
@@ -204,7 +204,7 @@ void lte_ue_measurements_emul(PHY_VARS_UE *phy_vars_ue,uint8_t last_slot,uint8_t
 @returns Path loss in dB
  */
 int16_t get_PL(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index);
-uint32_t get_RSRP(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index);
+double get_RSRP(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index);
 uint32_t get_RSRQ(module_id_t Mod_id,uint8_t CC_id,uint8_t eNB_index);
 uint8_t get_n_adj_cells(module_id_t Mod_id,uint8_t CC_id);
 uint32_t get_rx_total_gain_dB(module_id_t Mod_id,uint8_t CC_id);
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c b/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c
index c24d76e985f3e68b83a96a1a8a52a4909e5e283f..50f55156420b6d770762cc7cbdf116417c26a09f 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_ue_measurements.c
@@ -114,15 +114,20 @@ uint32_t get_RSSI (uint8_t Mod_id,uint8_t CC_id)
 
   return 0xFFFFFFFF;
 }
-uint32_t get_RSRP(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
+double get_RSRP(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
 {
 
+  AssertFatal(PHY_vars_UE_g!=NULL,"PHY_vars_UE_g is null\n");
+  AssertFatal(PHY_vars_UE_g[Mod_id]!=NULL,"PHY_vars_UE_g[%d] is null\n",Mod_id);
+  AssertFatal(PHY_vars_UE_g[Mod_id][CC_id]!=NULL,"PHY_vars_UE_g[%d][%d] is null\n",Mod_id,CC_id);
+
   PHY_VARS_UE *ue = PHY_vars_UE_g[Mod_id][CC_id];
 
   if (ue)
-    return ue->measurements.rsrp[eNB_index];
-
-  return 0xFFFFFFFF;
+    return ((dB_fixed_times10(ue->measurements.rsrp[eNB_index]))/10.0-
+	    get_rx_total_gain_dB(Mod_id,0) -
+	    10*log10(ue->frame_parms.N_RB_DL*12));
+  return -140.0;
 }
 
 uint32_t get_RSRQ(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
diff --git a/openair1/PHY/LTE_TRANSPORT/dci.c b/openair1/PHY/LTE_TRANSPORT/dci.c
index 159dd13cb534fe200e62d7eeec0f407c06401d63..a8f646acb14b198c42c9644ed1f3e529386ddaf9 100755
--- a/openair1/PHY/LTE_TRANSPORT/dci.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci.c
@@ -2037,8 +2037,7 @@ uint8_t get_num_pdcch_symbols(uint8_t num_dci,
   return(0);
 }
 
-uint8_t generate_dci_top(uint8_t num_ue_spec_dci,
-                         uint8_t num_common_dci,
+uint8_t generate_dci_top(uint8_t num_dci,
                          DCI_ALLOC_t *dci_alloc,
                          uint32_t n_rnti,
                          int16_t amp,
@@ -2094,9 +2093,8 @@ uint8_t generate_dci_top(uint8_t num_ue_spec_dci,
     break;
   }
 
-  num_pdcch_symbols = get_num_pdcch_symbols(num_ue_spec_dci+num_common_dci,dci_alloc,frame_parms,subframe);
-  //  printf("subframe %d in generate_dci_top num_pdcch_symbols = %d, num_dci %d\n",
-  //     subframe,num_pdcch_symbols,num_ue_spec_dci+num_common_dci);
+  num_pdcch_symbols = get_num_pdcch_symbols(num_dci,dci_alloc,frame_parms,subframe);
+
   generate_pcfich(num_pdcch_symbols,
                   amp,
                   frame_parms,
@@ -2118,15 +2116,15 @@ uint8_t generate_dci_top(uint8_t num_ue_spec_dci,
   // generate DCIs in order of decreasing aggregation level, then common/ue spec
   // MAC is assumed to have ordered the UE spec DCI according to the RNTI-based randomization
   for (L=3; L>=0; L--) {
-    for (i=0; i<num_common_dci; i++) {
+    for (i=0; i<num_dci; i++) {
 
       if (dci_alloc[i].L == (uint8_t)L) {
 
-#ifdef DEBUG_DCI_ENCODING
-        LOG_I(PHY,"Generating common DCI %d/%d (nCCE %d) of length %d, aggregation %d (%x)\n",i,num_common_dci,dci_alloc[i].firstCCE,dci_alloc[i].dci_length,1<<dci_alloc[i].L,
+	//#ifdef DEBUG_DCI_ENCODING
+        LOG_I(PHY,"Generating DCI %d/%d (nCCE %d) of length %d, aggregation %d (%x)\n",i,num_dci,dci_alloc[i].firstCCE,dci_alloc[i].dci_length,1<<dci_alloc[i].L,
               *(unsigned int*)dci_alloc[i].dci_pdu);
         dump_dci(frame_parms,&dci_alloc[i]);
-#endif
+	//#endif
 
         if (dci_alloc[i].firstCCE>=0) {
           e_ptr = generate_dci0(dci_alloc[i].dci_pdu,
@@ -2137,29 +2135,6 @@ uint8_t generate_dci_top(uint8_t num_ue_spec_dci,
         }
       }
     }
-
-    for (; i<num_ue_spec_dci + num_common_dci; i++) {
-
-      if (dci_alloc[i].L == (uint8_t)L) {
-
-#ifdef DEBUG_DCI_ENCODING
-        printf(" Generating UE (rnti %x) (nCCE %d) specific DCI %d of length %d, aggregation %d, format %d (%x)\n",dci_alloc[i].rnti,dci_alloc[i].firstCCE,i,dci_alloc[i].dci_length,1<<dci_alloc[i].L,dci_alloc[i].format,
-              dci_alloc[i].dci_pdu);
-        dump_dci(frame_parms,&dci_alloc[i]);
-#endif
-
-        if (dci_alloc[i].firstCCE >= 0) {
-          e_ptr = generate_dci0(dci_alloc[i].dci_pdu,
-                                e+(72*dci_alloc[i].firstCCE),
-                                dci_alloc[i].dci_length,
-                                dci_alloc[i].L,
-                                dci_alloc[i].rnti);
-        }
-	else {
-	  
-	}
-      }
-    }
   }
 
   // Scrambling
@@ -2367,84 +2342,6 @@ uint8_t generate_dci_top(uint8_t num_ue_spec_dci,
   return(num_pdcch_symbols);
 }
 
-#ifdef PHY_ABSTRACTION
-uint8_t generate_dci_top_emul(PHY_VARS_eNB *phy_vars_eNB,
-                              uint8_t num_ue_spec_dci,
-                              uint8_t num_common_dci,
-                              DCI_ALLOC_t *dci_alloc,
-                              uint8_t subframe)
-{
-  int n_dci, n_dci_dl;
-  uint8_t ue_id;
-  LTE_eNB_DLSCH_t *dlsch_eNB;
-  uint8_t num_pdcch_symbols = get_num_pdcch_symbols(num_ue_spec_dci+num_common_dci,
-                              dci_alloc,
-                              &phy_vars_eNB->frame_parms,
-                              subframe);
-  eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].cntl.cfi=num_pdcch_symbols;
-
-  memcpy(phy_vars_eNB->dci_alloc[subframe&1],dci_alloc,sizeof(DCI_ALLOC_t)*(num_ue_spec_dci+num_common_dci));
-  phy_vars_eNB->num_ue_spec_dci[subframe&1]=num_ue_spec_dci;
-  phy_vars_eNB->num_common_dci[subframe&1]=num_common_dci;
-  eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_ue_spec_dci = num_ue_spec_dci;
-  eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_common_dci = num_common_dci;
-
-  LOG_D(PHY,"[eNB %d][DCI][EMUL] CC id %d:  num spec dci %d num comm dci %d num PMCH %d \n",
-        phy_vars_eNB->Mod_id, phy_vars_eNB->CC_id, num_ue_spec_dci,num_common_dci,
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_pmch);
-
-  if (eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].cntl.pmch_flag == 1 )
-    n_dci_dl = eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_pmch;
-  else
-    n_dci_dl = 0;
-
-  for (n_dci =0 ;
-       n_dci < (eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_ue_spec_dci+ eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].num_common_dci);
-       n_dci++) {
-
-    if (dci_alloc[n_dci].format > 0) { // exclude the uplink dci
-
-      if (dci_alloc[n_dci].rnti == SI_RNTI) {
-        dlsch_eNB = RC.eNB[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]->dlsch_SI;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[n_dci_dl] = 0;//SI;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl] = 0;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl] = dlsch_eNB->harq_processes[0]->TBS>>3;
-        LOG_D(PHY,"[DCI][EMUL]SI tbs is %d and dci index %d harq pid is %d \n",eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl],n_dci_dl,
-              eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl]);
-      } else if (dci_alloc[n_dci_dl].ra_flag == 1) {
-        dlsch_eNB = RC.eNB[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]->dlsch_ra;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[n_dci_dl] = 1;//RA;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl] = 0;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl] = dlsch_eNB->harq_processes[0]->TBS>>3;
-        LOG_D(PHY,"[DCI][EMUL] RA  tbs is %d and dci index %d harq pid is %d \n",eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl],n_dci_dl,
-              eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl]);
-      } else {
-        ue_id = find_ue(dci_alloc[n_dci_dl].rnti,RC.eNB[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]);
-        DevAssert( ue_id != (uint8_t)-1 );
-        dlsch_eNB = RC.eNB[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]->dlsch[ue_id][0];
-
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[n_dci_dl] = 2;//TB0;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl] = dlsch_eNB->current_harq_pid;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].ue_id[n_dci_dl] = ue_id;
-        eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl] = dlsch_eNB->harq_processes[dlsch_eNB->current_harq_pid]->TBS>>3;
-        LOG_D(PHY,"[DCI][EMUL] TB1 tbs is %d and dci index %d harq pid is %d \n",eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].tbs[n_dci_dl],n_dci_dl,
-              eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].harq_pid[n_dci_dl]);
-        // check for TB1 later
-
-      }
-    }
-
-    n_dci_dl++;
-  }
-
-  memcpy((void *)&eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dci_alloc,
-         (void *)dci_alloc,
-         n_dci*sizeof(DCI_ALLOC_t));
-
-  return(num_pdcch_symbols);
-}
-#endif
-
 
 void dci_decoding(uint8_t DCI_LENGTH,
                   uint8_t aggregation_level,
@@ -2768,9 +2665,8 @@ void dci_decoding_procedure0(LTE_UE_PDCCH **pdcch_vars,
     else if (CCEind<96)
       CCEmap = CCEmap2;
     else {
-      LOG_E(PHY,"Illegal CCEind %d (Yk %d, m %d, nCCE %d, L2 %d\n",CCEind,Yk,m,nCCE,L2);
-      mac_xface->macphy_exit("Illegal CCEind\n");
-      return; // not reached
+      AssertFatal(1==0,
+		  "Illegal CCEind %d (Yk %d, m %d, nCCE %d, L2 %d\n",CCEind,Yk,m,nCCE,L2);
     }
 
     switch (L2) {
@@ -2791,9 +2687,8 @@ void dci_decoding_procedure0(LTE_UE_PDCCH **pdcch_vars,
       break;
 
     default:
-      LOG_E( PHY, "Illegal L2 value %d\n", L2 );
-      mac_xface->macphy_exit( "Illegal L2\n" );
-      return; // not reached
+      AssertFatal(1==0,
+		  "Illegal L2 value %d\n", L2 );
     }
 
     CCEmap_cand = (*CCEmap)&CCEmap_mask;
diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index d1ef5468f4266c37e30884ecca810f18fe341016..07a274523e4daa1fc0ba190060b52822078af2e5 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -29,6 +29,7 @@
  * \note
  * \warning
  */
+
 #include "PHY/defs.h"
 #include "PHY/extern.h"
 #include "SCHED/defs.h"
@@ -36,7 +37,7 @@
 #include "PHY/vars.h"
 #endif
 #include "assertions.h"
-
+#include "nfapi_interface.h"
 
 //#define DEBUG_HARQ
 
@@ -213,89 +214,28 @@ void conv_rballoc(uint8_t ra_header,uint32_t rb_alloc,uint32_t N_RB_DL,uint32_t
     break;
 
   case 50:
-    if (ra_header == 0) {// Type 0 Allocation
-
-      for (i=16; i>0; i--) {
-        if ((rb_alloc&(1<<i)) != 0)
-          rb_alloc2[(3*(16-i))>>5] |= (7<<((3*(16-i))%32));
-      }
-
-      /*
-      for (i=1;i<=16;i++) {
-        if ((rb_alloc&(1<<(16-i))) != 0)
-      rb_alloc2[(3*i)>>5] |= (7<<((3*i)%32));
-      }
-      */
-      // bit mask across
-      if ((rb_alloc2[0]>>31)==1)
-        rb_alloc2[1] |= 1;
-
-      if ((rb_alloc&1) != 0)
-        rb_alloc2[1] |= (3<<16);
-
-      /*
-        for (i=0;i<16;i++) {
-        if (((rb_alloc>>(16-i))&1) != 0)
-        rb_alloc2[(3*i)>>5] |= (7<<((3*i)%32));
-        if ((i==10)&&((rb_alloc&(1<<6))!=0))
-        rb_alloc2[1] = 1;
-        //  printf("rb_alloc2[%d] (type 0) %x ((%x>>%d)&1=%d)\n",(3*i)>>5,rb_alloc2[(3*i)>>5],rb_alloc,i,(rb_alloc>>i)&1);
+    AssertFatal(ra_header==0,"resource type 1 not supported for  N_RB_DL=50\n");
 
-        }
-        // fill in 2 from last bit instead of 3
-        if ((rb_alloc&1) != 0)
-        rb_alloc2[1] |= (3<<i);
-        //    printf("rb_alloc2[%d] (type 0) %x ((%x>>%d)&1=%d)\n",(3*i)>>5,rb_alloc2[(3*i)>>5],rb_alloc,i,(rb_alloc>>i)&1);
-        */
-      //      printf("rb_alloc[1]=%x,rb_alloc[0]=%x\n",rb_alloc2[1],rb_alloc2[0]);
-    } else {
-      LOG_E(PHY,"resource type 1 not supported for  N_RB_DL=50\n");
-      //      mac_xface->macphy_exit("resource type 1 not supported for  N_RB_DL=100\n");
-      /*
-      subset = rb_alloc&1;
-      shift  = (rb_alloc>>1)&1;
-      for (i=0;i<11;i++) {
-      if ((rb_alloc&(1<<(i+2))) != 0)
-      rb_alloc2 |= (1<<(2*i));
-      //      printf("rb_alloc2 (type 1) %x\n",rb_alloc2);
-      }
-      if ((shift == 0) && (subset == 1))
-      rb_alloc2<<=1;
-      else if ((shift == 1) && (subset == 0))
-      rb_alloc2<<=4;
-      else if ((shift == 1) && (subset == 1))
-      rb_alloc2<<=3;
-      */
+    for (i=16; i>0; i--) {
+      if ((rb_alloc&(1<<i)) != 0)
+	rb_alloc2[(3*(16-i))>>5] |= (7<<((3*(16-i))%32));
     }
 
+    // bit mask across
+    if ((rb_alloc2[0]>>31)==1)
+      rb_alloc2[1] |= 1;
+    
+    if ((rb_alloc&1) != 0)
+      rb_alloc2[1] |= (3<<16);
     break;
 
   case 100:
-    if (ra_header == 0) {// Type 0 Allocation
-      for (i=0; i<25; i++) {
-        if ((rb_alloc&(1<<(24-i))) != 0)
-          rb_alloc2[(4*i)>>5] |= (0xf<<((4*i)%32));
-
-        //  printf("rb_alloc2[%d] (type 0) %x (%d)\n",(4*i)>>5,rb_alloc2[(4*i)>>5],rb_alloc&(1<<i));
-      }
-    } else {
-      LOG_E(PHY,"resource type 1 not supported for  N_RB_DL=100\n");
-      //      mac_xface->macphy_exit("resource type 1 not supported for  N_RB_DL=100\n");
-      /*
-      subset = rb_alloc&1;
-      shift  = (rb_alloc>>1)&1;
-      for (i=0;i<11;i++) {
-      if ((rb_alloc&(1<<(i+2))) != 0)
-      rb_alloc2 |= (1<<(2*i));
-      //      printf("rb_alloc2 (type 1) %x\n",rb_alloc2);
-      }
-      if ((shift == 0) && (subset == 1))
-      rb_alloc2<<=1;
-      else if ((shift == 1) && (subset == 0))
-      rb_alloc2<<=4;
-      else if ((shift == 1) && (subset == 1))
-      rb_alloc2<<=3;
-      */
+    AssertFatal(ra_header==0,"resource type 1 not supported for  N_RB_DL=100\n");
+    for (i=0; i<25; i++) {
+      if ((rb_alloc&(1<<(24-i))) != 0)
+	rb_alloc2[(4*i)>>5] |= (0xf<<((4*i)%32));
+      
+      //  printf("rb_alloc2[%d] (type 0) %x (%d)\n",(4*i)>>5,rb_alloc2[(4*i)>>5],rb_alloc&(1<<i));
     }
 
     break;
@@ -771,90 +711,1247 @@ void generate_RIV_tables()
   allocdist3_0_odd |= (1<<(nVRB_odd_dist-96));
 
 
-      // Distributed Gap2, even slot
-      nVRB_even_dist = get_prb(100,0,nVRB,1);
-      if (nVRB_even_dist<32)
-        allocdist0_1_even |= (1<<nVRB_even_dist);
-      else if (nVRB_even_dist<64)
-        allocdist1_1_even |= (1<<(nVRB_even_dist-32));
-      else if (nVRB_even_dist<96)
-  allocdist2_1_even |= (1<<(nVRB_even_dist-64));
-      else
-  allocdist3_1_even |= (1<<(nVRB_even_dist-96));
+      // Distributed Gap2, even slot
+      nVRB_even_dist = get_prb(100,0,nVRB,1);
+      if (nVRB_even_dist<32)
+        allocdist0_1_even |= (1<<nVRB_even_dist);
+      else if (nVRB_even_dist<64)
+        allocdist1_1_even |= (1<<(nVRB_even_dist-32));
+      else if (nVRB_even_dist<96)
+  allocdist2_1_even |= (1<<(nVRB_even_dist-64));
+      else
+  allocdist3_1_even |= (1<<(nVRB_even_dist-96));
+
+
+      // Distributed Gap2, odd slot
+      nVRB_odd_dist = get_prb(100,1,nVRB,1);
+      if (nVRB_odd_dist<32)
+        allocdist0_1_odd |= (1<<nVRB_odd_dist);
+      else if (nVRB_odd_dist<64)
+        allocdist1_1_odd |= (1<<(nVRB_odd_dist-32));
+      else if (nVRB_odd_dist<96)
+  allocdist2_1_odd |= (1<<(nVRB_odd_dist-64));
+      else
+  allocdist3_1_odd |= (1<<(nVRB_odd_dist-96));
+
+
+      RIV=computeRIV(100,RBstart,Lcrbs);
+
+      if (RIV>RIV_max100)
+        RIV_max100 = RIV;
+
+      //      printf("RIV %d : first_rb %d NBRB %d\n",RIV,RBstart,Lcrbs);
+      localRIV2alloc_LUT100_0[RIV] = alloc0;
+      localRIV2alloc_LUT100_1[RIV] = alloc1;
+      localRIV2alloc_LUT100_2[RIV] = alloc2;
+      localRIV2alloc_LUT100_3[RIV] = alloc3;
+      distRIV2alloc_gap0_even_LUT100_0[RIV]  = allocdist0_0_even;
+      distRIV2alloc_gap0_even_LUT100_1[RIV]  = allocdist1_0_even;
+      distRIV2alloc_gap0_even_LUT100_2[RIV]  = allocdist2_0_even;
+      distRIV2alloc_gap0_even_LUT100_3[RIV]  = allocdist3_0_even;
+      distRIV2alloc_gap0_odd_LUT100_0[RIV]   = allocdist0_0_odd;
+      distRIV2alloc_gap0_odd_LUT100_1[RIV]   = allocdist1_0_odd;
+      distRIV2alloc_gap0_odd_LUT100_2[RIV]   = allocdist2_0_odd;
+      distRIV2alloc_gap0_odd_LUT100_3[RIV]   = allocdist3_0_odd;
+      distRIV2alloc_gap1_even_LUT100_0[RIV]  = allocdist0_1_even;
+      distRIV2alloc_gap1_even_LUT100_1[RIV]  = allocdist1_1_even;
+      distRIV2alloc_gap1_even_LUT100_2[RIV]  = allocdist2_1_even;
+      distRIV2alloc_gap1_even_LUT100_3[RIV]  = allocdist3_1_even;
+      distRIV2alloc_gap1_odd_LUT100_0[RIV]   = allocdist0_1_odd;
+      distRIV2alloc_gap1_odd_LUT100_1[RIV]   = allocdist1_1_odd;
+      distRIV2alloc_gap1_odd_LUT100_2[RIV]   = allocdist2_1_odd;
+      distRIV2alloc_gap1_odd_LUT100_3[RIV]   = allocdist3_1_odd;
+
+      RIV2nb_rb_LUT100[RIV]      = Lcrbs;
+      RIV2first_rb_LUT100[RIV]   = RBstart;
+    }
+  }
+}
+
+// Ngap = 3, N_VRB_DL=6, P=1, N_row=2, N_null=4*2-6=2
+// permutation for even slots :
+//    n_PRB'(0,2,4) = (0,1,2), n_PRB'(1,3,5) = (4,5,6)
+//    n_PRB''(0,1,2,3) = (0,2,4,6)
+//    => n_tilde_PRB(5) = (4)
+//       n_tilde_PRB(4) = (1)
+//       n_tilde_PRB(2,3) = (3,5)
+//       n_tilde_PRB(0,1) = (0,2)
+
+
+int8_t find_dlsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type)
+{
+  uint8_t i;
+  int8_t first_free_index=-1;
+
+  AssertFatal(eNB!=NULL,"eNB is null\n");
+  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
+    AssertFatal(eNB->dlsch[i]!=NULL,"eNB->dlsch[%d] is null\n",i);
+    AssertFatal(eNB->dlsch[i]!=NULL,"eNB->dlsch[%d][0] is null\n",i);
+    LOG_D(PHY,"searching for rnti %x : UE index %d=> harq_mask %x, rnti %x, first_free_index %d\n",
+	  rnti,i,eNB->dlsch[i][0]->harq_mask,eNB->dlsch[i][0]->rnti,first_free_index);
+    if ((eNB->dlsch[i][0]->harq_mask >0) &&
+	(eNB->dlsch[i][0]->rnti==rnti))       return(i); 
+    else if ((eNB->dlsch[i][0]->harq_mask == 0) && (first_free_index==-1)) first_free_index=i;
+  }
+  if (type == SEARCH_EXIST) return(-1);
+  else return(first_free_index);
+}
+
+int8_t find_ulsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type)
+{
+  uint8_t i;
+  int8_t first_free_index=-1;
+
+  AssertFatal(eNB==NULL,"eNB is null\n");
+  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
+    AssertFatal(eNB->ulsch[i]==NULL,"eNB->dlsch[%d] is null\n",i);
+    if ((eNB->ulsch[i]->harq_mask >0) &&
+	(eNB->ulsch[i]->rnti==rnti))       return(i); 
+    else if ((eNB->ulsch[i]->harq_mask == 0) && (first_free_index==-1)) first_free_index=i;
+  }
+  if (type == SEARCH_EXIST) return(-1);
+  else return(first_free_index);
+}
+
+
+uint32_t get_rballoc(vrb_t vrb_type,uint16_t rb_alloc_dci)
+{
+
+  return(localRIV2alloc_LUT25[rb_alloc_dci]);
+
+}
+
+/*
+uint8_t get_transmission_mode(module_id_t Mod_id, uint8_t CC_id, rnti_t rnti)
+{
+  unsigned char UE_id;
+
+  // find the UE_index corresponding to rnti
+  UE_id = find_ue(rnti,RC.eNB[Mod_id][CC_id]);
+  DevAssert( UE_id != (unsigned char)-1 );
+
+  return(RC.eNB[Mod_id][CC_id]->transmission_mode[UE_id]);
+}
+*/
+
+int fill_dci_and_dlsch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,nfapi_dl_config_dci_dl_pdu *pdu) {
+
+  LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
+
+  uint8_t *dci_pdu = &dci_alloc->dci_pdu[0];
+  nfapi_dl_config_dci_dl_pdu_rel8_t *rel8 = &pdu->dci_dl_pdu_rel8;
+  int harq_pid;
+  LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
+  LTE_DL_eNB_HARQ_t *dlsch0_harq=NULL,*dlsch1_harq=NULL;
+  int beamforming_mode = 0;
+  int UE_id=-1;
+  int subframe = proc->subframe_tx;
+  int RIV_max;
+  int NPRB;
+  int TB0_active;
+  int TB1_active;
+  uint16_t DL_pmi_single=0; // This should be taken from DLSCH parameters for PUSCH precoding
+  uint8_t I_mcs = 0;
+  
+  dci_alloc->firstCCE = rel8->cce_idx;
+  dci_alloc->L        = rel8->aggregation_level;
+  dci_alloc->rnti     = rel8->rnti;
+  dci_alloc->harq_pid = rel8->harq_process;
+  dci_alloc->ra_flag  = 0;
+
+  LOG_I(PHY,"NFAPI: DCI format %d, nCCE %d, L %d, rnti %x,harq_pid %d\n",
+	rel8->dci_format,rel8->cce_idx,rel8->aggregation_level,rel8->rnti,rel8->harq_process);
+  if ((rel8->rnti_type == 2 ) && (rel8->rnti != SI_RNTI) && (rel8->rnti != P_RNTI)) dci_alloc->ra_flag = 1;
+
+  UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
+  AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
+  AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
+  dlsch0 = eNB->dlsch[UE_id][0];
+  dlsch1 = eNB->dlsch[UE_id][1];
+  
+  beamforming_mode                          = eNB->transmission_mode[(uint8_t)UE_id]<7?0:eNB->transmission_mode[(uint8_t)UE_id];
+  dlsch0_harq                               = dlsch0->harq_processes[rel8->harq_process];
+  dlsch0_harq->codeword                     = 0;
+  dlsch1_harq                               = dlsch1->harq_processes[rel8->harq_process];
+  dlsch1_harq->codeword                     = 1;
+  dlsch0->subframe_tx[subframe]             = 1;  
+
+  switch (rel8->dci_format) {
+
+  case NFAPI_DL_DCI_FORMAT_1A:
+    dci_alloc->format     = format1A;
+    dlsch0->active       = 1;
+
+    switch (fp->N_RB_DL) {
+    case 6:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                         = sizeof_DCI1A_1_5MHz_TDD_1_6_t; 
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->type     = 1;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->mcs      = rel8->mcs_1;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->ndi      = rel8->new_data_indicator_1;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->rv       = rel8->redundancy_version_1;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->harq_pid = rel8->harq_process;
+        ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;
+	
+      } else {
+	dci_alloc->dci_length                         = sizeof_DCI1A_1_5MHz_FDD_t; 
+	((DCI1A_1_5MHz_FDD_t *)dci_pdu)->type         = 1;
+        ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->vrb_type     = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->mcs          = rel8->mcs_1;
+        ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->ndi          = rel8->new_data_indicator_1;
+        ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->rballoc      = rel8->resource_block_coding;
+        ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->rv           = rel8->redundancy_version_1;
+        ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->TPC          = rel8->tpc;
+        ((DCI1A_1_5MHz_FDD_t *)dci_pdu)->harq_pid     = rel8->harq_process;
+        //      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+
+      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT6[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type           =  rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb          = RIV2nb_rb_LUT6[rel8->resource_block_coding];//NPRB;
+      RIV_max = RIV_max6;
+      break;
+    case 25:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                         = sizeof_DCI1A_5MHz_TDD_1_6_t; 
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->type       = 1;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type   = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->mcs        = rel8->mcs_1;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->ndi        = rel8->new_data_indicator_1;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->rballoc    = rel8->resource_block_coding;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->rv         = rel8->redundancy_version_1;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->TPC        = rel8->tpc;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->harq_pid   = rel8->harq_process;
+        ((DCI1A_5MHz_TDD_1_6_t *)dci_pdu)->dai      = rel8->downlink_assignment_index; 	
+         //        printf("TDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                         = sizeof_DCI1A_5MHz_FDD_t; 
+	((DCI1A_5MHz_FDD_t *)dci_pdu)->type           = 1;
+        ((DCI1A_5MHz_FDD_t *)dci_pdu)->vrb_type       = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_5MHz_FDD_t *)dci_pdu)->mcs            = rel8->mcs_1;
+        ((DCI1A_5MHz_FDD_t *)dci_pdu)->ndi            = rel8->new_data_indicator_1;
+        ((DCI1A_5MHz_FDD_t *)dci_pdu)->rballoc        = rel8->resource_block_coding;
+        ((DCI1A_5MHz_FDD_t *)dci_pdu)->rv             = rel8->redundancy_version_1;
+        ((DCI1A_5MHz_FDD_t *)dci_pdu)->TPC            = rel8->tpc;
+        ((DCI1A_5MHz_FDD_t *)dci_pdu)->harq_pid       = rel8->harq_process;
+        //      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT25[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type           =  rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb          = RIV2nb_rb_LUT25[rel8->resource_block_coding];//NPRB;
+      RIV_max                     = RIV_max25;
+      break;
+    case 50:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                         = sizeof_DCI1A_10MHz_TDD_1_6_t; 
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->type      = 1;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->vrb_type  = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->mcs       = rel8->mcs_1;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->ndi       = rel8->new_data_indicator_1;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->rv        = rel8->redundancy_version_1;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+        ((DCI1A_10MHz_TDD_1_6_t *)dci_pdu)->dai       = rel8->downlink_assignment_index;	
+        //        printf("TDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                         = sizeof_DCI1A_20MHz_FDD_t; 
+	((DCI1A_10MHz_FDD_t *)dci_pdu)->type          = 1;
+        ((DCI1A_10MHz_FDD_t *)dci_pdu)->vrb_type      = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_10MHz_FDD_t *)dci_pdu)->mcs           = rel8->mcs_1;
+        ((DCI1A_10MHz_FDD_t *)dci_pdu)->ndi           = rel8->new_data_indicator_1;
+        ((DCI1A_10MHz_FDD_t *)dci_pdu)->rballoc       = rel8->resource_block_coding;
+        ((DCI1A_10MHz_FDD_t *)dci_pdu)->rv            = rel8->redundancy_version_1;
+        ((DCI1A_10MHz_FDD_t *)dci_pdu)->TPC           = rel8->tpc;
+        ((DCI1A_10MHz_FDD_t *)dci_pdu)->harq_pid      = rel8->harq_process;
+	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]     = localRIV2alloc_LUT50_0[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[1]     = localRIV2alloc_LUT50_1[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type           =  rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb              = RIV2nb_rb_LUT50[rel8->resource_block_coding];//NPRB;
+      RIV_max = RIV_max50;
+      break;
+    case 100:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                         = sizeof_DCI1A_20MHz_TDD_1_6_t; 
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->type      = 1;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->vrb_type  = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->mcs       = rel8->mcs_1;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->ndi       = rel8->new_data_indicator_1;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->rv        = rel8->redundancy_version_1;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+        ((DCI1A_20MHz_TDD_1_6_t *)dci_pdu)->dai       = rel8->downlink_assignment_index;	
+        //        printf("TDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                         = sizeof_DCI1A_20MHz_FDD_t; 
+	((DCI1A_20MHz_FDD_t *)dci_pdu)->type          = 1;
+        ((DCI1A_20MHz_FDD_t *)dci_pdu)->vrb_type      = rel8->virtual_resource_block_assignment_flag;
+        ((DCI1A_20MHz_FDD_t *)dci_pdu)->mcs           = rel8->mcs_1;
+        ((DCI1A_20MHz_FDD_t *)dci_pdu)->ndi           = rel8->new_data_indicator_1;
+        ((DCI1A_20MHz_FDD_t *)dci_pdu)->rballoc       = rel8->resource_block_coding;
+        ((DCI1A_20MHz_FDD_t *)dci_pdu)->rv            = rel8->redundancy_version_1;
+        ((DCI1A_20MHz_FDD_t *)dci_pdu)->TPC           = rel8->tpc;
+        ((DCI1A_20MHz_FDD_t *)dci_pdu)->harq_pid      = rel8->harq_process;
+	//      printf("FDD 1A: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      AssertFatal(rel8->virtual_resource_block_assignment_flag==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT100_0[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT100_1[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[2]      = localRIV2alloc_LUT100_2[rel8->resource_block_coding];
+      dlsch0_harq->rb_alloc[3]      = localRIV2alloc_LUT100_3[rel8->resource_block_coding];
+      dlsch0_harq->vrb_type         =  rel8->virtual_resource_block_assignment_flag;
+      dlsch0_harq->nb_rb            = RIV2nb_rb_LUT100[rel8->resource_block_coding];//NPRB;
+      RIV_max = RIV_max100;
+      break;
+    }
+
+    if (rel8->rnti_type == 2 ) {
+      // see 36-212 V8.6.0 p. 45
+      NPRB      = (rel8->tpc&1)+2;
+      // 36-213 sec.7.1.7.2 p.26
+      I_mcs     = rel8->mcs_1;
+    }
+    else {
+      NPRB      = dlsch0_harq->nb_rb;
+      I_mcs     = get_I_TBS(rel8->mcs_1);
+    }
+    AssertFatal(NPRB>0,"DCI 1A: NPRB == 0\n");
+    dlsch0_harq->rvidx         = rel8->redundancy_version_1;
+    dlsch0_harq->Nl            = 1;
+    dlsch0_harq->mimo_mode     = (fp->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
+    dlsch0_harq->dl_power_off  = 1;
+    
+    
+
+    dlsch0_harq->mcs             = rel8->mcs_1;
+    dlsch0_harq->TBS             = TBStable[I_mcs][NPRB-1];
+    dlsch0->harq_ids[subframe]   = rel8->harq_process;
+    dlsch0->active               = 1;
+    dlsch0->rnti                 = rel8->rnti;
+    dlsch0->harq_ids[subframe]   = rel8->harq_process;
+    if (dlsch0_harq->round == 0)
+      dlsch0_harq->status = ACTIVE;
+
+    LOG_I(PHY,"DCI 1A: mcs %d, rballoc %x,rv %d, rnti %x\n",rel8->mcs_1,rel8->resource_block_coding,rel8->redundancy_version_1,rel8->rnti);
+
+    break;
+  case NFAPI_DL_DCI_FORMAT_1:
+
+    dci_alloc->format           = format1;
+    dlsch0->active              = 1;
+
+    switch (fp->N_RB_DL) {
+    case 6:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                     = sizeof_DCI1_1_5MHz_TDD_t; 
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->mcs       = rel8->mcs_1;
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->ndi       = rel8->new_data_indicator_1;
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->rv        = rel8->redundancy_version_1;
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+        ((DCI1_1_5MHz_TDD_t *)dci_pdu)->dai       = rel8->downlink_assignment_index; 	
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                         = sizeof_DCI1_1_5MHz_FDD_t; 
+        ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rah           = rel8->resource_allocation_type;
+        ((DCI1_1_5MHz_FDD_t *)dci_pdu)->mcs           = rel8->mcs_1;
+        ((DCI1_1_5MHz_FDD_t *)dci_pdu)->ndi       = rel8->new_data_indicator_1;
+        ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rballoc       = rel8->resource_block_coding;
+        ((DCI1_1_5MHz_FDD_t *)dci_pdu)->rv            = rel8->redundancy_version_1;
+        ((DCI1_1_5MHz_FDD_t *)dci_pdu)->TPC           = rel8->tpc;
+        ((DCI1_1_5MHz_FDD_t *)dci_pdu)->harq_pid      = rel8->harq_process;
+        //      printf("FDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      break;
+    case 25:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                      = sizeof_DCI1_5MHz_TDD_t; 
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->ndi      = rel8->new_data_indicator_1;
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->rv       = rel8->redundancy_version_1;
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+        ((DCI1_5MHz_TDD_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;	
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                  = sizeof_DCI1_5MHz_FDD_t; 
+        ((DCI1_5MHz_FDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI1_5MHz_FDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
+        ((DCI1_5MHz_FDD_t *)dci_pdu)->ndi      = rel8->new_data_indicator_1;
+        ((DCI1_5MHz_FDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI1_5MHz_FDD_t *)dci_pdu)->rv       = rel8->redundancy_version_1;
+        ((DCI1_5MHz_FDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI1_5MHz_FDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+        //      printf("FDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      break;
+    case 50:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                       = sizeof_DCI1_10MHz_TDD_t; 
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->ndi      = rel8->new_data_indicator_1;
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->rv       = rel8->redundancy_version_1;
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+        ((DCI1_10MHz_TDD_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;	
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                   = sizeof_DCI1_10MHz_FDD_t; 
+        ((DCI1_10MHz_FDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI1_10MHz_FDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
+        ((DCI1_10MHz_FDD_t *)dci_pdu)->ndi      = rel8->new_data_indicator_1;
+        ((DCI1_10MHz_FDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI1_10MHz_FDD_t *)dci_pdu)->rv       = rel8->redundancy_version_1;
+        ((DCI1_10MHz_FDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI1_10MHz_FDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+      }
+      break;
+    case 100:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                       = sizeof_DCI1_20MHz_TDD_t; 
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->ndi      = rel8->new_data_indicator_1;
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->rv       = rel8->redundancy_version_1;
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+        ((DCI1_20MHz_TDD_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;	
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                   = sizeof_DCI1_20MHz_FDD_t; 
+        ((DCI1_20MHz_FDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI1_20MHz_FDD_t *)dci_pdu)->mcs      = rel8->mcs_1;
+        ((DCI1_20MHz_FDD_t *)dci_pdu)->ndi      = rel8->new_data_indicator_1;
+        ((DCI1_20MHz_FDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI1_20MHz_FDD_t *)dci_pdu)->rv       = rel8->redundancy_version_1;
+        ((DCI1_20MHz_FDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI1_20MHz_FDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+      }
+      break;
+    }
+
+    if (rel8->harq_process>=8) {
+      LOG_E(PHY,"ERROR: Format 1: harq_pid=%d >= 8\n", rel8->harq_process);
+      return(-1);
+    }
+
+    dlsch0_harq = dlsch0->harq_processes[rel8->harq_process];
+    dlsch0_harq->codeword=0;
+
+    // printf("DCI: Setting subframe_tx for subframe %d\n",subframe);
+    dlsch0->subframe_tx[subframe] = 1;
+
+    conv_rballoc(rel8->resource_allocation_type,
+                 rel8->resource_block_coding,
+		 fp->N_RB_DL,
+                 dlsch0_harq->rb_alloc);
+
+    dlsch0_harq->nb_rb = conv_nprb(rel8->resource_allocation_type,
+                                   rel8->resource_block_coding,
+                                   fp->N_RB_DL);
+
+    NPRB      = dlsch0_harq->nb_rb;
+
+
+    if (NPRB==0)
+      return(-1);
+
+
+    dlsch0_harq->rvidx       = rel8->redundancy_version_1;
+
+    dlsch0_harq->Nl          = 1;
+    //    dlsch[0]->layer_index = 0;
+    if (beamforming_mode == 0)
+      dlsch0_harq->mimo_mode = (fp->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
+    else if (beamforming_mode == 7)
+      dlsch0_harq->mimo_mode = TM7;
+    else
+      LOG_E(PHY,"Invalid beamforming mode %dL\n", beamforming_mode);
+
+    dlsch0_harq->dl_power_off = 1;
+
+    dlsch0->active = 1;
+
+
+
+    if (dlsch0_harq->round == 0) {
+      dlsch0_harq->status = ACTIVE;
+      //            printf("Setting DLSCH process %d to ACTIVE\n",rel8->harq_process);
+      // MCS and TBS don't change across HARQ rounds
+      dlsch0_harq->mcs         = rel8->mcs_1;
+      dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][NPRB-1];
+
+    }
+
+    dlsch0->harq_ids[subframe] = rel8->harq_process;
+
+
+
+    dlsch0->rnti = rel8->rnti;
+
+
+    break;
+  case NFAPI_DL_DCI_FORMAT_2A:
+
+    dci_alloc->format     = format2A;
+    switch (fp->N_RB_DL) {
+    case 6:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                         = sizeof_DCI2A_1_5MHz_2A_TDD_t; 
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->mcs1     = rel8->mcs_1;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->mcs2     = rel8->mcs_2;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->ndi1     = rel8->new_data_indicator_1;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->ndi2     = rel8->new_data_indicator_2;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->rv1      = rel8->redundancy_version_1;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->rv2      = rel8->redundancy_version_2;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+	((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->tb_swap  = rel8->transport_block_to_codeword_swap_flag;
+        ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                         = sizeof_DCI2A_1_5MHz_2A_FDD_t; 
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->rah          = rel8->resource_allocation_type;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->mcs1         = rel8->mcs_1;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->mcs2         = rel8->mcs_2;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->ndi1         = rel8->new_data_indicator_1;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->ndi2         = rel8->new_data_indicator_2;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->rballoc      = rel8->resource_block_coding;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->rv1          = rel8->redundancy_version_1;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->rv2          = rel8->redundancy_version_2;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->TPC          = rel8->tpc;
+        ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->harq_pid     = rel8->harq_process;
+	((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->tb_swap      = rel8->transport_block_to_codeword_swap_flag;
+        //      printf("FDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      break;
+    case 25:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                        = sizeof_DCI2A_5MHz_2A_TDD_t; 
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->mcs1      = rel8->mcs_1;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->mcs2      = rel8->mcs_2;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->ndi1      = rel8->new_data_indicator_1;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->ndi2      = rel8->new_data_indicator_2;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->rv1       = rel8->redundancy_version_1;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->rv2       = rel8->redundancy_version_2;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+	((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->tb_swap   = rel8->transport_block_to_codeword_swap_flag;	
+        ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->dai       = rel8->downlink_assignment_index;	
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                           = sizeof_DCI2A_5MHz_2A_FDD_t; 
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->rah           = rel8->resource_allocation_type;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->mcs1          = rel8->mcs_1;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->mcs2          = rel8->mcs_2;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->ndi1          = rel8->new_data_indicator_1;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->ndi2          = rel8->new_data_indicator_2;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->rballoc       = rel8->resource_block_coding;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->rv1           = rel8->redundancy_version_1;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->rv2           = rel8->redundancy_version_2;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->TPC           = rel8->tpc;
+        ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->harq_pid      = rel8->harq_process;
+	((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->tb_swap       = rel8->transport_block_to_codeword_swap_flag;	
+        //      printf("FDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      break;
+    case 50:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                        = sizeof_DCI2A_10MHz_2A_TDD_t; 
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->mcs1     = rel8->mcs_1;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->mcs2     = rel8->mcs_2;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->ndi1     = rel8->new_data_indicator_1;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->ndi2     = rel8->new_data_indicator_2;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->rv1      = rel8->redundancy_version_1;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->rv2      = rel8->redundancy_version_2;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+	((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->tb_swap  = rel8->transport_block_to_codeword_swap_flag;	
+        ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;	
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                        = sizeof_DCI2A_10MHz_2A_FDD_t; 
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->mcs1      = rel8->mcs_1;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->mcs2      = rel8->mcs_2;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->ndi1      = rel8->new_data_indicator_1;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->ndi2      = rel8->new_data_indicator_2;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->rv1       = rel8->redundancy_version_1;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->rv2       = rel8->redundancy_version_2;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+	((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->tb_swap   = rel8->transport_block_to_codeword_swap_flag;	
+      }
+      break;
+    case 100:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                        = sizeof_DCI2A_20MHz_2A_TDD_t; 
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->mcs1      = rel8->mcs_1;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->mcs2      = rel8->mcs_2;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->ndi1      = rel8->new_data_indicator_1;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->ndi2      = rel8->new_data_indicator_2;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->rv1       = rel8->redundancy_version_1;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->rv2       = rel8->redundancy_version_2;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+	((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->tb_swap   = rel8->transport_block_to_codeword_swap_flag;		
+        ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->dai       = rel8->downlink_assignment_index;	
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                           = sizeof_DCI2A_20MHz_2A_FDD_t; 
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->rah          = rel8->resource_allocation_type;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->mcs1         = rel8->mcs_1;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->mcs2         = rel8->mcs_2;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->ndi1         = rel8->new_data_indicator_1;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->ndi2         = rel8->new_data_indicator_2;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->rballoc      = rel8->resource_block_coding;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->rv1          = rel8->redundancy_version_1;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->rv2          = rel8->redundancy_version_2;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->TPC          = rel8->tpc;
+        ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->harq_pid     = rel8->harq_process;
+	((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->tb_swap      = rel8->transport_block_to_codeword_swap_flag;	
+      }
+      break;
+
+    }
+    if (rel8->harq_process>=8) {
+      LOG_E(PHY,"ERROR: Format 2_2A: harq_pid=%d >= 8\n", rel8->harq_process);
+      return(-1);
+    }
+
+
+    // Flip the TB to codeword mapping as described in 5.3.3.1.5 of 36-212 V11.3.0
+    // note that we must set tbswap=0 in eNB scheduler if one TB is deactivated
+    // This must be set as in TM4, does not work properly now.
+    if (rel8->transport_block_to_codeword_swap_flag == 1) {
+      dlsch0 = eNB->dlsch[UE_id][1];
+      dlsch1 = eNB->dlsch[UE_id][0];
+    }
+
+    dlsch0_harq = dlsch0->harq_processes[rel8->harq_process];
+    dlsch1_harq = dlsch1->harq_processes[rel8->harq_process];
+
+    dlsch0->subframe_tx[subframe] = 1;
+
+    dlsch0->harq_ids[subframe] = rel8->harq_process;
+    dlsch1->harq_ids[subframe] = rel8->harq_process;
+    //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);
+
+
+    conv_rballoc(rel8->resource_allocation_type,
+                 rel8->resource_block_coding,
+                 fp->N_RB_DL,
+                 dlsch0_harq->rb_alloc);
+
+    dlsch1_harq->rb_alloc[0]                         = dlsch0_harq->rb_alloc[0];
+    dlsch0_harq->nb_rb                               = conv_nprb(rel8->resource_allocation_type,
+								 rel8->resource_block_coding,
+								 fp->N_RB_DL);
+    dlsch1_harq->nb_rb                               = dlsch0_harq->nb_rb;
+
+    if (dlsch0_harq->nb_rb == 0)
+      return(-1);
+
+    dlsch0_harq->mcs       = rel8->mcs_1;
+    dlsch1_harq->mcs       = rel8->mcs_2;
+    dlsch0_harq->rvidx     = rel8->redundancy_version_1;
+    dlsch1_harq->rvidx     = rel8->redundancy_version_2;
+
+    // assume both TBs are active
+    dlsch0_harq->Nl        = 1;
+    dlsch1_harq->Nl        = 1;
+    dlsch0->active = 1;
+    dlsch1->active = 1;
+
+
+    // check if either TB is disabled (see 36-213 V11.3 Section )
+    if ((dlsch0_harq->rvidx == 1) && (dlsch0_harq->mcs == 0)) {
+      dlsch0->active = 0;
+    }
+
+    if ((dlsch1_harq->rvidx == 1) && (dlsch1_harq->mcs == 0)) {
+      dlsch1->active = 0;
+    }
+
+   // dlsch0_harq->dl_power_off = 0;
+   // dlsch1_harq->dl_power_off = 0;
+
+
+    if (fp->nb_antenna_ports_eNB == 2) {
+      dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+      dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch0_harq->nb_rb-1];
+
+      if ((dlsch0->active==1) && (dlsch1->active==1)) {
+
+        dlsch0_harq->mimo_mode = LARGE_CDD;
+        dlsch1_harq->mimo_mode = LARGE_CDD;
+        dlsch0_harq->dl_power_off = 1;
+        dlsch1_harq->dl_power_off = 1;
+      } else {
+        dlsch0_harq->mimo_mode   = ALAMOUTI;
+        dlsch1_harq->mimo_mode   = ALAMOUTI;
+      }
+    } else if (fp->nb_antenna_ports_eNB == 4) { // 4 antenna case
+      if ((dlsch0->active==1) && (dlsch1->active==1)) {
+        switch (rel8->precoding_information) {
+        case 0: // one layer per transport block
+          dlsch0_harq->mimo_mode   = LARGE_CDD;
+          dlsch1_harq->mimo_mode   = LARGE_CDD;
+          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+          dlsch0_harq->dl_power_off = 1;
+          dlsch1_harq->dl_power_off = 1;
+          break;
+
+        case 1: // one-layers on TB 0, two on TB 1
+          dlsch0_harq->mimo_mode   = LARGE_CDD;
+          dlsch1_harq->mimo_mode   = LARGE_CDD;
+          dlsch1_harq->Nl          = 2;
+          dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][(dlsch1_harq->nb_rb<<1)-1];
+          dlsch0_harq->dl_power_off = 1;
+          dlsch1_harq->dl_power_off = 1;
+          break;
+
+        case 2: // two-layers on TB 0, two on TB 1
+          dlsch0_harq->mimo_mode   = LARGE_CDD;
+          dlsch1_harq->mimo_mode   = LARGE_CDD;
+          dlsch0_harq->Nl          = 2;
+          dlsch0_harq->dl_power_off = 1;
+          dlsch1_harq->dl_power_off = 1;
+
+          if (fp->N_RB_DL <= 56) {
+            dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][(dlsch0_harq->nb_rb<<1)-1];
+            dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][(dlsch1_harq->nb_rb<<1)-1];
+          } else {
+            LOG_E(PHY,"Add implementation of Table 7.1.7.2.2-1 for two-layer TBS conversion with N_RB_DL > 56\n");
+          }
+
+          break;
+
+        case 3: //
+          LOG_E(PHY,"Illegal value (3) for TPMI in Format 2A DCI\n");
+          break;
+        }
+      } else if (dlsch0->active == 1) {
+        switch (rel8->precoding_information) {
+        case 0: // one layer per transport block
+          dlsch0_harq->mimo_mode   = ALAMOUTI;
+          dlsch1_harq->mimo_mode   = ALAMOUTI;
+          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+          break;
+
+        case 1: // two-layers on TB 0
+          dlsch0_harq->mimo_mode   = LARGE_CDD;
+          dlsch0_harq->Nl          = 2;
+          dlsch0_harq->dl_power_off = 1;
+          dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][(dlsch0_harq->nb_rb<<1)-1];
+          break;
+
+        case 2: // two-layers on TB 0, two on TB 1
+        case 3: //
+          LOG_E(PHY,"Illegal value %d for TPMI in Format 2A DCI with one transport block enabled\n",rel8->precoding_information);
+          break;
+        }
+      } else if (dlsch1->active == 1) {
+        switch (rel8->precoding_information) {
+        case 0: // one layer per transport block
+          dlsch0_harq->mimo_mode   = ALAMOUTI;
+          dlsch1_harq->mimo_mode   = ALAMOUTI;
+          dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch1_harq->nb_rb-1];
+          break;
+
+        case 1: // two-layers on TB 0
+          dlsch1_harq->mimo_mode   = LARGE_CDD;
+          dlsch1_harq->Nl          = 2;
+          dlsch1_harq->dl_power_off = 1;
+          dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][(dlsch1_harq->nb_rb<<1)-1];
+          break;
+
+        case 2: // two-layers on TB 0, two on TB 1
+        case 3: //
+          LOG_E(PHY,"Illegal value %d for TPMI in Format 2A DCI with one transport block enabled\n",rel8->precoding_information);
+          break;
+        }
+      }
+    } else {
+      LOG_E(PHY,"Illegal number of antennas for eNB %d\n",fp->nb_antenna_ports_eNB);
+    }
+
+    // reset HARQ process if this is the first transmission
+    if ((dlsch0->active==1) && (dlsch0_harq->round == 0))
+      dlsch0_harq->status = ACTIVE;
+
+    if ((dlsch1->active==1) && (dlsch1_harq->round == 0))
+      dlsch1_harq->status = ACTIVE;
+
+    dlsch0->rnti = rel8->rnti;
+    dlsch1->rnti = rel8->rnti;
+
+
+    break;
+      
+  case NFAPI_DL_DCI_FORMAT_2:
+
+    dci_alloc->format     = format2;
+    switch (fp->N_RB_DL) {
+    case 6:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                       = sizeof_DCI2_1_5MHz_2A_TDD_t; 
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs1     = rel8->mcs_1;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs2     = rel8->mcs_2;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->ndi1     = rel8->new_data_indicator_1;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->ndi2     = rel8->new_data_indicator_2;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rv1      = rel8->redundancy_version_1;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->rv2      = rel8->redundancy_version_2;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+	((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->tb_swap  = rel8->transport_block_to_codeword_swap_flag;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;
+        ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->tpmi     = rel8->precoding_information;
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                         = sizeof_DCI2_1_5MHz_2A_FDD_t; 
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->mcs1         = rel8->mcs_1;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->mcs2         = rel8->mcs_2;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->ndi1         = rel8->new_data_indicator_1;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->ndi2         = rel8->new_data_indicator_2;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rballoc      = rel8->resource_block_coding;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rv1          = rel8->redundancy_version_1;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->rv2          = rel8->redundancy_version_2;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->TPC          = rel8->tpc;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->harq_pid     = rel8->harq_process;
+	((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tb_swap      = rel8->transport_block_to_codeword_swap_flag;
+        ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tpmi         = rel8->precoding_information;
+        //      printf("FDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      break;
+    case 25:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                        = sizeof_DCI2_5MHz_2A_TDD_t; 
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs1      = rel8->mcs_1;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs2      = rel8->mcs_2;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->ndi1      = rel8->new_data_indicator_1;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->ndi2      = rel8->new_data_indicator_2;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rv1       = rel8->redundancy_version_1;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->rv2       = rel8->redundancy_version_2;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+	((DCI2_5MHz_2A_TDD_t *)dci_pdu)->tb_swap   = rel8->transport_block_to_codeword_swap_flag;	
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->dai       = rel8->downlink_assignment_index;	
+        ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->tpmi      = rel8->precoding_information;
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                           = sizeof_DCI2_5MHz_2A_FDD_t; 
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rah           = rel8->resource_allocation_type;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->mcs1          = rel8->mcs_1;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->mcs2          = rel8->mcs_2;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->ndi1          = rel8->new_data_indicator_1;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->ndi2          = rel8->new_data_indicator_2;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rballoc       = rel8->resource_block_coding;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rv1           = rel8->redundancy_version_1;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->rv2           = rel8->redundancy_version_2;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->TPC           = rel8->tpc;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->harq_pid      = rel8->harq_process;
+	((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tb_swap       = rel8->transport_block_to_codeword_swap_flag;
+        ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tpmi     = rel8->precoding_information;	
+        //      printf("FDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      }
+      break;
+    case 50:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                        = sizeof_DCI2_10MHz_2A_TDD_t; 
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rah      = rel8->resource_allocation_type;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs1     = rel8->mcs_1;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs2     = rel8->mcs_2;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->ndi1     = rel8->new_data_indicator_1;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->ndi2     = rel8->new_data_indicator_2;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rballoc  = rel8->resource_block_coding;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rv1      = rel8->redundancy_version_1;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->rv2      = rel8->redundancy_version_2;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->TPC      = rel8->tpc;
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->harq_pid = rel8->harq_process;
+	((DCI2_10MHz_2A_TDD_t *)dci_pdu)->tb_swap  = rel8->transport_block_to_codeword_swap_flag;	
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->dai      = rel8->downlink_assignment_index;	
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->tpmi     = rel8->precoding_information;
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                        = sizeof_DCI2_10MHz_2A_FDD_t; 
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->mcs1      = rel8->mcs_1;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->mcs2      = rel8->mcs_2;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->ndi1      = rel8->new_data_indicator_1;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->ndi2      = rel8->new_data_indicator_2;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rv1       = rel8->redundancy_version_1;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->rv2       = rel8->redundancy_version_2;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+	((DCI2_10MHz_2A_FDD_t *)dci_pdu)->tb_swap   = rel8->transport_block_to_codeword_swap_flag;	
+        ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->tpmi      = rel8->precoding_information;
+      }
+      break;
+    case 100:
+      if (fp->frame_type == TDD) {
+	dci_alloc->dci_length                        = sizeof_DCI2_20MHz_2A_TDD_t; 
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rah       = rel8->resource_allocation_type;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs1      = rel8->mcs_1;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs2      = rel8->mcs_2;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->ndi1      = rel8->new_data_indicator_1;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->ndi2      = rel8->new_data_indicator_2;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rballoc   = rel8->resource_block_coding;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rv1       = rel8->redundancy_version_1;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->rv2       = rel8->redundancy_version_2;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->TPC       = rel8->tpc;
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->harq_pid  = rel8->harq_process;
+	((DCI2_20MHz_2A_TDD_t *)dci_pdu)->tb_swap   = rel8->transport_block_to_codeword_swap_flag;		
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->dai       = rel8->downlink_assignment_index;	
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->tpmi      = rel8->precoding_information;
+        //        printf("TDD 1: mcs %d, rballoc %x,rv %d, NPRB %d\n",mcs,rballoc,rv,NPRB);
+      } else {
+	dci_alloc->dci_length                           = sizeof_DCI2_20MHz_2A_FDD_t; 
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rah          = rel8->resource_allocation_type;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->mcs1         = rel8->mcs_1;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->mcs2         = rel8->mcs_2;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->ndi1         = rel8->new_data_indicator_1;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->ndi2         = rel8->new_data_indicator_2;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rballoc      = rel8->resource_block_coding;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rv1          = rel8->redundancy_version_1;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->rv2          = rel8->redundancy_version_2;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->TPC          = rel8->tpc;
+        ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->harq_pid     = rel8->harq_process;
+	((DCI2_20MHz_2A_FDD_t *)dci_pdu)->tb_swap      = rel8->transport_block_to_codeword_swap_flag;	
+        ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->tpmi         = rel8->precoding_information;
+      }
+      break;
+
+    }
+
+    if (rel8->harq_process>=8) {
+      LOG_E(PHY,"ERROR: Format 2_2A: harq_pid=%d >= 8\n", rel8->harq_process);
+      return(-1);
+    }
+
+
+    // Flip the TB to codeword mapping as described in 5.3.3.1.5 of 36-212 V11.3.0
+    // note that we must set tbswap=0 in eNB scheduler if one TB is deactivated
+    TB0_active = 1;
+    TB1_active = 1;
+
+    if ((rel8->redundancy_version_1 == 1) && (rel8->mcs_1 == 0)) {
+      TB0_active=0;
+    }
+    if ((rel8->redundancy_version_2 == 1) && (rel8->mcs_2 == 0)) {
+      TB1_active=0;
+    }
+#ifdef DEBUG_HARQ
+    printf("RV0 = %d, RV1 = %d. MCS0 = %d, MCS1=%d\n", rel8->redundancy_version_1, rel8->redundancy_version_2, rel8->mcs_1, rel8->mcs_2);
+#endif
+    if (TB0_active && TB1_active && rel8->transport_block_to_codeword_swap_flag==0) {
+      dlsch0->active = 1;
+      dlsch1->active = 1;
+      dlsch0_harq = dlsch0->harq_processes[rel8->harq_process];
+      dlsch1_harq = dlsch1->harq_processes[rel8->harq_process];
+      dlsch0_harq->mcs = rel8->mcs_1;
+      dlsch1_harq->mcs = rel8->mcs_2;
+      dlsch0_harq->rvidx = rel8->redundancy_version_1;
+      dlsch1_harq->rvidx = rel8->redundancy_version_2;
+      dlsch0_harq->status = ACTIVE;
+      dlsch1_harq->status = ACTIVE;
+      dlsch0_harq->codeword=0;
+      dlsch1_harq->codeword=1;
+#ifdef DEBUG_HARQ
+      printf("\n ENB: BOTH ACTIVE\n");
+#endif
+    }
+    else if (TB0_active && TB1_active && rel8->transport_block_to_codeword_swap_flag==1) {
+      dlsch0 = eNB->dlsch[UE_id][1];
+      dlsch1 = eNB->dlsch[UE_id][0];
+      dlsch0->active = 1;
+      dlsch1->active = 1;
+      dlsch0_harq = dlsch0->harq_processes[rel8->harq_process];
+      dlsch1_harq = dlsch1->harq_processes[rel8->harq_process];
+      dlsch0_harq->mcs = rel8->mcs_1;
+      dlsch1_harq->mcs = rel8->mcs_2;
+      dlsch0_harq->rvidx = rel8->redundancy_version_1;
+      dlsch1_harq->rvidx = rel8->redundancy_version_2;
+      dlsch0_harq->status = ACTIVE;
+      dlsch1_harq->status = ACTIVE;
+      dlsch0_harq->codeword=1;
+      dlsch1_harq->codeword=0;
+    }
+    else if (TB0_active && (TB1_active==0)) {
+      dlsch0->active = 1;
+      dlsch0_harq = dlsch0->harq_processes[rel8->harq_process];
+      dlsch0_harq->mcs = rel8->mcs_1;
+      dlsch0_harq->rvidx = rel8->redundancy_version_1;
+      dlsch0_harq->status = ACTIVE;
+      dlsch0_harq->codeword = 0;
+      dlsch1=NULL;
+      dlsch1_harq = NULL;
+#ifdef DEBUG_HARQ
+      printf("\n ENB: TB1 is deactivated, retransmit TB0 transmit in TM6\n");
+#endif
+    }
+    else if ((TB0_active==0) && TB1_active) {
+      dlsch1->active = 1;
+      dlsch1_harq = dlsch1->harq_processes[rel8->harq_process];
+      dlsch1_harq->mcs = rel8->mcs_2;
+      dlsch1_harq->rvidx = rel8->redundancy_version_2;
+      dlsch1_harq->status = ACTIVE;
+      dlsch1_harq->codeword = 0;
+      dlsch0=NULL;
+      dlsch0_harq = NULL;
+#ifdef DEBUG_HARQ
+      printf("\n ENB: TB0 is deactivated, retransmit TB1 transmit in TM6\n");
+#endif
+    }
+
+    if (dlsch0 != NULL){
+      dlsch0->subframe_tx[subframe] = 1;
+
+      dlsch0->harq_ids[subframe] = rel8->harq_process;
+    }
+
+    if (dlsch1_harq != NULL){
+      dlsch1->harq_ids[subframe] = rel8->harq_process;
+    }
+
+
+    if (dlsch0 != NULL ){
+      conv_rballoc(rel8->resource_allocation_type,
+                   rel8->resource_block_coding,
+                   fp->N_RB_DL,
+                   dlsch0_harq->rb_alloc);
+
+      dlsch0_harq->nb_rb = conv_nprb(rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
+
+      if (dlsch1 != NULL){
+        dlsch1_harq->rb_alloc[0] = dlsch0_harq->rb_alloc[0];
+        dlsch1_harq->nb_rb = dlsch0_harq->nb_rb;
+      }
+    } else if ((dlsch0 == NULL ) && (dlsch1 != NULL )){
+        conv_rballoc(rel8->resource_allocation_type,
+                     rel8->resource_block_coding,
+                     fp->N_RB_DL,
+                     dlsch1_harq->rb_alloc);
+
+        dlsch1_harq->nb_rb = conv_nprb(rel8->resource_allocation_type, rel8->resource_block_coding, fp->N_RB_DL);
+    }
+
+
+    /*if (dlsch0_harq->nb_rb == 0)
+      return(-1);*/
+
+
+    // assume both TBs are active
+    if (dlsch0_harq != NULL)
+      dlsch0_harq->Nl        = 1;
+    if (dlsch1_harq != NULL)
+      dlsch1_harq->Nl        = 1;
+
+
+    // check if either TB is disabled (see 36-213 V11.3 Section )
 
+    if (fp->nb_antenna_ports_eNB == 2) {
+      if ((dlsch0 != NULL) && (dlsch1 != NULL)) {  //two CW active
 
-      // Distributed Gap2, odd slot
-      nVRB_odd_dist = get_prb(100,1,nVRB,1);
-      if (nVRB_odd_dist<32)
-        allocdist0_1_odd |= (1<<nVRB_odd_dist);
-      else if (nVRB_odd_dist<64)
-        allocdist1_1_odd |= (1<<(nVRB_odd_dist-32));
-      else if (nVRB_odd_dist<96)
-  allocdist2_1_odd |= (1<<(nVRB_odd_dist-64));
-      else
-  allocdist3_1_odd |= (1<<(nVRB_odd_dist-96));
+        dlsch0_harq->dl_power_off = 1;
+        dlsch1_harq->dl_power_off = 1;
+        dlsch0_harq->TBS = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+        dlsch1_harq->TBS = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch1_harq->nb_rb-1];
+        switch (rel8->precoding_information) {
+        case 0:
+          dlsch0_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODING1;
+          dlsch1_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODING1;
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,0,1);
+          dlsch1_harq->pmi_alloc   = pmi_extend(fp,0,1);
+          break;
+        case 1:
+          dlsch0_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODINGj;
+          dlsch1_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODINGj;
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,1);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,1);
 
+          break;
+        case 2: // PUSCH precoding
+          dlsch0_harq->mimo_mode   = DUALSTREAM_PUSCH_PRECODING;
+          dlsch0_harq->pmi_alloc   = DL_pmi_single;
+          dlsch1_harq->mimo_mode   = DUALSTREAM_PUSCH_PRECODING;
+          dlsch1_harq->pmi_alloc   = DL_pmi_single;
+          break;
+        default:
+          break;
+        }
+      } else if ((dlsch0 != NULL) && (dlsch1 == NULL))  { // only CW 0 active
+        dlsch0_harq->dl_power_off = 1;
+        dlsch0_harq->TBS= TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
+        switch (rel8->precoding_information) {
+        case 0 :
+          dlsch0_harq->mimo_mode   = ALAMOUTI;
+          break;
+        case 1:
+          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING11;
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,0,0);
+          break;
+        case 2:
+          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1m1;
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,0);
+          break;
+        case 3:
+          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1j;
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,2,0);
+          break;
+        case 4:
+          dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1mj;
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,3,0);
+          break;
+        case 5:
+          dlsch0_harq->mimo_mode   = PUSCH_PRECODING0;
+          dlsch0_harq->pmi_alloc   = DL_pmi_single;
+          break;
+        case 6:
+          dlsch0_harq->mimo_mode   = PUSCH_PRECODING1;
+          dlsch0_harq->pmi_alloc   = DL_pmi_single;
+          break;
+        }
+      } else if ((dlsch0 == NULL) && (dlsch1 != NULL))  {
+          dlsch1_harq->dl_power_off = 1;
+          dlsch1_harq->TBS= TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch1_harq->nb_rb-1];
+          switch (rel8->precoding_information) {
+          case 0 :
+            dlsch1_harq->mimo_mode   = ALAMOUTI;
+            break;
+          case 1:
+            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING11;
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,0,0);
+            break;
+          case 2:
+            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1m1;
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,1,0);
+            break;
+          case 3:
+            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1j;
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,2,0);
+            break;
+          case 4:
+            dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1mj;
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,3,0);
+            break;
+          case 5:
+            dlsch1_harq->mimo_mode   = PUSCH_PRECODING0;
+            dlsch1_harq->pmi_alloc   = DL_pmi_single;
+            break;
+          case 6:
+            dlsch1_harq->mimo_mode   = PUSCH_PRECODING1;
+            dlsch1_harq->pmi_alloc   = DL_pmi_single;
+            break;
+          }
+        }
 
-      RIV=computeRIV(100,RBstart,Lcrbs);
+    } else if (fp->nb_antenna_ports_eNB == 4) {
+      // fill in later
+    }
 
-      if (RIV>RIV_max100)
-        RIV_max100 = RIV;
+    // reset HARQ process if this is the first transmission
+   /* if (dlsch0_harq->round == 0)
+      dlsch0_harq->status = ACTIVE;
 
-      //      printf("RIV %d : first_rb %d NBRB %d\n",RIV,RBstart,Lcrbs);
-      localRIV2alloc_LUT100_0[RIV] = alloc0;
-      localRIV2alloc_LUT100_1[RIV] = alloc1;
-      localRIV2alloc_LUT100_2[RIV] = alloc2;
-      localRIV2alloc_LUT100_3[RIV] = alloc3;
-      distRIV2alloc_gap0_even_LUT100_0[RIV]  = allocdist0_0_even;
-      distRIV2alloc_gap0_even_LUT100_1[RIV]  = allocdist1_0_even;
-      distRIV2alloc_gap0_even_LUT100_2[RIV]  = allocdist2_0_even;
-      distRIV2alloc_gap0_even_LUT100_3[RIV]  = allocdist3_0_even;
-      distRIV2alloc_gap0_odd_LUT100_0[RIV]   = allocdist0_0_odd;
-      distRIV2alloc_gap0_odd_LUT100_1[RIV]   = allocdist1_0_odd;
-      distRIV2alloc_gap0_odd_LUT100_2[RIV]   = allocdist2_0_odd;
-      distRIV2alloc_gap0_odd_LUT100_3[RIV]   = allocdist3_0_odd;
-      distRIV2alloc_gap1_even_LUT100_0[RIV]  = allocdist0_1_even;
-      distRIV2alloc_gap1_even_LUT100_1[RIV]  = allocdist1_1_even;
-      distRIV2alloc_gap1_even_LUT100_2[RIV]  = allocdist2_1_even;
-      distRIV2alloc_gap1_even_LUT100_3[RIV]  = allocdist3_1_even;
-      distRIV2alloc_gap1_odd_LUT100_0[RIV]   = allocdist0_1_odd;
-      distRIV2alloc_gap1_odd_LUT100_1[RIV]   = allocdist1_1_odd;
-      distRIV2alloc_gap1_odd_LUT100_2[RIV]   = allocdist2_1_odd;
-      distRIV2alloc_gap1_odd_LUT100_3[RIV]   = allocdist3_1_odd;
+    if (dlsch1_harq->round == 0)
+      dlsch1_harq->status = ACTIVE;*/
+    if (dlsch0_harq != NULL)
+      dlsch0->rnti = rel8->rnti;
+    if (dlsch1 != NULL)
+      dlsch1->rnti = rel8->rnti;
 
-      RIV2nb_rb_LUT100[RIV]      = Lcrbs;
-      RIV2first_rb_LUT100[RIV]   = RBstart;
-    }
+    break;
   }
-}
 
-// Ngap = 3, N_VRB_DL=6, P=1, N_row=2, N_null=4*2-6=2
-// permutation for even slots :
-//    n_PRB'(0,2,4) = (0,1,2), n_PRB'(1,3,5) = (4,5,6)
-//    n_PRB''(0,1,2,3) = (0,2,4,6)
-//    => n_tilde_PRB(5) = (4)
-//       n_tilde_PRB(4) = (1)
-//       n_tilde_PRB(2,3) = (3,5)
-//       n_tilde_PRB(0,1) = (0,2)
+  if (dlsch0_harq) {
+    dlsch0_harq->frame    = proc->frame_tx;
+    dlsch0_harq->subframe = subframe;
+  }
+  if (dlsch1_harq) {
+    dlsch1_harq->frame    = proc->frame_tx;
+    dlsch1_harq->subframe = subframe;
+  }
 
+#ifdef DEBUG_DCI
 
+  if (dlsch0) {
+    printf("dlsch0 eNB: dlsch0   %p\n",dlsch0);
+    printf("dlsch0 eNB: rnti     %x\n",dlsch0->rnti);
+    printf("dlsch0 eNB: NBRB     %d\n",dlsch0_harq->nb_rb);
+    printf("dlsch0 eNB: rballoc  %x\n",dlsch0_harq->rb_alloc[0]);
+    printf("dlsch0 eNB: harq_pid %d\n",harq_pid);
+    printf("dlsch0 eNB: round    %d\n",dlsch0_harq->round);
+    printf("dlsch0 eNB: rvidx    %d\n",dlsch0_harq->rvidx);
+    printf("dlsch0 eNB: TBS      %d (NPRB %d)\n",dlsch0_harq->TBS,NPRB);
+    printf("dlsch0 eNB: mcs      %d\n",dlsch0_harq->mcs);
+    printf("dlsch0 eNB: tpmi %d\n",rel8->precoding_information);
+    printf("dlsch0 eNB: mimo_mode %d\n",dlsch0_harq->mimo_mode);
+  }
 
-uint32_t get_rballoc(vrb_t vrb_type,uint16_t rb_alloc_dci)
-{
+    if (dlsch1) {
+    printf("dlsch1 eNB: dlsch1   %p\n",dlsch1);
+    printf("dlsch1 eNB: rnti     %x\n",dlsch1->rnti);
+    printf("dlsch1 eNB: NBRB     %d\n",dlsch1_harq->nb_rb);
+    printf("dlsch1 eNB: rballoc  %x\n",dlsch1_harq->rb_alloc[0]);
+    printf("dlsch1 eNB: harq_pid %d\n",harq_pid);
+    printf("dlsch1 eNB: round    %d\n",dlsch1_harq->round);
+    printf("dlsch1 eNB: rvidx    %d\n",dlsch1_harq->rvidx);
+    printf("dlsch1 eNB: TBS      %d (NPRB %d)\n",dlsch1_harq->TBS,NPRB);
+    printf("dlsch1 eNB: mcs      %d\n",dlsch1_harq->mcs);
+    printf("dlsch1 eNB: tpmi %d\n",rel8->precoding_information);
+    printf("dlsch1 eNB: mimo_mode %d\n",dlsch1_harq->mimo_mode);
+  }
 
-  return(localRIV2alloc_LUT25[rb_alloc_dci]);
+#endif
+    
+    // compute DL power control parameters
 
+    if (dlsch0 != NULL){
+      computeRhoA_eNB(&eNB->pdsch_config_dedicated[UE_id], dlsch0,dlsch0_harq->dl_power_off, fp->nb_antenna_ports_eNB);
+      computeRhoB_eNB(&eNB->pdsch_config_dedicated[UE_id],&(fp->pdsch_config_common),fp->nb_antenna_ports_eNB,dlsch0,dlsch0_harq->dl_power_off);
+    }
+    if (dlsch1 != NULL){
+      computeRhoA_eNB(&eNB->pdsch_config_dedicated[UE_id], dlsch1,dlsch1_harq->dl_power_off, fp->nb_antenna_ports_eNB);
+      computeRhoB_eNB(&eNB->pdsch_config_dedicated[UE_id],&(fp->pdsch_config_common),fp->nb_antenna_ports_eNB,dlsch1,dlsch1_harq->dl_power_off);
+    }
+    
+    
 }
 
-uint8_t get_transmission_mode(module_id_t Mod_id, uint8_t CC_id, rnti_t rnti)
-{
-  unsigned char UE_id;
-
-  // find the UE_index corresponding to rnti
-  UE_id = find_ue(rnti,RC.eNB[Mod_id][CC_id]);
-  DevAssert( UE_id != (unsigned char)-1 );
+int fill_dci_and_ulsch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,nfapi_hi_dci0_dci_pdu *pdu) {
 
-  return(RC.eNB[Mod_id][CC_id]->transmission_mode[UE_id]);
+  exit(-1);
 }
 
 int generate_eNB_dlsch_params_from_dci(int frame,
@@ -863,7 +1960,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
                                        uint16_t rnti,
                                        DCI_format_t dci_format,
                                        LTE_eNB_DLSCH_t **dlsch,
-                                       LTE_DL_FRAME_PARMS *frame_parms,
+                                       LTE_DL_FRAME_PARMS *fp,
                                        PDSCH_CONFIG_DEDICATED *pdsch_config_dedicated,
                                        uint16_t si_rnti,
                                        uint16_t ra_rnti,
@@ -877,7 +1974,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
   uint32_t RIV_max = 0;
   uint8_t NPRB,tbswap,tpmi=0;
   LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
-  uint8_t frame_type=frame_parms->frame_type;
+  uint8_t frame_type=fp->frame_type;
   uint8_t vrb_type=0;
   uint8_t mcs=0,mcs1=0,mcs2=0;
   uint8_t I_mcs = 0;
@@ -902,7 +1999,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     dlsch[0]->subframe_tx[subframe] = 1;
 
 
-    switch (frame_parms->N_RB_DL) {
+    switch (fp->N_RB_DL) {
     case 6:
       if (frame_type == TDD) {
         vrb_type = ((DCI1A_1_5MHz_TDD_1_6_t *)dci_pdu)->vrb_type;
@@ -927,13 +2024,8 @@ int generate_eNB_dlsch_params_from_dci(int frame,
       dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
       dlsch0_harq->codeword=0;
 
-      if (vrb_type==LOCALIZED) {
-  dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT6[rballoc];
-      }
-      else {
-  LOG_E(PHY,"Distributed RB allocation not done yet\n");
-  mac_xface->macphy_exit("exiting");
-      }
+      AssertFatal(vrb_type==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT6[rballoc];
       dlsch0_harq->vrb_type       = vrb_type;
       dlsch0_harq->nb_rb          = RIV2nb_rb_LUT6[rballoc];//NPRB;
       RIV_max = RIV_max6;
@@ -965,13 +2057,8 @@ int generate_eNB_dlsch_params_from_dci(int frame,
       dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
 
 
-      if (vrb_type==LOCALIZED) {
-  dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT25[rballoc];
-      }
-      else {
-  LOG_E(PHY,"Distributed RB allocation not done yet\n");
-  mac_xface->macphy_exit("exiting");
-      }
+      AssertFatal(vrb_type==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]    = localRIV2alloc_LUT25[rballoc];
       dlsch0_harq->vrb_type       = vrb_type;
       dlsch0_harq->nb_rb          = RIV2nb_rb_LUT25[rballoc];//NPRB;
       RIV_max                     = RIV_max25;
@@ -998,18 +2085,11 @@ int generate_eNB_dlsch_params_from_dci(int frame,
       }
 
       dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
-      if (vrb_type==LOCALIZED) {
-  dlsch0_harq->rb_alloc[0]     = localRIV2alloc_LUT50_0[rballoc];
-  dlsch0_harq->rb_alloc[1]     = localRIV2alloc_LUT50_1[rballoc];
-      }
-      else {
-  LOG_E(PHY,"Distributed RB allocation not done yet\n");
-  mac_xface->macphy_exit("exiting");
-      }
-
-
+      AssertFatal(vrb_type==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]     = localRIV2alloc_LUT50_0[rballoc];
+      dlsch0_harq->rb_alloc[1]     = localRIV2alloc_LUT50_1[rballoc];
       dlsch0_harq->vrb_type        = vrb_type;
-      dlsch0_harq->nb_rb                               = RIV2nb_rb_LUT50[rballoc];//NPRB;
+      dlsch0_harq->nb_rb           = RIV2nb_rb_LUT50[rballoc];//NPRB;
       RIV_max = RIV_max50;
       break;
 
@@ -1035,36 +2115,25 @@ int generate_eNB_dlsch_params_from_dci(int frame,
       dlsch0_harq = dlsch[0]->harq_processes[harq_pid];
 
       dlsch0_harq->vrb_type         = vrb_type;
-      if (vrb_type==LOCALIZED) {
-  dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT100_0[rballoc];
-  dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT100_1[rballoc];
-  dlsch0_harq->rb_alloc[2]      = localRIV2alloc_LUT100_2[rballoc];
-  dlsch0_harq->rb_alloc[3]      = localRIV2alloc_LUT100_3[rballoc];
-      }
-      else {
-  LOG_E(PHY,"Distributed RB allocation not done yet\n");
-  mac_xface->macphy_exit("exiting");
-      }
-
-
-
-      dlsch0_harq->nb_rb                               = RIV2nb_rb_LUT100[rballoc];//NPRB;
-      RIV_max = RIV_max100;
+      AssertFatal(vrb_type==LOCALIZED,"Distributed RB allocation not done yet\n");
+      dlsch0_harq->rb_alloc[0]      = localRIV2alloc_LUT100_0[rballoc];
+      dlsch0_harq->rb_alloc[1]      = localRIV2alloc_LUT100_1[rballoc];
+      dlsch0_harq->rb_alloc[2]      = localRIV2alloc_LUT100_2[rballoc];
+      dlsch0_harq->rb_alloc[3]      = localRIV2alloc_LUT100_3[rballoc];
+      dlsch0_harq->nb_rb            = RIV2nb_rb_LUT100[rballoc];//NPRB;
+      RIV_max                       = RIV_max100;
       break;
 
     default:
-      LOG_E(PHY,"Invalid N_RB_D %dL\n", frame_parms->N_RB_DL);
-      DevParam (frame_parms->N_RB_DL, 0, 0);
+      LOG_E(PHY,"Invalid N_RB_D %dL\n", fp->N_RB_DL);
+      DevParam (fp->N_RB_DL, 0, 0);
       break;
     }
 
     // harq_pid field is reserved
     if ((rnti==si_rnti) || (rnti==ra_rnti) || (rnti==p_rnti)) { //
       harq_pid=0;
-      // see 36-212 V8.6.0 p. 45
-      NPRB      = (TPC&1)+2;
-      // 36-213 sec.7.1.7.2 p.26
-      I_mcs     = mcs;
+
     } else {
       if (harq_pid>=8) {
         LOG_E(PHY,"ERROR: Format 1A: harq_pid=%d >= 8\n", harq_pid);
@@ -1089,7 +2158,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     dlsch0_harq->Nl          = 1;
     //dlsch0_harq->layer_index = 0;
 
-    dlsch0_harq->mimo_mode   = (frame_parms->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
+    dlsch0_harq->mimo_mode   = (fp->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
     /*
     if ((rnti!=si_rnti)&&(rnti!=ra_rnti)&&(rnti!=p_rnti)) {  //handle toggling for C-RNTI
     if (dlsch0_harq->first_tx == 1) {
@@ -1117,7 +2186,6 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     dlsch0_harq->mcs           = mcs;
     dlsch0_harq->TBS           = TBStable[I_mcs][NPRB-1];
 
-    dlsch[0]->current_harq_pid   = harq_pid;
     dlsch[0]->harq_ids[subframe] = harq_pid;
 
     dlsch[0]->active = 1;
@@ -1134,7 +2202,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
   case format1:
 
-    switch (frame_parms->N_RB_DL) {
+    switch (fp->N_RB_DL) {
 
     case 6:
       if (frame_type == TDD) {
@@ -1222,12 +2290,12 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     dlsch[0]->subframe_tx[subframe] = 1;
 
     conv_rballoc(rah,
-                 rballoc,frame_parms->N_RB_DL,
+                 rballoc,fp->N_RB_DL,
                  dlsch0_harq->rb_alloc);
 
     dlsch0_harq->nb_rb = conv_nprb(rah,
                                    rballoc,
-                                   frame_parms->N_RB_DL);
+                                   fp->N_RB_DL);
 
     NPRB      = dlsch0_harq->nb_rb;
 
@@ -1241,7 +2309,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     dlsch0_harq->Nl          = 1;
     //    dlsch[0]->layer_index = 0;
     if (beamforming_mode == 0)
-      dlsch0_harq->mimo_mode = (frame_parms->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
+      dlsch0_harq->mimo_mode = (fp->nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI;
     else if (beamforming_mode == 7)
       dlsch0_harq->mimo_mode = TM7;
     else
@@ -1277,7 +2345,6 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     }
 
-    dlsch[0]->current_harq_pid = harq_pid;
     dlsch[0]->harq_ids[subframe] = harq_pid;
 
 
@@ -1291,10 +2358,10 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
   case format2: // DL Scheduling assignment for MIMO including closed loop spatial multiplexing
 
-    switch (frame_parms->N_RB_DL) {
+    switch (fp->N_RB_DL) {
 
     case 6:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_1_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1314,7 +2381,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tbswap    = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
           tpmi      = ((DCI2_1_5MHz_2A_FDD_t *)dci_pdu)->tpmi;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_1_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1335,13 +2402,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi      = ((DCI2_1_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
 
     case 25:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1363,7 +2430,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tbswap    = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
           tpmi      = ((DCI2_5MHz_2A_FDD_t *)dci_pdu)->tpmi;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1386,13 +2453,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi      = ((DCI2_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
 
     case 50:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_10MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1414,7 +2481,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tbswap    = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->tb_swap;
           tpmi      = ((DCI2_10MHz_2A_FDD_t *)dci_pdu)->tpmi;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_10MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1437,13 +2504,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi      = ((DCI2_10MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
 
     case 100:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_20MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1465,7 +2532,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tbswap    = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->tb_swap;
           tpmi      = ((DCI2_20MHz_2A_FDD_t *)dci_pdu)->tpmi;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2_20MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1488,7 +2555,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi      = ((DCI2_20MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2 DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
@@ -1582,12 +2649,10 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     if (dlsch0 != NULL){
       dlsch0->subframe_tx[subframe] = 1;
 
-      dlsch0->current_harq_pid = harq_pid;
       dlsch0->harq_ids[subframe] = harq_pid;
     }
 
     if (dlsch1_harq != NULL){
-      dlsch1->current_harq_pid = harq_pid;
       dlsch1->harq_ids[subframe] = harq_pid;
     }
 
@@ -1595,10 +2660,10 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     if (dlsch0 != NULL ){
       conv_rballoc(rah,
                    rballoc,
-                   frame_parms->N_RB_DL,
+                   fp->N_RB_DL,
                    dlsch0_harq->rb_alloc);
 
-      dlsch0_harq->nb_rb = conv_nprb(rah, rballoc, frame_parms->N_RB_DL);
+      dlsch0_harq->nb_rb = conv_nprb(rah, rballoc, fp->N_RB_DL);
 
       if (dlsch1 != NULL){
         dlsch1_harq->rb_alloc[0] = dlsch0_harq->rb_alloc[0];
@@ -1607,10 +2672,10 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     } else if ((dlsch0 == NULL ) && (dlsch1 != NULL )){
         conv_rballoc(rah,
                      rballoc,
-                     frame_parms->N_RB_DL,
+                     fp->N_RB_DL,
                      dlsch1_harq->rb_alloc);
 
-        dlsch1_harq->nb_rb = conv_nprb(rah, rballoc, frame_parms->N_RB_DL);
+        dlsch1_harq->nb_rb = conv_nprb(rah, rballoc, fp->N_RB_DL);
     }
 
 
@@ -1627,7 +2692,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     // check if either TB is disabled (see 36-213 V11.3 Section )
 
-    if (frame_parms->nb_antenna_ports_eNB == 2) {
+    if (fp->nb_antenna_ports_eNB == 2) {
       if ((dlsch0 != NULL) && (dlsch1 != NULL)) {  //two CW active
 
         dlsch0_harq->dl_power_off = 1;
@@ -1638,14 +2703,14 @@ int generate_eNB_dlsch_params_from_dci(int frame,
         case 0:
           dlsch0_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODING1;
           dlsch1_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODING1;
-          dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,0,1);
-          dlsch1_harq->pmi_alloc   = pmi_extend(frame_parms,0,1);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,0,1);
+          dlsch1_harq->pmi_alloc   = pmi_extend(fp,0,1);
           break;
         case 1:
           dlsch0_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODINGj;
           dlsch1_harq->mimo_mode   = DUALSTREAM_UNIFORM_PRECODINGj;
-          dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,1,1);
-          dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,1,1);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,1);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,1);
 
           break;
         case 2: // PUSCH precoding
@@ -1666,19 +2731,19 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           break;
         case 1:
           dlsch0_harq->mimo_mode   = UNIFORM_PRECODING11;
-          dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,0,0);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,0,0);
           break;
         case 2:
           dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1m1;
-          dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,1,0);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,1,0);
           break;
         case 3:
           dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1j;
-          dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,2,0);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,2,0);
           break;
         case 4:
           dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1mj;
-          dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,3,0);
+          dlsch0_harq->pmi_alloc   = pmi_extend(fp,3,0);
           break;
         case 5:
           dlsch0_harq->mimo_mode   = PUSCH_PRECODING0;
@@ -1698,19 +2763,19 @@ int generate_eNB_dlsch_params_from_dci(int frame,
             break;
           case 1:
             dlsch1_harq->mimo_mode   = UNIFORM_PRECODING11;
-            dlsch1_harq->pmi_alloc   = pmi_extend(frame_parms,0,0);
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,0,0);
             break;
           case 2:
             dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1m1;
-            dlsch1_harq->pmi_alloc   = pmi_extend(frame_parms,1,0);
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,1,0);
             break;
           case 3:
             dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1j;
-            dlsch1_harq->pmi_alloc   = pmi_extend(frame_parms,2,0);
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,2,0);
             break;
           case 4:
             dlsch1_harq->mimo_mode   = UNIFORM_PRECODING1mj;
-            dlsch1_harq->pmi_alloc   = pmi_extend(frame_parms,3,0);
+            dlsch1_harq->pmi_alloc   = pmi_extend(fp,3,0);
             break;
           case 5:
             dlsch1_harq->mimo_mode   = PUSCH_PRECODING0;
@@ -1723,7 +2788,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           }
         }
 
-    } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+    } else if (fp->nb_antenna_ports_eNB == 4) {
       // fill in later
     }
 
@@ -1742,10 +2807,10 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
   case format2A:
 
-    switch (frame_parms->N_RB_DL) {
+    switch (fp->N_RB_DL) {
 
     case 6:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_1_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1763,7 +2828,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           harq_pid  = ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->harq_pid;
           tbswap    = ((DCI2A_1_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_1_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_1_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1784,13 +2849,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi      = ((DCI2A_1_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
 
     case 25:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_5MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1810,7 +2875,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           harq_pid  = ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->harq_pid;
           tbswap    = ((DCI2A_5MHz_2A_FDD_t *)dci_pdu)->tb_swap;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_5MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_5MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1833,13 +2898,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi      = ((DCI2A_5MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
 
     case 50:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_10MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1859,7 +2924,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           harq_pid  = ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->harq_pid;
           tbswap    = ((DCI2A_10MHz_2A_FDD_t *)dci_pdu)->tb_swap;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_10MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_10MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1882,13 +2947,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi      = ((DCI2A_10MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
 
     case 100:
-      if (frame_parms->nb_antenna_ports_eNB == 2) {
+      if (fp->nb_antenna_ports_eNB == 2) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_20MHz_2A_TDD_t *)dci_pdu)->mcs2;
@@ -1908,7 +2973,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           harq_pid  = ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->harq_pid;
           tbswap    = ((DCI2A_20MHz_2A_FDD_t *)dci_pdu)->tb_swap;
         }
-      } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+      } else if (fp->nb_antenna_ports_eNB == 4) {
         if (frame_type == TDD) {
           mcs1      = ((DCI2A_20MHz_4A_TDD_t *)dci_pdu)->mcs1;
           mcs2      = ((DCI2A_20MHz_4A_TDD_t *)dci_pdu)->mcs2;
@@ -1931,7 +2996,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           tpmi    = ((DCI2A_20MHz_4A_FDD_t *)dci_pdu)->tpmi;
         }
       } else {
-        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,frame_parms->nb_antenna_ports_eNB);
+        LOG_E(PHY,"eNB: subframe %d UE %x, Format2A DCI: unsupported number of TX antennas %d\n",subframe,rnti,fp->nb_antenna_ports_eNB);
       }
 
       break;
@@ -1960,8 +3025,6 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     dlsch0->subframe_tx[subframe] = 1;
 
-    dlsch0->current_harq_pid = harq_pid;
-    dlsch1->current_harq_pid = harq_pid;
     dlsch0->harq_ids[subframe] = harq_pid;
     dlsch1->harq_ids[subframe] = harq_pid;
     //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);
@@ -1969,13 +3032,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     conv_rballoc(rah,
                  rballoc,
-                 frame_parms->N_RB_DL,
+                 fp->N_RB_DL,
                  dlsch0_harq->rb_alloc);
 
     dlsch1_harq->rb_alloc[0]                         = dlsch0_harq->rb_alloc[0];
     dlsch0_harq->nb_rb                               = conv_nprb(rah,
         rballoc,
-        frame_parms->N_RB_DL);
+        fp->N_RB_DL);
     dlsch1_harq->nb_rb                               = dlsch0_harq->nb_rb;
 
     if (dlsch0_harq->nb_rb == 0)
@@ -2006,7 +3069,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
    // dlsch1_harq->dl_power_off = 0;
 
 
-    if (frame_parms->nb_antenna_ports_eNB == 2) {
+    if (fp->nb_antenna_ports_eNB == 2) {
       dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
       dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch0_harq->nb_rb-1];
 
@@ -2020,7 +3083,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
         dlsch0_harq->mimo_mode   = ALAMOUTI;
         dlsch1_harq->mimo_mode   = ALAMOUTI;
       }
-    } else if (frame_parms->nb_antenna_ports_eNB == 4) { // 4 antenna case
+    } else if (fp->nb_antenna_ports_eNB == 4) { // 4 antenna case
       if ((dlsch0->active==1) && (dlsch1->active==1)) {
         switch (tpmi) {
         case 0: // one layer per transport block
@@ -2048,7 +3111,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
           dlsch0_harq->dl_power_off = 1;
           dlsch1_harq->dl_power_off = 1;
 
-          if (frame_parms->N_RB_DL <= 56) {
+          if (fp->N_RB_DL <= 56) {
             dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][(dlsch0_harq->nb_rb<<1)-1];
             dlsch1_harq->TBS         = TBStable[get_I_TBS(dlsch1_harq->mcs)][(dlsch1_harq->nb_rb<<1)-1];
           } else {
@@ -2103,7 +3166,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
         }
       }
     } else {
-      LOG_E(PHY,"Illegal number of antennas for eNB %d\n",frame_parms->nb_antenna_ports_eNB);
+      LOG_E(PHY,"Illegal number of antennas for eNB %d\n",fp->nb_antenna_ports_eNB);
     }
 
     // reset HARQ process if this is the first transmission
@@ -2123,7 +3186,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
   case format2B:
 
-    switch (frame_parms->N_RB_DL) {
+    switch (fp->N_RB_DL) {
 
     case 6:
       if (frame_type == TDD) {
@@ -2222,8 +3285,6 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     dlsch0->subframe_tx[subframe] = 1;
 
-    dlsch0->current_harq_pid = harq_pid;
-    dlsch1->current_harq_pid = harq_pid;
     dlsch0->harq_ids[subframe] = harq_pid;
     dlsch1->harq_ids[subframe] = harq_pid;
     //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);
@@ -2238,14 +3299,14 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     conv_rballoc(rah,
                  rballoc,
-                 frame_parms->N_RB_DL,
+                 fp->N_RB_DL,
                  dlsch0_harq->rb_alloc);
 
     dlsch1_harq->rb_alloc[0]     = dlsch0_harq->rb_alloc[0];
 
     dlsch0_harq->nb_rb           = conv_nprb(rah,
               rballoc,
-              frame_parms->N_RB_DL);
+              fp->N_RB_DL);
     dlsch1_harq->nb_rb           = dlsch0_harq->nb_rb;
 
     dlsch0_harq->mcs       = mcs1;
@@ -2290,7 +3351,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
   case format2C:
 
-    switch (frame_parms->N_RB_DL) {
+    switch (fp->N_RB_DL) {
 
     case 6:
       if (frame_type == TDD) {
@@ -2388,8 +3449,6 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     dlsch0->subframe_tx[subframe] = 1;
 
-    dlsch0->current_harq_pid = harq_pid;
-    dlsch1->current_harq_pid = harq_pid;
     dlsch0->harq_ids[subframe] = harq_pid;
     dlsch1->harq_ids[subframe] = harq_pid;
     //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);
@@ -2403,13 +3462,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     conv_rballoc(rah,
                  rballoc,
-                 frame_parms->N_RB_DL,
+                 fp->N_RB_DL,
                  dlsch0_harq->rb_alloc);
     dlsch1_harq->rb_alloc[0]                         = dlsch0_harq->rb_alloc[0];
 
     dlsch0_harq->nb_rb                               = conv_nprb(rah,
         rballoc,
-        frame_parms->N_RB_DL);
+        fp->N_RB_DL);
     dlsch1_harq->nb_rb                               = dlsch0_harq->nb_rb;
 
     if (dlsch0_harq->nb_rb == 0)
@@ -2444,14 +3503,14 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     }
 
     // check TPMI information to compute TBS
-    if (frame_parms->nb_antenna_ports_eNB == 2) {
+    if (fp->nb_antenna_ports_eNB == 2) {
       if (dlsch1->active == 1) { // both TBs are active
         dlsch0_harq->TBS           = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
         dlsch1_harq->TBS           = TBStable[get_I_TBS(dlsch1_harq->mcs)][dlsch0_harq->nb_rb-1];
       } else {
         dlsch0_harq->TBS         = TBStable[get_I_TBS(dlsch0_harq->mcs)][dlsch0_harq->nb_rb-1];
       }
-    } else if (frame_parms->nb_antenna_ports_eNB == 4) {
+    } else if (fp->nb_antenna_ports_eNB == 4) {
 
     }
 
@@ -2465,7 +3524,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
   case format2D:
 
-    switch (frame_parms->N_RB_DL) {
+    switch (fp->N_RB_DL) {
 
     case 6:
       if (frame_type == TDD) {
@@ -2563,8 +3622,6 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     dlsch0->subframe_tx[subframe] = 1;
 
-    dlsch0->current_harq_pid = harq_pid;
-    dlsch1->current_harq_pid = harq_pid;
     dlsch0->harq_ids[subframe] = harq_pid;
     dlsch1->harq_ids[subframe] = harq_pid;
     //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);
@@ -2579,13 +3636,13 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     conv_rballoc(rah,
                  rballoc,
-                 frame_parms->N_RB_DL,
+                 fp->N_RB_DL,
                  dlsch0_harq->rb_alloc);
     dlsch1_harq->rb_alloc[0]                         = dlsch0_harq->rb_alloc[0];
 
     dlsch0_harq->nb_rb                               = conv_nprb(rah,
         rballoc,
-        frame_parms->N_RB_DL);
+        fp->N_RB_DL);
     dlsch1_harq->nb_rb                               = dlsch0_harq->nb_rb;
 
     dlsch0_harq->mcs       = mcs1;
@@ -2652,24 +3709,22 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     dlsch0 = dlsch[0];
     dlsch0->subframe_tx[subframe] = 1;
 
-    dlsch0->current_harq_pid = harq_pid;
-    //dlsch1->current_harq_pid = harq_pid;
+
     dlsch0->harq_ids[subframe] = harq_pid;
-    //dlsch1->harq_ids[subframe] = harq_pid;
     //    printf("Setting DLSCH harq id %d to subframe %d\n",harq_pid,subframe);
     dlsch0_harq = dlsch0->harq_processes[harq_pid];
        // Needs to be checked
     dlsch0_harq->codeword=0;
 
     conv_rballoc(((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rah,
-                 ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rballoc,frame_parms->N_RB_DL,
+                 ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rballoc,fp->N_RB_DL,
                  dlsch0_harq->rb_alloc);
 
     //dlsch1->rb_alloc[0]                         = dlsch0->rb_alloc[0];
 
     dlsch0_harq->nb_rb                               = conv_nprb(((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rah,
         ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->rballoc,
-        frame_parms->N_RB_DL);
+        fp->N_RB_DL);
     //dlsch1->nb_rb                               = dlsch0->nb_rb;
 
     dlsch0_harq->mcs       = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->mcs;
@@ -2700,25 +3755,25 @@ int generate_eNB_dlsch_params_from_dci(int frame,
 
     case 1:
       dlsch0_harq->mimo_mode   = UNIFORM_PRECODING11;
-      dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,0, 0);
+      dlsch0_harq->pmi_alloc   = pmi_extend(fp,0, 0);
 
       break;
 
     case 2:
       dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1m1;
-      dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,1, 0);
+      dlsch0_harq->pmi_alloc   = pmi_extend(fp,1, 0);
 
       break;
 
     case 3:
       dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1j;
-      dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,2, 0);
+      dlsch0_harq->pmi_alloc   = pmi_extend(fp,2, 0);
 
       break;
 
     case 4:
       dlsch0_harq->mimo_mode   = UNIFORM_PRECODING1mj;
-      dlsch0_harq->pmi_alloc   = pmi_extend(frame_parms,3, 0);
+      dlsch0_harq->pmi_alloc   = pmi_extend(fp,3, 0);
       break;
 
     case 5:
@@ -2735,7 +3790,7 @@ int generate_eNB_dlsch_params_from_dci(int frame,
     //    printf("Set pmi %x (tpmi %d)\n",dlsch0->pmi_alloc,tpmi);
 
 
-    if (frame_parms->nb_antenna_ports_eNB == 1)
+    if (fp->nb_antenna_ports_eNB == 1)
       dlsch0_harq->mimo_mode   = SISO;
 
     //    dlsch0_harq->Ndi         = ((DCI1E_5MHz_2A_M10PRB_TDD_t *)dci_pdu)->ndi;
@@ -2814,12 +3869,12 @@ int generate_eNB_dlsch_params_from_dci(int frame,
   // compute DL power control parameters
 
   if (dlsch0 != NULL){
-  computeRhoA_eNB(pdsch_config_dedicated, dlsch[0],dlsch0_harq->dl_power_off, frame_parms->nb_antenna_ports_eNB);
-  computeRhoB_eNB(pdsch_config_dedicated,&(frame_parms->pdsch_config_common),frame_parms->nb_antenna_ports_eNB,dlsch[0],dlsch0_harq->dl_power_off);
-}
+  computeRhoA_eNB(pdsch_config_dedicated, dlsch[0],dlsch0_harq->dl_power_off, fp->nb_antenna_ports_eNB);
+  computeRhoB_eNB(pdsch_config_dedicated,&(fp->pdsch_config_common),fp->nb_antenna_ports_eNB,dlsch[0],dlsch0_harq->dl_power_off);
+  }
   if (dlsch1 != NULL){
-      computeRhoA_eNB(pdsch_config_dedicated, dlsch[1],dlsch1_harq->dl_power_off, frame_parms->nb_antenna_ports_eNB);
-  computeRhoB_eNB(pdsch_config_dedicated,&(frame_parms->pdsch_config_common),frame_parms->nb_antenna_ports_eNB,dlsch[1],dlsch1_harq->dl_power_off);
+      computeRhoA_eNB(pdsch_config_dedicated, dlsch[1],dlsch1_harq->dl_power_off, fp->nb_antenna_ports_eNB);
+  computeRhoB_eNB(pdsch_config_dedicated,&(fp->pdsch_config_common),fp->nb_antenna_ports_eNB,dlsch[1],dlsch1_harq->dl_power_off);
   }
 
 
@@ -6477,12 +7532,10 @@ uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t
 
     case 2:
       if ((subframe!=2) && (subframe!=7)) {
-        LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
-        mac_xface->macphy_exit("subframe2_harq_pid, Illegal subframe");
-        ret = (255);
+	LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
+	ret=255;
       }
-
-      ret = (subframe/7);
+      else ret = (subframe/7);
       break;
 
     case 3:
@@ -6490,8 +7543,7 @@ uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t
         LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
         ret = (255);
       }
-
-      ret = (subframe-2);
+      else ret = (subframe-2);
       break;
 
     case 4:
@@ -6499,8 +7551,7 @@ uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t
         LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
         ret = (255);
       }
-
-      ret = (subframe-2);
+      else ret = (subframe-2);
       break;
 
     case 5:
@@ -6508,21 +7559,17 @@ uint8_t subframe2harq_pid(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame,uint8_t
         LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframe,frame_parms->tdd_config);
         ret = (255);
       }
-
-      ret = (subframe-2);
+      else ret = (subframe-2);
       break;
 
     default:
       LOG_E(PHY,"subframe2_harq_pid, Unsupported TDD mode %d\n",frame_parms->tdd_config);
       ret = (255);
-
     }
   }
 
-  if (ret == 255) {
-    LOG_E(PHY, "invalid harq_pid(%d) at SFN/SF = %d/%d\n", ret, frame, subframe);
-    mac_xface->macphy_exit("invalid harq_pid");
-  }
+  AssertFatal(ret!=255,
+	      "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t)ret, frame, subframe);
   return ret;
 }
 
@@ -6973,12 +8020,12 @@ void fill_CQI(LTE_UE_ULSCH_t *ulsch,PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint8_
 
     case ue_selected:
       LOG_E(PHY,"fill_CQI ue_selected CQI not supported yet!!!\n");
-      mac_xface->macphy_exit("fill_CQI ue_selected CQI not supported yet!!!");
+      AssertFatal(1==0,"fill_CQI ue_selected CQI not supported yet!!!");
       break;
 
     default:
       LOG_E(PHY,"unsupported CQI mode (%d)!!!\n",uci_format);
-      mac_xface->macphy_exit("unsupported CQI mode !!!");
+      AssertFatal(1==0,"unsupported CQI mode !!!");
       break;
 
     }
@@ -7027,12 +8074,12 @@ void fill_CQI(LTE_UE_ULSCH_t *ulsch,PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint8_
 
     case ue_selected:
       LOG_E(PHY,"fill_CQI ue_selected CQI not supported yet!!!\n");
-      mac_xface->macphy_exit("fill_CQI ue_selected CQI not supported yet!!!");
+      AssertFatal(1==0,"fill_CQI ue_selected CQI not supported yet!!!");
       break;
 
     default:
       LOG_E(PHY,"unsupported CQI mode (%d)!!!\n",uci_format);
-      mac_xface->macphy_exit("unsupported CQI mode !!!");
+      AssertFatal(1==0,"unsupported CQI mode !!!");
       break;
 
     }
@@ -7081,12 +8128,12 @@ void fill_CQI(LTE_UE_ULSCH_t *ulsch,PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint8_
 
     case ue_selected:
       LOG_E(PHY,"fill_CQI ue_selected CQI not supported yet!!!\n");
-      mac_xface->macphy_exit("fill_CQI ue_selected CQI not supported yet!!!");
+      AssertFatal(1==0,"fill_CQI ue_selected CQI not supported yet!!!");
       break;
 
     default:
       LOG_E(PHY,"unsupported CQI mode (%d)!!!\n",uci_format);
-      mac_xface->macphy_exit("unsupported CQI mode !!!");
+      AssertFatal(1==0,"unsupported CQI mode !!!");
       break;
 
     }
@@ -7135,12 +8182,12 @@ void fill_CQI(LTE_UE_ULSCH_t *ulsch,PHY_MEASUREMENTS *meas,uint8_t eNB_id,uint8_
 
     case ue_selected:
       LOG_E(PHY,"fill_CQI ue_selected CQI not supported yet!!!\n");
-      mac_xface->macphy_exit("fill_CQI ue_selected CQI not supported yet!!!");
+      AssertFatal(1==0,"fill_CQI ue_selected CQI not supported yet!!!");
       break;
 
     default:
       LOG_E(PHY,"unsupported CQI mode (%d)!!!\n",uci_format);
-      mac_xface->macphy_exit("unsupported CQI mode !!!");
+      AssertFatal(1==0,"unsupported CQI mode !!!");
       break;
 
     }
@@ -8288,13 +9335,8 @@ int generate_eNB_ulsch_params_from_dci(PHY_VARS_eNB *eNB,
     }
 
     rb_alloc = rballoc;
-
-    if (rb_alloc>RIV_max) {
-      LOG_E(PHY,"Format 0: rb_alloc (%d) > RIV_max (%d)\n",rb_alloc,RIV_max);
-      mac_xface->macphy_exit("Format 0: error");
-      return(-1);
-    }
-
+    AssertFatal(rb_alloc>RIV_max,
+		"Format 0: rb_alloc (%d) > RIV_max (%d)\n",rb_alloc,RIV_max);
 #ifdef DEBUG_DCI
     printf("generate_eNB_ulsch_params_from_dci: subframe %d, rnti %x,harq_pid %d,cqi_req %d\n",subframe,rnti,harq_pid,cqi_req);
 #endif
diff --git a/openair1/PHY/LTE_TRANSPORT/defs.h b/openair1/PHY/LTE_TRANSPORT/defs.h
index a5975937a4048e04c14167257e325e2e4255d38d..e5f22d07335ff5f8394b435755b5b02a5b4ff56d 100644
--- a/openair1/PHY/LTE_TRANSPORT/defs.h
+++ b/openair1/PHY/LTE_TRANSPORT/defs.h
@@ -32,6 +32,7 @@
 #ifndef __LTE_TRANSPORT_DEFS__H__
 #define __LTE_TRANSPORT_DEFS__H__
 #include "PHY/defs.h"
+#include "PHY/impl_defs_lte.h"
 #include "dci.h"
 #include "uci.h"
 #ifndef STANDALONE_COMPILE
@@ -90,6 +91,8 @@
 #define PMI_2A_R1_11 1
 #define PMI_2A_R1_1j 2
 
+typedef enum { SEARCH_EXIST=0,
+	       SEARCH_EXIST_OR_FREE} find_type_t;
 
 typedef enum {
   SCH_IDLE,
@@ -104,6 +107,8 @@ typedef struct {
   SCH_status_t status;
   /// Transport block size
   uint32_t TBS;
+  /// pointer to pdu from MAC interface (this is "a" in 36.212)
+  uint8_t *pdu;
   /// The payload + CRC size in bits, "B" from 36-212
   uint32_t B;
   /// Pointer to the payload
@@ -253,12 +258,12 @@ typedef struct {
   uint16_t rnti;
   /// Active flag for baseband transmitter processing
   uint8_t active;
+  /// HARQ process mask, indicates which processes are currently active
+  uint16_t harq_mask;
   /// Indicator of TX activation per subframe.  Used during PUCCH detection for ACK/NAK.
   uint8_t subframe_tx[10];
   /// First CCE of last PDSCH scheduling per subframe.  Again used during PUCCH detection for ACK/NAK.
   uint8_t nCCE[10];
-  /// Current HARQ process id
-  uint8_t current_harq_pid;
   /// Process ID's per subframe.  Used to associate received ACKs on PUSCH/PUCCH to DLSCH harq process ids
   uint8_t harq_ids[10];
   /// Window size (in outgoing transport blocks) for fine-grain rate adaptation
@@ -482,6 +487,8 @@ typedef struct {
 } LTE_UL_eNB_HARQ_t;
 
 typedef struct {
+  /// HARQ process mask, indicates which processes are currently active
+  uint16_t harq_mask;
   /// Pointers to 8 HARQ processes for the ULSCH
   LTE_UL_eNB_HARQ_t *harq_processes[8];
   /// Maximum number of HARQ rounds
@@ -738,22 +745,7 @@ typedef struct {
   int8_t               g_pucch;
 } LTE_UE_DLSCH_t;
 
-typedef enum {format0,
-              format1,
-              format1A,
-              format1B,
-              format1C,
-              format1D,
-              format1E_2A_M10PRB,
-              format2,
-              format2A,
-              format2B,
-              format2C,
-              format2D,
-              format3,
-	      format3A,
-	      format4
-             } DCI_format_t;
+
 
 typedef enum {
   SI_PDSCH=0,
@@ -782,22 +774,6 @@ typedef enum {
 } PUCCH_FMT_t;
 
 
-typedef struct {
-  /// Length of DCI in bits
-  uint8_t dci_length;
-  /// Aggregation level
-  uint8_t L;
-  /// Position of first CCE of the dci
-  int firstCCE;
-  /// flag to indicate that this is a RA response
-  boolean_t ra_flag;
-  /// rnti
-  rnti_t rnti;
-  /// Format
-  DCI_format_t format;
-  /// DCI pdu
-  uint8_t dci_pdu[8];
-} DCI_ALLOC_t;
 
 
 /**@}*/
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
index 1186f5cfb49c233a2cf13bc6523c839675908013..e88b1e7beb824a16ae9652202f9336b4402b5e59 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_coding.c
@@ -274,9 +274,10 @@ int dlsch_encoding_2threads0(te_params *tep) {
 
   LTE_eNB_DLSCH_t *dlsch          = tep->dlsch;
   unsigned int G                  = tep->G;
+  unsigned char harq_pid          = tep->harq_pid;
 
   unsigned short iind;
-  unsigned char harq_pid = dlsch->current_harq_pid;
+
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
   unsigned int Kr=0,Kr_bytes,r,r_offset=0;
   unsigned short m=dlsch->harq_processes[harq_pid]->mcs;
@@ -394,7 +395,7 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
   unsigned int crc=1;
   unsigned short iind;
 
-  unsigned char harq_pid = dlsch->current_harq_pid;
+  unsigned char harq_pid = dlsch->harq_ids[subframe];
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
   unsigned int A;
   unsigned char mod_order;
@@ -446,6 +447,7 @@ int dlsch_encoding_2threads(PHY_VARS_eNB *eNB,
     proc->tep.eNB               = eNB;
     proc->tep.dlsch             = dlsch;
     proc->tep.G                 = G;
+    proc->tep.harq_pid          = harq_pid;
 
     // wakeup worker to do second half segments
     if (pthread_cond_signal(&proc->cond_te) != 0) {
@@ -577,7 +579,7 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
   unsigned short iind;
 
   LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
-  unsigned char harq_pid = dlsch->current_harq_pid;
+  unsigned char harq_pid = dlsch->harq_ids[subframe];
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
   unsigned int A;
   unsigned char mod_order;
@@ -739,22 +741,22 @@ int dlsch_encoding(PHY_VARS_eNB *eNB,
 
 
 int dlsch_encoding_SIC(PHY_VARS_UE *ue,
-                   unsigned char *a,
-                   uint8_t num_pdcch_symbols,
-                   LTE_eNB_DLSCH_t *dlsch,
-                   int frame,
-                   uint8_t subframe,
-                   time_stats_t *rm_stats,
-                   time_stats_t *te_stats,
-                   time_stats_t *i_stats)
+		       unsigned char *a,
+		       uint8_t num_pdcch_symbols,
+		       LTE_eNB_DLSCH_t *dlsch,
+		       int frame,
+		       uint8_t subframe,
+		       time_stats_t *rm_stats,
+		       time_stats_t *te_stats,
+		       time_stats_t *i_stats)
 {
-
+  
   unsigned int G;
   unsigned int crc=1;
   unsigned short iind;
 
   LTE_DL_FRAME_PARMS *frame_parms = &ue->frame_parms;
-  unsigned char harq_pid = dlsch->current_harq_pid;
+  unsigned char harq_pid = ue->dlsch[subframe&2][0][0]->rnti;
   unsigned short nb_rb = dlsch->harq_processes[harq_pid]->nb_rb;
   unsigned int A;
   unsigned char mod_order;
@@ -917,39 +919,4 @@ int dlsch_encoding_SIC(PHY_VARS_UE *ue,
 
 
 
-#ifdef PHY_ABSTRACTION
-void dlsch_encoding_emul(PHY_VARS_eNB *phy_vars_eNB,
-                         uint8_t *DLSCH_pdu,
-                         LTE_eNB_DLSCH_t *dlsch)
-{
-
-  //int payload_offset = 0;
-  unsigned char harq_pid = dlsch->current_harq_pid;
-  unsigned short i;
-
-  //  if (dlsch->harq_processes[harq_pid]->Ndi == 1) {
-  if (dlsch->harq_processes[harq_pid]->round == 0) {
-    memcpy(dlsch->harq_processes[harq_pid]->b,
-           DLSCH_pdu,
-           dlsch->harq_processes[harq_pid]->TBS>>3);
-    LOG_D(PHY, "eNB %d dlsch_encoding_emul, tbs is %d harq pid %d \n",
-          phy_vars_eNB->Mod_id,
-          dlsch->harq_processes[harq_pid]->TBS>>3,
-          harq_pid);
-
-    for (i=0; i<dlsch->harq_processes[harq_pid]->TBS>>3; i++)
-      LOG_T(PHY,"%x.",DLSCH_pdu[i]);
-
-    LOG_T(PHY,"\n");
-
-    memcpy(&eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].transport_blocks[eNB_transport_info_TB_index[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]],
-           //     memcpy(&eNB_transport_info[phy_vars_eNB->Mod_id].transport_blocks[payload_offset],
-           DLSCH_pdu,
-           dlsch->harq_processes[harq_pid]->TBS>>3);
-  }
 
-  eNB_transport_info_TB_index[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]+=dlsch->harq_processes[harq_pid]->TBS>>3;
-  //payload_offset +=dlsch->harq_processes[harq_pid]->TBS>>3;
-
-}
-#endif
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
index a83bc88af92cfd506a3b3f74704b96c8cda3f4b5..35b3bd3e3b94c6df9bda240caf39a6d263e3ea09 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
@@ -864,6 +864,7 @@ int dlsch_abstraction_MIESM(double* sinr_dB,uint8_t TM, uint32_t rb_alloc[4], ui
 #endif
 }
 
+/*
 uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
                              uint8_t subframe,
                              PDSCH_t dlsch_id,
@@ -886,10 +887,8 @@ uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
       break;
   }
 
-  if (eNB_id2==NB_eNB_INST) {
-    LOG_E(PHY,"FATAL : Could not find attached eNB for DLSCH emulation !!!!\n");
-    mac_xface->macphy_exit("Could not find attached eNB for DLSCH emulation");
-  }
+  AssertFatal(eNB_id2!=NB_eNB_INST,
+              "FATAL : Could not find attached eNB for DLSCH emulation !!!!\n");
 
   LOG_D(PHY,"[UE] dlsch_decoding_emul : subframe %d, eNB_id %d, dlsch_id %d\n",subframe,eNB_id2,dlsch_id);
 
@@ -1008,10 +1007,10 @@ uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
     printf("\n");
 #endif
 
-    /*
-      if (dlsch_abstraction_MIESM(phy_vars_ue->sinr_dB, phy_vars_ue->transmission_mode[eNB_id], dlsch_eNB->rb_alloc,
-        dlsch_eNB->harq_processes[0]->mcs,RC.eNB[eNB_id]->mu_mimo_mode[ue_id].dl_pow_off) == 1) {
-    */
+    
+    //  if (dlsch_abstraction_MIESM(phy_vars_ue->sinr_dB, phy_vars_ue->transmission_mode[eNB_id], dlsch_eNB->rb_alloc,
+    //    dlsch_eNB->harq_processes[0]->mcs,RC.eNB[eNB_id]->mu_mimo_mode[ue_id].dl_pow_off) == 1) {
+    
     if (1) {
       // reset HARQ
       dlsch_ue->harq_processes[0]->status = SCH_IDLE;
@@ -1038,5 +1037,6 @@ uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
 
   LOG_E(PHY,"[FATAL] dlsch_decoding.c: Should never exit here ...\n");
   return(0);
-}
+  }*/
 #endif
+
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
index 0fce0184d92188b6c47e3322e8c830cb2c8ba8ea..187535ef25ec3e581c3c21399aa8bcd7ef3d9c72 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_modulation.c
@@ -2062,7 +2062,7 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
 
   if ((dlsch0 != NULL) && (dlsch1 != NULL)){
 
-    harq_pid = dlsch0->current_harq_pid;
+    harq_pid = dlsch0->harq_ids[subframe_offset];
     dlsch0_harq = dlsch0->harq_processes[harq_pid];
     mimo_mode = dlsch0_harq->mimo_mode;
     mod_order0 = get_Qm(dlsch0_harq->mcs);
@@ -2079,7 +2079,7 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
 
   }else if ((dlsch0 != NULL) && (dlsch1 == NULL)){
 
-    harq_pid = dlsch0->current_harq_pid;
+    harq_pid = dlsch0->harq_ids[subframe_offset];
     dlsch0_harq = dlsch0->harq_processes[harq_pid];
     mimo_mode = dlsch0_harq->mimo_mode;
     mod_order0 = get_Qm(dlsch0_harq->mcs);
@@ -2096,7 +2096,7 @@ int dlsch_modulation(PHY_VARS_eNB* phy_vars_eNB,
 
   }else if ((dlsch0 == NULL) && (dlsch1 != NULL)){
 
-    harq_pid = dlsch1->current_harq_pid;
+    harq_pid = dlsch1->harq_ids[subframe_offset];
     dlsch1_harq = dlsch1->harq_processes[harq_pid];
     mimo_mode = dlsch1_harq->mimo_mode;
     mod_order0 = get_Qm(dlsch1_harq->mcs);
@@ -2454,7 +2454,7 @@ int dlsch_modulation_SIC(int32_t **sic_buffer,
                          int G)
 {
 
-  uint8_t harq_pid = dlsch0->current_harq_pid;
+  uint8_t harq_pid = -1;//dlsch0->current_harq_pid;
   LTE_DL_eNB_HARQ_t *dlsch0_harq = dlsch0->harq_processes[harq_pid];
   uint32_t i,jj,re_allocated=0;
   uint8_t mod_order0 = get_Qm(dlsch0_harq->mcs);
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c b/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c
index 079cfcbc529f9020f2fea4d209dae11a9bbf0bb9..eaaddb0c073d6dece0a9bc1ce59ce9654536f0ca 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_scrambling.c
@@ -71,6 +71,7 @@ static inline unsigned int lte_gold_scram(unsigned int *x1, unsigned int *x2, un
 void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
                       int mbsfn_flag,
                       LTE_eNB_DLSCH_t *dlsch,
+		      int harq_pid,
                       int G,
                       uint8_t q,
                       uint8_t Ns)
@@ -79,7 +80,7 @@ void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
   int i;
   //  uint8_t reset;
   uint32_t x1, x2, s=0;
-  uint8_t *dlsch_e=dlsch->harq_processes[dlsch->current_harq_pid]->e;
+  uint8_t *dlsch_e=dlsch->harq_processes[harq_pid]->e;
   uint8_t *e=dlsch_e;
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_SCRAMBLING, VCD_FUNCTION_IN);
diff --git a/openair1/PHY/LTE_TRANSPORT/initial_sync.c b/openair1/PHY/LTE_TRANSPORT/initial_sync.c
index 612d69063967945994f3bf364a23db70c4b1a133..1a609a618d277e86cf9b1d4e421269d6be9fed82 100644
--- a/openair1/PHY/LTE_TRANSPORT/initial_sync.c
+++ b/openair1/PHY/LTE_TRANSPORT/initial_sync.c
@@ -489,7 +489,7 @@ int initial_sync(PHY_VARS_UE *ue, runmode_t mode)
       if (ue->mac_enabled==1) {
 	LOG_I(PHY,"[UE%d] Sending synch status to higher layers\n",ue->Mod_id);
 	//mac_resynch();
-	mac_xface->dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
+	dl_phy_sync_success(ue->Mod_id,ue->proc.proc_rxtx[0].frame_rx,0,1);//ue->common_vars.eNb_id);
 	ue->UE_mode[0] = PRACH;
       }
       else {
diff --git a/openair1/PHY/LTE_TRANSPORT/lte_mcs.c b/openair1/PHY/LTE_TRANSPORT/lte_mcs.c
index 8f8bc80b1e7140067ad0c950773d3f9ce7288d3e..bf206bd318492d65163d3605d53a68053c75f5a0 100644
--- a/openair1/PHY/LTE_TRANSPORT/lte_mcs.c
+++ b/openair1/PHY/LTE_TRANSPORT/lte_mcs.c
@@ -113,13 +113,8 @@ uint32_t get_TBS_DL(uint8_t mcs, uint16_t nb_rb)
   uint32_t TBS;
 
   if ((nb_rb > 0) && (mcs < 29)) {
-#ifdef TBS_FIX
-    TBS = 3*TBStable[get_I_TBS(mcs)][nb_rb-1]/4;
-    TBS = TBS>>3;
-#else
     TBS = TBStable[get_I_TBS(mcs)][nb_rb-1];
     TBS = TBS>>3;
-#endif
     return(TBS);
   } else {
     return(uint32_t)0;
@@ -132,13 +127,8 @@ uint32_t get_TBS_UL(uint8_t mcs, uint16_t nb_rb)
   uint32_t TBS = 0;
 
   if ((nb_rb > 0) && (mcs < 29)) {
-#ifdef TBS_FIX
-    TBS = 3*TBStable[get_I_TBS_UL(mcs)][nb_rb-1]/4;
-    TBS = TBS>>3;
-#else
     TBS = TBStable[get_I_TBS_UL(mcs)][nb_rb-1];
     TBS = TBS>>3;
-#endif
     return(TBS);
   } else {
     return(uint32_t)0;
diff --git a/openair1/PHY/LTE_TRANSPORT/pbch.c b/openair1/PHY/LTE_TRANSPORT/pbch.c
index 41fccbc5619141a8da2130a54a5c6428a46e7d9d..cc11afd2dc35f20c55a84c199c54d38a51d468b1 100644
--- a/openair1/PHY/LTE_TRANSPORT/pbch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pbch.c
@@ -46,9 +46,6 @@
 //#define DEBUG_PBCH_ENCODING
 //#define INTERFERENCE_MITIGATION 1
 
-#ifdef OPENAIR2
-#include "PHY_INTERFACE/defs.h"
-#endif
 
 #define PBCH_A 24
 
@@ -210,12 +207,12 @@ int generate_pbch(LTE_eNB_PBCH *eNB_pbch,
 
     //  pbch_data[i] = ((char*) &crc)[0];
     //  pbch_data[i+1] = ((char*) &crc)[1];
-#ifdef DEBUG_PBCH
+    //#ifdef DEBUG_PBCH
 
     for (i=0; i<(PBCH_A>>3); i++)
-      LOG_D(PHY,"[PBCH] pbch_data[%d] = %x\n",i,pbch_a[i]);
+      LOG_I(PHY,"[PBCH] pbch_data[%d] = %x\n",i,pbch_a[i]);
 
-#endif
+    //#endif
 
     if (frame_parms->nb_antenna_ports_eNB == 1)
       amask = 0x0000;
diff --git a/openair1/PHY/LTE_TRANSPORT/phich.c b/openair1/PHY/LTE_TRANSPORT/phich.c
index dd32fc73c6267beec737bd0805a2867497f9ddfb..558ff580de7c06358b954b1ba979bcec98557b75 100644
--- a/openair1/PHY/LTE_TRANSPORT/phich.c
+++ b/openair1/PHY/LTE_TRANSPORT/phich.c
@@ -318,17 +318,17 @@ void generate_phich_reg_mapping(LTE_DL_FRAME_PARMS *frame_parms)
     Ngroup_PHICH<<=1;
   }
 
-  #ifdef DEBUG_PHICH
-  printf("Ngroup_PHICH %d (phich_config_common.phich_resource %d,phich_config_common.phich_duration %s, NidCell %d,Ncp %d, frame_type %d), smallest pcfich REG %d, n0 %d, n1 %d (first PHICH REG %d)\n",
-	 ((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)),
-	 frame_parms->phich_config_common.phich_resource,
-	 frame_parms->phich_config_common.phich_duration==normal?"normal":"extended",
-	 frame_parms->Nid_cell,frame_parms->Ncp,frame_parms->frame_type,
-	 pcfich_reg[frame_parms->pcfich_first_reg_idx],
-	 n0,
-	 n1,
-	 ((frame_parms->Nid_cell))%n0);
-  #endif
+  //  #ifdef DEBUG_PHICH
+  LOG_I(PHY,"Ngroup_PHICH %d (phich_config_common.phich_resource %d,phich_config_common.phich_duration %s, NidCell %d,Ncp %d, frame_type %d), smallest pcfich REG %d, n0 %d, n1 %d (first PHICH REG %d)\n",
+    ((frame_parms->Ncp == NORMAL)?Ngroup_PHICH:(Ngroup_PHICH>>1)),
+    frame_parms->phich_config_common.phich_resource,
+    frame_parms->phich_config_common.phich_duration==normal?"normal":"extended",
+    frame_parms->Nid_cell,frame_parms->Ncp,frame_parms->frame_type,
+    pcfich_reg[frame_parms->pcfich_first_reg_idx],
+    n0,
+    n1,
+    ((frame_parms->Nid_cell))%n0);
+//#endif
 
   // This is the algorithm from Section 6.9.3 in 36-211, it works only for normal PHICH duration for now ...
 
@@ -1394,7 +1394,7 @@ void rx_phich(PHY_VARS_UE *ue,
 
       if (ulsch->harq_processes[harq_pid]->round>=ue->frame_parms.maxHARQ_Msg3Tx) {
         ulsch->harq_processes[harq_pid]->subframe_scheduling_flag =0;
-        ulsch->harq_processes[harq_pid]->status = IDLE;
+        ulsch->harq_processes[harq_pid]->status = SCH_IDLE;
         // inform MAC that Msg3 transmission has failed
         ue->ulsch_Msg3_active[eNB_id] = 0;
       }
@@ -1423,7 +1423,7 @@ void rx_phich(PHY_VARS_UE *ue,
           ulsch->uci_format = HLC_subband_cqi_nopmi;
 
           // disable phich decoding since it is the last retransmission
-          ulsch->harq_processes[harq_pid]->status = IDLE;
+          ulsch->harq_processes[harq_pid]->status = SCH_IDLE;
 
           //ulsch->harq_processes[harq_pid]->subframe_scheduling_flag = 0;
           //ulsch->harq_processes[harq_pid]->round  = 0;
@@ -1474,7 +1474,7 @@ void rx_phich(PHY_VARS_UE *ue,
     //ulsch->harq_processes[8] = ulsch->harq_processes[harq_pid];
 
     ulsch->harq_processes[harq_pid]->subframe_scheduling_flag =0;
-    ulsch->harq_processes[harq_pid]->status = IDLE;
+    ulsch->harq_processes[harq_pid]->status = SCH_IDLE;
     ulsch->harq_processes[harq_pid]->round  = 0;
     // inform MAC?
     ue->ulsch_Msg3_active[eNB_id] = 0;
diff --git a/openair1/PHY/LTE_TRANSPORT/pmch.c b/openair1/PHY/LTE_TRANSPORT/pmch.c
index 033948ebf930dbb70d11bce1b0df0e61278196f2..3aa14d924ca6c93f323731282a7b2bf7f96bcc27 100644
--- a/openair1/PHY/LTE_TRANSPORT/pmch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pmch.c
@@ -196,7 +196,7 @@ void fill_eNB_dlsch_MCH(PHY_VARS_eNB *eNB,int mcs,int ndi,int rvidx)
   dlsch->harq_processes[0]->rvidx = rvidx;
   dlsch->harq_processes[0]->Nl    = 1;
   dlsch->harq_processes[0]->TBS   = TBStable[get_I_TBS(dlsch->harq_processes[0]->mcs)][frame_parms->N_RB_DL-1];
-  dlsch->current_harq_pid = 0;
+  //  dlsch->harq_ids[subframe]       = 0;
   dlsch->harq_processes[0]->nb_rb = frame_parms->N_RB_DL;
 
   switch(frame_parms->N_RB_DL) {
@@ -313,7 +313,7 @@ void generate_mch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,uint8_t *a)
                          AMP);
 
 
-    if (dlsch_encoding(eNB,
+    AssertFatal(dlsch_encoding(eNB,
 		       a,
                        1,
                        eNB->dlsch_MCH,
@@ -321,11 +321,10 @@ void generate_mch(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,uint8_t *a)
                        subframe,
                        &eNB->dlsch_rate_matching_stats,
                        &eNB->dlsch_turbo_encoding_stats,
-                       &eNB->dlsch_interleaving_stats
-                      )<0)
-      mac_xface->macphy_exit("problem in dlsch_encoding");
+                       &eNB->dlsch_interleaving_stats)==0,
+		"problem in dlsch_encoding");
 
-    dlsch_scrambling(&eNB->frame_parms,1,eNB->dlsch_MCH,G,0,subframe<<1);
+    dlsch_scrambling(&eNB->frame_parms,1,eNB->dlsch_MCH,0,G,0,subframe<<1);
 
 
     mch_modulation(eNB->common_vars.txdataF,
diff --git a/openair1/PHY/LTE_TRANSPORT/prach.c b/openair1/PHY/LTE_TRANSPORT/prach.c
index db5c5a4eaff8f43b4046f33d8099d29bfdc55a38..fd7f8ab3e01eb8f8dfbe1bd850eeab318b698878 100644
--- a/openair1/PHY/LTE_TRANSPORT/prach.c
+++ b/openair1/PHY/LTE_TRANSPORT/prach.c
@@ -393,16 +393,16 @@ void fill_du(uint8_t prach_fmt)
 
 }
 
-uint8_t get_num_prach_tdd(LTE_DL_FRAME_PARMS *frame_parms)
+uint8_t get_num_prach_tdd(module_id_t Mod_id)
 {
-
-  return(tdd_preamble_map[frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex][frame_parms->tdd_config].num_prach);
+  LTE_DL_FRAME_PARMS *fp = &PHY_vars_UE_g[Mod_id][0]->frame_parms;
+  return(tdd_preamble_map[fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex][fp->tdd_config].num_prach);
 }
 
-uint8_t get_fid_prach_tdd(LTE_DL_FRAME_PARMS *frame_parms,uint8_t tdd_map_index)
+uint8_t get_fid_prach_tdd(module_id_t Mod_id,uint8_t tdd_map_index)
 {
-
-  return(tdd_preamble_map[frame_parms->prach_config_common.prach_ConfigInfo.prach_ConfigIndex][frame_parms->tdd_config].map[tdd_map_index].f_ra);
+  LTE_DL_FRAME_PARMS *fp = &PHY_vars_UE_g[Mod_id][0]->frame_parms;
+  return(tdd_preamble_map[fp->prach_config_common.prach_ConfigInfo.prach_ConfigIndex][fp->tdd_config].map[tdd_map_index].f_ra);
 }
 
 uint8_t get_prach_fmt(uint8_t prach_ConfigIndex,lte_frame_type_t frame_type)
@@ -656,20 +656,12 @@ int32_t generate_prach( PHY_VARS_UE *ue, uint8_t eNB_id, uint8_t subframe, uint1
 
   // First compute physical root sequence
   if (restricted_set == 0) {
-    if (Ncs_config > 15) {
-      LOG_E( PHY, "[PHY] FATAL, Illegal Ncs_config for unrestricted format %"PRIu8"\n", Ncs_config );
-      mac_xface->macphy_exit("PRACH: Illegal Ncs_config for unrestricted format");
-      return 0; // not reached
-    }
-
+    AssertFatal(Ncs_config <= 15,
+		"[PHY] FATAL, Illegal Ncs_config for unrestricted format %"PRIu8"\n", Ncs_config );
     NCS = NCS_unrestricted[Ncs_config];
   } else {
-    if (Ncs_config > 14) {
-      LOG_E( PHY, "[PHY] FATAL, Illegal Ncs_config for restricted format %"PRIu8"\n", Ncs_config );
-      mac_xface->macphy_exit("PRACH: Illegal Ncs_config for restricted format");
-      return 0; // not reached
-    }
-
+    AssertFatal(Ncs_config <= 14,
+		"[PHY] FATAL, Illegal Ncs_config for restricted format %"PRIu8"\n", Ncs_config );
     NCS = NCS_restricted[Ncs_config];
   }
 
@@ -1036,47 +1028,44 @@ int32_t generate_prach( PHY_VARS_UE *ue, uint8_t eNB_id, uint8_t subframe, uint1
 
   //LOG_D(PHY,"prach_len=%d\n",prach_len);
 
-  if (prach_fmt==4) {
-    LOG_E( PHY, "prach_fmt4 not fully implemented" );
-    mac_xface->macphy_exit("prach_fmt4 not fully implemented");
-    return 0; // not reached
-  } else {
+  AssertFatal(prach_fmt<4,
+	      "prach_fmt4 not fully implemented" );
 #if defined(EXMIMO) || defined(OAI_USRP)
-    int j;
-    int overflow = prach_start + prach_len - LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*ue->frame_parms.samples_per_tti;
-    LOG_D( PHY, "prach_start=%d, overflow=%d\n", prach_start, overflow );
-
-    for (i=prach_start,j=0; i<min(ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME,prach_start+prach_len); i++,j++) {
-      ((int16_t*)ue->common_vars.txdata[0])[2*i] = prach[2*j]<<4;
-      ((int16_t*)ue->common_vars.txdata[0])[2*i+1] = prach[2*j+1]<<4;
-    }
-
-    for (i=0; i<overflow; i++,j++) {
-      ((int16_t*)ue->common_vars.txdata[0])[2*i] = prach[2*j]<<4;
-      ((int16_t*)ue->common_vars.txdata[0])[2*i+1] = prach[2*j+1]<<4;
-    }
+  int j;
+  int overflow = prach_start + prach_len - LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*ue->frame_parms.samples_per_tti;
+  LOG_D( PHY, "prach_start=%d, overflow=%d\n", prach_start, overflow );
+  
+  for (i=prach_start,j=0; i<min(ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME,prach_start+prach_len); i++,j++) {
+    ((int16_t*)ue->common_vars.txdata[0])[2*i] = prach[2*j]<<4;
+    ((int16_t*)ue->common_vars.txdata[0])[2*i+1] = prach[2*j+1]<<4;
+  }
+  
+  for (i=0; i<overflow; i++,j++) {
+    ((int16_t*)ue->common_vars.txdata[0])[2*i] = prach[2*j]<<4;
+    ((int16_t*)ue->common_vars.txdata[0])[2*i+1] = prach[2*j+1]<<4;
+  }
 #if defined(EXMIMO)
-    // handle switch before 1st TX subframe, guarantee that the slot prior to transmission is switch on
-    for (k=prach_start - (ue->frame_parms.samples_per_tti>>1) ; k<prach_start ; k++) {
-      if (k<0)
-	ue->common_vars.txdata[0][k+ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
-      else if (k>(ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME))
-	ue->common_vars.txdata[0][k-ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
-      else
-	ue->common_vars.txdata[0][k] &= 0xFFFEFFFE;
-    }
+  // handle switch before 1st TX subframe, guarantee that the slot prior to transmission is switch on
+  for (k=prach_start - (ue->frame_parms.samples_per_tti>>1) ; k<prach_start ; k++) {
+    if (k<0)
+      ue->common_vars.txdata[0][k+ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
+    else if (k>(ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME))
+      ue->common_vars.txdata[0][k-ue->frame_parms.samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME] &= 0xFFFEFFFE;
+    else
+      ue->common_vars.txdata[0][k] &= 0xFFFEFFFE;
+  }
 #endif
 #else
-    
-    for (i=0; i<prach_len; i++) {
-      ((int16_t*)(&ue->common_vars.txdata[0][prach_start]))[2*i] = prach[2*i];
-      ((int16_t*)(&ue->common_vars.txdata[0][prach_start]))[2*i+1] = prach[2*i+1];
-    }
-
-#endif
+  
+  for (i=0; i<prach_len; i++) {
+    ((int16_t*)(&ue->common_vars.txdata[0][prach_start]))[2*i] = prach[2*i];
+    ((int16_t*)(&ue->common_vars.txdata[0][prach_start]))[2*i+1] = prach[2*i+1];
   }
+  
+#endif
+  
 
-
+  
 #if 0
   write_output("prach_txF0.m","prachtxF0",prachF,prach_len-Ncp,1,1);
   write_output("prach_tx0.m","prachtx0",prach+(Ncp<<1),prach_len-Ncp,1,1);
@@ -1184,20 +1173,12 @@ void rx_prach(PHY_VARS_eNB *eNB,
 
   // First compute physical root sequence
   if (restricted_set == 0) {
-    if (Ncs_config>15) {
-      LOG_E(PHY,"FATAL, Illegal Ncs_config for unrestricted format %d\n",Ncs_config);
-      mac_xface->macphy_exit("PRACH Illegal Ncs_config for unrestricted format");
-      return; // not reached
-    }
-
+    AssertFatal(Ncs_config<=15,
+		"Illegal Ncs_config for unrestricted format %d\n",Ncs_config);
     NCS = NCS_unrestricted[Ncs_config];
   } else {
-    if (Ncs_config>14) {
-      LOG_E(PHY,"FATAL, Illegal Ncs_config for restricted format %d\n",Ncs_config);
-      mac_xface->macphy_exit("PRACH Illegal Ncs_config for restricted format");
-      return; // not reached
-    }
-
+    AssertFatal(Ncs_config<=14,
+		"FATAL, Illegal Ncs_config for restricted format %d\n",Ncs_config);
     NCS = NCS_restricted[Ncs_config];
   }
 
@@ -1654,12 +1635,8 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
   LOG_I(PHY,"compute_prach_seq: NCS_config %d, prach_fmt %d\n",prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig, prach_fmt);
 #endif
 
-  if (prach_fmt>=4) {
-    LOG_E( PHY, "PRACH sequence is only precomputed for prach_fmt<4 (have %"PRIu8")\n", prach_fmt );
-    mac_xface->macphy_exit("PRACH sequence is only precomputed for prach_fmt<4");
-    return; // not reached
-  }
-
+  AssertFatal(prach_fmt<4,
+	      "PRACH sequence is only precomputed for prach_fmt<4 (have %"PRIu8")\n", prach_fmt );
   N_ZC = (prach_fmt < 4) ? 839 : 139;
   //init_prach_tables(N_ZC); //moved to phy_init_lte_ue/eNB, since it takes to long in real-time
 
@@ -1681,13 +1658,9 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
     LOG_I(PHY,"Low speed prach : NCS_config %d\n",prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig);
 #endif
 
-    if (prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig>15) {
-      LOG_E( PHY, "FATAL, Illegal Ncs_config for unrestricted format %"PRIu8"\n", prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig );
-      mac_xface->macphy_exit("PRACH Illegal Ncs_config for unrestricted format");
-      return; // not reached
-    } else {
-      NCS = NCS_unrestricted[prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig];
-    }
+    AssertFatal(prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig<=15,
+		"FATAL, Illegal Ncs_config for unrestricted format %"PRIu8"\n", prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig );
+    NCS = NCS_unrestricted[prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig];
 
     num_preambles = (NCS==0) ? 64 : ((64*NCS)/N_ZC);
 
@@ -1700,14 +1673,10 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
     LOG_I( PHY, "high speed prach : NCS_config %"PRIu8"\n", prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig );
 #endif
 
-    if (prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig>14) {
-      LOG_E( PHY, "FATAL, Illegal Ncs_config for restricted format %"PRIu8"\n", prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig );
-      mac_xface->macphy_exit("PRACH Illegal Ncs_config for restricted format");
-      return; // not reached
-    } else {
-      NCS = NCS_restricted[prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig];
-      fill_du(prach_fmt);
-    }
+    AssertFatal(prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig<=14,
+		"FATAL, Illegal Ncs_config for restricted format %"PRIu8"\n", prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig );
+    NCS = NCS_restricted[prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig];
+    fill_du(prach_fmt);
 
     num_preambles = 64; // compute ZC sequence for 64 possible roots
     // find first non-zero shift root (stored in preamble_offset)
diff --git a/openair1/PHY/LTE_TRANSPORT/proto.h b/openair1/PHY/LTE_TRANSPORT/proto.h
index 18f5da08fd0c3725a7162b5691d1ec5cd5403136..950be1e9a868c2179caacd50ec89ff3635a612c6 100644
--- a/openair1/PHY/LTE_TRANSPORT/proto.h
+++ b/openair1/PHY/LTE_TRANSPORT/proto.h
@@ -33,6 +33,7 @@
 #define __LTE_TRANSPORT_PROTO__H__
 #include "PHY/defs.h"
 #include <math.h>
+#include "nfapi_interface.h"
 
 // Functions below implement 36-211 and 36-212
 
@@ -1402,8 +1403,7 @@ void dci_encoding(uint8_t *a,
                   uint16_t rnti);
 
 /*! \brief Top-level DCI entry point. This routine codes an set of DCI PDUs and performs PDCCH modulation, interleaving and mapping.
-  \param num_ue_spec_dci  Number of UE specific DCI pdus to encode
-  \param num_common_dci Number of Common DCI pdus to encode
+  \param num_dci  Number of DCI pdus to encode
   \param dci_alloc Allocation vectors for each DCI pdu
   \param n_rnti n_RNTI (see )
   \param amp Amplitude of QPSK symbols
@@ -1412,8 +1412,7 @@ void dci_encoding(uint8_t *a,
   \param sub_frame_offset subframe offset in frame
   @returns Number of PDCCH symbols
 */
-uint8_t generate_dci_top(uint8_t num_ue_spec_dci,
-                         uint8_t num_common_dci,
+uint8_t generate_dci_top(uint8_t num_dci,
                          DCI_ALLOC_t *dci_alloc,
                          uint32_t n_rnti,
                          int16_t amp,
@@ -1655,6 +1654,17 @@ int generate_ue_dlsch_params_from_dci(int frame,
                                       uint8_t beamforming_mode,
                                       uint16_t tc_rnti);
 
+int fill_dci_and_dlsch(PHY_VARS_eNB *eNB,
+			eNB_rxtx_proc_t *proc,
+			DCI_ALLOC_t *dci_alloc,
+			nfapi_dl_config_dci_dl_pdu *pdu);
+
+
+int fill_dci_and_ulsch(PHY_VARS_eNB *eNB,
+			eNB_rxtx_proc_t *proc,
+			DCI_ALLOC_t *dci_alloc,
+			nfapi_hi_dci0_dci_pdu *pdu);
+
 int32_t generate_eNB_dlsch_params_from_dci(int frame,
     uint8_t subframe,
     void *dci_pdu,
@@ -1959,6 +1969,7 @@ void pdcch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
 void dlsch_scrambling(LTE_DL_FRAME_PARMS *frame_parms,
                       int mbsfn_flag,
                       LTE_eNB_DLSCH_t *dlsch,
+		      int hard_pid,
                       int G,
                       uint8_t q,
                       uint8_t Ns);
@@ -2076,7 +2087,7 @@ void rx_prach(PHY_VARS_eNB *phy_vars_eNB,RU_t *ru,uint16_t *preamble_energy_list
   @param frame_parms Pointer to LTE_DL_FRAME_PARMS structure
   @returns 0-5 depending on number of available prach
 */
-uint8_t get_num_prach_tdd(LTE_DL_FRAME_PARMS *frame_parms);
+uint8_t get_num_prach_tdd(module_id_t Mod_id);
 
 /*!
   \brief Return the PRACH format as a function of the Configuration Index and Frame type.
@@ -2091,7 +2102,7 @@ uint8_t get_prach_fmt(uint8_t prach_ConfigIndex,lte_frame_type_t frame_type);
   @param frame_parms Pointer to LTE_DL_FRAME_PARMS structure
   @returns 0-5 depending on number of available prach
 */
-uint8_t get_fid_prach_tdd(LTE_DL_FRAME_PARMS *frame_parms,uint8_t tdd_map_index);
+uint8_t get_fid_prach_tdd(module_id_t Mod_id,uint8_t tdd_map_index);
 
 /*!
   \brief Comp ute DFT of PRACH ZC sequences.  Used for generation of prach in UE and reception of PRACH in eNB.
@@ -2161,5 +2172,10 @@ uint8_t get_prach_prb_offset(LTE_DL_FRAME_PARMS *frame_parms, uint8_t tdd_mapind
 
 uint8_t ul_subframe2pdcch_alloc_subframe(LTE_DL_FRAME_PARMS *frame_parms,uint8_t n);
 
+
+int8_t find_dlsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type);
+
+int8_t find_ulsch(uint16_t rnti, PHY_VARS_eNB *eNB,find_type_t type);
+
 /**@}*/
 #endif
diff --git a/openair1/PHY/LTE_TRANSPORT/rar_tools.c b/openair1/PHY/LTE_TRANSPORT/rar_tools.c
index 72413420c37a023f6ff44d576e5917f4d2933cbd..fe552653cd571791ffc5f9012837ab49d6a7df6e 100644
--- a/openair1/PHY/LTE_TRANSPORT/rar_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/rar_tools.c
@@ -314,10 +314,10 @@ int generate_ue_ulsch_params_from_rar(PHY_VARS_UE *ue,
 
   // initialize power control based on PRACH power
   ulsch->f_pusch = delta_PUSCH_msg2[ulsch->harq_processes[harq_pid]->TPC] +
-                   mac_xface->get_deltaP_rampup(ue->Mod_id,ue->CC_id);
+                   get_deltaP_rampup(ue->Mod_id,ue->CC_id);
   LOG_D(PHY,"[UE %d][PUSCH PC] Initializing f_pusch to %d dB, TPC %d (delta_PUSCH_msg2 %d dB), deltaP_rampup %d dB\n",
         ue->Mod_id,ulsch->f_pusch,ulsch->harq_processes[harq_pid]->TPC,delta_PUSCH_msg2[ulsch->harq_processes[harq_pid]->TPC],
-        mac_xface->get_deltaP_rampup(ue->Mod_id,ue->CC_id));
+        get_deltaP_rampup(ue->Mod_id,ue->CC_id));
 
 
   //#ifdef DEBUG_RAR
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
index 51a9d1e9469d8862088c2d17fb9fe32640d2e8a1..c9cb1a18c02ed1b06d8e4c93bba03ad7496dbfd1 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
@@ -954,21 +954,18 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
     sumKr += Kr;
   }
 
-  if (sumKr==0) {
-    LOG_N(PHY,"[eNB %d] ulsch_decoding.c: FATAL sumKr is 0!\n",eNB->Mod_id);
-    LOG_D(PHY,"ulsch_decoding (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, mcs %d, O_RI %d, O_ACK %d, G %d, subframe %d\n",
-          frame_parms->Nid_cell,ulsch->rnti,x2,
-          harq_pid,
-          ulsch_harq->round,
-          ulsch_harq->rvidx,
-          ulsch_harq->mcs,
-          ulsch_harq->O_RI,
-          ulsch_harq->O_ACK,
-          G,
-          subframe);
-    mac_xface->macphy_exit("ulsch_decoding.c: FATAL sumKr is 0!");
-    return(-1);
-  }
+  AssertFatal(sumKr>0,
+	      "[eNB %d] ulsch_decoding.c: FATAL sumKr is 0! (Nid_cell %d, rnti %x, x2 %x): harq_pid %d round %d, RV %d, mcs %d, O_RI %d, O_ACK %d, G %d, subframe %d\n",
+	      frame_parms->Nid_cell,ulsch->rnti,x2,
+	      harq_pid,
+	      ulsch_harq->round,
+	      ulsch_harq->rvidx,
+	      ulsch_harq->mcs,
+	      ulsch_harq->O_RI,
+	      ulsch_harq->O_ACK,
+	      G,
+	      subframe);
+
 
   // Compute Q_ri
   Qprime = ulsch_harq->O_RI*ulsch_harq->Msc_initial*ulsch_harq->Nsymb_initial * ulsch->beta_offset_ri_times8;
diff --git a/openair1/PHY/defs.h b/openair1/PHY/defs.h
index db95d787bd040da83c16fdef7221446359802ded..7040bbaa9751e7917ae405a7d1c686db78f0f549 100644
--- a/openair1/PHY/defs.h
+++ b/openair1/PHY/defs.h
@@ -57,6 +57,8 @@
 #include "common_lib.h"
 #include "msc.h"
 
+#include "openair2/PHY_INTERFACE/IF_Module.h"
+
 //#include <complex.h>
 #include "assertions.h"
 #ifdef MEX
@@ -270,6 +272,7 @@ typedef struct {
   struct PHY_VARS_eNB_s *eNB;
   LTE_eNB_DLSCH_t *dlsch;
   int G;
+  int harq_pid;
 } te_params;
 
 typedef struct RU_proc_t_s {
@@ -805,6 +808,10 @@ typedef struct PHY_VARS_eNB_s {
   int                  abstraction_flag;
   int                  num_RU;
   RU_t                 *RU_list[MAX_NUM_RU_PER_eNB];
+  /// Ethernet parameters for northbound midhaul interface
+  eth_params_t         eth_params_n;
+  /// Ethernet parameters for fronthaul interface
+  eth_params_t         eth_params;
   int                  rx_total_gain_dB;
   //  void                 (*do_prach)(struct PHY_VARS_eNB_s *eNB,struct RU_t_s *ru,int frame, int subframe);
   int                  (*td)(struct PHY_VARS_eNB_s *eNB,int UE_id,int harq_pid,int llr8_flag);
@@ -817,7 +824,11 @@ typedef struct PHY_VARS_eNB_s {
   //  void                 (*fh_asynch)(struct PHY_VARS_eNB_s *eNB,int *frame, int *subframe);
   uint8_t              local_flag;
   LTE_DL_FRAME_PARMS   frame_parms;
-  PHY_MEASUREMENTS_eNB measurements; 
+  PHY_MEASUREMENTS_eNB measurements;
+  IF_Module_t          *if_inst;
+  UL_IND_t             UL_INFO;
+  Sched_Rsp_t          Sched_INFO;
+  LTE_eNB_PDCCH        pdcch_vars[2];
   LTE_eNB_COMMON       common_vars;
   LTE_eNB_SRS          srs_vars[NUMBER_OF_UE_MAX];
   LTE_eNB_PBCH         pbch;
@@ -825,7 +836,7 @@ typedef struct PHY_VARS_eNB_s {
   LTE_eNB_PRACH        prach_vars;
   LTE_eNB_DLSCH_t     *dlsch[NUMBER_OF_UE_MAX][2];   // Nusers times two spatial streams
   LTE_eNB_ULSCH_t     *ulsch[NUMBER_OF_UE_MAX+1];      // Nusers + number of RA
-  LTE_eNB_DLSCH_t     *dlsch_SI,*dlsch_ra;
+  LTE_eNB_DLSCH_t     *dlsch_SI,*dlsch_ra,*dlsch_p;
   LTE_eNB_DLSCH_t     *dlsch_MCH;
   LTE_eNB_UE_stats     UE_stats[NUMBER_OF_UE_MAX];
   LTE_eNB_UE_stats    *UE_stats_ptr[NUMBER_OF_UE_MAX];
@@ -844,6 +855,7 @@ typedef struct PHY_VARS_eNB_s {
 
   uint32_t X_u[64][839];
 
+  uint8_t pbch_configured;
   uint8_t pbch_pdu[4]; //PBCH_PDU_SIZE
   char eNB_generate_rar;
 
@@ -876,10 +888,6 @@ typedef struct PHY_VARS_eNB_s {
   /// if ==0 enables phy only test mode
   int mac_enabled;
 
-  /// For emulation only (used by UE abstraction to retrieve DCI)
-  uint8_t num_common_dci[2];                         // num_dci in even/odd subframes
-  uint8_t num_ue_spec_dci[2];                         // num_dci in even/odd subframes
-  DCI_ALLOC_t dci_alloc[2][NUM_DCI_MAX]; // dci_alloc from even/odd subframes
 
 
   // PDSCH Varaibles
diff --git a/openair1/PHY/extern.h b/openair1/PHY/extern.h
index a9ed9e275f14292eef4e442f998803bd3b047df9..5f86678159f91f87fd09c046357f4e928cab219f 100644
--- a/openair1/PHY/extern.h
+++ b/openair1/PHY/extern.h
@@ -23,7 +23,6 @@
 #define __PHY_EXTERN_H__
 
 #include "PHY/defs.h"
-#include "PHY_INTERFACE/defs.h"
 #include "common/ran_context.h"
 
 extern  char* namepointer_chMag ;
@@ -53,9 +52,6 @@ extern PHY_VARS_UE * PHY_vars_UE_g[MAX_UE][MAX_NUM_CCs];
 extern PHY_VARS_eNB * PHY_vars_eNB_g[MAX_eNB][MAX_NUM_CCs];
 #endif
 
-extern MAC_xface *mac_xface;
-
-
 extern short primary_synch0[144];
 extern short primary_synch1[144];
 extern short primary_synch2[144];
diff --git a/openair1/PHY/impl_defs_lte.h b/openair1/PHY/impl_defs_lte.h
index 42e1f198a796da68e55b8cb3394c704d0e298d81..9452c5f00e5a0b7f3611aea4543221f744205037 100644
--- a/openair1/PHY/impl_defs_lte.h
+++ b/openair1/PHY/impl_defs_lte.h
@@ -36,6 +36,7 @@
 
 #include "types.h"
 //#include "defs.h"
+#include "openair2/COMMON/platform_types.h"
 
 #define LTE_NUMBER_OF_SUBFRAMES_PER_FRAME 10
 #define LTE_SLOTS_PER_FRAME  20
@@ -658,6 +659,59 @@ typedef struct {
   int32_t **tdd_calib_coeffs;
 } RU_COMMON;
 
+typedef enum {format0,
+              format1,
+              format1A,
+              format1B,
+              format1C,
+              format1D,
+              format1E_2A_M10PRB,
+              format2,
+              format2A,
+              format2B,
+              format2C,
+              format2D,
+              format3,
+	      format3A,
+	      format4
+             } DCI_format_t;
+
+typedef struct {
+  /// Length of DCI in bits
+  uint8_t dci_length;
+  /// Aggregation level
+  uint8_t L;
+  /// Position of first CCE of the dci
+  int firstCCE;
+  /// flag to indicate that this is a RA response
+  boolean_t ra_flag;
+  /// rnti
+  rnti_t rnti;
+  /// harq_pid
+  rnti_t harq_pid;
+  /// Format
+  DCI_format_t format;
+  /// DCI pdu
+  uint8_t dci_pdu[8];
+} DCI_ALLOC_t;
+
+
+typedef struct {
+  uint8_t     num_dci;
+  uint8_t     num_pdcch_symbols; 
+  DCI_ALLOC_t dci_alloc[32];
+} LTE_eNB_PDCCH;
+
+/*
+typedef struct {
+
+} LTE_eNB_ePDCCH;
+
+typedef struct {
+
+} LTE_eNB_MPDCCH;
+*/
+
 typedef struct {
   /// \brief Hold the channel estimates in frequency domain based on SRS.
   /// - first index: rx antenna id [0..nb_antennas_rx[
diff --git a/openair1/SCHED/defs.h b/openair1/SCHED/defs.h
index 10d9d69c5219287de740513132754ca1d77cf10d..26859b6528356bdd764bb76402a5e2f8ffd6c739 100644
--- a/openair1/SCHED/defs.h
+++ b/openair1/SCHED/defs.h
@@ -29,7 +29,7 @@
 #define __openair_SCHED_H__
 
 #include "PHY/defs.h"
-
+#include "PHY_INTERFACE/defs.h"
 
 enum THREAD_INDEX { OPENAIR_THREAD_INDEX = 0,
                     TOP_LEVEL_SCHEDULER_THREAD_INDEX,
@@ -373,9 +373,11 @@ uint32_t pdcch_alloc2ul_frame(LTE_DL_FRAME_PARMS *frame_parms,uint32_t frame, ui
 uint16_t get_Np(uint8_t N_RB_DL,uint8_t nCCE,uint8_t plus1);
 
 
-int8_t find_ue(uint16_t rnti, PHY_VARS_eNB *phy_vars_eNB);
-int32_t add_ue(int16_t rnti, PHY_VARS_eNB *phy_vars_eNB);
-int mac_phy_remove_ue(module_id_t Mod_idP,rnti_t rnti);
+int8_t find_ue_dlsch(uint16_t rnti, PHY_VARS_eNB *phy_vars_eNB);
+int8_t find_ue_ulsch(uint16_t rnti, PHY_VARS_eNB *phy_vars_eNB);
+
+//int32_t add_ue(int16_t rnti, PHY_VARS_eNB *phy_vars_eNB);
+//int mac_phy_remove_ue(module_id_t Mod_idP,rnti_t rnti);
 
 void process_timing_advance(module_id_t Mod_id,uint8_t CC_id,int16_t timing_advance);
 void process_timing_advance_rar(PHY_VARS_UE *phy_vars_ue,UE_rxtx_proc_t *proc,uint16_t timing_advance);
@@ -480,17 +482,8 @@ void get_cqipmiri_params(PHY_VARS_UE *ue,uint8_t eNB_id);
 
 int8_t get_PHR(uint8_t Mod_id, uint8_t CC_id, uint8_t eNB_index);
 
-#ifdef LOCALIZATION
-/*! \brief This function collects eNB_UE stats and aggregate them in lists for localization
-    @param phy_vars_ue PHY variables
-    @param UE_id Index of UE
-    @param frame Index of frame
-    @param subframe Index of subframe
-    @param UE_tx_power_dB estimated UE Tx power
-    @returns -1 if updated list, 0 if calculated median
- */
-double aggregate_eNB_UE_localization_stats(PHY_VARS_eNB *phy_vars_eNB, int8_t UE_id, frame_t frameP, sub_frame_t subframeP, int32_t UE_tx_power_dB);
-#endif
+void schedule_response(Sched_Rsp_t *Sched_INFO);
+
 LTE_eNB_UE_stats* get_UE_stats(uint8_t Mod_id, uint8_t CC_id,uint16_t rnti);
 
 
diff --git a/openair1/SCHED/phy_procedures_lte_common.c b/openair1/SCHED/phy_procedures_lte_common.c
index efbcaa66d31e2de8442f48d49ce332e5bc083d34..5817d12b0311ca2bb4486f01495aace41072e437 100644
--- a/openair1/SCHED/phy_procedures_lte_common.c
+++ b/openair1/SCHED/phy_procedures_lte_common.c
@@ -34,10 +34,6 @@
 #include "SCHED/defs.h"
 #include "SCHED/extern.h"
 
-#ifdef LOCALIZATION
-#include <sys/time.h>
-#endif
-
 void get_Msg3_alloc(LTE_DL_FRAME_PARMS *frame_parms,
                     unsigned char current_subframe,
                     unsigned int current_frame,
@@ -266,7 +262,7 @@ uint8_t get_Msg3_harq_pid(LTE_DL_FRAME_PARMS *frame_parms,
 
     default:
       LOG_E(PHY,"get_Msg3_harq_pid: Unsupported TDD configuration %d\n",frame_parms->tdd_config);
-      mac_xface->macphy_exit("get_Msg3_harq_pid: Unsupported TDD configuration");
+      AssertFatal(1==0,"get_Msg3_harq_pid: Unsupported TDD configuration");
       break;
     }
   }
@@ -781,8 +777,7 @@ lte_subframe_t subframe_select(LTE_DL_FRAME_PARMS *frame_parms,unsigned char sub
     break;
 
   default:
-    LOG_E(PHY,"subframe %d Unsupported TDD configuration %d\n",subframe,frame_parms->tdd_config);
-    mac_xface->macphy_exit("subframe x Unsupported TDD configuration");
+    AssertFatal(1==0,"subframe %d Unsupported TDD configuration %d\n",subframe,frame_parms->tdd_config);
     return(255);
 
   }
@@ -873,198 +868,8 @@ unsigned int is_phich_subframe(LTE_DL_FRAME_PARMS *frame_parms,unsigned char sub
 }
 
 
-#ifdef LOCALIZATION
-double aggregate_eNB_UE_localization_stats(PHY_VARS_eNB *phy_vars_eNB, int8_t UE_id, frame_t frame, sub_frame_t subframe, int32_t UE_tx_power_dB)
-{
-  // parameters declaration
-  int8_t Mod_id, CC_id;
-  //    int32_t harq_pid;
-  int32_t avg_power, avg_rssi, median_power, median_rssi, median_subcarrier_rss, median_TA, median_TA_update, ref_timestamp_ms, current_timestamp_ms;
-  char cqis[100], sub_powers[2048];
-  int len = 0, i;
-  struct timeval ts;
-  double sys_bw = 0;
-  uint8_t N_RB_DL;
-  LTE_DL_FRAME_PARMS *frame_parms = &eNB->frame_parms;
-
-  Mod_id = eNB->Mod_id;
-  CC_id = eNB->CC_id;
-  ref_timestamp_ms = eNB->ulsch[UE_id+1]->reference_timestamp_ms;
-
-  for (i=0; i<13; i++) {
-    len += sprintf(&cqis[len]," %d ", eNB->UE_stats[(uint32_t)UE_id].DL_subband_cqi[0][i]);
-  }
-
-  len = 0;
-
-  for (i=0; i<eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->active_subcarrier; i++) {
-    len += sprintf(&sub_powers[len]," %d ", eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->subcarrier_power[i]);
-  }
-
-  gettimeofday(&ts, NULL);
-  current_timestamp_ms = ts.tv_sec * 1000 + ts.tv_usec / 1000;
-
-
-  LOG_D(LOCALIZE, " PHY: [UE %x/%d -> eNB %d], timestamp %d, "
-        "frame %d, subframe %d"
-        "UE Tx power %d dBm, "
-        "RSSI ant1 %d dBm, "
-        "RSSI ant2 %d dBm, "
-        "pwr ant1 %d dBm, "
-        "pwr ant2 %d dBm, "
-        "Rx gain %d dB, "
-        "TA %d, "
-        "TA update %d, "
-        "DL_CQI (%d,%d), "
-        "Wideband CQI (%d,%d), "
-        "DL Subband CQI[13] %s \n",
-        //          "timestamp %d, (%d active subcarrier) %s \n"
-        eNB->dlsch[(uint32_t)UE_id][0]->rnti, UE_id, Mod_id, current_timestamp_ms,
-        frame,subframe,
-        UE_tx_power_dB,
-        eNB->UE_stats[(uint32_t)UE_id].UL_rssi[0],
-        eNB->UE_stats[(uint32_t)UE_id].UL_rssi[1],
-        dB_fixed(eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->ulsch_power[0]),
-        dB_fixed(eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->ulsch_power[1]),
-        eNB->rx_total_gain_eNB_dB,
-        eNB->UE_stats[(uint32_t)UE_id].UE_timing_offset, // raw timing advance 1/sampling rate
-        eNB->UE_stats[(uint32_t)UE_id].timing_advance_update,
-        eNB->UE_stats[(uint32_t)UE_id].DL_cqi[0],eNB->UE_stats[(uint32_t)UE_id].DL_cqi[1],
-        eNB->measurements[Mod_id].wideband_cqi_dB[(uint32_t)UE_id][0],
-        eNB->measurements[Mod_id].wideband_cqi_dB[(uint32_t)UE_id][1],
-        cqis);
-  LOG_D(LOCALIZE, " PHY: timestamp %d, (%d active subcarrier) %s \n",
-        current_timestamp_ms,
-        eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->active_subcarrier,
-        sub_powers);
-
-  N_RB_DL = frame_parms->N_RB_DL;
-
-  switch (N_RB_DL) {
-  case 6:
-    sys_bw = 1.92;
-    break;
-
-  case 25:
-    sys_bw = 7.68;
-    break;
-
-  case 50:
-    sys_bw = 15.36;
-    break;
-
-  case 100:
-    sys_bw = 30.72;
-    break;
-  }
-
-  if ((current_timestamp_ms - ref_timestamp_ms > eNB->ulsch[UE_id+1]->aggregation_period_ms)) {
-    // check the size of one list to be sure there was a message transmitted during the defined aggregation period
-
-    // make the reference timestamp == current timestamp
-    eNB->ulsch[UE_id+1]->reference_timestamp_ms = current_timestamp_ms;
-    int i;
-
-    for (i=0; i<10; i++) {
-      median_power = calculate_median(&eNB->ulsch[UE_id+1]->loc_rss_list[i]);
-      del(&eNB->ulsch[UE_id+1]->loc_rss_list[i]);
-      median_rssi = calculate_median(&eNB->ulsch[UE_id+1]->loc_rssi_list[i]);
-      del(&eNB->ulsch[UE_id+1]->loc_rssi_list[i]);
-      median_subcarrier_rss = calculate_median(&eNB->ulsch[UE_id+1]->loc_subcarrier_rss_list[i]);
-      del(&eNB->ulsch[UE_id+1]->loc_subcarrier_rss_list[i]);
-      median_TA = calculate_median(&eNB->ulsch[UE_id+1]->loc_timing_advance_list[i]);
-      del(&eNB->ulsch[UE_id+1]->loc_timing_advance_list[i]);
-      median_TA_update = calculate_median(&eNB->ulsch[UE_id+1]->loc_timing_update_list[i]);
-      del(&eNB->ulsch[UE_id+1]->loc_timing_update_list[i]);
-
-      if (median_power != 0)
-        push_front(&eNB->ulsch[UE_id+1]->tot_loc_rss_list,median_power);
-
-      if (median_rssi != 0)
-        push_front(&eNB->ulsch[UE_id+1]->tot_loc_rssi_list,median_rssi);
-
-      if (median_subcarrier_rss != 0)
-        push_front(&eNB->ulsch[UE_id+1]->tot_loc_subcarrier_rss_list,median_subcarrier_rss);
-
-      if (median_TA != 0)
-        push_front(&eNB->ulsch[UE_id+1]->tot_loc_timing_advance_list,median_TA);
-
-      if (median_TA_update != 0)
-        push_front(&eNB->ulsch[UE_id+1]->tot_loc_timing_update_list,median_TA_update);
-
-      initialize(&eNB->ulsch[UE_id+1]->loc_rss_list[i]);
-      initialize(&eNB->ulsch[UE_id+1]->loc_subcarrier_rss_list[i]);
-      initialize(&eNB->ulsch[UE_id+1]->loc_rssi_list[i]);
-      initialize(&eNB->ulsch[UE_id+1]->loc_timing_advance_list[i]);
-      initialize(&eNB->ulsch[UE_id+1]->loc_timing_update_list[i]);
-    }
-
-    median_power = calculate_median(&eNB->ulsch[UE_id+1]->tot_loc_rss_list);
-    del(&eNB->ulsch[UE_id+1]->tot_loc_rss_list);
-    median_rssi = calculate_median(&eNB->ulsch[UE_id+1]->tot_loc_rssi_list);
-    del(&eNB->ulsch[UE_id+1]->tot_loc_rssi_list);
-    median_subcarrier_rss = calculate_median(&eNB->ulsch[UE_id+1]->tot_loc_subcarrier_rss_list);
-    del(&eNB->ulsch[UE_id+1]->tot_loc_subcarrier_rss_list);
-    median_TA = calculate_median(&eNB->ulsch[UE_id+1]->tot_loc_timing_advance_list);
-    del(&eNB->ulsch[UE_id+1]->tot_loc_timing_advance_list);
-    median_TA_update = calculate_median(&eNB->ulsch[UE_id+1]->tot_loc_timing_update_list);
-    del(&eNB->ulsch[UE_id+1]->tot_loc_timing_update_list);
-
-    initialize(&eNB->ulsch[UE_id+1]->tot_loc_rss_list);
-    initialize(&eNB->ulsch[UE_id+1]->tot_loc_subcarrier_rss_list);
-    initialize(&eNB->ulsch[UE_id+1]->tot_loc_rssi_list);
-    initialize(&eNB->ulsch[UE_id+1]->tot_loc_timing_advance_list);
-    initialize(&eNB->ulsch[UE_id+1]->tot_loc_timing_update_list);
-
-    double alpha = 2, power_distance, time_distance;
-    // distance = 10^((Ptx - Prx - A)/10alpha), A is a constance experimentally evaluated
-    // A includes the rx gain (eNB->rx_total_gain_eNB_dB) and hardware calibration
-    power_distance = pow(10, ((UE_tx_power_dB - median_power - eNB->rx_total_gain_eNB_dB + 133)/(10.0*alpha)));
-    /* current measurements shows constant UE_timing_offset = 18
-       and timing_advance_update = 11 at 1m. at 5m, timing_advance_update = 12*/
-    //time_distance = (double) 299792458*(eNB->UE_stats[(uint32_t)UE_id].timing_advance_update)/(sys_bw*1000000);
-    time_distance = (double) abs(eNB->UE_stats[(uint32_t)UE_id].timing_advance_update - 11) * 4.89;//  (3 x 108 x 1 / (15000 x 2048)) / 2 = 4.89 m
-
-    eNB->UE_stats[(uint32_t)UE_id].distance.time_based = time_distance;
-    eNB->UE_stats[(uint32_t)UE_id].distance.power_based = power_distance;
-
-    LOG_D(LOCALIZE, " PHY agg [UE %x/%d -> eNB %d], timestamp %d, "
-          "frame %d, subframe %d "
-          "UE Tx power %d dBm, "
-          "median RSSI %d dBm, "
-          "median Power %d dBm, "
-          "Rx gain %d dB, "
-          "power estimated r = %0.3f, "
-          " TA %d, update %d "
-          "TA estimated r = %0.3f\n"
-          ,eNB->dlsch[(uint32_t)UE_id][0]->rnti, UE_id, Mod_id, current_timestamp_ms,
-          frame, subframe,
-          UE_tx_power_dB,
-          median_rssi,
-          median_power,
-          eNB->rx_total_gain_eNB_dB,
-          power_distance,
-          eNB->UE_stats[(uint32_t)UE_id].UE_timing_offset, median_TA_update,
-          time_distance);
-
-    return 0;
-  } else {
-    avg_power = (dB_fixed(eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->ulsch_power[0]) + dB_fixed(eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->ulsch_power[1]))/2;
-    avg_rssi = (eNB->UE_stats[(uint32_t)UE_id].UL_rssi[0] + eNB->UE_stats[(uint32_t)UE_id].UL_rssi[1])/2;
-
-    push_front(&eNB->ulsch[UE_id+1]->loc_rss_list[subframe],avg_power);
-    push_front(&eNB->ulsch[UE_id+1]->loc_rssi_list[subframe],avg_rssi);
-
-    for (i=0; i<eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->active_subcarrier; i++) {
-      push_front(&eNB->ulsch[UE_id+1]->loc_subcarrier_rss_list[subframe], eNB->lte_eNB_pusch_vars[(uint32_t)UE_id]->subcarrier_power[i]);
-    }
 
-    push_front(&eNB->ulsch[UE_id+1]->loc_timing_advance_list[subframe], eNB->UE_stats[(uint32_t)UE_id].UE_timing_offset);
-    push_front(&eNB->ulsch[UE_id+1]->loc_timing_update_list[subframe], eNB->UE_stats[(uint32_t)UE_id].timing_advance_update);
-    return -1;
-  }
-}
-#endif
+/*
 LTE_eNB_UE_stats* get_UE_stats(uint8_t Mod_id, uint8_t  CC_id,uint16_t rnti)
 {
   int8_t UE_id;
@@ -1083,33 +888,9 @@ LTE_eNB_UE_stats* get_UE_stats(uint8_t Mod_id, uint8_t  CC_id,uint16_t rnti)
 
   return(&RC.eNB[Mod_id][CC_id]->UE_stats[(uint32_t)UE_id]);
 }
+*/
 
-int8_t find_ue(uint16_t rnti, PHY_VARS_eNB *eNB)
-{
-  uint8_t i;
-
-  for (i=0; i<NUMBER_OF_UE_MAX; i++) {
-    if ((eNB->dlsch[i]) &&
-        (eNB->dlsch[i][0]) &&
-        (eNB->dlsch[i][0]->rnti==rnti)) {
-      return(i);
-    }
-  }
-
-#ifdef CBA
-
-  for (i=0; i<NUM_MAX_CBA_GROUP; i++) {
-    if ((eNB->ulsch[i]) && // ue J is the representative of group j
-        (eNB->ulsch[i]->num_active_cba_groups) &&
-        (eNB->ulsch[i]->cba_rnti[i]== rnti))
-      return(i);
-  }
-
-#endif
-
-  return(-1);
-}
-
+/*
 LTE_DL_FRAME_PARMS* get_lte_frame_parms(module_id_t Mod_id, uint8_t  CC_id)
 {
 
@@ -1126,6 +907,7 @@ MU_MIMO_mode *get_mu_mimo_mode (module_id_t Mod_id, uint8_t  CC_id, rnti_t rnti)
 
   return &RC.eNB[Mod_id][CC_id]->mu_mimo_mode[UE_id];
 }
+*/
 
 int is_srs_occasion_common(LTE_DL_FRAME_PARMS *frame_parms,int frame_tx,int subframe_tx)
 {
@@ -1176,98 +958,90 @@ void compute_srs_pos(lte_frame_type_t frameType,uint16_t isrs,uint16_t *psrsPeri
 {
     if(TDD == frameType)
     {
-        if(isrs<10)
-        {
-            mac_xface->macphy_exit("2 ms SRS periodicity not supported");
-        }
+      AssertFatal(isrs>=10,"2 ms SRS periodicity not supported");
 
-        if((isrs>9)&&(isrs<15))
-        {
-            *psrsPeriodicity=5;
-            *psrsOffset=isrs-10;
-        }
-        if((isrs>14)&&(isrs<25))
+      if((isrs>9)&&(isrs<15))
         {
-            *psrsPeriodicity=10;
-            *psrsOffset=isrs-15;
+	  *psrsPeriodicity=5;
+	  *psrsOffset=isrs-10;
         }
-        if((isrs>24)&&(isrs<45))
+      if((isrs>14)&&(isrs<25))
         {
-            *psrsPeriodicity=20;
-            *psrsOffset=isrs-25;
+	  *psrsPeriodicity=10;
+	  *psrsOffset=isrs-15;
         }
-        if((isrs>44)&&(isrs<85))
+      if((isrs>24)&&(isrs<45))
         {
-            *psrsPeriodicity=40;
-            *psrsOffset=isrs-45;
+	  *psrsPeriodicity=20;
+	  *psrsOffset=isrs-25;
         }
-        if((isrs>84)&&(isrs<165))
+      if((isrs>44)&&(isrs<85))
         {
-            *psrsPeriodicity=80;
-            *psrsOffset=isrs-85;
+	  *psrsPeriodicity=40;
+	  *psrsOffset=isrs-45;
         }
-        if((isrs>164)&&(isrs<325))
+      if((isrs>84)&&(isrs<165))
         {
-            *psrsPeriodicity=160;
-            *psrsOffset=isrs-165;
+	  *psrsPeriodicity=80;
+	  *psrsOffset=isrs-85;
         }
-        if((isrs>324)&&(isrs<645))
+      if((isrs>164)&&(isrs<325))
         {
-            *psrsPeriodicity=320;
-            *psrsOffset=isrs-325;
+	  *psrsPeriodicity=160;
+	  *psrsOffset=isrs-165;
         }
-
-        if(isrs>644)
+      if((isrs>324)&&(isrs<645))
         {
-            mac_xface->macphy_exit("Isrs out of range");
+	  *psrsPeriodicity=320;
+	  *psrsOffset=isrs-325;
         }
-
+      
+      AssertFatal(isrs<=644,"Isrs out of range %d>644\n",isrs);
+      
     }
     else
-    {
+      {
         if(isrs<2)
-        {
+	  {
             *psrsPeriodicity=2;
             *psrsOffset=isrs;
-        }
+	  }
         if((isrs>1)&&(isrs<7))
-        {
+	  {
             *psrsPeriodicity=5;
             *psrsOffset=isrs-2;
         }
         if((isrs>6)&&(isrs<17))
-        {
+	  {
             *psrsPeriodicity=10;
             *psrsOffset=isrs-7;
-        }
+	  }
         if((isrs>16)&&(isrs<37))
-        {
+	  {
             *psrsPeriodicity=20;
             *psrsOffset=isrs-17;
-        }
+	  }
         if((isrs>36)&&(isrs<77))
-        {
+	  {
             *psrsPeriodicity=40;
             *psrsOffset=isrs-37;
-        }
+	  }
         if((isrs>76)&&(isrs<157))
-        {
+	  {
             *psrsPeriodicity=80;
             *psrsOffset=isrs-77;
-        }
+	  }
         if((isrs>156)&&(isrs<317))
-        {
+	  {
             *psrsPeriodicity=160;
             *psrsOffset=isrs-157;
         }
         if((isrs>316)&&(isrs<637))
-        {
+	  {
             *psrsPeriodicity=320;
             *psrsOffset=isrs-317;
-        }
-        if(isrs>636)
-        {
-            mac_xface->macphy_exit("Isrs out of range");
-        }
-    }
+	  }
+	AssertFatal(isrs<=636,"Isrs out of range %d>636\n",isrs);
+	
+      }
 }
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 2b3a2d2525ee9a6836ce306b5e6d04172db8c7a1..95f823e2e7fcc08b7944383820a3c510d96645fa 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -34,19 +34,17 @@
 #include "PHY/extern.h"
 #include "SCHED/defs.h"
 #include "SCHED/extern.h"
+#include "nfapi_interface.h"
 
 #include "PHY/LTE_TRANSPORT/if4_tools.h"
 #include "PHY/LTE_TRANSPORT/if5_tools.h"
 
-#ifdef EMOS
-#include "SCHED/phy_procedures_emos.h"
-#endif
-
 //#define DEBUG_PHY_PROC (Already defined in cmake)
 //#define DEBUG_ULSCH
 
 #include "LAYER2/MAC/extern.h"
 #include "LAYER2/MAC/defs.h"
+
 #include "UTIL/LOG/log.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
 
@@ -69,7 +67,6 @@
 #include "LAYER2/MAC/flexran_agent_mac_proto.h"
 #endif
 
-//#define DIAG_PHY
 
 #define NS_PER_SLOT 500000
 
@@ -98,20 +95,6 @@ int harq_pid_round[NUMBER_OF_UE_MAX][8] = {{0}};
 
 //DCI_ALLOC_t dci_alloc[8];
 
-#ifdef EMOS
-fifo_dump_emos_eNB emos_dump_eNB;
-#endif
-
-#if defined(SMBV) 
-extern const char smbv_fname[];
-extern unsigned short config_frames[4];
-extern uint8_t smbv_frame_cnt;
-#endif
-
-#ifdef DIAG_PHY
-extern int rx_sig_fifo;
-#endif
-
 uint8_t is_SR_subframe(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,uint8_t UE_id)
 {
 
@@ -216,15 +199,14 @@ int mac_phy_remove_ue(module_id_t Mod_idP,rnti_t rntiP) {
   return(-1);
 }
 
+/*
 int8_t find_next_ue_index(PHY_VARS_eNB *eNB)
 {
   uint8_t i;
 
   for (i=0; i<NUMBER_OF_UE_MAX; i++) {
     if (eNB->UE_stats[i].crnti==0) {
-      /*if ((eNB->dlsch[i]) &&
-	(eNB->dlsch[i][0]) &&
-	(eNB->dlsch[i][0]->rnti==0))*/
+	(eNB->dlsch[i][0]->rnti==0))
       LOG_D(PHY,"Next free UE id is %d\n",i);
       return(i);
     }
@@ -232,7 +214,9 @@ int8_t find_next_ue_index(PHY_VARS_eNB *eNB)
 
   return(-1);
 }
+*/
 
+/*
 int get_ue_active_harq_pid(const uint8_t Mod_id,const uint8_t CC_id,const uint16_t rnti, const int frame, const uint8_t subframe,uint8_t *harq_pid,uint8_t *round,const uint8_t harq_flag)
 {
   LTE_eNB_DLSCH_t *DLSCH_ptr;
@@ -261,7 +245,7 @@ int get_ue_active_harq_pid(const uint8_t Mod_id,const uint8_t CC_id,const uint16
       }
     }
 
-    /* let's go synchronous for the moment - maybe we can change at some point */
+    // let's go synchronous for the moment - maybe we can change at some point
     i = (frame * 10 + subframe) % 8;
 
     if (DLSCH_ptr->harq_processes[i]->status == ACTIVE) {
@@ -289,6 +273,7 @@ int get_ue_active_harq_pid(const uint8_t Mod_id,const uint8_t CC_id,const uint16
 
   return(0);
 }
+*/
 
 int16_t get_target_pusch_rx_power(const module_id_t module_idP, const uint8_t CC_id)
 {
@@ -300,13 +285,6 @@ int16_t get_target_pucch_rx_power(const module_id_t module_idP, const uint8_t CC
   return RC.eNB[module_idP][CC_id]->frame_parms.ul_power_control_config_common.p0_NominalPUCCH;
 }
 
-#ifdef EMOS
-void phy_procedures_emos_eNB_TX(unsigned char subframe, PHY_VARS_eNB *eNB)
-{
-
-}
-#endif
-
 void phy_procedures_eNB_S_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,relaying_type_t r_type)
 {
   UNUSED(r_type);
@@ -317,82 +295,15 @@ void phy_procedures_eNB_S_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,relaying_ty
 #endif
 
 
-  if (eNB->abstraction_flag == 0) {
-    lte_eNB_I0_measurements(eNB,
-			    subframe,
-                            0,
-                            eNB->first_run_I0_measurements);
-  }
-
-#ifdef PHY_ABSTRACTION
-  else {
-    lte_eNB_I0_measurements_emul(eNB,
-                                 0);
-  }
-
-#endif
-
+  lte_eNB_I0_measurements(eNB,
+			  subframe,
+			  0,
+			  eNB->first_run_I0_measurements);
 
 }
 
 
 
-#ifdef EMOS
-void phy_procedures_emos_eNB_RX(unsigned char subframe,PHY_VARS_eNB *eNB)
-{
-
-  uint8_t aa;
-  uint16_t last_subframe_emos;
-  uint16_t pilot_pos1 = 3 - eNB->frame_parms.Ncp, pilot_pos2 = 10 - 2*eNB->frame_parms.Ncp;
-  uint32_t bytes;
-
-  last_subframe_emos=0;
-
-
-
-
-#ifdef EMOS_CHANNEL
-
-  //if (last_slot%2==1) // this is for all UL subframes
-  if (subframe==3)
-    for (aa=0; aa<eNB->frame_parms.nb_antennas_rx; aa++) {
-      memcpy(&emos_dump_eNB.channel[aa][last_subframe_emos*2*eNB->frame_parms.N_RB_UL*12],
-             &eNB->pusch_vars[0]->drs_ch_estimates[0][aa][eNB->frame_parms.N_RB_UL*12*pilot_pos1],
-             eNB->frame_parms.N_RB_UL*12*sizeof(int));
-      memcpy(&emos_dump_eNB.channel[aa][(last_subframe_emos*2+1)*eNB->frame_parms.N_RB_UL*12],
-             &eNB->pusch_vars[0]->drs_ch_estimates[0][aa][eNB->frame_parms.N_RB_UL*12*pilot_pos2],
-             eNB->frame_parms.N_RB_UL*12*sizeof(int));
-    }
-
-#endif
-
-  if (subframe==4) {
-    emos_dump_eNB.timestamp = rt_get_time_ns();
-    emos_dump_eNB.frame_tx = eNB->proc[subframe].frame_rx;
-    emos_dump_eNB.rx_total_gain_dB = eNB->rx_total_gain_dB;
-    emos_dump_eNB.mimo_mode = eNB->transmission_mode[0];
-    memcpy(&emos_dump_eNB.measurements,
-           &eNB->measurements,
-           sizeof(PHY_MEASUREMENTS_eNB));
-    memcpy(&emos_dump_eNB.UE_stats[0],&eNB->UE_stats[0],NUMBER_OF_UE_MAX*sizeof(LTE_eNB_UE_stats));
-
-    bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, &emos_dump_eNB, sizeof(fifo_dump_emos_eNB));
-
-    //bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, "test", sizeof("test"));
-    if (bytes!=sizeof(fifo_dump_emos_eNB)) {
-      LOG_W(PHY,"[eNB %d] Frame %d, subframe %d, Problem writing EMOS data to FIFO (bytes=%d, size=%d)\n",
-            eNB->Mod_id,eNB->proc[(subframe+1)%10].frame_rx, subframe,bytes,sizeof(fifo_dump_emos_eNB));
-    } else {
-      if (eNB->proc[(subframe+1)%10].frame_tx%100==0) {
-        LOG_I(PHY,"[eNB %d] Frame %d (%d), subframe %d, Writing %d bytes EMOS data to FIFO\n",
-              eNB->Mod_id,eNB->proc[(subframe+1)%10].frame_rx, ((fifo_dump_emos_eNB*)&emos_dump_eNB)->frame_tx, subframe, bytes);
-      }
-    }
-  }
-}
-#endif
-
-
 #define AMP_OVER_SQRT2 ((AMP*ONE_OVER_SQRT2_Q15)>>15)
 #define AMP_OVER_2 (AMP>>1)
 int QPSK[4]= {AMP_OVER_SQRT2|(AMP_OVER_SQRT2<<16),AMP_OVER_SQRT2|((65536-AMP_OVER_SQRT2)<<16),((65536-AMP_OVER_SQRT2)<<16)|AMP_OVER_SQRT2,((65536-AMP_OVER_SQRT2)<<16)|(65536-AMP_OVER_SQRT2)};
@@ -401,7 +312,6 @@ int QPSK2[4]= {AMP_OVER_2|(AMP_OVER_2<<16),AMP_OVER_2|((65536-AMP_OVER_2)<<16),(
 
 
 unsigned int taus(void);
-DCI_PDU DCI_pdu_tmp;
 
 
 void pmch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,PHY_VARS_RN *rn,relaying_type_t r_type) {
@@ -415,22 +325,22 @@ void pmch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,PHY_VARS_RN *rn,rel
 
   int subframe = proc->subframe_tx;
 
-  if (eNB->abstraction_flag==0) {
-    // This is DL-Cell spec pilots in Control region
-    generate_pilots_slot(eNB,
-			 eNB->common_vars.txdataF,
-			 AMP,
-			 subframe<<1,1);
-  }
+  // This is DL-Cell spec pilots in Control region
+  generate_pilots_slot(eNB,
+		       eNB->common_vars.txdataF,
+		       AMP,
+		       subframe<<1,1);
+
   
 #if defined(Rel10) || defined(Rel14)
   // if mcch is active, send regardless of the node type: eNB or RN
   // when mcch is active, MAC sched does not allow MCCH and MTCH multiplexing
+  /*
   mch_pduP = mac_xface->get_mch_sdu(eNB->Mod_id,
 				    eNB->CC_id,
 				    proc->frame_tx,
 				    subframe);
-  
+  */
   switch (r_type) {
   case no_relay:
     if ((mch_pduP->Pdu_size > 0) && (mch_pduP->sync_area == 0)) // TEST: only transmit mcch for sync area 0
@@ -497,26 +407,24 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
   LOG_D(PHY,"common_signal_procedures: frame %d, subframe %d\n",frame,subframe); 
 
   // generate Cell-Specific Reference Signals for both slots
-  if (eNB->abstraction_flag==0) {
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,1);
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,1);
+  generate_pilots_slot(eNB,
+		       txdataF,
+		       AMP,
+		       subframe<<1,0);
+  // check that 2nd slot is for DL
+  if (subframe_select(fp,subframe) == SF_DL)
     generate_pilots_slot(eNB,
 			 txdataF,
 			 AMP,
-			 subframe<<1,0);
-    // check that 2nd slot is for DL
-    if (subframe_select(fp,subframe) == SF_DL)
-      generate_pilots_slot(eNB,
-			   txdataF,
-			   AMP,
-			   (subframe<<1)+1,0);
-    
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,0);
-  }    
+			 (subframe<<1)+1,0);
+  
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_RS_TX,0);
+      
 
   // First half of PSS/SSS (FDD, slot 0)
   if (subframe == 0) {
-    if ((fp->frame_type == FDD) &&
-	(eNB->abstraction_flag==0)) {
+    if (fp->frame_type == FDD) {
       generate_pss(txdataF,
 		   AMP,
 		   fp,
@@ -530,76 +438,12 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
       
     }
     
-    // generate PBCH (Physical Broadcast CHannel) info
-    if ((frame&3) == 0) {
-      pbch_pdu[2] = 0;
-      
-      // FIXME setting pbch_pdu[2] to zero makes the switch statement easier: remove all the or-operators
-      switch (fp->N_RB_DL) {
-      case 6:
-	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (0<<5);
-	break;
-	
-      case 15:
-	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (1<<5);
-	break;
-	
-      case 25:
-	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
-	break;
-	
-      case 50:
-	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (3<<5);
-	break;
-	
-      case 75:
-	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (4<<5);
-	break;
-	
-      case 100:
-	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (5<<5);
-	break;
-	
-      default:
-	// FIXME if we get here, this should be flagged as an error, right?
-	pbch_pdu[2] = (pbch_pdu[2]&0x1f) | (2<<5);
-	break;
-      }
-      
-      pbch_pdu[2] = (pbch_pdu[2]&0xef) |
-	((fp->phich_config_common.phich_duration << 4)&0x10);
-      
-      switch (fp->phich_config_common.phich_resource) {
-      case oneSixth:
-	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (0<<2);
-	break;
-	
-      case half:
-	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (1<<2);
-	break;
-	
-      case one:
-	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (2<<2);
-	break;
-	
-      case two:
-	pbch_pdu[2] = (pbch_pdu[2]&0xf3) | (3<<2);
-	break;
-	
-      default:
-	// unreachable
-	break;
-      }
-      
-      pbch_pdu[2] = (pbch_pdu[2]&0xfc) | ((frame>>8)&0x3);
-      pbch_pdu[1] = frame&0xfc;
-      pbch_pdu[0] = 0;
-    }
+
+
       
     /// First half of SSS (TDD, slot 1)
     
-    if ((fp->frame_type == TDD)&&
-	(eNB->abstraction_flag==0)){
+    if (fp->frame_type == TDD) {
       generate_sss(txdataF,
 		   AMP,
 		   fp,
@@ -607,25 +451,23 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
 		   1);
     }
 
+    // generate PBCH (Physical Broadcast CHannel) info
+
     /// generate PBCH
-    if (eNB->abstraction_flag==0) {
-      generate_pbch(&eNB->pbch,
-                    txdataF,
-                    AMP,
-                    fp,
-                    pbch_pdu,
-                    frame&3);
+    if ((frame&3)==0) {
+      AssertFatal(eNB->pbch_configured==1,"PBCH was not configured by MAC\n");
+      eNB->pbch_configured=0;
     }
-#ifdef PHY_ABSTRACTION
-    else {
-      generate_pbch_emul(eNB,pbch_pdu);
-    }
-#endif
-
+    generate_pbch(&eNB->pbch,
+		  txdataF,
+		  AMP,
+		  fp,
+		  pbch_pdu,
+		  frame&3);
+  
   }
   else if ((subframe == 1) &&
-	   (fp->frame_type == TDD)&&
-	   (eNB->abstraction_flag==0)) {
+	   (fp->frame_type == TDD)){
     generate_pss(txdataF,
 		 AMP,
 		 fp,
@@ -635,8 +477,7 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
   
   // Second half of PSS/SSS (FDD, slot 10)
   else if ((subframe == 5) && 
-	   (fp->frame_type == FDD) &&
-	   (eNB->abstraction_flag==0)) {
+	   (fp->frame_type == FDD)) {
     generate_pss(txdataF,
 		 AMP,
 		 &eNB->frame_parms,
@@ -652,8 +493,7 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
 
   //  Second-half of SSS (TDD, slot 11)
   else if ((subframe == 5) &&
-	   (fp->frame_type == TDD) &&
-	   (eNB->abstraction_flag==0)) {
+	   (fp->frame_type == TDD)) {
     generate_sss(txdataF,
 		 AMP,
 		 fp,
@@ -663,8 +503,7 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
 
   // Second half of PSS (TDD, slot 12)
   else if ((subframe == 6) &&
-	   (fp->frame_type == TDD) &&
-	   (eNB->abstraction_flag==0)) {
+	   (fp->frame_type == TDD)) { 
     generate_pss(txdataF,
 		 AMP,
 		 fp,
@@ -674,6 +513,7 @@ void common_signal_procedures (PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc) {
 
 }
 
+/*
 void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,const int UE_id) {
 
   LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
@@ -683,6 +523,7 @@ void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
   // if we have SI_RNTI, configure dlsch parameters and CCE index
   if (dci_alloc->rnti == SI_RNTI) {
     LOG_D(PHY,"Generating dlsch params for SI_RNTI\n");
+    
     generate_eNB_dlsch_params_from_dci(frame,
 				       subframe,
 				       &dci_alloc->dci_pdu[0],
@@ -703,20 +544,10 @@ void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
     LOG_I(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (SI)  => %"PRIu8", aggregation %d\n",eNB->Mod_id,frame,subframe,
 	  eNB->dlsch_SI->nCCE[subframe],1<<dci_alloc->L);
     
-#if defined(SMBV) 
-    
-    // configure SI DCI
-    if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-      LOG_D(PHY,"[SMBV] Frame %3d, SI in SF %d DCI %"PRIu32"\n",frame,subframe,i);
-      smbv_configure_common_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), "SI", dci_alloc, i);
-    }
-    
-#endif
-    
-    
   } else if (dci_alloc->ra_flag == 1) {  // This is format 1A allocation for RA
     // configure dlsch parameters and CCE index
     LOG_D(PHY,"Generating dlsch params for RA_RNTI\n");    
+    
     generate_eNB_dlsch_params_from_dci(frame,
 				       subframe,
 				       &dci_alloc->dci_pdu[0],
@@ -731,22 +562,12 @@ void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
 				       eNB->UE_stats[0].DL_pmi_single,
 				       0);
     
-    
+        
     eNB->dlsch_ra->nCCE[subframe] = dci_alloc->firstCCE;
     
     LOG_I(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for common DCI (RA)  => %"PRIu8" length %d bits\n",eNB->Mod_id,frame,subframe,
 	  eNB->dlsch_ra->nCCE[subframe],
 	  dci_alloc->dci_length);
-#if defined(SMBV) 
-    
-    // configure RA DCI
-    if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-      LOG_D(PHY,"[SMBV] Frame %3d, RA in SF %d DCI %"PRIu32"\n",frame,subframe,i);
-      smbv_configure_common_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), "RA", dci_alloc, i);
-    }
-    
-#endif
-    
   }
   
   else if ((dci_alloc->format != format0)&&
@@ -757,17 +578,8 @@ void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
 
     
     if (UE_id>=0) {
-#if defined(SMBV) 
-      // Configure this user
-      if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-	LOG_D(PHY,"[SMBV] Frame %3d, SF %d (SMBV SF %d) Configuring user %d with RNTI %"PRIu16" in TM%"PRIu8"\n",frame,subframe,(smbv_frame_cnt*10) + (subframe),UE_id+1,
-              dci_alloc->rnti,eNB->transmission_mode[(uint8_t)UE_id]);
-	smbv_configure_user(smbv_fname,UE_id+1,eNB->transmission_mode[(uint8_t)UE_id],dci_alloc->rnti);
-      }
-      
-#endif
-
       LOG_I(PHY,"Generating dlsch params for RNTI %x\n",dci_alloc->rnti);      
+      
       generate_eNB_dlsch_params_from_dci(frame,
 					 subframe,
 					 &dci_alloc->dci_pdu[0],
@@ -787,25 +599,15 @@ void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
       
       T(T_ENB_PHY_DLSCH_UE_DCI, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id),
         T_INT(dci_alloc->rnti), T_INT(dci_alloc->format),
-        T_INT(eNB->dlsch[(int)UE_id][0]->current_harq_pid),
-        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[eNB->dlsch[(int)UE_id][0]->current_harq_pid]->mcs),
-        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[eNB->dlsch[(int)UE_id][0]->current_harq_pid]->TBS));
+        T_INT(dci_alloc->harq_pid),
+        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[dci_alloc->harq_pid]->mcs),
+        T_INT(eNB->dlsch[(int)UE_id][0]->harq_processes[dci_alloc->harq_pid]->TBS));
 
       eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe] = dci_alloc->firstCCE;
       
       LOG_I(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for ue DCI (PDSCH %"PRIx16")  => %"PRIu8" length %d bits\n",eNB->Mod_id,frame,subframe,
 	    dci_alloc->rnti,eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe],dci_alloc->dci_length);
       
-#if defined(SMBV) 
-      
-      // configure UE-spec DCI
-      if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-	LOG_D(PHY,"[SMBV] Frame %3d, PDSCH in SF %d DCI %"PRIu32"\n",frame,subframe,i);
-	smbv_configure_ue_spec_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), UE_id+1,dci_alloc, i);
-      }
-      
-#endif
-      
       LOG_D(PHY,"[eNB %"PRIu8"][DCI][PDSCH %"PRIx16"] Frame %d subframe %d UE_id %"PRId8" Generated DCI format %d, aggregation %d\n",
 	    eNB->Mod_id, dci_alloc->rnti,
 	    frame, subframe,UE_id,
@@ -818,6 +620,7 @@ void generate_eNB_dlsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
   }
   
 }
+*/
 
 void generate_eNB_ulsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC_t *dci_alloc,const int UE_id) {
 
@@ -876,31 +679,14 @@ void generate_eNB_ulsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
 	eNB->Mod_id,frame,subframe,dci_alloc->rnti,
 	dci_alloc->firstCCE);
   
-#if defined(SMBV) 
-  
-  // configure UE-spec DCI for UL Grant
-  if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-    LOG_D(PHY,"[SMBV] Frame %3d, SF %d UL DCI %"PRIu32"\n",frame,subframe,i);
-    smbv_configure_ue_spec_dci(smbv_fname,(smbv_frame_cnt*10) + (subframe), UE_id+1, &DCI_pdu->dci_alloc[i], i);
-  }
-  
-#endif
-  
-  
   // get the hard_pid for this subframe 
   harq_pid = subframe2harq_pid(fp,
 			       pdcch_alloc2ul_frame(fp,frame,subframe),
 			       pdcch_alloc2ul_subframe(fp,subframe));
   
-  if (harq_pid==255) { // should not happen, log an error and exit, this is a fatal error
-    LOG_E(PHY,"[eNB %"PRIu8"] Frame %d: Bad harq_pid for ULSCH allocation\n",eNB->Mod_id,frame);
-    mac_xface->macphy_exit("FATAL\n"); 
-  }
-  
-  if ((dci_alloc->rnti  >= CBA_RNTI) && (dci_alloc->rnti < P_RNTI))
-    eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_cba_scheduling_flag = 1;
-  else
-    eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
+  AssertFatal(harq_pid!=255,"[eNB %"PRIu8"] Frame %d: Bad harq_pid for ULSCH allocation\n",eNB->Mod_id,frame);
+
+  eNB->ulsch[(uint32_t)UE_id]->harq_processes[harq_pid]->subframe_scheduling_flag = 1;
   
   T(T_ENB_PHY_ULSCH_UE_DCI, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id),
     T_INT(dci_alloc->rnti), T_INT(harq_pid),
@@ -913,20 +699,23 @@ void generate_eNB_ulsch_params(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,DCI_ALLOC
     T_INT(dci_alloc->firstCCE));
 }
 
-void pdsch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,LTE_eNB_DLSCH_t *dlsch, LTE_eNB_DLSCH_t *dlsch1,LTE_eNB_UE_stats *ue_stats,int ra_flag,int num_pdcch_symbols) {
+void pdsch_procedures(PHY_VARS_eNB *eNB,
+		      eNB_rxtx_proc_t *proc,
+		      int harq_pid,
+		      LTE_eNB_DLSCH_t *dlsch, 
+		      LTE_eNB_DLSCH_t *dlsch1,
+		      LTE_eNB_UE_stats *ue_stats,
+		      int ra_flag,
+		      int num_pdcch_symbols) {
 
   int frame=proc->frame_tx;
   int subframe=proc->subframe_tx;
-  int harq_pid = dlsch->current_harq_pid;
   LTE_DL_eNB_HARQ_t *dlsch_harq=dlsch->harq_processes[harq_pid];
   int input_buffer_length = dlsch_harq->TBS/8;
   LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
-  uint8_t *DLSCH_pdu=NULL;
-  uint8_t DLSCH_pdu_tmp[input_buffer_length+4]; //[768*8];
-  uint8_t DLSCH_pdu_rar[256];
   int i;
 
-  LOG_D(PHY,
+  LOG_I(PHY,
 	"[eNB %"PRIu8"][PDSCH %"PRIx16"/%"PRIu8"] Frame %d, subframe %d: Generating PDSCH/DLSCH with input size = %"PRIu16", G %d, nb_rb %"PRIu16", mcs %"PRIu8", pmi_alloc %"PRIx64", rv %"PRIu8" (round %"PRIu8")\n",
 	eNB->Mod_id, dlsch->rnti,harq_pid,
 	frame, subframe, input_buffer_length,
@@ -975,14 +764,19 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,LTE_eNB_DLSCH_t *d
     if (ue_stats)
       ue_stats->dlsch_trials[harq_pid][0]++;
 
+
     if (eNB->mac_enabled==1) {
-      if (ra_flag == 0) {
-	DLSCH_pdu = mac_xface->get_dlsch_sdu(eNB->Mod_id,
-					     eNB->CC_id,
-					     frame,
-					     dlsch->rnti,
-					     0);
+
+
+      /*
+      //      if (ra_flag == 0) {
+      DLSCH_pdu = get_dlsch_pdu(eNB->Mod_id,
+				eNB->CC_id,
+				dlsch->rnti);
+
+      
       }
+
       else {
 	int16_t crnti = mac_xface->fill_rar(eNB->Mod_id,
 					    eNB->CC_id,
@@ -1023,11 +817,7 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,LTE_eNB_DLSCH_t *d
 		eNB->ulsch[(uint32_t)UE_id]->Msg3_frame,
 		eNB->ulsch[(uint32_t)UE_id]->Msg3_subframe);
 
-          /* TODO: get rid of this hack. The problem is that the eNodeB may
-           * sometimes wrongly generate PHICH because somewhere 'phich_active' was
-           * not reset to 0, due to an unidentified reason. When adding this
-           * resetting here the problem seems to disappear completely.
-           */
+
           LOG_D(PHY, "hack: set phich_active to 0 for UE %d fsf %d %d all HARQs\n", UE_id, frame, subframe);
           for (i = 0; i < 8; i++)
             eNB->ulsch[(uint32_t)UE_id]->harq_processes[i]->phich_active = 0;
@@ -1036,115 +826,253 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,LTE_eNB_DLSCH_t *d
                                        eNB->ulsch[UE_id]->Msg3_frame, eNB->ulsch[UE_id]->Msg3_subframe);
 
           T(T_ENB_PHY_MSG3_ALLOCATION, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe),
-            T_INT(UE_id), T_INT((uint16_t)crnti), T_INT(1 /* 1 is for initial transmission*/),
+            T_INT(UE_id), T_INT((uint16_t)crnti), T_INT(1 // 1 is for initial transmission
+	    ),
             T_INT(eNB->ulsch[UE_id]->Msg3_frame), T_INT(eNB->ulsch[UE_id]->Msg3_subframe));
 	}
 	if (ue_stats) ue_stats->total_TBS_MAC += dlsch_harq->TBS;
-      }
+      */
     }
     else {
-      DLSCH_pdu = DLSCH_pdu_tmp;
-	  
       for (i=0; i<input_buffer_length; i++)
-	DLSCH_pdu[i] = (unsigned char)(taus()&0xff);
+	dlsch_harq->pdu[i] = (unsigned char)(taus()&0xff);
     }
-	
-#if defined(SMBV) 
+  } else {
+    ue_stats->dlsch_trials[harq_pid][dlsch_harq->round]++;
+#ifdef DEBUG_PHY_PROC
+#ifdef DEBUG_DLSCH
+    LOG_D(PHY,"[eNB] This DLSCH is a retransmission\n");
+#endif
+#endif
+  }
 
-    // Configures the data source of allocation (allocation is configured by DCI)
-    if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-      LOG_D(PHY,"[SMBV] Frame %3d, Configuring PDSCH payload in SF %d alloc %"PRIu8"\n",frame,(smbv_frame_cnt*10) + (subframe),smbv_alloc_cnt);
-      //          smbv_configure_datalist_for_user(smbv_fname, find_ue(dlsch->rnti,eNB)+1, DLSCH_pdu, input_buffer_length);
-    }
 
-#endif
+  LOG_D(PHY,"Generating DLSCH/PDSCH %d\n",ra_flag);
+  // 36-212
+  start_meas(&eNB->dlsch_encoding_stats);
+  eNB->te(eNB,
+	  dlsch_harq->pdu,
+	  num_pdcch_symbols,
+	  dlsch,
+	  frame,subframe,
+	  &eNB->dlsch_rate_matching_stats,
+	  &eNB->dlsch_turbo_encoding_stats,
+	  &eNB->dlsch_interleaving_stats);
+  stop_meas(&eNB->dlsch_encoding_stats);
+  // 36-211
+  start_meas(&eNB->dlsch_scrambling_stats);
+  dlsch_scrambling(fp,
+		   0,
+		   dlsch,
+		   harq_pid,
+		   get_G(fp,
+			 dlsch_harq->nb_rb,
+			 dlsch_harq->rb_alloc,
+			 get_Qm(dlsch_harq->mcs),
+			 dlsch_harq->Nl,
+			 num_pdcch_symbols,
+			 frame,subframe,
+			 0),
+		   0,
+		   subframe<<1);
+  stop_meas(&eNB->dlsch_scrambling_stats);
+  
+  start_meas(&eNB->dlsch_modulation_stats);
+  
+  
+  dlsch_modulation(eNB,
+		   eNB->common_vars.txdataF,
+		   AMP,
+		   subframe,
+		   num_pdcch_symbols,
+		   dlsch,
+		   dlsch1);
+  
+  stop_meas(&eNB->dlsch_modulation_stats);
 
+  dlsch->active = 0;
+}
 
 
-#ifdef DEBUG_PHY_PROC
-#ifdef DEBUG_DLSCH
-    LOG_T(PHY,"eNB DLSCH SDU: \n");
+void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,nfapi_dl_config_request_pdu_t *dl_config_pdu);
+void handle_nfapi_dci_dl_pdu(PHY_VARS_eNB *eNB,  
+			     eNB_rxtx_proc_t *proc,
+			     nfapi_dl_config_request_pdu_t *dl_config_pdu) {
 
-    //eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe] = DCI_pdu->dci_alloc[i].firstCCE;
+  int idx                         = proc->subframe_tx&1;  
+  LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
+  nfapi_dl_config_dci_dl_pdu *pdu = &dl_config_pdu->dci_dl_pdu;
 
-    LOG_D(PHY,"[eNB %"PRIu8"] Frame %d subframe %d : CCE resource for ue DCI (PDSCH %"PRIx16")  => %"PRIu8"/%u\n",eNB->Mod_id,eNB->proc[sched_subframe].frame_tx,subframe,
-	  DCI_pdu->dci_alloc[i].rnti,eNB->dlsch[(uint8_t)UE_id][0]->nCCE[subframe],DCI_pdu->dci_alloc[i].firstCCE);
+  LOG_I(PHY,"Frame %d, Subframe %d: DCI processing\n",proc->frame_tx,proc->subframe_tx);
 
+  // copy dci configuration into eNB structure
+  fill_dci_and_dlsch(eNB,proc,&pdcch_vars->dci_alloc[pdcch_vars->num_dci],pdu);
+}
 
-    for (i=0; i<dlsch_harq->TBS>>3; i++)
-      LOG_T(PHY,"%"PRIx8".",DLSCH_pdu[i]);
+void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
+				  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu);
 
-    LOG_T(PHY,"\n");
-#endif
-#endif
-  } else {
-    ue_stats->dlsch_trials[harq_pid][dlsch_harq->round]++;
-#ifdef DEBUG_PHY_PROC
-#ifdef DEBUG_DLSCH
-    LOG_D(PHY,"[eNB] This DLSCH is a retransmission\n");
-#endif
-#endif
-  }
+void handle_nfapi_hi_dci0_dci_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
+				  nfapi_hi_dci0_request_pdu_t *hi_dci0_config_pdu) {
+  
+  int idx                         = proc->subframe_tx&1;
+  LTE_eNB_PDCCH *pdcch_vars       = &eNB->pdcch_vars[idx];
+  nfapi_hi_dci0_dci_pdu *pdu      = &hi_dci0_config_pdu->dci_pdu;
+  // copy dci configuration in to eNB structure
+  fill_dci_and_ulsch(eNB,proc,&pdcch_vars->dci_alloc[pdcch_vars->num_dci],pdu);
+}
 
-  if (eNB->abstraction_flag==0) {
-
-    LOG_D(PHY,"Generating DLSCH/PDSCH %d\n",ra_flag);
-    // 36-212
-    start_meas(&eNB->dlsch_encoding_stats);
-    eNB->te(eNB,
-	    DLSCH_pdu,
-	    num_pdcch_symbols,
-	    dlsch,
-	    frame,subframe,
-	    &eNB->dlsch_rate_matching_stats,
-	    &eNB->dlsch_turbo_encoding_stats,
-	    &eNB->dlsch_interleaving_stats);
-    stop_meas(&eNB->dlsch_encoding_stats);
-    // 36-211
-    start_meas(&eNB->dlsch_scrambling_stats);
-    dlsch_scrambling(fp,
-		     0,
-		     dlsch,
-		     get_G(fp,
-			   dlsch_harq->nb_rb,
-			   dlsch_harq->rb_alloc,
-			   get_Qm(dlsch_harq->mcs),
-			   dlsch_harq->Nl,
-			   num_pdcch_symbols,
-			   frame,subframe,
-			   0),
-		     0,
-		     subframe<<1);
-    stop_meas(&eNB->dlsch_scrambling_stats);
 
-    start_meas(&eNB->dlsch_modulation_stats);
+handle_nfapi_bch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
+		     nfapi_dl_config_request_pdu_t *dl_config_pdu,
+		     uint8_t *sdu) {
 
+  nfapi_dl_config_bch_pdu_rel8_t *rel8 = &dl_config_pdu->bch_pdu.bch_pdu_rel8;
+  
+  AssertFatal(rel8->length == 3, "BCH PDU has length %d != 3\n",rel8->length);
 
-    dlsch_modulation(eNB,
-		     eNB->common_vars.txdataF,
-		     AMP,
-		     subframe,
-		     num_pdcch_symbols,
-		     dlsch,
-		     dlsch1);
-	
-    stop_meas(&eNB->dlsch_modulation_stats);
-  }
+  LOG_I(PHY,"bch_pdu: %x,%x,%x\n",sdu[0],sdu[1],sdu[2]);
+  eNB->pbch_pdu[0] = sdu[2];
+  eNB->pbch_pdu[1] = sdu[1];
+  eNB->pbch_pdu[2] = sdu[0];
 
+  // adjust transmit amplitude here based on NFAPI info
 
-#ifdef PHY_ABSTRACTION
-  else {
-    start_meas(&eNB->dlsch_encoding_stats);
-    dlsch_encoding_emul(eNB,
-			DLSCH_pdu,
-			dlsch);
-    stop_meas(&eNB->dlsch_encoding_stats);
+}
+
+handle_nfapi_dlsch_pdu(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,  
+		       nfapi_dl_config_request_pdu_t *dl_config_pdu,
+		       uint8_t codeword_index,
+		       uint8_t *sdu) {
+
+  nfapi_dl_config_dlsch_pdu_rel8_t *rel8 = &dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8;
+  LTE_eNB_DLSCH_t *dlsch0=NULL,*dlsch1=NULL;
+  LTE_DL_eNB_HARQ_t *dlsch0_harq=NULL,*dlsch1_harq=NULL;
+  int UE_id;
+  int harq_pid;
+
+  
+  UE_id = find_dlsch(rel8->rnti,eNB,SEARCH_EXIST_OR_FREE);
+  AssertFatal(UE_id!=-1,"no free or exiting dlsch_context\n");
+  AssertFatal(UE_id<NUMBER_OF_UE_MAX,"returned UE_id %d >= %d(NUMBER_OF_UE_MAX)\n",UE_id,NUMBER_OF_UE_MAX);
+  dlsch0 = eNB->dlsch[UE_id][0];
+  dlsch1 = eNB->dlsch[UE_id][1];
+  
+  harq_pid        = dlsch0->harq_ids[proc->subframe_tx];
+  AssertFatal((harq_pid>=0) && (harq_pid<8),"harq_pid %d not in 0...7\n",harq_pid);
+  dlsch0_harq     = dlsch0->harq_processes[harq_pid];
+  dlsch1_harq     = dlsch1->harq_processes[harq_pid];
+  AssertFatal(dlsch0_harq!=NULL,"dlsch_harq is null\n");
+
+  LOG_I(PHY,"NFAPI: frame %d, subframe %d: programming dlsch, rnti %x, UE_id %d, harq_pid %d\n",
+	proc->frame_tx,proc->subframe_tx,rel8->rnti,UE_id,harq_pid);
+  if (codeword_index == 0) dlsch0_harq->pdu                    = sdu;
+  else                     dlsch1_harq->pdu                    = sdu;
+
+}
+
+void schedule_response(Sched_Rsp_t *Sched_INFO) {
+
+  PHY_VARS_eNB *eNB;
+  eNB_rxtx_proc_t *proc;
+  // copy data from L2 interface into L1 structures
+  module_id_t                     Mod_id      = Sched_INFO->module_id;
+  uint8_t                         CC_id       = Sched_INFO->CC_id;
+  nfapi_dl_config_request_body_t *DL_req      = Sched_INFO->DL_req;
+  nfapi_hi_dci0_request_body_t   *HI_DCI0_req = Sched_INFO->HI_DCI0_req;
+  frame_t                         frame       = Sched_INFO->frame;
+  sub_frame_t                     subframe    = Sched_INFO->subframe;
+
+  AssertFatal(RC.eNB!=NULL,"RC.eNB is null\n");
+  AssertFatal(RC.eNB[Mod_id]!=NULL,"RC.eNB[%d] is null\n",Mod_id);
+  AssertFatal(RC.eNB[Mod_id][CC_id]!=NULL,"RC.eNB[%d][%d] is null\n",Mod_id,CC_id);
+
+  eNB  = RC.eNB[Mod_id][CC_id];
+  proc = &eNB->proc.proc_rxtx[0];
+
+  AssertFatal(proc->subframe_tx == subframe, "Current subframe %d != NFAPI subframe %d\n",proc->subframe_tx,subframe);
+  AssertFatal(proc->subframe_tx == subframe, "Current frame %d != NFAPI frame %d\n",proc->frame_tx,frame);
+
+  uint8_t number_dl_pdu             = DL_req->number_pdu;
+  uint8_t number_hi_dci0_pdu        = HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi;
+  uint8_t number_pdsch_rnti         = DL_req->number_pdsch_rnti;
+  uint8_t transmission_power_pcfich = DL_req->transmission_power_pcfich;
+
+
+  nfapi_dl_config_request_pdu_t *dl_config_pdu;
+  nfapi_hi_dci0_request_pdu_t *hi_dci0_req_pdu;
+
+  int i;
+
+  eNB->pdcch_vars[subframe&1].num_pdcch_symbols = DL_req->number_pdcch_ofdm_symbols;
+  eNB->pdcch_vars[subframe&1].num_dci           = 0;
+
+  LOG_I(PHY,"NFAPI: received %d dl_pdu, %d tx_req\n",number_dl_pdu,Sched_INFO->TX_req->number_of_pdus);
+
+  for (i=0;i<number_dl_pdu;i++) {
+    dl_config_pdu = &DL_req->dl_config_pdu_list[i];
+    LOG_I(PHY,"NFAPI: dl_pdu %d : type %d\n",i,dl_config_pdu->pdu_type);
+    switch (dl_config_pdu->pdu_type) {
+    case NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE:
+      handle_nfapi_dci_dl_pdu(eNB,proc,dl_config_pdu);
+      eNB->pdcch_vars[subframe&1].num_dci++; 
+      break;
+    case NFAPI_DL_CONFIG_BCH_PDU_TYPE:
+      AssertFatal(dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index<Sched_INFO->TX_req->number_of_pdus,
+		  "bch_pdu_rel8.pdu_index>=TX_req->number_of_pdus (%d>%d)\n",
+		  dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index,
+		  Sched_INFO->TX_req->number_of_pdus);
+      eNB->pbch_configured=1;
+      handle_nfapi_bch_pdu(eNB,proc,dl_config_pdu,Sched_INFO->TX_req->tx_pdu_list[dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index].segments[0].segment_data);
+      break;
+    case NFAPI_DL_CONFIG_MCH_PDU_TYPE:
+      //      handle_nfapi_mch_dl_pdu(eNB,dl_config_pdu);
+      break;
+    case NFAPI_DL_CONFIG_DLSCH_PDU_TYPE:
+      AssertFatal(dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index<Sched_INFO->TX_req->number_of_pdus,
+		  "dlsch_pdu_rel8.pdu_index>=TX_req->number_of_pdus (%d>%d)\n",
+		  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index,
+		  Sched_INFO->TX_req->number_of_pdus);
+      AssertFatal((dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks<3) &&
+		  (dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks>0),
+		  "dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks = %d not in [1,2]\n",
+		  dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks);
+      handle_nfapi_dlsch_pdu(eNB,proc,dl_config_pdu,
+			     dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks-1,
+			     Sched_INFO->TX_req->tx_pdu_list[dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index].segments[0].segment_data);
+      break;
+    case NFAPI_DL_CONFIG_PCH_PDU_TYPE:
+      //      handle_nfapi_pch_pdu(eNB,dl_config_pdu);
+      break;
+    case NFAPI_DL_CONFIG_PRS_PDU_TYPE:
+      //      handle_nfapi_prs_pdu(eNB,dl_config_pdu);
+      break;
+    case NFAPI_DL_CONFIG_CSI_RS_PDU_TYPE:
+      //      handle_nfapi_csi_rs_pdu(eNB,dl_config_pdu);
+      break;
+    case NFAPI_DL_CONFIG_EPDCCH_DL_PDU_TYPE:
+      //      handle_nfapi_epdcch_pdu(eNB,dl_config_pdu);
+      break;
+    case NFAPI_DL_CONFIG_MPDCCH_PDU_TYPE:
+      //      handle_nfapi_mpdcch_pdu(eNB,dl_config_pdu);
+      break;
+    }
   }
+  
+  for (i=0;i<number_hi_dci0_pdu;i++) {
+    hi_dci0_req_pdu = &HI_DCI0_req->hi_dci0_pdu_list[i];
+    switch (hi_dci0_req_pdu->pdu_type) {
 
-#endif
-  dlsch->active = 0;
+    case NFAPI_HI_DCI0_DCI_PDU_TYPE:
+      handle_nfapi_hi_dci0_dci_pdu(eNB,proc,hi_dci0_req_pdu);
+      eNB->pdcch_vars[subframe&1].num_dci++; 
+      break;
+    }
+  } 
 }
 
+
+
 void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 			   eNB_rxtx_proc_t *proc,
                            relaying_type_t r_type,
@@ -1154,27 +1082,17 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
   UNUSED(rn);
   int frame=proc->frame_tx;
   int subframe=proc->subframe_tx;
-  //  uint16_t input_buffer_length;
   uint32_t i,j,aa;
   uint8_t harq_pid;
-  DCI_PDU *DCI_pdu;
-  DCI_PDU DCI_pdu_tmp;
   int8_t UE_id=0;
   uint8_t num_pdcch_symbols=0;
+  uint8_t num_dci=0;
   uint8_t ul_subframe;
   uint32_t ul_frame;
   LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
-  DCI_ALLOC_t *dci_alloc=(DCI_ALLOC_t *)NULL;
 
   int offset = eNB->CC_id;//proc == &eNB->proc.proc_rxtx[0] ? 0 : 1;
 
-#if defined(SMBV) 
-  // counts number of allocations in subframe
-  // there is at least one allocation for PDCCH
-  uint8_t smbv_alloc_cnt = 1;Exiting eNB thread RXn_TXnp4
-
-#endif
-
   if ((fp->frame_type == TDD) && (subframe_select(fp,subframe)==SF_UL)) return;
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,1);
@@ -1182,6 +1100,7 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 
   T(T_ENB_PHY_DL_TICK, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe));
 
+  /*
   for (i=0; i<NUMBER_OF_UE_MAX; i++) {
     // If we've dropped the UE, go back to PRACH mode for this UE
     if ((frame==0)&&(subframe==0)) {
@@ -1212,14 +1131,14 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
       mac_xface->eNB_dlsch_ulsch_scheduler(eNB->Mod_id,0,frame,subframe);//,1);
     }
   }
+  */
 
   // clear the transmit data array for the current subframe
-  if (eNB->abstraction_flag==0) {
-    for (aa=0; aa<fp->nb_antenna_ports_eNB; aa++) {      
-      memset(&eNB->common_vars.txdataF[aa][subframe*fp->ofdm_symbol_size*(fp->symbols_per_tti)],
-             0,fp->ofdm_symbol_size*(fp->symbols_per_tti)*sizeof(int32_t));
-    }
+  for (aa=0; aa<fp->nb_antenna_ports_eNB; aa++) {      
+    memset(&eNB->common_vars.txdataF[aa][subframe*fp->ofdm_symbol_size*(fp->symbols_per_tti)],
+	   0,fp->ofdm_symbol_size*(fp->symbols_per_tti)*sizeof(int32_t));
   }
+  
 
   if (is_pmch_subframe(frame,subframe,fp)) {
     pmch_procedures(eNB,proc,rn,r_type);
@@ -1229,16 +1148,7 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
     common_signal_procedures(eNB,proc);
   }
 
-#if defined(SMBV) 
-
-  // PBCH takes one allocation
-  if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-    if (subframe==0)
-      smbv_alloc_cnt++;
-  }
-
-#endif
-
+  /*
   if (eNB->mac_enabled==1) {
     // Parse DCI received from MAC
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PDCCH_TX,1);
@@ -1249,9 +1159,6 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
   }
   else {
     DCI_pdu = &DCI_pdu_tmp;
-#ifdef EMOS_CHANNEL
-    fill_dci_emos(DCI_pdu,eNB);
-#else
     fill_dci(DCI_pdu,eNB,proc);
     // clear previous allocation information for all UEs
     for (i=0; i<NUMBER_OF_UE_MAX; i++) {
@@ -1260,10 +1167,8 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
           eNB->dlsch[i][0]->harq_processes[j]->round = 0;
       }
     }
-
-#endif
   }
-
+*/
   // clear existing ulsch dci allocations before applying info from MAC  (this is table
   ul_subframe = pdcch_alloc2ul_subframe(fp,subframe);
   ul_frame = pdcch_alloc2ul_frame(fp,frame,subframe);
@@ -1319,28 +1224,24 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
   }
 
 
-  num_pdcch_symbols = DCI_pdu->num_pdcch_symbols;
-  LOG_D(PHY,"num_pdcch_symbols %"PRIu8",(dci common %"PRIu8", dci uespec %"PRIu8"\n",num_pdcch_symbols,
-        DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);
-
-#if defined(SMBV) 
-  // Sets up PDCCH and DCI table
-  if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4) && ((DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci)>0)) {
-    LOG_D(PHY,"[SMBV] Frame %3d, SF %d PDCCH, number of DCIs %d\n",frame,subframe,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci);
-    dump_dci(fp,&DCI_pdu->dci_alloc[0]);
-    smbv_configure_pdcch(smbv_fname,(smbv_frame_cnt*10) + (subframe),num_pdcch_symbols,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci);
-  }
-#endif
-
-  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,DCI_pdu->num_pdcch_symbols);
+  //  num_pdcch_symbols = DCI_pdu->num_pdcch_symbols;
+  num_pdcch_symbols = eNB->pdcch_vars[subframe&1].num_pdcch_symbols;
+  num_dci           = eNB->pdcch_vars[subframe&1].num_dci;
+  //  LOG_D(PHY,"num_pdcch_symbols %"PRIu8",(dci common %"PRIu8", dci uespec %"PRIu8"\n",num_pdcch_symbols,
+  //        DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);
+  LOG_I(PHY,"num_pdcch_symbols %"PRIu8",(number dci %"PRIu8"\n",num_pdcch_symbols,
+	num_dci);
+  VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,num_pdcch_symbols);
 
   // loop over all DCIs for this subframe to generate DLSCH allocations
-  for (i=0; i<DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci ; i++) {
-    LOG_D(PHY,"[eNB] Subframe %d: DCI %d/%d : rnti %x, CCEind %d\n",subframe,i,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci,DCI_pdu->dci_alloc[i].rnti,DCI_pdu->dci_alloc[i].firstCCE);
-    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,DCI_pdu->dci_alloc[i].rnti);
-    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,DCI_pdu->dci_alloc[i].format);
-    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,DCI_pdu->dci_alloc[i].firstCCE);
-    dci_alloc = &DCI_pdu->dci_alloc[i];
+  /*
+  for (i=0; i<num_dci ; i++) {
+    dci_alloc = &eNB_pdcch_vars[subframe&1].dci_alloc[i];
+    LOG_D(PHY,"[eNB] Subframe %d: DCI %d/%d : rnti %x, CCEind %d\n",subframe,i,num_dci,dci_alloc->rnti,dci_alloc->firstCCE);
+    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,dci_alloc->rnti);
+    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,dci_alloc->format);
+    VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,dci_alloc->firstCCE);
+
 
     if ((dci_alloc->rnti<= P_RNTI) && 
 	(dci_alloc->ra_flag!=1)) {
@@ -1354,6 +1255,7 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
     generate_eNB_dlsch_params(eNB,proc,dci_alloc,UE_id);
 
   }
+  */
 
   VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_DCI_INFO,(frame*10)+subframe);
 
@@ -1362,6 +1264,7 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
   phy_config_dedicated_eNB_step2(eNB);
 
   // Now loop again over the DCIs for UL configuration
+  /*
   for (i=0; i<DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci ; i++) {
     dci_alloc = &DCI_pdu->dci_alloc[i];
 
@@ -1378,94 +1281,81 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
       generate_eNB_ulsch_params(eNB,proc,dci_alloc,UE_id);
     }
   }
-
+  */
 
 
 
 
   // if we have DCI to generate do it now
-  if ((DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci)>0) {
+  /*
+  if (num_dci>0) {
 
 
   } else { // for emulation!!
     eNB->num_ue_spec_dci[(subframe)&1]=0;
     eNB->num_common_dci[(subframe)&1]=0;
   }
+  */
 
-  if (eNB->abstraction_flag == 0) {
-
-    if (DCI_pdu->Num_ue_spec_dci+DCI_pdu->Num_common_dci > 0) {
-      LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_top (pdcch) (common %"PRIu8",ue_spec %"PRIu8")\n",eNB->Mod_id,frame, subframe,
-            DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);
-    }
-
-
-    num_pdcch_symbols = generate_dci_top(DCI_pdu->Num_ue_spec_dci,
-                                         DCI_pdu->Num_common_dci,
-                                         DCI_pdu->dci_alloc,
+  if (num_dci > 0) {
+    LOG_I(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_top (pdcch) (num_dci %"PRIu8")\n",eNB->Mod_id,frame, subframe,
+	  num_dci);
+  
+    
+    
+    num_pdcch_symbols = generate_dci_top(num_dci,
+					 &eNB->pdcch_vars[subframe&1].dci_alloc[0],
                                          0,
                                          AMP,
                                          fp,
                                          eNB->common_vars.txdataF,
                                          subframe);
-    if (DCI_pdu->Num_ue_spec_dci+DCI_pdu->Num_common_dci > 0) {
-      LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: num_pdcch_symbols %d\n",eNB->Mod_id,frame, subframe,
+    if (num_dci > 0) {
+      LOG_I(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: num_pdcch_symbols %d\n",eNB->Mod_id,frame, subframe,
             num_pdcch_symbols);
     }
   }
 
-#ifdef PHY_ABSTRACTION // FIXME this ifdef seems suspicious
-  else {
-    LOG_D(PHY,"[eNB %"PRIu8"] Frame %d, subframe %d: Calling generate_dci_to_emul\n",eNB->Mod_id,frame, subframe);
-    num_pdcch_symbols = generate_dci_top_emul(eNB,DCI_pdu->Num_ue_spec_dci,DCI_pdu->Num_common_dci,DCI_pdu->dci_alloc,subframe);
-  }
-
-#endif
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_ENB_PDCCH_TX,0);
 
   // Check for SI activity
-
+  /*
   if ((eNB->dlsch_SI) && (eNB->dlsch_SI->active == 1)) {
 
-    pdsch_procedures(eNB,proc,eNB->dlsch_SI,(LTE_eNB_DLSCH_t*)NULL,(LTE_eNB_UE_stats*)NULL,0,num_pdcch_symbols);
-
-#if defined(SMBV) 
-
-    // Configures the data source of allocation (allocation is configured by DCI)
-    if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-      LOG_D(PHY,"[SMBV] Frame %3d, Configuring SI payload in SF %d alloc %"PRIu8"\n",frame,(smbv_frame_cnt*10) + (subframe),smbv_alloc_cnt);
-      smbv_configure_datalist_for_alloc(smbv_fname, smbv_alloc_cnt++, (smbv_frame_cnt*10) + (subframe), DLSCH_pdu, input_buffer_length);
-    }
+    pdsch_procedures(eNB,
+		     proc,
+		     0,
+		     eNB->dlsch_SI,
+		     (LTE_eNB_DLSCH_t*)NULL,
+		     (LTE_eNB_UE_stats*)NULL,
+		     0,
+		     num_pdcch_symbols);
 
-#endif
   }
-
+  */
   // Check for RA activity
+  /*
   if ((eNB->dlsch_ra) && (eNB->dlsch_ra->active == 1)) {
 
-#if defined(SMBV) 
-
-    // Configures the data source of allocation (allocation is configured by DCI)
-    if (smbv_is_config_frame(frame) && (smbv_frame_cnt < 4)) {
-      LOG_D(PHY,"[SMBV] Frame %3d, Configuring RA payload in SF %d alloc %"PRIu8"\n",frame,(smbv_frame_cnt*10) + (subframe),smbv_alloc_cnt);
-      smbv_configure_datalist_for_alloc(smbv_fname, smbv_alloc_cnt++, (smbv_frame_cnt*10) + (subframe), dlsch_input_buffer, input_buffer_length);
-    }
-    
-#endif
-    
-    
     LOG_D(PHY,"[eNB %"PRIu8"][RAPROC] Frame %d, subframe %d: Calling generate_dlsch (RA),Msg3 frame %"PRIu32", Msg3 subframe %"PRIu8"\n",
 	  eNB->Mod_id,
 	  frame, subframe,
 	  eNB->ulsch[(uint32_t)UE_id]->Msg3_frame,
 	  eNB->ulsch[(uint32_t)UE_id]->Msg3_subframe);
     
-    pdsch_procedures(eNB,proc,eNB->dlsch_ra,(LTE_eNB_DLSCH_t*)NULL,(LTE_eNB_UE_stats*)NULL,1,num_pdcch_symbols);
+    pdsch_procedures(eNB,
+		     proc,
+		     0,
+		     eNB->dlsch_ra,
+		     (LTE_eNB_DLSCH_t*)NULL,
+		     (LTE_eNB_UE_stats*)NULL,
+		     1,
+		     num_pdcch_symbols);
     
     
     eNB->dlsch_ra->active = 0;
   }
+  */
 
   // Now scan UE specific DLSCH
   for (UE_id=0; UE_id<NUMBER_OF_UE_MAX; UE_id++)
@@ -1474,7 +1364,18 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
 	  (eNB->dlsch[(uint8_t)UE_id][0]->rnti>0)&&
 	  (eNB->dlsch[(uint8_t)UE_id][0]->active == 1)) {
 
-	pdsch_procedures(eNB,proc,eNB->dlsch[(uint8_t)UE_id][0],eNB->dlsch[(uint8_t)UE_id][1],&eNB->UE_stats[(uint32_t)UE_id],0,num_pdcch_symbols);
+	// get harq_pid
+	harq_pid = eNB->dlsch[(uint8_t)UE_id][0]->harq_ids[subframe];
+	AssertFatal(harq_pid>=0,"harq_pid is negative\n");
+	// generate pdsch
+	pdsch_procedures(eNB,
+			 proc,
+			 harq_pid,
+			 eNB->dlsch[(uint8_t)UE_id][0],
+			 eNB->dlsch[(uint8_t)UE_id][1],
+			 &eNB->UE_stats[(uint32_t)UE_id],
+			 0,
+			 num_pdcch_symbols);
 
 
       }
@@ -1508,10 +1409,6 @@ void phy_procedures_eNB_TX(PHY_VARS_eNB *eNB,
   }
   */
 
-#ifdef EMOS
-  phy_procedures_emos_eNB_TX(subframe, eNB);
-#endif
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_ENB_TX+offset,0);
   if (do_meas==1) stop_meas(&eNB->phy_proc_tx);
   
@@ -1989,32 +1886,12 @@ void prach_procedures(PHY_VARS_eNB *eNB) {
     ru=eNB->RU_list[i];
     for (ru_aa=0;ru_aa<ru->nb_rx;ru_aa++) eNB->prach_vars.rxsigF[aa++] = eNB->RU_list[i]->prach_rxsigF[ru_aa];
   }
-  if (eNB->abstraction_flag == 0) {
-    rx_prach(eNB,
-	     eNB->RU_list[0],
-             preamble_energy_list,
-             preamble_delay_list,
-             frame,
-             0);
-  } else {
-    for (UE_id=0; UE_id<NB_UE_INST; UE_id++) {
-
-      LOG_D(PHY,"[RAPROC] UE_id %d (%p), generate_prach %d, UE RSI %d, eNB RSI %d preamble index %d\n",
-            UE_id,PHY_vars_UE_g[UE_id][CC_id],PHY_vars_UE_g[UE_id][CC_id]->generate_prach,
-            PHY_vars_UE_g[UE_id][CC_id]->frame_parms.prach_config_common.rootSequenceIndex,
-            fp->prach_config_common.rootSequenceIndex,
-            PHY_vars_UE_g[UE_id][CC_id]->prach_PreambleIndex);
-
-      if ((PHY_vars_UE_g[UE_id][CC_id]->generate_prach==1) &&
-          (PHY_vars_UE_g[UE_id][CC_id]->frame_parms.prach_config_common.rootSequenceIndex ==
-           fp->prach_config_common.rootSequenceIndex) ) {
-        preamble_energy_list[PHY_vars_UE_g[UE_id][CC_id]->prach_PreambleIndex] = 800;
-        preamble_delay_list[PHY_vars_UE_g[UE_id][CC_id]->prach_PreambleIndex] = 5;
-
-      }
-    }
-  }
-
+  rx_prach(eNB,
+	   eNB->RU_list[0],
+	   preamble_energy_list,
+	   preamble_delay_list,
+	   frame,
+	   0);
   preamble_energy_max = preamble_energy_list[0];
   preamble_max = 0;
 
@@ -2035,7 +1912,7 @@ void prach_procedures(PHY_VARS_eNB *eNB) {
 
   if (preamble_energy_list[preamble_max] > 580) {
 
-    UE_id = find_next_ue_index(eNB);
+    //    UE_id = find_next_ue_index(eNB);
  
     if (UE_id>=0) {
       eNB->UE_stats[(uint32_t)UE_id].UE_timing_offset = preamble_delay_list[preamble_max]&0x1FFF; //limit to 13 (=11+2) bits
@@ -2078,13 +1955,15 @@ void prach_procedures(PHY_VARS_eNB *eNB) {
           update_TA  = 1;
           break;
         }
-
+	/*
 	mac_xface->initiate_ra_proc(eNB->Mod_id,
 				    eNB->CC_id,
 				    frame,
 				    preamble_max,
 				    preamble_delay_list[preamble_max]*update_TA/update_TA2,
-				    0,subframe,0);
+				    0,subframe,0);*/
+
+	  // fill eNB->UL_info with prach information
       }      
 
     } else {
@@ -2169,37 +2048,23 @@ void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq
         eNB->UE_stats[UE_id].sr_total++;
 
 
-        if (eNB->abstraction_flag == 0) {
-          metric0_SR = rx_pucch(eNB,
-                                pucch_format1,
-                                UE_id,
-                                eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
-                                0, // n2_pucch
-                                do_srs, // shortened format
-                                &SR_payload,
-                                frame,
-                                subframe,
-                                PUCCH1_THRES);
-          LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR is %d (SR n1pucch is %d)\n",
-                eNB->Mod_id,
-                eNB->ulsch[UE_id]->rnti,
-                frame,
-                subframe,
-                SR_payload,
-                eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex);
-        }
-#ifdef PHY_ABSTRACTION
-        else {
-          metric0_SR = rx_pucch_emul(eNB,
-                                     proc,
-                                     UE_id,
-                                     pucch_format1,
-                                     0,
-                                     &SR_payload);
-          LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR (UE SR %d/%d)\n",eNB->Mod_id,
-                eNB->ulsch[UE_id]->rnti,frame,subframe,SR_payload,eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex);
-        }
-#endif
+	metric0_SR = rx_pucch(eNB,
+			      pucch_format1,
+			      UE_id,
+			      eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
+			      0, // n2_pucch
+			      do_srs, // shortened format
+			      &SR_payload,
+			      frame,
+			      subframe,
+			      PUCCH1_THRES);
+	LOG_D(PHY,"[eNB %d][SR %x] Frame %d subframe %d Checking SR is %d (SR n1pucch is %d)\n",
+	      eNB->Mod_id,
+	      eNB->ulsch[UE_id]->rnti,
+	      frame,
+	      subframe,
+	      SR_payload,
+	      eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex);
       }// do_SR==1
 
       if ((n1_pucch0==-1) && (n1_pucch1==-1)) { // just check for SR
@@ -2209,28 +2074,17 @@ void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq
 
         LOG_D(PHY,"Demodulating PUCCH for ACK/NAK: n1_pucch0 %d (%d), SR_payload %d\n",n1_pucch0,eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,SR_payload);
 
-        if (eNB->abstraction_flag == 0) {
-          metric0 = rx_pucch(eNB,
-                             pucch_format1a,
-                             UE_id,
-                             (uint16_t)n1_pucch0,
-                             0, //n2_pucch
-                             do_srs, // shortened format
-                             pucch_payload0,
-                             frame,
-                             subframe,
-                             PUCCH1a_THRES);
-        }
-#ifdef PHY_ABSTRACTION
-        else {
-          metric0 = rx_pucch_emul(eNB,
-                                  proc,
-                                  UE_id,
-                                  pucch_format1a,
-                                  0,
-                                  pucch_payload0);
-        }
-#endif
+	metric0 = rx_pucch(eNB,
+			   pucch_format1a,
+			   UE_id,
+			   (uint16_t)n1_pucch0,
+			   0, //n2_pucch
+			   do_srs, // shortened format
+			   pucch_payload0,
+			   frame,
+			   subframe,
+			   PUCCH1a_THRES);
+        
 
         /* cancel SR detection if reception on n1_pucch0 is better than on SR PUCCH resource index */
         if (do_SR && metric0 > metric0_SR) SR_payload = 0;
@@ -2239,28 +2093,16 @@ void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq
           /* when transmitting ACK/NACK on SR PUCCH resource index, SR payload is always 1 */
           SR_payload = 1;
 
-          if (eNB->abstraction_flag == 0) {
-            metric0=rx_pucch(eNB,
-                             pucch_format1a,
-                             UE_id,
-                             eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
-                             0, //n2_pucch
-                             do_srs, // shortened format
-                             pucch_payload0,
-                             frame,
-                             subframe,
-                             PUCCH1a_THRES);
-          }
-#ifdef PHY_ABSTRACTION
-          else {
-            metric0 = rx_pucch_emul(eNB,
-                                    proc,
-                                    UE_id,
-                                    pucch_format1a,
-                                    0,
-                                    pucch_payload0);
-          }
-#endif
+	  metric0=rx_pucch(eNB,
+			   pucch_format1a,
+			   UE_id,
+			   eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
+			   0, //n2_pucch
+			   do_srs, // shortened format
+			   pucch_payload0,
+			   frame,
+			   subframe,
+			   PUCCH1a_THRES);
         }
 
 #ifdef DEBUG_PHY_PROC
@@ -2300,26 +2142,16 @@ void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq
                 n1_pucch0,n1_pucch1,n1_pucch2,n1_pucch3,format);
 #endif
 
-          if (eNB->abstraction_flag == 0)
-            metric0 = rx_pucch(eNB,
-                               format,
-                               UE_id,
-                               eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
-                               0, //n2_pucch
-                               do_srs, // shortened format
-                               pucch_payload0,
-                               frame,
-                               subframe,
-                               PUCCH1a_THRES);
-          else {
-#ifdef PHY_ABSTRACTION
-            metric0 = rx_pucch_emul(eNB,proc,
-                                    UE_id,
-                                    format,
-                                    0,
-                                    pucch_payload0);
-#endif
-          }
+	  metric0 = rx_pucch(eNB,
+			     format,
+			     UE_id,
+			     eNB->scheduling_request_config[UE_id].sr_PUCCH_ResourceIndex,
+			     0, //n2_pucch
+			     do_srs, // shortened format
+			     pucch_payload0,
+			     frame,
+			     subframe,
+			     PUCCH1a_THRES);
         } else { //using n1_pucch0/n1_pucch1 resources
 #ifdef DEBUG_PHY_PROC
           LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d Checking ACK/NAK (%d,%d,%d,%d) format %d\n",eNB->Mod_id,
@@ -2332,58 +2164,36 @@ void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq
 
           // Check n1_pucch0 metric
           if (n1_pucch0 != -1) {
-            if (eNB->abstraction_flag == 0)
-              metric0 = rx_pucch(eNB,
-                                 format,
-                                 UE_id,
-                                 (uint16_t)n1_pucch0,
-                                 0, // n2_pucch
-				 do_srs, // shortened format
-                                 pucch_payload0,
-                                 frame,
-                                 subframe,
-                                 PUCCH1a_THRES);
-            else {
-#ifdef PHY_ABSTRACTION
-              metric0 = rx_pucch_emul(eNB,
-                                      proc,
-                                      UE_id,
-                                      format,
-                                      0,
-                                      pucch_payload0);
-#endif
-            }
+	    metric0 = rx_pucch(eNB,
+			       format,
+			       UE_id,
+			       (uint16_t)n1_pucch0,
+			       0, // n2_pucch
+			       do_srs, // shortened format
+			       pucch_payload0,
+			       frame,
+			       subframe,
+			       PUCCH1a_THRES);
           }
 
           // Check n1_pucch1 metric
           if (n1_pucch1 != -1) {
-            if (eNB->abstraction_flag == 0)
-              metric1 = rx_pucch(eNB,
-                                 format,
-                                 UE_id,
-                                 (uint16_t)n1_pucch1,
-                                 0, //n2_pucch
-                                 do_srs, // shortened format
-                                 pucch_payload1,
-                                 frame,
-                                 subframe,
-                                 PUCCH1a_THRES);
-            else {
-#ifdef PHY_ABSTRACTION
-              metric1 = rx_pucch_emul(eNB,
-                                      proc,
-                                      UE_id,
-                                      format,
-                                      1,
-                                      pucch_payload1);
-#endif
-            }
+	    metric1 = rx_pucch(eNB,
+			       format,
+			       UE_id,
+			       (uint16_t)n1_pucch1,
+			       0, //n2_pucch
+			       do_srs, // shortened format
+			       pucch_payload1,
+			       frame,
+			       subframe,
+			       PUCCH1a_THRES);
           }
         }
-
+	
         if (SR_payload == 1) {
           pucch_payload = pucch_payload0;
-
+	  
           if (bundling_flag == bundling)
             pucch_sel = 2;
         } else if (bundling_flag == multiplexing) { // multiplexing + no SR
@@ -2394,10 +2204,10 @@ void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq
             pucch_payload = pucch_payload1;
           else if (n1_pucch0 != -1)
             pucch_payload = pucch_payload0;
-
+	  
           pucch_sel = 2;  // indicate that this is a bundled ACK/NAK
         }
-
+	
 #ifdef DEBUG_PHY_PROC
         LOG_D(PHY,"[eNB %d][PDSCH %x] Frame %d subframe %d ACK/NAK metric 0 %d, metric 1 %d, sel %d, (%d,%d)\n",eNB->Mod_id,
               eNB->dlsch[UE_id][0]->rnti,
@@ -2427,172 +2237,20 @@ void pucch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq
       }
 
       if (eNB->mac_enabled==1) {
+	/*
         mac_xface->SR_indication(eNB->Mod_id,
                                  eNB->CC_id,
                                  frame,
                                  eNB->dlsch[UE_id][0]->rnti,subframe);
+	*/
+
+	// fill eNB->UL_info with SR indications
       }
     }
   }
 }
 
 
-void cba_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,int UE_id,int harq_pid) {
-
-  uint8_t access_mode;
-  int num_active_cba_groups;
-  const int subframe = proc->subframe_rx;
-  const int frame = proc->frame_rx;
-  uint16_t rnti=0;
-  int ret=0;
-  LTE_DL_FRAME_PARMS *fp=&eNB->frame_parms;
-
-  if (eNB->ulsch[UE_id]==NULL) return;
-
-  num_active_cba_groups = eNB->ulsch[UE_id]->num_active_cba_groups;
- 
-  if ((num_active_cba_groups > 0) &&
-      (eNB->ulsch[UE_id]->cba_rnti[UE_id%num_active_cba_groups]>0) &&
-      (eNB->ulsch[UE_id]->harq_processes[harq_pid]->subframe_cba_scheduling_flag==1)) {
-    rnti=0;
-    
-#ifdef DEBUG_PHY_PROC
-    LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d Checking PUSCH/ULSCH CBA Reception for UE %d with cba rnti %x mode %s\n",
-	  eNB->Mod_id,harq_pid,
-	  frame,subframe,
-	  UE_id, (uint16_t)eNB->ulsch[UE_id]->cba_rnti[UE_id%num_active_cba_groups],mode_string[eNB->UE_stats[UE_id].mode]);
-#endif
-    
-    if (eNB->abstraction_flag==0) {
-      rx_ulsch(eNB,proc,
-	       UE_id);
-    }
-    
-#ifdef PHY_ABSTRACTION
-    else {
-      rx_ulsch_emul(eNB,proc,
-		    UE_id);
-    }
-    
-#endif
-    
-    if (eNB->abstraction_flag == 0) {
-      ret = ulsch_decoding(eNB,proc,
-			   UE_id,
-			   0, // control_only_flag
-			   eNB->ulsch[UE_id]->harq_processes[harq_pid]->V_UL_DAI,
-			   eNB->ulsch[UE_id]->harq_processes[harq_pid]->nb_rb>20 ? 1 : 0);
-    }
-    
-#ifdef PHY_ABSTRACTION
-    else {
-      ret = ulsch_decoding_emul(eNB,
-				proc,
-				UE_id,
-				&rnti);
-    }
-    
-#endif
-    
-    if (eNB->ulsch[UE_id]->harq_processes[harq_pid]->cqi_crc_status == 1) {
-#ifdef DEBUG_PHY_PROC
-      
-      print_CQI(eNB->ulsch[UE_id]->harq_processes[harq_pid]->o,eNB->ulsch[UE_id]->harq_processes[harq_pid]->uci_format,0,fp->N_RB_DL);
-#endif
-      access_mode = UNKNOWN_ACCESS;
-      extract_CQI(eNB->ulsch[UE_id]->harq_processes[harq_pid]->o,
-		  eNB->ulsch[UE_id]->harq_processes[harq_pid]->uci_format,
-		  &eNB->UE_stats[UE_id],
-		  fp->N_RB_DL,
-		  &rnti, &access_mode);
-      eNB->UE_stats[UE_id].rank = eNB->ulsch[UE_id]->harq_processes[harq_pid]->o_RI[0];
-    }
-    
-    eNB->ulsch[UE_id]->harq_processes[harq_pid]->subframe_cba_scheduling_flag=0;
-    eNB->ulsch[UE_id]->harq_processes[harq_pid]->status= SCH_IDLE;
-      
-    if ((num_active_cba_groups > 0) &&
-	(UE_id + num_active_cba_groups < NUMBER_OF_UE_MAX) &&
-	(eNB->ulsch[UE_id+num_active_cba_groups]->cba_rnti[UE_id%num_active_cba_groups] > 0 ) &&
-	(eNB->ulsch[UE_id+num_active_cba_groups]->num_active_cba_groups> 0)) {
-#ifdef DEBUG_PHY_PROC
-      LOG_D(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d UE %d harq_pid %d resetting the subframe_scheduling_flag for Ue %d cba groups %d members\n",
-	    eNB->Mod_id,harq_pid,frame,subframe,UE_id,harq_pid,
-	    UE_id+num_active_cba_groups, UE_id%eNB->ulsch[UE_id]->num_active_cba_groups);
-#endif
-      eNB->ulsch[UE_id+num_active_cba_groups]->harq_processes[harq_pid]->subframe_cba_scheduling_flag=1;
-      eNB->ulsch[UE_id+num_active_cba_groups]->harq_processes[harq_pid]->status= CBA_ACTIVE;
-      eNB->ulsch[UE_id+num_active_cba_groups]->harq_processes[harq_pid]->TBS=eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS;
-    }
-
-    if (ret == (1+MAX_TURBO_ITERATIONS)) {
-      eNB->UE_stats[UE_id].ulsch_round_errors[harq_pid][eNB->ulsch[UE_id]->harq_processes[harq_pid]->round]++;
-      eNB->ulsch[UE_id]->harq_processes[harq_pid]->phich_active = 1;
-      eNB->ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK = 0;
-      eNB->ulsch[UE_id]->harq_processes[harq_pid]->round++;
-    } // ulsch in error
-    else {
-      LOG_D(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d ULSCH received, setting round to 0, PHICH ACK\n",
-	    eNB->Mod_id,harq_pid,
-	    frame,subframe);
-
-      eNB->ulsch[UE_id]->harq_processes[harq_pid]->phich_active = 1;
-      eNB->ulsch[UE_id]->harq_processes[harq_pid]->phich_ACK = 1;
-      eNB->ulsch[UE_id]->harq_processes[harq_pid]->round = 0;
-      eNB->UE_stats[UE_id].ulsch_consecutive_errors = 0;
-#ifdef DEBUG_PHY_PROC
-#ifdef DEBUG_ULSCH
-      LOG_D(PHY,"[eNB] Frame %d, Subframe %d : ULSCH SDU (RX harq_pid %d) %d bytes:",
-	    frame,subframe,
-	    harq_pid,eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3);
-
-      for (j=0; j<eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3; j++)
-	LOG_T(PHY,"%x.",eNB->ulsch[UE_id]->harq_processes[harq_pid]->b[j]);
-
-      LOG_T(PHY,"\n");
-#endif
-#endif
-
-      if (access_mode > UNKNOWN_ACCESS) {
-	LOG_D(PHY,"[eNB %d] Frame %d, Subframe %d : received ULSCH SDU from CBA transmission, UE (%d,%x), CBA (group %d, rnti %x)\n",
-	      eNB->Mod_id, frame,subframe,
-	      UE_id, eNB->ulsch[UE_id]->rnti,
-	      UE_id % eNB->ulsch[UE_id]->num_active_cba_groups, eNB->ulsch[UE_id]->cba_rnti[UE_id%num_active_cba_groups]);
-
-	// detect if there is a CBA collision
-	if ((eNB->cba_last_reception[UE_id%num_active_cba_groups] == 0 ) && 
-	    (eNB->mac_enabled==1)) {
-	  mac_xface->rx_sdu(eNB->Mod_id,
-			    eNB->CC_id,
-			    frame,subframe,
-			    eNB->ulsch[UE_id]->rnti,
-			    eNB->ulsch[UE_id]->harq_processes[harq_pid]->b,
-			    eNB->ulsch[UE_id]->harq_processes[harq_pid]->TBS>>3,
-			    harq_pid,
-			    NULL);
-
-	  eNB->cba_last_reception[UE_id%num_active_cba_groups]+=1;//(subframe);
-	} else {
-	  if (eNB->cba_last_reception[UE_id%num_active_cba_groups] == 1 )
-	    LOG_N(PHY,"[eNB%d] Frame %d subframe %d : first CBA collision detected \n ",
-		  eNB->Mod_id,frame,subframe);
-
-	  LOG_N(PHY,"[eNB%d] Frame %d subframe %d : CBA collision set SR for UE %d in group %d \n ",
-		eNB->Mod_id,frame,subframe,
-		eNB->cba_last_reception[UE_id%num_active_cba_groups],UE_id%num_active_cba_groups );
-
-	  eNB->cba_last_reception[UE_id%num_active_cba_groups]+=1;
-
-	  mac_xface->SR_indication(eNB->Mod_id,
-				   eNB->CC_id,
-				   frame,
-				   eNB->dlsch[UE_id][0]->rnti,subframe);
-	}
-      } // UNKNOWN_ACCESS
-    } // ULSCH CBA not in error
-  }
-
-}
 
 extern int oai_exit;
 
@@ -2711,11 +2369,6 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
   harq_pid = subframe2harq_pid(fp,
                                frame,subframe);
 
-  // reset the cba flag used for collision detection
-  for (i=0; i < NUM_MAX_CBA_GROUP; i++) {
-    eNB->cba_last_reception[i]=0;
-  }
-
   is_srs_pos = is_srs_occasion_common(fp,frame,subframe);
   
   for (i=0; i<NUMBER_OF_UE_MAX; i++) {
@@ -2827,42 +2480,23 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
       eNB->pusch_stats_mcs[i][(frame*10)+subframe] = eNB->ulsch[i]->harq_processes[harq_pid]->mcs;
       start_meas(&eNB->ulsch_demodulation_stats);
 
-      if (eNB->abstraction_flag==0) {
-        rx_ulsch(eNB,proc,
-                 i);
-
-
-      }
-
-#ifdef PHY_ABSTRACTION
-      else {
-        rx_ulsch_emul(eNB,proc,
-		      i);
-      }
+      rx_ulsch(eNB,proc,
+	       i);
+      
 
-#endif
       stop_meas(&eNB->ulsch_demodulation_stats);
 
 
       start_meas(&eNB->ulsch_decoding_stats);
 
-      if (eNB->abstraction_flag == 0) {
-        ret = ulsch_decoding(eNB,proc,
-                             i,
-                             0, // control_only_flag
-                             eNB->ulsch[i]->harq_processes[harq_pid]->V_UL_DAI,
-			     eNB->ulsch[i]->harq_processes[harq_pid]->nb_rb>20 ? 1 : 0);
-      }
+      ret = ulsch_decoding(eNB,proc,
+			   i,
+			   0, // control_only_flag
+			   eNB->ulsch[i]->harq_processes[harq_pid]->V_UL_DAI,
+			   eNB->ulsch[i]->harq_processes[harq_pid]->nb_rb>20 ? 1 : 0);
+      
 
-#ifdef PHY_ABSTRACTION
-      else {
-        ret = ulsch_decoding_emul(eNB,
-				  proc,
-                                  i,
-                                  &rnti);
-      }
 
-#endif
       stop_meas(&eNB->ulsch_decoding_stats);
 
       LOG_I(PHY,"[eNB %d][PUSCH %d] frame %d subframe %d RNTI %x RX power (%d,%d) RSSI (%d,%d) N0 (%d,%d) dB ACK (%d,%d), decoding iter %d\n",
@@ -2949,13 +2583,15 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
             LOG_D(PHY,"[eNB %d][RAPROC] maxHARQ_Msg3Tx reached, abandoning RA procedure for UE %d\n",
                   eNB->Mod_id, i);
             eNB->UE_stats[i].mode = PRACH;
-	    if (eNB->mac_enabled==1) {
+	    if (eNB->mac_enabled==1) { /*
 	      mac_xface->cancel_ra_proc(eNB->Mod_id,
 					eNB->CC_id,
 					frame,
 					eNB->UE_stats[i].crnti);
+				       */
 	    }
-            mac_phy_remove_ue(eNB->Mod_id,eNB->UE_stats[i].crnti);
+
+	    //            mac_phy_remove_ue(eNB->Mod_id,eNB->UE_stats[i].crnti);
 
             eNB->ulsch[(uint32_t)i]->Msg3_active = 0;
             //eNB->ulsch[i]->harq_processes[harq_pid]->phich_active = 0;
@@ -2969,9 +2605,10 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
                                frame,
                                &eNB->ulsch[i]->Msg3_frame,
                                &eNB->ulsch[i]->Msg3_subframe);
-
+	    /*
             mac_xface->set_msg3_subframe(eNB->Mod_id, eNB->CC_id, frame, subframe, eNB->ulsch[i]->rnti,
                                          eNB->ulsch[i]->Msg3_frame, eNB->ulsch[i]->Msg3_subframe);
+	    */
 
             T(T_ENB_PHY_MSG3_ALLOCATION, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe),
               T_INT(i), T_INT(eNB->ulsch[i]->rnti), T_INT(0 /* 0 is for retransmission*/),
@@ -3016,7 +2653,8 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
 	 	exit(-1);
            }*/
 	    // indicate error to MAC
-	    if (eNB->mac_enabled == 1)
+	    if (eNB->mac_enabled == 1) {
+	      /*
 	      mac_xface->rx_sdu(eNB->Mod_id,
 				eNB->CC_id,
 				frame,subframe,
@@ -3025,6 +2663,9 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
 				0,
 				harq_pid,
 				&eNB->ulsch[i]->Msg3_flag);
+	      */
+	      // Fill UL info
+	    }
           }
         }
       }  // ulsch in error
@@ -3084,7 +2725,8 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
 	    LOG_I(PHY,"[eNB %d][RAPROC] Frame %d Terminating ra_proc for harq %d, UE %d\n",
 		  eNB->Mod_id,
 		  frame,harq_pid,i);
-	    if (eNB->mac_enabled)
+	    if (eNB->mac_enabled) {
+	      /*
 	      mac_xface->rx_sdu(eNB->Mod_id,
 				eNB->CC_id,
 				frame,subframe,
@@ -3093,15 +2735,20 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
 				eNB->ulsch[i]->harq_processes[harq_pid]->TBS>>3,
 				harq_pid,
 				&eNB->ulsch[i]->Msg3_flag);
-	    
+	      */
+	      // Fill UL info
+	    }
 	    // one-shot msg3 detection by MAC: empty PDU (e.g. CRNTI)
 	    if (eNB->ulsch[i]->Msg3_flag == 0 ) {
 	      eNB->UE_stats[i].mode = PRACH;
+	      /*
 	      mac_xface->cancel_ra_proc(eNB->Mod_id,
 					eNB->CC_id,
 					frame,
 					eNB->UE_stats[i].crnti);
 	      mac_phy_remove_ue(eNB->Mod_id,eNB->UE_stats[i].crnti);
+	      */
+	      
 	      eNB->ulsch[(uint32_t)i]->Msg3_active = 0;
 	    } // Msg3_flag == 0
 	    
@@ -3150,7 +2797,7 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
 #endif
 
 	  if (eNB->mac_enabled==1) {
-
+	    /*
 	    mac_xface->rx_sdu(eNB->Mod_id,
 			      eNB->CC_id,
 			      frame,subframe,
@@ -3158,26 +2805,17 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
 			      eNB->ulsch[i]->harq_processes[harq_pid]->b,
 			      eNB->ulsch[i]->harq_processes[harq_pid]->TBS>>3,
 			      harq_pid,
-			      NULL);
-
-#ifdef LOCALIZATION
-	    start_meas(&eNB->localization_stats);
-	    aggregate_eNB_UE_localization_stats(eNB,
-						i,
-						frame,
-						subframe,
-						get_hundred_times_delta_IF_eNB(eNB,i,harq_pid, 1)/100);
-	    stop_meas(&eNB->localization_stats);
-#endif
-	    
+			      NULL);*/
+
+	    // Fill UL_INFO
+
 	  } // mac_enabled==1
         } // Msg3_flag == 0
 
         // estimate timing advance for MAC
-        if (eNB->abstraction_flag == 0) {
-          sync_pos = lte_est_timing_advance_pusch(eNB,i);
-          eNB->UE_stats[i].timing_advance_update = sync_pos - fp->nb_prefix_samples/4; //to check
-        }
+	sync_pos = lte_est_timing_advance_pusch(eNB,i);
+	eNB->UE_stats[i].timing_advance_update = sync_pos - fp->nb_prefix_samples/4; //to check
+        
 
 #ifdef DEBUG_PHY_PROC
         LOG_D(PHY,"[eNB %d] frame %d, subframe %d: user %d: timing advance = %d\n",
@@ -3260,31 +2898,18 @@ void phy_procedures_eNB_uespec_RX(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,const
       eNB->UE_stats[i].total_TBS_last = eNB->UE_stats[i].total_TBS;
     }
 
-    // CBA (non-LTE)
-    cba_procedures(eNB,proc,i,harq_pid);
   } // loop i=0 ... NUMBER_OF_UE_MAX-1
 
-  if (eNB->abstraction_flag == 0) {
-    lte_eNB_I0_measurements(eNB,
-			    subframe,
-			    0,
-			    eNB->first_run_I0_measurements);
-    eNB->first_run_I0_measurements = 0;
-  }
+  lte_eNB_I0_measurements(eNB,
+			  subframe,
+			  0,
+			  eNB->first_run_I0_measurements);
+  eNB->first_run_I0_measurements = 0;
+  
 
-#ifdef PHY_ABSTRACTION
-  else {
-    lte_eNB_I0_measurements_emul(eNB,
-				 0);
-  }
 
-#endif
   //}
 
-#ifdef EMOS
-  phy_procedures_emos_eNB_RX(subframe,eNB);
-#endif
-
 #if defined(FLEXRAN_AGENT_SB_IF)
 #ifndef DISABLE_SF_TRIGGER
   //Send subframe trigger to the controller
diff --git a/openair1/SCHED/phy_procedures_lte_ue.c b/openair1/SCHED/phy_procedures_lte_ue.c
index 932ba8a5b7cf39152f44031543e04b4c20e5b1b4..d25017155b725e5356f4f56de3d8dec505c11eeb 100644
--- a/openair1/SCHED/phy_procedures_lte_ue.c
+++ b/openair1/SCHED/phy_procedures_lte_ue.c
@@ -37,10 +37,6 @@
 #include "SCHED/defs.h"
 #include "SCHED/extern.h"
 
-#ifdef EMOS
-#include "SCHED/phy_procedures_emos.h"
-#endif
-
 #define DEBUG_PHY_PROC
 
 #ifndef PUCCH
@@ -209,14 +205,8 @@ unsigned int get_tx_amp(int power_dBm, int power_max_dBm, int N_RB_UL, int nb_rb
   double gain_lin;
 
   gain_lin = pow(10,.1*gain_dB);
-  if ((nb_rb >0) && (nb_rb <= N_RB_UL)) {
-    return((int)(AMP*sqrt(gain_lin*N_RB_UL/(double)nb_rb)));
-  }
-  else {
-    LOG_E(PHY,"Illegal nb_rb/N_RB_UL combination (%d/%d)\n",nb_rb,N_RB_UL);
-    mac_xface->macphy_exit("");
-  }
-  return(0);
+  AssertFatal((nb_rb >0) && (nb_rb <= N_RB_UL),"Illegal nb_rb/N_RB_UL combination (%d/%d)\n",nb_rb,N_RB_UL);
+  return((int)(AMP*sqrt(gain_lin*N_RB_UL/(double)nb_rb)));
 }
 
 #endif
@@ -314,7 +304,6 @@ void ra_failed(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
   PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[1][eNB_index]->crnti_is_temporary = 0;
   PHY_vars_UE_g[Mod_id][CC_id]->pdcch_vars[1][eNB_index]->crnti = 0;
   LOG_E(PHY,"[UE %d] Random-access procedure fails, going back to PRACH, setting SIStatus = 0, discard temporary C-RNTI and State RRC_IDLE\n",Mod_id);
-  //mac_xface->macphy_exit("");
 }
 
 void ra_succeeded(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
@@ -331,7 +320,7 @@ void ra_succeeded(uint8_t Mod_id,uint8_t CC_id,uint8_t eNB_index)
 
   for (i=0; i<8; i++) {
     if (PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->harq_processes[i]) {
-      PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->harq_processes[i]->status=IDLE;
+      PHY_vars_UE_g[Mod_id][CC_id]->ulsch[eNB_index]->harq_processes[i]->status=SCH_IDLE;
       PHY_vars_UE_g[Mod_id][CC_id]->dlsch[0][eNB_index][0]->harq_processes[i]->round=0;
       PHY_vars_UE_g[Mod_id][CC_id]->dlsch[1][eNB_index][0]->harq_processes[i]->round=0;
     }
@@ -514,12 +503,12 @@ void ue_compute_srs_occasion(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id
                   {
                       int Mod_id = ue->Mod_id;
                       int CC_id = ue->CC_id;
-                      SR_payload = mac_xface->ue_get_SR(Mod_id,
-                              CC_id,
-                              frame_tx,
-                              eNB_id,
-                              ue->pdcch_vars[proc->subframe_rx & 0x1][eNB_id]->crnti,
-                              subframe_tx); // subframe used for meas gap
+                      SR_payload = ue_get_SR(Mod_id,
+					     CC_id,
+					     frame_tx,
+					     eNB_id,
+					     ue->pdcch_vars[proc->subframe_rx & 0x1][eNB_id]->crnti,
+					     subframe_tx); // subframe used for meas gap
 
                       if (SR_payload > 0)
                           is_sr_an_subframe = 1;
@@ -1349,11 +1338,11 @@ void ue_prach_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
     // ask L2 for RACH transport
     if ((mode != rx_calib_ue) && (mode != rx_calib_ue_med) && (mode != rx_calib_ue_byp) && (mode != no_L2_connect) ) {
       LOG_D(PHY,"Getting PRACH resources\n");
-      ue->prach_resources[eNB_id] = mac_xface->ue_get_rach(ue->Mod_id,
-							   ue->CC_id,
-							   frame_tx,
-							   eNB_id,
-							   subframe_tx);
+      ue->prach_resources[eNB_id] = ue_get_rach(ue->Mod_id,
+						ue->CC_id,
+						frame_tx,
+						eNB_id,
+						subframe_tx);
       LOG_D(PHY,"Got prach_resources for eNB %d address %p, RRCCommon %p\n",eNB_id,ue->prach_resources[eNB_id],UE_mac_inst[ue->Mod_id].radioResourceConfigCommon);
       LOG_D(PHY,"Prach resources %p\n",ue->prach_resources[eNB_id]);
     }
@@ -1370,78 +1359,76 @@ void ue_prach_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
     ue->prach_PreambleIndex=ue->prach_resources[eNB_id]->ra_PreambleIndex;
 #endif
     
-    if (abstraction_flag == 0) {
-
-      LOG_I(PHY,"mode %d\n",mode);
-      
-      if ((ue->mac_enabled==1) && (mode != calib_prach_tx)) {
-	ue->tx_power_dBm[subframe_tx] = ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER+get_PL(ue->Mod_id,ue->CC_id,eNB_id);
-      }
-      else {
-	ue->tx_power_dBm[subframe_tx] = ue->tx_power_max_dBm;
-	ue->prach_resources[eNB_id]->ra_PreambleIndex = 19;	      
-      }
-      
-      LOG_I(PHY,"[UE  %d][RAPROC] Frame %d, Subframe %d : Generating PRACH, preamble %d,PL %d,  P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm, PRACH TDD Resource index %d, RA-RNTI %d\n",
-	    ue->Mod_id,
-	    frame_tx,
-	    subframe_tx,
-	    ue->prach_resources[eNB_id]->ra_PreambleIndex,
-		get_PL(ue->Mod_id,ue->CC_id,eNB_id),
-		ue->tx_power_dBm[subframe_tx],
-	    ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER,
-	    ue->prach_resources[eNB_id]->ra_TDD_map_index,
-	    ue->prach_resources[eNB_id]->ra_RNTI);
-
-      ue->tx_total_RE[subframe_tx] = 96;
-      
+    LOG_I(PHY,"mode %d\n",mode);
+    
+    if ((ue->mac_enabled==1) && (mode != calib_prach_tx)) {
+      ue->tx_power_dBm[subframe_tx] = ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER+get_PL(ue->Mod_id,ue->CC_id,eNB_id);
+    }
+    else {
+      ue->tx_power_dBm[subframe_tx] = ue->tx_power_max_dBm;
+      ue->prach_resources[eNB_id]->ra_PreambleIndex = 19;	      
+    }
+    
+    LOG_I(PHY,"[UE  %d][RAPROC] Frame %d, Subframe %d : Generating PRACH, preamble %d,PL %d,  P0_PRACH %d, TARGET_RECEIVED_POWER %d dBm, PRACH TDD Resource index %d, RA-RNTI %d\n",
+	  ue->Mod_id,
+	  frame_tx,
+	  subframe_tx,
+	  ue->prach_resources[eNB_id]->ra_PreambleIndex,
+	  get_PL(ue->Mod_id,ue->CC_id,eNB_id),
+	  ue->tx_power_dBm[subframe_tx],
+	  ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER,
+	  ue->prach_resources[eNB_id]->ra_TDD_map_index,
+	  ue->prach_resources[eNB_id]->ra_RNTI);
+    
+    ue->tx_total_RE[subframe_tx] = 96;
+    
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-      ue->prach_vars[eNB_id]->amp = get_tx_amp(ue->tx_power_dBm[subframe_tx],
-					       ue->tx_power_max_dBm,
-					       ue->frame_parms.N_RB_UL,
-					       6);
+    ue->prach_vars[eNB_id]->amp = get_tx_amp(ue->tx_power_dBm[subframe_tx],
+					     ue->tx_power_max_dBm,
+					     ue->frame_parms.N_RB_UL,
+					     6);
 #else
-      ue->prach_vars[eNB_id]->amp = AMP;
+    ue->prach_vars[eNB_id]->amp = AMP;
 #endif
-      if ((mode == calib_prach_tx) && (((proc->frame_tx&0xfffe)%100)==0))
-	LOG_D(PHY,"[UE  %d][RAPROC] Frame %d, Subframe %d : PRACH TX power %d dBm, amp %d\n",
-	      ue->Mod_id,
-	      proc->frame_rx,
-	      proc->subframe_tx,
-	      ue->tx_power_dBm[subframe_tx],
-	      ue->prach_vars[eNB_id]->amp);
-      
-      
-      //      start_meas(&ue->tx_prach);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GENERATE_PRACH, VCD_FUNCTION_IN);
-      prach_power = generate_prach(ue,eNB_id,subframe_tx,frame_tx);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GENERATE_PRACH, VCD_FUNCTION_OUT);
-      //      stop_meas(&ue->tx_prach);
-      LOG_D(PHY,"[UE  %d][RAPROC] PRACH PL %d dB, power %d dBm, digital power %d dB (amp %d)\n",
+    if ((mode == calib_prach_tx) && (((proc->frame_tx&0xfffe)%100)==0))
+      LOG_D(PHY,"[UE  %d][RAPROC] Frame %d, Subframe %d : PRACH TX power %d dBm, amp %d\n",
 	    ue->Mod_id,
-	    get_PL(ue->Mod_id,ue->CC_id,eNB_id),
+	    proc->frame_rx,
+	    proc->subframe_tx,
 	    ue->tx_power_dBm[subframe_tx],
-	    dB_fixed(prach_power),
 	    ue->prach_vars[eNB_id]->amp);
-    } else {
-      UE_transport_info[ue->Mod_id][ue->CC_id].cntl.prach_flag=1;
-      UE_transport_info[ue->Mod_id][ue->CC_id].cntl.prach_id=ue->prach_resources[eNB_id]->ra_PreambleIndex;
-    }
     
-    if (ue->mac_enabled==1){
-      mac_xface->Msg1_transmitted(ue->Mod_id,
-          ue->CC_id,
-          frame_tx,
-          eNB_id);
-    }
-
-    LOG_D(PHY,"[UE  %d][RAPROC] Frame %d, subframe %d: Generating PRACH (eNB %d) preamble index %d for UL, TX power %d dBm (PL %d dB), l3msg \n",
-	  ue->Mod_id,frame_tx,subframe_tx,eNB_id,
-	  ue->prach_resources[eNB_id]->ra_PreambleIndex,
-	  ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER+get_PL(ue->Mod_id,ue->CC_id,eNB_id),
-	  get_PL(ue->Mod_id,ue->CC_id,eNB_id));
     
-  }	  
+    //      start_meas(&ue->tx_prach);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GENERATE_PRACH, VCD_FUNCTION_IN);
+    prach_power = generate_prach(ue,eNB_id,subframe_tx,frame_tx);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GENERATE_PRACH, VCD_FUNCTION_OUT);
+    //      stop_meas(&ue->tx_prach);
+    LOG_D(PHY,"[UE  %d][RAPROC] PRACH PL %d dB, power %d dBm, digital power %d dB (amp %d)\n",
+	  ue->Mod_id,
+	  get_PL(ue->Mod_id,ue->CC_id,eNB_id),
+	  ue->tx_power_dBm[subframe_tx],
+	  dB_fixed(prach_power),
+	  ue->prach_vars[eNB_id]->amp);
+  } else {
+    UE_transport_info[ue->Mod_id][ue->CC_id].cntl.prach_flag=1;
+    UE_transport_info[ue->Mod_id][ue->CC_id].cntl.prach_id=ue->prach_resources[eNB_id]->ra_PreambleIndex;
+  }
+  
+  if (ue->mac_enabled==1){
+    Msg1_transmitted(ue->Mod_id,
+		     ue->CC_id,
+		     frame_tx,
+		     eNB_id);
+  }
+  
+  LOG_D(PHY,"[UE  %d][RAPROC] Frame %d, subframe %d: Generating PRACH (eNB %d) preamble index %d for UL, TX power %d dBm (PL %d dB), l3msg \n",
+	ue->Mod_id,frame_tx,subframe_tx,eNB_id,
+	ue->prach_resources[eNB_id]->ra_PreambleIndex,
+	ue->prach_resources[eNB_id]->ra_PREAMBLE_RECEIVED_TARGET_POWER+get_PL(ue->Mod_id,ue->CC_id,eNB_id),
+	get_PL(ue->Mod_id,ue->CC_id,eNB_id));
+  
+	  
   
 
   // if we're calibrating the PRACH kill the pointer to its resources so that the RA protocol doesn't continue
@@ -1509,15 +1496,8 @@ void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB
       Msg3_flag = 1;
     } else {
       
-      if (harq_pid==255) {
-	LOG_E(PHY,"[UE%d] Frame %d subframe %d ulsch_decoding.c: FATAL ERROR: illegal harq_pid, returning\n",
+      AssertFatal(harq_pid!=255,"[UE%d] Frame %d subframe %d ulsch_decoding.c: FATAL ERROR: illegal harq_pid, returning\n",
 	      Mod_id,frame_tx, subframe_tx);
-	mac_xface->macphy_exit("Error in ulsch_decoding");
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
-	stop_meas(&ue->phy_proc_tx);
-	return;
-      }
-      
       Msg3_flag=0;
     }
   }
@@ -1692,37 +1672,23 @@ void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB
       
       start_meas(&ue->ulsch_encoding_stats);
       
-      if (abstraction_flag==0) {
-	if (ulsch_encoding(ue->prach_resources[eNB_id]->Msg3,
-			   ue,
-			   harq_pid,
-			   eNB_id,
-			   proc->subframe_rx,
-			   ue->transmission_mode[eNB_id],0,0)!=0) {
-	  LOG_E(PHY,"ulsch_coding.c: FATAL ERROR: returning\n");
-	  mac_xface->macphy_exit("Error in ulsch_coding");
-	  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
-	  stop_meas(&ue->phy_proc_tx);
-	  //printf("------FULL TX PROC : %5.2f ------\n",ue->phy_proc_tx.p_time/(cpuf*1000.0));
-	  return;
-	}
-      }
-      
-#ifdef PHY_ABSTRACTION
-      else {
-	ulsch_encoding_emul(ue->prach_resources[eNB_id]->Msg3,ue,eNB_id,proc->subframe_rx,harq_pid,0);
-      }
-      
-#endif
+      AssertFatal(ulsch_encoding(ue->prach_resources[eNB_id]->Msg3,
+				 ue,
+				 harq_pid,
+				 eNB_id,
+				 proc->subframe_rx,
+				 ue->transmission_mode[eNB_id],0,0)==0,
+		  "ulsch_coding.c: FATAL ERROR: returning\n");
+      return;
       
       stop_meas(&ue->ulsch_encoding_stats);
       
       if (ue->mac_enabled == 1) {
 	// signal MAC that Msg3 was sent
-	mac_xface->Msg3_transmitted(Mod_id,
-				    CC_id,
-				    frame_tx,
-				    eNB_id);
+	Msg3_transmitted(Mod_id,
+			 CC_id,
+			 frame_tx,
+			 eNB_id);
       }
     } // Msg3_flag==1
     else {
@@ -1733,14 +1699,14 @@ void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB
 	if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->round==0) {
 	  //if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->calibration_flag == 0) {
 	  access_mode=SCHEDULED_ACCESS;
-	  mac_xface->ue_get_sdu(Mod_id,
-				CC_id,
-				frame_tx,
-				subframe_tx,
-				eNB_id,
-				ulsch_input_buffer,
-				input_buffer_length,
-				&access_mode);
+	  ue_get_sdu(Mod_id,
+		     CC_id,
+		     frame_tx,
+		     subframe_tx,
+		     eNB_id,
+		     ulsch_input_buffer,
+		     input_buffer_length,
+		     &access_mode);
 	}
 	
 #ifdef DEBUG_PHY_PROC
@@ -1764,79 +1730,64 @@ void ue_ulsch_uespec_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB
       
       start_meas(&ue->ulsch_encoding_stats);
       
-      if (abstraction_flag==0) {
-	
-	if (ulsch_encoding(ulsch_input_buffer,
-			   ue,
-			   harq_pid,
-			   eNB_id,
-			   proc->subframe_rx,
-         ue->transmission_mode[eNB_id],0,
-         Nbundled)!=0) {
-	  LOG_E(PHY,"ulsch_coding.c: FATAL ERROR: returning\n");
-	  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
-	  stop_meas(&ue->phy_proc_tx);
+      if (ulsch_encoding(ulsch_input_buffer,
+			 ue,
+			 harq_pid,
+			 eNB_id,
+			 proc->subframe_rx,
+			 ue->transmission_mode[eNB_id],0,
+			 Nbundled)!=0) {
+	LOG_E(PHY,"ulsch_coding.c: FATAL ERROR: returning\n");
+	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX, VCD_FUNCTION_OUT);
+	stop_meas(&ue->phy_proc_tx);
 	  return;
-	}
       }
-      
-#ifdef PHY_ABSTRACTION
-      else {
-	ulsch_encoding_emul(ulsch_input_buffer,ue,eNB_id,proc->subframe_rx,harq_pid,0);
-      }
-      
-#endif
-      stop_meas(&ue->ulsch_encoding_stats);
     }
+    stop_meas(&ue->ulsch_encoding_stats);
+  
     
-    if (abstraction_flag == 0) {
-      if (ue->mac_enabled==1) {
-	pusch_power_cntl(ue,proc,eNB_id,1, abstraction_flag);
-	ue->tx_power_dBm[subframe_tx] = ue->ulsch[eNB_id]->Po_PUSCH;
-      }
-      else {
-	ue->tx_power_dBm[subframe_tx] = ue->tx_power_max_dBm;
-      }
-      ue->tx_total_RE[subframe_tx] = nb_rb*12;
+    if (ue->mac_enabled==1) {
+      pusch_power_cntl(ue,proc,eNB_id,1, abstraction_flag);
+      ue->tx_power_dBm[subframe_tx] = ue->ulsch[eNB_id]->Po_PUSCH;
+    }
+    else {
+      ue->tx_power_dBm[subframe_tx] = ue->tx_power_max_dBm;
+    }
+    ue->tx_total_RE[subframe_tx] = nb_rb*12;
       
 #if defined(EXMIMO) || defined(OAI_USRP) || defined(OAI_BLADERF) || defined(OAI_LMSSDR)
-      tx_amp = get_tx_amp(ue->tx_power_dBm[subframe_tx],
-			  ue->tx_power_max_dBm,
-			  ue->frame_parms.N_RB_UL,
-			  nb_rb);
+    tx_amp = get_tx_amp(ue->tx_power_dBm[subframe_tx],
+			ue->tx_power_max_dBm,
+			ue->frame_parms.N_RB_UL,
+			nb_rb);
 #else
-      tx_amp = AMP;
+    tx_amp = AMP;
 #endif
 #if T_TRACER
-      T(T_UE_PHY_PUSCH_TX_POWER, T_INT(eNB_id),T_INT(Mod_id), T_INT(frame_tx%1024), T_INT(subframe_tx),T_INT(ue->tx_power_dBm[subframe_tx]),
-                    T_INT(tx_amp),T_INT(ue->ulsch[eNB_id]->f_pusch),T_INT(get_PL(Mod_id,0,eNB_id)),T_INT(nb_rb));
+    T(T_UE_PHY_PUSCH_TX_POWER, T_INT(eNB_id),T_INT(Mod_id), T_INT(frame_tx%1024), T_INT(subframe_tx),T_INT(ue->tx_power_dBm[subframe_tx]),
+      T_INT(tx_amp),T_INT(ue->ulsch[eNB_id]->f_pusch),T_INT(get_PL(Mod_id,0,eNB_id)),T_INT(nb_rb));
 #endif
-      LOG_D(PHY,"[UE  %d][PUSCH %d] AbsSubFrame %d.%d, generating PUSCH, Po_PUSCH: %d dBm (max %d dBm), amp %d\n",
-	    Mod_id,harq_pid,frame_tx%1024,subframe_tx,ue->tx_power_dBm[subframe_tx],ue->tx_power_max_dBm, tx_amp);
-      start_meas(&ue->ulsch_modulation_stats);
-      ulsch_modulation(ue->common_vars.txdataF,
-		       tx_amp,
-		       frame_tx,
-		       subframe_tx,
-		       &ue->frame_parms,
-		       ue->ulsch[eNB_id]);
-      for (aa=0; aa<1/*frame_parms->nb_antennas_tx*/; aa++)
-	generate_drs_pusch(ue,
-			   proc,
-			   eNB_id,
-			   tx_amp,
-			   subframe_tx,
-			   first_rb,
-			   nb_rb,
-			   aa);
-      
-      stop_meas(&ue->ulsch_modulation_stats);
-    }
+    LOG_D(PHY,"[UE  %d][PUSCH %d] AbsSubFrame %d.%d, generating PUSCH, Po_PUSCH: %d dBm (max %d dBm), amp %d\n",
+	  Mod_id,harq_pid,frame_tx%1024,subframe_tx,ue->tx_power_dBm[subframe_tx],ue->tx_power_max_dBm, tx_amp);
+    start_meas(&ue->ulsch_modulation_stats);
+    ulsch_modulation(ue->common_vars.txdataF,
+		     tx_amp,
+		     frame_tx,
+		     subframe_tx,
+		     &ue->frame_parms,
+		     ue->ulsch[eNB_id]);
+    for (aa=0; aa<1/*frame_parms->nb_antennas_tx*/; aa++)
+      generate_drs_pusch(ue,
+			 proc,
+			 eNB_id,
+			 tx_amp,
+			 subframe_tx,
+			 first_rb,
+			 nb_rb,
+			 aa);
     
-    if (abstraction_flag==1) {
-      // clear SR
-      ue->sr[subframe_tx]=0;
-    }
+    stop_meas(&ue->ulsch_modulation_stats);
+
   } // subframe_scheduling_flag==1
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_PHY_PROCEDURES_UE_TX_ULSCH_UESPEC,VCD_FUNCTION_OUT);
@@ -2064,12 +2015,12 @@ void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
   if (is_SR_TXOp(ue,proc,eNB_id)==1)
   {
       if (ue->mac_enabled==1) {
-          SR_payload = mac_xface->ue_get_SR(Mod_id,
-                  CC_id,
-                  frame_tx,
-                  eNB_id,
-                  ue->pdcch_vars[proc->subframe_rx & 0x1][eNB_id]->crnti,
-                  subframe_tx); // subframe used for meas gap
+          SR_payload = ue_get_SR(Mod_id,
+				 CC_id,
+				 frame_tx,
+				 eNB_id,
+				 ue->pdcch_vars[proc->subframe_rx & 0x1][eNB_id]->crnti,
+				 subframe_tx); // subframe used for meas gap
       }
       else {
           SR_payload = 1;
@@ -2215,30 +2166,17 @@ void ue_pucch_procedures(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
       }
 #endif
 
-      if (abstraction_flag == 0) {
-
-          generate_pucch1x(ue->common_vars.txdataF,
-                  &ue->frame_parms,
-                  ue->ncs_cell,
-                  format,
-                  &ue->pucch_config_dedicated[eNB_id],
-                  pucch_resource,
-                  isShortenPucch,  // shortened format
-                  pucch_payload,
-                  tx_amp,
-                  subframe_tx);
-
-      } else {
-#ifdef PHY_ABSTRACTION
-          LOG_D(PHY,"Calling generate_pucch_emul ... (ACK %d %d, SR %d)\n",pucch_ack_payload[0],pucch_ack_payload[1],SR_payload);
-          generate_pucch_emul(ue,
-                  proc,
-                  format,
-                  ue->frame_parms.pucch_config_common.nCS_AN,
-                  pucch_payload,
-                  SR_payload);
-#endif
-      }
+      generate_pucch1x(ue->common_vars.txdataF,
+		       &ue->frame_parms,
+		       ue->ncs_cell,
+		       format,
+		       &ue->pucch_config_dedicated[eNB_id],
+		       pucch_resource,
+		       isShortenPucch,  // shortened format
+		       pucch_payload,
+		       tx_amp,
+		       subframe_tx);
+      
   }
   break;
 
@@ -2337,13 +2275,12 @@ void phy_procedures_UE_TX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,ui
 
   ue->tx_power_dBm[subframe_tx]=-127;
       
-  if (abstraction_flag==0) {
-    for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
-      memset(&ue->common_vars.txdataF[aa][subframe_tx*frame_parms->ofdm_symbol_size*frame_parms->symbols_per_tti],
-	     0,
-	     frame_parms->ofdm_symbol_size*frame_parms->symbols_per_tti*sizeof(int32_t));
-    }
+  for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
+    memset(&ue->common_vars.txdataF[aa][subframe_tx*frame_parms->ofdm_symbol_size*frame_parms->symbols_per_tti],
+	   0,
+	   frame_parms->ofdm_symbol_size*frame_parms->symbols_per_tti*sizeof(int32_t));
   }
+  
       
   if (ue->UE_mode[eNB_id] != PRACH) {
     // check cell srs subframe and ue srs subframe. This has an impact on pusch encoding
@@ -2363,70 +2300,10 @@ void phy_procedures_UE_TX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,ui
   } // UE_mode==PUSCH
 	
   	
-#ifdef CBA
-	
-  if ((ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_cba_scheduling_flag >= 1) &&
-      (ue->ulsch[eNB_id]->harq_processes[harq_pid]->status == CBA_ACTIVE)) {
-    ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag=0; //-=1
-    //  ue->ulsch[eNB_id]->harq_processes[harq_pid]->status= IDLE;
-    first_rb = ue->ulsch[eNB_id]->harq_processes[harq_pid]->first_rb;
-    nb_rb = ue->ulsch[eNB_id]->harq_processes[harq_pid]->nb_rb;
-    //cba_mcs=ue->ulsch[eNB_id]->harq_processes[harq_pid]->mcs;
-    input_buffer_length = ue->ulsch[eNB_id]->harq_processes[harq_pid]->TBS/8;
-    access_mode=CBA_ACCESS;
-	  
-    LOG_D(PHY,"[UE %d] Frame %d, subframe %d: CBA num dci %d\n",
-	  Mod_id,frame_tx,subframe_tx,
-	  ue->ulsch[eNB_id]->num_cba_dci[subframe_tx]);
-	  
-    mac_xface->ue_get_sdu(Mod_id,
-			  CC_id,
-			  frame_tx,
-			  subframe_tx,
-			  eNB_id,
-			  ulsch_input_buffer,
-			  input_buffer_length,
-			  &access_mode);
-	  
-    ue->ulsch[eNB_id]->num_cba_dci[subframe_tx]=0;
-	  
-    if (access_mode > UNKNOWN_ACCESS) {
-	    
-      if (abstraction_flag==0) {
-	if (ulsch_encoding(ulsch_input_buffer,
-			   ue,
-			   harq_pid,
-			   eNB_id,
-			   proc->subframe_rx,
-			   ue->transmission_mode[eNB_id],0,
-			   0)!=0) {  //  Nbundled, to be updated!!!!
-	  LOG_E(PHY,"ulsch_coding.c: FATAL ERROR: returning\n");
-	  return;
-	}
-      }
-	    
-#ifdef PHY_ABSTRACTION
-      else {
-	ulsch_encoding_emul(ulsch_input_buffer,ue,eNB_id,proc->subframe_rx,harq_pid,0);
-      }
-	    
-#endif
-    } else {
-      ue->ulsch[eNB_id]->harq_processes[harq_pid]->status= IDLE;
-      //reset_cba_uci(ue->ulsch[eNB_id]->o);
-      LOG_N(PHY,"[UE %d] Frame %d, subframe %d: CBA transmission cancelled or postponed\n",
-	    Mod_id, frame_tx,subframe_tx);
-    }
-  }
-	
-#endif // end CBA
 
   	
-  if (abstraction_flag == 0) {
-    ulsch_common_procedures(ue,proc, (ue->generate_ul_signal[eNB_id] == 0));
-  } // mode != PRACH
-    
-      
+  ulsch_common_procedures(ue,proc, (ue->generate_ul_signal[eNB_id] == 0));
+        
   if ((ue->UE_mode[eNB_id] == PRACH) && 
       (ue->frame_parms.prach_config_common.prach_Config_enabled==1)) {
 	
@@ -2480,22 +2357,20 @@ void phy_procedures_UE_S_TX(PHY_VARS_UE *ue,uint8_t eNB_id,uint8_t abstraction_f
   int aa;//i,aa;
   LTE_DL_FRAME_PARMS *frame_parms=&ue->frame_parms;
   
-  if (abstraction_flag==0) {
-    
-    for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
+  for (aa=0; aa<frame_parms->nb_antennas_tx; aa++) {
 #if defined(EXMIMO) //this is the EXPRESS MIMO case
-      int i;
-      // set the whole tx buffer to RX
-      for (i=0; i<LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti; i++)
-	ue->common_vars.txdata[aa][i] = 0x00010001;
-      
+    int i;
+    // set the whole tx buffer to RX
+    for (i=0; i<LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti; i++)
+      ue->common_vars.txdata[aa][i] = 0x00010001;
+    
 #else //this is the normal case
-      memset(&ue->common_vars.txdata[aa][0],0,
-	     (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti)*sizeof(int32_t));
+    memset(&ue->common_vars.txdata[aa][0],0,
+	   (LTE_NUMBER_OF_SUBFRAMES_PER_FRAME*frame_parms->samples_per_tti)*sizeof(int32_t));
 #endif //else EXMIMO
-      
-    }
+    
   }
+  
 }
 
 void ue_measurement_procedures(
@@ -2515,32 +2390,31 @@ void ue_measurement_procedures(
 
   if (l==0) {
     // UE measurements on symbol 0
-    if (abstraction_flag==0) {
-      LOG_D(PHY,"Calling measurements subframe %d, rxdata %p\n",subframe_rx,ue->common_vars.rxdata);
-
-      lte_ue_measurements(ue,
-			  (subframe_rx*frame_parms->samples_per_tti+ue->rx_offset)%(frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME),
-			  (subframe_rx == 1) ? 1 : 0,
-			  0,subframe_rx);
-    } else {
-      lte_ue_measurements(ue,
-			  0,
-			  0,
-			  1,
-      subframe_rx);
-    }
+    LOG_D(PHY,"Calling measurements subframe %d, rxdata %p\n",subframe_rx,ue->common_vars.rxdata);
+    
+    lte_ue_measurements(ue,
+			(subframe_rx*frame_parms->samples_per_tti+ue->rx_offset)%(frame_parms->samples_per_tti*LTE_NUMBER_OF_SUBFRAMES_PER_FRAME),
+			(subframe_rx == 1) ? 1 : 0,
+			0,subframe_rx);
+  } else {
+    lte_ue_measurements(ue,
+			0,
+			0,
+			1,
+			subframe_rx);
+  }
 #if T_TRACER
-    if(slot == 0)
-      T(T_UE_PHY_MEAS, T_INT(eNB_id),  T_INT(ue->Mod_id), T_INT(proc->frame_rx%1024), T_INT(proc->subframe_rx),
-                             T_INT((int)(10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB)),
-                             T_INT((int)ue->measurements.rx_rssi_dBm[0]),
-                             T_INT((int)(ue->measurements.rx_power_avg_dB[0] - ue->measurements.n0_power_avg_dB)),
-                             T_INT((int)ue->measurements.rx_power_avg_dB[0]),
-                             T_INT((int)ue->measurements.n0_power_avg_dB),
-                             T_INT((int)ue->measurements.wideband_cqi_avg[0]),
-                             T_INT((int)ue->common_vars.freq_offset));
+  if(slot == 0)
+    T(T_UE_PHY_MEAS, T_INT(eNB_id),  T_INT(ue->Mod_id), T_INT(proc->frame_rx%1024), T_INT(proc->subframe_rx),
+      T_INT((int)(10*log10(ue->measurements.rsrp[0])-ue->rx_total_gain_dB)),
+      T_INT((int)ue->measurements.rx_rssi_dBm[0]),
+      T_INT((int)(ue->measurements.rx_power_avg_dB[0] - ue->measurements.n0_power_avg_dB)),
+      T_INT((int)ue->measurements.rx_power_avg_dB[0]),
+      T_INT((int)ue->measurements.n0_power_avg_dB),
+      T_INT((int)ue->measurements.wideband_cqi_avg[0]),
+      T_INT((int)ue->common_vars.freq_offset));
 #endif
-  }
+
 
   if (l==(6-ue->frame_parms.Ncp)) {
 	
@@ -2553,9 +2427,6 @@ void ue_measurement_procedures(
 			abstraction_flag);
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_RRC_MEASUREMENTS, VCD_FUNCTION_OUT);
 
-    if (abstraction_flag==1)
-      ue->sinr_eff =  sinr_eff_cqi_calc(ue, 0, subframe_rx);
-
   }
 
   if ((subframe_rx==0) && (slot == 0) && (l==(4-frame_parms->Ncp))) {
@@ -2576,175 +2447,20 @@ void ue_measurement_procedures(
 
     eNB_id = 0;
     
-    if (abstraction_flag == 0) {
-      if (ue->no_timing_correction==0)
-	lte_adjust_synch(&ue->frame_parms,
-			 ue,
-			 eNB_id,
-			 subframe_rx,
-			 0,
-			 16384);
-    }      
+    if (ue->no_timing_correction==0)
+      lte_adjust_synch(&ue->frame_parms,
+		       ue,
+		       eNB_id,
+		       subframe_rx,
+		       0,
+		       16384);
+ 
 
   }
 
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_MEASUREMENT_PROCEDURES, VCD_FUNCTION_OUT);
 }
 
-#ifdef EMOS
-void phy_procedures_emos_UE_RX(PHY_VARS_UE *ue,uint8_t last_slot,uint8_t eNB_id)
-{
-
-  uint8_t i,j;
-  //uint16_t last_slot_emos;
-  uint32_t bytes;
-  int Mod_id = ue->Mod_id;
-
-  /*
-    if (last_slot<2)
-    last_slot_emos = last_slot;
-    else if (last_slot>9)
-    last_slot_emos = last_slot - 8;
-    else {
-    LOG_E(PHY,"emos rx last_slot_emos %d, last_slot %d\n", last_slot_emos,last_slot);
-    mac_xface->macphy_exit("should never happen");
-    }
-  */
-
-#ifdef EMOS_CHANNEL
-
-  if ((last_slot==10) || (last_slot==11)) {
-    for (i=0; i<ue->frame_parms.nb_antennas_rx; i++)
-      for (j=0; j<ue->frame_parms.nb_antennas_tx; j++) {
-	// first OFDM symbol with pilots
-	memcpy(&emos_dump_UE.channel[i][j][(last_slot%2)*2*ue->frame_parms.ofdm_symbol_size],
-	       &ue->common_vars.dl_ch_estimates[eNB_id][(j<<1) + i][0],
-	       ue->frame_parms.ofdm_symbol_size*sizeof(int));
-	// second OFDM symbol with pilots
-	memcpy(&emos_dump_UE.channel[i][j][((last_slot%2)*2+1)*ue->frame_parms.ofdm_symbol_size],
-	       &ue->common_vars.dl_ch_estimates[eNB_id][(j<<1) + i][(ue->frame_parms.Ncp == 0 ? 4 : 3)*ue->frame_parms.ofdm_symbol_size],
-	       ue->frame_parms.ofdm_symbol_size*sizeof(int));
-      }
-  }
-
-#endif
-
-  if (last_slot==0) {
-    emos_dump_UE.timestamp = rt_get_time_ns();
-    emos_dump_UE.frame_rx = proc->frame_rx;
-    emos_dump_UE.UE_mode = ue->UE_mode[eNB_id];
-    emos_dump_UE.mimo_mode = ue->transmission_mode[eNB_id];
-    emos_dump_UE.freq_offset = ue->common_vars.freq_offset;
-    emos_dump_UE.timing_advance = ue->timing_advance;
-    emos_dump_UE.timing_offset  = ue->rx_offset;
-    emos_dump_UE.rx_total_gain_dB = ue->rx_total_gain_dB;
-    emos_dump_UE.eNb_id = eNB_id;
-    memcpy(&emos_dump_UE.PHY_measurements,&measurements,sizeof(PHY_MEASUREMENTS));
-  }
-
-  if (last_slot==1) {
-    emos_dump_UE.pbch_errors = ue->pbch_vars[eNB_id]->pdu_errors;
-    emos_dump_UE.pbch_errors_last = ue->pbch_vars[eNB_id]->pdu_errors_last;
-    emos_dump_UE.pbch_errors_conseq = ue->pbch_vars[eNB_id]->pdu_errors_conseq;
-    emos_dump_UE.pbch_fer = ue->pbch_vars[eNB_id]->pdu_fer;
-  }
-
-  if (last_slot==19) {
-    emos_dump_UE.dlsch_errors = ue->dlsch_errors[eNB_id];
-    emos_dump_UE.dlsch_errors_last = ue->dlsch_errors_last[eNB_id];
-    emos_dump_UE.dlsch_received = ue->dlsch_received[eNB_id];
-    emos_dump_UE.dlsch_received_last = ue->dlsch_received_last[eNB_id];
-    emos_dump_UE.dlsch_fer = ue->dlsch_fer[eNB_id];
-    emos_dump_UE.dlsch_cntl_errors = ue->dlsch_SI_errors[eNB_id];
-    emos_dump_UE.dlsch_ra_errors = ue->dlsch_ra_errors[eNB_id];
-    emos_dump_UE.total_TBS = ue->total_TBS[eNB_id];
-    emos_dump_UE.total_TBS_last = ue->total_TBS_last[eNB_id];
-    emos_dump_UE.bitrate = ue->bitrate[eNB_id];
-    emos_dump_UE.total_received_bits = ue->total_received_bits[eNB_id];
-    emos_dump_UE.pmi_saved = ue->dlsch[subframe&0x1][eNB_id][0]->pmi_alloc;
-    emos_dump_UE.mcs = ue->dlsch[subframe&0x1][eNB_id][0]->harq_processes[ue->dlsch[subframe&0x1][eNB_id][0]->current_harq_pid]->mcs;
-    emos_dump_UE.use_ia_receiver = openair_daq_vars.use_ia_receiver;
-
-    bytes = rtf_put(CHANSOUNDER_FIFO_MINOR, &emos_dump_UE, sizeof(fifo_dump_emos_UE));
-
-    if (bytes!=sizeof(fifo_dump_emos_UE)) {
-      LOG_W(PHY,"[UE  %d] frame %d, slot %d, Problem writing EMOS data to FIFO\n",Mod_id,proc->frame_rx, last_slot);
-    } else {
-      if (proc->frame_rx%100==0) {
-	LOG_I(PHY,"[UE  %d] frame %d, slot %d, Writing %d bytes EMOS data to FIFO\n",Mod_id,proc->frame_rx, last_slot, bytes);
-      }
-    }
-  }
-
-}
-#endif
-
-
-void restart_phy(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uint8_t eNB_id,uint8_t abstraction_flag)
-{
-
-  //  uint8_t last_slot;
-  uint8_t i;
-  LOG_I(PHY,"[UE  %d] frame %d, slot %d, restarting PHY!\n",ue->Mod_id,proc->frame_rx,proc->subframe_rx);
-  mac_xface->macphy_exit("restart_phy called");
-  //   first_run = 1;
-
-  if (abstraction_flag ==0 ) {
-    ue->UE_mode[eNB_id] = NOT_SYNCHED;
-  } else {
-    ue->UE_mode[eNB_id] = PRACH;
-    ue->prach_resources[eNB_id]=NULL;
-  }
-
-  proc->frame_rx = -1;
-  proc->frame_tx = -1;
-  //  ue->synch_wait_cnt=0;
-  //  ue->sched_cnt=-1;
-
-  ue->pbch_vars[eNB_id]->pdu_errors_conseq=0;
-  ue->pbch_vars[eNB_id]->pdu_errors=0;
-
-  ue->pdcch_vars[0][eNB_id]->dci_errors = 0;
-  ue->pdcch_vars[0][eNB_id]->dci_missed = 0;
-  ue->pdcch_vars[0][eNB_id]->dci_false  = 0;
-  ue->pdcch_vars[0][eNB_id]->dci_received = 0;
-
-  ue->pdcch_vars[1][eNB_id]->dci_errors = 0;
-  ue->pdcch_vars[1][eNB_id]->dci_missed = 0;
-  ue->pdcch_vars[1][eNB_id]->dci_false  = 0;
-  ue->pdcch_vars[1][eNB_id]->dci_received = 0;
-
-  ue->dlsch_errors[eNB_id] = 0;
-  ue->dlsch_errors_last[eNB_id] = 0;
-  ue->dlsch_received[eNB_id] = 0;
-  ue->dlsch_received_last[eNB_id] = 0;
-  ue->dlsch_fer[eNB_id] = 0;
-  ue->dlsch_SI_received[eNB_id] = 0;
-  ue->dlsch_ra_received[eNB_id] = 0;
-  ue->dlsch_p_received[eNB_id] = 0;
-  ue->dlsch_SI_errors[eNB_id] = 0;
-  ue->dlsch_ra_errors[eNB_id] = 0;
-  ue->dlsch_p_errors[eNB_id] = 0;
-
-  ue->dlsch_mch_received[eNB_id] = 0;
-
-  for (i=0; i < MAX_MBSFN_AREA ; i ++) {
-    ue->dlsch_mch_received_sf[i][eNB_id] = 0;
-    ue->dlsch_mcch_received[i][eNB_id] = 0;
-    ue->dlsch_mtch_received[i][eNB_id] = 0;
-    ue->dlsch_mcch_errors[i][eNB_id] = 0;
-    ue->dlsch_mtch_errors[i][eNB_id] = 0;
-    ue->dlsch_mcch_trials[i][eNB_id] = 0;
-    ue->dlsch_mtch_trials[i][eNB_id] = 0;
-  }
-
-  //ue->total_TBS[eNB_id] = 0;
-  //ue->total_TBS_last[eNB_id] = 0;
-  //ue->bitrate[eNB_id] = 0;
-  //ue->total_received_bits[eNB_id] = 0;
-}
-
-
 void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uint8_t abstraction_flag)
 {
 
@@ -2770,28 +2486,17 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
   for (pbch_trials=0; pbch_trials<4; pbch_trials++) {
     //for (pbch_phase=0;pbch_phase<4;pbch_phase++) {
     //LOG_I(PHY,"[UE  %d] Frame %d, Trying PBCH %d (NidCell %d, eNB_id %d)\n",ue->Mod_id,frame_rx,pbch_phase,ue->frame_parms.Nid_cell,eNB_id);
-    if (abstraction_flag == 0) {
-      pbch_tx_ant = rx_pbch(&ue->common_vars,
-			    ue->pbch_vars[eNB_id],
-			    &ue->frame_parms,
-			    eNB_id,
-			    ue->frame_parms.nb_antenna_ports_eNB==1?SISO:ALAMOUTI,
-			    ue->high_speed_flag,
-			    pbch_phase);
-
-
-
-    }
-
-#ifdef PHY_ABSTRACTION
-    else {
-      pbch_tx_ant = rx_pbch_emul(ue,
-				 eNB_id,
-				 pbch_phase);
-    }
+    pbch_tx_ant = rx_pbch(&ue->common_vars,
+			  ue->pbch_vars[eNB_id],
+			  &ue->frame_parms,
+			  eNB_id,
+			  ue->frame_parms.nb_antenna_ports_eNB==1?SISO:ALAMOUTI,
+			  ue->high_speed_flag,
+			  pbch_phase);
+    
 
-#endif
 
+    
     if ((pbch_tx_ant>0) && (pbch_tx_ant<=4)) {
       break;
     }
@@ -2830,8 +2535,8 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
     frame_tx += pbch_phase;
 
     if (ue->mac_enabled==1) {
-      mac_xface->dl_phy_sync_success(ue->Mod_id,frame_rx,eNB_id,
-				     ue->UE_mode[eNB_id]==NOT_SYNCHED ? 1 : 0);
+      dl_phy_sync_success(ue->Mod_id,frame_rx,eNB_id,
+			  ue->UE_mode[eNB_id]==NOT_SYNCHED ? 1 : 0);
     }
     
 #ifdef EMOS
@@ -2911,16 +2616,11 @@ void ue_pbch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc, uin
 
     ue->pbch_vars[eNB_id]->pdu_errors_conseq++;
     ue->pbch_vars[eNB_id]->pdu_errors++;
-    if (ue->mac_enabled == 1) {
-      mac_xface->out_of_sync_ind(ue->Mod_id,frame_rx,eNB_id);
-    }
-    else{
-      if (ue->pbch_vars[eNB_id]->pdu_errors_conseq>=100) {
-	LOG_E(PHY,"More that 100 consecutive PBCH errors! Exiting!\n");
-	mac_xface->macphy_exit("More that 100 consecutive PBCH errors!");
-      }
-    }
+    if (ue->mac_enabled == 1) rrc_out_of_sync_ind(ue->Mod_id,frame_rx,eNB_id);
+    else AssertFatal(ue->pbch_vars[eNB_id]->pdu_errors_conseq<100,
+		     "More that 100 consecutive PBCH errors! Exiting!\n");
   }
+  
 
   if (frame_rx % 100 == 0) {
     ue->pbch_vars[eNB_id]->pdu_fer = ue->pbch_vars[eNB_id]->pdu_errors - ue->pbch_vars[eNB_id]->pdu_errors_last;
@@ -2946,96 +2646,37 @@ int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint
   DCI_ALLOC_t dci_alloc_rx[8];
 
 
-#ifdef PHY_ABSTRACTION
-  int CC_id;
-  int UE_id;
-  uint8_t harq_pid;
-#endif
-
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PDCCH_PROCEDURES, VCD_FUNCTION_IN);
   start_meas(&ue->dlsch_rx_pdcch_stats);
 
-  //  if (subframe_rx != 5)
-  //    return 0;
-  if (abstraction_flag == 0)  {
-
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PDCCH, VCD_FUNCTION_IN);
-    rx_pdcch(ue,
-	     proc->frame_rx,
-	     subframe_rx,
-	     eNB_id,
-	     (ue->frame_parms.nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI,
-	     ue->high_speed_flag,
-	     ue->is_secondary_ue);
-
-
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PDCCH, VCD_FUNCTION_OUT);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DCI_DECODING, VCD_FUNCTION_IN);
-    dci_cnt = dci_decoding_procedure(ue,
-				     dci_alloc_rx,
-				     (ue->UE_mode[eNB_id] < PUSCH)? 1 : 0,  // if we're in PUSCH don't listen to common search space,
-				     // later when we need paging or RA during connection, update this ...
-				     eNB_id,subframe_rx);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DCI_DECODING, VCD_FUNCTION_OUT);
-    //LOG_D(PHY,"[UE  %d][PUSCH] Frame %d subframe %d PHICH RX\n",ue->Mod_id,frame_rx,subframe_rx);
-
-    if (is_phich_subframe(&ue->frame_parms,subframe_rx)) {
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PHICH, VCD_FUNCTION_IN);
-      rx_phich(ue,proc,
-	       subframe_rx,eNB_id);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PHICH, VCD_FUNCTION_OUT);
-    }
-  }
-
-#ifdef PHY_ABSTRACTION
-  else {
-    for (i=0; i<NB_eNB_INST; i++) {
-      for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++)
-	if (RC.eNB[i][CC_id]->frame_parms.Nid_cell == ue->frame_parms.Nid_cell)
-	  break;
-
-      if (CC_id < MAX_NUM_CCs)
-	break;
-    }
-
-    if (i==NB_eNB_INST) {
-      LOG_E(PHY,"[UE  %d] phy_procedures_lte_ue.c: FATAL : Could not find attached eNB for DCI emulation (Nid_cell %d)!!!!\n",ue->Mod_id,ue->frame_parms.Nid_cell);
-      mac_xface->macphy_exit("Could not find attached eNB for DCI emulation");
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_PDCCH_PROCEDURES, VCD_FUNCTION_OUT);
-      return(-1);
-    }
-
-    LOG_D(PHY,"Calling dci_decoding_proc_emul ...\n");
 
-    dci_cnt = dci_decoding_procedure_emul(ue->pdcch_vars,
-					  RC.eNB[i][CC_id]->num_ue_spec_dci[subframe_rx&1],
-					  RC.eNB[i][CC_id]->num_common_dci[subframe_rx&1],
-					  RC.eNB[i][CC_id]->dci_alloc[subframe_rx&1],
-					  dci_alloc_rx,
-					  eNB_id);
-    //    printf("DCI: dci_cnt %d\n",dci_cnt);
-    UE_id = (uint32_t)find_ue((int16_t)ue->pdcch_vars[0][eNB_id]->crnti,RC.eNB[i][CC_id]);
-
-    if (UE_id>=0) {
-      //      printf("Checking PHICH for UE  %d (eNB %d)\n",UE_id,i);
-      if (is_phich_subframe(&ue->frame_parms,subframe_rx)) {
-	harq_pid = phich_subframe_to_harq_pid(&ue->frame_parms,frame_rx,subframe_rx);
-
-	if (ue->ulsch[eNB_id]->harq_processes[harq_pid]->status == ACTIVE) {
-	  // ue->ulsch[eNB_id]->harq_processes[harq_pid]->phich_ACK=1;
-	  ue->ulsch[eNB_id]->harq_processes[harq_pid]->subframe_scheduling_flag =0;
-	  ue->ulsch[eNB_id]->harq_processes[harq_pid]->status = IDLE;
-	  ue->ulsch_Msg3_active[eNB_id] = 0;
-	  ue->ulsch[eNB_id]->harq_processes[harq_pid]->round = 0;
-	  LOG_D(PHY,"Msg3 inactive\n");
-
-	} // harq_pid is ACTIVE
-      } // This is a PHICH subframe
-    } // UE_id exists
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PDCCH, VCD_FUNCTION_IN);
+  rx_pdcch(ue,
+	   proc->frame_rx,
+	   subframe_rx,
+	   eNB_id,
+	   (ue->frame_parms.nb_antenna_ports_eNB == 1) ? SISO : ALAMOUTI,
+	   ue->high_speed_flag,
+	   ue->is_secondary_ue);
+  
+  
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PDCCH, VCD_FUNCTION_OUT);
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DCI_DECODING, VCD_FUNCTION_IN);
+  dci_cnt = dci_decoding_procedure(ue,
+				   dci_alloc_rx,
+				   (ue->UE_mode[eNB_id] < PUSCH)? 1 : 0,  // if we're in PUSCH don't listen to common search space,
+				   // later when we need paging or RA during connection, update this ...
+				   eNB_id,subframe_rx);
+  VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DCI_DECODING, VCD_FUNCTION_OUT);
+  //LOG_D(PHY,"[UE  %d][PUSCH] Frame %d subframe %d PHICH RX\n",ue->Mod_id,frame_rx,subframe_rx);
+  
+  if (is_phich_subframe(&ue->frame_parms,subframe_rx)) {
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PHICH, VCD_FUNCTION_IN);
+    rx_phich(ue,proc,
+	     subframe_rx,eNB_id);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RX_PHICH, VCD_FUNCTION_OUT);
   }
-
-#endif
-
+  
 
   LOG_D(PHY,"[UE  %d] AbsSubFrame %d.%d, Mode %s: DCI found %i --> rnti %x / crnti %x : format %d\n",
        ue->Mod_id,frame_rx%1024,subframe_rx,mode_string[ue->UE_mode[eNB_id]],
@@ -3045,11 +2686,6 @@ int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint
        dci_alloc_rx[0].format );
 
   ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->dci_received += dci_cnt;
-
-#ifdef EMOS
-  //emos_dump_UE.dci_cnt[subframe_rx] = dci_cnt;
-#endif
-
   for (i=0; i<dci_cnt; i++) {
 
 
@@ -3113,7 +2749,6 @@ int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint
 #endif
 	  //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
 	  ue->UE_mode[eNB_id] = PUSCH;
-	  //mac_xface->macphy_exit("Connected. Exiting\n");
 	}
       } else {
 	LOG_E(PHY,"[UE  %d] Frame %d, subframe %d: Problem in DCI!\n",ue->Mod_id,frame_rx,subframe_rx);
@@ -3189,10 +2824,6 @@ int ue_pdcch_procedures(uint8_t eNB_id,PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint
 
 #ifdef DEBUG_PHY_PROC
       LOG_I(PHY,"[UE  %d][RAPROC] subframe %d: Found RA rnti %x, format 1A, dci_cnt %d\n",ue->Mod_id,subframe_rx,dci_alloc_rx[i].rnti,i);
-
-      //if (((frame_rx%100) == 0) || (frame_rx < 20))
-      //dump_dci(&ue->frame_parms, &dci_alloc_rx[i]);
-      //mac_xface->macphy_exit("so far so good...\n");
 #endif
 
 
@@ -3334,13 +2965,13 @@ void ue_pmch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,int eNB_id,int abs
     LOG_D(PHY,"[UE %d] Frame %d, subframe %d: Querying for PMCH demodulation\n",
 	  ue->Mod_id,(subframe_rx==9?-1:0)+frame_rx,subframe_rx);
 #if defined(Rel10) || defined(Rel14)
-    pmch_mcs = mac_xface->ue_query_mch(ue->Mod_id,
-				       CC_id,
-				       frame_rx,
-				       subframe_rx,
-				       eNB_id,
-				       &sync_area,
-				       &mcch_active);
+    pmch_mcs = ue_query_mch(ue->Mod_id,
+			    CC_id,
+			    frame_rx,
+			    subframe_rx,
+			    eNB_id,
+			    &sync_area,
+			    &mcch_active);
     
 #else
     pmch_mcs=-1;
@@ -3350,55 +2981,45 @@ void ue_pmch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,int eNB_id,int abs
       LOG_D(PHY,"[UE %d] Frame %d, subframe %d: Programming PMCH demodulation for mcs %d\n",ue->Mod_id,frame_rx,subframe_rx,pmch_mcs);
       fill_UE_dlsch_MCH(ue,pmch_mcs,1,0,0);
       
-      if (abstraction_flag == 0 ) {
-	for (l=2; l<12; l++) {
-	  
-	  slot_fep_mbsfn(ue,
-			 l,
-			 subframe_rx,
-			 0,0);//ue->rx_offset,0);
-	}
-
-	for (l=2; l<12; l++) {
-	  rx_pmch(ue,
-		  0,
-		  subframe_rx,
-		  l);
-	}
-
-
-	ue->dlsch_MCH[0]->harq_processes[0]->G = get_G(&ue->frame_parms,
-						       ue->dlsch_MCH[0]->harq_processes[0]->nb_rb,
-						       ue->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even,
-						       ue->dlsch_MCH[0]->harq_processes[0]->Qm,
-						       1,
-						       2,
-						       frame_rx,
-						       subframe_rx,
-						       0);
-	
-	dlsch_unscrambling(&ue->frame_parms,1,ue->dlsch_MCH[0],
-			   ue->dlsch_MCH[0]->harq_processes[0]->G,
-			   ue->pdsch_vars_MCH[0]->llr[0],0,subframe_rx<<1);
+      for (l=2; l<12; l++) {
 	
-	ret = dlsch_decoding(ue,
-			     ue->pdsch_vars_MCH[0]->llr[0],
-			     &ue->frame_parms,
-			     ue->dlsch_MCH[0],
-			     ue->dlsch_MCH[0]->harq_processes[0],
-			     frame_rx,
-			     subframe_rx,
-			     0,
-			     0,1);
-      } else { // abstraction
-#ifdef PHY_ABSTRACTION
-	ret = dlsch_decoding_emul(ue,
-				  subframe_rx,
-				  5, // PMCH
-				  eNB_id);
-#endif
+	slot_fep_mbsfn(ue,
+		       l,
+		       subframe_rx,
+		       0,0);//ue->rx_offset,0);
+      }
+      
+      for (l=2; l<12; l++) {
+	rx_pmch(ue,
+		0,
+		subframe_rx,
+		l);
       }
       
+      
+      ue->dlsch_MCH[0]->harq_processes[0]->G = get_G(&ue->frame_parms,
+						     ue->dlsch_MCH[0]->harq_processes[0]->nb_rb,
+						     ue->dlsch_MCH[0]->harq_processes[0]->rb_alloc_even,
+						     ue->dlsch_MCH[0]->harq_processes[0]->Qm,
+						     1,
+						     2,
+						     frame_rx,
+						     subframe_rx,
+						     0);
+      
+      dlsch_unscrambling(&ue->frame_parms,1,ue->dlsch_MCH[0],
+			 ue->dlsch_MCH[0]->harq_processes[0]->G,
+			 ue->pdsch_vars_MCH[0]->llr[0],0,subframe_rx<<1);
+      
+      ret = dlsch_decoding(ue,
+			   ue->pdsch_vars_MCH[0]->llr[0],
+			   &ue->frame_parms,
+			   ue->dlsch_MCH[0],
+			   ue->dlsch_MCH[0]->harq_processes[0],
+			   frame_rx,
+			   subframe_rx,
+			   0,
+			   0,1);
       if (mcch_active == 1)
 	ue->dlsch_mcch_trials[sync_area][0]++;
       else
@@ -3428,19 +3049,19 @@ void ue_pmch_procedures(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc,int eNB_id,int abs
 	LOG_T(PHY,"\n");
 #endif
 	
-	if (subframe_rx==9)
-	  mac_xface->macphy_exit("Why are we exiting here?");
+	//	if (subframe_rx==9)
+	//  mac_xface->macphy_exit("Why are we exiting here?");
       } else { // decoding successful
 #if defined(Rel10) || defined(Rel14)
 	
 	if (mcch_active == 1) {
-	  mac_xface->ue_send_mch_sdu(ue->Mod_id,
-				     CC_id,
-				     frame_rx,
-				     ue->dlsch_MCH[0]->harq_processes[0]->b,
-				     ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
-				     eNB_id,// not relevant in eMBMS context
-				     sync_area);
+	  ue_send_mch_sdu(ue->Mod_id,
+			  CC_id,
+			  frame_rx,
+			  ue->dlsch_MCH[0]->harq_processes[0]->b,
+			  ue->dlsch_MCH[0]->harq_processes[0]->TBS>>3,
+			  eNB_id,// not relevant in eMBMS context
+			  sync_area);
 	  ue->dlsch_mcch_received[sync_area][0]++;
 	  
 	  
@@ -3595,15 +3216,15 @@ void process_rar(PHY_VARS_UE *ue, UE_rxtx_proc_t *proc, int eNB_id, runmode_t mo
 	    subframe_rx,
 	    ue->prach_resources[eNB_id]->ra_PreambleIndex);
       
-      timing_advance = mac_xface->ue_process_rar(ue->Mod_id,
-						 ue->CC_id,
-						 frame_rx,
-						 ue->prach_resources[eNB_id]->ra_RNTI,
-						 dlsch0->harq_processes[0]->b,
-						 &ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->crnti,
-						 ue->prach_resources[eNB_id]->ra_PreambleIndex,
-						 dlsch0->harq_processes[0]->b); // alter the 'b' buffer so it contains only the selected RAR header and RAR payload
-
+      timing_advance = ue_process_rar(ue->Mod_id,
+				      ue->CC_id,
+				      frame_rx,
+				      ue->prach_resources[eNB_id]->ra_RNTI,
+				      dlsch0->harq_processes[0]->b,
+				      &ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->crnti,
+				      ue->prach_resources[eNB_id]->ra_PreambleIndex,
+				      dlsch0->harq_processes[0]->b); // alter the 'b' buffer so it contains only the selected RAR header and RAR payload
+      
       ue->pdcch_vars[(subframe_rx+1) & 0x1][eNB_id]->crnti = ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->crnti;
       
 	    
@@ -3732,134 +3353,117 @@ void ue_dlsch_procedures(PHY_VARS_UE *ue,
       *dlsch_errors=0;
 
     if (pdsch==RA_PDSCH) {
-      if (ue->prach_resources[eNB_id]!=NULL)
-	dlsch0->rnti = ue->prach_resources[eNB_id]->ra_RNTI;
-      else {
-	LOG_E(PHY,"[UE %d] Frame %d, subframe %d: FATAL, prach_resources is NULL\n",ue->Mod_id,frame_rx,subframe_rx);
-	mac_xface->macphy_exit("prach_resources is NULL");
-	return;
-      }
+      
+      AssertFatal(ue->prach_resources[eNB_id]!=NULL,"[UE %d] Frame %d, subframe %d: FATAL, prach_resources is NULL\n",ue->Mod_id,frame_rx,subframe_rx);
+      dlsch0->rnti = ue->prach_resources[eNB_id]->ra_RNTI;
     }
 
-    if (abstraction_flag == 0) {
-
-      // start turbo decode for CW 0
-      dlsch0->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
-						  dlsch0->harq_processes[harq_pid]->nb_rb,
-						  dlsch0->harq_processes[harq_pid]->rb_alloc_even,
-						  dlsch0->harq_processes[harq_pid]->Qm,
-						  dlsch0->harq_processes[harq_pid]->Nl,
-						  ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols,
-						  frame_rx,
-						  subframe_rx,
-						  ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
-      start_meas(&ue->dlsch_unscrambling_stats);
-      dlsch_unscrambling(&ue->frame_parms,
-			 0,
-			 dlsch0,
-			 dlsch0->harq_processes[harq_pid]->G,
-			 pdsch_vars->llr[0],
-			 0,
-			 subframe_rx<<1);
-      stop_meas(&ue->dlsch_unscrambling_stats);
-
+    // start turbo decode for CW 0
+    dlsch0->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
+						dlsch0->harq_processes[harq_pid]->nb_rb,
+						dlsch0->harq_processes[harq_pid]->rb_alloc_even,
+						dlsch0->harq_processes[harq_pid]->Qm,
+						dlsch0->harq_processes[harq_pid]->Nl,
+						ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols,
+						frame_rx,
+						subframe_rx,
+						ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
+    start_meas(&ue->dlsch_unscrambling_stats);
+    dlsch_unscrambling(&ue->frame_parms,
+		       0,
+		       dlsch0,
+		       dlsch0->harq_processes[harq_pid]->G,
+		       pdsch_vars->llr[0],
+		       0,
+		       subframe_rx<<1);
+    stop_meas(&ue->dlsch_unscrambling_stats);
+    
 #if 0
-      LOG_I(PHY," ------ start turbo decoder for AbsSubframe %d.%d / %d  ------  \n", frame_rx, subframe_rx, harq_pid);
-      LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->nb_rb);
-      LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->rb_alloc_even);
-      LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Qm);
-      LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Nl);
-      LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->G);
-      LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->Kmimo);
-      LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid, ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols);
+    LOG_I(PHY," ------ start turbo decoder for AbsSubframe %d.%d / %d  ------  \n", frame_rx, subframe_rx, harq_pid);
+    LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->nb_rb);
+    LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->rb_alloc_even);
+    LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Qm);
+    LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->Nl);
+    LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->harq_processes[harq_pid]->G);
+    LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch0->Kmimo);
+    LOG_I(PHY,"start turbo decode for CW 0 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid, ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols);
 #endif
-
-      start_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
-      ret = dlsch_decoding(ue,
-			   pdsch_vars->llr[0],
-			   &ue->frame_parms,
-			   dlsch0,
-			   dlsch0->harq_processes[harq_pid],
-			   frame_rx,
-			   subframe_rx,
-			   harq_pid,
-			   pdsch==PDSCH?1:0,
-			   dlsch0->harq_processes[harq_pid]->TBS>256?1:0);
-      stop_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
-
-      LOG_D(PHY," --> Unscrambling for CW0 %5.3f\n",
-              (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
-      LOG_D(PHY,"AbsSubframe %d.%d --> Turbo Decoding for CW0 %5.3f\n",
-              frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[subframe_rx&0x1].p_time)/(cpuf*1000.0));
-
-
-      if(is_cw1_active)
+    
+    start_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
+    ret = dlsch_decoding(ue,
+			 pdsch_vars->llr[0],
+			 &ue->frame_parms,
+			 dlsch0,
+			 dlsch0->harq_processes[harq_pid],
+			 frame_rx,
+			 subframe_rx,
+			 harq_pid,
+			 pdsch==PDSCH?1:0,
+			 dlsch0->harq_processes[harq_pid]->TBS>256?1:0);
+    stop_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
+    
+    LOG_D(PHY," --> Unscrambling for CW0 %5.3f\n",
+	  (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
+    LOG_D(PHY,"AbsSubframe %d.%d --> Turbo Decoding for CW0 %5.3f\n",
+	  frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[subframe_rx&0x1].p_time)/(cpuf*1000.0));
+    
+    
+    if(is_cw1_active)
       {
-          // start turbo decode for CW 1
-          dlsch1->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
-                  dlsch1->harq_processes[harq_pid]->nb_rb,
-                  dlsch1->harq_processes[harq_pid]->rb_alloc_even,
-                  dlsch1->harq_processes[harq_pid]->Qm,
-                  dlsch1->harq_processes[harq_pid]->Nl,
-                  ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols,
-                  frame_rx,
-                  subframe_rx,
-                  ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
-
-          start_meas(&ue->dlsch_unscrambling_stats);
-          dlsch_unscrambling(&ue->frame_parms,
-                  0,
-                  dlsch1,
-                  dlsch1->harq_processes[harq_pid]->G,
-                  pdsch_vars->llr[1],
-                  1,
-                  subframe_rx<<1);
-          stop_meas(&ue->dlsch_unscrambling_stats);
-
+	// start turbo decode for CW 1
+	dlsch1->harq_processes[harq_pid]->G = get_G(&ue->frame_parms,
+						    dlsch1->harq_processes[harq_pid]->nb_rb,
+						    dlsch1->harq_processes[harq_pid]->rb_alloc_even,
+						    dlsch1->harq_processes[harq_pid]->Qm,
+						    dlsch1->harq_processes[harq_pid]->Nl,
+						    ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols,
+						    frame_rx,
+						    subframe_rx,
+						    ue->transmission_mode[eNB_id]<7?0:ue->transmission_mode[eNB_id]);
+	
+	start_meas(&ue->dlsch_unscrambling_stats);
+	dlsch_unscrambling(&ue->frame_parms,
+			   0,
+			   dlsch1,
+			   dlsch1->harq_processes[harq_pid]->G,
+			   pdsch_vars->llr[1],
+			   1,
+			   subframe_rx<<1);
+	stop_meas(&ue->dlsch_unscrambling_stats);
+	
 #if 0
-          LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->nb_rb);
-          LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->rb_alloc_even);
-          LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Qm);
-          LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Nl);
-          LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->G);
-          LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->Kmimo);
-          LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid, ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols);
+	LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d --> nb_rb %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->nb_rb);
+	LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> rb_alloc_even %x \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->rb_alloc_even);
+	LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Qm %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Qm);
+	LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Nl %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->Nl);
+	LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> G  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->harq_processes[harq_pid]->G);
+	LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Kmimo  %d \n", frame_rx, subframe_rx, harq_pid, dlsch1->Kmimo);
+	LOG_I(PHY,"start turbo decode for CW 1 for AbsSubframe %d.%d / %d  --> Pdcch Sym  %d \n", frame_rx, subframe_rx, harq_pid, ue->pdcch_vars[subframe_rx & 0x1][eNB_id]->num_pdcch_symbols);
 #endif
-
-          start_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
-
-          ret1 = dlsch_decoding(ue,
-                  pdsch_vars->llr[1],
-                  &ue->frame_parms,
-                  dlsch1,
-                  dlsch1->harq_processes[harq_pid],
-                  frame_rx,
-                  subframe_rx,
-                  harq_pid,
-                  pdsch==PDSCH?1:0,
-                  dlsch1->harq_processes[harq_pid]->TBS>256?1:0);
-          stop_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
-
-
-          LOG_D(PHY," --> Unscrambling for CW1 %5.3f\n",
-                  (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
-          LOG_D(PHY,"AbsSubframe %d.%d --> Turbo Decoding for CW1 %5.3f\n",
-                  frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[subframe_rx&0x1].p_time)/(cpuf*1000.0));
-      }
-
-      LOG_D(PHY," ------ end turbo decoder for AbsSubframe %d.%d ------  \n", frame_rx, subframe_rx);
-    }
 	
-    else {
-      LOG_D(PHY,"Calling dlsch_decoding_emul ...\n");
-#ifdef PHY_ABSTRACTION
-      ret = dlsch_decoding_emul(ue,
-				subframe_rx,
-				pdsch,
-				eNB_id);
-#endif
-    }
+	start_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
 	
+	ret1 = dlsch_decoding(ue,
+			      pdsch_vars->llr[1],
+			      &ue->frame_parms,
+			      dlsch1,
+			      dlsch1->harq_processes[harq_pid],
+			      frame_rx,
+			      subframe_rx,
+			      harq_pid,
+			      pdsch==PDSCH?1:0,
+			      dlsch1->harq_processes[harq_pid]->TBS>256?1:0);
+	stop_meas(&ue->dlsch_decoding_stats[subframe_rx&0x1]);
+	
+	
+	LOG_D(PHY," --> Unscrambling for CW1 %5.3f\n",
+	      (ue->dlsch_unscrambling_stats.p_time)/(cpuf*1000.0));
+	LOG_D(PHY,"AbsSubframe %d.%d --> Turbo Decoding for CW1 %5.3f\n",
+	      frame_rx%1024, subframe_rx,(ue->dlsch_decoding_stats[subframe_rx&0x1].p_time)/(cpuf*1000.0));
+      }
+    
+    LOG_D(PHY," ------ end turbo decoder for AbsSubframe %d.%d ------  \n", frame_rx, subframe_rx);
+  
     // Check CRC for CW 0
     if (ret == (1+dlsch0->max_turbo_iterations)) {
       *dlsch_errors=*dlsch_errors+1;
@@ -3902,29 +3506,29 @@ void ue_dlsch_procedures(PHY_VARS_UE *ue,
       if (ue->mac_enabled == 1) {
 	switch (pdsch) {
 	case PDSCH:
-	  mac_xface->ue_send_sdu(ue->Mod_id,
-				 CC_id,
-				 frame_rx,
-         subframe_rx,
-				 dlsch0->harq_processes[dlsch0->current_harq_pid]->b,
-				 dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS>>3,
-				 eNB_id);
+	  ue_send_sdu(ue->Mod_id,
+		      CC_id,
+		      frame_rx,
+		      subframe_rx,
+		      dlsch0->harq_processes[dlsch0->current_harq_pid]->b,
+		      dlsch0->harq_processes[dlsch0->current_harq_pid]->TBS>>3,
+		      eNB_id);
 	  break;
 	case SI_PDSCH:
-	  mac_xface->ue_decode_si(ue->Mod_id,
-				  CC_id,
-				  frame_rx,
-				  eNB_id,
-				  ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
-				  ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
+	  ue_decode_si(ue->Mod_id,
+		       CC_id,
+		       frame_rx,
+		       eNB_id,
+		       ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
+		       ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
 	  break;
 	case P_PDSCH:
-	  mac_xface->ue_decode_p(ue->Mod_id,
-				 CC_id,
-				 frame_rx,
-				 eNB_id,
-				 ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
-				 ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
+	  ue_decode_p(ue->Mod_id,
+		      CC_id,
+		      frame_rx,
+		      eNB_id,
+		      ue->dlsch_SI[eNB_id]->harq_processes[0]->b,
+		      ue->dlsch_SI[eNB_id]->harq_processes[0]->TBS>>3);
 	  break;
 	case RA_PDSCH:
 	  process_rar(ue,proc,eNB_id,mode,abstraction_flag);
@@ -3969,13 +3573,13 @@ void ue_dlsch_procedures(PHY_VARS_UE *ue,
                 switch (pdsch) {
                 case PDSCH:
                     if(is_cw1_active)
-                        mac_xface->ue_send_sdu(ue->Mod_id,
-                                CC_id,
-                                frame_rx,
-                                subframe_rx,
-                                dlsch1->harq_processes[dlsch1->current_harq_pid]->b,
-                                dlsch1->harq_processes[dlsch1->current_harq_pid]->TBS>>3,
-                                eNB_id);
+                        ue_send_sdu(ue->Mod_id,
+				    CC_id,
+				    frame_rx,
+				    subframe_rx,
+				    dlsch1->harq_processes[dlsch1->current_harq_pid]->b,
+				    dlsch1->harq_processes[dlsch1->current_harq_pid]->TBS>>3,
+				    eNB_id);
                     break;
                 case SI_PDSCH:
                 case P_PDSCH:
@@ -4106,18 +3710,17 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
   LOG_D(PHY," ------ slot 0 Processing: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
   LOG_D(PHY," ------  --> FFT/ChannelEst/PDCCH slot 0: AbsSubframe %d.%d ------  \n", frame_rx%1024, subframe_rx);
   for (; l<=l2; l++) {
-    if (abstraction_flag == 0) {
-      start_meas(&ue->ofdm_demod_stats);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
-      slot_fep(ue,
-	       l,
-	       (subframe_rx<<1),
-	       0,
-	       0,
-	       0);
-      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
-      stop_meas(&ue->ofdm_demod_stats);
-    }
+    start_meas(&ue->ofdm_demod_stats);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
+    slot_fep(ue,
+	     l,
+	     (subframe_rx<<1),
+	     0,
+	     0,
+	     0);
+    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
+    stop_meas(&ue->ofdm_demod_stats);
+  
     
     ue_measurement_procedures(l-1,ue,proc,eNB_id,(subframe_rx<<1),abstraction_flag,mode);
     if ((l==pilot1) ||
@@ -4220,18 +3823,17 @@ int phy_procedures_UE_RX(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uin
 
   if (subframe_select(&ue->frame_parms,subframe_rx) != SF_S) {  // do front-end processing for second slot, and first symbol of next subframe
     for (l=1; l<ue->frame_parms.symbols_per_tti>>1; l++) {
-      if (abstraction_flag == 0) {
-	start_meas(&ue->ofdm_demod_stats);
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
-	slot_fep(ue,
-		 l,
-		 1+(subframe_rx<<1),
-		 0,
-		 0,
-		 0);
-	VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
-	stop_meas(&ue->ofdm_demod_stats);
-      }
+      start_meas(&ue->ofdm_demod_stats);
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_IN);
+      slot_fep(ue,
+	       l,
+	       1+(subframe_rx<<1),
+	       0,
+	       0,
+	       0);
+      VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SLOT_FEP, VCD_FUNCTION_OUT);
+      stop_meas(&ue->ofdm_demod_stats);
+    
       
       ue_measurement_procedures(l-1,ue,proc,eNB_id,1+(subframe_rx<<1),abstraction_flag,mode);
       
@@ -4560,15 +4162,15 @@ void phy_procedures_UE_lte(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,u
        
     if (ue->mac_enabled==1) {
       if (slot==0) {
-        ret = mac_xface->ue_scheduler(ue->Mod_id,
-            frame_rx,
-            subframe_rx,
-            frame_tx,
-            subframe_tx,
-            subframe_select(&ue->frame_parms,subframe_tx),
-            eNB_id,
-            0/*FIXME CC_id*/);
-	   
+        ret = ue_scheduler(ue->Mod_id,
+			   frame_rx,
+			   subframe_rx,
+			   frame_tx,
+			   subframe_tx,
+			   subframe_select(&ue->frame_parms,subframe_tx),
+			   eNB_id,
+			   0/*FIXME CC_id*/);
+	
 	if (ret == CONNECTION_LOST) {
 	  LOG_E(PHY,"[UE %d] Frame %d, subframe %d RRC Connection lost, returning to PRACH\n",ue->Mod_id,
 		frame_rx,subframe_tx);
diff --git a/openair1/SCHED/pusch_pc.c b/openair1/SCHED/pusch_pc.c
index a03dd7fd3cb4b389677a6c8217ba25bc60f6ab16..ba17358d321f6a78738325247fa2677107938b6d 100644
--- a/openair1/SCHED/pusch_pc.c
+++ b/openair1/SCHED/pusch_pc.c
@@ -98,7 +98,7 @@ int16_t get_hundred_times_delta_IF_mac(module_id_t module_idP, uint8_t CC_id, rn
     return -1;
   }
 
-  UE_id = find_ue( rnti, RC.eNB[module_idP][CC_id] );
+  UE_id = find_ulsch( rnti, RC.eNB[module_idP][CC_id],SEARCH_EXIST);
 
   if (UE_id == -1) {
     // not found
@@ -161,11 +161,11 @@ void pusch_power_cntl(PHY_VARS_UE *ue,UE_rxtx_proc_t *proc,uint8_t eNB_id,uint8_
 
   if(ue->ulsch_Msg3_active[eNB_id] == 1) {  // Msg3 PUSCH
 
-    ue->ulsch[eNB_id]->Po_PUSCH += (mac_xface->get_Po_NOMINAL_PUSCH(ue->Mod_id,0) + PL);
+    ue->ulsch[eNB_id]->Po_PUSCH += (get_Po_NOMINAL_PUSCH(ue->Mod_id,0) + PL);
 
     LOG_I(PHY,"[UE  %d][RAPROC] frame %d, subframe %d: Msg3 Po_PUSCH %d dBm (%d,%d,100*PL=%d,%d,%d)\n",
           ue->Mod_id,proc->frame_tx,proc->subframe_tx,ue->ulsch[eNB_id]->Po_PUSCH,
-          100*mac_xface->get_Po_NOMINAL_PUSCH(ue->Mod_id,0),
+          100*get_Po_NOMINAL_PUSCH(ue->Mod_id,0),
           hundred_times_log10_NPRB[nb_rb-1],
           100*PL,
           get_hundred_times_delta_IF(ue,eNB_id,harq_pid),
diff --git a/openair2/COMMON/mac_rrc_primitives.h b/openair2/COMMON/mac_rrc_primitives.h
index e159530d7662cec582324002b117583a8c91b38e..49d22a8ceb0256c18d0ebf2dcca9c4174b58c23c 100644
--- a/openair2/COMMON/mac_rrc_primitives.h
+++ b/openair2/COMMON/mac_rrc_primitives.h
@@ -92,13 +92,6 @@ result could be based on an event-driven measurement report.
 #define RRC_RACH_ASS_REQ 0
 #define MAC_RACH_BW_REQ 1
 
-typedef enum {
-  RRC_OK=0,
-  RRC_ConnSetup_failed,
-  RRC_PHY_RESYNCH,
-  RRC_Handover_failed,
-  RRC_HO_STARTED
-} RRC_status_t;
 
 
 /*! MAC/PHY Measurement Structure*/
@@ -225,17 +218,7 @@ typedef struct {
 
 /*! \brief MAC Logical Channel Descriptor
  */
-typedef struct {
-  unsigned short transport_block_size;                  /*!< \brief Minimum PDU size in bytes provided by RLC to MAC layer interface */
-  unsigned short max_transport_blocks;                  /*!< \brief Maximum PDU size in bytes provided by RLC to MAC layer interface */
-  unsigned long  Guaranteed_bit_rate;           /*!< \brief Guaranteed Bit Rate (average) to be offered by MAC layer scheduling*/
-  unsigned long  Max_bit_rate;                  /*!< \brief Maximum Bit Rate that can be offered by MAC layer scheduling*/
-  uint8_t  Delay_class;                  /*!< \brief Delay class offered by MAC layer scheduling*/
-  uint8_t  Target_bler;                  /*!< \brief Target Average Transport Block Error rate*/
-  uint8_t  Lchan_t;                      /*!< \brief Logical Channel Type (BCCH,CCCH,DCCH,DTCH_B,DTCH,MRBCH)*/
-} __attribute__ ((__packed__))  LCHAN_DESC;
-
-#define LCHAN_DESC_SIZE sizeof(LCHAN_DESC)
+
 
 /*!\brief This primitive indicates to RRC that a particular logical channel has been established and that successful transmission has
 been received.  The parameter passed is the logical channel id.
diff --git a/openair2/COMMON/rrc_messages_types.h b/openair2/COMMON/rrc_messages_types.h
index 6633389cedb4ba6c372889dc39970cb2cbeda357..cd8b533dd3aab92a5a1f0817a2e1204f2f77598e 100644
--- a/openair2/COMMON/rrc_messages_types.h
+++ b/openair2/COMMON/rrc_messages_types.h
@@ -100,6 +100,7 @@ typedef struct RrcConfigurationReq_s {
   uint8_t                 tdd_config[MAX_NUM_CCs];
   uint8_t                 tdd_config_s[MAX_NUM_CCs];
   lte_prefix_type_t       prefix_type[MAX_NUM_CCs];
+  uint8_t                 pbch_repetition[MAX_NUM_CCs];
   int16_t                 eutra_band[MAX_NUM_CCs];
   uint32_t                downlink_frequency[MAX_NUM_CCs];
   int32_t                 uplink_frequency_offset[MAX_NUM_CCs];
diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c
index 16f7a1a7f68378f125d8e0d412249a8165242300..7cce68c143cc265aafc3c373538df56413626344 100644
--- a/openair2/ENB_APP/enb_app.c
+++ b/openair2/ENB_APP/enb_app.c
@@ -303,16 +303,22 @@ void *eNB_app_task(void *args_p)
   long                            enb_register_retry_timer_id;
 # endif
   uint32_t                        enb_id;
-  MessageDef                     *msg_p           = NULL;
-  const char                     *msg_name        = NULL;
+  MessageDef                      *msg_p           = NULL;
+  const char                      *msg_name        = NULL;
   instance_t                      instance;
   int                             result;
-
+  int                             j;
   /* for no gcc warnings */
   (void)instance;
 
   itti_mark_task_ready (TASK_ENB_APP);
 
+  RCconfig_L1();
+
+  RCconfig_macrlc();
+
+  if (RC.nb_L1_inst>0) AssertFatal(l1_north_init_eNB()==0,"could not initialize L1 north interface\n");
+
   # if defined(ENABLE_ITTI)
 #   if defined(OAI_EMU)
   enb_nb =        oai_emulation.info.nb_enb_local;
@@ -337,10 +343,10 @@ void *eNB_app_task(void *args_p)
   for (enb_id = enb_id_start; (enb_id < enb_id_end) ; enb_id++) {
     //    configure_phy(enb_id);//
     RC.rrc[enb_id] = (eNB_RRC_INST*)malloc(sizeof(eNB_RRC_INST));
-
+    
     configure_rrc(enb_id);//
   }
-
+  
 #if defined (FLEXRAN_AGENT_SB_IF)
   
   for (enb_id = enb_id_start; (enb_id < enb_id_end) ; enb_id++) {
@@ -348,6 +354,8 @@ void *eNB_app_task(void *args_p)
     flexran_agent_start(enb_id, enb_properties_p);
   }
 #endif 
+  
+
 
 # if defined(ENABLE_USE_MME)
   /* Try to register each eNB */
diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c
index 74be7b4208465d68d892ab38ac20d734464cd098..615199ba8f1ed4a067969938836e7ab544c583f0 100644
--- a/openair2/ENB_APP/enb_config.c
+++ b/openair2/ENB_APP/enb_config.c
@@ -86,6 +86,16 @@
 #define ENB_CONFIG_STRING_MOBILE_COUNTRY_CODE           "mobile_country_code"
 #define ENB_CONFIG_STRING_MOBILE_NETWORK_CODE           "mobile_network_code"
 
+#define ENB_CONFIG_STRING_LOCAL_S_IF_NAME               "local_s_if_name"
+#define ENB_CONFIG_STRING_LOCAL_S_ADDRESS               "local_s_address"
+#define ENB_CONFIG_STRING_REMOTE_S_ADDRESS              "remote_s_address"
+#define ENB_CONFIG_STRING_LOCAL_S_PORTC                 "local_s_portc"
+#define ENB_CONFIG_STRING_REMOTE_S_PORTC                "remote_s_portc"
+#define ENB_CONFIG_STRING_LOCAL_S_PORTD                 "local_s_portd"
+#define ENB_CONFIG_STRING_REMOTE_S_PORTD                "remote_s_portd"
+#define ENB_CONFIG_STRING_TRANSPORT_S_PREFERENCE        "tr_s_preference"
+
+
 #define ENB_CONFIG_STRING_COMPONENT_CARRIERS                            "component_carriers"
 
 #define ENB_CONFIG_STRING_CC_NODE_FUNCTION                              "node_function"
@@ -96,6 +106,7 @@
 #define ENB_CONFIG_STRING_TDD_CONFIG                                    "tdd_config"
 #define ENB_CONFIG_STRING_TDD_CONFIG_S                                  "tdd_config_s"
 #define ENB_CONFIG_STRING_PREFIX_TYPE                                   "prefix_type"
+#define ENB_CONFIG_STRING_PBCH_REPETITION                               "pbch_repetition"
 #define ENB_CONFIG_STRING_EUTRA_BAND                                    "eutra_band"
 #define ENB_CONFIG_STRING_DOWNLINK_FREQUENCY                            "downlink_frequency"
 #define ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET                       "uplink_frequency_offset"
@@ -234,10 +245,40 @@
 #define ENB_CONFIG_STRING_OSA_LOG_LEVEL                    "osa_log_level"
 #define ENB_CONFIG_STRING_OSA_LOG_VERBOSITY                "osa_log_verbosity"
 
-
-#define CONFIG_STRING_ACTIVE_RUS                   "Active_RUs"
-#define CONFIG_STRING_RU_LIST                      "RUs"
-
+#define CONFIG_STRING_MACRLC_LIST                          "MACRLCs"
+#define CONFIG_STRING_MACRLC_CONFIG                        "macrlc_config"
+#define CONFIG_STRING_MACRLC_CC                            "num_cc"
+#define CONFIG_STRING_MACRLC_LOCAL_N_IF_NAME               "local_n_if_name"
+#define CONFIG_STRING_MACRLC_LOCAL_N_ADDRESS               "local_n_address"
+#define CONFIG_STRING_MACRLC_REMOTE_N_ADDRESS              "remote_n_address"
+#define CONFIG_STRING_MACRLC_LOCAL_N_PORTC                 "local_n_portc"
+#define CONFIG_STRING_MACRLC_REMOTE_N_PORTC                "remote_n_portc"
+#define CONFIG_STRING_MACRLC_LOCAL_N_PORTD                 "local_n_portd"
+#define CONFIG_STRING_MACRLC_REMOTE_N_PORTD                "remote_n_portd"
+#define CONFIG_STRING_MACRLC_LOCAL_S_IF_NAME               "local_s_if_name"
+#define CONFIG_STRING_MACRLC_LOCAL_S_ADDRESS               "local_s_address"
+#define CONFIG_STRING_MACRLC_REMOTE_S_ADDRESS              "remote_s_address"
+#define CONFIG_STRING_MACRLC_LOCAL_S_PORTC                 "local_s_portc"
+#define CONFIG_STRING_MACRLC_REMOTE_S_PORTC                "remote_s_portc"
+#define CONFIG_STRING_MACRLC_LOCAL_S_PORTD                 "local_s_portd"
+#define CONFIG_STRING_MACRLC_REMOTE_S_PORTD                "remote_s_portd"
+#define CONFIG_STRING_MACRLC_TRANSPORT_S_PREFERENCE        "tr_s_preference"
+#define CONFIG_STRING_MACRLC_TRANSPORT_N_PREFERENCE        "tr_n_preference"
+
+#define CONFIG_STRING_L1_LIST                              "L1s"
+#define CONFIG_STRING_L1_CONFIG                            "l1_config"
+#define CONFIG_STRING_L1_CC                                "num_cc"
+#define CONFIG_STRING_L1_LOCAL_N_IF_NAME                   "local_n_if_name"
+#define CONFIG_STRING_L1_LOCAL_N_ADDRESS                   "local_n_address"
+#define CONFIG_STRING_L1_REMOTE_N_ADDRESS                  "remote_n_address"
+#define CONFIG_STRING_L1_LOCAL_N_PORTC                     "local_n_portc"
+#define CONFIG_STRING_L1_REMOTE_N_PORTC                    "remote_n_portc"
+#define CONFIG_STRING_L1_LOCAL_N_PORTD                     "local_n_portd"
+#define CONFIG_STRING_L1_REMOTE_N_PORTD                    "remote_n_portd"
+#define CONFIG_STRING_L1_TRANSPORT_N_PREFERENCE            "tr_n_preference"
+
+#define CONFIG_STRING_ACTIVE_RUS                  "Active_RUs"
+#define CONFIG_STRING_RU_LIST                     "RUs"
 #define CONFIG_STRING_RU_CONFIG                   "ru_config"
 #define CONFIG_STRING_RU_LOCAL_IF_NAME            "local_if_name"
 #define CONFIG_STRING_RU_LOCAL_ADDRESS            "local_address"
@@ -368,10 +409,10 @@ typedef enum {
 
 void RCconfig_RU(void);
 void RCconfig_L1(void);
-void RCconfig_L2(void);
+void RCconfig_macrlc(void);
 int  RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc);
 int  RCconfig_S1(MessageDef *msg_p, uint32_t i);
-//void (*RCconfig[lastel])(void) = {RCconfig_RU,RCconfig_L1,RCconfig_L2,RCconfig_RRC,RCconfig_S1};
+
 
 int load_config_file(config_t *cfg) {
 
@@ -432,7 +473,6 @@ void RCconfig_RU() {
 
     if (RC.ru==NULL) RC.ru = (RU_t**)malloc(RC.nb_RU*sizeof(RU_t*));
    
-    printf("Set RU mask to %x\n",RC.ru_mask);
     RC.ru_mask=(1<<NB_RU) - 1;
 
 
@@ -591,6 +631,239 @@ void RCconfig_RU() {
   
 }
 
+void RCconfig_L1() {
+
+  int               i,j;
+
+  config_t          cfg;
+  config_setting_t *setting                         = NULL;
+  config_setting_t *setting_l1                      = NULL;
+
+  char*             if_name_n                       = NULL;
+  char*             ipv4_n                          = NULL;
+  char*             ipv4_n_remote                   = NULL;
+ 
+  char*             tr_n_preference                 = NULL;
+  libconfig_int     local_n_portc                   = 0;
+  libconfig_int     remote_n_portc                  = 0;
+  libconfig_int     local_n_portd                   = 0;
+  libconfig_int     remote_n_portd                  = 0;
+
+  load_config_file(&cfg);
+
+  setting = config_lookup(&cfg, CONFIG_STRING_L1_LIST);
+  
+  if (setting != NULL) {
+
+    if (RC.eNB == NULL) {
+      RC.eNB                               = (PHY_VARS_eNB ***)malloc((1+NUMBER_OF_eNB_MAX)*sizeof(PHY_VARS_eNB***));
+      LOG_I(PHY,"RC.eNB = %p\n",RC.eNB);
+      memset(RC.eNB,0,(1+NUMBER_OF_eNB_MAX)*sizeof(PHY_VARS_eNB***));
+      RC.nb_L1_CC = malloc((1+RC.nb_L1_inst)*sizeof(int));
+    }
+
+    for (j = 0; j < RC.nb_L1_inst; j++) {
+
+      setting_l1 = config_setting_get_elem(setting, j);
+      if (!config_setting_lookup_int   (setting_l1,CONFIG_STRING_L1_CC,&RC.nb_L1_CC[j]))
+	AssertFatal (0,
+		     "Failed to parse configuration file %s, L1 %d config !\n",
+		     RC.config_file_name, j);	
+
+      if (RC.eNB[j] == NULL) {
+	RC.eNB[j]                       = (PHY_VARS_eNB **)malloc((1+MAX_NUM_CCs)*sizeof(PHY_VARS_eNB**));
+	LOG_I(PHY,"RC.eNB[%d] = %p\n",j,RC.eNB[j]);
+	memset(RC.eNB[j],0,(1+MAX_NUM_CCs)*sizeof(PHY_VARS_eNB***));
+      }
+
+
+      for (i=0;i<RC.nb_L1_CC[j];i++) {
+	if (RC.eNB[j][i] == NULL) {
+	  RC.eNB[j][i] = (PHY_VARS_eNB *)malloc(sizeof(PHY_VARS_eNB));
+	  LOG_I(PHY,"RC.eNB[%d][%d] = %p\n",j,i,RC.eNB[j][i]);
+	  RC.eNB[j][i]->Mod_id  = j;
+	  RC.eNB[j][i]->CC_id   = i;
+	}
+      }
+
+
+      
+      printf("l1 %d/%d (nb CC %d)\n",j,RC.nb_inst,RC.nb_CC[j]);
+      
+
+      printf("RU %d: Transport %s\n",j,tr_n_preference);
+      if (!(config_setting_lookup_string(setting_l1, CONFIG_STRING_L1_TRANSPORT_N_PREFERENCE, (const char **)&tr_n_preference))) {
+	  AssertFatal (0,
+		       "Failed to parse configuration file %s, L1 %d config !\n",
+		       RC.config_file_name, j);
+      }
+
+      if (strcmp(tr_n_preference, "local_mac") == 0) {
+
+      }
+      else if (strcmp(tr_n_preference, "nfapi") == 0) {
+	if (  !(
+		config_setting_lookup_string(setting_l1, CONFIG_STRING_L1_LOCAL_N_IF_NAME,        (const char **)&if_name_n)
+		&& config_setting_lookup_string(setting_l1, CONFIG_STRING_L1_LOCAL_N_ADDRESS,        (const char **)&ipv4_n)
+		&& config_setting_lookup_string(setting_l1, CONFIG_STRING_L1_REMOTE_N_ADDRESS,       (const char **)&ipv4_n_remote)
+		&& config_setting_lookup_int   (setting_l1, CONFIG_STRING_L1_LOCAL_N_PORTC,          &local_n_portc)
+		&& config_setting_lookup_int   (setting_l1, CONFIG_STRING_L1_REMOTE_N_PORTC,         &remote_n_portc)
+		&& config_setting_lookup_int   (setting_l1, CONFIG_STRING_L1_LOCAL_N_PORTD,          &local_n_portd)
+		&& config_setting_lookup_int   (setting_l1, CONFIG_STRING_L1_REMOTE_N_PORTD,         &remote_n_portd)
+		)
+	      ) {
+	  AssertFatal (0,
+		       "Failed to parse configuration file %s, L1 %d config !\n",
+		       RC.config_file_name, j);
+	  continue; // FIXME will prevent segfaults below, not sure what happens at function exit...
+	}
+	RC.eNB[j][0]->eth_params_n.local_if_name            = strdup(if_name_n);
+	RC.eNB[j][0]->eth_params_n.my_addr                  = strdup(ipv4_n);
+	RC.eNB[j][0]->eth_params_n.remote_addr              = strdup(ipv4_n_remote);
+	RC.eNB[j][0]->eth_params_n.my_portc                 = local_n_portc;
+	RC.eNB[j][0]->eth_params_n.remote_portc             = remote_n_portc;
+	RC.eNB[j][0]->eth_params_n.my_portd                 = local_n_portd;
+	RC.eNB[j][0]->eth_params_n.remote_portd             = remote_n_portd;
+	RC.eNB[j][0]->eth_params_n.transp_preference          = ETH_UDP_MODE;
+      }
+      
+      else { // other midhaul
+      }	
+    }// j=0..num_inst
+    printf("Initializing northbound interface for L1\n");
+    l1_north_init_eNB();
+  }
+}
+
+void RCconfig_macrlc() {
+
+  int               i,j;
+
+  config_t          cfg;
+  config_setting_t *setting                         = NULL;
+  config_setting_t *setting_macrlc                  = NULL;
+  char*             if_name_s                       = NULL;
+  char*             ipv4_s                          = NULL;
+  char*             ipv4_s_remote                   = NULL;
+ 
+  char*             tr_s_preference                 = NULL;
+  libconfig_int     local_s_portc                   = 0;
+  libconfig_int     remote_s_portc                  = 0;
+  libconfig_int     local_s_portd                   = 0;
+  libconfig_int     remote_s_portd                  = 0;
+  char*             if_name_n                       = NULL;
+  char*             ipv4_n                          = NULL;
+  char*             ipv4_n_remote                   = NULL;
+ 
+  char*             tr_n_preference                 = NULL;
+  libconfig_int     local_n_portc                   = 0;
+  libconfig_int     remote_n_portc                  = 0;
+  libconfig_int     local_n_portd                   = 0;
+  libconfig_int     remote_n_portd                  = 0;
+
+  load_config_file(&cfg);
+
+  setting = config_lookup(&cfg, CONFIG_STRING_MACRLC_LIST);
+  
+  if (setting != NULL) {
+    
+
+    
+    if ((RC.nb_macrlc_inst=config_setting_length(setting))>0) mac_top_init_eNB();
+    else AssertFatal(1==0,"improper macrlc setting\n");
+    
+    for (j=0;j<RC.nb_macrlc_inst;j++) {
+      setting_macrlc = config_setting_get_elem(setting, j);
+      
+      printf("macrlc %d/%d \n",j,RC.nb_macrlc_inst);
+      
+      if (!(config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_TRANSPORT_N_PREFERENCE, (const char **)&tr_n_preference))) {
+	AssertFatal (0,
+		     "Failed to parse configuration file %s, L1 %d config !\n",
+		     RC.config_file_name, j);
+      }
+
+      printf("MACRLC %d: Northbound Transport %s\n",j,tr_n_preference);
+      
+      if (strcmp(tr_n_preference, "local_RRC") == 0) {
+	// check number of instances is same as RRC/PDCP
+	
+      }
+      else if (strcmp(tr_n_preference, "cudu") == 0) {
+	if (  !(
+		config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_N_IF_NAME,        (const char **)&if_name_n)
+		&& config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_N_ADDRESS,        (const char **)&ipv4_n)
+		&& config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_REMOTE_N_ADDRESS,       (const char **)&ipv4_n_remote)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_N_PORTC,          &local_n_portc)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_REMOTE_N_PORTC,         &remote_n_portc)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_N_PORTD,          &local_n_portd)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_REMOTE_N_PORTD,         &remote_n_portd)
+		)
+	      ) {
+	  AssertFatal (0,
+		       "Failed to parse configuration file %s, L1 %d config !\n",
+		       RC.config_file_name, j);
+	  continue; // FIXME will prevent segfaults below, not sure what happens at function exit...
+	}
+	RC.mac[j]->eth_params_n.local_if_name            = strdup(if_name_n);
+	RC.mac[j]->eth_params_n.my_addr                  = strdup(ipv4_n);
+	RC.mac[j]->eth_params_n.remote_addr              = strdup(ipv4_n_remote);
+	RC.mac[j]->eth_params_n.my_portc                 = local_n_portc;
+	RC.mac[j]->eth_params_n.remote_portc             = remote_n_portc;
+	RC.mac[j]->eth_params_n.my_portd                 = local_n_portd;
+	RC.mac[j]->eth_params_n.remote_portd             = remote_n_portd;
+	RC.mac[j]->eth_params_n.transp_preference        = ETH_UDP_MODE;
+      }
+      
+      else { // other midhaul
+	AssertFatal(1==0,"MACRLC %d: unknown northbound midhaul\n",j);
+      }	
+
+      if (!(config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_TRANSPORT_S_PREFERENCE, (const char **)&tr_s_preference))) {
+	AssertFatal (0,
+		     "Failed to parse configuration file %s, L1 %d config !\n",
+		     RC.config_file_name, j);
+	continue; // FIXME will prevent segfaults below, not sure what happens at function exit...
+      }
+
+      printf("MACRLC %d: Southbound Transport %s\n",j,tr_s_preference);
+      
+      if (strcmp(tr_s_preference, "local_L1") == 0) {
+
+	
+      }
+      else if (strcmp(tr_s_preference, "nfapi") == 0) {
+	if (  !( 
+		config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_S_IF_NAME,        (const char **)&if_name_s)
+		&& config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_S_ADDRESS,        (const char **)&ipv4_s)
+		&& config_setting_lookup_string(setting_macrlc, CONFIG_STRING_MACRLC_REMOTE_S_ADDRESS,       (const char **)&ipv4_s_remote)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_S_PORTC,          &local_s_portc)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_REMOTE_S_PORTC,         &remote_s_portc)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_LOCAL_S_PORTD,          &local_s_portd)
+		&& config_setting_lookup_int   (setting_macrlc, CONFIG_STRING_MACRLC_REMOTE_S_PORTD,         &remote_s_portd)
+		 )){
+	  AssertFatal (0,
+		       "Failed to parse configuration file %s, L1 %d config !\n",
+		       RC.config_file_name, j);
+	  continue; // FIXME will prevent segfaults below, not sure what happens at function exit...
+	}
+
+	RC.mac[j]->eth_params_s.local_if_name            = strdup(if_name_s);
+	RC.mac[j]->eth_params_s.my_addr                  = strdup(ipv4_s);
+	RC.mac[j]->eth_params_s.remote_addr              = strdup(ipv4_s_remote);
+	RC.mac[j]->eth_params_s.my_portc                 = local_s_portc;
+	RC.mac[j]->eth_params_s.remote_portc             = remote_s_portc;
+	RC.mac[j]->eth_params_s.my_portd                 = local_s_portd;
+	RC.mac[j]->eth_params_s.remote_portd             = remote_s_portd;
+	RC.mac[j]->eth_params_s.transp_preference        = ETH_UDP_MODE;
+      }
+      
+      else { // other midhaul
+	AssertFatal(1==0,"MACRLC %d: unknown southbound midhaul\n",j);
+      }	
+    }// j=0..num_inst
+  }
+}
 	       
 int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
   config_t          cfg;
@@ -614,6 +887,16 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
   libconfig_int     enb_id                        = 0;
   int               nb_cc                         = 0;
 
+  char*             if_name_s                       = NULL;
+  char*             ipv4_s                          = NULL;
+  char*             ipv4_s_remote                   = NULL;
+ 
+  char*             tr_s_preference                 = NULL;
+  libconfig_int     local_s_portc                   = 0;
+  libconfig_int     remote_s_portc                  = 0;
+  libconfig_int     local_s_portd                   = 0;
+  libconfig_int     remote_s_portd                  = 0;
+
   const char*       cell_type                     = NULL;
   const char*       tac                           = 0;
   const char*       enb_name                      = NULL;
@@ -622,7 +905,8 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
   const char*       frame_type                    = NULL;
   libconfig_int     tdd_config                    = 0;
   libconfig_int     tdd_config_s                  = 0;
-  const char*            prefix_type              = NULL;
+  const char*       prefix_type                   = NULL;
+  const char*       pbch_repetition               = NULL;
   libconfig_int     eutra_band                    = 0;
   long long int     downlink_frequency            = 0;
   libconfig_int     uplink_frequency_offset       = 0;
@@ -706,18 +990,6 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
   libconfig_int     my_int;
 
 
-  char*             if_name                       = NULL;
-  char*             ipv4                          = NULL;
-  char*             ipv4_remote                   = NULL;
-  char*             ipv6                          = NULL;
-  char*             local_rf                      = NULL;
-  char*             preference                    = NULL;
-  char*             active                        = NULL;
-  char*             if_compression                = NULL;
-
-  char*             tr_preference                 = NULL;
-  libconfig_int     local_port                    = 0;
-  libconfig_int     remote_port                   = 0;
   const char*       active_enb[MAX_ENB];
   char*             enb_interface_name_for_S1U    = NULL;
   char*             enb_ipv4_address_for_S1U      = NULL;
@@ -826,14 +1098,13 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
 	enb_id = i;
 # endif
       }
-      
+
       if (  !(       config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_CELL_TYPE,           &cell_type)
 		     && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_ENB_NAME,            &enb_name)
 		     && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_TRACKING_AREA_CODE,  &tac)
 		     && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_MOBILE_COUNTRY_CODE, &mcc)
 		     && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_MOBILE_NETWORK_CODE, &mnc)
-		     
-		     
+		     && config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_TRANSPORT_S_PREFERENCE, (const char **)&tr_s_preference)
 		     )
 	    ) {
 	AssertFatal (0,
@@ -841,7 +1112,39 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
 		     RC.config_file_name, i);
       }
       
+      printf("RRC %d: Southbound Transport %s\n",j,tr_s_preference);
+	    
+      if (strcmp(tr_s_preference, "local_mac") == 0) {
+
+
+      }
+      else if (strcmp(tr_s_preference, "cudu") == 0) {
+	if (  !(config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_LOCAL_S_IF_NAME,        (const char **)&if_name_s)
+		&& config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_LOCAL_S_ADDRESS,        (const char **)&ipv4_s)
+		&& config_setting_lookup_string(setting_enb, ENB_CONFIG_STRING_REMOTE_S_ADDRESS,       (const char **)&ipv4_s_remote)
+		&& config_setting_lookup_int   (setting_enb, ENB_CONFIG_STRING_LOCAL_S_PORTC,          &local_s_portc)
+		&& config_setting_lookup_int   (setting_enb, ENB_CONFIG_STRING_REMOTE_S_PORTC,         &remote_s_portc)
+		&& config_setting_lookup_int   (setting_enb, ENB_CONFIG_STRING_LOCAL_S_PORTD,          &local_s_portd)
+		&& config_setting_lookup_int   (setting_enb, ENB_CONFIG_STRING_REMOTE_S_PORTD,         &remote_s_portd)	
+		)
+	    ) {
+	  AssertFatal (0,
+		       "Failed to parse eNB configuration file %s, %u th enb\n",
+		       RC.config_file_name, i);
+	}
+	rrc->eth_params_s.local_if_name            = strdup(if_name_s);
+	rrc->eth_params_s.my_addr                  = strdup(ipv4_s);
+	rrc->eth_params_s.remote_addr              = strdup(ipv4_s_remote);
+	rrc->eth_params_s.my_portc                 = local_s_portc;
+	rrc->eth_params_s.remote_portc             = remote_s_portc;
+	rrc->eth_params_s.my_portd                 = local_s_portd;
+	rrc->eth_params_s.remote_portd             = remote_s_portd;
+	rrc->eth_params_s.transp_preference        = ETH_UDP_MODE;
+      }
       
+      else { // other midhaul
+      }	      
+
       // search if in active list
 
       for (j=0; j < num_enbs; j++) {
@@ -892,6 +1195,7 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
 		    && config_setting_lookup_int(component_carrier, ENB_CONFIG_STRING_TDD_CONFIG, &tdd_config)
 		    && config_setting_lookup_int(component_carrier, ENB_CONFIG_STRING_TDD_CONFIG_S, &tdd_config_s)
 		    && config_setting_lookup_string(component_carrier, ENB_CONFIG_STRING_PREFIX_TYPE, &prefix_type)
+		    && config_setting_lookup_string(component_carrier, ENB_CONFIG_STRING_PBCH_REPETITION, &pbch_repetition)
 		    && config_setting_lookup_int(component_carrier, ENB_CONFIG_STRING_EUTRA_BAND, &eutra_band)
 		    && config_setting_lookup_int64(component_carrier, ENB_CONFIG_STRING_DOWNLINK_FREQUENCY, &downlink_frequency)
 		    && config_setting_lookup_int(component_carrier, ENB_CONFIG_STRING_UPLINK_FREQUENCY_OFFSET, &uplink_frequency_offset)
@@ -1026,6 +1330,21 @@ int RCconfig_RRC(MessageDef *msg_p, uint32_t i, eNB_RRC_INST *rrc) {
 			     "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for prefix_type choice: NORMAL or EXTENDED !\n",
 			     RC.config_file_name, i, prefix_type);
 	      }
+#ifdef Rel14
+	      if (!pbch_repetition)
+		AssertFatal (0,
+			     "Failed to parse eNB configuration file %s, enb %d define %s: TRUE,FALSE!\n",
+			     RC.config_file_name, i, ENB_CONFIG_STRING_PBCH_REPETITION);
+	      else if (strcmp(pbch_repetition, "TRUE") == 0) {
+		RRC_CONFIGURATION_REQ (msg_p).pbch_repetition[j] = 1;
+	      } else  if (strcmp(pbch_repetition, "FALSE") == 0) {
+		RRC_CONFIGURATION_REQ (msg_p).pbch_repetition[j] = 0;
+	      } else {
+		AssertFatal (0,
+			     "Failed to parse eNB configuration file %s, enb %d unknown value \"%s\" for pbch_repetition choice: TRUE or FALSE !\n",
+			     RC.config_file_name, i, pbch_repetition);
+	      }
+#endif
               
 	      RRC_CONFIGURATION_REQ (msg_p).eutra_band[j] = eutra_band;
 	      RRC_CONFIGURATION_REQ (msg_p).downlink_frequency[j] = (uint32_t) downlink_frequency;
@@ -3071,7 +3390,7 @@ void RCConfig(const char *config_file_name) {
     
     if (setting != NULL) RC.nb_inst = config_setting_length(setting);
     if (RC.nb_inst > 0) {
-      printf("Number of eNB instances %d\n",RC.nb_inst);
+      printf("Number of eNB RRC instances %d\n",RC.nb_inst);
       setting = config_lookup(&cfg, ENB_CONFIG_STRING_ENB_LIST);
       RC.nb_CC = (int *)malloc((1+RC.nb_inst)*sizeof(int));
       for (int i=0;i<RC.nb_inst;i++) {
@@ -3084,10 +3403,17 @@ void RCConfig(const char *config_file_name) {
       }
     }
 
+    // Get num MACRLC instances
+    setting = config_lookup(&cfg, CONFIG_STRING_MACRLC_LIST);
+    if (setting != NULL) RC.nb_macrlc_inst = config_setting_length(setting);
+
+    // Get num L1 instances
+    setting = config_lookup(&cfg, CONFIG_STRING_L1_LIST);
+    if (setting != NULL) RC.nb_L1_inst = config_setting_length(setting);
+
     // Get num RU instances
     setting = config_lookup(&cfg, CONFIG_STRING_RU_LIST);
-    
-    if (setting != NULL) RC.nb_RU = config_setting_length(setting); 
+    if (setting != NULL) RC.nb_RU     = config_setting_length(setting); 
   }
   else {
     config_destroy(&cfg);
diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c
index 68a8b6d6c0bfd82dbe79e3c2299bae50d8e5ae67..c9cfed16b8b7f37261eb4ab6c09f796742623d83 100644
--- a/openair2/LAYER2/MAC/config.c
+++ b/openair2/LAYER2/MAC/config.c
@@ -35,6 +35,9 @@
 #include "SystemInformationBlockType2.h"
 //#include "RadioResourceConfigCommonSIB.h"
 #include "RadioResourceConfigDedicated.h"
+#ifdef Rel14
+#include "PRACH-ConfigSIB-v1310.h"
+#endif
 #include "MeasGapConfig.h"
 #include "MeasObjectToAddModList.h"
 #include "TDD-Config.h"
@@ -69,7 +72,7 @@ void ue_mac_reset(module_id_t module_idP,uint8_t eNB_index)
   //timeAlignmentTimer expires
 
   // PHY changes for UE MAC reset
-  mac_xface->phy_reset_ue(module_idP,0,eNB_index);
+  phy_reset_ue(module_idP,0,eNB_index);
 
   // notify RRC to relase PUCCH/SRS
   // cancel all pending SRs
@@ -90,6 +93,326 @@ void ue_mac_reset(module_id_t module_idP,uint8_t eNB_index)
 
 }
 
+int32_t **rxdata;
+int32_t **txdata;
+
+
+typedef struct eutra_bandentry_s {
+    int16_t band;
+    uint32_t ul_min;
+    uint32_t ul_max;
+    uint32_t dl_min;
+    uint32_t dl_max;
+    uint32_t N_OFFs_DL;
+} eutra_bandentry_t;
+
+typedef struct band_info_s {
+    int nbands;
+    eutra_bandentry_t band_info[100];
+} band_info_t;
+
+
+
+static const eutra_bandentry_t eutra_bandtable[] = {
+  { 1, 19200, 19800, 21100, 21700, 0},
+  { 2, 18500, 19100, 19300, 19900, 6000},
+  { 3, 17100, 17850, 18050, 18800, 12000},
+  { 4, 17100, 17550, 21100, 21550, 19500},
+  { 5,  8240,  8490,  8690,  8940, 24000},
+  { 6,  8300,  8400,  8750,  8850, 26500},
+  { 7, 25000, 25700, 26200, 26900, 27500},
+  { 8,  8800, 9150 ,  9250,  9600, 34500},
+  { 9, 17499, 17849, 18449, 18799, 38000},
+  {10, 17100, 17700, 21100, 21700, 41500},
+  {11, 14279, 14529, 14759, 15009, 47500},
+  {12,  6980,  7160,  7280,  7460, 50100},
+  {13,  7770,  7870,  7460,  7560, 51800},
+  {14,  7880,  7980,  7580,  7680, 52800},
+  {17,  7040,  7160,  7340,  7460, 57300},
+  {18,  8150,  9650,  8600, 10100, 58500},
+  {19,  8300,  8450,  8750,  8900, 60000},
+  {20,  8320,  8620,  7910,  8210, 61500},
+  {21, 14479, 14629, 14959, 15109, 64500},
+  {22, 34100, 34900, 35100, 35900, 66000},
+  {23, 20000, 20200, 21800, 22000, 75000},
+  {24, 16126, 16605, 15250, 15590, 77000},
+  {25, 18500, 19150, 19300, 19950, 80400},
+  {26, 8140 ,  8490,  8590,  8940, 86900},
+  {27, 8070 ,  8240,  8520,  8690, 90400},
+  {28, 7030 ,  7580,  7580,  8130, 92100},
+  {29, 0    ,  0   ,  7170,  7280, 96600},
+  {30, 23050, 23250, 23500, 23600, 97700},
+  {31, 45250, 34900, 46250, 35900, 98700},
+  {32, 0    , 0    , 14520, 14960, 99200},
+  {33, 19000, 19200, 19000, 19200, 36000},
+  {34, 20100, 20250, 20100, 20250, 36200},
+  {35, 18500, 19100, 18500, 19100, 36350},
+  {36, 19300, 19900, 19300, 19900, 36950},
+  {37, 19100, 19300, 19100, 19300, 37550},
+  {38, 25700, 26200, 25700, 26300, 37750},
+  {39, 18800, 19200, 18800, 19200, 38250},
+  {40, 23000, 24000, 23000, 24000, 38650},
+  {41, 24960, 26900, 24960, 26900, 39650},
+  {42, 34000, 36000, 34000, 36000, 41590},
+  {43, 36000, 38000, 36000, 38000, 43590},
+  {44, 7030 ,  8030,  7030,  8030, 45590},
+  {45, 14470, 14670, 14470, 14670, 46590},
+  {46, 51500, 59250, 51500, 59250, 46790},
+  {65, 19200, 20100, 21100, 22000, 65536},
+  {66, 17100, 18000, 21100, 22000, 66436},
+  {67, 0    , 0    ,  7380,  7580, 67336},
+  {68, 6980 , 7280 ,  7530,  7830, 67536}};
+
+uint32_t to_earfcn(int eutra_bandP,uint32_t dl_CarrierFreq,uint32_t bw) {
+
+  uint32_t dl_CarrierFreq_by_100k = dl_CarrierFreq/100000;
+  int bw_by_100                   = bw/100;
+
+  int i;
+
+  AssertFatal(eutra_bandP < 69,"eutra_band %d > 68\n",eutra_bandP);
+  for (i=0;i<69 && eutra_bandtable[i].band!=eutra_bandP;i++);
+
+  AssertFatal(dl_CarrierFreq_by_100k>=eutra_bandtable[i].dl_min,
+	      "Band %d, bw %u : DL carrier frequency %u Hz < %u\n",
+	      eutra_bandP,bw,dl_CarrierFreq,eutra_bandtable[i].dl_min);
+  AssertFatal(dl_CarrierFreq_by_100k<=(eutra_bandtable[i].dl_max-bw_by_100),
+	      "Band %d, bw %u: DL carrier frequency %u Hz > %d\n",
+	      eutra_bandP,bw,dl_CarrierFreq,eutra_bandtable[i].dl_max-bw_by_100);
+
+
+  return(dl_CarrierFreq_by_100k - eutra_bandtable[i].dl_min + (eutra_bandtable[i].N_OFFs_DL/10));
+}
+
+uint32_t from_earfcn(int eutra_bandP,uint32_t dl_earfcn) {
+
+  int i;
+
+  AssertFatal(eutra_bandP < 69,"eutra_band %d > 68\n",eutra_bandP);
+  for (i=0;i<69 && eutra_bandtable[i].band!=eutra_bandP;i++);
+
+  return(eutra_bandtable[i].dl_min + (dl_earfcn-(eutra_bandtable[i].N_OFFs_DL/10)))*100000;
+}
+
+
+int32_t get_uldl_offset(int eutra_band) {
+  return(-eutra_bandtable[eutra_band].dl_min + eutra_bandtable[eutra_band].ul_min);
+}
+
+uint32_t bw_table[6] = {6*180,15*180,25*180,50*180,75*180,100*180};
+
+void config_mib(int                 Mod_idP,
+		int                 CC_idP,
+		int                 eutra_bandP,  
+		int                 dl_BandwidthP,
+		PHICH_Config_t      *phich_configP,
+		int                 Nid_cellP,
+		int                 NcpP,
+		int                 p_eNBP,
+		uint32_t            dl_CarrierFreqP,
+		uint32_t            ul_CarrierFreqP,
+		uint32_t            pbch_repetitionP) {
+
+  nfapi_config_request_t *cfg = &RC.mac[Mod_idP]->config[CC_idP];
+		
+  cfg->subframe_config.pcfich_power_offset.value   = 6000;  // 0dB
+  cfg->subframe_config.dl_cyclic_prefix_type.value = NcpP;
+  cfg->subframe_config.ul_cyclic_prefix_type.value = NcpP;
+ 
+  LOG_I(MAC,"Ncp %d,p_eNB %d\n",NcpP,p_eNBP);
+
+  cfg->rf_config.dl_channel_bandwidth.value        = dl_BandwidthP;
+  cfg->rf_config.ul_channel_bandwidth.value        = dl_BandwidthP;
+  cfg->rf_config.tx_antenna_ports.value            = p_eNBP;
+  cfg->rf_config.rx_antenna_ports.value            = 2;
+
+  cfg->nfapi_config.earfcn.value                   = to_earfcn(eutra_bandP,dl_CarrierFreqP,bw_table[dl_BandwidthP]/100);
+  cfg->nfapi_config.rf_bands.number_rf_bands       = 1;
+  cfg->nfapi_config.rf_bands.rf_band[0]            = eutra_bandP;  
+  cfg->phich_config.phich_resource.value           = phich_configP->phich_Resource;
+  cfg->phich_config.phich_duration.value           = phich_configP->phich_Duration;
+  cfg->phich_config.phich_power_offset.value       = 6000;  // 0dB
+
+  cfg->sch_config.primary_synchronization_signal_epre_eprers.value   = 6000; // 0dB
+  cfg->sch_config.secondary_synchronization_signal_epre_eprers.value = 6000; // 0dB
+  cfg->sch_config.physical_cell_id.value                             = Nid_cellP;
+
+#ifdef Rel14
+  cfg->emtc_config.pbch_repetitions_enable_r13.value                 = pbch_repetitionP;
+#endif  
+}
+
+void config_sib1(int Mod_idP,
+		 int CC_idP,
+		 TDD_Config_t *tdd_ConfigP) {
+
+  nfapi_config_request_t *cfg = &RC.mac[Mod_idP]->config[CC_idP];
+
+  if (tdd_ConfigP)   { //TDD
+    cfg->subframe_config.duplex_mode.value                          = 0;
+    cfg->tdd_frame_structure_config.subframe_assignment.value       = tdd_ConfigP->subframeAssignment;
+    cfg->tdd_frame_structure_config.special_subframe_patterns.value = tdd_ConfigP->specialSubframePatterns;
+  }
+  else { // FDD
+    cfg->subframe_config.duplex_mode.value                          = 1;
+    // Note no half-duplex here
+  }
+
+  
+}
+
+int power_off_dB[6] = {78,118,140,170,188,200};
+
+void config_sib2(int Mod_idP, 
+		 int CC_idP, 
+		 RadioResourceConfigCommonSIB_t   *radioResourceConfigCommonP,
+#ifdef Rel14
+		 RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon_BRP,
+#endif
+		 ARFCN_ValueEUTRA_t *ul_CArrierFreqP,
+		 long *ul_BandwidthP,
+		 AdditionalSpectrumEmission_t *additionalSpectrumEmissionP,
+		 struct MBSFN_SubframeConfigList  *mbsfn_SubframeConfigListP) {
+
+  nfapi_config_request_t *cfg = &RC.mac[Mod_idP]->config[CC_idP];
+
+  cfg->subframe_config.pb.value               = radioResourceConfigCommonP->pdsch_ConfigCommon.p_b;
+  cfg->rf_config.reference_signal_power.value = radioResourceConfigCommonP->pdsch_ConfigCommon.referenceSignalPower;
+  cfg->nfapi_config.max_transmit_power.value  = cfg->rf_config.reference_signal_power.value + power_off_dB[cfg->rf_config.dl_channel_bandwidth.value];
+
+  cfg->prach_config.configuration_index.value                 = radioResourceConfigCommonP->prach_Config.prach_ConfigInfo.prach_ConfigIndex;
+  cfg->prach_config.root_sequence_index.value                 = radioResourceConfigCommonP->prach_Config.rootSequenceIndex;
+  cfg->prach_config.zero_correlation_zone_configuration.value = radioResourceConfigCommonP->prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig;
+  cfg->prach_config.high_speed_flag.value                     = radioResourceConfigCommonP->prach_Config.prach_ConfigInfo.highSpeedFlag;
+  cfg->prach_config.frequency_offset.value                    = radioResourceConfigCommonP->prach_Config.prach_ConfigInfo.prach_FreqOffset;
+
+  cfg->pusch_config.hopping_mode.value                        = radioResourceConfigCommonP->pusch_ConfigCommon.pusch_ConfigBasic.hoppingMode;
+  cfg->pusch_config.number_of_subbands.value                  = radioResourceConfigCommonP->pusch_ConfigCommon.pusch_ConfigBasic.n_SB;
+  cfg->pusch_config.hopping_offset.value                      = radioResourceConfigCommonP->pusch_ConfigCommon.pusch_ConfigBasic.pusch_HoppingOffset;
+
+
+		
+  cfg->pucch_config.delta_pucch_shift.value                         = radioResourceConfigCommonP->pucch_ConfigCommon.deltaPUCCH_Shift;
+  cfg->pucch_config.n_cqi_rb.value                                  = radioResourceConfigCommonP->pucch_ConfigCommon.nRB_CQI;
+  cfg->pucch_config.n_an_cs.value                                   = radioResourceConfigCommonP->pucch_ConfigCommon.nCS_AN;
+  cfg->pucch_config.n1_pucch_an.value                               = radioResourceConfigCommonP->pucch_ConfigCommon.n1PUCCH_AN;
+
+  if (radioResourceConfigCommonP->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupHoppingEnabled == true)
+    cfg->uplink_reference_signal_config.uplink_rs_hopping.value     = 1;
+  else if (radioResourceConfigCommonP->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled == true)
+    cfg->uplink_reference_signal_config.uplink_rs_hopping.value     = 2;
+  else // No hopping
+    cfg->uplink_reference_signal_config.uplink_rs_hopping.value     = 0;
+
+  cfg->uplink_reference_signal_config.group_assignment.value        = radioResourceConfigCommonP->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH;
+  cfg->uplink_reference_signal_config.cyclic_shift_1_for_drms.value = radioResourceConfigCommonP->pusch_ConfigCommon.ul_ReferenceSignalsPUSCH.cyclicShift;
+
+  // how to enable/disable SRS?
+  if (radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.present==SoundingRS_UL_ConfigCommon_PR_setup) {
+    cfg->srs_config.bandwidth_configuration.value                       = radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.choice.setup.srs_BandwidthConfig;
+    cfg->srs_config.srs_subframe_configuration.value                    = radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.choice.setup.srs_SubframeConfig;
+    cfg->srs_config.srs_acknack_srs_simultaneous_transmission.value     = radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.choice.setup.ackNackSRS_SimultaneousTransmission;
+
+    if (radioResourceConfigCommonP->soundingRS_UL_ConfigCommon.choice.setup.srs_MaxUpPts)
+       cfg->srs_config.max_up_pts.value                                 = 1;
+    else
+       cfg->srs_config.max_up_pts.value                                 = 0;
+  }
+
+#ifdef Rel14
+  if (RC.mac[Mod_idP]->common_channels[CC_idP].mib->message.schedulingInfoSIB1_BR_r13>0) {
+    AssertFatal(radioResourceConfigCommon_BRP!=NULL,"radioResource rou is missing\n");
+    AssertFatal(radioResourceConfigCommon_BRP->ext4!=NULL,"ext4 is missing\n");
+    cfg->emtc_config.prach_catm_root_sequence_index.value                 = radioResourceConfigCommon_BRP->prach_Config.rootSequenceIndex;
+    cfg->emtc_config.prach_catm_zero_correlation_zone_configuration.value = radioResourceConfigCommon_BRP->prach_Config.prach_ConfigInfo.zeroCorrelationZoneConfig;
+    cfg->emtc_config.prach_catm_high_speed_flag.value                     = radioResourceConfigCommon_BRP->prach_Config.prach_ConfigInfo.highSpeedFlag;
+ 
+    struct PRACH_ConfigSIB_v1310 *ext4_prach=radioResourceConfigCommonP->ext4->prach_ConfigCommon_v1310; 
+
+    PRACH_ParametersListCE_r13_t	 *prach_ParametersListCE_r13 = &ext4_prach->prach_ParametersListCE_r13;
+    int i;
+    PRACH_ParametersCE_r13_t *p;
+    cfg->emtc_config.prach_ce_level_0_enable.value=0;
+    cfg->emtc_config.prach_ce_level_1_enable.value=0;
+    cfg->emtc_config.prach_ce_level_2_enable.value=0;
+    cfg->emtc_config.prach_ce_level_3_enable.value=0;
+    switch (prach_ParametersListCE_r13->list.count) {
+    case 4:
+      p=prach_ParametersListCE_r13->list.array[3];
+      cfg->emtc_config.prach_ce_level_3_enable.value                          = 1;
+      cfg->emtc_config.prach_ce_level_3_configuration_index.value             = p->prach_ConfigIndex_r13;
+      cfg->emtc_config.prach_ce_level_3_frequency_offset.value                = p->prach_FreqOffset_r13;
+      if (p->prach_StartingSubframe_r13) 
+	cfg->emtc_config.prach_ce_level_3_starting_subframe_periodicity.value = *p->prach_StartingSubframe_r13;
+      cfg->emtc_config.prach_ce_level_3_hopping_enable.value                  = p->prach_HoppingConfig_r13;
+      cfg->emtc_config.prach_ce_level_3_hopping_offset.value                  = cfg->rf_config.ul_channel_bandwidth.value-6;
+    case 3:
+      p=prach_ParametersListCE_r13->list.array[2];
+      cfg->emtc_config.prach_ce_level_2_enable.value                          = 1;
+      cfg->emtc_config.prach_ce_level_2_configuration_index.value             = p->prach_ConfigIndex_r13;
+      cfg->emtc_config.prach_ce_level_2_frequency_offset.value                = p->prach_FreqOffset_r13;
+      if (p->prach_StartingSubframe_r13) 
+	cfg->emtc_config.prach_ce_level_2_starting_subframe_periodicity.value = *p->prach_StartingSubframe_r13;
+      cfg->emtc_config.prach_ce_level_2_hopping_enable.value                  = p->prach_HoppingConfig_r13;
+      cfg->emtc_config.prach_ce_level_2_hopping_offset.value                  = cfg->rf_config.ul_channel_bandwidth.value-6;
+    case 2:
+      p=prach_ParametersListCE_r13->list.array[1];
+      cfg->emtc_config.prach_ce_level_1_enable.value                          = 1;
+      cfg->emtc_config.prach_ce_level_1_configuration_index.value             = p->prach_ConfigIndex_r13;
+      cfg->emtc_config.prach_ce_level_1_frequency_offset.value                = p->prach_FreqOffset_r13;
+      if (p->prach_StartingSubframe_r13) 
+	cfg->emtc_config.prach_ce_level_1_starting_subframe_periodicity.value = *p->prach_StartingSubframe_r13;
+      cfg->emtc_config.prach_ce_level_1_hopping_enable.value                  = p->prach_HoppingConfig_r13;
+      cfg->emtc_config.prach_ce_level_1_hopping_offset.value                  = cfg->rf_config.ul_channel_bandwidth.value-6;
+    case 1:
+      p=prach_ParametersListCE_r13->list.array[0];
+      cfg->emtc_config.prach_ce_level_0_enable.value                          = 1;
+      cfg->emtc_config.prach_ce_level_0_configuration_index.value             = p->prach_ConfigIndex_r13;
+      cfg->emtc_config.prach_ce_level_0_frequency_offset.value                = p->prach_FreqOffset_r13;
+      if (p->prach_StartingSubframe_r13) 
+	cfg->emtc_config.prach_ce_level_0_starting_subframe_periodicity.value = *p->prach_StartingSubframe_r13;
+      cfg->emtc_config.prach_ce_level_0_hopping_enable.value                  = p->prach_HoppingConfig_r13;
+      cfg->emtc_config.prach_ce_level_0_hopping_offset.value                  = cfg->rf_config.ul_channel_bandwidth.value-6;
+    }
+
+    struct FreqHoppingParameters_r13 *ext4_freqHoppingParameters = radioResourceConfigCommonP->ext4->freqHoppingParameters_r13;
+    if ((ext4_freqHoppingParameters) && 
+	(ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13)){
+      switch(ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13->present) {
+      case 	FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_NOTHING:	/* No components present */
+	break;
+      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_FDD_r13:
+	cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodea.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13->choice.interval_FDD_r13;
+	break;
+      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeA_r13_PR_interval_TDD_r13:
+	cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodea.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeA_r13->choice.interval_TDD_r13;
+	break;
+      }
+    }
+    if ((ext4_freqHoppingParameters) && 
+	(ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13)){
+      switch(ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13->present) {
+      case 	FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_NOTHING:	/* No components present */
+	break;
+      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_FDD_r13:
+	cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13->choice.interval_FDD_r13;
+	break;
+      case FreqHoppingParameters_r13__interval_ULHoppingConfigCommonModeB_r13_PR_interval_TDD_r13:
+	cfg->emtc_config.pucch_interval_ulhoppingconfigcommonmodeb.value = ext4_freqHoppingParameters->interval_ULHoppingConfigCommonModeB_r13->choice.interval_TDD_r13;
+	break;
+      }
+    }
+  }
+#endif
+
+}
+
+void config_dedicated(int Mod_idP, 
+		      int CC_idP, 
+		      uint16_t rnti, 
+		      struct PhysicalConfigDedicated  *physicalConfigDedicated) {
+
+}
 
 int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
 			   int                              CC_idP,
@@ -98,8 +421,14 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
 			   int                              Ncp,
 			   int                              eutra_band,
 			   uint32_t                         dl_CarrierFreq,
+#ifdef Rel14
+                           int                              pbch_repetition,
+#endif
 			   BCCH_BCH_Message_t               *mib,
 			   RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon,
+#ifdef Rel14
+			   RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon_BR,
+#endif
 			   struct PhysicalConfigDedicated  *physicalConfigDedicated,
 #if defined(Rel10) || defined(Rel14)
 			   SCellToAddMod_r10_t *sCellToAddMod_r10,
@@ -123,10 +452,6 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
 			   MBSFN_AreaInfoList_r9_t         *mbsfn_AreaInfoList,
 			   PMCH_InfoList_r9_t              *pmch_InfoList
 #endif
-#ifdef CBA
-			   ,uint8_t                              num_active_cba_groups,
-			   uint16_t                              cba_rnti
-#endif			   
 			   ) {
 			   
   int i;
@@ -142,32 +467,46 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
 
     mac_top_init_eNB();
 
-    RC.mac[Mod_idP]->common_channels[CC_idP].mib            = mib;
-    RC.mac[Mod_idP]->common_channels[CC_idP].physCellId     = physCellId;
-    RC.mac[Mod_idP]->common_channels[CC_idP].p_eNB          = p_eNB;
-    RC.mac[Mod_idP]->common_channels[CC_idP].Ncp            = Ncp;
-    RC.mac[Mod_idP]->common_channels[CC_idP].eutra_band     = eutra_band;
-    RC.mac[Mod_idP]->common_channels[CC_idP].dl_CarrierFreq = dl_CarrierFreq;
-
-    LOG_I(MAC,"Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d,Nid_cell %d,p %d,DL freq %u,phich_config.resource %d, phich_config.duration %d)\n",
-	  Mod_idP, CC_idP, eutra_band, mib->message.dl_Bandwidth, physCellId, p_eNB,dl_CarrierFreq,mib->message.phich_Config.phich_Resource,mib->message.phich_Config.phich_Duration);
-
-    mac_xface->phy_config_mib_eNB(Mod_idP,CC_idP,
-				  eutra_band,
-				  mib->message.dl_Bandwidth,
-				  &mib->message.phich_Config,
-				  physCellId,
-				  Ncp,
-				  p_eNB,
-				  dl_CarrierFreq,
-				  ul_CarrierFreq);
+    RC.mac[Mod_idP]->common_channels[CC_idP].mib             = mib;
+    RC.mac[Mod_idP]->common_channels[CC_idP].physCellId      = physCellId;
+    RC.mac[Mod_idP]->common_channels[CC_idP].p_eNB           = p_eNB;
+    RC.mac[Mod_idP]->common_channels[CC_idP].Ncp             = Ncp;
+    RC.mac[Mod_idP]->common_channels[CC_idP].eutra_band      = eutra_band;
+    RC.mac[Mod_idP]->common_channels[CC_idP].dl_CarrierFreq  = dl_CarrierFreq;
+
+    LOG_I(MAC,
+	  "Configuring MIB for instance %d, CCid %d : (band %d,N_RB_DL %d,Nid_cell %d,p %d,DL freq %u,phich_config.resource %d, phich_config.duration %d)\n",
+	  Mod_idP, 
+	  CC_idP, 
+	  eutra_band, 
+	  to_prb((int)mib->message.dl_Bandwidth), 
+	  physCellId, 
+	  p_eNB,
+	  dl_CarrierFreq,
+	  (int)mib->message.phich_Config.phich_Resource,
+	  (int)mib->message.phich_Config.phich_Duration);
+
+    config_mib(Mod_idP,CC_idP,
+	       eutra_band,
+	       mib->message.dl_Bandwidth,
+	       &mib->message.phich_Config,
+	       physCellId,
+	       Ncp,
+	       p_eNB,
+	       dl_CarrierFreq,
+	       ul_CarrierFreq
+#ifdef Rel14
+	       ,pbch_repetition
+#endif
+	       );
+
     mac_init_cell_params(Mod_idP,CC_idP);
   }
   if ((SIwindowsize!=NULL) && (SIperiod!=NULL))  {
     RC.mac[Mod_idP]->common_channels[CC_idP].tdd_Config            = tdd_Config;    
     RC.mac[Mod_idP]->common_channels[CC_idP].SIwindowsize          = *SIwindowsize;    
     RC.mac[Mod_idP]->common_channels[CC_idP].SIperiod              = *SIperiod;    
-    mac_xface->phy_config_sib1_eNB(Mod_idP,CC_idP,tdd_Config,*SIwindowsize,*SIperiod);
+    config_sib1(Mod_idP,CC_idP,tdd_Config);
   }
 
   if (radioResourceConfigCommon!=NULL) {
@@ -186,13 +525,18 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
       if (ul_Bandwidth) RC.mac[Mod_idP]->common_channels[CC_idP].ul_Bandwidth                = *ul_Bandwidth;
       else RC.mac[Mod_idP]->common_channels[CC_idP].ul_Bandwidth                             = RC.mac[Mod_idP]->common_channels[CC_idP].mib->message.dl_Bandwidth;
 
-      mac_xface->phy_config_sib2_eNB(Mod_idP, CC_idP, radioResourceConfigCommon, NULL, ul_Bandwidth, additionalSpectrumEmission, mbsfn_SubframeConfigList);
+      config_sib2(Mod_idP, CC_idP, 
+		  radioResourceConfigCommon, 
+#ifdef Rel14
+		  radioResourceConfigCommon_BR, 
+#endif
+		  NULL, ul_Bandwidth, additionalSpectrumEmission, mbsfn_SubframeConfigList);
 
 
   }
 
   // SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters->logicalChannelGroup
-  if (logicalChannelConfig!= NULL) {
+  if (logicalChannelConfig!= NULL) { // check for eMTC specific things
     if (UE_id == -1) {
       LOG_E(MAC,"%s:%d:%s: ERROR, UE_id == -1\n", __FILE__, __LINE__, __FUNCTION__);
     } else {
@@ -208,7 +552,7 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
     if (UE_id == -1)
       LOG_E(MAC,"%s:%d:%s: ERROR, UE_id == -1\n", __FILE__, __LINE__, __FUNCTION__);
     else
-      mac_xface->phy_config_dedicated_eNB(Mod_idP, CC_idP, UE_RNTI(Mod_idP, UE_id), physicalConfigDedicated);
+      config_dedicated(Mod_idP, CC_idP, UE_RNTI(Mod_idP, UE_id), physicalConfigDedicated);
   } 
 
 
@@ -221,7 +565,7 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
     if (UE_id == -1)
       LOG_E(MAC,"%s:%d:%s: ERROR, UE_id == -1\n", __FILE__, __LINE__, __FUNCTION__);
     else
-      mac_xface->phy_config_dedicated_scell_eNB(Mod_idP,UE_RNTI(Mod_idP,UE_id),sCellToAddMod_r10,1);
+      config_dedicated_scell(Mod_idP,UE_RNTI(Mod_idP,UE_id),sCellToAddMod_r10,1);
     
   }
 
@@ -256,7 +600,7 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
       RC.mac[Mod_idP]->common_channels[0].mbsfn_AreaInfo[i] = mbsfn_AreaInfoList->list.array[i];
       LOG_I(MAC,"[eNB %d][CONFIG] MBSFN_AreaInfo[%d]: MCCH Repetition Period = %ld\n", Mod_idP,i,
 	    RC.mac[Mod_idP]->common_channels[0].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
-      mac_xface->phy_config_sib13_eNB(Mod_idP,0,i,RC.mac[Mod_idP]->common_channels[0].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
+      //      config_sib13(Mod_idP,0,i,RC.mac[Mod_idP]->common_channels[0].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
     }
   } 
 
@@ -283,31 +627,15 @@ int rrc_mac_config_req_eNB(module_id_t                      Mod_idP,
   }
 
 #endif
-#ifdef CBA
 
+  AssertFatal(RC.mac[Mod_idP]->if_inst->PHY_config_req != NULL,"if_inst->phy_config_request is null\n");
+  PHY_Config_t phycfg;
+  phycfg.Mod_id = Mod_idP;
+  phycfg.CC_id  = CC_idP;
+  phycfg.cfg    = &RC.mac[Mod_idP]->config[CC_idP];
 
-  if (cba_rnti) {
-    LOG_D(MAC,"[eNB %d] configure CBA RNTI for UE  %d (total active cba groups %d)\n",
-	  Mod_idP, UE_id, num_active_cba_groups);
-    RC.mac[Mod_idP]->common_channels[CC_idP].num_active_cba_groups=num_active_cba_groups;
-    
-    for (i=0; i < num_active_cba_groups; i ++) {
-      if (RC.mac[Mod_idP]->common_channels[CC_idP].cba_rnti[i] != cba_rnti + i) {
-	RC.mac[Mod_idP]->common_channels[CC_idP].cba_rnti[i] = cba_rnti + i;
-      }
-      
-      //only configure UE ids up to num_active_cba_groups
-      //we use them as candidates for the transmission of dci format0)
-      if (UE_id%num_active_cba_groups == i) {
-	mac_xface->phy_config_cba_rnti(Mod_idP,CC_idP,eNB_flagP,UE_id,cba_rnti + i,i,num_active_cba_groups );
-	LOG_D(MAC,"[eNB %d] configure CBA groups %d with RNTI %x for UE  %d (total active cba groups %d)\n",
-	      Mod_idP, i, RC.mac[Mod_idP]->common_channels[CC_idP].cba_rnti[i],UE_id, num_active_cba_groups);
-      }
-    }
-  }
-  
+  if (RC.mac[Mod_idP]->if_inst->PHY_config_req) RC.mac[Mod_idP]->if_inst->PHY_config_req(&phycfg); 
 
-#endif
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_MAC_CONFIG, VCD_FUNCTION_OUT);
 
   return(0);			   
@@ -363,12 +691,12 @@ rrc_mac_config_req_ue(
  
 
   if (tdd_Config && SIwindowsize && SIperiod) {
-    mac_xface->phy_config_sib1_ue(Mod_idP,0,eNB_index,tdd_Config,*SIwindowsize,*SIperiod);
+    phy_config_sib1_ue(Mod_idP,0,eNB_index,tdd_Config,*SIwindowsize,*SIperiod);
   }
 
   if (radioResourceConfigCommon!=NULL) {
     UE_mac_inst[Mod_idP].radioResourceConfigCommon = radioResourceConfigCommon;
-    mac_xface->phy_config_sib2_ue(Mod_idP,0,eNB_index,radioResourceConfigCommon,ul_CarrierFreq,ul_Bandwidth,additionalSpectrumEmission,mbsfn_SubframeConfigList);
+    phy_config_sib2_ue(Mod_idP,0,eNB_index,radioResourceConfigCommon,ul_CarrierFreq,ul_Bandwidth,additionalSpectrumEmission,mbsfn_SubframeConfigList);
   }
 
   // SRB2_lchan_config->choice.explicitValue.ul_SpecificParameters->logicalChannelGroup
@@ -377,21 +705,19 @@ rrc_mac_config_req_ue(
     UE_mac_inst[Mod_idP].logicalChannelConfig[logicalChannelIdentity]=logicalChannelConfig;
     UE_mac_inst[Mod_idP].scheduling_info.Bj[logicalChannelIdentity]=0; // initilize the bucket for this lcid
     
-    if (logicalChannelConfig->ul_SpecificParameters) {
-      UE_mac_inst[Mod_idP].scheduling_info.bucket_size[logicalChannelIdentity]=logicalChannelConfig->ul_SpecificParameters->prioritisedBitRate *
-	logicalChannelConfig->ul_SpecificParameters->bucketSizeDuration; // set the max bucket size
-      if (logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup != NULL) {
-	UE_mac_inst[Mod_idP].scheduling_info.LCGID[logicalChannelIdentity]=*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup;
-	LOG_D(MAC,"[CONFIG][UE %d] LCID %ld is attached to the LCGID %ld\n",Mod_idP,logicalChannelIdentity,*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup);
-      }
-      else {
-	UE_mac_inst[Mod_idP].scheduling_info.LCGID[logicalChannelIdentity] = MAX_NUM_LCGID;
-      }
-      UE_mac_inst[Mod_idP].scheduling_info.LCID_buffer_remain[logicalChannelIdentity] = 0;
-    } else {
-      LOG_E(MAC,"[CONFIG][UE %d] LCID %ld NULL ul_SpecificParameters\n",Mod_idP,logicalChannelIdentity);
-      mac_xface->macphy_exit("NULL ul_SpecificParameters");
+    AssertFatal(logicalChannelConfig->ul_SpecificParameters!=NULL,
+		"[UE %d] LCID %ld NULL ul_SpecificParameters\n",
+		Mod_idP,logicalChannelIdentity);
+    UE_mac_inst[Mod_idP].scheduling_info.bucket_size[logicalChannelIdentity]=logicalChannelConfig->ul_SpecificParameters->prioritisedBitRate *
+      logicalChannelConfig->ul_SpecificParameters->bucketSizeDuration; // set the max bucket size
+    if (logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup != NULL) {
+      UE_mac_inst[Mod_idP].scheduling_info.LCGID[logicalChannelIdentity]=*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup;
+      LOG_D(MAC,"[CONFIG][UE %d] LCID %ld is attached to the LCGID %ld\n",Mod_idP,logicalChannelIdentity,*logicalChannelConfig->ul_SpecificParameters->logicalChannelGroup);
     }
+    else {
+      UE_mac_inst[Mod_idP].scheduling_info.LCGID[logicalChannelIdentity] = MAX_NUM_LCGID;
+    }
+    UE_mac_inst[Mod_idP].scheduling_info.LCID_buffer_remain[logicalChannelIdentity] = 0;
   }
 
   if (mac_MainConfig != NULL) {
@@ -418,7 +744,7 @@ rrc_mac_config_req_ue(
       } else {
 	UE_mac_inst[Mod_idP].scheduling_info.maxHARQ_Tx     = (uint16_t) MAC_MainConfig__ul_SCH_Config__maxHARQ_Tx_n5;
       }
-      mac_xface->phy_config_harq_ue(Mod_idP,0,eNB_index,UE_mac_inst[Mod_idP].scheduling_info.maxHARQ_Tx);
+      phy_config_harq_ue(Mod_idP,0,eNB_index,UE_mac_inst[Mod_idP].scheduling_info.maxHARQ_Tx);
       
       if (mac_MainConfig->ul_SCH_Config->retxBSR_Timer) {
 	UE_mac_inst[Mod_idP].scheduling_info.retxBSR_Timer     = (uint16_t) mac_MainConfig->ul_SCH_Config->retxBSR_Timer;
@@ -497,7 +823,7 @@ rrc_mac_config_req_ue(
 
 
   if (physicalConfigDedicated != NULL) {
-    mac_xface->phy_config_dedicated_ue(Mod_idP,0,eNB_index,physicalConfigDedicated);
+    phy_config_dedicated_ue(Mod_idP,0,eNB_index,physicalConfigDedicated);
     UE_mac_inst[Mod_idP].physicalConfigDedicated=physicalConfigDedicated; // for SR proc
   }
 
@@ -506,7 +832,7 @@ rrc_mac_config_req_ue(
   if (sCellToAddMod_r10 != NULL) {
 
 
-    mac_xface->phy_config_dedicated_scell_ue(Mod_idP,eNB_index,sCellToAddMod_r10,1);
+    phy_config_dedicated_scell_ue(Mod_idP,eNB_index,sCellToAddMod_r10,1);
     UE_mac_inst[Mod_idP].physicalConfigDedicatedSCell_r10 = sCellToAddMod_r10->radioResourceConfigDedicatedSCell_r10->physicalConfigDedicatedSCell_r10; // using SCell index 0
   }
   
@@ -523,18 +849,8 @@ rrc_mac_config_req_ue(
 	LOG_I(MAC,"Cell %d : Nid_cell %d\n",i,UE_mac_inst[Mod_idP].adj_cell_id[i]);
       }
       
-      mac_xface->phy_config_meas_ue(Mod_idP,0,eNB_index,UE_mac_inst[Mod_idP].n_adj_cells,UE_mac_inst[Mod_idP].adj_cell_id);
+      phy_config_meas_ue(Mod_idP,0,eNB_index,UE_mac_inst[Mod_idP].n_adj_cells,UE_mac_inst[Mod_idP].adj_cell_id);
     }
-    
-    /*
-      if (quantityConfig != NULL) {
-      if (quantityConfig[0] != NULL) {
-      UE_mac_inst[Mod_idP].quantityConfig = quantityConfig[0];
-      LOG_I(MAC,"UE %d configured filterCoeff.",UE_mac_inst[Mod_idP].crnti);
-      mac_xface->phy_config_meas_ue
-      }
-      }
-    */
   }
 
 
@@ -616,7 +932,7 @@ rrc_mac_config_req_ue(
 	     sizeof(*mobilityControlInfo->rach_ConfigDedicated));
     }
     
-    mac_xface->phy_config_afterHO_ue(Mod_idP,0,eNB_index,mobilityControlInfo,0);
+    phy_config_afterHO_ue(Mod_idP,0,eNB_index,mobilityControlInfo,0);
   }
 
 
@@ -643,7 +959,7 @@ rrc_mac_config_req_ue(
       UE_mac_inst[Mod_idP].mbsfn_AreaInfo[i] = mbsfn_AreaInfoList->list.array[i];
       LOG_I(MAC,"[UE %d] MBSFN_AreaInfo[%d]: MCCH Repetition Period = %ld\n",Mod_idP, i,
 	    UE_mac_inst[Mod_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
-      mac_xface->phy_config_sib13_ue(Mod_idP,0,eNB_index,i,UE_mac_inst[Mod_idP].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
+      phy_config_sib13_ue(Mod_idP,0,eNB_index,i,UE_mac_inst[Mod_idP].mbsfn_AreaInfo[i]->mbsfn_AreaId_r9);
     }
   }
   
@@ -670,54 +986,11 @@ rrc_mac_config_req_ue(
     UE_mac_inst[Mod_idP].cba_rnti[num_active_cba_groups-1] = cba_rnti;
     LOG_D(MAC,"[UE %d] configure CBA group %d RNTI %x for eNB %d (total active cba group %d)\n",
 	  Mod_idP,Mod_idP%num_active_cba_groups, cba_rnti,eNB_index,num_active_cba_groups);
-    mac_xface->phy_config_cba_rnti(Mod_idP,CC_idP,eNB_flagP,eNB_index,cba_rnti,num_active_cba_groups-1, num_active_cba_groups);
+    phy_config_cba_rnti(Mod_idP,CC_idP,eNB_flagP,eNB_index,cba_rnti,num_active_cba_groups-1, num_active_cba_groups);
   }
 #endif
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_RRC_MAC_CONFIG, VCD_FUNCTION_OUT);
 
   return(0);
 }
-#ifdef LOCALIZATION
-//------------------------------------------------------------------------------
-double
-rrc_get_estimated_ue_distance(
-  const protocol_ctxt_t* const ctxt_pP,
-  const int         CC_idP,
-  const uint8_t     loc_typeP
-)
-//------------------------------------------------------------------------------
-{
-  // localization types:
-  // 0: power based
-  // 1: time based
-  LTE_eNB_UE_stats     *eNB_UE_stats     = NULL;
-  UE_list_t*            UE_list = &eNB_mac_inst[ctxt_pP->module_id].UE_list;
-  int                   pCCid;
-  int                   UE_id;
-
-  if(ctxt_pP->rnti == NOT_A_RNTI) {
-    return -1;
-  }
-
-  UE_id = find_UE_id(ctxt_pP->module_id,ctxt_pP->rnti);
-  pCCid = UE_PCCID(ctxt_pP->module_id,UE_id);
-  eNB_UE_stats = mac_xface->get_eNB_UE_stats(ctxt_pP->module_id,pCCid,ctxt_pP->rnti);
-
-  switch (loc_typeP) {
-  case 0:
-    return eNB_UE_stats->distance.power_based;
-    break;
-
-  case 1:
-    return eNB_UE_stats->distance.time_based;
-    break;
-
-  default:
-    return  eNB_UE_stats->distance.power_based;
-  }
-
-  //    LOG_D(LOCALIZE, "DEBUG ME, dist = %d\n", &eNB_mac_inst[ctxt_pP->module_id].UE_list.UE_template[CC_idP][UE_id].distance.power_based);
-
-}
 
-#endif
diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h
index f56d4de76d9ebf6e8c70a064febcbb61545eb1a3..c3979c556449546caab64423f6689972eabd3647 100644
--- a/openair2/LAYER2/MAC/defs.h
+++ b/openair2/LAYER2/MAC/defs.h
@@ -52,7 +52,6 @@
 #include "PHY/defs.h"
 #include "PHY/LTE_TRANSPORT/defs.h"
 #include "COMMON/platform_constants.h"
-#include "COMMON/mac_rrc_primitives.h"
 #include "BCCH-BCH-Message.h"
 #include "RadioResourceConfigCommon.h"
 #include "RadioResourceConfigDedicated.h"
@@ -68,9 +67,8 @@
 #include "SCellToAddMod-r10.h"
 #endif
 
-//#ifdef PHY_EMUL
-//#include "SIMULATION/PHY_EMULATION/impl_defs.h"
-//#endif
+#include "nfapi_interface.h"
+#include "PHY_INTERFACE/IF_Module.h"
 
 /** @defgroup _mac  MAC
  * @ingroup _oai2
@@ -80,6 +78,7 @@
 #define BCCH_PAYLOAD_SIZE_MAX 128
 #define CCCH_PAYLOAD_SIZE_MAX 128
 #define PCCH_PAYLOAD_SIZE_MAX 128
+#define RAR_PAYLOAD_SIZE_MAX 128
 
 #define SCH_PAYLOAD_SIZE_MAX 4096
 /// Logical channel ids from 36-311 (Note BCCH is not specified in 36-311, uses the same as first DRB)
@@ -259,14 +258,10 @@ typedef struct {
   uint8_t R:2;
 } __attribute__((__packed__))POWER_HEADROOM_CMD;
 
-/*!\brief  DCI PDU filled by MAC for the PHY  */
+/*! \brief MIB payload */
 typedef struct {
-  uint8_t Num_ue_spec_dci ;
-  uint8_t Num_common_dci  ;
-  //  uint32_t nCCE;
-  uint32_t num_pdcch_symbols;
-  DCI_ALLOC_t dci_alloc[NUM_DCI_MAX] ;
-} DCI_PDU;
+  uint8_t payload[3] ;
+} __attribute__((__packed__))MIB_PDU;
 /*! \brief CCCH payload */
 typedef struct {
   uint8_t payload[CCCH_PAYLOAD_SIZE_MAX] ;
@@ -275,6 +270,10 @@ typedef struct {
 typedef struct {
   uint8_t payload[BCCH_PAYLOAD_SIZE_MAX] ;
 } __attribute__((__packed__))BCCH_PDU;
+/*! \brief RAR payload */
+typedef struct {
+  uint8_t payload[RAR_PAYLOAD_SIZE_MAX];
+} __attribute__ ((__packed__)) RAR_PDU;
 /*! \brief BCCH payload */
 typedef struct {
   uint8_t payload[PCCH_PAYLOAD_SIZE_MAX] ;
@@ -305,10 +304,12 @@ typedef struct {
 #endif
 /*! \brief Values of CCCH LCID for DLSCH */ 
 #define CCCH_LCHANID 0
-/*!\brief Values of BCCH logical channel */
+/*!\brief Values of BCCH logical channel (fake)*/
 #define BCCH 3  // SI 
-/*!\brief Values of PCCH logical channel */
+/*!\brief Values of PCCH logical channel (fake)*/
 #define PCCH 4  // Paging 
+/*!\brief Values of PCCH logical channel (fake) */
+#define MIBCH 5  // MIB 
 /*!\brief Value of CCCH / SRB0 logical channel */
 #define CCCH 0  // srb0
 /*!\brief DCCH / SRB1 logical channel */
@@ -363,10 +364,11 @@ typedef struct {
 
 /*! \brief Downlink SCH PDU Structure */
 typedef struct {
-  int8_t payload[8][SCH_PAYLOAD_SIZE_MAX];
+  uint8_t payload[8][SCH_PAYLOAD_SIZE_MAX];
   uint16_t Pdu_size[8];
 } __attribute__ ((__packed__)) DLSCH_PDU;
 
+
 /*! \brief MCH PDU Structure */
 typedef struct {
   int8_t payload[SCH_PAYLOAD_SIZE_MAX];
@@ -562,6 +564,12 @@ typedef struct {
 
   /// RX
 
+  /// PUCCH1a/b power (dBm)
+  int32_t Po_PUCCH_dBm;
+  /// Indicator that Po_PUCCH has been updated by PHY
+  int32_t Po_PUCCH_update;
+  /// Uplink measured RSSI
+  int32_t UL_rssi;
   /// preassigned mcs after rate adaptation
   uint8_t ulsch_mcs1;
   /// adjusted mcs
@@ -626,6 +634,10 @@ typedef struct {
   rnti_t rnti;
   /// NDI from last scheduling
   uint8_t oldNDI[8];
+  /// mcs1 from last scheduling
+  uint8_t oldmcs1[8];
+  /// mcs2 from last scheduling
+  uint8_t oldmcs2[8];
   /// NDI from last UL scheduling
   uint8_t oldNDI_UL[8];
   /// Flag to indicate UL has been scheduled at least once
@@ -641,26 +653,18 @@ typedef struct {
 
   // PHY interface info
 
-  /// DCI format for DLSCH
-  uint16_t DLSCH_dci_fmt;
-
-  /// Current Aggregation Level for DCI
-  uint8_t DCI_aggregation_min;
-
-  /// size of DLSCH size in bit 
-  uint8_t DLSCH_dci_size_bits;
-
-  /// DCI buffer for DLSCH
-  /* rounded to 32 bits unit (actual value should be 8 due to the logic
-   * of the function generate_dci0) */
-  uint8_t DLSCH_DCI[8][(((MAX_DCI_SIZE_BITS)+31)>>5)*4];
-
   /// Number of Allocated RBs for DL after scheduling (prior to frequency allocation)
   uint16_t nb_rb[8]; // num_max_harq
 
-  /// Number of Allocated RBs for UL after scheduling (prior to frequency allocation)
+  /// Number of Allocated RBs for UL after scheduling
   uint16_t nb_rb_ul[8]; // num_max_harq
 
+  /// Number of Allocated RBs for UL after scheduling
+  uint16_t first_rb_ul[8]; // num_max_harq
+
+  /// Cyclic shift for DMRS after scheduling
+  uint16_t cshift[8]; // num_max_harq
+
   /// Number of Allocated RBs by the ulsch preprocessor
   uint8_t pre_allocated_nb_rb_ul;
 
@@ -676,11 +680,6 @@ typedef struct {
   /// assigned MCS by the ulsch scheduler
   uint8_t assigned_mcs_ul;
 
-  /// DCI buffer for ULSCH
-  /* rounded to 32 bits unit (actual value should be 8 due to the logic
-   * of the function generate_dci0) */
-  uint8_t ULSCH_DCI[8][(((MAX_DCI_SIZE_BITS)+31)>>5)*4];
-
   /// DL DAI
   uint8_t DAI;
 
@@ -777,6 +776,7 @@ typedef struct {
   // resource scheduling information
   uint8_t       harq_pid[MAX_NUM_CCs];
   uint8_t       round[MAX_NUM_CCs];
+  uint8_t       round_UL[MAX_NUM_CCs];
   uint8_t       dl_pow_off[MAX_NUM_CCs];
   uint16_t      pre_nb_available_rbs[MAX_NUM_CCs];
   unsigned char rballoc_sub_UE[MAX_NUM_CCs][N_RBG_MAX];
@@ -846,6 +846,7 @@ typedef struct {
 } SBMAP_CONF;
 /*! \brief UE list used by eNB to order UEs/CC for scheduling*/ 
 typedef struct {
+  /// Dedicated information for UEs
   struct PhysicalConfigDedicated  *physicalConfigDedicated[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
   /// DLSCH pdu 
   DLSCH_PDU DLSCH_pdu[MAX_NUM_CCs][2][NUMBER_OF_UE_MAX];
@@ -867,7 +868,6 @@ typedef struct {
   eNB_UE_STATS eNB_UE_stats[MAX_NUM_CCs][NUMBER_OF_UE_MAX];
   /// scheduling control info
   UE_sched_ctrl UE_sched_ctrl[NUMBER_OF_UE_MAX];
-
   int next[NUMBER_OF_UE_MAX];
   int head;
   int next_ul[NUMBER_OF_UE_MAX];
@@ -886,19 +886,23 @@ typedef struct {
   uint32_t                         dl_CarrierFreq;
   BCCH_BCH_Message_t               *mib;
   RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon;  
+  RadioResourceConfigCommonSIB_t   *radioResourceConfigCommon_BR;  
   TDD_Config_t                     *tdd_Config;
   uint8_t                          SIwindowsize;
   uint16_t                         SIperiod;
   ARFCN_ValueEUTRA_t               ul_CarrierFreq;
   long                             ul_Bandwidth;
-  /// Outgoing DCI for PHY generated by eNB scheduler
-  DCI_PDU DCI_pdu;
+  /// Outgoing MIB PDU for PHY
+  MIB_PDU MIB_pdu;
   /// Outgoing BCCH pdu for PHY
   BCCH_PDU BCCH_pdu;
   /// Outgoing BCCH DCI allocation
   uint32_t BCCH_alloc_pdu;
   /// Outgoing CCCH pdu for PHY
   CCCH_PDU CCCH_pdu;
+  /// Outgoing RAR pdu for PHY
+  RAR_PDU RAR_pdu;
+  /// Template for RA computations
   RA_TEMPLATE RA_template[NB_RA_PROC_MAX];
   /// VRB map for common channels
   uint8_t vrb_map[100];
@@ -928,25 +932,44 @@ typedef struct {
   /// Outgoing MCH pdu for PHY
   MCH_PDU MCH_pdu;
 #endif
-#ifdef CBA
-  /// number of CBA groups 
-  uint8_t num_active_cba_groups;
-  /// RNTI for each CBA group 
-  uint16_t cba_rnti[NUM_MAX_CBA_GROUP];
-  /// MCS for each CBA group 
-  uint8_t group_mcs[NUM_MAX_CBA_GROUP];
-#endif
 } COMMON_channels_t;
 /*! \brief top level eNB MAC structure */ 
 typedef struct eNB_MAC_INST_s {
+  /// Ethernet parameters for northbound midhaul interface
+  eth_params_t         eth_params_n;
+  /// Ethernet parameters for fronthaul interface
+  eth_params_t         eth_params_s;
   ///
   uint16_t Node_id;
   /// frame counter
   frame_t frame;
   /// subframe counter
   sub_frame_t subframe;
+  /// Pointer to IF module instance for PHY
+  IF_Module_t *if_inst;
   /// Common cell resources
   COMMON_channels_t common_channels[MAX_NUM_CCs];
+  /// current PDU index (BCH,MCH,DLSCH)
+  int pdu_index[MAX_NUM_CCs];
+
+  /// NFAPI Config Request Structure
+  nfapi_config_request_t config[MAX_NUM_CCs];
+  /// Preallocated DL pdu list
+  nfapi_dl_config_request_pdu_t dl_config_pdu_list[MAX_NUM_CCs][MAX_NUM_DL_PDU];
+  /// NFAPI DL Config Request Structure
+  nfapi_dl_config_request_body_t DL_req[MAX_NUM_CCs];
+  /// Preallocated UL pdu list
+  nfapi_ul_config_request_pdu_t ul_config_pdu_list[MAX_NUM_CCs][MAX_NUM_UL_PDU];
+  /// NFAPI UL Config Request Structure
+  nfapi_ul_config_request_body_t UL_req[MAX_NUM_CCs];
+  /// Preallocated HI_DCI0 pdu list 
+  nfapi_hi_dci0_request_pdu_t hi_dci0_pdu_list[MAX_NUM_CCs][MAX_NUM_HI_DCI0_PDU];
+  /// NFAPI HI/DCI0 Config Request Structure
+  nfapi_hi_dci0_request_body_t HI_DCI0_req[MAX_NUM_CCs];
+  /// Prealocated TX pdu list
+  nfapi_tx_request_pdu_t tx_request_pdu[MAX_NUM_CCs][MAX_NUM_TX_REQUEST_PDU];
+  /// NFAPI DL PDU structure
+  nfapi_tx_request_body_t TX_req[MAX_NUM_CCs];
 
   UE_list_t UE_list;
 
@@ -1095,8 +1118,10 @@ typedef struct {
   UE_SCHEDULING_INFO scheduling_info;
   /// Outgoing CCCH pdu for PHY
   CCCH_PDU CCCH_pdu;
+  /// Outgoing RAR pdu for PHY
+  RAR_PDU RAR_pdu;
   /// Incoming DLSCH pdu for PHY
-  //DLSCH_PDU DLSCH_pdu[NUMBER_OF_UE_MAX][2];
+  DLSCH_PDU DLSCH_pdu[NUMBER_OF_UE_MAX][2];
   /// number of attempt for rach
   uint8_t RA_attempt_number;
   /// Random-access procedure flag
diff --git a/openair2/LAYER2/MAC/eNB_scheduler.c b/openair2/LAYER2/MAC/eNB_scheduler.c
index ac977fe3d3d4793670acd32e74436ccf6542c44e..e29f96b8f77a54b475492ac188ef98843d9924c9 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler.c
@@ -68,6 +68,68 @@
 
 extern RAN_CONTEXT_t RC;
 
+uint16_t pdcch_order_table[6] = {31,31,511,2047,2047,8191};
+
+void check_ul_failure(module_id_t module_idP,int CC_id,int UE_id,
+		      frame_t frameP, sub_frame_t subframeP) {
+
+  UE_list_t                           *UE_list      = &RC.mac[module_idP]->UE_list;
+  nfapi_dl_config_request_body_t      *DL_req       = &RC.mac[module_idP]->DL_req[0];
+  uint16_t                            rnti          = UE_RNTI(module_idP,UE_id);
+  eNB_UE_STATS                        *eNB_UE_stats = &RC.mac[module_idP]->UE_list.eNB_UE_stats[CC_id][UE_id];
+  COMMON_channels_t                   *cc           = RC.mac[module_idP]->common_channels;
+
+  // check uplink failure
+  if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer>0)&&
+      (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync==0)) {
+    LOG_D(MAC,"UE %d rnti %x: UL Failure timer %d \n",UE_id,rnti,UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);
+    if (UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent==0) {
+      UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent=1;
+      
+      // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
+      LOG_D(MAC,"UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d) \n",UE_id,rnti,UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);	    
+      nfapi_dl_config_request_pdu_t* dl_config_pdu                    = &DL_req[CC_id].dl_config_pdu_list[DL_req[CC_id].number_pdu]; 
+      memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+      dl_config_pdu->pdu_type                                         = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
+      dl_config_pdu->pdu_size                                         = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format            = NFAPI_DL_DCI_FORMAT_1A;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level     = get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->dl_cqi,format1A);
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                  = rnti;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type             = 1;    // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power    = 6000; // equal to RS power
+      
+      AssertFatal((cc[CC_id].mib->message.dl_Bandwidth >=0) && (cc[CC_id].mib->message.dl_Bandwidth<6),
+		  "illegal dl_Bandwidth %d\n",(int)cc[CC_id].mib->message.dl_Bandwidth);
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding = pdcch_order_table[cc[CC_id].mib->message.dl_Bandwidth];
+      DL_req[CC_id].number_dci++;
+      DL_req[CC_id].number_pdu++;
+      
+      /* 
+	 add_ue_spec_dci(&DL_req[CC_id],
+	 rnti,
+	 get_aggregation(get_tw_index(module_idP,CC_id),eNB_UE_stats->DL_cqi[0],format1A),
+	 format1A,
+	 NO_DLSCH);*/
+    }
+    else { // ra_pdcch_sent==1
+      LOG_D(MAC,"UE %d rnti %x: sent PDCCH order for RAPROC waiting (failure timer %d) \n",UE_id,rnti,UE_list->UE_sched_ctrl[UE_id].ul_failure_timer);	    	    
+      if ((UE_list->UE_sched_ctrl[UE_id].ul_failure_timer % 40) == 0)
+	UE_list->UE_sched_ctrl[UE_id].ra_pdcch_order_sent=0; // resend every 4 frames	      
+    }
+    
+    UE_list->UE_sched_ctrl[UE_id].ul_failure_timer++;
+    // check threshold
+    if (UE_list->UE_sched_ctrl[UE_id].ul_failure_timer > 200) {
+      // inform RRC of failure and clear timer
+      LOG_I(MAC,"UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",UE_id,rnti);
+      mac_eNB_rrc_ul_failure(module_idP,CC_id,frameP,subframeP,rnti);
+      UE_list->UE_sched_ctrl[UE_id].ul_failure_timer=0;
+      UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync=1;
+    }
+  } // ul_failure_timer>0
+  
+}
+
 void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP)  //, int calibration_flag) {
 {
 
@@ -80,38 +142,49 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
   instance_t    instance;
   int           result;
 #endif
-  DCI_PDU *DCI_pdu[MAX_NUM_CCs];
   int CC_id,i; //,next_i;
   UE_list_t *UE_list=&RC.mac[module_idP]->UE_list;
   rnti_t rnti;
-  void         *DLSCH_dci=NULL;
-  int size_bits=0,size_bytes=0;
   
-  LTE_eNB_UE_stats  *eNB_UE_stats   = NULL;
-  COMMON_channels_t *cc = RC.mac[module_idP]->common_channels;
-
+  COMMON_channels_t                   *cc             = RC.mac[module_idP]->common_channels;
+  nfapi_dl_config_request_body_t      *DL_req         = &RC.mac[module_idP]->DL_req[0];
+  nfapi_ul_config_request_body_t      *UL_req         = &RC.mac[module_idP]->UL_req[0];
+  nfapi_hi_dci0_request_body_t        *HI_DCI0_req    = &RC.mac[module_idP]->HI_DCI0_req[0];
+  nfapi_tx_request_body_t             *TX_req         = &RC.mac[module_idP]->TX_req[0];
+  eNB_UE_STATS                        *eNB_UE_stats;
 #if defined(FLEXRAN_AGENT_SB_IF)
   Protocol__FlexranMessage *msg;
 #endif
 
   
-  LOG_D(MAC,"[eNB %d] Frame %d, Subframe %d, entering MAC scheduler (UE_list->head %d)\n",module_idP, frameP, subframeP,UE_list->head);
+  LOG_I(MAC,"[eNB %d] Frame %d, Subframe %d, entering MAC scheduler (UE_list->head %d)\n",module_idP, frameP, subframeP,UE_list->head);
 
   start_meas(&RC.mac[module_idP]->eNB_scheduler);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_IN);
 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-    DCI_pdu[CC_id] = &cc[CC_id].DCI_pdu;
     mbsfn_status[CC_id]=0;
     // clear vrb_map
     memset(cc[CC_id].vrb_map,0,100);
-  }
 
-  // clear DCI and BCCH contents before scheduling
-  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-    DCI_pdu[CC_id]->Num_common_dci  = 0;
-    DCI_pdu[CC_id]->Num_ue_spec_dci = 0;
+    // clear DL/UL info for new scheduling round
+
+    RC.mac[module_idP]->pdu_index[CC_id]         = 0;
+    DL_req[CC_id].number_pdcch_ofdm_symbols      = 1;
+    DL_req[CC_id].number_dci                     = 0;
+    DL_req[CC_id].number_pdu                     = 0;
+    DL_req[CC_id].number_pdsch_rnti              = 0;
+    DL_req[CC_id].transmission_power_pcfich      = 6000;
+
+    HI_DCI0_req[CC_id].sfnsf                     = subframeP + (frameP<<3);
+    HI_DCI0_req[CC_id].number_of_dci             = 0;
+    HI_DCI0_req[CC_id].number_of_hi              = 0;
+
+    UL_req[CC_id].number_of_pdus                 = 0;
+    UL_req[CC_id].rach_prach_frequency_resources = 0; // ignored, handled by PHY for now
+    UL_req[CC_id].srs_present                    = 0; // ignored, handled by PHY for now
 
+    TX_req[CC_id].number_of_pdus                 = 0;
 #if defined(Rel10) || defined(Rel14)
     cc[CC_id].mcch_active =0;
 #endif
@@ -123,15 +196,15 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
   for (i = 0; i < NUMBER_OF_UE_MAX; i++) {
     if (UE_list->active[i] != TRUE) continue;
 
-    rnti = UE_RNTI(module_idP, i);
-    CC_id = UE_PCCID(module_idP, i);
+    rnti         = UE_RNTI(module_idP, i);
+    CC_id        = UE_PCCID(module_idP, i);
+    eNB_UE_stats = &RC.mac[module_idP]->UE_list.eNB_UE_stats[CC_id][i];
+
     if ((frameP==0)&&(subframeP==0)) {
-      LTE_eNB_UE_stats *eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP, CC_id, rnti);
-      int cqi = eNB_UE_stats == NULL ? -1 : eNB_UE_stats->DL_cqi[0];
       LOG_I(MAC,"UE  rnti %x : %s, PHR %d dB CQI %d\n", rnti,
             UE_list->UE_sched_ctrl[i].ul_out_of_sync==0 ? "in synch" : "out of sync",
             UE_list->UE_template[CC_id][i].phr_info,
-            cqi);
+            eNB_UE_stats->dl_cqi);
     }
 
     RC.eNB[module_idP][CC_id]->pusch_stats_bsr[i][(frameP*10)+subframeP]=-63;
@@ -141,139 +214,26 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
     RC.mac[module_idP]->UE_list.UE_sched_ctrl[i].ul_inactivity_timer++;
 
     RC.mac[module_idP]->UE_list.UE_sched_ctrl[i].cqi_req_timer++;
-    eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
 
-    if (eNB_UE_stats==NULL) {
+    // 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_SB_IF)
+#if defined(FLEXRAN_AGENT_S_IF)
       if (mac_agent_registered[module_idP]) {
 	agent_mac_xface[module_idP]->flexran_agent_notify_ue_state_change(module_idP,
 									  rnti,
 									  PROTOCOL__FLEX_UE_STATE_CHANGE_TYPE__FLUESC_DEACTIVATED);
       }
 #endif
-    }
-    else {
-      // check uplink failure
-      if ((UE_list->UE_sched_ctrl[i].ul_failure_timer>0)&&
-	  (UE_list->UE_sched_ctrl[i].ul_out_of_sync==0)) {
-	LOG_D(MAC,"UE %d rnti %x: UL Failure timer %d \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);
-	if (UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent==0) {
-	  UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent=1;
-	  
-	  // add a format 1A dci for this UE to request an RA procedure (only one UE per subframe)
-	  LOG_D(MAC,"UE %d rnti %x: sending PDCCH order for RAPROC (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    
-	  DLSCH_dci = (void *)UE_list->UE_template[CC_id][i].DLSCH_DCI[0];
-	  *(uint32_t*)DLSCH_dci = 0;
-	  int N_RB_DL = cc[CC_id].mib->message.dl_Bandwidth;
-	  if (cc[CC_id].tdd_Config != NULL) {
-	    switch (N_RB_DL) {
-	    case 0:
-	      ((DCI1A_1_5MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_1_5MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 31;
-	      size_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-	      size_bits  = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-	      break;
-	    case 1:
-	      /*	      ((DCI1A_2_5MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_2_5MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 31;
-	      size_bytes = sizeof(DCI1A_2_5MHz_TDD_1_6_t);
-	      size_bits  = sizeof_DCI1A_2_5MHz_TDD_1_6_t;*/
-	      break;
-	    case 2:
-	      ((DCI1A_5MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_5MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 511;
-	      size_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
-	      size_bits  = sizeof_DCI1A_5MHz_TDD_1_6_t;
-	      break;
-	    case 3:
-	      ((DCI1A_10MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_10MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 2047;
-	      size_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
-	      size_bits  = sizeof_DCI1A_10MHz_TDD_1_6_t;
-	      break;
-	    case 4:/*
-	      ((DCI1A_15MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_15MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 2047;
-	      size_bytes = sizeof(DCI1A_15MHz_TDD_1_6_t);
-	      size_bits  = sizeof_DCI1A_15MHz_TDD_1_6_t;
-	      break;*/
-	    case 5:
-	      ((DCI1A_20MHz_TDD_1_6_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_20MHz_TDD_1_6_t*)DLSCH_dci)->rballoc = 8191;
-	      size_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
-	      size_bits  = sizeof_DCI1A_20MHz_TDD_1_6_t;
-	      break;
-	    }
-	  }
-	  else { // FDD
-	    switch (N_RB_DL) {
-	    case 0:
-	      ((DCI1A_1_5MHz_FDD_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_1_5MHz_FDD_t*)DLSCH_dci)->rballoc = 31;
-	      size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
-	      size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;
-	      break;
-	    case 1:/*
-	      ((DCI1A_2_5MHz_FDD_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_2_5MHz_FDD_t*)DLSCH_dci)->rballoc = 31;
-	      size_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
-	      size_bits  = sizeof_DCI1A_1_5MHz_FDD_t;*/
-	      break;
-	    case 2:
-	      ((DCI1A_5MHz_FDD_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_5MHz_FDD_t*)DLSCH_dci)->rballoc = 511;
-	      size_bytes = sizeof(DCI1A_5MHz_FDD_t);
-	      size_bits  = sizeof_DCI1A_5MHz_FDD_t;
-	      break;
-	    case 3:
-	      ((DCI1A_10MHz_FDD_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_10MHz_FDD_t*)DLSCH_dci)->rballoc = 2047;
-	      size_bytes = sizeof(DCI1A_10MHz_FDD_t);
-	      size_bits  = sizeof_DCI1A_10MHz_FDD_t;
-		break;
-	    case 4:
-	      /*	      ((DCI1A_15MHz_FDD_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_15MHz_FDD_t*)DLSCH_dci)->rballoc = 2047;
-	      size_bytes = sizeof(DCI1A_10MHz_FDD_t);
-	      size_bits  = sizeof_DCI1A_10MHz_FDD_t;*/
-		break;
-	    case 5:
-	      ((DCI1A_20MHz_FDD_t*)DLSCH_dci)->type = 1;
-	      ((DCI1A_20MHz_FDD_t*)DLSCH_dci)->rballoc = 8191;
-	      size_bytes = sizeof(DCI1A_20MHz_FDD_t);
-	      size_bits  = sizeof_DCI1A_20MHz_FDD_t;
-	      break;
-	    }
-	  }
-	  
-	  add_ue_spec_dci(DCI_pdu[CC_id],
-			  DLSCH_dci,
-			  rnti,
-			  size_bytes,
-			  get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->DL_cqi[0],format1A),
-			  size_bits,
-			  format1A,
-			  0);
-	}
-	else { // ra_pdcch_sent==1
-	  LOG_D(MAC,"UE %d rnti %x: sent PDCCH order for RAPROC waiting (failure timer %d) \n",i,rnti,UE_list->UE_sched_ctrl[i].ul_failure_timer);	    	    
-	  if ((UE_list->UE_sched_ctrl[i].ul_failure_timer % 40) == 0)
-	    UE_list->UE_sched_ctrl[i].ra_pdcch_order_sent=0; // resend every 4 frames	      
-	}
-      
-	UE_list->UE_sched_ctrl[i].ul_failure_timer++;
-	// check threshold
-	if (UE_list->UE_sched_ctrl[i].ul_failure_timer > 200) {
-	  // inform RRC of failure and clear timer
-	  LOG_I(MAC,"UE %d rnti %x: UL Failure after repeated PDCCH orders: Triggering RRC \n",i,rnti);
-	  mac_eNB_rrc_ul_failure(module_idP,CC_id,frameP,subframeP,rnti);
-	  UE_list->UE_sched_ctrl[i].ul_failure_timer=0;
-	  UE_list->UE_sched_ctrl[i].ul_out_of_sync=1;
-	}
-      }
-    } // ul_failure_timer>0
+}*/
+    check_ul_failure(module_idP,CC_id,i,frameP,subframeP);
+
   }
 
 #if defined(ENABLE_ITTI)
@@ -337,13 +297,9 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 /*   } */
 /* #endif */
   
-  //if (subframeP%5 == 0)
-  //#ifdef EXMIMO
   PROTOCOL_CTXT_SET_BY_MODULE_ID(&ctxt, module_idP, ENB_FLAG_YES, NOT_A_RNTI, frameP, subframeP,module_idP);
   pdcp_run(&ctxt);
-  //#endif
 
-  // check HO
   rrc_rx_tx(&ctxt,
             0, // eNB index, unused in eNB
             CC_id);
@@ -369,8 +325,11 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 
 
     //    schedule_RA(module_idP,frameP,subframeP,2);
-
-    
+    LOG_I(MAC,"Scheduling MIB\n");
+    if ((frameP&3) == 0) schedule_mib(module_idP,frameP,subframeP);
+    LOG_I(MAC,"NFAPI: number_of_pdus %d, number_of_TX_req %d\n",
+	  DL_req[0].number_pdu,
+	  TX_req[0].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) ||
@@ -1066,7 +1025,7 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 
   }
 
-  LOG_D(MAC,"FrameP %d, subframeP %d : Scheduling CCEs\n",frameP,subframeP);
+  LOG_I(MAC,"FrameP %d, subframeP %d : Scheduling CCEs\n",frameP,subframeP);
 
   // Allocate CCEs for good after scheduling is done
   for (CC_id=0;CC_id<MAX_NUM_CCs;CC_id++)
@@ -1081,27 +1040,6 @@ void eNB_dlsch_ulsch_scheduler(module_id_t module_idP,uint8_t cooperation_flag,
 #endif
 #endif
 
-  /*
-  int dummy=0;
-  for (i=0;
-       i<DCI_pdu[CC_id]->Num_common_dci+DCI_pdu[CC_id]->Num_ue_spec_dci;
-       i++)
-    if (DCI_pdu[CC_id]->dci_alloc[i].rnti==2)
-      dummy=1;
-	
-  if (dummy==1)
-    for (i=0;
-	 i<DCI_pdu[CC_id]->Num_common_dci+DCI_pdu[CC_id]->Num_ue_spec_dci;
-	 i++)
-      LOG_I(MAC,"Frame %d, subframe %d: DCI %d/%d, format %d, rnti %x, NCCE %d(num_pdcch_symb %d)\n",
-	    frameP,subframeP,i,DCI_pdu[CC_id]->Num_common_dci+DCI_pdu[CC_id]->Num_ue_spec_dci,
-	    DCI_pdu[CC_id]->dci_alloc[i].format,
-	    DCI_pdu[CC_id]->dci_alloc[i].rnti,
-	    DCI_pdu[CC_id]->dci_alloc[i].firstCCE,
-	    DCI_pdu[CC_id]->num_pdcch_symbols);
-
-  LOG_D(MAC,"frameP %d, subframeP %d\n",frameP,subframeP);
-  */
 
   stop_meas(&RC.mac[module_idP]->eNB_scheduler);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_ENB_DLSCH_ULSCH_SCHEDULER,VCD_FUNCTION_OUT);
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 2a8c9e28e2d72c21ad7f47799358a6a4cc46264b..53d2b694499b88b067373ee14b3f00b83903d4fd 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -62,40 +62,46 @@
 
 #include "T.h"
 
+// eMTC notes
+// Implements MSG2 and MSG4
+// fill_rar for eMTC
+// new RA_templates for eMTC UEs, CCCH_BR instead of CCCH
+// resource allocation for format 1A (4->6 PRBs)
+// initiate_ra_proc: add detection of BR/CE UEs
+
 void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,unsigned char Msg3_subframe)
 {
 
-  int                CC_id;
-  eNB_MAC_INST       *eNB = RC.mac[module_idP];
-  COMMON_channels_t  *cc  = eNB->common_channels;
-  RA_TEMPLATE        *RA_template;
-  uint8_t            i;
-  uint8_t            harq_pid;
-  uint8_t            round;
-  int16_t            rrc_sdu_length;
-  uint8_t            lcid;
-  uint8_t            offset;
-  int                UE_id           = -1;
-  int16_t            TBsize          = -1;
-  uint16_t           msg4_padding;
-  uint16_t           msg4_post_padding;
-  uint16_t           msg4_header;
-  uint8_t            *vrb_map;
-  int                first_rb;
-  int                rballoc[MAX_NUM_CCs];
-  DCI_PDU            *DCI_pdu;
-  int                N_RB_DL;
-  int                N_RB_UL;
+  int                             CC_id;
+  eNB_MAC_INST                    *eNB = RC.mac[module_idP];
+  COMMON_channels_t               *cc  = eNB->common_channels;
+  RA_TEMPLATE                     *RA_template;
+  uint8_t                         i;
+  int16_t                         rrc_sdu_length;
+  uint8_t                         lcid;
+  uint8_t                         offset;
+  int                             UE_id           = -1;
+  int16_t                         TBsize          = -1;
+  uint16_t                        msg4_padding;
+  uint16_t                        msg4_post_padding;
+  uint16_t                        msg4_header;
+  uint8_t                         *vrb_map;
+  int                             first_rb;
+  int                             N_RB_DL;
+  nfapi_dl_config_request_pdu_t   *dl_config_pdu;
+  nfapi_tx_request_pdu_t          *TX_req;
+  UE_list_t                       *UE_list=&eNB->UE_list;
+  int round;
 
   start_meas(&eNB->schedule_ra);
 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
 
 
-    vrb_map = cc[CC_id].vrb_map;
-    DCI_pdu = &cc[CC_id].DCI_pdu;
-    N_RB_DL = to_prb(cc[CC_id].mib->message.dl_Bandwidth);
-    N_RB_UL = to_prb(cc[CC_id].ul_Bandwidth);
+    vrb_map       = cc[CC_id].vrb_map;
+
+    dl_config_pdu = &eNB->DL_req[CC_id].dl_config_pdu_list[eNB->DL_req[CC_id].number_pdu]; 
+    N_RB_DL       = to_prb(cc[CC_id].mib->message.dl_Bandwidth);
 
     for (i=0; i<NB_RA_PROC_MAX; i++) {
 
@@ -120,161 +126,47 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
           vrb_map[first_rb+2] = 1;
           vrb_map[first_rb+3] = 1;
 
-          if (cc[CC_id].tdd_Config!=NULL) { // TDD
-            switch(N_RB_DL) {
-            case 6:
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            case 25:
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            case 50:
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            case 100:
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            default:
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-            }
-          } else {
-            switch(N_RB_DL) {
-            case 6:
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            case 25:
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_UL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            case 50:
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            case 100:
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->type=1;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type=0;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->ndi=1;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rv=0;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->mcs=0;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->harq_pid=0;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->TPC=1;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->padding=0;
-              ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-              rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->vrb_type,
-                                ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu1[0])->rballoc);
-              break;
-
-            default:
-              break;
-            }
-          }
+	  memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+	  dl_config_pdu->pdu_type                                                          = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
+	  dl_config_pdu->pdu_size                                                          = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                             = NFAPI_DL_DCI_FORMAT_1A;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = 4;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = RA_template->RA_rnti;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = 2;    // RA-RNTI : see Table 4-10 from SCF082 - nFAPI specifications
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power                     = 6000; // equal to RS power
+	  
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = 0;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = 1; // no TPC
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1                   = 1;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                                  = 0;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1                   = 0;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = 0;
 
 	  if (!CCE_allocation_infeasible(module_idP,CC_id,1,subframeP,2,RA_template->RA_rnti)) {
 	    LOG_D(MAC,"Frame %d: Subframe %d : Adding common DCI for RA_RNTI %x\n",
                   frameP,subframeP,RA_template->RA_rnti);
-	    add_common_dci(DCI_pdu,
-			   (void*)&RA_template->RA_alloc_pdu1[0],
-			   RA_template->RA_rnti,
-			   RA_template->RA_dci_size_bytes1,
-			   2,
-			   RA_template->RA_dci_size_bits1,
-			   RA_template->RA_dci_fmt1,
-			   1);
+	    eNB->DL_req[CC_id].number_dci++;
+	    eNB->DL_req[CC_id].number_pdu++;
 
             /* this will be updated when PHY calls set_msg3_subframe */
 	    RA_template->Msg3_subframe = -1;
+
+	    fill_rar(module_idP,CC_id,frameP,cc[CC_id].RAR_pdu.payload,N_RB_DL,7);
+	    // DL request
+		     
+	    TX_req                                                                = &eNB->TX_req[CC_id].tx_pdu_list[eNB->TX_req[CC_id].number_of_pdus]; 
+	    TX_req->pdu_length                                                    = 7;  // This should be changed if we have more than 1 preamble 
+	    TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
+	    TX_req->num_segments                                                  = 1;
+	    TX_req->segments[0].segment_length                                    = 7;
+	    TX_req->segments[0].segment_data                                      = cc[CC_id].RAR_pdu.payload;
+	    eNB->TX_req[CC_id].number_of_pdus++;
 	  }
         } else if (RA_template->generate_Msg4 == 1) {
 
           // check for Msg4 Message
           UE_id = find_UE_id(module_idP,RA_template->rnti);
-          if (UE_id == -1) { printf("%s:%d:%s: FATAL ERROR\n", __FILE__, __LINE__, __FUNCTION__); abort(); }
+	  AssertFatal(UE_id>=0,"Can't find UE for t-crnti\n");
 
           if (Is_rrc_registered == 1) {
 
@@ -289,12 +181,8 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
                                               module_idP,
                                               0); // not used in this case
 
-            if (rrc_sdu_length == -1) {
-              mac_xface->macphy_exit("[MAC][eNB Scheduler] CCCH not allocated\n");
-              return; // not reached
-            } else {
-              //msg("[MAC][eNB %d] Frame %d, subframeP %d: got %d bytes from RRC\n",module_idP,frameP, subframeP,rrc_sdu_length);
-            }
+	    AssertFatal(rrc_sdu_length>=0,
+			"[MAC][eNB Scheduler] CCCH not allocated\n");
           }
 
           LOG_D(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: UE_id %d, Is_rrc_registered %d, rrc_sdu_length %d\n",
@@ -312,304 +200,59 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 	    vrb_map[first_rb+3] = 1;
 
 
+	    memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+	    dl_config_pdu->pdu_type                                                          = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
+	    dl_config_pdu->pdu_size                                                          = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                             = NFAPI_DL_DCI_FORMAT_1A;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = 4;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = RA_template->rnti;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = 1;    // C-RNTI : see Table 4-10 from SCF082 - nFAPI specifications
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power                     = 6000; // equal to RS power
+	    
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = 0;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = 1; // no TPC
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1                   = 1;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1                   = 0;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = 0;
+
             // Compute MCS for 3 PRB
             msg4_header = 1+6+1;  // CR header, CR CE, SDU header
 
-            if (cc[CC_id].tdd_Config != NULL) { // TDD
-
-              switch (N_RB_DL) {
-              case 6:
-                ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-		((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->padding=0;
-		((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_1_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-		
-                break;
-
-              case 25:
-
-                ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-		
-		((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->padding=0;
-		((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-                break;
-
-              case 50:
-
-                ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-		((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->padding=0;
-		((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_10MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-
-                break;
-
-              case 100:
-
-                ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-
-		((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_20MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-                break;
-              }
-            } else { // FDD DCI
-              switch (N_RB_DL) {
-              case 6:
-                ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-
-		((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->padding=0;
-		((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_1_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-                break;
-
-              case 25:
-                ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-
-		((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->padding=0;
-		((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-                break;
-
-              case 50:
-                ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-
-		((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->padding=0;
-		((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_10MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-                break;
-
-              case 100:
-                ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-
-                if ((rrc_sdu_length+msg4_header) <= 22) {
-                  ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=4;
-                  TBsize = 22;
-                } else if ((rrc_sdu_length+msg4_header) <= 28) {
-                  ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=5;
-                  TBsize = 28;
-                } else if ((rrc_sdu_length+msg4_header) <= 32) {
-                  ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=6;
-                  TBsize = 32;
-                } else if ((rrc_sdu_length+msg4_header) <= 41) {
-                  ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=7;
-                  TBsize = 41;
-                } else if ((rrc_sdu_length+msg4_header) <= 49) {
-                  ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=8;
-                  TBsize = 49;
-                } else if ((rrc_sdu_length+msg4_header) <= 57) {
-                  ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->mcs=9;
-                  TBsize = 57;
-                }
-		((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->type=1;
-		((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type=0;
-		((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rv=0;
-		((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->harq_pid=0;
-		((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->TPC=1;
-		((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->padding=0;
-		((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc= mac_xface->computeRIV(N_RB_DL,first_rb,4);
-		rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-							 ((DCI1A_20MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-                break;
-              }
-            }
+
+	    if ((rrc_sdu_length+msg4_header) <= 22) {
+	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 4;
+	      TBsize = 22;
+	    } else if ((rrc_sdu_length+msg4_header) <= 28) {
+	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 5;
+	      TBsize = 28;
+	    } else if ((rrc_sdu_length+msg4_header) <= 32) {
+	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 6;
+	      TBsize = 32;
+	    } else if ((rrc_sdu_length+msg4_header) <= 41) {
+	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 7;
+	      TBsize = 41;
+	    } else if ((rrc_sdu_length+msg4_header) <= 49) {
+	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 8;
+	      TBsize = 49;
+	    } else if ((rrc_sdu_length+msg4_header) <= 57) {
+	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 9;
+	      TBsize = 57;
+	    }
+
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding= getRIV(N_RB_DL,first_rb,4);
 
 	    if (!CCE_allocation_infeasible(module_idP,CC_id,0,subframeP,2,RA_template->rnti)) {
-	      add_ue_spec_dci(DCI_pdu,
-			      (void*)&RA_template->RA_alloc_pdu2[0],
-			      RA_template->rnti,
-			      RA_template->RA_dci_size_bytes2,
-			      2,
-			      RA_template->RA_dci_size_bits2,
-			      RA_template->RA_dci_fmt2,
-			      0);
-	      
+	      eNB->DL_req[CC_id].number_dci++;
+	      eNB->DL_req[CC_id].number_pdu++;
+		      
 	      RA_template->generate_Msg4=0;
 	      RA_template->wait_ack_Msg4=1;
 	      RA_template->RA_active = FALSE;
 	      lcid=0;
-	      
+
+	      // set HARQ process 0 round to 0 for this UE
+	      UE_list->UE_sched_ctrl[UE_id].round[CC_id] = 0;
+
 	      if ((TBsize - rrc_sdu_length - msg4_header) <= 2) {
 		msg4_padding = TBsize - rrc_sdu_length - msg4_header;
 		msg4_post_padding = 0;
@@ -621,6 +264,7 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 	      LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d subframeP %d Msg4 : TBS %d, sdu_len %d, msg4_header %d, msg4_padding %d, msg4_post_padding %d\n",
 		    module_idP,CC_id,frameP,subframeP,TBsize,rrc_sdu_length,msg4_header,msg4_padding,msg4_post_padding);
 	      DevAssert( UE_id != UE_INDEX_INVALID ); // FIXME not sure how to gracefully return
+	      // CHECK THIS: &cc[CC_id].CCCH_pdu.payload[0]
 	      offset = generate_dlsch_header((unsigned char*)eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0],
 					     1,                           //num_sdus
 					     (unsigned short*)&rrc_sdu_length,             //
@@ -634,10 +278,20 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 	      memcpy((void*)&eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0][(unsigned char)offset],
 		     &cc[CC_id].CCCH_pdu.payload[0],
 		     rrc_sdu_length);
+
+	    // DL request
+	      
+	      TX_req                                                                = &eNB->TX_req[CC_id].tx_pdu_list[eNB->TX_req[CC_id].number_of_pdus]; 
+	      TX_req->pdu_length                                                    = rrc_sdu_length;
+	      TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
+	      TX_req->num_segments                                                  = 1;
+	      TX_req->segments[0].segment_length                                    = rrc_sdu_length;
+	      TX_req->segments[0].segment_data                                      = eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0];
+	      eNB->TX_req[CC_id].number_of_pdus++;
 	      
               T(T_ENB_MAC_UE_DL_PDU_WITH_DATA, T_INT(module_idP), T_INT(CC_id), T_INT(RA_template->rnti), T_INT(frameP), T_INT(subframeP),
                 T_INT(0 /*harq_pid always 0?*/), T_BUFFER(&eNB->UE_list.DLSCH_pdu[CC_id][0][UE_id].payload[0], TBsize));
-
+	      
 	      if (opt_enabled==1) {
 		trace_pdu(1, (uint8_t *)eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[0],
 			  rrc_sdu_length, UE_id, 3, UE_RNTI(module_idP, UE_id),
@@ -654,74 +308,82 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 
       } else if (RA_template->wait_ack_Msg4==1) {
 	// check HARQ status and retransmit if necessary
-	LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Checking if Msg4 was acknowledged: \n",
+	LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Checking if Msg4 was acknowledged: \tn",
 	      module_idP,CC_id,frameP,subframeP);
 	// Get candidate harq_pid from PHY
-	mac_xface->get_ue_active_harq_pid(module_idP,CC_id,RA_template->rnti,frameP,subframeP,&harq_pid,&round,openair_harq_RA);
-	
+
+	UE_id = find_UE_id(module_idP,RA_template->rnti);
+	AssertFatal(UE_id>=0,"Can't find UE for t-crnti\n");
+	round = UE_list->UE_sched_ctrl[UE_id].round[CC_id];
+
 	if (round>0) {
 	  //RA_template->wait_ack_Msg4++;
 	  // we have to schedule a retransmission
-	  if (cc[CC_id].tdd_Config!=NULL) { // TDD
-	    ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-	  } else {
-	    ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->ndi=1;
-	  }
 	  
-	  /*
-	  // randomize frequency allocation for RA
-	  while (1) {
-	    first_rb = (unsigned char)(taus()%(N_RB_DL-4));
-	    
-	    if ((vrb_map[first_rb] != 1) && (vrb_map[first_rb+3] != 1))
-	      break;
-	  }
-	  */
 	  first_rb=0;
 	  vrb_map[first_rb] = 1;
 	  vrb_map[first_rb+1] = 1;
 	  vrb_map[first_rb+2] = 1;
 	  vrb_map[first_rb+3] = 1;
+
+	  memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+	  dl_config_pdu->pdu_type                                                          = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
+	  dl_config_pdu->pdu_size                                                          = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                             = NFAPI_DL_DCI_FORMAT_1A;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level                      = 4;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                                   = RA_template->rnti;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                              = 1;    // C-RNTI : see Table 4-10 from SCF082 - nFAPI specifications
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power                     = 6000; // equal to RS power
+	  
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                           = 0;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                                    = 1; // no TPC
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1                   = 1;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1                   = 0;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.virtual_resource_block_assignment_flag = 0;
+	  
+	  // Compute MCS for 3 PRB
+	  msg4_header = 1+6+1;  // CR header, CR CE, SDU header
 	  
-	  if (cc[CC_id].tdd_Config!=NULL) {
-	    ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc = mac_xface->computeRIV(N_RB_UL,first_rb,4);
-	    rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-						     ((DCI1A_5MHz_TDD_1_6_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
-	  } else {
-	    ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc = mac_xface->computeRIV(N_RB_UL,first_rb,4);
-	    rballoc[CC_id] |= mac_xface->get_rballoc(((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->vrb_type,
-						     ((DCI1A_5MHz_FDD_t*)&RA_template->RA_alloc_pdu2[0])->rballoc);
+	  
+	  if ((rrc_sdu_length+msg4_header) <= 22) {
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 4;
+	    TBsize = 22;
+	  } else if ((rrc_sdu_length+msg4_header) <= 28) {
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 5;
+	    TBsize = 28;
+	  } else if ((rrc_sdu_length+msg4_header) <= 32) {
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 6;
+	    TBsize = 32;
+	  } else if ((rrc_sdu_length+msg4_header) <= 41) {
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 7;
+	    TBsize = 41;
+	  } else if ((rrc_sdu_length+msg4_header) <= 49) {
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 8;
+	    TBsize = 49;
+	  } else if ((rrc_sdu_length+msg4_header) <= 57) {
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = 9;
+	    TBsize = 57;
 	  }
 	  
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding= getRIV(N_RB_DL,first_rb,4);
+	  
 	  if (!CCE_allocation_infeasible(module_idP,CC_id,0,subframeP,2,RA_template->rnti)) {
-	    add_ue_spec_dci(DCI_pdu,
-			    (void*)&RA_template->RA_alloc_pdu2[0],
-			    RA_template->rnti,
-			    RA_template->RA_dci_size_bytes2,
-			    2,
-			    RA_template->RA_dci_size_bits2,
-			    RA_template->RA_dci_fmt2,
-			    0);
-printf("MAC: msg4 retransmission for rnti %x (round %d) fsf %d/%d\n", RA_template->rnti, round, frameP, subframeP);
+	    eNB->DL_req[CC_id].number_dci++;
+	    eNB->DL_req[CC_id].number_pdu++;
+		  
+	    LOG_I(MAC,"msg4 retransmission for rnti %x (round %d) fsf %d/%d\n", RA_template->rnti, round, frameP, subframeP);
 	  }
-else
-printf("MAC: msg4 retransmission for rnti %x (round %d) fsf %d/%d CCE allocation failed!\n", RA_template->rnti, round, frameP, subframeP);
+	  else
+	    LOG_I(MAC,"msg4 retransmission for rnti %x (round %d) fsf %d/%d CCE allocation failed!\n", RA_template->rnti, round, frameP, subframeP);
 	  LOG_W(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d: Msg4 not acknowledged, adding ue specific dci (rnti %x) for RA (Msg4 Retransmission)\n",
 		module_idP,CC_id,frameP,subframeP,RA_template->rnti);
 	} else {
-	  /*      msg4 not received
-		  if ((round == 0) && (RA_template->wait_ack_Msg4>1){
-		  remove UE instance across all the layers: mac_xface->cancel_RA();
-		  }
-	  */
-printf("MAC: msg4 acknowledged for rnti %x fsf %d/%d, let's configure it\n", RA_template->rnti, frameP, subframeP);
 	  LOG_I(MAC,"[eNB %d][RAPROC] CC_id %d Frame %d, subframeP %d : Msg4 acknowledged\n",module_idP,CC_id,frameP,subframeP);
 	  RA_template->wait_ack_Msg4=0;
 	  RA_template->RA_active=FALSE;
 	  UE_id = find_UE_id(module_idP,RA_template->rnti);
 	  DevAssert( UE_id != -1 );
 	  eNB->UE_list.UE_template[UE_PCCID(module_idP,UE_id)][UE_id].configured=TRUE;
-	  
 	}
       }
     } // for i=0 .. N_RA_PROC-1 
@@ -730,6 +392,7 @@ printf("MAC: msg4 acknowledged for rnti %x fsf %d/%d, let's configure it\n", RA_
   stop_meas(&eNB->schedule_ra);
 }
 
+// handles the event of MSG1 reception
 void initiate_ra_proc(module_id_t module_idP, int CC_id,frame_t frameP, uint16_t preamble_index,int16_t timing_offset,uint8_t sect_id,sub_frame_t subframeP,
                       uint8_t f_id)
 {
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
index 456b8c13b91df731f5b593a06070d41083f83f03..6f0b277e4ecc3c0955c8a115e7b07118a392859d 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_bch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
@@ -59,6 +59,9 @@
 #define DEBUG_eNB_SCHEDULER 1
 
 
+// NEED TO ADD schedule_SI_BR for SIB1_BR and SIB23_BR
+// CCE_allocation_infeasible to be done for EPDCCH/MPDCCH
+
 //------------------------------------------------------------------------------
 void
 schedule_SI(
@@ -69,26 +72,22 @@ schedule_SI(
 //------------------------------------------------------------------------------
 {
 
-  int8_t            bcch_sdu_length;
-  int               mcs = -1;
-  void              *BCCH_alloc_pdu;
-  int               CC_id;
-  eNB_MAC_INST      *eNB = RC.mac[module_idP];
-  uint8_t           *vrb_map;
-  int               first_rb = -1;
-  int               rballoc[MAX_NUM_CCs];
-  int               sizeof1A_bytes;
-  int               sizeof1A_bits = -1;
-  DCI_PDU           *DCI_pdu;
-  COMMON_channels_t *cc;
-  int               N_RB_DL;
+  int8_t                         bcch_sdu_length;
+  int                            mcs = -1;
+  int                            CC_id;
+  eNB_MAC_INST                   *eNB = RC.mac[module_idP];
+  COMMON_channels_t              *cc;
+  uint8_t                        *vrb_map;
+  int                            first_rb = -1;
+  int                            N_RB_DL;
+  nfapi_dl_config_request_pdu_t  *dl_config_pdu;
+  nfapi_tx_request_pdu_t         *TX_req;
+
   start_meas(&eNB->schedule_si);
 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
 
     cc              = &eNB->common_channels[CC_id];
-    BCCH_alloc_pdu  = (void*)&cc->BCCH_alloc_pdu;
-    DCI_pdu         = (void*)&cc->DCI_pdu;
     vrb_map         = (void*)&cc->vrb_map;
     N_RB_DL         = to_prb(cc->mib->message.dl_Bandwidth);
 
@@ -138,169 +137,86 @@ schedule_SI(
       vrb_map[first_rb+2] = 1;
       vrb_map[first_rb+3] = 1;
 
-      // Get MCS for length of SI
-      if (bcch_sdu_length <= (mac_xface->get_TBS_DL(0,3))) {
+      // Get MCS for length of SI, 3 PRBs
+      if (bcch_sdu_length <= 7) {
         mcs=0;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(1,3))) {
+      } else if (bcch_sdu_length <= 11) {
         mcs=1;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(2,3))) {
+      } else if (bcch_sdu_length <= 18) {
         mcs=2;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(3,3))) {
+      } else if (bcch_sdu_length <= 22) {
         mcs=3;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(4,3))) {
+      } else if (bcch_sdu_length <= 26) {
         mcs=4;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(5,3))) {
+      } else if (bcch_sdu_length <= 28) {
         mcs=5;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(6,3))) {
+      } else if (bcch_sdu_length <= 32) {
         mcs=6;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(7,3))) {
+      } else if (bcch_sdu_length <= 41) {
         mcs=7;
-      } else if (bcch_sdu_length <= (mac_xface->get_TBS_DL(8,3))) {
+      } else if (bcch_sdu_length <= 49) {
         mcs=8;
       }
-
-
-
-      if (cc->tdd_Config!=NULL) { // TDD
-        switch (N_RB_DL) {
-        case 6:
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0;
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_1_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc);
-	  sizeof1A_bytes = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-	  sizeof1A_bits = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-          break;
-
-        case 25:
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0;
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_5MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc);
-	  sizeof1A_bytes = sizeof(DCI1A_5MHz_TDD_1_6_t);
-	  sizeof1A_bits = sizeof_DCI1A_5MHz_TDD_1_6_t;
-	  break;
-
-        case 50:
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0;
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_10MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc);
-	  sizeof1A_bytes = sizeof(DCI1A_10MHz_TDD_1_6_t);
-	  sizeof1A_bits = sizeof_DCI1A_10MHz_TDD_1_6_t;
-          break;
-
-        case 100:
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->padding = 0;
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_20MHz_TDD_1_6_t*)BCCH_alloc_pdu)->rballoc);
-	  sizeof1A_bytes = sizeof(DCI1A_20MHz_TDD_1_6_t);
-	  sizeof1A_bits = sizeof_DCI1A_20MHz_TDD_1_6_t; 
-         break;
-        }
-
-      } else {
-        switch (N_RB_DL) {
-        case 6:
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0;
-
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_1_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc);
-	  sizeof1A_bytes = sizeof(DCI1A_1_5MHz_FDD_t);
-	  sizeof1A_bits = sizeof_DCI1A_1_5MHz_FDD_t;
-          break;
-
-        case 25:
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0;
-
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_5MHz_FDD_t*)BCCH_alloc_pdu)->rballoc);
-	  sizeof1A_bytes = sizeof(DCI1A_5MHz_FDD_t);
-	  sizeof1A_bits = sizeof_DCI1A_5MHz_FDD_t;
-          break;
-
-        case 50:
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0;
-
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_10MHz_FDD_t*)BCCH_alloc_pdu)->rballoc);
-	  sizeof1A_bytes = sizeof(DCI1A_10MHz_FDD_t);
-	  sizeof1A_bits = sizeof_DCI1A_10MHz_FDD_t;
-          break;
-
-        case 100:
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->mcs = mcs;
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rballoc = mac_xface->computeRIV(N_RB_DL,first_rb,4);
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->type = 1;
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->vrb_type = 0;
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->ndi = 1;
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rv = 1;
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->harq_pid = 0;
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->TPC = 1;
-          ((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->padding = 0;
-
-          rballoc[CC_id] |= mac_xface->get_rballoc(0,((DCI1A_20MHz_FDD_t*)BCCH_alloc_pdu)->rballoc);
- 	  sizeof1A_bytes = sizeof(DCI1A_20MHz_FDD_t);
-	  sizeof1A_bits = sizeof_DCI1A_20MHz_FDD_t;
-	  break;
-
-        }
-      }
+      dl_config_pdu                                                         = &eNB->DL_req[CC_id].dl_config_pdu_list[eNB->DL_req[CC_id].number_pdu]; 
+      memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+      dl_config_pdu->pdu_type                                               = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
+      dl_config_pdu->pdu_size                                               = (uint8_t)(2+sizeof(nfapi_dl_config_dci_dl_pdu));
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                  = NFAPI_DL_DCI_FORMAT_1A;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level           = 4;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                        = 0xFFFF;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                   = 2;    // S-RNTI : see Table 4-10 from SCF082 - nFAPI specifications
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power          = 6000; // equal to RS power
+      
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                = 0;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                         = 1; // no TPC
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1        = 1;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = mcs;
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1        = 0;
+
+      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding       = getRIV(N_RB_DL,first_rb,4);      
 
       if (!CCE_allocation_infeasible(module_idP,CC_id,1,subframeP,2,SI_RNTI)) {
-	add_common_dci(DCI_pdu,
-		       BCCH_alloc_pdu,
-		       SI_RNTI,
-		       sizeof1A_bytes,
-		       2,
-		       sizeof1A_bits,
-		       format1A,0);
+	LOG_I(MAC,"Frame %d: Subframe %d : Adding common DCI for S_RNTI\n",
+	      frameP,subframeP);
+	eNB->DL_req[CC_id].number_dci++;
+	eNB->DL_req[CC_id].number_pdu++;
+	dl_config_pdu                                                                  = &eNB->DL_req[CC_id].dl_config_pdu_list[eNB->DL_req[CC_id].number_pdu]; 
+	memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+	dl_config_pdu->pdu_type                                                        = NFAPI_DL_CONFIG_DLSCH_PDU_TYPE; 
+	dl_config_pdu->pdu_size                                                        = (uint8_t)(2+sizeof(nfapi_dl_config_dlsch_pdu));
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pdu_index                              = eNB->pdu_index[CC_id];
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.rnti                                   = 0xFFFF;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_allocation_type               = 2;   // format 1A/1B/1D
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.virtual_resource_block_assignment_flag = 0;   // localized
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.resource_block_coding                  = getRIV(N_RB_DL,first_rb,4);
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.modulation                             = 2; //QPSK
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.redundancy_version                     = 0;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_blocks                       = 1;// first block
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transport_block_to_codeword_swap_flag  = 0;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_scheme                    = (cc->p_eNB==1 ) ? 0 : 1;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_layers                       = 1;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.number_of_subbands                     = 1;
+	//	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.codebook_index                         = ;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ue_category_capacity                   = 1;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.pa                                     = 4; // 0 dB
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.delta_power_offset_index               = 0;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.ngap                                   = 0;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.nprb                                   = get_subbandsize(cc->mib->message.dl_Bandwidth); // ignored
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.transmission_mode                      = (cc->p_eNB==1 ) ? 1 : 2;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_prb_per_subband                 = 1;
+	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.num_bf_vector                          = 1;
+	//	dl_config_pdu->dlsch_pdu.dlsch_pdu_rel8.bf_vector                    = ; 
+	eNB->DL_req[CC_id].number_pdu++;
+
+	// Program TX Request
+	TX_req                                                                = &eNB->TX_req[CC_id].tx_pdu_list[eNB->TX_req[CC_id].number_of_pdus]; 
+	TX_req->pdu_length                                                    = bcch_sdu_length;
+	TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
+	TX_req->num_segments                                                  = 1;
+	TX_req->segments[0].segment_length                                    = bcch_sdu_length;
+	TX_req->segments[0].segment_data                                      = cc->BCCH_pdu.payload;
+	eNB->TX_req[CC_id].number_of_pdus++;
+
       }
       else {
 	LOG_E(MAC,"[eNB %d] CCid %d Frame %d, subframe %d : Cannot add DCI 1A for SI\n",module_idP, CC_id,frameP,subframeP);
@@ -321,19 +237,17 @@ schedule_SI(
 	    module_idP, frameP, CC_id, 0xffff, bcch_sdu_length);
       }
       if (cc->tdd_Config!=NULL) { //TDD
-        LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (TDD) for CC_id %d SI %d bytes (mcs %d, rb 3, TBS %d)\n",
+        LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (TDD) for CC_id %d SI %d bytes (mcs %d, rb 3)\n",
               frameP,
               CC_id,
               bcch_sdu_length,
-              mcs,
-              mac_xface->get_TBS_DL(mcs,3));
+              mcs);
       } else {
-        LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (FDD) for CC_id %d SI %d bytes (mcs %d, rb 3, TBS %d)\n",
+        LOG_D(MAC,"[eNB] Frame %d : Scheduling BCCH->DLSCH (FDD) for CC_id %d SI %d bytes (mcs %d, rb 3)\n",
               frameP,
               CC_id,
               bcch_sdu_length,
-              mcs,
-              mac_xface->get_TBS_DL(mcs,3));
+              mcs);
       }
 
 
@@ -351,3 +265,64 @@ schedule_SI(
   stop_meas(&eNB->schedule_si);
   return;
 }
+
+void schedule_mib(module_id_t   module_idP,
+		  frame_t       frameP,
+		  sub_frame_t   subframeP) {
+
+  eNB_MAC_INST                   *eNB = RC.mac[module_idP];
+  COMMON_channels_t              *cc;
+  nfapi_dl_config_request_pdu_t  *dl_config_pdu;
+  nfapi_tx_request_pdu_t         *TX_req;
+  int mib_sdu_length;
+  int CC_id;
+
+  AssertFatal(subframeP==0,"Subframe must be 0\n");
+  AssertFatal((frameP&3)==0,"Frame must be a multiple of 4\n");
+
+  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
+
+    cc              = &eNB->common_channels[CC_id];
+
+    mib_sdu_length = mac_rrc_data_req(module_idP,
+				      CC_id,
+				      frameP,
+				      MIBCH,1,
+				      &cc->MIB_pdu.payload[0],
+				      1,
+				      module_idP,
+				      0); // not used in this case
+
+    LOG_I(MAC,"Frame %d, subframe %d: BCH PDU length %d\n",
+	  frameP,subframeP,mib_sdu_length);
+
+    if (mib_sdu_length > 0) {
+
+      LOG_I(MAC,"Frame %d, subframe %d: Adding BCH PDU in position %d (length %d)\n",
+	    frameP,subframeP,eNB->DL_req[CC_id].number_pdu,mib_sdu_length);
+
+      dl_config_pdu                                                         = &eNB->DL_req[CC_id].dl_config_pdu_list[eNB->DL_req[CC_id].number_pdu]; 
+      memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+      dl_config_pdu->pdu_type                                               = NFAPI_DL_CONFIG_BCH_PDU_TYPE,
+      dl_config_pdu->pdu_size                                               = 2+sizeof(nfapi_dl_config_bch_pdu);
+      dl_config_pdu->bch_pdu.bch_pdu_rel8.length                            = mib_sdu_length;
+      dl_config_pdu->bch_pdu.bch_pdu_rel8.pdu_index                         = eNB->pdu_index[CC_id];
+      dl_config_pdu->bch_pdu.bch_pdu_rel8.transmission_power                = 6000;
+      eNB->DL_req[CC_id].number_pdu++;
+
+      LOG_I(MAC,"eNB->DL_req[0].number_pdu %d (%p)\n",
+	    eNB->DL_req[CC_id].number_pdu,&eNB->DL_req[CC_id].number_pdu);
+      // DL request
+
+      TX_req                                                                = &eNB->TX_req[CC_id].tx_pdu_list[eNB->TX_req[CC_id].number_of_pdus]; 
+      TX_req->pdu_length                                                    = 3;
+      TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
+      TX_req->num_segments                                                  = 1;
+      TX_req->segments[0].segment_length                                    = 0;
+      TX_req->segments[0].segment_data                                      = cc[CC_id].MIB_pdu.payload;
+      eNB->TX_req[CC_id].number_of_pdus++;
+    }
+  }
+}
+
+ 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
index a5409764f902066f6730fe0a637c65b7fac5946d..657ae108ee067ff24bdf09c92e0386362b6fd032 100755
--- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
@@ -409,6 +409,8 @@ set_ul_DAI(
 }
 
 
+// changes to pre-processor for eMTC
+
 //------------------------------------------------------------------------------
 void
 schedule_ue_spec(
@@ -420,37 +422,38 @@ schedule_ue_spec(
 //------------------------------------------------------------------------------
 {
 
-  uint8_t               CC_id;
-  int                   UE_id;
-  unsigned char         aggregation;
-  mac_rlc_status_resp_t rlc_status;
-  unsigned char         header_len_dcch=0, header_len_dcch_tmp=0; 
-  unsigned char         header_len_dtch=0, header_len_dtch_tmp=0, header_len_dtch_last=0; 
-  unsigned char         ta_len=0;
-  unsigned char         sdu_lcids[NB_RB_MAX],lcid,offset,num_sdus=0;
-  uint16_t              nb_rb,nb_rb_temp,nb_available_rb;
-  uint16_t              TBS,j,sdu_lengths[NB_RB_MAX],rnti,padding=0,post_padding=0;
-  unsigned char         dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES];
-  unsigned char         round             = 0;
-  unsigned char         harq_pid          = 0;
-  void                  *DLSCH_dci        = NULL;
-  LTE_eNB_UE_stats      *eNB_UE_stats     = NULL;
-  uint16_t              sdu_length_total = 0;
-  int                   mcs; 
-
-  eNB_MAC_INST          *eNB      = RC.mac[module_idP];
-  COMMON_channels_t     *cc       = eNB->common_channels;
-  UE_list_t             *UE_list  = &eNB->UE_list;
-  int                   continue_flag=0;
-  int32_t               normalized_rx_power, target_rx_power;
-  int32_t               tpc=1;
-  static int32_t        tpc_accumulated=0;
-  UE_sched_ctrl         *ue_sched_ctl;
-  int                   i;
-  int                   min_rb_unit[MAX_NUM_CCs];
-  int                   N_RB_DL[MAX_NUM_CCs];
-  int                   total_nb_available_rb[MAX_NUM_CCs];
-  int                   N_RBG[MAX_NUM_CCs];
+  uint8_t                        CC_id;
+  int                            UE_id;
+  unsigned char                  aggregation;
+  mac_rlc_status_resp_t          rlc_status;
+  unsigned char                  header_len_dcch=0, header_len_dcch_tmp=0; 
+  unsigned char                  header_len_dtch=0, header_len_dtch_tmp=0, header_len_dtch_last=0; 
+  unsigned char                  ta_len=0;
+  unsigned char                  sdu_lcids[NB_RB_MAX],lcid,offset,num_sdus=0;
+  uint16_t                       nb_rb,nb_rb_temp,nb_available_rb;
+  uint16_t                       TBS,j,sdu_lengths[NB_RB_MAX],rnti,padding=0,post_padding=0;
+  unsigned char                  dlsch_buffer[MAX_DLSCH_PAYLOAD_BYTES];
+  unsigned char                  round             = 0;
+  unsigned char                  harq_pid          = 0;
+  eNB_UE_STATS                   *eNB_UE_stats     = NULL;
+  uint16_t                       sdu_length_total = 0;
+
+  eNB_MAC_INST                   *eNB      = RC.mac[module_idP];
+  COMMON_channels_t              *cc       = eNB->common_channels;
+  UE_list_t                      *UE_list  = &eNB->UE_list;
+  int                            continue_flag=0;
+  int32_t                        normalized_rx_power, target_rx_power;
+  int32_t                        tpc=1;
+  static int32_t                 tpc_accumulated=0;
+  UE_sched_ctrl                  *ue_sched_ctl;
+  int                            mcs;
+  int                            i;
+  int                            min_rb_unit[MAX_NUM_CCs];
+  int                            N_RB_DL[MAX_NUM_CCs];
+  int                            total_nb_available_rb[MAX_NUM_CCs];
+  int                            N_RBG[MAX_NUM_CCs];
+  nfapi_dl_config_request_pdu_t  *dl_config_pdu;
+  nfapi_tx_request_pdu_t         *TX_req;
 
 #if 0
   if (UE_list->head==-1) {
@@ -504,37 +507,36 @@ schedule_ue_spec(
     for (UE_id=UE_list->head; UE_id>=0; UE_id=UE_list->next[UE_id]) {
       continue_flag=0; // reset the flag to allow allocation for the remaining UEs
       rnti = UE_RNTI(module_idP,UE_id);
-      eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
+      eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
       ue_sched_ctl = &UE_list->UE_sched_ctrl[UE_id];
 
+
       if (rnti==NOT_A_RNTI) {
         LOG_D(MAC,"Cannot find rnti for UE_id %d (num_UEs %d)\n",UE_id,UE_list->num_UEs);
-        // mac_xface->macphy_exit("Cannot find rnti for UE_id");
         continue_flag=1;
       }
 
       if (eNB_UE_stats==NULL) {
         LOG_D(MAC,"[eNB] Cannot find eNB_UE_stats\n");
-        //  mac_xface->macphy_exit("[MAC][eNB] Cannot find eNB_UE_stats\n");
         continue_flag=1;
       }
 
       if (continue_flag != 1){
-        switch(mac_xface->get_transmission_mode(module_idP,CC_id,rnti)){
+        switch(get_tmode(module_idP,CC_id,UE_id)){
         case 1:
         case 2:
         case 7:
 	  aggregation = get_aggregation(get_bw_index(module_idP,CC_id), 
-				      eNB_UE_stats->DL_cqi[0],
-				      format1);
+					eNB_UE_stats->dl_cqi,
+					format1);
 	  break;
         case 3:
 	  aggregation = get_aggregation(get_bw_index(module_idP,CC_id), 
-				      eNB_UE_stats->DL_cqi[0],
-				      format2A);
+					eNB_UE_stats->dl_cqi,
+					format2A);
 	  break;
         default:
-	  LOG_W(MAC,"Unsupported transmission mode %d\n", mac_xface->get_transmission_mode(module_idP,CC_id,rnti));
+	  LOG_W(MAC,"Unsupported transmission mode %d\n", get_tmode(module_idP,CC_id,UE_id));
 	  aggregation = 2;
         }
       } /* if (continue_flag != 1 */
@@ -544,10 +546,7 @@ schedule_ue_spec(
 	  ) {
         LOG_D(MAC,"[eNB %d] Frame %d : no RB allocated for UE %d on CC_id %d: continue \n",
               module_idP, frameP, UE_id, CC_id);
-        //if(mac_xface->get_transmission_mode(module_idP,rnti)==5)
         continue_flag=1; //to next user (there might be rbs availiable for other UEs in TM5
-        // else
-        //  break;
       }
 
       if (cc[CC_id].tdd_Config != NULL) { //TDD
@@ -581,15 +580,15 @@ schedule_ue_spec(
       num_sdus=0;
 
       /*
-      DevCheck(((eNB_UE_stats->DL_cqi[0] < MIN_CQI_VALUE) || (eNB_UE_stats->DL_cqi[0] > MAX_CQI_VALUE)),
-      eNB_UE_stats->DL_cqi[0], MIN_CQI_VALUE, MAX_CQI_VALUE);
+      DevCheck(((eNB_UE_stats->dl_cqi < MIN_CQI_VALUE) || (eNB_UE_stats->dl_cqi > MAX_CQI_VALUE)),
+      eNB_UE_stats->dl_cqi, MIN_CQI_VALUE, MAX_CQI_VALUE);
       */
-      eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[eNB_UE_stats->DL_cqi[0]];
+      eNB_UE_stats->dlsch_mcs1 = cqi_to_mcs[eNB_UE_stats->dl_cqi];
       eNB_UE_stats->dlsch_mcs1 = eNB_UE_stats->dlsch_mcs1;//cmin(eNB_UE_stats->dlsch_mcs1, openair_daq_vars.target_ue_dl_mcs);
 
 
       // store stats
-      UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi= eNB_UE_stats->DL_cqi[0];
+      UE_list->eNB_UE_stats[CC_id][UE_id].dl_cqi= eNB_UE_stats->dl_cqi;
 
       // initializing the rb allocation indicator for each UE
       for(j=0; j<N_RBG[CC_id]; j++) {
@@ -598,19 +597,14 @@ schedule_ue_spec(
 
       LOG_D(MAC,"[eNB %d] Frame %d: Scheduling UE %d on CC_id %d (rnti %x, harq_pid %d, round %d, rb %d, cqi %d, mcs %d, rrc %d)\n",
             module_idP, frameP, UE_id,CC_id,rnti,harq_pid, round,nb_available_rb,
-            eNB_UE_stats->DL_cqi[0], eNB_UE_stats->dlsch_mcs1,
+            eNB_UE_stats->dl_cqi, eNB_UE_stats->dlsch_mcs1,
 	    UE_list->eNB_UE_stats[CC_id][UE_id].rrc_status);
 
 
-      // Note this code is for a specific DCI format
-      DLSCH_dci = (void *)UE_list->UE_template[CC_id][UE_id].DLSCH_DCI[harq_pid];
-
 
       /* process retransmission  */
 
       if (round > 0) {
-
-
         // get freq_allocation
         nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
 
@@ -656,159 +650,73 @@ schedule_ue_spec(
           }
 	  */
 
-          switch (mac_xface->get_transmission_mode(module_idP,CC_id,rnti)) {
+          switch (get_tmode(module_idP,CC_id,UE_id)) {
           case 1:
           case 2:
           case 7:
           default:
-            switch (N_RB_DL[CC_id]) {
-            case 6:
-              if (cc[CC_id].tdd_Config != NULL) { //TDD
-                //        ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rv       = round&3;
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,(UE_list->UE_template[CC_id][UE_id].DAI-1),
-                      ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->mcs);
-              } else {
-                //        ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rv       = round&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->mcs);
-
-              }
-
-              break;
-
-            case 25:
-              if (cc[CC_id].tdd_Config != NULL) { //TDD
-                //        ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv       = round&3;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,(UE_list->UE_template[CC_id][UE_id].DAI-1),
-                      ((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs);
-              } else {
-                //        ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv       = round&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs);
-
-              }
-
-              break;
-
-            case 50:
-              if (cc[CC_id].tdd_Config != NULL) { //TDD
-                //        ((DCI1_10MHz_TDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rv       = round&3;
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,(UE_list->UE_template[CC_id][UE_id].DAI-1),
-                      ((DCI1_10MHz_TDD_t*)DLSCH_dci)->mcs);
-              } else {
-                //        ((DCI1_10MHz_FDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_10MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rv       = round&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,((DCI1_10MHz_FDD_t*)DLSCH_dci)->mcs);
-
-              }
-
-              break;
-
-            case 100:
-              if (cc[CC_id].tdd_Config != NULL) { //TDD
-                //        ((DCI1_20MHz_TDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rv       = round&3;
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,(UE_list->UE_template[CC_id][UE_id].DAI-1),
-                      ((DCI1_20MHz_TDD_t*)DLSCH_dci)->mcs);
-              } else {
-                //        ((DCI1_20MHz_FDD_t*)DLSCH_dci)->ndi      = 0;
-                ((DCI1_20MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rv       = round&3;
-                LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
-                      module_idP,CC_id,harq_pid,round,((DCI1_20MHz_FDD_t*)DLSCH_dci)->mcs);
-
-              }
-
-              break;
-            }
-
-            break;
-	    /* 
-	    // this code is disabled for now - needs to be done properly
-          case 4:
-            //    if (nb_rb>10) {
-            ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 0;
-            ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-            ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->dai = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-            // }
-            //else {
-            //  ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->ndi1 = 0;
-            // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-            // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->rv1 = round&3;
-            // ((DCI2_5MHz_2A_L10PRB_TDD_t*)DLSCH_dci)->dai = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-            // }
-            break;
-
-          case 5:
-            // if(nb_rb>10){
-            //((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = eNB_UE_stats->DL_cqi[0]<<1;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 0;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-
-            if(ue_sched_ctl->dl_pow_off[CC_id] == 2) {
-              ue_sched_ctl->dl_pow_off[CC_id] = 1;
-            }
-
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = ue_sched_ctl->dl_pow_off[CC_id];
-            // }
-            break;
-
-          case 6:
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 0;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = 1;//dl_pow_off[UE_id];
-            break;
-	    */
-          }
+	    dl_config_pdu                                                         = &eNB->DL_req[CC_id].dl_config_pdu_list[eNB->DL_req[CC_id].number_pdu]; 
+	    memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+	    dl_config_pdu->pdu_type                                               = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
+	    dl_config_pdu->pdu_size                                               = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                  = NFAPI_DL_DCI_FORMAT_1;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level           = get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->dl_cqi,format1);
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                        = rnti;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                   = 1;    // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power          = 6000; // equal to RS power
+
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                = harq_pid;
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                         = 1; // dont adjust power when retransmitting
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1        = UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid];
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1        = round&3;
+
+	    if (cc[CC_id].tdd_Config != NULL) { //TDD
+	      dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
+	      LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
+		    module_idP,CC_id,harq_pid,round,
+		    (UE_list->UE_template[CC_id][UE_id].DAI-1),
+		    UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]);
+	    } else {
+	      LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
+		    module_idP,CC_id,harq_pid,round,
+		    UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid]);
+	      
+	    }
+	    if (!CCE_allocation_infeasible(module_idP,CC_id,0,subframeP,
+					   dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+					   rnti)) {
+	      eNB->DL_req[CC_id].number_dci++;
+	      eNB->DL_req[CC_id].number_pdu++;
 
-          add_ue_dlsch_info(module_idP,
-                            CC_id,
-                            UE_id,
-                            subframeP,
-                            S_DL_SCHEDULED);
+	    }
+	    else {
+	      // No TX request for retransmission (check if null request for FAPI)
+	    }
+	  }
 
-          //eNB_UE_stats->dlsch_trials[round]++;
-          UE_list->eNB_UE_stats[CC_id][UE_id].num_retransmission+=1;
-          UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx=nb_rb;
-          UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_retx+=nb_rb;
-          UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1;
-          UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2=eNB_UE_stats->dlsch_mcs1;
-        } else {
+	  add_ue_dlsch_info(module_idP,
+			    CC_id,
+			    UE_id,
+			    subframeP,
+			    S_DL_SCHEDULED);
+	  
+	  //eNB_UE_stats->dlsch_trials[round]++;
+	  UE_list->eNB_UE_stats[CC_id][UE_id].num_retransmission+=1;
+	  UE_list->eNB_UE_stats[CC_id][UE_id].rbs_used_retx=nb_rb;
+	  UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_retx+=nb_rb;
+	  UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs1=eNB_UE_stats->dlsch_mcs1;
+	  UE_list->eNB_UE_stats[CC_id][UE_id].dlsch_mcs2=eNB_UE_stats->dlsch_mcs1;
+	} else {
           LOG_D(MAC,"[eNB %d] Frame %d CC_id %d : don't schedule UE %d, its retransmission takes more resources than we have\n",
                 module_idP, frameP, CC_id, UE_id);
         }
       } else { /* This is a potentially new SDU opportunity */
-
+	
         rlc_status.bytes_in_buffer = 0;
         // Now check RLC information to compute number of required RBs
         // get maximum TBS size for RLC request
-        //TBS = mac_xface->get_TBS(eNB_UE_stats->DL_cqi[0]<<1,nb_available_rb);
-        TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb);
+        TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb);
         // check first for RLC data on DCCH
         // add the length for  all the control elements (timing adv, drx, etc) : header + payload
 
@@ -822,7 +730,7 @@ schedule_ue_spec(
                          rnti,
 			 module_idP,
                          frameP,
-						 subframeP,
+			 subframeP,
                          ENB_FLAG_YES,
                          MBMS_FLAG_NO,
                          DCCH,
@@ -1006,19 +914,19 @@ schedule_ue_spec(
             nb_rb=min_rb_unit[CC_id];
           }
 
-          TBS = mac_xface->get_TBS_DL(mcs,nb_rb);
+          TBS = get_TBS_DL(mcs,nb_rb);
 
           while (TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len))  {
             nb_rb += min_rb_unit[CC_id];  //
 
             if (nb_rb>nb_available_rb) { // if we've gone beyond the maximum number of RBs
               // (can happen if N_RB_DL is odd)
-              TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb);
+              TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_available_rb);
               nb_rb = nb_available_rb;
               break;
             }
 
-            TBS = mac_xface->get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_rb);
+            TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_rb);
           }
 
           if(nb_rb == ue_sched_ctl->pre_nb_available_rbs[CC_id]) {
@@ -1057,14 +965,14 @@ schedule_ue_spec(
           // decrease mcs until TBS falls below required length
           while ((TBS > (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && (mcs>0)) {
             mcs--;
-            TBS = mac_xface->get_TBS_DL(mcs,nb_rb);
+            TBS = get_TBS_DL(mcs,nb_rb);
           }
 
           // if we have decreased too much or we don't have enough RBs, increase MCS
           while ((TBS < (sdu_length_total + header_len_dcch + header_len_dtch + ta_len)) && ((( ue_sched_ctl->dl_pow_off[CC_id]>0) && (mcs<28))
                  || ( (ue_sched_ctl->dl_pow_off[CC_id]==0) && (mcs<=15)))) {
             mcs++;
-            TBS = mac_xface->get_TBS_DL(mcs,nb_rb);
+            TBS = get_TBS_DL(mcs,nb_rb);
           }
 
           LOG_D(MAC,"dlsch_mcs before and after the rate matching = (%d, %d)\n",eNB_UE_stats->dlsch_mcs1, mcs);
@@ -1170,9 +1078,9 @@ schedule_ue_spec(
 
 	  // do PUCCH power control
           // this is the normalized RX power
-	  eNB_UE_stats =  mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
+	  eNB_UE_stats =  &UE_list->eNB_UE_stats[CC_id][UE_id];
 	  normalized_rx_power = eNB_UE_stats->Po_PUCCH_dBm; 
-	  target_rx_power = mac_xface->get_target_pucch_rx_power(module_idP,CC_id) + 20;
+	  target_rx_power = get_target_pucch_rx_power(module_idP,CC_id) + 20;
 	    
           // this assumes accumulated tpc
 	  // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
@@ -1207,430 +1115,55 @@ schedule_ue_spec(
 	    tpc = 1; //0
 	  }
 
-          switch (mac_xface->get_transmission_mode(module_idP,CC_id,rnti)) {
-          case 1:
-          case 2:
-          default:
-            if (cc[CC_id].tdd_Config != NULL) {//TDD
-              switch (N_RB_DL[CC_id]) {
-              case 6:
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->TPC = tpc;
-                ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                break;
-
-              case 25:
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->TPC = tpc;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                LOG_D(MAC,"Format1 DCI: harq_pid %d, ndi %d\n",harq_pid,((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi);
-                break;
-
-              case 50:
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->TPC = tpc;
-                ((DCI1_10MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                break;
-
-              case 100:
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->TPC = tpc;
-                ((DCI1_20MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                break;
-
-              default:
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->TPC = tpc;
-                ((DCI1_5MHz_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                break;
-              }
-            } else {
-              switch (N_RB_DL[CC_id]) {
-              case 6:
-                ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->TPC = tpc;
-                break;
-
-              case 25:
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->TPC = tpc;
-                break;
-
-              case 50:
-                ((DCI1_10MHz_FDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_10MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_10MHz_FDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_10MHz_FDD_t*)DLSCH_dci)->TPC = tpc;
-                break;
-
-              case 100:
-                ((DCI1_20MHz_FDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_20MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_20MHz_FDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_20MHz_FDD_t*)DLSCH_dci)->TPC = tpc;
-                break;
-
-              default:
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->mcs = mcs;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->ndi = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rv = 0;
-                ((DCI1_5MHz_FDD_t*)DLSCH_dci)->TPC = tpc;
-                break;
-              }
-            }
-
-            break;
-
-          case 3:
-            if (cc[CC_id].tdd_Config!=NULL) {
-              switch (N_RB_DL[CC_id]) {
-              case 6:
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-
-                // deactivate TB2
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->TPC      = tpc;
-                break;
-
-              case 25:
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-		((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-
-                LOG_D(MAC,"Format1 DCI: harq_pid %d, ndi %d\n",harq_pid,((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1);
-                break;
-
-              case 50:
-                ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-		((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              case 100:
-                ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-		((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              default:
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-		((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-              }
-            } else {
-              switch (N_RB_DL[CC_id]) {
-              case 6:
-                ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-		((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              case 25:
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-		((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              case 50:
-                ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-		((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-                // deactivate TB2
-                ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              case 100:
-                ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-		((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              default:
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-		((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-              }
-            }
-
-            break;
-
-	    /*
-	    // disabled for now as this needs to be done properly
-          case 4:
-            if (frame_parms[CC_id]->frame_type == TDD) {
-              switch (frame_parms[CC_id]->N_RB_DL) {
-              case 6:
-                // fall back to alamouti for now
-                ((DCI2_1_5MHz_2A_TDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_1_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_1_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_1_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_1_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-
-                // deactivate TB2
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->TPC      = tpc;
-                break;
-
-              case 25:
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->tpmi = 0;
-            ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-            ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-
-                LOG_D(MAC,"Format2 DCI: harq_pid %d, ndi %d\n",harq_pid,((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1);
-                break;
-
-              case 50:
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_10MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              case 100:
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->dai      = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_20MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              default:
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rv1 = 0;
-            ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->dai = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-	    ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-
-                // deactivate TB2
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-              }
-            } else {
-              switch (frame_parms[CC_id]->N_RB_DL) {
-              case 6:
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_1_5MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-            break;
-
-              case 25:
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-
-                LOG_I(MAC,"Format2 DCI: harq_pid %d, ndi %d\n",harq_pid,((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->ndi1);
-                break;
-
-              case 50:
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-                // deactivate TB2
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_10MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              case 100:
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_20MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-
-              default:
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->tpmi = 0;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->mcs1 = mcs;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->ndi1 = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->rv1 = 0;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->TPC = tpc;
-
-                // deactivate TB2
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->mcs2 = 0;
-                ((DCI2_5MHz_2A_FDD_t*)DLSCH_dci)->rv2 = 1;
-                break;
-              }
-            }
-
-            break;
-            */
-            /*
-            // disabled for now as this needs to be done properly
-          case 5:
-
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = mcs;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 1;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-	    ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-            if(ue_sched_ctl->dl_pow_off[CC_id] == 2) {
-              ue_sched_ctl->dl_pow_off[CC_id] = 1;
-            }
-
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = ue_sched_ctl->dl_pow_off[CC_id];
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->tpmi = 5;
-            break;
-
-          case 6:
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->mcs = mcs;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->harq_pid = harq_pid;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->ndi = 1;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rv = round&3;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dai = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->dl_power_off = 1;
-            ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->tpmi = 5;
-	    ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->TPC = tpc;
-
-            break;
-	    */
-          }
+	  dl_config_pdu                                                         = &eNB->DL_req[CC_id].dl_config_pdu_list[eNB->DL_req[CC_id].number_pdu]; 
+	  memset((void*)dl_config_pdu,0,sizeof(nfapi_dl_config_request_pdu_t));
+	  dl_config_pdu->pdu_type                                               = NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE; 
+	  dl_config_pdu->pdu_size                                               = 2+sizeof(nfapi_dl_config_dci_dl_pdu);
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.dci_format                  = NFAPI_DL_DCI_FORMAT_1;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level           = get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->dl_cqi,format1);
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti                        = rnti;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti_type                   = 1;    // CRNTI : see Table 4-10 from SCF082 - nFAPI specifications
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.transmission_power          = 6000; // equal to RS power
+	  
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.harq_process                = harq_pid;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.tpc                         = tpc; // dont adjust power when retransmitting
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.new_data_indicator_1        = 1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_1                       = mcs;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_1        = 0;
+	  //deactivate second codeword
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.mcs_2                       = 0;
+	  dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.redundancy_version_2        = 1;
+	  if (cc[CC_id].tdd_Config != NULL) { //TDD
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.downlink_assignment_index = (UE_list->UE_template[CC_id][UE_id].DAI-1)&3;
+	    LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, dai %d, mcs %d\n",
+		  module_idP,CC_id,harq_pid,round,
+		  (UE_list->UE_template[CC_id][UE_id].DAI-1),
+		  mcs);
+	  } else {
+	    LOG_D(MAC,"[eNB %d] Retransmission CC_id %d : harq_pid %d, round %d, mcs %d\n",
+		  module_idP,CC_id,harq_pid,round,mcs);
+	    
+	  }
+	  eNB->DL_req[CC_id].number_dci++;
+	  eNB->DL_req[CC_id].number_pdu++;
 
           // Toggle NDI for next time
           LOG_D(MAC,"CC_id %d Frame %d, subframeP %d: Toggling Format1 NDI for UE %d (rnti %x/%d) oldNDI %d\n",
                 CC_id, frameP,subframeP,UE_id,
                 UE_list->UE_template[CC_id][UE_id].rnti,harq_pid,UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]);
-          UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]=1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
+          
+	  UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid]=1-UE_list->UE_template[CC_id][UE_id].oldNDI[harq_pid];
+	  UE_list->UE_template[CC_id][UE_id].oldmcs1[harq_pid] = mcs;
+	  UE_list->UE_template[CC_id][UE_id].oldmcs2[harq_pid] = 0;
+
+	  TX_req                                                                = &eNB->TX_req[CC_id].tx_pdu_list[eNB->TX_req[CC_id].number_of_pdus]; 
+	  TX_req->pdu_length                                                    = TBS;
+	  TX_req->pdu_index                                                     = eNB->pdu_index[CC_id]++;
+	  TX_req->num_segments                                                  = 1;
+	  TX_req->segments[0].segment_length                                    = TBS;
+	  TX_req->segments[0].segment_data                                      = eNB->UE_list.DLSCH_pdu[CC_id][0][(unsigned char)UE_id].payload[harq_pid];
+	  eNB->TX_req[CC_id].number_of_pdus++;
+
         } else {  // There is no data from RLC or MAC header, so don't schedule
 
         }
@@ -1670,17 +1203,14 @@ fill_DLSCH_dci(
 
   //unsigned char round;
   unsigned char     harq_pid;
-  void              *DLSCH_dci=NULL;
-  DCI_PDU           *DCI_pdu;
   int               i;
-  int               size_bits,size_bytes;
   int               CC_id;
   eNB_MAC_INST      *eNB  =RC.mac[module_idP];
   UE_list_t         *UE_list = &eNB->UE_list;
-  LTE_eNB_UE_stats  *eNB_UE_stats   = NULL;
   int               N_RBG;
   int               N_RB_DL;
   COMMON_channels_t *cc;
+  eNB_UE_STATS      *eNB_UE_stats;
 
   start_meas(&eNB->fill_DLSCH_dci);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_FILL_DLSCH_DCI,VCD_FUNCTION_IN);
@@ -1692,7 +1222,6 @@ fill_DLSCH_dci(
       continue;
 
     cc              = &eNB->common_channels[CC_id];
-    DCI_pdu         = &cc->DCI_pdu;
     N_RBG           = to_rbg(cc->mib->message.dl_Bandwidth);
     N_RB_DL         = to_prb(cc->mib->message.dl_Bandwidth);
 
@@ -1705,261 +1234,29 @@ fill_DLSCH_dci(
         // clear scheduling flag
         eNB_dlsch_info[module_idP][CC_id][UE_id].status = S_DL_WAITING;
         rnti = UE_RNTI(module_idP,UE_id);
-	//        mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,0);
 	harq_pid = UE_list->UE_sched_ctrl[UE_id].harq_pid[CC_id];
         nb_rb = UE_list->UE_template[CC_id][UE_id].nb_rb[harq_pid];
 
-        DLSCH_dci = (void *)UE_list->UE_template[CC_id][UE_id].DLSCH_DCI[harq_pid];
-	eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
-
+	eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id]; 
 
+	
         /// Synchronizing rballoc with rballoc_sub
         for(i=0; i<N_RBG; i++) {
           rballoc_sub[i] = UE_list->UE_template[CC_id][UE_id].rballoc_subband[harq_pid][i];
         }
 
-        switch(mac_xface->get_transmission_mode(module_idP,CC_id,rnti)) {
-        default:
-
-        case 1:
-
-        case 2:
-
-        case 7:
-          LOG_D(MAC,"[eNB %d] CC_id %d Adding UE %d spec DCI for %d PRBS \n",module_idP, CC_id, UE_id, nb_rb);
-
-          if (cc->tdd_Config != NULL) { //TDD
-            switch (N_RB_DL) {
-            case 6:
-              ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_1_5MHz_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI1_1_5MHz_TDD_t);
-              size_bits  = sizeof_DCI1_1_5MHz_TDD_t;
-              break;
-
-            case 25:
-              ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI1_5MHz_TDD_t);
-              size_bits  = sizeof_DCI1_5MHz_TDD_t;
-              break;
-
-            case 50:
-              ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_10MHz_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI1_10MHz_TDD_t);
-              size_bits  = sizeof_DCI1_10MHz_TDD_t;
-              break;
-
-            case 100:
-              ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_20MHz_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI1_20MHz_TDD_t);
-              size_bits  = sizeof_DCI1_20MHz_TDD_t;
-              break;
-
-            default:
-              ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_5MHz_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI1_5MHz_TDD_t);
-              size_bits  = sizeof_DCI1_5MHz_TDD_t;
-              break;
-            }
-
-
-          } else {
-            switch (N_RB_DL) {
-            case 6:
-              ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_1_5MHz_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI1_1_5MHz_FDD_t);
-              size_bits=sizeof_DCI1_1_5MHz_FDD_t;
-              break;
-
-            case 25:
-              ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI1_5MHz_FDD_t);
-              size_bits=sizeof_DCI1_5MHz_FDD_t;
-              break;
-
-            case 50:
-              ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_10MHz_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI1_10MHz_FDD_t);
-              size_bits=sizeof_DCI1_10MHz_FDD_t;
-              break;
-
-            case 100:
-              ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_20MHz_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI1_20MHz_FDD_t);
-              size_bits=sizeof_DCI1_20MHz_FDD_t;
-              break;
-
-            default:
-              ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI1_5MHz_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI1_5MHz_FDD_t);
-              size_bits=sizeof_DCI1_5MHz_FDD_t;
-              break;
-            }
-          }
-
-          add_ue_spec_dci(DCI_pdu,
-                          DLSCH_dci,
-                          rnti,
-                          size_bytes,
-                          get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->DL_cqi[0],format1),
-                          size_bits,
-                          format1,
-                          0);
-
-          break;
+	nfapi_dl_config_request_body_t      *DL_req         = &RC.mac[module_idP]->DL_req[0];
+	nfapi_dl_config_request_pdu_t* dl_config_pdu;
 
-        case 3:
-          /* TODO: fix log, what is 'rb alloc'? */
-          /*LOG_D(MAC,"[eNB %d] CC_id %d Adding Format 2A UE %d spec DCI for %d PRBS (rb alloc: %x) \n",
-                module_idP, CC_id, UE_id, nb_rb);*/
-          LOG_D(MAC,"[eNB %d] CC_id %d Adding Format 2A UE %d spec DCI for %d PRBS\n",
-                module_idP, CC_id, UE_id, nb_rb);
-
-          if (cc[CC_id].tdd_Config != NULL) { //TDD
-            switch (N_RB_DL) {
-            case 6:
-              ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_1_5MHz_2A_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI2A_1_5MHz_2A_TDD_t);
-              size_bits  = sizeof_DCI2A_1_5MHz_2A_TDD_t;
-              break;
-
-            case 25:
-              ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI2A_5MHz_2A_TDD_t);
-              size_bits  = sizeof_DCI2A_5MHz_2A_TDD_t;
-              break;
-
-            case 50:
-              ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_10MHz_2A_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI2A_10MHz_2A_TDD_t);
-              size_bits  = sizeof_DCI2A_10MHz_2A_TDD_t;
-              break;
-
-            case 100:
-              ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_20MHz_2A_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI2A_20MHz_2A_TDD_t);
-              size_bits  = sizeof_DCI2A_20MHz_2A_TDD_t;
-              break;
-
-            default:
-              ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_5MHz_2A_TDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes = sizeof(DCI2A_5MHz_2A_TDD_t);
-              size_bits  = sizeof_DCI2A_5MHz_2A_TDD_t;
-              break;
-            }
-
-
-          } else {
-
-            switch (N_RB_DL) {
-            case 6:
-              ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_1_5MHz_2A_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI2A_1_5MHz_2A_FDD_t);
-              size_bits=sizeof_DCI2A_1_5MHz_2A_FDD_t;
-              break;
-
-            case 25:
-              ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI2A_5MHz_2A_FDD_t);
-              size_bits=sizeof_DCI2A_5MHz_2A_FDD_t;
-              break;
-
-            case 50:
-              ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_10MHz_2A_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI2A_10MHz_2A_FDD_t);
-              size_bits=sizeof_DCI2A_10MHz_2A_FDD_t;
-              break;
-
-            case 100:
-              ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_20MHz_2A_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI2A_20MHz_2A_FDD_t);
-              size_bits=sizeof_DCI2A_20MHz_2A_FDD_t;
-              break;
-
-            default:
-              ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-              ((DCI2A_5MHz_2A_FDD_t*)DLSCH_dci)->rah = 0;
-              size_bytes=sizeof(DCI2A_5MHz_2A_FDD_t);
-              size_bits=sizeof_DCI2A_5MHz_2A_FDD_t;
-              break;
-            }
-          }
-
-          add_ue_spec_dci(DCI_pdu,
-                          DLSCH_dci,
-                          rnti,
-                          size_bytes,
-			  get_aggregation(get_bw_index(module_idP,CC_id),eNB_UE_stats->DL_cqi[0],format2A),
-			  size_bits,
-                          format2A,
-                          0);
-
-          break;
-
-	  /*
-        case 4:
-
-          // DCI format 2_2A
-          ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-          ((DCI2_5MHz_2A_TDD_t*)DLSCH_dci)->rah = 0;
-          add_ue_spec_dci(DCI_pdu,
-                          DLSCH_dci,
-                          rnti,
-                          sizeof(DCI2_5MHz_2A_TDD_t),
-                          process_ue_cqi (module_idP,UE_id),//aggregation,
-                          sizeof_DCI2_5MHz_2A_TDD_t,
-                          format2,
-                          0);
-          break;
-
-        case 5:
-          ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-          ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rah = 0;
-
-          add_ue_spec_dci(DCI_pdu,
-                          DLSCH_dci,
-                          rnti,
-                          sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t),
-                          process_ue_cqi (module_idP,UE_id),//aggregation,
-                          sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t,
-                          format1E_2A_M10PRB,
-                          0);
-          break;
-
-        case 6:
-          ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rballoc = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
-          ((DCI1E_5MHz_2A_M10PRB_TDD_t*)DLSCH_dci)->rah = 0;
-
-          add_ue_spec_dci(DCI_pdu,
-                          DLSCH_dci,
-                          rnti,
-                          sizeof(DCI1E_5MHz_2A_M10PRB_TDD_t),
-                          process_ue_cqi (module_idP,UE_id),//aggregation
-                          sizeof_DCI1E_5MHz_2A_M10PRB_TDD_t,
-                          format1E_2A_M10PRB,
-                          0);
-          break;
-	  */
-
-        }
+	for (i=0;i<DL_req[CC_id].number_pdu;i++) {
+	  dl_config_pdu                    = &DL_req[CC_id].dl_config_pdu_list[i];
+	  if ((dl_config_pdu->pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)&&
+	      (dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti == rnti)) {
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_block_coding    = allocate_prbs_sub(nb_rb,N_RB_DL,N_RBG,rballoc_sub);
+	    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.resource_allocation_type = 0;
+	    break;
+	  }
+	}
       }
     }
 
@@ -2004,31 +1301,27 @@ get_dlsch_sdu(
 
 
 //------------------------------------------------------------------------------
-void
-update_ul_dci(
-  module_id_t module_idP,
-  uint8_t CC_id,
-  rnti_t rnti,
-  uint8_t dai)
+void update_ul_dci(module_id_t module_idP,
+		   uint8_t CC_idP,
+		   rnti_t rntiP,
+		   uint8_t daiP)
 //------------------------------------------------------------------------------
 {
 
-  COMMON_channels_t   *cc        = &RC.mac[module_idP]->common_channels[CC_id]; 
-  DCI_PDU             *DCI_pdu   = &cc->DCI_pdu;
-  int                  i;
-  DCI0_5MHz_TDD_1_6_t *ULSCH_dci = NULL;;
+  nfapi_hi_dci0_request_body_t *HI_DCI0_req    = &RC.mac[module_idP]->HI_DCI0_req[CC_idP];
+  nfapi_hi_dci0_request_pdu_t  *hi_dci0_pdu    = &HI_DCI0_req->hi_dci0_pdu_list[0];
+  COMMON_channels_t    *cc                     = &RC.mac[module_idP]->common_channels[CC_idP];
+  int i;
 
-  if (cc->tdd_Config != NULL) { // TDD
-    for (i=0; i<DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci; i++) {
-      ULSCH_dci = (DCI0_5MHz_TDD_1_6_t *)DCI_pdu->dci_alloc[i].dci_pdu;
+  if (cc->tdd_Config != NULL) { // TDD 
+    for (i=0; i<HI_DCI0_req->number_of_dci + HI_DCI0_req->number_of_dci; i++) {
 
-      if ((DCI_pdu->dci_alloc[i].format == format0) && (DCI_pdu->dci_alloc[i].rnti == rnti)) {
-        ULSCH_dci->dai = (dai-1)&3;
-      }
+      if ((hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE)  && 
+	  (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti == rntiP))
+        hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.dl_assignment_index = (daiP-1)&3;
+      
     }
   }
-
-  //  printf("Update UL DCI: DAI %d\n",dai);
 }
 
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_mch.c b/openair2/LAYER2/MAC/eNB_scheduler_mch.c
index e4172a562c78cf05c11706c9cb33aec463202c1c..4921d3bfa9b8e041b522801089581dac048c91d9 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_mch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_mch.c
@@ -468,7 +468,7 @@ int schedule_MBMS(module_id_t module_idP, uint8_t CC_id, frame_t frameP, sub_fra
     }
   }
 
-  TBS = mac_xface->get_TBS_DL(cc->MCH_pdu.mcs, to_prb(cc->mib->message.dl_Bandwidth));
+  TBS = get_TBS_DL(cc->MCH_pdu.mcs, to_prb(cc->mib->message.dl_Bandwidth));
 #if defined(Rel10) || defined(Rel14)
   // do not let mcch and mtch multiplexing when relaying is active
   // for sync area 1, so not transmit data
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index f7f4f34627a00b72247526855b55682532dddba0..c50a666fcc79197e48cbf3f01a07bc5246869569 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -72,6 +72,31 @@ int to_rbg(int dl_Bandwidth) {
   AssertFatal(dl_Bandwidth < 6,"dl_Bandwidth is 0..5\n");
   return(rbgmap[dl_Bandwidth]);
 }
+
+
+int get_phich_resource_times6(COMMON_channels_t *cc) {
+  int phichmap[4] = {1,3,6,12};
+  AssertFatal(cc!=NULL,"cc is null\n");
+  AssertFatal(cc->mib!=NULL,"cc->mib is null\n");
+  AssertFatal((cc->mib->message.phich_Config.phich_Resource>=0) && 
+	      (cc->mib->message.phich_Config.phich_Resource<4),
+	      "phich_Resource %d not in 0..3\n",(int)cc->mib->message.phich_Config.phich_Resource);
+
+  return(phichmap[cc->mib->message.phich_Config.phich_Resource]);
+}
+
+uint16_t mac_computeRIV(uint16_t N_RB_DL,uint16_t RBstart,uint16_t Lcrbs) {
+
+  uint16_t RIV;
+
+  if (Lcrbs<=(1+(N_RB_DL>>1)))
+    RIV = (N_RB_DL*(Lcrbs-1)) + RBstart;
+  else
+    RIV = (N_RB_DL*(N_RB_DL+1-Lcrbs)) + (N_RB_DL-1-RBstart);
+
+  return(RIV);
+}
+
 //------------------------------------------------------------------------------
 void init_ue_sched_info(void)
 //------------------------------------------------------------------------------
@@ -98,20 +123,11 @@ void init_ue_sched_info(void)
 
 
 //------------------------------------------------------------------------------
-unsigned char get_ue_weight(module_id_t module_idP, int CC_id, int ue_idP)
-//------------------------------------------------------------------------------
-{
-
-  return(eNB_dlsch_info[module_idP][CC_id][ue_idP].weight);
-
-}
-
-//------------------------------------------------------------------------------
-DCI_PDU *get_dci_sdu(module_id_t module_idP, int CC_id,frame_t frameP, sub_frame_t subframeP)
+unsigned char get_ue_weight(module_id_t module_idP, int CC_idP, int ue_idP)
 //------------------------------------------------------------------------------
 {
 
-  return(&RC.mac[module_idP]->common_channels[CC_id].DCI_pdu);
+  return(eNB_dlsch_info[module_idP][CC_idP][ue_idP].weight);
 
 }
 
@@ -228,35 +244,8 @@ unsigned char get_aggregation (uint8_t bw_index, uint8_t cqi, uint8_t dci_fmt)
    LOG_D(MAC,"Aggregation level %d (cqi %d, bw_index %d, format %d)\n", 
    	1<<aggregation, cqi,bw_index,dci_fmt);
    
-  return aggregation;
+  return 1<<aggregation;
 }
-#ifdef CBA
-/*
-uint8_t find_num_active_UEs_in_cbagroup(module_id_t module_idP, int CC_id,unsigned char group_id){
-
-  module_id_t    UE_id;
-  rnti_t    rnti;
-  unsigned char nb_ue_in_pusch=0;
-  LTE_eNB_UE_stats* eNB_UE_stats;
-
-  for (UE_id=group_id;UE_id<NUMBER_OF_UE_MAX;UE_id+=RC.mac[module_idP]->common_channels[CC_id].num_active_cba_groups) {
-
-      if (((rnti=eNB_mac_inst[module_idP][CC_id].UE_template[UE_id].rnti) !=0) &&
-          (eNB_mac_inst[module_idP][CC_id].UE_template[UE_id].ul_active==TRUE)    &&
-          (mac_get_rrc_status(module_idP,1,UE_id) > RRC_CONNECTED)){
-  //  && (UE_is_to_be_scheduled(module_idP,UE_id)))
-  // check at the phy enb_ue state for this rnti
-  if ((eNB_UE_stats= mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti)) != NULL){
-    if ((eNB_UE_stats->mode == PUSCH) && (UE_is_to_be_scheduled(module_idP,UE_id) == 0)){
-      nb_ue_in_pusch++;
-    }
-  }
-      }
-  }
-  return(nb_ue_in_pusch);
-}
-*/
-#endif
 
 void dump_ue_list(UE_list_t *listP, int ul_flag)
 {
@@ -423,10 +412,8 @@ void swap_UEs(UE_list_t *listP,int nodeiP, int nodejP, int ul_flag)
   prev_i = prev(listP,nodeiP,ul_flag);
   prev_j = prev(listP,nodejP,ul_flag);
 
-  if ((prev_i<0) || (prev_j<0)) {
-    mac_xface->macphy_exit("swap_UEs: problem");
-    return; // not reached
-  }
+  AssertFatal((prev_i>=0) && (prev_j>=0),
+	      "swap_UEs: problem");
 
   if (ul_flag == 0) {
     next_i = listP->next[nodeiP];
@@ -648,44 +635,6 @@ void swap_UEs(UE_list_t *listP,int nodeiP, int nodejP, int ul_flag)
   }
   #endif
  */
-void add_common_dci(DCI_PDU *DCI_pdu,
-                    void *pdu,
-                    rnti_t rnti,
-                    unsigned char dci_size_bytes,
-                    unsigned char aggregation,
-                    unsigned char dci_size_bits,
-                    unsigned char dci_fmt,
-                    uint8_t ra_flag)
-{
-
-  memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].dci_pdu[0],pdu,dci_size_bytes);
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].dci_length = dci_size_bits;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].L          = aggregation;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].rnti       = rnti;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].format     = dci_fmt;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci].ra_flag    = ra_flag;
-
-
-  DCI_pdu->Num_common_dci++;
-  LOG_D(MAC,"add common dci format %d for rnti %x \n",dci_fmt,rnti);
-}
-
-void add_ue_spec_dci(DCI_PDU *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt,uint8_t ra_flag)
-{
-
-  memcpy(&DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].dci_pdu[0],pdu,dci_size_bytes);
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].dci_length = dci_size_bits;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].L          = aggregation;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].rnti       = rnti;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].format     = dci_fmt;
-  DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci].ra_flag    = ra_flag;
-
-  DCI_pdu->Num_ue_spec_dci++;
-
-  LOG_D(MAC,"add ue specific dci format %d for rnti %x \n",dci_fmt,rnti);
-}
-
-
 
 
 
@@ -725,7 +674,122 @@ uint8_t UE_is_to_be_scheduled(module_id_t module_idP,int CC_id,uint8_t UE_id)
 }
 
 
+uint8_t get_tmode(module_id_t module_idP,int CC_idP,int UE_idP) {
+
+  eNB_MAC_INST         *eNB                                = RC.mac[module_idP];
+  COMMON_channels_t    *cc                                 = &eNB->common_channels[CC_idP];
+
+  struct PhysicalConfigDedicated  *physicalConfigDedicated = eNB->UE_list.physicalConfigDedicated[CC_idP][UE_idP];
+
+  AssertFatal(physicalConfigDedicated->antennaInfo!=NULL,
+	      "antennaInfo is null for CCId %d, UEid %d\n",CC_idP,UE_idP);
+
+  AssertFatal(physicalConfigDedicated->antennaInfo->present != PhysicalConfigDedicated__antennaInfo_PR_NOTHING, 
+	      "antennaInfo (mod_id %d, CC_id %d) is set to NOTHING\n",module_idP,CC_idP);
+
+  if (physicalConfigDedicated->antennaInfo->present == PhysicalConfigDedicated__antennaInfo_PR_explicitValue) {
+    return(physicalConfigDedicated->antennaInfo->choice.explicitValue.transmissionMode);
+  }
+  else if (physicalConfigDedicated->antennaInfo->present == PhysicalConfigDedicated__antennaInfo_PR_defaultValue) {
+    AssertFatal(cc->p_eNB<=2,"p_eNB is %d, should be <2\n",cc->p_eNB);
+    return(cc->p_eNB);
+  }
+  else AssertFatal(1==0,"Shouldn't be here\n");
+
+}
+
+int8_t get_UL_harq(module_id_t module_idP,int CC_idP,uint16_t frameP,uint8_t subframeP) {
+
+  uint8_t           ret       = -1;
+  eNB_MAC_INST      *eNB      = RC.mac[module_idP];
+  COMMON_channels_t *cc       = &eNB->common_channels[CC_idP];
+
+  if (cc->tdd_Config==NULL) { // FDD
+    ret = (((frameP<<1)+subframeP)&7);
+  } else {
+
+    switch (cc->tdd_Config->subframeAssignment) {
+
+    case 1:
+      if ((subframeP==2) ||
+          (subframeP==3) ||
+          (subframeP==7) ||
+          (subframeP==8))
+        switch (subframeP) {
+        case 2:
+        case 3:
+          ret = (subframeP-2);
+          break;
+
+        case 7:
+        case 8:
+          ret = (subframeP-5);
+          break;
+
+        default:
+          LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframeP,cc->tdd_Config->subframeAssignment);
+          ret = -1;
+          break;
+        }
+
+      break;
+
+    case 2:
+      if ((subframeP!=2) && (subframeP!=7)) {
+	LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframeP,cc->tdd_Config->subframeAssignment);
+	ret=-1;
+      }
+      else ret = (subframeP/7);
+      break;
+
+    case 3:
+      if ((subframeP<2) || (subframeP>4)) {
+        LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframeP,cc->tdd_Config->subframeAssignment);
+        ret = -1;
+      }
+      else ret = (subframeP-2);
+      break;
+
+    case 4:
+      if ((subframeP<2) || (subframeP>3)) {
+        LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframeP,cc->tdd_Config->subframeAssignment);
+        ret = -1;
+      }
+      else ret = (subframeP-2);
+      break;
+
+    case 5:
+      if (subframeP!=2) {
+        LOG_E(PHY,"subframe2_harq_pid, Illegal subframe %d for TDD mode %d\n",subframeP,cc->tdd_Config->subframeAssignment);
+        ret = -1;
+      }
+      else ret = (subframeP-2);
+      break;
+
+    default:
+      LOG_E(PHY,"subframe2_harq_pid, Unsupported TDD mode %d\n",cc->tdd_Config->subframeAssignment);
+      ret = -1;
+    }
+  }
+
+  AssertFatal(ret!=-1,
+	      "invalid harq_pid(%d) at SFN/SF = %d/%d\n", (int8_t)ret, frameP, subframeP);
+  return ret;
+}
+
+
+uint16_t getRIV(uint16_t N_RB_DL,uint16_t RBstart,uint16_t Lcrbs)
+{
+
+  uint16_t RIV;
+
+  if (Lcrbs<=(1+(N_RB_DL>>1)))
+    RIV = (N_RB_DL*(Lcrbs-1)) + RBstart;
+  else
+    RIV = (N_RB_DL*(N_RB_DL+1-Lcrbs)) + (N_RB_DL-1-RBstart);
 
+  return(RIV);
+}
 
 uint32_t allocate_prbs(int UE_id,unsigned char nb_rb, int N_RB_DL, uint32_t *rballoc)
 {
@@ -877,7 +941,13 @@ uint32_t allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc)
   return (rballoc_dci);
 }
 
+int get_subbandsize(uint8_t dl_Bandwidth) {
+  uint8_t ss[6] = {6,4,4,6,8,8};
+
+  AssertFatal(dl_Bandwidth<6,"dl_Bandwidth %d is out of bounds\n",dl_Bandwidth);
 
+  return(ss[dl_Bandwidth]);
+}
 int get_nb_subband(int N_RB_DL)
 {
 
@@ -1062,6 +1132,131 @@ void dump_CCE_table(int *CCE_table,const int nCCE,const unsigned short rnti,cons
 
 }
 
+
+
+uint16_t getnquad(COMMON_channels_t *cc, uint8_t num_pdcch_symbols,uint8_t mi)
+{
+
+  uint16_t Nreg=0;
+
+  AssertFatal(cc!=NULL,"cc is null\n");
+  AssertFatal(cc->mib!=NULL,"cc->mib is null\n");
+
+  int N_RB_DL        = to_prb(cc->mib->message.dl_Bandwidth);
+  int phich_resource = get_phich_resource_times6(cc); 
+
+  uint8_t Ngroup_PHICH = (phich_resource*N_RB_DL)/48;
+
+  if (((phich_resource*N_RB_DL)%48) > 0)
+    Ngroup_PHICH++;
+
+  if (cc->Ncp == 1) {
+    Ngroup_PHICH<<=1;
+  }
+
+  Ngroup_PHICH*=mi;
+
+  if ((num_pdcch_symbols>0) && (num_pdcch_symbols<4))
+    switch (N_RB_DL) {
+    case 6:
+      Nreg=12+(num_pdcch_symbols-1)*18;
+      break;
+
+    case 25:
+      Nreg=50+(num_pdcch_symbols-1)*75;
+      break;
+
+    case 50:
+      Nreg=100+(num_pdcch_symbols-1)*150;
+      break;
+
+    case 100:
+      Nreg=200+(num_pdcch_symbols-1)*300;
+      break;
+
+    default:
+      return(0);
+    }
+
+  //   printf("Nreg %d (%d)\n",Nreg,Nreg - 4 - (3*Ngroup_PHICH));
+  return(Nreg - 4 - (3*Ngroup_PHICH));
+}
+
+uint16_t getnCCE(COMMON_channels_t *cc, uint8_t num_pdcch_symbols, uint8_t mi)
+{
+  AssertFatal(cc!=NULL,"cc is null\n");
+  return(getnquad(cc,num_pdcch_symbols,mi)/9);
+}
+
+uint8_t getmi(COMMON_channels_t *cc,int subframe) {
+
+  AssertFatal(cc!=NULL,"cc is null\n");
+
+  // for FDD
+  if (cc->tdd_Config==NULL) // FDD
+    return 1;
+
+  // for TDD
+  switch (cc->tdd_Config->subframeAssignment) {
+
+  case 0:
+    if ((subframe==0) || (subframe==5))
+      return(2);
+    else return(1);
+
+    break;
+
+  case 1:
+    if ((subframe==0) || (subframe==5))
+      return(0);
+    else return(1);
+
+    break;
+
+  case 2:
+    if ((subframe==3) || (subframe==8))
+      return(1);
+    else return(0);
+
+    break;
+
+  case 3:
+    if ((subframe==0) || (subframe==8) || (subframe==9))
+      return(1);
+    else return(0);
+
+    break;
+
+  case 4:
+    if ((subframe==8) || (subframe==9))
+      return(1);
+    else return(0);
+
+    break;
+
+  case 5:
+    if (subframe==8)
+      return(1);
+    else return(0);
+
+    break;
+
+  case 6:
+    return(1);
+    break;
+
+  default:
+    return(0);
+  }
+}
+
+uint16_t get_nCCE_max(COMMON_channels_t *cc, int num_pdcch_symbols,int subframe)
+{
+  AssertFatal(cc!=NULL,"cc is null\n");
+  return(getnCCE(cc,num_pdcch_symbols,
+		 getmi(cc,subframe))); 
+}
+ 
 // Allocate the CCEs
 int allocate_CCEs(int module_idP,
 		  int CC_idP,
@@ -1069,72 +1264,199 @@ int allocate_CCEs(int module_idP,
 		  int test_onlyP) {
 
 
-  int *CCE_table = RC.mac[module_idP]->CCE_table[CC_idP];
-  DCI_PDU *DCI_pdu = &RC.mac[module_idP]->common_channels[CC_idP].DCI_pdu;
-  int nCCE_max = mac_xface->get_nCCE_max(module_idP,CC_idP,1,subframeP);
+  int                                 *CCE_table           = RC.mac[module_idP]->CCE_table[CC_idP];
+  nfapi_dl_config_request_body_t      *DL_req              = &RC.mac[module_idP]->DL_req[CC_idP];
+  nfapi_hi_dci0_request_body_t        *HI_DCI0_req         = &RC.mac[module_idP]->HI_DCI0_req[CC_idP];
+  nfapi_dl_config_request_pdu_t       *dl_config_pdu       = &DL_req->dl_config_pdu_list[0];
+  nfapi_hi_dci0_request_pdu_t         *hi_dci0_pdu         = &HI_DCI0_req->hi_dci0_pdu_list[0];
+  int                                 nCCE_max             = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],1,subframeP);
   int fCCE;
-  int i,j;
-  DCI_ALLOC_t *dci_alloc;
+  int i,j,idci;
   int nCCE=0;
 
-  LOG_D(MAC,"Allocate CCEs subframe %d, test %d : (common %d,uspec %d)\n",subframeP,test_onlyP,DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci);
-  DCI_pdu->num_pdcch_symbols=1;
+  LOG_I(MAC,"Allocate CCEs subframe %d, test %d : (DL %d,UL %d)\n",subframeP,test_onlyP,DL_req->number_dci,HI_DCI0_req->number_of_dci);
+  DL_req->number_pdcch_ofdm_symbols=1;
 
 try_again:
   init_CCE_table(module_idP,CC_idP);
   nCCE=0;
 
-  for (i=0;i<DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci;i++) {
-    dci_alloc = &DCI_pdu->dci_alloc[i];
-    LOG_D(MAC,"Trying to allocate DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-          i,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci,
-          DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci,
-          dci_alloc->rnti,1<<dci_alloc->L,
-          nCCE,nCCE_max,DCI_pdu->num_pdcch_symbols);
-
-    if (nCCE + (1<<dci_alloc->L) > nCCE_max) {
-      if (DCI_pdu->num_pdcch_symbols == 3)
-        goto failed;
-      DCI_pdu->num_pdcch_symbols++;
-      nCCE_max = mac_xface->get_nCCE_max(module_idP,CC_idP,DCI_pdu->num_pdcch_symbols,subframeP);
-      goto try_again;
+  for (i=0,idci=0;i<DL_req->number_pdu;i++) {
+    // allocate DL common DCIs first
+    if ((dl_config_pdu[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)&&
+	(dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type==2)) {
+      LOG_I(MAC,"Trying to allocate COMMON DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+	    idci,DL_req->number_dci+HI_DCI0_req->number_of_dci,
+	    DL_req->number_dci,HI_DCI0_req->number_of_dci,
+	    dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+	    dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+	    nCCE,nCCE_max, DL_req->number_pdcch_ofdm_symbols);
+    
+      if (nCCE + (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) {
+	if (DL_req->number_pdcch_ofdm_symbols == 3)
+	  goto failed;
+	DL_req->number_pdcch_ofdm_symbols++;
+	nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],DL_req->number_pdcch_ofdm_symbols,subframeP);
+	goto try_again;
+      }
+      
+      // number of CCEs left can potentially hold this allocation
+      fCCE = get_nCCE_offset(CCE_table,
+			     dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+			     nCCE_max,
+			     1,
+			     dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+			     subframeP);
+      if (fCCE == -1) {
+	if (DL_req->number_pdcch_ofdm_symbols == 3) {
+	  LOG_I(MAC,"subframe %d: Dropping Allocation for RNTI %x\n",
+		subframeP,dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti);
+	  for (j=0;j<=i;j++){
+	    if (dl_config_pdu[j].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
+	      LOG_I(MAC,"DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+		    j,DL_req->number_dci+HI_DCI0_req->number_of_dci,
+		    DL_req->number_dci,HI_DCI0_req->number_of_dci,
+		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.dci_format,
+		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+		    nCCE,nCCE_max,DL_req->number_pdcch_ofdm_symbols);
+	  }
+	  //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
+	  goto failed;
+	}
+	DL_req->number_pdcch_ofdm_symbols++;
+	nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],DL_req->number_pdcch_ofdm_symbols,subframeP);
+	goto try_again;
+      } // fCCE==-1
+      
+      // the allocation is feasible, rnti rule passes
+      nCCE += dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level;
+      LOG_D(MAC,"Allocating at nCCE %d\n",fCCE);
+      if (test_onlyP == 0) {
+	dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx=fCCE;
+	LOG_I(MAC,"Allocate COMMON DCI CCEs subframe %d, test %d => L %d fCCE %d\n",subframeP,test_onlyP,dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,fCCE);
+      }
+      idci++;
     }
+  } // for i = 0 ... num_DL_DCIs
 
-    // number of CCEs left can potentially hold this allocation
-    fCCE = get_nCCE_offset(CCE_table,
-                           1<<(dci_alloc->L),
-                           nCCE_max,
-                           (i<DCI_pdu->Num_common_dci) ? 1 : 0,
-                           dci_alloc->rnti,
-                           subframeP);
-    if (fCCE == -1) {
-      if (DCI_pdu->num_pdcch_symbols == 3) {
-        LOG_I(MAC,"subframe %d: Dropping Allocation for RNTI %x\n",
-              subframeP,dci_alloc->rnti);
-        for (j=0;j<=i;j++){
-          LOG_I(MAC,"DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
-                j,DCI_pdu->Num_common_dci+DCI_pdu->Num_ue_spec_dci,
-                DCI_pdu->Num_common_dci,DCI_pdu->Num_ue_spec_dci,
-                DCI_pdu->dci_alloc[j].rnti,DCI_pdu->dci_alloc[j].format,
-                1<<DCI_pdu->dci_alloc[j].L,
-                nCCE,nCCE_max,DCI_pdu->num_pdcch_symbols);
-        }
-	//dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
-        goto failed;
+  // no try to allocate UL DCIs
+  for (i=0;i<HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi;i++) {
+
+    // allocate UL DCIs 
+    if (hi_dci0_pdu[i].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE) {
+
+      LOG_D(MAC,"Trying to allocate format 0 DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+	    idci,DL_req->number_dci+HI_DCI0_req->number_of_dci,
+	    DL_req->number_dci,HI_DCI0_req->number_of_dci,
+	    hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti,hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level,
+	    nCCE,nCCE_max, DL_req->number_pdcch_ofdm_symbols);
+   
+      if (nCCE + (hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level) > nCCE_max) {
+	if (DL_req->number_pdcch_ofdm_symbols == 3)
+	  goto failed;
+	DL_req->number_pdcch_ofdm_symbols++;
+	nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],DL_req->number_pdcch_ofdm_symbols,subframeP);
+	goto try_again;
+      }
+      
+      // number of CCEs left can potentially hold this allocation
+      fCCE = get_nCCE_offset(CCE_table,
+			     hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level,
+			     nCCE_max,
+			     1,
+			     hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti,
+			     subframeP);
+      if (fCCE == -1) {
+	if (DL_req->number_pdcch_ofdm_symbols == 3) {
+	  LOG_I(MAC,"subframe %d: Dropping Allocation for RNTI %x\n",
+		subframeP,hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.rnti);
+	  for (j=0;j<=i;j++){
+	    if (hi_dci0_pdu[j].pdu_type == NFAPI_HI_DCI0_DCI_PDU_TYPE)
+	      LOG_I(MAC,"DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+		    j,DL_req->number_dci+HI_DCI0_req->number_of_dci,
+		    DL_req->number_dci,HI_DCI0_req->number_of_dci,
+		    hi_dci0_pdu[j].dci_pdu.dci_pdu_rel8.rnti,
+		    hi_dci0_pdu[j].dci_pdu.dci_pdu_rel8.dci_format,
+		    hi_dci0_pdu[j].dci_pdu.dci_pdu_rel8.aggregation_level,
+		    nCCE,nCCE_max,DL_req->number_pdcch_ofdm_symbols);
+	  }
+	  //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
+	  goto failed;
+	}
+	DL_req->number_pdcch_ofdm_symbols++;
+	nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],DL_req->number_pdcch_ofdm_symbols,subframeP);
+	goto try_again;
+      } // fCCE==-1
+      
+      // the allocation is feasible, rnti rule passes
+      nCCE += hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.aggregation_level;
+      LOG_D(MAC,"Allocating at nCCE %d\n",fCCE);
+      if (test_onlyP == 0) {
+	hi_dci0_pdu[i].dci_pdu.dci_pdu_rel8.cce_index=fCCE;
+	LOG_D(MAC,"Allocate CCEs subframe %d, test %d\n",subframeP,test_onlyP);
+      }
+      idci++;
+    }
+  } // for i = 0 ... num_UL_DCIs
+
+  for (i=0;i<DL_req->number_pdu;i++) {
+    // allocate DL common DCIs first
+    if ((dl_config_pdu[i].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)&&
+	(dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti_type==1)) {
+      LOG_D(MAC,"Trying to allocate DL UE-SPECIFIC DCI %d/%d (%d,%d) : rnti %x, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+	    idci,DL_req->number_dci+HI_DCI0_req->number_of_dci,
+	    DL_req->number_dci,HI_DCI0_req->number_of_dci,
+	    dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti,dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+	    nCCE,nCCE_max, DL_req->number_pdcch_ofdm_symbols);
+   
+      if (nCCE + (dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level) > nCCE_max) {
+	if (DL_req->number_pdcch_ofdm_symbols == 3)
+	  goto failed;
+	DL_req->number_pdcch_ofdm_symbols++;
+	nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],DL_req->number_pdcch_ofdm_symbols,subframeP);
+	goto try_again;
+      }
+      
+      // number of CCEs left can potentially hold this allocation
+      fCCE = get_nCCE_offset(CCE_table,
+			     dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+			     nCCE_max,
+			     1,
+			     dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+			     subframeP);
+      if (fCCE == -1) {
+	if (DL_req->number_pdcch_ofdm_symbols == 3) {
+	  LOG_I(MAC,"subframe %d: Dropping Allocation for RNTI %x\n",
+		subframeP,dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.rnti);
+	  for (j=0;j<=i;j++){
+	    if (dl_config_pdu[j].pdu_type == NFAPI_DL_CONFIG_DCI_DL_PDU_TYPE)
+	      LOG_I(MAC,"DCI %d/%d (%d,%d) : rnti %x dci format %d, aggreg %d nCCE %d / %d (num_pdcch_symbols %d)\n",
+		    j,DL_req->number_dci+HI_DCI0_req->number_of_dci,
+		    DL_req->number_dci,HI_DCI0_req->number_of_dci,
+		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.rnti,
+		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.dci_format,
+		    dl_config_pdu[j].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level,
+		    nCCE,nCCE_max,DL_req->number_pdcch_ofdm_symbols);
+	  }
+	  //dump_CCE_table(CCE_table,nCCE_max,subframeP,dci_alloc->rnti,1<<dci_alloc->L);
+	  goto failed;
+	}
+	DL_req->number_pdcch_ofdm_symbols++;
+	nCCE_max = get_nCCE_max(&RC.mac[module_idP]->common_channels[CC_idP],DL_req->number_pdcch_ofdm_symbols,subframeP);
+	goto try_again;
+      } // fCCE==-1
+      
+      // the allocation is feasible, rnti rule passes
+      nCCE += dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level;
+      LOG_D(MAC,"Allocating at nCCE %d\n",fCCE);
+      if (test_onlyP == 0) {
+	dl_config_pdu[i].dci_dl_pdu.dci_dl_pdu_rel8.cce_idx=fCCE;
+	LOG_D(MAC,"Allocate CCEs subframe %d, test %d\n",subframeP,test_onlyP);
       }
-      DCI_pdu->num_pdcch_symbols++;
-      nCCE_max = mac_xface->get_nCCE_max(module_idP,CC_idP,DCI_pdu->num_pdcch_symbols,subframeP);
-      goto try_again;
-    } // fCCE==-1
-
-    // the allocation is feasible, rnti rule passes
-    nCCE += (1<<dci_alloc->L);
-    LOG_D(MAC,"Allocating at nCCE %d\n",fCCE);
-    if (test_onlyP == 0) {
-      dci_alloc->firstCCE=fCCE;
-      LOG_D(MAC,"Allocate CCEs subframe %d, test %d\n",subframeP,test_onlyP);
+      idci++;
     }
-  } // for i = 0 ... num_dcis
+  } // for i = 0 ... num_DL_DCIs
 
   return 0;
 
@@ -1144,34 +1466,36 @@ failed:
 
 boolean_t CCE_allocation_infeasible(int module_idP,
 				    int CC_idP,
-				    int common_flag,
+				    int format_flag,
 				    int subframe,
 				    int aggregation,
 				    int rnti) {
 
-
-  DCI_PDU *DCI_pdu = &RC.mac[module_idP]->common_channels[CC_idP].DCI_pdu;
+  nfapi_dl_config_request_body_t *DL_req       = &RC.mac[module_idP]->DL_req[CC_idP];
+  nfapi_dl_config_request_pdu_t* dl_config_pdu = &DL_req->dl_config_pdu_list[DL_req->number_pdu];
+  nfapi_hi_dci0_request_body_t *HI_DCI0_req    = &RC.mac[module_idP]->HI_DCI0_req[CC_idP];
+  nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu     = &HI_DCI0_req->hi_dci0_pdu_list[HI_DCI0_req->number_of_dci+HI_DCI0_req->number_of_hi]; 
   //DCI_ALLOC_t *dci_alloc;
   int ret;
   boolean_t res=FALSE;
 
-  if (common_flag==1) {
-    DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci].rnti = rnti;
-    DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci].L = aggregation;
-    DCI_pdu->Num_common_dci++;
+  if (format_flag!=2) { // DL DCI
+    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.rnti              = rnti;
+    dl_config_pdu->dci_dl_pdu.dci_dl_pdu_rel8.aggregation_level = aggregation;
+    DL_req->number_pdu++;
     ret = allocate_CCEs(module_idP,CC_idP,subframe,1);
     if (ret==-1)
       res = TRUE;
-    DCI_pdu->Num_common_dci--;
+    DL_req->number_pdu--;
   }
-  else {
-    DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci].rnti = rnti;
-    DCI_pdu->dci_alloc[DCI_pdu->Num_common_dci + DCI_pdu->Num_ue_spec_dci].L = aggregation;
-    DCI_pdu->Num_ue_spec_dci++;
+  else if (format_flag == 2) { // ue-specific UL DCI
+    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti             = rnti;
+    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level = aggregation;
+    HI_DCI0_req->number_of_dci++;
     ret = allocate_CCEs(module_idP,CC_idP,subframe,1);
     if (ret==-1)
       res = TRUE;
-    DCI_pdu->Num_ue_spec_dci--;
+    HI_DCI0_req->number_of_dci--;
   }
   return(res);
 }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index 7d3682ee5496503f81fc0413231328048a6ff224..f2f27ca380eadc9ee36624f6852702d3559cc750 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -337,7 +337,7 @@ void rx_sdu(const module_id_t enb_mod_idP,
                   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_pidP)) == -1 ) {
-              mac_xface->macphy_exit("[MAC][eNB] Max user count reached\n");
+              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",
@@ -589,7 +589,7 @@ unsigned char *parse_ulsch_header(unsigned char *mac_header,
           ce_len++;
         } else {
           LOG_E(MAC,"unknown CE %d \n", lcid);
-          mac_xface->macphy_exit("unknown CE");
+          AssertFatal(1==0,"unknown CE");
         }
       }
     }
@@ -669,20 +669,10 @@ void schedule_ulsch(module_id_t module_idP,
         break;
       }
     }
-
-    /*
-    if (mac_xface->is_prach_subframe(&(mac_xface->lte_frame_parms),frameP,subframeP)) {
-      first_rb[CC_id] = (mac_xface->get_prach_prb_offset(&(mac_xface->lte_frame_parms),
-    */
-
   }
 
   schedule_ulsch_rnti(module_idP, cooperation_flag, frameP, subframeP, sched_subframe,first_rb);
 
-#ifdef CBA
-  schedule_ulsch_cba_rnti(module_idP, cooperation_flag, frameP, subframeP, sched_subframe, first_rb);
-#endif
-
 
   stop_meas(&eNB->schedule_ulsch);
 
@@ -703,9 +693,7 @@ void schedule_ulsch_rnti(module_id_t   module_idP,
   rnti_t            rnti           = -1;
   uint8_t           round          = 0;
   uint8_t           harq_pid       = 0;
-  void              *ULSCH_dci      = NULL;
-  LTE_eNB_UE_stats  *eNB_UE_stats   = NULL;
-  DCI_PDU           *DCI_pdu;
+  eNB_UE_STATS      *eNB_UE_stats   = NULL;
   uint8_t           status         = 0; 
   uint8_t           rb_table_index = -1;
   uint16_t          TBS = 0;
@@ -723,6 +711,7 @@ void schedule_ulsch_rnti(module_id_t   module_idP,
   UE_TEMPLATE       *UE_template;
   UE_sched_ctrl     *UE_sched_ctrl;
 
+  nfapi_hi_dci0_request_pdu_t *hi_dci0_pdu;
 
   LOG_D(MAC,"entering ulsch preprocesor\n");
 
@@ -750,17 +739,19 @@ void schedule_ulsch_rnti(module_id_t   module_idP,
       continue;
     }
 
-    /* let's drop the UE if get_eNB_UE_stats returns NULL when calling it with any of the UE's active UL CCs */
-    /* TODO: refine? */
     drop_ue = 0;
+    /* let's drop the UE if get_eNB_UE_stats returns NULL when calling it with any of the UE's active UL CCs */
+    /* TODO: refine? 
+
     for (n=0; n<UE_list->numactiveULCCs[UE_id]; n++) {
       CC_id = UE_list->ordered_ULCCids[n][UE_id];
+      
       if (mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti) == NULL) {
         LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: no PHY context\n", module_idP,frameP,subframeP,UE_id,rnti,CC_id);
         drop_ue = 1;
         break;
       }
-    }
+      }*/
     if (drop_ue == 1) {
 /* we can't come here, ulsch_scheduler_pre_processor won't put in the list a UE with no PHY context */
 abort();
@@ -788,11 +779,11 @@ abort();
       // This is the actual CC_id in the list
       CC_id        = UE_list->ordered_ULCCids[n][UE_id];
       N_RB_UL      = to_prb(cc[CC_id].ul_Bandwidth);
-      eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
+      eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
 
       
       aggregation=get_aggregation(get_bw_index(module_idP,CC_id), 
-				  eNB_UE_stats->DL_cqi[0],
+				  eNB_UE_stats->dl_cqi,
 				  format0);
       
 
@@ -800,29 +791,31 @@ abort();
         LOG_W(MAC,"[eNB %d] frame %d subframe %d, UE %d/%x CC %d: not enough nCCE\n", module_idP,frameP,subframeP,UE_id,rnti,CC_id);
         continue; // break;
       } else{
-	LOG_D(MAC,"[eNB %d] frame %d subframe %d,Scheduling PUSCH for UE %d/%x CC %d mode %s: aggregation level %d, N_RB_UL %d\n", 
-	      module_idP,frameP,subframeP,UE_id,rnti,CC_id, mode_string[eNB_UE_stats->mode], 1<<aggregation,N_RB_UL);
+	LOG_D(MAC,"[eNB %d] frame %d subframe %d,Scheduling PUSCH for UE %d/%x CC %d : aggregation level %d, N_RB_UL %d\n", 
+	      module_idP,frameP,subframeP,UE_id,rnti,CC_id, aggregation,N_RB_UL);
       }
 
 
-      if (eNB_UE_stats->mode == PUSCH) { // ue has a ulsch channel
-
-        DCI_pdu = &eNB->common_channels[CC_id].DCI_pdu;
-        UE_template   = &UE_list->UE_template[CC_id][UE_id];
-        UE_sched_ctrl = &UE_list->UE_sched_ctrl[UE_id];
-
-        if (mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL) == -1 ) {
-          LOG_W(MAC,"[eNB %d] Scheduler Frame %d, subframeP %d: candidate harq_pid from PHY for UE %d CC %d RNTI %x\n",
-                module_idP,frameP,subframeP, UE_id, CC_id, rnti);
-          continue;
-        } else
-          LOG_T(MAC,"[eNB %d] Frame %d, subframeP %d, UE %d CC %d : got harq pid %d  round %d (rnti %x,mode %s)\n",
-                module_idP,frameP,subframeP,UE_id,CC_id, harq_pid, round,rnti,mode_string[eNB_UE_stats->mode]);
-
-	RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP] = UE_template->ul_total_buffer;
-	VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO,RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP]);	
-        if (((UE_is_to_be_scheduled(module_idP,CC_id,UE_id)>0)) || (round>0))// || ((frameP%10)==0))
-          // if there is information on bsr of DCCH, DTCH or if there is UL_SR, or if there is a packet to retransmit, or we want to schedule a periodic feedback every 10 frames
+      //      if (eNB_UE_stats->mode == PUSCH) { // ue has a ulsch channel
+
+      UE_template   = &UE_list->UE_template[CC_id][UE_id];
+      UE_sched_ctrl = &UE_list->UE_sched_ctrl[UE_id];
+      harq_pid = get_UL_harq(frameP,subframeP);
+      round    = UE_sched_ctrl->round_UL[CC_id];
+      /*      
+      if (get_UL_harq_info(module_idP,CC_id,frameP,subframeP,&harq_pid,&round)<0) {
+	LOG_W(MAC,"[eNB %d] Scheduler Frame %d, subframeP %d: candidate harq_pid from PHY for UE %d CC %d RNTI %x\n",
+	      module_idP,frameP,subframeP, UE_id, CC_id, rnti);
+	continue;
+      } else
+	LOG_T(MAC,"[eNB %d] Frame %d, subframeP %d, UE %d CC %d : got harq pid %d  round %d (rnti %x)\n",
+	      module_idP,frameP,subframeP,UE_id,CC_id, harq_pid, round,rnti);
+      */
+
+      RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP] = UE_template->ul_total_buffer;
+      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_BO,RC.eNB[module_idP][CC_id]->pusch_stats_BO[UE_id][(frameP*10)+subframeP]);	
+      if (((UE_is_to_be_scheduled(module_idP,CC_id,UE_id)>0)) || (round>0))// || ((frameP%10)==0))
+	// if there is information on bsr of DCCH, DTCH or if there is UL_SR, or if there is a packet to retransmit, or we want to schedule a periodic feedback every 10 frames
         {
 	  LOG_D(MAC,"[eNB %d][PUSCH] Frame %d subframe %d Scheduling UE %d/%x in round %d(SR %d,UL_inactivity timer %d,UL_failure timer %d)\n",
 		module_idP,frameP,subframeP,UE_id,rnti,round,UE_template->ul_SR,
@@ -839,44 +832,44 @@ abort();
 	  }
 	  else
 	    cqi_req = 0;
-
+	  
           //power control
           //compute the expected ULSCH RX power (for the stats)
-
+	  
           // this is the normalized RX power and this should be constant (regardless of mcs
-          normalized_rx_power = eNB_UE_stats->UL_rssi[0];
-          target_rx_power = mac_xface->get_target_pusch_rx_power(module_idP,CC_id);
-
+          normalized_rx_power = eNB_UE_stats->UL_rssi;
+          target_rx_power = cc[CC_id].radioResourceConfigCommon->uplinkPowerControlCommon.p0_NominalPUSCH;//get_target_pusch_rx_power(module_idP,CC_id);
+	  
           // this assumes accumulated tpc
 	  // make sure that we are only sending a tpc update once a frame, otherwise the control loop will freak out
 	  int32_t framex10psubframe = UE_template->pusch_tpc_tx_frame*10+UE_template->pusch_tpc_tx_subframe;
           if (((framex10psubframe+10)<=(frameP*10+subframeP)) || //normal case
 	      ((framex10psubframe>(frameP*10+subframeP)) && (((10240-framex10psubframe+frameP*10+subframeP)>=10)))) //frame wrap-around
 	    {
-	    UE_template->pusch_tpc_tx_frame=frameP;
-	    UE_template->pusch_tpc_tx_subframe=subframeP;
-            if (normalized_rx_power>(target_rx_power+1)) {
-              tpc = 0; //-1
-              tpc_accumulated--;
-            } else if (normalized_rx_power<(target_rx_power-1)) {
-              tpc = 2; //+1
-              tpc_accumulated++;
-            } else {
-              tpc = 1; //0
-            }
-          } else {
+	      UE_template->pusch_tpc_tx_frame=frameP;
+	      UE_template->pusch_tpc_tx_subframe=subframeP;
+	      if (normalized_rx_power>(target_rx_power+1)) {
+		tpc = 0; //-1
+		tpc_accumulated--;
+	      } else if (normalized_rx_power<(target_rx_power-1)) {
+		tpc = 2; //+1
+		tpc_accumulated++;
+	      } else {
+		tpc = 1; //0
+	      }
+	    } else {
             tpc = 1; //0
           }
-
+	  
 	  if (tpc!=1) {
 	    LOG_D(MAC,"[eNB %d] ULSCH scheduler: frame %d, subframe %d, harq_pid %d, tpc %d, accumulated %d, normalized/target rx power %d/%d\n",
 		  module_idP,frameP,subframeP,harq_pid,tpc,
 		  tpc_accumulated,normalized_rx_power,target_rx_power);
 	  }
-
+	  
           // new transmission
           if (round==0) {
-
+	    
             ndi = 1-UE_template->oldNDI_UL[harq_pid];
             UE_template->oldNDI_UL[harq_pid]=ndi;
 	    UE_list->eNB_UE_stats[CC_id][UE_id].normalized_rx_power=normalized_rx_power;
@@ -889,43 +882,45 @@ abort();
 	      mcs=10;//cmin (10, openair_daq_vars.target_ue_ul_mcs);
               rb_table_index=5; // for PHR
 	    }
-
+	    
             UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=mcs;
 	    //            buffer_occupancy = UE_template->ul_total_buffer;
-
+	    
             while (((rb_table[rb_table_index]>(N_RB_UL-1-first_rb[CC_id])) ||
 		    (rb_table[rb_table_index]>45)) &&
                    (rb_table_index>0)) {
               rb_table_index--;
             }
-
-            TBS = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]);
+	    
+            TBS = get_TBS_UL(mcs,rb_table[rb_table_index]);
 	    UE_list->eNB_UE_stats[CC_id][UE_id].total_rbs_used_rx+=rb_table[rb_table_index];
 	    UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_TBS=TBS;
 	    //            buffer_occupancy -= TBS;
-            rballoc = mac_xface->computeRIV(N_RB_UL,
-                                            first_rb[CC_id],
-                                            rb_table[rb_table_index]);
-
+            rballoc = getRIV(N_RB_UL,
+			     first_rb[CC_id],
+			     rb_table[rb_table_index]);
+	    
             T(T_ENB_MAC_UE_UL_SCHEDULE, T_INT(module_idP), T_INT(CC_id), T_INT(rnti), T_INT(frameP),
               T_INT(subframeP), T_INT(harq_pid), T_INT(mcs), T_INT(first_rb[CC_id]), T_INT(rb_table[rb_table_index]),
               T_INT(TBS), T_INT(ndi));
-
+	    
 	    if (mac_eNB_get_rrc_status(module_idP,rnti) < RRC_CONNECTED)
 	      LOG_D(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d)\n",
 		    module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,mcs,
 		    first_rb[CC_id],rb_table[rb_table_index],
 		    rb_table_index,TBS,harq_pid);
-
+	    
 	    // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
             // increment for next UE allocation
             first_rb[CC_id]+=rb_table[rb_table_index];
             //store for possible retransmission
-            UE_template->nb_rb_ul[harq_pid] = rb_table[rb_table_index];
+            UE_template->nb_rb_ul[harq_pid]    = rb_table[rb_table_index];
+            UE_template->first_rb_ul[harq_pid] = first_rb[CC_id];
+	    
 	    UE_sched_ctrl->ul_scheduled |= (1<<harq_pid);
 	    if (UE_id == UE_list->head)
 	      VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_SCHEDULED,UE_sched_ctrl->ul_scheduled);
-
+	    
 	    // adjust total UL buffer status by TBS, wait for UL sdus to do final update
 	    LOG_D(MAC,"[eNB %d] CC_id %d UE %d/%x : adjusting ul_total_buffer, old %d, TBS %d\n", module_idP,CC_id,UE_id,rnti,UE_template->ul_total_buffer,TBS);
 	    if (UE_template->ul_total_buffer > TBS)
@@ -935,207 +930,31 @@ abort();
 	    LOG_D(MAC,"ul_total_buffer, new %d\n", UE_template->ul_total_buffer);
 	    // Cyclic shift for DM RS
 	    cshift = 0;// values from 0 to 7 can be used for mapping the cyclic shift (36.211 , Table 5.5.2.1.1-1)
-	    	    
-	    if (cc[CC_id].tdd_Config!= NULL) { // TDD
-	      switch (N_RB_UL) {
-	      case 6:
-		ULSCH_dci = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->type     = 0;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->dai      = UE_template->DAI_ul[sched_subframe];
-		((DCI0_1_5MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req  = cqi_req;
-		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_1_5MHz_TDD_1_6_t),
-				aggregation,
-				sizeof_DCI0_1_5MHz_TDD_1_6_t,
-				format0,
-				0);
-		break;
-		
-	      default:
-	      case 25:
-		ULSCH_dci = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->type     = 0;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->dai      = UE_template->DAI_ul[sched_subframe];
-		((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req  = cqi_req;
-		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_5MHz_TDD_1_6_t),
-				aggregation,
-				sizeof_DCI0_5MHz_TDD_1_6_t,
-				format0,
-				0);
-		break;
-		
-	      case 50:
-		ULSCH_dci = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->type     = 0;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->dai      = UE_template->DAI_ul[sched_subframe];
-		((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req  = cqi_req;
-		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_10MHz_TDD_1_6_t),
-				aggregation,
-				sizeof_DCI0_10MHz_TDD_1_6_t,
-				format0,
-				0);
-		break;
-		
-	      case 100:
-		ULSCH_dci = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->type     = 0;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->dai      = UE_template->DAI_ul[sched_subframe];
-		((DCI0_20MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req  = cqi_req;
-		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_20MHz_TDD_1_6_t),
-				aggregation,
-				sizeof_DCI0_20MHz_TDD_1_6_t,
-				format0,
-				0);
-		break;
-	      }
-	    } // TDD
-	    else { //FDD
-	      switch (N_RB_UL) {
-	      case 25:
-	      default:
-		
-		ULSCH_dci          = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->type     = 0;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_5MHz_FDD_t *)ULSCH_dci)->cqi_req  = cqi_req;
-		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_5MHz_FDD_t),
-				aggregation,
-				sizeof_DCI0_5MHz_FDD_t,
-				format0,
-				0);
-		break;
-		
-	      case 6:
-		ULSCH_dci          = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->type     = 0;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_1_5MHz_FDD_t *)ULSCH_dci)->cqi_req  = cqi_req;
-		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_1_5MHz_FDD_t),
-				aggregation,
-				sizeof_DCI0_1_5MHz_FDD_t,
-				format0,
-				0);
-		break;
-		
-	      case 50:
-		ULSCH_dci          = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->type     = 0;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_10MHz_FDD_t *)ULSCH_dci)->cqi_req  = cqi_req;
-		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_10MHz_FDD_t),
-				aggregation,
-				sizeof_DCI0_10MHz_FDD_t,
-				format0,
-				0);
-		break;
-		
-	      case 100:
-		ULSCH_dci          = UE_template->ULSCH_DCI[harq_pid];
-		
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->type     = 0;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->hopping  = 0;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->rballoc  = rballoc;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->mcs      = mcs;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->ndi      = ndi;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->TPC      = tpc;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->padding  = 0;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->cshift   = cshift;
-		((DCI0_20MHz_FDD_t *)ULSCH_dci)->cqi_req  = cqi_req;
+	    // save it for a potential retransmission
+            UE_template->cshift[harq_pid] = cshift;	    	    
+	    hi_dci0_pdu                                                         = &eNB->HI_DCI0_req[CC_id].hi_dci0_pdu_list[eNB->HI_DCI0_req[CC_id].number_of_dci+eNB->HI_DCI0_req[CC_id].number_of_hi]; 	
+	    memset((void*)hi_dci0_pdu,0,sizeof(nfapi_hi_dci0_request_pdu_t));
+	    hi_dci0_pdu->pdu_type                                               = NFAPI_HI_DCI0_DCI_PDU_TYPE; 
+	    hi_dci0_pdu->pdu_size                                               = 2+sizeof(nfapi_hi_dci0_dci_pdu);
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dci_format                        = NFAPI_UL_DCI_FORMAT_0;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.aggregation_level                 = aggregation;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.rnti                              = rnti;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.transmission_power                = 6000;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.resource_block_start              = first_rb[CC_id];
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.number_of_resource_block          = rb_table[rb_table_index];
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.mcs_1                             = mcs;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cyclic_shift_2_for_drms           = cshift;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.frequency_hopping_enabled_flag    = 0;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.new_data_indication_1             = ndi;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.tpc                               = tpc;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.cqi_csi_request                   = cqi_req;
+	    hi_dci0_pdu->dci_pdu.dci_pdu_rel8.dl_assignment_index               = UE_template->DAI_ul[sched_subframe];
+
+	    if (!CCE_allocation_infeasible(module_idP,CC_id,2,subframeP,
+					   aggregation,
+					   rnti))
+	      eNB->HI_DCI0_req[CC_id].number_of_dci++;
 		
-		add_ue_spec_dci(DCI_pdu,
-				ULSCH_dci,
-				rnti,
-				sizeof(DCI0_20MHz_FDD_t),
-				aggregation,
-				sizeof_DCI0_20MHz_FDD_t,
-				format0,
-				0);
-		break;
-		
-	      }
-	    }
-
-
 	    add_ue_ulsch_info(module_idP,
 			      CC_id,
 			      UE_id,
@@ -1150,6 +969,16 @@ abort();
               T_INT(subframeP), T_INT(harq_pid), T_INT(mcs), T_INT(first_rb[CC_id]), T_INT(rb_table[rb_table_index]),
               T_INT(round));
 
+	    // fill in NAK information
+	    hi_dci0_pdu                                                         = &eNB->HI_DCI0_req[CC_id].hi_dci0_pdu_list[eNB->HI_DCI0_req[CC_id].number_of_dci+eNB->HI_DCI0_req[CC_id].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.resource_block_start                = UE_template->first_rb_ul[harq_pid];
+	    hi_dci0_pdu->hi_pdu.hi_pdu_rel8.cyclic_shift_2_for_drms             = UE_template->cshift[harq_pid];
+	    hi_dci0_pdu->hi_pdu.hi_pdu_rel8.hi_value                            = 0;
+	    eNB->HI_DCI0_req[CC_id].number_of_hi++;
+
             LOG_D(MAC,"[eNB %d][PUSCH %d/%x] CC_id %d Frame %d subframeP %d Scheduled (PHICH) UE %d (mcs %d, first rb %d, nb_rb %d, rb_table_index %d, TBS %d, harq_pid %d,round %d)\n",
                   module_idP,harq_pid,rnti,CC_id,frameP,subframeP,UE_id,mcs,
                   first_rb[CC_id],rb_table[rb_table_index],
@@ -1183,332 +1012,9 @@ abort();
 	    UE_list->eNB_UE_stats[CC_id][UE_id].ulsch_mcs2=mcs;
 	  }
 	   */
-
+	  
         } // UE_is_to_be_scheduled
-      } // UE is in PUSCH
     } // loop over UE_id
   } // loop of CC_id
 }
 
-#ifdef CBA
-void schedule_ulsch_cba_rnti(module_id_t module_idP, unsigned char cooperation_flag, frame_t frameP, sub_frame_t subframeP, unsigned char sched_subframe, uint16_t *first_rb)
-{
-
-  eNB_MAC_INST *eNB = RC.mac[module_idP];
-  UE_list_t         *UE_list=&eNB->UE_list;
-  //UE_TEMPLATE       *UE_template;
-  void              *ULSCH_dci      = NULL;
-  DCI_PDU *DCI_pdu;
-  uint8_t CC_id=0;
-  uint8_t rb_table_index=0, aggregation=2;
-  uint32_t rballoc;
-  uint8_t cba_group, cba_resources;
-  uint8_t required_rbs[NUM_MAX_CBA_GROUP];
-  int8_t num_cba_resources[NUM_MAX_CBA_GROUP];// , weight[NUM_MAX_CBA_GROUP]
-  // the following vars should become a vector [MAX_NUM_CCs]
-  LTE_DL_FRAME_PARMS   *frame_parms;
-  int8_t available_rbs=0;
-  uint8_t remaining_rbs=0;
-  uint8_t allocated_rbs=0;
-  uint8_t total_UEs=UE_list->num_UEs;
-  uint8_t active_UEs[NUM_MAX_CBA_GROUP];
-  uint8_t total_groups=RC.mac[module_idP]->common_channels[CC_id].num_active_cba_groups;
-  int     min_rb_unit=2;
-  uint8_t cba_policy=CBA_ES;
-  int     UE_id;
-  uint8_t mcs[NUM_MAX_CBA_GROUP];
-  uint32_t total_cba_resources=0;
-  uint32_t total_rbs=0;
-  // We compute the weight of each group and initialize some variables
-
-  // loop over all active UEs
-  //  for (UE_id=UE_list->head_ul;UE_id>=0;UE_id=UE_list->next_ul[UE_id]) {
-
-  for (cba_group=0; cba_group<total_groups; cba_group++) {
-    // UEs in PUSCH with traffic
-    //    weight[cba_group] = 0;
-    required_rbs[cba_group] = 0;
-    num_cba_resources[cba_group]=0;
-    active_UEs[cba_group]=0;
-    mcs[cba_group]=10;//openair_daq_vars.target_ue_ul_mcs;
-  }
-
-  //LOG_D(MAC, "[eNB ] CBA granted ues are %d\n",granted_UEs );
-
-  for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-
-    frame_parms=mac_xface->get_lte_frame_parms(module_idP,CC_id);
-    available_rbs=frame_parms->N_RB_DL-1-first_rb[CC_id];
-    remaining_rbs=available_rbs;
-    total_groups=RC.mac[module_idP]->common_channels[CC_id].num_active_cba_groups;
-    min_rb_unit=get_min_rb_unit(module_idP,CC_id);
-
-    if (available_rbs  < min_rb_unit )
-      continue;
-
-    // remove this condition later
-    // cba group template uses the exisitng UE template, and thus if a UE
-    // is scheduled, the correspodning group can't be used for CBA
-    // this can be fixed later
-    if (total_groups > 0)  {
-      DCI_pdu = &RC.mac[module_idP]->common_channels[CC_id].DCI_pdu;
-
-      for (cba_group=0;
-           (cba_group<total_groups)   > (1<<aggregation));
-           cba_group++) {
-        // equal weight
-        //weight[cba_group] = floor(total_UEs/active_groups);//find_num_active_UEs_in_cbagroup(module_idP, cba_group);
-
-        for (UE_id=UE_list->head_ul; UE_id>=0; UE_id=UE_list->next_ul[UE_id]) {
-          if (UE_RNTI(module_idP,UE_id)==NOT_A_RNTI)
-            continue;
-
-          // simple UE identity based grouping
-          if ((UE_id % total_groups) == cba_group) { // this could be simplifed to  active_UEs[UE_id % total_groups]++;
-            if ((mac_eNB_get_rrc_status(module_idP,rnti) > RRC_CONNECTED) &&
-                (UE_is_to_be_scheduled(module_idP,CC_id,UE_id) == 0)) {
-              active_UEs[cba_group]++;
-            }
-          }
-
-          if (UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul <= 2) {
-            mcs[cba_group]= 8; // apply fixed scheduling
-          } else if ((UE_id % total_groups) == cba_group) {
-            mcs[cba_group]= cmin(mcs[cba_group],UE_list->UE_template[CC_id][UE_id].pre_assigned_mcs_ul);
-          }
-        }
-
-        mcs[cba_group]= mcs[cba_group];//cmin(mcs[cba_group],openair_daq_vars.target_ue_ul_mcs);
-
-        if (available_rbs < min_rb_unit )
-          break;
-
-        // If the group needs some resource
-        // determine the total number of allocations (one or multiple DCIs): to be refined
-        if ((active_UEs[cba_group] > 0) && (RC.mac[module_idP]->common_channels[CC_id].cba_rnti[cba_group] != 0)) {
-          // to be refined in case of : total_UEs >> weight[cba_group]*available_rbs
-
-          switch(cba_policy) {
-          case CBA_ES:
-            required_rbs[cba_group] = (uint8_t)floor(available_rbs/total_groups); // allocate equally among groups
-            num_cba_resources[cba_group]=1;
-            break;
-
-            // can't have more than one allocation for the same group/UE
-            /*  case CBA_ES_S:
-            required_rbs[cba_group] = (uint8_t)floor(available_rbs/total_groups); // allocate equally among groups
-            if (required_rbs[cba_group] > min_rb_unit)
-            num_cba_resources[cba_group]=(uint8_t)(required_rbs[cba_group]/ min_rb_unit);
-            break;*/
-          case CBA_PF:
-            required_rbs[cba_group] = (uint8_t)floor((active_UEs[cba_group]*available_rbs)/total_UEs);
-            num_cba_resources[cba_group]=1;
-            break;
-            /* case CBA_PF_S:
-            required_rbs[cba_group] = (uint8_t)ceil((active_UEs[cba_group]*available_rbs)/total_UEs);
-            if (required_rbs[cba_group] > min_rb_unit)
-            num_cba_resources[cba_group]=(uint8_t) floor(required_rbs[cba_group] / min_rb_unit);
-            break;*/
-
-          default:
-            LOG_W(MAC,"unknown CBA policy\n");
-            break;
-          }
-
-          total_cba_resources+=num_cba_resources[cba_group];
-          total_rbs+=required_rbs[cba_group];
-
-          /*  while ((remaining_rbs < required_rbs[cba_group]) &&
-          (required_rbs[cba_group] > 0) &&
-          (required_rbs[cba_group] < min_rb_unit ))
-          required_rbs[cba_group]--;
-           */
-
-          /*
-          while (rb_table[rb_table_index] < required_rbs[cba_group])
-          rb_table_index++;
-
-          while (rb_table[rb_table_index] > remaining_rbs )
-          rb_table_index--;
-
-          remaining_rbs-=rb_table[rb_table_index];
-          required_rbs[cba_group]=rb_table[rb_table_index];
-           */
-          //    num_cba_resources[cba_group]=1;
-
-        }
-      }
-
-      // phase 2 reduce the number of cba allocations among the groups
-      cba_group=0;
-
-      if (total_cba_resources <= 0) {
-        return;
-      }
-
-      // increase rb if any left: to be done
-      cba_group=0;
-
-      while (total_rbs  < available_rbs - 1 ) {
-        required_rbs[cba_group%total_groups]++;
-        total_rbs++;
-        cba_group++;
-      }
-
-      // phase 3:
-      for (cba_group=0; cba_group<total_groups; cba_group++) {
-
-        LOG_N(MAC,
-              "[eNB %d] CC_id %d Frame %d, subframe %d: cba group %d active_ues %d total groups %d mcs %d, available/required rb (%d/%d), num resources %d, ncce required %d \n",
-              module_idP, CC_id, frameP, subframeP, cba_group,active_UEs[cba_group],total_groups,
-              mcs[cba_group], available_rbs,required_rbs[cba_group],
-              num_cba_resources[cba_group],
-              (1<<aggregation) * num_cba_resources[cba_group]);
-
-        for (cba_resources=0; cba_resources < num_cba_resources[cba_group]; cba_resources++) {
-          rb_table_index =0;
-
-          // check if there was an allocation for this group in the 1st phase
-          if (required_rbs[cba_group] == 0 )
-            continue;
-
-          while (rb_table[rb_table_index] < (uint8_t) ceil(required_rbs[cba_group] / num_cba_resources[cba_group]) ) {
-            rb_table_index++;
-          }
-
-          while (rb_table[rb_table_index] > remaining_rbs ) {
-            rb_table_index--;
-          }
-
-          remaining_rbs-=rb_table[rb_table_index];
-          allocated_rbs=rb_table[rb_table_index];
-
-          rballoc = mac_xface->computeRIV(mac_xface->lte_frame_parms->N_RB_UL,
-                                          first_rb[CC_id],
-                                          rb_table[rb_table_index]);
-
-          first_rb[CC_id]+=rb_table[rb_table_index];
-          LOG_N(MAC,
-                "[eNB %d] CC_id %d Frame %d, subframeP %d: schedule CBA access %d rnti %x, total/required/allocated/remaining rbs (%d/%d/%d/%d), mcs %d, rballoc %d\n",
-                module_idP, CC_id, frameP, subframeP, cba_group,RC.mac[module_idP]->common_channels[CC_id].cba_rnti[cba_group],
-                available_rbs, required_rbs[cba_group], allocated_rbs, remaining_rbs,
-                mcs[cba_group],rballoc);
-
-          switch (frame_parms->N_RB_UL) {
-          case 6:
-            mac_xface->macphy_exit("[MAC][eNB] CBA RB=6 not supported \n");
-            break;
-
-          case 25:
-            if (frame_parms->frame_type == TDD) {
-              ULSCH_dci = UE_list->UE_template[CC_id][cba_group].ULSCH_DCI[0];
-
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->type     = 0;
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->hopping  = 0;
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->rballoc  = rballoc;
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->mcs      = mcs[cba_group];
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->ndi      = 1;
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->TPC      = 1;//tpc;
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cshift   = cba_group;
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->dai      = UE_list->UE_template[CC_id][cba_group].DAI_ul[sched_subframe];
-              ((DCI0_5MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req  = 1;
-
-              //add_ue_spec_dci
-              add_common_dci(DCI_pdu,
-                             ULSCH_dci,
-                             RC.mac[module_idP]->common_channels[CC_id].cba_rnti[cba_group],
-                             sizeof(DCI0_5MHz_TDD_1_6_t),
-                             aggregation,
-                             sizeof_DCI0_5MHz_TDD_1_6_t,
-                             format0,
-                             0);
-            } else {
-              ULSCH_dci = UE_list->UE_template[CC_id][cba_group].ULSCH_DCI[0];
-
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->type     = 0;
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->hopping  = 0;
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->rballoc  = rballoc;
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->mcs      = mcs[cba_group];
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->ndi      = 1;
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->TPC      = 1;//tpc;
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->cshift   = cba_group;
-              ((DCI0_5MHz_FDD_t *)ULSCH_dci)->cqi_req  = 1;
-
-              //add_ue_spec_dci
-              add_common_dci(DCI_pdu,
-                             ULSCH_dci,
-                             RC.mac[module_idP]->common_channels[CC_id].cba_rnti[cba_group],
-                             sizeof(DCI0_5MHz_FDD_t),
-                             aggregation,
-                             sizeof_DCI0_5MHz_FDD_t,
-                             format0,
-                             0);
-            }
-
-            LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for CBA group %d, RB 25 format 0\n", module_idP,CC_id,frameP,subframeP,cba_group);
-            break;
-
-          case 50:
-            if (frame_parms->frame_type == TDD) {
-              ULSCH_dci = UE_list->UE_template[CC_id][cba_group].ULSCH_DCI[0];
-
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->type     = 0;
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->hopping  = 0;
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->rballoc  = rballoc;
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->mcs      = mcs[cba_group];
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->ndi      = 1;
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->TPC      = 1;//tpc;
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cshift   = cba_group;
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->dai      = UE_list->UE_template[CC_id][cba_group].DAI_ul[sched_subframe];
-              ((DCI0_10MHz_TDD_1_6_t *)ULSCH_dci)->cqi_req  = 1;
-
-              //add_ue_spec_dci
-              add_common_dci(DCI_pdu,
-                             ULSCH_dci,
-                             RC.mac[module_idP]->common_channels[CC_id].cba_rnti[cba_group],
-                             sizeof(DCI0_10MHz_TDD_1_6_t),
-                             aggregation,
-                             sizeof_DCI0_10MHz_TDD_1_6_t,
-                             format0,
-                             0);
-            } else {
-              ULSCH_dci = UE_list->UE_template[CC_id][cba_group].ULSCH_DCI[0];
-
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->type     = 0;
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->hopping  = 0;
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->rballoc  = rballoc;
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->mcs      = mcs[cba_group];
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->ndi      = 1;
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->TPC      = 1;//tpc;
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->cshift   = cba_group;
-              ((DCI0_10MHz_FDD_t *)ULSCH_dci)->cqi_req  = 1;
-
-              //add_ue_spec_dci
-              add_common_dci(DCI_pdu,
-                             ULSCH_dci,
-                             RC.mac[module_idP]->common_channels[CC_id].cba_rnti[cba_group],
-                             sizeof(DCI0_10MHz_FDD_t),
-                             aggregation,
-                             sizeof_DCI0_10MHz_FDD_t,
-                             format0,
-                             0);
-            }
-
-            LOG_D(MAC,"[eNB %d] CC_id %d Frame %d, subframeP %d: Generated ULSCH DCI for CBA group %d, RB 50 format 0\n", module_idP,CC_id,frameP,subframeP,cba_group);
-            break;
-
-          case 100:
-            mac_xface->macphy_exit("[MAC][eNB] CBA RB=100 not supported \n");
-            break;
-
-          default:
-            break;
-          }
-
-          //      break;// for the moment only schedule one
-        }
-      }
-    }
-  }
-}
-#endif
diff --git a/openair2/LAYER2/MAC/extern.h b/openair2/LAYER2/MAC/extern.h
index 4a3417d824f7f4b309e3646d6e8db1fdedeaccc8..7058a98798a2f6317f0a42ad1ddffc6ad47fcc55 100644
--- a/openair2/LAYER2/MAC/extern.h
+++ b/openair2/LAYER2/MAC/extern.h
@@ -38,11 +38,7 @@
 #endif //USER_MODE
 #include "PHY/defs.h"
 #include "defs.h"
-#include "COMMON/mac_rrc_primitives.h"
-#ifdef PHY_EMUL
-//#include "SIMULATION/simulation_defs.h"
-#endif //PHY_EMUL
-#include "PHY_INTERFACE/defs.h"
+
 #include "RRC/LITE/defs.h"
 
 extern const uint32_t BSR_TABLE[BSR_TABLE_SIZE];
@@ -58,7 +54,6 @@ extern const uint8_t cqi2fmt2x_agg[MAX_SUPPORTED_BW][CQI_VALUE_RANGE];
 
 extern UE_RRC_INST *UE_rrc_inst;
 extern UE_MAC_INST *UE_mac_inst;
-extern MAC_RLC_XFACE *Mac_rlc_xface;
 extern uint8_t Is_rrc_registered;
 
 extern eNB_ULSCH_INFO eNB_ulsch_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs][NUMBER_OF_UE_MAX]; // eNBxUE = 8x8
@@ -66,13 +61,8 @@ extern eNB_DLSCH_INFO eNB_dlsch_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs][NUMBER_OF_U
 
 
 
-//#ifndef USER_MODE
-extern MAC_xface *mac_xface;
-extern RRC_XFACE *Rrc_xface;
-
 extern uint8_t Is_rrc_registered;
 
-#ifndef PHY_EMUL
 #ifndef PHYSIM
 #define NB_INST 1
 #else
@@ -82,10 +72,6 @@ extern unsigned char NB_eNB_INST;
 extern unsigned char NB_UE_INST;
 extern unsigned char NB_RN_INST;
 extern unsigned short NODE_ID[1];
-extern void* bigphys_malloc(int);
-#else
-extern EMULATION_VARS *Emul_vars;
-#endif //PHY_EMUL
 
 
 extern int cqi_to_mcs[16];
diff --git a/openair2/LAYER2/MAC/l1_helpers.c b/openair2/LAYER2/MAC/l1_helpers.c
index e5dcd5add547aa3613ada2361519d749ed43d487..b136b993a649bc2f0abe172ff88ab232194d2854 100644
--- a/openair2/LAYER2/MAC/l1_helpers.c
+++ b/openair2/LAYER2/MAC/l1_helpers.c
@@ -38,20 +38,12 @@ int8_t get_Po_NOMINAL_PUSCH(module_id_t module_idP,uint8_t CC_id)
 {
   RACH_ConfigCommon_t *rach_ConfigCommon = NULL;
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    //mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return 0; 
-  }
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
+  AssertFatal(UE_mac_inst[module_idP].radioResourceConfigCommon!=NULL,
+	      "[UE %d] CCid %d FATAL radioResourceConfigCommon is NULL !!!\n",module_idP,CC_id);	      
 
-  if (UE_mac_inst[module_idP].radioResourceConfigCommon) {
-    rach_ConfigCommon = &UE_mac_inst[module_idP].radioResourceConfigCommon->rach_ConfigCommon;
-  }
-  else {
-    LOG_E(MAC,"[UE %d] CCid %d FATAL radioResourceConfigCommon is NULL !!!\n",module_idP,CC_id);
-    //mac_xface->macphy_exit("FATAL radioResourceConfigCommon is NULL");
-    return 0;
-  }
+  rach_ConfigCommon = &UE_mac_inst[module_idP].radioResourceConfigCommon->rach_ConfigCommon;
 
   return(-120 + (rach_ConfigCommon->powerRampingParameters.preambleInitialReceivedTargetPower<<1) +
          get_DELTA_PREAMBLE(module_idP,CC_id));
@@ -60,11 +52,8 @@ int8_t get_Po_NOMINAL_PUSCH(module_id_t module_idP,uint8_t CC_id)
 int8_t get_deltaP_rampup(module_id_t module_idP,uint8_t CC_id)
 {
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return 0; // not reached
-  }
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
 
   LOG_D(MAC,"[PUSCH]%d dB\n",UE_mac_inst[module_idP].RA_PREAMBLE_TRANSMISSION_COUNTER<<1);
   return((int8_t)(UE_mac_inst[module_idP].RA_PREAMBLE_TRANSMISSION_COUNTER<<1));
diff --git a/openair2/LAYER2/MAC/main.c b/openair2/LAYER2/MAC/main.c
index 751b5470e4375561cf6681d07f3b2354846d91e6..3e9af4380a25d73a5a59b602ac507462bb232225 100644
--- a/openair2/LAYER2/MAC/main.c
+++ b/openair2/LAYER2/MAC/main.c
@@ -29,37 +29,17 @@
 
  */
 
-#ifdef USER_MODE
-#include "LAYER2/register.h"
-#else
-#ifdef KERNEL2_6
-//#include <linux/config.h>
-#include <linux/slab.h>
-#endif
-
-#ifdef KERNEL2_4
-#include <linux/malloc.h>
-#include <linux/wrapper.h>
-#endif
-
-
-#endif //USER_MODE
-
 #include "defs.h"
 #include "proto.h"
 #include "extern.h"
 #include "assertions.h"
 #include "PHY_INTERFACE/extern.h"
-#include "PHY_INTERFACE/defs.h"
 #include "PHY/defs.h"
 #include "SCHED/defs.h"
 #include "LAYER2/PDCP_v10.1.0/pdcp.h"
 #include "RRC/LITE/defs.h"
 #include "UTIL/LOG/log.h"
 #include "RRC/L2_INTERFACE/openair_rrc_L2_interface.h"
-#ifdef PHY_EMUL
-#include "SIMULATION/simulation_defs.h"
-#endif //PHY_EMUL
 
 #include "SCHED/defs.h"
 
@@ -112,10 +92,8 @@ int mac_top_init_ue(int eMBMS_active, char *uecap_xer, uint8_t cba_group_active,
   if (NB_UE_INST>0) {
     UE_mac_inst = (UE_MAC_INST*)malloc16(NB_UE_INST*sizeof(UE_MAC_INST));
 
-    if (UE_mac_inst == NULL) {
-      LOG_C(MAC,"[MAIN] Can't ALLOCATE %zu Bytes for %d UE_MAC_INST with size %zu \n",NB_UE_INST*sizeof(UE_MAC_INST),NB_UE_INST,sizeof(UE_MAC_INST));
-      mac_xface->macphy_exit("[MAC][MAIN] not enough memory for UEs \n");
-    }
+    AssertFatal(UE_mac_inst!=NULL,
+		"[MAIN] Can't ALLOCATE %zu Bytes for %d UE_MAC_INST with size %zu \n",NB_UE_INST*sizeof(UE_MAC_INST),NB_UE_INST,sizeof(UE_MAC_INST));
 
     LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d UE_MAC_INST @ %p\n",NB_UE_INST*sizeof(UE_MAC_INST),NB_UE_INST,UE_mac_inst);
 
@@ -128,19 +106,15 @@ int mac_top_init_ue(int eMBMS_active, char *uecap_xer, uint8_t cba_group_active,
     UE_mac_inst = NULL;
   }
 
-  LOG_I(MAC,"[MAIN] Init function start:Nb_eNB_INST=%d\n",NB_eNB_INST);
 
   if (NB_eNB_INST>0) {
     RC.mac = (eNB_MAC_INST**)malloc16(NB_eNB_INST*sizeof(eNB_MAC_INST*));
     for (i=0;i<NB_eNB_INST;i++)
       RC.mac[i] = (eNB_MAC_INST*)malloc16(sizeof(eNB_MAC_INST));
-    if (RC.mac == NULL) {
-      LOG_D(MAC,"[MAIN] can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",NB_eNB_INST*sizeof(eNB_MAC_INST*),NB_eNB_INST,sizeof(eNB_MAC_INST));
-      mac_xface->macphy_exit("[MAC][MAIN] not enough memory for eNB \n");
-    } else {
-      LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d eNB_MAC_INST @ %p\n",sizeof(eNB_MAC_INST),NB_eNB_INST,RC.mac);
-      for (i=0;i<NB_eNB_INST;i++) bzero(RC.mac[i],sizeof(eNB_MAC_INST));
-    }
+    AssertFatal(RC.mac != NULL,
+		"[MAIN] can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",NB_eNB_INST*sizeof(eNB_MAC_INST*),NB_eNB_INST,sizeof(eNB_MAC_INST));
+    LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d eNB_MAC_INST @ %p\n",sizeof(eNB_MAC_INST),NB_eNB_INST,RC.mac);
+    for (i=0;i<NB_eNB_INST;i++) bzero(RC.mac[i],sizeof(eNB_MAC_INST));
   } else {
     RC.mac = NULL;
   }
@@ -163,125 +137,10 @@ int mac_top_init_ue(int eMBMS_active, char *uecap_xer, uint8_t cba_group_active,
     UE_list->next_ul[list_el]=-1;
   }
 
-  if (Is_rrc_registered == 1) {
-    LOG_I(MAC,"[MAIN] calling RRC\n");
-#ifndef CELLULAR //nothing to be done yet for cellular
-    openair_rrc_top_init_ue(eMBMS_active, uecap_xer, cba_group_active,HO_active);
-#endif
-  } else {
-    LOG_I(MAC,"[MAIN] Running without an RRC\n");
-  }
-  
-  for (i=0; i<NB_eNB_INST; i++)
-    for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
-      LOG_D(MAC,"[MAIN][eNB %d] CC_id %d initializing RA_template\n",i, CC_id);
-      LOG_D(MAC, "[MSC_NEW][FRAME 00000][MAC_eNB][MOD %02d][]\n", i);
-
-      cc = &RC.mac[i]->common_channels[CC_id];
-      RA_template = &cc->RA_template[0];
-
-
-      for (j=0; j<NB_RA_PROC_MAX; j++) {
-        if (cc->tdd_Config != NULL) { // TDD
-          switch (to_prb(cc->mib->message.dl_Bandwidth)) {
-          case 6:
-            size_bytes1 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-            size_bytes2 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-            size_bits1 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-            size_bits2 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-            break;
-
-          case 25:
-            size_bytes1 = sizeof(DCI1A_5MHz_TDD_1_6_t);
-            size_bytes2 = sizeof(DCI1A_5MHz_TDD_1_6_t);
-            size_bits1 = sizeof_DCI1A_5MHz_TDD_1_6_t;
-            size_bits2 = sizeof_DCI1A_5MHz_TDD_1_6_t;
-            break;
-
-          case 50:
-            size_bytes1 = sizeof(DCI1A_10MHz_TDD_1_6_t);
-            size_bytes2 = sizeof(DCI1A_10MHz_TDD_1_6_t);
-            size_bits1 = sizeof_DCI1A_10MHz_TDD_1_6_t;
-            size_bits2 = sizeof_DCI1A_10MHz_TDD_1_6_t;
-            break;
-
-          case 100:
-            size_bytes1 = sizeof(DCI1A_20MHz_TDD_1_6_t);
-            size_bytes2 = sizeof(DCI1A_20MHz_TDD_1_6_t);
-            size_bits1 = sizeof_DCI1A_20MHz_TDD_1_6_t;
-            size_bits2 = sizeof_DCI1A_20MHz_TDD_1_6_t;
-            break;
-
-          default:
-            size_bytes1 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-            size_bytes2 = sizeof(DCI1A_1_5MHz_TDD_1_6_t);
-            size_bits1 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-            size_bits2 = sizeof_DCI1A_1_5MHz_TDD_1_6_t;
-            break;
-          }
-
-        } else {
-          switch (to_prb(cc->mib->message.dl_Bandwidth)) {
-          case 6:
-            size_bytes1 = sizeof(DCI1A_1_5MHz_FDD_t);
-            size_bytes2 = sizeof(DCI1A_1_5MHz_FDD_t);
-            size_bits1 = sizeof_DCI1A_1_5MHz_FDD_t;
-            size_bits2 = sizeof_DCI1A_1_5MHz_FDD_t;
-            break;
-
-          case 25:
-            size_bytes1 = sizeof(DCI1A_5MHz_FDD_t);
-            size_bytes2 = sizeof(DCI1A_5MHz_FDD_t);
-            size_bits1 = sizeof_DCI1A_5MHz_FDD_t;
-            size_bits2 = sizeof_DCI1A_5MHz_FDD_t;
-            break;
-
-          case 50:
-            size_bytes1 = sizeof(DCI1A_10MHz_FDD_t);
-            size_bytes2 = sizeof(DCI1A_10MHz_FDD_t);
-            size_bits1 = sizeof_DCI1A_10MHz_FDD_t;
-            size_bits2 = sizeof_DCI1A_10MHz_FDD_t;
-            break;
-
-          case 100:
-            size_bytes1 = sizeof(DCI1A_20MHz_FDD_t);
-            size_bytes2 = sizeof(DCI1A_20MHz_FDD_t);
-            size_bits1 = sizeof_DCI1A_20MHz_FDD_t;
-            size_bits2 = sizeof_DCI1A_20MHz_FDD_t;
-            break;
-
-          default:
-            size_bytes1 = sizeof(DCI1A_1_5MHz_FDD_t);
-            size_bytes2 = sizeof(DCI1A_1_5MHz_FDD_t);
-            size_bits1 = sizeof_DCI1A_1_5MHz_FDD_t;
-            size_bits2 = sizeof_DCI1A_1_5MHz_FDD_t;
-            break;
-          }
-        }
-
-        memcpy((void *)&RA_template[j].RA_alloc_pdu1[0],(void *)&RA_alloc_pdu,size_bytes1);
-        memcpy((void *)&RA_template[j].RA_alloc_pdu2[0],(void *)&DLSCH_alloc_pdu1A,size_bytes2);
-        RA_template[j].RA_dci_size_bytes1 = size_bytes1;
-        RA_template[j].RA_dci_size_bytes2 = size_bytes2;
-        RA_template[j].RA_dci_size_bits1  = size_bits1;
-        RA_template[j].RA_dci_size_bits2  = size_bits2;
-
-        RA_template[j].RA_dci_fmt1        = format1A;
-        RA_template[j].RA_dci_fmt2        = format1A;
-      }
-
-      memset (&RC.mac[i]->eNB_stats,0,sizeof(eNB_STATS));
-      UE_template = (UE_TEMPLATE *)&RC.mac[i]->UE_list.UE_template[CC_id][0];
-
-      for (j=0; j<NUMBER_OF_UE_MAX; j++) {
-        UE_template[j].rnti=0;
-        // initiallize the eNB to UE statistics
-        memset (&RC.mac[i]->UE_list.eNB_UE_stats[CC_id][j],0,sizeof(eNB_UE_STATS));
-      }
-    }
-
-
+  LOG_I(MAC,"[MAIN] calling RRC\n");
+  openair_rrc_top_init_ue(eMBMS_active, uecap_xer, cba_group_active,HO_active);
 
+  
   LOG_I(MAC,"[MAIN][INIT] Init function finished\n");
 
   return(0);
@@ -292,31 +151,43 @@ int mac_top_init_ue(int eMBMS_active, char *uecap_xer, uint8_t cba_group_active,
 int mac_top_init_eNB()
 {
 
-  module_id_t    Mod_id,i;
+  module_id_t    Mod_id,i,j;
   int list_el;
   UE_list_t *UE_list;
   eNB_MAC_INST *mac;
 
-  LOG_I(MAC,"[MAIN] Init function start:Nb_eNB_INST=%d\n",RC.nb_inst);
+  LOG_I(MAC,"[MAIN] Init function start:nb_macrlc_inst=%d\n",RC.nb_macrlc_inst);
 
-  if (RC.nb_inst>0) {
-    RC.mac = (eNB_MAC_INST**)malloc16(RC.nb_inst*sizeof(eNB_MAC_INST*));
-    for (i=0;i<RC.nb_inst;i++)
+  if (RC.nb_macrlc_inst>0) {
+    RC.mac = (eNB_MAC_INST**)malloc16(RC.nb_macrlc_inst*sizeof(eNB_MAC_INST*));
+    AssertFatal(RC.mac != NULL,"can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",
+		RC.nb_macrlc_inst*sizeof(eNB_MAC_INST*),
+		RC.nb_macrlc_inst,
+		sizeof(eNB_MAC_INST));
+    for (i=0;i<RC.nb_macrlc_inst;i++) {
       RC.mac[i] = (eNB_MAC_INST*)malloc16(sizeof(eNB_MAC_INST));
-    if (RC.mac == NULL) {
-      LOG_D(MAC,"[MAIN] can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",RC.nb_inst*sizeof(eNB_MAC_INST*),RC.nb_inst,sizeof(eNB_MAC_INST));
-      mac_xface->macphy_exit("[MAC][MAIN] not enough memory for eNB \n");
-    } else {
-      LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d eNB_MAC_INST @ %p\n",sizeof(eNB_MAC_INST),RC.nb_inst,RC.mac);
-      for (i=0;i<RC.nb_inst;i++) bzero(RC.mac[i],sizeof(eNB_MAC_INST));
+      AssertFatal(RC.mac != NULL,
+		  "can't ALLOCATE %zu Bytes for %d eNB_MAC_INST with size %zu \n",
+		  RC.nb_macrlc_inst*sizeof(eNB_MAC_INST*),RC.nb_macrlc_inst,sizeof(eNB_MAC_INST));
+      LOG_D(MAC,"[MAIN] ALLOCATE %zu Bytes for %d eNB_MAC_INST @ %p\n",sizeof(eNB_MAC_INST),RC.nb_macrlc_inst,RC.mac);
+      bzero(RC.mac[i],sizeof(eNB_MAC_INST));
+      for (j=0;j<MAX_NUM_CCs;j++) {
+	RC.mac[i]->DL_req[j].dl_config_pdu_list    = RC.mac[i]->dl_config_pdu_list[j];
+	RC.mac[i]->UL_req[j].ul_config_pdu_list    = RC.mac[i]->ul_config_pdu_list[j];
+	RC.mac[i]->HI_DCI0_req[j].hi_dci0_pdu_list = RC.mac[i]->hi_dci0_pdu_list[j];
+	RC.mac[i]->TX_req[j].tx_pdu_list           = RC.mac[i]->tx_request_pdu[j];
+      }
     }
   } else {
     RC.mac = NULL;
   }
-
+  
   // Initialize Linked-List for Active UEs
-  for(Mod_id=0; Mod_id<RC.nb_inst; Mod_id++) {
+  for(Mod_id=0; Mod_id<RC.nb_macrlc_inst; Mod_id++) {
     mac = RC.mac[Mod_id];
+
+    mac->if_inst                = IF_Module_init(Mod_id);
+
     UE_list = &mac->UE_list;
 
     UE_list->num_UEs=0;
@@ -459,21 +330,6 @@ int rlcmac_init_global_param(void)
     return(-1);
   }
 
-  LOG_I(MAC,"[MAIN] RLC_MODULE_INIT OK, malloc16 for mac_rlc_xface...\n");
-
-  Mac_rlc_xface = (MAC_RLC_XFACE*)malloc16(sizeof(MAC_RLC_XFACE));
-  bzero(Mac_rlc_xface,sizeof(MAC_RLC_XFACE));
-
-  if(Mac_rlc_xface == NULL) {
-    LOG_E(MAC,"[MAIN] FATAL EROOR: Could not allocate memory for Mac_rlc_xface !!!\n");
-    return (-1);
-
-  }
-
-  LOG_I(MAC,"[MAIN] malloc16 OK, mac_rlc_xface @ %p\n",(void *)Mac_rlc_xface);
-
-
-
   pdcp_layer_init ();
 
   LOG_I(MAC,"[MAIN] Init Global Param Done\n");
@@ -493,120 +349,21 @@ void mac_top_cleanup(void)
     free (UE_mac_inst);
   }
 
-  if (RC.nb_inst>0) {
+  if (RC.nb_macrlc_inst>0) {
     free(RC.mac);
   }
 
-  free( Mac_rlc_xface);
-
-  free(mac_xface);
 }
 
 int l2_init_ue(int eMBMS_active, char *uecap_xer,uint8_t cba_group_active, uint8_t HO_active)
 {
-
-
-
   LOG_I(MAC,"[MAIN] MAC_INIT_GLOBAL_PARAM IN...\n");
   //    NB_NODE=2;
   //    NB_INST=2;
 
-  Is_rrc_registered=0;
   rlcmac_init_global_param();
-  Is_rrc_registered=1;
-
-  mac_xface->dl_phy_sync_success=dl_phy_sync_success;
-  mac_xface->out_of_sync_ind=rrc_out_of_sync_ind;
-
-
-  mac_xface->macphy_init = mac_top_init_ue;
-#ifndef USER_MODE
-  mac_xface->macphy_exit = openair_sched_exit;
-#else
-  mac_xface->macphy_exit=(void (*)(const char*)) exit;
-#endif
   LOG_I(MAC,"[MAIN] init UE MAC functions \n");
-  mac_xface->ue_decode_si              = ue_decode_si;
-  mac_xface->ue_decode_p               = ue_decode_p;
-  mac_xface->ue_send_sdu               = ue_send_sdu;
-#if defined(Rel10) || defined(Rel14)
-  mac_xface->ue_send_mch_sdu           = ue_send_mch_sdu;
-  mac_xface->ue_query_mch              = ue_query_mch;
-#endif
-  mac_xface->ue_get_SR                 = ue_get_SR;
-  mac_xface->ue_get_sdu                = ue_get_sdu;
-  mac_xface->ue_get_rach               = ue_get_rach;
-  mac_xface->ue_process_rar            = ue_process_rar;
-  mac_xface->ue_scheduler              = ue_scheduler;
-  mac_xface->process_timing_advance    = process_timing_advance;
-  mac_xface->Msg3_transmitted          = Msg3_tx;
-  mac_xface->Msg1_transmitted          = Msg1_tx;
-  mac_xface->ra_failed                 = ra_failed;
-  mac_xface->ra_succeeded              = ra_succeeded;
-
-
-  LOG_I(MAC,"[MAIN] PHY Frame configuration \n");
-
-  mac_xface->get_ue_active_harq_pid = get_ue_active_harq_pid;
-  mac_xface->get_PL                 = get_PL;
-  mac_xface->get_RSRP               = get_RSRP;
-  mac_xface->get_RSRQ               = get_RSRQ;
-  mac_xface->get_RSSI               = get_RSSI;
-  mac_xface->get_n_adj_cells        = get_n_adj_cells;
-  mac_xface->get_rx_total_gain_dB   = get_rx_total_gain_dB;
-  mac_xface->get_Po_NOMINAL_PUSCH   = get_Po_NOMINAL_PUSCH;
-  mac_xface->get_num_prach_tdd      = get_num_prach_tdd;
-  mac_xface->get_fid_prach_tdd      = get_fid_prach_tdd;
-  mac_xface->get_deltaP_rampup      = get_deltaP_rampup;
-  mac_xface->computeRIV             = computeRIV;
-  mac_xface->get_TBS_DL             = get_TBS_DL;
-  mac_xface->get_TBS_UL             = get_TBS_UL;
-  mac_xface->get_nCCE_max           = get_nCCE_mac;
-  mac_xface->get_nCCE_offset        = get_nCCE_offset;
-  mac_xface->get_ue_mode            = get_ue_mode;
-  mac_xface->phy_config_sib1_ue     = phy_config_sib1_ue;
-
-  mac_xface->phy_config_sib2_ue         = phy_config_sib2_ue;
-  mac_xface->phy_config_afterHO_ue      = phy_config_afterHO_ue;
-#if defined(Rel10) || defined(Rel14)
-  mac_xface->phy_config_sib13_eNB        = phy_config_sib13_eNB;
-  mac_xface->phy_config_sib13_ue         = phy_config_sib13_ue;
-#endif
-#ifdef CBA
-  mac_xface->phy_config_cba_rnti         = phy_config_cba_rnti ;
-#endif
-  mac_xface->estimate_ue_tx_power        = estimate_ue_tx_power;
-  mac_xface->phy_config_meas_ue          = phy_config_meas_ue;
-  mac_xface->phy_reset_ue    = phy_reset_ue;
-
-  mac_xface->phy_config_dedicated_ue     = phy_config_dedicated_ue;
-  mac_xface->phy_config_harq_ue          = phy_config_harq_ue;
-
-  mac_xface->get_lte_frame_parms        = get_lte_frame_parms;
-  mac_xface->get_mu_mimo_mode           = get_mu_mimo_mode;
-
-  mac_xface->get_hundred_times_delta_TF = get_hundred_times_delta_IF_mac;
-  mac_xface->get_target_pusch_rx_power     = get_target_pusch_rx_power;
-  mac_xface->get_target_pucch_rx_power     = get_target_pucch_rx_power;
-
-  mac_xface->get_prach_prb_offset       = get_prach_prb_offset;
-  mac_xface->is_prach_subframe          = is_prach_subframe;
-
-#if defined(Rel10) || defined(Rel14)
-  mac_xface->get_mch_sdu                 = get_mch_sdu;
-  mac_xface->phy_config_dedicated_scell_ue= phy_config_dedicated_scell_ue;
-
-#endif
-
-  mac_xface->get_PHR = get_PHR;
-  LOG_D(MAC,"[MAIN] ALL INIT OK\n");
-
-  mac_xface->macphy_init(eMBMS_active,uecap_xer,cba_group_active,HO_active);
-
-  //Mac_rlc_xface->Is_cluster_head[0] = 1;
-  //Mac_rlc_xface->Is_cluster_head[1] = 0;
-
-
+  mac_top_init_ue(eMBMS_active,uecap_xer,cba_group_active,HO_active);
   return(1);
 }
 
@@ -614,101 +371,15 @@ int l2_init_eNB()
 {
 
 
+  int i;
 
   LOG_I(MAC,"[MAIN] MAC_INIT_GLOBAL_PARAM IN...\n");
-  //    NB_NODE=2;
-  //    NB_INST=2;
 
-  Is_rrc_registered=0;
   rlcmac_init_global_param();
-  Is_rrc_registered=1;
-
-  mac_xface = (MAC_xface *)malloc(sizeof(MAC_xface));
-
-  mac_xface->macphy_init = mac_top_init_eNB;
-#ifndef USER_MODE
-  mac_xface->macphy_exit = openair_sched_exit;
-#else
-  mac_xface->macphy_exit=(void (*)(const char*)) exit;
-#endif
-  LOG_I(MAC,"[MAIN] init eNB MAC functions  \n");
-  mac_xface->eNB_dlsch_ulsch_scheduler = eNB_dlsch_ulsch_scheduler;
-  mac_xface->get_dci_sdu               = get_dci_sdu;
-  mac_xface->fill_rar                  = fill_rar;
-  mac_xface->initiate_ra_proc          = initiate_ra_proc;
-  mac_xface->cancel_ra_proc            = cancel_ra_proc;
-  mac_xface->set_msg3_subframe         = set_msg3_subframe;
-  mac_xface->SR_indication             = SR_indication;
-  mac_xface->UL_failure_indication     = UL_failure_indication;
-  mac_xface->rx_sdu                    = rx_sdu;
-  mac_xface->get_dlsch_sdu             = get_dlsch_sdu;
-  mac_xface->get_eNB_UE_stats          = get_UE_stats;
-  mac_xface->get_transmission_mode     = get_transmission_mode;
-  mac_xface->get_rballoc               = get_rballoc;
-  mac_xface->get_nb_rb                 = conv_nprb;
-  mac_xface->get_prb                   = get_prb;
-  //  mac_xface->get_SB_size               = Get_SB_size;
-  mac_xface->get_subframe_direction    = get_subframe_direction;
-  mac_xface->mac_phy_remove_ue         = mac_phy_remove_ue;
-
-  LOG_I(MAC,"[MAIN] PHY Frame configuration \n");
-
-  mac_xface->get_ue_active_harq_pid = get_ue_active_harq_pid;
-  mac_xface->get_PL                 = get_PL;
-  mac_xface->get_RSRP               = get_RSRP;
-  mac_xface->get_RSRQ               = get_RSRQ;
-  mac_xface->get_RSSI               = get_RSSI;
-  mac_xface->get_n_adj_cells        = get_n_adj_cells;
-  mac_xface->get_rx_total_gain_dB   = get_rx_total_gain_dB;
-  mac_xface->get_Po_NOMINAL_PUSCH   = get_Po_NOMINAL_PUSCH;
-  mac_xface->get_num_prach_tdd      = get_num_prach_tdd;
-  mac_xface->get_fid_prach_tdd      = get_fid_prach_tdd;
-  mac_xface->get_deltaP_rampup      = get_deltaP_rampup;
-  mac_xface->computeRIV             = computeRIV;
-  mac_xface->get_TBS_DL             = get_TBS_DL;
-  mac_xface->get_TBS_UL             = get_TBS_UL;
-  mac_xface->get_nCCE_max           = get_nCCE_mac;
-  mac_xface->get_nCCE_offset        = get_nCCE_offset;
-  mac_xface->get_ue_mode            = get_ue_mode;
-  mac_xface->phy_config_mib_eNB     = phy_config_mib_eNB;
-  mac_xface->phy_config_sib1_eNB    = phy_config_sib1_eNB;
-  mac_xface->phy_config_sib1_ue     = phy_config_sib1_ue;
-
-  mac_xface->phy_config_sib2_eNB        = phy_config_sib2_eNB;
-#ifdef Rel10
-  mac_xface->phy_config_sib13_eNB        = phy_config_sib13_eNB;
-#endif
-#ifdef CBA
-  mac_xface->phy_config_cba_rnti         = phy_config_cba_rnti ;
-#endif
-  mac_xface->estimate_ue_tx_power        = estimate_ue_tx_power;
-
-  mac_xface->phy_config_dedicated_eNB    = phy_config_dedicated_eNB;
-  mac_xface->get_lte_frame_parms        = get_lte_frame_parms;
-  mac_xface->get_mu_mimo_mode           = get_mu_mimo_mode;
-
-  mac_xface->get_hundred_times_delta_TF = get_hundred_times_delta_IF_mac;
-  mac_xface->get_target_pusch_rx_power     = get_target_pusch_rx_power;
-  mac_xface->get_target_pucch_rx_power     = get_target_pucch_rx_power;
-
-  mac_xface->get_prach_prb_offset       = get_prach_prb_offset;
-  mac_xface->is_prach_subframe          = is_prach_subframe;
 
-#ifdef Rel10
-  mac_xface->get_mch_sdu                 = get_mch_sdu;
-  mac_xface->phy_config_dedicated_scell_eNB= phy_config_dedicated_scell_eNB;
-  mac_xface->phy_config_dedicated_scell_ue= phy_config_dedicated_scell_ue;
-
-#endif
-
-  mac_xface->get_PHR = get_PHR;
   LOG_D(MAC,"[MAIN] ALL INIT OK\n");
 
 
-  //Mac_rlc_xface->Is_cluster_head[0] = 1;
-  //Mac_rlc_xface->Is_cluster_head[1] = 0;
-
-
   return(1);
 }
 
diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c
index 79278edf741466f23f17a63bb804b7b54e00f883..41fa379ae21b1fdeeb623c1781357fefafe4b24e 100644
--- a/openair2/LAYER2/MAC/pre_processor.c
+++ b/openair2/LAYER2/MAC/pre_processor.c
@@ -68,6 +68,7 @@
 /* this function checks that get_eNB_UE_stats returns
  * a non-NULL pointer for all the active CCs of an UE
  */
+/*
 int phy_stats_exist(module_id_t Mod_id, int rnti)
 {
   int CC_id;
@@ -91,6 +92,7 @@ int phy_stats_exist(module_id_t Mod_id, int rnti)
   }
   return 1;
 }
+*/
 
 // This function stores the downlink buffer for all the logical channels
 void store_dlsch_buffer (module_id_t Mod_id,
@@ -175,12 +177,11 @@ void assign_rbs_required (module_id_t Mod_id,
                           int         min_rb_unit[MAX_NUM_CCs])
 {
 
-
-  rnti_t           rnti;
   uint16_t         TBS = 0;
-  LTE_eNB_UE_stats *eNB_UE_stats[MAX_NUM_CCs];
+
   int              UE_id,n,i,j,CC_id,pCCid,tmp;
   UE_list_t        *UE_list = &RC.mac[Mod_id]->UE_list;
+  eNB_UE_STATS     *eNB_UE_stats,*eNB_UE_stats_i,*eNB_UE_stats_j;
   int N_RB_DL;
 
   // clear rb allocations across all CC_id
@@ -188,34 +189,24 @@ void assign_rbs_required (module_id_t Mod_id,
     if (UE_list->active[UE_id] != TRUE) continue;
 
     pCCid = UE_PCCID(Mod_id,UE_id);
-    rnti = UE_list->UE_template[pCCid][UE_id].rnti;
-
-    /* skip UE not present in PHY (for any of its active CCs) */
-    if (!phy_stats_exist(Mod_id, rnti))
-      continue;
-
+    eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
     //update CQI information across component carriers
     for (n=0; n<UE_list->numactiveCCs[UE_id]; n++) {
 
       CC_id = UE_list->ordered_CCids[n][UE_id];
-      eNB_UE_stats[CC_id] = mac_xface->get_eNB_UE_stats(Mod_id,CC_id,rnti);
-      /*
-      DevCheck(((eNB_UE_stats[CC_id]->DL_cqi[0] < MIN_CQI_VALUE) || (eNB_UE_stats[CC_id]->DL_cqi[0] > MAX_CQI_VALUE)),
-      eNB_UE_stats[CC_id]->DL_cqi[0], MIN_CQI_VALUE, MAX_CQI_VALUE);
-      */
-      eNB_UE_stats[CC_id]->dlsch_mcs1=cqi_to_mcs[eNB_UE_stats[CC_id]->DL_cqi[0]];
 
-      eNB_UE_stats[CC_id]->dlsch_mcs1 = eNB_UE_stats[CC_id]->dlsch_mcs1;//cmin(eNB_UE_stats[CC_id]->dlsch_mcs1,openair_daq_vars.target_ue_dl_mcs);
+      eNB_UE_stats->dlsch_mcs1=cqi_to_mcs[eNB_UE_stats->dl_cqi];
 
     }
 
     // provide the list of CCs sorted according to MCS
     for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) {
+      eNB_UE_stats_i = &UE_list->eNB_UE_stats[UE_list->ordered_CCids[i][UE_id]][UE_id];
       for (j=i+1; j<UE_list->numactiveCCs[UE_id]; j++) {
         DevAssert( j < MAX_NUM_CCs );
-
-        if (eNB_UE_stats[UE_list->ordered_CCids[i][UE_id]]->dlsch_mcs1 >
-            eNB_UE_stats[UE_list->ordered_CCids[j][UE_id]]->dlsch_mcs1) {
+	eNB_UE_stats_j = &UE_list->eNB_UE_stats[UE_list->ordered_CCids[j][UE_id]][UE_id];
+        if (eNB_UE_stats_j->dlsch_mcs1 >
+            eNB_UE_stats_i->dlsch_mcs1) {
           tmp = UE_list->ordered_CCids[i][UE_id];
           UE_list->ordered_CCids[i][UE_id] = UE_list->ordered_CCids[j][UE_id];
           UE_list->ordered_CCids[j][UE_id] = tmp;
@@ -228,19 +219,19 @@ void assign_rbs_required (module_id_t Mod_id,
 
       for (i=0; i<UE_list->numactiveCCs[UE_id]; i++) {
         CC_id = UE_list->ordered_CCids[i][UE_id];
-        eNB_UE_stats[CC_id] = mac_xface->get_eNB_UE_stats(Mod_id,CC_id,rnti);
+	eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
 
-        if (eNB_UE_stats[CC_id]->dlsch_mcs1==0) {
+        if (eNB_UE_stats->dlsch_mcs1==0) {
           nb_rbs_required[CC_id][UE_id] = 4;  // don't let the TBS get too small
         } else {
           nb_rbs_required[CC_id][UE_id] = min_rb_unit[CC_id];
         }
 
-        TBS = mac_xface->get_TBS_DL(eNB_UE_stats[CC_id]->dlsch_mcs1,nb_rbs_required[CC_id][UE_id]);
+        TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_rbs_required[CC_id][UE_id]);
 
         LOG_D(MAC,"[preprocessor] start RB assignement for UE %d CC_id %d dl buffer %d (RB unit %d, MCS %d, TBS %d) \n",
               UE_id, CC_id, UE_list->UE_template[pCCid][UE_id].dl_buffer_total,
-              nb_rbs_required[CC_id][UE_id],eNB_UE_stats[CC_id]->dlsch_mcs1,TBS);
+              nb_rbs_required[CC_id][UE_id],eNB_UE_stats->dlsch_mcs1,TBS);
 
 	N_RB_DL = to_prb(RC.mac[Mod_id]->common_channels[CC_id].mib->message.dl_Bandwidth);
 
@@ -249,16 +240,16 @@ void assign_rbs_required (module_id_t Mod_id,
           nb_rbs_required[CC_id][UE_id] += min_rb_unit[CC_id];
 
           if (nb_rbs_required[CC_id][UE_id] > N_RB_DL) {
-            TBS = mac_xface->get_TBS_DL(eNB_UE_stats[CC_id]->dlsch_mcs1,N_RB_DL);
+            TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,N_RB_DL);
             nb_rbs_required[CC_id][UE_id] = N_RB_DL;
             break;
           }
 
-          TBS = mac_xface->get_TBS_DL(eNB_UE_stats[CC_id]->dlsch_mcs1,nb_rbs_required[CC_id][UE_id]);
+          TBS = get_TBS_DL(eNB_UE_stats->dlsch_mcs1,nb_rbs_required[CC_id][UE_id]);
         } // end of while
 
         LOG_D(MAC,"[eNB %d] Frame %d: UE %d on CC %d: RB unit %d,  nb_required RB %d (TBS %d, mcs %d)\n",
-              Mod_id, frameP,UE_id, CC_id,  min_rb_unit[CC_id], nb_rbs_required[CC_id][UE_id], TBS, eNB_UE_stats[CC_id]->dlsch_mcs1);
+              Mod_id, frameP,UE_id, CC_id,  min_rb_unit[CC_id], nb_rbs_required[CC_id][UE_id], TBS, eNB_UE_stats->dlsch_mcs1);
       }
     }
   }
@@ -291,23 +282,17 @@ int maxround(module_id_t Mod_id,uint16_t rnti,int frame,sub_frame_t subframe,uin
 int maxcqi(module_id_t Mod_id,int32_t UE_id)
 {
 
-  LTE_eNB_UE_stats *eNB_UE_stats = NULL;
+  eNB_UE_STATS *eNB_UE_stats = NULL;
   UE_list_t *UE_list = &RC.mac[Mod_id]->UE_list;
   int CC_id,n;
   int CQI = 0;
 
   for (n=0; n<UE_list->numactiveCCs[UE_id]; n++) {
     CC_id = UE_list->ordered_CCids[n][UE_id];
-    eNB_UE_stats = mac_xface->get_eNB_UE_stats(Mod_id,CC_id,UE_RNTI(Mod_id,UE_id));
+    eNB_UE_stats = &UE_list->eNB_UE_stats[CC_id][UE_id];
 
-    if (eNB_UE_stats==NULL) {
-      /* the UE may have been removed in the PHY layer, don't exit */
-      //mac_xface->macphy_exit("maxcqi: could not get eNB_UE_stats\n");
-      return -1;
-    }
-
-    if (eNB_UE_stats->DL_cqi[0] > CQI) {
-      CQI = eNB_UE_stats->DL_cqi[0];
+    if (eNB_UE_stats->dl_cqi > CQI) {
+      CQI = eNB_UE_stats->dl_cqi;
     }
   }
 
@@ -414,8 +399,6 @@ void sort_UEs (module_id_t Mod_idP,
       continue;
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
       continue;
-    if (!phy_stats_exist(Mod_idP, rnti))
-      continue;
     list[list_size] = i;
     list_size++;
   }
@@ -452,8 +435,6 @@ void sort_UEs (module_id_t Mod_idP,
 	continue;
       if (UE_list->UE_sched_ctrl[UE_id1].ul_out_of_sync == 1)
 	continue;
-      if (!phy_stats_exist(Mod_idP, rnti1))
-        continue;
       pCC_id1 = UE_PCCID(Mod_idP,UE_id1);
       cqi1    = maxcqi(Mod_idP,UE_id1); //
       round1  = maxround(Mod_idP,rnti1,frameP,subframeP,0);
@@ -464,8 +445,6 @@ void sort_UEs (module_id_t Mod_idP,
         continue;
       if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1)
 	continue;
-      if (!phy_stats_exist(Mod_idP, rnti2))
-        continue;
       cqi2    = maxcqi(Mod_idP,UE_id2);
       round2  = maxround(Mod_idP,rnti2,frameP,subframeP,0);  //mac_xface->get_ue_active_harq_pid(Mod_id,rnti2,subframe,&harq_pid2,&round2,0);
       pCC_id2 = UE_PCCID(Mod_idP,UE_id2);
@@ -596,8 +575,6 @@ void dlsch_scheduler_pre_processor (module_id_t   Mod_id,
       continue;
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
       continue;
-    if (!phy_stats_exist(Mod_id, rnti))
-      continue;
     UE_id = i;
 
     for (ii=0; ii<UE_num_active_CC(UE_list,UE_id); ii++) {
@@ -654,8 +631,6 @@ void dlsch_scheduler_pre_processor (module_id_t   Mod_id,
       continue;
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
       continue;
-    if (!phy_stats_exist(Mod_id, rnti))
-      continue;
 
     for (ii=0; ii<UE_num_active_CC(UE_list,i); ii++) {
       CC_id = UE_list->ordered_CCids[ii][i];
@@ -715,10 +690,8 @@ void dlsch_scheduler_pre_processor (module_id_t   Mod_id,
             continue;
 	  if (UE_list->UE_sched_ctrl[UE_id].ul_out_of_sync == 1)
 	    continue;
-          if (!phy_stats_exist(Mod_id, rnti))
-            continue;
 
-          transmission_mode = mac_xface->get_transmission_mode(Mod_id,CC_id,rnti);
+          transmission_mode = get_tmode(Mod_id,CC_id,UE_id);
 	  //          mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti,frameP,subframeP,&harq_pid,&round,0);
           //rrc_status = mac_eNB_get_rrc_status(Mod_id,rnti);
           /* 1st allocate for the retx */
@@ -763,15 +736,13 @@ void dlsch_scheduler_pre_processor (module_id_t   Mod_id,
                     continue;
 		  if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1)
 		    continue;
-                  if (!phy_stats_exist(Mod_idP, rnti2))
-                    continue;
 
-                  eNB_UE_stats2 = mac_xface->get_eNB_UE_stats(Mod_id,CC_id,rnti2);
+                  eNB_UE_stats2 = UE_list->eNB_UE_stats[CC_id][UE_id2];
                   //mac_xface->get_ue_active_harq_pid(Mod_id,CC_id,rnti2,frameP,subframeP,&harq_pid2,&round2,0);
 
                   if ((mac_eNB_get_rrc_status(Mod_id,rnti2) >= RRC_RECONFIGURED) &&
                       (round2==0) &&
-                      (mac_xface->get_transmission_mode(Mod_id,CC_id,rnti2)==5) &&
+                      (get_tmode(Mod_id,CC_id,UE_id2)==5) &&
                       (ue_sched_ctl->dl_pow_off[CC_id] != 1)) {
 
                     if( (((j == (N_RBG[CC_id]-1)) && (ue_sched_ctl->rballoc_sub_UE[CC_id][j] == 0)) ||
@@ -913,19 +884,25 @@ void dlsch_scheduler_pre_processor_reset (int module_idP,
   //int subframe05_limit=0;
   int sf05_upper=-1,sf05_lower=-1;
 #endif
-  LTE_eNB_UE_stats *eNB_UE_stats = mac_xface->get_eNB_UE_stats(module_idP,CC_id,rnti);
-  if (eNB_UE_stats == NULL) return;
+
+
 
   // initialize harq_pid and round
 
+  /*
+  eNB_UE_stats *eNB_UE_stats;
+
   if (eNB_UE_stats == NULL)
     return;
 
+  
   mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,
 				    frameP,subframeP,
 				    &ue_sched_ctl->harq_pid[CC_id],
 				    &ue_sched_ctl->round[CC_id],
 				    openair_harq_DL);
+  
+
   if (ue_sched_ctl->ta_timer == 0) {
 
     // WE SHOULD PROTECT the eNB_UE_stats with a mutex here ...
@@ -963,9 +940,13 @@ void dlsch_scheduler_pre_processor_reset (int module_idP,
     ue_sched_ctl->ta_timer--;
     ue_sched_ctl->ta_update =0; // don't trigger a timing advance command
   }
+  
+
   if (UE_id==0) {
     VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME(VCD_SIGNAL_DUMPER_VARIABLES_UE0_TIMING_ADVANCE,ue_sched_ctl->ta_update);
   }
+  */
+
   nb_rbs_required[CC_id][UE_id]=0;
   ue_sched_ctl->pre_nb_available_rbs[CC_id] = 0;
   ue_sched_ctl->dl_pow_off[CC_id] = 2;
@@ -1086,7 +1067,7 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP,
 
   int16_t            i;
   uint16_t           UE_id,n,r;
-  uint8_t            CC_id, round, harq_pid;
+  uint8_t            CC_id, harq_pid;
   uint16_t           nb_allocated_rbs[MAX_NUM_CCs][NUMBER_OF_UE_MAX],total_allocated_rbs[MAX_NUM_CCs],average_rbs_per_user[MAX_NUM_CCs];
   int16_t            total_remaining_rbs[MAX_NUM_CCs];
   uint16_t           max_num_ue_to_be_scheduled = 0;
@@ -1134,8 +1115,6 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP,
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
       continue;
 
-    if (!phy_stats_exist(module_idP, rnti))
-      continue;
 
     UE_id = i;
 
@@ -1186,18 +1165,17 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP,
       continue;
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
       continue;
-    if (!phy_stats_exist(module_idP, rnti))
-      continue;
 
     UE_id = i;
 
     for (n=0; n<UE_list->numactiveULCCs[UE_id]; n++) {
       // This is the actual CC_id in the list
       CC_id = UE_list->ordered_ULCCids[n][UE_id];
+      harq_pid = get_UL_harq(frameP,subframeP);
 
-      mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL);
+      //      mac_xface->get_ue_active_harq_pid(module_idP,CC_id,rnti,frameP,subframeP,&harq_pid,&round,openair_harq_UL);
 
-      if(round>0) {
+      if(UE_list->UE_sched_ctrl[UE_id].round_UL[CC_id]>0) {
         nb_allocated_rbs[CC_id][UE_id] = UE_list->UE_template[CC_id][UE_id].nb_rb_ul[harq_pid];
       } else {
         nb_allocated_rbs[CC_id][UE_id] = cmin(UE_list->UE_template[CC_id][UE_id].pre_allocated_nb_rb_ul, average_rbs_per_user[CC_id]);
@@ -1218,9 +1196,6 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP,
         continue;
       if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
 	continue;
-      if (!phy_stats_exist(module_idP, rnti))
-        continue;
-
       UE_id = i;
 
       for (n=0; n<UE_list->numactiveULCCs[UE_id]; n++) {
@@ -1284,8 +1259,6 @@ void assign_max_mcs_min_rb(module_id_t module_idP,int frameP, sub_frame_t subfra
       continue;
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
       continue;
-    if (!phy_stats_exist(module_idP, rnti))
-      continue;
 
     if (UE_list->UE_sched_ctrl[i].phr_received == 1)
       mcs = 20; // if we've received the power headroom information the UE, we can go to maximum mcs
@@ -1321,16 +1294,16 @@ void assign_max_mcs_min_rb(module_id_t module_idP,int frameP, sub_frame_t subfra
       // if this UE has UL traffic
       if (UE_template->ul_total_buffer > 0 ) {
 
-        tbs = mac_xface->get_TBS_UL(mcs,3);  // 1 or 2 PRB with cqi enabled does not work well!
+        tbs = get_TBS_UL(mcs,3);  // 1 or 2 PRB with cqi enabled does not work well!
         // fixme: set use_srs flag
-        tx_power= mac_xface->estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,Ncp,0);
+        tx_power= estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,Ncp,0);
 
         while ((((UE_template->phr_info - tx_power) < 0 ) || (tbs > UE_template->ul_total_buffer))&&
                (mcs > 3)) {
           // LOG_I(MAC,"UE_template->phr_info %d tx_power %d mcs %d\n", UE_template->phr_info,tx_power, mcs);
           mcs--;
-          tbs = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]);
-          tx_power = mac_xface->estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,Ncp,0); // fixme: set use_srs
+          tbs = get_TBS_UL(mcs,rb_table[rb_table_index]);
+          tx_power = estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,Ncp,0); // fixme: set use_srs
         }
 
         while ((tbs < UE_template->ul_total_buffer) &&
@@ -1339,8 +1312,8 @@ void assign_max_mcs_min_rb(module_id_t module_idP,int frameP, sub_frame_t subfra
                (rb_table_index < 32 )) {
    
           rb_table_index++;
-          tbs = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]);
-          tx_power = mac_xface->estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,Ncp,0);
+          tbs = get_TBS_UL(mcs,rb_table[rb_table_index]);
+          tx_power = estimate_ue_tx_power(tbs,rb_table[rb_table_index],0,Ncp,0);
         }
 
         UE_template->ue_tx_power = tx_power;
@@ -1450,8 +1423,7 @@ void sort_ue_ul (module_id_t module_idP,int frameP, sub_frame_t subframeP)
       continue;
     if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
       continue;
-    if (!phy_stats_exist(module_idP, rnti))
-      continue;
+
     list[list_size] = i;
     list_size++;
   }
@@ -1489,8 +1461,7 @@ void sort_ue_ul (module_id_t module_idP,int frameP, sub_frame_t subframeP)
 	continue;
       if (UE_list->UE_sched_ctrl[i].ul_out_of_sync == 1)
 	continue;
-      if (!phy_stats_exist(module_idP, rnti1))
-        continue;
+
 
       pCCid1 = UE_PCCID(module_idP,UE_id1);
       round1  = maxround(module_idP,rnti1,frameP,subframeP,1);
@@ -1502,8 +1473,6 @@ void sort_ue_ul (module_id_t module_idP,int frameP, sub_frame_t subframeP)
         continue;
       if (UE_list->UE_sched_ctrl[UE_id2].ul_out_of_sync == 1)
 	continue;
-      if (!phy_stats_exist(module_idP, rnti2))
-        continue;
 
       pCCid2 = UE_PCCID(module_idP,UE_id2);
       round2  = maxround(module_idP,rnti2,frameP,subframeP,1);
diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h
index 54798adc998a9e0dd17eb3631f62ff965ae985d9..0ad0b157e9aa44406a891b43bbaa9dc30a3e58ad 100644
--- a/openair2/LAYER2/MAC/proto.h
+++ b/openair2/LAYER2/MAC/proto.h
@@ -33,13 +33,6 @@
  *  @{
  */
 
-/** \fn void add_ue_spec_dci(DCI_PDU *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt,uint8_t ra_flag);
-\brief 
-
-*/
-void add_ue_spec_dci(DCI_PDU *DCI_pdu,void *pdu,rnti_t rnti,unsigned char dci_size_bytes,unsigned char aggregation,unsigned char dci_size_bits,unsigned char dci_fmt,uint8_t ra_flag);
-
-//LG commented cause compilation error for RT eNB extern inline unsigned int taus(void);
 
 /** \fn void schedule_RA(module_id_t module_idP,frame_t frameP,sub_frame_t subframe,uint8_t Msg3_subframe,unsigned int *nprb);
 \brief First stage of Random-Access Scheduling. Loops over the RA_templates and checks if RAR, Msg3 or its retransmission are to be scheduled in the subframe.  It returns the total number of PRB used for RA SDUs.  For Msg3 it retrieves the L3msg from RRC and fills the appropriate buffers.  For the others it just computes the number of PRBs. Each DCI uses 3 PRBs (format 1A)
@@ -142,11 +135,9 @@ int8_t get_DELTA_PREAMBLE(module_id_t module_idP,int CC_id);
 */
 int8_t get_deltaP_rampup(module_id_t module_idP,uint8_t CC_id);
 
-//main.c
-
-void chbch_phy_sync_success(module_id_t module_idP,frame_t frameP,uint8_t eNB_index);
+uint16_t mac_computeRIV(uint16_t N_RB_DL,uint16_t RBstart,uint16_t Lcrbs);
 
-void mrbch_phy_sync_failure(module_id_t module_idP, frame_t frameP,uint8_t free_eNB_index);
+//main.c
 
 int mac_top_init(int eMBMS_active, char *uecap_xer,uint8_t cba_group_active, uint8_t HO_active);
 
@@ -201,8 +192,7 @@ void dlsch_scheduler_pre_processor_allocate (module_id_t   Mod_id,
     unsigned char MIMO_mode_indicator[MAX_NUM_CCs][N_RBG_MAX]);
 
 /* \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. The resultant DCI_PDU is
-   ready after returning from this call.
+   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.
@@ -211,15 +201,6 @@ can be scheduled.
 */
 void eNB_dlsch_ulsch_scheduler(module_id_t module_idP, uint8_t cooperation_flag, frame_t frameP, sub_frame_t subframeP);//, int calibration_flag);
 
-/* \brief Function to retrieve result of scheduling (DCI) in current subframe.  Can be called an arbitrary numeber of times after eNB_dlsch_ulsch_scheduler
-in a given subframe.
-@param Mod_id Instance ID of eNB
-@param CC_id Component Carrier Index
-@param subframe Index of current subframe
-@returns Pointer to generated DCI for subframe
-*/
-DCI_PDU *get_dci_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subframe);
-
 /* \brief Function to indicate a received preamble on PRACH.  It initiates the RA procedure.
 @param Mod_id Instance ID of eNB
 @param preamble_index index of the received RA request
@@ -687,7 +668,7 @@ int dump_eNB_l2_stats(char *buffer, int length);
 
 double uniform_rngen(int min, int max);
 
-
+/*
 void add_common_dci(DCI_PDU *DCI_pdu,
                     void *pdu,
                     rnti_t rnti,
@@ -696,6 +677,7 @@ void add_common_dci(DCI_PDU *DCI_pdu,
                     unsigned char dci_size_bits,
                     unsigned char dci_fmt,
                     uint8_t ra_flag);
+*/
 
 uint32_t allocate_prbs_sub(int nb_rb, int N_RB_DL, int N_RBG, uint8_t *rballoc);
 
@@ -734,7 +716,7 @@ unsigned char generate_dlsch_header(unsigned char *mac_header,
 @param CC_id Component Carrier of the eNB
 @param mib Pointer to MIB
 @param radioResourceConfigCommon Structure from SIB2 for common radio parameters (if NULL keep existing configuration)
-@param physcialConfigDedicated Structure from RRCConnectionSetup or RRCConnectionReconfiguration for dedicated PHY parameters (if NULL keep existing configuration)
+@param physicalConfigDedicated Structure from RRCConnectionSetup or RRCConnectionReconfiguration for dedicated PHY parameters (if NULL keep existing configuration)
 @param measObj Structure from RRCConnectionReconfiguration for UE measurement procedures
 @param mac_MainConfig Structure from RRCConnectionSetup or RRCConnectionReconfiguration for dedicated MAC parameters (if NULL keep existing configuration)
 @param logicalChannelIdentity Logical channel identity index of corresponding logical channel config
@@ -757,8 +739,14 @@ int rrc_mac_config_req_eNB(module_id_t        module_idP,
 			   int                Ncp,
 			   int                eutra_band,
 			   uint32_t           dl_CarrierFreq,
+#ifdef Rel14
+                           int                pbch_repetition,
+#endif
 			   BCCH_BCH_Message_t *mib,
  			   RadioResourceConfigCommonSIB_t *radioResourceConfigCommon,
+#ifdef Rel14
+ 			   RadioResourceConfigCommonSIB_t *radioResourceConfigCommon_BR,
+#endif
 			   struct PhysicalConfigDedicated *physicalConfigDedicated,
 #if defined(Rel10) || defined(Rel14)
 			   SCellToAddMod_r10_t *sCellToAddMod_r10,
@@ -847,20 +835,9 @@ int rrc_mac_config_req_ue(module_id_t     module_idP,
 #endif
 			  );
 
-/** \brief get the estimated UE distance from the PHY->MAC layer.
-@param Mod_id Instance ID of eNB
-@param UE_id Index of UE if this is an eNB configuration
-@param CC_id Component Carrier Index
-@param loc_type localization type: time-based or power-based
-@return the estimated distance in meters
- */
-double
-rrc_get_estimated_ue_distance(
-  const protocol_ctxt_t * const ctxt_pP,
-  const int         CC_idP,
-  const uint8_t     loc_typeP);
+uint16_t getRIV(uint16_t N_RB_DL,uint16_t RBstart,uint16_t Lcrbs);
 
-void fill_dci(DCI_PDU *DCI_pdu, PHY_VARS_eNB *phy_vars_eNB,eNB_rxtx_proc_t *proc);
+int get_subbandsize(uint8_t dl_bandwidth);
 
 #endif
 /** @}*/
diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c
index d2d52383b007c34a0a7b98417fbd58147fee6194..b9c5b7872405cfc4f2b8f54b0a19f23e87842a0a 100644
--- a/openair2/LAYER2/MAC/ra_procedures.c
+++ b/openair2/LAYER2/MAC/ra_procedures.c
@@ -34,7 +34,6 @@
 #include "defs.h"
 #include "proto.h"
 #include "UTIL/LOG/vcd_signal_dumper.h"
-#include "PHY_INTERFACE/defs.h"
 #include "PHY_INTERFACE/extern.h"
 #include "COMMON/mac_rrc_primitives.h"
 #include "RRC/LITE/extern.h"
@@ -52,12 +51,8 @@
 int8_t get_DELTA_PREAMBLE(module_id_t module_idP,int CC_id)
 {
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return 0; // not reached
-  }
-
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
   uint8_t prachConfigIndex = UE_mac_inst[module_idP].radioResourceConfigCommon->prach_Config.prach_ConfigInfo.prach_ConfigIndex;
   uint8_t preambleformat;
 
@@ -90,11 +85,9 @@ int8_t get_DELTA_PREAMBLE(module_id_t module_idP,int CC_id)
     return(8);
 
   default:
-    LOG_E(MAC,"[UE %d] ue_procedures.c: FATAL, Illegal preambleformat %d, prachConfigIndex %d\n",
-          module_idP,
-          preambleformat,prachConfigIndex);
-    mac_xface->macphy_exit("MAC get_DELTA_PREAMBLE Illegal preamble format");
-    return(0);
+    AssertFatal(1==0,"[UE %d] ue_procedures.c: FATAL, Illegal preambleformat %d, prachConfigIndex %d\n",
+		module_idP,
+		preambleformat,prachConfigIndex);
   }
 
 }
@@ -120,20 +113,12 @@ void get_prach_resources(module_id_t module_idP,
   int messagePowerOffsetGroupB;
   int PLThreshold;
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return;
-  }
-
-  if (UE_mac_inst[module_idP].radioResourceConfigCommon) {
-    rach_ConfigCommon = &UE_mac_inst[module_idP].radioResourceConfigCommon->rach_ConfigCommon;
-  } else {
-    LOG_E(MAC,"[UE %d] FATAL  radioResourceConfigCommon is NULL !!!\n",module_idP);
-    mac_xface->macphy_exit("MAC FATAL  radioResourceConfigCommon is NULL");
-    return; // not reached
-  }
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
+  AssertFatal(UE_mac_inst[module_idP].radioResourceConfigCommon!=NULL,
+	      "[UE %d] FATAL  radioResourceConfigCommon is NULL !!!\n",module_idP);
 
+  rach_ConfigCommon = &UE_mac_inst[module_idP].radioResourceConfigCommon->rach_ConfigCommon;
   numberOfRA_Preambles = (1+rach_ConfigCommon->preambleInfo.numberOfRA_Preambles)<<2;  
 
   if (rach_ConfigDedicated) {   // This is for network controlled Mobility, later
@@ -210,7 +195,7 @@ void get_prach_resources(module_id_t module_idP,
       UE_mac_inst[module_idP].RA_prach_resources.ra_RACH_MaskIndex = 0;
       UE_mac_inst[module_idP].RA_usedGroupA = 1;
     } else if ((Msg3_size <messageSizeGroupA) ||
-               (mac_xface->get_PL(module_idP,0,eNB_index) > PLThreshold)) {
+               (get_PL(module_idP,0,eNB_index) > PLThreshold)) {
       // use Group A procedure
       UE_mac_inst[module_idP].RA_prach_resources.ra_PreambleIndex  = (taus())%sizeOfRA_PreamblesGroupA;
       UE_mac_inst[module_idP].RA_prach_resources.ra_RACH_MaskIndex = 0;
@@ -244,29 +229,25 @@ void get_prach_resources(module_id_t module_idP,
 
   // choose random PRACH resource in TDD
   if (UE_mac_inst[module_idP].tdd_Config) {
-    num_prach = mac_xface->get_num_prach_tdd(mac_xface->frame_parms);
+    num_prach = get_num_prach_tdd(module_idP);
 
     if ((num_prach>0) && (num_prach<6)) {
       UE_mac_inst[module_idP].RA_prach_resources.ra_TDD_map_index = (taus()%num_prach);
     }
 
-    f_id = mac_xface->get_fid_prach_tdd(mac_xface->frame_parms,
-                                        UE_mac_inst[module_idP].RA_prach_resources.ra_TDD_map_index);
+    f_id = get_fid_prach_tdd(module_idP,
+			     UE_mac_inst[module_idP].RA_prach_resources.ra_TDD_map_index);
   }
 
   // choose RA-RNTI
   UE_mac_inst[module_idP].RA_prach_resources.ra_RNTI = 1 + t_id + 10*f_id;
 }
 
-void Msg1_tx(module_id_t module_idP,uint8_t CC_id,frame_t frameP, uint8_t eNB_id)
+void Msg1_transmitted(module_id_t module_idP,uint8_t CC_id,frame_t frameP, uint8_t eNB_id)
 {
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return;
-  }
-
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
   // start contention resolution timer
   UE_mac_inst[module_idP].RA_attempt_number++;
 
@@ -280,14 +261,11 @@ void Msg1_tx(module_id_t module_idP,uint8_t CC_id,frame_t frameP, uint8_t eNB_id
 }
 
 
-void Msg3_tx(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)
 {
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return;
-  }
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
 
   // start contention resolution timer
   LOG_D(MAC,"[UE %d][RAPROC] Frame %d : Msg3_tx: Setting contention resolution timer\n",module_idP,frameP);
@@ -308,22 +286,19 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP,
 {
 
 
-  uint8_t                        Size=0;
-  UE_MODE_t                 UE_mode = mac_xface->get_ue_mode(module_idP,0,eNB_indexP);
-  uint8_t                        lcid = CCCH;
-  uint16_t                       Size16;
+  uint8_t                  Size               = 0;
+  UE_MODE_t                UE_mode            = get_ue_mode(module_idP,0,eNB_indexP);
+  uint8_t                  lcid               = CCCH;
+  uint16_t                 Size16;
   struct RACH_ConfigCommon *rach_ConfigCommon = (struct RACH_ConfigCommon *)NULL;
-  int32_t                       frame_diff=0;
-  mac_rlc_status_resp_t     rlc_status;
-  uint8_t                        dcch_header_len=0;
-  uint16_t                       sdu_lengths[8];
-  uint8_t                        ulsch_buff[MAX_ULSCH_PAYLOAD_BYTES];
-
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return 0; // not reached
-  }
+  int32_t                  frame_diff         = 0;
+  mac_rlc_status_resp_t    rlc_status;
+  uint8_t                  dcch_header_len    = 0;
+  uint16_t                 sdu_lengths[8];
+  uint8_t                  ulsch_buff[MAX_ULSCH_PAYLOAD_BYTES];
+
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
 
   if (UE_mode == PRACH) {
     if (UE_mac_inst[module_idP].radioResourceConfigCommon) {
@@ -360,16 +335,13 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP,
           UE_mac_inst[module_idP].RA_prach_resources.Msg3          = UE_mac_inst[module_idP].CCCH_pdu.payload;
           UE_mac_inst[module_idP].RA_backoff_cnt                   = 0;  // add the backoff condition here if we have it from a previous RA reponse which failed (i.e. backoff indicator)
 
-          if (rach_ConfigCommon) {
-            UE_mac_inst[module_idP].RA_window_cnt                    = 2+ rach_ConfigCommon->ra_SupervisionInfo.ra_ResponseWindowSize;
+	  AssertFatal(rach_ConfigCommon==NULL,
+		      "[UE %d] FATAL Frame %d: rach_ConfigCommon is NULL !!!\n",module_idP,frameP);
+	  UE_mac_inst[module_idP].RA_window_cnt                    = 2+ rach_ConfigCommon->ra_SupervisionInfo.ra_ResponseWindowSize;
 
-            if (UE_mac_inst[module_idP].RA_window_cnt == 9) {
-              UE_mac_inst[module_idP].RA_window_cnt = 10;  // Note: 9 subframe window doesn't exist, after 8 is 10!
-            }
-          } else {
-            LOG_D(MAC,"[UE %d] FATAL Frame %d: rach_ConfigCommon is NULL !!!\n",module_idP,frameP);
-            mac_xface->macphy_exit("MAC rach_ConfigCommon is NULL");
-          }
+	  if (UE_mac_inst[module_idP].RA_window_cnt == 9) {
+	    UE_mac_inst[module_idP].RA_window_cnt = 10;  // Note: 9 subframe window doesn't exist, after 8 is 10!
+	  }
 
           UE_mac_inst[module_idP].RA_tx_frame         = frameP;
           UE_mac_inst[module_idP].RA_tx_subframe      = subframeP;
@@ -427,16 +399,14 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP,
           UE_mac_inst[module_idP].RA_prach_resources.Msg3          = ulsch_buff;
           UE_mac_inst[module_idP].RA_backoff_cnt                   = 0;  // add the backoff condition here if we have it from a previous RA reponse which failed (i.e. backoff indicator)
 
-          if (rach_ConfigCommon) {
-            UE_mac_inst[module_idP].RA_window_cnt                    = 2+ rach_ConfigCommon->ra_SupervisionInfo.ra_ResponseWindowSize;
+	  AssertFatal(rach_ConfigCommon!=NULL,
+		      "[UE %d] FATAL Frame %d: rach_ConfigCommon is NULL !!!\n",module_idP,frameP);
+	  UE_mac_inst[module_idP].RA_window_cnt                    = 2+ rach_ConfigCommon->ra_SupervisionInfo.ra_ResponseWindowSize;
+
+	  if (UE_mac_inst[module_idP].RA_window_cnt == 9) {
+	    UE_mac_inst[module_idP].RA_window_cnt = 10;  // Note: 9 subframe window doesn't exist, after 8 is 10!
+	  }
 
-            if (UE_mac_inst[module_idP].RA_window_cnt == 9) {
-              UE_mac_inst[module_idP].RA_window_cnt = 10;  // Note: 9 subframe window doesn't exist, after 8 is 10!
-            }
-          } else {
-            LOG_D(MAC,"[UE %d] FATAL Frame %d: rach_ConfigCommon is NULL !!!\n",module_idP,frameP);
-            mac_xface->macphy_exit("MAC rach_ConfigCommon is NULL");
-          }
 
           UE_mac_inst[module_idP].RA_tx_frame         = frameP;
           UE_mac_inst[module_idP].RA_tx_subframe      = subframeP;
@@ -553,7 +523,7 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP,
     }
   } else if (UE_mode == PUSCH) {
     LOG_D(MAC,"[UE %d] FATAL: Should not have checked for RACH in PUSCH yet ...",module_idP);
-    mac_xface->macphy_exit("MAC FATAL: Should not have checked for RACH in PUSCH yet");
+    AssertFatal(1==0,"");
   }
 
   return(NULL);
diff --git a/openair2/LAYER2/MAC/rar_tools.c b/openair2/LAYER2/MAC/rar_tools.c
index 2acf04068ba5db40f4cbc25c67a5e6f0bce4ee3f..647fba659c66d586dd0a2d12391e9cd0adeca7f4 100644
--- a/openair2/LAYER2/MAC/rar_tools.c
+++ b/openair2/LAYER2/MAC/rar_tools.c
@@ -99,7 +99,7 @@ unsigned short fill_rar(
   RC.mac[module_idP]->common_channels[CC_id].RA_template[ra_idx].timing_offset /= 16; //T_A = N_TA/16, where N_TA should be on a 30.72Msps
   rar[0] = (uint8_t)(RC.mac[module_idP]->common_channels[CC_id].RA_template[ra_idx].timing_offset>>(2+4)); // 7 MSBs of timing advance + divide by 4
   rar[1] = (uint8_t)(RC.mac[module_idP]->common_channels[CC_id].RA_template[ra_idx].timing_offset<<(4-2))&0xf0; // 4 LSBs of timing advance + divide by 4
-  rballoc = mac_xface->computeRIV(N_RB_UL,26,1); // first PRB only for UL Grant
+  rballoc = mac_computeRIV(N_RB_UL,26,1); // first PRB only for UL Grant
   rar[1] |= (rballoc>>7)&7; // Hopping = 0 (bit 3), 3 MSBs of rballoc
   rar[2] = ((uint8_t)(rballoc&0xff))<<1; // 7 LSBs of rballoc
   mcs = 10;
diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c
index f9488ce5437d97169a94b90f1d9a39d9afe800fb..3d9cc64f246ff6d971642f3d3e2ff342599c308e 100644
--- a/openair2/LAYER2/MAC/ue_procedures.c
+++ b/openair2/LAYER2/MAC/ue_procedures.c
@@ -42,7 +42,6 @@
 # include "SCHED/defs.h"
 # include "PHY/impl_defs_top.h"
 #endif
-#include "PHY_INTERFACE/defs.h"
 #include "PHY_INTERFACE/extern.h"
 #include "COMMON/mac_rrc_primitives.h"
 
@@ -251,11 +250,8 @@ uint32_t ue_get_SR(module_id_t module_idP,int CC_id,frame_t frameP,uint8_t eNB_i
 
   DevCheck(module_idP < (int)NB_UE_INST, module_idP, NB_UE_INST, 0);
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return 0;
-  }
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
 
   // determin the measurement gap
   if (UE_mac_inst[module_idP].measGapConfig !=NULL) {
@@ -396,7 +392,7 @@ ue_send_sdu(
         for (i=0; i<6; i++)
           if (tx_sdu[i] != payload_ptr[i]) {
             LOG_E(MAC,"[UE %d][RAPROC] Contention detected, RA failed\n",module_idP);
-            mac_xface->ra_failed(module_idP,CC_id,eNB_index);
+            ra_failed(module_idP,CC_id,eNB_index);
             UE_mac_inst[module_idP].RA_contention_resolution_timer_active = 0;
             VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SEND_SDU, VCD_FUNCTION_OUT);
             return;
@@ -404,7 +400,7 @@ ue_send_sdu(
 
         LOG_I(MAC,"[UE %d][RAPROC] Frame %d : Clearing contention resolution timer\n", module_idP, frameP);
         UE_mac_inst[module_idP].RA_contention_resolution_timer_active = 0;
-        mac_xface->ra_succeeded(module_idP,CC_id,eNB_index);
+        ra_succeeded(module_idP,CC_id,eNB_index);
       }
 
       payload_ptr+=6;
@@ -414,7 +410,7 @@ ue_send_sdu(
 #ifdef DEBUG_HEADER_PARSING
       LOG_D(MAC,"[UE] CE %d : UE Timing Advance : %d\n",i,payload_ptr[0]);
 #endif
-      mac_xface->process_timing_advance(module_idP,CC_id,payload_ptr[0]);
+      process_timing_advance(module_idP,CC_id,payload_ptr[0]);
       payload_ptr++;
       break;
 
@@ -721,6 +717,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
   int mbsfn_period = 0;// 1<<(UE_mac_inst[module_idP].mbsfn_SubframeConfig[0]->radioframeAllocationPeriod);
   int mcch_period = 0;// 32<<(UE_mac_inst[module_idP].mbsfn_AreaInfo[0]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
   int mch_scheduling_period = -1;
+  int frame_FDD=1;
 
   start_meas(&UE_mac_inst[module_idP].ue_query_mch);
 
@@ -779,16 +776,18 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           }
         }
 
+	if (UE_mac_inst[module_idP].tdd_Config == NULL) frame_FDD=1;
+	else frame_FDD=0;
         // Check if the subframe is for MSI, MCCH or MTCHs and Set the correspoding flag to 1
         switch (subframe) {
         case 1:
-          if (mac_xface->frame_parms->frame_type == FDD) {
+          if (frame_FDD==1) {
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF1) == MBSFN_FDD_SF1) {
               if (msi_pos == 1) {
                 msi_flag = 1;
               }
 
-              if ( (frameP % mcch_period == UE_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) &&
+	      if ( (frameP % mcch_period == UE_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.mcch_Offset_r9) &&
                    ((UE_mac_inst[module_idP].mbsfn_AreaInfo[i]->mcch_Config_r9.sf_AllocInfo_r9.buf[0] & MBSFN_FDD_SF1) == MBSFN_FDD_SF1) ) {
                 mcch_flag = 1;
               }
@@ -800,7 +799,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           break;
 
         case 2:
-          if (mac_xface->frame_parms->frame_type == FDD) {
+          if (frame_FDD==1) {
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF2) == MBSFN_FDD_SF2) {
               if (msi_pos == 2) {
                 msi_flag = 1;
@@ -818,7 +817,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           break;
 
         case 3:
-          if (mac_xface->frame_parms->frame_type == TDD) { // TDD
+          if (frame_FDD==0) { //TDD
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF3) == MBSFN_TDD_SF3) {
               if (msi_pos == 1) {
                 msi_flag = 1;
@@ -849,7 +848,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           break;
 
         case 4:
-          if (mac_xface->frame_parms->frame_type == TDD) {
+          if (frame_FDD==0) {
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF4) == MBSFN_TDD_SF4) {
               if (msi_pos == 2) {
                 msi_flag = 1;
@@ -867,7 +866,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           break;
 
         case 6:
-          if (mac_xface->frame_parms->frame_type == FDD) {
+          if (frame_FDD==1) {
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_FDD_SF6) == MBSFN_FDD_SF6) {
               if (msi_pos == 4) {
                 msi_flag = 1;
@@ -885,7 +884,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           break;
 
         case 7:
-          if (mac_xface->frame_parms->frame_type == TDD) { // TDD
+          if (frame_FDD==0) { // TDD
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF7) == MBSFN_TDD_SF7) {
               if (msi_pos == 3) {
                 msi_flag = 1;
@@ -916,7 +915,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           break;
 
         case 8:
-          if (mac_xface->frame_parms->frame_type == TDD) { //TDD
+          if (frame_FDD==0) { //TDD
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF8) == MBSFN_TDD_SF8) {
               if (msi_pos == 4) {
                 msi_flag = 1;
@@ -947,7 +946,7 @@ int ue_query_mch(module_id_t module_idP, uint8_t CC_id, uint32_t frameP, uint32_
           break;
 
         case 9:
-          if (mac_xface->frame_parms->frame_type == TDD) {
+          if (frame_FDD==0) {
             if ((UE_mac_inst[module_idP].mbsfn_SubframeConfig[j]->subframeAllocation.choice.oneFrame.buf[0] & MBSFN_TDD_SF9) == MBSFN_TDD_SF9) {
               if (msi_pos == 5) {
                 msi_flag = 1;
@@ -1296,13 +1295,8 @@ void ue_get_sdu(module_id_t module_idP,int CC_id,frame_t frameP,sub_frame_t subf
   LOG_D(MAC,"[UE %d] MAC PROCESS UL TRANSPORT BLOCK at frame%d subframe %d TBS=%d\n",
                         module_idP, frameP, subframe, buflen);
 
-  
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return;
-  }
-
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
   start_meas(&UE_mac_inst[module_idP].tx_ulsch_sdu);
   VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_GET_SDU, VCD_FUNCTION_IN);
 
@@ -1574,7 +1568,7 @@ for (lcid=DCCH; (lcid < MAX_NUM_LCID) && (is_all_lcid_processed == FALSE) ; lcid
     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, mac_xface->get_PHR(module_idP,CC_id,eNB_index), phr_p->PH,POWER_HEADROOM);
+          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;
@@ -1902,7 +1896,7 @@ ue_scheduler(
   case RRC_Handover_failed:
     LOG_N(MAC,"Handover failure for UE %d eNB_index %d\n",module_idP,eNB_indexP);
     //Invalid...need to add another MAC UE state for re-connection procedure
-    mac_xface->phy_config_afterHO_ue(module_idP,0,eNB_indexP,(MobilityControlInfo_t *)NULL,1);
+    phy_config_afterHO_ue(module_idP,0,eNB_indexP,(MobilityControlInfo_t *)NULL,1);
     //return(3);
     break;
 
@@ -1927,7 +1921,7 @@ ue_scheduler(
       LOG_E(MAC,"FATAL: radioResourceConfigCommon is NULL!!!\n");
       VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_UE_SCHEDULER, VCD_FUNCTION_OUT);
       stop_meas(&UE_mac_inst[module_idP].ue_scheduler);
-      mac_xface->macphy_exit("");
+      AssertFatal(1==0,"");
       //return(RRC_OK);
     }
 
@@ -1942,7 +1936,7 @@ ue_scheduler(
       UE_mac_inst[module_idP].RA_contention_resolution_timer_active = 0;
       // Signal PHY to quit RA procedure
       LOG_E(MAC,"Module id %u Contention resolution timer expired, RA failed\n", module_idP);
-      mac_xface->ra_failed(module_idP,0,eNB_indexP);
+      ra_failed(module_idP,0,eNB_indexP);
     }
   }
 
@@ -1957,7 +1951,7 @@ ue_scheduler(
           bucketsizeduration_max = get_ms_bucketsizeduration(UE_mac_inst[module_idP].logicalChannelConfig[lcid]->ul_SpecificParameters->bucketSizeDuration);
         } else {
           LOG_E(MAC,"[UE %d] lcid %d, NULL ul_SpecificParameters\n",module_idP,lcid);
-          mac_xface->macphy_exit("");
+          AssertFatal(1==0,"");
         }
 
         if ( UE_mac_inst[module_idP].scheduling_info.Bj[lcid] > bucketsizeduration_max ) {
@@ -2036,7 +2030,7 @@ ue_scheduler(
     } else {
       //LOG_D(MAC,"PHR normal operation %d active %d \n", UE_mac_inst[module_idP].scheduling_info.periodicPHR_SF, UE_mac_inst[module_idP].PHR_reporting_active);
       if ((UE_mac_inst[module_idP].scheduling_info.prohibitPHR_SF <= 0) &&
-          ((mac_xface->get_PL(module_idP,0,eNB_indexP) <  UE_mac_inst[module_idP].scheduling_info.PathlossChange_db) ||
+          ((get_PL(module_idP,0,eNB_indexP) <  UE_mac_inst[module_idP].scheduling_info.PathlossChange_db) ||
            (UE_mac_inst[module_idP].power_backoff_db[eNB_indexP] > UE_mac_inst[module_idP].scheduling_info.PathlossChange_db)))
         // trigger PHR and reset the timer later when the PHR report is sent
       {
@@ -2530,11 +2524,8 @@ int get_ms_bucketsizeduration(uint8_t bucketsizeduration)
 void update_phr(module_id_t module_idP,int CC_id)
 {
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return;
-  }
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
 
   UE_mac_inst[module_idP].PHR_reporting_active =0;
   UE_mac_inst[module_idP].scheduling_info.periodicPHR_SF =  get_sf_perioidicPHR_Timer(UE_mac_inst[module_idP].scheduling_info.periodicPHR_Timer);
@@ -2544,20 +2535,17 @@ void update_phr(module_id_t module_idP,int CC_id)
 uint8_t get_phr_mapping (module_id_t module_idP, int CC_id, uint8_t eNB_index)
 {
 
-  if (CC_id>0) {
-    LOG_E(MAC,"Transmission on secondary CCs is not supported yet\n");
-    mac_xface->macphy_exit("MAC FATAL  CC_id>0");
-    return 0; // not reached
-  }
+  AssertFatal(CC_id==0,
+	      "Transmission on secondary CCs is not supported yet\n");
 
   //power headroom reporting range is from -23 ...+40 dB, as described in 36313
   //note: mac_xface->get_Po_NOMINAL_PUSCH(module_idP) is float
-  if (mac_xface->get_PHR(module_idP,CC_id,eNB_index) < -23) {
+  if (get_PHR(module_idP,CC_id,eNB_index) < -23) {
     return 0;
-  } else if (mac_xface->get_PHR(module_idP,CC_id,eNB_index) >= 40) {
+  } else if (get_PHR(module_idP,CC_id,eNB_index) >= 40) {
     return 63;
   } else { // -23 to 40
-    return  (uint8_t) mac_xface->get_PHR(module_idP,CC_id,eNB_index) + PHR_MAPPING_OFFSET;
+    return  (uint8_t) get_PHR(module_idP,CC_id,eNB_index) + PHR_MAPPING_OFFSET;
 
   }
 }
diff --git a/openair2/LAYER2/MAC/vars.h b/openair2/LAYER2/MAC/vars.h
index d218d842311309bef42c5124ce4398204e22031a..74c0e68bcf1af3980cb014444345f0069eed9e51 100644
--- a/openair2/LAYER2/MAC/vars.h
+++ b/openair2/LAYER2/MAC/vars.h
@@ -37,7 +37,6 @@
 #endif //USER_MODE
 #include "PHY/defs.h"
 #include "defs.h"
-#include "PHY_INTERFACE/defs.h"
 #include "COMMON/mac_rrc_primitives.h"
 
 const uint32_t BSR_TABLE[BSR_TABLE_SIZE]= {0,10,12,14,17,19,22,26,31,36,42,49,57,67,78,91,
@@ -87,7 +86,6 @@ const uint8_t cqi2fmt2x_agg[MAX_SUPPORTED_BW][CQI_VALUE_RANGE]= {
 
 //uint32_t EBSR_Level[63]={0,10,13,16,19,23,29,35,43,53,65,80,98,120,147,181};
 
-MAC_xface *mac_xface;
 
 uint32_t RRC_CONNECTION_FLAG;
 
@@ -102,16 +100,6 @@ int pCC_id[NUMBER_OF_eNB_MAX];
 eNB_ULSCH_INFO eNB_ulsch_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs][NUMBER_OF_UE_MAX]; // eNBxUE = 8x8
 eNB_DLSCH_INFO eNB_dlsch_info[NUMBER_OF_eNB_MAX][MAX_NUM_CCs][NUMBER_OF_UE_MAX]; // eNBxUE = 8x8
 
-/*
-#ifndef USER_MODE
-RRC_XFACE *Rrc_xface;
-MAC_xface *mac_xface;
-#else
-#include "PHY_INTERFACE/extern.h"
-#include "RRC/LITE/extern.h"
-#endif
-*/
-
 uint8_t Is_rrc_registered;
 
 #ifdef OPENAIR2
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
index 8dad83a90a71d4a26d155b4be46f3a158df8c469..ac8b87a41a7cb079528922dcd33defb0323a47a1 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.c
@@ -118,13 +118,8 @@ boolean_t pdcp_data_req(
   /*
    * XXX MAX_IP_PACKET_SIZE is 4096, shouldn't this be MAX SDU size, which is 8188 bytes?
    */
-
-  if (sdu_buffer_sizeP > MAX_IP_PACKET_SIZE) {
-    LOG_E(PDCP, "Requested SDU size (%d) is bigger than that can be handled by PDCP (%u)!\n",
+  AssertFatal(sdu_buffer_sizeP<= MAX_IP_PACKET_SIZE,"Requested SDU size (%d) is bigger than that can be handled by PDCP (%u)!\n",
           sdu_buffer_sizeP, MAX_IP_PACKET_SIZE);
-    // XXX What does following call do?
-    mac_xface->macphy_exit("PDCP sdu buffer size > MAX_IP_PACKET_SIZE");
-  }
   
   if (modeP == PDCP_TRANSMISSION_MODE_TRANSPARENT) {
     AssertError (rb_idP < NB_RB_MBMS_MAX, return FALSE, "RB id is too high (%u/%d) %u %u!\n", rb_idP, NB_RB_MBMS_MAX, ctxt_pP->module_id, ctxt_pP->rnti);
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
index 94084273d15b5254859875c0bb8aa4975eb40c5d..b33eb2f2aa344af0bcbcda7f2cf60d79a07db299 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp.h
@@ -65,9 +65,9 @@
 #ifndef NON_ACCESS_STRATUM
 #include "UTIL/MEM/mem_block.h"
 #include "UTIL/LISTS/list.h"
-#include "COMMON/mac_rrc_primitives.h"
 #endif //NON_ACCESS_STRATUM
 //-----------------------------------------------------------------------------
+#include "RRC/LITE/defs.h"
 #include "COMMON/platform_constants.h"
 #include "COMMON/platform_types.h"
 #include "DRB-ToAddMod.h"
diff --git a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
index b45689c782c818a6a0f0e1fa6acb290325ec5db4..046ba33e71de16fe607a67b703c4f5118b8aac3c 100644
--- a/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
+++ b/openair2/LAYER2/PDCP_v10.1.0/pdcp_fifo.c
@@ -262,7 +262,7 @@ int pdcp_fifo_flush_sdus(const protocol_ctxt_t* const  ctxt_pP)
       	      MSC_AS_TIME_ARGS(ctxt_pP),
       	      ((pdcp_data_ind_header_t *)(sdu_p->data))->rb_id,
       	      ((pdcp_data_ind_header_t *)(sdu_p->data))->data_size);
-           mac_xface->macphy_exit("sendmsg failed for nas_sock_fd\n");
+	    AssertFatal(1==0,"sendmsg failed for nas_sock_fd\n");
             break;
           } else {
         	  MSC_LOG_TX_MESSAGE(
diff --git a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_fsm.c b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_fsm.c
index c66df33872ed56317400786ba39e8b24ac37eb60..a0995944504edb1d05d7c99889ad58611f686be1 100644
--- a/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_fsm.c
+++ b/openair2/LAYER2/RLC/UM_v9.3.0/rlc_um_fsm.c
@@ -52,7 +52,7 @@ rlc_um_fsm_notify_event (
       LOG_E(RLC, PROTOCOL_RLC_UM_CTXT_FMT" FSM WARNING PROTOCOL ERROR - EVENT %02X hex NOT EXPECTED FROM NULL_STATE\n",
             PROTOCOL_RLC_UM_CTXT_ARGS(ctxt_pP, rlc_pP),
             eventP);
-      mac_xface->macphy_exit("RLC-UM FSM WARNING PROTOCOL ERROR - EVENT NOT EXPECTED FROM NULL_STATE");
+      AssertFatal(1==0,"RLC-UM FSM WARNING PROTOCOL ERROR - EVENT NOT EXPECTED FROM NULL_STATE");
       return 0;
     }
 
diff --git a/openair2/PHY_INTERFACE/IF_Module.c b/openair2/PHY_INTERFACE/IF_Module.c
new file mode 100644
index 0000000000000000000000000000000000000000..afb521d2c0aa265882e36c957050a2eee3aaf6f7
--- /dev/null
+++ b/openair2/PHY_INTERFACE/IF_Module.c
@@ -0,0 +1,97 @@
+#include "openair1/PHY/defs.h"
+#include "openair2/PHY_INTERFACE/IF_Module.h"
+#include "openair1/PHY/extern.h"
+#include "LAYER2/MAC/extern.h"
+#include "LAYER2/MAC/proto.h"
+#include "common/ran_context.h"
+
+#define MAX_IF_MODULES 100
+
+IF_Module_t *if_inst[MAX_IF_MODULES];
+Sched_Rsp_t Sched_INFO[MAX_IF_MODULES][MAX_NUM_CCs];
+
+void UL_indication(UL_IND_t *UL_info)
+{
+
+  AssertFatal(UL_info!=NULL,"UL_INFO is null\n");
+
+
+  module_id_t  module_id   = UL_info->module_id;
+  int          CC_id       = UL_info->CC_id;
+  Sched_Rsp_t  *sched_info = &Sched_INFO[module_id][CC_id];
+  IF_Module_t  *ifi        = if_inst[module_id];
+  eNB_MAC_INST *mac        = RC.mac[module_id];
+
+  LOG_I(PHY,"UL_Indication: frame %d, subframe %d, module_id %d, CC_id %d\n",
+	UL_info->frame,UL_info->subframe,
+	module_id,CC_id);
+
+  if (ifi->CC_mask==0) {
+    ifi->current_frame    = UL_info->frame;
+    ifi->current_subframe = UL_info->subframe;
+  }
+  else {
+    AssertFatal(UL_info->frame != ifi->current_frame,"CC_mask %x is not full and frame has changed\n",ifi->CC_mask);
+    AssertFatal(UL_info->subframe != ifi->current_subframe,"CC_mask %x is not full and subframe has changed\n",ifi->CC_mask);
+  }
+  ifi->CC_mask |= (1<<CC_id);
+ 
+
+
+  // Call uplink indication function
+  AssertFatal(ifi->UL_indication!=NULL,"UL_indication is null (mod %d, cc %d)\n",
+	      module_id,
+	      CC_id);
+
+  //  ifi->UL_indication(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);
+
+    ifi->CC_mask            = 0;
+
+    sched_info->module_id   = module_id;
+    sched_info->CC_id       = CC_id;
+    sched_info->frame       = UL_info->frame + ((UL_info->subframe>5) ? 1 : 0);
+    sched_info->subframe    = (UL_info->subframe+4)%10;
+    sched_info->DL_req      = &mac->DL_req[CC_id];
+    sched_info->HI_DCI0_req = &mac->HI_DCI0_req[CC_id];
+    sched_info->UL_req      = &mac->UL_req[CC_id];
+    sched_info->TX_req      = &mac->TX_req[CC_id];
+    AssertFatal(ifi->schedule_response!=NULL,
+		"UL_indication is null (mod %d, cc %d)\n",
+		module_id,
+		CC_id);
+    ifi->schedule_response(sched_info);
+    LOG_I(PHY,"Schedule_response: frame %d, subframe %d (dl_pdus %d / %p)\n",sched_info->frame,sched_info->subframe,sched_info->DL_req->number_pdu,
+	  &sched_info->DL_req->number_pdu);
+  }						 
+}
+
+IF_Module_t *IF_Module_init(int Mod_id){
+
+  AssertFatal(Mod_id<MAX_MODULES,"Asking for Module %d > %d\n",Mod_id,MAX_IF_MODULES);
+
+  if (if_inst[Mod_id]==NULL) {
+    if_inst[Mod_id] = (IF_Module_t*)malloc(sizeof(IF_Module_t));
+    memset((void*)if_inst[Mod_id],0,sizeof(IF_Module_t));
+    
+    if_inst[Mod_id]->CC_mask=0;
+    if_inst[Mod_id]->UL_indication = UL_indication;
+
+    AssertFatal(pthread_mutex_init(&if_inst[Mod_id]->if_mutex,NULL)==0,
+		"allocation of if_inst[%d]->if_mutex fails\n",Mod_id);
+  }
+  return if_inst[Mod_id];
+}
+
+void IF_Module_kill(int Mod_id) {
+
+  AssertFatal(Mod_id>MAX_MODULES,"Asking for Module %d > %d\n",Mod_id,MAX_IF_MODULES);
+  if (if_inst[Mod_id]!=NULL) free(if_inst[Mod_id]);
+
+}
diff --git a/openair2/PHY_INTERFACE/IF_Module.h b/openair2/PHY_INTERFACE/IF_Module.h
new file mode 100644
index 0000000000000000000000000000000000000000..86933c22a68bab93de2e78583b5296620900e853
--- /dev/null
+++ b/openair2/PHY_INTERFACE/IF_Module.h
@@ -0,0 +1,151 @@
+
+/*This is the interface module between PHY
+*Provided the FAPI style interface structures for P7.
+*
+*
+*
+*//*
+ * 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.0  (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 openair2/PHY_INTERFACE/IF_Module.h
+* \brief data structures for PHY/MAC interface modules
+* \author EURECOM/NTUST
+* \date 2017
+* \version 0.1
+* \company Eurecom
+* \email: raymond.knopp@eurecom.fr
+* \note
+* \warning
+*/
+#ifndef __IF_MODULE__H__
+#define __IF_MODULE__H__
+
+
+#include <stdint.h>
+#include "openair1/PHY/LTE_TRANSPORT/defs.h"
+#include "nfapi_interface.h"
+
+// uplink subframe P7
+
+
+	///
+
+/*UL_IND_t:
+* A structure handles all the uplink information.
+*/
+
+#define MAX_NUM_DL_PDU 100
+#define MAX_NUM_UL_PDU 100
+#define MAX_NUM_HI_DCI0_PDU 100
+#define MAX_NUM_TX_REQUEST_PDU 100
+
+#define MAX_NUM_HARQ_IND 100
+#define MAX_NUM_CRC_IND 100
+#define MAX_NUM_SR_IND 100
+#define MAX_NUM_CQI_IND 100
+#define MAX_NUM_RACH_IND 100
+#define MAX_NUM_SRS_IND 100
+
+typedef struct{
+  /// Module ID
+  module_id_t module_id;
+  /// CC ID
+  int CC_id;
+  /// frame 
+  frame_t frame;
+  /// subframe
+  sub_frame_t subframe;
+
+  /// harq indication list
+  nfapi_harq_indication_body_t *harq_ind[MAX_NUM_HARQ_IND];
+
+  /// crc indication list
+  nfapi_crc_indication_body_t *crc_ind[MAX_NUM_CRC_IND];
+
+  /// SR indication list
+  nfapi_sr_indication_body_t sr_ind[MAX_NUM_SR_IND];
+
+  /// CQI indication list
+  nfapi_cqi_indication_body_t cqi_ind[MAX_NUM_CQI_IND];
+
+  /// RACH indication list
+  nfapi_rach_indication_body_t rach_ind[MAX_NUM_RACH_IND];
+
+  /// SRS indication list
+  nfapi_srs_indication_body_t srs_ind[MAX_NUM_SRS_IND];
+
+  /// RX indication
+  nfapi_rx_indication_body_t rx_ind;
+
+} UL_IND_t;
+
+// Downlink subframe P7
+
+
+typedef struct{
+  /// Module ID
+  module_id_t module_id; 
+  /// CC ID
+  uint8_t CC_id;
+  /// frame
+  frame_t frame;
+  /// subframe
+  sub_frame_t subframe;
+  /// nFAPI DL Config Request
+  nfapi_dl_config_request_body_t *DL_req;
+  /// nFAPI UL Config Request
+  nfapi_ul_config_request_body_t *UL_req;
+  /// nFAPI HI_DCI Request
+  nfapi_hi_dci0_request_body_t *HI_DCI0_req;
+  /// Pointers to DL SDUs
+  nfapi_tx_request_body_t *TX_req;
+}Sched_Rsp_t;
+
+typedef struct {
+    uint8_t Mod_id;
+    int CC_id;
+    nfapi_config_request_t *cfg;
+}PHY_Config_t;
+
+typedef struct IF_Module_s{
+//define the function pointer
+  void (*UL_indication)(UL_IND_t *UL_INFO);
+  void (*schedule_response)(Sched_Rsp_t *Sched_INFO);
+  void (*PHY_config_req)(PHY_Config_t* config_INFO);
+  uint32_t CC_mask;
+  uint16_t current_frame;
+  uint8_t current_subframe;
+  pthread_mutex_t if_mutex;
+}IF_Module_t;
+
+/*Initial */
+IF_Module_t *IF_Module_init(int Mod_id);
+void IF_Module_kill(int Mod_id);
+
+/*Interface for uplink, transmitting the Preamble(list), ULSCH SDU, NAK, Tick (trigger scheduler)
+ */
+void UL_indication(UL_IND_t *UL_INFO);
+
+/*Interface for Downlink, transmitting the DLSCH SDU, DCI SDU*/
+void Schedule_Response(Sched_Rsp_t *Sched_INFO);
+
+#endif
+
diff --git a/openair2/PHY_INTERFACE/defs.h b/openair2/PHY_INTERFACE/defs.h
index 592b54411b01a570042038f193bcc63d74f33296..1fdd69497aa66e045d426ec5b3ec211124b27422 100644
--- a/openair2/PHY_INTERFACE/defs.h
+++ b/openair2/PHY_INTERFACE/defs.h
@@ -52,6 +52,7 @@ do {
  * @{
  */
 /*! \brief MACPHY Interface */
+/*
 typedef struct {
   /// Pointer function that initializes L2
   int (*macphy_init)(int eMBMS_active, char *uecap_xer, uint8_t CBA_active,uint8_t HO_active);
@@ -364,6 +365,7 @@ typedef struct {
 
 } MAC_xface;
 
+*/
 
 #endif
 
diff --git a/openair2/PHY_INTERFACE/extern.h b/openair2/PHY_INTERFACE/extern.h
index f75d716b6311d8a86fed2d454427fa72aba54b78..403847f3f4c8e31b9414268776c7387a7ff6b90d 100644
--- a/openair2/PHY_INTERFACE/extern.h
+++ b/openair2/PHY_INTERFACE/extern.h
@@ -22,22 +22,6 @@
 #ifndef __PHY_INTERFACE_EXTERN_H__
 #define __PHY_INTERFACE_EXTERN_H__
 
-//#include "SIMULATION/PHY_EMULATION/spec_defs.h"
-#ifdef PHY_EMUL
-#include "SIMULATION/PHY_EMULATION/DEVICE_DRIVER/defs.h"
-#include "SIMULATION/PHY_EMULATION/DEVICE_DRIVER/extern.h"
-#endif //PHY_EMUL
-
-#include "defs.h"
-
-
-extern unsigned int mac_debug;
-#ifdef PHYSIM
-extern MAC_xface *mac_xface;
-#endif
-//extern MACPHY_PARAMS MACPHY_params;
-
-extern unsigned int mac_registered;
 
 
 #endif
diff --git a/openair2/RRC/LITE/L2_interface.c b/openair2/RRC/LITE/L2_interface.c
index cf8c9e5150c2a1eeeae84c5a54b09171a0e3de1d..5cf2bbcdf7a6997c195415571f28a649ada990df 100644
--- a/openair2/RRC/LITE/L2_interface.c
+++ b/openair2/RRC/LITE/L2_interface.c
@@ -75,9 +75,13 @@ mac_rrc_data_req(
 )
 //--------------------------------------------------------------------------
 {
+  asn_enc_rval_t enc_rval;
   SRB_INFO *Srb_info;
-  uint8_t Sdu_size=0;
-
+  uint8_t Sdu_size                = 0;
+  uint8_t sfn                     = (uint8_t)((frameP>>2)&0xff);
+  eNB_RRC_INST *rrc               = RC.rrc[Mod_idP];
+  rrc_eNB_carrier_data_t *carrier = &rrc->carrier[0];
+  BCCH_BCH_Message_t *mib         = &carrier->mib;
 #ifdef DEBUG_RRC
   int i;
   LOG_T(RRC,"[eNB %d] mac_rrc_data_req to SRB ID=%d\n",Mod_idP,Srb_id);
@@ -91,10 +95,8 @@ mac_rrc_data_req(
       }
 
       // All even frames transmit SIB in SF 5
-      if (RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1 == 255) {
-        LOG_E(RRC,"[eNB %d] MAC Request for SIB1 and SIB1 not initialized\n",Mod_idP);
-        mac_xface->macphy_exit("mac_rrc_data_req:  MAC Request for SIB1 and SIB1 not initialized");
-      }
+      AssertFatal(RC.rrc[Mod_idP]->carrier[CC_id].sizeof_SIB1 != 255, 
+		  "[eNB %d] MAC Request for SIB1 and SIB1 not initialized\n",Mod_idP);
 
       if ((frameP%2) == 0) {
         memcpy(&buffer_pP[0],
@@ -180,6 +182,21 @@ mac_rrc_data_req(
         return(0);
       }
     }
+    if( (Srb_id & RAB_OFFSET ) == MIBCH) {
+
+        mib->message.systemFrameNumber.buf = &sfn;
+	enc_rval = uper_encode_to_buffer(&asn_DEF_BCCH_BCH_Message,
+					 (void*)mib,
+					 carrier->MIB,
+					 100);
+	LOG_I(RRC,"Encoded MIB for frame %d (%p)\n",sfn,carrier->MIB);
+	buffer_pP[0]=carrier->MIB[0];
+	buffer_pP[1]=carrier->MIB[1];
+	buffer_pP[2]=carrier->MIB[2];
+	AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %lu)!\n",
+		     enc_rval.failed_type->name, enc_rval.encoded);
+	return(3);
+    }
 
     if( (Srb_id & RAB_OFFSET ) == CCCH) {
       LOG_T(RRC,"[eNB %d] Frame %d CCCH request (Srb_id %d)\n",Mod_idP,frameP, Srb_id);
@@ -232,12 +249,6 @@ mac_rrc_data_req(
         return 0;  // this parameter is set in function init_mcch in rrc_eNB.c
       }
 
-      // this part not needed as it is done in init_mcch
-      /*     if (eNB_rrc_inst[Mod_id].sizeof_MCCH_MESSAGE[mbsfn_sync_area] == 255) {
-      LOG_E(RRC,"[eNB %d] MAC Request for MCCH MESSAGE and MCCH MESSAGE is not initialized\n",Mod_id);
-      mac_xface->macphy_exit("");
-      }*/
-
 
 #if defined(ENABLE_ITTI)
       {
diff --git a/openair2/RRC/LITE/defs.h b/openair2/RRC/LITE/defs.h
index 7bf4bd512373fb9f11b0cf87da5d262259eb04c7..eff2969e84278e3e8b3b4bcf357ede8083da801a 100644
--- a/openair2/RRC/LITE/defs.h
+++ b/openair2/RRC/LITE/defs.h
@@ -40,10 +40,11 @@
 #include "collection/tree.h"
 #include "rrc_types.h"
 #include "PHY/defs.h"
+#include "LAYER2/RLC/rlc.h"
+
 #include "COMMON/platform_constants.h"
 #include "COMMON/platform_types.h"
 
-#include "COMMON/mac_rrc_primitives.h"
 #include "LAYER2/MAC/defs.h"
 
 //#include "COMMON/openair_defs.h"
@@ -136,6 +137,13 @@
 #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib10 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib10
 #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib11 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib11
 #endif
+
+
+#define NB_SIG_CNX_CH 1
+#define NB_CNX_CH MAX_MOBILES_PER_ENB
+#define NB_SIG_CNX_UE 2 //MAX_MANAGED_RG_PER_MOBILE
+#define NB_CNX_UE 2//MAX_MANAGED_RG_PER_MOBILE
+
 /*
 #if defined(Rel10) || defined(Rel14)
 #define SystemInformation_r8_IEs__sib_TypeAndInfo__Member_PR_sib12_v920 SystemInformation_r8_IEs_sib_TypeAndInfo_Member_PR_sib12_v920
@@ -165,10 +173,6 @@
 # include "commonDef.h"
 #endif
 
-#if ENABLE_RAL
-# include "collection/hashtable/obj_hashtable.h"
-#endif
-
 //--------
 typedef unsigned int uid_t;
 #define UID_LINEAR_ALLOCATOR_BITMAP_SIZE (((NUMBER_OF_UE_MAX/8)/sizeof(unsigned int)) + 1)
@@ -190,18 +194,18 @@ typedef struct uid_linear_allocator_s {
  * @{
  */
 
-#if ENABLE_RAL
-typedef struct rrc_ral_threshold_key_s {
-  ral_link_param_type_t   link_param_type;
-  ral_threshold_t         threshold;
-} rrc_ral_threshold_key_t;
-#endif
-
-//#define NUM_PRECONFIGURED_LCHAN (NB_CH_CX*2)  //BCCH, CCCH
 
 #define UE_MODULE_INVALID ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!!
 #define UE_INDEX_INVALID  ((module_id_t) ~0) // FIXME attention! depends on type uint8_t!!! used to be -1
 
+typedef enum {
+  RRC_OK=0,
+  RRC_ConnSetup_failed,
+  RRC_PHY_RESYNCH,
+  RRC_Handover_failed,
+  RRC_HO_STARTED
+} RRC_status_t;
+
 typedef enum UE_STATE_e {
   RRC_INACTIVE=0,
   RRC_IDLE,
@@ -240,6 +244,18 @@ typedef enum HO_STATE_e {
 /* TS 36.331: RRC-TransactionIdentifier ::= INTEGER (0..3) */
 #define RRC_TRANSACTION_IDENTIFIER_NUMBER  3
 
+typedef struct {
+  unsigned short transport_block_size;                  /*!< \brief Minimum PDU size in bytes provided by RLC to MAC layer interface */
+  unsigned short max_transport_blocks;                  /*!< \brief Maximum PDU size in bytes provided by RLC to MAC layer interface */
+  unsigned long  Guaranteed_bit_rate;           /*!< \brief Guaranteed Bit Rate (average) to be offered by MAC layer scheduling*/
+  unsigned long  Max_bit_rate;                  /*!< \brief Maximum Bit Rate that can be offered by MAC layer scheduling*/
+  uint8_t  Delay_class;                  /*!< \brief Delay class offered by MAC layer scheduling*/
+  uint8_t  Target_bler;                  /*!< \brief Target Average Transport Block Error rate*/
+  uint8_t  Lchan_t;                      /*!< \brief Logical Channel Type (BCCH,CCCH,DCCH,DTCH_B,DTCH,MRBCH)*/
+} __attribute__ ((__packed__))  LCHAN_DESC;
+
+#define LCHAN_DESC_SIZE sizeof(LCHAN_DESC)
+
 typedef struct UE_RRC_INFO_s {
   UE_STATE_t State;
   uint8_t SIB1systemInfoValueTag;
@@ -313,7 +329,7 @@ typedef struct {
 typedef struct RB_INFO_s {
   uint16_t Rb_id;  //=Lchan_id
   LCHAN_DESC Lchan_desc[2];
-  MAC_MEAS_REQ_ENTRY *Meas_entry;
+  //  MAC_MEAS_REQ_ENTRY *Meas_entry;
 } RB_INFO;
 
 typedef struct SRB_INFO_s {
@@ -445,17 +461,25 @@ typedef struct {
   uint8_t                           sizeof_SIB1;
   uint8_t                           *SIB23;
   uint8_t                           sizeof_SIB23;
+#ifdef Rel14
+  uint8_t                           *SIB23_BR;
+  uint8_t                           sizeof_SIB23_BR;
+#endif
   int                               physCellId;
   int                               Ncp;
   int                               p_eNB;
   uint32_t                          dl_CarrierFreq;
   uint32_t                          ul_CarrierFreq;
+  uint32_t                          pbch_repetition;
   BCCH_BCH_Message_t                mib;
   BCCH_DL_SCH_Message_t             siblock1;
   BCCH_DL_SCH_Message_t             systemInformation;
   //  SystemInformation_t               systemInformation;
   SystemInformationBlockType1_t     *sib1;
   SystemInformationBlockType2_t     *sib2;
+#ifdef Rel14
+  SystemInformationBlockType2_t     *sib2_BR;
+#endif
   SystemInformationBlockType3_t     *sib3;
 #if defined(Rel10) || defined(Rel14)
   SystemInformationBlockType13_r9_t *sib13;
@@ -476,14 +500,13 @@ typedef struct {
 } rrc_eNB_carrier_data_t;
 
 typedef struct eNB_RRC_INST_s {
+  /// southbound midhaul configuration
+  eth_params_t                    eth_params_s;
   rrc_eNB_carrier_data_t          carrier[MAX_NUM_CCs];
   uid_allocator_t                    uid_allocator; // for rrc_ue_head
   RB_HEAD(rrc_ue_tree_s, rrc_eNB_ue_context_s)     rrc_ue_head; // ue_context tree key search by rnti
   uint8_t                           HO_flag;
   uint8_t                            Nb_ue;
-#if ENABLE_RAL
-  obj_hash_table_t                  *ral_meas_thresholds;
-#endif
   hash_table_t                      *initial_id2_s1ap_ids; // key is    content is rrc_ue_s1ap_ids_t
   hash_table_t                      *s1ap_id2_s1ap_ids   ; // key is    content is rrc_ue_s1ap_ids_t
 
@@ -598,10 +621,6 @@ typedef struct UE_RRC_INST_s {
   float                           rsrq_db[7];
   float                           rsrp_db_filtered[7];
   float                           rsrq_db_filtered[7];
-#if ENABLE_RAL
-  obj_hash_table_t               *ral_meas_thresholds;
-  ral_transaction_id_t            scan_transaction_id;
-#endif
 #if defined(ENABLE_SECURITY)
   /* KeNB as computed from parameters within USIM card */
   uint8_t kenb[32];
diff --git a/openair2/RRC/LITE/rrc_UE.c b/openair2/RRC/LITE/rrc_UE.c
index f2f6bd49ae7d48d7634120430253c9e8bd11b19d..5cbc612b4801d3bc4aeb1ff4ba87478b33c102e3 100644
--- a/openair2/RRC/LITE/rrc_UE.c
+++ b/openair2/RRC/LITE/rrc_UE.c
@@ -100,7 +100,7 @@ extern void *bigphys_malloc(int);
 
 //#define XER_PRINT
 
-extern int8_t dB_fixed2(uint32_t x,uint32_t y);
+//extern int8_t dB_fixed2(uint32_t x,uint32_t y);
 
 extern void pdcp_config_set_security(
   const protocol_ctxt_t* const  ctxt_pP,
@@ -3800,30 +3800,25 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
   if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0] != NULL) { // Only consider 1 serving cell (index: 0)
     if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
       if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP != NULL) {
-        for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
-          //filter_factor = 1/power(2,*UE_rrc_inst[ue_mod_idP].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRP/4);
-          // LOG_N(RRC,"[UE %d] Frame %d : check proper operation in abstraction mode rsrp (%d), rx gain (%d) N_RB_DL (%d)\n",
-          //  ue_mod_idP,frameP,mac_xface->get_RSRP(ue_mod_idP,0,eNB_offset),mac_xface->get_rx_total_gain_dB(ue_mod_idP,0),mac_xface->lte_frame_parms->N_RB_DL);
-          UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset] =
-            (dB_fixed_times10(mac_xface->get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0) -
-            mac_xface->get_rx_total_gain_dB(ctxt_pP->module_id,0) -
-            dB_fixed(mac_xface->frame_parms->N_RB_DL*12);
+        for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
+          UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset] = get_RSRP(ctxt_pP->module_id,0,eNB_offset);
+	  /*
+	  (dB_fixed_times10(get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0) -
+	  get_rx_total_gain_dB(ctxt_pP->module_id,0) -
+	  get_bw_gain_dB(ctxt_pP->module_id);
+	  */
           UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] =
             (1.0-a)*UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset] +
             a*UE_rrc_inst[ctxt_pP->module_id].rsrp_db[eNB_offset];
-          //mac_xface->set_RSRP_filtered(ue_mod_idP,eNB_offset,UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]);
 
-
-          //LOG_D(RRC,"RSRP_total_dB: %3.2f \n",(dB_fixed_times10(mac_xface->get_RSRP(ue_mod_idP,0,eNB_offset))/10.0)-mac_xface->get_rx_total_gain_dB(ue_mod_idP,0)-dB_fixed(mac_xface->lte_frame_parms->N_RB_DL*12));
-
-          LOG_D(RRC,"RSRP_dBm: %3.2f \n",(dB_fixed_times10(mac_xface->get_RSRP(ctxt_pP->module_id,0,eNB_offset))/10.0));
-          LOG_D(RRC,"gain_loss_dB: %d \n",mac_xface->get_rx_total_gain_dB(ctxt_pP->module_id,0));
-          LOG_D(RRC,"gain_fixed_dB: %d \n",dB_fixed(mac_xface->frame_parms->N_RB_DL*12));
+          LOG_D(RRC,"RSRP_dBm: %3.2f \n",get_RSRP(ctxt_pP->module_id,0,eNB_offset));;
+	  /*          LOG_D(RRC,"gain_loss_dB: %d \n",get_rx_total_gain_dB(ctxt_pP->module_id,0));
+		      LOG_D(RRC,"gain_fixed_dB: %d \n",dB_fixed(frame_parms->N_RB_DL*12));*/
           LOG_D(PHY,"[UE %d] Frame %d, RRC Measurements => rssi %3.1f dBm (digital: %3.1f dB)\n",
                 ctxt_pP->module_id,
                 ctxt_pP->frame,
-                10*log10(mac_xface->get_RSSI(ctxt_pP->module_id,0))-mac_xface->get_rx_total_gain_dB(ctxt_pP->module_id,0),
-                10*log10(mac_xface->get_RSSI(ctxt_pP->module_id,0)));
+                10*log10(get_RSSI(ctxt_pP->module_id,0))-get_rx_total_gain_dB(ctxt_pP->module_id,0),
+                10*log10(get_RSSI(ctxt_pP->module_id,0)));
           LOG_D(RRC,"[UE %d] Frame %d: Meas RSRP: eNB_offset: %d rsrp_coef: %3.1f filter_coef: %ld before L3 filtering: rsrp: %3.1f after L3 filtering: rsrp: %3.1f \n ",
                 ctxt_pP->module_id,
                 ctxt_pP->frame, eNB_offset,a,
@@ -3833,34 +3828,22 @@ void ue_meas_filtering( const protocol_ctxt_t* const ctxt_pP, const uint8_t eNB_
         }
       }
     } else {
-      for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
-        UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset]= mac_xface->get_RSRP(ctxt_pP->module_id,0,eNB_offset);
-        // phy_vars_ue->PHY_measurements.rsrp_filtered[eNB_offset]=UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset];
-        //mac_xface->set_RSRP_filtered(ue_mod_idP,eNB_offset,UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]);
+      for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
+        UE_rrc_inst[ctxt_pP->module_id].rsrp_db_filtered[eNB_offset]= get_RSRP(ctxt_pP->module_id,0,eNB_offset);
       }
     }
 
     if (UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA != NULL) {
       if(UE_rrc_inst[ctxt_pP->module_id].QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRQ != NULL) {
-        for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
-          // LOG_N(RRC,"[UE %d] Frame %d : check if this operation workes properly in abstraction mode\n",ue_mod_idP,frameP);
-          UE_rrc_inst[ctxt_pP->module_id].rsrq_db[eNB_offset] = (10*log10(mac_xface->get_RSRQ(ctxt_pP->module_id,0,eNB_offset)))-20;
+        for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
+          UE_rrc_inst[ctxt_pP->module_id].rsrq_db[eNB_offset] = (10*log10(get_RSRQ(ctxt_pP->module_id,0,eNB_offset)))-20;
           UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset]=(1-a1)*UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset] +
               a1 *UE_rrc_inst[ctxt_pP->module_id].rsrq_db[eNB_offset];
-          //mac_xface->set_RSRP_filtered(ue_mod_idP,eNB_offset,UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]);
-          /*
-          LOG_D(RRC,"[UE %d] Frame %d: Meas RSRQ: eNB_offset: %d rsrq_coef: %3.2f filter_coef: %d before L3 filtering: rsrq: %3.1f after L3 filtering: rsrq: %3.1f \n ",
-          ue_mod_idP,frameP,eNB_offset,a1,
-           *UE_rrc_inst->QuantityConfig[0]->quantityConfigEUTRA->filterCoefficientRSRQ,
-          mac_xface->get_RSRQ(ue_mod_idP,0,eNB_offset),
-          UE_rrc_inst[ue_mod_idP].rsrq_db[eNB_offset],
-          UE_rrc_inst[ue_mod_idP].rsrq_db_filtered[eNB_offset]);
-           */
         }
       }
     } else {
-      for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
-        UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset]= mac_xface->get_RSRQ(ctxt_pP->module_id,0,eNB_offset);
+      for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ctxt_pP->module_id,0); eNB_offset++) {
+        UE_rrc_inst[ctxt_pP->module_id].rsrq_db_filtered[eNB_offset]= get_RSRQ(ctxt_pP->module_id,0,eNB_offset);
       }
     }
   }
@@ -4061,6 +4044,7 @@ void ue_measurement_report_triggering(protocol_ctxt_t* const ctxt_pP, const uint
 
 //check_trigger_meas_event(ue_mod_idP, frameP, eNB_index, i,j,ofn,ocn,hys,ofs,ocs,a3_offset,ttt_ms)
 //-----------------------------------------------------------------------------
+
 static uint8_t check_trigger_meas_event(
   module_id_t     ue_mod_idP,
   frame_t         frameP,
@@ -4076,16 +4060,15 @@ static uint8_t check_trigger_meas_event(
   TimeToTrigger_t ttt )
 {
   uint8_t eNB_offset;
-  uint8_t currentCellIndex = mac_xface->frame_parms->Nid_cell;
+  //  uint8_t currentCellIndex = frame_parms->Nid_cell;
   uint8_t tmp_offset;
 
   LOG_I(RRC,"[UE %d] ofn(%ld) ocn(%ld) hys(%ld) ofs(%ld) ocs(%ld) a3_offset(%ld) ttt(%ld) rssi %3.1f\n",
         ue_mod_idP,
         ofn,ocn,hys,ofs,ocs,a3_offset,ttt,
-        10*log10(mac_xface->get_RSSI(ue_mod_idP,0))-mac_xface->get_rx_total_gain_dB(ue_mod_idP,0));
+        10*log10(get_RSSI(ue_mod_idP,0))-get_rx_total_gain_dB(ue_mod_idP,0));
 
-  for (eNB_offset = 0; eNB_offset<1+mac_xface->get_n_adj_cells(ue_mod_idP,0); eNB_offset++) {
-    //for (eNB_offset = 1;(eNB_offset<1+mac_xface->get_n_adj_cells(ue_mod_idP,0));eNB_offset++) {
+  for (eNB_offset = 0; eNB_offset<1+get_n_adj_cells(ue_mod_idP,0); eNB_offset++) {
     /* RHS: Verify that idx 0 corresponds to currentCellIndex in rsrp array */
     if((eNB_offset!=eNB_index)&&(eNB_offset<NB_eNB_INST)) {
       if(eNB_offset<eNB_index) {
@@ -4097,21 +4080,20 @@ static uint8_t check_trigger_meas_event(
       if(UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_offset]+ofn+ocn-hys > UE_rrc_inst[ue_mod_idP].rsrp_db_filtered[eNB_index]+ofs+ocs-1/*+a3_offset*/) {
         UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] += 2; //Called every subframe = 2ms
         LOG_D(RRC,"[UE %d] Frame %d: Entry measTimer[%d][%d][%d]: %d currentCell: %d betterCell: %d \n",
-              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],currentCellIndex,eNB_offset);
+              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],0,eNB_offset);
       } else {
         UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] = 0; //Exit condition: Resetting the measurement timer
         LOG_D(RRC,"[UE %d] Frame %d: Exit measTimer[%d][%d][%d]: %d currentCell: %d betterCell: %d \n",
-              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],currentCellIndex,eNB_offset);
+              ue_mod_idP, frameP, ue_cnx_index,meas_index,tmp_offset,UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset],0,eNB_offset);
       }
 
       if (UE_rrc_inst->measTimer[ue_cnx_index][meas_index][tmp_offset] >= ttt) {
         UE_rrc_inst->HandoverInfoUe.targetCellId = get_adjacent_cell_id(ue_mod_idP,tmp_offset); //WARNING!!!...check this!
-        LOG_D(RRC,"[UE %d] Frame %d eNB %d: Handover triggered: targetCellId: %ld currentCellId: %d eNB_offset: %d rsrp source: %3.1f rsrp target: %3.1f\n", \
+        LOG_D(RRC,"[UE %d] Frame %d eNB %d: Handover triggered: targetCellId: %ld currentCellId: %d eNB_offset: %d rsrp source: %3.1f rsrp target: %3.1f\n",
               ue_mod_idP, frameP, eNB_index,
               UE_rrc_inst->HandoverInfoUe.targetCellId,ue_cnx_index,eNB_offset,
-              (dB_fixed_times10(UE_rrc_inst[ue_mod_idP].rsrp_db[0])/10.0)-mac_xface->get_rx_total_gain_dB(ue_mod_idP,0)-dB_fixed(mac_xface->frame_parms->N_RB_DL*12),
-              (dB_fixed_times10(UE_rrc_inst[ue_mod_idP].rsrp_db[eNB_offset])/10.0)-mac_xface->get_rx_total_gain_dB(ue_mod_idP,
-                  0)-dB_fixed(mac_xface->frame_parms->N_RB_DL*12));
+	      get_RSRP(ue_mod_idP,0,0),
+	      get_RSRP(ue_mod_idP,0,1));
         UE_rrc_inst->Info[0].handoverTarget = eNB_offset;
         //LOG_D(RRC,"PHY_ID: %d \n",UE_rrc_inst->HandoverInfoUe.targetCellId);
         return 1;
diff --git a/openair2/RRC/LITE/rrc_eNB.c b/openair2/RRC/LITE/rrc_eNB.c
index 827f304d5d8c71bc0fb278cb95669719b1044454..1bc8af09b91dc8aa0760fa9f626f413929f0f5b0 100644
--- a/openair2/RRC/LITE/rrc_eNB.c
+++ b/openair2/RRC/LITE/rrc_eNB.c
@@ -133,13 +133,16 @@ init_SI(
   int                                 i;
 #endif
   
-
+  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MIB = (uint8_t*) malloc16(3);
   // copy basic parameters
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId      = configuration->Nid_cell[CC_id];
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB           = configuration->nb_antenna_ports[CC_id];
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp             = configuration->prefix_type[CC_id];
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq  = configuration->downlink_frequency[CC_id];
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq  = configuration->downlink_frequency[CC_id]+ configuration->uplink_frequency_offset[CC_id];
+#ifdef Rel14
+  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition = configuration->pbch_repetition[CC_id];
+#endif
   LOG_I(RRC, "Configuring MIB (N_RB_DL %d,phich_Resource %d,phich_Duration %d)\n", 
 	configuration->N_RB_DL[CC_id],
 	configuration->phich_resource[CC_id],
@@ -159,157 +162,150 @@ init_SI(
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = 0;
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1 = (uint8_t*) malloc16(32);
 
-  if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1)
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 = do_SIB1(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id
+  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB1!=NULL,PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
+	      PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 = do_SIB1(&RC.rrc[ctxt_pP->module_id]->carrier[CC_id],ctxt_pP->module_id,CC_id
 #if defined(ENABLE_ITTI)
-          , configuration
+								   , configuration
 #endif
-        );
-  else {
-    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB1 allocated\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-    mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB1 allocated");
-  }
+								   );
 
-  if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 == 255) {
-    mac_xface->macphy_exit("[RRC][init_SI] FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
-  }
+  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB1 != 255,"FATAL, RC.rrc[enb_mod_idP].carrier[CC_id].sizeof_SIB1 == 255");
 
   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23 = (uint8_t*) malloc16(64);
-
-  if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23) {
-    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = do_SIB23(
-          ctxt_pP->module_id,
-
-          CC_id
+  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].SIB23!=NULL,"cannot allocate memory for SIB");
+  RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 = do_SIB23(
+								     ctxt_pP->module_id,
+								     
+								     CC_id
 #if defined(ENABLE_ITTI)
-          , configuration
+								     , configuration
 #endif
-        );
+								     );
 
-    if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 == 255) {
-      mac_xface->macphy_exit("[RRC][init_SI] FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
-    }
-
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          pusch_ConfigBasic.n_SB);
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          pusch_ConfigBasic.hoppingMode);
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          pusch_ConfigBasic.pusch_HoppingOffset);
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          pusch_ConfigBasic.enable64QAM);
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          (int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
-    LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-          RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
-          ul_ReferenceSignalsPUSCH.cyclicShift);
+  AssertFatal(RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sizeof_SIB23 != 255,"FATAL, RC.rrc[mod].carrier[CC_id].sizeof_SIB23 == 255");
+  
 
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" SIB2/3 Contents (partial)\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.n_SB = %ld\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	pusch_ConfigBasic.n_SB);
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.hoppingMode = %ld\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	pusch_ConfigBasic.hoppingMode);
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.pusch_HoppingOffset = %ld\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	pusch_ConfigBasic.pusch_HoppingOffset);
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.enable64QAM = %d\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	(int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	pusch_ConfigBasic.enable64QAM);
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupHoppingEnabled = %d\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	(int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	ul_ReferenceSignalsPUSCH.groupHoppingEnabled);
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.groupAssignmentPUSCH = %ld\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	ul_ReferenceSignalsPUSCH.groupAssignmentPUSCH);
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.sequenceHoppingEnabled = %d\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	(int)RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	ul_ReferenceSignalsPUSCH.sequenceHoppingEnabled);
+  LOG_T(RRC, PROTOCOL_RRC_CTXT_FMT" pusch_config_common.cyclicShift  = %ld\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon.pusch_ConfigCommon.
+	ul_ReferenceSignalsPUSCH.cyclicShift);
+  
 #if defined(Rel10) || defined(Rel14)
 
-    if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag > 0) {
-      for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count; i++) {
-        // SIB 2
-        //   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", enb_mod_idP, RC.rrc[enb_mod_idP].sib2->mbsfn_SubframeConfigList->list.count);
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
-              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-              i,
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
-              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
-              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
-              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
-      }
-
-      //   SIB13
-      for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
-              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-              i,
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
-              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
-        LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
-              PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
-              RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
-      }
+  if (RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag > 0) {
+    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count; i++) {
+      // SIB 2
+      //   LOG_D(RRC, "[eNB %d] mbsfn_SubframeConfigList.list.count = %ld\n", enb_mod_idP, RC.rrc[enb_mod_idP].sib2->mbsfn_SubframeConfigList->list.count);
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN subframe allocation %d/%d(partial)\n",
+	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	    i,
+	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.count);
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" mbsfn_Subframe_pattern is  = %x\n",
+	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->subframeAllocation.choice.oneFrame.buf[0] >> 0);
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_period  = %ld (just index number, not the real value)\n",
+	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationPeriod);   // need to display the real value, using array of char (like in dumping SIB2)
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" radioframe_allocation_offset  = %ld\n",
+	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList->list.array[i]->radioframeAllocationOffset);
     }
-
+    
+    //   SIB13
+    for (i = 0; i < RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count; i++) {
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" SIB13 contents for MBSFN sync area %d/%d (partial)\n",
+	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	    i,
+	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.count);
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Repetition Period: %ld (just index number, not real value)\n",
+	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_RepetitionPeriod_r9);
+      LOG_D(RRC, PROTOCOL_RRC_CTXT_FMT" MCCH Offset: %ld\n",
+	    PROTOCOL_RRC_CTXT_ARGS(ctxt_pP),
+	    RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9.list.array[i]->mcch_Config_r9.mcch_Offset_r9);
+    }
+  }  
 #endif
 
-    LOG_D(RRC,
-          PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-
-    rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->freqBandIndicator,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq,
-			   (BCCH_BCH_Message_t *)
-			   &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib,
-			   (RadioResourceConfigCommonSIB_t *) &
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon,
-			   (struct PhysicalConfigDedicated *)NULL,
+  LOG_D(RRC,
+	PROTOCOL_RRC_CTXT_FMT" RRC_UE --- MAC_CONFIG_REQ (SIB1.tdd & SIB2 params) ---> MAC_UE\n",
+	PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
+  
+  rrc_mac_config_req_eNB(ctxt_pP->module_id, CC_id,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].physCellId,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].p_eNB,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].Ncp,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->freqBandIndicator,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].dl_CarrierFreq,
+#ifdef Rel14
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].pbch_repetition,
+#endif
+			 (BCCH_BCH_Message_t *)
+			 &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].mib,
+			 (RadioResourceConfigCommonSIB_t *) &
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->radioResourceConfigCommon,
+#if defined(Rel14)
+			 (RadioResourceConfigCommonSIB_t *) &
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2_BR->radioResourceConfigCommon,
+#endif
+			 (struct PhysicalConfigDedicated *)NULL,
 #if defined(Rel10) || defined(Rel14)
-			   (SCellToAddMod_r10_t *)NULL,
-			   //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
+			 (SCellToAddMod_r10_t *)NULL,
+			 //(struct PhysicalConfigDedicatedSCell_r10 *)NULL,
 #endif
-			   (MeasObjectToAddMod_t **) NULL,
-			   (MAC_MainConfig_t *) NULL, 0,
-			   (struct LogicalChannelConfig *)NULL,
-			   (MeasGapConfig_t *) NULL,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->tdd_Config,
-			   NULL,
-			   &SIwindowsize, &SIperiod,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.ul_Bandwidth,
-			   &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.additionalSpectrumEmission,
-			   (MBSFN_SubframeConfigList_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList
+			 (MeasObjectToAddMod_t **) NULL,
+			 (MAC_MainConfig_t *) NULL, 0,
+			 (struct LogicalChannelConfig *)NULL,
+			 (MeasGapConfig_t *) NULL,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib1->tdd_Config,
+			 NULL,
+			 &SIwindowsize, &SIperiod,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].ul_CarrierFreq,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.ul_Bandwidth,
+			 &RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->freqInfo.additionalSpectrumEmission,
+			 (MBSFN_SubframeConfigList_t*) RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib2->mbsfn_SubframeConfigList
 #if defined(Rel10) || defined(Rel14)
-			   ,
-			   RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag,
-			   (MBSFN_AreaInfoList_r9_t*) & RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9,
-			   (PMCH_InfoList_r9_t *) NULL
+			 ,
+			 RC.rrc[ctxt_pP->module_id]->carrier[CC_id].MBMS_flag,
+			 (MBSFN_AreaInfoList_r9_t*) & RC.rrc[ctxt_pP->module_id]->carrier[CC_id].sib13->mbsfn_AreaInfoList_r9,
+			 (PMCH_InfoList_r9_t *) NULL
 #endif
 #ifdef CBA
-			   , 0, //RC.rrc[ctxt_pP->module_id]->num_active_cba_groups,
-			   0    //RC.rrc[ctxt_pP->module_id]->cba_rnti[0]
+			 , 0, //RC.rrc[ctxt_pP->module_id]->num_active_cba_groups,
+			 0    //RC.rrc[ctxt_pP->module_id]->cba_rnti[0]
 #endif
-			   );
-  } else {
-    LOG_E(RRC, PROTOCOL_RRC_CTXT_FMT" init_SI: FATAL, no memory for SIB2/3 allocated\n",
-          PROTOCOL_RRC_CTXT_ARGS(ctxt_pP));
-    mac_xface->macphy_exit("[RRC][init_SI] FATAL, no memory for SIB2/3 allocated");
-  }
+			 );
 }
 
 #if defined(Rel10) || defined(Rel14)
@@ -332,37 +328,33 @@ init_MCCH(
     RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = 0;
     RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] = (uint8_t *) malloc16(32);
 
-    if (RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] == NULL) {
-      LOG_E(RRC, "[eNB %d][MAIN] init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
-      mac_xface->macphy_exit("[RRC][init_MCCH] not enough memory\n");
-    } else {
-      RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
-          sync_area,
-          (uint8_t *)RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
-          &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch,
-          &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message);
-
-      LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
-            RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
-            sync_area);
-      LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
-      LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %ld\n", enb_mod_idP,
-            RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
-      LOG_D(RRC,
-            "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
-            enb_mod_idP, RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
-      LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
-            enb_mod_idP,
-            RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
-            choice.oneFrame.buf[0]);
-
-      if (RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255) {
-        mac_xface->macphy_exit("[RRC][init_MCCH] RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
-      } else {
-        RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
-      }
-    }
+    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area] != NULL,
+		"[eNB %d]init_MCCH: FATAL, no memory for MCCH MESSAGE allocated \n", enb_mod_idP);
+    RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] = do_MBSFNAreaConfig(enb_mod_idP,
+											    sync_area,
+											    (uint8_t *)RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
+											    &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch,
+											    &RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message);
+    
+    LOG_I(RRC, "mcch message pointer %p for sync area %d \n",
+	  RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESSAGE[sync_area],
+	  sync_area);
+    LOG_D(RRC, "[eNB %d] MCCH_MESSAGE  contents for Sync Area %d (partial)\n", enb_mod_idP, sync_area);
+    LOG_D(RRC, "[eNB %d] CommonSF_AllocPeriod_r9 %ld\n", enb_mod_idP,
+	  RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_AllocPeriod_r9);
+    LOG_D(RRC,
+	  "[eNB %d] CommonSF_Alloc_r9.list.count (number of MBSFN Subframe Pattern) %d\n",
+	  enb_mod_idP, RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.count);
+    LOG_D(RRC, "[eNB %d] MBSFN Subframe Pattern: %02x (in hex)\n",
+	  enb_mod_idP,
+	  RC.rrc[enb_mod_idP]->carrier[CC_id].mcch_message->commonSF_Alloc_r9.list.array[0]->subframeAllocation.
+	  choice.oneFrame.buf[0]);
+    
+    AssertFatal(RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] != 255,
+		"RC.rrc[enb_mod_idP]->carrier[CC_id].sizeof_MCCH_MESSAGE[sync_area] == 255");
+    RC.rrc[enb_mod_idP]->carrier[CC_id].MCCH_MESS[sync_area].Active = 1;
   }
+  
 
   //Set the RC.rrc[enb_mod_idP]->MCCH_MESS.Active to 1 (allow to  transfer MCCH message RRC->MAC in function mac_rrc_data_req)
 
@@ -373,7 +365,12 @@ init_MCCH(
   //  LOG_I(RRC, "DUY: serviceID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->tmgi_r9.serviceId_r9.buf[2]);
   //  LOG_I(RRC, "DUY: session ID is %d\n",RC.rrc[enb_mod_idP]->mcch_message->pmch_InfoList_r9.list.array[0]->mbms_SessionInfoList_r9.list.array[0]->sessionId_r9->buf[0]);
   rrc_mac_config_req_eNB(enb_mod_idP, CC_id,
-			 0,0,0,0,0,(BCCH_BCH_Message_t *)NULL,
+			 0,0,0,0,0,
+#ifdef Rel14 
+			 0,
+#endif
+			 (BCCH_BCH_Message_t *)NULL,
+			 (RadioResourceConfigCommonSIB_t *) NULL,
 			 (RadioResourceConfigCommonSIB_t *) NULL,
 			 (struct PhysicalConfigDedicated *)NULL,
 #if defined(Rel10) || defined(Rel14)
@@ -2728,7 +2725,12 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
   rrc_mac_config_req_eNB(
 			 ctxt_pP->module_id,
 			 ue_context_pP->ue_context.primaryCC_id,
-			 0,0,0,0,0,(BCCH_BCH_Message_t *) NULL,
+			 0,0,0,0,0,
+#ifdef Rel14 
+0,
+#endif 
+			 (BCCH_BCH_Message_t *) NULL,
+			 (RadioResourceConfigCommonSIB_t*) NULL,
 			 (RadioResourceConfigCommonSIB_t*) NULL,
 			 ue_context_pP->ue_context.physicalConfigDedicated,
 #if defined(Rel10) || defined(Rel14)
@@ -3301,7 +3303,12 @@ rrc_eNB_generate_RRCConnectionReconfiguration_handover(
   rrc_mac_config_req_eNB(
 			 ctxt_pP->module_id,
 			 ue_context_pP->ue_context.primaryCC_id,
-			 0,0,0,0,0,(BCCH_BCH_Message_t *) NULL,
+			 0,0,0,0,0,
+#ifdef Rel14 
+			 0,
+#endif
+			 (BCCH_BCH_Message_t *) NULL,
+			 (RadioResourceConfigCommonSIB_t *) NULL,
 			 (RadioResourceConfigCommonSIB_t *) NULL,
 			 ue_context_pP->ue_context.physicalConfigDedicated,
 #if defined(Rel10) || defined(Rel14)
@@ -3597,7 +3604,12 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
           rrc_mac_config_req_eNB(
 				 ctxt_pP->module_id,
 				 ue_context_pP->ue_context.primaryCC_id,
-				 0,0,0,0,0,(BCCH_BCH_Message_t *) NULL,
+				 0,0,0,0,0,
+#ifdef Rel14 
+				 0,
+#endif
+				 (BCCH_BCH_Message_t *) NULL,
+				 (RadioResourceConfigCommonSIB_t *) NULL,
 				 (RadioResourceConfigCommonSIB_t *) NULL,
 				 ue_context_pP->ue_context.physicalConfigDedicated,
 #if defined(Rel10) || defined(Rel14)
@@ -3643,7 +3655,12 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
                 PROTOCOL_RRC_CTXT_UE_ARGS(ctxt_pP));
           rrc_mac_config_req_eNB(ctxt_pP->module_id,
 				 ue_context_pP->ue_context.primaryCC_id,
-				 0,0,0,0,0,(BCCH_BCH_Message_t *) NULL,
+				 0,0,0,0,0,
+#ifdef Rel14 
+				 0,
+#endif
+				 (BCCH_BCH_Message_t *) NULL,
+				 (RadioResourceConfigCommonSIB_t *) NULL,
 				 (RadioResourceConfigCommonSIB_t *) NULL,
 				 ue_context_pP->ue_context.physicalConfigDedicated,
 #if defined(Rel10) || defined(Rel14)
@@ -3734,7 +3751,12 @@ rrc_eNB_generate_RRCConnectionSetup(
         rrc_mac_config_req_eNB(
 			       ctxt_pP->module_id,
 			       ue_context_pP->ue_context.primaryCC_id,
-			       0,0,0,0,0,(BCCH_BCH_Message_t *) NULL,
+			       0,0,0,0,0,
+#ifdef Rel14 
+			       0,
+#endif
+			       (BCCH_BCH_Message_t *) NULL,
+			       (RadioResourceConfigCommonSIB_t *) NULL,
 			       (RadioResourceConfigCommonSIB_t *) NULL,
 			       ue_context_pP->ue_context.physicalConfigDedicated,
 #if defined(Rel10) || defined(Rel14)
diff --git a/openair2/UTIL/MEM/mem_block.c b/openair2/UTIL/MEM/mem_block.c
index 606bc7f30f8366fb8cab136ca9ead6a2f9fbf221..81db9c28ddff0de614875d62683fa3942ac3f3dd 100644
--- a/openair2/UTIL/MEM/mem_block.c
+++ b/openair2/UTIL/MEM/mem_block.c
@@ -225,7 +225,7 @@ get_free_mem_block (uint32_t sizeP, const char* caller)
   if (sizeP > MEM_MNGT_MB12_BLOCK_SIZE) {
     LOG_E (RLC,"[MEM_MNGT][ERROR][FATAL] size requested %d out of bounds\n", sizeP);
     display_mem_load ();
-    mac_xface->macphy_exit("[MEM_MNGT][ERROR][FATAL] get_free_mem_block size requested out of bounds");
+    AssertFatal(1==0,"get_free_mem_block size requested out of bounds");
     return NULL;
   }
 
@@ -278,7 +278,7 @@ get_free_mem_block (uint32_t sizeP, const char* caller)
 
   LOG_E(PHY, "[MEM_MNGT][ERROR][FATAL] failed allocating MEM_BLOCK size %d byes (pool_selected=%d size=%d)\n", sizeP, pool_selected, size);
   display_mem_load();
-  mac_xface->macphy_exit("[MEM_MNGT][ERROR][FATAL] get_free_mem_block failed");
+  AssertFatal(1==0,"get_free_mem_block failed");
 
 #ifdef MEMBLOCK_BIG_LOCK
   if (pthread_mutex_unlock(&mtex)) abort();
@@ -317,7 +317,7 @@ get_free_copy_mem_block (void)
     //    break_point ();
     //#endif
 
-    mac_xface->macphy_exit("[MEM_MNGT][ERROR][FATAL] get_free_copy_mem_block failed");
+    AssertFatal(1==0,"mem pool is empty");
     return NULL;
   }
 }
diff --git a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf
index e1bba750f583ff8db5b356127c585216eb43361b..218adf005050ee9fd017a027e418122450fffbf4 100644
--- a/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf
+++ b/targets/PROJECTS/GENERIC-LTE-EPC/CONF/rcc.band7.tm1.if4p5.50PRB.lo.conf
@@ -19,7 +19,9 @@ eNBs =
 
     mobile_network_code =  "93";
 
-       ////////// Physical parameters:
+    tr_s_preference     = "local_mac"
+
+    ////////// Physical parameters:
 
     component_carriers = (
       {
@@ -41,6 +43,7 @@ eNBs =
       nb_antennas_rx          			      = 1;
       tx_gain                                            = 90;
       rx_gain                                            = 125;
+      pbch_repetition                                 = "FALSE";
       prach_root              			      = 0;
       prach_config_index      			      = 0;
       prach_high_speed        			      = "DISABLE";
@@ -174,6 +177,21 @@ eNBs =
   }
 );
 
+MACRLCs = (
+	{
+	num_cc = 1;
+	tr_s_preference = "local_L1";
+	tr_n_preference = "local_RRC";
+        }  
+);
+
+L1s = (
+    	{
+	num_cc = 1;
+	tr_n_preference = "local_mac";
+        }  
+);
+
 RUs = (
     {		  
       	local_if_name  = "lo";			  
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index cf0e551ceb298d900ba0f9739d7fce7faf7c4c5a..23373d177baf0093d5ed1b6d14f780ccac90faca 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -64,7 +64,7 @@
 #include "LAYER2/MAC/proto.h"
 #include "RRC/LITE/extern.h"
 #include "PHY_INTERFACE/extern.h"
-
+#include "PHY_INTERFACE/defs.h"
 #ifdef SMBV
 #include "PHY/TOOLS/smbv.h"
 unsigned short config_frames[4] = {2,9,11,13};
@@ -157,6 +157,12 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
 
   // UE-specific RX processing for subframe n
   phy_procedures_eNB_uespec_RX(eNB, proc, no_relay );
+  LOG_I(PHY,"uespec_RX complete: frame %d, subframe %d\n",proc->frame_rx,proc->subframe_rx);
+  eNB->UL_INFO.frame     = proc->frame_rx;
+  eNB->UL_INFO.subframe  = proc->subframe_rx;
+  eNB->UL_INFO.module_id = eNB->Mod_id;
+  eNB->UL_INFO.CC_id     = eNB->CC_id;
+  eNB->if_inst->UL_indication(&eNB->UL_INFO);
   
   // *****************************************
   // TX processing for subframe n+4
@@ -165,6 +171,8 @@ static inline int rxtx(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc, char *thread_nam
   // *****************************************
   //if (wait_CCs(proc)<0) return(-1);
   
+
+  
   if (oai_exit) return(-1);
   
   phy_procedures_eNB_TX(eNB, proc, no_relay, NULL, 1);
@@ -742,10 +750,10 @@ void init_eNB(int single_thread_flag,int wait_for_sync) {
   int inst;
   PHY_VARS_eNB *eNB;
 
-  if (RC.eNB == NULL) RC.eNB = (PHY_VARS_eNB***) malloc(RC.nb_inst*sizeof(PHY_VARS_eNB **));
-  for (inst=0;inst<RC.nb_inst;inst++) {
+  if (RC.eNB == NULL) RC.eNB = (PHY_VARS_eNB***) malloc(RC.nb_L1_inst*sizeof(PHY_VARS_eNB **));
+  for (inst=0;inst<RC.nb_L1_inst;inst++) {
     if (RC.eNB[inst] == NULL) RC.eNB[inst] = (PHY_VARS_eNB**) malloc(RC.nb_CC[inst]*sizeof(PHY_VARS_eNB *));
-    for (CC_id=0;CC_id<RC.nb_CC[inst];CC_id++) {
+    for (CC_id=0;CC_id<RC.nb_L1_CC[inst];CC_id++) {
       if (RC.eNB[inst][CC_id] == NULL) RC.eNB[inst][CC_id] = (PHY_VARS_eNB*) malloc(sizeof(PHY_VARS_eNB));
       eNB                     = RC.eNB[inst][CC_id]; 
       eNB->abstraction_flag   = 0;
@@ -761,15 +769,19 @@ void init_eNB(int single_thread_flag,int wait_for_sync) {
       eNB->te                   = dlsch_encoding;//(single_thread_flag==1) ? dlsch_encoding_2threads : dlsch_encoding;
 
       
-
+      LOG_I(PHY,"Registering with MAC interface module\n");
+      AssertFatal((eNB->if_inst       = IF_Module_init(inst))!=NULL,"Cannot register interface");
+      eNB->if_inst->schedule_response = schedule_response;
+      eNB->if_inst->PHY_config_req    = phy_config_request;
     }
 
   }
 
 
-  LOG_D(HW,"[lte-softmodem.c] eNB structure allocated\n");
+  LOG_D(PHY,"[lte-softmodem.c] eNB structure allocated\n");
   
- 
+
+
 }
 
 
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 7b89bc7b6042f8070063d4c377c784d20ed533ab..fedcb1b05a649bfc910ae44822330ead541dace4 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -1581,7 +1581,7 @@ int main( int argc, char **argv )
     if (UE_flag==1) {
       printf("Filling UE band info\n");
       fill_ue_band_info();
-      mac_xface->dl_phy_sync_success (0, 0, 0, 1);
+      dl_phy_sync_success (0, 0, 0, 1);
     } 
   }
   
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index e689399b27bcf9d8a256af3b501627ad40c267d3..022f993715b2e696c9c35506b6bdb4db192fba43 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -211,12 +211,10 @@ void init_UE(int nb_inst,int eMBMS_active, int uecap_xer_in) {
 
   LOG_I(PHY,"UE : Calling Layer 2 for initialization\n");
     
-  if (mac_xface==NULL) mac_xface = malloc(sizeof(MAC_xface));  
   l2_init_ue(eMBMS_active,(uecap_xer_in==1)?uecap_xer:NULL,
 	     0,// cba_group_active
 	     0); // HO flag
-  mac_xface->macphy_exit = &exit_fun;
-
+  
   for (inst=0;inst<nb_inst;inst++) {
 
     LOG_I(PHY,"Initializing memory for UE instance %d (%p)\n",inst,PHY_vars_UE_g[inst]);
@@ -511,7 +509,7 @@ static void *UE_thread_synch(void *arg)
 	      fclose(fd);
 	      exit(0);
 	    }
-	    mac_xface->macphy_exit("No cell synchronization found, abandoning");
+	    exit_fun("No cell synchronization found, abandoning");
 	    return &UE_thread_synch_retval; // not reached
 	  }
 	}
@@ -633,14 +631,14 @@ static void *UE_thread_rxn_txnp4(void *arg) {
 
         if (UE->mac_enabled==1) {
 
-            ret = mac_xface->ue_scheduler(UE->Mod_id,
-                                          proc->frame_rx,
-                                          proc->subframe_rx,
-                                          proc->frame_tx,
-                                          proc->subframe_tx,
-                                          subframe_select(&UE->frame_parms,proc->subframe_tx),
-                                          0,
-                                          0/*FIXME CC_id*/);
+            ret = ue_scheduler(UE->Mod_id,
+			       proc->frame_rx,
+			       proc->subframe_rx,
+			       proc->frame_tx,
+			       proc->subframe_tx,
+			       subframe_select(&UE->frame_parms,proc->subframe_tx),
+			       0,
+			       0/*FIXME CC_id*/);
             if ( ret != CONNECTION_OK) {
                 char *txt;
                 switch (ret) {
diff --git a/targets/SIMU/USER/channel_sim.c b/targets/SIMU/USER/channel_sim.c
index f49cd57d727346c0cc5cd2cc7c2ecd4e8f9f0f1f..8efcca81e073f5056366cfd54297f437fa9f8b5a 100644
--- a/targets/SIMU/USER/channel_sim.c
+++ b/targets/SIMU/USER/channel_sim.c
@@ -150,7 +150,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM
       }
 
       // find out which eNB the UE is attached to
-
+      /*
       for (eNB_id=0; eNB_id<RC.nb_inst; eNB_id++) {
         if (find_ue(PHY_vars_UE_g[UE_id][CC_id]->pdcch_vars[0][0]->crnti,RC.eNB[eNB_id][CC_id])>=0) {
           // UE with UE_id is connected to eNb with eNB_id
@@ -158,7 +158,7 @@ void do_DL_sig(channel_desc_t *RU2UE[NUMBER_OF_RU_MAX][NUMBER_OF_UE_MAX][MAX_NUM
           LOG_D(OCM,"A: UE attached to eNB (UE%d->eNB%d)\n",UE_id,eNB_id);
         }
       }
-
+      */
       // if UE is not attached yet, find assume its the eNB with the smallest pathloss
       if (att_eNB_id<0) {
         for (eNB_id=0; eNB_id<NB_eNB_INST; eNB_id++) {
diff --git a/targets/SIMU/USER/event_handler.c b/targets/SIMU/USER/event_handler.c
index c140dab50b6fd4bf4530354c3b85e0e5ae194db9..f0239b621d0830b0b90f6ff5416207c01610285e 100644
--- a/targets/SIMU/USER/event_handler.c
+++ b/targets/SIMU/USER/event_handler.c
@@ -434,6 +434,7 @@ void update_mac(Event_t event)
           UE_list = &eNB_mac_inst->UE_list;
 
           for(i=UE_list->head; i>=0; i=UE_list->next[i]) {
+	    /*
             if(&mac_config[i].DCI_aggregation_min) {
               LOG_I(EMU,"update dci aggregation min\n");
               oai_emulation->mac_config[i].DCI_aggregation_min= mac_config[i].DCI_aggregation_min;
@@ -449,6 +450,7 @@ void update_mac(Event_t event)
               LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n",i);
               LOG_I(EMU,"%" PRIu8,UE_list->UE_template[0][i].DLSCH_dci_size_bits);
             }
+	    */
 
             if(mac_config[i].priority !=NULL) {
               LOG_I(EMU,"update priority \n");
@@ -546,7 +548,7 @@ void update_mac(Event_t event)
           LOG_I(EMU,"update complete mac params \n");
           i = event.ue;
           int j = event.lcid;
-
+	  /*
           if(&mac_config[i].DCI_aggregation_min) {
             LOG_I(EMU,"update dci aggregation min\n");
             oai_emulation->mac_config[i].DCI_aggregation_min= mac_config[i].DCI_aggregation_min;
@@ -562,7 +564,7 @@ void update_mac(Event_t event)
             LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n",i);
             LOG_I(EMU,"%" PRIu8,UE_list->UE_template[0][i].DLSCH_dci_size_bits);
           }
-
+	  */
           if(mac_config[i].priority !=NULL) {
             LOG_I(EMU,"update priority \n");
 
@@ -690,18 +692,18 @@ void update_mac(Event_t event)
 
       if(event.ue == -1) {
         UE_list = &eNB_mac_inst->UE_list;
-
+	/*
         for(i=UE_list->head; i>=0; i=UE_list->next[i]) {
           oai_emulation->mac_config[i].DCI_aggregation_min=mac_config[i].DCI_aggregation_min;
           UE_list->UE_template[0][i].DCI_aggregation_min = oai_emulation->mac_config[i].DCI_aggregation_min;
           LOG_I(EMU,"DCI_aggregation_min UE %d : \n", i);
           LOG_I(EMU,"%" PRIu8 "\n",UE_list->UE_template[0][i].DCI_aggregation_min);
-        }
+	  }*/
       } else {
-        oai_emulation->mac_config[event.ue].DCI_aggregation_min=mac_config[event.ue].DCI_aggregation_min;
+	/*        oai_emulation->mac_config[event.ue].DCI_aggregation_min=mac_config[event.ue].DCI_aggregation_min;
         UE_list->UE_template[0][event.ue].DCI_aggregation_min = oai_emulation->mac_config[event.ue].DCI_aggregation_min;
         LOG_I(EMU,"DCI_aggregation_min UE %d : \n", event.ue);
-        LOG_I(EMU,"%" PRIu8 "\n",UE_list->UE_template[0][event.ue].DCI_aggregation_min);
+        LOG_I(EMU,"%" PRIu8 "\n",UE_list->UE_template[0][event.ue].DCI_aggregation_min);*/
       }
     } else if(!strcmp((char *) event.key, "DLSCH_dci_size_bits") && event.value!=NULL && validate_mac(event)) {
       Mac_config* mac_config;// = malloc(sizeof(Mac_config)*16);
@@ -712,18 +714,18 @@ void update_mac(Event_t event)
 
       if(event.ue == -1) {
         UE_list = &eNB_mac_inst->UE_list;
-
+	/*
         for(i=UE_list->head; i>=0; i=UE_list->next[i]) {
           oai_emulation->mac_config[i].DLSCH_dci_size_bits=mac_config[i].DLSCH_dci_size_bits;
           UE_list->UE_template[0][i].DLSCH_dci_size_bits = oai_emulation->mac_config[i].DLSCH_dci_size_bits;
           LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n", i);
           LOG_I(EMU,"%" PRIu8,UE_list->UE_template[0][i].DLSCH_dci_size_bits);
-        }
+	  }*/
       } else {
-        oai_emulation->mac_config[event.ue].DLSCH_dci_size_bits=mac_config[event.ue].DLSCH_dci_size_bits;
+	/*        oai_emulation->mac_config[event.ue].DLSCH_dci_size_bits=mac_config[event.ue].DLSCH_dci_size_bits;
         UE_list->UE_template[0][event.ue].DLSCH_dci_size_bits = oai_emulation->mac_config[event.ue].DLSCH_dci_size_bits;
         LOG_I(EMU,"DLSCH_dci_size_bits UE %d: \n", event.ue);
-        LOG_I(EMU,"%" PRIu8,UE_list->UE_template[0][event.ue].DLSCH_dci_size_bits);
+        LOG_I(EMU,"%" PRIu8,UE_list->UE_template[0][event.ue].DLSCH_dci_size_bits);*/
       }
 
     } else if(!strcmp((char *) event.key, "ul_bandwidth") && event.value!=NULL) {
diff --git a/targets/SIMU/USER/oaisim.c b/targets/SIMU/USER/oaisim.c
index 5056e9e95727f974b0a2fb497627dc7214531579..913b6a42f35d512ed6c11c48f7cc4f65f372f4dd 100644
--- a/targets/SIMU/USER/oaisim.c
+++ b/targets/SIMU/USER/oaisim.c
@@ -625,7 +625,7 @@ l2l1_task (void *args_p)
 
   if (abstraction_flag == 1) {
     for (UE_id = 0; UE_id < NB_UE_INST; UE_id++)
-      mac_xface->dl_phy_sync_success (UE_id, 0, 0,1);   //UE_id%NB_eNB_INST);
+      dl_phy_sync_success (UE_id, 0, 0,1);   //UE_id%NB_eNB_INST);
   }
   
   start_meas (&oaisim_stats);
@@ -733,7 +733,7 @@ l2l1_task (void *args_p)
         log_set_instance_type (LOG_INSTANCE_ENB);
 #endif
 
-	clear_eNB_transport_info (oai_emulation.info.nb_enb_local);
+
 	CC_id=0;
         int all_done=0;
 
@@ -830,8 +830,6 @@ l2l1_task (void *args_p)
           }
         }// eNB_inst loop
 
-        // Call ETHERNET emulation here
-        //emu_transport (frame, last_slot, next_slot, direction, oai_emulation.info.frame_type, ethernet_flag);
 
 #if defined(ENABLE_ITTI)
         log_set_instance_type (LOG_INSTANCE_UE);
@@ -1895,10 +1893,6 @@ oai_shutdown (void)
   if (oai_emulation.info.opp_enabled == 1)
     print_opp_meas_oaisim ();
 
-  // relase all rx state
-  if (ethernet_flag == 1) {
-    emu_transport_release ();
-  }
 
 #ifdef PROC
 
diff --git a/targets/SIMU/USER/oaisim_functions.c b/targets/SIMU/USER/oaisim_functions.c
index 016b6ead0f0f315afcf0d2136edf3573b746b7f5..f916faed6ea0500caba2a151c6a612fdda882d3c 100644
--- a/targets/SIMU/USER/oaisim_functions.c
+++ b/targets/SIMU/USER/oaisim_functions.c
@@ -882,7 +882,7 @@ void check_and_adjust_params(void)
 
   if (ret < 0)
     LOG_W(EMU,"[INIT] Netlink not available, careful ...\n");
-
+  /*
   if (ethernet_flag == 1) {
     oai_emulation.info.master[oai_emulation.info.master_id].nb_ue = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_rn_local;
     oai_emulation.info.master[oai_emulation.info.master_id].nb_enb = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_rn_local;
@@ -904,14 +904,14 @@ void check_and_adjust_params(void)
     }
 
     LOG_I (EMU, " Total number of master %d my master id %d\n", oai_emulation.info.nb_master, oai_emulation.info.master_id);
-    init_bypass ();
+    //    init_bypass ();
 
     while (emu_tx_status != SYNCED_TRANSPORT) {
       LOG_I (EMU, " Waiting for EMU Transport to be synced\n");
       emu_transport_sync ();    //emulation_tx_rx();
     }
   } // ethernet flag
-
+  */
   //
   NB_UE_INST = oai_emulation.info.nb_ue_local + oai_emulation.info.nb_ue_remote;
   NB_eNB_INST = oai_emulation.info.nb_enb_local + oai_emulation.info.nb_enb_remote;