Using TAPA Task to generated PHY Stub's slot indication [Issue-Id: ODUHIGH-348]
[o-du/l2.git] / src / du_app / du_msg_hdl.c
index 3887cc8..85579c5 100644 (file)
 #include "du_ue_mgr.h"
 #include "lsctp.h"
 #include "legtp.h"
-#include "lphy_stub.h"
 #include "du_utils.h"
 #include "du_cell_mgr.h" 
 
 #ifdef O1_ENABLE
 
-#include "GlobalDefs.h"
 #include "AlarmInterface.h"
+#include "ConfigInterface.h"
 
 #endif 
 
@@ -335,40 +334,41 @@ uint8_t duProcCfgComplete()
    for(idx=0; idx< DEFAULT_CELLS; idx++)
    {
       DuCellCb *cell = NULLP;
-      DU_ALLOC(cell, sizeof(DuCellCb))
+      DU_ALLOC(cell, sizeof(DuCellCb));
       if(cell == NULLP)
       {
-        DU_LOG("\nERROR  -->  DU_APP : Memory Allocation failed in duProcCfgComplete");
-        ret = RFAILED;
+         DU_LOG("\nERROR  -->  DU_APP : Memory Allocation failed in duProcCfgComplete");
+         ret = RFAILED;
       }
       else
       {
-        uint8_t idx1=0; 
-        memset(cell, 0, sizeof(DuCellCb));
-        cell->cellId = ++cellId;
-        memset(&cell->cellInfo.nrEcgi.plmn, 0, sizeof(Plmn));
-        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.cellId = NR_CELL_ID;
-        cell->cellInfo.nrPci = NR_PCI; 
-        cell->cellInfo.fiveGsTac = DU_TAC;
-        memset(&cell->cellInfo.plmn[idx1], 0, sizeof(Plmn));
-        for(idx1=0; idx1<MAX_PLMN; idx1++)
-        {
-           cell->cellInfo.plmn[idx1].mcc[0] = PLMN_MCC0;
-           cell->cellInfo.plmn[idx1].mcc[1] = PLMN_MCC1;
-           cell->cellInfo.plmn[idx1].mcc[2] = PLMN_MCC2;
-           cell->cellInfo.plmn[idx1].mnc[0] = PLMN_MNC0;
-           cell->cellInfo.plmn[idx1].mnc[1] = PLMN_MNC1;
-        }
-        cell->cellInfo.maxUe = duCfgParam.maxUe;
-        cell->cellStatus = CELL_OUT_OF_SERVICE;
-
-        duCb.cfgCellLst[duCb.numCfgCells] = cell;
-        duCb.numCfgCells++;
+         uint8_t idx1=0; 
+         memset(cell, 0, sizeof(DuCellCb));
+         cell->cellId = ++cellId;
+         memset(&cell->cellInfo.nrEcgi.plmn, 0, sizeof(Plmn));
+         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.cellId = NR_CELL_ID;
+         cell->cellInfo.nrPci = NR_PCI; 
+         cell->cellInfo.fiveGsTac = DU_TAC;
+         memset(&cell->cellInfo.plmn[idx1], 0, sizeof(Plmn));
+         for(idx1=0; idx1<MAX_PLMN; idx1++)
+         {
+            cell->cellInfo.plmn[idx1].mcc[0] = PLMN_MCC0;
+            cell->cellInfo.plmn[idx1].mcc[1] = PLMN_MCC1;
+            cell->cellInfo.plmn[idx1].mcc[2] = PLMN_MCC2;
+            cell->cellInfo.plmn[idx1].mnc[0] = PLMN_MNC0;
+            cell->cellInfo.plmn[idx1].mnc[1] = PLMN_MNC1;
+         }
+         cell->cellInfo.maxUe = duCfgParam.maxUe;
+         cell->cellStatus = CELL_OUT_OF_SERVICE;
+         gCellStatus = CELL_DOWN;
+
+         duCb.cfgCellLst[duCb.numCfgCells] = cell;
+         duCb.numCfgCells++;
       }
    }
    if(ret != RFAILED)
@@ -1136,9 +1136,6 @@ uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm)
    if(cfm.status == LCM_PRIM_OK)
    {
       DU_LOG("\nDEBUG   -->  DU_APP : EGTP server opened successfully");
-#ifdef EGTP_TEST
-      duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, EGTP_LCL_TEID, EGTP_REM_TEID);
-#endif
    }
    else
    {
@@ -1168,19 +1165,28 @@ uint8_t duHdlEgtpSrvOpenComplete(CmStatus cfm)
  *
  * ****************************************************************/
 
-uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t lclTeid, uint32_t remTeid)
+uint8_t duSendEgtpTnlMgmtReq(uint8_t action, uint32_t teIdTobeMod, GtpTnlCfg *ueCbTnlCfg)
 {
+   uint8_t ret =ROK;
    Pst pst;
    EgtpTnlEvt tnlEvt;
 
-   tnlEvt.action = action;
-   tnlEvt.lclTeid = lclTeid;
-   tnlEvt.remTeid = remTeid;
+   DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP tunnel management request for teId [%d]", ueCbTnlCfg->teId);
 
-   DU_LOG("\nDEBUG   -->  DU_APP : Sending EGTP tunnel management request");
+   /* ADD/MOD/DEL per tunnel */
+   tnlEvt.action = action;
+   tnlEvt.remTeid = ueCbTnlCfg->teId;
+   if(action != EGTP_TNL_MGMT_ADD)
+   {
+      tnlEvt.lclTeid = teIdTobeMod;
+   }
+   else
+   {
+      tnlEvt.lclTeid = ueCbTnlCfg->teId;
+   }
    duFillEgtpPst(&pst, EVTTNLMGMTREQ);
-   egtpTnlMgmtReq(&pst, tnlEvt);
-   return ROK;
+   ret = egtpTnlMgmtReq(&pst, tnlEvt);
+   return ret;
 }
 
 /*******************************************************************
@@ -1469,13 +1475,13 @@ uint8_t  duHandleMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
    {
       if(macCellCfgCfm->cellId == duCb.actvCellLst[actvCellIdx]->cellId)
       {
-        duCb.actvCellLst[actvCellIdx]->duMacCellCfg = NULLP;
+         duCb.actvCellLst[actvCellIdx]->duMacCellCfg = NULLP;
       }
    }
    if(macCellCfgCfm->rsp == ROK)
    {
       /* Build and send GNB-DU config update */
-      ret = BuildAndSendDUConfigUpdate();
+      ret = BuildAndSendDUConfigUpdate(SERV_CELL_TO_MODIFY);
 
       /* Build and Send Cell Start Req to MAC */
       ret = duBuildAndSendMacCellStart();
@@ -1553,26 +1559,38 @@ uint8_t duBuildAndSendMacCellStart()
  *         RFAILED - failure
  *
  * ****************************************************************/
-uint8_t duBuildAndSendMacCellStop()
+uint8_t duBuildAndSendMacCellStop(uint16_t cellId)
 {
    Pst pst;
-   OduCellId *cellId = NULL;
-
+   uint16_t cellIdx=0;
+   OduCellId *oduCellId = NULL;
+   
    DU_LOG("\nINFO   -->  DU APP : Building and Sending cell stop request to MAC");
 
-   /* Send Cell Stop Request to MAC */
-   DU_ALLOC_SHRABL_BUF(cellId, sizeof(OduCellId));
-   if(!cellId)
+   GET_CELL_IDX(cellId, cellIdx);
+   if(duCb.actvCellLst[cellIdx] != NULLP)
    {
-      DU_LOG("\nERROR  -->  DU APP : Memory alloc failed while building cell stop request");
-      return RFAILED;
-   }
-   cellId->cellId = duCb.actvCellLst[0]->cellId;
+      /* Send Cell Stop Request to MAC */
+      DU_ALLOC_SHRABL_BUF(oduCellId, sizeof(OduCellId));
+      if(!oduCellId)
+      {
+         DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop():  Memory allocation failed ");
+         return RFAILED;
+      }
 
-   /* Fill Pst */
-   FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP);
+      oduCellId->cellId = duCb.actvCellLst[cellIdx]->cellId;
+
+      /* Fill Pst */
+      FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP);
 
-   return (*packMacCellStopOpts[pst.selector])(&pst, cellId);
+      return (*packMacCellStopOpts[pst.selector])(&pst, oduCellId);
+   }
+   else
+   {
+      DU_LOG("\nERROR  -->  DU APP : duBuildAndSendMacCellStop(): cellId[%d] doesnot exists", cellId);
+      return RFAILED;
+   }
+   return ROK;
 }
 
 /*******************************************************************
@@ -1611,6 +1629,7 @@ uint8_t duHandleStopInd(Pst *pst, OduCellId *cellId)
 #ifdef O1_ENABLE
       DU_LOG("\nINFO   -->  DU APP : Raise cell down alarm for cell id=%d", cellId->cellId);
       raiseCellAlrm(CELL_DOWN_ALARM_ID, cellId->cellId);
+      setCellOpState(cellId->cellId, DISABLED, INACTIVE);
 #endif
    }
 
@@ -1736,16 +1755,9 @@ uint8_t DuProcRlcRrcDeliveryReport(Pst *pst, RrcDeliveryReport *rrcDeliveryRepor
 uint8_t DuProcRlcUlUserDataTrans(Pst *pst, RlcUlUserDatInfo *ulUserData)
 {
    uint8_t  rbIdx;
-   DuCellCb *cellCb;
-   DuUeCb   ueCb;
    EgtpMsg  egtpMsg;
    Buffer   *mBuf;
 
-   if(duGetCellCb(ulUserData->cellId, &cellCb) != ROK)
-      return RFAILED;
-
-   ueCb = cellCb->ueCb[ulUserData->ueIdx -1];
-
    DU_LOG("\nDEBUG  -->  DU APP : Received UL user data");
 
    /* Fill EGTP header */
@@ -1756,18 +1768,17 @@ uint8_t DuProcRlcUlUserDataTrans(Pst *pst, RlcUlUserDatInfo *ulUserData)
    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
 
    /* Fetch EGTP tunnel info */
-   /* TODO : keep the "#if 0" code block and test once DL User data changes are submitted */
-#if 0
-   for(rbIdx = 0; rbIdx < MAX_NUM_DRB; rbIdx++)
+   for(rbIdx = 0; rbIdx < duCb.numDrb; rbIdx++)
    {
-      if(ueCb.ulTnlCfg[rbIx]->drbId == ulUserData->rbId)
+      if((duCb.upTnlCfg[rbIdx] != NULLP) && (duCb.upTnlCfg[rbIdx]->drbId == ulUserData->rbId))
       {
-         egtpMsg.msgHdr.teId = ueCb.ulTnlCfg[rbIx]->tnlCfg.teId;
+        if(duCb.upTnlCfg[rbIdx]->tnlCfg1)
+        {
+            egtpMsg.msgHdr.teId = duCb.upTnlCfg[rbIdx]->tnlCfg1->teId; /*As we are supporting only 1 tunnel per DRB*/
+           break;
+        }
       }
    }
-#else
-   egtpMsg.msgHdr.teId = 1;
-#endif
 
    if (ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &mBuf) != ROK)
    {