+#endif /* EGTP_TEST */
+
+
+/**************************************************************************
+ * @brief Function to send configs to SCH
+ *
+ * @details
+ *
+ * Function : duSendSchCfg
+ *
+ * Functionality:
+ * Sends general config to Scheduler via MAC layer
+ *
+ * @param[in] void
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ***************************************************************************/
+uint8_t duSendSchCfg()
+{
+ RgMngmt rgMngmt;
+ RgSchInstCfg *cfg = NULLP;
+ Pst pst;
+
+ DU_SET_ZERO(&pst, sizeof(Pst));
+ DU_SET_ZERO(&rgMngmt, sizeof(RgMngmt));
+
+ cfg = &(rgMngmt.t.cfg.s.schInstCfg);
+
+ /* Filling of Instance Id */
+ cfg->instId = DEFAULT_CELLS + 1;
+ /* Filling of Gen config */
+ cfg->genCfg.mem.region = MAC_MEM_REGION;
+ cfg->genCfg.mem.pool = MAC_POOL;
+ cfg->genCfg.tmrRes = 10;
+
+#ifdef LTE_ADV
+ cfg->genCfg.forceCntrlSrbBoOnPCel = FALSE;
+ cfg->genCfg.isSCellActDeactAlgoEnable = TRUE;
+#endif/*LTE_ADV*/
+ cfg->genCfg.startCellId = 1;
+ cfg->genCfg.lmPst.dstProcId = DU_PROC;
+ cfg->genCfg.lmPst.srcProcId = DU_PROC;
+ cfg->genCfg.lmPst.dstEnt = ENTDUAPP;
+ cfg->genCfg.lmPst.dstInst = DU_INST;
+ cfg->genCfg.lmPst.srcEnt = ENTMAC;
+ cfg->genCfg.lmPst.srcInst = DEFAULT_CELLS + 1;
+ cfg->genCfg.lmPst.prior = PRIOR0;
+ cfg->genCfg.lmPst.route = RTESPEC;
+ cfg->genCfg.lmPst.region = MAC_MEM_REGION;
+ cfg->genCfg.lmPst.pool = MAC_POOL;
+ cfg->genCfg.lmPst.selector = ODU_SELECTOR_LC;
+
+ /* Fill Header */
+ rgMngmt.hdr.msgType = TCFG;
+ rgMngmt.hdr.entId.ent = ENTMAC;
+ rgMngmt.hdr.entId.inst = DU_INST;
+ rgMngmt.hdr.elmId.elmnt = STSCHINST;
+ rgMngmt.hdr.response.mem.region = MAC_MEM_REGION;
+ rgMngmt.hdr.response.mem.pool = MAC_POOL;
+
+ /* Fill Pst */
+ pst.selector = ODU_SELECTOR_LC;
+ pst.srcEnt = ENTDUAPP;
+ pst.dstEnt = ENTMAC;
+ pst.dstProcId = DU_PROC;
+ pst.srcProcId = DU_PROC;
+ pst.srcInst = DU_INST;
+ pst.dstInst = 0;
+ pst.region = duCb.init.region;
+ pst.event = (Event) EVTMACSCHGENCFGREQ;
+
+ DU_LOG("\nDU_APP : MAC Sch Cfg sent");
+
+ /* Send the request to MAC */
+ cmPkLrgSchCfgReq(&pst, &rgMngmt);
+
+ 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
+ *
+ ***************************************************************************/
+uint8_t duLayerConfigComplete()
+{
+ uint8_t 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;
+ }
+
+ return (ret);
+}
+
+/**************************************************************************
+ * @brief Function to handle SCH Config Confirm from MAC
+ *
+ * @details
+ *
+ * Function : duHdlSchCfgComplete
+ *
+ * Functionality:
+ * Handles Scheduler Gen Config Confirm from MAC
+ *
+ * @param[in] Pst *pst, Post structure of the primitive.
+ * @param[in] RgMngmt *cfm, Unpacked primitive info received from MAC
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ ***************************************************************************/
+uint8_t duHdlSchCfgComplete(Pst *pst, RgMngmt *cfm)
+{
+ if (cfm->cfm.status == LCM_PRIM_OK)
+ {
+ switch (cfm->hdr.elmId.elmnt)
+ {
+ case STSCHINST:
+ {
+ DU_LOG("\nDU_APP : Received SCH CFG CFM at DU APP");
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ duLayerConfigComplete();
+ duBuildEgtpCfgReq();
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Sends Slot indication to EGTP
+ *
+ * @details
+ *
+ * Function : duSendEgtpSlotInd
+ *
+ * Functionality:
+ * Sends Slot indication to EGTP
+ *
+ * @params[in]
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t duSendEgtpSlotInd()
+{
+ Pst pst;
+
+ duFillEgtpPst(&pst, EVTSLOTIND);
+ packEgtpSlotInd(&pst);
+
+ return 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
+ *
+ ***************************************************************************/
+uint8_t duBuildAndSendMacCellCfg()
+{
+ Pst pst;
+ DU_SET_ZERO(&pst, sizeof(Pst));
+ MacCellCfg *duMacCellCfg = NULLP;
+
+ DU_ALLOC_SHRABL_BUF(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));
+
+ /* Fill Pst */
+ FILL_PST_DUAPP_TO_MAC(pst, 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
+ *
+ ***************************************************************************/
+uint8_t duHandleMacCellCfgCfm(Pst *pst, MacCellCfgCfm *macCellCfgCfm)
+{
+ uint8_t actvCellIdx = 0;
+ uint8_t ret = ROK;
+
+ if(macCellCfgCfm->rsp == ROK)
+ {
+ for(actvCellIdx = 0 ; actvCellIdx <duCb.numActvCells ; actvCellIdx++)
+ {
+ if(macCellCfgCfm->cellId == duCb.actvCellLst[actvCellIdx]->cellId)
+ {
+ 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
+ {
+ 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
+ *
+ * ****************************************************************/
+uint8_t duHandleSlotInd(Pst *pst, SlotIndInfo *slotInfo)
+{
+ if(slotInfo->cellId <=0 || slotInfo->cellId > MAX_NUM_CELL)
+ {
+ DU_LOG("\nDU APP : Invalid Cell Id %d", slotInfo->cellId);
+ }
+ if(!duCb.actvCellLst[slotInfo->cellId-1]->firstSlotIndRcvd)
+ {
+#ifdef ODU_SLOT_IND_DEBUG_LOG
+ DU_LOG("\nDU APP : Slot Indication received");
+#endif
+ duCb.actvCellLst[slotInfo->cellId-1]->firstSlotIndRcvd = true;
+ if((duCb.actvCellLst[slotInfo->cellId-1] != NULL) && \
+ (duCb.actvCellLst[slotInfo->cellId-1]->cellStatus == \
+ ACTIVATION_IN_PROGRESS))
+ {
+ DU_LOG("\nDU APP : 5G-NR Cell %d is UP", slotInfo->cellId);
+ duCb.actvCellLst[slotInfo->cellId-1]->cellStatus = ACTIVATED;
+ }
+
+ }
+
+ /* TODO : Slot Indication to be moved out of EGTP_TEST when
+ * data path is established */
+#ifdef EGTP_TEST
+ duSendEgtpSlotInd();
+#endif
+
+ if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
+ DU_FREE_SHRABL_BUF(MAC_MEM_REGION, pst->pool, slotInfo, sizeof(SlotIndInfo));
+
+ 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
+ *
+ * ****************************************************************/
+uint8_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_SHRABL_BUF(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 < MAX_NUM_CELL; id++)
+ {
+ if(duCb.actvCellLst[id])
+ {
+ duCb.actvCellLst[id]->firstSlotIndRcvd = FALSE;
+ cellStartInfo->cellId = duCb.actvCellLst[id]->cellInfo.nrEcgi.cellId;
+
+ /* Fill Pst */
+ FILL_PST_DUAPP_TO_MAC(pst, 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
+ *
+ * ****************************************************************/
+uint8_t 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_SHRABL_BUF(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 */
+ FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_CELL_STOP_REQ);
+
+ return (*packMacCellStopReqOpts[pst.selector])(&pst, cellStopInfo);
+}
+
+/*******************************************************************
+ *
+ * @brief Handles stop indication from MAC
+ *
+ * @details
+ *
+ * Function : duHandleStopInd
+ *
+ * Functionality:
+ * Handles stop indication from MAC
+ *
+ * @params[in] Post structure pointer
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t duHandleStopInd(Pst *pst, MacCellStopInfo *cellStopId)
+{
+ if(cellStopId->cellId <=0 || cellStopId->cellId > MAX_NUM_CELL)
+ {
+ DU_LOG("\nDU APP : Invalid Cell Id %d", cellStopId->cellId);
+ }
+ if(duCb.actvCellLst[cellStopId->cellId-1] != NULL)
+ {
+ if(duCb.actvCellLst[cellStopId->cellId-1]->firstSlotIndRcvd)
+ {
+ duCb.actvCellLst[cellStopId->cellId-1]->firstSlotIndRcvd = false;
+ if((duCb.actvCellLst[cellStopId->cellId-1]->cellStatus == \
+ ACTIVATED))
+ {
+ DU_LOG("\nDU APP : 5G-NR Cell %d is DOWN", cellStopId->cellId);
+ duCb.actvCellLst[cellStopId->cellId-1]->cellStatus = DELETION_IN_PROGRESS;
+ }
+ }
+ }
+ if((pst->selector == ODU_SELECTOR_LWLC) || (pst->selector == ODU_SELECTOR_TC))
+ DU_FREE_SHRABL_BUF(MAC_MEM_REGION, pst->pool, cellStopId, sizeof(MacCellStopInfo));
+
+ return ROK;
+}
+
+/*******************************************************************
+ *
+ * @brief Handles slot indication from MAC
+ *
+ * @details
+ *
+ * Function : duHandleUlCcchInd
+ *
+ * Functionality:
+ * Handles UL CCCH indication from MAC
+ *
+ * @params[in] Post structure pointer
+ * UL CCCH Ind pointer
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t duHandleUlCcchInd(Pst *pst, UlCcchIndInfo *ulCcchIndInfo)
+{
+
+ DU_LOG("\nDU APP : UL CCCH Indication received");
+
+ return (duProcUlCcchInd(ulCcchIndInfo));
+}
+
+/*******************************************************************
+ *
+ * @brief Process UL RRC Message from RLC
+ *
+ * @details
+ *
+ * Function : DuProcRlcUlRrcMsgTrans
+ *
+ * Functionality: Process UL RRC Message from RLC
+ *
+ * @params[in] Post structure
+ * UL RRC Message Info
+ * @return ROK - success
+ * RFAILED - failure
+ *
+ * ****************************************************************/
+uint8_t DuProcRlcUlRrcMsgTrans(Pst *pst, RlcUlRrcMsgInfo *ulRrcMsgInfo)
+{
+ DuUeCb ueCb;
+
+ ueCb = duCb.actvCellLst[ulRrcMsgInfo->cellId -1]->ueCb[ulRrcMsgInfo->ueIdx -1];
+ BuildAndSendULRRCMessageTransfer(ueCb, ulRrcMsgInfo->lcId, ulRrcMsgInfo->msgLen, \
+ ulRrcMsgInfo->rrcMsg);
+
+ DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo->rrcMsg, ulRrcMsgInfo->msgLen);
+ DU_FREE_SHRABL_BUF(pst->region, pst->pool, ulRrcMsgInfo, sizeof(RlcUlRrcMsgInfo));
+ return ROK;
+}
+
+/*******************************************************************
+*
+* @brief Process RRC delivery report from RLC
+*
+* @details
+*
+* Function : DuProcRlcRrcDeliveryReport
+*
+* Functionality: Process RRC delivery Message from RLC
+*
+* @params[in] Post structure
+* UL RRC Message Info
+* @return ROK - success
+* RFAILED - failure
+*
+* ****************************************************************/
+uint8_t DuProcRlcRrcDeliveryReport(Pst *pst, RrcDeliveryReport *rrcDeliveryReport)
+{
+ DuUeCb ueCb;
+ uint8_t ret = RFAILED;
+
+ ueCb = duCb.actvCellLst[rrcDeliveryReport->cellId -1]->ueCb[rrcDeliveryReport->ueIdx -1];
+ ret = BuildAndSendRrcDeliveryReport(ueCb.gnbCuUeF1apId, ueCb.gnbDuUeF1apId,rrcDeliveryReport);
+
+ DU_FREE_SHRABL_BUF(pst->region, pst->pool, rrcDeliveryReport, sizeof(RrcDeliveryReport));
+ return ret;
+}
+