From 4ea75401319a1b8e2f963657155d703d59b4858b Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Wed, 18 Feb 2015 20:37:02 +0000
Subject: [PATCH] Applications of S. Held (IMST) from 16.02.15, modifications
 in lte-ue.c for FDD transmission, patches from D. Panaitopol (Thales) in
 prach.c, RK

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@6580 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
 openair1/PHY/CODING/3gpplte_sse.c             |   7 +-
 .../CODING/3gpplte_turbo_decoder_sse_16bit.c  |   2 +-
 .../CODING/3gpplte_turbo_decoder_sse_8bit.c   |   2 +-
 openair1/PHY/INIT/lte_init.c                  |   2 +-
 .../PHY/LTE_ESTIMATION/lte_sync_timefreq.c    |  86 ++++++-----
 .../PHY/LTE_ESTIMATION/lte_sync_timefreq.m    |   1 -
 openair1/PHY/LTE_TRANSPORT/dci.c              |   1 +
 openair1/PHY/LTE_TRANSPORT/dci_tools.c        |   1 +
 openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c   |   9 +-
 openair1/PHY/LTE_TRANSPORT/prach.c            |  56 ++++++-
 openair1/SCHED/phy_procedures_lte_common.c    |   9 +-
 openair1/SCHED/phy_procedures_lte_eNb.c       |   1 +
 .../SIMULATION/ETH_TRANSPORT/multicast_link.c |   2 +-
 openair1/SIMULATION/LTE_PHY/scansim.c         |   4 +-
 openair2/LAYER2/MAC/eNB_scheduler_RA.c        |   7 +-
 openair2/LAYER2/MAC/eNB_scheduler_dlsch.c     |   1 +
 openair2/LAYER2/MAC/pre_processor.c           |  10 +-
 openair2/LAYER2/MAC/ra_procedures.c           |   4 +-
 openair2/LAYER2/MAC/rar_tools.c               |   2 +
 openair2/LAYER2/MAC/ue_procedures.c           |   3 +-
 openair2/UTIL/MEM/mem_block.c                 | 140 ++++++++++--------
 openair2/UTIL/OMG/sumo.c                      |   9 +-
 openair2/UTIL/OTG/otg_models.c                |   2 +-
 targets/RT/USER/lte-ue.c                      |  34 ++++-
 targets/RT/USER/rrh.c                         |  54 +++++--
 targets/SIMU/USER/event_handler.c             |   2 +-
 26 files changed, 305 insertions(+), 146 deletions(-)

diff --git a/openair1/PHY/CODING/3gpplte_sse.c b/openair1/PHY/CODING/3gpplte_sse.c
index c3197d3c16..b392e12be1 100755
--- a/openair1/PHY/CODING/3gpplte_sse.c
+++ b/openair1/PHY/CODING/3gpplte_sse.c
@@ -81,7 +81,10 @@ void treillis_table_init(void) {
   int i, j,b;
   unsigned char v, current_state;
 
-  bzero(all_treillis,sizeof(all_treillis));
+  // clear all_treillis
+  for (i=0; i<8; i++)
+    bzero( all_treillis[i], sizeof(all_treillis[0]) );
+
   for (i=0; i<8; i++) { //all possible initial states
     for (j=0; j<=255; j++) { // all possible values of a byte
       current_state=i;
@@ -219,7 +222,7 @@ void threegpplte_turbo_encoder(unsigned char *input,
     treillis_table_init();
   
   // look for f1 and f2 precomputed interleaver values
-  for (i=0;f1f2mat[i].nb_bits!= input_length_bits && i <188; i++);
+  for (i=0; i < 188 && f1f2mat[i].nb_bits != input_length_bits; i++);
   if ( i == 188 ) {
     msg("Illegal frame length!\n");
     return;
diff --git a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c
index 29f2de0c74..55d0581ba0 100644
--- a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c
+++ b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_16bit.c
@@ -702,7 +702,7 @@ unsigned char phy_threegpplte_turbo_decoder16(short *y,
 
 
 
-  for (iind=0;f1f2mat[iind].nb_bits!=n && iind <188; iind++);
+  for (iind=0; iind < 188 && f1f2mat[iind].nb_bits != n; iind++);
   if ( iind == 188 ) {
     msg("Illegal frame length!\n");
     return 255;
diff --git a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
index ef4d25156b..d3e1253755 100644
--- a/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
+++ b/openair1/PHY/CODING/3gpplte_turbo_decoder_sse_8bit.c
@@ -660,7 +660,7 @@ unsigned char phy_threegpplte_turbo_decoder8(short *y,
     n2 = n;
 
 
-  for (iind=0;f1f2mat[iind].nb_bits!=n && iind <188; iind++);
+  for (iind=0; iind < 188 && f1f2mat[iind].nb_bits != n; iind++);
   if ( iind == 188 ) {
     msg("Illegal frame length!\n");
     return 255;
diff --git a/openair1/PHY/INIT/lte_init.c b/openair1/PHY/INIT/lte_init.c
index 667925bcb2..9fb665b270 100644
--- a/openair1/PHY/INIT/lte_init.c
+++ b/openair1/PHY/INIT/lte_init.c
@@ -1284,7 +1284,7 @@ int phy_init_lte_eNB(PHY_VARS_eNB *phy_vars_eNB,
     
   // ULSCH VARS
 
-  eNB_prach_vars->prachF = (int16_t*)malloc16_clear( 1024*sizeof(int16_t) );
+  eNB_prach_vars->prachF = (int16_t*)malloc16_clear( 2*1024 /*FIXME what is the correct number?*/ *sizeof(int16_t) );
  
   AssertFatal( frame_parms->nb_antennas_rx <= sizeof(eNB_prach_vars->rxsigF), "nb_antennas_rx too large" );
   for (i=0; i<frame_parms->nb_antennas_rx; i++) {
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.c b/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.c
index 87e3178fb7..a2d4c91b73 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.c
+++ b/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.c
@@ -64,7 +64,7 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
   int16_t *sp;
   __m128i *sp2;
   __m128i s;
-  int re;
+  int re,re256;
   __m128i mmtmp00,mmtmp01,mmtmp02,mmtmp10,mmtmp11,mmtmp12;
   int maxcorr[3],minamp,pos,pssind;
   int16_t *pss6144_0,*pss6144_1,*pss6144_2;
@@ -72,7 +72,7 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
   
   
   //    for (i=0;i<38400*4;i+=3072)   // steps of 200 us with 100 us overlap, 0 to 5s
-
+  write_output("rxsig0.m","rxs0",ue->lte_ue_common_vars.rxdata[0],30720,1,1);
   for (i = 15360-3072*2;i<15360+3072+1;i+=3072)  {
 
  
@@ -85,25 +85,28 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
 	//compute frequency-domain representation of 6144-sample chunk
 	fft6144((int16_t *)rxp,
 		sp);
-	printf("sp %p\n",sp);
-	if (i==12288)
+	printf("i %d: sp %p\n",i,sp);
+
+	if (i==12288){
 	  write_output("scan6144F.m","s6144F",sp,6144,1,1);
-	  for (f = -130;f<-125;f++) {  // this is -10MHz to 10 MHz in 5 kHz steps
-	    
-	    if ((f<-256)||(f>=0)) { // no split around DC
-	      printf("No split, f %d\n",f);
-	      // align filters and input buffer pointer to 128-bit
-	      switch (f&3) {
-	      case 0: 
-		pss6144_0 = &pss6144_0_0[0];
-		pss6144_1 = &pss6144_1_0[0];
-		pss6144_2 = &pss6144_2_0[0];
-		sp2 = (f<0) ? (__m128i*)&sp[12288+(f<<1)] : (__m128i*)&sp;
-		break;
-	      case 1: 
-		pss6144_0 = &pss6144_0_1[0];
-		pss6144_1 = &pss6144_1_1[0];
-		pss6144_2 = &pss6144_2_1[0];
+	  write_output("scan6144.m","s6144",rxp,6144,1,1);
+	}
+	for (f = -130;f<-125;f++) {  // this is -10MHz to 10 MHz in 5 kHz steps
+	  
+	  if ((f<-256)||(f>=0)) { // no split around DC
+	    printf("No split, f %d (%d)\n",f,f&3);
+	    // align filters and input buffer pointer to 128-bit
+	    switch (f&3) {
+	    case 0: 
+	      pss6144_0 = &pss6144_0_0[0];
+	      pss6144_1 = &pss6144_1_0[0];
+	      pss6144_2 = &pss6144_2_0[0];
+	      sp2 = (f<0) ? (__m128i*)&sp[12288+(f<<1)] : (__m128i*)&sp;
+	      break;
+	    case 1: 
+	      pss6144_0 = &pss6144_0_1[0];
+	      pss6144_1 = &pss6144_1_1[0];
+	      pss6144_2 = &pss6144_2_1[0];
 		sp2 = (f<0) ? (__m128i*)&sp[12286+(f<<1)] : (__m128i*)sp;
 		break;
 	      case 2: 
@@ -119,7 +122,7 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
 		sp2 = (f<0) ? (__m128i*)&sp[12282+(f<<1)] : (__m128i*)sp;
 		break;
 	      } 
-
+	      re256=32;
 	      for (re = 0; re<256/4; re++) {  // loop over 256 points of upsampled PSS
 		s = sp2[re];
 		mmtmp00 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_0)[re],s),15);
@@ -133,14 +136,15 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
 		mmtmp11 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_1)[re],s),15);
 		mmtmp12 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_2)[re],s),15);
 		
-		autocorr0[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp00,mmtmp10),_mm_unpackhi_epi32(mmtmp00,mmtmp10));
-		autocorr1[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp01,mmtmp11),_mm_unpackhi_epi32(mmtmp01,mmtmp11));
-		autocorr2[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp02,mmtmp12),_mm_unpackhi_epi32(mmtmp02,mmtmp12));
-		
+		autocorr0[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp00,mmtmp10),_mm_unpackhi_epi32(mmtmp00,mmtmp10));
+		autocorr1[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp01,mmtmp11),_mm_unpackhi_epi32(mmtmp01,mmtmp11));
+		autocorr2[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp02,mmtmp12),_mm_unpackhi_epi32(mmtmp02,mmtmp12));
+
+		re256 = (re256+1)&0x3f;
 	      }
 	    }
 	    else { // Split around DC, this is the negative frequencies
-	      printf("split around DC, f %d (f/4 %d)\n",f,f>>2);
+	      printf("split around DC, f %d (f/4 %d, f&3 %d)\n",f,f>>2,f&3);
 	      // align filters and input buffer pointer to 128-bit	      
 	      switch (f&3) {
 	      case 0: 
@@ -168,11 +172,12 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
 		sp2 = (__m128i*)&sp[12282+(f<<1)];
 		break;
 	      } 
-	      for (re = 0; re<(256+f)/4; re++) {  // loop over 256 points of upsampled PSS
+	      re256 = 32;
+	      for (re = 0; re<(-f+3)/4; re++) {  // loop over 256 points of upsampled PSS
 		s = sp2[re];
 		printf("re %d, %p\n",re,&sp2[re]);
 		print_shorts("s",&s);
-		print_shorts("pss",&pss6144_0[re]);
+		print_shorts("pss",&((__m128i*)pss6144_0)[re]);
 
 		mmtmp00 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_0)[re],s),15);
 		mmtmp01 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_1)[re],s),15);
@@ -185,11 +190,11 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
 		mmtmp11 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_1)[re],s),15);
 		mmtmp12 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_2)[re],s),15);
 		
-		autocorr0[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp00,mmtmp10),_mm_unpackhi_epi32(mmtmp00,mmtmp10));
-		autocorr1[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp01,mmtmp11),_mm_unpackhi_epi32(mmtmp01,mmtmp11));
-		autocorr2[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp02,mmtmp12),_mm_unpackhi_epi32(mmtmp02,mmtmp12));
-		
+		autocorr0[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp00,mmtmp10),_mm_unpackhi_epi32(mmtmp00,mmtmp10));
+		autocorr1[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp01,mmtmp11),_mm_unpackhi_epi32(mmtmp01,mmtmp11));
+		autocorr2[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp02,mmtmp12),_mm_unpackhi_epi32(mmtmp02,mmtmp12));
 		
+		re256 = (re256+1)&0x3f;
 	      }
 	      // This is the +ve frequencies
 
@@ -217,11 +222,11 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
 		pss6144_2 = &pss6144_2_3[256];
 		break;
 	      } 
-	      for (re = 0; re<-f/4; re++) {  // loop over 256 points of upsampled PSS
+	      for (re = 0; re<(256+f)/4; re++) {  // loop over 256 points of upsampled PSS
 		s = sp2[re];
 		printf("re %d %p\n",re,&sp2[re]);
 		print_shorts("s",&s);
-		print_shorts("pss",&pss6144_0[re]);
+		print_shorts("pss",&((__m128i*)pss6144_0)[re]);
 		mmtmp00 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_0)[re],s),15);
 		mmtmp01 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_1)[re],s),15);
 		mmtmp02 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_2)[re],s),15);
@@ -233,15 +238,20 @@ void lte_sync_timefreq(PHY_VARS_UE *ue,int band,unsigned int DL_freq) {
 		mmtmp11 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_1)[re],s),15);
 		mmtmp12 = _mm_srai_epi32(_mm_madd_epi16(((__m128i*)pss6144_2)[re],s),15);
 		
-		autocorr0[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp00,mmtmp10),_mm_unpackhi_epi32(mmtmp00,mmtmp10));
-		autocorr1[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp01,mmtmp11),_mm_unpackhi_epi32(mmtmp01,mmtmp11));
-		autocorr2[re] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp02,mmtmp12),_mm_unpackhi_epi32(mmtmp02,mmtmp12));
-		
+		autocorr0[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp00,mmtmp10),_mm_unpackhi_epi32(mmtmp00,mmtmp10));
+		autocorr1[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp01,mmtmp11),_mm_unpackhi_epi32(mmtmp01,mmtmp11));
+		autocorr2[re256] = _mm_packs_epi32(_mm_unpacklo_epi32(mmtmp02,mmtmp12),_mm_unpackhi_epi32(mmtmp02,mmtmp12));
+
+		re256 = (re256+1)&0x3f;		
 	      }
 	      
 	    }
 	    // ifft, accumulate energy over two half-frames
 	    idft256((int16_t*)autocorr0,(int16_t*)tmp_t,1);
+	    if (i==12288) {
+	      write_output("corr256F.m","c256F",autocorr0,256,1,1);
+	      write_output("corr256.m","c256",tmp_t,256,1,1);
+	    }
 	    memset((void*)autocorr0_t,0,256*4);
 	    memset((void*)autocorr1_t,0,256*4);
 	    memset((void*)autocorr2_t,0,256*4);
diff --git a/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.m b/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.m
index 06962b3e99..a843d302ad 100644
--- a/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.m
+++ b/openair1/PHY/LTE_ESTIMATION/lte_sync_timefreq.m
@@ -21,7 +21,6 @@ pss2f = zeros(1,2048);
 pss2f(2:32) = d2(1:31);
 pss2f(2048+(-30:0)) = d2(32:62);
 
-
 pss0_6144f = fftshift(fft(ifft(pss0f)*sqrt(2048),6144)/sqrt(6144));
 pss1_6144f = fftshift(fft(ifft(pss1f)*sqrt(2048),6144)/sqrt(6144));
 pss2_6144f = fftshift(fft(ifft(pss2f)*sqrt(2048),6144)/sqrt(6144));
diff --git a/openair1/PHY/LTE_TRANSPORT/dci.c b/openair1/PHY/LTE_TRANSPORT/dci.c
index 54fb8c03af..28e1ff5a34 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci.c
@@ -2184,6 +2184,7 @@ uint8_t generate_dci_top_emul(PHY_VARS_eNB *phy_vars_eNB,
       }
       else {
 	ue_id = find_ue(dci_alloc[n_dci_dl].rnti,PHY_vars_eNB_g[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]);
+	DevAssert( ue_id != (uint8_t)-1 );
 	dlsch_eNB = PHY_vars_eNB_g[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id]->dlsch_eNB[ue_id][0];
 	
 	eNB_transport_info[phy_vars_eNB->Mod_id][phy_vars_eNB->CC_id].dlsch_type[n_dci_dl] = 2;//TB0;
diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index 2a5e2c0735..c136a802a3 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -529,6 +529,7 @@ uint8_t get_transmission_mode(module_id_t Mod_id, uint8_t CC_id, rnti_t rnti) {
 
   // find the UE_index corresponding to rnti
   UE_id = find_ue(rnti,PHY_vars_eNB_g[Mod_id][CC_id]);
+  DevAssert( UE_id != (unsigned char)-1 );
 
   return(PHY_vars_eNB_g[Mod_id][CC_id]->transmission_mode[UE_id]);
 }
diff --git a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
index 5ef35ee07b..224d8a91e3 100644
--- a/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
+++ b/openair1/PHY/LTE_TRANSPORT/dlsch_decoding.c
@@ -669,6 +669,7 @@ uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
     dlsch_ue  = phy_vars_ue->dlsch_ue[eNB_id][0];
     harq_pid = dlsch_ue->current_harq_pid;
     ue_id= (uint32_t)find_ue((int16_t)phy_vars_ue->lte_ue_pdcch_vars[(uint32_t)eNB_id]->crnti,PHY_vars_eNB_g[eNB_id2][CC_id]);
+    DevAssert( ue_id != (uint32_t)-1 );
     dlsch_eNB = PHY_vars_eNB_g[eNB_id2][CC_id]->dlsch_eNB[ue_id][0];
 
 #ifdef DEBUG_DLSCH_DECODING
@@ -705,11 +706,12 @@ uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
       }
 
     break;
-  case 3: // TB1
+  case 3: { // TB1
     dlsch_ue = phy_vars_ue->dlsch_ue[eNB_id][1];
     harq_pid = dlsch_ue->current_harq_pid;
-    dlsch_eNB = PHY_vars_eNB_g[eNB_id2][CC_id]->dlsch_eNB[(uint32_t)find_ue((int16_t)phy_vars_ue->lte_ue_pdcch_vars[(uint32_t)eNB_id]->crnti,
-								PHY_vars_eNB_g[eNB_id2][CC_id])][1];
+    int8_t UE_id = find_ue( phy_vars_ue->lte_ue_pdcch_vars[eNB_id]->crnti, PHY_vars_eNB_g[eNB_id2][CC_id] );
+    DevAssert( UE_id != -1 );
+    dlsch_eNB = PHY_vars_eNB_g[eNB_id2][CC_id]->dlsch_eNB[UE_id][1];
      // reset HARQ 
     dlsch_ue->harq_processes[harq_pid]->status = SCH_IDLE;
     dlsch_ue->harq_processes[harq_pid]->round  = 0;
@@ -719,6 +721,7 @@ uint32_t dlsch_decoding_emul(PHY_VARS_UE *phy_vars_ue,
     if (dlsch_ue->harq_processes[harq_pid]->round == 0)
       memcpy(dlsch_eNB->harq_processes[harq_pid]->b,dlsch_ue->harq_processes[harq_pid]->b,dlsch_ue->harq_processes[harq_pid]->TBS>>3);
     break;
+  }
   case 5: // PMCH
  
     dlsch_ue  = phy_vars_ue->dlsch_ue_MCH[eNB_id];
diff --git a/openair1/PHY/LTE_TRANSPORT/prach.c b/openair1/PHY/LTE_TRANSPORT/prach.c
index de250e6000..c1b06b4b7a 100644
--- a/openair1/PHY/LTE_TRANSPORT/prach.c
+++ b/openair1/PHY/LTE_TRANSPORT/prach.c
@@ -403,6 +403,7 @@ int32_t generate_prach(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe,
     if (Ncs_config>15) {
       LOG_E(PHY,"[PHY] FATAL, Illegal Ncs_config for unrestricted format %d\n",Ncs_config);
       mac_xface->macphy_exit("PRACH: Illegal Ncs_config for unrestricted format");
+      return 0; // not reached
     }
     NCS = NCS_unrestricted[Ncs_config];      
   }
@@ -410,6 +411,7 @@ int32_t generate_prach(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe,
     if (Ncs_config>14) {
       LOG_E(PHY,"[PHY] FATAL, Illegal Ncs_config for restricted format %d\n",Ncs_config);
       mac_xface->macphy_exit("PRACH: Illegal Ncs_config for restricted format");
+      return 0; // not reached
     }
     NCS = NCS_restricted[Ncs_config];
   }
@@ -468,7 +470,15 @@ int32_t generate_prach(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe,
     preamble_offset = 0; // relative rootSequenceIndex;
     while (not_found == 1) {
       // current root depending on rootSequenceIndex and preamble_offset
-      u = prach_root_sequence_map[(rootSequenceIndex + preamble_offset)%N_ZC];
+      int index = (rootSequenceIndex + preamble_offset) % N_ZC;
+      if (prach_fmt<4) {
+          // prach_root_sequence_map points to prach_root_sequence_map0_3
+          DevAssert( index < sizeof(prach_root_sequence_map0_3) );
+      } else {
+          // prach_root_sequence_map points to prach_root_sequence_map4
+          DevAssert( index < sizeof(prach_root_sequence_map4) );
+      }
+      u = prach_root_sequence_map[index];
       if ( (du[u]<(N_ZC/3)) && (du[u]>=NCS) ) {
 	n_shift_ra     = du[u]/NCS;
 	d_start        = (du[u]<<1) + (n_shift_ra * NCS);
@@ -718,6 +728,7 @@ int32_t generate_prach(PHY_VARS_UE *phy_vars_ue,uint8_t eNB_id,uint8_t subframe,
     //TODO: account for repeated format in fft output
     LOG_E(PHY,"prach_fmt4 not fully implemented");
     mac_xface->macphy_exit("prach_fmt4 not fully implemented");
+    return 0; // not reached
   }
   else {
 #ifdef BIT8_TX
@@ -807,6 +818,7 @@ void rx_prach(PHY_VARS_eNB *phy_vars_eNB,uint8_t subframe,uint16_t *preamble_ene
     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
     }
     NCS = NCS_unrestricted[Ncs_config];      
   }
@@ -814,6 +826,7 @@ void rx_prach(PHY_VARS_eNB *phy_vars_eNB,uint8_t subframe,uint16_t *preamble_ene
     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
     }
     NCS = NCS_restricted[Ncs_config];
   }
@@ -930,7 +943,15 @@ void rx_prach(PHY_VARS_eNB *phy_vars_eNB,uint8_t subframe,uint16_t *preamble_ene
 	(preamble_offset==0 && numshift==0) ? (preamble_offset) : (preamble_offset++);
 	while (not_found == 1) {
 	  // current root depending on rootSequenceIndex 
-	  u = prach_root_sequence_map[(rootSequenceIndex + preamble_offset)%N_ZC];
+	  int index = (rootSequenceIndex + preamble_offset) % N_ZC;
+	  if (prach_fmt<4) {
+	      // prach_root_sequence_map points to prach_root_sequence_map0_3
+	      DevAssert( index < sizeof(prach_root_sequence_map0_3) );
+	  } else {
+	      // prach_root_sequence_map points to prach_root_sequence_map4
+	      DevAssert( index < sizeof(prach_root_sequence_map4) );
+	  }
+	  u = prach_root_sequence_map[index];
 	  if ( (du[u]<(N_ZC/3)) && (du[u]>=NCS) ) {
 	    n_shift_ra     = du[u]/NCS;
 	    d_start        = (du[u]<<1) + (n_shift_ra * NCS);
@@ -1059,7 +1080,7 @@ void rx_prach(PHY_VARS_eNB *phy_vars_eNB,uint8_t subframe,uint16_t *preamble_ene
 	  break;
 	}
             
-	memset(prachF,0,4*1024);
+    memset( prachF, 0, sizeof(int16_t)*2*1024 );
 
 
 
@@ -1188,6 +1209,7 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
   if (prach_fmt>=4) {
     LOG_E(PHY, "PRACH sequence is only precomputed for prach_fmt<4 (have %d)\n");
     mac_xface->macphy_exit("PRACH sequence is only precomputed for prach_fmt<4");
+    return; // not reached
   }
 
   N_ZC = (prach_fmt < 4) ? 839 : 139;
@@ -1208,6 +1230,7 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
     if (prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig>15) {
       LOG_E(PHY,"FATAL, Illegal Ncs_config for unrestricted format %d\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];
@@ -1224,6 +1247,7 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
     if (prach_config_common->prach_ConfigInfo.zeroCorrelationZoneConfig>14) {
       LOG_E(PHY,"FATAL, Illegal Ncs_config for restricted format %d\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];
@@ -1235,7 +1259,15 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
     preamble_offset = 0;
     while (not_found == 1) {
       // current root depending on rootSequenceIndex 
-      u = prach_root_sequence_map[(prach_config_common->rootSequenceIndex + preamble_offset)%N_ZC];
+      int index = (prach_config_common->rootSequenceIndex + preamble_offset) % N_ZC;
+      if (prach_fmt<4) {
+          // prach_root_sequence_map points to prach_root_sequence_map0_3
+          DevAssert( index < sizeof(prach_root_sequence_map0_3) );
+      } else {
+          // prach_root_sequence_map points to prach_root_sequence_map4
+          DevAssert( index < sizeof(prach_root_sequence_map4) );
+      }
+      u = prach_root_sequence_map[index];
       if ( (du[u]<(N_ZC/3)) && (du[u]>=NCS) ) {
 	n_shift_ra     = du[u]/NCS;
 	d_start        = (du[u]<<1) + (n_shift_ra * NCS);
@@ -1251,11 +1283,15 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
       else {
 	n_shift_ra     = 0;
 	n_shift_ra_bar = 0;
+	n_group_ra     = 0;
       }
       // This is the number of cyclic shifts for the current root u
       numshift = (n_shift_ra*n_group_ra) + n_shift_ra_bar;
       // skip to next root and recompute parameters if numshift==0
-      (numshift>0) ? (not_found = 0) : (preamble_offset++);
+      if (numshift>0)
+        not_found = 0;
+      else
+        preamble_offset++;
     }
   }
 
@@ -1265,7 +1301,15 @@ void compute_prach_seq(PRACH_CONFIG_COMMON *prach_config_common,
 #endif
 
   for (i=0;i<num_preambles;i++) {
-    u = prach_root_sequence_map[(prach_config_common->rootSequenceIndex+i+preamble_offset)%N_ZC];
+    int index = (prach_config_common->rootSequenceIndex+i+preamble_offset) % N_ZC;
+    if (prach_fmt<4) {
+        // prach_root_sequence_map points to prach_root_sequence_map0_3
+        DevAssert( index < sizeof(prach_root_sequence_map0_3) );
+    } else {
+        // prach_root_sequence_map points to prach_root_sequence_map4
+        DevAssert( index < sizeof(prach_root_sequence_map4) );
+    }
+    u = prach_root_sequence_map[index];
         
     inv_u = ZC_inv[u]; // multiplicative inverse of u
     
diff --git a/openair1/SCHED/phy_procedures_lte_common.c b/openair1/SCHED/phy_procedures_lte_common.c
index 7c3832c34b..ae999b8115 100755
--- a/openair1/SCHED/phy_procedures_lte_common.c
+++ b/openair1/SCHED/phy_procedures_lte_common.c
@@ -772,7 +772,10 @@ LTE_DL_FRAME_PARMS* get_lte_frame_parms(module_id_t Mod_id, uint8_t  CC_id){
 
 }
 
-MU_MIMO_mode *get_mu_mimo_mode (module_id_t Mod_id, uint8_t  CC_id, rnti_t rnti){
-
-  return(&PHY_vars_eNB_g[Mod_id][CC_id]->mu_mimo_mode[find_ue(rnti,PHY_vars_eNB_g[Mod_id][CC_id])]);
+MU_MIMO_mode *get_mu_mimo_mode (module_id_t Mod_id, uint8_t  CC_id, rnti_t rnti)
+{
+  int8_t UE_id = find_ue( rnti, PHY_vars_eNB_g[Mod_id][CC_id] );
+  if (UE_id == -1)
+      return 0;
+  return &PHY_vars_eNB_g[Mod_id][CC_id]->mu_mimo_mode[UE_id];
 }
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index bd276efa2f..d91170da1b 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -1884,6 +1884,7 @@ void phy_procedures_eNB_TX(unsigned char sched_subframe,PHY_VARS_eNB *phy_vars_e
       if (harq_pid==255) {
         LOG_E(PHY,"[eNB %"PRIu8"] Frame %d: Bad harq_pid for ULSCH allocation\n",phy_vars_eNB->Mod_id,phy_vars_eNB->proc[sched_subframe].frame_tx);
 	mac_exit_wrapper("Invalid harq_pid (255) detected");
+	return; // not reached
       }
 #ifdef OPENAIR2
       UE_id = find_ue((int16_t)DCI_pdu->dci_alloc[i].rnti,phy_vars_eNB);
diff --git a/openair1/SIMULATION/ETH_TRANSPORT/multicast_link.c b/openair1/SIMULATION/ETH_TRANSPORT/multicast_link.c
index 9e9050d192..c86214104d 100755
--- a/openair1/SIMULATION/ETH_TRANSPORT/multicast_link.c
+++ b/openair1/SIMULATION/ETH_TRANSPORT/multicast_link.c
@@ -203,7 +203,7 @@ multicast_link_read_data (int groupP)
 {
     int num_bytes;
 
-    if ((groupP <= MULTICAST_LINK_NUM_GROUPS) && (groupP >= 0)) {
+    if ((groupP < MULTICAST_LINK_NUM_GROUPS) && (groupP >= 0)) {
         if ((num_bytes = recvfrom (group_list[groupP].socket,
                                    group_list[groupP].rx_buffer, 40000, 0, 0, 0)) < 0) {
             LOG_E(EMU, "[MULTICAST] recvfrom has failed (%d:%s)\n   (%s:%d)\n",
diff --git a/openair1/SIMULATION/LTE_PHY/scansim.c b/openair1/SIMULATION/LTE_PHY/scansim.c
index 4f08ee8362..9babaf8dcd 100644
--- a/openair1/SIMULATION/LTE_PHY/scansim.c
+++ b/openair1/SIMULATION/LTE_PHY/scansim.c
@@ -649,8 +649,8 @@ int main(int argc, char **argv) {
 	//printf("n_trial %d\n",n_trials);
 	for (i=0; i<2*nsymb*OFDM_SYMBOL_SIZE_COMPLEX_SAMPLES; i++) {
 	  for (aa=0;aa<PHY_vars_eNb->lte_frame_parms.nb_antennas_rx;aa++) {
-	    ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i] = (short) (.167*(r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
-	    ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i+1] = (short) (.167*(r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+	    ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i] = (short) ((r_re[aa][i] +sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
+	    ((short*) PHY_vars_UE->lte_ue_common_vars.rxdata[aa])[2*i+1] = (short) ((r_im[aa][i] + (iqim*r_re[aa][i]) + sqrt(sigma2/2)*gaussdouble(0.0,1.0)));
 	  }
 	}    
 
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 14e87633d0..b4414138fa 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -74,7 +74,7 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
 
     RA_TEMPLATE *RA_template;
     unsigned char i;//,harq_pid,round;
-    uint16_t rrc_sdu_length;
+    int16_t rrc_sdu_length;
     unsigned char lcid,offset;
     module_id_t UE_id= UE_INDEX_INVALID;
     unsigned short TBsize = -1;
@@ -111,9 +111,10 @@ void schedule_RA(module_id_t module_idP,frame_t frameP, sub_frame_t subframeP,un
                                                           1,
                                                           module_idP,
                                                           0); // not used in this case
-                        if (rrc_sdu_length == -1)
+                        if (rrc_sdu_length == -1) {
                             mac_xface->macphy_exit("[MAC][eNB Scheduler] CCCH not allocated\n");
-                        else {
+                            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);
                         }
                     }
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
index f1b4c293e0..cdc5f99212 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_dlsch.c
@@ -1878,6 +1878,7 @@ void fill_DLSCH_dci(module_id_t module_idP,frame_t frameP, sub_frame_t 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_mac_inst[module_idP].UE_list.UE_template[UE_PCCID(module_idP,UE_id)][UE_id].configured=TRUE;
 
 	  }
diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c
index db92f7539f..9d839628fc 100644
--- a/openair2/LAYER2/MAC/pre_processor.c
+++ b/openair2/LAYER2/MAC/pre_processor.c
@@ -174,6 +174,7 @@ void assign_rbs_required (module_id_t Mod_id,
     // provide the list of CCs sorted according to MCS
     for (i=0;i<UE_list->numactiveCCs[UE_id];i++) {
       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) {
 	  tmp = UE_list->ordered_CCids[i][UE_id];
@@ -236,6 +237,7 @@ int maxround(module_id_t Mod_id,uint16_t rnti,int frame,sub_frame_t subframe,uin
       round_max = round;
   }
 
+  return round_max;
 }
 
 // This function scans all CC_ids for a particular UE to find the maximum DL CQI
@@ -360,7 +362,7 @@ void dlsch_scheduler_pre_processor (module_id_t   Mod_id,
 
   uint8_t CC_id;
   UE_list_t *UE_list = &eNB_mac_inst[Mod_id].UE_list;
-  LTE_DL_FRAME_PARMS   *frame_parms[MAX_NUM_CCs];
+  LTE_DL_FRAME_PARMS   *frame_parms[MAX_NUM_CCs] = {0};
   int rrc_status           = RRC_IDLE;
   int transmission_mode = 0;
   
@@ -743,8 +745,8 @@ void ulsch_scheduler_pre_processor(module_id_t module_idP,
   rnti_t             rnti= -1;
   uint32_t            nCCE_to_be_used[MAX_NUM_CCs];
   UE_list_t          *UE_list = &eNB_mac_inst[module_idP].UE_list; 
-  UE_TEMPLATE        *UE_template;
-  LTE_DL_FRAME_PARMS   *frame_parms;
+  UE_TEMPLATE        *UE_template = 0;
+  LTE_DL_FRAME_PARMS   *frame_parms = 0;
 
   // LOG_I(MAC,"store ulsch buffers\n");
   // convert BSR to bytes for comparison with tbs
@@ -968,7 +970,7 @@ void assign_max_mcs_min_rb(module_id_t module_idP,int frameP, sub_frame_t subfra
 	while ((tbs < UE_template->ul_total_buffer) && 
 	       (rb_table[rb_table_index]<(frame_parms->N_RB_UL-first_rb[CC_id])) &&
 	       ((UE_template->phr_info - tx_power) > 0) && 
-	       (rb_table_index < 33 )){
+	       (rb_table_index < 32 )){
 	  //  LOG_I(MAC,"tbs %d ul buffer %d rb table %d max ul rb %d\n", tbs, UE_template->ul_total_buffer, rb_table[rb_table_index], frame_parms->N_RB_UL-first_rb[CC_id]);
 	  rb_table_index++;
 	  tbs = mac_xface->get_TBS_UL(mcs,rb_table[rb_table_index]);
diff --git a/openair2/LAYER2/MAC/ra_procedures.c b/openair2/LAYER2/MAC/ra_procedures.c
index e00a12f3cd..4e4699a927 100644
--- a/openair2/LAYER2/MAC/ra_procedures.c
+++ b/openair2/LAYER2/MAC/ra_procedures.c
@@ -62,7 +62,7 @@ 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;
+    return 0; // not reached
   }
 
   uint8_t prachConfigIndex = UE_mac_inst[module_idP].radioResourceConfigCommon->prach_Config.prach_ConfigInfo.prach_ConfigIndex;
@@ -263,7 +263,7 @@ PRACH_RESOURCES_t *ue_get_rach(module_id_t module_idP,int CC_id,frame_t frameP,
   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;
+    return 0; // not reached
   }
 
   if (UE_mode == PRACH) {
diff --git a/openair2/LAYER2/MAC/rar_tools.c b/openair2/LAYER2/MAC/rar_tools.c
index 8b5c5f49d6..3414c8633e 100644
--- a/openair2/LAYER2/MAC/rar_tools.c
+++ b/openair2/LAYER2/MAC/rar_tools.c
@@ -78,6 +78,8 @@ unsigned short fill_rar(module_id_t module_idP,
       }
   }
 
+  DevAssert( ra_idx != -1 );
+
   // subheader fixed 
   rarh->E                     = 0; // First and last RAR
   rarh->T                     = 1; // 0 for E/T/R/R/BI subheader, 1 for E/T/RAPID subheader
diff --git a/openair2/LAYER2/MAC/ue_procedures.c b/openair2/LAYER2/MAC/ue_procedures.c
index bb3870596a..07a5db675d 100644
--- a/openair2/LAYER2/MAC/ue_procedures.c
+++ b/openair2/LAYER2/MAC/ue_procedures.c
@@ -234,6 +234,7 @@ uint32_t ue_get_SR(module_id_t module_idP,int CC_id,frame_t frameP,uint8_t eNB_i
           LOG_W(MAC, "Measurement GAP offset is unknown\n");
       }
       T=MGRP/10;
+      DevAssert( T != 0 );
       //check the measurement gap and sr prohibit timer
       if ((subframe ==  gapOffset %10) && ((frameP %T) == (floor(gapOffset/10)))
           && (UE_mac_inst[module_idP].scheduling_info.sr_ProhibitTimer_Running ==0)){
@@ -1911,7 +1912,7 @@ 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;
+    return 0; // not reached
   }
   //power headroom reporting range is from -23 ...+40 dB, as described in 36313
   //note: mac_xface->get_Po_NOMINAL_PUSCH(module_idP) is float
diff --git a/openair2/UTIL/MEM/mem_block.c b/openair2/UTIL/MEM/mem_block.c
index 0890731238..cf9af86caf 100644
--- a/openair2/UTIL/MEM/mem_block.c
+++ b/openair2/UTIL/MEM/mem_block.c
@@ -390,94 +390,116 @@ check_free_mem_block (mem_block_t * leP)
 {
 //-----------------------------------------------------------------------------
   ptrdiff_t             block_index;
-  if ((leP >= &mem_block_var.mem_blocks[0]) && (leP <= &mem_block_var.mem_blocks[MEM_MNGT_NB_ELEMENTS])) {
-    block_index = (leP - (&mem_block_var.mem_blocks[0])) / sizeof (mem_block_t);
+  if ((leP >= mem_block_var.mem_blocks) && (leP <= &mem_block_var.mem_blocks[MEM_MNGT_NB_ELEMENTS-1])) {
+    // the pointer is inside the memory region
+    block_index = leP - mem_block_var.mem_blocks;
+    // block_index is now: 0 <= block_index < MEM_MNGT_NB_ELEMENTS
+
     if (block_index < MEM_MNGT_MB0_NB_BLOCKS) {
-      if ((leP->data != (&(mem_block_var.mem_pool0[block_index][0]))) && (leP->pool_id != MEM_MNGT_POOL_ID0)) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool0[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID0)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index < (MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS)) {
-      if ((leP->data != &(mem_block_var.mem_pool1[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID1)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB0_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB1_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool1[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID1)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index < MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool2[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID2)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB1_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB2_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool2[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID2)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool3[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID3)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB2_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB3_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool3[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID3)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool4[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID4)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB3_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB4_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool4[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID4)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool5[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID5)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB4_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB5_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool5[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID5)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS
-             + MEM_MNGT_MB6_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool6[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID6)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB5_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB6_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool6[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID6)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS
-             + MEM_MNGT_MB6_NB_BLOCKS + MEM_MNGT_MB7_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool7[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID7)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB6_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB7_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool7[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID7)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS
-             + MEM_MNGT_MB6_NB_BLOCKS + MEM_MNGT_MB7_NB_BLOCKS + MEM_MNGT_MB8_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool8[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID8)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB7_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB8_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool8[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID8)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS
-             + MEM_MNGT_MB6_NB_BLOCKS + MEM_MNGT_MB7_NB_BLOCKS + MEM_MNGT_MB8_NB_BLOCKS
-             + MEM_MNGT_MB9_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool9[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID9)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB8_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB9_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool9[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID9)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS
-             + MEM_MNGT_MB6_NB_BLOCKS + MEM_MNGT_MB7_NB_BLOCKS + MEM_MNGT_MB8_NB_BLOCKS
-             + MEM_MNGT_MB9_NB_BLOCKS + MEM_MNGT_MB10_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool10[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID10)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB9_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB10_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool10[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID10)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS
-             + MEM_MNGT_MB6_NB_BLOCKS + MEM_MNGT_MB7_NB_BLOCKS + MEM_MNGT_MB8_NB_BLOCKS
-             + MEM_MNGT_MB9_NB_BLOCKS + MEM_MNGT_MB10_NB_BLOCKS+ MEM_MNGT_MB11_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool11[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID11)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB10_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB11_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool11[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID11)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
-    } else if (block_index <
-               MEM_MNGT_MB0_NB_BLOCKS + MEM_MNGT_MB1_NB_BLOCKS + MEM_MNGT_MB2_NB_BLOCKS
-             + MEM_MNGT_MB3_NB_BLOCKS + MEM_MNGT_MB4_NB_BLOCKS + MEM_MNGT_MB5_NB_BLOCKS
-             + MEM_MNGT_MB6_NB_BLOCKS + MEM_MNGT_MB7_NB_BLOCKS + MEM_MNGT_MB8_NB_BLOCKS
-             + MEM_MNGT_MB9_NB_BLOCKS + MEM_MNGT_MB10_NB_BLOCKS+ MEM_MNGT_MB11_NB_BLOCKS
-             + MEM_MNGT_MB12_NB_BLOCKS) {
-      if ((leP->data != &(mem_block_var.mem_pool12[block_index][0])) && (leP->pool_id != MEM_MNGT_POOL_ID12)) {
+      return;
+    }
+    block_index -= MEM_MNGT_MB11_NB_BLOCKS;
+
+    if (block_index < MEM_MNGT_MB12_NB_BLOCKS) {
+      if ((leP->data != (unsigned char*)mem_block_var.mem_pool12[block_index]) && (leP->pool_id != MEM_MNGT_POOL_ID12)) {
         msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
       }
+      return;
     }
   } else {
     msg ("[MEM][ERROR][FATAL] free mem block is corrupted\n");
   }
+
+  // the block is ok
 }
diff --git a/openair2/UTIL/OMG/sumo.c b/openair2/UTIL/OMG/sumo.c
index 270fbf5c5c..aeb0f6ed71 100644
--- a/openair2/UTIL/OMG/sumo.c
+++ b/openair2/UTIL/OMG/sumo.c
@@ -171,8 +171,8 @@ start_sumo_generator (omg_global_param omg_param_list)
       node->generator = SUMO;	// SUMO
       node->mob = mobility;
 
-      DevAssert( SUMO >= sizeof(node_vector_end) ); // FIXME node_vector_end is declared with MAX_NUM_NODE_TYPES elements, but here we are indexing with SUMO from enum mobility_types
-      DevAssert( SUMO >= sizeof(node_vector) ); // FIXME node_vector is declared with MAX_NUM_NODE_TYPES elements, but here we are indexing with SUMO from enum mobility_types
+      DevAssert( SUMO >= MAX_NUM_NODE_TYPES ); // FIXME node_vector_end is declared with MAX_NUM_NODE_TYPES elements, but here we are indexing with SUMO from enum mobility_types
+      DevAssert( SUMO >= MAX_NUM_NODE_TYPES ); // FIXME node_vector is declared with MAX_NUM_NODE_TYPES elements, but here we are indexing with SUMO from enum mobility_types
 
       node_vector_end[SUMO] =
 	(node_list *) add_entry (node, node_vector_end[SUMO]);
@@ -297,6 +297,7 @@ desactivate_and_unmap (char *sumo_id)
   if (OAI_ID != -1)
     {
       //TODO generalize to UE and eNB (must change the method)
+      DevAssert( SUMO >= MAX_NUM_NODE_TYPES ); // FIXME node_vector is declared with MAX_NUM_NODE_TYPES elements, but here we are indexing with SUMO from enum mobility_types
       node_struct *node = find_node (node_vector[SUMO], OAI_ID, UE);
       if (node == NULL)
 	node = find_node (node_vector[SUMO], OAI_ID, eNB);
@@ -333,7 +334,8 @@ activate_and_map (char *sumo_id)
 #else
   LOG_I (OMG, "activating node %s \n", sumo_id);
 #endif
-  // TODO: So far, only UE can be SUMO mobile, but could change 
+  // TODO: So far, only UE can be SUMO mobile, but could change
+  AssertFatal( false, "node_vector array has only MAX_NUM_NODE_TYPES (=3) elements, but indexing here with SUMO (=4)");
   node_struct *active_node = get_first_inactive_OAI_node (node_vector[SUMO], UE);
   if (active_node != NULL)
     {				// found an inactive OAI node; will be mapped to SUMO
@@ -438,6 +440,7 @@ get_sumo_positions_updated (double cur_time)
 	 "--------GET SUMO Mobility for a group of ACTIVE OAI nodes--------\n");
 #endif
 
+  DevAssert( SUMO >= MAX_NUM_NODE_TYPES ); // FIXME node_vector is declared with MAX_NUM_NODE_TYPES elements, but here we are indexing with SUMO from enum mobility_types
   if (node_vector[SUMO] != NULL)
     {
       node_list *tmp = node_vector[SUMO];
diff --git a/openair2/UTIL/OTG/otg_models.c b/openair2/UTIL/OTG/otg_models.c
index cce1328ec9..379cc04f94 100644
--- a/openair2/UTIL/OTG/otg_models.c
+++ b/openair2/UTIL/OTG/otg_models.c
@@ -262,7 +262,7 @@ double tarmaCalculateVideoSample(tarmaVideo_t *video){
 	frameidx=video->tarmaVideoGopStructure[video->tarmaVideoFrameNumber];
   LOG_D(OTG,"TARMA_DEBUG: tarmaCalculateVideoSample(%p) called\n", video);
   LOG_D(OTG,"TARMA_DEBUG:     frameidx=%d\n",frameidx);
-	if(frameidx>=0 && frameidx<=TARMA_NUM_FRAME_TYPES){
+        if(frameidx>=0 && frameidx<TARMA_NUM_FRAME_TYPES){
 	  for(cntpy=0; cntpy<TARMA_NUM_POLY_MAX; cntpy++){
 		proc->polyWeight[cntpy]=video->polyWeightFrame[frameidx][cntpy];
 	  }
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index ac357853ab..1e99f791a8 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -209,7 +209,10 @@ static void *UE_thread_synch(void *arg) {
   int current_offset = 0;
   sync_mode_t sync_mode = pss;
   int card;
-
+  int ind;
+  int CC_id;
+  int k;
+  int found;
 
   UE->is_synchronized = 0;
   printf("UE_thread_sync in with PHY_vars_UE %p\n",arg);
@@ -224,8 +227,28 @@ static void *UE_thread_synch(void *arg) {
   printf("unlocked sync_mutex (UE_sync_thread)\n");
 
   printf("starting UE synch thread\n");
+  ind = 0;
+  found = 0;
+  current_band = eutra_bands[ind].band; 
+  do  {
+    if ((eutra_bands[ind].dl_min <= downlink_frequency[0][0]) && (eutra_bands[ind].dl_max>= downlink_frequency[0][0])) {
+      for (card=0;card<MAX_NUM_CCs;card++)
+	for (i=0; i<4; i++) 
+	  uplink_frequency_offset[card][i] = eutra_bands[ind].ul_min - eutra_bands[ind].dl_min;
+      found = 1;
+      break;
+    }
+    ind++;
+    current_band = eutra_bands[++ind].band; 
+  } while (current_band < 44);
+    
+  if (found == 0) {
+    exit_fun("Can't find EUTRA band for frequency");
+    oai_exit=1;
+  }
 
-  if (UE->UE_scan == 1) {
+
+  if  (UE->UE_scan == 1) {
     for (card=0;card<MAX_CARDS;card++) {
       for (i=0; i<openair0_cfg[card].rx_num_channels; i++) {
 	downlink_frequency[card][i] = bands_to_scan.band_info[0].dl_min;
@@ -239,9 +262,11 @@ static void *UE_thread_synch(void *arg) {
 	openair0_set_rx_frequencies(&openair0,&openair0_cfg[0]);
 	openair0_set_gains(&openair0,&openair0_cfg[0]);
 #endif
+#else
+	openair0_config(&openair0_cfg[0],1);
 #endif
       }
-    }    
+      }    
     LOG_D(PHY,"[SCHED][UE] Scanning band %d, freq %u\n",bands_to_scan.band_info[0].band, bands_to_scan.band_info[0].dl_min);
   }
   else {
@@ -361,6 +386,9 @@ static void *UE_thread_synch(void *arg) {
 	      openair0_set_frequencies(&openair0,&openair0_cfg[0]);
 	      //	    openair0_set_gains(&openair0,&openair0_cfg[0]);
 #endif
+
+#else
+	      openair0_config(&openair0_cfg[card],1);
 #endif
 	    }
 	  }
diff --git a/targets/RT/USER/rrh.c b/targets/RT/USER/rrh.c
index fb28588c7d..c72da9748f 100644
--- a/targets/RT/USER/rrh.c
+++ b/targets/RT/USER/rrh.c
@@ -55,7 +55,7 @@
 #define BUF_LEN 4096+32
 #define RRH_eNB_PORT 50000
 #define RRH_eNB_DEST_IP "127.0.0.1"  
-#define RRH_UE_PORT 22222
+#define RRH_UE_PORT 51000
 #define RRH_UE_DEST_IP "127.0.0.1"  
 
 #define FRAME_MAX_SIZE 307200 
@@ -180,10 +180,10 @@ return (0);
 void *rrh_proc_eNB_thread() {
 
   //rrh_desc_t *rrh_desc = (rrh_desc_t *)arg;
-  int antenna_index;
+  int antenna_index,i;
   openair0_timestamp truncated_timestamp, truncated_timestamp_final, last_hw_counter=0;
   struct timespec time_req, time_rem;  
-
+  int16_t *rxp,*txp;
 
   time_req.tv_sec = 0;
   time_req.tv_nsec = 1000;
@@ -233,8 +233,19 @@ void *rrh_proc_eNB_thread() {
                 nanosleep(&time_req,&time_rem);
             }
           }
-          memcpy(&rx_buffer_UE[antenna_index][truncated_timestamp + (sizeof(openair0_timestamp)>>2)],&tx_buffer_eNB[antenna_index][truncated_timestamp],(FRAME_MAX_SIZE<<2)-(truncated_timestamp<<2));
-          memcpy(&rx_buffer_UE[antenna_index][(sizeof(openair0_timestamp)>>2)],&tx_buffer_eNB[antenna_index][0],(nsamps_eNB[antenna_index]<<2)-(FRAME_MAX_SIZE<<2)+(truncated_timestamp<<2));
+	  rxp = (int16_t*)&rx_buffer_UE[antenna_index][truncated_timestamp+(sizeof(openair0_timestamp)>>2)];
+	  txp = (int16_t*)&tx_buffer_eNB[antenna_index][truncated_timestamp+(sizeof(openair0_timestamp)>>2)];
+	  for (i=0;i<(FRAME_MAX_SIZE<<1)-(truncated_timestamp<<1);i++) {
+	    rxp[i] = txp[i]>>6;
+	  }
+	  rxp = (int16_t*)&rx_buffer_UE[antenna_index][(sizeof(openair0_timestamp)>>2)];
+	  txp = (int16_t*)&tx_buffer_eNB[antenna_index][0];
+	  for (i=0;i<nsamps_eNB[antenna_index]-(FRAME_MAX_SIZE)+(truncated_timestamp);i++) {
+	    rxp[i] = txp[i]>>6;
+	  }
+
+	  /*          memcpy(&rx_buffer_UE[antenna_index][truncated_timestamp + (sizeof(openair0_timestamp)>>2)],&tx_buffer_eNB[antenna_index][truncated_timestamp],(FRAME_MAX_SIZE<<2)-(truncated_timestamp<<2));
+		      memcpy(&rx_buffer_UE[antenna_index][(sizeof(openair0_timestamp)>>2)],&tx_buffer_eNB[antenna_index][0],(nsamps_eNB[antenna_index]<<2)-(FRAME_MAX_SIZE<<2)+(truncated_timestamp<<2));*/
         }
         else
         {
@@ -248,7 +259,13 @@ void *rrh_proc_eNB_thread() {
                  nanosleep(&time_req,&time_rem);
             }
           }
-          memcpy(&rx_buffer_UE[antenna_index][truncated_timestamp + (sizeof(openair0_timestamp)>>2)],&tx_buffer_eNB[antenna_index][truncated_timestamp],(nsamps_eNB[antenna_index]<<2));
+	  rxp = (int16_t*)&rx_buffer_UE[antenna_index][truncated_timestamp+(sizeof(openair0_timestamp))];
+	  txp = (int16_t*)&tx_buffer_eNB[antenna_index][truncated_timestamp];
+	  for (i=0;i<(nsamps_eNB[antenna_index]);i++) {
+	    rxp[i] =txp[i]>>6; 
+	  }
+	  /*
+	    memcpy(&rx_buffer_UE[antenna_index][truncated_timestamp + (sizeof(openair0_timestamp)>>2)],&tx_buffer_eNB[antenna_index][truncated_timestamp],(nsamps_eNB[antenna_index]<<2));*/
         }
      
       
@@ -268,10 +285,10 @@ void *rrh_proc_eNB_thread() {
 void *rrh_proc_UE_thread() {
 
   //rrh_desc_t *rrh_desc = (rrh_desc_t *)arg;
-  int antenna_index;
+  int antenna_index,i;
   openair0_timestamp truncated_timestamp, truncated_timestamp_final, last_hw_counter=0;
   struct timespec time_req, time_rem;
-
+  int16_t *txp,*rxp;
 
   time_req.tv_sec = 0;
   time_req.tv_nsec = 1000;
@@ -322,8 +339,20 @@ void *rrh_proc_UE_thread() {
                 nanosleep(&time_req,&time_rem);
             }
           }
+	  rxp = (int16_t*)&rx_buffer_eNB[antenna_index][truncated_timestamp+(sizeof(openair0_timestamp)>>2)];
+	  txp = (int16_t*)&tx_buffer_UE[antenna_index][truncated_timestamp+(sizeof(openair0_timestamp)>>2)];
+	  for (i=0;i<(FRAME_MAX_SIZE<<1)-(truncated_timestamp<<1);i++) {
+	    rxp[i] = txp[i]>>6;
+	  }
+	  rxp = (int16_t*)&rx_buffer_eNB[antenna_index][(sizeof(openair0_timestamp)>>2)];
+	  txp = (int16_t*)&tx_buffer_UE[antenna_index][0];
+	  for (i=0;i<nsamps_eNB[antenna_index]-(FRAME_MAX_SIZE)+(truncated_timestamp);i++) {
+	    rxp[i] = txp[i]>>6;
+	  }
+	  /*
           memcpy(&rx_buffer_eNB[antenna_index][truncated_timestamp + (sizeof(openair0_timestamp)>>2)],&tx_buffer_UE[antenna_index][truncated_timestamp],(FRAME_MAX_SIZE<<2)-(truncated_timestamp<<2));
-          memcpy(&rx_buffer_eNB[antenna_index][(sizeof(openair0_timestamp)>>2)],&tx_buffer_UE[antenna_index][0],(nsamps_UE[antenna_index]<<2)-(FRAME_MAX_SIZE<<2)+(truncated_timestamp<<2));
+          memcpy(&rx_buffer_eNB[antenna_index][(sizeof(openair0_timestamp)>>2)],&tx_buffer_UE[antenna_index][0],(nsamps_UE[antenna_index]<<2)-(FRAME_MAX_SIZE<<2)+(truncated_timestamp<<2));*/
+
         }
         else
         {
@@ -337,7 +366,12 @@ void *rrh_proc_UE_thread() {
                  nanosleep(&time_req,&time_rem);
             }
           }
-          memcpy(&rx_buffer_eNB[antenna_index][truncated_timestamp+ (sizeof(openair0_timestamp)>>2)],&tx_buffer_UE[antenna_index][truncated_timestamp],(nsamps_UE[antenna_index]<<2));
+	  rxp = (int16_t*)&rx_buffer_eNB[antenna_index][truncated_timestamp+(sizeof(openair0_timestamp))];
+	  txp = (int16_t*)&tx_buffer_UE[antenna_index][truncated_timestamp];
+	  for (i=0;i<(nsamps_eNB[antenna_index]);i++) {
+	    rxp[i] =txp[i]>>6; 
+	  }
+	  /*          memcpy(&rx_buffer_eNB[antenna_index][truncated_timestamp+ (sizeof(openair0_timestamp)>>2)],&tx_buffer_UE[antenna_index][truncated_timestamp],(nsamps_UE[antenna_index]<<2));*/
         }
       
  //end_copy_UE :
diff --git a/targets/SIMU/USER/event_handler.c b/targets/SIMU/USER/event_handler.c
index 335252afb4..d318dcd195 100644
--- a/targets/SIMU/USER/event_handler.c
+++ b/targets/SIMU/USER/event_handler.c
@@ -340,7 +340,7 @@ void execute_events(frame_t frame){
 void update_mac(Event_t event) {
 	LOG_I(EMU,"A NEW MAC MODEL\n");
 	int i = 0;
-	UE_list_t *UE_list;
+	UE_list_t *UE_list = 0;
 	int enb_module_id=0;
 	int cc_id =0;	
 	eNB_MAC_INST *eNB_mac_inst = get_eNB_mac_inst(enb_module_id);
-- 
GitLab