FAPI Slot Indication Changes
[o-du/l2.git] / src / du_app / du_msg_hdl.c
index 7a35a68..5f81917 100644 (file)
@@ -16,8 +16,9 @@
 ################################################################################
 *******************************************************************************/
 
-/* This file contains message handling functionality for DU cell management */
+/* This file contains message handling functionality for DU APP */
 
+#include "du_mgr.h"
 #include "du_sctp.h"
 #include "du_f1ap_msg_hdl.h"
 #include "lsctp.h"
@@ -31,12 +32,32 @@ U8 numRlcMacSaps = 0;
 U8 macCfg = 0;
 U8 macCfgInst = 0;
 
-extern DuCfgParams duCfgParam;;
-
+extern DuCfgParams duCfgParam;
 extern S16 cmPkLkwCfgReq(Pst *pst, KwMngmt *cfg);
 extern S16 cmPkLkwCntrlReq(Pst *pst, KwMngmt *cfg);
 extern S16 cmPkLrgCfgReq(Pst *pst, RgMngmt *cfg);
 
+packMacCellCfgReq packMacCellCfgOpts[] =
+{
+   packMacCellCfg, /* packing for loosely coupled */
+   MacHdlCellCfgReq, /* packing for tightly coupled */
+   packMacCellCfg, /* packing for light weight loosly coupled */
+};
+
+DuMacCellStartReq packMacCellStartReqOpts[] =
+{
+   packMacCellStartReq,   /* Loose coupling */
+   MacHdlCellStartReq,    /* TIght coupling */
+   packMacCellStartReq    /* Light weight-loose coupling */
+};
+
+DuMacCellStopReq packMacCellStopReqOpts[] =
+{
+   packMacCellStopReq,   /* Loose coupling */
+   MacHdlCellStopReq,    /* TIght coupling */
+   packMacCellStopReq    /* Light weight-loose coupling */
+};
+
 /**************************************************************************
  * @brief Function to fill configs required by RLC
  *
@@ -284,7 +305,7 @@ S16 duProcCfgComplete()
    S16 ret = ROK;
    static U16 cellId = 0;
    U16 idx;
-   for(idx=0; idx< DEFAULT_CELLS; idx++) //TODO: the length of this loop must be determined
+   for(idx=0; idx< DEFAULT_CELLS; idx++)
    {
       DuCellCb *cell;
       DU_ALLOC(cell, sizeof(DuCellCb))
@@ -295,25 +316,34 @@ S16 duProcCfgComplete()
       }
       else
       {
-         U16 nci;
-
+         U32 nci;
+         U8 idx;
+         
+         memset(cell, 0, sizeof(DuCellCb));
          cell->cellId = cellId++;
-         memcpy((void*)&cell->cellInfo, (void*)&duCfgParam.cellCfg[idx],\
-               sizeof(CellCfgParams));
-         cell->cellStatus = OOS;
-         nci = cell->cellInfo.nrEcgi.cellId;
-         ret = cmHashListInsert(&(duCb.cellLst), (PTR)(cell), 
-                     (U8 *)&(nci), (U16) sizeof(nci));
-
-         if(ret != ROK)
+         cell->cellInfo.nrEcgi.plmn.mcc[0] = PLMN_MCC0;
+         cell->cellInfo.nrEcgi.plmn.mcc[1] = PLMN_MCC1;
+         cell->cellInfo.nrEcgi.plmn.mcc[2] = PLMN_MCC2;
+         cell->cellInfo.nrEcgi.plmn.mnc[0] = PLMN_MNC0;
+         cell->cellInfo.nrEcgi.plmn.mnc[1] = PLMN_MNC1;
+         cell->cellInfo.nrEcgi.plmn.mnc[2] = PLMN_MNC2;
+         cell->cellInfo.nrEcgi.cellId = NR_CELL_ID;
+         cell->cellInfo.nrPci = NR_PCI; 
+         cell->cellInfo.fiveGsTac = DU_TAC;
+         for(idx=0; idx<MAX_PLMN; idx++)
          {
-            DU_LOG("\nDU_APP : HashListInsert into cellLst failed for [%d]", nci);
-            break;
-         }
-         else
-         {
-            DU_LOG("\nDU_APP : HashListInsert into cellLst successful for [%d]", nci);
-         }
+            cell->cellInfo.plmn[idx].mcc[0] = PLMN_MCC0;
+            cell->cellInfo.plmn[idx].mcc[1] = PLMN_MCC1;
+            cell->cellInfo.plmn[idx].mcc[2] = PLMN_MCC2;
+            cell->cellInfo.plmn[idx].mnc[0] = PLMN_MNC0;
+            cell->cellInfo.plmn[idx].mnc[1] = PLMN_MNC1;
+            cell->cellInfo.plmn[idx].mnc[2] = PLMN_MNC2;
+                       }
+         cell->cellInfo.maxUe = duCfgParam.maxUe;
+         cell->cellStatus = CELL_OUT_OF_SERVICE;
+         nci = (U16)cell->cellInfo.nrEcgi.cellId;
+         
+         duCb.cfgCellLst[nci-1] = cell;
       }
    }
    if(ret != RFAILED)
@@ -884,42 +914,6 @@ S16 duBindUnbindRlcToMacSap(U8 inst, U8 action)
 
    return ROK;
 }
-/*******************************************************************
- *
- * @brief  Function to start SCTP
- *
- * @details
- *
- *    Function : duSctpStartReq
- *
- *    Functionality:
- *       Function to start SCTP
- *
- * @params[in] 
- * @return ROK     - success
- *         RFAILED - failure
- *
- * ****************************************************************/
-S16 duSctpStartReq()
-{
-   Pst pst;
-
-   cmMemset((U8 *)&(pst), 0, sizeof(Pst));
-   pst.srcEnt = (Ent)ENTDUAPP;
-   pst.srcInst = (Inst)DU_INST;
-   pst.srcProcId = DU_PROC;
-   pst.dstEnt = (Ent)ENTSCTP;
-   pst.dstInst = (Inst)SCTP_INST;
-   pst.dstProcId = pst.srcProcId;
-   pst.event = EVTSCTPSTRT;
-   pst.selector = DU_SELECTOR_LC;
-   pst.pool= DU_POOL;
-
-   cmPkSctpAssocReq(&pst, duCfgParam.sctpParams);
-
-   RETVALUE(ROK);
-}
-
 /*******************************************************************
  *
  * @brief Handles SCTP notifications
@@ -941,34 +935,26 @@ S16 duSctpStartReq()
 
 S16 duSctpNtfyHdl(Buffer *mBuf, CmInetSctpNotification *ntfy)
 {
-   switch(ntfy->header.nType)
+   if(f1Params.assocId == ntfy->u.assocChange.assocId)
    {
-      case CM_INET_SCTP_ASSOC_CHANGE:
-         switch(ntfy->u.assocChange.state)
-         {
-            case CM_INET_SCTP_COMM_UP:
-               {
-                  DU_LOG("\nDU_APP : SCTP communication UP");
-                  //Setup F1-C
-                  if(!duCb.f1Status)
-                  {
-                     /* Build and send F1 Setup response */
-                     if(BuildAndSendF1SetupReq() != ROK)
-                     {
-                        RETVALUE(RFAILED);
-                     }
-                  }
-                  else
-                  {
-                     //Only SCTP is down, when SCTP comes up again, no need to
-                     //start from setting up F1 link
-                  }
-                  break;
-               }
-         }
-         break;
+      if(BuildAndSendF1SetupReq() != ROK)
+      {
+         return RFAILED;
+      }
    }
-   RETVALUE(ROK);
+   else if(ricParams.assocId == ntfy->u.assocChange.assocId)
+   {
+      if(BuildAndSendE2SetupReq() != ROK)
+      {
+         return RFAILED;
+      }
+   }
+   else
+       {
+      DU_LOG("\nDU_APP : Invalid assocId %d received", ntfy->u.assocChange.assocId);
+               return RFAILED;
+       }
+   return ROK;
 }
 
 /*******************************************************************
@@ -1032,7 +1018,7 @@ S16 duBuildEgtpCfgReq()
     cmMemcpy((U8 *)&egtpCfg, (U8 *)&duCfgParam.egtpParams, (PTR)sizeof(EgtpConfig));
     
     duFillEgtpPst(&pst, EVTCFGREQ);
-    cmPkEgtpCfgReq(&pst, egtpCfg);
+    packEgtpCfgReq(&pst, egtpCfg);
  
     RETVALUE(ROK);
 }
@@ -1097,7 +1083,7 @@ S16 duSendEgtpSrvOpenReq()
    DU_LOG("\nDU_APP : Sending EGTP server open request");
 
    duFillEgtpPst(&pst, EVTSRVOPENREQ);
-   cmPkEgtpSrvOpenReq(&pst);
+   packEgtpSrvOpenReq(&pst);
 
    RETVALUE(ROK);
 }
@@ -1170,7 +1156,7 @@ S16 duSendEgtpTnlMgmtReq(U8 action, U32 lclTeid, U32 remTeid)
    DU_LOG("\nDU_APP : Sending EGTP tunnel management request");
     
    duFillEgtpPst(&pst, EVTTNLMGMTREQ);
-   cmPkEgtpTnlMgmtReq(&pst, tnlEvt);
+   packEgtpTnlMgmtReq(&pst, tnlEvt);
     
    RETVALUE(ROK);
 }
@@ -1200,10 +1186,9 @@ S16 duHdlEgtpTnlMgmtCfm(EgtpTnlEvt tnlEvtCfm)
       DU_LOG("\nDU_APP : Tunnel management confirm OK");
 
 #ifdef EGTP_TEST
-      duSendEgtpDatInd();
-      
-      /* For testing purpose. TTI thread should actually be in L1 */
-      duStartTtiThread();
+      duSendUeCreateReqToRlc();
+
+      duSendEgtpTestData();
 #endif      
    }
    else
@@ -1215,38 +1200,52 @@ S16 duHdlEgtpTnlMgmtCfm(EgtpTnlEvt tnlEvtCfm)
    RETVALUE(ret);
 }
 
+S16 duSendEgtpDatInd(Buffer *mBuf)
+{
+   EgtpMsg  egtpMsg;
+
+   /* Fill EGTP header */
+   egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
+   egtpMsg.msgHdr.nPdu.pres = FALSE;
+   egtpMsg.msgHdr.seqNum.pres = FALSE;
+   egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
+   egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
+   egtpMsg.msgHdr.teId = 1;
+   egtpMsg.msg = mBuf;
+   
+   egtpHdlDatInd(egtpMsg);
+
+   return ROK;
+
+}
+
 #ifdef EGTP_TEST
 /*******************************************************************
  *
- * @brief Simulate RLC to EGTP data indication 
+ * @brief Simulate UL Data for intial test
  *
  * @details
  *
- *    Function : duSendEgtpDatInd
+ *    Function : duSendEgtpTestData
  *
  *    Functionality:
- *      Simulate RLC to EGTP data indication
+ *      Simulate UL data for initial test
  *
  * @params[in] 
  * @return ROK     - success
  *         RFAILED - failure
  *
  * ****************************************************************/
-S16 duSendEgtpDatInd()
+S16 duSendEgtpTestData()
 {
    char data[30] = "This is EGTP data from DU";
    int datSize = 30;
 
    Buffer   *mBuf;
-   EgtpMsg  egtpMsg;
 
    if(SGetMsg(DU_APP_MEM_REGION, DU_POOL, &mBuf) == ROK)
    {
-      if(SAddPstMsgMult((Data *)data, datSize, mBuf) == ROK)
-      {
-         SPrntMsg(mBuf, 0,0);
-      }
-      else
+      if(SAddPstMsgMult((Data *)data, datSize, mBuf) != ROK)
       {
          DU_LOG("\nDU_APP : SAddPstMsgMult failed");
          SPutMsg(mBuf);
@@ -1327,19 +1326,8 @@ S16 duSendEgtpDatInd()
 
    /* this function automatically reverses revPkArray */
    ret = SAddPreMsgMult(revPkArray, (MsgLen)cnt, mBuf);
-
-
-   egtpMsg.msgHdr.msgType = EGTPU_MSG_GPDU;
-   egtpMsg.msgHdr.nPdu.pres = FALSE;
-   egtpMsg.msgHdr.seqNum.pres = FALSE;
-   egtpMsg.msgHdr.extHdr.udpPort.pres = FALSE;
-   egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
-   egtpMsg.msgHdr.teId = 1;
-   egtpMsg.msg = mBuf;
-
-   SPrntMsg(mBuf, 0, 0);
-
-   egtpHdlDatInd(egtpMsg);
+    
+   duSendEgtpDatInd(mBuf);
  
    RETVALUE(ROK);
 }
@@ -1423,6 +1411,49 @@ S16 duSendSchCfg()
    return ROK;
 }
 
+
+/**************************************************************************
+ * @brief Function to configure SCTP params and 
+ *  responsible for F1 and E2 interfaces
+ *
+ * @details
+ *
+ *      Function : duLayerConfigComplete
+ * 
+ *      Functionality:
+ *           Configures SCTP Params and responsible for handling
+ *           F1 and E2 interface.
+ *     
+ * @param[in]  void
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ***************************************************************************/
+S16 duLayerConfigComplete()
+{
+   S16 ret = ROK;
+
+   DU_LOG("\nDU_APP : Configuring all Layer is complete");
+
+   if((ret = duSctpCfgReq(duCfgParam.sctpParams)) != ROK)
+   {
+      DU_LOG("\nDU_APP : Failed configuring Sctp Params");
+      ret = RFAILED;
+   }
+   if((ret = duSctpAssocReq(F1_INTERFACE)) != ROK)
+   {
+      DU_LOG("\nDU_APP : Failed to send AssocReq F1");
+      ret = RFAILED;
+   }
+   if((ret = duSctpAssocReq(E2_INTERFACE)) != ROK)
+   {
+      DU_LOG("\nDU_APP : Failed to send AssocReq E2");
+      ret = RFAILED;
+   }
+
+   RETVALUE(ret); 
+} 
+
 /**************************************************************************
  * @brief Function to handle  SCH Config Confirm from MAC
  *
@@ -1454,38 +1485,273 @@ S16 duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm)
             break;
       }
    }
-   duSctpStartReq();
-
+   duLayerConfigComplete();
    duBuildEgtpCfgReq();
    return ROK;
 }
 
 /*******************************************************************
  *
- * @brief Handles TTI indication 
+ * @brief Sends Slot indication to EGTP
  *
  * @details
  *
- *    Function : duSendEgtpTTIInd
+ *    Function : duSendEgtpSlotInd
  *
  *    Functionality:
- *     Handles TTI indication received from PHY
+ *     Sends Slot indication to EGTP
  *
  * @params[in] 
  * @return ROK     - success
  *         RFAILED - failure
  *
  * ****************************************************************/
-S16 duSendEgtpTTIInd()
+S16 duSendEgtpSlotInd()
 {
    Pst pst;
 
-   duFillEgtpPst(&pst, EVTTTIIND);
-   cmPkEgtpTTIInd(&pst);
+   duFillEgtpPst(&pst, EVTSLOTIND);
+   packEgtpSlotInd(&pst);
    
    RETVALUE(ROK);
    
 }
+
+/**************************************************************************
+ * @brief Function to fill and send MacCellconfig
+ *
+ * @details
+ *
+ *      Function : duBuildAndSendMacCellCfg 
+ * 
+ *      Functionality:
+ *           Initiates MAC Configs towards MAC
+ *     
+ * @param[in] void
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ***************************************************************************/
+S16 duBuildAndSendMacCellCfg()
+{
+   Pst pst;
+   DU_SET_ZERO(&pst, sizeof(Pst));
+   MacCellCfg *duMacCellCfg = NULLP;
+
+   DU_ALLOC(duMacCellCfg, sizeof(MacCellCfg));
+   if(duMacCellCfg == NULLP)
+   {
+      return RFAILED;
+   }
+
+   /* store the address in the duCb so that we can free on confirm msg */
+   duCb.duMacCellCfg = duMacCellCfg;
+
+   /* copy the mac config structure from duCfgParams */
+   memcpy(duMacCellCfg,&duCfgParam.macCellCfg,sizeof(MacCellCfg));
+
+   duMacCellCfg->transId = getTransId(); /* transaction ID */
+   
+   /* Fill Pst */
+   pst.selector  = DU_SELECTOR_LWLC;
+   pst.srcEnt    = ENTDUAPP;
+   pst.dstEnt    = ENTRG;
+   pst.dstInst   = 0;
+   pst.srcInst   = 0;
+   pst.dstProcId = DU_PROC;
+   pst.srcProcId = DU_PROC;
+   pst.region = duCb.init.region;
+   pst.event = EVENT_MAC_CELL_CONFIG_REQ;
+
+   /* Send MAC cell config to MAC */
+   return (*packMacCellCfgOpts[pst.selector])(&pst, duMacCellCfg);
+}
+
+/**************************************************************************
+ * @brief Function to Handle MAC cell config confirm
+ *
+ * @details
+ *
+ *      Function : duHandleMacCellCfgCfm 
+ * 
+ *      Functionality:
+ *           Initiates general Configs towards MAC
+ *     
+ * @param[in] void
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ ***************************************************************************/
+uint16_t duHandleMacCellCfgCfm(MacCellCfgCfm *macCellCfgCfm)
+{
+   S16 ret = ROK;
+
+   if(macCellCfgCfm->rsp == ROK)  
+       {
+               if(macCellCfgCfm->transId == duCb.duMacCellCfg->transId)
+               {
+                       /* free the memory allocated during sending macCellCfg request */
+                       DU_FREE(duCb.duMacCellCfg->sib1Cfg.sib1Pdu, duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
+                       DU_FREE(duCb.duMacCellCfg,sizeof(MacCellCfg));
+                       duCb.duMacCellCfg = NULLP;
+
+                       /* Build and send GNB-DU config update */
+                       ret = BuildAndSendDUConfigUpdate();
+
+         /* TODO: Trigger cell start req once cell up slot ind is received*/
+                       /* Build and Send Cell Start Req to MAC */
+                       //ret = duBuildAndSendMacCellStartReq();
+
+               }
+               else
+               {
+                       /* transaction ID missmatch */
+                       DU_LOG("\n transaction ID mismatch in macCellCfg");
+                       ret = RFAILED;
+               }
+       }
+       else
+       {
+               DU_LOG("\nMac cell cfg failed");
+               ret = RFAILED;
+       }
+   return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Handles slot indication from MAC
+ *
+ * @details
+ *
+ *    Function : duHandleSlotInd
+ *
+ *    Functionality:
+ *      Handles slot indication from MAC
+ *
+ * @params[in] Post structure pointer
+ *             Slot Info pointer
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint16_t duHandleSlotInd(Pst *pst, SlotInfo *slotInfo)
+{
+   
+   DU_LOG("\nDU APP : Slot Indication received");
+
+   /* TODO : Slot Indication to be moved out of EGTP_TEST when
+    * data path is established */
+#ifdef EGTP_TEST
+   duSendEgtpSlotInd();    
+#endif
+   DU_FREE_MEM(pst->region, pst->pool, slotInfo, sizeof(SlotInfo));
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and sends cell start request to MAC
+ *
+ * @details
+ *
+ *    Function : duBuildAndSendMacCellStartReq
+ *
+ *    Functionality:
+ *       Builds and sends cell start request to MAC
+ *
+ * @params[in] 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint16_t duBuildAndSendMacCellStartReq()
+{
+   Pst pst;
+   MacCellStartInfo *cellStartInfo = NULL;
+
+   DU_LOG("\nDU APP : Building and Sending cell start request to MAC");
+
+   /* Send Cell Start Request to MAC */
+   DU_ALLOC(cellStartInfo, sizeof(MacCellStartInfo));
+   if(!cellStartInfo)
+   {
+      DU_LOG("\nDU APP : Memory alloc failed while building cell start request");
+      return RFAILED;
+   }
+
+   for(uint8_t id = 0; id < DU_MAX_CELLS; id++) 
+   {
+      if(duCb.actvCellLst[id])
+      {
+         cellStartInfo->cellId = duCb.actvCellLst[id]->cellInfo.nrEcgi.cellId;
+         /* Fill Pst */
+         pst.selector  = DU_MAC_LWLC;
+         pst.srcEnt    = ENTDUAPP;
+         pst.dstEnt    = ENTRG;
+         pst.dstInst   = 0;
+         pst.srcInst   = 0;
+         pst.dstProcId = DU_PROC;
+         pst.srcProcId = DU_PROC;
+         pst.region = DU_APP_MEM_REGION;
+         pst.pool = DU_POOL;
+         pst.event = EVENT_MAC_CELL_START_REQ;
+         return (*packMacCellStartReqOpts[pst.selector])(&pst, cellStartInfo);
+      }
+   }
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Builds and sends cell stop request to MAC
+ *
+ * @details
+ *
+ *    Function : duBuildAndSendMacCellStopReq 
+ *
+ *    Functionality:
+ *       Builds and sends cell stop request to MAC
+ *
+ * @params[in] 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+S16 duBuildAndSendMacCellStopReq()
+{
+   Pst pst;
+   MacCellStopInfo *cellStopInfo = NULL;
+   DU_LOG("\nDU APP : Building and Sending cell stop request to MAC");
+
+   /* Send Cell Stop Request to MAC */
+   DU_ALLOC(cellStopInfo, sizeof(MacCellStopInfo));
+   if(!cellStopInfo)
+   {
+      DU_LOG("\nDU APP : Memory alloc failed while building cell stop request");
+      return RFAILED;
+   }
+   cellStopInfo->cellId = duCb.actvCellLst[0]->cellId;
+   /* Fill Pst */
+   pst.selector  = DU_MAC_LWLC;
+   pst.srcEnt    = ENTDUAPP;
+   pst.dstEnt    = ENTRG;
+   pst.dstInst   = 0;
+   pst.srcInst   = 0;
+   pst.dstProcId = DU_PROC;
+   pst.srcProcId = DU_PROC;
+   pst.region = DU_APP_MEM_REGION;
+   pst.pool = DU_POOL;
+   pst.event = EVENT_MAC_CELL_STOP_REQ;
+   return (*packMacCellStopReqOpts[pst.selector])(&pst, cellStopInfo);
+}
+
+
 /**********************************************************************
   End of file
  **********************************************************************/