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