From 8013d5d8ccb8f5e4a9bb9a6b89258a9d0e917500 Mon Sep 17 00:00:00 2001
From: francescomani <email@francescomani.it>
Date: Fri, 20 Oct 2023 11:36:35 +0200
Subject: [PATCH] removing CellGroup dependance from MAC common functions

---
 openair2/LAYER2/NR_MAC_COMMON/nr_mac.h        |  3 ++
 openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c | 26 +++++------
 openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h |  6 +--
 openair2/LAYER2/NR_MAC_UE/config_ue.c         | 10 ++++-
 openair2/LAYER2/NR_MAC_UE/mac_defs.h          |  5 +--
 .../NR_MAC_UE/nr_ue_dci_configuration.c       | 26 +++++++++--
 openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c  | 11 ++---
 openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c   |  3 +-
 openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c |  6 +--
 .../LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c   |  4 +-
 .../NR_MAC_gNB/gNB_scheduler_primitives.c     | 45 ++++++++++++++++---
 .../LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c   |  4 +-
 12 files changed, 99 insertions(+), 50 deletions(-)

diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h
index affac3fbd4..d33390d75a 100644
--- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h
+++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac.h
@@ -573,6 +573,7 @@ typedef struct NR_UE_DL_BWP {
   long *pdsch_HARQ_ACK_Codebook;
   uint8_t mcsTableIdx;
   nr_dci_format_t dci_format;
+  int bw_tbslbrm;
 } NR_UE_DL_BWP_t;
 
 typedef struct NR_UE_UL_BWP {
@@ -591,6 +592,7 @@ typedef struct NR_UE_UL_BWP {
   NR_PUSCH_Config_t *pusch_Config;
   NR_PUCCH_Config_t *pucch_Config;
   NR_PUCCH_ConfigCommon_t *pucch_ConfigCommon;
+  NR_UplinkConfig_t *supplementaryUplink;
   long *harq_ACK_SpatialBundlingPUCCH;
   NR_CSI_MeasConfig_t *csi_MeasConfig;
   NR_SRS_Config_t *srs_Config;
@@ -598,6 +600,7 @@ typedef struct NR_UE_UL_BWP {
   long transform_precoding;
   uint8_t mcs_table;
   nr_dci_format_t dci_format;
+  int bw_tbslbrm;
   int max_fb_time;
 } NR_UE_UL_BWP_t;
 
diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c
index 14bce7f816..5498a2c9ae 100644
--- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c
+++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.c
@@ -3278,7 +3278,7 @@ uint16_t get_rb_bwp_dci(nr_dci_format_t format,
 
 uint16_t nr_dci_size(const NR_UE_DL_BWP_t *DL_BWP,
                      const NR_UE_UL_BWP_t *UL_BWP,
-                     const NR_CellGroupConfig_t *cg,
+                     NR_CrossCarrierSchedulingConfig_t *crossCarrierSchedulingConfig,
                      dci_pdu_rel15_t *dci_pdu,
                      nr_dci_format_t format,
                      nr_rnti_type_t rnti_type,
@@ -3328,12 +3328,12 @@ uint16_t nr_dci_size(const NR_UE_DL_BWP_t *DL_BWP,
       /// fixed: Format identifier 1, MCS 5, NDI 1, RV 2, HARQ PID 4, PUSCH TPC 2, ULSCH indicator 1 --16
       size += 16;
       // Carrier indicator
-      if (cg->spCellConfig->spCellConfigDedicated->crossCarrierSchedulingConfig != NULL) {
+      if (crossCarrierSchedulingConfig != NULL) {
         dci_pdu->carrier_indicator.nbits=3;
         size += dci_pdu->carrier_indicator.nbits;
       }
       // UL/SUL indicator
-      if (cg->spCellConfig->spCellConfigDedicated->supplementaryUplink != NULL) {
+      if (UL_BWP->supplementaryUplink != NULL) {
         dci_pdu->carrier_indicator.nbits=1;
         size += dci_pdu->ul_sul_indicator.nbits;
       }
@@ -3416,7 +3416,7 @@ uint16_t nr_dci_size(const NR_UE_DL_BWP_t *DL_BWP,
       size += dci_pdu->antenna_ports.nbits;
       LOG_D(NR_MAC,"dci_pdu->antenna_ports.nbits = %d\n",dci_pdu->antenna_ports.nbits);
       // SRS request
-      if (cg->spCellConfig->spCellConfigDedicated->supplementaryUplink==NULL)
+      if (UL_BWP->supplementaryUplink == NULL)
         dci_pdu->srs_request.nbits = 2;
       else
         dci_pdu->srs_request.nbits = 3;
@@ -3481,7 +3481,7 @@ uint16_t nr_dci_size(const NR_UE_DL_BWP_t *DL_BWP,
       // Format identifier
       size = 1;
       // Carrier indicator
-      if (cg->spCellConfig->spCellConfigDedicated->crossCarrierSchedulingConfig != NULL) {
+      if (crossCarrierSchedulingConfig != NULL) {
         dci_pdu->carrier_indicator.nbits=3;
         size += dci_pdu->carrier_indicator.nbits;
       }
@@ -3575,7 +3575,7 @@ uint16_t nr_dci_size(const NR_UE_DL_BWP_t *DL_BWP,
         size += dci_pdu->transmission_configuration_indication.nbits;
       }
       // SRS request
-      if (cg->spCellConfig->spCellConfigDedicated->supplementaryUplink==NULL)
+      if (UL_BWP->supplementaryUplink == NULL)
         dci_pdu->srs_request.nbits = 2;
       else
         dci_pdu->srs_request.nbits = 3;
@@ -4734,11 +4734,10 @@ uint16_t compute_pucch_prb_size(uint8_t format,
 }
 
 int get_dlbw_tbslbrm(int scc_bwpsize,
-                     NR_CellGroupConfig_t *cg) {
-
+                     NR_ServingCellConfig_t *servingCellConfig)
+{
   int bw = scc_bwpsize;
-  if (cg && cg->spCellConfig && cg->spCellConfig->spCellConfigDedicated) {
-    const NR_ServingCellConfig_t *servingCellConfig = cg->spCellConfig->spCellConfigDedicated;
+  if (servingCellConfig) {
     if(servingCellConfig->downlinkBWP_ToAddModList) {
       const struct NR_ServingCellConfig__downlinkBWP_ToAddModList *BWP_list = servingCellConfig->downlinkBWP_ToAddModList;
       for (int i=0; i<BWP_list->list.count; i++) {
@@ -4753,11 +4752,10 @@ int get_dlbw_tbslbrm(int scc_bwpsize,
 }
 
 int get_ulbw_tbslbrm(int scc_bwpsize,
-                     NR_CellGroupConfig_t *cg) {
-
+                     NR_ServingCellConfig_t *servingCellConfig)
+{
   int bw = scc_bwpsize;
-  if (cg && cg->spCellConfig && cg->spCellConfig->spCellConfigDedicated) {
-    const NR_ServingCellConfig_t *servingCellConfig = cg->spCellConfig->spCellConfigDedicated;
+  if (servingCellConfig) {
     if (servingCellConfig->uplinkConfig &&
         servingCellConfig->uplinkConfig->uplinkBWP_ToAddModList) {
       const struct NR_UplinkConfig__uplinkBWP_ToAddModList *BWP_list = servingCellConfig->uplinkConfig->uplinkBWP_ToAddModList;
diff --git a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h
index d21e441978..059dc31acd 100644
--- a/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h
+++ b/openair2/LAYER2/NR_MAC_COMMON/nr_mac_common.h
@@ -95,7 +95,7 @@ NR_tda_info_t get_dl_tda_info(const NR_UE_DL_BWP_t *dl_BWP, int ss_type, int tda
 
 uint16_t nr_dci_size(const NR_UE_DL_BWP_t *DL_BWP,
                      const NR_UE_UL_BWP_t *UL_BWP,
-                     const NR_CellGroupConfig_t *cg,
+                     NR_CrossCarrierSchedulingConfig_t *crossCarrierSchedulingConfig,
                      dci_pdu_rel15_t *dci_pdu,
                      nr_dci_format_t format,
                      nr_rnti_type_t rnti_type,
@@ -196,10 +196,10 @@ uint32_t nr_get_code_rate_ul(uint8_t Imcs, uint8_t table_idx);
 uint16_t get_nr_srs_offset(NR_SRS_PeriodicityAndOffset_t periodicityAndOffset);
 
 int get_dlbw_tbslbrm(int scc_bwpsize,
-                     NR_CellGroupConfig_t *cg);
+                     NR_ServingCellConfig_t *servingCellConfig);
 
 int get_ulbw_tbslbrm(int scc_bwpsize,
-                     NR_CellGroupConfig_t *cg);
+                     NR_ServingCellConfig_t *servingCellConfig);
 
 uint32_t nr_compute_tbslbrm(uint16_t table,
 			    uint16_t nb_rb,
diff --git a/openair2/LAYER2/NR_MAC_UE/config_ue.c b/openair2/LAYER2/NR_MAC_UE/config_ue.c
index b1624126bb..e6c494aa27 100644
--- a/openair2/LAYER2/NR_MAC_UE/config_ue.c
+++ b/openair2/LAYER2/NR_MAC_UE/config_ue.c
@@ -570,6 +570,8 @@ void configure_current_BWP(NR_UE_MAC_INST_t *mac,
       configure_ss_coreset(mac, mac->bwp_dlcommon->pdcch_ConfigCommon->choice.setup, NULL);
   }
 
+  NR_ServingCellConfig_t *spCellConfigDedicated = NULL;
+
   if(cell_group_config) {
     if (cell_group_config->physicalCellGroupConfig) {
       DL_BWP->pdsch_HARQ_ACK_Codebook = &cell_group_config->physicalCellGroupConfig->pdsch_HARQ_ACK_Codebook;
@@ -577,7 +579,8 @@ void configure_current_BWP(NR_UE_MAC_INST_t *mac,
     }
     if (cell_group_config->spCellConfig &&
         cell_group_config->spCellConfig->spCellConfigDedicated) {
-      struct NR_ServingCellConfig *spCellConfigDedicated = cell_group_config->spCellConfig->spCellConfigDedicated;
+      spCellConfigDedicated = cell_group_config->spCellConfig->spCellConfigDedicated;
+      UL_BWP->supplementaryUplink = spCellConfigDedicated->supplementaryUplink;
       UL_BWP->csi_MeasConfig = spCellConfigDedicated->csi_MeasConfig ? spCellConfigDedicated->csi_MeasConfig->choice.setup : NULL;
       UL_BWP->pusch_servingcellconfig =
           spCellConfigDedicated->uplinkConfig && spCellConfigDedicated->uplinkConfig->pusch_ServingCellConfig ? spCellConfigDedicated->uplinkConfig->pusch_ServingCellConfig->choice.setup : NULL;
@@ -673,6 +676,8 @@ void configure_current_BWP(NR_UE_MAC_INST_t *mac,
   DL_BWP->initial_BWPStart = NRRIV2PRBOFFSET(mac->bwp_dlcommon->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
   UL_BWP->initial_BWPStart = NRRIV2PRBOFFSET(mac->bwp_ulcommon->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
 
+  DL_BWP->bw_tbslbrm = get_dlbw_tbslbrm(DL_BWP->initial_BWPSize, spCellConfigDedicated);
+  UL_BWP->bw_tbslbrm = get_ulbw_tbslbrm(UL_BWP->initial_BWPSize, spCellConfigDedicated);
 }
 
 void ue_init_config_request(NR_UE_MAC_INST_t *mac, int scs)
@@ -762,7 +767,7 @@ void nr_rrc_mac_config_req_mcg(module_id_t module_id,
     mac->servCellIndex = cell_group_config->spCellConfig->servCellIndex ? *cell_group_config->spCellConfig->servCellIndex : 0;
   else
     mac->servCellIndex = 0;
-
+  mac->crossCarrierSchedulingConfig = cell_group_config->spCellConfig->spCellConfigDedicated->crossCarrierSchedulingConfig;
   mac->scheduling_info.periodicBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
   mac->scheduling_info.retxBSR_SF = MAC_UE_BSR_TIMER_NOT_RUNNING;
   mac->BSR_reporting_active = NR_BSR_TRIGGER_NONE;
@@ -803,6 +808,7 @@ void nr_rrc_mac_config_req_scg(module_id_t module_id,
 
   mac->cg = scell_group_config;
   mac->servCellIndex = *scell_group_config->spCellConfig->servCellIndex;
+  mac->crossCarrierSchedulingConfig = scell_group_config->spCellConfig->spCellConfigDedicated->crossCarrierSchedulingConfig;
   if (scell_group_config->spCellConfig->reconfigurationWithSync)
     handle_reconfiguration_with_sync(mac, module_id, cc_idP, scell_group_config->spCellConfig->reconfigurationWithSync);
   configure_current_BWP(mac, NULL, scell_group_config);
diff --git a/openair2/LAYER2/NR_MAC_UE/mac_defs.h b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
index 068890f620..cb91486b97 100644
--- a/openair2/LAYER2/NR_MAC_UE/mac_defs.h
+++ b/openair2/LAYER2/NR_MAC_UE/mac_defs.h
@@ -429,7 +429,6 @@ typedef struct {
   NR_UE_L2_STATE_t state;
   NR_CellGroupConfig_t            *cg;
   int                             servCellIndex;
-  NR_CSI_ReportConfig_t           *csirc;
   long                            physCellId;
   ////  MAC config
   int                             first_sync_frame;
@@ -437,9 +436,6 @@ typedef struct {
   bool                            get_otherSI;
   NR_DRX_Config_t                 *drx_Config;
   NR_SchedulingRequestConfig_t    *schedulingRequestConfig;
-  NR_BSR_Config_t                 *bsr_Config;
-  NR_TAG_Config_t                 *tag_Config;
-  NR_PHR_Config_t                 *phr_Config;
   NR_RNTI_Value_t                 *cs_RNTI;
   NR_MIB_t                        *mib;
   struct NR_SI_SchedulingInfo *si_SchedulingInfo;
@@ -462,6 +458,7 @@ typedef struct {
   NR_SearchSpace_t *search_space_zero;
 
   NR_TDD_UL_DL_ConfigCommon_t *tdd_UL_DL_ConfigurationCommon;
+  NR_CrossCarrierSchedulingConfig_t *crossCarrierSchedulingConfig;
 
   bool phy_config_request_sent;
   frame_type_t frame_type;
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
index d89dc44ef3..4c281239ec 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_dci_configuration.c
@@ -186,15 +186,35 @@ void config_dci_pdu(NR_UE_MAC_INST_t *mac,
       dci_pdu_rel15_t temp_pdu;
       if(dci_format == NR_DL_DCI_FORMAT_1_0)
         alt_size =
-            nr_dci_size(current_DL_BWP, current_UL_BWP, mac->cg, &temp_pdu, NR_UL_DCI_FORMAT_0_0, rnti_type, coreset, dl_bwp_id, ss->searchSpaceType->present, mac->type0_PDCCH_CSS_config.num_rbs, 0);
+            nr_dci_size(current_DL_BWP,
+                        current_UL_BWP,
+                        mac->crossCarrierSchedulingConfig,
+                        &temp_pdu,
+                        NR_UL_DCI_FORMAT_0_0,
+                        rnti_type,
+                        coreset,
+                        dl_bwp_id,
+                        ss->searchSpaceType->present,
+                        mac->type0_PDCCH_CSS_config.num_rbs,
+                        0);
       if(dci_format == NR_UL_DCI_FORMAT_0_0)
         alt_size =
-            nr_dci_size(current_DL_BWP, current_UL_BWP, mac->cg, &temp_pdu, NR_DL_DCI_FORMAT_1_0, rnti_type, coreset, dl_bwp_id, ss->searchSpaceType->present, mac->type0_PDCCH_CSS_config.num_rbs, 0);
+            nr_dci_size(current_DL_BWP,
+                        current_UL_BWP,
+                        mac->crossCarrierSchedulingConfig,
+                        &temp_pdu,
+                        NR_DL_DCI_FORMAT_1_0,
+                        rnti_type,
+                        coreset,
+                        dl_bwp_id,
+                        ss->searchSpaceType->present,
+                        mac->type0_PDCCH_CSS_config.num_rbs,
+                        0);
     }
 
     rel15->dci_length_options[i] = nr_dci_size(current_DL_BWP,
                                                current_UL_BWP,
-                                               mac->cg,
+                                               mac->crossCarrierSchedulingConfig,
                                                &mac->def_dci_pdu_rel15[dl_config->slot][dci_format],
                                                dci_format,
                                                rnti_type,
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
index f5902bed27..9251b9b38a 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_procedures.c
@@ -735,11 +735,9 @@ static int nr_ue_process_dci_dl_10(module_id_t module_id,
     dlsch_pdu->TBS = current_harq->TBS;
   }
 
-  int bw_tbslbrm;
-  if (current_DL_BWP->initial_BWPSize > 0)
-    bw_tbslbrm = get_dlbw_tbslbrm(current_DL_BWP->initial_BWPSize, mac->cg);
-  else
-    bw_tbslbrm = dlsch_pdu->BWPSize;
+  int bw_tbslbrm = current_DL_BWP->initial_BWPSize > 0 ?
+                   current_DL_BWP->bw_tbslbrm :
+                   dlsch_pdu->BWPSize;
   dlsch_pdu->tbslbrm = nr_compute_tbslbrm(dlsch_pdu->mcs_table, bw_tbslbrm, 1);
 
   /* NDI (only if CRC scrambled by C-RNTI or CS-RNTI or new-RNTI or TC-RNTI)*/
@@ -1164,8 +1162,7 @@ static int nr_ue_process_dci_dl_11(module_id_t module_id,
   long *maxMIMO_Layers = current_DL_BWP->pdsch_servingcellconfig->ext1->maxMIMO_Layers;
   AssertFatal(maxMIMO_Layers != NULL, "Option with max MIMO layers not configured is not supported\n");
   int nl_tbslbrm = *maxMIMO_Layers < 4 ? *maxMIMO_Layers : 4;
-  int bw_tbslbrm = get_dlbw_tbslbrm(current_DL_BWP->initial_BWPSize, mac->cg);
-  dlsch_pdu->tbslbrm = nr_compute_tbslbrm(dlsch_pdu->mcs_table, bw_tbslbrm, nl_tbslbrm);
+  dlsch_pdu->tbslbrm = nr_compute_tbslbrm(dlsch_pdu->mcs_table, current_DL_BWP->bw_tbslbrm, nl_tbslbrm);
   /*PTRS configuration */
   dlsch_pdu->pduBitmap = 0;
   if (pdsch_Config->dmrs_DownlinkForPDSCH_MappingTypeA->choice.setup->phaseTrackingRS != NULL) {
diff --git a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
index e5ecba5efc..2cf83fc4dc 100644
--- a/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
+++ b/openair2/LAYER2/NR_MAC_UE/nr_ue_scheduler.c
@@ -667,9 +667,8 @@ int nr_config_pusch_pdu(NR_UE_MAC_INST_t *mac,
       if (!maxMIMO_Layers)
         maxMIMO_Layers = pusch_Config ? pusch_Config->maxRank : NULL;
       AssertFatal (maxMIMO_Layers != NULL,"Option with max MIMO layers not configured is not supported\n");
-      int bw_tbslbrm = get_ulbw_tbslbrm(current_UL_BWP->initial_BWPSize, mac->cg);
       pusch_config_pdu->tbslbrm = nr_compute_tbslbrm(pusch_config_pdu->mcs_table,
-                                                     bw_tbslbrm,
+                                                     current_UL_BWP->bw_tbslbrm,
                                                      *maxMIMO_Layers);
     } else
       pusch_config_pdu->tbslbrm = 0;
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
index d7a36ec131..ec4ade5563 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_RA.c
@@ -1312,9 +1312,8 @@ static void nr_generate_Msg2(module_id_t module_idP,
       pdsch_pdu_rel15->TBSize[0] = TBS;
     }
 
-    int bw_tbslbrm = get_dlbw_tbslbrm(dl_bwp->initial_BWPSize, ra->CellGroup);
     pdsch_pdu_rel15->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(mcsTableIdx,
-                                                                               bw_tbslbrm,
+                                                                               dl_bwp->bw_tbslbrm,
                                                                                1);
     pdsch_pdu_rel15->maintenance_parms_v3.ldpcBaseGraph = get_BG(TBS<<3,R);
 
@@ -1522,9 +1521,8 @@ static void prepare_dl_pdus(gNB_MAC_INST *nr_mac,
   int x_Overhead = 0;
   nr_get_tbs_dl(&dl_tti_pdsch_pdu->pdsch_pdu, x_Overhead, pdsch_pdu_rel15->numDmrsCdmGrpsNoData, tb_scaling);
 
-  int bw_tbslbrm = get_dlbw_tbslbrm(dl_bwp->initial_BWPSize, ra->CellGroup);
   pdsch_pdu_rel15->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(mcsTableIdx,
-                                                                             bw_tbslbrm,
+                                                                             dl_bwp->bw_tbslbrm,
                                                                              1);
   pdsch_pdu_rel15->maintenance_parms_v3.ldpcBaseGraph = get_BG(tb_size<<3,R);
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
index 4675403834..90233cab82 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_dlsch.c
@@ -1086,10 +1086,8 @@ void nr_schedule_ue_spec(module_id_t module_id,
     long maxMIMO_Layers = current_BWP->pdsch_servingcellconfig ? *current_BWP->pdsch_servingcellconfig->ext1->maxMIMO_Layers : 1;
     const int nl_tbslbrm = min(maxMIMO_Layers, 4);
     // Maximum number of PRBs across all configured DL BWPs
-    int scc_bwpsize = current_BWP->initial_BWPSize;
-    int bw_tbslbrm = get_dlbw_tbslbrm(scc_bwpsize, cg);
     pdsch_pdu->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(current_BWP->mcsTableIdx,
-                                                                         bw_tbslbrm,
+                                                                         current_BWP->bw_tbslbrm,
                                                                          nl_tbslbrm);
     pdsch_pdu->maintenance_parms_v3.ldpcBaseGraph = get_BG(TBS<<3,R);
 
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
index fdc3e79b6e..5697107c0b 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_primitives.c
@@ -1140,7 +1140,7 @@ void fill_dci_pdu_rel15(const NR_ServingCellConfigCommon_t *scc,
                         NR_ControlResourceSet_t *coreset,
                         uint16_t cset0_bwp_size)
 {
-
+  NR_CrossCarrierSchedulingConfig_t *crossCarrierSchedulingConfig = NULL; // TODO configure
   uint8_t fsize = 0, pos = 0;
   uint64_t *dci_pdu = (uint64_t *)pdcch_dci_pdu->Payload;
   *dci_pdu = 0;
@@ -1158,16 +1158,46 @@ void fill_dci_pdu_rel15(const NR_ServingCellConfigCommon_t *scc,
     // computing alternative size for padding
     dci_pdu_rel15_t temp_pdu;
     if(dci_format == NR_DL_DCI_FORMAT_1_0)
-      alt_size = nr_dci_size(current_DL_BWP, current_UL_BWP, CellGroup, &temp_pdu, NR_UL_DCI_FORMAT_0_0, rnti_type, coreset, bwp_id, ss->searchSpaceType->present, cset0_bwp_size, 0);
+      alt_size = nr_dci_size(current_DL_BWP,
+                             current_UL_BWP,
+                             crossCarrierSchedulingConfig,
+                             &temp_pdu,
+                             NR_UL_DCI_FORMAT_0_0,
+                             rnti_type,
+                             coreset,
+                             bwp_id,
+                             ss->searchSpaceType->present,
+                             cset0_bwp_size,
+                             0);
 
     if(dci_format == NR_UL_DCI_FORMAT_0_0)
-      alt_size = nr_dci_size(current_DL_BWP, current_UL_BWP, CellGroup, &temp_pdu, NR_DL_DCI_FORMAT_1_0, rnti_type, coreset, bwp_id, ss->searchSpaceType->present, cset0_bwp_size, 0);
+      alt_size = nr_dci_size(current_DL_BWP,
+                             current_UL_BWP,
+                             crossCarrierSchedulingConfig,
+                             &temp_pdu,
+                             NR_DL_DCI_FORMAT_1_0,
+                             rnti_type,
+                             coreset,
+                             bwp_id,
+                             ss->searchSpaceType->present,
+                             cset0_bwp_size,
+                             0);
 
   }
   else
     N_RB = cset0_bwp_size;
 
-  int dci_size = nr_dci_size(current_DL_BWP, current_UL_BWP, CellGroup, dci_pdu_rel15, dci_format, rnti_type, coreset, bwp_id, ss->searchSpaceType->present, cset0_bwp_size, alt_size);
+  int dci_size = nr_dci_size(current_DL_BWP,
+                             current_UL_BWP,
+                             crossCarrierSchedulingConfig,
+                             dci_pdu_rel15,
+                             dci_format,
+                             rnti_type,
+                             coreset,
+                             bwp_id,
+                             ss->searchSpaceType->present,
+                             cset0_bwp_size,
+                             alt_size);
   pdcch_dci_pdu->PayloadSizeBits = dci_size;
   AssertFatal(dci_size <= 64, "DCI sizes above 64 bits not yet supported");
   if (dci_format == NR_DL_DCI_FORMAT_1_1 || dci_format == NR_UL_DCI_FORMAT_0_1)
@@ -2027,11 +2057,13 @@ void configure_UE_BWP(gNB_MAC_INST *nr_mac,
   if (CellGroup && CellGroup->physicalCellGroupConfig)
     DL_BWP->pdsch_HARQ_ACK_Codebook = &CellGroup->physicalCellGroupConfig->pdsch_HARQ_ACK_Codebook;
 
+  NR_ServingCellConfig_t *servingCellConfig = NULL;
   if (CellGroup &&
       CellGroup->spCellConfig &&
       CellGroup->spCellConfig->spCellConfigDedicated) {
 
-    const NR_ServingCellConfig_t *servingCellConfig = CellGroup->spCellConfig->spCellConfigDedicated;
+    servingCellConfig  = CellGroup->spCellConfig->spCellConfigDedicated;
+    UL_BWP->supplementaryUplink = servingCellConfig->supplementaryUplink;
     DL_BWP->pdsch_servingcellconfig = servingCellConfig->pdsch_ServingCellConfig ? servingCellConfig->pdsch_ServingCellConfig->choice.setup : NULL;
     UL_BWP->pusch_servingcellconfig = servingCellConfig->uplinkConfig && servingCellConfig->uplinkConfig->pusch_ServingCellConfig ?
                                       servingCellConfig->uplinkConfig->pusch_ServingCellConfig->choice.setup : NULL;
@@ -2144,6 +2176,9 @@ void configure_UE_BWP(gNB_MAC_INST *nr_mac,
   UL_BWP->initial_BWPSize = NRRIV2BW(scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
   UL_BWP->initial_BWPStart = NRRIV2PRBOFFSET(scc->uplinkConfigCommon->initialUplinkBWP->genericParameters.locationAndBandwidth, MAX_BWP_SIZE);
 
+  DL_BWP->bw_tbslbrm = get_dlbw_tbslbrm(DL_BWP->initial_BWPSize, servingCellConfig);
+  UL_BWP->bw_tbslbrm = get_ulbw_tbslbrm(UL_BWP->initial_BWPSize, servingCellConfig);
+
   if (UL_BWP->bwp_id > 0) {
     UL_BWP->pucch_ConfigCommon = ul_bwp->bwp_Common->pucch_ConfigCommon ? ul_bwp->bwp_Common->pucch_ConfigCommon->choice.setup : NULL;
     UL_BWP->rach_ConfigCommon = ul_bwp->bwp_Common->rach_ConfigCommon ? ul_bwp->bwp_Common->rach_ConfigCommon->choice.setup : NULL;
diff --git a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
index 761bbf6535..cc9a6c9f84 100644
--- a/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
+++ b/openair2/LAYER2/NR_MAC_gNB/gNB_scheduler_ulsch.c
@@ -2288,10 +2288,8 @@ void nr_schedule_ulsch(module_id_t module_id, frame_t frame, sub_frame_t slot, n
       if (!maxMIMO_Layers)
         maxMIMO_Layers = current_BWP->pusch_Config->maxRank;
       AssertFatal (maxMIMO_Layers != NULL,"Option with max MIMO layers not configured is not supported\n");
-      const int scc_bwpsize = current_BWP->initial_BWPSize;
-      int bw_tbslbrm = get_ulbw_tbslbrm(scc_bwpsize, cg);
       pusch_pdu->maintenance_parms_v3.tbSizeLbrmBytes = nr_compute_tbslbrm(current_BWP->mcs_table,
-                                                                           bw_tbslbrm,
+                                                                           current_BWP->bw_tbslbrm,
                                                                            *maxMIMO_Layers);
     }
     else
-- 
2.26.2