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 SchPdschCfgCmn pdschCfg;
269 SchPucchDlDataToUlAck *dlDataToUlAck;
271 ueCb->ueCfg.cellId = ueCfg->cellId;
272 ueCb->ueCfg.crnti = ueCfg->crnti;
273 if(ueCfg->macCellGrpCfgPres == true)
275 memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg));
276 ueCb->ueCfg.macCellGrpCfgPres = true;
279 if(ueCfg->phyCellGrpCfgPres == true)
281 memcpy(&ueCb->ueCfg.phyCellGrpCfg , &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
282 ueCb->ueCfg.phyCellGrpCfgPres = true;
285 if(ueCfg->spCellCfgPres == true)
287 memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
288 ueCb->ueCfg.spCellCfgPres = true;
289 dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
294 BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
295 ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
296 dlDataToUlAck->dlDataToUlAckList);
297 BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
298 ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
299 NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
304 ueCb->state = SCH_UE_STATE_ACTIVE;
307 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
308 ueCb->ueCfg.ambrCfg = ueCfg->ambrCfg;
310 memcpy(&ueCb->ueCfg.dlModInfo, &ueCfg->dlModInfo , sizeof(SchModulationInfo));
311 memcpy(&ueCb->ueCfg.ulModInfo, &ueCfg->ulModInfo , sizeof(SchModulationInfo));
313 //Updating SchUlCb and SchDlCb DB in SchUeCb
314 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
316 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
318 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueCb->ulInfo.numUlLc], &ueCfg->schLcCfg[lcIdx]);
319 ueCb->ulInfo.numUlLc++;
320 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueCb->dlInfo.numDlLc], &ueCfg->schLcCfg[lcIdx]);
321 ueCb->dlInfo.numDlLc++;
325 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++) //searching for Lc to be Mod
327 if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
329 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
331 fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
334 /*BUG: ueCfg using lcIdx (Looping around numLCs in ueCfg whereas
335 * ueLcIdx Loops around numUlLc in SCH UL DB*/
336 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
338 memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
339 ueCb->ulInfo.numUlLc--;
340 updateSchUlCb(ueLcIdx, &ueCb->ulInfo); //moving arr elements one idx ahead
345 }/*End of inner for loop */
347 for(ueLcIdx = 0; ueLcIdx < ueCb->dlInfo.numDlLc; ueLcIdx++) //searching for Lc to be Mod
349 if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
351 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
353 fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
356 if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
358 memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
359 ueCb->dlInfo.numDlLc--;
360 updateSchDlCb(ueLcIdx, &ueCb->dlInfo); //moving arr elements one idx ahead
364 }/*End of inner for loop */
367 SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
368 SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
370 }/* End of outer for loop */
374 /*******************************************************************
376 * @brief Function to get SCH Cell Cb
380 * Function : getSchCellCb
382 * Functionality: Function to get SCH Cell Cb
384 * @params[in] event, SchUeCfg pointer
385 * @return schUeCb pointer - success
388 * ****************************************************************/
390 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
393 SchCellCb *cellCb = NULLP;
395 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
397 /* Search of cell cb */
398 for(idx = 0; idx < MAX_NUM_CELL; idx++)
400 cellCb = schCb[inst].cells[idx];
401 if(cellCb->cellId == ueCfg->cellId)
404 if(idx == MAX_NUM_CELL)
406 DU_LOG("\nERROR --> SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
407 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
411 /* Check if max number of UE configured */
412 if(cellCb->numActvUe > MAX_NUM_UE)
414 DU_LOG("\nERROR --> SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
415 SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
422 /*******************************************************************
424 * @brief Function to Add Ue Config Request from MAC
428 * Function : MacSchAddUeConfigReq
430 * Functionality: Function to Add Ue config request from MAC
433 * @return ROK - success
436 * ****************************************************************/
437 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
439 uint8_t ueIdx, lcIdx, ret = ROK;
440 SchCellCb *cellCb = NULLP;
441 SchUeCb *ueCb = NULLP;
443 Inst inst = pst->dstInst - 1;
444 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
446 #ifdef CALL_FLOW_DEBUG_LOG
447 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
452 DU_LOG("\nERROR --> SCH : Adding UE Config Request failed at MacSchAddUeConfigReq()");
455 DU_LOG("\nDEBUG --> SCH : Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
456 cellCb = getSchCellCb(pst->event, inst, ueCfg);
458 /* Search if UE already configured */
459 GET_UE_IDX(ueCfg->crnti, ueIdx);
460 ueCb = &cellCb->ueCb[ueIdx -1];
463 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
465 DU_LOG("\nDEBUG --> SCH : CRNTI %d already configured ", ueCfg->crnti);
466 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
472 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
473 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
477 /* Fill received Ue Configuration in UeCb */
478 memset(ueCb, 0, sizeof(SchUeCb));
479 GET_UE_IDX(ueCfg->crnti, ueIdx);
481 ueCb->crnti = ueCfg->crnti;
482 ueCb->state = SCH_UE_STATE_ACTIVE;
483 ret = fillSchUeCb(ueCb, ueCfg);
487 SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
488 ueCb->cellCb = cellCb;
489 ueCb->srRcvd = false;
490 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
491 ueCb->bsrInfo[lcIdx].dataVol = 0;
493 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
498 /*******************************************************************
500 * @brief Fills PUSCH UL allocation
504 * Function : schFillPuschAlloc
506 * Functionality: fills PUSCH info
509 * @return ROK - success
512 * ****************************************************************/
513 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
515 uint16_t puschSlot = 0;
516 uint16_t startRb = 0;
521 SchCellCb *cellCb = ueCb->cellCb;
522 SchUlSlotInfo *schUlSlotInfo = NULLP;
523 uint8_t k2=0, startSymb=0 , symbLen=11;
525 if(ueCb->ueCfg.spCellCfgPres == true)
527 k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
528 startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
529 symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
531 puschSlot = (pdcchSlot + k2) % cellCb->numSlots;
533 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
534 tbSize = schCalcTbSize(dataVol + buffer); /* 2 bytes header + some buffer */
535 numRb = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
536 /* increment PUSCH PRB */
538 cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
540 puschInfo->crnti = ueCb->crnti;
541 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
542 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
543 puschInfo->fdAlloc.startPrb = startRb;
544 puschInfo->fdAlloc.numPrb = numRb;
545 puschInfo->tdAlloc.startSymb = startSymb;
546 puschInfo->tdAlloc.numSymb = symbLen;
547 puschInfo->tbInfo.qamOrder = ueCb->ueCfg.ulModInfo.modOrder;
548 puschInfo->tbInfo.mcs = ueCb->ueCfg.ulModInfo.mcsIndex;
549 puschInfo->tbInfo.mcsTable = ueCb->ueCfg.ulModInfo.mcsTable;
550 puschInfo->tbInfo.ndi = 1; /* new transmission */
551 puschInfo->tbInfo.rv = 0;
552 puschInfo->tbInfo.tbSize = tbSize;
553 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
554 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
555 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
557 /* Update pusch in cell */
558 for(idx=startSymb; idx<symbLen; idx++)
560 //cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
563 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
565 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
566 if(!schUlSlotInfo->schPuschInfo)
568 DU_LOG("\nERROR --> SCH: Memory allocation failed in schAllocMsg3Pusch");
571 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
576 /*******************************************************************
578 * @brief Fills DCI for UL grant
582 * Function : schFillUlDci
584 * Functionality: fills DCI for UL grant in response to BSR
587 * @return ROK - success
590 * ****************************************************************/
591 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
593 SchCellCb *cellCb = ueCb->cellCb;
594 SchControlRsrcSet coreset1 ;
596 memset(&coreset1, 0, sizeof(SchControlRsrcSet));
597 if(ueCb->ueCfg.spCellCfgPres == true)
599 coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
602 dciInfo->cellId = cellCb->cellId;
603 dciInfo->crnti = ueCb->crnti;
606 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
607 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
608 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
609 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
611 /*fill coreset cfg */
612 //Considering number of RBs in coreset1 is same as coreset0
613 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
614 //Considering coreset1 also starts from same symbol as coreset0
615 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
616 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
617 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
619 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
620 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
621 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
622 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
623 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
624 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
625 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
626 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
628 dciInfo->formatType = FORMAT0_0;
631 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
632 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
633 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
634 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
635 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
636 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
637 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
638 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
639 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
640 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
641 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
642 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
643 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
644 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
646 /* Fill DCI Structure */
647 dciInfo->dciInfo.rnti = ueCb->crnti;
648 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
649 dciInfo->dciInfo.scramblingRnti = 0;
650 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
651 dciInfo->dciInfo.aggregLevel = 4;
652 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
653 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
654 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
655 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
656 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
657 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
658 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
659 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
664 /*******************************************************************
666 * @brief Function to Modify Ue Config request from MAC
670 * Function : MacSchModUeConfigReq
672 * Functionality: Function to modify Ue Config request from MAC
675 * @return ROK - success
678 * ****************************************************************/
679 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
681 uint8_t ueIdx, lcIdx, ret = ROK;
682 SchCellCb *cellCb = NULLP;
683 SchUeCb *ueCb = NULLP;
685 Inst inst = pst->dstInst - 1;
686 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
688 #ifdef CALL_FLOW_DEBUG_LOG
689 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
694 DU_LOG("\nERROR --> SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
697 DU_LOG("\nDEBUG --> SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
698 cellCb = getSchCellCb(pst->event, inst, ueCfg);
700 /* Search if UE already configured */
701 GET_UE_IDX(ueCfg->crnti, ueIdx);
702 ueCb = &cellCb->ueCb[ueIdx -1];
706 DU_LOG("\nERROR --> SCH : SchUeCb not found at MacSchModUeConfigReq() ");
707 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
710 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
712 /* Found the UeCb to Reconfig */
713 ret = fillSchUeCb(ueCb, ueCfg);
716 ueCb->cellCb = cellCb;
717 ueCb->srRcvd = false;
718 for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
719 ueCb->bsrInfo[lcIdx].dataVol = 0;
721 SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
727 /*******************************************************************
729 * @brief Fill and send UE delete response to MAC
733 * Function : SchSendUeDeleteRspToMac
735 * Functionality: Fill and send UE delete response to MAC
737 * @params[in] Inst inst, SchUeDelete *ueDelete, SchMacRsp result,
739 * @return ROK - success
742 * ****************************************************************/
743 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete *ueDelete, SchMacRsp result, ErrorCause cause)
746 SchUeDeleteRsp delRsp;
748 memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
749 delRsp.cellId = ueDelete->cellId;
750 delRsp.crnti = ueDelete->crnti;
752 delRsp.cause = cause;
754 /* Filling response post */
755 memset(&rspPst, 0, sizeof(Pst));
756 FILL_PST_SCH_TO_MAC(rspPst, inst);
757 rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
758 SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
761 /*******************************************************************
763 * @brief Function to delete Sch Pucch ResrcCfg
767 * Function : deleteSchPucchResrcCfg
769 * Functionality: Function to delete Sch Pucch ResrcCfg
771 * @params[in] SchPucchResrcCfg *resrc
774 * ****************************************************************/
776 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
779 for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
781 switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
785 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
786 sizeof(SchPucchFormat0));
791 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
792 sizeof(SchPucchFormat1));
797 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
798 sizeof(SchPucchFormat2_3));
803 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
804 sizeof(SchPucchFormat2_3));
809 SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
810 sizeof(SchPucchFormat4));
817 /*******************************************************************
819 * @brief Function to delete SCH Pdsch ServCellCfg
823 * Function : deleteSchPdschServCellCfg
825 * Functionality: Function to delete SCH Pdsch ServCellCfg
827 * @params[in] SchPdschServCellCfg *pdschServCellCfg
830 * ****************************************************************/
832 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
834 SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
835 SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
836 SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
837 SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
840 /*******************************************************************
842 * @brief Function to delete SCH UeCb
846 * Function : deleteSchUeCb
848 * Functionality: Function to delete SCH UeCb
851 * @return ROK - success
854 * ****************************************************************/
855 void deleteSchUeCb(SchUeCb *ueCb)
857 uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
858 SchPucchCfg *pucchCfg = NULLP;
859 SchPdschConfig *pdschCfg = NULLP;
863 SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
864 if(ueCb->ueCfg.spCellCfgPres)
866 if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
868 pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
869 for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
870 SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
873 if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
875 pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
876 SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
879 deleteSchPucchResrcCfg(pucchCfg->resrc);
880 SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
882 SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
883 SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
884 SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
885 SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
886 SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
887 SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
888 SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
889 SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
890 SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
892 SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
893 deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
895 /*Need to Free the memory allocated for S-NSSAI*/
896 for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++)
898 SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
900 for(ueLcIdx = 0; ueLcIdx < ueCb->dlInfo.numDlLc; ueLcIdx++)
902 SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
904 memset(ueCb, 0, sizeof(SchUeCb));
908 /*******************************************************************
910 * @brief Function for Ue Delete request from MAC to SCH
914 * Function : MacSchUeDeleteReq
916 * Functionality: Function for Ue Delete request from MAC to SCH
918 * @params[in] Pst *pst, SchUeDelete *ueDelete
919 * @return ROK - success
922 * ****************************************************************/
923 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete *ueDelete)
925 uint8_t idx=0, ueIdx=0, ret=ROK;
927 SchCellCb *cellCb = NULLP;
928 Inst inst = pst->dstInst - 1;
930 #ifdef CALL_FLOW_DEBUG_LOG
931 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
936 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): Ue Delete request failed");
939 DU_LOG("\nDEBUG --> SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
941 cellCb = schCb[inst].cells[idx];
943 if(cellCb->cellId != ueDelete->cellId)
945 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): cell Id is not available");
946 result = INVALID_CELLID;
950 GET_UE_IDX(ueDelete->crnti, ueIdx);
951 if(( cellCb->ueCb[ueIdx-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueIdx-1].state == SCH_UE_STATE_ACTIVE))
953 deleteSchUeCb(&cellCb->ueCb[ueIdx-1]);
955 result = NOT_APPLICABLE;
959 DU_LOG("\nERROR --> SCH : MacSchUeDeleteReq(): SchUeCb not found");
960 result = INVALID_UEIDX;
964 if(result == NOT_APPLICABLE)
966 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
970 SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
976 /*******************************************************************
978 * @brief Fill and send Cell delete response to MAC
982 * Function : SchSendCellDeleteRspToMac
984 * Functionality: Fill and send Cell delete response to MAC
986 * @params[in] SchCellDelete *ueDelete, Inst inst, SchMacRsp result
987 * @return ROK - success
990 * ****************************************************************/
991 uint8_t SchSendCellDeleteRspToMac(SchCellDelete *ueDelete, Inst inst, SchMacRsp result)
996 SchCellDeleteRsp delRsp;
998 DU_LOG("\nINFO --> SCH : Filling Cell Delete response");
999 memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1000 delRsp.cellId = ueDelete->cellId;
1001 delRsp.rsp = result;
1003 /* Filling response post */
1004 memset(&rspPst, 0, sizeof(Pst));
1005 FILL_PST_SCH_TO_MAC(rspPst, inst);
1006 rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1007 ret = SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1010 DU_LOG("\nERROR --> SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1016 /*******************************************************************
1018 * @brief Function for cellCb Deletion
1022 * Function : deleteSchCellCb
1024 * Functionality: Function for cellCb Deletion
1026 * @params[in] SchCellDelete *cellDelete
1027 * @return ROK - success
1030 * ****************************************************************/
1031 void deleteSchCellCb(SchCellCb *cellCb)
1033 uint8_t sliceIdx=0, slotIdx=0;
1034 if(cellCb->schDlSlotInfo)
1036 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1038 SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1040 SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1042 if(cellCb->schUlSlotInfo)
1044 for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1046 SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));
1048 SCH_FREE(cellCb->schUlSlotInfo, cellCb->numSlots * sizeof(SchUlSlotInfo*));
1051 if(cellCb->cellCfg.snssai)
1053 for(sliceIdx=0; sliceIdx<cellCb->cellCfg.numSliceSupport; sliceIdx++)
1055 SCH_FREE(cellCb->cellCfg.snssai[sliceIdx], sizeof(Snssai));
1057 SCH_FREE(cellCb->cellCfg.snssai, cellCb->cellCfg.numSliceSupport*sizeof(Snssai*));
1059 SCH_FREE(cellCb->cellCfg.rrmPolicy, sizeof(SchRrmPolicy));
1060 memset(cellCb, 0, sizeof(SchCellCb));
1064 /*******************************************************************
1066 * @brief Function for cell Delete request from MAC to SCH
1070 * Function : MacSchCellDeleteReq
1072 * Functionality: Function for cell Delete request from MAC to SCH
1074 * @params[in] Pst *pst, SchCellDelete *cellDelete
1075 * @return ROK - success
1078 * ****************************************************************/
1080 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete *cellDelete)
1082 uint8_t cellIdx=0, ret = RFAILED;
1083 Inst inst = pst->dstInst - 1;
1084 SchMacRsp result= RSP_OK;
1086 #ifdef CALL_FLOW_DEBUG_LOG
1087 DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1092 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1096 GET_CELL_IDX(cellDelete->cellId, cellIdx);
1097 if(schCb[inst].cells[cellIdx] == NULLP)
1099 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1104 if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1106 deleteSchCellCb(schCb[inst].cells[cellIdx]);
1109 SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1110 DU_LOG("\nINFO --> SCH : Sending Cell Delete response to MAC");
1114 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1119 if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1121 DU_LOG("\nERROR --> SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1129 /**********************************************************************
1131 **********************************************************************/