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;
119 /* Process Config/Reconfig/Delete request from RRC */
120 switch (crgCfgReq->action)
124 ret = rgCOMHndlCfgReq(inst,&crgCfgReq->u.cfgInfo, &errInfo,&isCfmRqrd, transId);
129 ret = rgCOMHndlRecfgReq(inst,&crgCfgReq->u.recfgInfo, &errInfo, transId, &isCfmRqrd);
132 /* Start: LTEMAC_2.1_DEV_CFG */
135 ret = rgCOMHndlResetReq(inst,&crgCfgReq->u.rstInfo, &errInfo);
138 /* End: LTEMAC_2.1_DEV_CFG */
141 ret = rgCOMHndlDelReq(inst,&crgCfgReq->u.delInfo, &errInfo, &isCfmRqrd, transId);
146 RLOG1(L_ERROR, "Invalid configuration action %d",
155 cfmStatus = CRG_CFG_CFM_NOK;
158 /* When UeSCellCfg is present then confirmation will be sent later once
159 confirm from all SMAC are recved at PMAC. PMAC will send a consolidated
160 confirm to RRC.Handling the failure of PMAC for Ue Scell add*/
162 if(TRUE == isCfmRqrd)
165 /* Send back confirmation status to RRC */
166 rgUIMCrgCfgCfm(inst,transId, cfmStatus);
170 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
174 * @brief Handler for processing Cell/Ue/Logical channel configuration request
179 * Function: rgCOMHndlCfgReq
181 * This API handles processing of configuration request from RRC to MAC.
184 * - Validate configuration request parameters at CFG module.
185 * Call rgCFGVldtCrgCellCfg, rgCFGVldtCrgUeCfg, rgCFGVldtCrgLcCfg
186 * for Cell, UE and Logical channel configuration respectively.
187 * - If validated successfully, Call rgCFGCrgCellCfg, rgCFGCrgUeCfg,
188 * rgCFGCrgLcCfg for Cell, UE and Logical channel configuration
189 * respectively, else FAIL.
191 * @param[in] Inst inst
192 * @param[in] CrgCfg *cfg
193 * @param[out] RgErrInfo *errInfo
199 PRIVATE S16 rgCOMHndlCfgReq
205 CrgCfgTransId transId
208 PRIVATE S16 rgCOMHndlCfgReq(inst,cfg, errInfo,isCfmRqrd,transId)
213 CrgCfgTransId transId;
217 RgCellCb *cell = NULLP;
220 errInfo->errType = RGERR_COM_CFG_REQ;
222 /* Validate and process the configuration request */
223 switch (cfg->cfgType)
227 ret = rgCFGVldtCrgCellCfg(inst,&cfg->u.cellCfg,errInfo);
230 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId, "Cell configuration validation FAILED\n");
233 ret = rgCFGCrgCellCfg(inst,&cfg->u.cellCfg, errInfo);
239 ret = rgCFGVldtCrgUeCfg(inst,&cfg->u.ueCfg, &cell, errInfo);
242 RLOG_ARG0(L_ERROR,DBG_CRNTI,cfg->u.ueCfg.crnti, "Ue configuration validation FAILED\n");
245 ret = rgCFGCrgUeCfg(inst,cell, &cfg->u.ueCfg, errInfo);
252 ret = rgCFGVldtCrgLcCfg(inst,&cfg->u.lchCfg, &cell, &ue,errInfo);
256 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId,
257 "LC configuration validation FAILED: LC %d\n", cfg->u.lchCfg.lcId);
260 ret = rgCFGCrgLcCfg(inst,cell, ue, &cfg->u.lchCfg, errInfo,isCfmRqrd,transId);
265 RLOG1(L_ERROR, "Should never come here: cfgType %d",cfg->cfgType);
271 } /* rgCOMHndlCfgReq */
275 * @brief Handler for processing Cell/Ue/Logical channel re-configuration request
280 * Function: rgCOMHndlRecfgReq
282 * This API handles processing of reconfiguration request from RRC to MAC.
285 * - Validate reconfiguration request parameters at CFG module. Call
286 * rgCFGVldtCrgCellRecfg, rgCFGVldtCrgUeRecfg, rgCFGVldtCrgLchRecfg for
287 * Cell, UE and logical channel reconfiguration respectively.
288 * - If validated, Call rgCFGCrgCellRecfg, rgCFGCrgUeRecfg,
289 * rgCFGCrgLchRecfg for Cell, UE and Logical channel re-configuration
290 * respectively else FAIL.
292 * @param[in] Inst inst
293 * @param[in] CrgRecfg *recfg
294 * @param[out] RgErrInfo *errInfo
300 PRIVATE S16 rgCOMHndlRecfgReq
305 CrgCfgTransId transId,
309 PRIVATE S16 rgCOMHndlRecfgReq(inst,recfg, errInfo, transId, isCfmRqrd)
313 CrgCfgTransId transId;
318 RgCellCb *cell = rgCb[inst].cell;
320 RgUlLcCb *ulLc = NULLP;
322 errInfo->errType = RGERR_COM_RECFG_REQ;
324 /* Validate and process the re-configuration request */
325 switch (recfg->recfgType)
329 ret = rgCFGVldtCrgCellRecfg(inst,&recfg->u.cellRecfg, &cell, errInfo);
332 RLOG_ARG0(L_ERROR,DBG_CELLID,recfg->u.cellRecfg.cellId,
333 "Cell Recfg Validation FAILED");
336 ret = rgCFGCrgCellRecfg(inst,cell, &recfg->u.cellRecfg, errInfo);
341 /*ccpu00126865 - Added as a part of RRC Reestablishment issue with MAC
342 * having a possibility of sending NOK */
343 if (recfg->u.ueRecfg.oldCrnti != recfg->u.ueRecfg.newCrnti)
345 errInfo->errCause = RGERR_CFG_INVALID_CRG_UE_RECFG;
351 /* Check for isSCellCfgPres */
352 if(TRUE == recfg->u.ueRecfg.crgSCellCfg.isSCellCfgPres)
354 ret = rgFillAndAddSCellCfg(inst, cell, &recfg->u.ueRecfg, transId, isCfmRqrd);
357 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Ue SCell configuration FAILED for inst [%d]\n",
358 recfg->u.ueRecfg.oldCrnti, inst));
366 ret = rgCFGVldtCrgUeRecfg(inst,&recfg->u.ueRecfg, &cell, &ue, errInfo);
369 RLOG_ARG1(L_ERROR,DBG_CELLID,recfg->u.ueRecfg.cellId,
370 "Ue Re-configuration validation FAILED OLD CRNTI:%d",
371 recfg->u.ueRecfg.oldCrnti);
374 ret = rgCFGCrgUeRecfg(inst,cell, ue, &recfg->u.ueRecfg, errInfo);
383 ret = rgCFGVldtCrgLcRecfg(inst,&recfg->u.lchRecfg, &cell, &ue,
387 RLOG_ARG2(L_ERROR,DBG_CELLID,recfg->u.lchRecfg.cellId,
388 "LC Re-configuration validation FAILED LCID:%d CRNTI:%d",
389 recfg->u.lchRecfg.lcId,recfg->u.lchRecfg.crnti);
394 /*ERAB- multicell fix*/
395 memcpy( &(ue->cfgCfmInfo.transId), &transId,
396 sizeof(CrgCfgTransId));
398 ret = rgCFGCrgLcRecfg(inst,cell, ue, ulLc,
399 &recfg->u.lchRecfg, errInfo,isCfmRqrd);
405 RLOG1(L_ERROR, "Should never come here: recfgType %d",
412 } /* rgCOMHndlRecfgReq */
414 /*Start: LTEMAC_2.1_DEV_CFG */
416 * @brief Handler for processing UE Reset request recieved from RRC.
420 * Function: rgCOMHndlResetReq
422 * This API handles processing of Reset request from RRC to MAC.
425 * - Validate reset request parameters at CFG module. Call
426 * rgCFGVldtCrgUeReset for UE reset.
427 * - If validated, Call rgCFGCrgUeReset for UE reset, else FAIL.
429 * @param[in] Inst inst
430 * @param[in] CrgRst *reset
431 * @param[out] RgErrInfo *errInfo
437 PRIVATE S16 rgCOMHndlResetReq
444 PRIVATE S16 rgCOMHndlResetReq(inst,reset, errInfo)
450 /* Fix : ccpu00126865: ignore CRG reset. Let SCH trigger it. */
452 errInfo->errCause = RGERR_NONE;
453 RGDBGINFO(inst,(rgPBuf(inst), "CRG UE Reset processed \n"));
455 } /* rgCOMHndlResetReq */
456 /*End: LTEMAC_2.1_DEV_CFG */
459 * @brief Handler for processing Cell/UE/Logical channel delete request
464 * Function: rgCOMHndlDelReq
466 * This API handles processing of delete request from RRC to MAC.
469 * - Fetch corresponding control block and pass it to CFG module.
470 * - If control block does not exist, FAIL.
472 * @param[in] Inst inst
473 * @param[in] CrgDel *del
474 * @param[out] RgErrInfo *errInfo
475 @param[out] Bool *isCfmRqrd
481 PRIVATE S16 rgCOMHndlDelReq
487 CrgCfgTransId transId
490 PRIVATE S16 rgCOMHndlDelReq(inst,del, errInfo,isCfmRqrd,transId)
495 CrgCfgTransId transId;
500 VOLATILE U32 startTime=0;
502 errInfo->errType = RGERR_COM_DEL_REQ;
504 /* Process the delete request */
505 switch (del->delType)
509 ret = rgCFGCrgCellDel(inst,del, errInfo);
515 SStartTask(&startTime,PID_MAC_UE_DEL);
518 ret = rgCFGCrgUeDel(inst,del, errInfo);
519 RGDBGINFONEW(inst,(rgPBuf(inst),"[%d] Delete UE Done \n", del->u.ueDel.crnti));
522 SStopTask(startTime,PID_MAC_UE_DEL);
528 ret = rgCFGCrgLcDel(inst,del, errInfo,isCfmRqrd, transId);
533 RLOG1(L_ERROR, "Should never come here: delType %d",
540 } /* rgCOMHndlDelReq */
544 * @brief Handler for the SCell configuration request from RRC to MAC.
548 * Function : RgPrgPMacSMacUeSCellCfgReq
551 * - Allocate and create UE control block.
552 * - Update UE control block with the values recieved in the
554 * - If successful, add the control block to hash list of UEs for the cell
555 * else Rollback and FAIL.
557 * @param[in] Pst *pst
558 * @param[in] RgPrgUeSCellCfgInfo *ueSCellCb
564 S16 RgPrgPMacSMacUeSCellCfgReq
567 RgPrgUeSCellCfgInfo *ueSCellCb
570 S16 RgPrgPMacSMacUeSCellCfgReq(pst, ueSCellCb)
572 RgPrgUeSCellCfgInfo *ueSCellCb;
575 RgPrgCfgCfmInfo cfgCfm;
576 Inst inst = pst->dstInst;
577 RgCellCb *cell = rgCb[inst].cell;
582 RGDBGPRM(inst,(rgPBuf(inst),
583 "APPLYING CRG UE SCELL CONFIG: cellId %d ueId %d\n",
584 ueSCellCb->cellId, ueSCellCb->ueId));
586 cfgCfm.ueId = ueSCellCb->ueId;
587 cfgCfm.sCellId = ueSCellCb->cellId;
588 cfgCfm.status = PRG_CFG_CFM_OK;
589 cfgCfm.event = EVTPRGUESCELLCFGCFM;
590 rgGetPstToInst(&cfmPst, inst, pst->srcInst);
592 ret = rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst);
595 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
596 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
597 /* Set status as Not OK*/
598 cfgCfm.status = PRG_CFG_CFM_NOK;
602 ret = rgCfgAddUeSCellCfg(inst, ueSCellCb, cell);
605 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
606 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
607 /* Set status as Not OK*/
608 cfgCfm.status = PRG_CFG_CFM_NOK;
612 RGDBGINFONEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell Config done:\
613 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
615 /* Send positive confirmation to primary cell*/
616 RgPrgSMacPMacCfg(&cfmPst, &cfgCfm);
618 } /* RgPrgPMacSMacUeSCellCfgReq */
621 * @brief Hander for config confim from sec MAC to Pri mac for Add Scell Cfg.
625 * Function : RgPrgSMacPMacCfgCfm
628 * - Allocate and create UE control block.
629 * - If cfm event is lch recfg then send the confirmation to RRC for
631 * - If cfm event is Scell addition then send the confirmation to RRC for
633 * - Update UE control block with the values received in the
635 * - If successful, add the control block to hash list of UEs for the cell
636 * else Rollback and FAIL.
638 * @param[in] Inst dstMacInst
639 * @param[in] RgUrSCellCb *ueSCellCb
645 S16 RgPrgSMacPMacCfgCfm
648 RgPrgCfgCfmInfo *cfgCfm
651 S16 RgPrgSMacPMacCfgCfm(pst, cfgCfm)
653 RgPrgCfgCfmInfo *cfgCfm;
656 Inst inst = pst->dstInst;
660 RG_IS_INST_VALID(inst);
662 RGDBGPRM(pst->dstInst,(rgPBuf(pst->dstInst),
663 "Config Confirm Rcvd from Inst %d ueId %d cellId %d\n",
664 pst->srcInst, cfgCfm->ueId, cfgCfm->cellId));
666 cell = rgCb[inst].cell;
668 if ((ue = rgDBMGetUeCb(cell, cfgCfm->ueId)) == NULLP)
670 RGDBGERRNEW(inst,(rgPBuf(inst),
671 "[%d]Ue does not exist\n", cfgCfm->ueId));
674 switch(cfgCfm->event)
676 /* cfgCount increment for all cases */
677 case EVTPRGUESCELLLCHMODCFM:
678 case EVTPRGUESCELLLCHDELCFM:
679 case EVTPRGUESCELLLCHADDCFM:
681 ue->cfgCfmInfo.cfgCfgCount++;
682 ue->cfgCfmInfo.mask |= cfgCfm->status;
683 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
685 ue->cfgCfmInfo.cfgCfgCount = 0;
686 /* Send back confirmation status to RRC */
687 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
688 ue->cfgCfmInfo.mask = 0;
689 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
693 case EVTPRGUESCELLCFGCFM:
695 /*Commit Added SCell info to UeCb as we confirmation received */
696 if(PRG_CFG_CFM_OK == cfgCfm->status)
698 ue->sCelInfo[pst->srcInst].isSCellAdded = TRUE;
699 ue->sCelInfo[pst->srcInst].macInst = pst->srcInst;
700 ue->sCelInfo[pst->srcInst].sCellId = cfgCfm->sCellId;
703 ue->cfgCfmInfo.cfgCfgCount++;
704 ue->cfgCfmInfo.mask |= cfgCfm->status;
705 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
707 ue->cfgCfmInfo.cfgCfgCount = 0;
708 /* Send back confirmation status to RRC */
709 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
710 ue->cfgCfmInfo.mask = 0;
711 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
717 RGDBGERRNEW(inst,(rgPBuf(inst), "Invalid configuration confirm event %d\n",
725 } /* RgPrgSMacPMacCfgCfm */
728 * @brief Function for handling UE release for SCELL
729 * triggered from Primary Cell
733 * Function : RgPrgPMacSMacUeSCellDelReq
735 * - This Function should be invoked by PCell of UE
736 * - Remove the UE context from SCELL corresponding to rnti.
738 * @param[in] Pst *pst
739 * @param[in] RgPrgUeSCellDelInfo *ueSCellDelInfo
740 * @return ROK is SUCCESS
743 S16 RgPrgPMacSMacUeSCellDelReq
746 RgPrgUeSCellDelInfo *ueSCellDelInfo
749 S16 RgPrgPMacSMacUeSCellDelReq(pst, ueSCellDelInfo)
751 RgPrgUeSCellDelInfo *ueSCellDelInfo;
754 Inst inst = pst->dstInst - RG_INST_START;
755 RgCellCb *sCell = rgCb[inst].cell;
756 RgUeCb *sCellUe = NULLP;
758 /* Checking for cell Cb because in case of shutdownReq it is possible that
759 * cell is already deleted for this cell*/
764 /* Retrive the UeCb from sec cell*/
765 if ((sCellUe = rgDBMGetUeCb(sCell, ueSCellDelInfo->ueId)) == NULLP)
767 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:does not exist in sCell(%d)\n",
768 ueSCellDelInfo->ueId, sCell->cellId));
772 /*PMAC_Reest: ueId and newRnti is different that means its a UeId change
773 *request from PMAC to SMAC during PCell reestablishment
775 if(ueSCellDelInfo->ueId != ueSCellDelInfo->newRnti)
777 /* Retrive the UeCb from sec cell*/
778 if ((rgDBMGetUeCb(sCell, ueSCellDelInfo->newRnti)) != NULLP)
780 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:UE context already exist in\
781 sCell(%d)",ueSCellDelInfo->newRnti, sCell->cellId));
785 rgDBMDelUeCb(sCell, sCellUe);
787 sCellUe->ueId = ueSCellDelInfo->newRnti;
789 /* Reset harq procs*/
790 rgDHMUeReset(sCell, &sCellUe->dl.hqEnt);
792 rgDBMInsUeCb(sCell, sCellUe);
796 rgDBMDelUeCb(sCell, sCellUe);
797 rgCFGFreeUeCb(sCell, sCellUe);
801 } /* RgPrgPMacSMacUeSCellDelReq */
803 /**********************************************************************
806 **********************************************************************/