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 Sch Ul Lc Cb
179 * Function : updateSchUlCb
181 * Functionality: Function to update SCH Ul Lc Cb
185 * ****************************************************************/
187 void updateSchUlCb(uint8_t delIdx, SchUlCb *ulInfo)
191 for(lcIdx = delIdx; lcIdx < ulInfo->numUlLc; lcIdx++)
193 memcpy(&ulInfo->ulLcCtxt[lcIdx], &ulInfo->ulLcCtxt[lcIdx+1], sizeof(SchUlLcCtxt));
194 memset(&ulInfo->ulLcCtxt[lcIdx+1], 0, sizeof(SchUlLcCtxt));
196 /*Leakage of Last Index*/
197 /*Last index of ulLcCtxt(before deletion) should be void*/
198 if(ulInfo->ulLcCtxt[ulInfo->numUlLc].snssai != NULLP)
200 DU_LOG("ERROR --> SCH: updateSchUlCb Last index:%d (Before Deletion) memory is leaking",\
202 SCH_FREE(ulInfo->ulLcCtxt[ulInfo->numUlLc].snssai, sizeof(Snssai));
206 DU_LOG("INFO --> SCH: updateSchUlCb Last index:%d (before deletion) memory is freed successfully",\
212 /*******************************************************************
214 * @brief Function to update SCH Dl Lc Cb
218 * Function : updateSchDlCb
220 * Functionality: Function to update SCH DL Lc Cb
224 * ****************************************************************/
226 void updateSchDlCb(uint8_t delIdx, SchDlCb *dlInfo)
230 for(lcIdx = delIdx; lcIdx < dlInfo->numDlLc; lcIdx++)
232 memcpy(&dlInfo->dlLcCtxt[lcIdx], &dlInfo->dlLcCtxt[lcIdx+1], sizeof(SchDlLcCtxt));
233 memset(&dlInfo->dlLcCtxt[lcIdx+1], 0, sizeof(SchDlLcCtxt));
235 /*Leakage of Last Index*/
236 /*Last index of ulLcCtxt(before deletion) should be void*/
237 if(dlInfo->dlLcCtxt[dlInfo->numDlLc].snssai != NULLP)
239 DU_LOG("ERROR --> SCH: updateSchDlCb Last index:%d (before deletion) memory is leaking: Delete the S-NSSAI memory",\
241 SCH_FREE(dlInfo->dlLcCtxt[dlInfo->numDlLc].snssai, sizeof(Snssai));
245 DU_LOG("INFO --> SCH: updateSchDlCb Last index:%d (before deletion) memory is freed successfully",\
250 /*******************************************************************
252 * @brief Function to fill SchUeCb
256 * Function : fillSchUeCb
258 * Functionality: Function to fill SchUeCb
260 * @params[in] SchUeCb pointer,
262 * @return ROK/RFAILED
264 * ****************************************************************/
266 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
268 uint8_t lcIdx, ueLcIdx;
269 uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
270 SchPdschCfgCmn pdschCfg;
271 SchPucchDlDataToUlAck *dlDataToUlAck;
273 ueCb->ueCfg.cellId = ueCfg->cellId;
274 ueCb->ueCfg.crnti = ueCfg->crnti;
275 if(ueCfg->macCellGrpCfgPres == true)
277 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
278 ueCb->ueCfg.macCellGrpCfgPres = true;
281 if(ueCfg->phyCellGrpCfgPres == true)
283 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
284 ueCb->ueCfg.phyCellGrpCfgPres = true;
287 if(ueCfg->spCellCfgPres == true)
289 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
291 covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
293 memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
294 memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
296 ueCb->ueCfg.spCellCfgPres = true;
297 dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
302 BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
303 ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
304 dlDataToUlAck->dlDataToUlAckList);
305 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
306 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
307 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
312 ueCb->state = SCH_UE_STATE_ACTIVE;
315 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
316 ueCb->ueCfg.ambrCfg = ueCfg->ambrCfg;
318 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
319 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
321 //Updating SchUlCb and SchDlCb DB in SchUeCb
322 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
324 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
326 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueCb->ulInfo.numUlLc], &ueCfg->schLcCfg[lcIdx]);
327 ueCb->ulInfo.numUlLc++;
328 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueCb->dlInfo.numDlLc], &ueCfg->schLcCfg[lcIdx]);
329 ueCb->dlInfo.numDlLc++;
333 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++) //searching for Lc to be Mod
335 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
337 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
339 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
342 /*BUG: ueCfg using lcIdx (Looping around numLCs in ueCfg whereas
343 * ueLcIdx Loops around numUlLc in SCH UL DB*/
344 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
346 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
347 ueCb->ulInfo.numUlLc--;
348 updateSchUlCb(ueLcIdx, &ueCb->ulInfo); //moving arr elements one idx ahead
353 }/*End of inner for loop */
355 for(ueLcIdx = 0; ueLcIdx < ueCb->dlInfo.numDlLc; ueLcIdx++) //searching for Lc to be Mod
357 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
359 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
361 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
364 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
366 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
367 ueCb->dlInfo.numDlLc--;
368 updateSchDlCb(ueLcIdx, &ueCb->dlInfo); //moving arr elements one idx ahead
372 }/*End of inner for loop */
375 SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
376 SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
378 }/* End of outer for loop */
382 /*******************************************************************
384 * @brief Function to get SCH Cell Cb
388 * Function : getSchCellCb
390 * Functionality: Function to get SCH Cell Cb
392 * @params[in] event, SchUeCfg pointer
393 * @return schUeCb pointer - success
396 * ****************************************************************/
398 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
401 SchCellCb *cellCb = NULLP;
403 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
405 /* Search of cell cb */
406 for(idx = 0; idx < MAX_NUM_CELL; idx++)
408 cellCb = schCb[inst].cells[idx];
409 if(cellCb->cellId == ueCfg->cellId)
412 if(idx == MAX_NUM_CELL)
414 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
415 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
419 /* Check if max number of UE configured */
420 if(cellCb->numActvUe > MAX_NUM_UE)
422 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
423 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
430 /*******************************************************************
432 * @brief Function to Add Ue Config Request from MAC
436 * Function : MacSchAddUeConfigReq
438 * Functionality: Function to Add Ue config request from MAC
441 * @return ROK - success
444 * ****************************************************************/
445 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
447 uint8_t ueIdx, lcIdx, ret = ROK;
448 SchCellCb *cellCb = NULLP;
449 SchUeCb *ueCb = NULLP;
451 Inst inst = pst->dstInst - 1;
452 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
454 #ifdef CALL_FLOW_DEBUG_LOG
455 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
460 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
463 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
464 cellCb = getSchCellCb(pst->event, inst, ueCfg);
466 /* Search if UE already configured */
467 GET_UE_IDX(ueCfg->crnti, ueIdx);
468 ueCb = &cellCb->ueCb[ueIdx -1];
471 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
473 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
474 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
480 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
481 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
485 /* Fill received Ue Configuration in UeCb */
486 memset(ueCb, 0, sizeof(SchUeCb));
487 GET_UE_IDX(ueCfg->crnti, ueIdx);
489 ueCb->crnti = ueCfg->crnti;
490 ueCb->state = SCH_UE_STATE_ACTIVE;
491 ret = fillSchUeCb(ueCb, ueCfg);
495 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
496 ueCb->cellCb = cellCb;
497 ueCb->srRcvd = false;
498 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
499 ueCb->bsrInfo[lcIdx].dataVol = 0;
501 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
506 /*******************************************************************
508 * @brief Fills PUSCH UL allocation
512 * Function : schFillPuschAlloc
514 * Functionality: fills PUSCH info
517 * @return ROK - success
520 * ****************************************************************/
521 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo pdcchSlotTime, uint32_t dataVol, SchPuschInfo *puschInfo)
523 uint16_t startRb = 0;
527 uint8_t k2=0, startSymb=0 , symbLen=0;
528 SchCellCb *cellCb = ueCb->cellCb;
529 SchUlSlotInfo *schUlSlotInfo = NULLP;
530 SlotTimingInfo puschTime;
532 /* TODO : Scheduler to decide on which slot PUSCH is to be scheduled based on K2 Index table */
533 if(ueCb->ueCfg.spCellCfgPres == true)
535 k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
536 startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
537 symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
539 ADD_DELTA_TO_TIME(pdcchSlotTime, puschTime, k2);
541 startRb = MAX_NUM_RB;
542 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
543 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
544 allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startRb, numRb);
546 puschInfo->crnti = ueCb->crnti;
547 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
548 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
549 puschInfo->fdAlloc.startPrb = startRb;
550 puschInfo->fdAlloc.numPrb = numRb;
551 puschInfo->tdAlloc.startSymb = startSymb;
552 puschInfo->tdAlloc.numSymb = symbLen;
553 puschInfo->tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
554 puschInfo->tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
555 puschInfo->tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
556 puschInfo->tbInfo.ndi = 1; /* new transmission */
557 puschInfo->tbInfo.rv = 0;
558 puschInfo->tbInfo.tbSize = tbSize;
559 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
560 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
561 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
563 schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
564 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
565 if(!schUlSlotInfo->schPuschInfo)
567 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
570 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
575 /*******************************************************************
577 * @brief Fills DCI for UL grant
581 * Function : schFillUlDci
583 * Functionality: fills DCI for UL grant in response to BSR
586 * @return ROK - success
589 * ****************************************************************/
590 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
592 SchCellCb *cellCb = ueCb->cellCb;
593 SchControlRsrcSet coreset1 ;
595 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
596 if(ueCb->ueCfg.spCellCfgPres == true)
598 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
601 dciInfo->cellId = cellCb->cellId;
602 dciInfo->crnti = ueCb->crnti;
605 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
606 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
607 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
608 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
610 /*fill coreset cfg */
611 //Considering number of RBs in coreset1 is same as coreset0
612 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
613 //Considering coreset1 also starts from same symbol as coreset0
614 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
615 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
616 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
618 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
619 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
620 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
621 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
622 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
623 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
624 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
625 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
627 dciInfo->formatType = FORMAT0_0;
630 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
631 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
632 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
633 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
634 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
635 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
636 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
637 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
638 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
639 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
640 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
641 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
642 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
643 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
645 /* Fill DCI Structure */
646 dciInfo->dciInfo.rnti = ueCb->crnti;
647 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
648 dciInfo->dciInfo.scramblingRnti = 0;
649 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
650 dciInfo->dciInfo.aggregLevel = 4;
651 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
652 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
653 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
654 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
655 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
656 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
657 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
658 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
663 /*******************************************************************
665 * @brief Function to Modify Ue Config request from MAC
669 * Function : MacSchModUeConfigReq
671 * Functionality: Function to modify Ue Config request from MAC
674 * @return ROK - success
677 * ****************************************************************/
678 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
680 uint8_t ueIdx, lcIdx, ret = ROK;
681 SchCellCb *cellCb = NULLP;
682 SchUeCb *ueCb = NULLP;
684 Inst inst = pst->dstInst - 1;
685 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
687 #ifdef CALL_FLOW_DEBUG_LOG
688 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
693 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
696 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
697 cellCb = getSchCellCb(pst->event, inst, ueCfg);
699 /* Search if UE already configured */
700 GET_UE_IDX(ueCfg->crnti, ueIdx);
701 ueCb = &cellCb->ueCb[ueIdx -1];
705 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
706 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
709 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
711 /* Found the UeCb to Reconfig */
712 ret = fillSchUeCb(ueCb, ueCfg);
715 ueCb->cellCb = cellCb;
716 ueCb->srRcvd = false;
717 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
718 ueCb->bsrInfo[lcIdx].dataVol = 0;
720 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
726 /*******************************************************************
728 * @brief Fill and send UE delete response to MAC
732 * Function : SchSendUeDeleteRspToMac
734 * Functionality: Fill and send UE delete response to MAC
736 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
738 * @return ROK - success
741 * ****************************************************************/
742 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
745 SchUeDeleteRsp delRsp;
747 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
748 delRsp.cellId = ueDelete->cellId;
749 delRsp.crnti = ueDelete->crnti;
751 delRsp.cause = cause;
753 /* Filling response post */
754 memset(&rspPst, 0, sizeof(Pst));
755 FILL_PST_SCH_TO_MAC(rspPst, inst);
756 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
757 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
760 /*******************************************************************
762 * @brief Function to delete Sch Pucch ResrcCfg
766 * Function : deleteSchPucchResrcCfg
768 * Functionality: Function to delete Sch Pucch ResrcCfg
770 * @params[in] SchPucchResrcCfg *resrc
773 * ****************************************************************/
775 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
778 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
780 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
784 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
785 sizeof(SchPucchFormat0));
790 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
791 sizeof(SchPucchFormat1));
796 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
797 sizeof(SchPucchFormat2_3));
802 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
803 sizeof(SchPucchFormat2_3));
808 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
809 sizeof(SchPucchFormat4));
816 /*******************************************************************
818 * @brief Function to delete SCH Pdsch ServCellCfg
822 * Function : deleteSchPdschServCellCfg
824 * Functionality: Function to delete SCH Pdsch ServCellCfg
826 * @params[in] SchPdschServCellCfg *pdschServCellCfg
829 * ****************************************************************/
831 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
833 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
834 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
835 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
836 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
839 /*******************************************************************
841 * @brief Function to delete SCH UeCb
845 * Function : deleteSchUeCb
847 * Functionality: Function to delete SCH UeCb
850 * @return ROK - success
853 * ****************************************************************/
854 void deleteSchUeCb(SchUeCb *ueCb)
856 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
857 SchPucchCfg *pucchCfg = NULLP;
858 SchPdschConfig *pdschCfg = NULLP;
862 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
863 if(ueCb->ueCfg.spCellCfgPres)
865 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
867 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
868 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
869 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
872 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
874 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
875 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
878 deleteSchPucchResrcCfg(pucchCfg->resrc);
879 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
881 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
882 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
883 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
884 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
885 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
886 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
887 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
888 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
889 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
891 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
892 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
894 /*Need to Free the memory allocated for S-NSSAI*/
895 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++)
897 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
899 for(ueLcIdx = 0; ueLcIdx < ueCb->dlInfo.numDlLc; ueLcIdx++)
901 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
903 memset(ueCb, 0, sizeof(SchUeCb));
907 /*******************************************************************
909 * @brief Function for Ue Delete request from MAC to SCH
913 * Function : MacSchUeDeleteReq
915 * Functionality: Function for Ue Delete request from MAC to SCH
917 * @params[in] Pst *pst, SchUeDelete *ueDelete
918 * @return ROK - success
921 * ****************************************************************/
922 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
924 uint8_t idx=0, ueIdx=0, ret=ROK;
926 SchCellCb *cellCb = NULLP;
927 Inst inst = pst->dstInst - 1;
929 #ifdef CALL_FLOW_DEBUG_LOG
930 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
935 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
938 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
940 cellCb = schCb[inst].cells[idx];
942 if(cellCb->cellId != ueDelete->cellId)
944 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
945 result = INVALID_CELLID;
949 GET_UE_IDX(ueDelete->crnti, ueIdx);
950 if(( cellCb->ueCb[ueIdx-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueIdx-1].state == SCH_UE_STATE_ACTIVE))
952 deleteSchUeCb(&cellCb->ueCb[ueIdx-1]);
954 result = NOT_APPLICABLE;
958 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
959 result = INVALID_UEIDX;
963 if(result == NOT_APPLICABLE)
965 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
969 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
975 /*******************************************************************
977 * @brief Fill and send Cell delete response to MAC
981 * Function : SchSendCellDeleteRspToMac
983 * Functionality: Fill and send Cell delete response to MAC
985 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
986 * @return ROK - success
989 * ****************************************************************/
990 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
995 SchCellDeleteRsp delRsp;
997 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
998 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
999 delRsp.cellId = ueDelete->cellId;
1000 delRsp.rsp = result;
1002 /* Filling response post */
1003 memset(&rspPst, 0, sizeof(Pst));
1004 FILL_PST_SCH_TO_MAC(rspPst, inst);
1005 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1006 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1009 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1015 /*******************************************************************
1017 * @brief Function for cellCb Deletion
1021 * Function : deleteSchCellCb
1023 * Functionality: Function for cellCb Deletion
1025 * @params[in] SchCellDelete *cellDelete
1026 * @return ROK - success
1029 * ****************************************************************/
1030 void deleteSchCellCb(SchCellCb *cellCb)
1032 uint8_t sliceIdx=0, slotIdx=0;
1033 if(cellCb->schDlSlotInfo)
1035 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1037 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1039 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1041 if(cellCb->schUlSlotInfo)
1043 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1045 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1047 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1050 if(cellCb->cellCfg.snssai)
1052 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.numSliceSupport; sliceIdx++)
1054 SCH_FREE(cellCb->cellCfg.snssai[sliceIdx], sizeof(Snssai));
1056 SCH_FREE(cellCb->cellCfg.snssai, cellCb->cellCfg.numSliceSupport*sizeof(Snssai*));
1058 SCH_FREE(cellCb->cellCfg.rrmPolicy, sizeof(SchRrmPolicy));
1059 memset(cellCb, 0, sizeof(SchCellCb));
1063 /*******************************************************************
1065 * @brief Function for cell Delete request from MAC to SCH
1069 * Function : MacSchCellDeleteReq
1071 * Functionality: Function for cell Delete request from MAC to SCH
1073 * @params[in] Pst *pst, SchCellDelete *cellDelete
1074 * @return ROK - success
1077 * ****************************************************************/
1079 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1081 uint8_t cellIdx=0, ret = RFAILED;
1082 Inst inst = pst->dstInst - 1;
1083 SchMacRsp result= RSP_OK;
1085 #ifdef CALL_FLOW_DEBUG_LOG
1086 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1091 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1095 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1096 if(schCb[inst].cells[cellIdx] == NULLP)
1098 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1103 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1105 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1108 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1109 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1113 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1118 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1120 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1128 /**********************************************************************
1130 **********************************************************************/