<JIRA ID: ODUHIGH-386 : UL scheduling as per RRM policy
[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_utils.h"
31
32 /* local defines */
33 SchUeCfgRspFunc SchUeCfgRspOpts[] =
34 {
35    packSchUeCfgRsp,      /* LC */
36    MacProcSchUeCfgRsp,   /* TC */
37    packSchUeCfgRsp       /* LWLC */
38 };
39
40 SchUeDeleteRspFunc SchUeDeleteRspOpts[] =
41 {
42    packSchUeDeleteRsp,      /* LC */
43    MacProcSchUeDeleteRsp,   /* TC */
44    packSchUeDeleteRsp       /* LWLC */
45 };
46
47 SchCellDeleteRspFunc SchCellDeleteRspOpts[]=
48 {
49    packSchCellDeleteRsp,      /* LC */
50    MacProcSchCellDeleteRsp,   /* TC */
51    packSchCellDeleteRsp       /* LWLC */
52 };
53
54 /*******************************************************************
55  *
56  * @brief Fill and send UE cfg response to MAC
57  *
58  * @details
59  *
60  *    Function : SchSendUeCfgRspToMac
61  *
62  *    Functionality: Fill and send UE cfg response to MAC
63  *
64  * @params[in] 
65  * @return ROK     - success
66  *         RFAILED - failure
67  *
68  * ****************************************************************/
69 void SchSendUeCfgRspToMac(uint16_t event, SchUeCfg *ueCfg, Inst inst,\
70       SchMacRsp result, SchUeCfgRsp *cfgRsp)
71 {
72    Pst rspPst;
73
74    cfgRsp->cellId = ueCfg->cellId;
75    cfgRsp->crnti = ueCfg->crnti;
76    GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
77    cfgRsp->rsp = result;   
78
79    /* Filling response post */
80    memset(&rspPst, 0, sizeof(Pst));
81    FILL_PST_SCH_TO_MAC(rspPst, inst);
82    if(event == EVENT_ADD_UE_CONFIG_REQ_TO_SCH)
83    {
84       rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
85       DU_LOG("\nINFO  -->  SCH :  Sending UE Config response to MAC");
86    }
87    else if(event == EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH)
88    {
89       rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
90       DU_LOG("\nINFO  -->  SCH :  Sending UE Reconfig response to MAC");
91    }
92    SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
93 }
94
95 /*******************************************************************
96  
97  *
98  * @brief Function to fill Dl Lc Context in SCH Ue Cb
99  *
100  * @details
101  *
102  *    Function : fillSchDlLcCtxt
103  *
104  *    Functionality: Function to fill Dl Lc Context in SCH Ue Cb
105  *
106  * @params[in] SchDlLcCtxt pointer,
107  *             SchLcCfg pointer
108  * @return void
109  *
110  * ****************************************************************/
111
112 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
113 {
114    ueCbLcCfg->lcId = lcCfg->lcId;
115    ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
116    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
117    ueCbLcCfg->bo = 0;
118    if(lcCfg->drbQos)
119    {
120      ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
121    }
122    if(lcCfg->snssai)
123    {
124      if(ueCbLcCfg->snssai == NULLP)/*In CONFIG_MOD case, no need to allocate SNSSAI memory*/
125      {
126         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
127      }
128      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
129    }
130 }
131
132 /*******************************************************************
133  *
134  * @brief Function to fill Ul Lc Context in SCH Ue Cb
135  *
136  * @details
137  *
138  *    Function : fillSchUlLcCtxt
139  *
140  *    Functionality: Function to fill Ul Lc Context in SCH Ue Cb
141  *
142  * @params[in] SchUlLcCtxt pointer,
143  *             SchLcCfg pointer
144  * @return void
145  *
146  * ****************************************************************/
147
148 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
149 {
150    ueCbLcCfg->lcId = lcCfg->lcId;
151    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
152    ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
153    ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
154    ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
155    ueCbLcCfg->pbr     = lcCfg->ulLcCfg.pbr;
156    ueCbLcCfg->bsd     = lcCfg->ulLcCfg.bsd;
157
158    if(lcCfg->drbQos)
159    {
160       ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
161    }
162    if(lcCfg->snssai)
163    {
164      /*In CONFIG_MOD case, no need to allocate SNSSAI memory again*/
165      if(ueCbLcCfg->snssai == NULLP)
166      {
167         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
168      }
169      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
170    }
171 }
172
173 /*******************************************************************
174  *
175  * @brief Function to update/allocate dedLC Info
176  *
177  * @details
178  *
179  *    Function : updateDedLcInfo
180  *
181  *    Functionality: Function to fill DLDedLcInfo
182  *
183  * @params[arg] snssai pointer,
184  *              SchRrmPolicy pointer,
185  *              SchLcPrbEstimate pointer , It will be filled
186  *              isDedicated pointer,(Address of isDedicated flag in LC Context)
187  *
188  * @return ROK      >> This LC is part of RRM MemberList.
189  *         RFAILED  >> FATAL Error
190  *         ROKIGNORE >> This LC is not part of this RRM MemberList 
191  *
192  * ****************************************************************/
193
194 uint8_t updateDedLcInfo(Snssai *snssai, SchRrmPolicy *rrmPolicy, SchLcPrbEstimate *lcPrbEst,\
195                          bool *isDedicated)
196 {
197    if(memcmp(snssai, &(rrmPolicy->memberList.snssai), sizeof(Snssai)) == 0)
198    {
199       if(lcPrbEst->dedLcInfo == NULLP)
200       {
201          SCH_ALLOC(lcPrbEst->dedLcInfo, sizeof(DedicatedLCInfo));
202          if(lcPrbEst->dedLcInfo == NULLP)
203          {
204             DU_LOG("\nINFO  -->  SCH : Memory Allocation Failed");
205             return RFAILED;
206          }
207       }
208       /*Updating latest RrmPolicy*/
209       lcPrbEst->dedLcInfo->rsvdDedicatedPRB = \
210                                               (uint16_t)(((rrmPolicy->policyDedicatedRatio)*(MAX_NUM_RB))/100);
211       *isDedicated = TRUE;
212       DU_LOG("\nINFO  -->  SCH : Updated RRM policy, reservedPOOL:%d",lcPrbEst->dedLcInfo->rsvdDedicatedPRB);
213    }
214    /*else case: This LcCtxt  is either a Default LC or this LC is part of someother RRM_MemberList*/
215    else
216    {
217       DU_LOG("\nINFO  -->  SCH : This SNSSAI is not a part of this RRMPolicy");
218    }
219    return ROK;   
220 }
221
222 /*******************************************************************
223  *
224  * @brief Function to fill SchUeCb
225  *
226  * @details
227  *
228  *    Function : fillSchUeCb
229  *
230  *    Functionality: Function to fill SchUeCb
231  *
232  * @params[in] SchUeCb pointer,
233  *             SchUeCfg pointer
234  * @return ROK/RFAILED
235  *
236  * ****************************************************************/
237
238 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
239 {
240    uint8_t   lcIdx, ueLcIdx;
241    uint8_t   freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
242    SchPdschCfgCmn pdschCfg;
243    SchPucchDlDataToUlAck *dlDataToUlAck;
244    CmLListCp *lcLL = NULLP;
245    uint8_t retDL = ROK, retUL = ROK;
246    bool isLcIdValid = FALSE;
247
248    ueCb->ueCfg.cellId = ueCfg->cellId;
249    ueCb->ueCfg.crnti = ueCfg->crnti;
250    if(ueCfg->macCellGrpCfgPres == true)
251    {
252       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg)); 
253       ueCb->ueCfg.macCellGrpCfgPres = true;
254    }
255
256    if(ueCfg->phyCellGrpCfgPres == true)
257    {
258       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
259       ueCb->ueCfg.phyCellGrpCfgPres = true;
260    }
261
262    if(ueCfg->spCellCfgPres == true)
263    {
264       memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
265
266       covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
267             freqDomainResource);
268       memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
269       memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
270
271       ueCb->ueCfg.spCellCfgPres = true;
272       dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
273       if(ueCb->cellCb)
274       {
275          if(dlDataToUlAck)
276          {
277             BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
278                   ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
279                   dlDataToUlAck->dlDataToUlAckList);
280             ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1TblPrsnt = true;
281             BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
282                   ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
283                   NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
284                   ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt = true;
285          }
286       }
287    }
288
289    ueCb->state = SCH_UE_STATE_ACTIVE;
290    if(ueCfg->ambrCfg)
291    {
292       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
293       ueCb->ueCfg.ambrCfg =  ueCfg->ambrCfg;
294    }
295    memcpy(&ueCb->ueCfg.dlModInfo,  &ueCfg->dlModInfo , sizeof(SchModulationInfo));
296    memcpy(&ueCb->ueCfg.ulModInfo,  &ueCfg->ulModInfo , sizeof(SchModulationInfo));
297
298    //Updating SchUlCb and SchDlCb DB in SchUeCb
299    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
300    {
301       isLcIdValid = FALSE; /*Re-Initializing*/
302
303       ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
304       CHECK_LCID(ueLcIdx, isLcIdValid);
305       if(isLcIdValid == FALSE)
306       {
307          DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
308          continue;
309       }
310       if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
311       {
312          fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
313          fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
314
315          /*Checking whether this LC belong to Dedicated S-NSSAI 
316           * and Create the Dedicated LC List & Update the Reserve PRB number*/
317          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
318          {
319             retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai,  \
320                   ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst),\
321                   &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
322          }
323          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
324          {
325             retUL =  updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai,  \
326                   ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
327                   &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
328          }
329
330          if(retUL == RFAILED  || retDL == RFAILED)/*FATAL error*/
331          {
332             DU_LOG("\nERROR  -->  SCH : Failure in updateDedLcInfo");
333             return RFAILED;
334          }
335       }
336       else
337       {
338          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
339          {
340             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
341             {
342                fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
343                /*Updating the RRM reserved pool PRB count*/
344                if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
345                {
346                   retUL =  updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai,  \
347                         ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
348                         &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
349                }
350                if(retUL == RFAILED)
351                {
352                   DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
353                   return RFAILED;
354                }
355             }
356             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
357             {
358                /*Delete the LC node from the UL LC List*/
359                if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
360                {
361                   if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
362                   {
363                      lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
364                      handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
365                      if(lcLL->count == 0)/*IF No Node in DedicateLCList to be deleted*/
366                      {
367                         /*Free the Dedicated LC Info structure*/
368                         SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
369                      }
370                   }
371                }
372                else/*Default LC list*/
373                {
374                   lcLL = &(ueCb->ulLcPrbEst.defLcList);
375                   handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
376                }
377                SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
378                memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
379             }
380          }/*End of UL LC Ctxt*/
381
382          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
383          {
384             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
385             {
386                fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
387                /*Updating the RRM policy*/
388                if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
389                {
390                   retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai,  \
391                         ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst), \
392                         &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
393                }
394                if(retDL == RFAILED)
395                {
396                   DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
397                   return RFAILED;
398                }
399             }
400             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
401             {
402                /*Delete the LC node from the DL LC List*/
403                if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
404                {
405                   if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
406                   {
407                      lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
408                      handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
409                      if(lcLL->count == 0)/*Last Node in DedicateLCList to be deleted*/
410                      {
411                         /*Free the Dedicated LC Info structure*/
412                         SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
413                      }
414                   }
415                }
416                else
417                {
418                   lcLL = &(ueCb->dlLcPrbEst.defLcList);
419                   handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
420                }
421                SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
422                memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
423             }
424          }/*End of DL LC ctxt*/
425       }
426
427       SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
428       SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
429
430    }/* End of outer for loop */
431    return ROK;
432 }
433
434 /*******************************************************************
435  *
436  * @brief Function to get SCH Cell Cb
437  *
438  * @details
439  *
440  *    Function : getSchCellCb
441  *
442  *    Functionality: Function to get SCH Cell Cb
443  *
444  * @params[in] event, SchUeCfg pointer 
445  * @return schUeCb pointer  - success
446  *         NULLP - failure
447  *
448  * ****************************************************************/
449
450 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
451 {
452    uint8_t      idx;
453    SchCellCb    *cellCb = NULLP;
454    SchUeCfgRsp  cfgRsp;
455    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
456
457    /* Search of cell cb */
458    for(idx = 0; idx < MAX_NUM_CELL; idx++)
459    {
460       cellCb = schCb[inst].cells[idx];
461       if(cellCb->cellId == ueCfg->cellId)
462          break;
463    }
464    if(idx == MAX_NUM_CELL)
465    {
466       DU_LOG("\nERROR  -->  SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
467       SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
468       return NULLP;
469    }
470
471    /* Check if max number of UE configured */
472    if(cellCb->numActvUe > MAX_NUM_UE)
473    {
474       DU_LOG("\nERROR  -->  SCH :  Max number of UE [%d] already configured", MAX_NUM_UE);
475       SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
476       return NULLP;
477    }
478    return cellCb;
479 }
480
481
482 /*******************************************************************
483  *
484  * @brief Function to Add Ue Config Request from MAC
485  *
486  * @details
487  *
488  *    Function : MacSchAddUeConfigReq
489  *
490  *    Functionality: Function to Add Ue config request from MAC
491  *
492  * @params[in] 
493  * @return ROK     - success
494  *         RFAILED - failure
495  *
496  * ****************************************************************/
497 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
498 {
499    uint8_t ueIdx, lcIdx, ret = ROK;
500    SchCellCb    *cellCb = NULLP;
501    SchUeCb      *ueCb = NULLP;
502    SchUeCfgRsp  cfgRsp;
503    Inst         inst = pst->dstInst - 1;
504    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
505   
506 #ifdef CALL_FLOW_DEBUG_LOG
507    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
508 #endif
509
510    if(!ueCfg)
511    {
512       DU_LOG("\nERROR  -->  SCH :  Adding UE Config Request failed at MacSchAddUeConfigReq()");
513       return RFAILED;
514    }
515    DU_LOG("\nDEBUG  -->  SCH :  Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
516    cellCb = getSchCellCb(pst->event, inst, ueCfg);
517
518    /* Search if UE already configured */
519    GET_UE_IDX(ueCfg->crnti, ueIdx);
520    ueCb = &cellCb->ueCb[ueIdx -1];
521    if(ueCb)
522    {
523       if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
524       {
525          DU_LOG("\nDEBUG  -->  SCH : CRNTI %d already configured ", ueCfg->crnti);
526          SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
527          return ROK;
528       }
529    }
530    else
531    {
532       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
533       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
534       return RFAILED;
535    }
536
537    /* Fill received Ue Configuration in UeCb */
538    memset(ueCb, 0, sizeof(SchUeCb));
539    GET_UE_IDX(ueCfg->crnti, ueIdx);
540    ueCb->ueIdx = ueIdx;
541    ueCb->crnti = ueCfg->crnti;
542    ueCb->state = SCH_UE_STATE_ACTIVE;
543    ret = fillSchUeCb(ueCb, ueCfg);
544    if(ret == ROK)
545    {
546       cellCb->numActvUe++;
547       SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
548       ueCb->cellCb = cellCb;
549       ueCb->srRcvd = false;
550       ueCb->bsrRcvd = false;
551       for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
552          ueCb->bsrInfo[lcIdx].dataVol = 0;
553
554       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
555    }
556    return ret;
557 }
558
559 /*******************************************************************
560 *
561 * @brief Fills PUSCH UL allocation
562 *
563 * @details
564 *
565 *    Function : schFillPuschAlloc
566 *
567 *    Functionality: fills PUSCH info
568 *
569 * @params[in]
570 * @return ROK     - success
571 *         RFAILED - failure
572 *
573 * ****************************************************************/
574 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize, 
575                             uint8_t startSymb, uint8_t symbLen, uint16_t startPrb)
576 {
577   uint8_t  numRb          = 0;
578   SchCellCb *cellCb       = NULLP;
579   SchUlSlotInfo *schUlSlotInfo = NULLP;
580   SchPuschInfo puschInfo;
581   
582   if(ueCb == NULLP)
583   {
584     DU_LOG("\nERROR --> SCH: UE CB is empty");
585     return RFAILED;
586   }
587
588   cellCb = ueCb->cellCb;
589   if(cellCb == NULLP)
590   {
591     DU_LOG("\nERROR --> SCH: CELL CB is empty");
592     return RFAILED;
593   }
594
595   tbSize  +=  UL_TX_BUFFER_SIZE; /*  2 bytes header + some buffer */
596   numRb   = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
597   allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startPrb, numRb);
598
599   puschInfo.crnti             = ueCb->crnti; 
600   puschInfo.harqProcId        = SCH_HARQ_PROC_ID;
601   puschInfo.resAllocType      = SCH_ALLOC_TYPE_1;
602   puschInfo.fdAlloc.startPrb  = startPrb;
603   puschInfo.fdAlloc.numPrb    = numRb;
604   puschInfo.tdAlloc.startSymb = startSymb;
605   puschInfo.tdAlloc.numSymb   = symbLen;
606   puschInfo.tbInfo.qamOrder   = ueCb->ueCfg.ulModInfo.modOrder;
607   puschInfo.tbInfo.mcs        = ueCb->ueCfg.ulModInfo.mcsIndex;
608   puschInfo.tbInfo.mcsTable   = ueCb->ueCfg.ulModInfo.mcsTable;
609   puschInfo.tbInfo.ndi        = 1; /* new transmission */
610   puschInfo.tbInfo.rv         = 0;
611   puschInfo.tbInfo.tbSize     = tbSize;
612   puschInfo.dmrsMappingType   = DMRS_MAP_TYPE_A;  /* Setting Type-A */
613   puschInfo.nrOfDmrsSymbols   = NUM_DMRS_SYMBOLS;
614   puschInfo.dmrsAddPos        = DMRS_ADDITIONAL_POS;
615
616   schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
617   SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
618   if(!schUlSlotInfo->schPuschInfo)
619   {
620      DU_LOG("\nERROR  -->  SCH: Memory allocation failed in schAllocMsg3Pusch");
621      return RFAILED;
622   }
623   memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
624
625   return ROK;
626 }
627
628 /*******************************************************************
629  *
630  * @brief Fills DCI for UL grant
631  *
632  * @details
633  *
634  *    Function : schFillUlDci
635  *
636  *    Functionality: fills DCI for UL grant in response to BSR
637  *
638  * @params[in]
639  * @return ROK     - success
640  *         RFAILED - failure
641  *
642  * ****************************************************************/
643 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
644 {
645    SchCellCb         *cellCb  = ueCb->cellCb;
646    SchControlRsrcSet coreset1 ;
647   
648    memset(&coreset1, 0, sizeof(SchControlRsrcSet));
649    if(ueCb->ueCfg.spCellCfgPres == true)
650    {
651      coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
652    }
653    
654    dciInfo->cellId = cellCb->cellId;
655    dciInfo->crnti  = ueCb->crnti;
656
657    /* fill bwp cfg */
658    dciInfo->bwpCfg.subcarrierSpacing  = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
659    dciInfo->bwpCfg.cyclicPrefix       = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
660    dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb;
661    dciInfo->bwpCfg.freqAlloc.numPrb   = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb; 
662
663    /*fill coreset cfg */
664    //Considering number of RBs in coreset1 is same as coreset0
665    dciInfo->coresetCfg.coreSetSize      = coresetIdxTable[0][1];
666    //Considering coreset1 also starts from same symbol as coreset0
667    dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
668    dciInfo->coresetCfg.durationSymbols  = coreset1.duration;
669    memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
670    
671    dciInfo->coresetCfg.cceRegMappingType   = coreset1.cceRegMappingType; /* non-interleaved */
672    dciInfo->coresetCfg.regBundleSize       = 6; /* must be 6 for non-interleaved */
673    dciInfo->coresetCfg.interleaverSize     = 0; /* NA for non-interleaved */
674    dciInfo->coresetCfg.coreSetType         = 1; /* non PBCH coreset */
675    dciInfo->coresetCfg.shiftIndex          = cellCb->cellCfg.phyCellId;
676    dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
677    dciInfo->coresetCfg.cceIndex            = 0; /* 0-3 for UL and 4-7 for DL */
678    dciInfo->coresetCfg.aggregationLevel    = 4; /* same as for sib1 */
679    
680    dciInfo->formatType = FORMAT0_0;
681    
682    /* fill UL grant */
683    dciInfo->format.format0_0.resourceAllocType   = puschInfo->resAllocType;
684    dciInfo->format.format0_0.freqAlloc.startPrb  = puschInfo->fdAlloc.startPrb;
685    dciInfo->format.format0_0.freqAlloc.numPrb    = puschInfo->fdAlloc.numPrb;
686    dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
687    dciInfo->format.format0_0.timeAlloc.numSymb   = puschInfo->tdAlloc.numSymb;
688    dciInfo->format.format0_0.rowIndex            = 0; /* row Index */
689    dciInfo->format.format0_0.mcs                 = puschInfo->tbInfo.mcs;
690    dciInfo->format.format0_0.harqProcId          = puschInfo->harqProcId;
691    dciInfo->format.format0_0.puschHopFlag        = FALSE; /* disabled */
692    dciInfo->format.format0_0.freqHopFlag         = FALSE; /* disabled */
693    dciInfo->format.format0_0.ndi                 = puschInfo->tbInfo.ndi; /* new transmission */
694    dciInfo->format.format0_0.rv                  = puschInfo->tbInfo.rv;
695    dciInfo->format.format0_0.tpcCmd              = 0; //Sphoorthi TODO: check
696    dciInfo->format.format0_0.sUlCfgd             = FALSE; /* SUL not configured */
697    
698    /* Fill DCI Structure */
699    dciInfo->dciInfo.rnti                              = ueCb->crnti;
700    dciInfo->dciInfo.scramblingId                      = cellCb->cellCfg.phyCellId;
701    dciInfo->dciInfo.scramblingRnti                    = 0;
702    dciInfo->dciInfo.cceIndex                          = 0; /* 0-3 for UL and 4-7 for DL */
703    dciInfo->dciInfo.aggregLevel                       = 4;
704    dciInfo->dciInfo.beamPdcchInfo.numPrgs             = 1;
705    dciInfo->dciInfo.beamPdcchInfo.prgSize             = 1;
706    dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces     = 0;
707    dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx        = 0;
708    dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0]   = 0;
709    dciInfo->dciInfo.txPdcchPower.powerValue           = 0;
710    dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
711    dciInfo->dciInfo.pdschCfg                          = NULL; /* No DL data being sent */
712
713    return ROK;
714 }
715
716 /*******************************************************************
717  *
718  * @brief Function to Modify Ue Config request from MAC
719  *
720  * @details
721  *
722  *    Function : MacSchModUeConfigReq
723  *
724  *    Functionality: Function to modify Ue Config request from MAC
725  *
726  * @params[in] 
727  * @return ROK     - success
728  *         RFAILED - failure
729  *
730  * ****************************************************************/
731 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
732 {
733    uint8_t ueIdx, lcIdx, ret = ROK;
734    SchCellCb    *cellCb = NULLP;
735    SchUeCb      *ueCb = NULLP;
736    SchUeCfgRsp  cfgRsp;
737    Inst         inst = pst->dstInst - 1;
738    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
739   
740 #ifdef CALL_FLOW_DEBUG_LOG
741    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
742 #endif
743
744    if(!ueCfg)
745    {
746       DU_LOG("\nERROR  -->  SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
747       return RFAILED;
748    }
749    DU_LOG("\nDEBUG  -->  SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
750    cellCb = getSchCellCb(pst->event, inst, ueCfg);
751
752    /* Search if UE already configured */
753    GET_UE_IDX(ueCfg->crnti, ueIdx);
754    ueCb = &cellCb->ueCb[ueIdx -1];
755    
756    if(!ueCb)
757    {
758       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at MacSchModUeConfigReq() ");
759       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
760       return RFAILED;
761    }
762    if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
763    {
764       /* Found the UeCb to Reconfig */
765       ret = fillSchUeCb(ueCb, ueCfg);
766       if(ret == ROK)
767       {
768          ueCb->cellCb = cellCb;
769          ueCb->srRcvd = false;
770          ueCb->bsrRcvd = false;
771          for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
772             ueCb->bsrInfo[lcIdx].dataVol = 0;
773
774          SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
775       }
776    }
777    return ret;
778 }
779
780 /*******************************************************************
781 *
782 * @brief Fill and send UE delete response to MAC
783 *
784 * @details
785 *
786 *    Function :  SchSendUeDeleteRspToMac
787 *
788 *    Functionality: Fill and send UE delete response to MAC
789 *
790 * @params[in] Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, 
791 *              ErrorCause cause
792 * @return ROK     - success
793 *         RFAILED - failure
794 *
795 * ****************************************************************/
796 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, ErrorCause cause)
797 {
798     Pst rspPst;
799     SchUeDeleteRsp  delRsp;
800     
801     memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
802     delRsp.cellId = ueDelete->cellId;
803     delRsp.crnti = ueDelete->crnti;
804     delRsp.rsp = result; 
805     delRsp.cause = cause; 
806
807     /* Filling response post */
808     memset(&rspPst, 0, sizeof(Pst));
809     FILL_PST_SCH_TO_MAC(rspPst, inst);
810     rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
811     SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
812 }
813
814 /*******************************************************************
815 *
816 * @brief Function to delete Sch Pucch ResrcCfg
817 *
818 * @details
819 *
820 *    Function : deleteSchPucchResrcCfg 
821 *
822 *    Functionality: Function to delete Sch Pucch ResrcCfg
823 *
824 * @params[in] SchPucchResrcCfg *resrc
825 * @return void 
826 *
827 * ****************************************************************/
828
829 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
830 {
831    uint8_t rsrcIdx=0;
832    for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
833    {
834       switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
835       {
836          case PUCCH_FORMAT_0:
837          {
838             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
839             sizeof(SchPucchFormat0));
840             break;
841          }
842          case PUCCH_FORMAT_1:
843          {
844             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
845             sizeof(SchPucchFormat1));
846             break;
847          }
848          case PUCCH_FORMAT_2:
849          {
850             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
851             sizeof(SchPucchFormat2_3));
852             break;
853          }
854          case PUCCH_FORMAT_3:
855          {
856             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
857             sizeof(SchPucchFormat2_3));
858             break;
859          }
860          case PUCCH_FORMAT_4:
861          {
862             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
863             sizeof(SchPucchFormat4));
864             break;
865          }
866       }
867    }
868 }
869
870 /*******************************************************************
871 *
872 * @brief Function to delete SCH Pdsch ServCellCfg
873 *
874 * @details
875 *
876 *    Function : deleteSchPdschServCellCfg
877 *
878 *    Functionality: Function to delete SCH Pdsch ServCellCfg
879 *
880 * @params[in] SchPdschServCellCfg *pdschServCellCfg
881 * @return void 
882 *
883 * ****************************************************************/
884
885 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
886 {
887    SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
888    SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
889    SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
890    SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
891 }
892
893 /*******************************************************************
894 *
895 * @brief Function to  delete SCH UeCb
896 *
897 * @details
898 *
899 *    Function : deleteSchUeCb 
900 *
901 *    Functionality: Function to delete SCH UeCb
902 *
903 * @params[in]
904 * @return ROK     - success
905 *         RFAILED - failure
906 *
907 * ****************************************************************/
908 void deleteSchUeCb(SchUeCb *ueCb) 
909 {
910    uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
911    SchPucchCfg *pucchCfg = NULLP;
912    SchPdschConfig *pdschCfg = NULLP;
913    CmLListCp *lcLL  = NULLP;
914
915    if(ueCb)
916    {
917       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
918       if(ueCb->ueCfg.spCellCfgPres)
919       {
920          if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
921          {
922             pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
923             for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
924                SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
925          }
926
927          if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
928          {
929             pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
930             SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
931             if(pucchCfg->resrc)
932             {
933                deleteSchPucchResrcCfg(pucchCfg->resrc);
934                SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
935             }
936             SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
937             SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
938             SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
939             SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
940             SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
941             SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
942             SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));  
943             SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
944             SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
945          }
946          SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
947          deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
948       }
949       /*Need to Free the memory allocated for S-NSSAI*/
950       for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
951       {
952          SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
953          SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
954       }
955
956       /*Clearing out Dedicated LC list*/
957       if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
958       {
959          lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
960          deleteLcLL(lcLL);
961          SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
962       }
963       if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
964       {
965          lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
966          deleteLcLL(lcLL);
967          SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
968       }
969       /*Deleteing the Default LC list*/
970       lcLL = &(ueCb->dlLcPrbEst.defLcList);
971       deleteLcLL(lcLL);
972
973       lcLL = &(ueCb->ulLcPrbEst.defLcList);
974       deleteLcLL(lcLL);
975
976       memset(ueCb, 0, sizeof(SchUeCb));
977    }
978 }
979
980 /*******************************************************************
981 *
982 * @brief Function for Ue Delete request from MAC to SCH
983 *
984 * @details
985 *
986 *    Function : MacSchUeDeleteReq 
987 *
988 *    Functionality: Function for Ue Delete request from MAC to SCH
989 *
990 * @params[in] Pst *pst, SchUeDelete  *ueDelete
991 * @return ROK     - success
992 *         RFAILED - failure
993 *
994 * ****************************************************************/
995 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete  *ueDelete)
996 {
997     uint8_t      idx=0, ueId=0, ueIdToDel=0, ret=ROK;
998     ErrorCause   result;
999     SchCellCb    *cellCb = NULLP;
1000     Inst         inst = pst->dstInst - 1;
1001     CmLList      *node = NULL, *next = NULL;
1002    
1003 #ifdef CALL_FLOW_DEBUG_LOG
1004     DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1005 #endif
1006
1007     if(!ueDelete)
1008     {
1009        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1010        ret = RFAILED;
1011     }
1012     DU_LOG("\nDEBUG  -->  SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1013     
1014     cellCb = schCb[inst].cells[idx];
1015
1016     if(cellCb->cellId != ueDelete->cellId)
1017     {
1018        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): cell Id is not available");
1019        result =  INVALID_CELLID;
1020     }
1021     else
1022     {
1023        GET_UE_IDX(ueDelete->crnti, ueId);
1024        if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1025        {
1026           deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1027
1028           /* Remove UE from ueToBeScheduled list */
1029           node = cellCb->ueToBeScheduled.first;
1030           while(node)
1031           {
1032              next = node->next;
1033              ueId = *(uint8_t *)node->node;
1034              if(ueId == ueIdToDel)
1035              {
1036                 SCH_FREE(node->node, sizeof(uint8_t));
1037                 cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1038                 break;
1039              }
1040              node = next;
1041           }
1042           cellCb->numActvUe--;
1043           result = NOT_APPLICABLE;
1044        }
1045        else
1046        {
1047           DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): SchUeCb not found");
1048           result =  INVALID_UEIDX;
1049        }
1050     }
1051     
1052     if(result == NOT_APPLICABLE)
1053     {
1054        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1055     }
1056     else
1057     {
1058        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1059        ret = RFAILED;
1060     }
1061     return ret;
1062 }
1063
1064 /*******************************************************************
1065  *
1066  * @brief Fill and send Cell delete response to MAC
1067  *
1068  * @details
1069  *
1070  *    Function :  SchSendCellDeleteRspToMac
1071  *
1072  *    Functionality: Fill and send Cell delete response to MAC
1073  *
1074  * @params[in] SchCellDelete  *ueDelete, Inst inst, SchMacRsp result
1075  * @return ROK     - success
1076  *         RFAILED - failure
1077  *
1078  * ****************************************************************/
1079 uint8_t SchSendCellDeleteRspToMac(SchCellDelete  *ueDelete, Inst inst, SchMacRsp result)
1080 {
1081    Pst rspPst;
1082    uint8_t ret=0;
1083    
1084    SchCellDeleteRsp  delRsp;
1085
1086    DU_LOG("\nINFO   --> SCH : Filling Cell Delete response");
1087    memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1088    delRsp.cellId = ueDelete->cellId;
1089    delRsp.rsp = result;
1090
1091    /* Filling response post */
1092    memset(&rspPst, 0, sizeof(Pst));
1093    FILL_PST_SCH_TO_MAC(rspPst, inst);
1094    rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1095    ret =  SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1096    if(ret == RFAILED)
1097    {
1098       DU_LOG("\nERROR  -->  SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1099       return ret;
1100    }
1101    return ret;
1102 }
1103
1104 /*******************************************************************
1105  *
1106  * @brief Function for cellCb Deletion 
1107  *
1108  * @details
1109  *
1110  *    Function : deleteSchCellCb 
1111  *
1112  *    Functionality: Function for cellCb Deletion 
1113  *
1114  * @params[in] SchCellDelete  *cellDelete
1115  * @return ROK     - success
1116  *         RFAILED - failure
1117  *
1118  * ****************************************************************/
1119 void deleteSchCellCb(SchCellCb *cellCb)
1120 {
1121    uint8_t sliceIdx=0, slotIdx=0;
1122    CmLListCp *list=NULL;
1123    CmLList *node=NULL, *next=NULL;
1124
1125    if(cellCb->schDlSlotInfo)
1126    {
1127       for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1128       {
1129          list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1130          node = list->first;
1131          while(node)
1132          {
1133             next = node->next;
1134             SCH_FREE(node->node, sizeof(FreePrbBlock));
1135             deleteNodeFromLList(list, node);
1136             node = next;
1137          }
1138          SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1139       }
1140       SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1141    }
1142
1143    if(cellCb->schUlSlotInfo)
1144    {
1145       for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1146       {
1147          list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1148          node = list->first;
1149          while(node)
1150          {
1151             next = node->next;
1152             SCH_FREE(node->node, sizeof(FreePrbBlock));
1153             deleteNodeFromLList(list, node);
1154             node = next;
1155          }
1156          SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));  
1157       }
1158       SCH_FREE(cellCb->schUlSlotInfo,  cellCb->numSlots * sizeof(SchUlSlotInfo*));
1159    }
1160
1161    if(cellCb->cellCfg.snssai)
1162    {
1163       for(sliceIdx=0; sliceIdx<cellCb->cellCfg.numSliceSupport; sliceIdx++)
1164       {
1165          SCH_FREE(cellCb->cellCfg.snssai[sliceIdx], sizeof(Snssai));
1166       }
1167       SCH_FREE(cellCb->cellCfg.snssai, cellCb->cellCfg.numSliceSupport*sizeof(Snssai*));
1168    }
1169    SCH_FREE(cellCb->cellCfg.rrmPolicy, sizeof(SchRrmPolicy));
1170
1171    /* Remove all UE from ueToBeScheduled list and deallocate */
1172    node = cellCb->ueToBeScheduled.first;
1173    while(node)
1174    {
1175       next = node->next;
1176       SCH_FREE(node->node, sizeof(uint8_t));
1177       cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1178       node = next;
1179    }
1180
1181    memset(cellCb, 0, sizeof(SchCellCb));
1182
1183 }
1184
1185 /*******************************************************************
1186  *
1187  * @brief Function for cell Delete request from MAC to SCH
1188  *
1189  * @details
1190  *
1191  *    Function : MacSchCellDeleteReq
1192  *
1193  *    Functionality: Function for cell Delete request from MAC to SCH
1194  *
1195  * @params[in] Pst *pst, SchCellDelete  *cellDelete
1196  * @return ROK     - success
1197  *         RFAILED - failure
1198  *
1199  * ****************************************************************/
1200
1201 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete  *cellDelete)
1202 {
1203    uint8_t   cellIdx=0, ret = RFAILED;
1204    Inst      inst = pst->dstInst - 1;
1205    SchMacRsp result= RSP_OK;
1206    
1207 #ifdef CALL_FLOW_DEBUG_LOG
1208    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1209 #endif   
1210
1211    if(!cellDelete)
1212    {
1213       DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1214    }
1215    else
1216    {
1217       GET_CELL_IDX(cellDelete->cellId, cellIdx);
1218       if(schCb[inst].cells[cellIdx] == NULLP)
1219       { 
1220          DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1221          result = RSP_NOK;
1222       }
1223       else
1224       {
1225          if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1226          {
1227             deleteSchCellCb(schCb[inst].cells[cellIdx]);
1228             result = RSP_OK;
1229             ret = ROK;
1230             SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1231             DU_LOG("\nINFO   -->  SCH : Sending Cell Delete response to MAC");
1232          }
1233          else
1234          {
1235             DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1236             result = RSP_NOK;
1237          }
1238       }
1239
1240       if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1241       {
1242          DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1243          ret =  RFAILED;
1244       }
1245
1246    }
1247    return ret;   
1248 }
1249
1250 /**********************************************************************
1251   End of file
1252  **********************************************************************/