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