From c81535a8b08c8adaa78e5689acb6ee58f825485d Mon Sep 17 00:00:00 2001
From: Robert Schmidt <robert.schmidt@eurecom.fr>
Date: Wed, 24 Oct 2018 14:33:48 +0200
Subject: [PATCH] Add FlexRAN PHY CM

---
 cmake_targets/CMakeLists.txt                  |  2 +
 .../CONTROL_MODULES/PHY/flexran_agent_phy.c   | 63 +++++++++++++++++++
 .../CONTROL_MODULES/PHY/flexran_agent_phy.h   | 54 ++++++++++++++++
 .../PHY/flexran_agent_phy_defs.h              | 35 +++++++++++
 openair2/ENB_APP/flexran_agent.c              |  2 +
 openair2/ENB_APP/flexran_agent.h              |  1 +
 openair2/ENB_APP/flexran_agent_extern.h       |  4 ++
 7 files changed, 161 insertions(+)
 create mode 100644 openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.c
 create mode 100644 openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.h
 create mode 100644 openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy_defs.h

diff --git a/cmake_targets/CMakeLists.txt b/cmake_targets/CMakeLists.txt
index 7ad42079de4..7f420e337b6 100644
--- a/cmake_targets/CMakeLists.txt
+++ b/cmake_targets/CMakeLists.txt
@@ -825,6 +825,7 @@ include_directories("${OPENAIR_DIR}/targets/COMMON")
 include_directories("${OPENAIR_DIR}/targets/ARCH/COMMON")
 include_directories("${OPENAIR_DIR}/targets/ARCH/EXMIMO/USERSPACE/LIB/")
 include_directories("${OPENAIR_DIR}/targets/ARCH/EXMIMO/DEFS")
+include_directories("${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/PHY")
 include_directories("${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/MAC")
 include_directories("${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/RRC")
 include_directories("${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/PDCP")
@@ -916,6 +917,7 @@ add_library(FLEXRAN_AGENT
   ${OPENAIR2_DIR}/ENB_APP/flexran_agent_ran_api.c
   ${OPENAIR2_DIR}/ENB_APP/flexran_agent_timer.c
   ${OPENAIR2_DIR}/ENB_APP/flexran_agent_common_internal.c
+  ${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.c
   ${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/MAC/flexran_agent_mac.c
   ${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/RRC/flexran_agent_rrc.c
   ${OPENAIR2_DIR}/ENB_APP/CONTROL_MODULES/PDCP/flexran_agent_pdcp.c
diff --git a/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.c b/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.c
new file mode 100644
index 00000000000..745659c949e
--- /dev/null
+++ b/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.c
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file flexran_agent_phy.c
+ * \brief FlexRAN agent Control Module PHY
+ * \author Robert Schmidt
+ * \date Oct 2018
+ */
+
+#include "flexran_agent_phy.h"
+
+/* Array containing the Agent-PHY interfaces */
+AGENT_PHY_xface *agent_phy_xface[NUM_MAX_ENB];
+
+int flexran_agent_register_phy_xface(mid_t mod_id)
+{
+  if (agent_phy_xface[mod_id]) {
+    LOG_E(PHY, "PHY agent for eNB %d is already registered\n", mod_id);
+    return -1;
+  }
+  AGENT_PHY_xface *xface = malloc(sizeof(AGENT_PHY_xface));
+  if (!xface) {
+    LOG_E(FLEXRAN_AGENT, "could not allocate memory for PHY agent xface %d\n", mod_id);
+    return -1;
+  }
+
+  agent_phy_xface[mod_id] = xface;
+  return 0;
+}
+
+int flexran_agent_unregister_phy_xface(mid_t mod_id)
+{
+  if (!agent_phy_xface[mod_id]) {
+    LOG_E(FLEXRAN_AGENT, "PHY agent for eNB %d is not registered\n", mod_id);
+    return -1;
+  }
+  free(agent_phy_xface[mod_id]);
+  agent_phy_xface[mod_id] = NULL;
+  return 0;
+}
+
+AGENT_PHY_xface *flexran_agent_get_phy_xface(mid_t mod_id)
+{
+  return agent_phy_xface[mod_id];
+}
diff --git a/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.h b/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.h
new file mode 100644
index 00000000000..26a658a9431
--- /dev/null
+++ b/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy.h
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+
+/*! \file flexran_agent_phy.h
+ * \brief FlexRAN agent Control Module PHY header
+ * \author Robert Schmidt
+ * \date Oct 2018
+ */
+
+#ifndef FLEXRAN_AGENT_PHY_H_
+#define FLEXRAN_AGENT_PHY_H_
+
+#include "header.pb-c.h"
+#include "flexran.pb-c.h"
+#include "stats_messages.pb-c.h"
+#include "stats_common.pb-c.h"
+
+
+#include "flexran_agent_common.h"
+#include "flexran_agent_defs.h"
+#include "flexran_agent_phy_defs.h"
+#include "flexran_agent_ran_api.h"
+// for flexran_agent_get_phy_xface()
+#include "flexran_agent_extern.h"
+
+/**********************************
+ * FlexRAN agent - technology PHY API
+ **********************************/
+
+/* Register technology specific interface callbacks */
+int flexran_agent_register_phy_xface(mid_t mod_id);
+
+/* Unregister technology specific callbacks */
+int flexran_agent_unregister_phy_xface(mid_t mod_id);
+
+#endif
diff --git a/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy_defs.h b/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy_defs.h
new file mode 100644
index 00000000000..06c262ef7fa
--- /dev/null
+++ b/openair2/ENB_APP/CONTROL_MODULES/PHY/flexran_agent_phy_defs.h
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The OpenAirInterface Software Alliance licenses this file to You under
+ * the OAI Public License, Version 1.1  (the "License"); you may not use this file
+ * except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.openairinterface.org/?page_id=698
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *-------------------------------------------------------------------------------
+ * For more information about the OpenAirInterface (OAI) Software Alliance:
+ *      contact@openairinterface.org
+ */
+#ifndef __FLEXRAN_AGENT_PHY_PRIMITIVES_H__
+#define __FLEXRAN_AGENT_PHY_PRIMITIVES_H__
+
+#include "flexran_agent_defs.h"
+#include "flexran.pb-c.h"
+#include "header.pb-c.h"
+
+/* FLEXRAN AGENT-PHY Interface */
+typedef struct {
+
+  /* currently empty, will be used to control RU */
+
+} AGENT_PHY_xface;
+
+#endif /* __FLEXRAN_AGENT_PHY_PRIMITIVES_H__ */
diff --git a/openair2/ENB_APP/flexran_agent.c b/openair2/ENB_APP/flexran_agent.c
index 30f2e278954..bd353fdd2c2 100644
--- a/openair2/ENB_APP/flexran_agent.c
+++ b/openair2/ENB_APP/flexran_agent.c
@@ -231,6 +231,8 @@ int flexran_agent_start(mid_t mod_id)
   new_thread(receive_thread, flexran);
 
   /* Register and initialize the control modules */
+  flexran_agent_register_phy_xface(mod_id);
+
   flexran_agent_register_mac_xface(mod_id);
   flexran_agent_init_mac_agent(mod_id);
 
diff --git a/openair2/ENB_APP/flexran_agent.h b/openair2/ENB_APP/flexran_agent.h
index 4ce727ff1c7..e50a2be4f65 100644
--- a/openair2/ENB_APP/flexran_agent.h
+++ b/openair2/ENB_APP/flexran_agent.h
@@ -36,6 +36,7 @@
 #include "flexran_agent_defs.h"
 #include "flexran_agent_net_comm.h"
 #include "flexran_agent_ran_api.h"
+#include "flexran_agent_phy.h"
 #include "flexran_agent_mac.h"
 #include "flexran_agent_rrc.h"
 #include "flexran_agent_pdcp.h"
diff --git a/openair2/ENB_APP/flexran_agent_extern.h b/openair2/ENB_APP/flexran_agent_extern.h
index f80532be936..e1dec8506ce 100644
--- a/openair2/ENB_APP/flexran_agent_extern.h
+++ b/openair2/ENB_APP/flexran_agent_extern.h
@@ -31,10 +31,14 @@
 #define __FLEXRAN_AGENT_EXTERN_H__
 
 #include "flexran_agent_defs.h"
+#include "flexran_agent_phy_defs.h"
 #include "flexran_agent_mac_defs.h"
 #include "flexran_agent_rrc_defs.h"
 #include "flexran_agent_pdcp_defs.h"
 
+/* Control module interface for the communication of the PHY control module with the agent */
+AGENT_PHY_xface *flexran_agent_get_phy_xface(mid_t mod_id);
+
 /* Control module interface for the communication of the MAC Control Module with the agent */
 AGENT_MAC_xface *flexran_agent_get_mac_xface(mid_t mod_id);
 
-- 
GitLab