+/*******************************************************************
+ *
+ * @brief Build and Send Ue context mod request
+ *
+ * @details
+ *
+ *
+ * Function : duBuildAndSendUeContextModReq
+ *
+ * Functionality:
+ * Build and Send Ue context mod request
+ *
+ * @params[in] cellId, crnti, DuUeCfg pointer
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *****************************************************************/
+
+uint8_t duBuildAndSendUeContextModReq(uint16_t cellId, uint8_t gnbDuUeF1apId, uint16_t crnti, DuUeCfg *duUeCfg)
+{
+ uint8_t ret = ROK;
+
+ DU_LOG("\nDEBUG --> DU_APP: Processing Ue Context Mod Request for cellId [%d]", cellId);
+ /* Filling RLC Ue Reconfig */
+ ret = duBuildAndSendUeRecfgReqToRlc(cellId, gnbDuUeF1apId, crnti, duUeCfg);
+ if(ret == RFAILED)
+ DU_LOG("\nERROR --> DU APP : Failed to build ctxt setup req for RLC at duBuildAndSendUeContextModReq()");
+
+ /* Filling MAC Ue Reconfig */
+ ret = duBuildAndSendUeRecfgReqToMac(cellId, gnbDuUeF1apId, crnti, duUeCfg);
+ if(ret == RFAILED)
+ DU_LOG("\nERROR --> DU APP : Failed at build ctxt setup req for MAC at duBuildAndSendUeContextModReq()");
+
+ return ret;
+}
+/*******************************************************************
+ *
+ * @brief Processing Ue context mod request
+ *
+ * @details
+ *
+ *
+ * Function : duProcUeContextModReq
+ *
+ * Functionality:
+ * Processing Ue context mod request
+ *
+ * @params[in] DuUeCb *ueCb
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *****************************************************************/
+
+uint8_t duProcUeContextModReq(DuUeCb *ueCb)
+{
+ uint8_t ret, cellId;
+
+ ret = ROK;
+ if(ueCb)
+ {
+ cellId = duCb.actvCellLst[ueCb->f1UeDb->cellIdx]->cellId;
+ /* Send DL RRC msg for security Mode */
+ if(ueCb->f1UeDb->dlRrcMsg)
+ {
+ if(ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu)
+ {
+ /* Sending DL RRC Message to RLC */
+ ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->duRlcUeCfg, ueCb->f1UeDb->dlRrcMsg);
+ if(ret == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU APP : Failed to send DL RRC msg in duProcUeContextModReq()");
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
+ ueCb->f1UeDb->dlRrcMsg->rrcMsgSize);
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
+ }
+ }
+ }
+ else if(ueCb->f1UeDb->actionType == UE_CTXT_MOD)
+ {
+ ret = duBuildAndSendUeContextModReq(cellId, ueCb->gnbDuUeF1apId, ueCb->crnti, &ueCb->f1UeDb->duUeCfg);
+ if(ret == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU APP : Failed to build ue context setup Req in duProcUeContextModReq()");
+ return RFAILED;
+ }
+ }
+ else if((ueCb->f1UeDb->actionType == UE_CTXT_CFG_QUERY) || (ueCb->f1UeDb->actionType == UE_CTXT_RRC_RECFG_COMPLETE))
+ {
+ if((BuildAndSendUeContextModRsp(ueCb) != ROK))
+ {
+ DU_LOG("\nERROR --> DU APP : Failed to build UE Context modification response");
+ return RFAILED;
+ }
+ }
+ }
+ else
+ {
+ //TODO: To send the failure cause in UeContextModRsp
+
+ DU_LOG("ERROR --> DU APP : Failed to process UE CNTXT MOD REQ at duProcUeContextModReq()");
+ return RFAILED;
+ }
+ return ROK;
+}
+
+/*******************************************************************
+*
+* @brief Build and send dedicated RACH resource release request to MAC
+*
+* @details
+*
+* Function : duBuildAndSendRachRsrcRelToMac
+*
+* Functionality: Function to Build and send dedicated RACH resource
+* release request to MAC
+*
+* @params[in] Cell ID
+* UE CB
+* @return ROK - Success
+* RFAILED - Failure
+*
+* ****************************************************************/
+uint8_t duBuildAndSendRachRsrcRelToMac(uint16_t cellId, DuUeCb *ueCb)
+{
+ Pst pst;
+ MacRachRsrcRel *rachRsrcRel = NULLP;
+
+ DU_ALLOC_SHRABL_BUF(rachRsrcRel, sizeof(MacRachRsrcRel));
+ if(!rachRsrcRel)
+ {
+ DU_LOG("\nERROR --> DU APP : Failed to allocate memory for RACH Resource Release in \
+ duBuildAndSendRachRsrcRelToMac()");
+ return RFAILED;
+ }
+
+ rachRsrcRel->cellId = cellId;
+ rachRsrcRel->ueId = ueCb->gnbDuUeF1apId;
+ rachRsrcRel->crnti = ueCb->crnti;
+
+ /* Fill Pst */
+ FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_RACH_RESOURCE_REL);
+
+ if(((*packMacRachRsrcRelOpts[pst.selector])(&pst, rachRsrcRel)) != ROK)
+ {
+ DU_LOG("\nERROR --> DU_APP : Failure in sending RACH Resource Release to MAC at \
+ duBuildAndSendRachRsrcRelToMac()");
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rachRsrcRel, sizeof(MacRachRsrcRel));
+ return RFAILED;
+ }
+
+ return ROK;
+}
+
+/*******************************************************************
+ *
+* @brief delete DuMacUeCfg from duCb
+*
+* @details
+*
+* Function : deleteMacUeCfg
+*
+* Functionality: delete DuMacUeCfg from duCb
+*
+* @params[in] Pointer to DuMacUeCfg
+* @return ROK - success
+* RFAILED - failure
+*
+*******************************************************************/
+
+void deleteMacUeCfg(DuMacUeCfg *ueCfg)
+{
+ uint8_t lcCfgIdx=0;
+
+ if(ueCfg->spCellCfgPres)
+ {
+ freeUeRecfgCellGrpInfo(ueCfg);
+ }
+ if(ueCfg->ambrCfg)
+ {
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL,ueCfg->ambrCfg, sizeof(AmbrCfg));
+ }
+ for(lcCfgIdx=0; lcCfgIdx< ueCfg->numLcs; lcCfgIdx++)
+ {
+ freeMacLcCfg(&ueCfg->lcCfgList[lcCfgIdx].lcConfig);
+ }
+ memset(ueCfg, 0, sizeof(DuMacUeCfg));
+}
+
+/*******************************************************************
+*
+* @brief delete UE Configuration of a particular UE
+*
+* @details
+*
+* Function : deleteUeCfg
+*
+* Functionality: delete UE Configuration of a particular UE
+*
+* @params[in] uint16_t cellIdx, uint8_t ueId
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t deleteUeCfg(uint16_t cellId, uint8_t ueId)
+{
+ uint8_t tnlIdx = 0;
+ uint16_t cellIdx = 0;
+ DuUeCb *ueCb = NULLP;
+
+ GET_CELL_IDX(cellId, cellIdx);
+ if(duCb.actvCellLst[cellIdx] != NULLP)
+ {
+ if((duCb.actvCellLst[cellIdx]->ueCb[ueId-1].duMacUeCfg.macUeCfgState == UE_DELETE_COMPLETE)\
+ &&(duCb.actvCellLst[cellIdx]->ueCb[ueId-1].duRlcUeCfg.rlcUeCfgState == UE_DELETE_COMPLETE))
+ {
+ ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueId-1];
+ deleteMacUeCfg(&ueCb->duMacUeCfg);
+ deleteRlcUeCfg(&ueCb->duRlcUeCfg);
+ if(ueCb->f1UeDb !=NULLP)
+ {
+ freeF1UeDb(ueCb->f1UeDb);
+ }
+ for(tnlIdx = 0; tnlIdx < duCb.numTeId; )
+ {
+ if(duCb.upTnlCfg[tnlIdx]->ueId == ueId)
+ {
+ duCb.upTnlCfg[tnlIdx]->configType = CONFIG_DEL;
+ duProcEgtpTunnelCfg(tnlIdx, duCb.upTnlCfg[tnlIdx], duCb.upTnlCfg[tnlIdx]);
+ }
+ else
+ tnlIdx++;
+ }
+ unsetBitInUeBitMap(cellId, ueId-1);
+ duCb.actvCellLst[cellIdx]->numActvUes--;
+ memset(ueCb, 0, sizeof(DuUeCb));
+ }
+ else
+ {
+ return RFAILED;
+ }
+ }
+ else
+ {
+ DU_LOG("\nERROR --> DU APP : deleteUeCfg(): CellIdx[%d] is not found", cellIdx);
+ return RFAILED;
+ }
+ return ROK;
+}
+
+
+/*******************************************************************
+*
+* @brief Handle UE delete response from MAC
+*
+* @details
+*
+* Function : DuProcMacUeDeleteRsp
+*
+* Functionality: Handle UE delete response from MAC
+*
+* @params[in] Pointer to MacUeDeleteRsp and Pst
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+
+uint8_t DuProcMacUeDeleteRsp(Pst *pst, MacUeDeleteRsp *deleteRsp)
+{
+ uint8_t ret =ROK,ueId=0;
+ uint16_t cellIdx=0;
+ uint32_t gnbCuUeF1apId =0 , gnbDuUeF1apId =0;
+
+ if(deleteRsp)
+ {
+ if(deleteRsp->result == DEL_SUCCESSFUL)
+ {
+ DU_LOG("\nINFO --> DU APP : MAC UE Delete Response : SUCCESS [UE IDX : %d]", deleteRsp->ueId);
+ GET_CELL_IDX(deleteRsp->cellId, cellIdx);
+ if(duCb.actvCellLst[cellIdx])
+ {
+ duCb.actvCellLst[cellIdx]->ueCb[deleteRsp->ueId -1].duMacUeCfg.macUeCfgState = UE_DELETE_COMPLETE;
+ ueId = deleteRsp->ueId;
+ gnbCuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbCuUeF1apId;
+ gnbDuUeF1apId = duCb.actvCellLst[cellIdx]->ueCb[ueId-1].gnbDuUeF1apId;
+ if(deleteUeCfg(deleteRsp->cellId, ueId) == ROK)
+ {
+ ret = BuildAndSendUeContextReleaseComplete(deleteRsp->cellId, gnbCuUeF1apId, gnbDuUeF1apId);
+ if(ret != ROK)
+ {
+ DU_LOG("\nERROR --> DU APP : DuProcMacUeDeleteRsp(): failed to send UE context release complete");
+ }
+ }
+
+ }
+ }
+ else
+ {
+ DU_LOG("\nERROR --> DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response : FAILURE [UE IDX : %d]",\
+ deleteRsp->ueId);
+ ret = RFAILED;
+ }
+ DU_FREE_SHRABL_BUF(pst->region, pst->pool, deleteRsp, sizeof(MacUeDeleteRsp));
+ }
+ else
+ {
+ DU_LOG("\nERROR --> DU APP : DuProcMacUeDeleteRsp(): MAC UE Delete Response is null");
+ ret = RFAILED;
+ }
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Processes UE Delete Rsp received from RLC
+ *
+ * @details
+ *
+ * Function : DuProcRlcUeDeleteRsp
+ *
+ * Functionality:
+ * Processes UE Delete Rsp received from RLC
+ *
+ * @params[in] Post structure
+ * Pointer to RlcUeDeleteRsp
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * *****************************************************************/
+
+uint8_t DuProcRlcUeDeleteRsp(Pst *pst, RlcUeDeleteRsp *delRsp)
+{
+ uint8_t ueId = 0, ret = ROK;
+ uint16_t cellIdx = 0,crnti=0;
+
+ if(delRsp)
+ {
+ ueId = delRsp->ueId;
+ GET_CELL_IDX(delRsp->cellId, cellIdx);
+
+ if(delRsp->result == SUCCESSFUL)
+ {
+ DU_LOG("\nINFO --> DU_APP: RLC UE Delete Response : SUCCESS [UE IDX:%d]", ueId);
+ if(duCb.actvCellLst[cellIdx]!=NULLP)
+ {
+ duCb.actvCellLst[cellIdx]->ueCb[ueId-1].duRlcUeCfg.rlcUeCfgState = UE_DELETE_COMPLETE;
+ GET_CRNTI(crnti, ueId);
+ if(sendUeDeleteReqToMac(delRsp->cellId, ueId, crnti) == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU APP : duBuildAndSendUeDeleteReq(): Failed to build UE delete req for MAC ");
+ return RFAILED;
+ }
+
+ }
+ }
+ else
+ {
+ DU_LOG("\nERROR --> DU_APP: RLC UE Delete Response : FAILED [UE IDX:%d]", ueId);
+ ret = RFAILED;
+ }
+ DU_FREE_SHRABL_BUF(pst->region, pst->pool, delRsp, sizeof(RlcUeDeleteRsp));
+
+ }
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Sending UE Delete Req To Mac
+*
+* @details
+*
+* Function : sendUeDeleteReqToMac
+*
+* Functionality:
+* sending UE Delete Req To Mac
+*
+* @params[in] cellId, ueId, crnti
+* @return ROK - success
+* RFAILED - failure
+*
+*****************************************************************/
+
+uint8_t sendUeDeleteReqToMac(uint16_t cellId, uint8_t ueId, uint16_t crnti)
+{
+ Pst pst;
+ uint8_t ret=ROK;
+ MacUeDelete *ueDelete = NULLP;
+
+ DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(MacUeDelete));
+ if(ueDelete)
+ {
+ ueDelete->cellId = cellId;
+ ueDelete->ueId = ueId;
+ ueDelete->crnti = crnti;
+ FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_DELETE_REQ);
+
+ DU_LOG("\nDEBUG --> DU_APP: Sending UE delete Request to MAC ");
+ ret = (*packMacUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
+ if(ret == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU_APP: sendUeDeleteReqToMac(): Failed to send UE delete Req to MAC");
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(MacUeDelete));
+ }
+ }
+ else
+ {
+ DU_LOG("\nERROR --> DU_APP: sendUeDeleteReqToMac(): Failed to allocate memory");
+ ret = RFAILED;
+ }
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief Sending UE Delete Req To Rlc
+ *
+ * @details
+ *
+ * Function : sendUeDeleteReqToRlc
+ *
+ * Functionality:
+ * Sending UE Delete Req To Rlc
+ *
+ * @params[in] cellId, ueId
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *****************************************************************/
+
+uint8_t sendUeDeleteReqToRlc(uint16_t cellId, uint8_t ueId)
+{
+ uint8_t ret;
+ Pst pst;
+ RlcUeDelete *ueDelete;
+
+ DU_ALLOC_SHRABL_BUF(ueDelete, sizeof(RlcUeDelete));
+ if(ueDelete !=NULLP)
+ {
+ ueDelete->cellId = cellId;
+ ueDelete->ueId = ueId;
+ FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UE_DELETE_REQ);
+
+ ret = (*packRlcUeDeleteReqOpts[pst.selector])(&pst, ueDelete);
+ if(ret == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU_APP : sendUeDeleteReqToRlc():Failed to send UE Delete Req to RLC");
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, ueDelete, sizeof(RlcUeDelete));
+ }
+ }
+ else
+ {
+ DU_LOG("\nERROR --> DU_APP: sendUeDeleteReqToRlc():Memory allocation failed");
+ ret = RFAILED;
+ }
+ return ret;
+}
+
+/*******************************************************************
+ *
+ * @brief DU processes UE delete req from CU and sends to MAC and RLC
+ *
+ * @details
+ *
+ * Function : duBuildAndSendUeDeleteReq
+ *
+ * Functionality: DU processes UE delete req from CU and sends to MAC
+ * and RLC
+ *
+ * @params[in] cellId, crnti
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+
+uint8_t duBuildAndSendUeDeleteReq(uint16_t cellId, uint16_t crnti)
+{
+ uint8_t ueId =0;
+ uint16_t cellIdx = 0;
+
+ DU_LOG("\nDEBUG --> DU_APP: Processing UE Delete Request ");
+ GET_CELL_IDX(cellId, cellIdx);
+ GET_UE_ID(crnti, ueId);
+
+ if(duCb.actvCellLst[cellIdx] != NULLP)
+ {
+ if(crnti != duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].crnti)
+ {
+ DU_LOG("\nERROR --> DU APP : duBuildAndSendUeDeleteReq(): CRNTI [%d] not found", crnti);
+ return RFAILED;
+ }
+
+ duCb.actvCellLst[cellIdx]->ueCb[ueId - 1].ueState = UE_DELETION_IN_PROGRESS;
+ if(sendUeDeleteReqToRlc(cellId, ueId) == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU APP : DuProcMacUeDeleteRsp():Failed to build UE delete req for RLC ");
+ return RFAILED;
+ }
+ }
+ else
+ {
+ DU_LOG("\nERROR --> DU APP : duBuildAndSendUeDeleteReq(): Cell Id is not found");
+ return RFAILED;
+ }
+
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief delete RlcUeCfg from duCb
+ *
+ * @details
+ *
+ * Function : deleteRlcUeCfg
+ *
+ * Functionality:
+ * delete RlcUeCfg from duCb
+ *
+ * @params[in] RlcUeCfg *ueCfg
+ *
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ *****************************************************************/
+
+void deleteRlcUeCfg(DuRlcUeCfg *ueCfg)
+{
+ uint8_t lcIdx = 0;
+ RlcBearerCfg *lcCfg= NULLP;
+ if(ueCfg)
+ {
+ for(lcIdx =0 ; lcIdx < ueCfg->numLcs ; lcIdx++)
+ {
+ lcCfg = &ueCfg->rlcLcCfg[lcIdx].rlcBearerCfg;
+ switch(lcCfg->rlcMode)
+ {
+ case RLC_AM :
+ {
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.amCfg, sizeof(AmBearerCfg));
+ break;
+ }
+ case RLC_UM_BI_DIRECTIONAL :
+ {
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umBiDirCfg, sizeof(UmBiDirBearerCfg));
+ break;
+ }
+ case RLC_UM_UNI_DIRECTIONAL_UL :
+ {
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirUlCfg, sizeof(UmUniDirUlBearerCfg));
+ break;
+ }
+ case RLC_UM_UNI_DIRECTIONAL_DL :
+ {
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->u.umUniDirDlCfg, sizeof(UmUniDirDlBearerCfg));
+ break;
+ }
+ }
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, lcCfg->snssai, sizeof(Snssai));
+ }
+ memset(ueCfg, 0, sizeof(RlcUeCfg));
+ }
+}
+
+/*******************************************************************
+*
+* @brief Du process Ue Context Release Command
+*
+* @details
+*
+* Function : duProcUeContextReleaseCommand
+*
+* Functionality: Du process Ue Context Release Command
+*
+* @params[in] DuUeCb *duUeCb
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t duProcUeContextReleaseCommand(uint16_t cellId, DuUeCb *duUeCb)
+{
+ uint8_t ret =ROK, ueId=0;
+ uint16_t crnti = 0;
+
+ if(duUeCb != NULLP)
+ {
+ crnti = duUeCb->crnti;
+ GET_UE_ID(crnti, ueId);
+
+ if(duUeCb->f1UeDb)
+ {
+ /* Send DL RRC msg for RRC release */
+ if(duUeCb->f1UeDb->dlRrcMsg)
+ {
+ if(duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu != NULLP)
+ {
+ ret = duBuildAndSendDlRrcMsgToRlc(cellId, duCb.actvCellLst[duUeCb->f1UeDb->cellIdx]->ueCb[ueId-1].duRlcUeCfg,\
+ duUeCb->f1UeDb->dlRrcMsg);
+ if(ret == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU APP : duProcUeContextReleaseCommand() : Failed to send DL RRC msg");
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg->rrcMsgPdu,\
+ duUeCb->f1UeDb->dlRrcMsg->rrcMsgSize);
+ DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, duUeCb->f1UeDb->dlRrcMsg, sizeof(F1DlRrcMsg));
+ }
+ }
+ }
+ }
+ else
+ {
+ ret = duBuildAndSendUeDeleteReq(cellId,crnti);
+ if(ret == RFAILED)
+ {
+ DU_LOG("\nERROR --> DU APP : duProcUeContextReleaseCommand(): Failed to build and send Ue Delete request");
+ }
+ }
+ }
+ return ret;
+}
+