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 static S16 rgCOMHndlCfgReq ARGS((Inst inst,CrgCfg *cfg, RgErrInfo *errInfo,Bool *isCfmRqrd,CrgCfgTransId transId));
65 static S16 rgCOMHndlRecfgReq ARGS((Inst inst,CrgRecfg *recfg, RgErrInfo *errInfo, \
66 CrgCfgTransId transId,Bool *isCfmRqrd));
67 static S16 rgCOMHndlDelReq ARGS((Inst inst,CrgDel *del, RgErrInfo *errInfo, Bool *isCfmRqrd, CrgCfgTransId transId));
68 static 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
103 CrgCfgTransId transId,
104 CrgCfgReqInfo *crgCfgReq
108 uint8_t cfmStatus = CRG_CFG_CFM_OK;
110 Bool isCfmRqrd = TRUE;
112 /* Process Config/Reconfig/Delete request from RRC */
113 switch (crgCfgReq->action)
117 ret = rgCOMHndlCfgReq(inst,&crgCfgReq->u.cfgInfo, &errInfo,&isCfmRqrd, transId);
122 ret = rgCOMHndlRecfgReq(inst,&crgCfgReq->u.recfgInfo, &errInfo, transId, &isCfmRqrd);
125 /* Start: LTEMAC_2.1_DEV_CFG */
128 ret = rgCOMHndlResetReq(inst,&crgCfgReq->u.rstInfo, &errInfo);
131 /* End: LTEMAC_2.1_DEV_CFG */
134 ret = rgCOMHndlDelReq(inst,&crgCfgReq->u.delInfo, &errInfo, &isCfmRqrd, transId);
139 RLOG1(L_ERROR, "Invalid configuration action %d",
148 cfmStatus = CRG_CFG_CFM_NOK;
151 /* When UeSCellCfg is present then confirmation will be sent later once
152 confirm from all SMAC are recved at PMAC. PMAC will send a consolidated
153 confirm to RRC.Handling the failure of PMAC for Ue Scell add*/
155 if(TRUE == isCfmRqrd)
158 /* Send back confirmation status to RRC */
159 rgUIMCrgCfgCfm(inst,transId, cfmStatus);
163 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
167 * @brief Handler for processing Cell/Ue/Logical channel configuration request
172 * Function: rgCOMHndlCfgReq
174 * This API handles processing of configuration request from RRC to MAC.
177 * - Validate configuration request parameters at CFG module.
178 * Call rgCFGVldtCrgCellCfg, rgCFGVldtCrgUeCfg, rgCFGVldtCrgLcCfg
179 * for Cell, UE and Logical channel configuration respectively.
180 * - If validated successfully, Call rgCFGCrgCellCfg, rgCFGCrgUeCfg,
181 * rgCFGCrgLcCfg for Cell, UE and Logical channel configuration
182 * respectively, else FAIL.
184 * @param[in] Inst inst
185 * @param[in] CrgCfg *cfg
186 * @param[out] RgErrInfo *errInfo
191 static S16 rgCOMHndlCfgReq
197 CrgCfgTransId transId
201 RgCellCb *cell = NULLP;
204 errInfo->errType = RGERR_COM_CFG_REQ;
206 /* Validate and process the configuration request */
207 switch (cfg->cfgType)
211 ret = rgCFGVldtCrgCellCfg(inst,&cfg->u.cellCfg,errInfo);
214 RLOG_ARG0(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId, "Cell configuration validation FAILED\n");
217 ret = rgCFGCrgCellCfg(inst,&cfg->u.cellCfg, errInfo);
223 ret = rgCFGVldtCrgUeCfg(inst,&cfg->u.ueCfg, &cell, errInfo);
226 RLOG_ARG0(L_ERROR,DBG_CRNTI,cfg->u.ueCfg.crnti, "Ue configuration validation FAILED\n");
229 ret = rgCFGCrgUeCfg(inst,cell, &cfg->u.ueCfg, errInfo);
236 ret = rgCFGVldtCrgLcCfg(inst,&cfg->u.lchCfg, &cell, &ue,errInfo);
240 RLOG_ARG1(L_ERROR,DBG_CELLID,cfg->u.cellCfg.cellId,
241 "LC configuration validation FAILED: LC %d\n", cfg->u.lchCfg.lcId);
244 ret = rgCFGCrgLcCfg(inst,cell, ue, &cfg->u.lchCfg, errInfo,isCfmRqrd,transId);
249 RLOG1(L_ERROR, "Should never come here: cfgType %d",cfg->cfgType);
255 } /* rgCOMHndlCfgReq */
259 * @brief Handler for processing Cell/Ue/Logical channel re-configuration request
264 * Function: rgCOMHndlRecfgReq
266 * This API handles processing of reconfiguration request from RRC to MAC.
269 * - Validate reconfiguration request parameters at CFG module. Call
270 * rgCFGVldtCrgCellRecfg, rgCFGVldtCrgUeRecfg, rgCFGVldtCrgLchRecfg for
271 * Cell, UE and logical channel reconfiguration respectively.
272 * - If validated, Call rgCFGCrgCellRecfg, rgCFGCrgUeRecfg,
273 * rgCFGCrgLchRecfg for Cell, UE and Logical channel re-configuration
274 * respectively else FAIL.
276 * @param[in] Inst inst
277 * @param[in] CrgRecfg *recfg
278 * @param[out] RgErrInfo *errInfo
283 static S16 rgCOMHndlRecfgReq
288 CrgCfgTransId transId,
293 RgCellCb *cell = rgCb[inst].cell;
295 RgUlLcCb *ulLc = NULLP;
297 errInfo->errType = RGERR_COM_RECFG_REQ;
299 /* Validate and process the re-configuration request */
300 switch (recfg->recfgType)
304 ret = rgCFGVldtCrgCellRecfg(inst,&recfg->u.cellRecfg, &cell, errInfo);
307 RLOG_ARG0(L_ERROR,DBG_CELLID,recfg->u.cellRecfg.cellId,
308 "Cell Recfg Validation FAILED");
311 ret = rgCFGCrgCellRecfg(inst,cell, &recfg->u.cellRecfg, errInfo);
316 /*ccpu00126865 - Added as a part of RRC Reestablishment issue with MAC
317 * having a possibility of sending NOK */
318 if (recfg->u.ueRecfg.oldCrnti != recfg->u.ueRecfg.newCrnti)
320 errInfo->errCause = RGERR_CFG_INVALID_CRG_UE_RECFG;
326 /* Check for isSCellCfgPres */
327 if(TRUE == recfg->u.ueRecfg.crgSCellCfg.isSCellCfgPres)
329 ret = rgFillAndAddSCellCfg(inst, cell, &recfg->u.ueRecfg, transId, isCfmRqrd);
332 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Ue SCell configuration FAILED for inst [%d]\n",
333 recfg->u.ueRecfg.oldCrnti, inst));
341 ret = rgCFGVldtCrgUeRecfg(inst,&recfg->u.ueRecfg, &cell, &ue, errInfo);
344 RLOG_ARG1(L_ERROR,DBG_CELLID,recfg->u.ueRecfg.cellId,
345 "Ue Re-configuration validation FAILED OLD CRNTI:%d",
346 recfg->u.ueRecfg.oldCrnti);
349 ret = rgCFGCrgUeRecfg(inst,cell, ue, &recfg->u.ueRecfg, errInfo);
358 ret = rgCFGVldtCrgLcRecfg(inst,&recfg->u.lchRecfg, &cell, &ue,
362 RLOG_ARG2(L_ERROR,DBG_CELLID,recfg->u.lchRecfg.cellId,
363 "LC Re-configuration validation FAILED LCID:%d CRNTI:%d",
364 recfg->u.lchRecfg.lcId,recfg->u.lchRecfg.crnti);
369 /*ERAB- multicell fix*/
370 memcpy( &(ue->cfgCfmInfo.transId), &transId,
371 sizeof(CrgCfgTransId));
373 ret = rgCFGCrgLcRecfg(inst,cell, ue, ulLc,
374 &recfg->u.lchRecfg, errInfo,isCfmRqrd);
380 RLOG1(L_ERROR, "Should never come here: recfgType %d",
387 } /* rgCOMHndlRecfgReq */
389 /*Start: LTEMAC_2.1_DEV_CFG */
391 * @brief Handler for processing UE Reset request recieved from RRC.
395 * Function: rgCOMHndlResetReq
397 * This API handles processing of Reset request from RRC to MAC.
400 * - Validate reset request parameters at CFG module. Call
401 * rgCFGVldtCrgUeReset for UE reset.
402 * - If validated, Call rgCFGCrgUeReset for UE reset, else FAIL.
404 * @param[in] Inst inst
405 * @param[in] CrgRst *reset
406 * @param[out] RgErrInfo *errInfo
411 static S16 rgCOMHndlResetReq
418 /* Fix : ccpu00126865: ignore CRG reset. Let SCH trigger it. */
420 errInfo->errCause = RGERR_NONE;
421 RGDBGINFO(inst,(rgPBuf(inst), "CRG UE Reset processed \n"));
423 } /* rgCOMHndlResetReq */
424 /*End: LTEMAC_2.1_DEV_CFG */
427 * @brief Handler for processing Cell/UE/Logical channel delete request
432 * Function: rgCOMHndlDelReq
434 * This API handles processing of delete request from RRC to MAC.
437 * - Fetch corresponding control block and pass it to CFG module.
438 * - If control block does not exist, FAIL.
440 * @param[in] Inst inst
441 * @param[in] CrgDel *del
442 * @param[out] RgErrInfo *errInfo
443 @param[out] Bool *isCfmRqrd
448 static S16 rgCOMHndlDelReq
454 CrgCfgTransId transId
459 volatile uint32_t startTime=0;
461 errInfo->errType = RGERR_COM_DEL_REQ;
463 /* Process the delete request */
464 switch (del->delType)
468 ret = rgCFGCrgCellDel(inst,del, errInfo);
474 SStartTask(&startTime,PID_MAC_UE_DEL);
477 ret = rgCFGCrgUeDel(inst,del, errInfo);
478 RGDBGINFONEW(inst,(rgPBuf(inst),"[%d] Delete UE Done \n", del->u.ueDel.crnti));
481 SStopTask(startTime,PID_MAC_UE_DEL);
487 ret = rgCFGCrgLcDel(inst,del, errInfo,isCfmRqrd, transId);
492 RLOG1(L_ERROR, "Should never come here: delType %d",
499 } /* rgCOMHndlDelReq */
503 * @brief Handler for the SCell configuration request from RRC to MAC.
507 * Function : RgPrgPMacSMacUeSCellCfgReq
510 * - Allocate and create UE control block.
511 * - Update UE control block with the values recieved in the
513 * - If successful, add the control block to hash list of UEs for the cell
514 * else Rollback and FAIL.
516 * @param[in] Pst *pst
517 * @param[in] RgPrgUeSCellCfgInfo *ueSCellCb
522 S16 RgPrgPMacSMacUeSCellCfgReq
525 RgPrgUeSCellCfgInfo *ueSCellCb
528 RgPrgCfgCfmInfo cfgCfm;
529 Inst inst = pst->dstInst;
530 RgCellCb *cell = rgCb[inst].cell;
535 RGDBGPRM(inst,(rgPBuf(inst),
536 "APPLYING CRG UE SCELL CONFIG: cellId %d ueId %d\n",
537 ueSCellCb->cellId, ueSCellCb->ueId));
539 cfgCfm.ueId = ueSCellCb->ueId;
540 cfgCfm.sCellId = ueSCellCb->cellId;
541 cfgCfm.status = PRG_CFG_CFM_OK;
542 cfgCfm.event = EVTPRGUESCELLCFGCFM;
543 rgGetPstToInst(&cfmPst, inst, pst->srcInst);
545 ret = rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst);
548 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
549 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
550 /* Set status as Not OK*/
551 cfgCfm.status = PRG_CFG_CFM_NOK;
555 ret = rgCfgAddUeSCellCfg(inst, ueSCellCb, cell);
558 RGDBGERRNEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell failed:\
559 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
560 /* Set status as Not OK*/
561 cfgCfm.status = PRG_CFG_CFM_NOK;
565 RGDBGINFONEW(inst,(rgPBuf(inst), "[%d]Crg Ue SCell Config done:\
566 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId));
568 /* Send positive confirmation to primary cell*/
569 RgPrgSMacPMacCfg(&cfmPst, &cfgCfm);
571 } /* RgPrgPMacSMacUeSCellCfgReq */
574 * @brief Hander for config confim from sec MAC to Pri mac for Add Scell Cfg.
578 * Function : RgPrgSMacPMacCfgCfm
581 * - Allocate and create UE control block.
582 * - If cfm event is lch recfg then send the confirmation to RRC for
584 * - If cfm event is Scell addition then send the confirmation to RRC for
586 * - Update UE control block with the values received in the
588 * - If successful, add the control block to hash list of UEs for the cell
589 * else Rollback and FAIL.
591 * @param[in] Inst dstMacInst
592 * @param[in] RgUrSCellCb *ueSCellCb
597 S16 RgPrgSMacPMacCfgCfm
600 RgPrgCfgCfmInfo *cfgCfm
603 Inst inst = pst->dstInst;
607 RG_IS_INST_VALID(inst);
609 RGDBGPRM(pst->dstInst,(rgPBuf(pst->dstInst),
610 "Config Confirm Rcvd from Inst %d ueId %d cellId %d\n",
611 pst->srcInst, cfgCfm->ueId, cfgCfm->cellId));
613 cell = rgCb[inst].cell;
615 if ((ue = rgDBMGetUeCb(cell, cfgCfm->ueId)) == NULLP)
617 RGDBGERRNEW(inst,(rgPBuf(inst),
618 "[%d]Ue does not exist\n", cfgCfm->ueId));
621 switch(cfgCfm->event)
623 /* cfgCount increment for all cases */
624 case EVTPRGUESCELLLCHMODCFM:
625 case EVTPRGUESCELLLCHDELCFM:
626 case EVTPRGUESCELLLCHADDCFM:
628 ue->cfgCfmInfo.cfgCfgCount++;
629 ue->cfgCfmInfo.mask |= cfgCfm->status;
630 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
632 ue->cfgCfmInfo.cfgCfgCount = 0;
633 /* Send back confirmation status to RRC */
634 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
635 ue->cfgCfmInfo.mask = 0;
636 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
640 case EVTPRGUESCELLCFGCFM:
642 /*Commit Added SCell info to UeCb as we confirmation received */
643 if(PRG_CFG_CFM_OK == cfgCfm->status)
645 ue->sCelInfo[pst->srcInst].isSCellAdded = TRUE;
646 ue->sCelInfo[pst->srcInst].macInst = pst->srcInst;
647 ue->sCelInfo[pst->srcInst].sCellId = cfgCfm->sCellId;
650 ue->cfgCfmInfo.cfgCfgCount++;
651 ue->cfgCfmInfo.mask |= cfgCfm->status;
652 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
654 ue->cfgCfmInfo.cfgCfgCount = 0;
655 /* Send back confirmation status to RRC */
656 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
657 ue->cfgCfmInfo.mask = 0;
658 RGDBGINFO(inst,(rgPBuf(inst), "CRG Configuration request processed\n"));
664 RGDBGERRNEW(inst,(rgPBuf(inst), "Invalid configuration confirm event %d\n",
672 } /* RgPrgSMacPMacCfgCfm */
675 * @brief Function for handling UE release for SCELL
676 * triggered from Primary Cell
680 * Function : RgPrgPMacSMacUeSCellDelReq
682 * - This Function should be invoked by PCell of UE
683 * - Remove the UE context from SCELL corresponding to rnti.
685 * @param[in] Pst *pst
686 * @param[in] RgPrgUeSCellDelInfo *ueSCellDelInfo
687 * @return ROK is SUCCESS
689 S16 RgPrgPMacSMacUeSCellDelReq
692 RgPrgUeSCellDelInfo *ueSCellDelInfo
695 Inst inst = pst->dstInst - RG_INST_START;
696 RgCellCb *sCell = rgCb[inst].cell;
697 RgUeCb *sCellUe = NULLP;
699 /* Checking for cell Cb because in case of shutdownReq it is possible that
700 * cell is already deleted for this cell*/
705 /* Retrive the UeCb from sec cell*/
706 if ((sCellUe = rgDBMGetUeCb(sCell, ueSCellDelInfo->ueId)) == NULLP)
708 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:does not exist in sCell(%d)\n",
709 ueSCellDelInfo->ueId, sCell->cellId));
713 /*PMAC_Reest: ueId and newRnti is different that means its a UeId change
714 *request from PMAC to SMAC during PCell reestablishment
716 if(ueSCellDelInfo->ueId != ueSCellDelInfo->newRnti)
718 /* Retrive the UeCb from sec cell*/
719 if ((rgDBMGetUeCb(sCell, ueSCellDelInfo->newRnti)) != NULLP)
721 RGDBGERRNEW(inst, (rgPBuf(inst), "[%d]UE:UE context already exist in\
722 sCell(%d)",ueSCellDelInfo->newRnti, sCell->cellId));
726 rgDBMDelUeCb(sCell, sCellUe);
728 sCellUe->ueId = ueSCellDelInfo->newRnti;
730 /* Reset harq procs*/
731 rgDHMUeReset(sCell, &sCellUe->dl.hqEnt);
733 rgDBMInsUeCb(sCell, sCellUe);
737 rgDBMDelUeCb(sCell, sCellUe);
738 rgCFGFreeUeCb(sCell, sCellUe);
742 } /* RgPrgPMacSMacUeSCellDelReq */
744 /**********************************************************************
747 **********************************************************************/