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