<JIRA ID: ODUHIGH-386 : UL scheduling as per RRM policy
[o-du/l2.git] / src / 5gnrsch / sch_common.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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
19 /************************************************************************
20
21 Name:     5G NR SCH layer
22
23 Type:     C source file
24
25 Desc:     C source code for Entry point fucntions
26
27 File:     sch_common.c
28
29  **********************************************************************/
30
31 /** @file sch_common.c
32   @brief This module performs common scheduling
33  */
34 #include "common_def.h"
35 #include "tfu.h"
36 #include "lrg.h"
37
38 #include "tfu.x"
39 #include "lrg.x"
40 #include "du_log.h"
41 #include "du_app_mac_inf.h"
42 #include "mac_sch_interface.h"
43 #include "sch.h"
44 #include "sch_utils.h"
45
46 SchMacUlSchInfoFunc schMacUlSchInfoOpts[] =
47 {
48    packSchMacUlSchInfo,
49    MacProcUlSchInfo,
50    packSchMacUlSchInfo
51 };
52
53 /**
54  * @brief common resource allocation for SSB
55  *
56  * @details
57  *
58  *     Function : schBroadcastSsbAlloc
59  *     
60  *     This function handles common scheduling for SSB
61  *     
62  *  @param[in]  SchCellCb *cell, cell cb
63  *  @param[in]  DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
64  *  @return  void
65  **/
66 uint8_t schBroadcastSsbAlloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc)
67 {
68    /* schedule SSB */
69    uint8_t ssbStartSymb, idx;
70    uint16_t ssbStartPrb;
71    SchDlSlotInfo *schDlSlotInfo;
72    SsbInfo ssbInfo;
73
74    if(cell == NULL)
75    {
76       DU_LOG("\nERROR  -->  SCH: schBroadcastSsbAlloc() : Cell is NULL");
77       return RFAILED;
78    }
79
80    if(dlBrdcstAlloc == NULL)
81    {
82       DU_LOG("\nERROR  -->  SCH: schBroadcastSsbAlloc() : dlBrdcstAlloc is NULL");
83       return RFAILED;
84    }
85
86    schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
87    ssbStartPrb = cell->cellCfg.ssbSchCfg.ssbOffsetPointA; //+Kssb
88    ssbStartSymb = cell->ssbStartSymbArr[dlBrdcstAlloc->ssbIdxSupported-1]; /*since we are supporting only 1 ssb beam */
89
90    /* Assign interface structure */
91    for(idx=0; idx<dlBrdcstAlloc->ssbIdxSupported; idx++)
92    {
93       ssbInfo.ssbIdx              = idx;
94       ssbInfo.fdAlloc.startPrb    = ssbStartPrb;
95       ssbInfo.fdAlloc.numPrb      = SCH_SSB_NUM_PRB;
96       ssbInfo.tdAlloc.startSymb   = ssbStartSymb;
97       ssbInfo.tdAlloc.numSymb     = SCH_SSB_NUM_SYMB;
98       dlBrdcstAlloc->ssbInfo[idx] = ssbInfo;
99       schDlSlotInfo->ssbInfo[idx] = ssbInfo;
100    }
101
102    if((allocatePrbDl(cell, slotTime, ssbStartSymb, SCH_SSB_NUM_SYMB, &ssbInfo.fdAlloc.startPrb, ssbInfo.fdAlloc.numPrb)) != ROK)
103    {
104        DU_LOG("\nERROR  -->  SCH: PRB allocation failed for SSB in SFN:SLOT [%d : %d]", slotTime.sfn, slotTime.slot);
105        return RFAILED;
106    }
107
108
109    schDlSlotInfo->ssbPres = true;
110    schDlSlotInfo->ssbIdxSupported = dlBrdcstAlloc->ssbIdxSupported;
111    return ROK;
112 }
113
114 /**
115  * @brief common resource allocation for SIB1
116  *
117  * @details
118  *
119  *     Function : schBroadcastSib1Alloc
120  *     
121  *     This function handles common scheduling for SIB1
122  *     
123  *  @param[in]  SchCellCb *cell, cell cb
124  *  @param[in]  DlBrdcstAlloc *dlBrdcstAlloc, DL brdcst allocation
125  *  @return  void
126  **/
127 uint8_t schBroadcastSib1Alloc(SchCellCb *cell, SlotTimingInfo slotTime, DlBrdcstAlloc *dlBrdcstAlloc)
128 {
129    uint8_t dmrsStartSymbol, startSymbol, numSymbol ;
130    DmrsInfo dmrs;
131    FreqDomainAlloc freqAlloc;
132    TimeDomainAlloc timeAlloc;
133    SchDlSlotInfo *schDlSlotInfo = NULLP;
134
135    if(cell == NULL)
136    {
137       DU_LOG("\nERROR  -->  SCH: schBroadcastSsbAlloc() : Cell is NULL");
138       return RFAILED;
139    }
140
141    if(dlBrdcstAlloc == NULL)
142    {
143       DU_LOG("\nERROR  -->  SCH: schBroadcastSsbAlloc() : dlBrdcstAlloc is NULL");
144       return RFAILED;
145    }
146
147    dmrs = cell->cellCfg.sib1SchCfg.sib1PdschCfg.dmrs;
148    freqAlloc = cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschFreqAlloc.freqAlloc;
149    timeAlloc = cell->cellCfg.sib1SchCfg.sib1PdschCfg.pdschTimeAlloc.timeAlloc;
150    schDlSlotInfo = cell->schDlSlotInfo[slotTime.slot];
151
152    /* Find total symbols used including DMRS */
153    /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
154     * in that case only PDSCH symbols are marked as occupied */
155    dmrsStartSymbol = findDmrsStartSymbol(dmrs.dlDmrsSymbPos);   
156    if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
157    {
158       startSymbol = timeAlloc.startSymb;
159       numSymbol = timeAlloc.numSymb;
160    }
161    /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
162    else
163    {
164       startSymbol = dmrsStartSymbol;
165       numSymbol = dmrs.nrOfDmrsSymbols + timeAlloc.numSymb;
166    }
167
168    /* Allocate PRB */
169    if((allocatePrbDl(cell, slotTime, startSymbol, numSymbol, &freqAlloc.startPrb, freqAlloc.numPrb)) != ROK)
170    {
171        DU_LOG("\nERROR  -->  SCH: PRB allocation failed for SIB1 in SFN:Slot [%d : %d]", slotTime.sfn, slotTime.slot);
172        return RFAILED;
173    }
174
175    memcpy(&dlBrdcstAlloc->sib1Alloc.bwp, &cell->cellCfg.sib1SchCfg.bwp, sizeof(BwpCfg)); 
176    memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg, &cell->cellCfg.sib1SchCfg.sib1PdcchCfg, sizeof(PdcchCfg)); 
177    memcpy(&dlBrdcstAlloc->sib1Alloc.sib1PdschCfg, &cell->cellCfg.sib1SchCfg.sib1PdschCfg, sizeof(PdschCfg)); 
178    dlBrdcstAlloc->sib1Alloc.sib1PdcchCfg.dci.pdschCfg = &dlBrdcstAlloc->sib1Alloc.sib1PdschCfg;
179    schDlSlotInfo->sib1Pres = true;
180    return ROK;
181 }
182
183 /*******************************************************************
184  *
185  * @brief Handles sending UL scheduler info to MAC 
186  *
187  * @details
188  *
189  *    Function : sendUlSchInfoToMac
190  *
191  *    Functionality:
192  *     Sends UL Sch info to MAC from SCH
193  *
194  * @params[in] 
195  * @return ROK     - success
196  *         RFAILED - failure
197  *
198  * ****************************************************************/
199 int sendUlSchInfoToMac(UlSchedInfo *ulSchedInfo, Inst inst)
200 {
201    Pst pst;
202
203    memset(&pst, 0, sizeof(Pst));
204    FILL_PST_SCH_TO_MAC(pst, inst);
205    pst.event = EVENT_UL_SCH_INFO;
206
207    return(*schMacUlSchInfoOpts[pst.selector])(&pst, ulSchedInfo);
208 }
209
210 /**
211  * @brief Function to fill Pucch Format 0
212  *
213  * @details
214  *
215  *     Function : fillPucchFormat0
216  *     
217  *     Function to fill Pucch format 0
218  *     
219  *  @param[in]  SchPucchInfo pointer, SchPucchResrcInfo pointer
220  *  @return  void
221  **/
222
223 void fillPucchFormat0(SchPucchInfo *ulSchedPucch, SchPucchResrcInfo *resrcInfo)
224 {
225    if(resrcInfo->SchPucchFormat.format0)
226    {
227       ulSchedPucch->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
228       ulSchedPucch->pucchFormat  = PUCCH_FORMAT_0;
229       ulSchedPucch->initialCyclicShift =  resrcInfo->SchPucchFormat.format0->initialCyclicShift;
230       ulSchedPucch->tdAlloc.numSymb = resrcInfo->SchPucchFormat.format0->numSymbols;
231       ulSchedPucch->tdAlloc.startSymb = resrcInfo->SchPucchFormat.format0->startSymbolIdx;
232    }
233 }
234
235 /**
236  * @brief Function to fill Pucch Format 1
237  *
238  * @details
239  *
240  *     Function : fillPucchFormat1
241  *     
242  *     Function to fill Pucch format 1
243  *     
244  *  @param[in]  SchPucchInfo pointer, SchPucchResrcInfo pointer
245  *  @return  void
246  **/
247
248 void fillPucchFormat1(SchPucchInfo *ulSchedPucch, SchPucchResrcInfo *resrcInfo)
249 {
250    if(resrcInfo->SchPucchFormat.format1)
251    {
252       ulSchedPucch->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
253       ulSchedPucch->pucchFormat  = PUCCH_FORMAT_1;
254       ulSchedPucch->initialCyclicShift =  resrcInfo->SchPucchFormat.format1->initialCyclicShift;
255       ulSchedPucch->tdAlloc.numSymb = resrcInfo->SchPucchFormat.format1->numSymbols;
256       ulSchedPucch->tdAlloc.startSymb = resrcInfo->SchPucchFormat.format1->startSymbolIdx;
257       ulSchedPucch->timeDomOCC =  resrcInfo->SchPucchFormat.format1->timeDomOCC;
258   }
259 }
260
261 /**
262  * @brief Function to fill Pucch format for UL Sched Info
263  *
264  * @details
265  *
266  *     Function : fillUlSchedPucchFormat
267  *     
268  *     Function to fill Pucch format for UL Sched Info
269  *     
270  *  @param[in]  pucchFormat , SchPucchInfo pointer,
271  *  @param[in]  SchPucchFormatCfg pointer, SchPucchResrcInfo pointer
272  *  @return  void
273  **/
274
275 uint8_t fillUlSchedPucchFormat(uint8_t pucchFormat, SchPucchInfo *ulSchedPucch,\
276    SchPucchResrcInfo *resrcInfo, SchPucchFormatCfg *formatCfg)
277 {
278    uint8_t ret = ROK;
279
280    switch(pucchFormat)
281    {
282       case PUCCH_FORMAT_0:
283          {
284             if(resrcInfo)
285                fillPucchFormat0(ulSchedPucch, resrcInfo);
286             return ret;
287          }
288       case PUCCH_FORMAT_1:
289          {
290             if(resrcInfo)
291             {
292                fillPucchFormat1(ulSchedPucch, resrcInfo);
293             }
294             if(formatCfg)
295             {
296                memcpy(&ulSchedPucch->cmnFormatCfg, formatCfg, sizeof(SchPucchFormatCfg));
297             }
298             return ret;
299          }/* To Add support for more Pucch Format */
300       
301       default:
302          DU_LOG("\nERROR  --> SCH : Invalid PUCCH format[%d] in fillUlSchedPucchFormatCfg()", pucchFormat);
303          ret = RFAILED;
304          return ret;
305    }
306    return ret;
307 }
308
309 /**
310  * @brief Function to fill Pucch Dedicated Cfg for UL Sched Info
311  *
312  * @details
313  *
314  *     Function : fillUlSchedPucchDedicatedCfg
315  *     
316  *     Function to fill Pucch Dedicated Cfg for UL Sched Info
317  *     
318  *  @param[in]  pucchFormat to be filled
319  *  @param[in]  SchPucchFormatCfg pointer, SchPucchCfg pointer
320  *  @return  void
321  **/
322
323 uint8_t fillUlSchedPucchDedicatedCfg(uint16_t numSlots, SchPucchCfg *pucchDedCfg,\
324    SlotTimingInfo *slotInfo, SchPucchInfo *ulSchedPucch)
325 {
326    uint8_t ret, resrcSetIdx, resrcIdx, schedReqIdx, srPeriodicity = 0;
327    uint16_t srOffset = 0;
328
329    ret = ROK;
330    if(pucchDedCfg->resrcSet && pucchDedCfg->resrc)
331    {
332       //Assuming one entry in the list
333       for(resrcSetIdx = 0; resrcSetIdx < pucchDedCfg->resrcSet->resrcSetToAddModListCount; resrcSetIdx++)
334       {
335          for(resrcIdx = 0; resrcIdx < pucchDedCfg->resrc->resrcToAddModListCount; resrcIdx++)
336          {
337             if(pucchDedCfg->resrcSet->resrcSetToAddModList[resrcSetIdx].resrcList[resrcSetIdx] ==\
338                pucchDedCfg->resrc->resrcToAddModList[resrcIdx].resrcId)
339             {
340                ulSchedPucch->intraFreqHop = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].intraFreqHop;
341                ulSchedPucch->secondPrbHop = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].secondPrbHop;
342                ulSchedPucch->fdAlloc.startPrb = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].startPrb;
343                ulSchedPucch->pucchFormat = pucchDedCfg->resrc->resrcToAddModList[resrcIdx].pucchFormat;
344                ret = fillUlSchedPucchFormat(ulSchedPucch->pucchFormat, ulSchedPucch,\
345                         &pucchDedCfg->resrc->resrcToAddModList[resrcIdx], NULLP);
346                if(ret == RFAILED)
347                   return ret;
348             }
349          }
350       }
351    }
352    if(pucchDedCfg->format1)
353    {
354       memset(&ulSchedPucch->cmnFormatCfg, 0, sizeof(SchPucchFormatCfg));
355       ret = fillUlSchedPucchFormat(ulSchedPucch->pucchFormat, ulSchedPucch, NULLP, pucchDedCfg->format1);
356       if(ret == RFAILED)
357          return ret;
358    }
359    
360    /* setting SR and UCI flag */
361    if(pucchDedCfg->schedReq)
362    {
363       for(schedReqIdx = 0; schedReqIdx < pucchDedCfg->schedReq->schedAddModListCount; schedReqIdx++)
364       {
365          srPeriodicity = pucchDedCfg->schedReq->schedAddModList[schedReqIdx].periodicity;
366          srOffset      = pucchDedCfg->schedReq->schedAddModList[schedReqIdx].offset;
367          break;
368       }
369       if(((numSlots * slotInfo->sfn + slotInfo->slot - srOffset) % srPeriodicity) == 0)
370       {
371          ulSchedPucch->srFlag  = true;
372          ulSchedPucch->uciFlag = true;
373       }
374    }
375    return ret;
376 }
377
378 /**
379  * @brief Function to fill Pucch Resource Info
380  *
381  * @details
382  *
383  *     Function : fillPucchResourceInfo
384  *     
385  *     Function to fill Pucch Resource Info
386  *     
387  *  @param[in]  SchPucchInfo *schPucchInfo, Inst inst
388  *  @return  ROK/RFAILED
389  **/
390
391 uint16_t fillPucchResourceInfo(SchPucchInfo *schPucchInfo, Inst inst)
392 {
393    uint8_t ret = ROK, ueIdx = 0, pucchIdx = 0;
394    SchCellCb  *cell = schCb[inst].cells[inst];
395    SchPucchCfgCmn *pucchCfg = NULLP;
396    SchBwpParams *ulBwp = NULLP;
397
398    GET_UE_IDX(schPucchInfo->rnti, ueIdx);
399    if(cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres)
400    {
401       /* fill pucch dedicated cfg */
402       ret = fillUlSchedPucchDedicatedCfg(cell->numSlots,\
403        &cell->ueCb[ueIdx].ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg, &cell->slotInfo, schPucchInfo);
404       if(ret == RFAILED)
405       {
406          memset(schPucchInfo, 0, sizeof(SchPucchInfo));
407          DU_LOG("\nERROR  --> SCH : Filling PUCCH dedicated cfg failed at fillPucchResourceInfo()");
408          return ret;
409       }
410    }
411    else
412    {
413       /* fill pucch common cfg */
414       /* derive pucchResourceSet from schCellCfg */
415       pucchCfg = &cell->cellCfg.schInitialUlBwp.pucchCommon;
416       pucchIdx = pucchCfg->pucchResourceCommon;
417       ulBwp = &cell->cellCfg.schInitialUlBwp.bwp;
418       schPucchInfo->fdAlloc.startPrb = ulBwp->freqAlloc.startPrb + pucchResourceSet[pucchIdx][3];
419       schPucchInfo->fdAlloc.numPrb = PUCCH_NUM_PRB_FORMAT_0_1_4;
420       schPucchInfo->tdAlloc.startSymb = pucchResourceSet[pucchIdx][1];
421       schPucchInfo->tdAlloc.numSymb = pucchResourceSet[pucchIdx][2];
422       schPucchInfo->pucchFormat = pucchResourceSet[pucchIdx][0];
423
424       /* set SR and UCI flag to false */
425       schPucchInfo->srFlag  = true;
426       schPucchInfo->uciFlag = true;
427    }
428    /* set HARQ flag to true */
429    schPucchInfo->harqFlag = true;
430    schPucchInfo->numHarqBits = 1; /* 1 bit for HARQ */
431
432    return ROK;
433 }
434
435 /**
436  * @brief resource allocation for UL
437  *
438  * @details
439  *
440  *     Function : schUlResAlloc
441  *     
442  *     This function handles UL Resource allocation
443  *     
444  *  @param[in]  SchCellCb *cell, cellCb
445  *  @return  void
446  **/
447 uint8_t schUlResAlloc(SchCellCb *cell, Inst schInst)
448 {
449    int ret = ROK;
450    UlSchedInfo ulSchedInfo;
451    SchUlSlotInfo  *schUlSlotInfo = NULLP;
452    SlotTimingInfo ulTimingInfo;
453    memset(&ulSchedInfo, 0, sizeof(UlSchedInfo));
454
455    /* add PHY delta */
456    ADD_DELTA_TO_TIME(cell->slotInfo,ulTimingInfo,PHY_DELTA_UL+SCHED_DELTA);
457
458    ulSchedInfo.cellId = cell->cellId;
459    ulSchedInfo.slotIndInfo.cellId = ulSchedInfo.cellId;
460    ulSchedInfo.slotIndInfo.sfn = ulTimingInfo.sfn;
461    ulSchedInfo.slotIndInfo.slot = ulTimingInfo.slot;
462
463    /* Schedule resources for PRACH */
464    if(cell->firstSib1Transmitted)
465     schPrachResAlloc(cell, &ulSchedInfo, ulTimingInfo);
466
467    schUlSlotInfo = cell->schUlSlotInfo[ulTimingInfo.slot]; 
468    if(schUlSlotInfo->schPuschInfo)
469    {
470       ulSchedInfo.crnti = schUlSlotInfo->schPuschInfo->crnti;
471       ulSchedInfo.dataType |= SCH_DATATYPE_PUSCH;
472       memcpy(&ulSchedInfo.schPuschInfo, schUlSlotInfo->schPuschInfo,
473             sizeof(SchPuschInfo));
474       SCH_FREE(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
475       schUlSlotInfo->schPuschInfo = NULL;
476    }
477
478    if(schUlSlotInfo->pucchPres)
479    {
480       ulSchedInfo.dataType |= SCH_DATATYPE_UCI;
481       fillPucchResourceInfo(&schUlSlotInfo->schPucchInfo, schInst);
482       memcpy(&ulSchedInfo.schPucchInfo, &schUlSlotInfo->schPucchInfo,
483             sizeof(SchPucchInfo));
484       memset(&schUlSlotInfo->schPucchInfo, 0, sizeof(SchPucchInfo));
485    }
486
487    //send msg to MAC
488    ret = sendUlSchInfoToMac(&ulSchedInfo, schInst);
489    if(ret != ROK)
490    {
491       DU_LOG("\nERROR  -->  SCH : Sending UL Sch info from SCH to MAC failed");
492    }
493
494    schInitUlSlot(schUlSlotInfo);
495    return ret;
496 }
497
498 /*******************************************************************
499  *
500  * @brief Fills pdcch and pdsch info for msg4
501  *
502  * @details
503  *
504  *    Function : schDlRsrcAllocMsg4
505  *
506  *    Functionality:
507  *       Fills pdcch and pdsch info for msg4
508  *
509  * @params[in] 
510  * @return ROK     - success
511  *         RFAILED - failure
512  *
513  * ****************************************************************/
514 uint8_t schDlRsrcAllocMsg4(SchCellCb *cell, SlotTimingInfo msg4Time, uint8_t ueId, DlMsgAlloc *dlMsgAlloc,\
515 uint8_t pdschStartSymbol, uint8_t pdschNumSymbols)
516 {
517    uint8_t coreset0Idx = 0;
518    uint8_t firstSymbol = 0;
519    uint8_t numSymbols = 0;
520    uint8_t mcs = DEFAULT_MCS;                         /* MCS fixed to 4 */
521    uint8_t dmrsStartSymbol = 0, startSymbol = 0, numSymbol = 0;
522    uint16_t tbSize = 0;
523    uint16_t numRbs;
524    SchBwpDlCfg *initialBwp = NULLP;
525    PdcchCfg *pdcch = NULLP;
526    PdschCfg *pdsch = NULLP;
527    BwpCfg *bwp = NULLP;
528    DlMsgSchInfo *msg4Alloc = NULLP;
529
530    if(cell == NULL)
531    {
532       DU_LOG("\nERROR  -->  SCH: schDlRsrcAllocMsg4() : Cell is NULL");
533       return RFAILED;
534    }
535
536    if(dlMsgAlloc == NULL)
537    {
538       DU_LOG("\nERROR  -->  SCH: schDlRsrcAllocMsg4() :  dlMsgAlloc is NULL");
539       return RFAILED;
540    }
541
542    msg4Alloc = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo];
543    initialBwp   = &cell->cellCfg.schInitialDlBwp;
544    pdcch = &msg4Alloc->dlMsgPdcchCfg;
545    pdsch = &msg4Alloc->dlMsgPdschCfg;
546    bwp = &msg4Alloc->bwp;
547    coreset0Idx  = initialBwp->pdcchCommon.commonSearchSpace.coresetId;
548
549    fillDlMsgInfo(&msg4Alloc->dlMsgInfo, cell->raCb[ueId-1].tcrnti);
550    msg4Alloc->dlMsgInfo.dlMsgPduLen = cell->raCb[ueId-1].dlMsgPduLen;
551
552    /* derive the sib1 coreset0 params from table 13-1 spec 38.213 */
553    numRbs     = coresetIdxTable[coreset0Idx][1];
554    numSymbols = coresetIdxTable[coreset0Idx][2];
555
556    /* calculate time domain parameters */
557    uint16_t mask = 0x2000;
558    for(firstSymbol=0; firstSymbol<MAX_SYMB_PER_SLOT; firstSymbol++)
559    {
560       if(initialBwp->pdcchCommon.commonSearchSpace.monitoringSymbol & mask)
561          break;
562       else
563          mask = mask>>1;
564    }
565
566    /* fill BWP */
567    bwp->freqAlloc.numPrb   = initialBwp->bwp.freqAlloc.numPrb;
568    bwp->freqAlloc.startPrb = initialBwp->bwp.freqAlloc.startPrb;
569    bwp->subcarrierSpacing  = initialBwp->bwp.scs;
570    bwp->cyclicPrefix       = initialBwp->bwp.cyclicPrefix;
571
572    /* fill the PDCCH PDU */
573    pdcch->coresetCfg.startSymbolIndex = firstSymbol;
574    pdcch->coresetCfg.durationSymbols = numSymbols;
575    memcpy(pdcch->coresetCfg.freqDomainResource, \
576       cell->cellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
577
578    pdcch->coresetCfg.cceRegMappingType = 1; /* coreset0 is always interleaved */
579    pdcch->coresetCfg.regBundleSize = 6;    /* spec-38.211 sec 7.3.2.2 */
580    pdcch->coresetCfg.interleaverSize = 2;  /* spec-38.211 sec 7.3.2.2 */
581    pdcch->coresetCfg.coreSetType = 0;
582    pdcch->coresetCfg.coreSetSize = numRbs;
583    pdcch->coresetCfg.shiftIndex = cell->cellCfg.phyCellId;
584    pdcch->coresetCfg.precoderGranularity = 0; /* sameAsRegBundle */
585    pdcch->numDlDci = 1;
586    pdcch->dci.rnti = cell->raCb[ueId-1].tcrnti;
587    pdcch->dci.scramblingId = cell->cellCfg.phyCellId;
588    pdcch->dci.scramblingRnti = 0;
589    pdcch->dci.cceIndex = 4; /* considering SIB1 is sent at cce 0-1-2-3 */
590    pdcch->dci.aggregLevel = 4;
591    pdcch->dci.beamPdcchInfo.numPrgs = 1;
592    pdcch->dci.beamPdcchInfo.prgSize = 1;
593    pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
594    pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
595    pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
596    pdcch->dci.txPdcchPower.powerValue = 0;
597    pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
598    pdcch->dci.pdschCfg = pdsch;
599
600    /* fill the PDSCH PDU */
601    uint8_t cwCount = 0;
602    pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
603    pdsch->rnti = cell->raCb[ueId-1].tcrnti;
604    pdsch->pduIndex = 0;
605    pdsch->numCodewords = 1;
606    for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
607    {
608       pdsch->codeword[cwCount].targetCodeRate = 308;
609       pdsch->codeword[cwCount].qamModOrder = 2;
610       pdsch->codeword[cwCount].mcsIndex = mcs; /* mcs configured to 4 */
611       pdsch->codeword[cwCount].mcsTable = 0; /* notqam256 */
612       pdsch->codeword[cwCount].rvIndex = 0;
613       tbSize = schCalcTbSize(msg4Alloc->dlMsgInfo.dlMsgPduLen + TX_PAYLOAD_HDR_LEN); /* MSG4 size + FAPI header size*/
614       pdsch->codeword[cwCount].tbSize = tbSize;
615    }
616    pdsch->dataScramblingId = cell->cellCfg.phyCellId;
617    pdsch->numLayers = 1;
618    pdsch->transmissionScheme = 0;
619    pdsch->refPoint = 0;
620    pdsch->dmrs.dlDmrsSymbPos = 4; /* Bitmap value 00000000000100 i.e. using 3rd symbol for PDSCH DMRS */
621    pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
622    pdsch->dmrs.dlDmrsScramblingId = cell->cellCfg.phyCellId;
623    pdsch->dmrs.scid = 0;
624    pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
625    pdsch->dmrs.dmrsPorts = 0;
626    pdsch->dmrs.mappingType      = DMRS_MAP_TYPE_A; /* Setting to Type-A */
627    pdsch->dmrs.nrOfDmrsSymbols  = NUM_DMRS_SYMBOLS;
628    pdsch->dmrs.dmrsAddPos       = DMRS_ADDITIONAL_POS;
629
630    pdsch->pdschTimeAlloc.timeAlloc.startSymb = pdschStartSymbol; 
631    pdsch->pdschTimeAlloc.timeAlloc.numSymb = pdschNumSymbols;
632
633    pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
634    pdsch->pdschFreqAlloc.freqAlloc.startPrb = MAX_NUM_RB;
635    pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, mcs, pdschNumSymbols);
636    pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
637
638    /* Find total symbols occupied including DMRS */
639    dmrsStartSymbol = findDmrsStartSymbol(pdsch->dmrs.dlDmrsSymbPos);
640    /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
641     * in that case only PDSCH symbols are marked as occupied */
642    if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
643    {
644       startSymbol = pdsch->pdschTimeAlloc.timeAlloc.startSymb;
645       numSymbol = pdsch->pdschTimeAlloc.timeAlloc.numSymb;
646    }
647    /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
648    else
649    {
650       startSymbol = dmrsStartSymbol;
651       numSymbol = pdsch->dmrs.nrOfDmrsSymbols + pdsch->pdschTimeAlloc.timeAlloc.numSymb;
652    }
653
654    /* Allocate the number of PRBs required for RAR PDSCH */
655    if((allocatePrbDl(cell, msg4Time, startSymbol, numSymbol,\
656       &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
657    {
658       DU_LOG("\nERROR  --> SCH : Resource allocation failed for MSG4");
659       return RFAILED;
660    }
661
662    pdsch->beamPdschInfo.numPrgs = 1;
663    pdsch->beamPdschInfo.prgSize = 1;
664    pdsch->beamPdschInfo.digBfInterfaces = 0;
665    pdsch->beamPdschInfo.prg[0].pmIdx = 0;
666    pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
667    pdsch->txPdschPower.powerControlOffset = 0;
668    pdsch->txPdschPower.powerControlOffsetSS = 0;
669
670    msg4Alloc->dlMsgInfo.isMsg4Pdu = true;
671    return ROK;
672 }
673  
674 /*******************************************************************
675  *
676  * @brief Scheduling for Pucch Resource
677  *
678  * @details
679  *
680  *    Function : schAllocPucchResource
681  *
682  *    Functionality:
683  *       Scheduling for Pucch Resource
684  *
685  * @params[in] SchCellCb *cell, SlotTimingInfo pucchTime, crnti
686  * @return ROK     - success
687  *         RFAILED - failure
688  *
689  *******************************************************************/
690
691 uint16_t schAllocPucchResource(SchCellCb *cell, SlotTimingInfo pucchTime, uint16_t crnti)
692 {
693    uint16_t pucchSlot = 0;
694    SchUlSlotInfo  *schUlSlotInfo = NULLP;
695    
696    pucchSlot = pucchTime.slot;
697    schUlSlotInfo = cell->schUlSlotInfo[pucchSlot];
698    memset(&schUlSlotInfo->schPucchInfo, 0, sizeof(SchPucchInfo));
699
700    schUlSlotInfo->pucchPres = true;
701    schUlSlotInfo->schPucchInfo.rnti = crnti;
702
703    return ROK;
704 }
705
706 /*******************************************************************
707  *
708  * @brief Fills pdcch and pdsch info for dedicated DL msg
709  *
710  * @details
711  *
712  *    Function : schDlRsrcAllocDlMsg
713  *
714  *    Functionality:
715  *       Fills pdcch and pdsch info for dl msg
716  *
717  * @params[in]
718  * @return ROK     - success
719  *         RFAILED - failure
720  *
721  * ****************************************************************/
722 uint8_t schDlRsrcAllocDlMsg(SchCellCb *cell, SlotTimingInfo slotTime, uint16_t crnti,
723                 uint32_t tbSize, DlMsgAlloc *dlMsgAlloc, uint16_t startPRB, uint8_t pdschStartSymbol, uint8_t pdschNumSymbols)
724 {
725    uint8_t ueIdx;
726    PdcchCfg *pdcch = NULLP;
727    PdschCfg *pdsch = NULLP;
728    BwpCfg *bwp = NULLP;
729    SchUeCb ueCb;
730    SchControlRsrcSet coreset1;
731    SchPdschConfig pdschCfg;
732    uint8_t dmrsStartSymbol, startSymbol, numSymbol;
733
734    pdcch = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo].dlMsgPdcchCfg;
735    pdsch = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo].dlMsgPdschCfg;
736    bwp = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo].bwp;
737
738    GET_UE_IDX(crnti, ueIdx);
739    ueCb  = cell->ueCb[ueIdx-1];
740    coreset1 = ueCb.ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
741    pdschCfg = ueCb.ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
742
743    /* fill BWP */
744    bwp->freqAlloc.numPrb = MAX_NUM_RB;
745    bwp->freqAlloc.startPrb = 0;
746    bwp->subcarrierSpacing = cell->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
747    bwp->cyclicPrefix = cell->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
748
749    /* fill the PDCCH PDU */
750    //Considering coreset1 also starts from same symbol as coreset0
751    pdcch->coresetCfg.startSymbolIndex = coresetIdxTable[0][3];
752    pdcch->coresetCfg.durationSymbols = coreset1.duration;
753    memcpy(pdcch->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
754    pdcch->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
755    pdcch->coresetCfg.regBundleSize = 6;   /* must be 6 for non-interleaved */
756    pdcch->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
757    pdcch->coresetCfg.coreSetType = 1; /* non PBCH coreset */
758    //Considering number of RBs in coreset1 is same as coreset0
759    pdcch->coresetCfg.coreSetSize = coresetIdxTable[0][1];
760    pdcch->coresetCfg.shiftIndex = cell->cellCfg.phyCellId;
761    pdcch->coresetCfg.precoderGranularity =  coreset1.precoderGranularity;
762    pdcch->numDlDci = 1;
763    pdcch->dci.rnti = ueCb.crnti;
764    pdcch->dci.scramblingId = cell->cellCfg.phyCellId;
765    pdcch->dci.scramblingRnti = 0;
766    pdcch->dci.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
767    pdcch->dci.aggregLevel = 4;
768    pdcch->dci.beamPdcchInfo.numPrgs = 1;
769    pdcch->dci.beamPdcchInfo.prgSize = 1;
770    pdcch->dci.beamPdcchInfo.digBfInterfaces = 0;
771    pdcch->dci.beamPdcchInfo.prg[0].pmIdx = 0;
772    pdcch->dci.beamPdcchInfo.prg[0].beamIdx[0] = 0;
773    pdcch->dci.txPdcchPower.powerValue = 0;
774    pdcch->dci.txPdcchPower.powerControlOffsetSS = 0;
775
776    /* fill the PDSCH PDU */
777    uint8_t cwCount = 0;
778    pdsch->pduBitmap = 0; /* PTRS and CBG params are excluded */
779    pdsch->rnti = ueCb.crnti;
780    pdsch->pduIndex = 0;
781    pdsch->numCodewords = 1;
782    for(cwCount = 0; cwCount < pdsch->numCodewords; cwCount++)
783    {
784       pdsch->codeword[cwCount].targetCodeRate = 308;
785       pdsch->codeword[cwCount].qamModOrder = ueCb.ueCfg.dlModInfo.modOrder;
786       pdsch->codeword[cwCount].mcsIndex = ueCb.ueCfg.dlModInfo.mcsIndex;
787       pdsch->codeword[cwCount].mcsTable = ueCb.ueCfg.dlModInfo.mcsTable;
788       pdsch->codeword[cwCount].rvIndex = 0;
789
790       tbSize +=TX_PAYLOAD_HDR_LEN;
791       pdsch->codeword[cwCount].tbSize = tbSize;
792    }
793    pdsch->dataScramblingId = cell->cellCfg.phyCellId;
794    pdsch->numLayers = 1;
795    pdsch->transmissionScheme = 0;
796    pdsch->refPoint = 0;
797    pdsch->dmrs.dlDmrsSymbPos = 4; /* Bitmap value 00000000000100 i.e. using 3rd symbol for PDSCH DMRS */
798    pdsch->dmrs.dmrsConfigType = 0; /* type-1 */
799    pdsch->dmrs.dlDmrsScramblingId = cell->cellCfg.phyCellId;
800    pdsch->dmrs.scid = 0;
801    pdsch->dmrs.numDmrsCdmGrpsNoData = 1;
802    pdsch->dmrs.dmrsPorts = 0;
803    pdsch->dmrs.mappingType      = DMRS_MAP_TYPE_A; /* Setting to Type-A */
804    pdsch->dmrs.nrOfDmrsSymbols  = NUM_DMRS_SYMBOLS;
805    pdsch->dmrs.dmrsAddPos       = pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos;
806
807    pdsch->pdschTimeAlloc.timeAlloc.startSymb = pdschStartSymbol; 
808    pdsch->pdschTimeAlloc.timeAlloc.numSymb = pdschNumSymbols;
809
810    pdsch->pdschFreqAlloc.vrbPrbMapping = 0; /* non-interleaved */
811    pdsch->pdschFreqAlloc.resourceAllocType = 1; /* RAT type-1 RIV format */
812    pdsch->pdschFreqAlloc.freqAlloc.startPrb = startPRB; /*Start PRB will be already known*/
813    pdsch->pdschFreqAlloc.freqAlloc.numPrb = schCalcNumPrb(tbSize, ueCb.ueCfg.dlModInfo.mcsIndex, pdschNumSymbols);
814
815    /* Find total symbols occupied including DMRS */
816    dmrsStartSymbol = findDmrsStartSymbol(pdsch->dmrs.dlDmrsSymbPos);
817    /* If there are no DRMS symbols, findDmrsStartSymbol() returns MAX_SYMB_PER_SLOT,
818     * in that case only PDSCH symbols are marked as occupied */
819    if(dmrsStartSymbol == MAX_SYMB_PER_SLOT)
820    {
821       startSymbol = pdsch->pdschTimeAlloc.timeAlloc.startSymb;
822       numSymbol = pdsch->pdschTimeAlloc.timeAlloc.numSymb;
823    }
824    /* If DMRS symbol is found, mark DMRS and PDSCH symbols as occupied */
825    else
826    {
827       startSymbol = dmrsStartSymbol;
828       numSymbol = pdsch->dmrs.nrOfDmrsSymbols + pdsch->pdschTimeAlloc.timeAlloc.numSymb;
829    }
830
831    /* Allocate the number of PRBs required for DL PDSCH */
832    if((allocatePrbDl(cell, slotTime, startSymbol, numSymbol,\
833       &pdsch->pdschFreqAlloc.freqAlloc.startPrb, pdsch->pdschFreqAlloc.freqAlloc.numPrb)) != ROK)
834    {
835       DU_LOG("\nERROR  --> SCH : allocatePrbDl() failed for DL MSG");
836       return RFAILED;
837    }
838
839    pdsch->beamPdschInfo.numPrgs = 1;
840    pdsch->beamPdschInfo.prgSize = 1;
841    pdsch->beamPdschInfo.digBfInterfaces = 0;
842    pdsch->beamPdschInfo.prg[0].pmIdx = 0;
843    pdsch->beamPdschInfo.prg[0].beamIdx[0] = 0;
844    pdsch->txPdschPower.powerControlOffset = 0;
845    pdsch->txPdschPower.powerControlOffsetSS = 0;
846
847    pdcch->dci.pdschCfg = pdsch;
848    return ROK;
849 }
850
851 /*******************************************************************
852  *
853  * @brief Fills k0 and k1 information table for FDD 
854  *
855  * @details
856  *
857  *    Function : BuildK0K1TableForFdd 
858  *
859  *    Functionality:
860  *      Fills k0 and k1 information table for FDD
861  *
862  * @params[in] SchCellCb *cell,SchK0K1TimingInfoTbl *k0K1InfoTbl,bool
863  * pdschCfgCmnPres,uint8_t numTimeDomAlloc, SchPdschCfgCmnTimeDomRsrcAlloc
864  * cmnTimeDomRsrcAllocList[], SchPdschTimeDomRsrcAlloc
865  * dedTimeDomRsrcAllocList[], uint8_t ulAckListCount, uint8_t *UlAckTbl
866  * @return ROK     - success
867  *         RFAILED - failure
868  *
869  * ****************************************************************/
870 void BuildK0K1TableForFdd(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres,SchPdschCfgCmn pdschCmnCfg,\
871 SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl)
872 {
873    
874    uint8_t k1TmpVal =0, cfgIdx=0;
875    uint8_t slotIdx=0, k0Index=0, k1Index=0, numK0=0, numK1=0, numTimeDomAlloc=0;
876    
877    /* TODO Commented these below lines for resolving warnings. Presently these variable are not 
878     * required but this will require for harq processing */
879    // uint8_t k0TmpVal = 0; 
880    // SchPdschCfgCmnTimeDomRsrcAlloc cmnTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
881    // SchPdschTimeDomRsrcAlloc dedTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
882
883    /* Initialization the structure and storing the total slot values. */
884    memset(k0K1InfoTbl, 0, sizeof(SchK0K1TimingInfoTbl));
885    k0K1InfoTbl->tblSize = cell->numSlots;
886    
887    /* Storing time domain resource allocation list based on common or dedicated configuration. */
888    if(pdschCfgCmnPres == true)
889    {
890       numTimeDomAlloc = pdschCmnCfg.numTimeDomAlloc;
891       for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
892       {
893          /*TODO uncomment this line during harq processing */
894          //cmnTimeDomRsrcAllocList[cfgIdx] = pdschCmnCfg.timeDomRsrcAllocList[cfgIdx];
895       }
896    }
897    else
898    {
899       numTimeDomAlloc = pdschDedCfg.numTimeDomRsrcAlloc;
900       for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
901       {
902          /*TODO uncomment this line during harq processing */
903          //dedTimeDomRsrcAllocList[cfgIdx] = pdschDedCfg.timeDomRsrcAllociList[cfgIdx];
904       }
905    }
906    
907    /* Checking all the slots for K0 and K1 values. */
908    for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
909    {
910       numK0 = 0;
911       /* Storing the values of k0 based on time domain resource
912        * allocation list. If the value is unavailable then fill default values,
913        * As per 38.331 PDSCH-TimeDomainResourceAllocation field descriptions. */
914       for(k0Index = 0; ((k0Index < numTimeDomAlloc) && (k0Index < MAX_NUM_K0_IDX));  k0Index++)
915       {
916          /* TODO These if 0 we will remove during harq processing */
917 #if 0
918          if(pdschCfgCmnPres == true)
919          {
920             k0TmpVal = cmnTimeDomRsrcAllocList[k0Index].k0;
921          }
922          else
923          {
924             if(dedTimeDomRsrcAllocList[k0Index].k0 != NULLP)
925             {
926                k0TmpVal = *(dedTimeDomRsrcAllocList[k0Index].k0);
927             }
928             else
929             { 
930                k0TmpVal = DEFAULT_K0_VALUE;
931             }
932          }
933 #endif         
934          /* Checking all the Ul Alloc values. If value is less than MIN_NUM_K1_IDX
935           * then skip else continue storing the values. */
936          numK1 = 0;
937          for(k1Index = 0; k1Index < ulAckListCount; k1Index++)
938          {
939             k1TmpVal = UlAckTbl[k1Index];
940             if(k1TmpVal <= MIN_NUM_K1_IDX)
941             {
942                continue;
943             }
944
945             k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.k1Indexes[numK1++] = k1Index;
946             /* TODO Store K1 index where harq feedback will be received in harq table. */ 
947          }
948          if(numK1)
949          {
950             k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.numK1 = numK1;
951             k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k0Index = k0Index;
952             numK0++;
953          }
954       }
955       if(numK0)
956       {
957          k0K1InfoTbl->k0k1TimingInfo[slotIdx].numK0 = numK0;
958       }
959    }
960 }
961
962 /*******************************************************************
963  *
964  * @brief Fills k0 and k1 information table  
965  *
966  * @details
967  *
968  *    Function : BuildK0K1Table
969  *
970  *    Functionality:
971  *       Fills K0 and k1 information table 
972  *
973  * @params[in] SchCellCb *cell,SchK0K1TimingInfoTbl *k0K1InfoTbl,bool
974  * pdschCfgCmnPres,uint8_t numTimeDomAlloc, SchPdschCfgCmnTimeDomRsrcAlloc
975  * cmnTimeDomRsrcAllocList[], SchPdschTimeDomRsrcAlloc
976  * dedTimeDomRsrcAllocList[], uint8_t ulAckListCount, uint8_t *UlAckTbl
977  * @return ROK     - success
978  *         RFAILED - failure
979  *
980  * ****************************************************************/
981 void BuildK0K1Table(SchCellCb *cell, SchK0K1TimingInfoTbl *k0K1InfoTbl, bool pdschCfgCmnPres, SchPdschCfgCmn pdschCmnCfg,\
982 SchPdschConfig pdschDedCfg, uint8_t ulAckListCount, uint8_t *UlAckTbl)
983 {
984
985 #ifdef NR_TDD
986    SlotConfig  slotCfg;
987    bool ulSlotPresent = false;
988    uint8_t k0TmpVal = 0, k1TmpVal =0, tmpSlot=0, startSymbol=0, endSymbol=0, checkSymbol=0;
989    uint8_t slotIdx=0, k0Index=0, k1Index=0, numK0=0, numK1=0, cfgIdx=0, numTimeDomAlloc =0, totalCfgSlot =0;
990    SchPdschCfgCmnTimeDomRsrcAlloc cmnTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
991    SchPdschTimeDomRsrcAlloc dedTimeDomRsrcAllocList[MAX_NUM_DL_ALLOC];
992 #endif
993
994    if(cell->cellCfg.dupMode == DUPLEX_MODE_FDD)
995    {
996       BuildK0K1TableForFdd(cell, k0K1InfoTbl, pdschCfgCmnPres, pdschCmnCfg, pdschDedCfg, ulAckListCount, UlAckTbl);
997    }
998    else
999    {
1000 #ifdef NR_TDD
1001       
1002       /* Initialization the K0K1 structure, total num of slot and calculating the slot pattern length. */
1003       memset(k0K1InfoTbl, 0, sizeof(SchK0K1TimingInfoTbl));
1004       k0K1InfoTbl->tblSize = cell->numSlots;
1005       totalCfgSlot = calculateSlotPatternLength(cell->cellCfg.ssbSchCfg.scsCommon, cell->cellCfg.tddCfg.tddPeriod);
1006       
1007       /* Storing time domain resource allocation list based on common or 
1008        * dedicated configuration availability. */
1009       if(pdschCfgCmnPres == true)
1010       {
1011          numTimeDomAlloc = pdschCmnCfg.numTimeDomAlloc;
1012          for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
1013          {
1014             cmnTimeDomRsrcAllocList[cfgIdx] = pdschCmnCfg.timeDomRsrcAllocList[cfgIdx];
1015          }
1016       }
1017       else
1018       {
1019          numTimeDomAlloc = pdschDedCfg.numTimeDomRsrcAlloc;
1020          for(cfgIdx = 0; cfgIdx<numTimeDomAlloc; cfgIdx++)
1021          {
1022             dedTimeDomRsrcAllocList[cfgIdx] = pdschDedCfg.timeDomRsrcAllociList[cfgIdx];
1023          }
1024       }
1025
1026       /* Checking all possible indexes for K0 and K1 values. */
1027       for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
1028       {
1029          /* If current slot is UL or FLEXI then Skip because PDCCH is sent only in DL slots. */
1030          slotCfg = schGetSlotSymbFrmt(slotIdx%totalCfgSlot, cell->slotFrmtBitMap);
1031          if(slotCfg == UL_SLOT || slotCfg == FLEXI_SLOT)
1032          {
1033             continue;
1034          }
1035          
1036          /* Storing K0 , start symbol and length symbol for further processing.
1037           * If K0 value is not available then we can fill the default values
1038           * given in spec 38.331. */
1039          numK0 = 0;
1040          for(k0Index = 0; ((k0Index < numTimeDomAlloc) && (k0Index < MAX_NUM_K0_IDX)); k0Index++)
1041          {
1042             if(pdschCfgCmnPres == true)
1043             {
1044                k0TmpVal = cmnTimeDomRsrcAllocList[k0Index].k0;
1045                startSymbol = cmnTimeDomRsrcAllocList[k0Index].startSymbol;
1046                endSymbol = startSymbol + cmnTimeDomRsrcAllocList[k0Index].lengthSymbol;
1047             }
1048             else
1049             {
1050                if(dedTimeDomRsrcAllocList[k0Index].k0 != NULLP)
1051                {
1052                   k0TmpVal =  *(dedTimeDomRsrcAllocList[k0Index].k0);
1053                }
1054                else
1055                {
1056                   k0TmpVal = DEFAULT_K0_VALUE;
1057                }
1058                startSymbol = dedTimeDomRsrcAllocList[k0Index].startSymbol;
1059                endSymbol = startSymbol + dedTimeDomRsrcAllocList[k0Index].symbolLength;
1060             }
1061             
1062             /* If current slot + k0 is UL then skip the slot
1063              * else if it is DL slot then continue the next steps
1064              * else if it is a FLEXI slot then check symbols of slot, It should not
1065              * contain any UL slot. */
1066             tmpSlot = (slotIdx+k0TmpVal) % totalCfgSlot;
1067             slotCfg = schGetSlotSymbFrmt(tmpSlot, cell->slotFrmtBitMap);
1068             if(slotCfg == UL_SLOT)
1069             {
1070                continue;
1071             }
1072             if(slotCfg == FLEXI_SLOT)
1073             {
1074                for(checkSymbol = startSymbol; checkSymbol<endSymbol; checkSymbol ++)
1075                {
1076                   slotCfg = cell->cellCfg.tddCfg.slotCfg[tmpSlot][checkSymbol];
1077                   if(slotCfg == UL_SLOT)
1078                   {
1079                      continue;
1080                   }
1081                }
1082             }
1083
1084             /* If current slot + k0 + k1 is a DL slot then skip the slot
1085              * else if it is UL slot then store the information 
1086              * else if it is FLEXI slot then check the symbols, it must have
1087              * at least one UL symbol. */
1088             numK1 = 0;
1089             for(k1Index = 0; k1Index < ulAckListCount; k1Index++)
1090             {
1091                k1TmpVal = UlAckTbl[k1Index];
1092                if(k1TmpVal > MIN_NUM_K1_IDX)
1093                {
1094                   tmpSlot = (slotIdx+k0TmpVal+k1TmpVal) % totalCfgSlot;
1095                   slotCfg =  schGetSlotSymbFrmt(tmpSlot, cell->slotFrmtBitMap);
1096                   if(slotCfg == DL_SLOT) 
1097                   {
1098                      continue;
1099                   }   
1100                   if(slotCfg == FLEXI_SLOT)
1101                   {
1102                      for(checkSymbol = 0; checkSymbol< MAX_SYMB_PER_SLOT;checkSymbol++)
1103                      {
1104                         if(cell->cellCfg.tddCfg.slotCfg[tmpSlot][checkSymbol] == UL_SLOT)
1105                         {
1106                            ulSlotPresent = true;
1107                            break;
1108                         }
1109                      }
1110                   }
1111                   if(ulSlotPresent == true || slotCfg ==  UL_SLOT)
1112                   {
1113                      k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.k1Indexes[numK1++] = k1Index;
1114                      /* TODO Store K1 index where harq feedback will be received
1115                       * in harq table. */
1116                   }
1117                }
1118             }
1119             
1120             /* Store all the values if all condition satisfies. */
1121             if(numK1)
1122             {
1123                k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k1TimingInfo.numK1 = numK1;
1124                k0K1InfoTbl->k0k1TimingInfo[slotIdx].k0Indexes[numK0].k0Index = k0Index;
1125                numK0++;
1126             }
1127          }
1128          if(numK0)
1129          {
1130             k0K1InfoTbl->k0k1TimingInfo[slotIdx].numK0 = numK0;
1131          }
1132       }
1133 #endif
1134    }
1135 }
1136
1137 /*******************************************************************
1138 *
1139 * @brief Fills K2 information table for FDD
1140 *
1141 * @details
1142 *
1143 *    Function : BuildK2InfoTableForFdd 
1144 *
1145 *    Functionality:
1146 *       Fills K2 information table for FDD
1147 *
1148 * @params[in] SchCellCb *cell,SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[],
1149 * uint16_t puschSymTblSize,SchK2TimingInfoTbl *k2InfoTbl
1150 * @return ROK     - success
1151 *         RFAILED - failure
1152 *
1153 * ****************************************************************/
1154 void BuildK2InfoTableForFdd(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], uint16_t puschSymTblSize,\
1155 SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl)
1156 {
1157    uint16_t slotIdx=0, k2Index=0, k2TmpIdx=0, msg3K2TmpIdx=0;
1158
1159    /* Initialization the structure and storing the total slot values. */
1160    memset(k2InfoTbl, 0, sizeof(SchK2TimingInfoTbl));
1161    k2InfoTbl->tblSize = cell->numSlots;
1162    if(msg3K2InfoTbl)
1163       msg3K2InfoTbl->tblSize = cell->numSlots;
1164    
1165    /* Checking all possible indexes for K2. */
1166    for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
1167    {
1168       /* Storing K2 values. */
1169       for(k2Index = 0; ((k2Index < puschSymTblSize) && (k2Index < MAX_NUM_K2_IDX)); k2Index++)
1170       {
1171          k2TmpIdx= k2InfoTbl->k2TimingInfo[slotIdx].numK2;
1172          k2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[k2TmpIdx] = k2Index;
1173          k2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1174
1175          /* Updating K2 values for MSG3 */
1176          if(msg3K2InfoTbl)
1177          {
1178             msg3K2TmpIdx = msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2;
1179             msg3K2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[msg3K2TmpIdx] = k2Index;
1180             msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1181          }
1182       }
1183    }
1184 }
1185
1186 /*******************************************************************
1187  *
1188  * @brief Fills K2 information table
1189  *
1190  * @details
1191  *
1192  *    Function : BuildK2InfoTable 
1193  *
1194  *    Functionality:
1195  *       Fills K2 information table
1196  *
1197  * @params[in] SchCellCb *cell,SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[],
1198  * uint16_t puschSymTblSize, SchK2TimingInfoTbl *k2InfoTbl
1199  * @return ROK     - success
1200  *         RFAILED - failure
1201  *
1202  * ****************************************************************/
1203 void BuildK2InfoTable(SchCellCb *cell, SchPuschTimeDomRsrcAlloc timeDomRsrcAllocList[], uint16_t puschSymTblSize,\
1204 SchK2TimingInfoTbl *msg3K2InfoTbl, SchK2TimingInfoTbl *k2InfoTbl)
1205 {
1206
1207 #ifdef NR_TDD
1208    bool dlSymbolPresent = false;
1209    uint8_t slotIdx=0, k2Index=0, k2Val=0, k2TmpVal=0, msg3K2TmpVal=0, msg3Delta=0, numK2 =0, currentSymbol =0;
1210    uint8_t startSymbol =0, endSymbol =0, checkSymbol=0, totalCfgSlot=0, slotCfg=0;
1211    SlotConfig currentSlot;
1212 #endif
1213
1214    if(cell->cellCfg.dupMode == DUPLEX_MODE_FDD)
1215    {
1216       BuildK2InfoTableForFdd(cell, timeDomRsrcAllocList, puschSymTblSize, msg3K2InfoTbl, k2InfoTbl);
1217    }
1218    else
1219    {
1220 #ifdef NR_TDD
1221
1222       /* Initialization the structure and storing the total slot values. */
1223       memset(k2InfoTbl, 0, sizeof(SchK2TimingInfoTbl));
1224       k2InfoTbl->tblSize = cell->numSlots;
1225       if(msg3K2InfoTbl)
1226          msg3K2InfoTbl->tblSize = cell->numSlots;
1227       totalCfgSlot = calculateSlotPatternLength(cell->cellCfg.ssbSchCfg.scsCommon, cell->cellCfg.tddCfg.tddPeriod);
1228
1229       /* Checking all possible indexes for K2. */
1230       for(slotIdx = 0; slotIdx < cell->numSlots; slotIdx++)
1231       {
1232          currentSlot = schGetSlotSymbFrmt(slotIdx % totalCfgSlot, cell->slotFrmtBitMap);
1233          
1234          /* If current slot is UL then skip because PDCCH is sent only in DL slots */
1235          if(currentSlot != UL_SLOT)
1236          {
1237             for(k2Index = 0; ((k2Index < puschSymTblSize) && (k2Index < MAX_NUM_K2_IDX)); k2Index++)
1238             {
1239                /* Storing k2, startSymbol, endSymbol information for further processing.
1240                 * If k2 is absent then fill the default values given in spec 38.331
1241                 * PUSCH-TimeDomainResourceAllocationList field descriptions */
1242                k2Val = timeDomRsrcAllocList[k2Index].k2;
1243                if(!k2Val)
1244                {
1245                   switch(cell->cellCfg.ssbSchCfg.scsCommon)
1246                   {
1247                      case SCS_15KHZ:
1248                         k2Val = DEFAULT_K2_VALUE_FOR_SCS15;
1249                         break;
1250                      case SCS_30KHZ:
1251                         k2Val = DEFAULT_K2_VALUE_FOR_SCS30;
1252                         break;
1253                      case SCS_60KHZ:
1254                         k2Val = DEFAULT_K2_VALUE_FOR_SCS60;
1255                         break;
1256                      case SCS_120KHZ:
1257                         k2Val = DEFAULT_K2_VALUE_FOR_SCS120;
1258                         break;
1259                   }
1260                }
1261                
1262                /* Current slot + k2 should be either UL or FLEXI slot.
1263                 * If slot is FLEXI then check all the symbols of that slot,
1264                 * it should not contain any DL or FLEXI slot */
1265                k2TmpVal = (slotIdx + k2Val) % totalCfgSlot;
1266                slotCfg = schGetSlotSymbFrmt(k2TmpVal, cell->slotFrmtBitMap);
1267                if(slotCfg != DL_SLOT)
1268                {
1269                   if(slotCfg == FLEXI_SLOT)
1270                   {
1271                      startSymbol =  timeDomRsrcAllocList[k2Index].startSymbol;
1272                      endSymbol   =  startSymbol+ timeDomRsrcAllocList[k2Index].symbolLength;
1273                      dlSymbolPresent = false;
1274                      for(checkSymbol= startSymbol; checkSymbol<endSymbol; checkSymbol++)
1275                      {
1276                         currentSymbol = cell->cellCfg.tddCfg.slotCfg[k2TmpVal][checkSymbol];
1277                         if(currentSymbol == DL_SLOT || currentSymbol == FLEXI_SLOT)
1278                         {
1279                            dlSymbolPresent = true;
1280                            break;
1281                         }
1282                      }
1283                   }
1284                   /* Store all the values if all condition satisfies. */
1285                   if(dlSymbolPresent != true || slotCfg == UL_SLOT)
1286                   {
1287                      numK2 = k2InfoTbl->k2TimingInfo[slotIdx].numK2;
1288                      k2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[numK2] = k2Index;
1289                      k2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1290                   }
1291                }
1292
1293                if(msg3K2InfoTbl)
1294                {
1295                    msg3Delta = puschDeltaTable[cell->cellCfg.numerology];
1296
1297                   /* Check for K2 for MSG3 */
1298                   /* Current slot + k2 should be either UL or FLEXI slot.
1299                    * If slot is FLEXI then check all the symbols of that slot,
1300                    * it should not contain any DL or FLEXI slot */
1301                   msg3K2TmpVal = (slotIdx + k2Val + msg3Delta) % totalCfgSlot;
1302                   slotCfg = schGetSlotSymbFrmt(msg3K2TmpVal, cell->slotFrmtBitMap);
1303                   if(slotCfg != DL_SLOT)
1304                   {
1305                      if(slotCfg == FLEXI_SLOT)
1306                      {
1307                         startSymbol =  timeDomRsrcAllocList[k2Index].startSymbol;
1308                         endSymbol   =  startSymbol+ timeDomRsrcAllocList[k2Index].symbolLength;
1309                         dlSymbolPresent = false;
1310                         for(checkSymbol= startSymbol; checkSymbol<endSymbol; checkSymbol++)
1311                         {
1312                            currentSymbol = cell->cellCfg.tddCfg.slotCfg[msg3K2TmpVal][checkSymbol];
1313                            if(currentSymbol == DL_SLOT || currentSymbol == FLEXI_SLOT)
1314                            {
1315                               dlSymbolPresent = true;
1316                               break;
1317                            }
1318                         }
1319                      }
1320                      /* Store all the values if all condition satisfies. */
1321                      if(dlSymbolPresent != true || slotCfg == UL_SLOT)
1322                      {
1323                         numK2 = msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2;
1324                         msg3K2InfoTbl->k2TimingInfo[slotIdx].k2Indexes[numK2] = k2Index;
1325                         msg3K2InfoTbl->k2TimingInfo[slotIdx].numK2++;
1326                      }
1327                   }
1328                }
1329             }
1330          }
1331       }
1332 #endif
1333    }
1334 }
1335
1336 /*******************************************************************************************
1337  *
1338  * @brief Allocate the PRB using RRM policy
1339  *
1340  * @details
1341  *
1342  *    Function : prbAllocUsingRRMPolicy
1343  *
1344  *    Functionality:
1345  *      [Step1]: Traverse each Node in the LC list
1346  *      [Step2]: Check whether the LC has ZERO requirement then clean this LC
1347  *      [Step3]: Calcualte the maxPRB for this LC.
1348  *              a. For Dedicated LC, maxPRB = sum of remainingReservedPRB and
1349  *              sharedPRB
1350  *              b. For Default, just SharedPRB count
1351  *      [Step4]: If the LC is the First one to be allocated for this UE then add
1352  *      TX_PAYLODN_LEN to reqBO 
1353  *      [Step5]: Calculate the estimate PRB and estimate BO to be allocated
1354  *               based on reqBO and maxPRB left.
1355  *      [Step6]: Based on calculated PRB, Update Reserved PRB and Shared PRB counts
1356  *      [Step7]: Deduce the reqBO based on allocBO and move the LC node to last.
1357  *      [Step8]: Continue the next loop from List->head
1358  *
1359  *      [Loop Exit]:
1360  *        [Exit1]: If all the LCs are allocated in list
1361  *        [Exit2]: If PRBs are exhausted
1362  *
1363  * @params[in] I/P > lcLinkList pointer (LcInfo list)
1364  *             I/P > IsDedicatedPRB (Flag to indicate that RESERVED PRB to use 
1365  *             I/P > mcsIdx and PDSCH symbols count 
1366  *             I/P & O/P > Shared PRB , reserved PRB Count
1367  *             I/P & O/P > Total TBS size accumulated
1368  *             I/P & O/P > isTxPayloadLenAdded[For DL] : Decision flag to add the TX_PAYLOAD_HDR_LEN
1369  *             I/P & O/P > srRcvd Flag[For UL] : Decision flag to add UL_GRANT_SIZE
1370  *
1371  * @return void
1372  *
1373  * *******************************************************************************************/
1374 void prbAllocUsingRRMPolicy(CmLListCp *lcLL, bool isDedicatedPRB, uint16_t mcsIdx,uint8_t numSymbols,\
1375                   uint16_t *sharedPRB, uint16_t *reservedPRB, bool *isTxPayloadLenAdded, bool *srRcvd)
1376 {
1377    CmLList *node = NULLP;
1378    LcInfo *lcNode = NULLP;
1379    uint16_t remReservedPRB = 0, estPrb = 0, maxPRB = 0;
1380
1381    if(lcLL == NULLP)
1382    {
1383       DU_LOG("\nERROR --> SCH: LcList not present");
1384       return;
1385    }
1386    node = lcLL->first;
1387
1388    /*Only for Dedicated LcList, Valid value will be assigned to remReservedPRB
1389     * For Other LcList, remReservedPRB = 0*/
1390    if(reservedPRB != NULLP && isDedicatedPRB == TRUE)
1391    {
1392       remReservedPRB = *reservedPRB;
1393    }
1394
1395    /*[Step1]*/
1396    while(node)
1397    {
1398 #if 0
1399       /*For Debugging purpose*/
1400       printLcLL(lcLL);
1401 #endif
1402       lcNode = (LcInfo *)node->node;
1403
1404       /* [Step2]: Below condition will hit in rare case as it has been taken care during the cleaning 
1405        * process of LCID which was fully allocated. Check is just for safety purpose*/
1406       if(lcNode->reqBO == 0 && lcNode->allocBO == 0)
1407       {
1408          DU_LOG("\nERROR --> SCH: LCID:%d has no requirement, clearing this node",\
1409                lcNode->lcId);
1410          deleteNodeFromLList(lcLL, node);
1411          SCH_FREE(lcNode, sizeof(LcInfo));
1412          node = lcLL->first; 
1413          continue;
1414       }
1415
1416       /*[Exit1]: All LCs are allocated(allocBO = 0 for fully unallocated LC)*/
1417       if(lcNode->allocBO != 0)
1418       {
1419          DU_LOG("\nDEBUG -->  SCH: All LC are allocated [SharedPRB:%d]",*sharedPRB);
1420          return;
1421       }
1422
1423       /*[Exit2]: If PRBs are exhausted*/
1424       if(isDedicatedPRB)
1425       {
1426          /*Loop Exit: All resources exhausted*/
1427          if(remReservedPRB == 0 && *sharedPRB == 0)
1428          {
1429             DU_LOG("\nDEBUG  -->  SCH: Dedicated resources exhausted for LC:%d",lcNode->lcId);
1430             return;
1431          }
1432       }
1433       else
1434       {
1435          /*Loop Exit: All resources exhausted*/
1436          if(*sharedPRB == 0)
1437          {
1438             DU_LOG("\nDEBUG  --> SCH: Default resources exhausted for LC:%d",lcNode->lcId);
1439             return;
1440          }
1441       }
1442
1443       /*[Step3]*/
1444       maxPRB = remReservedPRB + *sharedPRB;
1445
1446       /*[Step4]*/
1447       if((isTxPayloadLenAdded != NULLP) && (*isTxPayloadLenAdded == FALSE))
1448       {
1449          DU_LOG("\nDEBUG  --> SCH: LC:%d is the First node to be allocated which includes TX_PAYLOAD_HDR_LEN",\
1450                lcNode->lcId);
1451          *isTxPayloadLenAdded = TRUE;
1452          lcNode->allocBO = calculateEstimateTBSize((lcNode->reqBO + TX_PAYLOAD_HDR_LEN),\
1453                mcsIdx, numSymbols, maxPRB, &estPrb);
1454          lcNode->allocBO -=TX_PAYLOAD_HDR_LEN;
1455       }
1456       else if((srRcvd != NULLP) && (*srRcvd == TRUE))
1457       {
1458          DU_LOG("\nDEBUG  --> SCH: LC:%d is the First node to be allocated which includes UL_GRANT_SIZE",\
1459                lcNode->lcId);
1460          *srRcvd = FALSE;
1461          lcNode->reqBO += UL_GRANT_SIZE;
1462          lcNode->allocBO = calculateEstimateTBSize(lcNode->reqBO, mcsIdx, numSymbols, maxPRB, &estPrb);
1463       }
1464       else
1465       {
1466          /*[Step4]*/
1467          lcNode->allocBO = calculateEstimateTBSize(lcNode->reqBO,\
1468                mcsIdx, numSymbols, maxPRB, &estPrb);
1469       }
1470
1471       /*[Step6]:Re-adjust the reservedPRB pool count and *SharedPRB Count based on
1472        * estimated PRB allocated*/
1473       if((isDedicatedPRB == TRUE) && (estPrb <= remReservedPRB))
1474       {
1475          remReservedPRB = remReservedPRB - estPrb;
1476       }
1477       else   /*LC requirement need PRB share from SharedPRB*/
1478       {
1479          if(*sharedPRB <=  (estPrb - remReservedPRB))
1480          {
1481             DU_LOG("\nDEBUG  --> SCH: SharedPRB is less");
1482             *sharedPRB = 0;
1483          }
1484          else
1485          {
1486             *sharedPRB = *sharedPRB - (estPrb - remReservedPRB);
1487          }
1488          remReservedPRB = 0;
1489       }
1490
1491       /*[Step7]*/
1492       lcNode->reqBO -= lcNode->allocBO;  /*Update the reqBO with remaining bytes unallocated*/
1493       lcNode->allocPRB = estPrb;
1494       cmLListAdd2Tail(lcLL, cmLListDelFrm(lcLL, node));
1495
1496       /*[Step8]:Next loop: First LC to be picked from the list
1497        * because Allocated Nodes are moved to the last*/
1498       node = lcLL->first; 
1499
1500    }
1501    return;
1502 }
1503
1504 /*******************************************************************************************
1505  *
1506  * @brief Check the LC List and fill the LC and GrantSize to be sent to MAC as
1507  * BO Report
1508  *
1509  * @details
1510  *
1511  *    Function : updateGrantSizeForBoRpt
1512  *
1513  *    Functionality:
1514  *             Check the LC List and fill the LC and GrantSize to be sent to MAC as
1515  *             BO Report in dlMsgAlloc Pointer
1516  *
1517  * @params[in] I/P > lcLinkList pointer (LcInfo list)
1518  *             I/P & O/P > dlMsgAlloc[for DL](Pending LC to be added in this context) 
1519  *             I/P & O/P > BsrInfo (applicable for UL)
1520  *             I/P & O/P > accumalatedBOSize
1521  * @return void
1522  *
1523  * *******************************************************************************************/
1524 void updateGrantSizeForBoRpt(CmLListCp *lcLL, DlMsgAlloc *dlMsgAlloc,\
1525                                 BsrInfo *bsrInfo, uint32_t *accumalatedBOSize)
1526 {
1527    CmLList *node = NULLP, *next = NULLP;
1528    LcInfo *lcNode = NULLP;
1529    DlMsgSchInfo *dlMsgSchInfo = NULLP;
1530
1531    if(lcLL == NULLP)
1532    {
1533       DU_LOG("\nERROR --> SCH: LcList not present");
1534       return;
1535    }
1536
1537    if(lcLL->count)
1538    {
1539       node = lcLL->first;
1540    }
1541    else
1542    {
1543       /*lcLL is empty*/
1544       return;
1545    }
1546
1547    /*Traverse List*/
1548    while(node)
1549    {
1550       next = node->next;
1551       lcNode = (LcInfo *)node->node;
1552       if(lcNode != NULLP)
1553       {
1554          DU_LOG("\nINFO   --> SCH : LcID:%d, [reqBO, allocBO, allocPRB]:[%d,%d,%d]",\
1555                lcNode->lcId, lcNode->reqBO, lcNode->allocBO, lcNode->allocPRB);
1556          if(dlMsgAlloc != NULLP)
1557          {
1558             dlMsgSchInfo = &dlMsgAlloc->dlMsgSchedInfo[dlMsgAlloc->numSchedInfo];
1559
1560             /*Add this LC to dlMsgAlloc so that if this LC gets allocated, BO
1561              * report for allocation can be sent to MAC*/
1562             dlMsgSchInfo->lcSchInfo[dlMsgSchInfo->numLc].lcId = lcNode->lcId;
1563             dlMsgSchInfo->lcSchInfo[dlMsgSchInfo->numLc].schBytes = lcNode->allocBO;
1564
1565             /*Calculate the Total Payload/BO size allocated*/
1566             *accumalatedBOSize += dlMsgSchInfo->lcSchInfo[dlMsgSchInfo->numLc].schBytes; 
1567
1568             DU_LOG("\nINFO   --> SCH: Added in MAC BO report: LCID:%d,reqBO:%d,Idx:%d, TotalBO Size:%d",\
1569                   lcNode->lcId,lcNode->reqBO, dlMsgSchInfo->numLc, *accumalatedBOSize);
1570
1571             dlMsgSchInfo->numLc++;
1572             /*The LC has been fully allocated, clean it*/
1573             if(lcNode->reqBO == 0)
1574             {
1575                handleLcLList(lcLL, lcNode->lcId, DELETE);
1576             }
1577          }
1578          else if(bsrInfo != NULLP)
1579          {
1580             *accumalatedBOSize += lcNode->allocBO;   
1581             DU_LOG("\nINFO   --> SCH: UL : LCID:%d,reqBO:%d, TotalBO Size:%d",\
1582                   lcNode->lcId,lcNode->reqBO, *accumalatedBOSize);
1583          }
1584       }
1585       node = next;
1586    }/*End of while*/
1587    return;
1588 }
1589
1590 /*******************************************************************
1591 *
1592 * @brief fill DL message information for MSG4 and Dedicated DL Msg
1593 *
1594 * @details
1595 *
1596 *    Function : fillDlMsgInfo
1597 *
1598 *    Functionality:
1599 *       fill DL message information for MSG4 and Dedicated DL Msg
1600 *
1601 * @params[in] DlMsgInfo *dlMsgInfo,  uint8_t crnti
1602 * @return void
1603 *
1604 *******************************************************************/
1605 void fillDlMsgInfo(DlMsgInfo *dlMsgInfo, uint8_t crnti)
1606 {
1607    dlMsgInfo->crnti = crnti;
1608    dlMsgInfo->ndi = 1;
1609    dlMsgInfo->harqProcNum = 0;
1610    dlMsgInfo->dlAssignIdx = 0;
1611    dlMsgInfo->pucchTpc = 0;
1612    dlMsgInfo->pucchResInd = 0;
1613    dlMsgInfo->harqFeedbackInd = 0;
1614    dlMsgInfo->dciFormatId = 1;
1615 }
1616
1617 /*******************************************************************
1618  *
1619  * @brief sch Process pending Msg4 Req
1620  *
1621  * @details
1622  *
1623  *    Function : schProcessMsg4Req
1624  *
1625  *    Functionality:
1626  *       sch Process pending Msg4 Req
1627  *
1628  * @params[in] SchCellCb *cell,  SlotTimingInfo currTime 
1629  * @return ROK     - success
1630  *         RFAILED - failure
1631  *
1632  *******************************************************************/
1633
1634 bool schProcessMsg4Req(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId)
1635 {
1636    uint8_t pdschStartSymbol = 0, pdschNumSymbols = 0;
1637    SlotTimingInfo pdcchTime, pdschTime, pucchTime;
1638    DlMsgAlloc *dciSlotAlloc = NULLP;    /* Stores info for transmission of PDCCH for Msg4 */
1639    DlMsgAlloc  *msg4SlotAlloc = NULLP;   /* Stores info for transmission of PDSCH for Msg4 */
1640
1641    if(cell == NULL)
1642    {
1643       DU_LOG("\nERROR  -->  SCH: schDlRsrcAllocMsg4() : Cell is NULL");
1644       return false;
1645    }
1646    
1647    if(findValidK0K1Value(cell, currTime, ueId, false, &pdschStartSymbol, &pdschNumSymbols, &pdcchTime, &pdschTime,\
1648             &pucchTime) != true )
1649    {
1650       return false;
1651    }
1652
1653    if(cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] == NULL)
1654    {
1655       SCH_ALLOC(dciSlotAlloc, sizeof(DlMsgAlloc));
1656       if(dciSlotAlloc == NULLP)
1657       {
1658          DU_LOG("\nERROR  -->  SCH : Memory Allocation failed for dciSlotAlloc");
1659          return false;
1660       }
1661       cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] = dciSlotAlloc;
1662       memset(dciSlotAlloc, 0, sizeof(DlMsgAlloc));
1663       GET_CRNTI(dciSlotAlloc->crnti, ueId);
1664    }
1665    else
1666       dciSlotAlloc = cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1];
1667
1668    /* Fill PDCCH and PDSCH scheduling information for Msg4 */
1669    if((schDlRsrcAllocMsg4(cell, pdschTime, ueId, dciSlotAlloc, pdschStartSymbol, pdschNumSymbols)) != ROK)
1670    {
1671       DU_LOG("\nERROR  -->  SCH: Scheduling of Msg4 failed in slot [%d]", pdschTime.slot);
1672       if(dciSlotAlloc->numSchedInfo == 0)
1673       {
1674          SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
1675          cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] = NULLP;
1676       }
1677       else
1678          memset(&dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], 0, sizeof(DlMsgSchInfo));
1679       return false;
1680    }
1681
1682    /* Check if both DCI and RAR are sent in the same slot.
1683     * If not, allocate memory RAR PDSCH slot to store RAR info
1684     */
1685    if(pdcchTime.slot == pdschTime.slot)
1686    {
1687       dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo].pduPres = BOTH;
1688       dciSlotAlloc->numSchedInfo++;
1689    }
1690    else
1691    {
1692       /* Allocate memory to schedule rarSlot to send RAR, pointer will be checked at schProcessSlotInd() */
1693       if(cell->schDlSlotInfo[pdschTime.slot]->dlMsgAlloc[ueId-1] == NULL)
1694       {
1695          SCH_ALLOC(msg4SlotAlloc, sizeof(DlMsgAlloc));
1696          if(msg4SlotAlloc == NULLP)
1697          {
1698             DU_LOG("\nERROR  -->  SCH : Memory Allocation failed for msg4SlotAlloc");
1699             if(dciSlotAlloc->numSchedInfo == 0)
1700             {
1701                SCH_FREE(dciSlotAlloc, sizeof(DlMsgAlloc));
1702                cell->schDlSlotInfo[pdcchTime.slot]->dlMsgAlloc[ueId-1] = NULLP;
1703             }
1704             else
1705                memset(&dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], 0, sizeof(DlMsgSchInfo));
1706             return false;
1707          }
1708          cell->schDlSlotInfo[pdschTime.slot]->dlMsgAlloc[ueId-1] = msg4SlotAlloc;
1709          memset(msg4SlotAlloc, 0, sizeof(DlMsgAlloc));
1710          msg4SlotAlloc->crnti = dciSlotAlloc->crnti;
1711       }
1712       else
1713          msg4SlotAlloc = cell->schDlSlotInfo[pdschTime.slot]->dlMsgAlloc[ueId-1];
1714
1715       /* Copy all RAR info */
1716       memcpy(&msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo], \
1717          &dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo], sizeof(DlMsgSchInfo));
1718       msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo].dlMsgPdcchCfg.dci.pdschCfg = \
1719          &msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo].dlMsgPdschCfg;
1720
1721       /* Assign correct PDU types in corresponding slots */
1722       msg4SlotAlloc->dlMsgSchedInfo[msg4SlotAlloc->numSchedInfo].pduPres = PDSCH_PDU;
1723       dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo].pduPres = PDCCH_PDU;
1724       dciSlotAlloc->dlMsgSchedInfo[dciSlotAlloc->numSchedInfo].pdschSlot = pdschTime.slot;
1725
1726       dciSlotAlloc->numSchedInfo++;
1727       msg4SlotAlloc->numSchedInfo++;
1728    }
1729
1730    /* PUCCH resource */
1731    schAllocPucchResource(cell, pucchTime, cell->raCb[ueId-1].tcrnti);
1732
1733    cell->schDlSlotInfo[pdcchTime.slot]->pdcchUe = ueId;
1734    cell->schDlSlotInfo[pdschTime.slot]->pdschUe = ueId;
1735    cell->schUlSlotInfo[pucchTime.slot]->pucchUe = ueId;
1736    cell->raCb[ueId-1].msg4recvd = FALSE;
1737    return true;
1738 }
1739
1740 /*******************************************************************
1741  *
1742  * @brief  Handler to calculate TBS size for BSR requested
1743  *
1744  * @details
1745  *
1746  *    Function :  schCalculateUlTbs
1747  *
1748  *    Functionality: Function will note the required TBS for each LCGIDX and use
1749  *    the Priority LCG List and RRM policy to allocate the TBS size
1750  *
1751  * @params [in] ueCb (Pointer to UE CB)
1752  *         [in] puschTime (Time slot where PUSCH will be sent)
1753  *         [in] symbLen (No of Symbols used for PUSCH transmission)
1754  *         [out] startPrb(Pointer to startPRB which will be calculated while
1755  *         finding the best Free Block)
1756  *         [out] totTBS(Pointer to total TBS size)
1757  *
1758  * @return bool : true > Scheduling of UL grant is successful
1759  *                false > vice versa
1760  *
1761  * ****************************************************************/
1762 bool schCalculateUlTbs(SchUeCb *ueCb, SlotTimingInfo puschTime, uint8_t symbLen,\
1763                           uint16_t *startPrb, uint32_t *totTBS)
1764 {
1765    uint16_t mcsIdx = 0;
1766    CmLListCp *lcLL = NULLP;
1767    uint16_t lcgIdx = 0, lcId =0, maxFreePRB = 0;
1768
1769    *startPrb = 0;
1770    *totTBS = 0;
1771
1772    /* check for BSR */
1773    for(lcgIdx=0; lcgIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcgIdx++)
1774    {
1775       if(ueCb->bsrInfo[lcgIdx].dataVol == 0)
1776       {
1777          continue;
1778       }
1779
1780       /*TODO: lcgIdx and LCID has been implemented as one to one mapping.
1781        * Need to check the mapping to figure out the LCID and lcgIdx once L2
1782        * spec specifies any logic*/
1783       lcId = lcgIdx;
1784       if(ueCb->ulInfo.ulLcCtxt[lcId].isDedicated)
1785       {
1786          lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
1787       }
1788       else
1789       {
1790          lcLL = &(ueCb->ulLcPrbEst.defLcList);
1791       }
1792
1793       /*[Step2]: Update the reqPRB and Payloadsize for this LC in the appropriate List*/
1794       if(updateLcListReqPRB(lcLL, lcId, ueCb->bsrInfo[lcgIdx].dataVol) != ROK)
1795       {
1796          DU_LOG("\nERROR  --> SCH: LcgId:%d updation failed",lcId);
1797          return false; 
1798       }
1799    }
1800
1801    if ((ueCb->ulLcPrbEst.defLcList.count == 0) && \
1802          ((ueCb->ulLcPrbEst.dedLcInfo == NULL) || (ueCb->ulLcPrbEst.dedLcInfo->dedLcList.count == 0)))
1803    {
1804       if(ueCb->srRcvd)
1805       {
1806          *startPrb = MAX_NUM_RB;
1807          *totTBS = schCalcTbSize(UL_GRANT_SIZE);
1808       }
1809
1810       /*Returning true when NO Grant is there for UE as this is not scheduling
1811        * error*/
1812       return (true);
1813    }
1814
1815    maxFreePRB = searchLargestFreeBlock(ueCb->cellCb, puschTime, startPrb, DIR_UL);
1816
1817    /*[Step4]: Estimation of PRB and BO which can be allocated to each LC in
1818     * the list based on RRM policy*/
1819
1820    /*Either this UE contains no reservedPRB pool fir dedicated S-NSSAI or 
1821     * Num of Free PRB available is not enough to reserve Dedicated PRBs*/
1822    if(maxFreePRB != 0)
1823    {
1824       mcsIdx = ueCb->ueCfg.ulModInfo.mcsIndex;
1825       if((ueCb->ulLcPrbEst.dedLcInfo == NULLP) 
1826             || ((maxFreePRB <  ueCb->ulLcPrbEst.dedLcInfo->rsvdDedicatedPRB)))
1827       { 
1828          ueCb->ulLcPrbEst.sharedNumPrb = maxFreePRB;
1829          DU_LOG("\nDEBUG  -->  SCH : UL Only Default Slice is scheduled, sharedPRB Count:%d",\
1830                ueCb->ulLcPrbEst.sharedNumPrb);
1831
1832          /*PRB Alloc for Default LCs*/
1833          prbAllocUsingRRMPolicy(&(ueCb->ulLcPrbEst.defLcList), FALSE, mcsIdx, symbLen,\
1834                &(ueCb->ulLcPrbEst.sharedNumPrb), NULLP, NULLP,&(ueCb->srRcvd));
1835       }
1836       else
1837       {
1838          ueCb->ulLcPrbEst.sharedNumPrb = maxFreePRB - ueCb->ulLcPrbEst.dedLcInfo->rsvdDedicatedPRB;
1839
1840          /*PRB Alloc for Dedicated LCs*/
1841          prbAllocUsingRRMPolicy(&(ueCb->ulLcPrbEst.dedLcInfo->dedLcList), TRUE, mcsIdx, symbLen,\
1842                &(ueCb->ulLcPrbEst.sharedNumPrb), &(ueCb->ulLcPrbEst.dedLcInfo->rsvdDedicatedPRB),\
1843                NULLP,&(ueCb->srRcvd));
1844
1845          /*PRB Alloc for Default LCs*/
1846          prbAllocUsingRRMPolicy(&(ueCb->ulLcPrbEst.defLcList), FALSE, mcsIdx, symbLen, \
1847                &(ueCb->ulLcPrbEst.sharedNumPrb), &(ueCb->ulLcPrbEst.dedLcInfo->rsvdDedicatedPRB),\
1848                NULLP,&(ueCb->srRcvd));
1849       }
1850    }
1851    /*[Step5]:Traverse each LCID in LcList to calculate the exact Scheduled Bytes
1852     * using allocated BO per LC and Update dlMsgAlloc(BO report for MAC*/ 
1853    if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
1854       updateGrantSizeForBoRpt(&(ueCb->ulLcPrbEst.dedLcInfo->dedLcList), NULLP, ueCb->bsrInfo, totTBS);
1855
1856    updateGrantSizeForBoRpt(&(ueCb->ulLcPrbEst.defLcList), NULLP, ueCb->bsrInfo, totTBS);
1857
1858    /*Below case will hit if NO LC(s) are allocated due to resource crunch*/
1859    if (*totTBS == 0)
1860    {
1861       if(maxFreePRB == 0)
1862       {
1863          DU_LOG("\nERROR  --> SCH : NO FREE PRB!!");
1864       }
1865       else
1866       {
1867          /*Schedule the LC for next slot*/
1868          DU_LOG("\nDEBUG  -->  SCH : No LC has been scheduled");
1869       }
1870       return (false);
1871    }
1872    return (true);
1873 }
1874
1875 /*******************************************************************
1876  *
1877  * @brief sch Process pending Sr or Bsr Req
1878  *
1879  * @details
1880  *
1881  *    Function : schProcessSrOrBsrReq
1882  *
1883  *    Functionality:
1884  *       sch Process pending Sr or Bsr Req
1885  *
1886  * @params[in] SchCellCb *cell,  SlotTimingInfo currTime 
1887  * @return ROK     - success
1888  *         RFAILED - failure
1889  *
1890  *******************************************************************/
1891 bool schProcessSrOrBsrReq(SchCellCb *cell, SlotTimingInfo currTime, uint8_t ueId)
1892 {
1893    bool k2Found = FALSE, ret = FALSE;
1894    uint8_t startSymb = 0, symbLen = 0;
1895    uint8_t k2TblIdx = 0, k2Index = 0, k2Val = 0;
1896    uint16_t startPrb = 0;
1897    uint32_t totDataReq = 0; /* in bytes */
1898    SchUeCb *ueCb;
1899    SchPuschInfo *puschInfo;
1900    DciInfo  *dciInfo = NULLP;
1901    SchK2TimingInfoTbl *k2InfoTbl=NULLP;
1902    SlotTimingInfo dciTime, puschTime;
1903
1904    if(cell == NULLP)
1905    {
1906       DU_LOG("\nERROR  -->  SCH: schDlRsrcAllocMsg4() : Cell is NULL");
1907       return false;
1908    }
1909
1910    ueCb = &cell->ueCb[ueId-1];
1911
1912    if(ueCb == NULLP)
1913    {
1914       DU_LOG("\nERROR  -->  SCH: schDlRsrcAllocMsg4() : UE is NULL");
1915       return false;
1916    }
1917    /* Calculating time frame to send DCI for SR */
1918    ADD_DELTA_TO_TIME(currTime, dciTime, PHY_DELTA_DL + SCHED_DELTA);
1919 #ifdef NR_TDD
1920    if(schGetSlotSymbFrmt(dciTime.slot, cell->slotFrmtBitMap) == DL_SLOT)
1921 #endif
1922    {     
1923       if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt)
1924          k2InfoTbl = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl;
1925       else
1926          k2InfoTbl =  &cell->cellCfg.schInitialUlBwp.k2InfoTbl;
1927
1928       for(k2TblIdx = 0; k2TblIdx < k2InfoTbl->k2TimingInfo[dciTime.slot].numK2; k2TblIdx++)
1929       {
1930          k2Index = k2InfoTbl->k2TimingInfo[dciTime.slot].k2Indexes[k2TblIdx];
1931
1932          if(!ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt)
1933          {
1934             k2Val = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].k2;
1935             startSymb = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].startSymbol;
1936             symbLen = cell->cellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[k2Index].symbolLength;
1937          }
1938          else
1939          {
1940             k2Val = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[k2Index].k2;
1941             startSymb =  ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[k2Index].startSymbol;
1942             symbLen =  ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[k2Index].symbolLength;
1943          }
1944
1945          /* Calculating time frame to send PUSCH for SR */
1946          ADD_DELTA_TO_TIME(dciTime, puschTime, k2Val);
1947 #ifdef NR_TDD
1948          if(schGetSlotSymbFrmt(puschTime.slot, cell->slotFrmtBitMap) == DL_SLOT)
1949             continue;
1950 #endif
1951          if(cell->schUlSlotInfo[puschTime.slot]->puschUe != 0)
1952          {
1953             continue;
1954          }
1955          k2Found = true;
1956          break;
1957       }
1958    }
1959
1960    if(k2Found == true)
1961    {
1962       ret = schCalculateUlTbs(ueCb, puschTime, symbLen, &startPrb, &totDataReq);
1963       if(totDataReq > 0 && ret == TRUE)
1964       {
1965          SCH_ALLOC(dciInfo, sizeof(DciInfo));
1966          if(!dciInfo)
1967          {
1968             DU_LOG("\nERROR  -->  SCH : Memory Allocation failed for dciInfo alloc");
1969
1970             if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
1971                updateBsrAndLcList(&(ueCb->ulLcPrbEst.dedLcInfo->dedLcList), ueCb->bsrInfo, RFAILED);
1972
1973             updateBsrAndLcList(&(ueCb->ulLcPrbEst.defLcList), ueCb->bsrInfo, RFAILED);
1974             return false;
1975          }
1976          cell->schDlSlotInfo[dciTime.slot]->ulGrant = dciInfo;
1977          memset(dciInfo,0,sizeof(DciInfo));
1978
1979          /* Update PUSCH allocation */
1980          if(schFillPuschAlloc(ueCb, puschTime, totDataReq, startSymb, symbLen, startPrb) == ROK)
1981          {
1982             if(cell->schUlSlotInfo[puschTime.slot]->schPuschInfo)
1983             {
1984                puschInfo = cell->schUlSlotInfo[puschTime.slot]->schPuschInfo;
1985                if(puschInfo != NULLP)
1986                {
1987                   /* Fill DCI for UL grant */
1988                   schFillUlDci(ueCb, puschInfo, dciInfo);
1989                   memcpy(&dciInfo->slotIndInfo, &dciTime, sizeof(SlotTimingInfo));
1990                   ueCb->srRcvd = false;
1991                   ueCb->bsrRcvd = false;
1992                   cell->schUlSlotInfo[puschTime.slot]->puschUe = ueId;
1993                   if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
1994                      updateBsrAndLcList(&(ueCb->ulLcPrbEst.dedLcInfo->dedLcList), ueCb->bsrInfo, ROK);
1995
1996                   updateBsrAndLcList(&(ueCb->ulLcPrbEst.defLcList), ueCb->bsrInfo, ROK);
1997                   return true;
1998                }
1999             }
2000          }
2001
2002          if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
2003             updateBsrAndLcList(&(ueCb->ulLcPrbEst.dedLcInfo->dedLcList), ueCb->bsrInfo, RFAILED);
2004
2005          updateBsrAndLcList(&(ueCb->ulLcPrbEst.defLcList), ueCb->bsrInfo, RFAILED);
2006       }
2007    }
2008    return (ret);
2009 }
2010
2011
2012 /*******************************************************************
2013  *
2014  * @brief sch Process pending Sr or Bsr Req
2015  *
2016  * @details
2017  *
2018  *    Function : updateBsrAndLcList
2019  *
2020  *    Functionality:
2021  *       Updating the BSRInfo in UECB and Lclist
2022  *
2023  * @params[in] SchCellCb *cell,  SlotTimingInfo currTime 
2024  * @return ROK     - success
2025  *         RFAILED - failure
2026  *
2027  *******************************************************************/
2028 void updateBsrAndLcList(CmLListCp *lcLL, BsrInfo *bsrInfo, uint8_t status)
2029 {
2030    CmLList *node = NULLP, *next = NULLP;
2031    LcInfo *lcNode = NULLP;
2032
2033    if(lcLL == NULLP)
2034    {
2035       DU_LOG("\nERROR --> SCH: LcList not present");
2036       return;
2037    }
2038
2039    if(lcLL->count)
2040    {
2041       node = lcLL->first;
2042    }
2043    else
2044    {
2045       /*lcLL is empty*/
2046       return;
2047    }
2048
2049    while(node)
2050    {
2051       next = node->next;
2052       lcNode = (LcInfo *)node->node;
2053       if(lcNode != NULLP)
2054       {
2055           /*Only when Status is OK then allocation is marked as ZERO and reqBO
2056            * is updated in UE's DB. If Failure, then allocation is added to reqBO 
2057            * and same is updated in Ue's DB inside BSR Info structure*/
2058          if(status == ROK)
2059          {
2060             lcNode->allocBO = 0;
2061          }
2062
2063          lcNode->reqBO += lcNode->allocBO;
2064          bsrInfo[lcNode->lcId].dataVol = lcNode->reqBO;
2065          if(lcNode->reqBO == 0)
2066          {
2067             handleLcLList(lcLL, lcNode->lcId, DELETE);
2068          }
2069       }
2070       node = next;
2071    }
2072 }     
2073 /**********************************************************************
2074   End of file
2075  **********************************************************************/
2076