From 519ab68b211c3920a612d15d19d79ff25f55bd4a Mon Sep 17 00:00:00 2001
From: "masayuki.harada" <masayuki.harada@jp.fujitsu.com>
Date: Thu, 10 Dec 2020 20:27:55 +0900
Subject: [PATCH] Fix some merge miss.

---
 openair1/PHY/LTE_TRANSPORT/dci_tools.c    |  2 ++
 openair1/PHY/LTE_TRANSPORT/phich.c        | 11 ++++++---
 openair1/PHY/LTE_TRANSPORT/phich_common.c | 28 +++++++++++++++++++++++
 openair1/PHY/LTE_TRANSPORT/pucch.c        |  6 ++---
 4 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/openair1/PHY/LTE_TRANSPORT/dci_tools.c b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
index 8de011acef..4b06f67bbe 100644
--- a/openair1/PHY/LTE_TRANSPORT/dci_tools.c
+++ b/openair1/PHY/LTE_TRANSPORT/dci_tools.c
@@ -2071,6 +2071,8 @@ void fill_ulsch(PHY_VARS_eNB *eNB,int UE_id,nfapi_ul_config_ulsch_pdu *ulsch_pdu
     ulsch->harq_processes[harq_pid]->round++;
     ulsch->harq_processes[harq_pid]->TBS           = ulsch_pdu->ulsch_pdu_rel8.size<<3;
     ulsch->harq_processes[harq_pid]->Msc_initial   = 12*ulsch_pdu->ulsch_pdu_rel8.number_of_resource_blocks;
+    ulsch->harq_processes[harq_pid]->Or1           = 0;
+    ulsch->harq_processes[harq_pid]->Or2           = 0;
   }
 
   ulsch->rnti = ulsch_pdu->ulsch_pdu_rel8.rnti;
diff --git a/openair1/PHY/LTE_TRANSPORT/phich.c b/openair1/PHY/LTE_TRANSPORT/phich.c
index 6d8b58818b..1725588f4c 100644
--- a/openair1/PHY/LTE_TRANSPORT/phich.c
+++ b/openair1/PHY/LTE_TRANSPORT/phich.c
@@ -716,6 +716,7 @@ void generate_phich_top(PHY_VARS_eNB *eNB,
   uint8_t NSF_PHICH = 4;
   uint8_t pusch_subframe=-1;
   uint8_t i;
+  uint8_t harq_pid = 0; 
   int subframe = proc->subframe_tx;
   phich_config_t *phich;
 
@@ -748,16 +749,20 @@ void generate_phich_top(PHY_VARS_eNB *eNB,
     
     nseq_PHICH = ((phich->first_rb/Ngroup_PHICH) +
 		  phich->n_DMRS)%(2*NSF_PHICH);
+    harq_pid = subframe2harq_pid(frame_parms,phich_frame2_pusch_frame(frame_parms,proc->frame_tx,subframe),pusch_subframe);
+	if (harq_pid == 255) {
+      LOG_E(PHY,"FATAL ERROR: illegal harq_pid, returning\n");
+	  return;
+	}
     LOG_D(PHY,"[eNB %d][PUSCH %d] Frame %d subframe %d Generating PHICH, AMP %d  ngroup_PHICH %d/%d, nseq_PHICH %d : HI %d, first_rb %d)\n",
-	  eNB->Mod_id,subframe2harq_pid(frame_parms,
-          phich_frame2_pusch_frame(frame_parms,proc->frame_tx,subframe),pusch_subframe),proc->frame_tx,
+	  eNB->Mod_id,harq_pid,proc->frame_tx,
 	  subframe,amp,ngroup_PHICH,Ngroup_PHICH,nseq_PHICH,
 	  phich->hi,
 	  phich->first_rb);
     
     T(T_ENB_PHY_PHICH, T_INT(eNB->Mod_id), T_INT(proc->frame_tx), T_INT(subframe),
       T_INT(-1 /* TODO: rnti */), 
-      T_INT(subframe2harq_pid(frame_parms,phich_frame2_pusch_frame(frame_parms,proc->frame_tx,subframe),pusch_subframe)),
+      T_INT(harq_pid),
       T_INT(Ngroup_PHICH), T_INT(NSF_PHICH),
       T_INT(ngroup_PHICH), T_INT(nseq_PHICH),
       T_INT(phich->hi),
diff --git a/openair1/PHY/LTE_TRANSPORT/phich_common.c b/openair1/PHY/LTE_TRANSPORT/phich_common.c
index 89c826be66..302229b88d 100644
--- a/openair1/PHY/LTE_TRANSPORT/phich_common.c
+++ b/openair1/PHY/LTE_TRANSPORT/phich_common.c
@@ -102,6 +102,34 @@ unsigned char subframe2_ul_harq(LTE_DL_FRAME_PARMS *frame_parms,unsigned char su
     return(subframe&7);
 
   switch (frame_parms->tdd_config) {
+  case 1:
+    if (subframe == 6) {
+      return(0);
+    } else if (subframe==9){
+      return(1);
+    } else if (subframe==1){
+      return(2);
+    } else if (subframe==4){
+      return(3);
+    } else {
+      LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n",
+            subframe,frame_parms->tdd_config);
+      return(0);
+    }
+
+    break;
+  case 2:
+    if (subframe == 3) {
+      return(1);
+    } else if (subframe==8){
+      return(0);
+    } else {
+      LOG_E(PHY,"phich.c: subframe2_ul_harq, illegal subframe %d for tdd_config %d\n",
+            subframe,frame_parms->tdd_config);
+      return(0);
+    }
+
+    break;
     case 3:
       if ( (subframe == 8) || (subframe == 9) ) {
         return(subframe-8);
diff --git a/openair1/PHY/LTE_TRANSPORT/pucch.c b/openair1/PHY/LTE_TRANSPORT/pucch.c
index fa4d883d64..c72fa1b480 100644
--- a/openair1/PHY/LTE_TRANSPORT/pucch.c
+++ b/openair1/PHY/LTE_TRANSPORT/pucch.c
@@ -741,7 +741,7 @@ uint32_t calc_pucch_1x_interference(PHY_VARS_eNB *eNB,
   uint8_t m,l;
   uint8_t n_cs,alpha_ind;
   int16_t tmp_re,tmp_im,W_re=0,W_im=0;
-  int16_t W4_nouse[4]={1,1,-1,-1};
+  int16_t W4_nouse[4]={32767,32767,-32768,-32768};
   int32_t n0_IQ[2];
   double interference_power;
   int16_t *rxptr;
@@ -846,7 +846,7 @@ uint32_t calc_pucch_1x_interference(PHY_VARS_eNB *eNB,
     }  // antenna
   }
   interference_power /= calc_cnt;
-  eNB->measurements.n0_pucch_dB = dB_fixed_x10((int)(interference_power/calc_cnt))/10;
+  eNB->measurements.n0_pucch_dB = dB_fixed_x10((int)interference_power)/10;
   LOG_D(PHY,"estimate pucch noise %lf %d %d\n",interference_power,calc_cnt,eNB->measurements.n0_pucch_dB);
   return 0;
 }
@@ -1188,7 +1188,7 @@ uint32_t rx_pucch(PHY_VARS_eNB *eNB,
 #endif
             }
 
-            stat += (stat_re*stat_re);
+            stat += ((stat_re*stat_re) + (stat_im*stat_im));
           } //re
         } // aa
 
-- 
2.26.2