From 9eaee53bb647d2f971d0b81e27a5920581d61fd2 Mon Sep 17 00:00:00 2001
From: Cedric Roux <cedric.roux@eurecom.fr>
Date: Sat, 13 May 2017 12:45:17 +0200
Subject: [PATCH] rewrite phy_stats_exist

We have to test that all active CCs of a given UE exist in the PHY layer.
Maybe not the end of the story...
---
 openair2/LAYER2/MAC/pre_processor.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/openair2/LAYER2/MAC/pre_processor.c b/openair2/LAYER2/MAC/pre_processor.c
index 29972d6a1a..1be9a2ba3a 100644
--- a/openair2/LAYER2/MAC/pre_processor.c
+++ b/openair2/LAYER2/MAC/pre_processor.c
@@ -66,18 +66,28 @@
 */
 
 /* this function checks that get_eNB_UE_stats returns
- * a non-NULL pointer for all CCs for a given UE
+ * a non-NULL pointer for all the active CCs of an UE
  */
 int phy_stats_exist(module_id_t Mod_id, int rnti)
 {
   int CC_id;
-  for (CC_id = 0; CC_id < MAX_NUM_CCs; CC_id++){
-    int UE_id = find_UE_id(Mod_id,rnti);  
-    if (UE_id == -1) 
-      continue;   //skip if UE is not valid
-    if (CC_id == UE_PCCID(Mod_id,UE_id))  //get stats for only the CCs which the UE belongs to
-      if (mac_xface->get_eNB_UE_stats(Mod_id, CC_id, rnti) == NULL)
-        return 0;
+  int i;
+  int UE_id          = find_UE_id(Mod_id, rnti);
+  UE_list_t *UE_list = &eNB_mac_inst[Mod_id].UE_list;
+  if (UE_id == -1) {
+    LOG_W(MAC, "[eNB %d] UE %x not found, should be there (in phy_stats_exist)\n",
+	  Mod_id, rnti);
+    return 0;
+  }
+  if (UE_list->numactiveCCs[UE_id] == 0) {
+    LOG_W(MAC, "[eNB %d] UE %x has no active CC (in phy_stats_exist)\n",
+	  Mod_id, rnti);
+    return 0;
+  }
+  for (i = 0; i < UE_list->numactiveCCs[UE_id]; i++) {
+    CC_id = UE_list->ordered_CCids[i][UE_id];
+    if (mac_xface->get_eNB_UE_stats(Mod_id, CC_id, rnti) == NULL)
+      return 0;
   }
   return 1;
 }
-- 
GitLab