JIRA ID: ODUHIGH-381 : DL packets Scheduling as per RRM Policy
[o-du/l2.git] / src / 5gnrsch / sch_ue_mgr.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17  *******************************************************************************/
18 /* This file contains UE management handling functionality for SCH */
19
20 #include "common_def.h"
21 #include "tfu.h"
22 #include "lrg.h"
23
24 #include "tfu.x"
25 #include "lrg.x"
26 #include "du_log.h"
27 #include "du_app_mac_inf.h"
28 #include "mac_sch_interface.h"
29 #include "sch.h"
30 #include "sch_utils.h"
31
32 /* local defines */
33 SchUeCfgRspFunc SchUeCfgRspOpts[] =
34 {
35    packSchUeCfgRsp,      /* LC */
36    MacProcSchUeCfgRsp,   /* TC */
37    packSchUeCfgRsp       /* LWLC */
38 };
39
40 SchUeDeleteRspFunc SchUeDeleteRspOpts[] =
41 {
42    packSchUeDeleteRsp,      /* LC */
43    MacProcSchUeDeleteRsp,   /* TC */
44    packSchUeDeleteRsp       /* LWLC */
45 };
46
47 SchCellDeleteRspFunc SchCellDeleteRspOpts[]=
48 {
49    packSchCellDeleteRsp,      /* LC */
50    MacProcSchCellDeleteRsp,   /* TC */
51    packSchCellDeleteRsp       /* LWLC */
52 };
53
54 /*******************************************************************
55  *
56  * @brief Fill and send UE cfg response to MAC
57  *
58  * @details
59  *
60  *    Function : SchSendUeCfgRspToMac
61  *
62  *    Functionality: Fill and send UE cfg response to MAC
63  *
64  * @params[in] 
65  * @return ROK     - success
66  *         RFAILED - failure
67  *
68  * ****************************************************************/
69 void SchSendUeCfgRspToMac(uint16_t event, SchUeCfg *ueCfg, Inst inst,\
70       SchMacRsp result, SchUeCfgRsp *cfgRsp)
71 {
72    Pst rspPst;
73
74    cfgRsp->cellId = ueCfg->cellId;
75    cfgRsp->crnti = ueCfg->crnti;
76    GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
77    cfgRsp->rsp = result;   
78
79    /* Filling response post */
80    memset(&rspPst, 0, sizeof(Pst));
81    FILL_PST_SCH_TO_MAC(rspPst, inst);
82    if(event == EVENT_ADD_UE_CONFIG_REQ_TO_SCH)
83    {
84       rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
85       DU_LOG("\nINFO  -->  SCH :  Sending UE Config response to MAC");
86    }
87    else if(event == EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH)
88    {
89       rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
90       DU_LOG("\nINFO  -->  SCH :  Sending UE Reconfig response to MAC");
91    }
92    SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
93 }
94
95 /*******************************************************************
96  
97  *
98  * @brief Function to fill Dl Lc Context in SCH Ue Cb
99  *
100  * @details
101  *
102  *    Function : fillSchDlLcCtxt
103  *
104  *    Functionality: Function to fill Dl Lc Context in SCH Ue Cb
105  *
106  * @params[in] SchDlLcCtxt pointer,
107  *             SchLcCfg pointer
108  * @return void
109  *
110  * ****************************************************************/
111
112 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
113 {
114    ueCbLcCfg->lcId = lcCfg->lcId;
115    ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
116    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
117    ueCbLcCfg->bo = 0;
118    if(lcCfg->drbQos)
119    {
120      ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
121    }
122    if(lcCfg->snssai)
123    {
124      if(ueCbLcCfg->snssai == NULLP)/*In CONFIG_MOD case, no need to allocate SNSSAI memory*/
125      {
126         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
127      }
128      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
129    }
130 }
131
132 /*******************************************************************
133  *
134  * @brief Function to fill Ul Lc Context in SCH Ue Cb
135  *
136  * @details
137  *
138  *    Function : fillSchUlLcCtxt
139  *
140  *    Functionality: Function to fill Ul Lc Context in SCH Ue Cb
141  *
142  * @params[in] SchUlLcCtxt pointer,
143  *             SchLcCfg pointer
144  * @return void
145  *
146  * ****************************************************************/
147
148 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
149 {
150    ueCbLcCfg->lcId = lcCfg->lcId;
151    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
152    ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
153    ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
154    ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
155    ueCbLcCfg->pbr     = lcCfg->ulLcCfg.pbr;
156    ueCbLcCfg->bsd     = lcCfg->ulLcCfg.bsd;
157
158    if(lcCfg->drbQos)
159    {
160       ueCbLcCfg->pduSessionId = lcCfg->drbQos->pduSessionId;
161    }
162    if(lcCfg->snssai)
163    {
164      /*In CONFIG_MOD case, no need to allocate SNSSAI memory again*/
165      if(ueCbLcCfg->snssai == NULLP)
166      {
167         SCH_ALLOC(ueCbLcCfg->snssai, sizeof(Snssai));
168      }
169      memcpy(ueCbLcCfg->snssai, lcCfg->snssai,sizeof(Snssai));
170    }
171 }
172
173 /*******************************************************************
174  *
175  * @brief Function to update/allocate dedLC Info
176  *
177  * @details
178  *
179  *    Function : updateDedLcInfo
180  *
181  *    Functionality: Function to fill DLDedLcInfo
182  *
183  * @params[arg] snssai pointer,
184  *              SchRrmPolicy pointer,
185  *              SchLcPrbEstimate pointer , It will be filled
186  *              isDedicated pointer,(Address of isDedicated flag in LC Context)
187  *
188  * @return ROK      >> This LC is part of RRM MemberList.
189  *         RFAILED  >> FATAL Error
190  *         ROKIGNORE >> This LC is not part of this RRM MemberList 
191  *
192  * ****************************************************************/
193
194 uint8_t updateDedLcInfo(Snssai *snssai, SchRrmPolicy *rrmPolicy, SchLcPrbEstimate *lcPrbEst,\
195                          bool *isDedicated)
196 {
197    if(memcmp(snssai, &(rrmPolicy->memberList.snssai), sizeof(Snssai)))
198    {
199       if(lcPrbEst->dedLcInfo == NULLP)
200       {
201          SCH_ALLOC(lcPrbEst->dedLcInfo, sizeof(DedicatedLCInfo));
202          if(lcPrbEst->dedLcInfo == NULLP)
203          {
204             DU_LOG("\nINFO  -->  SCH : Memory Allocation Failed");
205             return RFAILED;
206          }
207       }
208       /*Updating latest RrmPolicy*/
209       lcPrbEst->dedLcInfo->rsvdDedicatedPRB = \
210                                               (uint16_t)(((rrmPolicy->policyDedicatedRatio)*(MAX_NUM_RB))/100);
211       *isDedicated = TRUE;
212       DU_LOG("\nINFO  -->  SCH : Updated RRM policy, reservedPOOL:%d",lcPrbEst->dedLcInfo->rsvdDedicatedPRB);
213    }
214    /*else case: This LcCtxt  is either a Default LC or this LC is part of someother RRM_MemberList*/
215    else
216    {
217       DU_LOG("\nINFO  -->  SCH : This SNSSAI is not a part of this RRMPolicy");
218    }
219    return ROK;   
220 }
221
222 /*******************************************************************
223  *
224  * @brief Function to fill SchUeCb
225  *
226  * @details
227  *
228  *    Function : fillSchUeCb
229  *
230  *    Functionality: Function to fill SchUeCb
231  *
232  * @params[in] SchUeCb pointer,
233  *             SchUeCfg pointer
234  * @return ROK/RFAILED
235  *
236  * ****************************************************************/
237
238 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
239 {
240    uint8_t   lcIdx, ueLcIdx;
241    uint8_t   freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
242    SchPdschCfgCmn pdschCfg;
243    SchPucchDlDataToUlAck *dlDataToUlAck;
244    CmLListCp *lcLL = NULLP;
245    uint8_t retDL = ROK, retUL = ROK;
246    bool isLcIdValid = FALSE;
247
248    ueCb->ueCfg.cellId = ueCfg->cellId;
249    ueCb->ueCfg.crnti = ueCfg->crnti;
250    if(ueCfg->macCellGrpCfgPres == true)
251    {
252       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg)); 
253       ueCb->ueCfg.macCellGrpCfgPres = true;
254    }
255
256    if(ueCfg->phyCellGrpCfgPres == true)
257    {
258       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
259       ueCb->ueCfg.phyCellGrpCfgPres = true;
260    }
261
262    if(ueCfg->spCellCfgPres == true)
263    {
264       memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
265
266       covertFreqDomRsrcMapToIAPIFormat(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc,\
267             freqDomainResource);
268       memset(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, 0, FREQ_DOM_RSRC_SIZE);
269       memcpy(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0].freqDomainRsrc, freqDomainResource, FREQ_DOM_RSRC_SIZE);
270
271       ueCb->ueCfg.spCellCfgPres = true;
272       dlDataToUlAck = ueCfg->spCellCfg.servCellCfg.initUlBwp.pucchCfg.dlDataToUlAck;
273       if(ueCb->cellCb)
274       {
275          if(dlDataToUlAck)
276          {
277             BuildK0K1Table(ueCb->cellCb, &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.k0K1InfoTbl, false, pdschCfg,\
278                   ueCfg->spCellCfg.servCellCfg.initDlBwp.pdschCfg, dlDataToUlAck->dlDataToUlAckListCount,\
279                   dlDataToUlAck->dlDataToUlAckList);
280             BuildK2InfoTable(ueCb->cellCb, ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList,\
281                   ueCfg->spCellCfg.servCellCfg.initUlBwp.puschCfg.numTimeDomRsrcAlloc,\
282                   NULLP, &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.k2InfoTbl);
283          }
284       }
285    }
286
287    ueCb->state = SCH_UE_STATE_ACTIVE;
288    if(ueCfg->ambrCfg)
289    {
290       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
291       ueCb->ueCfg.ambrCfg =  ueCfg->ambrCfg;
292    }
293    memcpy(&ueCb->ueCfg.dlModInfo,  &ueCfg->dlModInfo , sizeof(SchModulationInfo));
294    memcpy(&ueCb->ueCfg.ulModInfo,  &ueCfg->ulModInfo , sizeof(SchModulationInfo));
295
296    //Updating SchUlCb and SchDlCb DB in SchUeCb
297    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
298    {
299       isLcIdValid = FALSE; /*Re-Initializing*/
300
301       ueLcIdx = ueCfg->schLcCfg[lcIdx].lcId;
302       CHECK_LCID(ueLcIdx, isLcIdValid);
303       if(isLcIdValid == FALSE)
304       {
305          DU_LOG("ERROR --> SCH: LCID:%d is not Valid",ueLcIdx);
306          continue;
307       }
308       if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
309       {
310          fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
311          fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
312
313          /*Checking whether this LC belong to Dedicated S-NSSAI 
314           * and Create the Dedicated LC List & Update the Reserve PRB number*/
315          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
316          {
317             retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai,  \
318                   ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst),\
319                   &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
320          }
321          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
322          {
323             retUL =  updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai,  \
324                   ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
325                   &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
326          }
327
328          if(retUL == RFAILED  || retDL == RFAILED)/*FATAL error*/
329          {
330             DU_LOG("\nERROR  -->  SCH : Failure in updateDedLcInfo");
331             return RFAILED;
332          }
333       }
334       else
335       {
336          if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
337          {
338             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
339             {
340                fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
341                /*Updating the RRM reserved pool PRB count*/
342                if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai != NULLP)
343                {
344                   retUL =  updateDedLcInfo(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai,  \
345                         ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->ulLcPrbEst),\
346                         &(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated));
347                }
348                if(retUL == RFAILED)
349                {
350                   DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
351                   return RFAILED;
352                }
353             }
354             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
355             {
356                /*Delete the LC node from the UL LC List*/
357                if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].isDedicated)
358                {
359                   if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
360                   {
361                      lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
362                      handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
363                      if(lcLL->count == 0)/*IF No Node in DedicateLCList to be deleted*/
364                      {
365                         /*Free the Dedicated LC Info structure*/
366                         SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
367                      }
368                   }
369                }
370                else/*Default LC list*/
371                {
372                   lcLL = &(ueCb->ulLcPrbEst.defLcList);
373                   handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
374                }
375                SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
376                memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
377             }
378          }/*End of UL LC Ctxt*/
379
380          if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
381          {
382             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
383             {
384                fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
385                /*Updating the RRM policy*/
386                if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai != NULLP)
387                {
388                   retDL = updateDedLcInfo(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai,  \
389                         ueCb->cellCb->cellCfg.rrmPolicy, &(ueCb->dlLcPrbEst), \
390                         &(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated));
391                }
392                if(retDL == RFAILED)
393                {
394                   DU_LOG("\nERROR  -->  SCH : Failed in updating Ded Lc info");
395                   return RFAILED;
396                }
397             }
398             if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_DEL)
399             {
400                /*Delete the LC node from the DL LC List*/
401                if(ueCb->dlInfo.dlLcCtxt[ueLcIdx].isDedicated)
402                {
403                   if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
404                   {
405                      lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
406                      handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
407                      if(lcLL->count == 0)/*Last Node in DedicateLCList to be deleted*/
408                      {
409                         /*Free the Dedicated LC Info structure*/
410                         SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
411                      }
412                   }
413                }
414                else
415                {
416                   lcLL = &(ueCb->dlLcPrbEst.defLcList);
417                   handleLcLList(lcLL, ueCfg->schLcCfg[lcIdx].lcId, DELETE);
418                }
419                SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
420                memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
421             }
422          }/*End of DL LC ctxt*/
423       }
424
425       SCH_FREE(ueCfg->schLcCfg[lcIdx].drbQos, sizeof(SchDrbQosInfo));
426       SCH_FREE(ueCfg->schLcCfg[lcIdx].snssai, sizeof(Snssai));
427
428    }/* End of outer for loop */
429    return ROK;
430 }
431
432 /*******************************************************************
433  *
434  * @brief Function to get SCH Cell Cb
435  *
436  * @details
437  *
438  *    Function : getSchCellCb
439  *
440  *    Functionality: Function to get SCH Cell Cb
441  *
442  * @params[in] event, SchUeCfg pointer 
443  * @return schUeCb pointer  - success
444  *         NULLP - failure
445  *
446  * ****************************************************************/
447
448 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
449 {
450    uint8_t      idx;
451    SchCellCb    *cellCb = NULLP;
452    SchUeCfgRsp  cfgRsp;
453    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
454
455    /* Search of cell cb */
456    for(idx = 0; idx < MAX_NUM_CELL; idx++)
457    {
458       cellCb = schCb[inst].cells[idx];
459       if(cellCb->cellId == ueCfg->cellId)
460          break;
461    }
462    if(idx == MAX_NUM_CELL)
463    {
464       DU_LOG("\nERROR  -->  SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
465       SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
466       return NULLP;
467    }
468
469    /* Check if max number of UE configured */
470    if(cellCb->numActvUe > MAX_NUM_UE)
471    {
472       DU_LOG("\nERROR  -->  SCH :  Max number of UE [%d] already configured", MAX_NUM_UE);
473       SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
474       return NULLP;
475    }
476    return cellCb;
477 }
478
479
480 /*******************************************************************
481  *
482  * @brief Function to Add Ue Config Request from MAC
483  *
484  * @details
485  *
486  *    Function : MacSchAddUeConfigReq
487  *
488  *    Functionality: Function to Add Ue config request from MAC
489  *
490  * @params[in] 
491  * @return ROK     - success
492  *         RFAILED - failure
493  *
494  * ****************************************************************/
495 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
496 {
497    uint8_t ueIdx, lcIdx, ret = ROK;
498    SchCellCb    *cellCb = NULLP;
499    SchUeCb      *ueCb = NULLP;
500    SchUeCfgRsp  cfgRsp;
501    Inst         inst = pst->dstInst - 1;
502    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
503   
504 #ifdef CALL_FLOW_DEBUG_LOG
505    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_ADD_UE_CONFIG_REQ_TO_SCH\n");
506 #endif
507
508    if(!ueCfg)
509    {
510       DU_LOG("\nERROR  -->  SCH :  Adding UE Config Request failed at MacSchAddUeConfigReq()");
511       return RFAILED;
512    }
513    DU_LOG("\nDEBUG  -->  SCH :  Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
514    cellCb = getSchCellCb(pst->event, inst, ueCfg);
515
516    /* Search if UE already configured */
517    GET_UE_IDX(ueCfg->crnti, ueIdx);
518    ueCb = &cellCb->ueCb[ueIdx -1];
519    if(ueCb)
520    {
521       if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
522       {
523          DU_LOG("\nDEBUG  -->  SCH : CRNTI %d already configured ", ueCfg->crnti);
524          SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
525          return ROK;
526       }
527    }
528    else
529    {
530       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
531       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
532       return RFAILED;
533    }
534
535    /* Fill received Ue Configuration in UeCb */
536    memset(ueCb, 0, sizeof(SchUeCb));
537    GET_UE_IDX(ueCfg->crnti, ueIdx);
538    ueCb->ueIdx = ueIdx;
539    ueCb->crnti = ueCfg->crnti;
540    ueCb->state = SCH_UE_STATE_ACTIVE;
541    ret = fillSchUeCb(ueCb, ueCfg);
542    if(ret == ROK)
543    {
544       cellCb->numActvUe++;
545       SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
546       ueCb->cellCb = cellCb;
547       ueCb->srRcvd = false;
548       for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
549          ueCb->bsrInfo[lcIdx].dataVol = 0;
550
551       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
552    }
553    return ret;
554 }
555
556 /*******************************************************************
557 *
558 * @brief Fills PUSCH UL allocation
559 *
560 * @details
561 *
562 *    Function : schFillPuschAlloc
563 *
564 *    Functionality: fills PUSCH info
565 *
566 * @params[in]
567 * @return ROK     - success
568 *         RFAILED - failure
569 *
570 * ****************************************************************/
571 uint8_t schFillPuschAlloc(SchUeCb *ueCb, SlotTimingInfo pdcchSlotTime, uint32_t dataVol, SchPuschInfo *puschInfo)
572 {
573   uint16_t startRb        = 0;
574   uint8_t  numRb          = 0;
575   uint16_t tbSize         = 0;
576   uint8_t  buffer         = 5;
577   uint8_t k2=0, startSymb=0 , symbLen=0;
578   SchCellCb *cellCb       = ueCb->cellCb;
579   SchUlSlotInfo *schUlSlotInfo = NULLP;
580   SlotTimingInfo puschTime;
581   
582   /* TODO : Scheduler to decide on which slot PUSCH is to be scheduled based on K2 Index table */
583   if(ueCb->ueCfg.spCellCfgPres == true)
584   {
585      k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
586      startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
587      symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
588   }
589   ADD_DELTA_TO_TIME(pdcchSlotTime, puschTime, k2);
590
591   startRb = MAX_NUM_RB;
592   tbSize  = schCalcTbSize(dataVol + buffer); /*  2 bytes header + some buffer */
593   numRb   = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, symbLen);
594   allocatePrbUl(cellCb, puschTime, startSymb, symbLen, &startRb, numRb);
595
596   puschInfo->crnti             = ueCb->crnti; 
597   puschInfo->harqProcId        = SCH_HARQ_PROC_ID;
598   puschInfo->resAllocType      = SCH_ALLOC_TYPE_1;
599   puschInfo->fdAlloc.startPrb  = startRb;
600   puschInfo->fdAlloc.numPrb    = numRb;
601   puschInfo->tdAlloc.startSymb = startSymb;
602   puschInfo->tdAlloc.numSymb   = symbLen;
603   puschInfo->tbInfo.qamOrder   = ueCb->ueCfg.ulModInfo.modOrder;
604   puschInfo->tbInfo.mcs        = ueCb->ueCfg.ulModInfo.mcsIndex;
605   puschInfo->tbInfo.mcsTable   = ueCb->ueCfg.ulModInfo.mcsTable;
606   puschInfo->tbInfo.ndi        = 1; /* new transmission */
607   puschInfo->tbInfo.rv         = 0;
608   puschInfo->tbInfo.tbSize     = tbSize;
609   puschInfo->dmrsMappingType   = DMRS_MAP_TYPE_A;  /* Setting Type-A */
610   puschInfo->nrOfDmrsSymbols   = NUM_DMRS_SYMBOLS;
611   puschInfo->dmrsAddPos        = DMRS_ADDITIONAL_POS;
612
613   schUlSlotInfo = cellCb->schUlSlotInfo[puschTime.slot];
614   SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
615   if(!schUlSlotInfo->schPuschInfo)
616   {
617      DU_LOG("\nERROR  -->  SCH: Memory allocation failed in schAllocMsg3Pusch");
618      return RFAILED;
619   }
620   memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
621
622   return ROK;
623 }
624
625 /*******************************************************************
626  *
627  * @brief Fills DCI for UL grant
628  *
629  * @details
630  *
631  *    Function : schFillUlDci
632  *
633  *    Functionality: fills DCI for UL grant in response to BSR
634  *
635  * @params[in]
636  * @return ROK     - success
637  *         RFAILED - failure
638  *
639  * ****************************************************************/
640 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
641 {
642    SchCellCb         *cellCb  = ueCb->cellCb;
643    SchControlRsrcSet coreset1 ;
644   
645    memset(&coreset1, 0, sizeof(SchControlRsrcSet));
646    if(ueCb->ueCfg.spCellCfgPres == true)
647    {
648      coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
649    }
650    
651    dciInfo->cellId = cellCb->cellId;
652    dciInfo->crnti  = ueCb->crnti;
653
654    /* fill bwp cfg */
655    dciInfo->bwpCfg.subcarrierSpacing  = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
656    dciInfo->bwpCfg.cyclicPrefix       = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
657    dciInfo->bwpCfg.freqAlloc.startPrb = 0;
658    dciInfo->bwpCfg.freqAlloc.numPrb   = MAX_NUM_RB; /* whole of BW */
659
660    /*fill coreset cfg */
661    //Considering number of RBs in coreset1 is same as coreset0
662    dciInfo->coresetCfg.coreSetSize      = coresetIdxTable[0][1];
663    //Considering coreset1 also starts from same symbol as coreset0
664    dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
665    dciInfo->coresetCfg.durationSymbols  = coreset1.duration;
666    memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
667    
668    dciInfo->coresetCfg.cceRegMappingType   = coreset1.cceRegMappingType; /* non-interleaved */
669    dciInfo->coresetCfg.regBundleSize       = 6; /* must be 6 for non-interleaved */
670    dciInfo->coresetCfg.interleaverSize     = 0; /* NA for non-interleaved */
671    dciInfo->coresetCfg.coreSetType         = 1; /* non PBCH coreset */
672    dciInfo->coresetCfg.shiftIndex          = cellCb->cellCfg.phyCellId;
673    dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
674    dciInfo->coresetCfg.cceIndex            = 0; /* 0-3 for UL and 4-7 for DL */
675    dciInfo->coresetCfg.aggregationLevel    = 4; /* same as for sib1 */
676    
677    dciInfo->formatType = FORMAT0_0;
678    
679    /* fill UL grant */
680    dciInfo->format.format0_0.resourceAllocType   = puschInfo.resAllocType;
681    dciInfo->format.format0_0.freqAlloc.startPrb  = puschInfo.fdAlloc.startPrb;
682    dciInfo->format.format0_0.freqAlloc.numPrb    = puschInfo.fdAlloc.numPrb;
683    dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
684    dciInfo->format.format0_0.timeAlloc.numSymb   = puschInfo.tdAlloc.numSymb;
685    dciInfo->format.format0_0.rowIndex            = 0; /* row Index */
686    dciInfo->format.format0_0.mcs                 = puschInfo.tbInfo.mcs;
687    dciInfo->format.format0_0.harqProcId          = puschInfo.harqProcId;
688    dciInfo->format.format0_0.puschHopFlag        = FALSE; /* disabled */
689    dciInfo->format.format0_0.freqHopFlag         = FALSE; /* disabled */
690    dciInfo->format.format0_0.ndi                 = puschInfo.tbInfo.ndi; /* new transmission */
691    dciInfo->format.format0_0.rv                  = puschInfo.tbInfo.rv;
692    dciInfo->format.format0_0.tpcCmd              = 0; //Sphoorthi TODO: check
693    dciInfo->format.format0_0.sUlCfgd             = FALSE; /* SUL not configured */
694    
695    /* Fill DCI Structure */
696    dciInfo->dciInfo.rnti                              = ueCb->crnti;
697    dciInfo->dciInfo.scramblingId                      = cellCb->cellCfg.phyCellId;
698    dciInfo->dciInfo.scramblingRnti                    = 0;
699    dciInfo->dciInfo.cceIndex                          = 0; /* 0-3 for UL and 4-7 for DL */
700    dciInfo->dciInfo.aggregLevel                       = 4;
701    dciInfo->dciInfo.beamPdcchInfo.numPrgs             = 1;
702    dciInfo->dciInfo.beamPdcchInfo.prgSize             = 1;
703    dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces     = 0;
704    dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx        = 0;
705    dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0]   = 0;
706    dciInfo->dciInfo.txPdcchPower.powerValue           = 0;
707    dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
708    dciInfo->dciInfo.pdschCfg                          = NULLP; /* No DL data being sent */
709
710    return ROK;
711 }
712
713 /*******************************************************************
714  *
715  * @brief Function to Modify Ue Config request from MAC
716  *
717  * @details
718  *
719  *    Function : MacSchModUeConfigReq
720  *
721  *    Functionality: Function to modify Ue Config request from MAC
722  *
723  * @params[in] 
724  * @return ROK     - success
725  *         RFAILED - failure
726  *
727  * ****************************************************************/
728 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
729 {
730    uint8_t ueIdx, lcIdx, ret = ROK;
731    SchCellCb    *cellCb = NULLP;
732    SchUeCb      *ueCb = NULLP;
733    SchUeCfgRsp  cfgRsp;
734    Inst         inst = pst->dstInst - 1;
735    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
736   
737 #ifdef CALL_FLOW_DEBUG_LOG
738    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH\n");
739 #endif
740
741    if(!ueCfg)
742    {
743       DU_LOG("\nERROR  -->  SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
744       return RFAILED;
745    }
746    DU_LOG("\nDEBUG  -->  SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
747    cellCb = getSchCellCb(pst->event, inst, ueCfg);
748
749    /* Search if UE already configured */
750    GET_UE_IDX(ueCfg->crnti, ueIdx);
751    ueCb = &cellCb->ueCb[ueIdx -1];
752    
753    if(!ueCb)
754    {
755       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at MacSchModUeConfigReq() ");
756       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
757       return RFAILED;
758    }
759    if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
760    {
761       /* Found the UeCb to Reconfig */
762       ret = fillSchUeCb(ueCb, ueCfg);
763       if(ret == ROK)
764       {
765          ueCb->cellCb = cellCb;
766          ueCb->srRcvd = false;
767          for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
768             ueCb->bsrInfo[lcIdx].dataVol = 0;
769
770          SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
771       }
772    }
773    return ret;
774 }
775
776 /*******************************************************************
777 *
778 * @brief Fill and send UE delete response to MAC
779 *
780 * @details
781 *
782 *    Function :  SchSendUeDeleteRspToMac
783 *
784 *    Functionality: Fill and send UE delete response to MAC
785 *
786 * @params[in] Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, 
787 *              ErrorCause cause
788 * @return ROK     - success
789 *         RFAILED - failure
790 *
791 * ****************************************************************/
792 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, ErrorCause cause)
793 {
794     Pst rspPst;
795     SchUeDeleteRsp  delRsp;
796     
797     memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
798     delRsp.cellId = ueDelete->cellId;
799     delRsp.crnti = ueDelete->crnti;
800     delRsp.rsp = result; 
801     delRsp.cause = cause; 
802
803     /* Filling response post */
804     memset(&rspPst, 0, sizeof(Pst));
805     FILL_PST_SCH_TO_MAC(rspPst, inst);
806     rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
807     SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
808 }
809
810 /*******************************************************************
811 *
812 * @brief Function to delete Sch Pucch ResrcCfg
813 *
814 * @details
815 *
816 *    Function : deleteSchPucchResrcCfg 
817 *
818 *    Functionality: Function to delete Sch Pucch ResrcCfg
819 *
820 * @params[in] SchPucchResrcCfg *resrc
821 * @return void 
822 *
823 * ****************************************************************/
824
825 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
826 {
827    uint8_t rsrcIdx=0;
828    for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
829    {
830       switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
831       {
832          case PUCCH_FORMAT_0:
833          {
834             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
835             sizeof(SchPucchFormat0));
836             break;
837          }
838          case PUCCH_FORMAT_1:
839          {
840             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
841             sizeof(SchPucchFormat1));
842             break;
843          }
844          case PUCCH_FORMAT_2:
845          {
846             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
847             sizeof(SchPucchFormat2_3));
848             break;
849          }
850          case PUCCH_FORMAT_3:
851          {
852             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
853             sizeof(SchPucchFormat2_3));
854             break;
855          }
856          case PUCCH_FORMAT_4:
857          {
858             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
859             sizeof(SchPucchFormat4));
860             break;
861          }
862       }
863    }
864 }
865
866 /*******************************************************************
867 *
868 * @brief Function to delete SCH Pdsch ServCellCfg
869 *
870 * @details
871 *
872 *    Function : deleteSchPdschServCellCfg
873 *
874 *    Functionality: Function to delete SCH Pdsch ServCellCfg
875 *
876 * @params[in] SchPdschServCellCfg *pdschServCellCfg
877 * @return void 
878 *
879 * ****************************************************************/
880
881 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
882 {
883    SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
884    SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
885    SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
886    SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
887 }
888
889 /*******************************************************************
890 *
891 * @brief Function to  delete SCH UeCb
892 *
893 * @details
894 *
895 *    Function : deleteSchUeCb 
896 *
897 *    Functionality: Function to delete SCH UeCb
898 *
899 * @params[in]
900 * @return ROK     - success
901 *         RFAILED - failure
902 *
903 * ****************************************************************/
904 void deleteSchUeCb(SchUeCb *ueCb) 
905 {
906    uint8_t timeDomRsrcIdx = 0, ueLcIdx = 0;
907    SchPucchCfg *pucchCfg = NULLP;
908    SchPdschConfig *pdschCfg = NULLP;
909    CmLListCp *lcLL  = NULLP;
910
911    if(ueCb)
912    {
913       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
914       if(ueCb->ueCfg.spCellCfgPres)
915       {
916          if(ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfgPres == true)
917          {
918             pdschCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdschCfg;
919             for(timeDomRsrcIdx = 0; timeDomRsrcIdx < pdschCfg->numTimeDomRsrcAlloc; timeDomRsrcIdx++)
920                SCH_FREE(pdschCfg->timeDomRsrcAllociList[timeDomRsrcIdx].k0, sizeof(uint8_t));
921          }
922
923          if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
924          {
925             pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
926             SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
927             if(pucchCfg->resrc)
928             {
929                deleteSchPucchResrcCfg(pucchCfg->resrc);
930                SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
931             }
932             SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
933             SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
934             SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
935             SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
936             SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
937             SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
938             SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));  
939             SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
940             SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
941          }
942          SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
943          deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
944       }
945       /*Need to Free the memory allocated for S-NSSAI*/
946       for(ueLcIdx = 0; ueLcIdx < MAX_NUM_LC; ueLcIdx++)
947       {
948          SCH_FREE(ueCb->ulInfo.ulLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
949          SCH_FREE(ueCb->dlInfo.dlLcCtxt[ueLcIdx].snssai, sizeof(Snssai));
950       }
951
952       /*Clearing out Dedicated LC list*/
953       if(ueCb->dlLcPrbEst.dedLcInfo != NULLP)
954       {
955          lcLL = &(ueCb->dlLcPrbEst.dedLcInfo->dedLcList);
956          deleteLcLL(lcLL);
957          SCH_FREE(ueCb->dlLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
958       }
959       if(ueCb->ulLcPrbEst.dedLcInfo != NULLP)
960       {
961          lcLL = &(ueCb->ulLcPrbEst.dedLcInfo->dedLcList);
962          deleteLcLL(lcLL);
963          SCH_FREE(ueCb->ulLcPrbEst.dedLcInfo, sizeof(DedicatedLCInfo));
964       }
965       /*Deleteing the Default LC list*/
966       lcLL = &(ueCb->dlLcPrbEst.defLcList);
967       deleteLcLL(lcLL);
968
969       lcLL = &(ueCb->ulLcPrbEst.defLcList);
970       deleteLcLL(lcLL);
971
972       memset(ueCb, 0, sizeof(SchUeCb));
973    }
974 }
975
976 /*******************************************************************
977 *
978 * @brief Function for Ue Delete request from MAC to SCH
979 *
980 * @details
981 *
982 *    Function : MacSchUeDeleteReq 
983 *
984 *    Functionality: Function for Ue Delete request from MAC to SCH
985 *
986 * @params[in] Pst *pst, SchUeDelete  *ueDelete
987 * @return ROK     - success
988 *         RFAILED - failure
989 *
990 * ****************************************************************/
991 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete  *ueDelete)
992 {
993     uint8_t idx=0, ueIdx=0, ret=ROK;
994     ErrorCause result;
995     SchCellCb    *cellCb = NULLP;
996     Inst         inst = pst->dstInst - 1;
997    
998 #ifdef CALL_FLOW_DEBUG_LOG
999     DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_UE_DELETE_REQ_TO_SCH\n");
1000 #endif
1001
1002     if(!ueDelete)
1003     {
1004        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): Ue Delete request failed");
1005        ret = RFAILED;
1006     }
1007     DU_LOG("\nDEBUG  -->  SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
1008     
1009     cellCb = schCb[inst].cells[idx];
1010
1011     if(cellCb->cellId != ueDelete->cellId)
1012     {
1013        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): cell Id is not available");
1014        result =  INVALID_CELLID;
1015     }
1016     else
1017     {
1018        GET_UE_IDX(ueDelete->crnti, ueIdx);
1019        if(( cellCb->ueCb[ueIdx-1].crnti == ueDelete->crnti) && ( cellCb->ueCb[ueIdx-1].state == SCH_UE_STATE_ACTIVE))
1020        {
1021           deleteSchUeCb(&cellCb->ueCb[ueIdx-1]);
1022           cellCb->numActvUe--;
1023           result = NOT_APPLICABLE;
1024        }
1025        else
1026        {
1027           DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): SchUeCb not found");
1028           result =  INVALID_UEIDX;
1029        }
1030     }
1031     
1032     if(result == NOT_APPLICABLE)
1033     {
1034        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
1035     }
1036     else
1037     {
1038        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
1039        ret = RFAILED;
1040     }
1041     return ret;
1042 }
1043
1044 /*******************************************************************
1045  *
1046  * @brief Fill and send Cell delete response to MAC
1047  *
1048  * @details
1049  *
1050  *    Function :  SchSendCellDeleteRspToMac
1051  *
1052  *    Functionality: Fill and send Cell delete response to MAC
1053  *
1054  * @params[in] SchCellDelete  *ueDelete, Inst inst, SchMacRsp result
1055  * @return ROK     - success
1056  *         RFAILED - failure
1057  *
1058  * ****************************************************************/
1059 uint8_t SchSendCellDeleteRspToMac(SchCellDelete  *ueDelete, Inst inst, SchMacRsp result)
1060 {
1061    Pst rspPst;
1062    uint8_t ret=0;
1063    
1064    SchCellDeleteRsp  delRsp;
1065
1066    DU_LOG("\nINFO   --> SCH : Filling Cell Delete response");
1067    memset(&delRsp, 0, sizeof(SchCellDeleteRsp));
1068    delRsp.cellId = ueDelete->cellId;
1069    delRsp.rsp = result;
1070
1071    /* Filling response post */
1072    memset(&rspPst, 0, sizeof(Pst));
1073    FILL_PST_SCH_TO_MAC(rspPst, inst);
1074    rspPst.event = EVENT_CELL_DELETE_RSP_TO_MAC;
1075    ret =  SchCellDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
1076    if(ret == RFAILED)
1077    {
1078       DU_LOG("\nERROR  -->  SCH : SchSendCellDeleteRspToMac(): failed to send the Cell Delete response");
1079       return ret;
1080    }
1081    return ret;
1082 }
1083
1084 /*******************************************************************
1085  *
1086  * @brief Function for cellCb Deletion 
1087  *
1088  * @details
1089  *
1090  *    Function : deleteSchCellCb 
1091  *
1092  *    Functionality: Function for cellCb Deletion 
1093  *
1094  * @params[in] SchCellDelete  *cellDelete
1095  * @return ROK     - success
1096  *         RFAILED - failure
1097  *
1098  * ****************************************************************/
1099 void deleteSchCellCb(SchCellCb *cellCb)
1100 {
1101    uint8_t sliceIdx=0, slotIdx=0;
1102    if(cellCb->schDlSlotInfo)
1103    {
1104       for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1105       {
1106          SCH_FREE(cellCb->schDlSlotInfo[slotIdx], sizeof(SchDlSlotInfo));
1107       }
1108       SCH_FREE(cellCb->schDlSlotInfo, cellCb->numSlots *sizeof(SchDlSlotInfo*));
1109    }
1110    if(cellCb->schUlSlotInfo)
1111    {
1112       for(slotIdx=0; slotIdx<cellCb->numSlots; slotIdx++)
1113       {
1114          SCH_FREE(cellCb->schUlSlotInfo[slotIdx], sizeof(SchUlSlotInfo));  
1115       }
1116       SCH_FREE(cellCb->schUlSlotInfo,  cellCb->numSlots * sizeof(SchUlSlotInfo*));
1117    }
1118
1119    if(cellCb->cellCfg.snssai)
1120    {
1121       for(sliceIdx=0; sliceIdx<cellCb->cellCfg.numSliceSupport; sliceIdx++)
1122       {
1123          SCH_FREE(cellCb->cellCfg.snssai[sliceIdx], sizeof(Snssai));
1124       }
1125       SCH_FREE(cellCb->cellCfg.snssai, cellCb->cellCfg.numSliceSupport*sizeof(Snssai*));
1126    }
1127    SCH_FREE(cellCb->cellCfg.rrmPolicy, sizeof(SchRrmPolicy));
1128    memset(cellCb, 0, sizeof(SchCellCb));
1129
1130 }
1131
1132 /*******************************************************************
1133  *
1134  * @brief Function for cell Delete request from MAC to SCH
1135  *
1136  * @details
1137  *
1138  *    Function : MacSchCellDeleteReq
1139  *
1140  *    Functionality: Function for cell Delete request from MAC to SCH
1141  *
1142  * @params[in] Pst *pst, SchCellDelete  *cellDelete
1143  * @return ROK     - success
1144  *         RFAILED - failure
1145  *
1146  * ****************************************************************/
1147
1148 uint8_t MacSchCellDeleteReq(Pst *pst, SchCellDelete  *cellDelete)
1149 {
1150    uint8_t   cellIdx=0, ret = RFAILED;
1151    Inst      inst = pst->dstInst - 1;
1152    SchMacRsp result= RSP_OK;
1153    
1154 #ifdef CALL_FLOW_DEBUG_LOG
1155    DU_LOG("\nCall Flow: ENTMAC -> ENTSCH : EVENT_CELL_DELETE_REQ_TO_SCH\n");
1156 #endif   
1157
1158    if(!cellDelete)
1159    {
1160       DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): Ue Delete request failed");
1161    }
1162    else
1163    {
1164       GET_CELL_IDX(cellDelete->cellId, cellIdx);
1165       if(schCb[inst].cells[cellIdx] == NULLP)
1166       { 
1167          DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): cell Id[%d] is not available", cellDelete->cellId);
1168          result = RSP_NOK;
1169       }
1170       else
1171       {
1172          if(schCb[inst].cells[cellIdx]->cellId == cellDelete->cellId)
1173          {
1174             deleteSchCellCb(schCb[inst].cells[cellIdx]);
1175             result = RSP_OK;
1176             ret = ROK;
1177             SCH_FREE(schCb[inst].cells[cellIdx], sizeof(SchCellCb));
1178             DU_LOG("\nINFO   -->  SCH : Sending Cell Delete response to MAC");
1179          }
1180          else
1181          {
1182             DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): cell Id[%d] is not available",cellDelete->cellId);
1183             result = RSP_NOK;
1184          }
1185       }
1186
1187       if(SchSendCellDeleteRspToMac(cellDelete, inst, result)!=ROK)
1188       {
1189          DU_LOG("\nERROR  -->  SCH : MacSchCellDeleteReq(): failed to send Cell Delete response");
1190          ret =  RFAILED;
1191       }
1192
1193    }
1194    return ret;   
1195 }
1196
1197 /**********************************************************************
1198   End of file
1199  **********************************************************************/