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