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)) == 0)
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 ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1TblPrsnt = true;
281 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
282 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
283 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
284 ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt = true;
289 ueCb->state = SCH_UE_STATE_ACTIVE;
292 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
293 ueCb->ueCfg.ambrCfg = ueCfg->ambrCfg;
295 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
296 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
298 //Updating SchUlCb and SchDlCb DB in SchUeCb
299 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
301 isLcIdValid = FALSE; /*Re-Initializing*/
303 ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
304 CHECK_LCID(ueLcIdx, isLcIdValid);
305 if(isLcIdValid == FALSE)
307 DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
310 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
312 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
313 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
315 /*Checking whether this LC belong to Dedicated S-NSSAI
316 * and Create the Dedicated LC List & Update the Reserve PRB number*/
317 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
319 retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, \
320 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst),\
321 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
323 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
325 retUL = updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, \
326 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
327 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
330 if(retUL == RFAILED || retDL == RFAILED)/*FATAL error*/
332 DU_LOG("\nERROR --> SCH : Failure in updateDedLcInfo");
338 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
340 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
342 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
343 /*Updating the RRM reserved pool PRB count*/
344 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
346 retUL = updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, \
347 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
348 &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
352 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
356 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
358 /*Delete the LC node from the UL LC List*/
359 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
361 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
363 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
364 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
365 if(lcLL->count == 0)/*IF No Node in DedicateLCList to be deleted*/
367 /*Free the Dedicated LC Info structure*/
368 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
372 else/*Default LC list*/
374 lcLL = &(ueCb->ulLcPrbEst.defLcList);
375 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
377 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
378 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
380 }/*End of UL LC Ctxt*/
382 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
384 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
386 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
387 /*Updating the RRM policy*/
388 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
390 retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, \
391 ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst), \
392 &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
396 DU_LOG("\nERROR --> SCH : Failed in updating Ded Lc info");
400 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
402 /*Delete the LC node from the DL LC List*/
403 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
405 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
407 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
408 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
409 if(lcLL->count == 0)/*Last Node in DedicateLCList to be deleted*/
411 /*Free the Dedicated LC Info structure*/
412 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
418 lcLL = &(ueCb->dlLcPrbEst.defLcList);
419 handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
421 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
422 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
424 }/*End of DL LC ctxt*/
427 SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
428 SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
430 }/* End of outer for loop */
434 /*******************************************************************
436 * @brief Function to get SCH Cell Cb
440 * Function : getSchCellCb
442 * Functionality: Function to get SCH Cell Cb
444 * @params[in] event, SchUeCfg pointer
445 * @return schUeCb pointer - success
448 * ****************************************************************/
450 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
453 SchCellCb *cellCb = NULLP;
455 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
457 /* Search of cell cb */
458 for(idx = 0; idx < MAX_NUM_CELL; idx++)
460 cellCb = schCb[inst].cells[idx];
461 if(cellCb->cellId == ueCfg->cellId)
464 if(idx == MAX_NUM_CELL)
466 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
467 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
471 /* Check if max number of UE configured */
472 if(cellCb->numActvUe > MAX_NUM_UE)
474 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
475 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
482 /*******************************************************************
484 * @brief Function to Add Ue Config Request from MAC
488 * Function : MacSchAddUeConfigReq
490 * Functionality: Function to Add Ue config request from MAC
493 * @return ROK - success
496 * ****************************************************************/
497 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
499 uint8_t ueIdx, lcIdx, ret = ROK;
500 SchCellCb *cellCb = NULLP;
501 SchUeCb *ueCb = NULLP;
503 Inst inst = pst->dstInst - 1;
504 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
506 #ifdef CALL_FLOW_DEBUG_LOG
507 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
512 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
515 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
516 cellCb = getSchCellCb(pst->event, inst, ueCfg);
518 /* Search if UE already configured */
519 GET_UE_IDX(ueCfg->crnti, ueIdx);
520 ueCb = &cellCb->ueCb[ueIdx -1];
523 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
525 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
526 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
532 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
533 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
537 /* Fill received Ue Configuration in UeCb */
538 memset(ueCb, 0, sizeof(SchUeCb));
539 GET_UE_IDX(ueCfg->crnti, ueIdx);
541 ueCb->crnti = ueCfg->crnti;
542 ueCb->state = SCH_UE_STATE_ACTIVE;
543 ret = fillSchUeCb(ueCb, ueCfg);
547 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
548 ueCb->cellCb = cellCb;
549 ueCb->srRcvd = false;
550 ueCb->bsrRcvd = false;
551 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
552 ueCb->bsrInfo[lcIdx].dataVol = 0;
554 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
559 /*******************************************************************
561 * @brief Fills PUSCH UL allocation
565 * Function : schFillPuschAlloc
567 * Functionality: fills PUSCH info
570 * @return ROK - success
573 * ****************************************************************/
574 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t dataVol, uint8_t k2, uint8_t startSymb, uint8_t symbLen)
576 uint16_t startRb = 0;
580 SchCellCb *cellCb = ueCb->cellCb;
581 SchUlSlotInfo *schUlSlotInfo = NULLP;
582 SchPuschInfo puschInfo;
584 startRb = MAX_NUM_RB;
585 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
586 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
587 allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startRb, numRb);
589 puschInfo.crnti = ueCb->crnti;
590 puschInfo.harqProcId = SCH_HARQ_PROC_ID;
591 puschInfo.resAllocType = SCH_ALLOC_TYPE_1;
592 puschInfo.fdAlloc.startPrb = startRb;
593 puschInfo.fdAlloc.numPrb = numRb;
594 puschInfo.tdAlloc.startSymb = startSymb;
595 puschInfo.tdAlloc.numSymb = symbLen;
596 puschInfo.tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
597 puschInfo.tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
598 puschInfo.tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
599 puschInfo.tbInfo.ndi = 1; /* new transmission */
600 puschInfo.tbInfo.rv = 0;
601 puschInfo.tbInfo.tbSize = tbSize;
602 puschInfo.dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
603 puschInfo.nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
604 puschInfo.dmrsAddPos = DMRS_ADDITIONAL_POS;
606 schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
607 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
608 if(!schUlSlotInfo->schPuschInfo)
610 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
613 memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
618 /*******************************************************************
620 * @brief Fills DCI for UL grant
624 * Function : schFillUlDci
626 * Functionality: fills DCI for UL grant in response to BSR
629 * @return ROK - success
632 * ****************************************************************/
633 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
635 SchCellCb *cellCb = ueCb->cellCb;
636 SchControlRsrcSet coreset1 ;
638 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
639 if(ueCb->ueCfg.spCellCfgPres == true)
641 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
644 dciInfo->cellId = cellCb->cellId;
645 dciInfo->crnti = ueCb->crnti;
648 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
649 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
650 dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb;
651 dciInfo->bwpCfg.freqAlloc.numPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb;
653 /*fill coreset cfg */
654 //Considering number of RBs in coreset1 is same as coreset0
655 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
656 //Considering coreset1 also starts from same symbol as coreset0
657 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
658 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
659 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
661 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
662 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
663 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
664 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
665 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
666 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
667 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
668 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
670 dciInfo->formatType = FORMAT0_0;
673 dciInfo->format.format0_0.resourceAllocType = puschInfo->resAllocType;
674 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo->fdAlloc.startPrb;
675 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo->fdAlloc.numPrb;
676 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
677 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo->tdAlloc.numSymb;
678 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
679 dciInfo->format.format0_0.mcs = puschInfo->tbInfo.mcs;
680 dciInfo->format.format0_0.harqProcId = puschInfo->harqProcId;
681 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
682 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
683 dciInfo->format.format0_0.ndi = puschInfo->tbInfo.ndi; /* new transmission */
684 dciInfo->format.format0_0.rv = puschInfo->tbInfo.rv;
685 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
686 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
688 /* Fill DCI Structure */
689 dciInfo->dciInfo.rnti = ueCb->crnti;
690 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
691 dciInfo->dciInfo.scramblingRnti = 0;
692 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
693 dciInfo->dciInfo.aggregLevel = 4;
694 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
695 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
696 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
697 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
698 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
699 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
700 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
701 dciInfo->dciInfo.pdschCfg = NULL; /* No DL data being sent */
706 /*******************************************************************
708 * @brief Function to Modify Ue Config request from MAC
712 * Function : MacSchModUeConfigReq
714 * Functionality: Function to modify Ue Config request from MAC
717 * @return ROK - success
720 * ****************************************************************/
721 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
723 uint8_t ueIdx, lcIdx, ret = ROK;
724 SchCellCb *cellCb = NULLP;
725 SchUeCb *ueCb = NULLP;
727 Inst inst = pst->dstInst - 1;
728 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
730 #ifdef CALL_FLOW_DEBUG_LOG
731 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
736 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
739 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
740 cellCb = getSchCellCb(pst->event, inst, ueCfg);
742 /* Search if UE already configured */
743 GET_UE_IDX(ueCfg->crnti, ueIdx);
744 ueCb = &cellCb->ueCb[ueIdx -1];
748 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
749 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
752 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
754 /* Found the UeCb to Reconfig */
755 ret = fillSchUeCb(ueCb, ueCfg);
758 ueCb->cellCb = cellCb;
759 ueCb->srRcvd = false;
760 ueCb->bsrRcvd = false;
761 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
762 ueCb->bsrInfo[lcIdx].dataVol = 0;
764 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
770 /*******************************************************************
772 * @brief Fill and send UE delete response to MAC
776 * Function : SchSendUeDeleteRspToMac
778 * Functionality: Fill and send UE delete response to MAC
780 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
782 * @return ROK - success
785 * ****************************************************************/
786 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
789 SchUeDeleteRsp delRsp;
791 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
792 delRsp.cellId = ueDelete->cellId;
793 delRsp.crnti = ueDelete->crnti;
795 delRsp.cause = cause;
797 /* Filling response post */
798 memset(&rspPst, 0, sizeof(Pst));
799 FILL_PST_SCH_TO_MAC(rspPst, inst);
800 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
801 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
804 /*******************************************************************
806 * @brief Function to delete Sch Pucch ResrcCfg
810 * Function : deleteSchPucchResrcCfg
812 * Functionality: Function to delete Sch Pucch ResrcCfg
814 * @params[in] SchPucchResrcCfg *resrc
817 * ****************************************************************/
819 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
822 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
824 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
828 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
829 sizeof(SchPucchFormat0));
834 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
835 sizeof(SchPucchFormat1));
840 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
841 sizeof(SchPucchFormat2_3));
846 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
847 sizeof(SchPucchFormat2_3));
852 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
853 sizeof(SchPucchFormat4));
860 /*******************************************************************
862 * @brief Function to delete SCH Pdsch ServCellCfg
866 * Function : deleteSchPdschServCellCfg
868 * Functionality: Function to delete SCH Pdsch ServCellCfg
870 * @params[in] SchPdschServCellCfg *pdschServCellCfg
873 * ****************************************************************/
875 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
877 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
878 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
879 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
880 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
883 /*******************************************************************
885 * @brief Function to delete SCH UeCb
889 * Function : deleteSchUeCb
891 * Functionality: Function to delete SCH UeCb
894 * @return ROK - success
897 * ****************************************************************/
898 void deleteSchUeCb(SchUeCb *ueCb)
900 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
901 SchPucchCfg *pucchCfg = NULLP;
902 SchPdschConfig *pdschCfg = NULLP;
903 CmLListCp *lcLL = NULLP;
907 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
908 if(ueCb->ueCfg.spCellCfgPres)
910 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
912 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
913 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
914 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
917 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
919 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
920 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
923 deleteSchPucchResrcCfg(pucchCfg->resrc);
924 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
926 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
927 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
928 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
929 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
930 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
931 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
932 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
933 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
934 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
936 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
937 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
939 /*Need to Free the memory allocated for S-NSSAI*/
940 for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
942 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
943 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
946 /*Clearing out Dedicated LC list*/
947 if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
949 lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
951 SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
953 if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
955 lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
957 SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
959 /*Deleteing the Default LC list*/
960 lcLL = &(ueCb->dlLcPrbEst.defLcList);
963 lcLL = &(ueCb->ulLcPrbEst.defLcList);
966 memset(ueCb, 0, sizeof(SchUeCb));
970 /*******************************************************************
972 * @brief Function for Ue Delete request from MAC to SCH
976 * Function : MacSchUeDeleteReq
978 * Functionality: Function for Ue Delete request from MAC to SCH
980 * @params[in] Pst *pst, SchUeDelete *ueDelete
981 * @return ROK - success
984 * ****************************************************************/
985 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
987 uint8_t idx=0, ueId=0, ueIdToDel=0, ret=ROK;
989 SchCellCb *cellCb = NULLP;
990 Inst inst = pst->dstInst - 1;
991 CmLList *node = NULL, *next = NULL;
993 #ifdef CALL_FLOW_DEBUG_LOG
994 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
999 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1002 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1004 cellCb = schCb[inst].cells[idx];
1006 if(cellCb->cellId != ueDelete->cellId)
1008 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
1009 result = INVALID_CELLID;
1013 GET_UE_IDX(ueDelete->crnti, ueId);
1014 if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1016 deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1018 /* Remove UE from ueToBeScheduled list */
1019 node = cellCb->ueToBeScheduled.first;
1023 ueId = *(uint8_t *)node->node;
1024 if(ueId == ueIdToDel)
1026 SCH_FREE(node->node, sizeof(uint8_t));
1027 cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1032 cellCb->numActvUe--;
1033 result = NOT_APPLICABLE;
1037 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
1038 result = INVALID_UEIDX;
1042 if(result == NOT_APPLICABLE)
1044 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1048 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1054 /*******************************************************************
1056 * @brief Fill and send Cell delete response to MAC
1060 * Function : SchSendCellDeleteRspToMac
1062 * Functionality: Fill and send Cell delete response to MAC
1064 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
1065 * @return ROK - success
1068 * ****************************************************************/
1069 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
1074 SchCellDeleteRsp delRsp;
1076 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
1077 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1078 delRsp.cellId = ueDelete->cellId;
1079 delRsp.rsp = result;
1081 /* Filling response post */
1082 memset(&rspPst, 0, sizeof(Pst));
1083 FILL_PST_SCH_TO_MAC(rspPst, inst);
1084 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1085 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1088 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1094 /*******************************************************************
1096 * @brief Function for cellCb Deletion
1100 * Function : deleteSchCellCb
1102 * Functionality: Function for cellCb Deletion
1104 * @params[in] SchCellDelete *cellDelete
1105 * @return ROK - success
1108 * ****************************************************************/
1109 void deleteSchCellCb(SchCellCb *cellCb)
1111 uint8_t sliceIdx=0, slotIdx=0;
1112 CmLListCp *list=NULL;
1113 CmLList *node=NULL, *next=NULL;
1115 if(cellCb->schDlSlotInfo)
1117 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1119 list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1124 SCH_FREE(node->node, sizeof(FreePrbBlock));
1125 deleteNodeFromLList(list, node);
1128 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1130 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1133 if(cellCb->schUlSlotInfo)
1135 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1137 list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1142 SCH_FREE(node->node, sizeof(FreePrbBlock));
1143 deleteNodeFromLList(list, node);
1146 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1148 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1151 if(cellCb->cellCfg.snssai)
1153 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.numSliceSupport; sliceIdx++)
1155 SCH_FREE(cellCb->cellCfg.snssai[sliceIdx], sizeof(Snssai));
1157 SCH_FREE(cellCb->cellCfg.snssai, cellCb->cellCfg.numSliceSupport*sizeof(Snssai*));
1159 SCH_FREE(cellCb->cellCfg.rrmPolicy, sizeof(SchRrmPolicy));
1161 /* Remove all UE from ueToBeScheduled list and deallocate */
1162 node = cellCb->ueToBeScheduled.first;
1166 SCH_FREE(node->node, sizeof(uint8_t));
1167 cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1171 memset(cellCb, 0, sizeof(SchCellCb));
1175 /*******************************************************************
1177 * @brief Function for cell Delete request from MAC to SCH
1181 * Function : MacSchCellDeleteReq
1183 * Functionality: Function for cell Delete request from MAC to SCH
1185 * @params[in] Pst *pst, SchCellDelete *cellDelete
1186 * @return ROK - success
1189 * ****************************************************************/
1191 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1193 uint8_t cellIdx=0, ret = RFAILED;
1194 Inst inst = pst->dstInst - 1;
1195 SchMacRsp result= RSP_OK;
1197 #ifdef CALL_FLOW_DEBUG_LOG
1198 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1203 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1207 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1208 if(schCb[inst].cells[cellIdx] == NULLP)
1210 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1215 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1217 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1220 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1221 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1225 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1230 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1232 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1240 /**********************************************************************
1242 **********************************************************************/