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 *******************************************************************************/
18 /* This file contains UE management handling functionality for SCH */
20 #include "common_def.h"
27 #include "du_app_mac_inf.h"
28 #include "mac_sch_interface.h"
30 #include "sch_utils.h"
33 SchUeCfgRspFunc SchUeCfgRspOpts[] =
35 packSchUeCfgRsp, /* LC */
36 MacProcSchUeCfgRsp, /* TC */
37 packSchUeCfgRsp /* LWLC */
40 SchUeDeleteRspFunc SchUeDeleteRspOpts[] =
42 packSchUeDeleteRsp, /* LC */
43 MacProcSchUeDeleteRsp, /* TC */
44 packSchUeDeleteRsp /* LWLC */
47 SchCellDeleteRspFunc SchCellDeleteRspOpts[]=
49 packSchCellDeleteRsp, /* LC */
50 MacProcSchCellDeleteRsp, /* TC */
51 packSchCellDeleteRsp /* LWLC */
54 /*******************************************************************
56 * @brief Fill and send UE cfg response to MAC
60 * Function : SchSendUeCfgRspToMac
62 * Functionality: Fill and send UE cfg response to MAC
65 * @return ROK - success
68 * ****************************************************************/
69 void SchSendUeCfgRspToMac(uint16_t event, SchUeCfg *ueCfg, Inst inst,\
70 SchMacRsp result, SchUeCfgRsp *cfgRsp)
74 cfgRsp->cellId = ueCfg->cellId;
75 cfgRsp->crnti = ueCfg->crnti;
76 GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
79 /* Filling response post */
80 memset(&rspPst, 0, sizeof(Pst));
81 FILL_PST_SCH_TO_MAC(rspPst, inst);
82 if(event == EVENT_ADD_UE_CONFIG_REQ_TO_SCH)
84 rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
85 DU_LOG("\nINFO --> SCH : Sending UE Config response to MAC");
87 else if(event == EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH)
89 rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
90 DU_LOG("\nINFO --> SCH : Sending UE Reconfig response to MAC");
92 SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
95 /*******************************************************************
98 * @brief Function to fill Dl Lc Context in SCH Ue Cb
102 * Function : fillSchDlLcCtxt
104 * Functionality: Function to fill Dl Lc Context in SCH Ue Cb
106 * @params[in] SchDlLcCtxt pointer,
110 * ****************************************************************/
112 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
114 ueCbLcCfg->lcId = lcCfg->lcId;
115 ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
116 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
120 ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
124 if(ueCbLcCfg->snssai == NULLP)/*In CONFIG_MOD case, no need to allocate SNSSAI memory*/
126 SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
128 memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
132 /*******************************************************************
134 * @brief Function to fill Ul Lc Context in SCH Ue Cb
138 * Function : fillSchUlLcCtxt
140 * Functionality: Function to fill Ul Lc Context in SCH Ue Cb
142 * @params[in] SchUlLcCtxt pointer,
146 * ****************************************************************/
148 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
150 ueCbLcCfg->lcId = lcCfg->lcId;
151 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
152 ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
153 ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
154 ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
155 ueCbLcCfg->pbr = lcCfg->ulLcCfg.pbr;
156 ueCbLcCfg->bsd = lcCfg->ulLcCfg.bsd;
160 ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
164 /*In CONFIG_MOD case, no need to allocate SNSSAI memory again*/
165 if(ueCbLcCfg->snssai == NULLP)
167 SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
169 memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
173 /*******************************************************************
175 * @brief Function to update/allocate dedLC Info
179 * Function : updateDedLcInfo
181 * Functionality: Function to fill DLDedLcInfo
183 * @params[arg] snssai pointer,
184 * SchRrmPolicy pointer,
185 * SchLcPrbEstimate pointer , It will be filled
186 * isDedicated pointer,(Address of isDedicated flag in LC Context)
188 * @return ROK >> This LC is part of RRM MemberList.
189 * RFAILED >> FATAL Error
190 * ROKIGNORE >> This LC is not part of this RRM MemberList
192 * ****************************************************************/
194 uint8_t updateDedLcInfo(Snssai *snssai, SchRrmPolicy *rrmPolicy, SchLcPrbEstimate *lcPrbEst,\
197 if(memcmp(snssai, &(rrmPolicy->memberList.snssai), sizeof(Snssai)))
199 if(lcPrbEst->dedLcInfo == NULLP)
201 SCH_ALLOC(lcPrbEst->dedLcInfo, sizeof(DedicatedLCInfo));
202 if(lcPrbEst->dedLcInfo == NULLP)
204 DU_LOG("\nINFO --> SCH : Memory Allocation Failed");
208 /*Updating latest RrmPolicy*/
209 lcPrbEst->dedLcInfo->rsvdDedicatedPRB = \
210 (uint16_t)(((rrmPolicy->policyDedicatedRatio)*(MAX_NUM_RB))/100);
212 DU_LOG("\nINFO --> SCH : Updated RRM policy, reservedPOOL:%d",lcPrbEst->dedLcInfo->rsvdDedicatedPRB);
214 /*else case: This LcCtxt is either a Default LC or this LC is part of someother RRM_MemberList*/
217 DU_LOG("\nINFO --> SCH : This SNSSAI is not a part of this RRMPolicy");
222 /*******************************************************************
224 * @brief Function to fill SchUeCb
228 * Function : fillSchUeCb
230 * Functionality: Function to fill SchUeCb
232 * @params[in] SchUeCb pointer,
234 * @return ROK/RFAILED
236 * ****************************************************************/
238 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
240 uint8_t lcIdx, ueLcIdx;
241 uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
242 SchPdschCfgCmn pdschCfg;
243 SchPucchDlDataToUlAck *dlDataToUlAck;
244 CmLListCp *lcLL = NULLP;
245 uint8_t retDL = ROK, retUL = ROK;
246 bool isLcIdValid = FALSE;
248 ueCb->ueCfg.cellId = ueCfg->cellId;
249 ueCb->ueCfg.crnti = ueCfg->crnti;
250 if(ueCfg->macCellGrpCfgPres == true)
252 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
253 ueCb->ueCfg.macCellGrpCfgPres = true;
256 if(ueCfg->phyCellGrpCfgPres == true)
258 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
259 ueCb->ueCfg.phyCellGrpCfgPres = true;
262 if(ueCfg->spCellCfgPres == true)
264 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
266 covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
268 memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
269 memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
271 ueCb->ueCfg.spCellCfgPres = true;
272 dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
277 BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
278 ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
279 dlDataToUlAck->dlDataToUlAckList);
280 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
281 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
282 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
287 ueCb->state = SCH_UE_STATE_ACTIVE;
290 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
291 ueCb->ueCfg.ambrCfg = ueCfg->ambrCfg;
293 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
294 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
296 //Updating SchUlCb and SchDlCb DB in SchUeCb
297 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
299 isLcIdValid = FALSE; /*Re-Initializing*/
301 ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
302 CHECK_LCID(ueLcIdx, isLcIdValid);
303 if(isLcIdValid == FALSE)
305 DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
308 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
310 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
311 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
313 /*Checking whether this LC belong to Dedicated S-NSSAI
314 * and Create the Dedicated LC List & Update the Reserve PRB number*/
315 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
317 retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, \
318 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst),\
319 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
321 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
323 retUL = updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, \
324 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
325 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
328 if(retUL == RFAILED || retDL == RFAILED)/*FATAL error*/
330 DU_LOG("\nERROR --> SCH : Failure in updateDedLcInfo");
336 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
338 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
340 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
341 /*Updating the RRM reserved pool PRB count*/
342 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
344 retUL = updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, \
345 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
346 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
350 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
354 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
356 /*Delete the LC node from the UL LC List*/
357 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
359 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
361 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
362 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
363 if(lcLL->count == 0)/*IF No Node in DedicateLCList to be deleted*/
365 /*Free the Dedicated LC Info structure*/
366 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
370 else/*Default LC list*/
372 lcLL = &(ueCb->ulLcPrbEst.defLcList);
373 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
375 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
376 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
378 }/*End of UL LC Ctxt*/
380 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
382 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
384 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
385 /*Updating the RRM policy*/
386 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
388 retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, \
389 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst), \
390 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
394 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
398 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
400 /*Delete the LC node from the DL LC List*/
401 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
403 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
405 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
406 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
407 if(lcLL->count == 0)/*Last Node in DedicateLCList to be deleted*/
409 /*Free the Dedicated LC Info structure*/
410 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
416 lcLL = &(ueCb->dlLcPrbEst.defLcList);
417 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
419 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
420 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
422 }/*End of DL LC ctxt*/
425 SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
426 SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
428 }/* End of outer for loop */
432 /*******************************************************************
434 * @brief Function to get SCH Cell Cb
438 * Function : getSchCellCb
440 * Functionality: Function to get SCH Cell Cb
442 * @params[in] event, SchUeCfg pointer
443 * @return schUeCb pointer - success
446 * ****************************************************************/
448 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
451 SchCellCb *cellCb = NULLP;
453 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
455 /* Search of cell cb */
456 for(idx = 0; idx < MAX_NUM_CELL; idx++)
458 cellCb = schCb[inst].cells[idx];
459 if(cellCb->cellId == ueCfg->cellId)
462 if(idx == MAX_NUM_CELL)
464 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
465 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
469 /* Check if max number of UE configured */
470 if(cellCb->numActvUe > MAX_NUM_UE)
472 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
473 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
480 /*******************************************************************
482 * @brief Function to Add Ue Config Request from MAC
486 * Function : MacSchAddUeConfigReq
488 * Functionality: Function to Add Ue config request from MAC
491 * @return ROK - success
494 * ****************************************************************/
495 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
497 uint8_t ueIdx, lcIdx, ret = ROK;
498 SchCellCb *cellCb = NULLP;
499 SchUeCb *ueCb = NULLP;
501 Inst inst = pst->dstInst - 1;
502 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
504 #ifdef CALL_FLOW_DEBUG_LOG
505 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
510 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
513 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
514 cellCb = getSchCellCb(pst->event, inst, ueCfg);
516 /* Search if UE already configured */
517 GET_UE_IDX(ueCfg->crnti, ueIdx);
518 ueCb = &cellCb->ueCb[ueIdx -1];
521 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
523 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
524 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
530 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
531 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
535 /* Fill received Ue Configuration in UeCb */
536 memset(ueCb, 0, sizeof(SchUeCb));
537 GET_UE_IDX(ueCfg->crnti, ueIdx);
539 ueCb->crnti = ueCfg->crnti;
540 ueCb->state = SCH_UE_STATE_ACTIVE;
541 ret = fillSchUeCb(ueCb, ueCfg);
545 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
546 ueCb->cellCb = cellCb;
547 ueCb->srRcvd = false;
548 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
549 ueCb->bsrInfo[lcIdx].dataVol = 0;
551 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
556 /*******************************************************************
558 * @brief Fills PUSCH UL allocation
562 * Function : schFillPuschAlloc
564 * Functionality: fills PUSCH info
567 * @return ROK - success
570 * ****************************************************************/
571 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo pdcchSlotTime, uint32_t dataVol, SchPuschInfo *puschInfo)
573 uint16_t startRb = 0;
577 uint8_t k2=0, startSymb=0 , symbLen=0;
578 SchCellCb *cellCb = ueCb->cellCb;
579 SchUlSlotInfo *schUlSlotInfo = NULLP;
580 SlotTimingInfo puschTime;
582 /* TODO : Scheduler to decide on which slot PUSCH is to be scheduled based on K2 Index table */
583 if(ueCb->ueCfg.spCellCfgPres == true)
585 k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
586 startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
587 symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
589 ADD_DELTA_TO_TIME(pdcchSlotTime, puschTime, k2);
591 startRb = MAX_NUM_RB;
592 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
593 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
594 allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startRb, numRb);
596 puschInfo->crnti = ueCb->crnti;
597 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
598 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
599 puschInfo->fdAlloc.startPrb = startRb;
600 puschInfo->fdAlloc.numPrb = numRb;
601 puschInfo->tdAlloc.startSymb = startSymb;
602 puschInfo->tdAlloc.numSymb = symbLen;
603 puschInfo->tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
604 puschInfo->tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
605 puschInfo->tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
606 puschInfo->tbInfo.ndi = 1; /* new transmission */
607 puschInfo->tbInfo.rv = 0;
608 puschInfo->tbInfo.tbSize = tbSize;
609 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
610 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
611 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
613 schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
614 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
615 if(!schUlSlotInfo->schPuschInfo)
617 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
620 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
625 /*******************************************************************
627 * @brief Fills DCI for UL grant
631 * Function : schFillUlDci
633 * Functionality: fills DCI for UL grant in response to BSR
636 * @return ROK - success
639 * ****************************************************************/
640 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
642 SchCellCb *cellCb = ueCb->cellCb;
643 SchControlRsrcSet coreset1 ;
645 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
646 if(ueCb->ueCfg.spCellCfgPres == true)
648 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
651 dciInfo->cellId = cellCb->cellId;
652 dciInfo->crnti = ueCb->crnti;
655 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
656 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
657 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
658 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
660 /*fill coreset cfg */
661 //Considering number of RBs in coreset1 is same as coreset0
662 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
663 //Considering coreset1 also starts from same symbol as coreset0
664 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
665 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
666 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
668 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
669 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
670 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
671 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
672 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
673 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
674 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
675 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
677 dciInfo->formatType = FORMAT0_0;
680 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
681 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
682 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
683 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
684 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
685 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
686 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
687 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
688 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
689 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
690 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
691 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
692 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
693 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
695 /* Fill DCI Structure */
696 dciInfo->dciInfo.rnti = ueCb->crnti;
697 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
698 dciInfo->dciInfo.scramblingRnti = 0;
699 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
700 dciInfo->dciInfo.aggregLevel = 4;
701 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
702 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
703 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
704 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
705 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
706 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
707 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
708 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
713 /*******************************************************************
715 * @brief Function to Modify Ue Config request from MAC
719 * Function : MacSchModUeConfigReq
721 * Functionality: Function to modify Ue Config request from MAC
724 * @return ROK - success
727 * ****************************************************************/
728 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
730 uint8_t ueIdx, lcIdx, ret = ROK;
731 SchCellCb *cellCb = NULLP;
732 SchUeCb *ueCb = NULLP;
734 Inst inst = pst->dstInst - 1;
735 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
737 #ifdef CALL_FLOW_DEBUG_LOG
738 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
743 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
746 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
747 cellCb = getSchCellCb(pst->event, inst, ueCfg);
749 /* Search if UE already configured */
750 GET_UE_IDX(ueCfg->crnti, ueIdx);
751 ueCb = &cellCb->ueCb[ueIdx -1];
755 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
756 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
759 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
761 /* Found the UeCb to Reconfig */
762 ret = fillSchUeCb(ueCb, ueCfg);
765 ueCb->cellCb = cellCb;
766 ueCb->srRcvd = false;
767 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
768 ueCb->bsrInfo[lcIdx].dataVol = 0;
770 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
776 /*******************************************************************
778 * @brief Fill and send UE delete response to MAC
782 * Function : SchSendUeDeleteRspToMac
784 * Functionality: Fill and send UE delete response to MAC
786 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
788 * @return ROK - success
791 * ****************************************************************/
792 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
795 SchUeDeleteRsp delRsp;
797 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
798 delRsp.cellId = ueDelete->cellId;
799 delRsp.crnti = ueDelete->crnti;
801 delRsp.cause = cause;
803 /* Filling response post */
804 memset(&rspPst, 0, sizeof(Pst));
805 FILL_PST_SCH_TO_MAC(rspPst, inst);
806 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
807 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
810 /*******************************************************************
812 * @brief Function to delete Sch Pucch ResrcCfg
816 * Function : deleteSchPucchResrcCfg
818 * Functionality: Function to delete Sch Pucch ResrcCfg
820 * @params[in] SchPucchResrcCfg *resrc
823 * ****************************************************************/
825 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
828 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
830 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
834 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
835 sizeof(SchPucchFormat0));
840 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
841 sizeof(SchPucchFormat1));
846 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
847 sizeof(SchPucchFormat2_3));
852 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
853 sizeof(SchPucchFormat2_3));
858 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
859 sizeof(SchPucchFormat4));
866 /*******************************************************************
868 * @brief Function to delete SCH Pdsch ServCellCfg
872 * Function : deleteSchPdschServCellCfg
874 * Functionality: Function to delete SCH Pdsch ServCellCfg
876 * @params[in] SchPdschServCellCfg *pdschServCellCfg
879 * ****************************************************************/
881 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
883 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
884 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
885 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
886 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
889 /*******************************************************************
891 * @brief Function to delete SCH UeCb
895 * Function : deleteSchUeCb
897 * Functionality: Function to delete SCH UeCb
900 * @return ROK - success
903 * ****************************************************************/
904 void deleteSchUeCb(SchUeCb *ueCb)
906 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
907 SchPucchCfg *pucchCfg = NULLP;
908 SchPdschConfig *pdschCfg = NULLP;
909 CmLListCp *lcLL = NULLP;
913 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
914 if(ueCb->ueCfg.spCellCfgPres)
916 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
918 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
919 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
920 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
923 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
925 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
926 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
929 deleteSchPucchResrcCfg(pucchCfg->resrc);
930 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
932 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
933 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
934 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
935 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
936 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
937 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
938 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
939 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
940 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
942 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
943 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
945 /*Need to Free the memory allocated for S-NSSAI*/
946 for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
948 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
949 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
952 /*Clearing out Dedicated LC list*/
953 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
955 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
957 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
959 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
961 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
963 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
965 /*Deleteing the Default LC list*/
966 lcLL = &(ueCb->dlLcPrbEst.defLcList);
969 lcLL = &(ueCb->ulLcPrbEst.defLcList);
972 memset(ueCb, 0, sizeof(SchUeCb));
976 /*******************************************************************
978 * @brief Function for Ue Delete request from MAC to SCH
982 * Function : MacSchUeDeleteReq
984 * Functionality: Function for Ue Delete request from MAC to SCH
986 * @params[in] Pst *pst, SchUeDelete *ueDelete
987 * @return ROK - success
990 * ****************************************************************/
991 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
993 uint8_t idx=0, ueIdx=0, ret=ROK;
995 SchCellCb *cellCb = NULLP;
996 Inst inst = pst->dstInst - 1;
998 #ifdef CALL_FLOW_DEBUG_LOG
999 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1004 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1007 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1009 cellCb = schCb[inst].cells[idx];
1011 if(cellCb->cellId != ueDelete->cellId)
1013 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
1014 result = INVALID_CELLID;
1018 GET_UE_IDX(ueDelete->crnti, ueIdx);
1019 if(( cellCb->ueCb[ueIdx-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueIdx-1].state == SCH_UE_STATE_ACTIVE))
1021 deleteSchUeCb(&cellCb->ueCb[ueIdx-1]);
1022 cellCb->numActvUe--;
1023 result = NOT_APPLICABLE;
1027 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
1028 result = INVALID_UEIDX;
1032 if(result == NOT_APPLICABLE)
1034 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1038 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1044 /*******************************************************************
1046 * @brief Fill and send Cell delete response to MAC
1050 * Function : SchSendCellDeleteRspToMac
1052 * Functionality: Fill and send Cell delete response to MAC
1054 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
1055 * @return ROK - success
1058 * ****************************************************************/
1059 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
1064 SchCellDeleteRsp delRsp;
1066 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
1067 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1068 delRsp.cellId = ueDelete->cellId;
1069 delRsp.rsp = result;
1071 /* Filling response post */
1072 memset(&rspPst, 0, sizeof(Pst));
1073 FILL_PST_SCH_TO_MAC(rspPst, inst);
1074 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1075 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1078 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1084 /*******************************************************************
1086 * @brief Function for cellCb Deletion
1090 * Function : deleteSchCellCb
1092 * Functionality: Function for cellCb Deletion
1094 * @params[in] SchCellDelete *cellDelete
1095 * @return ROK - success
1098 * ****************************************************************/
1099 void deleteSchCellCb(SchCellCb *cellCb)
1101 uint8_t sliceIdx=0, slotIdx=0;
1102 if(cellCb->schDlSlotInfo)
1104 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1106 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1108 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1110 if(cellCb->schUlSlotInfo)
1112 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1114 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1116 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1119 if(cellCb->cellCfg.snssai)
1121 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.numSliceSupport; sliceIdx++)
1123 SCH_FREE(cellCb->cellCfg.snssai[sliceIdx], sizeof(Snssai));
1125 SCH_FREE(cellCb->cellCfg.snssai, cellCb->cellCfg.numSliceSupport*sizeof(Snssai*));
1127 SCH_FREE(cellCb->cellCfg.rrmPolicy, sizeof(SchRrmPolicy));
1128 memset(cellCb, 0, sizeof(SchCellCb));
1132 /*******************************************************************
1134 * @brief Function for cell Delete request from MAC to SCH
1138 * Function : MacSchCellDeleteReq
1140 * Functionality: Function for cell Delete request from MAC to SCH
1142 * @params[in] Pst *pst, SchCellDelete *cellDelete
1143 * @return ROK - success
1146 * ****************************************************************/
1148 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1150 uint8_t cellIdx=0, ret = RFAILED;
1151 Inst inst = pst->dstInst - 1;
1152 SchMacRsp result= RSP_OK;
1154 #ifdef CALL_FLOW_DEBUG_LOG
1155 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1160 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1164 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1165 if(schCb[inst].cells[cellIdx] == NULLP)
1167 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1172 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1174 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1177 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1178 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1182 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1187 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1189 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1197 /**********************************************************************
1199 **********************************************************************/