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.
37 /* header include files -- defines (.h) */
38 #include "common_def.h"
40 #include "du_app_mac_inf.h"
44 #include "rg_sch_inf.h"
49 /* header/extern include files (.x) */
54 #include "rg_sch_inf.x"
55 #include "rg_prg.x" /* PRG interface typedefs*/
58 #include "rg_pom_scell.x"
61 static S16 rgCOMHndlCfgReq ARGS((Inst inst,CrgCfg *cfg, RgErrInfo *errInfo,Bool *isCfmRqrd,CrgCfgTransId transId));
62 static S16 rgCOMHndlRecfgReq ARGS((Inst inst,CrgRecfg *recfg, RgErrInfo *errInfo, \
63 CrgCfgTransId transId,Bool *isCfmRqrd));
64 static S16 rgCOMHndlDelReq ARGS((Inst inst,CrgDel *del, RgErrInfo *errInfo, Bool *isCfmRqrd, CrgCfgTransId transId));
65 static S16 rgCOMHndlResetReq ARGS((Inst inst,CrgRst *reset,RgErrInfo *errInfo));
70 /* forward references */
73 * @brief Handler to handle config request from RRC to MAC.
77 * Function: rgCOMCfgReq
79 * This API handles processing for config request from RRC to MAC.
82 * - If configuration, process configuration request. Call rgCOMHndlCfgReq.
83 * - else If re-configuration, process re-configuration request.
84 * Call rgCOMHndlRecfgReq.
85 * - else If reset, process reset request. Call rgCOMHndlResetReq.
86 * - else If delete, process delete request. Call rgCOMHndlDelReq.
87 * - If successful, send confirmation to RRC. Call rgUIMCrgCfgCfm.
90 * @param[in] Inst inst
91 * @param[in] CrgCfgTransId transId
92 * @param[in] CrgCfgReqInfo *crgCfgReq
100 CrgCfgTransId transId,
101 CrgCfgReqInfo *crgCfgReq
105 uint8_t cfmStatus = CRG_CFG_CFM_OK;
107 Bool isCfmRqrd = TRUE;
109 /* Process Config/Reconfig/Delete request from RRC */
110 switch (crgCfgReq->action)
114 ret = rgCOMHndlCfgReq(inst,&crgCfgReq->u.cfgInfo, &errInfo,&isCfmRqrd, transId);
119 ret = rgCOMHndlRecfgReq(inst,&crgCfgReq->u.recfgInfo, &errInfo, transId, &isCfmRqrd);
122 /* Start: LTEMAC_2.1_DEV_CFG */
125 ret = rgCOMHndlResetReq(inst,&crgCfgReq->u.rstInfo, &errInfo);
128 /* End: LTEMAC_2.1_DEV_CFG */
131 ret = rgCOMHndlDelReq(inst,&crgCfgReq->u.delInfo, &errInfo, &isCfmRqrd, transId);
136 DU_LOG("\nERROR --> MAC : Invalid configuration action %d",
145 cfmStatus = CRG_CFG_CFM_NOK;
148 /* When UeSCellCfg is present then confirmation will be sent later once
149 confirm from all SMAC are recved at PMAC. PMAC will send a consolidated
150 confirm to RRC.Handling the failure of PMAC for Ue Scell add*/
152 if(TRUE == isCfmRqrd)
155 /* Send back confirmation status to RRC */
156 rgUIMCrgCfgCfm(inst,transId, cfmStatus);
160 DU_LOG("\nINFO --> MAC : CRG Configuration request processed\n");
164 * @brief Handler for processing Cell/Ue/Logical channel configuration request
169 * Function: rgCOMHndlCfgReq
171 * This API handles processing of configuration request from RRC to MAC.
174 * - Validate configuration request parameters at CFG module.
175 * Call rgCFGVldtCrgCellCfg, rgCFGVldtCrgUeCfg, rgCFGVldtCrgLcCfg
176 * for Cell, UE and Logical channel configuration respectively.
177 * - If validated successfully, Call rgCFGCrgCellCfg, rgCFGCrgUeCfg,
178 * rgCFGCrgLcCfg for Cell, UE and Logical channel configuration
179 * respectively, else FAIL.
181 * @param[in] Inst inst
182 * @param[in] CrgCfg *cfg
183 * @param[out] RgErrInfo *errInfo
188 static S16 rgCOMHndlCfgReq
194 CrgCfgTransId transId
198 RgCellCb *cell = NULLP;
201 errInfo->errType = RGERR_COM_CFG_REQ;
203 /* Validate and process the configuration request */
204 switch (cfg->cfgType)
208 ret = rgCFGVldtCrgCellCfg(inst,&cfg->u.cellCfg,errInfo);
211 DU_LOG("\nERROR --> MAC : Cell configuration validation FAILED\n");
214 ret = rgCFGCrgCellCfg(inst,&cfg->u.cellCfg, errInfo);
220 ret = rgCFGVldtCrgUeCfg(inst,&cfg->u.ueCfg, &cell, errInfo);
223 DU_LOG("\nERROR --> MAC : UE configuration validation FAILED\n");
226 ret = rgCFGCrgUeCfg(inst,cell, &cfg->u.ueCfg, errInfo);
233 ret = rgCFGVldtCrgLcCfg(inst,&cfg->u.lchCfg, &cell, &ue,errInfo);
237 DU_LOG("\nERROR --> MAC : LC configuration validation FAILED: LC %d\n", cfg->u.lchCfg.lcId);
240 ret = rgCFGCrgLcCfg(inst,cell, ue, &cfg->u.lchCfg, errInfo,isCfmRqrd,transId);
245 DU_LOG("\nERROR --> MAC : Should never come here: cfgType %d",cfg->cfgType);
251 } /* rgCOMHndlCfgReq */
255 * @brief Handler for processing Cell/Ue/Logical channel re-configuration request
260 * Function: rgCOMHndlRecfgReq
262 * This API handles processing of reconfiguration request from RRC to MAC.
265 * - Validate reconfiguration request parameters at CFG module. Call
266 * rgCFGVldtCrgCellRecfg, rgCFGVldtCrgUeRecfg, rgCFGVldtCrgLchRecfg for
267 * Cell, UE and logical channel reconfiguration respectively.
268 * - If validated, Call rgCFGCrgCellRecfg, rgCFGCrgUeRecfg,
269 * rgCFGCrgLchRecfg for Cell, UE and Logical channel re-configuration
270 * respectively else FAIL.
272 * @param[in] Inst inst
273 * @param[in] CrgRecfg *recfg
274 * @param[out] RgErrInfo *errInfo
279 static S16 rgCOMHndlRecfgReq
284 CrgCfgTransId transId,
289 RgCellCb *cell = rgCb[inst].cell;
291 RgUlLcCb *ulLc = NULLP;
293 errInfo->errType = RGERR_COM_RECFG_REQ;
295 /* Validate and process the re-configuration request */
296 switch (recfg->recfgType)
300 ret = rgCFGVldtCrgCellRecfg(inst,&recfg->u.cellRecfg, &cell, errInfo);
303 DU_LOG("\nERROR --> MAC : Cell Recfg Validation FAILED");
306 ret = rgCFGCrgCellRecfg(inst,cell, &recfg->u.cellRecfg, errInfo);
311 /*ccpu00126865 - Added as a part of RRC Reestablishment issue with MAC
312 * having a possibility of sending NOK */
313 if (recfg->u.ueRecfg.oldCrnti != recfg->u.ueRecfg.newCrnti)
315 errInfo->errCause = RGERR_CFG_INVALID_CRG_UE_RECFG;
321 /* Check for isSCellCfgPres */
322 if(TRUE == recfg->u.ueRecfg.crgSCellCfg.isSCellCfgPres)
324 ret = rgFillAndAddSCellCfg(inst, cell, &recfg->u.ueRecfg, transId, isCfmRqrd);
327 DU_LOG("\nERROR --> MAC : [%d]UE SCell configuration FAILED for inst [%d]\n",
328 recfg->u.ueRecfg.oldCrnti, inst);
336 ret = rgCFGVldtCrgUeRecfg(inst,&recfg->u.ueRecfg, &cell, &ue, errInfo);
339 DU_LOG("\nERROR --> MAC : UE Re-configuration validation FAILED OLD CRNTI:%d",
340 recfg->u.ueRecfg.oldCrnti);
343 ret = rgCFGCrgUeRecfg(inst,cell, ue, &recfg->u.ueRecfg, errInfo);
352 ret = rgCFGVldtCrgLcRecfg(inst,&recfg->u.lchRecfg, &cell, &ue,
356 DU_LOG("\nERROR --> MAC : LC Re-configuration validation FAILED LCID:%d CRNTI:%d",
357 recfg->u.lchRecfg.lcId,recfg->u.lchRecfg.crnti);
362 /*ERAB- multicell fix*/
363 memcpy( &(ue->cfgCfmInfo.transId), &transId,
364 sizeof(CrgCfgTransId));
366 ret = rgCFGCrgLcRecfg(inst,cell, ue, ulLc,
367 &recfg->u.lchRecfg, errInfo,isCfmRqrd);
373 DU_LOG("\nERROR --> MAC : Should never come here: recfgType %d",
380 } /* rgCOMHndlRecfgReq */
382 /*Start: LTEMAC_2.1_DEV_CFG */
384 * @brief Handler for processing UE Reset request recieved from RRC.
388 * Function: rgCOMHndlResetReq
390 * This API handles processing of Reset request from RRC to MAC.
393 * - Validate reset request parameters at CFG module. Call
394 * rgCFGVldtCrgUeReset for UE reset.
395 * - If validated, Call rgCFGCrgUeReset for UE reset, else FAIL.
397 * @param[in] Inst inst
398 * @param[in] CrgRst *reset
399 * @param[out] RgErrInfo *errInfo
404 static S16 rgCOMHndlResetReq
411 /* Fix : ccpu00126865: ignore CRG reset. Let SCH trigger it. */
413 errInfo->errCause = RGERR_NONE;
414 DU_LOG("\nINFO --> MAC : CRG UE Reset processed \n");
416 } /* rgCOMHndlResetReq */
417 /*End: LTEMAC_2.1_DEV_CFG */
420 * @brief Handler for processing Cell/UE/Logical channel delete request
425 * Function: rgCOMHndlDelReq
427 * This API handles processing of delete request from RRC to MAC.
430 * - Fetch corresponding control block and pass it to CFG module.
431 * - If control block does not exist, FAIL.
433 * @param[in] Inst inst
434 * @param[in] CrgDel *del
435 * @param[out] RgErrInfo *errInfo
436 @param[out] Bool *isCfmRqrd
441 static S16 rgCOMHndlDelReq
447 CrgCfgTransId transId
452 volatile uint32_t startTime=0;
454 errInfo->errType = RGERR_COM_DEL_REQ;
456 /* Process the delete request */
457 switch (del->delType)
461 ret = rgCFGCrgCellDel(inst,del, errInfo);
467 SStartTask(&startTime,PID_MAC_UE_DEL);
469 ret = rgCFGCrgUeDel(inst,del, errInfo);
470 DU_LOG("\nINFO --> MAC : [%d] Delete UE Done \n", del->u.ueDel.crnti);
473 SStopTask(startTime,PID_MAC_UE_DEL);
479 ret = rgCFGCrgLcDel(inst,del, errInfo,isCfmRqrd, transId);
484 DU_LOG("\nERROR --> MAC : Should never come here: delType %d",
491 } /* rgCOMHndlDelReq */
495 * @brief Handler for the SCell configuration request from RRC to MAC.
499 * Function : RgPrgPMacSMacUeSCellCfgReq
502 * - Allocate and create UE control block.
503 * - Update UE control block with the values recieved in the
505 * - If successful, add the control block to hash list of UEs for the cell
506 * else Rollback and FAIL.
508 * @param[in] Pst *pst
509 * @param[in] RgPrgUeSCellCfgInfo *ueSCellCb
514 S16 RgPrgPMacSMacUeSCellCfgReq
517 RgPrgUeSCellCfgInfo *ueSCellCb
520 RgPrgCfgCfmInfo cfgCfm;
521 Inst inst = pst->dstInst;
522 RgCellCb *cell = rgCb[inst].cell;
527 DU_LOG("\nDEBUG --> MAC : APPLYING CRG UE SCELL CONFIG: cellId %d ueId %d\n",
528 ueSCellCb->cellId, ueSCellCb->ueId);
530 cfgCfm.ueId = ueSCellCb->ueId;
531 cfgCfm.sCellId = ueSCellCb->cellId;
532 cfgCfm.status = PRG_CFG_CFM_OK;
533 cfgCfm.event = EVTPRGUESCELLCFGCFM;
534 rgGetPstToInst(&cfmPst, inst, pst->srcInst);
536 ret = rgUtlVltdAddSCellCfg(ueSCellCb, cell, inst);
539 DU_LOG("\nERROR --> MAC : [%d]Crg UE SCell failed:\
540 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId);
541 /* Set status as Not OK*/
542 cfgCfm.status = PRG_CFG_CFM_NOK;
546 ret = rgCfgAddUeSCellCfg(inst, ueSCellCb, cell);
549 DU_LOG("\nERROR --> MAC : [%d]Crg UE SCell failed:\
550 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId);
551 /* Set status as Not OK*/
552 cfgCfm.status = PRG_CFG_CFM_NOK;
556 DU_LOG("\nINFO --> MAC : [%d]Crg UE SCell Config done:\
557 cellId %d\n", ueSCellCb->ueId, ueSCellCb->cellId);
559 /* Send positive confirmation to primary cell*/
560 RgPrgSMacPMacCfg(&cfmPst, &cfgCfm);
562 } /* RgPrgPMacSMacUeSCellCfgReq */
565 * @brief Hander for config confim from sec MAC to Pri mac for Add Scell Cfg.
569 * Function : RgPrgSMacPMacCfgCfm
572 * - Allocate and create UE control block.
573 * - If cfm event is lch recfg then send the confirmation to RRC for
575 * - If cfm event is Scell addition then send the confirmation to RRC for
577 * - Update UE control block with the values received in the
579 * - If successful, add the control block to hash list of UEs for the cell
580 * else Rollback and FAIL.
582 * @param[in] Inst dstMacInst
583 * @param[in] RgUrSCellCb *ueSCellCb
588 S16 RgPrgSMacPMacCfgCfm
591 RgPrgCfgCfmInfo *cfgCfm
594 Inst inst = pst->dstInst;
598 RG_IS_INST_VALID(inst);
600 DU_LOG("\nINFO --> MAC : Config Confirm Rcvd from Inst %d ueId %d cellId %d\n",
601 pst->srcInst, cfgCfm->ueId, cfgCfm->cellId);
603 cell = rgCb[inst].cell;
605 if ((ue = rgDBMGetUeCb(cell, cfgCfm->ueId)) == NULLP)
607 DU_LOG("\nERROR --> MAC : [%d]UE does not exist\n", cfgCfm->ueId);
610 switch(cfgCfm->event)
612 /* cfgCount increment for all cases */
613 case EVTPRGUESCELLLCHMODCFM:
614 case EVTPRGUESCELLLCHDELCFM:
615 case EVTPRGUESCELLLCHADDCFM:
617 ue->cfgCfmInfo.cfgCfgCount++;
618 ue->cfgCfmInfo.mask |= cfgCfm->status;
619 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
621 ue->cfgCfmInfo.cfgCfgCount = 0;
622 /* Send back confirmation status to RRC */
623 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
624 ue->cfgCfmInfo.mask = 0;
625 DU_LOG("\nINFO --> MAC : CRG Configuration request processed\n");
629 case EVTPRGUESCELLCFGCFM:
631 /*Commit Added SCell info to UeCb as we confirmation received */
632 if(PRG_CFG_CFM_OK == cfgCfm->status)
634 ue->sCelInfo[pst->srcInst].isSCellAdded = TRUE;
635 ue->sCelInfo[pst->srcInst].macInst = pst->srcInst;
636 ue->sCelInfo[pst->srcInst].sCellId = cfgCfm->sCellId;
639 ue->cfgCfmInfo.cfgCfgCount++;
640 ue->cfgCfmInfo.mask |= cfgCfm->status;
641 if(ue->cfgCfmInfo.numSCells == ue->cfgCfmInfo.cfgCfgCount)
643 ue->cfgCfmInfo.cfgCfgCount = 0;
644 /* Send back confirmation status to RRC */
645 rgUIMCrgCfgCfm(inst, ue->cfgCfmInfo.transId, ue->cfgCfmInfo.mask);
646 ue->cfgCfmInfo.mask = 0;
647 DU_LOG("\nINFO --> MAC : CRG Configuration request processed\n");
653 DU_LOG("\nERROR --> MAC : Invalid configuration confirm event %d\n",
661 } /* RgPrgSMacPMacCfgCfm */
664 * @brief Function for handling UE release for SCELL
665 * triggered from Primary Cell
669 * Function : RgPrgPMacSMacUeSCellDelReq
671 * - This Function should be invoked by PCell of UE
672 * - Remove the UE context from SCELL corresponding to rnti.
674 * @param[in] Pst *pst
675 * @param[in] RgPrgUeSCellDelInfo *ueSCellDelInfo
676 * @return ROK is SUCCESS
678 S16 RgPrgPMacSMacUeSCellDelReq
681 RgPrgUeSCellDelInfo *ueSCellDelInfo
684 Inst inst = pst->dstInst - RG_INST_START;
685 RgCellCb *sCell = rgCb[inst].cell;
686 RgUeCb *sCellUe = NULLP;
688 /* Checking for cell Cb because in case of shutdownReq it is possible that
689 * cell is already deleted for this cell*/
694 /* Retrive the UeCb from sec cell*/
695 if ((sCellUe = rgDBMGetUeCb(sCell, ueSCellDelInfo->ueId)) == NULLP)
697 DU_LOG("\nERROR --> MAC : [%d]UE:does not exist in sCell(%d)\n",
698 ueSCellDelInfo->ueId, sCell->cellId);
702 /*PMAC_Reest: ueId and newRnti is different that means its a UeId change
703 *request from PMAC to SMAC during PCell reestablishment
705 if(ueSCellDelInfo->ueId != ueSCellDelInfo->newRnti)
707 /* Retrive the UeCb from sec cell*/
708 if ((rgDBMGetUeCb(sCell, ueSCellDelInfo->newRnti)) != NULLP)
710 DU_LOG("\nERROR --> MAC : [%d]UE:UE context already exist in\
711 sCell(%d)",ueSCellDelInfo->newRnti, sCell->cellId);
715 rgDBMDelUeCb(sCell, sCellUe);
717 sCellUe->ueId = ueSCellDelInfo->newRnti;
719 /* Reset harq procs*/
720 rgDHMUeReset(sCell, &sCellUe->dl.hqEnt);
722 rgDBMInsUeCb(sCell, sCellUe);
726 rgDBMDelUeCb(sCell, sCellUe);
727 rgCFGFreeUeCb(sCell, sCellUe);
731 } /* RgPrgPMacSMacUeSCellDelReq */
733 /**********************************************************************
736 **********************************************************************/