Merge "[ODUHIGH-343]: PUCCH resource allocation (check for SR PRBs, if unavailable...
[o-du/l2.git] / src / du_app / du_msg_hdl.c
index 3887cc8..198653a 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 
 
@@ -63,6 +62,7 @@ uint8_t egtpHdlDatInd(EgtpMsg egtpMsg);
 uint8_t BuildAndSendDUConfigUpdate();
 uint16_t getTransId();
 uint8_t cmPkLrgSchCfgReq(Pst * pst,RgMngmt * cfg);
+uint8_t sendCellDeleteReqToMac(uint16_t cellId);
 
 packMacCellCfgReq packMacCellCfgOpts[] =
 {
@@ -330,45 +330,46 @@ uint8_t duBuildRlcUsapCfg(uint8_t elemId, Ent ent, Inst inst)
 uint8_t duProcCfgComplete()
 {
    uint8_t         ret = ROK;
-   static uint16_t cellId = 0;
+   uint16_t        cellId = 0;
    uint16_t        idx;
    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 = cell->cellId;
+         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;
+         cell->gnbDuUeF1apIdGenerator = 0;
+         duCb.cfgCellLst[duCb.numCfgCells] = cell;
+         duCb.numCfgCells++;
       }
    }
    if(ret != RFAILED)
@@ -1070,9 +1071,7 @@ uint8_t duHdlEgtpCfgComplete(CmStatus cfm)
    if(cfm.status == LCM_PRIM_OK)
    {
       DU_LOG("\nDEBUG   -->  DU_APP : EGTP configuraton complete");
-#ifdef EGTP_TEST
       duSendEgtpSrvOpenReq();
-#endif
    }
    else
    {
@@ -1136,9 +1135,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 +1164,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;
 }
 
 /*******************************************************************
@@ -1243,7 +1248,7 @@ uint8_t duSendEgtpDatInd(Buffer *mBuf)
    egtpMsg.msgHdr.extHdr.pdcpNmb.pres = FALSE;
    egtpMsg.msgHdr.teId = 1;
    egtpMsg.msg = mBuf;
-
+   
    egtpHdlDatInd(egtpMsg);
 
    return ROK;
@@ -1469,13 +1474,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 +1558,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;
+      }
+      memset(oduCellId, 0, sizeof(OduCellId));
+      oduCellId->cellId = duCb.actvCellLst[cellIdx]->cellId;
 
-   /* Fill Pst */
-   FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP);
+      /* 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;
 }
 
 /*******************************************************************
@@ -1603,14 +1620,21 @@ uint8_t duHandleStopInd(Pst *pst, OduCellId *cellId)
    if(duGetCellCb(cellId->cellId, &cellCb) != ROK)
       return RFAILED;
 
-   if((cellCb->cellStatus == ACTIVATED))
+   if((cellCb->cellStatus == ACTIVATED) || (cellCb->cellStatus == DELETION_IN_PROGRESS))
    {
       DU_LOG("\nINFO   -->  DU APP : 5G-NR Cell %d is DOWN", cellId->cellId);
-      cellCb->cellStatus = DELETION_IN_PROGRESS;
+      if(sendCellDeleteReqToMac(cellId->cellId) == RFAILED)
+      {
+         DU_LOG("\nERROR  -->  DU APP : duHandleStopInd(): Failed to send Cell delete req to MAC for\
+               cellId[%d]", cellId->cellId);
+         return RFAILED;
+      }
+
 
 #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 +1760,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 +1773,18 @@ 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]->ueIdx == ulUserData->ueIdx) && \
+         (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)
    {