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