diff --git a/common/utils/T/T_messages.txt b/common/utils/T/T_messages.txt
index 6e5e0ad7aa26f86d760c6df773782f076cbe23c5..3e3ba082dd8aa2c42287bb53f1703cdcdef22a9a 100644
--- a/common/utils/T/T_messages.txt
+++ b/common/utils/T/T_messages.txt
@@ -65,6 +65,14 @@ ID = ENB_PHY_PHICH
     DESC = eNodeB PHICH
     GROUP = ALL:PHY:ENB
     FORMAT = int,eNB_ID : int,frame : int,subframe : int,UE_id : int,rnti : int,harq_pid : int,NGROUP : int,NSF : int,ngroup : int,nseq : int,ACK : int,first_rb : int,n_DMRS
+ID = ENB_PHY_MSG3_ALLOCATION
+    DESC = eNodeB Msg3 allocation/reallocation
+    GROUP = ALL:PHY:ENB
+    FORMAT = int,eNB_ID : int,frame : int,subframe : int,UE_id : int,rnti : int,first_transmission : int,Msg3_frame : int,Msg3_subframe
+ID = ENB_PHY_INITIATE_RA_PROCEDURE
+    DESC = eNodeB initiates a random access procedure after detecting enough energy for one of the preambles
+    GROUP = ALL:PHY:ENB
+    FORMAT = int,eNB_ID : int,frame : int,subframe : int,UE_id : int,preamble : int,energy : int,delay
 
 #MAC logs
 ID = ENB_MAC_UE_DL_SDU
@@ -74,7 +82,7 @@ ID = ENB_MAC_UE_DL_SDU
 ID = ENB_MAC_UE_UL_SCHEDULE
     DESC = MAC uplink UE scheduling decision
     GROUP = ALL:MAC:ENB
-    FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,harq_pid : int,mcs : int,first_rb : int,nb_rb : int,TBS
+    FORMAT = int,eNB_ID : int,CC_id : int,rnti : int,frame : int,subframe : int,harq_pid : int,mcs : int,first_rb : int,nb_rb : int,TBS : int,ndi
 ID = ENB_MAC_UE_UL_SCHEDULE_RETRANSMISSION
     DESC = MAC uplink UE scheduling retransmission decision
     GROUP = ALL:MAC:ENB
diff --git a/common/utils/T/tracer/macpdu2wireshark.c b/common/utils/T/tracer/macpdu2wireshark.c
index 886638f5ef2c6774045395cc593e20cbd12a50a9..be0bbd382142bf82f171401bac34f91a7e4d4f67 100644
--- a/common/utils/T/tracer/macpdu2wireshark.c
+++ b/common/utils/T/tracer/macpdu2wireshark.c
@@ -177,7 +177,7 @@ void usage(void)
   printf(
 "options:\n"
 "    -d <database file>        this option is mandatory\n"
-"    -in <dump file>           read events from this dump file\n"
+"    -i <dump file>            read events from this dump file\n"
 "    -ip <IP address>          send packets to this IP address (default %s)\n"
 "    -p <port>                 send packets to this port (default %d)\n",
   DEFAULT_IP,
@@ -205,7 +205,7 @@ int main(int n, char **v)
     if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage();
     if (!strcmp(v[i], "-d"))
       { if (i > n-2) usage(); database_filename = v[++i]; continue; }
-    if (!strcmp(v[i], "-in"))
+    if (!strcmp(v[i], "-i"))
       { if (i > n-2) usage(); input_filename = v[++i]; continue; }
     if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; }
     if (!strcmp(v[i], "-p")) {if(i>n-2)usage(); port=atoi(v[++i]); continue; }
diff --git a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
index 4cdfb4f7949828b254fe382a5536dcbfa4cff3e7..ff7e02a239b777db692c46773a79db67f5911fab 100644
--- a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
+++ b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
@@ -486,7 +486,7 @@ void compute_beta8(llr_t* alpha,llr_t* beta,llr_t *m_11,llr_t* m_10,unsigned sho
 
 #endif
 
-  if (frame_length > 6143) {
+  if (frame_length > 6144) {
     LOG_E(PHY,"compute_beta: frame_length %d\n",frame_length);
     return;
   }
diff --git a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
index 80dfb69877a157e1f1c56b8b5f816c36752faf00..0ce810a52cfabd7d856bcee07d0f7cfe095abef8 100644
--- a/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/ulsch_decoding.c
@@ -449,7 +449,7 @@ int ulsch_decoding_data_2thread(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr
   int16_t dummy_w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)];
   LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id];
   LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
-  int Q_m = get_Qm_ul(ulsch_harq->mcs);
+  //int Q_m = get_Qm_ul(ulsch_harq->mcs);
   int G = ulsch_harq->G;
   unsigned int E;
   int Cby2;
@@ -657,7 +657,7 @@ int ulsch_decoding_data(PHY_VARS_eNB *eNB,int UE_id,int harq_pid,int llr8_flag)
   int16_t dummy_w[MAX_NUM_ULSCH_SEGMENTS][3*(6144+64)];
   LTE_eNB_ULSCH_t *ulsch = eNB->ulsch[UE_id];
   LTE_UL_eNB_HARQ_t *ulsch_harq = ulsch->harq_processes[harq_pid];
-  int Q_m = get_Qm_ul(ulsch_harq->mcs);
+  //int Q_m = get_Qm_ul(ulsch_harq->mcs);
   int G = ulsch_harq->G;
   unsigned int E;
 
@@ -1533,6 +1533,7 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
   // CQI
 
   //  printf("before cqi c[%d] = %p\n",0,ulsch_harq->c[0]);
+  ulsch_harq->cqi_crc_status = 0;
   if (Q_CQI>0) {
     memset((void *)&dummy_w_cc[0],0,3*(ulsch_harq->Or1+8+32));
 
@@ -1555,9 +1556,6 @@ unsigned int  ulsch_decoding(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,
 
     if (extract_cqi_crc(o_flip,ulsch_harq->Or1) == (crc8(o_flip,ulsch_harq->Or1)>>24))
       ulsch_harq->cqi_crc_status = 1;
-    else
-      ulsch_harq->cqi_crc_status = 0;
-
 
     if (ulsch->harq_processes[harq_pid]->Or1<=32) {
       ulsch_harq->o[3] = o_flip[0] ;
diff --git a/openair1/SCHED/phy_mac_stub.c b/openair1/SCHED/phy_mac_stub.c
index da1147fe8de92ca5dec756b991d7d84078667741..cae8b8c82ea2b4241b29b64acfbbf27b2363370d 100644
--- a/openair1/SCHED/phy_mac_stub.c
+++ b/openair1/SCHED/phy_mac_stub.c
@@ -70,6 +70,7 @@ void fill_dci(DCI_PDU *DCI_pdu,PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
   case 5:
     DCI_pdu->Num_common_dci = 1;
     DCI_pdu->dci_alloc[0].L          = 2;
+    DCI_pdu->dci_alloc[0].firstCCE   = 0;
     DCI_pdu->dci_alloc[0].rnti       = SI_RNTI;
     DCI_pdu->dci_alloc[0].format     = format1A;
     DCI_pdu->dci_alloc[0].ra_flag    = 0;
@@ -212,6 +213,7 @@ void fill_dci(DCI_PDU *DCI_pdu,PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc)
   case 7:
     DCI_pdu->Num_ue_spec_dci = 1;
     DCI_pdu->dci_alloc[0].L          = 2;
+    DCI_pdu->dci_alloc[0].firstCCE   = 0;
     DCI_pdu->dci_alloc[0].rnti       = 0x1235;
     DCI_pdu->dci_alloc[0].format     = format1;
     DCI_pdu->dci_alloc[0].ra_flag    = 0;
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index ecb0c23a5f136f07373f92a278b62a68bebac9c1..c5b9b89f7eda67e473c472ef9ede6ac91aa59970 100644
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -977,6 +977,22 @@ void pdsch_procedures(PHY_VARS_eNB *eNB,eNB_rxtx_proc_t *proc,LTE_eNB_DLSCH_t *d
 		UE_id,
 		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;
+
+          mac_xface->set_msg3_subframe(eNB->Mod_id, eNB->CC_id, frame, subframe, (uint16_t)crnti,
+                                       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(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;
       }
@@ -1970,6 +1986,9 @@ void prach_procedures(PHY_VARS_eNB *eNB) {
             preamble_energy_max%10,
             preamble_delay_list[preamble_max]);
 
+      T(T_ENB_PHY_INITIATE_RA_PROCEDURE, T_INT(eNB->Mod_id), T_INT(frame), T_INT(subframe), T_INT(UE_id),
+        T_INT(preamble_max), T_INT(preamble_energy_max), T_INT(preamble_delay_list[preamble_max]));
+
       if (eNB->mac_enabled==1) {
         uint8_t update_TA=4;
 
@@ -3070,6 +3089,13 @@ 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*/),
+              T_INT(eNB->ulsch[i]->Msg3_frame), T_INT(eNB->ulsch[i]->Msg3_subframe));
           }
           LOG_D(PHY,"[eNB] Frame %d, Subframe %d: Msg3 in error, i = %d \n", frame,subframe,i);
         } // This is Msg3 error
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 0da90652c044f4c71bb32e0e204494b11c9872df..23ba001d4c3804a011fb4dd1c333686484e64be3 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -259,7 +259,8 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 			   RA_template->RA_dci_fmt1,
 			   1);
 
-	    RA_template->Msg3_subframe=Msg3_subframe;
+            /* this will be updated when PHY calls set_msg3_subframe */
+	    RA_template->Msg3_subframe = -1;
 	  }
         } else if (RA_template->generate_Msg4 == 1) {
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
index a65ec917deb20667e30c879fe14d5fdfcc012d03..671e95aec57d040a6bedbd5a9e9e03506cd32dd9 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_ulsch.c
@@ -601,6 +601,29 @@ unsigned char *parse_ulsch_header(unsigned char *mac_header,
   return(mac_header_ptr);
 }
 
+/* This function is called by PHY layer when it schedules some
+ * uplink for a random access message 3.
+ * The MAC scheduler has to skip the RBs used by this message 3
+ * (done below in schedule_ulsch).
+ */
+void set_msg3_subframe(module_id_t Mod_id,
+                       int CC_id,
+                       int frame,
+                       int subframe,
+                       int rnti,
+                       int Msg3_frame,
+                       int Msg3_subframe)
+{
+  eNB_MAC_INST *eNB=&eNB_mac_inst[Mod_id];
+  int i;
+  for (i=0; i<NB_RA_PROC_MAX; i++) {
+    if (eNB->common_channels[CC_id].RA_template[i].RA_active == TRUE &&
+        eNB->common_channels[CC_id].RA_template[i].rnti == rnti) {
+      eNB->common_channels[CC_id].RA_template[i].Msg3_subframe = Msg3_subframe;
+      break;
+    }
+  }
+}
 
 void schedule_ulsch(module_id_t module_idP, 
 		    frame_t frameP,
@@ -619,6 +642,7 @@ void schedule_ulsch(module_id_t module_idP,
 
   for (CC_id=0; CC_id<MAX_NUM_CCs; CC_id++) {
 
+    //leave out first RB for PUCCH
     first_rb[CC_id] = 1;
 
     // UE data info;
@@ -637,9 +661,11 @@ void schedule_ulsch(module_id_t module_idP,
     for (i=0; i<NB_RA_PROC_MAX; i++) {
       if ((eNB->common_channels[CC_id].RA_template[i].RA_active == TRUE) &&
           (eNB->common_channels[CC_id].RA_template[i].generate_rar == 0) &&
+          (eNB->common_channels[CC_id].RA_template[i].generate_Msg4 == 0) &&
+          (eNB->common_channels[CC_id].RA_template[i].wait_ack_Msg4 == 0) &&
           (eNB->common_channels[CC_id].RA_template[i].Msg3_subframe == sched_subframe)) {
-	//leave out first RB for PUCCH
         first_rb[CC_id]++;
+        eNB->common_channels[CC_id].RA_template[i].Msg3_subframe = -1;
         break;
       }
     }
@@ -854,7 +880,7 @@ void schedule_ulsch_rnti(module_id_t   module_idP,
 
             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(TBS), T_INT(ndi));
 
 	    // bad indices : 20 (40 PRB), 21 (45 PRB), 22 (48 PRB)
             // increment for next UE allocation
diff --git a/openair2/LAYER2/MAC/main.c b/openair2/LAYER2/MAC/main.c
index 4fee906f7497bec84e9876eaf5e868c59a170f30..0fe9d63b6ff26ba5d03ebe4bb95e004627f2875a 100644
--- a/openair2/LAYER2/MAC/main.c
+++ b/openair2/LAYER2/MAC/main.c
@@ -454,6 +454,7 @@ int l2_init(LTE_DL_FRAME_PARMS *frame_parms,int eMBMS_active, char *uecap_xer,ui
   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;
diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h
index 59d6c352feca094bebe2059038059d313ed22fc9..4df0c6fa459861f441404ebf4419f57a772a071e 100644
--- a/openair2/LAYER2/MAC/proto.h
+++ b/openair2/LAYER2/MAC/proto.h
@@ -246,6 +246,25 @@ unsigned short fill_rar(
 */
 void cancel_ra_proc(module_id_t module_idP,int CC_id,frame_t frameP, uint16_t preamble_index);
 
+/* \brief Function used by PHY to inform MAC that an uplink is scheduled
+          for Msg3 in given subframe. This is used so that the MAC
+          scheduler marks as busy the RBs used by the Msg3.
+@param Mod_id        Instance ID of eNB
+@param CC_id         CC ID of eNB
+@param frame         current frame
+@param subframe      current subframe
+@param rnti          UE rnti concerned
+@param Msg3_frame    frame where scheduling takes place
+@param Msg3_subframe subframe where scheduling takes place
+*/
+void set_msg3_subframe(module_id_t Mod_id,
+                       int CC_id,
+                       int frame,
+                       int subframe,
+                       int rnti,
+                       int Msg3_frame,
+                       int Msg3_subframe);
+
 /* \brief Function to indicate a received SDU on ULSCH.
 @param Mod_id Instance ID of eNB
 @param rnti RNTI of UE transmitting the SR
diff --git a/openair2/PHY_INTERFACE/defs.h b/openair2/PHY_INTERFACE/defs.h
index 0892b4d0b17775667d898f65f315359af37edc2d..8c711e971de8d7fe0a955bcad5ca09904ad63b92 100644
--- a/openair2/PHY_INTERFACE/defs.h
+++ b/openair2/PHY_INTERFACE/defs.h
@@ -72,6 +72,16 @@ typedef struct {
   /// cancel an ongoing RA procedure
   void (*cancel_ra_proc)(module_id_t Mod_id,int CC_id,frame_t frameP,uint16_t preamble);
 
+  /// Inform MAC layer that an uplink is scheduled for Msg3 in given subframe.
+  /// This is used so that the MAC scheduler marks as busy the RBs used by the Msg3.
+  void (*set_msg3_subframe)(module_id_t Mod_id,
+                            int CC_id,
+                            int frame,
+                            int subframe,
+                            int rnti,
+                            int Msg3_frame,
+                            int Msg3_subframe);
+
   /// Get DCI for current subframe from MAC
   DCI_PDU* (*get_dci_sdu)(module_id_t Mod_id,int CC_id,frame_t frameP,sub_frame_t subframe);
 
diff --git a/targets/RT/USER/lte-softmodem.c b/targets/RT/USER/lte-softmodem.c
index 0cca7b637980960dac53751d32d0420017cb6225..d2362081dea8c8764ce4867a9332ee04bb5e621f 100644
--- a/targets/RT/USER/lte-softmodem.c
+++ b/targets/RT/USER/lte-softmodem.c
@@ -1601,6 +1601,11 @@ int main( int argc, char **argv )
       PHY_vars_eNB_g[0][CC_id] = init_lte_eNB(frame_parms[CC_id],0,frame_parms[CC_id]->Nid_cell,abstraction_flag);
       PHY_vars_eNB_g[0][CC_id]->CC_id = CC_id;
 
+      PHY_vars_eNB_g[0][CC_id]->ue_dl_rb_alloc=0x1fff;
+      PHY_vars_eNB_g[0][CC_id]->target_ue_dl_mcs=target_dl_mcs;
+      PHY_vars_eNB_g[0][CC_id]->ue_ul_nb_rb=6;
+      PHY_vars_eNB_g[0][CC_id]->target_ue_ul_mcs=target_ul_mcs;
+
       if (phy_test==1) PHY_vars_eNB_g[0][CC_id]->mac_enabled = 0;
       else PHY_vars_eNB_g[0][CC_id]->mac_enabled = 1;