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