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;
39 /* header include files -- defines (.h) */
40 #include "envopt.h" /* environment options */
41 #include "envdep.h" /* environment dependent */
42 #include "envind.h" /* environment independent */
43 #include "gen.h" /* general layer */
44 #include "ssi.h" /* system service interface */
45 #include "cm_hash.h" /* common hash list */
46 #include "cm_mblk.h" /* common memory link list library */
47 #include "cm_llist.h" /* common linked list library */
48 #include "cm_err.h" /* common error */
49 #include "cm_lte.h" /* common LTE */
54 #include "rg_sch_inf.h"
55 #include "rg_prg.h" /* PRG interface includes*/
60 /* header/extern include files (.x) */
61 #include "gen.x" /* general layer */
62 #include "ssi.x" /* system service interface */
63 #include "cm5.x" /* common timers */
64 #include "cm_lib.x" /* common library */
65 #include "cm_hash.x" /* common hash list */
66 #include "cm_mblk.x" /* common memory link list library */
67 #include "cm_llist.x" /* common linked list library */
68 #include "cm_tkns.x" /* common tokens */
69 #include "cm_lte.x" /* common LTE */
74 #include "rg_sch_inf.x"
75 #include "rg_prg.x" /* PRG interface typedefs*/
78 #include "rg_pom_scell.x"
81 PRIVATE S16 rgCOMHndlCfgReq ARGS((Inst inst,CrgCfg *cfg, RgErrInfo *errInfo,Bool *isCfmRqrd,CrgCfgTransId transId));
82 PRIVATE S16 rgCOMHndlRecfgReq ARGS((Inst inst,CrgRecfg *recfg, RgErrInfo *errInfo, \
83 CrgCfgTransId transId,Bool *isCfmRqrd));
84 PRIVATE S16 rgCOMHndlDelReq ARGS((Inst inst,CrgDel *del, RgErrInfo *errInfo, Bool *isCfmRqrd, CrgCfgTransId transId));
85 PRIVATE S16 rgCOMHndlResetReq ARGS((Inst inst,CrgRst *reset,RgErrInfo *errInfo));
90 /* forward references */
93 * @brief Handler to handle config request from RRC to MAC.
97 * Function: rgCOMCfgReq
99 * This API handles processing for config request from RRC to MAC.
102 * - If configuration, process configuration request. Call rgCOMHndlCfgReq.
103 * - else If re-configuration, process re-configuration request.
104 * Call rgCOMHndlRecfgReq.
105 * - else If reset, process reset request. Call rgCOMHndlResetReq.
106 * - else If delete, process delete request. Call rgCOMHndlDelReq.
107 * - If successful, send confirmation to RRC. Call rgUIMCrgCfgCfm.
110 * @param[in] Inst inst
111 * @param[in] CrgCfgTransId transId
112 * @param[in] CrgCfgReqInfo *crgCfgReq
118 PUBLIC S16 rgCOMCfgReq
121 CrgCfgTransId transId,
122 CrgCfgReqInfo *crgCfgReq
125 PUBLIC S16 rgCOMCfgReq(inst,transId, crgCfgReq)
127 CrgCfgTransId transId;
128 CrgCfgReqInfo *crgCfgReq;
132 U8 cfmStatus = CRG_CFG_CFM_OK;
134 Bool isCfmRqrd = TRUE;
138 /* Process Config/Reconfig/Delete request from RRC */
139 switch (crgCfgReq->action)
143 ret = rgCOMHndlCfgReq(inst,&crgCfgReq->u.cfgInfo, &errInfo,&isCfmRqrd, transId);
148 ret = rgCOMHndlRecfgReq(inst,&crgCfgReq->u.recfgInfo, &errInfo, transId, &isCfmRqrd);
151 /* Start: LTEMAC_2.1_DEV_CFG */
154 ret = rgCOMHndlResetReq(inst,&crgCfgReq->u.rstInfo, &errInfo);
157 /* End: LTEMAC_2.1_DEV_CFG */
160 ret = rgCOMHndlDelReq(inst,&crgCfgReq->u.delInfo, &errInfo, &isCfmRqrd, transId);
165 RLOG1(L_ERROR, "Invalid configuration action %d",
174 cfmStatus = CRG_CFG_CFM_NOK;
177 /* When UeSCellCfg is present then confirmation will be sent later once
178 confirm from all SMAC are recved at PMAC. PMAC will send a consolidated
179 confirm to RRC.Handling the failure of PMAC for Ue Scell add*/
181 if(TRUE == isCfmRqrd)
184 /* Send back confirmation status to RRC */
185 rgUIMCrgCfgCfm(inst,transId, cfmStatus);
189 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
193 * @brief Handler for processing Cell/Ue/Logical channel configuration request
198 * Function: rgCOMHndlCfgReq
200 * This API handles processing of configuration request from RRC to MAC.
203 * - Validate configuration request parameters at CFG module.
204 * Call rgCFGVldtCrgCellCfg, rgCFGVldtCrgUeCfg, rgCFGVldtCrgLcCfg
205 * for Cell, UE and Logical channel configuration respectively.
206 * - If validated successfully, Call rgCFGCrgCellCfg, rgCFGCrgUeCfg,
207 * rgCFGCrgLcCfg for Cell, UE and Logical channel configuration
208 * respectively, else FAIL.
210 * @param[in] Inst inst
211 * @param[in] CrgCfg *cfg
212 * @param[out] RgErrInfo *errInfo
218 PRIVATE S16 rgCOMHndlCfgReq
224 CrgCfgTransId transId
227 PRIVATE S16 rgCOMHndlCfgReq(inst,cfg, errInfo,isCfmRqrd,transId)
232 CrgCfgTransId transId;
236 RgCellCb *cell = NULLP;
239 TRC2(rgCOMHndlCfgReq);
241 errInfo->errType = RGERR_COM_CFG_REQ;
243 /* Validate and process the configuration request */
244 switch (cfg->cfgType)
248 ret = rgCFGVldtCrgCellCfg(inst,&cfg->u.cellCfg,errInfo);
251 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId, "Cell configuration validation FAILED\n");
254 ret = rgCFGCrgCellCfg(inst,&cfg->u.cellCfg, errInfo);
260 ret = rgCFGVldtCrgUeCfg(inst,&cfg->u.ueCfg, &cell, errInfo);
263 RLOG_ARG0(L_ERROR,DBG_CRNTI,cfg->u.ueCfg.crnti, "Ue configuration validation FAILED\n");
266 ret = rgCFGCrgUeCfg(inst,cell, &cfg->u.ueCfg, errInfo);
273 ret = rgCFGVldtCrgLcCfg(inst,&cfg->u.lchCfg, &cell, &ue,errInfo);
277 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId,
278 "LC configuration validation FAILED: LC %d\n", cfg->u.lchCfg.lcId);
281 ret = rgCFGCrgLcCfg(inst,cell, ue, &cfg->u.lchCfg, errInfo,isCfmRqrd,transId);
286 RLOG1(L_ERROR, "Should never come here: cfgType %d",cfg->cfgType);
292 } /* rgCOMHndlCfgReq */
296 * @brief Handler for processing Cell/Ue/Logical channel re-configuration request
301 * Function: rgCOMHndlRecfgReq
303 * This API handles processing of reconfiguration request from RRC to MAC.
306 * - Validate reconfiguration request parameters at CFG module. Call
307 * rgCFGVldtCrgCellRecfg, rgCFGVldtCrgUeRecfg, rgCFGVldtCrgLchRecfg for
308 * Cell, UE and logical channel reconfiguration respectively.
309 * - If validated, Call rgCFGCrgCellRecfg, rgCFGCrgUeRecfg,
310 * rgCFGCrgLchRecfg for Cell, UE and Logical channel re-configuration
311 * respectively else FAIL.
313 * @param[in] Inst inst
314 * @param[in] CrgRecfg *recfg
315 * @param[out] RgErrInfo *errInfo
321 PRIVATE S16 rgCOMHndlRecfgReq
326 CrgCfgTransId transId,
330 PRIVATE S16 rgCOMHndlRecfgReq(inst,recfg, errInfo, transId, isCfmRqrd)
334 CrgCfgTransId transId;
339 RgCellCb *cell = rgCb[inst].cell;
341 RgUlLcCb *ulLc = NULLP;
343 TRC2(rgCOMHndlRecfgReq);
345 errInfo->errType = RGERR_COM_RECFG_REQ;
347 /* Validate and process the re-configuration request */
348 switch (recfg->recfgType)
352 ret = rgCFGVldtCrgCellRecfg(inst,&recfg->u.cellRecfg, &cell, errInfo);
355 RLOG_ARG0(L_ERROR,DBG_CELLID,recfg->u.cellRecfg.cellId,
356 "Cell Recfg Validation FAILED");
359 ret = rgCFGCrgCellRecfg(inst,cell, &recfg->u.cellRecfg, errInfo);
364 /*ccpu00126865 - Added as a part of RRC Reestablishment issue with MAC
365 * having a possibility of sending NOK */
366 if (recfg->u.ueRecfg.oldCrnti != recfg->u.ueRecfg.newCrnti)
368 errInfo->errCause = RGERR_CFG_INVALID_CRG_UE_RECFG;
374 /* Check for isSCellCfgPres */
375 if(TRUE == recfg->u.ueRecfg.crgSCellCfg.isSCellCfgPres)
377 ret = rgFillAndAddSCellCfg(inst, cell, &recfg->u.ueRecfg, transId, isCfmRqrd);
380 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Ue SCell configuration FAILED for inst [%d]\n",
381 recfg->u.ueRecfg.oldCrnti, inst));
389 ret = rgCFGVldtCrgUeRecfg(inst,&recfg->u.ueRecfg, &cell, &ue, errInfo);
392 RLOG_ARG1(L_ERROR,DBG_CELLID,recfg->u.ueRecfg.cellId,
393 "Ue Re-configuration validation FAILED OLD CRNTI:%d",
394 recfg->u.ueRecfg.oldCrnti);
397 ret = rgCFGCrgUeRecfg(inst,cell, ue, &recfg->u.ueRecfg, errInfo);
406 ret = rgCFGVldtCrgLcRecfg(inst,&recfg->u.lchRecfg, &cell, &ue,
410 RLOG_ARG2(L_ERROR,DBG_CELLID,recfg->u.lchRecfg.cellId,
411 "LC Re-configuration validation FAILED LCID:%d CRNTI:%d",
412 recfg->u.lchRecfg.lcId,recfg->u.lchRecfg.crnti);
417 /*ERAB- multicell fix*/
418 cmMemcpy( (U8*)&(ue->cfgCfmInfo.transId), (U8*)&transId,
419 sizeof(CrgCfgTransId));
421 ret = rgCFGCrgLcRecfg(inst,cell, ue, ulLc,
422 &recfg->u.lchRecfg, errInfo,isCfmRqrd);
428 RLOG1(L_ERROR, "Should never come here: recfgType %d",
435 } /* rgCOMHndlRecfgReq */
437 /*Start: LTEMAC_2.1_DEV_CFG */
439 * @brief Handler for processing UE Reset request recieved from RRC.
443 * Function: rgCOMHndlResetReq
445 * This API handles processing of Reset request from RRC to MAC.
448 * - Validate reset request parameters at CFG module. Call
449 * rgCFGVldtCrgUeReset for UE reset.
450 * - If validated, Call rgCFGCrgUeReset for UE reset, else FAIL.
452 * @param[in] Inst inst
453 * @param[in] CrgRst *reset
454 * @param[out] RgErrInfo *errInfo
460 PRIVATE S16 rgCOMHndlResetReq
467 PRIVATE S16 rgCOMHndlResetReq(inst,reset, errInfo)
473 TRC2(rgCOMHndlResetReq);
475 /* Fix : ccpu00126865: ignore CRG reset. Let SCH trigger it. */
477 errInfo->errCause = RGERR_NONE;
478 RGDBGINFO(inst,(rgPBuf(inst), "CRG UE Reset processed \n"));
480 } /* rgCOMHndlResetReq */
481 /*End: LTEMAC_2.1_DEV_CFG */
484 * @brief Handler for processing Cell/UE/Logical channel delete request
489 * Function: rgCOMHndlDelReq
491 * This API handles processing of delete request from RRC to MAC.
494 * - Fetch corresponding control block and pass it to CFG module.
495 * - If control block does not exist, FAIL.
497 * @param[in] Inst inst
498 * @param[in] CrgDel *del
499 * @param[out] RgErrInfo *errInfo
500 @param[out] Bool *isCfmRqrd
506 PRIVATE S16 rgCOMHndlDelReq
512 CrgCfgTransId transId
515 PRIVATE S16 rgCOMHndlDelReq(inst,del, errInfo,isCfmRqrd,transId)
520 CrgCfgTransId transId;
525 VOLATILE U32 startTime=0;
527 TRC2(rgCOMHndlDelReq);
529 errInfo->errType = RGERR_COM_DEL_REQ;
531 /* Process the delete request */
532 switch (del->delType)
536 ret = rgCFGCrgCellDel(inst,del, errInfo);
542 SStartTask(&startTime,PID_MAC_UE_DEL);
545 ret = rgCFGCrgUeDel(inst,del, errInfo);
546 RGDBGINFONEW(inst,(rgPBuf(inst),"[%d] Delete UE Done \n", del->u.ueDel.crnti));
549 SStopTask(startTime,PID_MAC_UE_DEL);
555 ret = rgCFGCrgLcDel(inst,del, errInfo,isCfmRqrd, transId);
560 RLOG1(L_ERROR, "Should never come here: delType %d",
567 } /* rgCOMHndlDelReq */
571 * @brief Handler for the SCell configuration request from RRC to MAC.
575 * Function : RgPrgPMacSMacUeSCellCfgReq
578 * - Allocate and create UE control block.
579 * - Update UE control block with the values recieved in the
581 * - If successful, add the control block to hash list of UEs for the cell
582 * else Rollback and FAIL.
584 * @param[in] Pst *pst
585 * @param[in] RgPrgUeSCellCfgInfo *ueSCellCb
591 PUBLIC S16 RgPrgPMacSMacUeSCellCfgReq
594 RgPrgUeSCellCfgInfo *ueSCellCb
597 PUBLIC S16 RgPrgPMacSMacUeSCellCfgReq(pst, ueSCellCb)
599 RgPrgUeSCellCfgInfo *ueSCellCb;
602 RgPrgCfgCfmInfo cfgCfm;
603 Inst inst = pst->dstInst;
604 RgCellCb *cell = rgCb[inst].cell;
608 TRC2(RgPrgPMacSMacUeSCellCfgReq);
610 RGDBGPRM(inst,(rgPBuf(inst),
611 "APPLYING CRG UE SCELL CONFIG: cellId %d ueId %d\n",
612 ueSCellCb->cellId, ueSCellCb->ueId));
614 cfgCfm.ueId = ueSCellCb->ueId;
615 cfgCfm.sCellId = ueSCellCb->cellId;
616 cfgCfm.status = PRG_CFG_CFM_OK;
617 cfgCfm.event = EVTPRGUESCELLCFGCFM;
618 rgGetPstToInst(&cfmPst, inst, pst->srcInst);
620 ret = rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst);
623 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
624 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
625 /* Set status as Not OK*/
626 cfgCfm.status = PRG_CFG_CFM_NOK;
630 ret = rgCfgAddUeSCellCfg(inst, ueSCellCb, cell);
633 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
634 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
635 /* Set status as Not OK*/
636 cfgCfm.status = PRG_CFG_CFM_NOK;
640 RGDBGINFONEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell Config done:\
641 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
643 /* Send positive confirmation to primary cell*/
644 RgPrgSMacPMacCfg(&cfmPst, &cfgCfm);
646 } /* RgPrgPMacSMacUeSCellCfgReq */
649 * @brief Hander for config confim from sec MAC to Pri mac for Add Scell Cfg.
653 * Function : RgPrgSMacPMacCfgCfm
656 * - Allocate and create UE control block.
657 * - If cfm event is lch recfg then send the confirmation to RRC for
659 * - If cfm event is Scell addition then send the confirmation to RRC for
661 * - Update UE control block with the values received in the
663 * - If successful, add the control block to hash list of UEs for the cell
664 * else Rollback and FAIL.
666 * @param[in] Inst dstMacInst
667 * @param[in] RgUrSCellCb *ueSCellCb
673 PUBLIC S16 RgPrgSMacPMacCfgCfm
676 RgPrgCfgCfmInfo *cfgCfm
679 PUBLIC S16 RgPrgSMacPMacCfgCfm(pst, cfgCfm)
681 RgPrgCfgCfmInfo *cfgCfm;
684 Inst inst = pst->dstInst;
687 TRC2(RgPrgSMacPMacCfgCfm);
690 RG_IS_INST_VALID(inst);
692 RGDBGPRM(pst->dstInst,(rgPBuf(pst->dstInst),
693 "Config Confirm Rcvd from Inst %d ueId %d cellId %d\n",
694 pst->srcInst, cfgCfm->ueId, cfgCfm->cellId));
696 cell = rgCb[inst].cell;
698 if ((ue = rgDBMGetUeCb(cell, cfgCfm->ueId)) == NULLP)
700 RGDBGERRNEW(inst,(rgPBuf(inst),
701 "[%d]Ue does not exist\n", cfgCfm->ueId));
704 switch(cfgCfm->event)
706 /* cfgCount increment for all cases */
707 case EVTPRGUESCELLLCHMODCFM:
708 case EVTPRGUESCELLLCHDELCFM:
709 case EVTPRGUESCELLLCHADDCFM:
711 ue->cfgCfmInfo.cfgCfgCount++;
712 ue->cfgCfmInfo.mask |= cfgCfm->status;
713 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
715 ue->cfgCfmInfo.cfgCfgCount = 0;
716 /* Send back confirmation status to RRC */
717 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
718 ue->cfgCfmInfo.mask = 0;
719 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
723 case EVTPRGUESCELLCFGCFM:
725 /*Commit Added SCell info to UeCb as we confirmation received */
726 if(PRG_CFG_CFM_OK == cfgCfm->status)
728 ue->sCelInfo[pst->srcInst].isSCellAdded = TRUE;
729 ue->sCelInfo[pst->srcInst].macInst = pst->srcInst;
730 ue->sCelInfo[pst->srcInst].sCellId = cfgCfm->sCellId;
733 ue->cfgCfmInfo.cfgCfgCount++;
734 ue->cfgCfmInfo.mask |= cfgCfm->status;
735 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
737 ue->cfgCfmInfo.cfgCfgCount = 0;
738 /* Send back confirmation status to RRC */
739 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
740 ue->cfgCfmInfo.mask = 0;
741 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
747 RGDBGERRNEW(inst,(rgPBuf(inst), "Invalid configuration confirm event %d\n",
755 } /* RgPrgSMacPMacCfgCfm */
758 * @brief Function for handling UE release for SCELL
759 * triggered from Primary Cell
763 * Function : RgPrgPMacSMacUeSCellDelReq
765 * - This Function should be invoked by PCell of UE
766 * - Remove the UE context from SCELL corresponding to rnti.
768 * @param[in] Pst *pst
769 * @param[in] RgPrgUeSCellDelInfo *ueSCellDelInfo
770 * @return ROK is SUCCESS
773 PUBLIC S16 RgPrgPMacSMacUeSCellDelReq
776 RgPrgUeSCellDelInfo *ueSCellDelInfo
779 PUBLIC S16 RgPrgPMacSMacUeSCellDelReq(pst, ueSCellDelInfo)
781 RgPrgUeSCellDelInfo *ueSCellDelInfo;
784 Inst inst = pst->dstInst - RG_INST_START;
785 RgCellCb *sCell = rgCb[inst].cell;
786 RgUeCb *sCellUe = NULLP;
788 TRC2(RgPrgPMacSMacUeSCellDelReq)
790 /* Checking for cell Cb because in case of shutdownReq it is possible that
791 * cell is already deleted for this cell*/
796 /* Retrive the UeCb from sec cell*/
797 if ((sCellUe = rgDBMGetUeCb(sCell, ueSCellDelInfo->ueId)) == NULLP)
799 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:does not exist in sCell(%d)\n",
800 ueSCellDelInfo->ueId, sCell->cellId));
804 /*PMAC_Reest: ueId and newRnti is different that means its a UeId change
805 *request from PMAC to SMAC during PCell reestablishment
807 if(ueSCellDelInfo->ueId != ueSCellDelInfo->newRnti)
809 /* Retrive the UeCb from sec cell*/
810 if ((rgDBMGetUeCb(sCell, ueSCellDelInfo->newRnti)) != NULLP)
812 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:UE context already exist in\
813 sCell(%d)",ueSCellDelInfo->newRnti, sCell->cellId));
817 rgDBMDelUeCb(sCell, sCellUe);
819 sCellUe->ueId = ueSCellDelInfo->newRnti;
821 /* Reset harq procs*/
822 rgDHMUeReset(sCell, &sCellUe->dl.hqEnt);
824 rgDBMInsUeCb(sCell, sCellUe);
828 rgDBMDelUeCb(sCell, sCellUe);
829 rgCFGFreeUeCb(sCell, sCellUe);
833 } /* RgPrgPMacSMacUeSCellDelReq */
835 /**********************************************************************
838 **********************************************************************/