From e686da4e48c641472facf0377bec7bfe56bce039 Mon Sep 17 00:00:00 2001
From: Sakthivel Velumani <velumani@eurecom.fr>
Date: Tue, 8 Sep 2020 16:08:30 +0200
Subject: [PATCH] fixed tbslbrm

---
 openair1/PHY/CODING/coding_defs.h                  |  3 +--
 openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c        |  2 +-
 openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c      |  2 +-
 openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c   | 10 +++++-----
 openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c     |  2 +-
 openair2/LAYER2/NR_MAC_gNB/nr_compute_tbs_common.c |  7 ++++---
 6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/openair1/PHY/CODING/coding_defs.h b/openair1/PHY/CODING/coding_defs.h
index 7f466c7097..00f0a8c0c9 100644
--- a/openair1/PHY/CODING/coding_defs.h
+++ b/openair1/PHY/CODING/coding_defs.h
@@ -480,8 +480,7 @@ uint32_t nr_compute_tbs(uint16_t Qm,
 
 uint32_t nr_compute_tbslbrm(uint16_t table,
 			    uint16_t nb_rb,
-		            uint8_t Nl,
-                            uint8_t C);
+		            uint8_t Nl);
 
 void nr_interleaving_ldpc(uint32_t E, uint8_t Qm, uint8_t *e,uint8_t *f);
 
diff --git a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
index e5841d3262..a4a684c4e4 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_dlsch_coding.c
@@ -527,7 +527,7 @@ int nr_dlsch_encoding(PHY_VARS_gNB *gNB,
     if (rel15->nrOfLayers < Nl)
       Nl = rel15->nrOfLayers;
 
-    Tbslbrm = nr_compute_tbslbrm(rel15->mcsTable[0],nb_rb,Nl,dlsch->harq_processes[harq_pid]->C);
+    Tbslbrm = nr_compute_tbslbrm(rel15->mcsTable[0],nb_rb,Nl);
 
     start_meas(dlsch_rate_matching_stats);
     nr_rate_matching_ldpc(Ilbrm,
diff --git a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
index ceb8c4f719..6f9849a89f 100644
--- a/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
+++ b/openair1/PHY/NR_TRANSPORT/nr_ulsch_decoding.c
@@ -599,7 +599,7 @@ uint32_t nr_ulsch_decoding(PHY_VARS_gNB *phy_vars_gNB,
       printf("K %d C %d Z %d \n", harq_process->K, harq_process->C, harq_process->Z);
 #endif
   }
-  Tbslbrm = nr_compute_tbslbrm(0,nb_rb,n_layers,harq_process->C);
+  Tbslbrm = nr_compute_tbslbrm(0,nb_rb,n_layers);
 
   p_decParams->Z = harq_process->Z;
 
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
index 36bcb2f379..7378f69c27 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_dlsch_decoding.c
@@ -478,9 +478,9 @@ uint32_t nr_dlsch_decoding(PHY_VARS_NR_UE *phy_vars_ue,
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_DLSCH_RATE_MATCHING, VCD_FUNCTION_IN);
 
     if ((harq_process->Nl)<4)
-      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,harq_process->Nl,harq_process->C);
+      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,harq_process->Nl);
     else
-      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,4,harq_process->C);
+      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,4);
 
 
     if (nr_rate_matching_ldpc_rx(Ilbrm,
@@ -1069,7 +1069,7 @@ uint32_t  nr_dlsch_decoding_mthread(PHY_VARS_NR_UE *phy_vars_ue,
     if (harq_process->Nl < Nl)
       Nl = harq_process->Nl;
 
-    Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,harq_process->Nl,harq_process->C);
+    Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,harq_process->Nl);
 
     if (nr_rate_matching_ldpc_rx(Ilbrm,
                                  Tbslbrm,
@@ -1610,9 +1610,9 @@ void nr_dlsch_decoding_process(void *arg)
 #endif
 
     if (Nl<4)
-      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,Nl,harq_process->C);
+      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,Nl);
     else
-      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,4,harq_process->C);
+      Tbslbrm = nr_compute_tbslbrm(harq_process->mcs_table,nb_rb,4);
 
     if (nr_rate_matching_ldpc_rx(Ilbrm,
                                  Tbslbrm,
diff --git a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
index 6f5fba7812..ac4877d00f 100644
--- a/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
+++ b/openair1/PHY/NR_UE_TRANSPORT/nr_ulsch_coding.c
@@ -438,7 +438,7 @@ int nr_ulsch_encoding(NR_UE_ULSCH_t *ulsch,
 
     E = nr_get_E(G, harq_process->C, mod_order, harq_process->pusch_pdu.nrOfLayers, r);
 
-    Tbslbrm = nr_compute_tbslbrm(0,nb_rb,harq_process->pusch_pdu.nrOfLayers,harq_process->C);
+    Tbslbrm = nr_compute_tbslbrm(0,nb_rb,harq_process->pusch_pdu.nrOfLayers);
 
     VCD_SIGNAL_DUMPER_DUMP_FUNCTION_BY_NAME(VCD_SIGNAL_DUMPER_FUNCTIONS_NR_RATE_MATCHING_LDPC, VCD_FUNCTION_IN);
     nr_rate_matching_ldpc(Ilbrm,
diff --git a/openair2/LAYER2/NR_MAC_gNB/nr_compute_tbs_common.c b/openair2/LAYER2/NR_MAC_gNB/nr_compute_tbs_common.c
index df23b64e07..336fa1d68d 100644
--- a/openair2/LAYER2/NR_MAC_gNB/nr_compute_tbs_common.c
+++ b/openair2/LAYER2/NR_MAC_gNB/nr_compute_tbs_common.c
@@ -95,8 +95,7 @@ uint32_t nr_compute_tbs(uint16_t Qm,
 //tbslbrm calculation according to 5.4.2.1 of 38.212
 uint32_t nr_compute_tbslbrm(uint16_t table,
 			    uint16_t nb_rb,
-		            uint8_t Nl,
-                            uint8_t C)
+		            uint8_t Nl)
 {
 
   uint16_t R, nb_re;
@@ -104,7 +103,7 @@ uint32_t nr_compute_tbslbrm(uint16_t table,
   uint8_t Qm;
   int i;
   uint32_t nr_tbs=0;
-  uint32_t Ninfo, Np_info;
+  uint32_t Ninfo, Np_info, C;
   uint8_t n;
 
   for (i=0; i<7; i++) {
@@ -136,10 +135,12 @@ uint32_t nr_compute_tbslbrm(uint16_t table,
         Np_info = max(3840, (ROUNDIDIV((Ninfo-24),(1<<n)))<<n);
 
         if (R <= 256) { 
+            C = CEILIDIV((Np_info+24),3816);
             nr_tbs = (C<<3)*CEILIDIV((Np_info+24),(C<<3)) - 24;
         }
         else {
             if (Np_info > 8424){
+                C = CEILIDIV((Np_info+24),8424);
                 nr_tbs = (C<<3)*CEILIDIV((Np_info+24),(C<<3)) - 24;
             }
             else {
-- 
2.26.2