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