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*/
76 #include "du_app_mac_inf.h"
79 #include "rg_pom_scell.x"
82 PRIVATE S16 rgCOMHndlCfgReq ARGS((Inst inst,CrgCfg *cfg, RgErrInfo *errInfo,Bool *isCfmRqrd,CrgCfgTransId transId));
83 PRIVATE S16 rgCOMHndlRecfgReq ARGS((Inst inst,CrgRecfg *recfg, RgErrInfo *errInfo, \
84 CrgCfgTransId transId,Bool *isCfmRqrd));
85 PRIVATE S16 rgCOMHndlDelReq ARGS((Inst inst,CrgDel *del, RgErrInfo *errInfo, Bool *isCfmRqrd, CrgCfgTransId transId));
86 PRIVATE S16 rgCOMHndlResetReq ARGS((Inst inst,CrgRst *reset,RgErrInfo *errInfo));
91 /* forward references */
94 * @brief Handler to handle config request from RRC to MAC.
98 * Function: rgCOMCfgReq
100 * This API handles processing for config request from RRC to MAC.
103 * - If configuration, process configuration request. Call rgCOMHndlCfgReq.
104 * - else If re-configuration, process re-configuration request.
105 * Call rgCOMHndlRecfgReq.
106 * - else If reset, process reset request. Call rgCOMHndlResetReq.
107 * - else If delete, process delete request. Call rgCOMHndlDelReq.
108 * - If successful, send confirmation to RRC. Call rgUIMCrgCfgCfm.
111 * @param[in] Inst inst
112 * @param[in] CrgCfgTransId transId
113 * @param[in] CrgCfgReqInfo *crgCfgReq
119 PUBLIC S16 rgCOMCfgReq
122 CrgCfgTransId transId,
123 CrgCfgReqInfo *crgCfgReq
126 PUBLIC S16 rgCOMCfgReq(inst,transId, crgCfgReq)
128 CrgCfgTransId transId;
129 CrgCfgReqInfo *crgCfgReq;
133 U8 cfmStatus = CRG_CFG_CFM_OK;
135 Bool isCfmRqrd = TRUE;
139 /* Process Config/Reconfig/Delete request from RRC */
140 switch (crgCfgReq->action)
144 ret = rgCOMHndlCfgReq(inst,&crgCfgReq->u.cfgInfo, &errInfo,&isCfmRqrd, transId);
149 ret = rgCOMHndlRecfgReq(inst,&crgCfgReq->u.recfgInfo, &errInfo, transId, &isCfmRqrd);
152 /* Start: LTEMAC_2.1_DEV_CFG */
155 ret = rgCOMHndlResetReq(inst,&crgCfgReq->u.rstInfo, &errInfo);
158 /* End: LTEMAC_2.1_DEV_CFG */
161 ret = rgCOMHndlDelReq(inst,&crgCfgReq->u.delInfo, &errInfo, &isCfmRqrd, transId);
166 RLOG1(L_ERROR, "Invalid configuration action %d",
175 cfmStatus = CRG_CFG_CFM_NOK;
178 /* When UeSCellCfg is present then confirmation will be sent later once
179 confirm from all SMAC are recved at PMAC. PMAC will send a consolidated
180 confirm to RRC.Handling the failure of PMAC for Ue Scell add*/
182 if(TRUE == isCfmRqrd)
185 /* Send back confirmation status to RRC */
186 rgUIMCrgCfgCfm(inst,transId, cfmStatus);
190 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
194 * @brief Handler for processing Cell/Ue/Logical channel configuration request
199 * Function: rgCOMHndlCfgReq
201 * This API handles processing of configuration request from RRC to MAC.
204 * - Validate configuration request parameters at CFG module.
205 * Call rgCFGVldtCrgCellCfg, rgCFGVldtCrgUeCfg, rgCFGVldtCrgLcCfg
206 * for Cell, UE and Logical channel configuration respectively.
207 * - If validated successfully, Call rgCFGCrgCellCfg, rgCFGCrgUeCfg,
208 * rgCFGCrgLcCfg for Cell, UE and Logical channel configuration
209 * respectively, else FAIL.
211 * @param[in] Inst inst
212 * @param[in] CrgCfg *cfg
213 * @param[out] RgErrInfo *errInfo
219 PRIVATE S16 rgCOMHndlCfgReq
225 CrgCfgTransId transId
228 PRIVATE S16 rgCOMHndlCfgReq(inst,cfg, errInfo,isCfmRqrd,transId)
233 CrgCfgTransId transId;
237 RgCellCb *cell = NULLP;
240 TRC2(rgCOMHndlCfgReq);
242 errInfo->errType = RGERR_COM_CFG_REQ;
244 /* Validate and process the configuration request */
245 switch (cfg->cfgType)
249 ret = rgCFGVldtCrgCellCfg(inst,&cfg->u.cellCfg,errInfo);
252 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId, "Cell configuration validation FAILED\n");
255 ret = rgCFGCrgCellCfg(inst,&cfg->u.cellCfg, errInfo);
261 ret = rgCFGVldtCrgUeCfg(inst,&cfg->u.ueCfg, &cell, errInfo);
264 RLOG_ARG0(L_ERROR,DBG_CRNTI,cfg->u.ueCfg.crnti, "Ue configuration validation FAILED\n");
267 ret = rgCFGCrgUeCfg(inst,cell, &cfg->u.ueCfg, errInfo);
274 ret = rgCFGVldtCrgLcCfg(inst,&cfg->u.lchCfg, &cell, &ue,errInfo);
278 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId,
279 "LC configuration validation FAILED: LC %d\n", cfg->u.lchCfg.lcId);
282 ret = rgCFGCrgLcCfg(inst,cell, ue, &cfg->u.lchCfg, errInfo,isCfmRqrd,transId);
287 RLOG1(L_ERROR, "Should never come here: cfgType %d",cfg->cfgType);
293 } /* rgCOMHndlCfgReq */
297 * @brief Handler for processing Cell/Ue/Logical channel re-configuration request
302 * Function: rgCOMHndlRecfgReq
304 * This API handles processing of reconfiguration request from RRC to MAC.
307 * - Validate reconfiguration request parameters at CFG module. Call
308 * rgCFGVldtCrgCellRecfg, rgCFGVldtCrgUeRecfg, rgCFGVldtCrgLchRecfg for
309 * Cell, UE and logical channel reconfiguration respectively.
310 * - If validated, Call rgCFGCrgCellRecfg, rgCFGCrgUeRecfg,
311 * rgCFGCrgLchRecfg for Cell, UE and Logical channel re-configuration
312 * respectively else FAIL.
314 * @param[in] Inst inst
315 * @param[in] CrgRecfg *recfg
316 * @param[out] RgErrInfo *errInfo
322 PRIVATE S16 rgCOMHndlRecfgReq
327 CrgCfgTransId transId,
331 PRIVATE S16 rgCOMHndlRecfgReq(inst,recfg, errInfo, transId, isCfmRqrd)
335 CrgCfgTransId transId;
340 RgCellCb *cell = rgCb[inst].cell;
342 RgUlLcCb *ulLc = NULLP;
344 TRC2(rgCOMHndlRecfgReq);
346 errInfo->errType = RGERR_COM_RECFG_REQ;
348 /* Validate and process the re-configuration request */
349 switch (recfg->recfgType)
353 ret = rgCFGVldtCrgCellRecfg(inst,&recfg->u.cellRecfg, &cell, errInfo);
356 RLOG_ARG0(L_ERROR,DBG_CELLID,recfg->u.cellRecfg.cellId,
357 "Cell Recfg Validation FAILED");
360 ret = rgCFGCrgCellRecfg(inst,cell, &recfg->u.cellRecfg, errInfo);
365 /*ccpu00126865 - Added as a part of RRC Reestablishment issue with MAC
366 * having a possibility of sending NOK */
367 if (recfg->u.ueRecfg.oldCrnti != recfg->u.ueRecfg.newCrnti)
369 errInfo->errCause = RGERR_CFG_INVALID_CRG_UE_RECFG;
375 /* Check for isSCellCfgPres */
376 if(TRUE == recfg->u.ueRecfg.crgSCellCfg.isSCellCfgPres)
378 ret = rgFillAndAddSCellCfg(inst, cell, &recfg->u.ueRecfg, transId, isCfmRqrd);
381 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Ue SCell configuration FAILED for inst [%d]\n",
382 recfg->u.ueRecfg.oldCrnti, inst));
390 ret = rgCFGVldtCrgUeRecfg(inst,&recfg->u.ueRecfg, &cell, &ue, errInfo);
393 RLOG_ARG1(L_ERROR,DBG_CELLID,recfg->u.ueRecfg.cellId,
394 "Ue Re-configuration validation FAILED OLD CRNTI:%d",
395 recfg->u.ueRecfg.oldCrnti);
398 ret = rgCFGCrgUeRecfg(inst,cell, ue, &recfg->u.ueRecfg, errInfo);
407 ret = rgCFGVldtCrgLcRecfg(inst,&recfg->u.lchRecfg, &cell, &ue,
411 RLOG_ARG2(L_ERROR,DBG_CELLID,recfg->u.lchRecfg.cellId,
412 "LC Re-configuration validation FAILED LCID:%d CRNTI:%d",
413 recfg->u.lchRecfg.lcId,recfg->u.lchRecfg.crnti);
418 /*ERAB- multicell fix*/
419 cmMemcpy( (U8*)&(ue->cfgCfmInfo.transId), (U8*)&transId,
420 sizeof(CrgCfgTransId));
422 ret = rgCFGCrgLcRecfg(inst,cell, ue, ulLc,
423 &recfg->u.lchRecfg, errInfo,isCfmRqrd);
429 RLOG1(L_ERROR, "Should never come here: recfgType %d",
436 } /* rgCOMHndlRecfgReq */
438 /*Start: LTEMAC_2.1_DEV_CFG */
440 * @brief Handler for processing UE Reset request recieved from RRC.
444 * Function: rgCOMHndlResetReq
446 * This API handles processing of Reset request from RRC to MAC.
449 * - Validate reset request parameters at CFG module. Call
450 * rgCFGVldtCrgUeReset for UE reset.
451 * - If validated, Call rgCFGCrgUeReset for UE reset, else FAIL.
453 * @param[in] Inst inst
454 * @param[in] CrgRst *reset
455 * @param[out] RgErrInfo *errInfo
461 PRIVATE S16 rgCOMHndlResetReq
468 PRIVATE S16 rgCOMHndlResetReq(inst,reset, errInfo)
474 TRC2(rgCOMHndlResetReq);
476 /* Fix : ccpu00126865: ignore CRG reset. Let SCH trigger it. */
478 errInfo->errCause = RGERR_NONE;
479 RGDBGINFO(inst,(rgPBuf(inst), "CRG UE Reset processed \n"));
481 } /* rgCOMHndlResetReq */
482 /*End: LTEMAC_2.1_DEV_CFG */
485 * @brief Handler for processing Cell/UE/Logical channel delete request
490 * Function: rgCOMHndlDelReq
492 * This API handles processing of delete request from RRC to MAC.
495 * - Fetch corresponding control block and pass it to CFG module.
496 * - If control block does not exist, FAIL.
498 * @param[in] Inst inst
499 * @param[in] CrgDel *del
500 * @param[out] RgErrInfo *errInfo
501 @param[out] Bool *isCfmRqrd
507 PRIVATE S16 rgCOMHndlDelReq
513 CrgCfgTransId transId
516 PRIVATE S16 rgCOMHndlDelReq(inst,del, errInfo,isCfmRqrd,transId)
521 CrgCfgTransId transId;
526 VOLATILE U32 startTime=0;
528 TRC2(rgCOMHndlDelReq);
530 errInfo->errType = RGERR_COM_DEL_REQ;
532 /* Process the delete request */
533 switch (del->delType)
537 ret = rgCFGCrgCellDel(inst,del, errInfo);
543 SStartTask(&startTime,PID_MAC_UE_DEL);
546 ret = rgCFGCrgUeDel(inst,del, errInfo);
547 RGDBGINFONEW(inst,(rgPBuf(inst),"[%d] Delete UE Done \n", del->u.ueDel.crnti));
550 SStopTask(startTime,PID_MAC_UE_DEL);
556 ret = rgCFGCrgLcDel(inst,del, errInfo,isCfmRqrd, transId);
561 RLOG1(L_ERROR, "Should never come here: delType %d",
568 } /* rgCOMHndlDelReq */
572 * @brief Handler for the SCell configuration request from RRC to MAC.
576 * Function : RgPrgPMacSMacUeSCellCfgReq
579 * - Allocate and create UE control block.
580 * - Update UE control block with the values recieved in the
582 * - If successful, add the control block to hash list of UEs for the cell
583 * else Rollback and FAIL.
585 * @param[in] Pst *pst
586 * @param[in] RgPrgUeSCellCfgInfo *ueSCellCb
592 PUBLIC S16 RgPrgPMacSMacUeSCellCfgReq
595 RgPrgUeSCellCfgInfo *ueSCellCb
598 PUBLIC S16 RgPrgPMacSMacUeSCellCfgReq(pst, ueSCellCb)
600 RgPrgUeSCellCfgInfo *ueSCellCb;
603 RgPrgCfgCfmInfo cfgCfm;
604 Inst inst = pst->dstInst;
605 RgCellCb *cell = rgCb[inst].cell;
609 TRC2(RgPrgPMacSMacUeSCellCfgReq);
611 RGDBGPRM(inst,(rgPBuf(inst),
612 "APPLYING CRG UE SCELL CONFIG: cellId %d ueId %d\n",
613 ueSCellCb->cellId, ueSCellCb->ueId));
615 cfgCfm.ueId = ueSCellCb->ueId;
616 cfgCfm.sCellId = ueSCellCb->cellId;
617 cfgCfm.status = PRG_CFG_CFM_OK;
618 cfgCfm.event = EVTPRGUESCELLCFGCFM;
619 rgGetPstToInst(&cfmPst, inst, pst->srcInst);
621 ret = rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst);
624 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
625 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
626 /* Set status as Not OK*/
627 cfgCfm.status = PRG_CFG_CFM_NOK;
631 ret = rgCfgAddUeSCellCfg(inst, ueSCellCb, cell);
634 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
635 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
636 /* Set status as Not OK*/
637 cfgCfm.status = PRG_CFG_CFM_NOK;
641 RGDBGINFONEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell Config done:\
642 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
644 /* Send positive confirmation to primary cell*/
645 RgPrgSMacPMacCfg(&cfmPst, &cfgCfm);
647 } /* RgPrgPMacSMacUeSCellCfgReq */
650 * @brief Hander for config confim from sec MAC to Pri mac for Add Scell Cfg.
654 * Function : RgPrgSMacPMacCfgCfm
657 * - Allocate and create UE control block.
658 * - If cfm event is lch recfg then send the confirmation to RRC for
660 * - If cfm event is Scell addition then send the confirmation to RRC for
662 * - Update UE control block with the values received in the
664 * - If successful, add the control block to hash list of UEs for the cell
665 * else Rollback and FAIL.
667 * @param[in] Inst dstMacInst
668 * @param[in] RgUrSCellCb *ueSCellCb
674 PUBLIC S16 RgPrgSMacPMacCfgCfm
677 RgPrgCfgCfmInfo *cfgCfm
680 PUBLIC S16 RgPrgSMacPMacCfgCfm(pst, cfgCfm)
682 RgPrgCfgCfmInfo *cfgCfm;
685 Inst inst = pst->dstInst;
688 TRC2(RgPrgSMacPMacCfgCfm);
691 RG_IS_INST_VALID(inst);
693 RGDBGPRM(pst->dstInst,(rgPBuf(pst->dstInst),
694 "Config Confirm Rcvd from Inst %d ueId %d cellId %d\n",
695 pst->srcInst, cfgCfm->ueId, cfgCfm->cellId));
697 cell = rgCb[inst].cell;
699 if ((ue = rgDBMGetUeCb(cell, cfgCfm->ueId)) == NULLP)
701 RGDBGERRNEW(inst,(rgPBuf(inst),
702 "[%d]Ue does not exist\n", cfgCfm->ueId));
705 switch(cfgCfm->event)
707 /* cfgCount increment for all cases */
708 case EVTPRGUESCELLLCHMODCFM:
709 case EVTPRGUESCELLLCHDELCFM:
710 case EVTPRGUESCELLLCHADDCFM:
712 ue->cfgCfmInfo.cfgCfgCount++;
713 ue->cfgCfmInfo.mask |= cfgCfm->status;
714 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
716 ue->cfgCfmInfo.cfgCfgCount = 0;
717 /* Send back confirmation status to RRC */
718 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
719 ue->cfgCfmInfo.mask = 0;
720 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
724 case EVTPRGUESCELLCFGCFM:
726 /*Commit Added SCell info to UeCb as we confirmation received */
727 if(PRG_CFG_CFM_OK == cfgCfm->status)
729 ue->sCelInfo[pst->srcInst].isSCellAdded = TRUE;
730 ue->sCelInfo[pst->srcInst].macInst = pst->srcInst;
731 ue->sCelInfo[pst->srcInst].sCellId = cfgCfm->sCellId;
734 ue->cfgCfmInfo.cfgCfgCount++;
735 ue->cfgCfmInfo.mask |= cfgCfm->status;
736 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
738 ue->cfgCfmInfo.cfgCfgCount = 0;
739 /* Send back confirmation status to RRC */
740 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
741 ue->cfgCfmInfo.mask = 0;
742 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
748 RGDBGERRNEW(inst,(rgPBuf(inst), "Invalid configuration confirm event %d\n",
756 } /* RgPrgSMacPMacCfgCfm */
759 * @brief Function for handling UE release for SCELL
760 * triggered from Primary Cell
764 * Function : RgPrgPMacSMacUeSCellDelReq
766 * - This Function should be invoked by PCell of UE
767 * - Remove the UE context from SCELL corresponding to rnti.
769 * @param[in] Pst *pst
770 * @param[in] RgPrgUeSCellDelInfo *ueSCellDelInfo
771 * @return ROK is SUCCESS
774 PUBLIC S16 RgPrgPMacSMacUeSCellDelReq
777 RgPrgUeSCellDelInfo *ueSCellDelInfo
780 PUBLIC S16 RgPrgPMacSMacUeSCellDelReq(pst, ueSCellDelInfo)
782 RgPrgUeSCellDelInfo *ueSCellDelInfo;
785 Inst inst = pst->dstInst - RG_INST_START;
786 RgCellCb *sCell = rgCb[inst].cell;
787 RgUeCb *sCellUe = NULLP;
789 TRC2(RgPrgPMacSMacUeSCellDelReq)
791 /* Checking for cell Cb because in case of shutdownReq it is possible that
792 * cell is already deleted for this cell*/
797 /* Retrive the UeCb from sec cell*/
798 if ((sCellUe = rgDBMGetUeCb(sCell, ueSCellDelInfo->ueId)) == NULLP)
800 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:does not exist in sCell(%d)\n",
801 ueSCellDelInfo->ueId, sCell->cellId));
805 /*PMAC_Reest: ueId and newRnti is different that means its a UeId change
806 *request from PMAC to SMAC during PCell reestablishment
808 if(ueSCellDelInfo->ueId != ueSCellDelInfo->newRnti)
810 /* Retrive the UeCb from sec cell*/
811 if ((rgDBMGetUeCb(sCell, ueSCellDelInfo->newRnti)) != NULLP)
813 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:UE context already exist in\
814 sCell(%d)",ueSCellDelInfo->newRnti, sCell->cellId));
818 rgDBMDelUeCb(sCell, sCellUe);
820 sCellUe->ueId = ueSCellDelInfo->newRnti;
822 /* Reset harq procs*/
823 rgDHMUeReset(sCell, &sCellUe->dl.hqEnt);
825 rgDBMInsUeCb(sCell, sCellUe);
829 rgDBMDelUeCb(sCell, sCellUe);
830 rgCFGFreeUeCb(sCell, sCellUe);
834 } /* RgPrgPMacSMacUeSCellDelReq */
836 /**********************************************************************
839 **********************************************************************/