From 96f18a06d239ee6556cc1ddd344da8a736d33ca8 Mon Sep 17 00:00:00 2001
From: matzakos <panagiotis.matzakos@eurecom.fr>
Date: Mon, 13 Nov 2017 16:58:11 +0100
Subject: [PATCH] Added functions copying nfapi requests to UE_mac_inst +
 Substituted calls to phy_procedures_ue rx/tx with phy_stub functions
 triggering MAC layer Tx/Rx procedures at UE MAC. Changes within
 UE_thread_rxn_txnp4

---
 openair2/LAYER2/MAC/defs.h           | 13 ++++++--
 openair2/PHY_INTERFACE/phy_stub_UE.c | 48 +++++++++++++++++++++++-----
 openair2/PHY_INTERFACE/phy_stub_UE.h | 22 +++++++++++--
 targets/RT/USER/lte-ue.c             | 29 ++++++++++++++---
 4 files changed, 95 insertions(+), 17 deletions(-)

diff --git a/openair2/LAYER2/MAC/defs.h b/openair2/LAYER2/MAC/defs.h
index e9914d40fe3..cba8112f349 100644
--- a/openair2/LAYER2/MAC/defs.h
+++ b/openair2/LAYER2/MAC/defs.h
@@ -1280,14 +1280,14 @@ typedef struct {
   /// Pointers to LogicalChannelConfig indexed by LogicalChannelIdentity. Note NULL means LCHAN is inactive.
   LogicalChannelConfig_t *logicalChannelConfig[MAX_NUM_LCID];
 
-  /// Panos: Pointer to IF_Module_UE instance of the UE
+  /*/// Panos: Pointer to IF_Module_UE instance of the UE
   IF_Module_UE_t *if_inst_ue;
   /// Panos: UE_MAC interface: Config request structure.
   UE_PHY_Config_t UE_config;
   /// Panos: UE_MAC interface: UL Config Request Structure
   UE_MAC_ul_config_request_t UL_req_ue[MAX_NUM_CCs];
   /// Panos: UE_MAC interface: UL Transmission request structure.
-  UE_MAC_tx_request_t UL_TX_req[MAX_NUM_CCs];
+  UE_MAC_tx_request_t UL_TX_req[MAX_NUM_CCs];*/
 
 
   /// Scheduling Information
@@ -1391,6 +1391,15 @@ typedef struct {
   /// Panos: Phy_stub mode: Boolean variable to distinguish whether a Msg3 or a regular ULSCH data pdu should be generated
   /// after the reception of NFAPI_UL_CONFIG_ULSCH_PDU_TYPE.
   uint8_t first_ULSCH_Tx;
+
+  /// Panos: Pointers to config_request types. Used from nfapi callback functions.
+  nfapi_dl_config_request_t* dl_config_req;
+  nfapi_ul_config_request_t* ul_config_req;
+  nfapi_hi_dci0_request_t* hi_dci0_req;
+  nfapi_tx_request_t* tx_req;
+
+
+
 } UE_MAC_INST;
 /*! \brief ID of the neighboring cells used for HO*/
 typedef struct {
diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.c b/openair2/PHY_INTERFACE/phy_stub_UE.c
index c1c4b94befb..0a6b8962024 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.c
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.c
@@ -2,9 +2,11 @@
 //#include "openair1/PHY/defs.h"
 //#include "openair2/PHY_INTERFACE/IF_Module.h"
 //#include "openair1/PHY/extern.h"
-#include "LAYER2/MAC/extern.h"
-//#include "LAYER2/MAC/proto.h"
-#include "openair2/LAYER2/MAC/vars.h"
+#include "openair2/LAYER2/MAC/extern.h"
+#include "openair2/LAYER2/MAC/defs.h"
+#include "openair2/LAYER2/MAC/proto.h"
+//#include "openair2/LAYER2/MAC/vars.h"
+#include "openair1/SCHED/defs.h"
 //#include "common/ran_context.h"
 #include "openair2/PHY_INTERFACE/phy_stub_UE.h"
 //#include "nfapi_pnf_interface.h"
@@ -636,7 +638,7 @@ void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
 
 
 
-int ul_config_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req)
+int ul_config_req_UE_MAC(nfapi_ul_config_request_t* req)
 {
   LOG_D(PHY,"[PNF] UL_CONFIG_REQ %s() sfn_sf:%d pdu:%d rach_prach_frequency_resources:%d srs_present:%u\n",
       __FUNCTION__,
@@ -725,8 +727,12 @@ int ul_config_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_
   return 0;
 }
 
+int tx_req_UE_MAC1( int k) {
+	return 0;
+}
+
 
-int tx_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_tx_request_t* req)
+int tx_req_UE_MAC(nfapi_tx_request_t* req)
 {
   uint16_t sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
   uint16_t sf = NFAPI_SFNSF2SF(req->sfn_sf);
@@ -756,7 +762,7 @@ int tx_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_tx_request_t* req)
 }
 
 
-int dl_config_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request_t* req)
+int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req)
 {
 
   int sfn = NFAPI_SFNSF2SFN(req->sfn_sf);
@@ -856,7 +862,7 @@ int dl_config_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request_
 
     else
     {
-      NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() UNKNOWN:%d\n", __FUNCTION__, dl_config_pdu_list[i].pdu_type);
+      //NFAPI_TRACE(NFAPI_TRACE_ERROR, "%s() UNKNOWN:%d\n", __FUNCTION__, dl_config_pdu_list[i].pdu_type);
     }
   }
 
@@ -868,7 +874,7 @@ int dl_config_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request_
 
 
 
-int hi_dci0_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* req)
+int hi_dci0_req_UE_MAC(nfapi_hi_dci0_request_t* req)
 {
   LOG_D(PHY,"[UE-PHY_STUB] hi dci0 request sfn_sf:%d number_of_dci:%d number_of_hi:%d\n", NFAPI_SFNSF2DEC(req->sfn_sf), req->hi_dci0_request_body.number_of_dci, req->hi_dci0_request_body.number_of_hi);
 
@@ -910,6 +916,32 @@ int hi_dci0_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* r
   return 0;
 }
 
+// The following set of memcpy functions should be getting called as callback functions from
+// pnf_p7_subframe_ind.
+void memcpy_dl_config_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request_t* req)
+{
+	module_id_t Mod_id = 0; //Panos: Currently static (only for one UE) but this should change.
+	UE_mac_inst[Mod_id].dl_config_req = req;
+}
+
+void memcpy_ul_config_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req)
+{
+	module_id_t Mod_id = 0; //Panos: Currently static (only for one UE) but this should change.
+	UE_mac_inst[Mod_id].ul_config_req = req;
+}
+
+void memcpy_tx_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_tx_request_t* req)
+{
+	module_id_t Mod_id = 0; //Panos: Currently static (only for one UE) but this should change.
+	UE_mac_inst[Mod_id].tx_req = req;
+}
+
+void memcpy_hi_dci0_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* req)
+{
+	module_id_t Mod_id = 0; //Panos: Currently static (only for one UE) but this should change.
+	UE_mac_inst[Mod_id].hi_dci0_req = req;
+}
+
 
 
 /*void handle_nfapi_UE_Rx(uint8_t Mod_id, Sched_Rsp_t *Sched_INFO, int eNB_id){
diff --git a/openair2/PHY_INTERFACE/phy_stub_UE.h b/openair2/PHY_INTERFACE/phy_stub_UE.h
index 97935871619..69d3e2b9823 100644
--- a/openair2/PHY_INTERFACE/phy_stub_UE.h
+++ b/openair2/PHY_INTERFACE/phy_stub_UE.h
@@ -71,16 +71,32 @@ void fill_uci_harq_indication_UE_MAC(int Mod_id, int frame, int subframe, UL_IND
 			      /*uint8_t tdd_mapping_mode,
 			      uint16_t tdd_multiplexing_mask*/);
 
-int ul_config_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req);
+int ul_config_req_UE_MAC(nfapi_ul_config_request_t* req);
 
 void handle_nfapi_ul_pdu_UE_MAC(module_id_t Mod_id,
                          nfapi_ul_config_request_pdu_t *ul_config_pdu,
                          uint16_t frame,uint8_t subframe,uint8_t srs_present);
 
-int tx_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_tx_request_t* req);
+int dl_config_req_UE_MAC(nfapi_dl_config_request_t* req);
 
+int tx_req_UE_MAC(nfapi_tx_request_t* req);
 
-int hi_dci0_req_UE_MAC(nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* req);
+
+int hi_dci0_req_UE_MAC(nfapi_hi_dci0_request_t* req);
+
+// The following set of memcpy functions should be getting called as callback functions from
+// pnf_p7_subframe_ind.
+
+void memcpy_dl_config_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_dl_config_request_t* req);
+
+
+void memcpy_ul_config_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_ul_config_request_t* req);
+
+
+void memcpy_tx_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_tx_request_t* req);
+
+
+void memcpy_hi_dci0_req (nfapi_pnf_p7_config_t* pnf_p7, nfapi_hi_dci0_request_t* req);
 
 
 
diff --git a/targets/RT/USER/lte-ue.c b/targets/RT/USER/lte-ue.c
index 24276eabde0..56a364cfa0a 100644
--- a/targets/RT/USER/lte-ue.c
+++ b/targets/RT/USER/lte-ue.c
@@ -37,6 +37,7 @@
 #include "LAYER2/MAC/defs.h"
 #include "RRC/LITE/extern.h"
 #endif
+#include "PHY_INTERFACE/phy_stub_UE.h"
 #include "PHY_INTERFACE/extern.h"
 
 #undef MALLOC //there are two conflicting definitions, so we better make sure we don't use it at all
@@ -46,6 +47,8 @@
 #include "SCHED/extern.h"
 #include "LAYER2/MAC/extern.h"
 #include "LAYER2/MAC/proto.h"
+//#include "openair2/PHY_INTERFACE/phy_stub_UE.h"
+
 
 #include "UTIL/LOG/log_extern.h"
 #include "UTIL/OTG/otg_tx.h"
@@ -71,6 +74,7 @@ typedef enum {
 void init_UE_threads(int);
 void *UE_thread(void *arg);
 void init_UE(int nb_inst,int,int);
+//extern int tx_req_UE_MAC1();
 
 int32_t **rxdata;
 int32_t **txdata;
@@ -560,6 +564,7 @@ static void *UE_thread_synch(void *arg)
  */
 
 static void *UE_thread_rxn_txnp4(void *arg) {
+	module_id_t Mod_id = 0;
     static __thread int UE_thread_rxtx_retval;
     struct rx_tx_thread_data *rtd = arg;
     UE_rxtx_proc_t *proc = rtd->proc;
@@ -633,8 +638,18 @@ static void *UE_thread_rxn_txnp4(void *arg) {
 #ifdef UE_SLOT_PARALLELISATION
             phy_procedures_slot_parallelization_UE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL );
 #else
-			// Panos: Substitute with call to handle_nfapi_UE_Rx(Sched_Resp).
-            phy_procedures_UE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL );
+			// Panos: Substitute call to phy_procedures Rx with call to phy_stub functions in order to trigger
+            // UE Rx procedures directly at the MAC layer, based on the received nfapi requests from the vnf (eNB).
+            // Hardcode Mod_id for now. Will be changed later.
+
+            if(UE_mac_inst[Mod_id].tx_req)
+            	tx_req_UE_MAC(UE_mac_inst[Mod_id].tx_req);
+            if(UE_mac_inst[Mod_id].dl_config_req)
+            	dl_config_req_UE_MAC(UE_mac_inst[Mod_id].dl_config_req);
+            if(UE_mac_inst[Mod_id].hi_dci0_req)
+            	hi_dci0_req_UE_MAC(UE_mac_inst[Mod_id].hi_dci0_req);
+
+            //phy_procedures_UE_RX( UE, proc, 0, 0, 1, UE->mode, no_relay, NULL );
 #endif
         }
 
@@ -680,8 +695,14 @@ static void *UE_thread_rxn_txnp4(void *arg) {
         if ((subframe_select( &UE->frame_parms, proc->subframe_tx) == SF_UL) ||
 	    (UE->frame_parms.frame_type == FDD) )
             if (UE->mode != loop_through_memory){
-            	// Panos: Substitute with call to generate_nfapi_UL_indications and then send_nfapi_UL_indications()
-            	phy_procedures_UE_TX(UE,proc,0,0,UE->mode,no_relay);
+            	// Panos: Substitute call to phy_procedures Tx with call to phy_stub functions in order to trigger
+                // UE Tx procedures directly at the MAC layer, based on the received ul_config requests from the vnf (eNB).
+            	// Generate UL_indications which corresponf to UL traffic.
+            	if(UE_mac_inst[Mod_id].ul_config_req){
+            		ul_config_req_UE_MAC(UE_mac_inst[Mod_id].ul_config_req);
+            		UL_indication(UL_INFO);
+            	}
+            	//phy_procedures_UE_TX(UE,proc,0,0,UE->mode,no_relay);
             }
 
 
-- 
GitLab