[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-423]UE context creation at MAC/SCH in Target DU
[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->duUeF1apId = ueCfg->duUeF1apId;
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.duUeF1apId = ueCfg->duUeF1apId;
263    ueCb->ueCfg.crnti = ueCfg->crnti;
264    if(ueCfg->macCellGrpCfgPres == true)
265    {
266       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg)); 
267       ueCb->ueCfg.macCellGrpCfgPres = true;
268    }
269
270    if(ueCfg->phyCellGrpCfgPres == true)
271    {
272       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
273       ueCb->ueCfg.phyCellGrpCfgPres = true;
274    }
275
276    if(ueCfg->spCellCfgPres == true)
277    {
278       memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
279
280       covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
281             freqDomainResource);
282       memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
283       memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
284
285       ueCb->ueCfg.spCellCfgPres = true;
286       dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
287       if(ueCb->cellCb)
288       {
289          if(dlDataToUlAck)
290          {
291             BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
292                   ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
293                   dlDataToUlAck->dlDataToUlAckList);
294             ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1TblPrsnt = true;
295             BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
296                   ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
297                   NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
298                   ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2TblPrsnt = true;
299          }
300       }
301    }
302
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    if(ueCfg->crnti)
529    {
530       GET_UE_ID(ueCfg->crnti, ueId);
531       ueCb = &cellCb->ueCb[ueId -1];
532    }
533    else
534       ueCb = &cellCb->hoUeCb[ueCfg->duUeF1apId - 1];
535
536    if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
537    {
538       DU_LOG("\nDEBUG  -->  SCH : CRNTI %d already configured ", ueCfg->crnti);
539       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
540       return ROK;
541    }
542
543    /* Fill received Ue Configuration in UeCb */
544    memset(ueCb, 0, sizeof(SchUeCb));
545    ueCb->ueId = ueId;
546    ueCb->crnti = ueCfg->crnti;
547    if(ueCb->crnti)
548       ueCb->state = SCH_UE_STATE_ACTIVE;
549    else
550       ueCb->state = SCH_UE_HANDIN_IN_PROGRESS;
551
552    ret = fillSchUeCb(inst, ueCb, ueCfg);
553    if(ret == ROK)
554    {
555       if(ueCb->state == SCH_UE_STATE_ACTIVE)
556       {
557          cellCb->numActvUe++;
558          SET_ONE_BIT(ueCb->ueId, cellCb->actvUeBitMap);
559       }
560       ueCb->cellCb = cellCb;
561       ueCb->srRcvd = false;
562       ueCb->bsrRcvd = false;
563       for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
564          ueCb->bsrInfo[lcIdx].dataVol = 0;
565
566       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
567    }
568    return ret;
569 }
570
571 /*******************************************************************
572 *
573 * @brief Fills PUSCH UL allocation
574 *
575 * @details
576 *
577 *    Function : schFillPuschAlloc
578 *
579 *    Functionality: fills PUSCH info
580 *
581 * @params[in]
582 * @return ROK     - success
583 *         RFAILED - failure
584 *
585 * ****************************************************************/
586 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo puschTime, uint32_t tbSize, 
587                             uint8_t startSymb, uint8_t symbLen, uint16_t startPrb)
588 {
589   uint8_t  numRb          = 0;
590   SchCellCb *cellCb       = NULLP;
591   SchUlSlotInfo *schUlSlotInfo = NULLP;
592   SchPuschInfo puschInfo;
593   
594   if(ueCb == NULLP)
595   {
596     DU_LOG("\nERROR --> SCH: UE CB is empty");
597     return RFAILED;
598   }
599
600   cellCb = ueCb->cellCb;
601   if(cellCb == NULLP)
602   {
603     DU_LOG("\nERROR --> SCH: CELL CB is empty");
604     return RFAILED;
605   }
606
607   tbSize  +=  UL_TX_BUFFER_SIZE; /*  2 bytes header + some buffer */
608   numRb   = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
609   allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startPrb, numRb);
610
611   puschInfo.crnti             = ueCb->crnti; 
612   puschInfo.harqProcId        = SCH_HARQ_PROC_ID;
613   puschInfo.resAllocType      = SCH_ALLOC_TYPE_1;
614   puschInfo.fdAlloc.startPrb  = startPrb;
615   puschInfo.fdAlloc.numPrb    = numRb;
616   puschInfo.tdAlloc.startSymb = startSymb;
617   puschInfo.tdAlloc.numSymb   = symbLen;
618   puschInfo.tbInfo.qamOrder   = ueCb->ueCfg.ulModInfo.modOrder;
619   puschInfo.tbInfo.mcs        = ueCb->ueCfg.ulModInfo.mcsIndex;
620   puschInfo.tbInfo.mcsTable   = ueCb->ueCfg.ulModInfo.mcsTable;
621   puschInfo.tbInfo.ndi        = 1; /* new transmission */
622   puschInfo.tbInfo.rv         = 0;
623   puschInfo.tbInfo.tbSize     = tbSize;
624   puschInfo.dmrsMappingType   = DMRS_MAP_TYPE_A;  /* Setting Type-A */
625   puschInfo.nrOfDmrsSymbols   = NUM_DMRS_SYMBOLS;
626   puschInfo.dmrsAddPos        = DMRS_ADDITIONAL_POS;
627
628   schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
629   SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
630   if(!schUlSlotInfo->schPuschInfo)
631   {
632      DU_LOG("\nERROR  -->  SCH: Memory allocation failed in schAllocMsg3Pusch");
633      return RFAILED;
634   }
635   memcpy(schUlSlotInfo->schPuschInfo, &puschInfo, sizeof(SchPuschInfo));
636
637   return ROK;
638 }
639
640 /*******************************************************************
641  *
642  * @brief Fills DCI for UL grant
643  *
644  * @details
645  *
646  *    Function : schFillUlDci
647  *
648  *    Functionality: fills DCI for UL grant in response to BSR
649  *
650  * @params[in]
651  * @return ROK     - success
652  *         RFAILED - failure
653  *
654  * ****************************************************************/
655 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo *puschInfo, DciInfo *dciInfo)
656 {
657    SchCellCb         *cellCb  = ueCb->cellCb;
658    SchControlRsrcSet coreset1 ;
659   
660    memset(&coreset1, 0, sizeof(SchControlRsrcSet));
661    if(ueCb->ueCfg.spCellCfgPres == true)
662    {
663      coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
664    }
665    
666    dciInfo->cellId = cellCb->cellId;
667    dciInfo->crnti  = ueCb->crnti;
668
669    /* fill bwp cfg */
670    dciInfo->bwpCfg.subcarrierSpacing  = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
671    dciInfo->bwpCfg.cyclicPrefix       = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
672    dciInfo->bwpCfg.freqAlloc.startPrb = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb;
673    dciInfo->bwpCfg.freqAlloc.numPrb   = cellCb->cellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb; 
674
675    /*fill coreset cfg */
676    //Considering number of RBs in coreset1 is same as coreset0
677    dciInfo->coresetCfg.coreSetSize      = coresetIdxTable[0][1];
678    //Considering coreset1 also starts from same symbol as coreset0
679    dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
680    dciInfo->coresetCfg.durationSymbols  = coreset1.duration;
681    memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
682    
683    dciInfo->coresetCfg.cceRegMappingType   = coreset1.cceRegMappingType; /* non-interleaved */
684    dciInfo->coresetCfg.regBundleSize       = 6; /* must be 6 for non-interleaved */
685    dciInfo->coresetCfg.interleaverSize     = 0; /* NA for non-interleaved */
686    dciInfo->coresetCfg.coreSetType         = 1; /* non PBCH coreset */
687    dciInfo->coresetCfg.shiftIndex          = cellCb->cellCfg.phyCellId;
688    dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
689    dciInfo->coresetCfg.cceIndex            = 0; /* 0-3 for UL and 4-7 for DL */
690    dciInfo->coresetCfg.aggregationLevel    = 4; /* same as for sib1 */
691    
692    dciInfo->formatType = FORMAT0_0;
693    
694    /* fill UL grant */
695    dciInfo->format.format0_0.resourceAllocType   = puschInfo->resAllocType;
696    dciInfo->format.format0_0.freqAlloc.startPrb  = puschInfo->fdAlloc.startPrb;
697    dciInfo->format.format0_0.freqAlloc.numPrb    = puschInfo->fdAlloc.numPrb;
698    dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo->tdAlloc.startSymb;
699    dciInfo->format.format0_0.timeAlloc.numSymb   = puschInfo->tdAlloc.numSymb;
700    dciInfo->format.format0_0.rowIndex            = 0; /* row Index */
701    dciInfo->format.format0_0.mcs                 = puschInfo->tbInfo.mcs;
702    dciInfo->format.format0_0.harqProcId          = puschInfo->harqProcId;
703    dciInfo->format.format0_0.puschHopFlag        = FALSE; /* disabled */
704    dciInfo->format.format0_0.freqHopFlag         = FALSE; /* disabled */
705    dciInfo->format.format0_0.ndi                 = puschInfo->tbInfo.ndi; /* new transmission */
706    dciInfo->format.format0_0.rv                  = puschInfo->tbInfo.rv;
707    dciInfo->format.format0_0.tpcCmd              = 0; //Sphoorthi TODO: check
708    dciInfo->format.format0_0.sUlCfgd             = FALSE; /* SUL not configured */
709    
710    /* Fill DCI Structure */
711    dciInfo->dciInfo.rnti                              = ueCb->crnti;
712    dciInfo->dciInfo.scramblingId                      = cellCb->cellCfg.phyCellId;
713    dciInfo->dciInfo.scramblingRnti                    = 0;
714    dciInfo->dciInfo.cceIndex                          = 0; /* 0-3 for UL and 4-7 for DL */
715    dciInfo->dciInfo.aggregLevel                       = 4;
716    dciInfo->dciInfo.beamPdcchInfo.numPrgs             = 1;
717    dciInfo->dciInfo.beamPdcchInfo.prgSize             = 1;
718    dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces     = 0;
719    dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx        = 0;
720    dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0]   = 0;
721    dciInfo->dciInfo.txPdcchPower.powerValue           = 0;
722    dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
723    dciInfo->dciInfo.pdschCfg                          = NULL; /* No DL data being sent */
724
725    return ROK;
726 }
727
728 /*******************************************************************
729  *
730  * @brief Function to Modify Ue Config request from MAC
731  *
732  * @details
733  *
734  *    Function : MacSchModUeConfigReq
735  *
736  *    Functionality: Function to modify Ue Config request from MAC
737  *
738  * @params[in] 
739  * @return ROK     - success
740  *         RFAILED - failure
741  *
742  * ****************************************************************/
743 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
744 {
745    uint8_t ueId, lcIdx, ret = ROK;
746    SchCellCb    *cellCb = NULLP;
747    SchUeCb      *ueCb = NULLP;
748    SchUeCfgRsp  cfgRsp;
749    Inst         inst = pst->dstInst - SCH_INST_START;
750    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
751   
752 #ifdef CALL_FLOW_DEBUG_LOG
753    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
754 #endif
755
756    if(!ueCfg)
757    {
758       DU_LOG("\nERROR  -->  SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
759       return RFAILED;
760    }
761    DU_LOG("\nDEBUG  -->  SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
762    cellCb = getSchCellCb(pst->event, inst, ueCfg);
763
764    /* Search if UE already configured */
765    GET_UE_ID(ueCfg->crnti, ueId);
766    ueCb = &cellCb->ueCb[ueId -1];
767    
768    if(!ueCb)
769    {
770       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at MacSchModUeConfigReq() ");
771       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
772       return RFAILED;
773    }
774    if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
775    {
776       /* Found the UeCb to Reconfig */
777       ret = fillSchUeCb(inst, ueCb, ueCfg);
778       if(ret == ROK)
779       {
780          ueCb->cellCb = cellCb;
781          ueCb->srRcvd = false;
782          ueCb->bsrRcvd = false;
783          for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
784             ueCb->bsrInfo[lcIdx].dataVol = 0;
785
786          SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
787       }
788    }
789    return ret;
790 }
791
792 /*******************************************************************
793 *
794 * @brief Fill and send UE delete response to MAC
795 *
796 * @details
797 *
798 *    Function :  SchSendUeDeleteRspToMac
799 *
800 *    Functionality: Fill and send UE delete response to MAC
801 *
802 * @params[in] Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, 
803 *              ErrorCause cause
804 * @return ROK     - success
805 *         RFAILED - failure
806 *
807 * ****************************************************************/
808 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, ErrorCause cause)
809 {
810     Pst rspPst;
811     SchUeDeleteRsp  delRsp;
812     
813     memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
814     delRsp.cellId = ueDelete->cellId;
815     delRsp.crnti = ueDelete->crnti;
816     delRsp.rsp = result; 
817     delRsp.cause = cause; 
818
819     /* Filling response post */
820     memset(&rspPst, 0, sizeof(Pst));
821     FILL_PST_SCH_TO_MAC(rspPst, inst);
822     rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
823     SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
824 }
825
826 /*******************************************************************
827 *
828 * @brief Function to delete Sch Pucch ResrcCfg
829 *
830 * @details
831 *
832 *    Function : deleteSchPucchResrcCfg 
833 *
834 *    Functionality: Function to delete Sch Pucch ResrcCfg
835 *
836 * @params[in] SchPucchResrcCfg *resrc
837 * @return void 
838 *
839 * ****************************************************************/
840
841 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
842 {
843    uint8_t rsrcIdx=0;
844    for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
845    {
846       switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
847       {
848          case PUCCH_FORMAT_0:
849          {
850             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
851             sizeof(SchPucchFormat0));
852             break;
853          }
854          case PUCCH_FORMAT_1:
855          {
856             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
857             sizeof(SchPucchFormat1));
858             break;
859          }
860          case PUCCH_FORMAT_2:
861          {
862             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
863             sizeof(SchPucchFormat2_3));
864             break;
865          }
866          case PUCCH_FORMAT_3:
867          {
868             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
869             sizeof(SchPucchFormat2_3));
870             break;
871          }
872          case PUCCH_FORMAT_4:
873          {
874             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
875             sizeof(SchPucchFormat4));
876             break;
877          }
878       }
879    }
880 }
881
882 /*******************************************************************
883 *
884 * @brief Function to delete SCH Pdsch ServCellCfg
885 *
886 * @details
887 *
888 *    Function : deleteSchPdschServCellCfg
889 *
890 *    Functionality: Function to delete SCH Pdsch ServCellCfg
891 *
892 * @params[in] SchPdschServCellCfg *pdschServCellCfg
893 * @return void 
894 *
895 * ****************************************************************/
896
897 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
898 {
899    SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
900    SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
901    SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
902    SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
903 }
904
905 /*******************************************************************
906 *
907 * @brief Function to  delete SCH UeCb
908 *
909 * @details
910 *
911 *    Function : deleteSchUeCb 
912 *
913 *    Functionality: Function to delete SCH UeCb
914 *
915 * @params[in]
916 * @return ROK     - success
917 *         RFAILED - failure
918 *
919 * ****************************************************************/
920 void deleteSchUeCb(SchUeCb *ueCb) 
921 {
922    uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
923    SchPucchCfg *pucchCfg = NULLP;
924    SchPdschConfig *pdschCfg = NULLP;
925    CmLListCp *lcLL  = NULLP;
926
927    if(ueCb)
928    {
929       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
930       if(ueCb->ueCfg.spCellCfgPres)
931       {
932          if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
933          {
934             pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
935             for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
936                SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
937          }
938
939          if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
940          {
941             pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
942             SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
943             if(pucchCfg->resrc)
944             {
945                deleteSchPucchResrcCfg(pucchCfg->resrc);
946                SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
947             }
948             SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
949             SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
950             SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
951             SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
952             SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
953             SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
954             SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));  
955             SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
956             SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
957          }
958          SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
959          deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
960       }
961       /*Need to Free the memory allocated for S-NSSAI*/
962       for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
963       {
964          SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
965          SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
966       }
967
968       /*Clearing out Dedicated LC list*/
969       if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
970       {
971          lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
972          deleteLcLL(lcLL);
973          SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
974       }
975       if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
976       {
977          lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
978          deleteLcLL(lcLL);
979          SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
980       }
981       /*Deleteing the Default LC list*/
982       lcLL = &(ueCb->dlLcPrbEst.defLcList);
983       deleteLcLL(lcLL);
984
985       lcLL = &(ueCb->ulLcPrbEst.defLcList);
986       deleteLcLL(lcLL);
987
988       memset(ueCb, 0, sizeof(SchUeCb));
989    }
990 }
991
992 /*******************************************************************
993 *
994 * @brief Function for Ue Delete request from MAC to SCH
995 *
996 * @details
997 *
998 *    Function : MacSchUeDeleteReq 
999 *
1000 *    Functionality: Function for Ue Delete request from MAC to SCH
1001 *
1002 * @params[in] Pst *pst, SchUeDelete  *ueDelete
1003 * @return ROK     - success
1004 *         RFAILED - failure
1005 *
1006 * ****************************************************************/
1007 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete  *ueDelete)
1008 {
1009     uint8_t      idx=0, ueId=0, ueIdToDel=0, ret=ROK;
1010     ErrorCause   result;
1011     SchCellCb    *cellCb = NULLP;
1012     Inst         inst = pst->dstInst - SCH_INST_START;
1013     CmLList      *node = NULL, *next = NULL;
1014    
1015 #ifdef CALL_FLOW_DEBUG_LOG
1016     DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1017 #endif
1018
1019     if(!ueDelete)
1020     {
1021        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1022        ret = RFAILED;
1023     }
1024     DU_LOG("\nDEBUG  -->  SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1025     
1026     cellCb = schCb[inst].cells[idx];
1027
1028     if(cellCb->cellId != ueDelete->cellId)
1029     {
1030        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): cell Id is not available");
1031        result =  INVALID_CELLID;
1032     }
1033     else
1034     {
1035        GET_UE_ID(ueDelete->crnti, ueId);
1036        if(( cellCb->ueCb[ueId-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueId-1].state == SCH_UE_STATE_ACTIVE))
1037        {
1038           deleteSchUeCb(&cellCb->ueCb[ueId-1]);
1039           ueIdToDel  = ueId;
1040           /* Remove UE from ueToBeScheduled list */
1041           node = cellCb->ueToBeScheduled.first;
1042           while(node)
1043           {
1044              next = node->next;
1045              ueId = *(uint8_t *)node->node;
1046              if(ueId == ueIdToDel)
1047              {
1048                 SCH_FREE(node->node, sizeof(uint8_t));
1049                 deleteNodeFromLList(&cellCb->ueToBeScheduled, node);
1050                 break;
1051              }
1052              node = next;
1053           }
1054           cellCb->numActvUe--;
1055           result = NOT_APPLICABLE;
1056        }
1057        else
1058        {
1059           DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): SchUeCb not found");
1060           result =  INVALID_UEID;
1061        }
1062     }
1063     
1064     if(result == NOT_APPLICABLE)
1065     {
1066        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1067     }
1068     else
1069     {
1070        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1071        ret = RFAILED;
1072     }
1073     return ret;
1074 }
1075
1076 /*******************************************************************
1077  *
1078  * @brief Fill and send Cell delete response to MAC
1079  *
1080  * @details
1081  *
1082  *    Function :  SchSendCellDeleteRspToMac
1083  *
1084  *    Functionality: Fill and send Cell delete response to MAC
1085  *
1086  * @params[in] SchCellDelete  *ueDelete, Inst inst, SchMacRsp result
1087  * @return ROK     - success
1088  *         RFAILED - failure
1089  *
1090  * ****************************************************************/
1091 uint8_t SchSendCellDeleteRspToMac(SchCellDelete  *ueDelete, Inst inst, SchMacRsp result)
1092 {
1093    Pst rspPst;
1094    uint8_t ret=0;
1095    
1096    SchCellDeleteRsp  delRsp;
1097
1098    DU_LOG("\nINFO   --> SCH : Filling Cell Delete response");
1099    memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1100    delRsp.cellId = ueDelete->cellId;
1101    delRsp.rsp = result;
1102
1103    /* Filling response post */
1104    memset(&rspPst, 0, sizeof(Pst));
1105    FILL_PST_SCH_TO_MAC(rspPst, inst);
1106    rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1107    ret =  SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1108    if(ret == RFAILED)
1109    {
1110       DU_LOG("\nERROR  -->  SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1111       return ret;
1112    }
1113    return ret;
1114 }
1115
1116 /*******************************************************************
1117  *
1118  * @brief Function for cellCb Deletion 
1119  *
1120  * @details
1121  *
1122  *    Function : deleteSchCellCb 
1123  *
1124  *    Functionality: Function for cellCb Deletion 
1125  *
1126  * @params[in] SchCellDelete  *cellDelete
1127  * @return ROK     - success
1128  *         RFAILED - failure
1129  *
1130  * ****************************************************************/
1131 void deleteSchCellCb(SchCellCb *cellCb)
1132 {
1133    uint8_t sliceIdx=0, slotIdx=0;
1134    CmLListCp *list=NULL;
1135    CmLList *node=NULL, *next=NULL;
1136
1137    if(cellCb->schDlSlotInfo)
1138    {
1139       for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1140       {
1141          list = &cellCb->schDlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1142          node = list->first;
1143          while(node)
1144          {
1145             next = node->next;
1146             SCH_FREE(node->node, sizeof(FreePrbBlock));
1147             deleteNodeFromLList(list, node);
1148             node = next;
1149          }
1150          SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1151       }
1152       SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1153    }
1154
1155    if(cellCb->schUlSlotInfo)
1156    {
1157       for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1158       {
1159          list = &cellCb->schUlSlotInfo[slotIdx]->prbAlloc.freePrbBlockList;
1160          node = list->first;
1161          while(node)
1162          {
1163             next = node->next;
1164             SCH_FREE(node->node, sizeof(FreePrbBlock));
1165             deleteNodeFromLList(list, node);
1166             node = next;
1167          }
1168          SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));  
1169       }
1170       SCH_FREE(cellCb->schUlSlotInfo,  cellCb->numSlots * sizeof(SchUlSlotInfo*));
1171    }
1172
1173    if(cellCb->cellCfg.plmnInfoList.snssai)
1174    {
1175       for(sliceIdx=0; sliceIdx<cellCb->cellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
1176       {
1177          SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
1178       }
1179       SCH_FREE(cellCb->cellCfg.plmnInfoList.snssai, cellCb->cellCfg.plmnInfoList.numSliceSupport*sizeof(Snssai*));
1180    }
1181
1182    /* Remove all UE from ueToBeScheduled list and deallocate */
1183    node = cellCb->ueToBeScheduled.first;
1184    while(node)
1185    {
1186       next = node->next;
1187       SCH_FREE(node->node, sizeof(uint8_t));
1188       cmLListDelFrm(&cellCb->ueToBeScheduled, node);
1189       SCH_FREE(node, sizeof(CmLList));
1190       node = next;
1191    }
1192
1193    memset(cellCb, 0, sizeof(SchCellCb));
1194
1195 }
1196
1197 /*******************************************************************
1198  *
1199  * @brief Function for cell Delete request from MAC to SCH
1200  *
1201  * @details
1202  *
1203  *    Function : MacSchCellDeleteReq
1204  *
1205  *    Functionality: Function for cell Delete request from MAC to SCH
1206  *
1207  * @params[in] Pst *pst, SchCellDelete  *cellDelete
1208  * @return ROK     - success
1209  *         RFAILED - failure
1210  *
1211  * ****************************************************************/
1212
1213 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete  *cellDelete)
1214 {
1215    uint8_t   cellIdx=0, ret = RFAILED;
1216    Inst      inst = pst->dstInst - SCH_INST_START;
1217    SchMacRsp result= RSP_OK;
1218    
1219 #ifdef CALL_FLOW_DEBUG_LOG
1220    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1221 #endif   
1222
1223    if(!cellDelete)
1224    {
1225       DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1226    }
1227    else
1228    {
1229       GET_CELL_IDX(cellDelete->cellId, cellIdx);
1230       if(schCb[inst].cells[cellIdx] == NULLP)
1231       { 
1232          DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1233          result = RSP_NOK;
1234       }
1235       else
1236       {
1237          if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1238          {
1239             deleteSchCellCb(schCb[inst].cells[cellIdx]);
1240             result = RSP_OK;
1241             ret = ROK;
1242             SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1243             DU_LOG("\nINFO   -->  SCH : Sending Cell Delete response to MAC");
1244          }
1245          else
1246          {
1247             DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1248             result = RSP_NOK;
1249          }
1250       }
1251
1252       if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1253       {
1254          DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1255          ret =  RFAILED;
1256       }
1257
1258    }
1259    return ret;   
1260 }
1261
1262 /**********************************************************************
1263   End of file
1264  **********************************************************************/