Merge "Implementation of UE context release command JIRA ID = ODUHIGH-330"
[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 /*******************************************************************
48  *
49  * @brief Fill and send UE cfg response to MAC
50  *
51  * @details
52  *
53  *    Function : SchSendUeCfgRspToMac
54  *
55  *    Functionality: Fill and send UE cfg response to MAC
56  *
57  * @params[in] 
58  * @return ROK     - success
59  *         RFAILED - failure
60  *
61  * ****************************************************************/
62 void SchSendUeCfgRspToMac(uint16_t event, SchUeCfg *ueCfg, Inst inst,\
63       SchMacRsp result, SchUeCfgRsp *cfgRsp)
64 {
65    Pst rspPst;
66
67    cfgRsp->cellId = ueCfg->cellId;
68    cfgRsp->crnti = ueCfg->crnti;
69    GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
70    cfgRsp->rsp = result;   
71
72    /* Filling response post */
73    memset(&rspPst, 0, sizeof(Pst));
74    FILL_PST_SCH_TO_MAC(rspPst, inst);
75    if(event == EVENT_ADD_UE_CONFIG_REQ_TO_SCH)
76    {
77       rspPst.event = EVENT_UE_CONFIG_RSP_TO_MAC;
78       DU_LOG("\nINFO  -->  SCH :  Sending UE Config response to MAC");
79    }
80    else if(event == EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH)
81    {
82       rspPst.event = EVENT_UE_RECONFIG_RSP_TO_MAC;
83       DU_LOG("\nINFO  -->  SCH :  Sending UE Reconfig response to MAC");
84    }
85    SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
86 }
87
88 /*******************************************************************
89  
90  *
91  * @brief Function to fill Dl Lc Context in SCH Ue Cb
92  *
93  * @details
94  *
95  *    Function : fillSchDlLcCtxt
96  *
97  *    Functionality: Function to fill Dl Lc Context in SCH Ue Cb
98  *
99  * @params[in] SchDlLcCtxt pointer,
100  *             SchLcCfg pointer
101  * @return void
102  *
103  * ****************************************************************/
104
105 void fillSchDlLcCtxt(SchDlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
106 {
107    ueCbLcCfg->lcId = lcCfg->lcId;
108    ueCbLcCfg->lcp = lcCfg->dlLcCfg.lcp;
109    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
110    ueCbLcCfg->bo = 0;
111 }
112
113 /*******************************************************************
114  *
115  * @brief Function to fill Ul Lc Context in SCH Ue Cb
116  *
117  * @details
118  *
119  *    Function : fillSchUlLcCtxt
120  *
121  *    Functionality: Function to fill Ul Lc Context in SCH Ue Cb
122  *
123  * @params[in] SchUlLcCtxt pointer,
124  *             SchLcCfg pointer
125  * @return void
126  *
127  * ****************************************************************/
128
129 void fillSchUlLcCtxt(SchUlLcCtxt *ueCbLcCfg, SchLcCfg *lcCfg)
130 {
131    ueCbLcCfg->lcId = lcCfg->lcId;
132    ueCbLcCfg->lcState = SCH_LC_STATE_ACTIVE;
133    ueCbLcCfg->priority = lcCfg->ulLcCfg.priority;
134    ueCbLcCfg->lcGroup = lcCfg->ulLcCfg.lcGroup;
135    ueCbLcCfg->schReqId = lcCfg->ulLcCfg.schReqId;
136    ueCbLcCfg->pbr     = lcCfg->ulLcCfg.pbr;
137    ueCbLcCfg->bsd     = lcCfg->ulLcCfg.bsd;
138
139 }
140
141 /*******************************************************************
142  *
143  * @brief Function to update Sch Ul Lc Cb
144  *
145  * @details
146  *
147  *    Function : updateSchUlCb
148  *
149  *    Functionality: Function to update SCH Ul Lc Cb
150  *
151  * @returns void
152  *
153  * ****************************************************************/
154
155 void updateSchUlCb(uint8_t delIdx, SchUlCb *ulInfo)
156 {
157    uint8_t lcIdx = 0;
158
159    for(lcIdx = delIdx; lcIdx < ulInfo->numUlLc; lcIdx++)
160    {
161       memcpy(&ulInfo->ulLcCtxt[lcIdx], &ulInfo->ulLcCtxt[lcIdx+1], sizeof(SchUlLcCtxt));
162       memset(&ulInfo->ulLcCtxt[lcIdx+1], 0, sizeof(SchUlLcCtxt));
163    }
164 }
165
166 /*******************************************************************
167  *
168  * @brief Function to update SCH Dl Lc Cb
169  *
170  * @details
171  *
172  *    Function : updateSchDlCb
173  *
174  *    Functionality: Function to update SCH DL Lc Cb
175  *
176  * @returns void
177  *
178  * ****************************************************************/
179
180 void updateSchDlCb(uint8_t delIdx, SchDlCb *dlInfo)
181 {
182    uint8_t lcIdx = 0;
183
184    for(lcIdx = delIdx; lcIdx < dlInfo->numDlLc; lcIdx++)
185    {
186       memcpy(&dlInfo->dlLcCtxt[lcIdx], &dlInfo->dlLcCtxt[lcIdx+1], sizeof(SchDlLcCtxt));
187       memset(&dlInfo->dlLcCtxt[lcIdx+1], 0, sizeof(SchDlLcCtxt));
188    }
189 }
190
191 /*******************************************************************
192  *
193  * @brief Function to fill SchUeCb
194  *
195  * @details
196  *
197  *    Function : fillSchUeCb
198  *
199  *    Functionality: Function to fill SchUeCb
200  *
201  * @params[in] SchUeCb pointer,
202  *             SchUeCfg pointer
203  * @return ROK/RFAILED
204  *
205  * ****************************************************************/
206
207 uint8_t fillSchUeCb(SchUeCb *ueCb, SchUeCfg *ueCfg)
208 {
209    uint8_t   lcIdx, ueLcIdx;
210   
211    ueCb->ueCfg.cellId = ueCfg->cellId;
212    ueCb->ueCfg.crnti = ueCfg->crnti;
213    if(ueCfg->macCellGrpCfgPres == true)
214    {
215       memcpy(&ueCb->ueCfg.macCellGrpCfg , &ueCfg->macCellGrpCfg, sizeof(SchMacCellGrpCfg)); 
216       ueCb->ueCfg.macCellGrpCfgPres = true;
217    }
218
219    if(ueCfg->phyCellGrpCfgPres == true)
220    {
221       memcpy(&ueCb->ueCfg.phyCellGrpCfg ,  &ueCfg->phyCellGrpCfg, sizeof(SchPhyCellGrpCfg));
222       ueCb->ueCfg.phyCellGrpCfgPres = true;
223    }
224
225    if(ueCfg->spCellCfgPres == true)
226    {
227       memcpy(&ueCb->ueCfg.spCellCfg , &ueCfg->spCellCfg, sizeof(SchSpCellCfg));
228       ueCb->ueCfg.spCellCfgPres = true;
229    }
230    ueCb->state = SCH_UE_STATE_ACTIVE;
231    if(ueCfg->ambrCfg != NULLP)
232    {
233       SCH_ALLOC(ueCb->ueCfg.ambrCfg , sizeof(SchAmbrCfg));
234       memcpy(&ueCb->ueCfg.ambrCfg->ulBr , &ueCfg->ambrCfg->ulBr, sizeof(SchAmbrCfg));
235    }
236    
237    memcpy(&ueCb->ueCfg.dlModInfo,  &ueCfg->dlModInfo , sizeof(SchModulationInfo));
238    memcpy(&ueCb->ueCfg.ulModInfo,  &ueCfg->ulModInfo , sizeof(SchModulationInfo));
239
240    //Updating SchUlCb and SchDlCb DB in SchUeCb
241    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
242    {
243       if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_ADD)
244       {
245          fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueCb->ulInfo.numUlLc], &ueCfg->schLcCfg[lcIdx]);
246          ueCb->ulInfo.numUlLc++;
247          fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueCb->dlInfo.numDlLc], &ueCfg->schLcCfg[lcIdx]);
248          ueCb->dlInfo.numDlLc++;
249       }
250       else
251       {
252          for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++) //searching for Lc to be Mod
253          {
254             if(ueCb->ulInfo.ulLcCtxt[ueLcIdx].lcId == ueCfg->schLcCfg[lcIdx].lcId)
255             {
256                if(ueCfg->schLcCfg[lcIdx].configType == CONFIG_MOD)
257                {
258                   fillSchUlLcCtxt(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
259                   fillSchDlLcCtxt(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], &ueCfg->schLcCfg[lcIdx]);
260                   break;
261                }
262                if(ueCfg->schLcCfg[ueLcIdx].configType == CONFIG_DEL)
263                {
264                   memset(&ueCb->ulInfo.ulLcCtxt[ueLcIdx], 0, sizeof(SchUlLcCtxt));
265                   ueCb->ulInfo.numUlLc--;
266                   updateSchUlCb(ueLcIdx, &ueCb->ulInfo); //moving arr elements one idx ahead 
267                   memset(&ueCb->dlInfo.dlLcCtxt[ueLcIdx], 0, sizeof(SchDlLcCtxt));
268                   ueCb->dlInfo.numDlLc--;
269                   updateSchDlCb(ueLcIdx, &ueCb->dlInfo); //moving arr elements one idx ahead
270                   break;
271                }
272             }
273          }/*End of inner for loop */
274       }
275    }/* End of outer for loop */
276    return ROK;
277 }
278
279 /*******************************************************************
280  *
281  * @brief Function to get SCH Cell Cb
282  *
283  * @details
284  *
285  *    Function : getSchCellCb
286  *
287  *    Functionality: Function to get SCH Cell Cb
288  *
289  * @params[in] event, SchUeCfg pointer 
290  * @return schUeCb pointer  - success
291  *         NULLP - failure
292  *
293  * ****************************************************************/
294
295 SchCellCb *getSchCellCb(uint16_t srcEvent, Inst inst, SchUeCfg *ueCfg)
296 {
297    uint8_t      idx;
298    SchCellCb    *cellCb = NULLP;
299    SchUeCfgRsp  cfgRsp;
300    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
301
302    /* Search of cell cb */
303    for(idx = 0; idx < MAX_NUM_CELL; idx++)
304    {
305       cellCb = schCb[inst].cells[idx];
306       if(cellCb->cellId == ueCfg->cellId)
307          break;
308    }
309    if(idx == MAX_NUM_CELL)
310    {
311       DU_LOG("\nERROR  -->  SCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
312       SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
313       return NULLP;
314    }
315
316    /* Check if max number of UE configured */
317    if(cellCb->numActvUe > MAX_NUM_UE)
318    {
319       DU_LOG("\nERROR  -->  SCH :  Max number of UE [%d] already configured", MAX_NUM_UE);
320       SchSendUeCfgRspToMac(srcEvent, ueCfg, inst, RSP_NOK, &cfgRsp);
321       return NULLP;
322    }
323    return cellCb;
324 }
325
326
327 /*******************************************************************
328  *
329  * @brief Function to Add Ue Config Request from MAC
330  *
331  * @details
332  *
333  *    Function : MacSchAddUeConfigReq
334  *
335  *    Functionality: Function to Add Ue config request from MAC
336  *
337  * @params[in] 
338  * @return ROK     - success
339  *         RFAILED - failure
340  *
341  * ****************************************************************/
342 uint8_t MacSchAddUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
343 {
344    uint8_t ueIdx, lcIdx, ret = ROK;
345    SchCellCb    *cellCb = NULLP;
346    SchUeCb      *ueCb = NULLP;
347    SchUeCfgRsp  cfgRsp;
348    Inst         inst = pst->dstInst - 1;
349    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
350
351    if(!ueCfg)
352    {
353       DU_LOG("\nERROR  -->  SCH :  Adding UE Config Request failed at MacSchAddUeConfigReq()");
354       return RFAILED;
355    }
356    DU_LOG("\nDEBUG  -->  SCH :  Adding UE Config Request for CRNTI[%d]", ueCfg->crnti);
357    cellCb = getSchCellCb(pst->event, inst, ueCfg);
358
359    /* Search if UE already configured */
360    GET_UE_IDX(ueCfg->crnti, ueIdx);
361    ueCb = &cellCb->ueCb[ueIdx -1];
362    if(ueCb)
363    {
364       if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
365       {
366          DU_LOG("\nDEBUG  -->  SCH : CRNTI %d already configured ", ueCfg->crnti);
367          SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
368          return ROK;
369       }
370    }
371    else
372    {
373       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at MacSchAddUeConfigReq() ");
374       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
375       return RFAILED;
376    }
377
378    /* Fill received Ue Configuration in UeCb */
379    memset(ueCb, 0, sizeof(SchUeCb));
380    GET_UE_IDX(ueCfg->crnti, ueIdx);
381    ueCb->ueIdx = ueIdx;
382    ueCb->crnti = ueCfg->crnti;
383    ueCb->state = SCH_UE_STATE_ACTIVE;
384    ret = fillSchUeCb(ueCb, ueCfg);
385    if(ret == ROK)
386    {
387       cellCb->numActvUe++;
388       SET_ONE_BIT(ueCb->ueIdx, cellCb->actvUeBitMap);
389       ueCb->cellCb = cellCb;
390       ueCb->srRcvd = false;
391       for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
392          ueCb->bsrInfo[lcIdx].dataVol = 0;
393
394       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
395    }
396    return ret;
397 }
398
399 /*******************************************************************
400 *
401 * @brief Fills PUSCH UL allocation
402 *
403 * @details
404 *
405 *    Function : schFillPuschAlloc
406 *
407 *    Functionality: fills PUSCH info
408 *
409 * @params[in]
410 * @return ROK     - success
411 *         RFAILED - failure
412 *
413 * ****************************************************************/
414 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
415 {
416   uint16_t puschSlot      = 0;
417   uint16_t startRb        = 0;
418   uint8_t  numRb          = 0;
419   uint8_t  numPdschSymbols= 14;
420   uint16_t tbSize         = 0;
421   uint8_t  buffer         = 5;
422   uint8_t  idx            = 0;
423   SchCellCb *cellCb       = ueCb->cellCb;
424   SchUlSlotInfo *schUlSlotInfo = NULLP;
425   uint8_t k2=0, startSymb=0 , symbLen=0;
426   
427   if(ueCb->ueCfg.spCellCfgPres == true)
428   {
429      k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
430      startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
431      symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
432   }
433   puschSlot = (pdcchSlot + k2) % cellCb->numSlots;
434
435   startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
436   tbSize  = schCalcTbSize(dataVol + buffer); /*  2 bytes header + some buffer */
437   numRb   = schCalcNumPrb(tbSize, ueCb->ueCfg.ulModInfo.mcsIndex, numPdschSymbols);
438   /* increment PUSCH PRB */
439
440   cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
441
442   puschInfo->crnti             = ueCb->crnti; 
443   puschInfo->harqProcId        = SCH_HARQ_PROC_ID;
444   puschInfo->resAllocType      = SCH_ALLOC_TYPE_1;
445   puschInfo->fdAlloc.startPrb  = startRb;
446   puschInfo->fdAlloc.numPrb    = numRb;
447   puschInfo->tdAlloc.startSymb = startSymb;
448   puschInfo->tdAlloc.numSymb   = symbLen;
449   puschInfo->tbInfo.qamOrder   = ueCb->ueCfg.ulModInfo.modOrder;
450   puschInfo->tbInfo.mcs        = ueCb->ueCfg.ulModInfo.mcsIndex;
451   puschInfo->tbInfo.mcsTable   = ueCb->ueCfg.ulModInfo.mcsTable;
452   puschInfo->tbInfo.ndi        = 1; /* new transmission */
453   puschInfo->tbInfo.rv         = 0;
454   puschInfo->tbInfo.tbSize     = tbSize;
455   puschInfo->dmrsMappingType   = DMRS_MAP_TYPE_A;  /* Setting Type-A */
456   puschInfo->nrOfDmrsSymbols   = NUM_DMRS_SYMBOLS;
457   puschInfo->dmrsAddPos        = DMRS_ADDITIONAL_POS;
458
459   /* Update pusch in cell */
460   for(idx=startSymb; idx<symbLen; idx++)
461   {
462      cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
463   }
464
465   schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
466
467   SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
468   if(!schUlSlotInfo->schPuschInfo)
469   {
470      DU_LOG("\nERROR  -->  SCH: Memory allocation failed in schAllocMsg3Pusch");
471      return RFAILED;
472   }
473   memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
474
475   return ROK;
476 }
477
478 /*******************************************************************
479  *
480  * @brief Fills DCI for UL grant
481  *
482  * @details
483  *
484  *    Function : schFillUlDci
485  *
486  *    Functionality: fills DCI for UL grant in response to BSR
487  *
488  * @params[in]
489  * @return ROK     - success
490  *         RFAILED - failure
491  *
492  * ****************************************************************/
493 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
494 {
495    SchCellCb         *cellCb  = ueCb->cellCb;
496    SchControlRsrcSet coreset1 ;
497   
498    memset(&coreset1, 0, sizeof(SchControlRsrcSet));
499    if(ueCb->ueCfg.spCellCfgPres == true)
500    {
501      coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
502    }
503    
504    dciInfo->cellId = cellCb->cellId;
505    dciInfo->crnti  = ueCb->crnti;
506
507    /* fill bwp cfg */
508    dciInfo->bwpCfg.subcarrierSpacing  = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
509    dciInfo->bwpCfg.cyclicPrefix       = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
510    dciInfo->bwpCfg.freqAlloc.startPrb = 0;
511    dciInfo->bwpCfg.freqAlloc.numPrb   = MAX_NUM_RB; /* whole of BW */
512
513    /*fill coreset cfg */
514    //Considering number of RBs in coreset1 is same as coreset0
515    dciInfo->coresetCfg.coreSetSize      = coresetIdxTable[0][1];
516    //Considering coreset1 also starts from same symbol as coreset0
517    dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
518    dciInfo->coresetCfg.durationSymbols  = coreset1.duration;
519    memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
520    
521    dciInfo->coresetCfg.cceRegMappingType   = coreset1.cceRegMappingType; /* non-interleaved */
522    dciInfo->coresetCfg.regBundleSize       = 6; /* must be 6 for non-interleaved */
523    dciInfo->coresetCfg.interleaverSize     = 0; /* NA for non-interleaved */
524    dciInfo->coresetCfg.coreSetType         = 1; /* non PBCH coreset */
525    dciInfo->coresetCfg.shiftIndex          = cellCb->cellCfg.phyCellId;
526    dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
527    dciInfo->coresetCfg.cceIndex            = 0; /* 0-3 for UL and 4-7 for DL */
528    dciInfo->coresetCfg.aggregationLevel    = 4; /* same as for sib1 */
529    
530    dciInfo->formatType = FORMAT0_0;
531    
532    /* fill UL grant */
533    dciInfo->format.format0_0.resourceAllocType   = puschInfo.resAllocType;
534    dciInfo->format.format0_0.freqAlloc.startPrb  = puschInfo.fdAlloc.startPrb;
535    dciInfo->format.format0_0.freqAlloc.numPrb    = puschInfo.fdAlloc.numPrb;
536    dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
537    dciInfo->format.format0_0.timeAlloc.numSymb   = puschInfo.tdAlloc.numSymb;
538    dciInfo->format.format0_0.rowIndex            = 0; /* row Index */
539    dciInfo->format.format0_0.mcs                 = puschInfo.tbInfo.mcs;
540    dciInfo->format.format0_0.harqProcId          = puschInfo.harqProcId;
541    dciInfo->format.format0_0.puschHopFlag        = FALSE; /* disabled */
542    dciInfo->format.format0_0.freqHopFlag         = FALSE; /* disabled */
543    dciInfo->format.format0_0.ndi                 = puschInfo.tbInfo.ndi; /* new transmission */
544    dciInfo->format.format0_0.rv                  = puschInfo.tbInfo.rv;
545    dciInfo->format.format0_0.tpcCmd              = 0; //Sphoorthi TODO: check
546    dciInfo->format.format0_0.sUlCfgd             = FALSE; /* SUL not configured */
547    
548    /* Fill DCI Structure */
549    dciInfo->dciInfo.rnti                              = ueCb->crnti;
550    dciInfo->dciInfo.scramblingId                      = cellCb->cellCfg.phyCellId;
551    dciInfo->dciInfo.scramblingRnti                    = 0;
552    dciInfo->dciInfo.cceIndex                          = 0; /* 0-3 for UL and 4-7 for DL */
553    dciInfo->dciInfo.aggregLevel                       = 4;
554    dciInfo->dciInfo.beamPdcchInfo.numPrgs             = 1;
555    dciInfo->dciInfo.beamPdcchInfo.prgSize             = 1;
556    dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces     = 0;
557    dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx        = 0;
558    dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0]   = 0;
559    dciInfo->dciInfo.txPdcchPower.powerValue           = 0;
560    dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
561    dciInfo->dciInfo.pdschCfg                          = NULLP; /* No DL data being sent */
562
563    return ROK;
564 }
565
566 /*******************************************************************
567  *
568  * @brief Function to Modify Ue Config request from MAC
569  *
570  * @details
571  *
572  *    Function : MacSchModUeConfigReq
573  *
574  *    Functionality: Function to modify Ue Config request from MAC
575  *
576  * @params[in] 
577  * @return ROK     - success
578  *         RFAILED - failure
579  *
580  * ****************************************************************/
581 uint8_t MacSchModUeConfigReq(Pst *pst, SchUeCfg *ueCfg)
582 {
583    uint8_t ueIdx, lcIdx, ret = ROK;
584    SchCellCb    *cellCb = NULLP;
585    SchUeCb      *ueCb = NULLP;
586    SchUeCfgRsp  cfgRsp;
587    Inst         inst = pst->dstInst - 1;
588    memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
589
590    if(!ueCfg)
591    {
592       DU_LOG("\nERROR  -->  SCH : Modifying Ue Config request failed at MacSchModUeConfigReq()");
593       return RFAILED;
594    }
595    DU_LOG("\nDEBUG  -->  SCH : Modifying Ue Config Request for CRNTI[%d]", ueCfg->crnti);
596    cellCb = getSchCellCb(pst->event, inst, ueCfg);
597
598    /* Search if UE already configured */
599    GET_UE_IDX(ueCfg->crnti, ueIdx);
600    ueCb = &cellCb->ueCb[ueIdx -1];
601    
602    if(!ueCb)
603    {
604       DU_LOG("\nERROR  -->  SCH : SchUeCb not found at MacSchModUeConfigReq() ");
605       SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_NOK, &cfgRsp);
606       return RFAILED;
607    }
608    if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
609    {
610       /* Found the UeCb to Reconfig */
611       ret = fillSchUeCb(ueCb, ueCfg);
612       if(ret == ROK)
613       {
614          ueCb->cellCb = cellCb;
615          ueCb->srRcvd = false;
616          for(lcIdx=0; lcIdx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; lcIdx++)
617             ueCb->bsrInfo[lcIdx].dataVol = 0;
618
619          SchSendUeCfgRspToMac(pst->event, ueCfg, inst, RSP_OK, &cfgRsp);
620       }
621    }
622    return ret;
623 }
624 /*******************************************************************
625 *
626 * @brief Fill and send UE delete response to MAC
627 *
628 * @details
629 *
630 *    Function :  SchSendUeDeleteRspToMac
631 *
632 *    Functionality: Fill and send UE delete response to MAC
633 *
634 * @params[in] Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, 
635 *              ErrorCause cause
636 * @return ROK     - success
637 *         RFAILED - failure
638 *
639 * ****************************************************************/
640 void SchSendUeDeleteRspToMac(Inst inst, SchUeDelete  *ueDelete, SchMacRsp result, ErrorCause cause)
641 {
642     Pst rspPst;
643     SchUeDeleteRsp  delRsp;
644     
645     memset(&delRsp, 0, sizeof(SchUeDeleteRsp));
646     delRsp.cellId = ueDelete->cellId;
647     delRsp.crnti = ueDelete->crnti;
648     delRsp.rsp = result; 
649     delRsp.cause = cause; 
650
651     /* Filling response post */
652     memset(&rspPst, 0, sizeof(Pst));
653     FILL_PST_SCH_TO_MAC(rspPst, inst);
654     rspPst.event = EVENT_UE_DELETE_RSP_TO_MAC;
655     SchUeDeleteRspOpts[rspPst.selector](&rspPst, &delRsp);
656 }
657 /*******************************************************************
658 *
659 * @brief Function to delete Sch Pucch ResrcCfg
660 *
661 * @details
662 *
663 *    Function : deleteSchPucchResrcCfg 
664 *
665 *    Functionality: Function to delete Sch Pucch ResrcCfg
666 *
667 * @params[in] SchPucchResrcCfg *resrc
668 * @return void 
669 *
670 * ****************************************************************/
671
672 void deleteSchPucchResrcCfg(SchPucchResrcCfg *resrc)
673 {
674    uint8_t rsrcIdx=0;
675    for(rsrcIdx=0; rsrcIdx < resrc->resrcToAddModListCount; rsrcIdx++)
676    {
677       switch(resrc->resrcToAddModList[rsrcIdx].pucchFormat)
678       {
679          case PUCCH_FORMAT_0:
680          {
681             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format0,\
682             sizeof(SchPucchFormat0));
683             break;
684          }
685          case PUCCH_FORMAT_1:
686          {
687             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format1,\
688             sizeof(SchPucchFormat1));
689             break;
690          }
691          case PUCCH_FORMAT_2:
692          {
693             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format2,\
694             sizeof(SchPucchFormat2_3));
695             break;
696          }
697          case PUCCH_FORMAT_3:
698          {
699             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format3,\
700             sizeof(SchPucchFormat2_3));
701             break;
702          }
703          case PUCCH_FORMAT_4:
704          {
705             SCH_FREE(resrc->resrcToAddModList[rsrcIdx].SchPucchFormat.format4,\
706             sizeof(SchPucchFormat4));
707             break;
708          }
709       }
710    }
711 }
712 /*******************************************************************
713 *
714 * @brief Function to delete SCH Pdsch ServCellCfg
715 *
716 * @details
717 *
718 *    Function : deleteSchPdschServCellCfg
719 *
720 *    Functionality: Function to delete SCH Pdsch ServCellCfg
721 *
722 * @params[in] SchPdschServCellCfg *pdschServCellCfg
723 * @return void 
724 *
725 * ****************************************************************/
726
727 void deleteSchPdschServCellCfg(SchPdschServCellCfg *pdschServCellCfg)
728 {
729    SCH_FREE(pdschServCellCfg->maxMimoLayers, sizeof(uint8_t));
730    SCH_FREE(pdschServCellCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
731    SCH_FREE(pdschServCellCfg->codeBlkGrpFlushInd, sizeof(bool));
732    SCH_FREE(pdschServCellCfg->xOverhead, sizeof(SchPdschXOverhead));
733 }
734 /*******************************************************************
735 *
736 * @brief Function to  delete SCH UeCb
737 *
738 * @details
739 *
740 *    Function : deleteSchUeCb 
741 *
742 *    Functionality: Function to delete SCH UeCb
743 *
744 * @params[in]
745 * @return ROK     - success
746 *         RFAILED - failure
747 *
748 * ****************************************************************/
749 void deleteSchUeCb(SchUeCb *ueCb) 
750 {
751    SchPucchCfg *pucchCfg = NULLP;
752    if(ueCb)
753    {
754       SCH_FREE(ueCb->ueCfg.ambrCfg, sizeof(SchAmbrCfg));
755       if(ueCb->ueCfg.spCellCfgPres)
756       {
757          if(ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfgPres == true)
758          {
759             pucchCfg = &ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.pucchCfg;
760             SCH_FREE(pucchCfg->resrcSet,sizeof(SchPucchResrcSetCfg));
761             if(pucchCfg->resrc)
762             {
763                deleteSchPucchResrcCfg(pucchCfg->resrc);
764                SCH_FREE(pucchCfg->resrc, sizeof(SchPucchResrcCfg));
765             }
766             SCH_FREE(pucchCfg->format1, sizeof(SchPucchFormatCfg));
767             SCH_FREE(pucchCfg->format2, sizeof(SchPucchFormatCfg));
768             SCH_FREE(pucchCfg->format3, sizeof(SchPucchFormatCfg));
769             SCH_FREE(pucchCfg->format4, sizeof(SchPucchFormatCfg));
770             SCH_FREE(pucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
771             SCH_FREE(pucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
772             SCH_FREE(pucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));  
773             SCH_FREE(pucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
774             SCH_FREE(pucchCfg->powerControl,sizeof(SchPucchPowerControl));
775          }
776          SCH_FREE(ueCb->ueCfg.spCellCfg.servCellCfg.bwpInactivityTmr, sizeof(uint8_t));
777          deleteSchPdschServCellCfg(&ueCb->ueCfg.spCellCfg.servCellCfg.pdschServCellCfg);
778       }
779       memset(ueCb, 0, sizeof(SchUeCb));
780    }
781 }
782 /*******************************************************************
783 *
784 * @brief Function for Ue Delete request from MAC to SCH
785 *
786 * @details
787 *
788 *    Function : MacSchUeDeleteReq 
789 *
790 *    Functionality: Function for Ue Delete request from MAC to SCH
791 *
792 * @params[in] Pst *pst, SchUeDelete  *ueDelete
793 * @return ROK     - success
794 *         RFAILED - failure
795 *
796 * ****************************************************************/
797 uint8_t MacSchUeDeleteReq(Pst *pst, SchUeDelete  *ueDelete)
798 {
799     uint8_t idx=0, ueIdx=0, ret=ROK;
800     ErrorCause result;
801     SchCellCb    *cellCb = NULLP;
802     SchUeCb      ueCb ;
803     Inst         inst = pst->dstInst - 1;
804     
805     if(!ueDelete)
806     {
807        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): Ue Delete request failed");
808        ret = RFAILED;
809     }
810     DU_LOG("\nDEBUG  -->  SCH : Ue Delete request received for crnti[%d]", ueDelete->crnti);
811     
812     cellCb = schCb[inst].cells[idx];
813
814     if(cellCb->cellId != ueDelete->cellId)
815     {
816        DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): cell Id is not available");
817        result =  INVALID_CELLID;
818     }
819     else
820     {
821        GET_UE_IDX(ueDelete->crnti, ueIdx);
822        ueCb = cellCb->ueCb[ueIdx-1];
823        if((ueCb.crnti == ueDelete->crnti) && (ueCb.state == SCH_UE_STATE_ACTIVE))
824        {
825           deleteSchUeCb(&ueCb);
826           result = NOT_APPLICABLE;
827        }
828        else
829        {
830           DU_LOG("\nERROR  -->  SCH : MacSchUeDeleteReq(): SchUeCb not found");
831           result =  INVALID_UEIDX;
832        }
833     }
834     
835     if(result == NOT_APPLICABLE)
836     {
837        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_OK, result);
838     }
839     else
840     {
841        SchSendUeDeleteRspToMac(inst, ueDelete, RSP_NOK, result);
842        ret = RFAILED;
843     }
844     return ret;
845 }
846
847 /**********************************************************************
848   End of file
849  **********************************************************************/