[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-523] Statistics Request API and Timer Based...
[o-du/l2.git] / src / 5gnrsch / sch_ue_mgr.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 /* This file contains UE management handling functionality for SCH */
19
20 #include "common_def.h"
21 #include "tfu.h"
22 #include "lrg.h"
23
24 #include "tfu.x"
25 #include "lrg.x"
26 #include "du_log.h"
27 #include "du_app_mac_inf.h"
28 #include "mac_sch_interface.h"
29 #include "sch.h"
30 #include "sch_tmr.h"
31 #include "sch_utils.h"
32 #ifdef NR_DRX 
33 #include "sch_drx.h"
34 #endif
35
36 /*******************************************************************
37  *
38  * @brief Fill and send UE cfg response to MAC
39  *
40  * @details
41  *
42  *    Function : SchSendUeCfgRspToMac
43  *
44  *    Functionality: Fill and send UE cfg response to MAC
45  *
46  * @params[in] 
47  * @return ROK     - success
48  *         RFAILED - failure
49  *
50  * ****************************************************************/
51 void SchSendUeCfgRspToMac(SchUeCfgReq *ueCfg, Inst inst,\
52       SchMacRsp result, SchUeCfgRsp *cfgRsp)
53 {
54    Pst rspPst;
55
56    cfgRsp->cellId = ueCfg->cellId;
57    cfgRsp->ueId = ueCfg->ueId;
58    cfgRsp->crnti = ueCfg->crnti;
59    cfgRsp->rsp = result;   
60
61    /* Filling response post */
62    memset(&rspPst, 0, sizeof(Pst));
63    FILL_PST_SCH_TO_MAC(rspPst, inst);
64    rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
65    DU_LOG("\nINFO  -->  SCH :  Sending UE Config response to MAC");
66    MacMessageRouter(&rspPst, (void *)cfgRsp);
67 }
68
69 /*******************************************************************
70  *
71  * @brief Fill and send UE Recfg response to MAC
72  *
73  * @details
74  *
75  *    Function : SchSendUeRecfgRspToMac
76  *
77  *    Functionality: Fill and send UE Recfg response to MAC
78  *
79  * @params[in] 
80  * @return ROK     - success
81  *         RFAILED - failure
82  *
83  * ****************************************************************/
84 void SchSendUeRecfgRspToMac(SchUeRecfgReq *ueRecfgReq, Inst inst,\
85       SchMacRsp result, SchUeRecfgRsp *reCfgRsp)
86 {
87    Pst rspPst;
88
89    reCfgRsp->cellId = ueRecfgReq->cellId;
90    reCfgRsp->ueId = ueRecfgReq->ueId;
91    reCfgRsp->crnti = ueRecfgReq->crnti;
92    reCfgRsp->rsp = result;   
93
94    /* Filling response post */
95    memset(&rspPst, 0, sizeof(Pst));
96    FILL_PST_SCH_TO_MAC(rspPst, inst);
97    rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
98    DU_LOG("\nINFO  -->  SCH :  Sending UE Reconfig response to MAC");
99     MacMessageRouter(&rspPst, (void *)reCfgRsp);
100 }
101
102 /*******************************************************************
103  
104  *
105  * @brief Function to fill Dl Lc Context in SCH Ue Cb
106  *
107  * @details
108  *
109  *    Function : fillSchDlLcCtxt
110  *
111  *    Functionality: Function to fill Dl Lc Context in SCH Ue Cb
112  *
113  * @params[in] SchDlLcCtxt pointer,
114  *             SchLcCfg pointer
115  * @return void
116  *
117  * ****************************************************************/
118
119 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
120 {
121    ueCbLcCfg->lcId = lcCfg->lcId;
122    ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
123    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
124    ueCbLcCfg->bo = 0;
125    if(lcCfg->drbQos)
126    {
127      ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
128    }
129    if(lcCfg->snssai)
130    {
131      if(ueCbLcCfg->snssai == NULLP)/*In CONFIG_MOD case, no need to allocate SNSSAI memory*/
132      {
133         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
134      }
135      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
136    }
137 }
138
139 /*******************************************************************
140  *
141  * @brief Function to fill Ul Lc Context in SCH Ue Cb
142  *
143  * @details
144  *
145  *    Function : fillSchUlLcCtxt
146  *
147  *    Functionality: Function to fill Ul Lc Context in SCH Ue Cb
148  *
149  * @params[in] SchUlLcCtxt pointer,
150  *             SchLcCfg pointer
151  * @return void
152  *
153  * ****************************************************************/
154
155 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
156 {
157    ueCbLcCfg->lcId = lcCfg->lcId;
158    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
159    ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
160    ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
161    ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
162    ueCbLcCfg->pbr     = lcCfg->ulLcCfg.pbr;
163    ueCbLcCfg->bsd     = lcCfg->ulLcCfg.bsd;
164
165    if(lcCfg->drbQos)
166    {
167       ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
168    }
169    if(lcCfg->snssai)
170    {
171      /*In CONFIG_MOD case, no need to allocate SNSSAI memory again*/
172      if(ueCbLcCfg->snssai == NULLP)
173      {
174         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
175      }
176      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
177    }
178 }
179
180 /*******************************************************************
181  *
182  * @brief Function to update/allocate dedLC Info
183  *
184  * @details
185  *
186  *    Function : updateDedLcInfo
187  *
188  *    Functionality: Function to fill DLDedLcInfo
189  *
190  * @params[arg] scheduler instance,
191  *              snssai pointer,
192  *              SchRrmPolicy pointer,
193  *              SchLcPrbEstimate pointer , It will be filled
194  *              isDedicated pointer,(Address of isDedicated flag in LC Context)
195  *
196  * @return ROK      >> This LC is part of RRM MemberList.
197  *         RFAILED  >> FATAL Error
198  *         ROKIGNORE >> This LC is not part of this RRM MemberList 
199  *
200  * ****************************************************************/
201
202 uint8_t updateDedLcInfo(Inst inst, Snssai *snssai, uint16_t *rsvdDedicatedPRB, bool *isDedicated)
203 {
204    CmLList *sliceCfg = schCb[inst].sliceCfg.first;
205    SchRrmPolicyOfSlice *rrmPolicyOfSlices;
206
207    while(sliceCfg)
208    {
209       rrmPolicyOfSlices = (SchRrmPolicyOfSlice*)sliceCfg->node;
210       if(rrmPolicyOfSlices && (memcmp(snssai, &(rrmPolicyOfSlices->snssai), sizeof(Snssai)) == 0))
211       {
212          /*Updating latest RrmPolicy*/
213          *rsvdDedicatedPRB = \
214                              (uint16_t)(((rrmPolicyOfSlices->rrmPolicyRatioInfo.dedicatedRatio)*(MAX_NUM_RB))/100);
215          *isDedicated = TRUE;
216          DU_LOG("\nINFO  -->  SCH : Updated RRM policy, reservedPOOL:%d",*rsvdDedicatedPRB);
217          break;
218       }
219       sliceCfg = sliceCfg->next;
220    }
221    /*case: This LcCtxt  is either a Default LC or this LC is part of someother RRM_MemberList*/
222    if(*isDedicated != TRUE) 
223    {
224       DU_LOG("\nINFO  -->  SCH : This SNSSAI is not a part of this RRMPolicy");
225    }
226    return ROK;   
227 }
228
229 /*******************************************************************
230  *
231  * @brief Function to fill SpCellCfg in SchUeCb From SchUeCfg Req
232  *
233  * @details
234  *
235  *    Function : fillSpCellInSchCb
236  *
237  *    Functionality: Function to fill SpCellCfg in SchUeCb
238  *
239  * @params[in] Scheduler instance,
240  *             SchUeCb pointer,
241  *             SchUeCfg pointer
242  * @return ROK/RFAILED
243  *
244  * ****************************************************************/
245
246 void fillSpCellInSchCb(SchSpCellRecfg *destSpCellCfg, SchSpCellCfg *srcSpCellCfg)
247 {
248    destSpCellCfg->servCellIdx = srcSpCellCfg->servCellIdx;
249    memcpy(&destSpCellCfg->servCellRecfg.initDlBwp, &srcSpCellCfg->servCellCfg.initDlBwp, sizeof(SchInitalDlBwp));
250    destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod =  srcSpCellCfg->servCellCfg.numDlBwpToAdd;
251    if(destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod > 0)
252    {
253       memcpy(destSpCellCfg->servCellRecfg.dlBwpToAddOrModList, srcSpCellCfg->servCellCfg.dlBwpToAddList,\
254               (sizeof(SchDlBwpInfo) * srcSpCellCfg->servCellCfg.numDlBwpToAdd));
255    }
256    destSpCellCfg->servCellRecfg.firstActvDlBwpId = srcSpCellCfg->servCellCfg.firstActvDlBwpId;
257    destSpCellCfg->servCellRecfg.defaultDlBwpId = srcSpCellCfg->servCellCfg.defaultDlBwpId;
258    destSpCellCfg->servCellRecfg.bwpInactivityTmr = srcSpCellCfg->servCellCfg.bwpInactivityTmr;
259    memcpy(&destSpCellCfg->servCellRecfg.pdschServCellCfg, &srcSpCellCfg->servCellCfg.pdschServCellCfg, sizeof(SchPdschServCellCfg));
260    memcpy(&destSpCellCfg->servCellRecfg.initUlBwp, &srcSpCellCfg->servCellCfg.initUlBwp, sizeof(SchInitialUlBwp));
261    
262    destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod =  srcSpCellCfg->servCellCfg.numDlBwpToAdd;
263    if(destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod > 0)
264    {
265       memcpy(destSpCellCfg->servCellRecfg.ulBwpToAddOrModList, srcSpCellCfg->servCellCfg.ulBwpToAddList,\
266               (sizeof(SchUlBwpInfo) * srcSpCellCfg->servCellCfg.numUlBwpToAdd));
267    }
268    destSpCellCfg->servCellRecfg.firstActvUlBwpId = srcSpCellCfg->servCellCfg.firstActvUlBwpId;
269    return;
270 }
271
272 /*******************************************************************
273  *
274  * @brief Function to fill SchUeCb From UeCfg Req
275  *
276  * @details
277  *
278  *    Function : fillSchUeCbFrmCfgReq
279  *
280  *    Functionality: Function to fill SchUeCb
281  *
282  * @params[in] Scheduler instance,
283  *             SchUeCb pointer,
284  *             SchUeCfg pointer
285  * @return ROK/RFAILED
286  *
287  * ****************************************************************/
288
289 uint8_t fillSchUeCbFrmCfgReq(Inst inst, SchUeCb *ueCb, SchUeCfgReq *ueCfg)
290 {
291    uint8_t   lcIdx, ueLcIdx, idx;
292    uint8_t   freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
293    SchPdschCfgCmn pdschCfg;
294    SchPucchDlDataToUlAck *dlDataToUlAck;
295    uint8_t retDL = ROK, retUL = ROK;
296    bool isLcIdValid = FALSE;
297
298    ueCb->ueCfg.cellId = ueCfg->cellId;
299    ueCb->ueCfg.ueId = ueCfg->ueId;
300    ueCb->ueCfg.crnti = ueCfg->crnti;
301    if(ueCfg->macCellGrpCfgPres == true)
302    {
303       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg)); 
304       ueCb->ueCfg.macCellGrpCfgPres = true;
305 #ifdef NR_DRX
306       if(ueCfg->macCellGrpCfg.drxCfgPresent == true)
307       {
308          if(ueCb->ueDrxInfoPres == false)
309          {
310             ueCb->ueDrxInfoPres = true;
311             /* intialize the drxUeCb */
312             schInitDrxUeCb(ueCb);
313
314             /* intialize the Dl drxHarqCb */
315             for(idx =0; idx<ueCb->dlHqEnt.numHqPrcs; idx++)
316             {
317                schInitDrxHarqCb(&ueCb->dlHqEnt.procs[idx].dlDrxHarqCb);
318             }
319             /* intialize the Ul drxHarqCb */
320             for(idx =0; idx<ueCb->ulHqEnt.numHqPrcs; idx++)
321             {
322                schInitDrxHarqCb(&ueCb->ulHqEnt.procs[idx].ulDrxHarqCb);
323             }
324             /* convert all the drx configuration recived in ms/subms into number of slots and store into the drxUeCb */
325             schFillDrxUeCb(ueCb->cellCb->numerology, ueCfg->macCellGrpCfg.drxCfg, &ueCb->drxUeCb);
326             /* Calculate the onduration timer and short cycle timer (if shortcycle configuration is present) as soon as we 
327              * recived ueCfg request */
328             schAddUeInOndurationList(ueCb->cellCb, ueCb, 0);
329
330          }
331          else
332          {
333             /* convert all the drx configuration recived in ms/subms into number
334              * of slots and store into the drxUeCb */
335             schFillDrxUeCb(ueCb->cellCb->numerology, ueCfg->macCellGrpCfg.drxCfg, &ueCb->drxUeCb);
336
337             /* Recalculate/Restart timer based on their presence */
338             schDrxUeReCfgTimer(ueCb->cellCb, ueCb);
339          }
340       }
341 #endif
342    }
343
344    if(ueCfg->phyCellGrpCfgPres == true)
345    {
346       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
347       ueCb->ueCfg.phyCellGrpCfgPres = true;
348    }
349
350    if(ueCfg->spCellCfgPres == true)
351    {
352       if(ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
353       {
354          if(ueCb->ueCfg.spCellCfgPres && ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfgPres == true)
355          {
356             for(idx = 0; idx < ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc; idx++)
357             {
358                if(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0 && ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0)
359                {
360                   SCH_FREE(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0, sizeof(uint8_t));  
361                }
362             }
363          }
364       }
365       fillSpCellInSchCb(&ueCb->ueCfg.spCellCfg, &ueCfg->spCellCfg);
366
367       covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
368             freqDomainResource);
369       memset(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
370       memcpy(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
371
372       ueCb->ueCfg.spCellCfgPres = true;
373       dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
374       if(ueCb->cellCb)
375       {
376          if(dlDataToUlAck)
377          {
378             BuildK0K1Table(ueCb->cellCb, &ueCb->k0K1InfoTbl, false, pdschCfg,\
379                   ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
380                   dlDataToUlAck->dlDataToUlAckList);
381             ueCb->k0K1TblPrsnt = true;
382             BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
383                   ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
384                   NULLP, &ueCb->k2InfoTbl);
385             ueCb->k2TblPrsnt = true;
386          }
387       }
388    }
389
390    if(ueCfg->ambrCfg)
391    {
392       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
393       ueCb->ueCfg.ambrCfg =  ueCfg->ambrCfg;
394    }
395    memcpy(&ueCb->ueCfg.dlModInfo,  &ueCfg->dlModInfo , sizeof(SchModulationInfo));
396    memcpy(&ueCb->ueCfg.ulModInfo,  &ueCfg->ulModInfo , sizeof(SchModulationInfo));
397    //Updating SchUlCb and SchDlCb DB in SchUeCb
398    for(lcIdx = 0; lcIdx < ueCfg->numLcsToAdd; lcIdx++)
399    {
400       isLcIdValid = FALSE; /*Re-Initializing*/
401
402       ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
403       CHECK_LCID(ueLcIdx, isLcIdValid);
404       if(isLcIdValid == FALSE)
405       {
406          DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
407          continue;
408       }
409       fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
410       fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
411
412       /*Checking whether this LC belong to Dedicated S-NSSAI 
413        * and Create the Dedicated LC List & Update the Reserve PRB number*/
414       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
415       {
416          retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
417                &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
418       }
419       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
420       {
421          retUL =  updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
422                &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
423       }
424
425       if(retUL == RFAILED  || retDL == RFAILED)/*FATAL error*/
426       {
427          DU_LOG("\nERROR  -->  SCH : Failure in updateDedLcInfo");
428          return RFAILED;
429       }
430       SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
431       SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
432
433    }/* End of outer for loop */
434    return ROK;
435 }
436
437 /*******************************************************************
438  *
439  * @brief Function to fill SchUeCb From UeReconfig Req
440  *
441  * @details
442  *
443  *    Function : fillSchUeCbFrmRecfgReq
444  *
445  *    Functionality: Function to fill SchUeCb
446  *
447  * @params[in] Scheduler instance,
448  *             SchUeCb pointer,
449  *             SchUeCfg pointer
450  * @return ROK/RFAILED
451  *
452  * ****************************************************************/
453
454 uint8_t fillSchUeCbFrmRecfgReq(Inst inst, SchUeCb *ueCb, SchUeRecfgReq *ueRecfg)
455 {
456    uint8_t   lcIdx, ueLcIdx, idx;
457    uint8_t   freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
458    SchPdschCfgCmn pdschCfg;
459    SchPucchDlDataToUlAck *dlDataToUlAck;
460    uint8_t retDL = ROK, retUL = ROK;
461    bool isLcIdValid = FALSE;
462
463
464    ueCb->ueCfg.cellId = ueRecfg->cellId;
465    ueCb->ueCfg.ueId = ueRecfg->ueId;
466    ueCb->ueCfg.crnti = ueRecfg->crnti;
467    ueCb->ueCfg.dataTransmissionAction = ueRecfg->dataTransmissionInfo;
468    if(ueRecfg->macCellGrpRecfgPres == true)
469    {
470       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueRecfg->macCellGrpRecfg, sizeof(SchMacCellGrpCfg)); 
471       ueCb->ueCfg.macCellGrpCfgPres = true;
472 #ifdef NR_DRX
473       if(ueRecfg->macCellGrpRecfg.drxCfgPresent == true)
474       {
475          if(ueCb->ueDrxInfoPres == false)
476          {
477             ueCb->ueDrxInfoPres = true;
478             /* intialize the drxUeCb */
479             schInitDrxUeCb(ueCb);
480
481             /* intialize the Dl drxHarqCb */
482             for(idx =0; idx<ueCb->dlHqEnt.numHqPrcs; idx++)
483             {
484                schInitDrxHarqCb(&ueCb->dlHqEnt.procs[idx].dlDrxHarqCb);
485             }
486             /* intialize the Ul drxHarqCb */
487             for(idx =0; idx<ueCb->ulHqEnt.numHqPrcs; idx++)
488             {
489                schInitDrxHarqCb(&ueCb->ulHqEnt.procs[idx].ulDrxHarqCb);
490             }
491             /* convert all the drx configuration recived in ms/subms into number of slots and store into the drxUeCb */
492             schFillDrxUeCb(ueCb->cellCb->numerology, ueRecfg->macCellGrpRecfg.drxCfg, &ueCb->drxUeCb);
493             /* Calculate the onduration timer and short cycle timer (if shortcycle configuration is present) as soon as we 
494              * recived ueCfg request */
495             schAddUeInOndurationList(ueCb->cellCb, ueCb, 0);
496
497          }
498          else
499          {
500             /* convert all the drx configuration recived in ms/subms into number
501              * of slots and store into the drxUeCb */
502             schFillDrxUeCb(ueCb->cellCb->numerology, ueRecfg->macCellGrpRecfg.drxCfg, &ueCb->drxUeCb);
503
504             /* Recalculate/Restart timer based on their presence */
505             schDrxUeReCfgTimer(ueCb->cellCb, ueCb);
506          }
507       }
508 #endif
509    }
510
511 #ifdef NR_DRX
512    if(ueRecfg->drxConfigIndicatorRelease == true)
513    {
514       if(ueCb->ueDrxInfoPres == true)
515       {
516          schDeleteUeDrxInfo(ueCb->cellCb, ueCb);
517          ueCb->ueDrxInfoPres = false;
518       }
519    }
520 #endif
521
522    if(ueRecfg->phyCellGrpRecfgPres == true)
523    {
524       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueRecfg->phyCellGrpRecfg, sizeof(SchPhyCellGrpCfg));
525       ueCb->ueCfg.phyCellGrpCfgPres = true;
526    }
527
528    if(ueRecfg->spCellRecfgPres == true)
529    {
530       if(ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfgPres == true)
531       {
532          if(ueCb->ueCfg.spCellCfgPres && ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfgPres == true)
533          {
534             for(idx = 0; idx < ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc; idx++)
535             {
536                if(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0 && ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0)
537                {
538                   SCH_FREE(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0, sizeof(uint8_t));  
539                }
540             }
541          }
542       }
543       memcpy(&ueCb->ueCfg.spCellCfg , &ueRecfg->spCellRecfg, sizeof(SchSpCellRecfg));
544
545       covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
546             freqDomainResource);
547       memset(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
548       memcpy(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
549
550       ueCb->ueCfg.spCellCfgPres = true;
551       dlDataToUlAck = ueRecfg->spCellRecfg.servCellRecfg.initUlBwp.pucchCfg.dlDataToUlAck;
552       if(ueCb->cellCb)
553       {
554          if(dlDataToUlAck)
555          {
556             BuildK0K1Table(ueCb->cellCb, &ueCb->k0K1InfoTbl, false, pdschCfg,\
557                   ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
558                   dlDataToUlAck->dlDataToUlAckList);
559             ueCb->k0K1TblPrsnt = true;
560             BuildK2InfoTable(ueCb->cellCb, ueRecfg->spCellRecfg.servCellRecfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
561                   ueRecfg->spCellRecfg.servCellRecfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
562                   NULLP, &ueCb->k2InfoTbl);
563             ueCb->k2TblPrsnt = true;
564          }
565       }
566    }
567
568    if(ueRecfg->ambrRecfg)
569    {
570       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
571       ueCb->ueCfg.ambrCfg =  ueRecfg->ambrRecfg;
572    }
573    memcpy(&ueCb->ueCfg.dlModInfo,  &ueRecfg->dlModInfo , sizeof(SchModulationInfo));
574    memcpy(&ueCb->ueCfg.ulModInfo,  &ueRecfg->ulModInfo , sizeof(SchModulationInfo));
575    //Updating Num of LC to ADD SchUlCb and SchDlCb DB in SchUeCb
576    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToAdd; lcIdx++)
577    {
578       isLcIdValid = FALSE; /*Re-Initializing*/
579
580       ueLcIdx = ueRecfg->schLcCfgAdd[lcIdx].lcId;
581       CHECK_LCID(ueLcIdx, isLcIdValid);
582       if(isLcIdValid == FALSE)
583       {
584          DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
585          continue;
586       }
587       fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueRecfg->schLcCfgAdd[lcIdx]);
588       fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueRecfg->schLcCfgAdd[lcIdx]);
589
590       /*Checking whether this LC belong to Dedicated S-NSSAI 
591        * and Create the Dedicated LC List & Update the Reserve PRB number*/
592       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
593       {
594          retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
595                &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
596       }
597       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
598       {
599          retUL =  updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
600                &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
601       }
602
603       if(retUL == RFAILED  || retDL == RFAILED)/*FATAL error*/
604       {
605          DU_LOG("\nERROR  -->  SCH : Failure in updateDedLcInfo");
606          return RFAILED;
607       }
608       SCH_FREE(ueRecfg->schLcCfgAdd[lcIdx].drbQos, sizeof(SchDrbQosInfo));
609       SCH_FREE(ueRecfg->schLcCfgAdd[lcIdx].snssai, sizeof(Snssai));
610    }
611    //Updating Num of LC to DEL SchUlCb and SchDlCb DB in SchUeCb
612    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToDel; lcIdx++)
613    {
614       ueLcIdx = ueRecfg->lcIdToDel[lcIdx];
615
616       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueRecfg->lcIdToDel[lcIdx])
617       {
618          /*Delete the LC node from the DL LC List*/
619          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
620          {
621             /*Remove from HARQ Transmission or retransmission*/
622          }
623          else
624          {
625          }
626          SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
627          memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
628       }
629       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueRecfg->lcIdToDel[lcIdx])
630       {
631          /*Delete the LC node from the UL LC List*/
632          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
633          {
634             /*Remove from HARQ Transmission or retransmission*/
635          }
636          else/*Default LC list*/
637          {
638
639          }
640          SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
641          memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
642       }
643    }
644    //Updating Num of LC to DEL SchUlCb and SchDlCb DB in SchUeCb
645    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToMod; lcIdx++)
646    {
647       ueLcIdx = ueRecfg->schLcCfgMod[lcIdx].lcId;
648
649       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueRecfg->schLcCfgMod[lcIdx].lcId)
650       {
651          fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueRecfg->schLcCfgMod[lcIdx]);
652          /*Updating the RRM reserved pool PRB count*/
653          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
654          {
655             retUL =  updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
656                   &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
657          }
658          if(retUL == RFAILED)
659          {
660             DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
661             return RFAILED;
662          }
663       }/*End of UL LC Ctxt*/
664
665       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueRecfg->schLcCfgMod[lcIdx].lcId)
666       {
667          fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueRecfg->schLcCfgMod[lcIdx]);
668          /*Updating the RRM policy*/
669          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
670          {
671             retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].rsvdDedicatedPRB), \
672                   &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
673          }
674          if(retDL == RFAILED)
675          {
676             DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
677             return RFAILED;
678          }
679       }/*End of DL LC ctxt*/
680
681       SCH_FREE(ueRecfg->schLcCfgMod[lcIdx].drbQos, sizeof(SchDrbQosInfo));
682       SCH_FREE(ueRecfg->schLcCfgMod[lcIdx].snssai, sizeof(Snssai));
683    }/* End of outer for loop */
684    return ROK;
685 }
686
687 /*******************************************************************
688  *
689  * @brief Function to get SCH Cell Cb
690  *
691  * @details
692  *
693  *    Function : getSchCellCb
694  *
695  *    Functionality: Function to get SCH Cell Cb
696  *
697  * @params[in] event, SchUeCfg pointer 
698  * @return schUeCb pointer  - success
699  *         NULLP - failure
700  *
701  * ****************************************************************/
702
703 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, uint16_t cellId)
704 {
705    uint8_t      idx = 0;
706    SchCellCb    *cellCb = NULLP;
707
708    /* Search of cell cb */
709    for(idx = 0; idx < MAX_NUM_CELL; idx++)
710    {
711       cellCb = schCb[inst].cells[idx];
712       if((cellCb != NULLP) && (cellCb->cellId == cellId))
713          break;
714    }
715    if((idx == MAX_NUM_CELL) || (cellCb == NULLP))
716    {
717       DU_LOG("\nERROR  -->  SCH : Ue create request failed. Invalid cell id %d", cellId);
718       return NULLP;
719    }
720
721    /* Check if max number of UE configured */
722    if(cellCb->numActvUe > MAX_NUM_UE)
723    {
724       DU_LOG("\nERROR  -->  SCH :  Max number of UE [%d] already configured", MAX_NUM_UE);
725       return NULLP;
726    }
727    return cellCb;
728 }
729
730
731 /*******************************************************************
732  *
733  * @brief Function to Add Ue Config Request from MAC
734  *
735  * @details
736  *
737  *    Function : SchAddUeConfigReq
738  *
739  *    Functionality: Function to Add Ue config request from MAC
740  *
741  * @params[in] 
742  * @return ROK     - success
743  *         RFAILED - failure
744  *
745  * ****************************************************************/
746 uint8_t SchAddUeConfigReq(Pst *pst, SchUeCfgReq *ueCfg)
747 {
748    uint8_t      lcIdx = 0, ret = ROK, idx = 0;
749    SchCellCb    *cellCb = NULLP;
750    SchUeCb      *ueCb = NULLP;
751    SchUeCfgRsp  cfgRsp;
752    Inst         inst = pst->dstInst - SCH_INST_START;
753    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
754   
755    if(!ueCfg)
756    {
757       DU_LOG("\nERROR  -->  SCH :  Adding UE Config Request failed at SchAddUeConfigReq()");
758       return RFAILED;
759    }
760    DU_LOG("\nDEBUG  -->  SCH :  Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
761    cellCb = getSchCellCb(pst->event, inst, ueCfg->cellId);
762
763    if(cellCb == NULLP)
764    {
765       SchSendUeCfgRspToMac(ueCfg, inst, RSP_NOK, &cfgRsp);
766       return RFAILED; 
767    }
768    /* Search if UE already configured */
769    ueCb = &cellCb->ueCb[ueCfg->ueId - 1];
770
771    if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
772    {
773       DU_LOG("\nDEBUG  -->  SCH : CRNTI %d already configured ", ueCfg->crnti);
774       SchSendUeCfgRspToMac(ueCfg, inst, RSP_OK, &cfgRsp);
775       return ROK;
776    }
777
778    /* Fill received Ue Configuration in UeCb */
779    memset(ueCb, 0, sizeof(SchUeCb));
780
781    ueCb->ueId = ueCfg->ueId;
782    ueCb->crnti = ueCfg->crnti;
783    ueCb->cellCb = cellCb;
784    schUlHqEntInit(cellCb, &cellCb->ueCb[ueCfg->ueId-1]);
785    schDlHqEntInit(cellCb, &cellCb->ueCb[ueCfg->ueId-1]);
786    SCH_ALLOC(ueCb->hqDlmap, sizeof(SchHqDlMap*)*(ueCb->cellCb->numSlots));
787    SCH_ALLOC(ueCb->hqUlmap, sizeof(SchHqUlMap*)*(ueCb->cellCb->numSlots));
788
789    if ( (ueCb->hqDlmap == NULLP) || (ueCb->hqUlmap == NULLP) )
790    {
791       DU_LOG("\nINFO  -->  SCH : Memory Allocation Failed");
792       return RFAILED;
793    }
794    for (idx = 0; idx<ueCb->cellCb->numSlots; idx++)
795    {
796       SCH_ALLOC(ueCb->hqDlmap[idx], sizeof(SchHqDlMap));
797       SCH_ALLOC(ueCb->hqUlmap[idx], sizeof(SchHqUlMap));
798       
799       if ( (ueCb->hqDlmap[idx] == NULLP) || (ueCb->hqUlmap[idx] == NULLP) )
800       {
801          DU_LOG("\nINFO  -->  SCH : Memory Allocation Failed");
802          return RFAILED;
803       }
804       cmLListInit(&ueCb->hqDlmap[idx]->hqList);
805       cmLListInit(&ueCb->hqUlmap[idx]->hqList);
806    }
807    ret = fillSchUeCbFrmCfgReq(inst, ueCb, ueCfg);
808
809    if(ret == ROK)
810    {
811       /* If UE has initiated RACH and then UE context is created, it means UE is
812        * active now.
813        * Else if UE context is created before RACH, this means that UE is being
814        * handed-in from source DU */
815       if(cellCb->raCb[ueCb->ueId-1].tcrnti == ueCb->crnti)
816       {
817          cellCb->numActvUe++;
818          SET_ONE_BIT(ueCb->ueId, cellCb->actvUeBitMap);
819          ueCb->state = SCH_UE_STATE_ACTIVE;
820       }
821       else
822       {
823          ueCb->state = SCH_UE_HANDIN_IN_PROGRESS;
824       }
825
826       ueCb->srRcvd = false;
827       ueCb->bsrRcvd = false;
828       for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
829          ueCb->bsrInfo[lcIdx].dataVol = 0;
830
831       SchSendUeCfgRspToMac(ueCfg, inst, RSP_OK, &cfgRsp);
832    }
833
834    cellCb->api->SchAddUeConfigReq(ueCb);
835    return ret;
836 }
837
838 /*******************************************************************
839 *
840 * @brief Fills PUSCH UL allocation
841 *
842 * @details
843 *
844 *    Function : schFillPuschAlloc
845 *
846 *    Functionality: fills PUSCH info
847 *
848 * @params[in] SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize
849 * @params[in] uint8_t startSymb, uint8_t symbLen, uint16_t startPrb
850 * @params[in] bool isRetx, SchUlHqProcCb *hq
851 * @return ROK     - success
852 *         RFAILED - failure
853 *
854 * ****************************************************************/
855 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize, 
856                           uint8_t startSymb, uint8_t symbLen, uint16_t startPrb, bool isRetx, SchUlHqProcCb *hqP)
857 {
858   uint8_t  numRb          = 0;
859   SchCellCb *cellCb       = NULLP;
860   SchUlSlotInfo *schUlSlotInfo = NULLP;
861   SchPuschInfo puschInfo;
862   
863   if(ueCb == NULLP)
864   {
865     DU_LOG("\nERROR --> SCH: UE CB is empty");
866     return RFAILED;
867   }
868
869   cellCb = ueCb->cellCb;
870   if(cellCb == NULLP)
871   {
872     DU_LOG("\nERROR --> SCH: CELL CB is empty");
873     return RFAILED;
874   }
875
876   tbSize  +=  UL_TX_BUFFER_SIZE; /*  2 bytes header + some buffer */
877   numRb   = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
878   allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startPrb, numRb);
879
880    if (isRetx == FALSE)
881    {
882       puschInfo.harqProcId                       = SCH_HARQ_PROC_ID;
883       puschInfo.fdAlloc.resAllocType             = SCH_ALLOC_TYPE_1;
884       puschInfo.fdAlloc.resAlloc.type1.startPrb  = startPrb;
885       puschInfo.fdAlloc.resAlloc.type1.numPrb    = numRb;
886       puschInfo.tdAlloc.startSymb = startSymb;
887       puschInfo.tdAlloc.numSymb   = symbLen;
888       puschInfo.tbInfo.qamOrder   = ueCb->ueCfg.ulModInfo.modOrder;
889       puschInfo.tbInfo.mcs        = ueCb->ueCfg.ulModInfo.mcsIndex;
890       puschInfo.tbInfo.mcsTable   = ueCb->ueCfg.ulModInfo.mcsTable;
891       puschInfo.tbInfo.ndi        = 1; /* new transmission */
892       puschInfo.tbInfo.rv         = 0;
893       puschInfo.tbInfo.tbSize     = tbSize;
894 #ifdef INTEL_FAPI      
895       puschInfo.dmrsMappingType   = DMRS_MAP_TYPE_A;  /* Setting Type-A */
896       puschInfo.nrOfDmrsSymbols   = NUM_DMRS_SYMBOLS;
897       puschInfo.dmrsAddPos        = DMRS_ADDITIONAL_POS;
898 #endif      
899       hqP->puschResType = puschInfo.fdAlloc.resAllocType;
900       hqP->puschStartPrb = puschInfo.fdAlloc.resAlloc.type1.startPrb;
901       hqP->puschNumPrb = puschInfo.fdAlloc.resAlloc.type1.numPrb;
902       hqP->strtSymbl = puschInfo.tdAlloc.startSymb;
903       hqP->numSymbl = puschInfo.tdAlloc.numSymb;
904       hqP->tbInfo.qamOrder = puschInfo.tbInfo.qamOrder;
905       hqP->tbInfo.iMcs = puschInfo.tbInfo.mcs;
906       hqP->tbInfo.mcsTable = puschInfo.tbInfo.mcsTable;
907       hqP->tbInfo.ndi = puschInfo.tbInfo.ndi;
908       hqP->tbInfo.rv = puschInfo.tbInfo.rv;
909       hqP->tbInfo.rvIdx = 0;
910       hqP->tbInfo.tbSzReq = puschInfo.tbInfo.tbSize;
911 #ifdef INTEL_FAPI      
912       hqP->dmrsMappingType = puschInfo.dmrsMappingType;
913       hqP->nrOfDmrsSymbols = puschInfo.nrOfDmrsSymbols;
914       hqP->dmrsAddPos = puschInfo.dmrsAddPos;
915 #endif
916    }
917    else
918    {
919       puschInfo.harqProcId                       = hqP->procId;
920       puschInfo.fdAlloc.resAllocType             = hqP->puschResType;
921       puschInfo.fdAlloc.resAlloc.type1.startPrb  = hqP->puschStartPrb;
922       puschInfo.fdAlloc.resAlloc.type1.numPrb    = hqP->puschNumPrb;
923       puschInfo.tdAlloc.startSymb = hqP->strtSymbl;
924       puschInfo.tdAlloc.numSymb   = hqP->numSymbl;
925       puschInfo.tbInfo.qamOrder   = hqP->tbInfo.qamOrder;
926       puschInfo.tbInfo.mcs        = hqP->tbInfo.iMcs;
927       puschInfo.tbInfo.mcsTable   = hqP->tbInfo.mcsTable;
928       puschInfo.tbInfo.ndi        = hqP->tbInfo.ndi; /* retransmission */
929       hqP->tbInfo.rvIdx = (hqP->tbInfo.rvIdx +1) & 0x3;
930       puschInfo.tbInfo.rv         = schCmnDlRvTbl[hqP->tbInfo.rvIdx];
931       puschInfo.tbInfo.tbSize     = hqP->tbInfo.tbSzReq;
932 #ifdef INTEL_FAPI      
933       puschInfo.dmrsMappingType   = hqP->dmrsMappingType;  /* Setting Type-A */
934       puschInfo.nrOfDmrsSymbols   = hqP->nrOfDmrsSymbols;
935       puschInfo.dmrsAddPos        = hqP->dmrsAddPos;
936 #endif 
937   }
938   schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
939   SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
940   if(!schUlSlotInfo->schPuschInfo)
941   {
942      DU_LOG("\nERROR  -->  SCH: Memory allocation failed in schAllocMsg3Pusch");
943      return RFAILED;
944   }
945   memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
946
947   return ROK;
948 }
949 /*******************************************************************
950 *
951 * @brief Fills UL DCI information for MSG3 retransmission
952 *
953 * @details
954 *
955 *    Function : schFillUlDciForMsg3Retx
956 *
957 *    Functionality: fills UL DCI information for MSG3 retransmission
958 *
959 * @params[in]
960 * @return ROK     - success
961 *         RFAILED - failure
962 *
963 * ****************************************************************/
964 uint8_t schFillUlDciForMsg3Retx(SchRaCb *raCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
965 {
966    SchCellCb         *cellCb  = raCb->cell;
967    
968    dciInfo->crnti  = raCb->tcrnti;
969    SchUlHqProcCb *msg3HqProc = &raCb->msg3HqProc;
970    if (msg3HqProc == NULLP)
971    {
972       return RFAILED;
973    }
974
975    /* fill bwp cfg */
976    dciInfo->bwpCfg.subcarrierSpacing  = cellCb->sib1SchCfg.bwp.subcarrierSpacing;
977    dciInfo->bwpCfg.cyclicPrefix       = cellCb->sib1SchCfg.bwp.cyclicPrefix;
978    dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.startPrb;
979    dciInfo->bwpCfg.freqAlloc.numPrb   = cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.numPrb; 
980
981    /*fill coreset cfg */
982    //Considering number of RBs in coreset1 is same as coreset0
983    dciInfo->coresetCfg.coreSetSize      = coresetIdxTable[0][1];
984    //Considering coreset1 also starts from same symbol as coreset0
985    dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
986    dciInfo->coresetCfg.durationSymbols  = coresetIdxTable[0][2];
987    memcpy(dciInfo->coresetCfg.freqDomainResource, cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
988    
989    dciInfo->coresetCfg.cceRegMappingType   = 1; /* coreset0 is always interleaved */
990    dciInfo->coresetCfg.regBundleSize       = 6; /* spec-38.211 sec 7.3.2.2 */
991    dciInfo->coresetCfg.interleaverSize     = 2; /* spec-38.211 sec 7.3.2.2 */
992    dciInfo->coresetCfg.coreSetType         = 0;
993    dciInfo->coresetCfg.coreSetSize         = coresetIdxTable[0][1];
994    dciInfo->coresetCfg.shiftIndex          = cellCb->cellCfg.phyCellId;
995    dciInfo->coresetCfg.precoderGranularity = 0;
996    dciInfo->coresetCfg.cceIndex            = 0; /* 0-3 for UL and 4-7 for DL */
997    dciInfo->coresetCfg.aggregationLevel    = 4; /* same as for sib1 */
998    
999    dciInfo->dciFormatInfo.formatType = FORMAT0_0;
1000    msg3HqProc->tbInfo.rvIdx++;
1001    msg3HqProc->tbInfo.rv = schCmnDlRvTbl[msg3HqProc->tbInfo.rvIdx & 0x03];
1002    /* fill UL grant */
1003    dciInfo->dciFormatInfo.format.format0_0.resourceAllocType                  = msg3HqProc->puschResType;
1004    dciInfo->dciFormatInfo.format.format0_0.freqAlloc.resAllocType             = msg3HqProc->puschResType;
1005    dciInfo->dciFormatInfo.format.format0_0.freqAlloc.resAlloc.type1.startPrb  = msg3HqProc->puschStartPrb;
1006    dciInfo->dciFormatInfo.format.format0_0.freqAlloc.resAlloc.type1.numPrb    = msg3HqProc->puschNumPrb;
1007    dciInfo->dciFormatInfo.format.format0_0.timeAlloc.startSymb = msg3HqProc->strtSymbl;
1008    dciInfo->dciFormatInfo.format.format0_0.timeAlloc.numSymb   = msg3HqProc->numSymbl;
1009    dciInfo->dciFormatInfo.format.format0_0.rowIndex            = 0; /* row Index */
1010    dciInfo->dciFormatInfo.format.format0_0.mcs                 = msg3HqProc->tbInfo.iMcs;
1011    dciInfo->dciFormatInfo.format.format0_0.harqProcId          = msg3HqProc->procId;
1012    dciInfo->dciFormatInfo.format.format0_0.freqHopFlag         = FALSE; /* disabled */
1013    dciInfo->dciFormatInfo.format.format0_0.ndi                 = msg3HqProc->tbInfo.ndi; /* new transmission */
1014    dciInfo->dciFormatInfo.format.format0_0.rvIndex             = msg3HqProc->tbInfo.rv;
1015    dciInfo->dciFormatInfo.format.format0_0.tpcCmd              = 0; //Sphoorthi TODO: check
1016    dciInfo->dciFormatInfo.format.format0_0.sulIndicator             = FALSE; /* SUL not configured */
1017    
1018    /* Fill DCI Structure */
1019    dciInfo->dciInfo.rnti                              = raCb->tcrnti;
1020    dciInfo->dciInfo.scramblingId                      = cellCb->cellCfg.phyCellId;
1021    dciInfo->dciInfo.scramblingRnti                    = 0;
1022    dciInfo->dciInfo.cceIndex                          = 0; /* 0-3 for UL and 4-7 for DL */
1023    dciInfo->dciInfo.aggregLevel                       = 4;
1024    dciInfo->dciInfo.beamPdcchInfo.numPrgs             = 1;
1025    dciInfo->dciInfo.beamPdcchInfo.prgSize             = 1;
1026    dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces     = 0;
1027    dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx        = 0;
1028    dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0]   = 0;
1029    dciInfo->dciInfo.txPdcchPower.beta_pdcch_1_0       = 0;
1030    dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
1031    memset(&dciInfo->dciInfo.pdschCfg, 0, sizeof(PdschCfg));
1032    msg3HqProc->tbInfo.txCntr++;
1033
1034   puschInfo->harqProcId                       = msg3HqProc->procId;
1035   puschInfo->fdAlloc.resAllocType             = msg3HqProc->puschResType;
1036   puschInfo->fdAlloc.resAlloc.type1.startPrb  = msg3HqProc->puschStartPrb;
1037   puschInfo->fdAlloc.resAlloc.type1.numPrb    = msg3HqProc->puschNumPrb;
1038   puschInfo->tdAlloc.startSymb = msg3HqProc->strtSymbl;
1039   puschInfo->tdAlloc.numSymb   = msg3HqProc->numSymbl;
1040   puschInfo->tbInfo.qamOrder   = msg3HqProc->tbInfo.qamOrder;
1041   puschInfo->tbInfo.mcs        = msg3HqProc->tbInfo.iMcs;
1042   puschInfo->tbInfo.mcsTable   = msg3HqProc->tbInfo.mcsTable;
1043   puschInfo->tbInfo.ndi        = msg3HqProc->tbInfo.ndi; /* retransmission */
1044   puschInfo->tbInfo.rv         = msg3HqProc->tbInfo.rvIdx;
1045   puschInfo->tbInfo.tbSize     = msg3HqProc->tbInfo.tbSzReq;
1046 #ifdef INTEL_FAPI
1047   puschInfo->dmrsMappingType   = msg3HqProc->dmrsMappingType;  /* Setting Type-A */
1048   puschInfo->nrOfDmrsSymbols   = msg3HqProc->nrOfDmrsSymbols;
1049   puschInfo->dmrsAddPos        = msg3HqProc->dmrsAddPos;
1050 #endif
1051    return ROK;
1052 }
1053
1054 /*******************************************************************
1055  *
1056  * @brief Fills DCI for UL grant
1057  *
1058  * @details
1059  *
1060  *    Function : schFillUlDci
1061  *
1062  *    Functionality: fills DCI for UL grant in response to BSR
1063  *
1064  * @params[in] SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo,
1065  * @params[in] bool isRetx, SchUlHqProcCb *hqP 
1066  * @return ROK     - success
1067  *         RFAILED - failure
1068  *
1069  * ****************************************************************/
1070 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo, bool isRetx, SchUlHqProcCb *hqP)
1071 {
1072    SchCellCb         *cellCb  = ueCb->cellCb;
1073    SchControlRsrcSet coreset1 ;
1074   
1075    memset(&coreset1, 0, sizeof(SchControlRsrcSet));
1076    if(ueCb->ueCfg.spCellCfgPres == true)
1077    {
1078      coreset1 = ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
1079    }
1080    
1081    dciInfo->crnti  = ueCb->crnti;
1082
1083    /* fill bwp cfg */
1084    dciInfo->bwpCfg.subcarrierSpacing  = cellCb->sib1SchCfg.bwp.subcarrierSpacing;
1085    dciInfo->bwpCfg.cyclicPrefix       = cellCb->sib1SchCfg.bwp.cyclicPrefix;
1086    dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.startPrb;
1087    dciInfo->bwpCfg.freqAlloc.numPrb   = cellCb->cellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.numPrb; 
1088
1089    /*fill coreset cfg */
1090    //Considering number of RBs in coreset1 is same as coreset0
1091    dciInfo->coresetCfg.coreSetSize      = coresetIdxTable[0][1];
1092    //Considering coreset1 also starts from same symbol as coreset0
1093    dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
1094    dciInfo->coresetCfg.durationSymbols  = coreset1.duration;
1095    memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
1096    
1097    dciInfo->coresetCfg.cceRegMappingType   = coreset1.cceRegMappingType; /* non-interleaved */
1098    dciInfo->coresetCfg.regBundleSize       = 6; /* must be 6 for non-interleaved */
1099    dciInfo->coresetCfg.interleaverSize     = 0; /* NA for non-interleaved */
1100    dciInfo->coresetCfg.coreSetType         = 1; /* non PBCH coreset */
1101    dciInfo->coresetCfg.shiftIndex          = cellCb->cellCfg.phyCellId;
1102    dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
1103    dciInfo->coresetCfg.cceIndex            = 0; /* 0-3 for UL and 4-7 for DL */
1104    dciInfo->coresetCfg.aggregationLevel    = 4; /* same as for sib1 */
1105    
1106    dciInfo->dciFormatInfo.formatType = FORMAT0_0;
1107    
1108    /* fill UL grant */
1109    dciInfo->dciFormatInfo.format.format0_0.resourceAllocType   = puschInfo->fdAlloc.resAllocType;
1110    dciInfo->dciFormatInfo.format.format0_0.freqAlloc.resAllocType = puschInfo->fdAlloc.resAllocType;
1111    dciInfo->dciFormatInfo.format.format0_0.freqAlloc.resAlloc.type1.startPrb  = \
1112    puschInfo->fdAlloc.resAlloc.type1.startPrb;
1113    dciInfo->dciFormatInfo.format.format0_0.freqAlloc.resAlloc.type1.numPrb    = \
1114    puschInfo->fdAlloc.resAlloc.type1.numPrb;
1115    dciInfo->dciFormatInfo.format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
1116    dciInfo->dciFormatInfo.format.format0_0.timeAlloc.numSymb   = puschInfo->tdAlloc.numSymb;
1117    dciInfo->dciFormatInfo.format.format0_0.rowIndex            = 0; /* row Index */
1118    dciInfo->dciFormatInfo.format.format0_0.mcs                 = puschInfo->tbInfo.mcs;
1119    dciInfo->dciFormatInfo.format.format0_0.harqProcId          = puschInfo->harqProcId;
1120    dciInfo->dciFormatInfo.format.format0_0.freqHopFlag         = FALSE; /* disabled */
1121    dciInfo->dciFormatInfo.format.format0_0.ndi                 = puschInfo->tbInfo.ndi; /* new transmission */
1122    dciInfo->dciFormatInfo.format.format0_0.rvIndex             = puschInfo->tbInfo.rv;
1123    dciInfo->dciFormatInfo.format.format0_0.tpcCmd              = 0; //Sphoorthi TODO: check
1124    dciInfo->dciFormatInfo.format.format0_0.sulIndicator             = FALSE; /* SUL not configured */
1125    
1126    /* Fill DCI Structure */
1127    dciInfo->dciInfo.rnti                              = ueCb->crnti;
1128    dciInfo->dciInfo.scramblingId                      = cellCb->cellCfg.phyCellId;
1129    dciInfo->dciInfo.scramblingRnti                    = 0;
1130    dciInfo->dciInfo.cceIndex                          = 0; /* 0-3 for UL and 4-7 for DL */
1131    dciInfo->dciInfo.aggregLevel                       = 4;
1132    dciInfo->dciInfo.beamPdcchInfo.numPrgs             = 1;
1133    dciInfo->dciInfo.beamPdcchInfo.prgSize             = 1;
1134    dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces     = 0;
1135    dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx        = 0;
1136    dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0]   = 0;
1137    dciInfo->dciInfo.txPdcchPower.beta_pdcch_1_0       = 0;
1138    dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
1139    memset(&dciInfo->dciInfo.pdschCfg, 0, sizeof(PdschCfg));
1140
1141    return ROK;
1142 }
1143
1144 /*******************************************************************
1145  *
1146  * @brief Function to Modify Ue Config request from MAC
1147  *
1148  * @details
1149  *
1150  *    Function : SchModUeConfigReq
1151  *
1152  *    Functionality: Function to modify Ue Config request from MAC
1153  *
1154  * @params[in] 
1155  * @return ROK     - success
1156  *         RFAILED - failure
1157  *
1158  * ****************************************************************/
1159 uint8_t SchModUeConfigReq(Pst *pst, SchUeRecfgReq *ueRecfg)
1160 {
1161    uint8_t ueId, lcIdx, ret = ROK;
1162    SchCellCb    *cellCb = NULLP;
1163    SchUeCb      *ueCb = NULLP;
1164    SchUeRecfgRsp  recfgRsp;
1165    Inst         inst = pst->dstInst - SCH_INST_START;
1166    memset(&recfgRsp, 0, sizeof(SchUeRecfgRsp));
1167   
1168    if(!ueRecfg)
1169    {
1170       DU_LOG("\nERROR  -->  SCH : Modifying Ue Config request failed at SchModUeConfigReq()");
1171       return RFAILED;
1172    }
1173    DU_LOG("\nDEBUG  -->  SCH : Modifying Ue Config Request for CRNTI[%d]", ueRecfg->crnti);
1174    cellCb = getSchCellCb(pst->event, inst, ueRecfg->cellId);
1175
1176    if(cellCb == NULLP)
1177    {
1178       SchSendUeRecfgRspToMac(ueRecfg, inst, RSP_NOK, &recfgRsp);
1179       return RFAILED;
1180    }
1181
1182    /* Search if UE already configured */
1183    GET_UE_ID(ueRecfg->crnti, ueId);
1184    ueCb = &cellCb->ueCb[ueId -1];
1185    
1186    if(!ueCb)
1187    {
1188       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at SchModUeConfigReq() ");
1189       SchSendUeRecfgRspToMac(ueRecfg, inst, RSP_NOK, &recfgRsp);
1190       return RFAILED;
1191    }
1192    if((ueCb->crnti == ueRecfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
1193    {
1194       /* Found the UeCb to Reconfig */
1195       ret = fillSchUeCbFrmRecfgReq(inst, ueCb, ueRecfg);
1196       if(ret == ROK)
1197       {
1198          ueCb->cellCb = cellCb;
1199          ueCb->srRcvd = false;
1200          ueCb->bsrRcvd = false;
1201          for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
1202             ueCb->bsrInfo[lcIdx].dataVol = 0;
1203
1204          SchSendUeRecfgRspToMac(ueRecfg, inst, RSP_OK, &recfgRsp);
1205       }
1206    }
1207    return ret;
1208 }
1209
1210
1211 /*******************************************************************
1212 *
1213 * @brief Function to delete Sch Pucch ResrcCfg
1214 *
1215 * @details
1216 *
1217 *    Function : deleteSchPucchResrcCfg 
1218 *
1219 *    Functionality: Function to delete Sch Pucch ResrcCfg
1220 *
1221 * @params[in] SchPucchResrcCfg *resrc
1222 * @return void 
1223 *
1224 * ****************************************************************/
1225
1226 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
1227 {
1228    uint8_t rsrcIdx=0;
1229    for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
1230    {
1231       switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
1232       {
1233          case PUCCH_FORMAT_0:
1234          {
1235             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
1236             sizeof(SchPucchFormat0));
1237             break;
1238          }
1239          case PUCCH_FORMAT_1:
1240          {
1241             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
1242             sizeof(SchPucchFormat1));
1243             break;
1244          }
1245          case PUCCH_FORMAT_2:
1246          {
1247             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
1248             sizeof(SchPucchFormat2_3));
1249             break;
1250          }
1251          case PUCCH_FORMAT_3:
1252          {
1253             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
1254             sizeof(SchPucchFormat2_3));
1255             break;
1256          }
1257          case PUCCH_FORMAT_4:
1258          {
1259             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
1260             sizeof(SchPucchFormat4));
1261             break;
1262          }
1263       }
1264    }
1265 }
1266
1267 /*******************************************************************
1268 *
1269 * @brief Function to delete SCH Pdsch ServCellCfg
1270 *
1271 * @details
1272 *
1273 *    Function : deleteSchPdschServCellCfg
1274 *
1275 *    Functionality: Function to delete SCH Pdsch ServCellCfg
1276 *
1277 * @params[in] SchPdschServCellCfg *pdschServCellCfg
1278 * @return void 
1279 *
1280 * ****************************************************************/
1281
1282 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
1283 {
1284    SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
1285    SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
1286    SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
1287    SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
1288 }
1289
1290 /*******************************************************************
1291 *
1292 * @brief Function to  delete SCH UeCb
1293 *
1294 * @details
1295 *
1296 *    Function : deleteSchUeCb 
1297 *
1298 *    Functionality: Function to delete SCH UeCb
1299 *
1300 * @params[in]
1301 * @return ROK     - success
1302 *         RFAILED - failure
1303 *
1304 * ****************************************************************/
1305 void deleteSchUeCb(SchUeCb *ueCb) 
1306 {
1307    uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0, idx =0;
1308    SchPucchCfg *pucchCfg = NULLP;
1309    SchPdschConfig *pdschCfg = NULLP;
1310
1311    if(ueCb)
1312    {
1313       if(ueCb->hqDlmap)
1314       {
1315          for (idx = 0; idx<ueCb->cellCb->numSlots; idx++)
1316          {
1317             if(ueCb->hqDlmap[idx])
1318             {
1319                cmLListDeleteLList(&ueCb->hqDlmap[idx]->hqList);
1320                SCH_FREE(ueCb->hqDlmap[idx], sizeof(SchHqDlMap));
1321             }
1322          }
1323          SCH_FREE(ueCb->hqDlmap, sizeof(SchHqDlMap*)*(ueCb->cellCb->numSlots));
1324       }
1325
1326       if(ueCb->hqUlmap)
1327       {
1328          for (idx = 0; idx<ueCb->cellCb->numSlots; idx++)
1329          {
1330             if(ueCb->hqUlmap[idx])
1331             {
1332                cmLListDeleteLList(&ueCb->hqUlmap[idx]->hqList);
1333                SCH_FREE(ueCb->hqUlmap[idx], sizeof(SchHqUlMap));
1334             }
1335          }
1336          SCH_FREE(ueCb->hqUlmap, sizeof(SchHqUlMap*)*(ueCb->cellCb->numSlots));
1337       }
1338
1339       schDlHqEntDelete(ueCb);
1340       schUlHqEntDelete(ueCb);
1341
1342       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
1343       if(ueCb->ueCfg.spCellCfgPres)
1344       {
1345          if(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfgPres == true)
1346          {
1347             pdschCfg = &ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg;
1348             for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
1349                SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
1350          }
1351
1352          if(ueCb->ueCfg.spCellCfg.servCellRecfg.initUlBwp.pucchCfgPres == true)
1353          {
1354             pucchCfg = &ueCb->ueCfg.spCellCfg.servCellRecfg.initUlBwp.pucchCfg;
1355             SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
1356             if(pucchCfg->resrc)
1357             {
1358                deleteSchPucchResrcCfg(pucchCfg->resrc);
1359                SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
1360             }
1361             SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
1362             SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
1363             SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
1364             SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
1365             SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
1366             SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
1367             SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));  
1368             SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
1369             SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
1370          }
1371          SCH_FREE(ueCb->ueCfg.spCellCfg.servCellRecfg.bwpInactivityTmr, sizeof(uint8_t));
1372          deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellRecfg.pdschServCellCfg);
1373       }
1374       /*Need to Free the memory allocated for S-NSSAI*/
1375       for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
1376       {
1377          SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
1378          SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
1379       }
1380 #ifdef NR_DRX
1381       if(ueCb->ueDrxInfoPres)
1382       {
1383          /* Removing all the calculated drx configuration timer list */ 
1384          schDeleteUeDrxInfo(ueCb->cellCb, ueCb);
1385          ueCb->ueDrxInfoPres = false;
1386       }
1387 #endif
1388       memset(ueCb, 0, sizeof(SchUeCb));
1389    }
1390 }
1391
1392 /*******************************************************************
1393 *
1394 * @brief Fill and send UE delete response to MAC
1395 *
1396 * @details
1397 *
1398 *    Function :  SchSendUeDeleteRspToMac
1399 *
1400 *    Functionality: Fill and send UE delete response to MAC
1401 *
1402 * @params[in] Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, 
1403 *              CauseOfResult  cause
1404 * @return ROK     - success
1405 *         RFAILED - failure
1406 *
1407 * ****************************************************************/
1408 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, CauseOfResult  cause)
1409 {
1410     Pst rspPst;
1411     SchUeDeleteRsp  delRsp;
1412     
1413     memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
1414     delRsp.cellId = ueDelete->cellId;
1415     delRsp.crnti = ueDelete->crnti;
1416     delRsp.rsp = result; 
1417     delRsp.cause = cause; 
1418
1419     /* Filling response post */
1420     memset(&rspPst, 0, sizeof(Pst));
1421     FILL_PST_SCH_TO_MAC(rspPst, inst);
1422     rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
1423     MacMessageRouter(&rspPst, (void *)&delRsp);
1424 }
1425
1426 /*******************************************************************
1427 *
1428 * @brief Function for Ue Delete request from MAC to SCH
1429 *
1430 * @details
1431 *
1432 *    Function : SchProcUeDeleteReq 
1433 *
1434 *    Functionality: Function for Ue Delete request from MAC to SCH
1435 *
1436 * @params[in] Pst *pst, SchUeDelete  *ueDelete
1437 * @return ROK     - success
1438 *         RFAILED - failure
1439 *
1440 * ****************************************************************/
1441 uint8_t SchProcUeDeleteReq(Pst *pst, SchUeDelete  *ueDelete)
1442 {
1443     uint8_t idx=0, ueId=0, ret=ROK;
1444     CauseOfResult  cause;
1445     SchCellCb *cellCb = NULLP;
1446     Inst         inst = pst->dstInst - SCH_INST_START;
1447    
1448     if(!ueDelete)
1449     {
1450        DU_LOG("\nERROR  -->  SCH : SchProcUeDeleteReq(): Ue Delete request failed");
1451        ret = RFAILED;
1452     }
1453     DU_LOG("\nDEBUG  -->  SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1454     
1455     cellCb = schCb[inst].cells[idx];
1456
1457     if(cellCb->cellId != ueDelete->cellId)
1458     {
1459        DU_LOG("\nERROR  -->  SCH : SchProcUeDeleteReq(): cell Id is not available");
1460        cause =  CELLID_INVALID;
1461     }
1462     else
1463     {
1464        GET_UE_ID(ueDelete->crnti, ueId);
1465        if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1466        {
1467           /* Remove UE from ueToBeScheduled list */
1468           cellCb->api->SchUeDeleteReq(&cellCb->ueCb[ueId-1]);
1469           deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1470           cellCb->numActvUe--;
1471           cause = SUCCESSFUL;
1472        }
1473        else
1474        {
1475           DU_LOG("\nERROR  -->  SCH : SchProcUeDeleteReq(): SchUeCb not found");
1476           cause =  UEID_INVALID;
1477        }
1478     }
1479     
1480     if(cause == SUCCESSFUL)
1481     {
1482        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, cause);
1483     }
1484     else
1485     {
1486        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, cause);
1487        ret = RFAILED;
1488     }
1489     return ret;
1490 }
1491
1492 /*******************************************************************
1493  *
1494  * @brief Function updates DL HARQ Feedback
1495  *
1496  * @details
1497  *
1498  *    Function : schUpdateHarqFdbk
1499  *
1500  *    Functionality: Function updates DL HARQ feedback
1501  *
1502  * @params[in] SchUeCb *ueCb, UE cb struct pointer
1503  * @params[in] uint8_t numHarq, number of HARQ processes in feedback 
1504  * @params[in] uint8_t *harqPayload, harq feedback payload received
1505  * @params[in] SlotTimingInfo *slotInd, slot timing information
1506  * @return void
1507  *
1508  * ****************************************************************/
1509 void schUpdateHarqFdbk(SchUeCb *ueCb, uint8_t numHarq, uint8_t *harqPayload, SlotTimingInfo *slotInd)
1510 {
1511    SchDlHqProcCb *hqP;
1512    SchHqDlMap *hqDlMap;
1513    CmLList  *node;
1514    uint8_t fdbkPos = 0;
1515
1516    hqDlMap = ueCb->hqDlmap[slotInd->slot];
1517
1518    if (ueCb->cellCb->raCb[ueCb->ueId-1].raState == SCH_RA_STATE_MSG2_HANDLE)
1519    {
1520       return;
1521    }
1522    if (ueCb->cellCb->raCb[ueCb->ueId-1].raState != SCH_RA_STATE_MSG4_PENDING)
1523    {
1524       node = hqDlMap->hqList.first;
1525       while(node)
1526       {
1527          hqP = (SchDlHqProcCb*)node->node;
1528          node = node->next;
1529          cmLListDelFrm(&hqDlMap->hqList, &hqP->ulSlotLnk);
1530          /* 
1531             Decode harq feedback if needed post FAPI message decoding also or check how to decode this FAPI msg.
1532             case 1 semi static harq Ack/Nack codebook //Supported
1533             case 2 dynamic harq ACK/NACK codebook //Not supported
1534          */
1535          schDlHqFeedbackUpdate(hqP, harqPayload[fdbkPos++], HQ_TB_ACKED);//Marking 2nd TB as ACKED for now as only one TB to be used
1536       }
1537    }
1538    else
1539    {
1540       node = hqDlMap->hqList.first;
1541       hqP = (SchDlHqProcCb*)node->node;
1542       cmLListDelFrm(&hqDlMap->hqList, &hqP->ulSlotLnk);
1543       schMsg4FeedbackUpdate(hqP, harqPayload[fdbkPos++]);
1544    }
1545 }
1546 /**********************************************************************
1547   End of file
1548  **********************************************************************/