67c05a8e200b7c07d3cc09386993d9c4440a7c42
[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->crnti = ueCfg->crnti;
58    cfgRsp->rsp = result;   
59
60    /* Filling response post */
61    memset(&rspPst, 0, sizeof(Pst));
62    FILL_PST_SCH_TO_MAC(rspPst, inst);
63    rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
64    DU_LOG("\nINFO  -->  SCH :  Sending UE Config response to MAC");
65    MacMessageRouter(&rspPst, (void *)cfgRsp);
66 }
67
68 /*******************************************************************
69  *
70  * @brief Fill and send UE Recfg response to MAC
71  *
72  * @details
73  *
74  *    Function : SchSendUeRecfgRspToMac
75  *
76  *    Functionality: Fill and send UE Recfg response to MAC
77  *
78  * @params[in] 
79  * @return ROK     - success
80  *         RFAILED - failure
81  *
82  * ****************************************************************/
83 void SchSendUeRecfgRspToMac(SchUeRecfgReq *ueRecfgReq, Inst inst,\
84       SchMacRsp result, SchUeRecfgRsp *reCfgRsp)
85 {
86    Pst rspPst;
87
88    reCfgRsp->cellId = ueRecfgReq->cellId;
89    reCfgRsp->crnti = ueRecfgReq->crnti;
90    reCfgRsp->rsp = result;   
91
92    /* Filling response post */
93    memset(&rspPst, 0, sizeof(Pst));
94    FILL_PST_SCH_TO_MAC(rspPst, inst);
95    rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
96    DU_LOG("\nINFO  -->  SCH :  Sending UE Reconfig response to MAC");
97     MacMessageRouter(&rspPst, (void *)reCfgRsp);
98 }
99
100 /*******************************************************************
101  
102  *
103  * @brief Function to fill Dl Lc Context in SCH Ue Cb
104  *
105  * @details
106  *
107  *    Function : fillSchDlLcCtxt
108  *
109  *    Functionality: Function to fill Dl Lc Context in SCH Ue Cb
110  *
111  * @params[in] SchDlLcCtxt pointer,
112  *             SchLcCfg pointer
113  * @return void
114  *
115  * ****************************************************************/
116
117 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
118 {
119    ueCbLcCfg->lcId = lcCfg->lcId;
120    ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
121    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
122    ueCbLcCfg->bo = 0;
123    if(lcCfg->drbQos)
124    {
125      ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
126    }
127    if(lcCfg->snssai)
128    {
129      if(ueCbLcCfg->snssai == NULLP)/*In CONFIG_MOD case, no need to allocate SNSSAI memory*/
130      {
131         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
132      }
133      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
134    }
135 }
136
137 /*******************************************************************
138  *
139  * @brief Function to fill Ul Lc Context in SCH Ue Cb
140  *
141  * @details
142  *
143  *    Function : fillSchUlLcCtxt
144  *
145  *    Functionality: Function to fill Ul Lc Context in SCH Ue Cb
146  *
147  * @params[in] SchUlLcCtxt pointer,
148  *             SchLcCfg pointer
149  * @return void
150  *
151  * ****************************************************************/
152
153 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
154 {
155    ueCbLcCfg->lcId = lcCfg->lcId;
156    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
157    ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
158    ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
159    ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
160    ueCbLcCfg->pbr     = lcCfg->ulLcCfg.pbr;
161    ueCbLcCfg->bsd     = lcCfg->ulLcCfg.bsd;
162
163    if(lcCfg->drbQos)
164    {
165       ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
166    }
167    if(lcCfg->snssai)
168    {
169      /*In CONFIG_MOD case, no need to allocate SNSSAI memory again*/
170      if(ueCbLcCfg->snssai == NULLP)
171      {
172         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
173      }
174      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
175    }
176 }
177
178 /*******************************************************************
179  *
180  * @brief Function to update/allocate dedLC Info
181  *
182  * @details
183  *
184  *    Function : updateDedLcInfo
185  *
186  *    Functionality: Function to fill DLDedLcInfo
187  *
188  * @params[arg] scheduler instance,
189  *              snssai pointer,
190  *              SchRrmPolicy pointer,
191  *              SchLcPrbEstimate pointer , It will be filled
192  *              isDedicated pointer,(Address of isDedicated flag in LC Context)
193  *
194  * @return ROK      >> This LC is part of RRM MemberList.
195  *         RFAILED  >> FATAL Error
196  *         ROKIGNORE >> This LC is not part of this RRM MemberList 
197  *
198  * ****************************************************************/
199
200 uint8_t updateDedLcInfo(Inst inst, Snssai *snssai, uint16_t *rsvdDedicatedPRB, bool *isDedicated)
201 {
202    CmLList *sliceCfg = schCb[inst].sliceCfg.first;
203    SchRrmPolicyOfSlice *rrmPolicyOfSlices;
204
205    while(sliceCfg)
206    {
207       rrmPolicyOfSlices = (SchRrmPolicyOfSlice*)sliceCfg->node;
208       if(rrmPolicyOfSlices && (memcmp(snssai, &(rrmPolicyOfSlices->snssai), sizeof(Snssai)) == 0))
209       {
210          /*Updating latest RrmPolicy*/
211          *rsvdDedicatedPRB = \
212                              (uint16_t)(((rrmPolicyOfSlices->rrmPolicyRatioInfo.dedicatedRatio)*(MAX_NUM_RB))/100);
213          *isDedicated = TRUE;
214          DU_LOG("\nINFO  -->  SCH : Updated RRM policy, reservedPOOL:%d",*rsvdDedicatedPRB);
215          break;
216       }
217       sliceCfg = sliceCfg->next;
218    }
219    /*case: This LcCtxt  is either a Default LC or this LC is part of someother RRM_MemberList*/
220    if(*isDedicated != TRUE) 
221    {
222       DU_LOG("\nINFO  -->  SCH : This SNSSAI is not a part of this RRMPolicy");
223    }
224    return ROK;   
225 }
226
227 /*******************************************************************
228  *
229  * @brief Function to fill SpCellCfg in SchUeCb From SchUeCfg Req
230  *
231  * @details
232  *
233  *    Function : fillSpCellInSchCb
234  *
235  *    Functionality: Function to fill SpCellCfg in SchUeCb
236  *
237  * @params[in] Scheduler instance,
238  *             SchUeCb pointer,
239  *             SchUeCfg pointer
240  * @return ROK/RFAILED
241  *
242  * ****************************************************************/
243
244 void fillSpCellInSchCb(SchSpCellRecfg *destSpCellCfg, SchSpCellCfg *srcSpCellCfg)
245 {
246    destSpCellCfg->servCellIdx = srcSpCellCfg->servCellIdx;
247    memcpy(&destSpCellCfg->servCellRecfg.initDlBwp, &srcSpCellCfg->servCellCfg.initDlBwp, sizeof(SchInitalDlBwp));
248    destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod =  srcSpCellCfg->servCellCfg.numDlBwpToAdd;
249    if(destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod > 0)
250    {
251       memcpy(destSpCellCfg->servCellRecfg.dlBwpToAddOrModList, srcSpCellCfg->servCellCfg.dlBwpToAddList,\
252               (sizeof(SchDlBwpInfo) * srcSpCellCfg->servCellCfg.numDlBwpToAdd));
253    }
254    destSpCellCfg->servCellRecfg.firstActvDlBwpId = srcSpCellCfg->servCellCfg.firstActvDlBwpId;
255    destSpCellCfg->servCellRecfg.defaultDlBwpId = srcSpCellCfg->servCellCfg.defaultDlBwpId;
256    destSpCellCfg->servCellRecfg.bwpInactivityTmr = srcSpCellCfg->servCellCfg.bwpInactivityTmr;
257    memcpy(&destSpCellCfg->servCellRecfg.pdschServCellCfg, &srcSpCellCfg->servCellCfg.pdschServCellCfg, sizeof(SchPdschServCellCfg));
258    memcpy(&destSpCellCfg->servCellRecfg.initUlBwp, &srcSpCellCfg->servCellCfg.initUlBwp, sizeof(SchInitialUlBwp));
259    
260    destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod =  srcSpCellCfg->servCellCfg.numDlBwpToAdd;
261    if(destSpCellCfg->servCellRecfg.numDlBwpToAddOrMod > 0)
262    {
263       memcpy(destSpCellCfg->servCellRecfg.ulBwpToAddOrModList, srcSpCellCfg->servCellCfg.ulBwpToAddList,\
264               (sizeof(SchUlBwpInfo) * srcSpCellCfg->servCellCfg.numUlBwpToAdd));
265    }
266    destSpCellCfg->servCellRecfg.firstActvUlBwpId = srcSpCellCfg->servCellCfg.firstActvUlBwpId;
267    return;
268 }
269
270 /*******************************************************************
271  *
272  * @brief Function to fill SchUeCb From UeCfg Req
273  *
274  * @details
275  *
276  *    Function : fillSchUeCbFrmCfgReq
277  *
278  *    Functionality: Function to fill SchUeCb
279  *
280  * @params[in] Scheduler instance,
281  *             SchUeCb pointer,
282  *             SchUeCfg pointer
283  * @return ROK/RFAILED
284  *
285  * ****************************************************************/
286
287 uint8_t fillSchUeCbFrmCfgReq(Inst inst, SchUeCb *ueCb, SchUeCfgReq *ueCfg)
288 {
289    uint8_t   lcIdx, ueLcIdx, idx;
290    uint8_t   freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
291    SchPdschCfgCmn pdschCfg;
292    SchPucchDlDataToUlAck *dlDataToUlAck;
293    uint8_t retDL = ROK, retUL = ROK;
294    bool isLcIdValid = FALSE;
295
296    ueCb->ueCfg.cellId = ueCfg->cellId;
297    ueCb->ueCfg.ueId = ueCb->ueId;
298    ueCb->ueCfg.crnti = ueCfg->crnti;
299    if(ueCfg->macCellGrpCfgPres == true)
300    {
301       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg)); 
302       ueCb->ueCfg.macCellGrpCfgPres = true;
303 #ifdef NR_DRX
304       if(ueCfg->macCellGrpCfg.drxCfgPresent == true)
305       {
306          if(ueCb->ueDrxInfoPres == false)
307          {
308             ueCb->ueDrxInfoPres = true;
309             /* intialize the drxUeCb */
310             schInitDrxUeCb(ueCb);
311
312             /* intialize the Dl drxHarqCb */
313             for(idx =0; idx<ueCb->dlHqEnt.numHqPrcs; idx++)
314             {
315                schInitDrxHarqCb(&ueCb->dlHqEnt.procs[idx].dlDrxHarqCb);
316             }
317             /* intialize the Ul drxHarqCb */
318             for(idx =0; idx<ueCb->ulHqEnt.numHqPrcs; idx++)
319             {
320                schInitDrxHarqCb(&ueCb->ulHqEnt.procs[idx].ulDrxHarqCb);
321             }
322             /* convert all the drx configuration recived in ms/subms into number of slots and store into the drxUeCb */
323             schFillDrxUeCb(ueCb->cellCb->numerology, ueCfg->macCellGrpCfg.drxCfg, &ueCb->drxUeCb);
324             /* Calculate the onduration timer and short cycle timer (if shortcycle configuration is present) as soon as we 
325              * recived ueCfg request */
326             schAddUeInOndurationList(ueCb->cellCb, ueCb, 0);
327
328          }
329          else
330          {
331             /* convert all the drx configuration recived in ms/subms into number
332              * of slots and store into the drxUeCb */
333             schFillDrxUeCb(ueCb->cellCb->numerology, ueCfg->macCellGrpCfg.drxCfg, &ueCb->drxUeCb);
334
335             /* Recalculate/Restart timer based on their presence */
336             schDrxUeReCfgTimer(ueCb->cellCb, ueCb);
337          }
338       }
339 #endif
340    }
341
342    if(ueCfg->phyCellGrpCfgPres == true)
343    {
344       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
345       ueCb->ueCfg.phyCellGrpCfgPres = true;
346    }
347
348    if(ueCfg->spCellCfgPres == true)
349    {
350       if(ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
351       {
352          if(ueCb->ueCfg.spCellCfgPres && ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfgPres == true)
353          {
354             for(idx = 0; idx < ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc; idx++)
355             {
356                if(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0 && ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0)
357                {
358                   SCH_FREE(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0, sizeof(uint8_t));  
359                }
360             }
361          }
362       }
363       fillSpCellInSchCb(&ueCb->ueCfg.spCellCfg, &ueCfg->spCellCfg);
364
365       covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
366             freqDomainResource);
367       memset(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
368       memcpy(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
369
370       ueCb->ueCfg.spCellCfgPres = true;
371       dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
372       if(ueCb->cellCb)
373       {
374          if(dlDataToUlAck)
375          {
376             BuildK0K1Table(ueCb->cellCb, &ueCb->k0K1InfoTbl, false, pdschCfg,\
377                   ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
378                   dlDataToUlAck->dlDataToUlAckList);
379             ueCb->k0K1TblPrsnt = true;
380             BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
381                   ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
382                   NULLP, &ueCb->k2InfoTbl);
383             ueCb->k2TblPrsnt = true;
384          }
385       }
386    }
387
388    if(ueCfg->ambrCfg)
389    {
390       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
391       ueCb->ueCfg.ambrCfg =  ueCfg->ambrCfg;
392    }
393    memcpy(&ueCb->ueCfg.dlModInfo,  &ueCfg->dlModInfo , sizeof(SchModulationInfo));
394    memcpy(&ueCb->ueCfg.ulModInfo,  &ueCfg->ulModInfo , sizeof(SchModulationInfo));
395    //Updating SchUlCb and SchDlCb DB in SchUeCb
396    for(lcIdx = 0; lcIdx < ueCfg->numLcsToAdd; lcIdx++)
397    {
398       isLcIdValid = FALSE; /*Re-Initializing*/
399
400       ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
401       CHECK_LCID(ueLcIdx, isLcIdValid);
402       if(isLcIdValid == FALSE)
403       {
404          DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
405          continue;
406       }
407       fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
408       fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
409
410       /*Checking whether this LC belong to Dedicated S-NSSAI 
411        * and Create the Dedicated LC List & Update the Reserve PRB number*/
412       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
413       {
414          retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
415                &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
416       }
417       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
418       {
419          retUL =  updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
420                &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
421       }
422
423       if(retUL == RFAILED  || retDL == RFAILED)/*FATAL error*/
424       {
425          DU_LOG("\nERROR  -->  SCH : Failure in updateDedLcInfo");
426          return RFAILED;
427       }
428       SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
429       SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
430
431    }/* End of outer for loop */
432    return ROK;
433 }
434
435 /*******************************************************************
436  *
437  * @brief Function to fill SchUeCb From UeReconfig Req
438  *
439  * @details
440  *
441  *    Function : fillSchUeCbFrmRecfgReq
442  *
443  *    Functionality: Function to fill SchUeCb
444  *
445  * @params[in] Scheduler instance,
446  *             SchUeCb pointer,
447  *             SchUeCfg pointer
448  * @return ROK/RFAILED
449  *
450  * ****************************************************************/
451
452 uint8_t fillSchUeCbFrmRecfgReq(Inst inst, SchUeCb *ueCb, SchUeRecfgReq *ueRecfg)
453 {
454    uint8_t   lcIdx, ueLcIdx, idx;
455    uint8_t   freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
456    SchPdschCfgCmn pdschCfg;
457    SchPucchDlDataToUlAck *dlDataToUlAck;
458    uint8_t retDL = ROK, retUL = ROK;
459    bool isLcIdValid = FALSE;
460
461
462    ueCb->ueCfg.cellId = ueRecfg->cellId;
463    ueCb->ueCfg.crnti = ueRecfg->crnti;
464    GET_UE_ID(ueRecfg->crnti, ueCb->ueCfg.ueId);
465    ueCb->ueCfg.dataTransmissionAction = ueRecfg->dataTransmissionInfo;
466    if(ueRecfg->macCellGrpRecfgPres == true)
467    {
468       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueRecfg->macCellGrpRecfg, sizeof(SchMacCellGrpCfg)); 
469       ueCb->ueCfg.macCellGrpCfgPres = true;
470 #ifdef NR_DRX
471       if(ueRecfg->macCellGrpRecfg.drxCfgPresent == true)
472       {
473          if(ueCb->ueDrxInfoPres == false)
474          {
475             ueCb->ueDrxInfoPres = true;
476             /* intialize the drxUeCb */
477             schInitDrxUeCb(ueCb);
478
479             /* intialize the Dl drxHarqCb */
480             for(idx =0; idx<ueCb->dlHqEnt.numHqPrcs; idx++)
481             {
482                schInitDrxHarqCb(&ueCb->dlHqEnt.procs[idx].dlDrxHarqCb);
483             }
484             /* intialize the Ul drxHarqCb */
485             for(idx =0; idx<ueCb->ulHqEnt.numHqPrcs; idx++)
486             {
487                schInitDrxHarqCb(&ueCb->ulHqEnt.procs[idx].ulDrxHarqCb);
488             }
489             /* convert all the drx configuration recived in ms/subms into number of slots and store into the drxUeCb */
490             schFillDrxUeCb(ueCb->cellCb->numerology, ueRecfg->macCellGrpRecfg.drxCfg, &ueCb->drxUeCb);
491             /* Calculate the onduration timer and short cycle timer (if shortcycle configuration is present) as soon as we 
492              * recived ueCfg request */
493             schAddUeInOndurationList(ueCb->cellCb, ueCb, 0);
494
495          }
496          else
497          {
498             /* convert all the drx configuration recived in ms/subms into number
499              * of slots and store into the drxUeCb */
500             schFillDrxUeCb(ueCb->cellCb->numerology, ueRecfg->macCellGrpRecfg.drxCfg, &ueCb->drxUeCb);
501
502             /* Recalculate/Restart timer based on their presence */
503             schDrxUeReCfgTimer(ueCb->cellCb, ueCb);
504          }
505       }
506 #endif
507    }
508
509 #ifdef NR_DRX
510    if(ueRecfg->drxConfigIndicatorRelease == true)
511    {
512       if(ueCb->ueDrxInfoPres == true)
513       {
514          schDeleteUeDrxInfo(ueCb->cellCb, ueCb);
515          ueCb->ueDrxInfoPres = false;
516       }
517    }
518 #endif
519
520    if(ueRecfg->phyCellGrpRecfgPres == true)
521    {
522       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueRecfg->phyCellGrpRecfg, sizeof(SchPhyCellGrpCfg));
523       ueCb->ueCfg.phyCellGrpCfgPres = true;
524    }
525
526    if(ueRecfg->spCellRecfgPres == true)
527    {
528       if(ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfgPres == true)
529       {
530          if(ueCb->ueCfg.spCellCfgPres && ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfgPres == true)
531          {
532             for(idx = 0; idx < ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfg.numTimeDomRsrcAlloc; idx++)
533             {
534                if(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0 && ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0)
535                {
536                   SCH_FREE(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdschCfg.timeDomRsrcAllociList[idx].k0, sizeof(uint8_t));  
537                }
538             }
539          }
540       }
541       memcpy(&ueCb->ueCfg.spCellCfg , &ueRecfg->spCellRecfg, sizeof(SchSpCellRecfg));
542
543       covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
544             freqDomainResource);
545       memset(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
546       memcpy(ueCb->ueCfg.spCellCfg.servCellRecfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
547
548       ueCb->ueCfg.spCellCfgPres = true;
549       dlDataToUlAck = ueRecfg->spCellRecfg.servCellRecfg.initUlBwp.pucchCfg.dlDataToUlAck;
550       if(ueCb->cellCb)
551       {
552          if(dlDataToUlAck)
553          {
554             BuildK0K1Table(ueCb->cellCb, &ueCb->k0K1InfoTbl, false, pdschCfg,\
555                   ueRecfg->spCellRecfg.servCellRecfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
556                   dlDataToUlAck->dlDataToUlAckList);
557             ueCb->k0K1TblPrsnt = true;
558             BuildK2InfoTable(ueCb->cellCb, ueRecfg->spCellRecfg.servCellRecfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
559                   ueRecfg->spCellRecfg.servCellRecfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
560                   NULLP, &ueCb->k2InfoTbl);
561             ueCb->k2TblPrsnt = true;
562          }
563       }
564    }
565
566    if(ueRecfg->ambrRecfg)
567    {
568       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
569       ueCb->ueCfg.ambrCfg =  ueRecfg->ambrRecfg;
570    }
571    memcpy(&ueCb->ueCfg.dlModInfo,  &ueRecfg->dlModInfo , sizeof(SchModulationInfo));
572    memcpy(&ueCb->ueCfg.ulModInfo,  &ueRecfg->ulModInfo , sizeof(SchModulationInfo));
573    //Updating Num of LC to ADD SchUlCb and SchDlCb DB in SchUeCb
574    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToAdd; lcIdx++)
575    {
576       isLcIdValid = FALSE; /*Re-Initializing*/
577
578       ueLcIdx = ueRecfg->schLcCfgAdd[lcIdx].lcId;
579       CHECK_LCID(ueLcIdx, isLcIdValid);
580       if(isLcIdValid == FALSE)
581       {
582          DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
583          continue;
584       }
585       fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueRecfg->schLcCfgAdd[lcIdx]);
586       fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueRecfg->schLcCfgAdd[lcIdx]);
587
588       /*Checking whether this LC belong to Dedicated S-NSSAI 
589        * and Create the Dedicated LC List & Update the Reserve PRB number*/
590       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
591       {
592          retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
593                &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
594       }
595       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
596       {
597          retUL =  updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
598                &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
599       }
600
601       if(retUL == RFAILED  || retDL == RFAILED)/*FATAL error*/
602       {
603          DU_LOG("\nERROR  -->  SCH : Failure in updateDedLcInfo");
604          return RFAILED;
605       }
606       SCH_FREE(ueRecfg->schLcCfgAdd[lcIdx].drbQos, sizeof(SchDrbQosInfo));
607       SCH_FREE(ueRecfg->schLcCfgAdd[lcIdx].snssai, sizeof(Snssai));
608    }
609    //Updating Num of LC to DEL SchUlCb and SchDlCb DB in SchUeCb
610    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToDel; lcIdx++)
611    {
612       ueLcIdx = ueRecfg->lcIdToDel[lcIdx];
613
614       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueRecfg->lcIdToDel[lcIdx])
615       {
616          /*Delete the LC node from the DL LC List*/
617          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
618          {
619             /*Remove from HARQ Transmission or retransmission*/
620          }
621          else
622          {
623          }
624          SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
625          memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
626       }
627       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueRecfg->lcIdToDel[lcIdx])
628       {
629          /*Delete the LC node from the UL LC List*/
630          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
631          {
632             /*Remove from HARQ Transmission or retransmission*/
633          }
634          else/*Default LC list*/
635          {
636
637          }
638          SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
639          memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
640       }
641    }
642    //Updating Num of LC to DEL SchUlCb and SchDlCb DB in SchUeCb
643    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToMod; lcIdx++)
644    {
645       ueLcIdx = ueRecfg->schLcCfgMod[lcIdx].lcId;
646
647       if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueRecfg->schLcCfgMod[lcIdx].lcId)
648       {
649          fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueRecfg->schLcCfgMod[lcIdx]);
650          /*Updating the RRM reserved pool PRB count*/
651          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
652          {
653             retUL =  updateDedLcInfo(inst, ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].rsvdDedicatedPRB),\
654                   &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
655          }
656          if(retUL == RFAILED)
657          {
658             DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
659             return RFAILED;
660          }
661       }/*End of UL LC Ctxt*/
662
663       if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueRecfg->schLcCfgMod[lcIdx].lcId)
664       {
665          fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueRecfg->schLcCfgMod[lcIdx]);
666          /*Updating the RRM policy*/
667          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
668          {
669             retDL = updateDedLcInfo(inst, ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].rsvdDedicatedPRB), \
670                   &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
671          }
672          if(retDL == RFAILED)
673          {
674             DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
675             return RFAILED;
676          }
677       }/*End of DL LC ctxt*/
678
679       SCH_FREE(ueRecfg->schLcCfgMod[lcIdx].drbQos, sizeof(SchDrbQosInfo));
680       SCH_FREE(ueRecfg->schLcCfgMod[lcIdx].snssai, sizeof(Snssai));
681    }/* End of outer for loop */
682    return ROK;
683 }
684
685 /*******************************************************************
686  *
687  * @brief Function to get SCH Cell Cb
688  *
689  * @details
690  *
691  *    Function : getSchCellCb
692  *
693  *    Functionality: Function to get SCH Cell Cb
694  *
695  * @params[in] event, SchUeCfg pointer 
696  * @return schUeCb pointer  - success
697  *         NULLP - failure
698  *
699  * ****************************************************************/
700
701 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, uint16_t cellId)
702 {
703    uint8_t      idx = 0;
704    SchCellCb    *cellCb = NULLP;
705
706    /* Search of cell cb */
707    for(idx = 0; idx < MAX_NUM_CELL; idx++)
708    {
709       cellCb = schCb[inst].cells[idx];
710       if((cellCb != NULLP) && (cellCb->cellId == cellId))
711          break;
712    }
713    if((idx == MAX_NUM_CELL) || (cellCb == NULLP))
714    {
715       DU_LOG("\nERROR  -->  SCH : Ue create request failed. Invalid cell id %d", cellId);
716       return NULLP;
717    }
718
719    /* Check if max number of UE configured */
720    if(cellCb->numActvUe > MAX_NUM_UE)
721    {
722       DU_LOG("\nERROR  -->  SCH :  Max number of UE [%d] already configured", MAX_NUM_UE);
723       return NULLP;
724    }
725    return cellCb;
726 }
727
728
729 /*******************************************************************
730  *
731  * @brief Function to Add Ue Config Request from MAC
732  *
733  * @details
734  *
735  *    Function : SchAddUeConfigReq
736  *
737  *    Functionality: Function to Add Ue config request from MAC
738  *
739  * @params[in] 
740  * @return ROK     - success
741  *         RFAILED - failure
742  *
743  * ****************************************************************/
744 uint8_t SchAddUeConfigReq(Pst *pst, SchUeCfgReq *ueCfg)
745 {
746    uint8_t      lcIdx = 0, ret = ROK, idx = 0;
747    uint16_t     ueId = 0;
748    SchCellCb    *cellCb = NULLP;
749    SchUeCb      *ueCb = NULLP;
750    SchUeCfgRsp  cfgRsp;
751    Inst         inst = pst->dstInst - SCH_INST_START;
752    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
753   
754    if(!ueCfg)
755    {
756       DU_LOG("\nERROR  -->  SCH :  Adding UE Config Request failed at SchAddUeConfigReq()");
757       return RFAILED;
758    }
759    DU_LOG("\nDEBUG  -->  SCH :  Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
760    cellCb = getSchCellCb(pst->event, inst, ueCfg->cellId);
761
762    if(cellCb == NULLP)
763    {
764       SchSendUeCfgRspToMac(ueCfg, inst, RSP_NOK, &cfgRsp);
765       return RFAILED; 
766    }
767    /* Search if UE already configured */
768    GET_UE_ID(ueCfg->crnti, ueId);
769    ueCb = &cellCb->ueCb[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->crnti = ueCfg->crnti;
782    GET_UE_ID(ueCb->crnti, ueCb->ueId);
783    ueCb->cellCb = cellCb;
784    schUlHqEntInit(cellCb, &cellCb->ueCb[ueCb->ueId-1]);
785    schDlHqEntInit(cellCb, &cellCb->ueCb[ueCb->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  **********************************************************************/