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