From c8c803235885e7b62d28abd2b76a1f8934f5dbf5 Mon Sep 17 00:00:00 2001
From: Raymond Knopp <raymond.knopp@eurecom.fr>
Date: Tue, 4 Sep 2018 09:25:02 +0200
Subject: [PATCH] initial DU part for F1AP_setup_resp

---
 openair2/ENB_APP/enb_app.c    | 52 +++++++++++++++++++++++++++++++++--
 openair2/ENB_APP/enb_config.c | 20 ++++++++++++++
 2 files changed, 69 insertions(+), 3 deletions(-)

diff --git a/openair2/ENB_APP/enb_app.c b/openair2/ENB_APP/enb_app.c
index 0008361d93..f0dd39d3e6 100644
--- a/openair2/ENB_APP/enb_app.c
+++ b/openair2/ENB_APP/enb_app.c
@@ -217,8 +217,7 @@ void *eNB_app_task(void *args_p)
     configure_rrc(enb_id);
 
     if (RC.nb_macrlc_inst >0 && mac_has_f1[enb_id]==1) RC.rrc[enb_id]->node_type = ngran_eNB_DU;
-
-    pdcp_layer_init();
+    else                                               pdcp_layer_init();
   }
 
 
@@ -252,8 +251,11 @@ void *eNB_app_task(void *args_p)
 # if defined(ENABLE_USE_MME)
 
     case S1AP_REGISTER_ENB_CNF:
+      AssertFatal(RC.rrc[0]->node_type != ngran_eNB_DU, "Should not have received S1AP_REGISTER_ENB_CNF\n");
+
       LOG_I(ENB_APP, "[eNB %d] Received %s: associated MME %d\n", instance, ITTI_MSG_NAME (msg_p),
-            S1AP_REGISTER_ENB_CNF(msg_p).nb_mme);
+	    S1AP_REGISTER_ENB_CNF(msg_p).nb_mme);
+      
 
       DevAssert(register_enb_pending > 0);
       register_enb_pending--;
@@ -291,6 +293,50 @@ void *eNB_app_task(void *args_p)
 
       break;
 
+    case F1AP_SETUP_RESP:
+      AssertFatal(RC.rrc[0]->node_type == ngran_eNB_DU, "Should not have received F1AP_REGISTER_ENB_CNF\n");
+
+      LOG_I(ENB_APP, "[eNB %d] Received %s: associated ngran_eNB_CU %s with %d cells to activate\n", instance, ITTI_MSG_NAME (msg_p),
+	    F1AP_SETUP_RESP(msg_p).gNB_CU_name,F1AP_SETUP_RESP(msg_p).num_cells_to_activate);
+      
+      handle_f1ap_setup_resp(&F1AP_SETUP_RESP(msg_p));
+
+      DevAssert(register_enb_pending > 0);
+      register_enb_pending--;
+
+      /* Check if at least eNB is registered with one MME */
+      if (F1AP_SETUP_RESP(msg_p).num_cells_to_activate > 0) {
+        registered_enb++;
+      }
+
+      /* Check if all register eNB requests have been processed */
+      if (register_enb_pending == 0) {
+        if (registered_enb == enb_nb) {
+          /* If all eNB cells are registered, start L2L1 task */
+          MessageDef *msg_init_p;
+
+          msg_init_p = itti_alloc_new_message (TASK_ENB_APP, INITIALIZE_MESSAGE);
+          itti_send_msg_to_task (TASK_L2L1, INSTANCE_DEFAULT, msg_init_p);
+
+        } else {
+          LOG_W(ENB_APP, " %d eNB not associated with a MME, retrying registration in %d seconds ...\n",
+                enb_nb - registered_enb,  ENB_REGISTER_RETRY_DELAY);
+
+          /* Restart the eNB registration process in ENB_REGISTER_RETRY_DELAY seconds */
+          if (timer_setup (ENB_REGISTER_RETRY_DELAY, 0, TASK_ENB_APP, INSTANCE_DEFAULT, TIMER_ONE_SHOT,
+                           NULL, &enb_register_retry_timer_id) < 0) {
+            LOG_E(ENB_APP, " Can not start eNB register retry timer, use \"sleep\" instead!\n");
+
+            sleep(ENB_REGISTER_RETRY_DELAY);
+            /* Restart the registration process */
+            registered_enb = 0;
+            register_enb_pending = eNB_app_register (RC.rrc[0]->node_type,enb_id_start, enb_id_end);//, enb_properties_p);
+          }
+        }
+      }
+
+      break;
+
     case S1AP_DEREGISTERED_ENB_IND:
       LOG_W(ENB_APP, "[eNB %d] Received %s: associated MME %d\n", instance, ITTI_MSG_NAME (msg_p),
             S1AP_DEREGISTERED_ENB_IND(msg_p).nb_mme);
diff --git a/openair2/ENB_APP/enb_config.c b/openair2/ENB_APP/enb_config.c
index 9cbb6cc9c8..3511aa021f 100644
--- a/openair2/ENB_APP/enb_config.c
+++ b/openair2/ENB_APP/enb_config.c
@@ -2706,3 +2706,23 @@ void RCConfig(void) {
     RC.nb_RU     = RUParamList.numelt; 
  
 }
+
+void handle_f1ap_setup_resp(f1ap_setup_resp_t *resp) {
+
+
+  int i,j,si_ind;
+  AssertFatal(1==0, "Shouldn't get here yet\n");
+  /*
+  for (j=0;j<resp->num_cells_to_activate;j++) {
+    for (i=0;i<RC.nb_inst;i++) {
+      rrc_eNB_carrier_data_t *carrier =  &RC.rrc[i]->carrier[0];
+      // identify local index of cell j by plmn identity
+      if (check_plmn_identity(carrier, resp->mcc[j], resp->mnc[j], resp->mnc_digit_length[j])>0 &&
+          resp->nrpci[j] == carrier->physCellId) {
+	// copy system information and decode it to perform MAC/L1 common configuration
+	for (si_ind=0;si_ind<resp->num_SI[j];si_ind++) {
+	  
+	}
+      }
+  */
+}
-- 
GitLab