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