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