Implementation of ue context modification response JIRA ID = ODUHIGH-298
[o-du/l2.git] / src / du_app / du_ue_mgr.c
index 5fb75f9..748f71a 100644 (file)
 #include "du_f1ap_msg_hdl.h"
 #include "du_ue_mgr.h"
 
-#ifdef EGTP_TEST
-uint32_t sduId = 0;
-#endif
-
 DuMacDlCcchInd packMacDlCcchIndOpts[] =
 {
-   packMacDlCcchInd,   /* Loose coupling */
-   MacProcDlCcchInd,    /* TIght coupling */
-   packMacDlCcchInd    /* Light weight-loose coupling */
+   packMacDlCcchInd,           /* Loose coupling */
+   MacProcDlCcchInd,           /* TIght coupling */
+   packMacDlCcchInd            /* Light weight-loose coupling */
 };
 
 DuMacUeCreateReq packMacUeCreateReqOpts[] =
 {
    packDuMacUeCreateReq,       /* Loose coupling */
-   MacProcUeCreateReq,          /* TIght coupling */
-   packDuMacUeCreateReq       /* Light weight-loose coupling */
+   MacProcUeCreateReq,         /* TIght coupling */
+   packDuMacUeCreateReq        /* Light weight-loose coupling */
 };
 
 DuRlcUeCreateReq packRlcUeCreateReqOpts[] =
 {
    packDuRlcUeCreateReq,       /* Loose coupling */
-   RlcProcUeCreateReq,          /* TIght coupling */
-   packDuRlcUeCreateReq       /* Light weight-loose coupling */
+   RlcProcUeCreateReq,         /* TIght coupling */
+   packDuRlcUeCreateReq        /* Light weight-loose coupling */
 };
 
 DuDlRrcMsgToRlcFunc duSendDlRrcMsgToRlcOpts[] =
 {
    packDlRrcMsgToRlc,          /* Loose coupling */ 
-   RlcProcDlRrcMsgTransfer,       /* Tight coupling */
+   RlcProcDlRrcMsgTransfer,    /* Tight coupling */
    packDlRrcMsgToRlc           /* Light weight-loose coupling */
 };
 
 DuRlcUeReconfigReq packRlcUeReconfigReqOpts[] =
 {
-   packDuRlcUeReconfigReq,       /* Loose coupling */
+   packDuRlcUeReconfigReq,     /* Loose coupling */
    RlcProcUeReconfigReq,       /* TIght coupling */
-   packDuRlcUeReconfigReq       /* Light weight-loose coupling */
+   packDuRlcUeReconfigReq      /* Light weight-loose coupling */
 };
 
 DuMacUeReconfigReq packMacUeReconfigReqOpts[] =
 {
-   packDuMacUeReconfigReq,       /* Loose coupling */
+   packDuMacUeReconfigReq,     /* Loose coupling */
    MacProcUeReconfigReq,       /* TIght coupling */
-   packDuMacUeReconfigReq     /* Light weight-loose coupling */
+   packDuMacUeReconfigReq      /* Light weight-loose coupling */
+};
+
+DuRlcDlUserDataToRlcFunc duSendRlcDlUserDataToRlcOpts[] =
+{
+   packRlcDlUserDataToRlc,        /* Loose coupling */ 
+   RlcProcDlUserDataTransfer,  /* Tight coupling */
+   packRlcDlUserDataToRlc         /* Light weight-loose coupling */
 };
+
+/*******************************************************************
+ *
+ * @brief Function to fillDlUserDataInfo
+ *
+ * @details
+ *
+ *    Function : fillDlUserDataInfo
+ *
+ *    Functionality:
+ *      Function to fillDlUserDataInfo
+ *
+ * @params[in] teId,
+ *             dlDataMsgInfo
+ *
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t fillDlUserDataInfo(uint32_t teId, RlcDlUserDataInfo *dlDataMsgInfo)
+{
+   uint8_t drbIdx;
+
+   for(drbIdx = 0; drbIdx < duCb.numDrb; drbIdx++)
+   {
+      if(duCb.upTnlCfg[drbIdx] && (duCb.upTnlCfg[drbIdx]->tnlCfg1 != NULLP))
+      {
+        if(duCb.upTnlCfg[drbIdx]->tnlCfg1->teId == teId)
+       {
+          dlDataMsgInfo->cellId = duCb.upTnlCfg[drbIdx]->cellId;
+          dlDataMsgInfo->ueIdx = duCb.upTnlCfg[drbIdx]->ueIdx;
+           dlDataMsgInfo->rbId = duCb.upTnlCfg[drbIdx]->drbId;
+          return ROK;
+       }
+      }
+   }
+   return RFAILED;
+}
+
+ /*******************************************************************
+ *
+ * @brief Build and Send DL Data Message transfer to RLC
+ *
+ * @details
+ *
+ *    Function : duBuildAndSendDlUserDataToRlc
+ *
+ *    Functionality:
+ *      Build and Send DL Data Message transfer to RLC
+ *
+ * @params[in] Cell ID
+ *             UE Index
+ *             Logical Channgel ID
+ *             RRC Message
+ *             RRC Message Length
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t duBuildAndSendDlUserDataToRlc(uint16_t msgLen, EgtpMsg *egtpMsg)
+{
+   uint8_t ret = RFAILED;
+   Pst     pst;
+   RlcDlUserDataInfo *dlDataMsgInfo = NULLP;
+
+   DU_ALLOC_SHRABL_BUF(dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
+   if(!dlDataMsgInfo)
+   {
+      DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed for dlDataMsgInfo in duHdlEgtpDlData()");
+      return RFAILED;
+   }
+   memset(dlDataMsgInfo, 0, sizeof(RlcDlUserDataInfo));
+   if(ODU_GET_MSG_BUF(DU_APP_MEM_REGION, DU_POOL, &dlDataMsgInfo->dlMsg) != ROK)
+   {
+      DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed for dlMsg in duHdlEgtpDlData()");
+      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
+      return RFAILED;
+   }
+   dlDataMsgInfo->dlMsg = egtpMsg->msg;
+   dlDataMsgInfo->msgLen = msgLen;
+
+   /* Filling DL DATA Msg Info */
+   if(fillDlUserDataInfo(egtpMsg->msgHdr.teId, dlDataMsgInfo) == ROK)
+   {
+      /* Filling post structure and sending msg */ 
+      FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_USER_DATA_TRANS_TO_RLC);
+      DU_LOG("\nDEBUG  -->  DU_APP : Sending User Data Msg to RLC \n");
+      ret = (*duSendRlcDlUserDataToRlcOpts[pst.selector])(&pst, dlDataMsgInfo);
+   }
+   if(ret != ROK)
+   {
+      DU_LOG("\nERROR  -->  DU_APP : Failed to send User Data to RLC in duHdlEgtpDlData()");
+      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlDataMsgInfo->dlMsg, msgLen);
+      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlDataMsgInfo, sizeof(RlcDlUserDataInfo));
+   }
+   return ret;
+}
+
 /*******************************************************************
  *
  * @brief Handles EGTP data from CU 
@@ -97,50 +200,21 @@ DuMacUeReconfigReq packMacUeReconfigReqOpts[] =
  * ****************************************************************/
 uint8_t duHdlEgtpDlData(EgtpMsg  *egtpMsg)
 {
-
-   /* TODO : Extract RbId/UeID/CellID/SduId from database
-      using tunnel id in egtp header */
-
-   DU_LOG("\nDEBUG   -->  DU_APP : Processing DL data");
-#ifdef EGTP_TEST
-   Pst pst;
-   uint8_t ret;
-   MsgLen copyLen;
-   RlcDlRrcMsgInfo  *dlRrcMsgInfo = NULLP;
-
-   DU_ALLOC_SHRABL_BUF(dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
-   if(!dlRrcMsgInfo)
+   uint16_t msgLen = 0;
+   DU_LOG("\nDEBUG  --> DU_APP : Processing DL data in duHdlEgtpDlData()");
+   
+   if(!egtpMsg->msg)
    {
-      DU_LOG("\nDU APP : Memory allocation failed for dlRrcMsgInfo in \
-         duBuildAndSendDlRrcMsgToRlc");
-      ODU_PUT_MSG_BUF(egtpMsg->msg);
+      DU_LOG("\nERROR  -->  DU_APP : Recevied Dl Data is NULLP in duHdlEgtpDlData()");
       return RFAILED;
    }
-
-   /* Filling up the RRC msg info */
-   dlRrcMsgInfo->cellId = NR_CELL_ID;
-   dlRrcMsgInfo->ueIdx = UE_ID;
-   dlRrcMsgInfo->rbType = CM_LTE_DRB;
-   dlRrcMsgInfo->rbId   = RB_ID;
-   dlRrcMsgInfo->lcType = CM_LTE_LCH_DTCH;
-   dlRrcMsgInfo->lcId   = 4;
-   dlRrcMsgInfo->execDup = false;
-   dlRrcMsgInfo->deliveryStaRpt = false;
-   ODU_GET_MSG_LEN(egtpMsg->msg, &dlRrcMsgInfo->msgLen);
-   DU_ALLOC_SHRABL_BUF(dlRrcMsgInfo->rrcMsg, dlRrcMsgInfo->msgLen);
-   ODU_COPY_MSG_TO_FIX_BUF(egtpMsg->msg, 0, dlRrcMsgInfo->msgLen, dlRrcMsgInfo->rrcMsg, (MsgLen *)&copyLen);
-   ODU_PUT_MSG_BUF(egtpMsg->msg);
-
-   /* Filling post structure and sending msg */
-   FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_RRC_MSG_TRANS_TO_RLC);
-   DU_LOG("\nDU_APP: Sending Dl User Msg to RLC \n");
-   ret = (*duSendDlRrcMsgToRlcOpts[pst.selector])(&pst, dlRrcMsgInfo);
-   if(ret != ROK)
+   ODU_GET_MSG_LEN(egtpMsg->msg, (MsgLen *)&msgLen);
+   if(duBuildAndSendDlUserDataToRlc(msgLen, egtpMsg) != ROK)
    {
-      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
+      DU_LOG("\nERROR  -->  DU_APP : Failed to build DL USer Data in duHdlEgtpDlData()");
+      DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, egtpMsg->msg, msgLen);
       return RFAILED;
    }
-#endif
    return ROK;
 }
 
@@ -920,7 +994,6 @@ uint8_t fillAmbr(AmbrCfg **macAmbr, AmbrCfg *ueDbAmbr)
       }
       memset(*macAmbr, 0, sizeof(AmbrCfg));
       (*macAmbr)->ulBr = ueDbAmbr->ulBr;
-      (*macAmbr)->dlBr = ueDbAmbr->dlBr;
    }
    else
    {
@@ -1140,8 +1213,8 @@ void fillDefaultAmInfo(AmBearerCfg *amCfg)
  
    /* UL AM */
    amCfg->ulAmCfg.snLenUl     = AM_SIZE_12;
-   amCfg->ulAmCfg.reAssemTmr  = RE_ASM_40MS
-   amCfg->ulAmCfg.statProhTmr = PROH_35MS;
+   amCfg->ulAmCfg.reAssemTmr  = T_REASSEMBLY_VAL
+   amCfg->ulAmCfg.statProhTmr = T_STATUS_PROHIBHIT_VAL;
 }
 
 /******************************************************************
@@ -1162,7 +1235,7 @@ void fillDefaultUmBiInfo(UmBiDirBearerCfg *umBiDirCfg)
 {
    /* UL UM BI DIR INFO */
    umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
-   umBiDirCfg->ulUmCfg.reAssemTmr = RE_ASM_40MS;
+   umBiDirCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
 
    /* DL UM BI DIR INFO */
    umBiDirCfg->dlUmCfg.snLenDlUm  = UM_SIZE_12;
@@ -1185,7 +1258,7 @@ void fillDefaultUmBiInfo(UmBiDirBearerCfg *umBiDirCfg)
 void fillDefaultUmUlInfo(UmUniDirUlBearerCfg *UmUlCfg)
 {
    UmUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
-   UmUlCfg->ulUmCfg.reAssemTmr = RE_ASM_40MS;
+   UmUlCfg->ulUmCfg.reAssemTmr = T_REASSEMBLY_VAL;
 }
 
 /******************************************************************
@@ -1800,6 +1873,190 @@ uint8_t duUpdateRlcLcCfg(RlcUeCfg *rlcUeCfg, F1UeContextSetupDb *f1UeDb)
 }
 
 
+/*******************************************************************
+ *
+ * @brief Function to fill Tunnel Config to Add/Mod
+ * 
+ *
+ * @details
+ *
+ *    Function : fillTnlCfgToAddMod
+ *
+ *    Functionality: Function to fill tunnel Config to Add/Mod
+ *
+ * @params[in] Pointer to tnlCfgDb,
+ *             pointer to f1TnlCfg
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t fillTnlCfgToAddMod(UpTnlCfg **ueCbTnlCfg, UpTnlCfg *f1TnlCfg)
+{
+   if(*ueCbTnlCfg == NULLP)
+   {
+      /* copying to DuCb Tnl Cfg */
+      DU_ALLOC(*ueCbTnlCfg, sizeof(UpTnlCfg));
+      if(*ueCbTnlCfg == NULLP)
+      {
+         DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for drbId[%d]", f1TnlCfg->drbId);
+         return RFAILED;
+      }
+   }
+   memset(*ueCbTnlCfg, 0, sizeof(UpTnlCfg));
+   (*ueCbTnlCfg)->configType = f1TnlCfg->configType;
+   (*ueCbTnlCfg)->cellId    = f1TnlCfg->cellId;
+   (*ueCbTnlCfg)->ueIdx     = f1TnlCfg->ueIdx;
+   (*ueCbTnlCfg)->drbId     = f1TnlCfg->drbId;
+   if(f1TnlCfg->tnlCfg1)
+   {
+      if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
+      {
+         DU_ALLOC((*ueCbTnlCfg)->tnlCfg1, sizeof(GtpTnlCfg));
+         if((*ueCbTnlCfg)->tnlCfg1 == NULLP)
+         {
+            DU_LOG("\nERROR  -->  DU_APP : fillTnlCfgToAddMod: Memory Alloc failed for tnlCfg1 for drbId[%d]", f1TnlCfg->drbId);
+            return RFAILED;
+         }
+      }
+      memset((*ueCbTnlCfg)->tnlCfg1, 0, sizeof(GtpTnlCfg));
+      (*ueCbTnlCfg)->tnlCfg1->teId = f1TnlCfg->tnlCfg1->teId;
+      (*ueCbTnlCfg)->tnlCfg1->ulTnlAddress = f1TnlCfg->tnlCfg1->ulTnlAddress;
+      (*ueCbTnlCfg)->tnlCfg1->dlTnlAddress = f1TnlCfg->tnlCfg1->dlTnlAddress;
+   }
+   return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Processing the tunnel Request to EGTP
+ *        
+ * @details
+ *
+ *    Function : duProcEgtpTunnelCfg
+ *
+ *    Functionality: Processing the tunnel Request to EGTP
+ *
+ * @params[in] UptnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t duProcEgtpTunnelCfg(uint8_t ueCbIdx, UpTnlCfg *duTnlCfg, UpTnlCfg *f1TnlCfg)
+{
+   uint8_t ret = RFAILED, delIdx;
+
+   if(f1TnlCfg->tnlCfg1 == NULLP)
+   {
+      DU_LOG("\nERROR  -->  DU_APP : Tunnel config not found");
+      return ret;
+   }
+
+   if(f1TnlCfg->configType == CONFIG_ADD)
+   {
+      if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_ADD, NULLP, f1TnlCfg->tnlCfg1) == ROK)
+      {
+        if(fillTnlCfgToAddMod(&duCb.upTnlCfg[duCb.numDrb], f1TnlCfg) == ROK)
+        {
+           duCb.numDrb++;
+           ret = ROK;
+        }
+      }      
+   }
+   else if(f1TnlCfg->configType == CONFIG_MOD)
+   {
+      if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_MOD, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
+      {
+        if(fillTnlCfgToAddMod(&duTnlCfg, f1TnlCfg) == ROK)
+        {
+           ret = ROK;
+        }
+      }   
+   }
+   else if(f1TnlCfg->configType == CONFIG_DEL)
+   {
+      if(duSendEgtpTnlMgmtReq(EGTP_TNL_MGMT_DEL, duTnlCfg->tnlCfg1->teId, f1TnlCfg->tnlCfg1) == ROK)
+      {           
+        /* Free memory at drbIdx */
+        DU_FREE(duTnlCfg->tnlCfg1, sizeof(GtpTnlCfg));
+        DU_FREE(duTnlCfg, sizeof(UpTnlCfg));
+        duCb.numDrb--;
+        for(delIdx = ueCbIdx; delIdx < duCb.numDrb; delIdx++)
+        {
+           /* moving all elements one index ahead */
+           ret = fillTnlCfgToAddMod(&duCb.upTnlCfg[delIdx], duCb.upTnlCfg[delIdx+1]);
+           if(ret != ROK)
+           {
+              return ret;
+           }
+        }
+      }   
+   }
+   return ret;
+}
+
+/***********************************************************************
+ *
+ * @brief Function to fill Tunnel Config
+ *        and sends tunnel Req to EGTP
+ * 
+ *
+ * @details
+ *
+ *    Function : duUpdateTunnelCfgDb
+ *
+ *    Functionality: Function to fill tunnel Config
+ *                   and sends tunnel Cfg Req to EGTP
+ *
+ * @params[in] ueIdx, cellId, DuUeCfg 
+ * @return ROK     - success
+ *         RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t duUpdateTunnelCfgDb(uint8_t ueIdx, uint8_t cellId, DuUeCfg *duUeCfg)
+{
+   uint8_t ret = ROK, drbIdx, duCbDrbIdx;
+   bool drbFound = false;
+
+   /*If Add/Mod tunnels request for that DRB is successful in EGTP */
+   /*then update drbId and tunnel Info in duCb */
+   for(drbIdx=0; drbIdx < duUeCfg->numDrb; drbIdx++)
+   {
+      duUeCfg->upTnlInfo[drbIdx].cellId = cellId;
+      duUeCfg->upTnlInfo[drbIdx].ueIdx = ueIdx;
+      for(duCbDrbIdx = 0; duCbDrbIdx < duCb.numDrb; duCbDrbIdx++)
+      {
+        if(duCb.upTnlCfg[duCbDrbIdx]->drbId == duUeCfg->upTnlInfo[drbIdx].drbId)
+        {
+           drbFound = true; /* existing DRB */
+           if(duProcEgtpTunnelCfg(duCbDrbIdx, duCb.upTnlCfg[duCbDrbIdx], &duUeCfg->upTnlInfo[drbIdx]) != ROK)
+           {
+              DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to modify tunnel req for Drb id[%d]",
+              duUeCfg->upTnlInfo[drbIdx].drbId);
+              ret = RFAILED;
+           }
+           break;
+        }
+        else
+           drbFound = false;
+      }
+      if(!drbFound && ret == ROK)/* new DRB to Add */
+      {
+        if(duProcEgtpTunnelCfg(NULLP, NULLP, &duUeCfg->upTnlInfo[drbIdx]) != ROK)
+        {
+            DU_LOG("\nERROR  -> DU_APP : duUpdateTunnelCfgDb: Failed to add tunnel req for Drb id[%d]",
+           duUeCfg->upTnlInfo[drbIdx].drbId);
+           ret = RFAILED;
+           break;
+        }
+      }
+      else
+         break;
+   }
+   return ret;
+}
+
 /*******************************************************************
  *
  * @brief @brief To update DuUeCb Mac and Rlc Ue Cfg
@@ -1845,6 +2102,14 @@ uint8_t duUpdateDuUeCbCfg(uint8_t ueIdx, uint8_t cellId)
          ret = duUpdateMacCfg(&ueCb->macUeCfg, ueCb->f1UeDb);
          if(ret == RFAILED)
             DU_LOG("\nERROR  -->  DU APP : Failed while updating MAC LC Config at duUpdateDuUeCbCfg()");
+         else
+        {
+           if(duUpdateTunnelCfgDb(ueIdx, cellId, &ueCb->f1UeDb->duUeCfg) != ROK)
+           {
+               DU_LOG("\nERROR  -->  DU_APP : Failed to establish tunnel in duUpdateDuUeCbCfg()");
+              return RFAILED;
+           }
+        }
       }
       else
          DU_LOG("\nERROR  -->  DU APP : Failed while updating RLC LC Config at duUpdateDuUeCbCfg()");
@@ -2182,7 +2447,7 @@ uint8_t DuProcRlcDlRrcMsgRsp(Pst *pst, RlcDlRrcMsgRsp *dlRrcMsg)
    {
       GET_UE_IDX(dlRrcMsg->crnti, ueIdx);
       ueCb = &duCb.actvCellLst[dlRrcMsg->cellId -1]->ueCb[ueIdx -1];
-      if(ueCb->f1UeDb)
+      if(ueCb->f1UeDb && ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
       {
         ret = duBuildAndSendUeContextSetupReq(dlRrcMsg->cellId, dlRrcMsg->crnti, &ueCb->f1UeDb->duUeCfg);
        if(ret == RFAILED)
@@ -2235,7 +2500,7 @@ uint8_t duProcUeContextSetupRequest(DuUeCb *ueCb)
             }
          }
       }
-      else
+      else if(ueCb->f1UeDb->actionType == UE_CTXT_SETUP)
       {
          ret = duBuildAndSendUeContextSetupReq(cellId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
         if(ret == RFAILED)
@@ -2251,7 +2516,27 @@ uint8_t duProcUeContextSetupRequest(DuUeCb *ueCb)
    }
    return ret;
 }
-
+/*******************************************************************
+*
+* @brief Process UE context modification request from CU
+*
+* @details
+*
+*    Function : duProcUeContextModReq
+*
+*    Functionality: Process UE context modification request from CU
+*
+* @params[in] DuUeCb *ueCb
+* @return ROK     - success
+*         RFAILED - failure
+*
+* ****************************************************************/
+uint8_t duProcUeContextModReq(DuUeCb *ueCb)
+{
+    
+    //TODO:After RB configuration are done Mod Response is triggered 
+    return ROK;
+}
 /**********************************************************************
   End of file
  ***********************************************************************/