1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /************************************************************************
25 Desc: C source code for Entry point functions
29 **********************************************************************/
32 @brief This module does processing related to handling of upper interface APIs
33 invoked by RRC towards MAC.
36 static const char* RLOG_MODULE_NAME="MAC";
37 static int RLOG_FILE_ID=181;
38 static int RLOG_MODULE_ID=4096;
40 /* header include files -- defines (.h) */
41 #include "common_def.h"
43 #include "du_app_mac_inf.h"
47 #include "rg_sch_inf.h"
52 /* header/extern include files (.x) */
57 #include "rg_sch_inf.x"
58 #include "rg_prg.x" /* PRG interface typedefs*/
61 #include "rg_pom_scell.x"
64 PRIVATE S16 rgCOMHndlCfgReq ARGS((Inst inst,CrgCfg *cfg, RgErrInfo *errInfo,Bool *isCfmRqrd,CrgCfgTransId transId));
65 PRIVATE S16 rgCOMHndlRecfgReq ARGS((Inst inst,CrgRecfg *recfg, RgErrInfo *errInfo, \
66 CrgCfgTransId transId,Bool *isCfmRqrd));
67 PRIVATE S16 rgCOMHndlDelReq ARGS((Inst inst,CrgDel *del, RgErrInfo *errInfo, Bool *isCfmRqrd, CrgCfgTransId transId));
68 PRIVATE S16 rgCOMHndlResetReq ARGS((Inst inst,CrgRst *reset,RgErrInfo *errInfo));
73 /* forward references */
76 * @brief Handler to handle config request from RRC to MAC.
80 * Function: rgCOMCfgReq
82 * This API handles processing for config request from RRC to MAC.
85 * - If configuration, process configuration request. Call rgCOMHndlCfgReq.
86 * - else If re-configuration, process re-configuration request.
87 * Call rgCOMHndlRecfgReq.
88 * - else If reset, process reset request. Call rgCOMHndlResetReq.
89 * - else If delete, process delete request. Call rgCOMHndlDelReq.
90 * - If successful, send confirmation to RRC. Call rgUIMCrgCfgCfm.
93 * @param[in] Inst inst
94 * @param[in] CrgCfgTransId transId
95 * @param[in] CrgCfgReqInfo *crgCfgReq
104 CrgCfgTransId transId,
105 CrgCfgReqInfo *crgCfgReq
108 S16 rgCOMCfgReq(inst,transId, crgCfgReq)
110 CrgCfgTransId transId;
111 CrgCfgReqInfo *crgCfgReq;
115 U8 cfmStatus = CRG_CFG_CFM_OK;
117 Bool isCfmRqrd = TRUE;
121 /* Process Config/Reconfig/Delete request from RRC */
122 switch (crgCfgReq->action)
126 ret = rgCOMHndlCfgReq(inst,&crgCfgReq->u.cfgInfo, &errInfo,&isCfmRqrd, transId);
131 ret = rgCOMHndlRecfgReq(inst,&crgCfgReq->u.recfgInfo, &errInfo, transId, &isCfmRqrd);
134 /* Start: LTEMAC_2.1_DEV_CFG */
137 ret = rgCOMHndlResetReq(inst,&crgCfgReq->u.rstInfo, &errInfo);
140 /* End: LTEMAC_2.1_DEV_CFG */
143 ret = rgCOMHndlDelReq(inst,&crgCfgReq->u.delInfo, &errInfo, &isCfmRqrd, transId);
148 RLOG1(L_ERROR, "Invalid configuration action %d",
157 cfmStatus = CRG_CFG_CFM_NOK;
160 /* When UeSCellCfg is present then confirmation will be sent later once
161 confirm from all SMAC are recved at PMAC. PMAC will send a consolidated
162 confirm to RRC.Handling the failure of PMAC for Ue Scell add*/
164 if(TRUE == isCfmRqrd)
167 /* Send back confirmation status to RRC */
168 rgUIMCrgCfgCfm(inst,transId, cfmStatus);
172 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
176 * @brief Handler for processing Cell/Ue/Logical channel configuration request
181 * Function: rgCOMHndlCfgReq
183 * This API handles processing of configuration request from RRC to MAC.
186 * - Validate configuration request parameters at CFG module.
187 * Call rgCFGVldtCrgCellCfg, rgCFGVldtCrgUeCfg, rgCFGVldtCrgLcCfg
188 * for Cell, UE and Logical channel configuration respectively.
189 * - If validated successfully, Call rgCFGCrgCellCfg, rgCFGCrgUeCfg,
190 * rgCFGCrgLcCfg for Cell, UE and Logical channel configuration
191 * respectively, else FAIL.
193 * @param[in] Inst inst
194 * @param[in] CrgCfg *cfg
195 * @param[out] RgErrInfo *errInfo
201 PRIVATE S16 rgCOMHndlCfgReq
207 CrgCfgTransId transId
210 PRIVATE S16 rgCOMHndlCfgReq(inst,cfg, errInfo,isCfmRqrd,transId)
215 CrgCfgTransId transId;
219 RgCellCb *cell = NULLP;
222 TRC2(rgCOMHndlCfgReq);
224 errInfo->errType = RGERR_COM_CFG_REQ;
226 /* Validate and process the configuration request */
227 switch (cfg->cfgType)
231 ret = rgCFGVldtCrgCellCfg(inst,&cfg->u.cellCfg,errInfo);
234 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId, "Cell configuration validation FAILED\n");
237 ret = rgCFGCrgCellCfg(inst,&cfg->u.cellCfg, errInfo);
243 ret = rgCFGVldtCrgUeCfg(inst,&cfg->u.ueCfg, &cell, errInfo);
246 RLOG_ARG0(L_ERROR,DBG_CRNTI,cfg->u.ueCfg.crnti, "Ue configuration validation FAILED\n");
249 ret = rgCFGCrgUeCfg(inst,cell, &cfg->u.ueCfg, errInfo);
256 ret = rgCFGVldtCrgLcCfg(inst,&cfg->u.lchCfg, &cell, &ue,errInfo);
260 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId,
261 "LC configuration validation FAILED: LC %d\n", cfg->u.lchCfg.lcId);
264 ret = rgCFGCrgLcCfg(inst,cell, ue, &cfg->u.lchCfg, errInfo,isCfmRqrd,transId);
269 RLOG1(L_ERROR, "Should never come here: cfgType %d",cfg->cfgType);
275 } /* rgCOMHndlCfgReq */
279 * @brief Handler for processing Cell/Ue/Logical channel re-configuration request
284 * Function: rgCOMHndlRecfgReq
286 * This API handles processing of reconfiguration request from RRC to MAC.
289 * - Validate reconfiguration request parameters at CFG module. Call
290 * rgCFGVldtCrgCellRecfg, rgCFGVldtCrgUeRecfg, rgCFGVldtCrgLchRecfg for
291 * Cell, UE and logical channel reconfiguration respectively.
292 * - If validated, Call rgCFGCrgCellRecfg, rgCFGCrgUeRecfg,
293 * rgCFGCrgLchRecfg for Cell, UE and Logical channel re-configuration
294 * respectively else FAIL.
296 * @param[in] Inst inst
297 * @param[in] CrgRecfg *recfg
298 * @param[out] RgErrInfo *errInfo
304 PRIVATE S16 rgCOMHndlRecfgReq
309 CrgCfgTransId transId,
313 PRIVATE S16 rgCOMHndlRecfgReq(inst,recfg, errInfo, transId, isCfmRqrd)
317 CrgCfgTransId transId;
322 RgCellCb *cell = rgCb[inst].cell;
324 RgUlLcCb *ulLc = NULLP;
326 TRC2(rgCOMHndlRecfgReq);
328 errInfo->errType = RGERR_COM_RECFG_REQ;
330 /* Validate and process the re-configuration request */
331 switch (recfg->recfgType)
335 ret = rgCFGVldtCrgCellRecfg(inst,&recfg->u.cellRecfg, &cell, errInfo);
338 RLOG_ARG0(L_ERROR,DBG_CELLID,recfg->u.cellRecfg.cellId,
339 "Cell Recfg Validation FAILED");
342 ret = rgCFGCrgCellRecfg(inst,cell, &recfg->u.cellRecfg, errInfo);
347 /*ccpu00126865 - Added as a part of RRC Reestablishment issue with MAC
348 * having a possibility of sending NOK */
349 if (recfg->u.ueRecfg.oldCrnti != recfg->u.ueRecfg.newCrnti)
351 errInfo->errCause = RGERR_CFG_INVALID_CRG_UE_RECFG;
357 /* Check for isSCellCfgPres */
358 if(TRUE == recfg->u.ueRecfg.crgSCellCfg.isSCellCfgPres)
360 ret = rgFillAndAddSCellCfg(inst, cell, &recfg->u.ueRecfg, transId, isCfmRqrd);
363 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Ue SCell configuration FAILED for inst [%d]\n",
364 recfg->u.ueRecfg.oldCrnti, inst));
372 ret = rgCFGVldtCrgUeRecfg(inst,&recfg->u.ueRecfg, &cell, &ue, errInfo);
375 RLOG_ARG1(L_ERROR,DBG_CELLID,recfg->u.ueRecfg.cellId,
376 "Ue Re-configuration validation FAILED OLD CRNTI:%d",
377 recfg->u.ueRecfg.oldCrnti);
380 ret = rgCFGCrgUeRecfg(inst,cell, ue, &recfg->u.ueRecfg, errInfo);
389 ret = rgCFGVldtCrgLcRecfg(inst,&recfg->u.lchRecfg, &cell, &ue,
393 RLOG_ARG2(L_ERROR,DBG_CELLID,recfg->u.lchRecfg.cellId,
394 "LC Re-configuration validation FAILED LCID:%d CRNTI:%d",
395 recfg->u.lchRecfg.lcId,recfg->u.lchRecfg.crnti);
400 /*ERAB- multicell fix*/
401 cmMemcpy( (U8*)&(ue->cfgCfmInfo.transId), (U8*)&transId,
402 sizeof(CrgCfgTransId));
404 ret = rgCFGCrgLcRecfg(inst,cell, ue, ulLc,
405 &recfg->u.lchRecfg, errInfo,isCfmRqrd);
411 RLOG1(L_ERROR, "Should never come here: recfgType %d",
418 } /* rgCOMHndlRecfgReq */
420 /*Start: LTEMAC_2.1_DEV_CFG */
422 * @brief Handler for processing UE Reset request recieved from RRC.
426 * Function: rgCOMHndlResetReq
428 * This API handles processing of Reset request from RRC to MAC.
431 * - Validate reset request parameters at CFG module. Call
432 * rgCFGVldtCrgUeReset for UE reset.
433 * - If validated, Call rgCFGCrgUeReset for UE reset, else FAIL.
435 * @param[in] Inst inst
436 * @param[in] CrgRst *reset
437 * @param[out] RgErrInfo *errInfo
443 PRIVATE S16 rgCOMHndlResetReq
450 PRIVATE S16 rgCOMHndlResetReq(inst,reset, errInfo)
456 TRC2(rgCOMHndlResetReq);
458 /* Fix : ccpu00126865: ignore CRG reset. Let SCH trigger it. */
460 errInfo->errCause = RGERR_NONE;
461 RGDBGINFO(inst,(rgPBuf(inst), "CRG UE Reset processed \n"));
463 } /* rgCOMHndlResetReq */
464 /*End: LTEMAC_2.1_DEV_CFG */
467 * @brief Handler for processing Cell/UE/Logical channel delete request
472 * Function: rgCOMHndlDelReq
474 * This API handles processing of delete request from RRC to MAC.
477 * - Fetch corresponding control block and pass it to CFG module.
478 * - If control block does not exist, FAIL.
480 * @param[in] Inst inst
481 * @param[in] CrgDel *del
482 * @param[out] RgErrInfo *errInfo
483 @param[out] Bool *isCfmRqrd
489 PRIVATE S16 rgCOMHndlDelReq
495 CrgCfgTransId transId
498 PRIVATE S16 rgCOMHndlDelReq(inst,del, errInfo,isCfmRqrd,transId)
503 CrgCfgTransId transId;
508 VOLATILE U32 startTime=0;
510 TRC2(rgCOMHndlDelReq);
512 errInfo->errType = RGERR_COM_DEL_REQ;
514 /* Process the delete request */
515 switch (del->delType)
519 ret = rgCFGCrgCellDel(inst,del, errInfo);
525 SStartTask(&startTime,PID_MAC_UE_DEL);
528 ret = rgCFGCrgUeDel(inst,del, errInfo);
529 RGDBGINFONEW(inst,(rgPBuf(inst),"[%d] Delete UE Done \n", del->u.ueDel.crnti));
532 SStopTask(startTime,PID_MAC_UE_DEL);
538 ret = rgCFGCrgLcDel(inst,del, errInfo,isCfmRqrd, transId);
543 RLOG1(L_ERROR, "Should never come here: delType %d",
550 } /* rgCOMHndlDelReq */
554 * @brief Handler for the SCell configuration request from RRC to MAC.
558 * Function : RgPrgPMacSMacUeSCellCfgReq
561 * - Allocate and create UE control block.
562 * - Update UE control block with the values recieved in the
564 * - If successful, add the control block to hash list of UEs for the cell
565 * else Rollback and FAIL.
567 * @param[in] Pst *pst
568 * @param[in] RgPrgUeSCellCfgInfo *ueSCellCb
574 S16 RgPrgPMacSMacUeSCellCfgReq
577 RgPrgUeSCellCfgInfo *ueSCellCb
580 S16 RgPrgPMacSMacUeSCellCfgReq(pst, ueSCellCb)
582 RgPrgUeSCellCfgInfo *ueSCellCb;
585 RgPrgCfgCfmInfo cfgCfm;
586 Inst inst = pst->dstInst;
587 RgCellCb *cell = rgCb[inst].cell;
591 TRC2(RgPrgPMacSMacUeSCellCfgReq);
593 RGDBGPRM(inst,(rgPBuf(inst),
594 "APPLYING CRG UE SCELL CONFIG: cellId %d ueId %d\n",
595 ueSCellCb->cellId, ueSCellCb->ueId));
597 cfgCfm.ueId = ueSCellCb->ueId;
598 cfgCfm.sCellId = ueSCellCb->cellId;
599 cfgCfm.status = PRG_CFG_CFM_OK;
600 cfgCfm.event = EVTPRGUESCELLCFGCFM;
601 rgGetPstToInst(&cfmPst, inst, pst->srcInst);
603 ret = rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst);
606 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
607 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
608 /* Set status as Not OK*/
609 cfgCfm.status = PRG_CFG_CFM_NOK;
613 ret = rgCfgAddUeSCellCfg(inst, ueSCellCb, cell);
616 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
617 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
618 /* Set status as Not OK*/
619 cfgCfm.status = PRG_CFG_CFM_NOK;
623 RGDBGINFONEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell Config done:\
624 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
626 /* Send positive confirmation to primary cell*/
627 RgPrgSMacPMacCfg(&cfmPst, &cfgCfm);
629 } /* RgPrgPMacSMacUeSCellCfgReq */
632 * @brief Hander for config confim from sec MAC to Pri mac for Add Scell Cfg.
636 * Function : RgPrgSMacPMacCfgCfm
639 * - Allocate and create UE control block.
640 * - If cfm event is lch recfg then send the confirmation to RRC for
642 * - If cfm event is Scell addition then send the confirmation to RRC for
644 * - Update UE control block with the values received in the
646 * - If successful, add the control block to hash list of UEs for the cell
647 * else Rollback and FAIL.
649 * @param[in] Inst dstMacInst
650 * @param[in] RgUrSCellCb *ueSCellCb
656 S16 RgPrgSMacPMacCfgCfm
659 RgPrgCfgCfmInfo *cfgCfm
662 S16 RgPrgSMacPMacCfgCfm(pst, cfgCfm)
664 RgPrgCfgCfmInfo *cfgCfm;
667 Inst inst = pst->dstInst;
670 TRC2(RgPrgSMacPMacCfgCfm);
673 RG_IS_INST_VALID(inst);
675 RGDBGPRM(pst->dstInst,(rgPBuf(pst->dstInst),
676 "Config Confirm Rcvd from Inst %d ueId %d cellId %d\n",
677 pst->srcInst, cfgCfm->ueId, cfgCfm->cellId));
679 cell = rgCb[inst].cell;
681 if ((ue = rgDBMGetUeCb(cell, cfgCfm->ueId)) == NULLP)
683 RGDBGERRNEW(inst,(rgPBuf(inst),
684 "[%d]Ue does not exist\n", cfgCfm->ueId));
687 switch(cfgCfm->event)
689 /* cfgCount increment for all cases */
690 case EVTPRGUESCELLLCHMODCFM:
691 case EVTPRGUESCELLLCHDELCFM:
692 case EVTPRGUESCELLLCHADDCFM:
694 ue->cfgCfmInfo.cfgCfgCount++;
695 ue->cfgCfmInfo.mask |= cfgCfm->status;
696 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
698 ue->cfgCfmInfo.cfgCfgCount = 0;
699 /* Send back confirmation status to RRC */
700 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
701 ue->cfgCfmInfo.mask = 0;
702 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
706 case EVTPRGUESCELLCFGCFM:
708 /*Commit Added SCell info to UeCb as we confirmation received */
709 if(PRG_CFG_CFM_OK == cfgCfm->status)
711 ue->sCelInfo[pst->srcInst].isSCellAdded = TRUE;
712 ue->sCelInfo[pst->srcInst].macInst = pst->srcInst;
713 ue->sCelInfo[pst->srcInst].sCellId = cfgCfm->sCellId;
716 ue->cfgCfmInfo.cfgCfgCount++;
717 ue->cfgCfmInfo.mask |= cfgCfm->status;
718 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
720 ue->cfgCfmInfo.cfgCfgCount = 0;
721 /* Send back confirmation status to RRC */
722 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
723 ue->cfgCfmInfo.mask = 0;
724 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
730 RGDBGERRNEW(inst,(rgPBuf(inst), "Invalid configuration confirm event %d\n",
738 } /* RgPrgSMacPMacCfgCfm */
741 * @brief Function for handling UE release for SCELL
742 * triggered from Primary Cell
746 * Function : RgPrgPMacSMacUeSCellDelReq
748 * - This Function should be invoked by PCell of UE
749 * - Remove the UE context from SCELL corresponding to rnti.
751 * @param[in] Pst *pst
752 * @param[in] RgPrgUeSCellDelInfo *ueSCellDelInfo
753 * @return ROK is SUCCESS
756 S16 RgPrgPMacSMacUeSCellDelReq
759 RgPrgUeSCellDelInfo *ueSCellDelInfo
762 S16 RgPrgPMacSMacUeSCellDelReq(pst, ueSCellDelInfo)
764 RgPrgUeSCellDelInfo *ueSCellDelInfo;
767 Inst inst = pst->dstInst - RG_INST_START;
768 RgCellCb *sCell = rgCb[inst].cell;
769 RgUeCb *sCellUe = NULLP;
771 TRC2(RgPrgPMacSMacUeSCellDelReq)
773 /* Checking for cell Cb because in case of shutdownReq it is possible that
774 * cell is already deleted for this cell*/
779 /* Retrive the UeCb from sec cell*/
780 if ((sCellUe = rgDBMGetUeCb(sCell, ueSCellDelInfo->ueId)) == NULLP)
782 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:does not exist in sCell(%d)\n",
783 ueSCellDelInfo->ueId, sCell->cellId));
787 /*PMAC_Reest: ueId and newRnti is different that means its a UeId change
788 *request from PMAC to SMAC during PCell reestablishment
790 if(ueSCellDelInfo->ueId != ueSCellDelInfo->newRnti)
792 /* Retrive the UeCb from sec cell*/
793 if ((rgDBMGetUeCb(sCell, ueSCellDelInfo->newRnti)) != NULLP)
795 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:UE context already exist in\
796 sCell(%d)",ueSCellDelInfo->newRnti, sCell->cellId));
800 rgDBMDelUeCb(sCell, sCellUe);
802 sCellUe->ueId = ueSCellDelInfo->newRnti;
804 /* Reset harq procs*/
805 rgDHMUeReset(sCell, &sCellUe->dl.hqEnt);
807 rgDBMInsUeCb(sCell, sCellUe);
811 rgDBMDelUeCb(sCell, sCellUe);
812 rgCFGFreeUeCb(sCell, sCellUe);
816 } /* RgPrgPMacSMacUeSCellDelReq */
818 /**********************************************************************
821 **********************************************************************/