From af3bbe425eed0543b0c4ed8a4fedc6f2106aa636 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <knopp@eurecom.fr>
Date: Thu, 4 Aug 2016 01:14:33 +0200
Subject: [PATCH] modifications for RRC IF4p5

---
 openair1/PHY/LTE_TRANSPORT/if4_tools.c        |  2 +-
 openair1/PHY/LTE_TRANSPORT/prach.c            | 26 ++++++++++++++++---
 openair1/SCHED/phy_procedures_lte_eNb.c       |  3 ++-
 targets/ARCH/ETHERNET/USERSPACE/LIB/eth_raw.c | 12 +++++----
 .../ETHERNET/USERSPACE/LIB/ethernet_lib.c     |  8 ++++--
 targets/RT/USER/lte-enb.c                     | 14 +++++-----
 6 files changed, 45 insertions(+), 20 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/if4_tools.c b/openair1/PHY/LTE_TRANSPORT/if4_tools.c
index 8f01fc5369..fb3e11780f 100644
--- a/openair1/PHY/LTE_TRANSPORT/if4_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/if4_tools.c
@@ -233,7 +233,7 @@ void recv_IF4p5(PHY_VARS_eNB *eNB, int *frame, int *subframe, uint16_t *packet_t
 		
   } else if (*packet_type == IF4p5_PRACH) {    
     // FIX: hard coded prach samples length
-    db_fulllength = 839*2;
+    db_fulllength = 840*2;
 		
     memcpy((&rxsigF[0][0]), 
            (int16_t*) (rx_buffer+MAC_HEADER_SIZE_BYTES+sizeof_IF4p5_header_t), 
diff --git a/openair1/PHY/LTE_TRANSPORT/prach.c b/openair1/PHY/LTE_TRANSPORT/prach.c
index 0adb8685f0..4d29ba55e7 100644
--- a/openair1/PHY/LTE_TRANSPORT/prach.c
+++ b/openair1/PHY/LTE_TRANSPORT/prach.c
@@ -1101,6 +1101,8 @@ void rx_prach(PHY_VARS_eNB *eNB,
   int fft_size,log2_ifft_size;
   uint8_t nb_ant_rx = 1; //eNB->frame_parms.nb_antennas_rx;
 
+  //  int en;
+
   for (aa=0; aa<nb_ant_rx; aa++) {
     prach[aa] = (int16_t*)&eNB->common_vars.rxdata[0][aa][subframe*eNB->frame_parms.samples_per_tti-eNB->N_TA_offset];
   }
@@ -1299,7 +1301,12 @@ void rx_prach(PHY_VARS_eNB *eNB,
     // Adjust received rxsigF offset    
     memmove((&rxsigF[0][k]),
             (&rxsigF[0][0]),
-            839*2*sizeof(int16_t));     
+            839*2*sizeof(int16_t));
+
+    //en = dB_fixed(signal_energy(&rxsigF[0][k],840));
+    //    if (en>60)
+    //printf("PRACH: Frame %d, Subframe %d => %d dB\n",eNB->proc.frame_rx,eNB->proc.subframe_rx,en);
+
   }
   
   // in case of RCC and prach received rx_thread wakes up prach
@@ -1470,9 +1477,22 @@ void rx_prach(PHY_VARS_eNB *eNB,
       // if (aa=1) write_output("prach_rxF_comp1.m","prach_rxF_comp1",prachF,1024,1,1);
       }// antennas_rx
 #ifdef PRACH_DEBUG
-      write_output("prach_ifft0.m","prach_t0",prach_ifft[0],2048,1,1);
+      
+      if (en>40) {
+	k = (12*n_ra_prb) - 6*eNB->frame_parms.N_RB_UL;
+	
+	if (k<0)
+	  k+=(eNB->frame_parms.ofdm_symbol_size);
+	
+	k*=12;
+	k+=13;
+	k*=2;
+	printf("Dumping prach, k = %d (n_ra_prb %d)\n",k,n_ra_prb);
+	write_output("rxsigF.m","prach_rxF",&rxsigF[0][k],840,1,1);
+	write_output("prach_rxF_comp0.m","prach_rxF_comp0",prachF,1024,1,1);
+	write_output("prach_ifft0.m","prach_t0",prach_ifft[0],1024,1,1);
+      }
 #endif
-      // write_output("prach_ifft1.m","prach_t1",prach_ifft[1],2048,1,1);
       
     } // new dft
     
diff --git a/openair1/SCHED/phy_procedures_lte_eNb.c b/openair1/SCHED/phy_procedures_lte_eNb.c
index 6bf9273776..8385d97f41 100755
--- a/openair1/SCHED/phy_procedures_lte_eNb.c
+++ b/openair1/SCHED/phy_procedures_lte_eNb.c
@@ -1949,13 +1949,14 @@ 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,
 				    0,subframe,0);
+	
       }      
 
     } else {
diff --git a/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_raw.c b/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_raw.c
index 02ca6ee7eb..0b73324080 100644
--- a/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_raw.c
+++ b/targets/ARCH/ETHERNET/USERSPACE/LIB/eth_raw.c
@@ -274,7 +274,7 @@ int trx_eth_read_raw(openair0_device *device, openair0_timestamp *timestamp, voi
 	
 	if (bytes_received ==-1) {
 	  eth->num_rx_errors++;
-	  perror("ETHERNET READ: ");
+	  perror("ETHERNET IF5 READ: ");
 	  exit(-1);	
 	} else {
 	  /* store the timestamp value from packet's header */
@@ -314,14 +314,15 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
   
   ssize_t packet_size = MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t;      
   IF4p5_header_t *test_header = (IF4p5_header_t*)(buff[0] + MAC_HEADER_SIZE_BYTES);
-  
+
+
   bytes_received = recv(eth->sockfd[Mod_id],
                         buff[0],
                         packet_size,
                         MSG_PEEK);                        
 	if (bytes_received ==-1) {
 	  eth->num_rx_errors++;
-	  perror("ETHERNET READ: ");
+	  perror("ETHERNET IF4p5 READ (header): ");
 	  exit(-1);	
   }
  
@@ -334,7 +335,8 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
   } else {
     packet_size = RAW_IF4p5_PRACH_SIZE_BYTES;
   }
-        
+  
+  
   while(bytes_received < packet_size) {
     bytes_received = recv(eth->sockfd[Mod_id],
                           buff[0],
@@ -342,7 +344,7 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
                           0);
 	  if (bytes_received ==-1) {
 	    eth->num_rx_errors++;
-	    perror("ETHERNET READ: ");
+	    perror("ETHERNET IF4p5 READ (payload): ");
 	    exit(-1);	
     } else {
       eth->rx_actual_nsamps = bytes_received>>1;   
diff --git a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
index d530558816..38a6d5a571 100644
--- a/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
+++ b/targets/ARCH/ETHERNET/USERSPACE/LIB/ethernet_lib.c
@@ -63,6 +63,7 @@ int trx_eth_start(openair0_device *device) {
   
   /* initialize socket */
   if (eth->flags == ETH_RAW_MODE) {     
+    printf("Setting ETHERNET to ETH_RAW_IF5_MODE\n");
     if (eth_socket_init_raw(device)!=0)   return -1;
     /* RRH gets openair0 device configuration - BBU sets openair0 device configuration*/
     if (device->host_type == BBU_HOST) {
@@ -74,6 +75,8 @@ int trx_eth_start(openair0_device *device) {
     if(ethernet_tune (device,MTU_SIZE,RAW_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0)  return -1;
     if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
   } else if (eth->flags == ETH_RAW_IF4p5_MODE) {
+
+    printf("Setting ETHERNET to ETH_RAW_IF4p5_MODE\n");
     if (eth_socket_init_raw(device)!=0)   return -1;
     /* RRH gets openair0 device configuration - BBU sets openair0 device configuration*/
     if (device->host_type == BBU_HOST) {
@@ -83,12 +86,13 @@ int trx_eth_start(openair0_device *device) {
     }
     /* adjust MTU wrt number of samples per packet */
     if(ethernet_tune (device,MTU_SIZE,RAW_IF4p5_PRACH_SIZE_BYTES)!=0)  return -1;
-        if(ethernet_tune (device,RCV_TIMEOUT,5000)!=0)  return -1;
+    if(ethernet_tune (device,RCV_TIMEOUT,999999)!=0)  return -1;
 
   } else if (eth->flags == ETH_UDP_IF4p5_MODE) {
-    
+    printf("Setting ETHERNET to UDP_IF4p5_MODE\n");
   
   } else if (eth->flags == ETH_RAW_IF5_MOBIPASS) {
+    printf("Setting ETHERNET to RAW_IF5_MODE\n");
     if (eth_socket_init_raw(device)!=0)   return -1;
     /* RRH gets openair0 device configuration - BBU sets openair0 device configuration*/
     //if (device->host_type == BBU_HOST) {
diff --git a/targets/RT/USER/lte-enb.c b/targets/RT/USER/lte-enb.c
index b0d1eb3d0e..231b1bceb0 100644
--- a/targets/RT/USER/lte-enb.c
+++ b/targets/RT/USER/lte-enb.c
@@ -975,7 +975,7 @@ void rx_fh_if5(PHY_VARS_eNB *eNB,eNB_proc_t *proc,int *frame, int *subframe) {
 
 }
 
-void rx_fh_if4p5(PHY_VARS_eNB *eNB,eNB_proc_t *proc,int *subframe,int *frame) {
+void rx_fh_if4p5(PHY_VARS_eNB *eNB,eNB_proc_t *proc,int *frame,int *subframe) {
 
   LTE_DL_FRAME_PARMS *fp = &eNB->frame_parms;
 
@@ -988,27 +988,25 @@ void rx_fh_if4p5(PHY_VARS_eNB *eNB,eNB_proc_t *proc,int *subframe,int *frame) {
   symbol_mask = 0;
   symbol_mask_full = (1<<fp->symbols_per_tti)-1;
   prach_rx = 0;
-  
+
   do {   // Blocking, we need a timeout on this !!!!!!!!!!!!!!!!!!!!!!!
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF4, 1 );   
     recv_IF4p5(eNB, &proc->frame_rx, &proc->subframe_rx, &packet_type, &symbol_number);
-    VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME( VCD_SIGNAL_DUMPER_FUNCTIONS_RECV_IF4, 0 );   
-    
     if (packet_type == IF4p5_PULFFT) {
       symbol_mask = symbol_mask | (1<<symbol_number);
       prach_rx = (is_prach_subframe(fp, proc->frame_rx, proc->subframe_rx)>0) ? 1 : 0;                            
     } else if (packet_type == IF4p5_PRACH) {
       prach_rx = 0;
     }
+
   } while( (symbol_mask != symbol_mask_full) || (prach_rx == 1));    
   
   if (proc->first_rx == 0) {
     if (proc->subframe_rx != *subframe){
-      LOG_E(PHY,"Received Timestamp doesn't correspond to the time we think it is (proc->subframe_rx %d, subframe %d)\n",proc->subframe_rx,subframe);
+      LOG_E(PHY,"Received Timestamp doesn't correspond to the time we think it is (proc->subframe_rx %d, subframe %d)\n",proc->subframe_rx,*subframe);
       exit_fun("Exiting");
     }
     if (proc->frame_rx != *frame) {
-      LOG_E(PHY,"Received Timestamp doesn't correspond to the time we think it is (proc->frame_rx %d frame %d)\n",proc->frame_rx,frame);
+      LOG_E(PHY,"Received Timestamp doesn't correspond to the time we think it is (proc->frame_rx %d frame %d)\n",proc->frame_rx,*frame);
       exit_fun("Exiting");
     }
   } else {
@@ -1271,7 +1269,7 @@ static void* eNB_thread_FH( void* param ) {
 
   // This is a forever while loop, it loops over subframes which are scheduled by incoming samples from HW devices
   while (!oai_exit) {
-   
+
     if (oai_exit) break;   
 
     if (subframe==9) { 
-- 
2.26.2