From 73560827544b1b5d72988b3147c5e16cddf04ba9 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Tue, 15 Aug 2017 00:51:50 -0700
Subject: [PATCH] added narrowband to first rb maping for L2

---
 openair2/LAYER2/MAC/eNB_scheduler_RA.c        |  6 ++--
 openair2/LAYER2/MAC/eNB_scheduler_bch.c       |  6 ++--
 .../LAYER2/MAC/eNB_scheduler_primitives.c     | 28 +++++++++++++++++++
 openair2/LAYER2/MAC/proto.h                   |  3 ++
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/openair2/LAYER2/MAC/eNB_scheduler_RA.c b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
index 64e8c8380f..88ee3d14ae 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_RA.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_RA.c
@@ -209,7 +209,7 @@ void generate_Msg2(module_id_t module_idP,int CC_idP,frame_t frameP,sub_frame_t
     // get narrowband according to higher-layer config 
     num_nb = p[RA_template->rach_resource_type-1]->mpdcch_NarrowbandsToMonitor_r13.list.count;
     RA_template->msg2_narrowband = *p[RA_template->rach_resource_type-1]->mpdcch_NarrowbandsToMonitor_r13.list.array[RA_template->preamble_index%num_nb];
-    first_rb = RA_template->msg2_narrowband*6;
+    first_rb = narrowband_to_first_rb(&cc[CC_idP],RA_template->msg2_narrowband);
     
     if ((RA_template->msg2_mpdcch_repetition_cnt == 0) &&
 	(mpdcch_sf_condition(eNB,CC_idP,frameP,subframeP,rmax,TYPE2)>0)){
@@ -555,8 +555,8 @@ void generate_Msg4(module_id_t module_idP,int CC_idP,frame_t frameP,sub_frame_t
     // get actual repetition count from Table 9.1.5-3
     reps           = (rmax<=8)?(1<<rep):(rmax>>(3-rep));
     // get first narrowband
-    first_rb = RA_template->msg34_narrowband*6;
-    
+    first_rb = narrowband_to_first_rb(&cc[CC_idP],RA_template->msg34_narrowband);
+
     if ((RA_template->msg4_mpdcch_repetition_cnt == 0) &&
 	(mpdcch_sf_condition(eNB,CC_idP,frameP,subframeP,rmax,TYPE2)>0)){
       // MPDCCH configuration for RAR
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_bch.c b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
index 426693dd9f..a5056f165c 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_bch.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_bch.c
@@ -199,7 +199,9 @@ schedule_SIB1_BR(
     LOG_D(MAC,"[eNB %d] Frame %d : BCCH_BR->DLSCH CC_id %d, Received %d bytes \n",module_idP,frameP,CC_id,bcch_sdu_length);
     
     // allocate all 6 PRBs in narrowband for SIB1_BR
-    first_rb = n_NB*6;
+
+    first_rb = narrowband_to_first_rb(cc,n_NB);
+
     vrb_map[first_rb] = 1;
     vrb_map[first_rb+1] = 1;
     vrb_map[first_rb+2] = 1;
@@ -383,7 +385,7 @@ schedule_SI_BR(
 	    LOG_D(MAC,"[eNB %d] Frame %d : BCCH_BR %d->DLSCH CC_id %d, Received %d bytes \n",module_idP,frameP,i,CC_id,bcch_sdu_length);
 	    
 	    // allocate all 6 PRBs in narrowband for SIB1_BR
-	    first_rb = si_Narrowband_r13*6;
+	    first_rb = narrowband_to_first_rb(cc,si_Narrowband_r13);
 	    vrb_map[first_rb]   = 1;
 	    vrb_map[first_rb+1] = 1;
 	    vrb_map[first_rb+2] = 1;
diff --git a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
index 09e5fe4d2c..02e0db1c4e 100644
--- a/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
+++ b/openair2/LAYER2/MAC/eNB_scheduler_primitives.c
@@ -524,7 +524,35 @@ int mpdcch_sf_condition(eNB_MAC_INST *eNB,int CC_id, frame_t frameP,sub_frame_t
 
 }
 
+int narrowband_to_first_rb(COMMON_channels_t *cc, int nb_index) {
 
+  switch (cc->mib->message.dl_Bandwidth) {
+  case 0: // 6 PRBs, N_NB=1, i_0=0
+    return(0);
+    break;
+  case 3: // 50 PRBs, N_NB=8, i_0=1
+    return((int)(1+(6*nb_index)));
+    break;
+  case 5: // 100 PRBs, N_NB=16, i_0=2
+    return((int)(2+(6*nb_index)));
+    break;
+  case 1: // 15 PRBs  N_NB=2, i_0=1
+    if (nb_index>0) return(1);
+    else            return(0);
+    break;
+  case 2: // 25 PRBs, N_NB=4, i_0=0
+    if (nb_index>1) return(1+(6*nb_index));
+    else            return((6*nb_index));
+    break;
+  case 4: // 75 PRBs, N_NB=12, i_0=1
+    if (nb_index>5) return(2+(6*nb_index));
+    else            return(1+(6*nb_index));
+    break;
+  default:
+    AssertFatal(1==0,"Impossible dl_Bandwidth %d\n",cc->mib->message.dl_Bandwidth);
+    break;
+  }
+}
 #endif
 
 //------------------------------------------------------------------------------
diff --git a/openair2/LAYER2/MAC/proto.h b/openair2/LAYER2/MAC/proto.h
index 54bb2f8ad9..8781a41128 100644
--- a/openair2/LAYER2/MAC/proto.h
+++ b/openair2/LAYER2/MAC/proto.h
@@ -904,6 +904,9 @@ int get_numnarrowbandbits(long dl_Bandwidth);
 int mpdcch_sf_condition(eNB_MAC_INST *eNB,int CC_id, frame_t frameP,sub_frame_t subframeP,int rmax,MPDCCH_TYPES_t mpdcch_type);
 
 int get_numnarrowbands(long dl_Bandwidth);
+
+int narrowband_to_first_rb(COMMON_channels_t *cc, int nb_index);
+
 #endif
 
 
-- 
GitLab