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 */
53 /*******************************************************************
55 * @brief Fill and send UE cfg response to MAC
59 * Function : SchSendUeCfgRspToMac
61 * Functionality: Fill and send UE cfg response to MAC
64 * @return ROK - success
67 * ****************************************************************/
68 void SchSendUeCfgRspToMac(uint16_t event, SchUeCfg *ueCfg, Inst inst,\
69 SchMacRsp result, SchUeCfgRsp *cfgRsp)
73 cfgRsp->cellId = ueCfg->cellId;
74 cfgRsp->crnti = ueCfg->crnti;
75 GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
78 /* Filling response post */
79 memset(&rspPst, 0, sizeof(Pst));
80 FILL_PST_SCH_TO_MAC(rspPst, inst);
81 if(event == EVENT_ADD_UE_CONFIG_REQ_TO_SCH)
83 rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
84 DU_LOG("\nINFO --> SCH : Sending UE Config response to MAC");
86 else if(event == EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH)
88 rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
89 DU_LOG("\nINFO --> SCH : Sending UE Reconfig response to MAC");
91 SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
94 /*******************************************************************
97 * @brief Function to fill Dl Lc Context in SCH Ue Cb
101 * Function : fillSchDlLcCtxt
103 * Functionality: Function to fill Dl Lc Context in SCH Ue Cb
105 * @params[in] SchDlLcCtxt pointer,
109 * ****************************************************************/
111 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
113 ueCbLcCfg->lcId = lcCfg->lcId;
114 ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
115 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
119 ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
123 if(ueCbLcCfg->snssai == NULLP)/*In CONFIG_MOD case, no need to allocate SNSSAI memory*/
125 SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
127 memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
131 /*******************************************************************
133 * @brief Function to fill Ul Lc Context in SCH Ue Cb
137 * Function : fillSchUlLcCtxt
139 * Functionality: Function to fill Ul Lc Context in SCH Ue Cb
141 * @params[in] SchUlLcCtxt pointer,
145 * ****************************************************************/
147 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
149 ueCbLcCfg->lcId = lcCfg->lcId;
150 ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
151 ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
152 ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
153 ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
154 ueCbLcCfg->pbr = lcCfg->ulLcCfg.pbr;
155 ueCbLcCfg->bsd = lcCfg->ulLcCfg.bsd;
159 ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
163 /*In CONFIG_MOD case, no need to allocate SNSSAI memory again*/
164 if(ueCbLcCfg->snssai == NULLP)
166 SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
168 memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
172 /*******************************************************************
174 * @brief Function to update Sch Ul Lc Cb
178 * Function : updateSchUlCb
180 * Functionality: Function to update SCH Ul Lc Cb
184 * ****************************************************************/
186 void updateSchUlCb(uint8_t delIdx, SchUlCb *ulInfo)
190 for(lcIdx = delIdx; lcIdx < ulInfo->numUlLc; lcIdx++)
192 memcpy(&ulInfo->ulLcCtxt[lcIdx], &ulInfo->ulLcCtxt[lcIdx+1], sizeof(SchUlLcCtxt));
193 memset(&ulInfo->ulLcCtxt[lcIdx+1], 0, sizeof(SchUlLcCtxt));
195 /*Leakage of Last Index*/
196 /*Last index of ulLcCtxt(before deletion) should be void*/
197 if(ulInfo->ulLcCtxt[ulInfo->numUlLc].snssai != NULLP)
199 DU_LOG("ERROR --> SCH: updateSchUlCb Last index:%d (Before Deletion) memory is leaking",\
201 SCH_FREE(ulInfo->ulLcCtxt[ulInfo->numUlLc].snssai, sizeof(Snssai));
205 DU_LOG("INFO --> SCH: updateSchUlCb Last index:%d (before deletion) memory is freed successfully",\
211 /*******************************************************************
213 * @brief Function to update SCH Dl Lc Cb
217 * Function : updateSchDlCb
219 * Functionality: Function to update SCH DL Lc Cb
223 * ****************************************************************/
225 void updateSchDlCb(uint8_t delIdx, SchDlCb *dlInfo)
229 for(lcIdx = delIdx; lcIdx < dlInfo->numDlLc; lcIdx++)
231 memcpy(&dlInfo->dlLcCtxt[lcIdx], &dlInfo->dlLcCtxt[lcIdx+1], sizeof(SchDlLcCtxt));
232 memset(&dlInfo->dlLcCtxt[lcIdx+1], 0, sizeof(SchDlLcCtxt));
234 /*Leakage of Last Index*/
235 /*Last index of ulLcCtxt(before deletion) should be void*/
236 if(dlInfo->dlLcCtxt[dlInfo->numDlLc].snssai != NULLP)
238 DU_LOG("ERROR --> SCH: updateSchDlCb Last index:%d (before deletion) memory is leaking: Delete the S-NSSAI memory",\
240 SCH_FREE(dlInfo->dlLcCtxt[dlInfo->numDlLc].snssai, sizeof(Snssai));
244 DU_LOG("INFO --> SCH: updateSchDlCb Last index:%d (before deletion) memory is freed successfully",\
249 /*******************************************************************
251 * @brief Function to fill SchUeCb
255 * Function : fillSchUeCb
257 * Functionality: Function to fill SchUeCb
259 * @params[in] SchUeCb pointer,
261 * @return ROK/RFAILED
263 * ****************************************************************/
265 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
267 uint8_t lcIdx, ueLcIdx;
268 uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
269 SchPdschCfgCmn pdschCfg;
270 SchPucchDlDataToUlAck *dlDataToUlAck;
272 ueCb->ueCfg.cellId = ueCfg->cellId;
273 ueCb->ueCfg.crnti = ueCfg->crnti;
274 if(ueCfg->macCellGrpCfgPres == true)
276 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
277 ueCb->ueCfg.macCellGrpCfgPres = true;
280 if(ueCfg->phyCellGrpCfgPres == true)
282 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
283 ueCb->ueCfg.phyCellGrpCfgPres = true;
286 if(ueCfg->spCellCfgPres == true)
288 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
290 covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
292 memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
293 memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
295 ueCb->ueCfg.spCellCfgPres = true;
296 dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
301 BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
302 ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
303 dlDataToUlAck->dlDataToUlAckList);
304 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
305 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
306 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
311 ueCb->state = SCH_UE_STATE_ACTIVE;
314 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
315 ueCb->ueCfg.ambrCfg = ueCfg->ambrCfg;
317 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
318 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
320 //Updating SchUlCb and SchDlCb DB in SchUeCb
321 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
323 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
325 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueCb->ulInfo.numUlLc], &ueCfg->schLcCfg[lcIdx]);
326 ueCb->ulInfo.numUlLc++;
327 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueCb->dlInfo.numDlLc], &ueCfg->schLcCfg[lcIdx]);
328 ueCb->dlInfo.numDlLc++;
332 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++) //searching for Lc to be Mod
334 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
336 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
338 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
341 /*BUG: ueCfg using lcIdx (Looping around numLCs in ueCfg whereas
342 * ueLcIdx Loops around numUlLc in SCH UL DB*/
343 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
345 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
346 ueCb->ulInfo.numUlLc--;
347 updateSchUlCb(ueLcIdx, &ueCb->ulInfo); //moving arr elements one idx ahead
352 }/*End of inner for loop */
354 for(ueLcIdx = 0; ueLcIdx < ueCb->dlInfo.numDlLc; ueLcIdx++) //searching for Lc to be Mod
356 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
358 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
360 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
363 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
365 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
366 ueCb->dlInfo.numDlLc--;
367 updateSchDlCb(ueLcIdx, &ueCb->dlInfo); //moving arr elements one idx ahead
371 }/*End of inner for loop */
374 SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
375 SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
377 }/* End of outer for loop */
381 /*******************************************************************
383 * @brief Function to get SCH Cell Cb
387 * Function : getSchCellCb
389 * Functionality: Function to get SCH Cell Cb
391 * @params[in] event, SchUeCfg pointer
392 * @return schUeCb pointer - success
395 * ****************************************************************/
397 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
400 SchCellCb *cellCb = NULLP;
402 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
404 /* Search of cell cb */
405 for(idx = 0; idx < MAX_NUM_CELL; idx++)
407 cellCb = schCb[inst].cells[idx];
408 if(cellCb->cellId == ueCfg->cellId)
411 if(idx == MAX_NUM_CELL)
413 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
414 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
418 /* Check if max number of UE configured */
419 if(cellCb->numActvUe > MAX_NUM_UE)
421 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
422 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
429 /*******************************************************************
431 * @brief Function to Add Ue Config Request from MAC
435 * Function : MacSchAddUeConfigReq
437 * Functionality: Function to Add Ue config request from MAC
440 * @return ROK - success
443 * ****************************************************************/
444 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
446 uint8_t ueIdx, lcIdx, ret = ROK;
447 SchCellCb *cellCb = NULLP;
448 SchUeCb *ueCb = NULLP;
450 Inst inst = pst->dstInst - 1;
451 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
453 #ifdef CALL_FLOW_DEBUG_LOG
454 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
459 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
462 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
463 cellCb = getSchCellCb(pst->event, inst, ueCfg);
465 /* Search if UE already configured */
466 GET_UE_IDX(ueCfg->crnti, ueIdx);
467 ueCb = &cellCb->ueCb[ueIdx -1];
470 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
472 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
473 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
479 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
480 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
484 /* Fill received Ue Configuration in UeCb */
485 memset(ueCb, 0, sizeof(SchUeCb));
486 GET_UE_IDX(ueCfg->crnti, ueIdx);
488 ueCb->crnti = ueCfg->crnti;
489 ueCb->state = SCH_UE_STATE_ACTIVE;
490 ret = fillSchUeCb(ueCb, ueCfg);
494 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
495 ueCb->cellCb = cellCb;
496 ueCb->srRcvd = false;
497 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
498 ueCb->bsrInfo[lcIdx].dataVol = 0;
500 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
505 /*******************************************************************
507 * @brief Fills PUSCH UL allocation
511 * Function : schFillPuschAlloc
513 * Functionality: fills PUSCH info
516 * @return ROK - success
519 * ****************************************************************/
520 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
522 uint16_t puschSlot = 0;
523 uint16_t startRb = 0;
528 SchCellCb *cellCb = ueCb->cellCb;
529 SchUlSlotInfo *schUlSlotInfo = NULLP;
530 uint8_t k2=0, startSymb=0 , symbLen=11;
532 if(ueCb->ueCfg.spCellCfgPres == true)
534 k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
535 startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
536 symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
538 puschSlot = (pdcchSlot + k2) % cellCb->numSlots;
540 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
541 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
542 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
543 /* increment PUSCH PRB */
545 cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
547 puschInfo->crnti = ueCb->crnti;
548 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
549 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
550 puschInfo->fdAlloc.startPrb = startRb;
551 puschInfo->fdAlloc.numPrb = numRb;
552 puschInfo->tdAlloc.startSymb = startSymb;
553 puschInfo->tdAlloc.numSymb = symbLen;
554 puschInfo->tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
555 puschInfo->tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
556 puschInfo->tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
557 puschInfo->tbInfo.ndi = 1; /* new transmission */
558 puschInfo->tbInfo.rv = 0;
559 puschInfo->tbInfo.tbSize = tbSize;
560 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
561 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
562 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
564 /* Update pusch in cell */
565 for(idx=startSymb; idx<symbLen; idx++)
567 //cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
570 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
572 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
573 if(!schUlSlotInfo->schPuschInfo)
575 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
578 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
583 /*******************************************************************
585 * @brief Fills DCI for UL grant
589 * Function : schFillUlDci
591 * Functionality: fills DCI for UL grant in response to BSR
594 * @return ROK - success
597 * ****************************************************************/
598 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
600 SchCellCb *cellCb = ueCb->cellCb;
601 SchControlRsrcSet coreset1 ;
603 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
604 if(ueCb->ueCfg.spCellCfgPres == true)
606 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
609 dciInfo->cellId = cellCb->cellId;
610 dciInfo->crnti = ueCb->crnti;
613 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
614 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
615 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
616 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
618 /*fill coreset cfg */
619 //Considering number of RBs in coreset1 is same as coreset0
620 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
621 //Considering coreset1 also starts from same symbol as coreset0
622 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
623 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
624 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
626 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
627 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
628 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
629 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
630 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
631 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
632 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
633 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
635 dciInfo->formatType = FORMAT0_0;
638 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
639 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
640 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
641 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
642 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
643 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
644 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
645 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
646 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
647 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
648 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
649 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
650 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
651 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
653 /* Fill DCI Structure */
654 dciInfo->dciInfo.rnti = ueCb->crnti;
655 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
656 dciInfo->dciInfo.scramblingRnti = 0;
657 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
658 dciInfo->dciInfo.aggregLevel = 4;
659 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
660 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
661 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
662 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
663 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
664 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
665 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
666 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
671 /*******************************************************************
673 * @brief Function to Modify Ue Config request from MAC
677 * Function : MacSchModUeConfigReq
679 * Functionality: Function to modify Ue Config request from MAC
682 * @return ROK - success
685 * ****************************************************************/
686 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
688 uint8_t ueIdx, lcIdx, ret = ROK;
689 SchCellCb *cellCb = NULLP;
690 SchUeCb *ueCb = NULLP;
692 Inst inst = pst->dstInst - 1;
693 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
695 #ifdef CALL_FLOW_DEBUG_LOG
696 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
701 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
704 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
705 cellCb = getSchCellCb(pst->event, inst, ueCfg);
707 /* Search if UE already configured */
708 GET_UE_IDX(ueCfg->crnti, ueIdx);
709 ueCb = &cellCb->ueCb[ueIdx -1];
713 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
714 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
717 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
719 /* Found the UeCb to Reconfig */
720 ret = fillSchUeCb(ueCb, ueCfg);
723 ueCb->cellCb = cellCb;
724 ueCb->srRcvd = false;
725 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
726 ueCb->bsrInfo[lcIdx].dataVol = 0;
728 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
734 /*******************************************************************
736 * @brief Fill and send UE delete response to MAC
740 * Function : SchSendUeDeleteRspToMac
742 * Functionality: Fill and send UE delete response to MAC
744 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
746 * @return ROK - success
749 * ****************************************************************/
750 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
753 SchUeDeleteRsp delRsp;
755 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
756 delRsp.cellId = ueDelete->cellId;
757 delRsp.crnti = ueDelete->crnti;
759 delRsp.cause = cause;
761 /* Filling response post */
762 memset(&rspPst, 0, sizeof(Pst));
763 FILL_PST_SCH_TO_MAC(rspPst, inst);
764 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
765 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
768 /*******************************************************************
770 * @brief Function to delete Sch Pucch ResrcCfg
774 * Function : deleteSchPucchResrcCfg
776 * Functionality: Function to delete Sch Pucch ResrcCfg
778 * @params[in] SchPucchResrcCfg *resrc
781 * ****************************************************************/
783 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
786 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
788 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
792 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
793 sizeof(SchPucchFormat0));
798 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
799 sizeof(SchPucchFormat1));
804 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
805 sizeof(SchPucchFormat2_3));
810 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
811 sizeof(SchPucchFormat2_3));
816 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
817 sizeof(SchPucchFormat4));
824 /*******************************************************************
826 * @brief Function to delete SCH Pdsch ServCellCfg
830 * Function : deleteSchPdschServCellCfg
832 * Functionality: Function to delete SCH Pdsch ServCellCfg
834 * @params[in] SchPdschServCellCfg *pdschServCellCfg
837 * ****************************************************************/
839 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
841 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
842 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
843 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
844 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
847 /*******************************************************************
849 * @brief Function to delete SCH UeCb
853 * Function : deleteSchUeCb
855 * Functionality: Function to delete SCH UeCb
858 * @return ROK - success
861 * ****************************************************************/
862 void deleteSchUeCb(SchUeCb *ueCb)
864 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
865 SchPucchCfg *pucchCfg = NULLP;
866 SchPdschConfig *pdschCfg = NULLP;
870 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
871 if(ueCb->ueCfg.spCellCfgPres)
873 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
875 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
876 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
877 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
880 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
882 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
883 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
886 deleteSchPucchResrcCfg(pucchCfg->resrc);
887 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
889 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
890 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
891 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
892 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
893 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
894 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
895 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
896 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
897 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
899 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
900 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
902 /*Need to Free the memory allocated for S-NSSAI*/
903 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++)
905 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
907 for(ueLcIdx = 0; ueLcIdx < ueCb->dlInfo.numDlLc; ueLcIdx++)
909 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
911 memset(ueCb, 0, sizeof(SchUeCb));
915 /*******************************************************************
917 * @brief Function for Ue Delete request from MAC to SCH
921 * Function : MacSchUeDeleteReq
923 * Functionality: Function for Ue Delete request from MAC to SCH
925 * @params[in] Pst *pst, SchUeDelete *ueDelete
926 * @return ROK - success
929 * ****************************************************************/
930 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
932 uint8_t idx=0, ueIdx=0, ret=ROK;
934 SchCellCb *cellCb = NULLP;
935 Inst inst = pst->dstInst - 1;
937 #ifdef CALL_FLOW_DEBUG_LOG
938 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
943 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
946 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
948 cellCb = schCb[inst].cells[idx];
950 if(cellCb->cellId != ueDelete->cellId)
952 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
953 result = INVALID_CELLID;
957 GET_UE_IDX(ueDelete->crnti, ueIdx);
958 if(( cellCb->ueCb[ueIdx-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueIdx-1].state == SCH_UE_STATE_ACTIVE))
960 deleteSchUeCb(&cellCb->ueCb[ueIdx-1]);
962 result = NOT_APPLICABLE;
966 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
967 result = INVALID_UEIDX;
971 if(result == NOT_APPLICABLE)
973 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
977 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
983 /*******************************************************************
985 * @brief Fill and send Cell delete response to MAC
989 * Function : SchSendCellDeleteRspToMac
991 * Functionality: Fill and send Cell delete response to MAC
993 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
994 * @return ROK - success
997 * ****************************************************************/
998 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
1003 SchCellDeleteRsp delRsp;
1005 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
1006 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1007 delRsp.cellId = ueDelete->cellId;
1008 delRsp.rsp = result;
1010 /* Filling response post */
1011 memset(&rspPst, 0, sizeof(Pst));
1012 FILL_PST_SCH_TO_MAC(rspPst, inst);
1013 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1014 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1017 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1023 /*******************************************************************
1025 * @brief Function for cellCb Deletion
1029 * Function : deleteSchCellCb
1031 * Functionality: Function for cellCb Deletion
1033 * @params[in] SchCellDelete *cellDelete
1034 * @return ROK - success
1037 * ****************************************************************/
1038 void deleteSchCellCb(SchCellCb *cellCb)
1040 uint8_t sliceIdx=0, slotIdx=0;
1041 if(cellCb->schDlSlotInfo)
1043 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1045 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1047 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1049 if(cellCb->schUlSlotInfo)
1051 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1053 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1055 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1058 if(cellCb->cellCfg.snssai)
1060 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.numSliceSupport; sliceIdx++)
1062 SCH_FREE(cellCb->cellCfg.snssai[sliceIdx], sizeof(Snssai));
1064 SCH_FREE(cellCb->cellCfg.snssai, cellCb->cellCfg.numSliceSupport*sizeof(Snssai*));
1066 SCH_FREE(cellCb->cellCfg.rrmPolicy, sizeof(SchRrmPolicy));
1067 memset(cellCb, 0, sizeof(SchCellCb));
1071 /*******************************************************************
1073 * @brief Function for cell Delete request from MAC to SCH
1077 * Function : MacSchCellDeleteReq
1079 * Functionality: Function for cell Delete request from MAC to SCH
1081 * @params[in] Pst *pst, SchCellDelete *cellDelete
1082 * @return ROK - success
1085 * ****************************************************************/
1087 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1089 uint8_t cellIdx=0, ret = RFAILED;
1090 Inst inst = pst->dstInst - 1;
1091 SchMacRsp result= RSP_OK;
1093 #ifdef CALL_FLOW_DEBUG_LOG
1094 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1099 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1103 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1104 if(schCb[inst].cells[cellIdx] == NULLP)
1106 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1111 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1113 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1116 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1117 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1121 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1126 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1128 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1136 /**********************************************************************
1138 **********************************************************************/