From 46b0a9fb38feb47286c8f35b2b1d143fee6c5cd0 Mon Sep 17 00:00:00 2001
From: Louis Adrien Dufrene <swmt1841@yd-CZC6227X3N.orangeai.mey>
Date: Thu, 11 Apr 2019 07:36:05 +0200
Subject: [PATCH] Remove bypass_cdrx variable and add cdrx_waiting_ack. The
 CDRX is now activated at RRC COnnection Reconfiguration Complete reception.
 To Test

---
 openair2/LAYER2/MAC/config.c        | 4 ++--
 openair2/LAYER2/MAC/mac.h           | 6 +++---
 openair2/LAYER2/MAC/pre_processor.c | 4 ++--
 openair2/RRC/LTE/rrc_eNB.c          | 9 +++++++--
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/openair2/LAYER2/MAC/config.c b/openair2/LAYER2/MAC/config.c
index e7373ff843..d55b205cab 100644
--- a/openair2/LAYER2/MAC/config.c
+++ b/openair2/LAYER2/MAC/config.c
@@ -1059,8 +1059,8 @@ void eNB_Config_Local_DRX(
   }
 
   /* Modify scheduling control structure according to DRX configuration: doesn't support every configurations! */
-  UE_scheduling_control->cdrx_configured = TRUE;
-  UE_scheduling_control->bypass_cdrx = TRUE; // set to true first, waiting for the UE to configure CDRX on its side
+  UE_scheduling_control->cdrx_configured = FALSE; // will be set to true when ACK is received
+  UE_scheduling_control->cdrx_waiting_ack = TRUE; // set to true first, waiting for the UE to configure CDRX on its side
   UE_scheduling_control->in_active_time = FALSE;
 
   UE_scheduling_control->on_duration_timer = 0;
diff --git a/openair2/LAYER2/MAC/mac.h b/openair2/LAYER2/MAC/mac.h
index 8a956bd7b9..538d174355 100644
--- a/openair2/LAYER2/MAC/mac.h
+++ b/openair2/LAYER2/MAC/mac.h
@@ -1013,11 +1013,11 @@ typedef struct {
     /// is TRUE if the following drx parameters are configured for UE
     boolean_t cdrx_configured;
     /* 
-     * if TRUE, the scheduler should bypass in_active_time and consider the UE as active
-     * This can be needed, especially during the RRC configuration process, when the context is
+     * if TRUE, the eNB has configured the CDRX locally, but is waiting for the UE to acknowledge 
+     * the activation. This is needed, during the RRC configuration process, when the context is
      * configured on the eNB side, but not yet on the UE side...
      */
-    boolean_t bypass_cdrx;
+    boolean_t cdrx_waiting_ack;
     /// is TRUE if the UE is in "Active Time", hence listening to PDCCH
     boolean_t in_active_time;
     /// OnDurationTimer
diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c
index a25505bab4..7be70edc43 100644
--- a/openair2/LAYER2/MAC/pre_processor.c
+++ b/openair2/LAYER2/MAC/pre_processor.c
@@ -480,7 +480,7 @@ void sort_UEs(module_id_t Mod_idP,
 
     /* Check CDRX configuration and if UE is in active time for this subframe */
     if (UE_scheduling_control->cdrx_configured == TRUE) {
-      if ((UE_scheduling_control->bypass_cdrx == FALSE) && (UE_scheduling_control->in_active_time == FALSE)) {
+      if (UE_scheduling_control->in_active_time == FALSE) {
         continue;
       }
     }
@@ -2017,7 +2017,7 @@ void sort_ue_ul(module_id_t module_idP,
 
     /* Check CDRX configuration and if UE is in active time for this subframe */
     if (UE_scheduling_control->cdrx_configured == TRUE) {
-      if ((UE_scheduling_control->bypass_cdrx == FALSE) && (UE_scheduling_control->in_active_time == FALSE)) {
+      if (UE_scheduling_control->in_active_time == FALSE) {
         continue;
       }
     }
diff --git a/openair2/RRC/LTE/rrc_eNB.c b/openair2/RRC/LTE/rrc_eNB.c
index 19dbd0f6eb..923ad83829 100644
--- a/openair2/RRC/LTE/rrc_eNB.c
+++ b/openair2/RRC/LTE/rrc_eNB.c
@@ -5474,9 +5474,14 @@ rrc_eNB_process_RRCConnectionReconfigurationComplete(
   ue_context_pP->ue_context.ue_reestablishment_timer = 0;
   ue_context_pP->ue_context.ue_rrc_inactivity_timer = 1; // reset rrc inactivity timer
 
-  /* CDRX: activated because acknowledged */
+  /* CDRX: activated if ack was expected */
   int UE_id_mac = find_UE_id(ctxt_pP->module_id, ue_context_pP->ue_context.rnti);
-  RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id_mac].bypass_cdrx = FALSE;
+  UE_sched_ctrl *UE_scheduling_control = &(RC.mac[ctxt_pP->module_id]->UE_list.UE_sched_ctrl[UE_id_mac])
+  
+  if (UE_scheduling_control.cdrx_waiting_ack) == TRUE {
+    UE_scheduling_control.cdrx_waiting_ack = FALSE;
+    UE_scheduling_control.cdrx_configured = TRUE;
+  }
 
   T(T_ENB_RRC_CONNECTION_RECONFIGURATION_COMPLETE,
     T_INT(ctxt_pP->module_id),
-- 
GitLab