77fc0f9c9260dc7b2e930c1231d0e9812f851ba3
[o-du/l2.git] / src / 5gnrmac / mac_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
19 /* This file contains UE management handling functionality for MAC */
20
21 /* header include files (.h) */
22 #include "common_def.h"
23 #include "lrg.h"
24 #include "lrg.x"
25 #include "du_app_mac_inf.h"
26 #include "mac_sch_interface.h"
27 #include "lwr_mac_upr_inf.h"
28 #include "mac.h"
29 #include "mac_utils.h"
30
31 /* function pointers for packing slot ind from mac to sch */
32 MacSchAddUeConfigReqFunc macSchAddUeConfigReqOpts[] =
33 {
34    packMacSchAddUeConfigReq,    /* packing for loosely coupled */
35    MacSchAddUeConfigReq,        /* packing for tightly coupled */
36    packMacSchAddUeConfigReq     /* packing for light weight loosely coupled */
37 };
38
39 MacDuUeCfgRspFunc macDuUeCfgRspOpts[] =
40 {
41    packDuMacUeCfgRsp,   /* packing for loosely coupled */
42    DuProcMacUeCfgRsp,   /* packing for tightly coupled */
43    packDuMacUeCfgRsp   /* packing for light weight loosly coupled */
44 };
45
46 MacSchModUeConfigReqFunc macSchModUeConfigReqOpts[] =
47 {
48    packMacSchModUeConfigReq,    /* packing for loosely coupled */
49    MacSchModUeConfigReq,        /* packing for tightly coupled */
50    packMacSchModUeConfigReq     /* packing for light weight loosely coupled */
51 };
52
53 MacSchUeDeleteReqFunc macSchUeDeleteReqOpts[] =
54 {
55    packMacSchUeDeleteReq,    /* packing for loosely coupled */
56    MacSchUeDeleteReq,        /* packing for tightly coupled */
57    packMacSchUeDeleteReq     /* packing for light weight loosely coupled */
58 };
59
60 MacDuUeDeleteRspFunc macDuUeDeleteRspOpts[] =
61 {
62    packDuMacUeDeleteRsp,   /* packing for loosely coupled */
63    DuProcMacUeDeleteRsp,   /* packing for tightly coupled */
64    packDuMacUeDeleteRsp   /* packing for light weight loosly coupled */
65 };
66
67 /*******************************************************************
68  *
69  * @brief Fills mac cell group config to be sent to scheduler
70  *
71  * @details
72  *
73  *    Function : fillMacCellGroupCfg
74  *
75  *    Functionality: Fills mac cell group config to be sent to sch
76  *
77  * @params[in] macCellGrp : mac cell group config at MAC
78  *             *macCellGrpCfg : mac cell group cfg to be filled
79  * @return ROK     - success
80  *         RFAILED - failure
81  *
82  * ****************************************************************/
83 uint8_t fillMacCellGroupCfg(MacCellGrpCfg macCellGrp, SchMacCellGrpCfg  *macCellGrpCfg)
84 {
85    uint8_t           idx;
86    SchSchedReqCfg    *schedReqCfg;
87    SchTagCfg         *tagCfg;
88
89    /* Copy scheduling request config */
90    schedReqCfg = &macCellGrpCfg->schedReqCfg;
91    schedReqCfg->addModListCount = macCellGrp.schReqCfg.addModListCount;
92    if(schedReqCfg->addModListCount > MAX_NUM_SR_CFG_PER_CELL_GRP)
93    {
94       DU_LOG("\nERROR  -->  MAC : Scheduling Request Add/Mod Count %d exceeds max limit %d", \
95             schedReqCfg->addModListCount, MAX_NUM_SR_CFG_PER_CELL_GRP);
96       return RFAILED;
97    }
98    for(idx = 0; idx < schedReqCfg->addModListCount; idx++)
99    {
100       schedReqCfg->addModList[idx].schedReqId = \
101          macCellGrp.schReqCfg.addModList[idx].schedReqId;
102       schedReqCfg->addModList[idx].srProhibitTmr = \
103          macCellGrp.schReqCfg.addModList[idx].srProhibitTmr;
104       schedReqCfg->addModList[idx].srTransMax = \
105          macCellGrp.schReqCfg.addModList[idx].srTransMax;
106    }
107    schedReqCfg->relListCount = macCellGrp.schReqCfg.relListCount;
108
109    /* copy TAG config */
110    tagCfg = &macCellGrpCfg->tagCfg;
111    tagCfg->addModListCount = macCellGrp.tagCfg.addModListCount;
112    if(tagCfg->addModListCount > MAX_NUM_TAGS)
113    {
114       DU_LOG("\nERROR  -->  MAC : Scheduling Request Add/Mod Count %d exceeds max limit %d", \
115             tagCfg->addModListCount, MAX_NUM_TAGS);
116       return RFAILED;
117    }
118    for(idx = 0; idx < tagCfg->addModListCount; idx++)
119    {
120       tagCfg->addModList[idx].tagId = \
121          macCellGrp.tagCfg.addModList[idx].tagId;
122       tagCfg->addModList[idx].timeAlignmentTmr = \
123          macCellGrp.tagCfg.addModList[idx].timeAlignTimer;
124    }
125    tagCfg->relListCount = macCellGrp.tagCfg.relListCount;
126
127    /* Copy PHR config */
128    if(macCellGrp.phrCfgSetupPres)
129    {
130       macCellGrpCfg->phrCfg.periodicTmr = macCellGrp.phrCfg.periodicTimer;
131       macCellGrpCfg->phrCfg.prohibitTmr =  macCellGrp.phrCfg.prohibitTimer;
132       macCellGrpCfg->phrCfg.txpowerFactorChange = macCellGrp.phrCfg.txPowerFactor;
133       macCellGrpCfg->phrCfg.multiplePhr = macCellGrp.phrCfg.multiplePHR;
134       macCellGrpCfg->phrCfg.dummy = macCellGrp.phrCfg.dummy;
135       macCellGrpCfg->phrCfg.type2OtherCell = macCellGrp.phrCfg.phrType2OtherCell;
136       macCellGrpCfg->phrCfg.modeOtherCG = macCellGrp.phrCfg.phrOtherCG;
137    }
138
139    return ROK;
140 }
141
142 /*******************************************************************
143  *
144  * @brief Fills phy cell group config to be sent to scheduler
145  *
146  * @details
147  *
148  *    Function : fillPhyCellGroupCfg
149  *
150  *    Functionality: Fills phy cell group config to be sent to sch
151  *
152  * @params[in] macUeCfg : Phy cell group config at MAC
153  *             *schPhyCellGrp : phy cell group config to be filled
154  * @return ROK     - success
155  *         RFAILED - failure
156  *
157  * ****************************************************************/
158 uint8_t fillPhyCellGroupCfg(PhyCellGrpCfg macUeCfg, SchPhyCellGrpCfg *schPhyCellGrp)
159 {
160    schPhyCellGrp->pdschHarqAckCodebook = macUeCfg.pdschHarqAckCodebook;
161    schPhyCellGrp->pNrFr1 = macUeCfg.pNrFr1;
162
163    return ROK;
164 }
165
166 /*******************************************************************
167  *
168  * @brief Fills PDSCh serving cell config to send to scheduler
169  *
170  * @details
171  *
172  *    Function : fillPdschServCellCfg 
173  *
174  *    Functionality: Fills PDSCh serving cell config to send to scheduler
175  *
176  * @params[in] macPdschCfg : Pdsch serving cell config at MAC
177  *             *schPdschCfg : Pdsch serving cell config to be filled
178  * @return ROK     - success
179  *         RFAILED - failure
180  *
181  * ****************************************************************/
182 uint8_t fillPdschServCellCfg(PdschServCellCfg macPdschCfg, SchPdschServCellCfg *schPdschCfg) 
183 {
184    if(macPdschCfg.maxMimoLayers)
185    {
186       if(!schPdschCfg->maxMimoLayers)
187       {
188          MAC_ALLOC(schPdschCfg->maxMimoLayers, sizeof(uint8_t));
189          if(!schPdschCfg->maxMimoLayers)
190          {
191             DU_LOG("\nERROR  -->  MAC :Memory Alloc MimoLayers Failed at fillPdschServCellCfg()");
192             return RFAILED;
193          }
194       }
195       *schPdschCfg->maxMimoLayers = *macPdschCfg.maxMimoLayers;
196    }
197    else
198    {
199       schPdschCfg->maxMimoLayers = NULLP;
200    }
201
202    schPdschCfg->numHarqProcForPdsch = \
203       macPdschCfg.numHarqProcForPdsch;
204
205    if(macPdschCfg.maxCodeBlkGrpPerTb)
206    {
207       if(!schPdschCfg->maxCodeBlkGrpPerTb)
208       {
209          MAC_ALLOC(schPdschCfg->maxCodeBlkGrpPerTb, sizeof(SchMaxCodeBlkGrpPerTB));
210          if(!schPdschCfg->maxCodeBlkGrpPerTb)
211          {
212             DU_LOG("\nERROR  -->  MAC :Memory Alloc for code Block Failed at fillPdschServCellCfg()");
213             return RFAILED;
214          }
215       }
216       *schPdschCfg->maxCodeBlkGrpPerTb = *macPdschCfg.maxCodeBlkGrpPerTb;
217    }
218    else
219    {
220       schPdschCfg->maxCodeBlkGrpPerTb = NULLP;
221    }
222
223    if(macPdschCfg.codeBlkGrpFlushInd)
224    {
225       if(!schPdschCfg->codeBlkGrpFlushInd)
226       {
227          MAC_ALLOC(schPdschCfg->codeBlkGrpFlushInd, sizeof(bool));
228          if(!schPdschCfg->codeBlkGrpFlushInd)
229          {
230             DU_LOG("\nERROR  -->  MAC :Memory Alloc for Flush Ind Failed at fillPdschServCellCfg()");
231             return RFAILED;
232          }
233       }
234       *schPdschCfg->codeBlkGrpFlushInd = *macPdschCfg.codeBlkGrpFlushInd;
235    }
236    else
237    {
238       schPdschCfg->codeBlkGrpFlushInd = NULLP;
239    }
240
241    if(macPdschCfg.xOverhead)
242    {
243       if(!schPdschCfg->xOverhead)
244       {
245          MAC_ALLOC(schPdschCfg->xOverhead, sizeof(SchPdschXOverhead));
246          if(!schPdschCfg->xOverhead)
247          {
248             DU_LOG("\nERROR  -->  MAC :Memory Alloc for xOverHead Failed at fillPdschServCellCfg()");
249             return RFAILED;
250          }
251       }
252       *schPdschCfg->xOverhead = *macPdschCfg.xOverhead;
253    }
254    else
255    {
256       schPdschCfg->xOverhead = NULLP;
257    }
258
259    return ROK;
260 }
261
262 /*******************************************************************
263  *
264  * @brief Fills PUSCH cofig in initial UL BWP config for SCH UE Cfg
265  *
266  * @details
267  *
268  *    Function : fillInitalUlBwpPuschCfg
269  *
270  *    Functionality:
271  *       Fills PUSCH cofig in initial UL BWP config for SCH UE Cfg
272  *
273  * @params[in] macPuschCfg : Initial UL-BWP PUSCH cfg at MAC
274  *             schPuschCfg : Initial UL-BWP PUSCH cfg to be filled
275  * @return ROK     - success
276  *         RFAILED - failure
277  *
278  * ****************************************************************/
279 uint8_t fillInitalUlBwpPuschCfg(PuschCfg macPuschCfg, SchPuschCfg *schPuschCfg)
280 {
281    uint8_t   idx;
282
283    schPuschCfg->dataScramblingId = macPuschCfg.dataScramblingId;
284    schPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos = \
285       macPuschCfg.dmrsUlCfgForPuschMapTypeA.addPos;
286    schPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
287       macPuschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0;
288    schPuschCfg->resourceAllocType = macPuschCfg.resourceAllocType;
289
290    schPuschCfg->numTimeDomRsrcAlloc = macPuschCfg.numTimeDomRsrcAlloc;
291    if(schPuschCfg->numTimeDomRsrcAlloc > MAX_NUM_UL_ALLOC)
292    {
293       DU_LOG("\nERROR  -->  MAC : Number of Time domain resource allocation [%d] exceeds max limit [%d]",\
294             schPuschCfg->numTimeDomRsrcAlloc, MAX_NUM_UL_ALLOC);
295       return RFAILED;
296    }    
297    for(idx = 0; idx < schPuschCfg->numTimeDomRsrcAlloc; idx++)
298    {
299       schPuschCfg->timeDomRsrcAllocList[idx].k2 = \
300          macPuschCfg.timeDomRsrcAllocList[idx].k2;
301       schPuschCfg->timeDomRsrcAllocList[idx].mappingType = \
302          macPuschCfg.timeDomRsrcAllocList[idx].mappingType;
303       schPuschCfg->timeDomRsrcAllocList[idx].startSymbol = \
304          macPuschCfg.timeDomRsrcAllocList[idx].startSymbol; 
305       schPuschCfg->timeDomRsrcAllocList[idx].symbolLength = \
306          macPuschCfg.timeDomRsrcAllocList[idx].symbolLength;
307    }
308
309    schPuschCfg->transformPrecoder = macPuschCfg.transformPrecoder;
310    return ROK;
311 }
312
313 /*******************************************************************
314  *
315  * @brief Function to fillResrcSetList sent by DU
316  *
317  * @details
318  *
319  *    Function : fillResrcSetList
320  *
321  *    Functionality: Function to fillResrcSetList sent by DU
322  *
323  * @params[in] PucchResrcSetCfg pointer,
324  *             SchPucchResrcSetCfg pointer
325  * @return void
326  *
327  * ****************************************************************/
328
329 void fillResrcSetList(PucchResrcSetCfg *macRsrcSetList, SchPucchResrcSetCfg *schRsrcSetList)
330 {
331    uint8_t arrIdx, rsrcListIdx;
332
333    /* ResrcSetToAddModList */
334    schRsrcSetList->resrcSetToAddModListCount  = macRsrcSetList->resrcSetToAddModListCount;
335    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToAddModListCount; arrIdx++)
336    {
337      schRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId =\
338         macRsrcSetList->resrcSetToAddModList[arrIdx].resrcSetId;
339      
340      schRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize =\
341         macRsrcSetList->resrcSetToAddModList[arrIdx].maxPayLoadSize;
342      
343      schRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount =\
344         macRsrcSetList->resrcSetToAddModList[arrIdx].resrcListCount;
345      for(rsrcListIdx = 0; rsrcListIdx < macRsrcSetList->resrcSetToAddModList[arrIdx].\
346          resrcListCount; rsrcListIdx++)
347       {
348          schRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx] =\
349          macRsrcSetList->resrcSetToAddModList[arrIdx].resrcList[rsrcListIdx];
350       }
351    }
352    /* ResrcSetToRelList */
353    schRsrcSetList->resrcSetToRelListCount = macRsrcSetList->resrcSetToRelListCount;
354    for(arrIdx = 0; arrIdx < macRsrcSetList->resrcSetToRelListCount; arrIdx++)
355    {
356       schRsrcSetList->resrcSetToRelList[arrIdx] = macRsrcSetList->resrcSetToRelList[arrIdx]; 
357    }
358 }
359
360 /*******************************************************************
361  *
362  * @brief Function to fillResrcList sent by DU
363  *
364  * @details
365  *
366  *    Function : fillResrcList
367  *
368  *    Functionality: Function to fillResrcList sent by DU
369  *
370  * @params[in] PucchResrcCfg pointer,
371  *             SchPucchResrcCfg pointer
372  * @return ROK/RFAILED;
373  *
374  * ****************************************************************/
375 uint8_t fillResrcList(PucchResrcCfg *macResrcCfg, SchPucchResrcCfg *schResrcCfg)
376 {
377    uint8_t arrIdx;
378    
379    schResrcCfg->resrcToAddModListCount = macResrcCfg->resrcToAddModListCount;
380    for(arrIdx=0; arrIdx < macResrcCfg->resrcToAddModListCount; arrIdx++)
381    {
382       schResrcCfg->resrcToAddModList[arrIdx].resrcId =\
383          macResrcCfg->resrcToAddModList[arrIdx].resrcId;
384       schResrcCfg->resrcToAddModList[arrIdx].startPrb =\
385          macResrcCfg->resrcToAddModList[arrIdx].startPrb;
386       schResrcCfg->resrcToAddModList[arrIdx].intraFreqHop =\
387          macResrcCfg->resrcToAddModList[arrIdx].intraFreqHop;
388       schResrcCfg->resrcToAddModList[arrIdx].secondPrbHop =\
389          macResrcCfg->resrcToAddModList[arrIdx].secondPrbHop;
390       schResrcCfg->resrcToAddModList[arrIdx].pucchFormat =\
391          macResrcCfg->resrcToAddModList[arrIdx].pucchFormat;
392       if(macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format0)
393       {
394          MAC_ALLOC(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format0, sizeof(SchPucchFormat0));
395          if(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format0 == NULLP)
396          {
397              DU_LOG("\nERROR  -->  MAC : Failed to allocate memory for Format0 in fillResrcList()");
398              return RFAILED;
399          }
400          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format0->initialCyclicShift =\
401             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format0->initialCyclicShift;
402          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format0->numSymbols =\
403             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format0->numSymbols;
404          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format0->startSymbolIdx =\
405             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format0->startSymbolIdx;
406       }
407          
408       if(macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format1)
409       {
410          MAC_ALLOC(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format1, sizeof(SchPucchFormat1));
411          if(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format1 == NULLP)
412          {
413              DU_LOG("\nERROR  -->  MAC : Failed to allocate memory for Format1 in fillResrcList()");
414              return RFAILED;
415          }
416          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format1->initialCyclicShift =\
417             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format1->initialCyclicShift;
418          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format1->numSymbols =\
419             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format1->numSymbols;
420          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format1->startSymbolIdx =\
421             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format1->startSymbolIdx;
422                 schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format1->timeDomOCC =\
423             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format1->timeDomOCC;
424       }
425
426       if(macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format2)
427       {
428          MAC_ALLOC(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format2, sizeof(SchPucchFormat2_3));
429          if(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format2 == NULLP)
430          {
431              DU_LOG("\nERROR  --> MAC : Failed to allocate memory for Format2 in fillResrcList()");
432              return RFAILED;
433          }
434          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format2->numPrbs =\
435             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format2->numPrbs;
436          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format2->numSymbols =\
437             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format2->numSymbols;
438          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format2->startSymbolIdx =\
439             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format2->startSymbolIdx;
440       }
441
442       if(macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format3)
443       {
444          MAC_ALLOC(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format3, sizeof(SchPucchFormat2_3));
445          if(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format3 == NULLP)
446          {
447              DU_LOG("\nERROR  --> MAC : Failed to allocate memory for Format3 in fillResrcList()");
448              return RFAILED;
449          }
450          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format3->numPrbs =\
451             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format3->numPrbs;
452          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format3->numSymbols =\
453             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format3->numSymbols;
454          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format3->startSymbolIdx =\
455             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format3->startSymbolIdx;
456       }
457
458       if(macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format4)
459       {
460          MAC_ALLOC(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format4, sizeof(SchPucchFormat4));
461          if(schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format4 == NULLP)
462          {
463              DU_LOG("\nERROR  --> MAC : Failed to allocate memory for Format4 in fillResrcList()");
464              return RFAILED;
465          }
466          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format4->numSymbols =\
467             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format4->numSymbols;
468          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format4->startSymbolIdx =\
469             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format4->startSymbolIdx;
470          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format4->occLen =\
471             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format4->occLen;
472          schResrcCfg->resrcToAddModList[arrIdx].SchPucchFormat.format4->occIdx =\
473             macResrcCfg->resrcToAddModList[arrIdx].PucchFormat.format4->occIdx;
474       }
475    }
476    return ROK;
477 }
478
479 /*******************************************************************
480  *
481  * @brief Function to fillPucchFormatCfg sent by DU
482  *
483  * @details
484  *
485  *    Function : fillPucchFormatCfg
486  *
487  *    Functionality: Function to fillPucchFormatCfg
488  *
489  * @params[in] PucchFormatCfg pointer,
490  *             SchPucchFormatCfg pointer
491  * @return void
492  *
493  * ****************************************************************/
494
495 void fillPucchFormatCfg(PucchFormatCfg *macFormatCfg, SchPucchFormatCfg *schFormatCfg)
496 {
497    schFormatCfg->interSlotFreqHop  = macFormatCfg->interSlotFreqHop; 
498    schFormatCfg->addDmrs           = macFormatCfg->addDmrs;        
499    schFormatCfg->maxCodeRate       = macFormatCfg->maxCodeRate;
500    schFormatCfg->numSlots          = macFormatCfg->numSlots;
501    schFormatCfg->pi2BPSK           = macFormatCfg->pi2BPSK;
502    schFormatCfg->harqAckCSI        = macFormatCfg->harqAckCSI;
503 }
504
505 /*******************************************************************
506  *
507  * @brief Function to fillPucchSchedReqCfg sent by DU
508  *
509  * @details
510  *
511  *    Function : fillPucchSchedReqCfg
512  *
513  *    Functionality: Function to fillPucchSchedReqCfg
514  *
515  * @params[in] PucchSchedReqCfg pointer,
516  *             SchPucchSchedReqCfg pointer
517  * @return void
518  *
519  * ****************************************************************/
520 void fillPucchSchedReqCfg(PucchSchedReqCfg *macSchedReqCfg, SchPucchSchedReqCfg *schSchedReqCfg)
521 {
522    uint8_t arrIdx;
523
524    schSchedReqCfg->schedAddModListCount = macSchedReqCfg->schedAddModListCount;
525    for(arrIdx=0; arrIdx < schSchedReqCfg->schedAddModListCount; arrIdx++)
526    {
527       schSchedReqCfg->schedAddModList[arrIdx].resrcId = macSchedReqCfg->schedAddModList[arrIdx].resrcId;
528       schSchedReqCfg->schedAddModList[arrIdx].requestId = macSchedReqCfg->schedAddModList[arrIdx].requestId;
529       schSchedReqCfg->schedAddModList[arrIdx].periodicity =\
530          macSchedReqCfg->schedAddModList[arrIdx].periodicity;
531       schSchedReqCfg->schedAddModList[arrIdx].offset =\
532          macSchedReqCfg->schedAddModList[arrIdx].offset;
533       schSchedReqCfg->schedAddModList[arrIdx].resrc =\
534          macSchedReqCfg->schedAddModList[arrIdx].resrc;
535    }
536    schSchedReqCfg->schedRelListCount = macSchedReqCfg->schedRelListCount;
537    for(arrIdx=0; arrIdx < schSchedReqCfg->schedRelListCount; arrIdx++)
538    {
539       schSchedReqCfg->schedRelList[arrIdx] = macSchedReqCfg->schedRelList[arrIdx];
540    }
541 }
542
543 /*******************************************************************
544  *
545  * @brief Function to fillMultiCsiCfg sent by DU
546  *
547  * @details
548  *
549  *    Function : fillMultiCsiCfg
550  *
551  *    Functionality: Function to fillMultiCsiCfg
552  *
553  * @params[in] PucchMultiCsiCfg pointer,
554  *             SchPucchMultiCsiCfg pointer
555  * @return void
556  *
557  * ****************************************************************/
558
559  void fillMultiCsiCfg(PucchMultiCsiCfg *macCsiCfg, SchPucchMultiCsiCfg *schCsiCfg)
560  {
561     uint8_t arrIdx;
562
563     schCsiCfg->multiCsiResrcListCount = macCsiCfg->multiCsiResrcListCount;
564     for(arrIdx =0; arrIdx < schCsiCfg->multiCsiResrcListCount; arrIdx++)
565     {
566        schCsiCfg->multiCsiResrcList[arrIdx] = macCsiCfg->multiCsiResrcList[arrIdx]; 
567     }
568  }
569
570 /*******************************************************************
571  *
572  * @brief Function to fillDlToUlAck sent by DU
573  *
574  * @details
575  *
576  *    Function : fillDlToUlAck
577  *
578  *    Functionality: Function to fillDlToUlAck
579  *
580  * @params[in] PucchDlDataToUlAck pointer,
581  *             SchPucchDlDataToUlAck pointer
582  * @return void
583  *
584  * ****************************************************************/
585
586 void fillDlToUlAck(PucchDlDataToUlAck *macUlAck, SchPucchDlDataToUlAck *schUlAck)
587 {
588    uint8_t arrIdx;
589
590    schUlAck->dlDataToUlAckListCount = macUlAck->dlDataToUlAckListCount;
591    for(arrIdx =0; arrIdx < macUlAck->dlDataToUlAckListCount; arrIdx++)
592    {
593       schUlAck->dlDataToUlAckList[arrIdx] = macUlAck->dlDataToUlAckList[arrIdx];
594    }
595 }
596
597 /*******************************************************************
598  *
599  * @brief Function to fillPucchPowerControl sent by DU
600  *
601  * @details
602  *
603  *    Function : fillPucchPowerControl
604  *
605  *    Functionality: Function to fillPucchPowerControl
606  *
607  * @params[in] PucchPowerControl pointer,
608  *             SchPucchPowerControl pointer
609  * @return void
610  *
611  * ****************************************************************/
612
613 void fillPucchPowerControl(PucchPowerControl *macPwrCtrl, SchPucchPowerControl *schPwrCtrl)
614 {
615    uint8_t arrIdx;
616
617    schPwrCtrl->deltaF_Format0 = macPwrCtrl->deltaF_Format0;
618    schPwrCtrl->deltaF_Format1 = macPwrCtrl->deltaF_Format1;
619    schPwrCtrl->deltaF_Format2 = macPwrCtrl->deltaF_Format2;
620    schPwrCtrl->deltaF_Format3 = macPwrCtrl->deltaF_Format3;
621    schPwrCtrl->deltaF_Format4 = macPwrCtrl->deltaF_Format4;
622    schPwrCtrl->p0SetCount = macPwrCtrl->p0SetCount;
623    for(arrIdx =0; arrIdx <  macPwrCtrl->p0SetCount; arrIdx++)
624    {
625       schPwrCtrl->p0Set[arrIdx].p0PucchId = macPwrCtrl->p0Set[arrIdx].p0PucchId;
626       schPwrCtrl->p0Set[arrIdx].p0PucchVal = macPwrCtrl->p0Set[arrIdx].p0PucchVal;
627    }
628    schPwrCtrl->pathLossRefRSListCount = macPwrCtrl->pathLossRefRSListCount;
629    for(arrIdx = 0; arrIdx < macPwrCtrl->pathLossRefRSListCount; arrIdx++)
630    {
631       schPwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId =\
632       macPwrCtrl->pathLossRefRSList[arrIdx].pathLossRefRSId;
633    }
634 }
635
636 /*******************************************************************
637  *
638  * @brief Function to fillOtherPucchFormatCfg sent by DU
639  *
640  * @details
641  *
642  *    Function : fillOtherPucchFormatCfg
643  *
644  *    Functionality: Function to fillOtherPucchFormatCfg
645  *
646  * @params[in] PucchFormat
647  *             PucchFormatCfg pointer,
648  *             SchPucchCfg pointer
649  * @return void
650  *
651  * ****************************************************************/
652
653 uint8_t fillOtherPucchFormatCfg(uint8_t pucchFormat, PucchFormatCfg *macFormatCfg, SchPucchCfg *schPucchCfg)
654 {
655
656    switch(pucchFormat)
657    {
658       case PUCCH_FORMAT_1:
659       {
660          if(macFormatCfg)
661          {
662             MAC_ALLOC(schPucchCfg->format1, sizeof(SchPucchFormatCfg));
663             if(schPucchCfg->format1 == NULLP)
664             {
665                DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for Format 1 in fillOtherPucchFormatCfg()");
666                return RFAILED;
667             }
668             fillPucchFormatCfg(macFormatCfg, schPucchCfg->format1);            
669          }
670          break;
671       }
672       case PUCCH_FORMAT_2:
673       {
674          if(macFormatCfg)
675          {
676             MAC_ALLOC(schPucchCfg->format2, sizeof(SchPucchFormatCfg));
677             if(schPucchCfg->format2 == NULLP)
678             {
679                DU_LOG("\nERROR --> MAC : Failed to allocate Mem for Format 2 in fillOtherPucchFormatCfg()");
680                return RFAILED;
681             }
682             fillPucchFormatCfg(macFormatCfg, schPucchCfg->format2);            
683          }
684          break;
685       }
686       case PUCCH_FORMAT_3:
687       {
688          if(macFormatCfg)
689          {
690             MAC_ALLOC(schPucchCfg->format3, sizeof(SchPucchFormatCfg));
691             if(schPucchCfg->format3 == NULLP)
692             {
693                DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for Format 3 in fillOtherPucchFormatCfg()");
694                return RFAILED;
695             }
696             fillPucchFormatCfg(macFormatCfg, schPucchCfg->format3);
697          }
698          break;
699       }
700       case PUCCH_FORMAT_4:
701       {
702          if(macFormatCfg)
703          {
704             MAC_ALLOC(schPucchCfg->format4, sizeof(SchPucchFormatCfg));
705             if(schPucchCfg->format4 == NULLP)
706             {
707                DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for Format 4 in fillOtherPucchFormatCfg()");
708                return RFAILED;
709             }
710             fillPucchFormatCfg(macFormatCfg, schPucchCfg->format4);
711         }
712         break;
713       }
714       default:
715          DU_LOG("\nERROR --> MAC : Invalid Format Cfg %d in fillInitialUlBwpPucchCfg()", pucchFormat);
716          return RFAILED;
717    }
718    return ROK;
719 }
720
721 /*******************************************************************
722  *
723  * @brief Fills PUCCH config in initial UL BWP config for SCH UE Cfg
724  *
725  * @details
726  *
727  *    Function : fillInitalUlBwpPucchCfg
728  *
729  *    Functionality:
730  *       Fills PUCCH cofig in initial UL BWP config for SCH UE Cfg
731  *
732  * @params[in] macPucchCfg : Initial UL-BWP PUCCH cfg at MAC
733  *             schPucchCfg : Initial UL-BWP PUCCH cfg to be filled
734  * @return ROK     - success
735  *         RFAILED - failure
736  *
737  * ****************************************************************/
738 uint8_t fillInitialUlBwpPucchCfg(PucchCfg *macPucchCfg, SchPucchCfg *schPucchCfg)
739 {
740    if(macPucchCfg->resrcSet)
741    {
742       MAC_ALLOC(schPucchCfg->resrcSet, sizeof(SchPucchResrcSetCfg));
743       if(schPucchCfg->resrcSet == NULLP)
744       {
745          DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for Resrc set List in fillInitialUlBwpPucchCfg()");
746          return RFAILED;
747       }
748       memset(schPucchCfg->resrcSet, 0, sizeof(SchPucchResrcSetCfg));
749       fillResrcSetList(macPucchCfg->resrcSet, schPucchCfg->resrcSet);
750    }
751
752    if(macPucchCfg->resrc)
753    {
754       MAC_ALLOC(schPucchCfg->resrc, sizeof(SchPucchResrcCfg));
755       if(schPucchCfg->resrc == NULLP)
756       {
757          DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for Resrc List in fillInitialUlBwpPucchCfg()");
758          return RFAILED;
759       }
760       memset(schPucchCfg->resrc, 0, sizeof(SchPucchResrcCfg));
761       if((fillResrcList(macPucchCfg->resrc, schPucchCfg->resrc)) != ROK)
762       {
763          DU_LOG("\nERROR  --> MAC : Failed in fillResrcList() at fillInitialUlBwpPucchCfg()");
764          return RFAILED;
765       }
766    }
767
768    /* valid for format 1, 2, 3, 4 */
769    fillOtherPucchFormatCfg(PUCCH_FORMAT_1, macPucchCfg->format1, schPucchCfg);
770    fillOtherPucchFormatCfg(PUCCH_FORMAT_2, macPucchCfg->format2, schPucchCfg);
771    fillOtherPucchFormatCfg(PUCCH_FORMAT_3, macPucchCfg->format3, schPucchCfg);
772    fillOtherPucchFormatCfg(PUCCH_FORMAT_4, macPucchCfg->format4, schPucchCfg);
773
774    if(macPucchCfg->schedReq)
775    {
776       MAC_ALLOC(schPucchCfg->schedReq, sizeof(SchPucchSchedReqCfg));
777       if(schPucchCfg->schedReq == NULLP)
778       {
779          DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for  PucchSchedReqCfg in fillInitialUlBwpPucchCfg()");
780          return RFAILED;
781       }
782       memset(schPucchCfg->schedReq, 0, sizeof(SchPucchSchedReqCfg));
783       fillPucchSchedReqCfg(macPucchCfg->schedReq, schPucchCfg->schedReq);
784    }
785
786    if(macPucchCfg->multiCsiCfg)
787    {
788       MAC_ALLOC(schPucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
789       if(schPucchCfg->multiCsiCfg == NULLP)
790       {
791          DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for multiCsiCfg in fillInitialUlBwpPucchCfg()");
792          return RFAILED;
793       }
794       memset(schPucchCfg->multiCsiCfg, 0, sizeof(SchPucchMultiCsiCfg));
795       fillMultiCsiCfg(macPucchCfg->multiCsiCfg, schPucchCfg->multiCsiCfg);
796    }
797
798    //TODO: To add the support for spatial Config
799    schPucchCfg->spatialInfo = NULLP;
800
801    if(macPucchCfg->dlDataToUlAck)
802    {
803       MAC_ALLOC(schPucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
804       if(schPucchCfg->dlDataToUlAck == NULLP)
805       {
806          DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for dlDataToUlAck in fillInitialUlBwpPucchCfg()");
807          return RFAILED;
808       }
809       memset(schPucchCfg->dlDataToUlAck, 0, sizeof(SchPucchDlDataToUlAck));
810       fillDlToUlAck(macPucchCfg->dlDataToUlAck, schPucchCfg->dlDataToUlAck);
811
812    }
813
814    if(macPucchCfg->powerControl)
815    {
816       MAC_ALLOC(schPucchCfg->powerControl, sizeof(SchPucchPowerControl));
817       if(schPucchCfg->powerControl == NULLP)
818       {
819          DU_LOG("\nERROR  --> MAC : Failed to allocate Mem for powerControl in fillInitialUlBwpPucchCfg()");
820          return RFAILED;
821       }
822       memset(schPucchCfg->powerControl, 0, sizeof(SchPucchPowerControl));
823       fillPucchPowerControl(macPucchCfg->powerControl, schPucchCfg->powerControl);
824    }
825
826    return ROK;
827 }
828
829 /*******************************************************************
830  *
831  * @brief function to free Pucch Format
832  *
833  * @details
834  *
835  *    Function : freeSchPucchFormat
836  *
837  *    Functionality:
838  *       function to free Pucch Format
839  *
840  * @params[in] pucchFormat, SchPucchResrcInfo Pointer, 
841  *             SchPucchResrcInfo pointer
842  * @return void
843  * ****************************************************************/
844
845 void freeSchPucchFormat(uint8_t pucchFormat, SchPucchResrcInfo *resrcInfo, SchPucchFormatCfg *formatCfg)
846 {
847    switch(pucchFormat)
848    {
849       case PUCCH_FORMAT_0 :
850          if(resrcInfo->SchPucchFormat.format0)
851          {
852             MAC_FREE(resrcInfo->SchPucchFormat.format0, sizeof(SchPucchFormat0)); 
853             resrcInfo->SchPucchFormat.format0 = NULLP;
854          }
855          break;
856
857       case PUCCH_FORMAT_1 :
858          if(resrcInfo->SchPucchFormat.format1)
859          {
860             MAC_FREE(resrcInfo->SchPucchFormat.format1, sizeof(SchPucchFormat1)); 
861             resrcInfo->SchPucchFormat.format1 = NULLP;
862          }
863          if(formatCfg)
864          {
865             memset(formatCfg, 0, sizeof(SchPucchFormatCfg));
866             MAC_FREE(formatCfg, sizeof(SchPucchFormatCfg));
867          }
868          break;
869
870       case PUCCH_FORMAT_2 :
871          if(resrcInfo->SchPucchFormat.format2)
872          {
873             MAC_FREE(resrcInfo->SchPucchFormat.format2, sizeof(SchPucchFormat2_3)); 
874             resrcInfo->SchPucchFormat.format2 = NULLP;
875          }
876          if(formatCfg)
877          {
878             memset(formatCfg, 0, sizeof(SchPucchFormatCfg));
879             MAC_FREE(formatCfg, sizeof(SchPucchFormatCfg));
880          }
881          break;
882
883       case PUCCH_FORMAT_3 :
884          if(resrcInfo->SchPucchFormat.format3)
885          {
886             MAC_FREE(resrcInfo->SchPucchFormat.format3, sizeof(SchPucchFormat2_3)); 
887             resrcInfo->SchPucchFormat.format3 = NULLP;
888          }
889          if(formatCfg)
890          {
891             memset(formatCfg, 0, sizeof(SchPucchFormatCfg));
892             MAC_FREE(formatCfg, sizeof(SchPucchFormatCfg));
893          }
894          break;
895
896       case PUCCH_FORMAT_4 :
897          if(resrcInfo->SchPucchFormat.format4)
898          {
899             MAC_FREE(resrcInfo->SchPucchFormat.format4, sizeof(SchPucchFormat4)); 
900             resrcInfo->SchPucchFormat.format4 = NULLP;
901          }
902          if(formatCfg)
903          {
904             memset(formatCfg, 0, sizeof(SchPucchFormatCfg));
905             MAC_FREE(formatCfg, sizeof(SchPucchFormatCfg));
906          }
907          break;
908
909       default:
910         break;
911    }
912 }
913
914 /*******************************************************************
915  *
916  * @brief function to free Pucch Resrc Cfg
917  *
918  * @details
919  *
920  *    Function : freePucchResrcCfg
921  *
922  *    Functionality:
923  *       function to free Pucch Resrc Cfg
924  *
925  * @params[in] SchPucchResrcCfg pointer, 
926  * @return void
927  * ****************************************************************/
928
929 void freePucchResrcCfg(SchPucchResrcCfg *schRsrcList)
930 {
931    uint8_t resrcIdx;
932
933    /* free Resrc To AddMod List */
934    for(resrcIdx = 0; resrcIdx < schRsrcList->resrcToAddModListCount; resrcIdx++)
935    {
936       freeSchPucchFormat(schRsrcList->resrcToAddModList[resrcIdx].pucchFormat,
937       &schRsrcList->resrcToAddModList[resrcIdx], NULLP);
938       memset(&schRsrcList->resrcToAddModList[resrcIdx], 0, sizeof(SchPucchResrcInfo));
939    }
940    memset(schRsrcList, 0, sizeof(SchPucchResrcCfg));
941    MAC_FREE(schRsrcList, sizeof(SchPucchResrcCfg));
942 }
943
944 /*******************************************************************
945  *
946  * @brief function to free Pucch Sched Req Cfg
947  *
948  * @details
949  *
950  *    Function : freePucchSchedReqCfg
951  *
952  *    Functionality:
953  *       function to free Pucch Sched Req Cfg
954  *
955  * @params[in] SchPucchSchedReqCfg pointer, 
956  * @return void
957  * ****************************************************************/
958
959 void freePucchSchedReqCfg(SchPucchSchedReqCfg *schedReqCfg)
960 {
961    uint8_t schedReqIdx;
962
963    for(schedReqIdx = 0; schedReqIdx < schedReqCfg->schedAddModListCount; schedReqIdx++)
964    {
965       memset(&schedReqCfg->schedAddModList[schedReqIdx], 0, sizeof(SchSchedReqResrcInfo));
966    }
967    memset(schedReqCfg, 0, sizeof(SchPucchSchedReqCfg));
968    MAC_FREE(schedReqCfg, sizeof(SchPucchSchedReqCfg));
969 }
970
971 /*******************************************************************
972  *
973  * @brief function to free Ul Bwp Pucch Cfg
974  *
975  * @details
976  *
977  *    Function : freeUlBwpPucchCfg
978  *
979  *    Functionality:
980  *       function to free Ul Bwp Pucch Cfg
981  *
982  * @params[in] SchPucchCfg pointer, 
983  * @return void
984  * ****************************************************************/
985
986 void freeUlBwpPucchCfg(SchPucchCfg *schPucchCfg)
987 {
988    if(schPucchCfg->resrcSet)
989    {
990       memset(schPucchCfg->resrcSet, 0, sizeof(SchPucchResrcSetCfg));
991       MAC_FREE(schPucchCfg->resrcSet, sizeof(SchPucchResrcSetCfg));
992    }
993    if(schPucchCfg->resrc)
994    {
995       freePucchResrcCfg(schPucchCfg->resrc);
996    }
997    if(schPucchCfg->format1)
998    {
999       freeSchPucchFormat(PUCCH_FORMAT_1, NULLP, schPucchCfg->format1);
1000    }
1001    if(schPucchCfg->format2)
1002    {
1003       freeSchPucchFormat(PUCCH_FORMAT_2, NULLP, schPucchCfg->format2);
1004    }
1005    if(schPucchCfg->format3)
1006    {
1007       freeSchPucchFormat(PUCCH_FORMAT_3, NULLP, schPucchCfg->format3);
1008    }
1009    if(schPucchCfg->format4)
1010    {
1011       freeSchPucchFormat(PUCCH_FORMAT_4, NULLP, schPucchCfg->format4);
1012    }
1013    if(schPucchCfg->schedReq)
1014    {
1015       freePucchSchedReqCfg(schPucchCfg->schedReq);
1016    }
1017    if(schPucchCfg->spatialInfo)
1018    {
1019       memset(schPucchCfg->spatialInfo, 0, sizeof(SchPucchSpatialCfg));
1020       MAC_FREE(schPucchCfg->spatialInfo, sizeof(SchPucchSpatialCfg));
1021    }
1022    if(schPucchCfg->multiCsiCfg)
1023    {
1024       memset(schPucchCfg->multiCsiCfg, 0, sizeof(SchPucchMultiCsiCfg));
1025       MAC_FREE(schPucchCfg->multiCsiCfg, sizeof(SchPucchMultiCsiCfg));
1026    }
1027    if(schPucchCfg->dlDataToUlAck)
1028    {
1029       memset(schPucchCfg->dlDataToUlAck, 0, sizeof(SchPucchDlDataToUlAck));
1030       MAC_FREE(schPucchCfg->dlDataToUlAck, sizeof(SchPucchDlDataToUlAck));
1031    }
1032    if(schPucchCfg->powerControl)
1033    {
1034       memset(schPucchCfg->powerControl, 0, sizeof(SchPucchPowerControl));
1035       MAC_FREE(schPucchCfg->powerControl, sizeof(SchPucchPowerControl));
1036    }
1037 }
1038
1039 /*******************************************************************
1040  *
1041  * @brief Fills initail UL BWP config to send to scheduler
1042  *
1043  * @details
1044  *
1045  *    Function : fillInitialUlBwp
1046  *
1047  *    Functionality: Fills initail UL BWP config to send to sch
1048  *
1049  * @params[in] macInitUlBwp : Initial UL BWP cfg at MAC
1050  *             schInitUlBwp : Initial UL BWP cfg to be filled
1051  * @return ROK     - success
1052  *         RFAILED - failure
1053  *
1054  * ****************************************************************/
1055 uint8_t fillInitialUlBwp(InitialUlBwp macInitUlBwp, SchInitialUlBwp *schInitUlBwp)
1056 {
1057    schInitUlBwp->pucchCfgPres = macInitUlBwp.pucchPresent;
1058    if(schInitUlBwp->pucchCfgPres)
1059    {
1060       memset(&schInitUlBwp->pucchCfg, 0, sizeof(SchPucchCfg));
1061       if(fillInitialUlBwpPucchCfg(&macInitUlBwp.pucchCfg, &schInitUlBwp->pucchCfg) != ROK)
1062       {
1063          DU_LOG("\nERROR  --> MAC : Failed to fill Pucch Cfg in fillInitialUlBwpPucchCfg()");
1064          freeUlBwpPucchCfg(&schInitUlBwp->pucchCfg);
1065          return RFAILED; 
1066       }
1067    }
1068    schInitUlBwp->puschCfgPres = macInitUlBwp.puschPresent;
1069    if(schInitUlBwp->puschCfgPres)
1070    {
1071       memset(&schInitUlBwp->puschCfg, 0, sizeof(SchPuschCfg));
1072       if(fillInitalUlBwpPuschCfg(macInitUlBwp.puschCfg, &schInitUlBwp->puschCfg) != ROK)
1073       {
1074          DU_LOG("\nERROR  --> MAC : Failed to fill Pusch Cfg in fillInitalUlBwpPuschCfg()");
1075          return RFAILED;
1076       }
1077    }
1078    return ROK;
1079 }
1080
1081 /*******************************************************************
1082  *
1083  * @brief Fill PDCCH cfg in Initial DL BWP for UE Cfg in Scheduler
1084  *
1085  * @details
1086  *
1087  *    Function : fillInitDlBwpPdcchCfg
1088  *
1089  *    Functionality:
1090  *        Fill PDCCH cfg in Initial DL BWP for UE Cfg in Scheduler
1091  *
1092  * @params[in] macPdcchCfg : Inital DL BWP PDCCH cfg in MAC
1093  *             schPdcchCfg : Inital DL BWP PDCCH cfg to be filled
1094  * @return ROK     - success
1095  *         RFAILED - failure
1096  *
1097  * ****************************************************************/
1098 uint8_t fillInitDlBwpPdcchCfg(PdcchConfig macPdcchCfg, SchPdcchConfig *schPdcchCfg)
1099 {
1100    uint8_t idx;
1101
1102    /* Fill CORESET info */
1103    schPdcchCfg->numCRsetToAddMod = macPdcchCfg.numCRsetToAddMod;
1104    if(schPdcchCfg->numCRsetToAddMod > MAX_NUM_CRSET)
1105    {
1106       DU_LOG("\nERROR  -->  MAC : Number of CORESET to ADD/MOD [%d] exceeds max limit [%d]",\
1107             schPdcchCfg->numCRsetToAddMod, MAX_NUM_CRSET);
1108       return RFAILED;
1109    }
1110
1111    for(idx = 0; idx < schPdcchCfg->numCRsetToAddMod; idx++)
1112    {
1113       schPdcchCfg->cRSetToAddModList[idx].cRSetId = \
1114          macPdcchCfg.cRSetToAddModList[idx].cRSetId;
1115       memcpy(&schPdcchCfg->cRSetToAddModList[idx].freqDomainRsrc,\
1116          &macPdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
1117       schPdcchCfg->cRSetToAddModList[idx].duration = \
1118          macPdcchCfg.cRSetToAddModList[idx].duration;
1119       schPdcchCfg->cRSetToAddModList[idx].cceRegMappingType = \
1120          macPdcchCfg.cRSetToAddModList[idx].cceRegMappingType;
1121       schPdcchCfg->cRSetToAddModList[idx].precoderGranularity = \
1122          macPdcchCfg.cRSetToAddModList[idx].precoderGranularity;
1123       schPdcchCfg->cRSetToAddModList[idx].dmrsScramblingId = \
1124          macPdcchCfg.cRSetToAddModList[idx].dmrsScramblingId;
1125    }
1126
1127    schPdcchCfg->numCRsetToRel = macPdcchCfg.numCRsetToRel;
1128    if(schPdcchCfg->numCRsetToAddMod > MAX_NUM_CRSET)
1129    {
1130       DU_LOG("\nERROR  -->  MAC : Number of CORESET to release [%d] exceeds max limit [%d]",\
1131             schPdcchCfg->numCRsetToRel, MAX_NUM_CRSET);
1132       return RFAILED;
1133    }
1134
1135    for(idx = 0; idx < schPdcchCfg->numCRsetToRel; idx++)
1136    {
1137       /* TODO */
1138    }
1139
1140    /* Fill Search space info */
1141    schPdcchCfg->numSearchSpcToAddMod = macPdcchCfg.numSearchSpcToAddMod;
1142    if(schPdcchCfg->numSearchSpcToAddMod > MAX_NUM_SEARCH_SPC)
1143    {
1144       DU_LOG("\nERROR  -->  MAC : Number of search space to ADD/MOD [%d] exceeds max [%d]", \
1145             schPdcchCfg->numSearchSpcToAddMod, MAX_NUM_SEARCH_SPC);
1146       return RFAILED;
1147    }
1148    for(idx = 0; idx < schPdcchCfg->numSearchSpcToAddMod; idx++)
1149    {
1150       schPdcchCfg->searchSpcToAddModList[idx].searchSpaceId = \
1151          macPdcchCfg.searchSpcToAddModList[idx].searchSpaceId;
1152       schPdcchCfg->searchSpcToAddModList[idx].cRSetId = \
1153          macPdcchCfg.searchSpcToAddModList[idx].cRSetId;
1154       schPdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset = \
1155          macPdcchCfg.searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
1156       memcpy(&schPdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot,
1157          &macPdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, \
1158          MONITORING_SYMB_WITHIN_SLOT_SIZE);
1159       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1 = \
1160          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1;
1161       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2 = \
1162          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2;
1163       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4 = \
1164          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4;
1165       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8 = \
1166          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8;
1167       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16 = \
1168          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16;
1169       schPdcchCfg->searchSpcToAddModList[idx].searchSpaceType = \
1170          macPdcchCfg.searchSpcToAddModList[idx].searchSpaceType;
1171       schPdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat = \
1172          macPdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat;
1173    }
1174
1175    schPdcchCfg->numSearchSpcToRel = macPdcchCfg.numSearchSpcToRel;
1176    if(schPdcchCfg->numSearchSpcToRel > MAX_NUM_SEARCH_SPC)
1177    {
1178       DU_LOG("\nERROR  -->  MAC : Number of search space to release [%d] exceeds max [%d]", \
1179             schPdcchCfg->numSearchSpcToRel, MAX_NUM_SEARCH_SPC);
1180       return RFAILED;
1181    }
1182    for(idx = 0; idx < schPdcchCfg->numSearchSpcToRel; idx++)
1183    {
1184       /* TODO */
1185    }
1186
1187    return ROK;
1188 }
1189
1190 /*******************************************************************
1191  *
1192  * @brief Fill PDSCH cfg in Initial DL BWP for UE Cfg in Scheduler
1193  *
1194  * @details
1195  *
1196  *    Function : fillInitDlBwpPdschCfg
1197  *
1198  *    Functionality:
1199  *        Fill PDSCH cfg in Initial DL BWP for UE Cfg in Scheduler
1200  *
1201  * @params[in] macPdschCfg : Inital DL BWP PDSCH cfg at  MAC
1202  *             schPdschCfg : Inital DL BWP PDSCH cfg to be filled
1203  * @return ROK     - success
1204  *         RFAILED - failure
1205  *
1206  * ****************************************************************/
1207 uint8_t fillInitDlBwpPdschCfg(PdschConfig macPdschCfg, SchPdschConfig *schPdschCfg)
1208 {
1209    uint8_t   idx;
1210
1211    schPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
1212        macPdschCfg.dmrsDlCfgForPdschMapTypeA.addPos;
1213    schPdschCfg->resourceAllocType = macPdschCfg.resourceAllocType;
1214    schPdschCfg->numTimeDomRsrcAlloc = macPdschCfg.numTimeDomRsrcAlloc;
1215    if(schPdschCfg->numTimeDomRsrcAlloc > MAX_NUM_DL_ALLOC)
1216    {
1217       DU_LOG("\nERROR  -->  MAC : Number of time domain resource allocation [%d], exceeds\
1218             max limit [%d]", schPdschCfg->numTimeDomRsrcAlloc, MAX_NUM_DL_ALLOC);
1219       return RFAILED;
1220    }
1221
1222    for(idx = 0; idx < schPdschCfg->numTimeDomRsrcAlloc; idx++)
1223    {
1224       if(macPdschCfg.timeDomRsrcAllociList[idx].k0)
1225       {
1226          MAC_ALLOC(schPdschCfg->timeDomRsrcAllociList[idx].k0, sizeof(uint8_t));
1227          if(!schPdschCfg->timeDomRsrcAllociList[idx].k0)
1228          {
1229             DU_LOG("\nERROR  -->  MAC : Memory allocation failed for K0 in fillInitDlBwpPdschCfg()");
1230             return RFAILED;
1231          }
1232          *(schPdschCfg->timeDomRsrcAllociList[idx].k0) = *(macPdschCfg.timeDomRsrcAllociList[idx].k0);
1233       }
1234       schPdschCfg->timeDomRsrcAllociList[idx].mappingType = \
1235          macPdschCfg.timeDomRsrcAllociList[idx].mappingType;
1236       schPdschCfg->timeDomRsrcAllociList[idx].startSymbol = \
1237          macPdschCfg.timeDomRsrcAllociList[idx].startSymbol;
1238       schPdschCfg->timeDomRsrcAllociList[idx].symbolLength = \
1239          macPdschCfg.timeDomRsrcAllociList[idx].symbolLength;
1240    }
1241
1242    schPdschCfg->rbgSize = macPdschCfg.rbgSize;
1243    schPdschCfg->numCodeWordsSchByDci = macPdschCfg.numCodeWordsSchByDci;
1244    schPdschCfg->bundlingType = macPdschCfg.bundlingType;
1245    if(schPdschCfg->bundlingType == STATIC_BUNDLING_TYPE)
1246    {
1247       schPdschCfg->bundlingInfo.SchStaticBundling.size  = macPdschCfg.bundlingInfo.StaticBundling.size;
1248    }
1249    else if(schPdschCfg->bundlingType == DYNAMIC_BUNDLING_TYPE)
1250    {
1251       schPdschCfg->bundlingInfo.SchDynamicBundling.sizeSet1 = macPdschCfg.bundlingInfo.DynamicBundling.sizeSet1;
1252       schPdschCfg->bundlingInfo.SchDynamicBundling.sizeSet2 = macPdschCfg.bundlingInfo.DynamicBundling.sizeSet2;
1253    }
1254    return ROK;
1255 }
1256
1257 /*******************************************************************
1258  *
1259  * @brief Fill Initial DL BWP for SCH UE config
1260  *
1261  * @details
1262  *
1263  *    Function : fillInitialDlBwp
1264  *
1265  *    Functionality: Fill Initial DL BWP for SCH UE config
1266  *
1267  * @params[in] macInitDlBwp : Inital DL BWP cfg at MAC
1268  *             schInitDlBwp : Inital DL BWP cfg to be filled
1269  * @return ROK     - success
1270  *         RFAILED - failure
1271  *
1272  * ****************************************************************/
1273 uint8_t fillInitialDlBwp(InitialDlBwp macInitDlBwp, SchInitalDlBwp *schInitDlBwp)
1274 {
1275    schInitDlBwp->pdcchCfgPres = macInitDlBwp.pdcchPresent;
1276    if(schInitDlBwp->pdcchCfgPres)
1277    {
1278       if(fillInitDlBwpPdcchCfg(macInitDlBwp.pdcchCfg, &schInitDlBwp->pdcchCfg) != ROK)
1279       {
1280          DU_LOG("\nERROR  -->  MAC : fillInitDlBwpPdcchCfg() failed");
1281          return RFAILED;
1282       }
1283    }
1284
1285    schInitDlBwp->pdschCfgPres = macInitDlBwp.pdschPresent;
1286    if(schInitDlBwp->pdschCfgPres)
1287    {
1288       if(fillInitDlBwpPdschCfg(macInitDlBwp.pdschCfg,&schInitDlBwp->pdschCfg) != ROK)
1289       {
1290          DU_LOG("\nERROR  -->  MAC : fillInitDlBwpPdschCfg() failed");
1291          return RFAILED;
1292       }
1293    }
1294    return ROK;
1295 }
1296
1297 /*******************************************************************
1298  *
1299  * @brief Fills Sp Cell config to be sent to scheduler
1300  *
1301  * @details
1302  *
1303  *    Function : fillSpCellCfg 
1304  *
1305  *    Functionality: Fills Sp Cell config to be sent to scheduler
1306  *
1307  * @params[in] macSpCellCfg : SP cell cfg at MAC
1308  *             schSpCellCfg : SP cell cfg to be filled
1309  * @return ROK     - success
1310  *         RFAILED - failure
1311  *
1312  * ****************************************************************/
1313 uint8_t fillSpCellCfg(SpCellCfg macSpCellCfg, SchSpCellCfg *schSpCellCfg)
1314 {
1315    uint8_t   idx;
1316    SchServCellCfgInfo   *servCellCfg;
1317
1318    schSpCellCfg->servCellIdx = macSpCellCfg.servCellIdx;
1319    servCellCfg = &schSpCellCfg->servCellCfg;
1320
1321    /* Fill initial DL BWP */
1322    if(fillInitialDlBwp(macSpCellCfg.servCellCfg.initDlBwp, \
1323             &servCellCfg->initDlBwp) != ROK )
1324    {
1325       DU_LOG("\nERROR  -->  MAC : fillInitialDlBwp() failed");
1326       return RFAILED;
1327    }
1328
1329    servCellCfg->numDlBwpToAdd = macSpCellCfg.servCellCfg.numDlBwpToAdd;
1330    if(servCellCfg->numDlBwpToAdd > MAX_NUM_BWP)
1331    {
1332       DU_LOG("\nERROR  -->  MAC : Number of DL BWP to ADD/MOD [%d] exceeds max limit [%d]",\
1333             servCellCfg->numDlBwpToAdd, MAX_NUM_BWP);
1334       return RFAILED;
1335    }
1336    for(idx = 0; idx < servCellCfg->numDlBwpToAdd; idx++)
1337    {
1338       /* TODO : As of now numDlBwpToAdd = 0 */
1339    }
1340
1341    servCellCfg->firstActvDlBwpId =  macSpCellCfg.servCellCfg.firstActvDlBwpId;
1342    servCellCfg->defaultDlBwpId = macSpCellCfg.servCellCfg.defaultDlBwpId;
1343    servCellCfg->bwpInactivityTmr = NULL;
1344    if(macSpCellCfg.servCellCfg.bwpInactivityTmr)
1345    {
1346       /* TODO : This is an optional parameter, not filled currently */
1347    }
1348
1349    /* Fill PDSCH serving cell config */
1350    if(fillPdschServCellCfg(macSpCellCfg.servCellCfg.pdschServCellCfg, \
1351             &servCellCfg->pdschServCellCfg) != ROK)
1352    {
1353       DU_LOG("\nERROR  -->  MAC : fillPdschServCellCfg() failed");
1354       return RFAILED;
1355    }
1356
1357    /* Fill Initail UL BWP */
1358    if(fillInitialUlBwp(macSpCellCfg.servCellCfg.initUlBwp, \
1359             &servCellCfg->initUlBwp) != ROK)
1360    {
1361       DU_LOG("\nERROR  -->  MAC : fillInitialUlBwp() failed");
1362       return RFAILED;
1363    }
1364
1365    servCellCfg->numUlBwpToAdd = macSpCellCfg.servCellCfg.numUlBwpToAdd;
1366    if(servCellCfg->numUlBwpToAdd > MAX_NUM_BWP)
1367    {
1368       DU_LOG("\nERROR  -->  MAC : Number of UL BWP to ADD/MOD [%d] exceeds max limit [%d]",\
1369             servCellCfg->numUlBwpToAdd, MAX_NUM_BWP);
1370       return RFAILED;
1371    }
1372    for(idx = 0; idx < servCellCfg->numUlBwpToAdd; idx++)
1373    {
1374       /* TODO : As of now numDlBwpToAdd = 0 */
1375    }
1376    servCellCfg->firstActvUlBwpId =  macSpCellCfg.servCellCfg.firstActvUlBwpId;
1377
1378    return ROK;
1379 }
1380
1381 /*******************************************************************
1382  *
1383  * @brief Sends UE configuration to Scheduler
1384  *
1385  * @details
1386  *
1387  *    Function : sendUeReqToSch
1388  *
1389  *    Functionality: sends UE configuration to Scheduler
1390  *
1391  * @params[in] Pst and Ue configuration
1392  * @return ROK     - success
1393  *         RFAILED - failure
1394  *
1395  * ****************************************************************/
1396
1397 uint8_t sendUeReqToSch(Pst *pst, SchUeCfg *schUeCfg)
1398 {
1399    Pst schPst;
1400    switch(pst->event)
1401    {
1402       case EVENT_MAC_UE_CREATE_REQ:
1403          FILL_PST_MAC_TO_SCH(schPst, EVENT_ADD_UE_CONFIG_REQ_TO_SCH);
1404          return(*macSchAddUeConfigReqOpts[schPst.selector])(&schPst, schUeCfg);
1405
1406       case EVENT_MAC_UE_RECONFIG_REQ:
1407          FILL_PST_MAC_TO_SCH(schPst, EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH);
1408          return(*macSchModUeConfigReqOpts[schPst.selector])(&schPst,schUeCfg);
1409       default: 
1410          DU_LOG("\nERROR  -->  Invalid Pst received %d", pst->event);
1411          return RFAILED;
1412    }
1413 }
1414
1415 /*******************************************************************
1416  *
1417  * @brief Fills Sch Drb Qos Information
1418  *
1419  * @details
1420  *
1421  *    Function : fillSchDrbQosInfo
1422  *
1423  *    Functionality: Fills Sch Drb Qos Information
1424  *
1425  * @params[in] macLcCfg : Logical channel Cfg at MAC
1426  *             schLcCfg : LC cfg to fill at scheduler
1427  * @return ROK     - success
1428  *         RFAILED - failure
1429  *
1430  * ****************************************************************/
1431 void fillSchDrbQosInfo(DrbQosInfo *macDrbQos, SchDrbQosInfo *schDrbQos)
1432 {
1433    schDrbQos->fiveQiType  = macDrbQos->fiveQiType;
1434    if(schDrbQos->fiveQiType == SCH_QOS_NON_DYNAMIC)
1435    {
1436       schDrbQos->u.nonDyn5Qi.fiveQi = macDrbQos->u.nonDyn5Qi.fiveQi;
1437       schDrbQos->u.nonDyn5Qi.avgWindow = macDrbQos->u.nonDyn5Qi.avgWindow;
1438       schDrbQos->u.nonDyn5Qi.maxDataBurstVol = macDrbQos->u.nonDyn5Qi.maxDataBurstVol;
1439       schDrbQos->u.nonDyn5Qi.priorLevel =  macDrbQos->u.nonDyn5Qi.priorLevel;
1440    }
1441    else if(schDrbQos->fiveQiType == SCH_QOS_DYNAMIC)
1442    {
1443       schDrbQos->u.dyn5Qi.priorLevel         = macDrbQos->u.dyn5Qi.priorLevel;
1444       schDrbQos->u.dyn5Qi.packetDelayBudget  = macDrbQos->u.dyn5Qi.packetDelayBudget;
1445       schDrbQos->u.dyn5Qi.packetErrRateScalar= macDrbQos->u.dyn5Qi.packetErrRateScalar;
1446       schDrbQos->u.dyn5Qi.packetErrRateExp   = macDrbQos->u.dyn5Qi.packetErrRateExp;
1447       schDrbQos->u.dyn5Qi.fiveQi             = macDrbQos->u.dyn5Qi.fiveQi;
1448       schDrbQos->u.dyn5Qi.delayCritical      = macDrbQos->u.dyn5Qi.delayCritical;
1449       schDrbQos->u.dyn5Qi.avgWindow          = macDrbQos->u.dyn5Qi.avgWindow;
1450       schDrbQos->u.dyn5Qi.maxDataBurstVol    = macDrbQos->u.dyn5Qi.maxDataBurstVol;
1451    }
1452    schDrbQos->ngRanRetPri.priorityLevel   = macDrbQos->ngRanRetPri.priorityLevel;
1453    schDrbQos->ngRanRetPri.preEmptionCap   = macDrbQos->ngRanRetPri.preEmptionCap;
1454    schDrbQos->ngRanRetPri.preEmptionVul   = macDrbQos->ngRanRetPri.preEmptionVul;
1455    schDrbQos->grbQosFlowInfo.maxFlowBitRateDl = macDrbQos->grbQosInfo.maxFlowBitRateDl;
1456    schDrbQos->grbQosFlowInfo.maxFlowBitRateUl = macDrbQos->grbQosInfo.maxFlowBitRateUl;
1457    schDrbQos->grbQosFlowInfo.guarFlowBitRateDl= macDrbQos->grbQosInfo.guarFlowBitRateDl;
1458    schDrbQos->grbQosFlowInfo.guarFlowBitRateUl= macDrbQos->grbQosInfo.guarFlowBitRateUl;
1459    schDrbQos->pduSessionId = macDrbQos->pduSessionId;
1460    schDrbQos->ulPduSessAggMaxBitRate = macDrbQos->ulPduSessAggMaxBitRate;
1461 }
1462
1463 /*******************************************************************
1464  *
1465  * @brief Fill SCH UL logical channel configuration
1466  *
1467  * @details
1468  *
1469  *    Function : fillSchUlLcCfg
1470  *
1471  *    Functionality: Fills Sch Ul Lc configuration
1472  *
1473  * @params[in] macLcCfg : Logical channel Cfg at MAC
1474  *             schLcCfg : LC cfg to fill at scheduler
1475  * @return void
1476  *
1477  * ****************************************************************/
1478
1479 void fillSchUlLcCfg(SchUlLcCfg *schUlLcCfg, UlLcCfg *macUlLcCfg) 
1480 {
1481    schUlLcCfg->priority= macUlLcCfg->priority;
1482    schUlLcCfg->lcGroup = macUlLcCfg->lcGroup;
1483    schUlLcCfg->schReqId= macUlLcCfg->schReqId;
1484    schUlLcCfg->pbr    = macUlLcCfg->pbr;    
1485    schUlLcCfg->bsd    = macUlLcCfg->bsd;    
1486 }
1487
1488 /*******************************************************************
1489  *
1490  * @brief Fill logical channel configuration
1491  *
1492  * @details
1493  *
1494  *    Function : fillLogicalChannelCfg
1495  *
1496  *    Functionality: Fill logical channel configuration
1497  *
1498  * @params[in] macLcCfg : Logical channel Cfg at MAC
1499  *             schLcCfg : LC cfg to fill at scheduler
1500  * @return ROK     - success
1501  *         RFAILED - failure
1502  *
1503  * ****************************************************************/
1504 uint8_t fillLogicalChannelCfg(SchLcCfg *schLcCfg, LcCfg *macLcCfg)
1505 {
1506    uint8_t sdIdx;
1507    uint8_t ret = ROK;
1508    schLcCfg->lcId = macLcCfg->lcId;
1509    schLcCfg->configType = macLcCfg->configType;
1510    schLcCfg->dlLcCfg.lcp = macLcCfg->dlLcCfg.lcp;
1511    fillSchUlLcCfg(&schLcCfg->ulLcCfg, &macLcCfg->ulLcCfg);
1512
1513    if(macLcCfg->drbQos)
1514    {
1515       if(!schLcCfg->drbQos)
1516       {
1517          MAC_ALLOC(schLcCfg->drbQos, sizeof(SchDrbQosInfo));
1518          if(!schLcCfg->drbQos)
1519          {
1520             DU_LOG("\nERROR  -->  MAC : Memory alloc failed at drbQos at fillLogicalChannelCfg()");
1521             ret = RFAILED;
1522          }
1523       }
1524       if(ret == ROK)
1525       {
1526          fillSchDrbQosInfo(macLcCfg->drbQos, schLcCfg->drbQos);
1527       }
1528       else
1529          return ret;
1530    }
1531    else
1532    {
1533       schLcCfg->drbQos = NULLP;
1534    }
1535
1536    if(ret == ROK)
1537    {
1538       if(macLcCfg->snssai)
1539       {
1540          if(!schLcCfg->snssai)
1541          {
1542             MAC_ALLOC(schLcCfg->snssai, sizeof(Snssai));
1543             if(!schLcCfg->snssai)
1544             {
1545                DU_LOG("\nERROR  -->  MAC : Memory alloc failed at snssai at fillLogicalChannelCfg()");
1546                ret = RFAILED;
1547             }
1548          }
1549          if(ret == ROK)
1550          {
1551             schLcCfg->snssai->sst = macLcCfg->snssai->sst;
1552             for(sdIdx = 0; sdIdx < SD_SIZE; sdIdx++)
1553             {
1554                schLcCfg->snssai->sd[sdIdx] = macLcCfg->snssai->sd[sdIdx];
1555             }
1556          }
1557       }
1558       else
1559       {
1560          schLcCfg->snssai = NULLP;
1561       }
1562    }
1563
1564    return ret;
1565 }
1566
1567 /*******************************************************************
1568  *
1569  * @brief Fills Logical channel Cfg List to Add/Mod/Del
1570  *
1571  * @details
1572  *
1573  *    Function : fillSchLcCfgList
1574  *
1575  *    Functionality: Fills Logical channel Cfg List to Add/Mod/Del
1576  *
1577  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
1578  * @return ROK     - success
1579  *         RFAILED - failure
1580  *
1581  * ****************************************************************/
1582
1583 uint8_t fillSchLcCfgList(SchUeCfg *schUeCfg, MacUeCfg *ueCfg)
1584 {
1585    uint8_t lcIdx;
1586
1587    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
1588    {
1589       if(fillLogicalChannelCfg(&schUeCfg->schLcCfg[lcIdx], &ueCfg->lcCfgList[lcIdx]) != ROK)
1590       {
1591          DU_LOG("\nERROR  -->  MAC : fillLogicalChannelCfg() failed for lc Idx[%d]", lcIdx);
1592          return RFAILED;
1593       }
1594       schUeCfg->numLcs++;
1595    }
1596    return ROK;
1597 }
1598
1599 /*******************************************************************
1600  *
1601  * @brief Fills and sends UE configuration to Scheduler
1602  *
1603  * @details
1604  *
1605  *    Function : fillSchUeCfg
1606  *
1607  *    Functionality: Fills and sends UE configuration to Scheduler
1608  *
1609  * @params[in] Ue configuration from DU APP
1610  * @return ROK     - success
1611  *         RFAILED - failure
1612  *
1613  * ****************************************************************/
1614 uint8_t fillSchUeCfg(Pst *pst, SchUeCfg *schUeCfg, MacUeCfg *ueCfg)
1615 {
1616    uint8_t ret = ROK;
1617
1618    schUeCfg->cellId = ueCfg->cellId;
1619    schUeCfg->crnti = ueCfg->crnti;
1620
1621    /* Copy MAC cell group config */
1622    if(ueCfg->macCellGrpCfgPres == true)
1623    {
1624       schUeCfg->macCellGrpCfgPres = true;
1625       memset(&schUeCfg->macCellGrpCfg, 0, sizeof(SchMacCellGrpCfg));
1626       if(fillMacCellGroupCfg(ueCfg->macCellGrpCfg, &schUeCfg->macCellGrpCfg) != ROK)
1627       {
1628          DU_LOG("\nERROR  -->  MAC : fillMacCellGroupCfg() failed");
1629          return RFAILED;
1630       }
1631    }
1632    if(ueCfg->phyCellGrpCfgPres == true)
1633    {
1634      schUeCfg->phyCellGrpCfgPres = true;
1635      /* Copy Physical cell group config */
1636       memset(&schUeCfg->phyCellGrpCfg, 0,sizeof(SchPhyCellGrpCfg));
1637       if(fillPhyCellGroupCfg(ueCfg->phyCellGrpCfg, &schUeCfg->phyCellGrpCfg) != ROK)
1638       {
1639          DU_LOG("\nERROR  -->  MAC : fillPhyCellGroupCfg() failed");
1640          return RFAILED;
1641       }
1642    }
1643
1644    if(ueCfg->spCellCfgPres == true)
1645    {
1646       schUeCfg->spCellCfgPres = true;
1647       /* Copy sp cell config */
1648       memset(&schUeCfg->spCellCfg, 0, sizeof(SchSpCellCfg));
1649       if(fillSpCellCfg(ueCfg->spCellCfg, &schUeCfg->spCellCfg) != ROK)
1650       {
1651          DU_LOG("\nERROR  -->  MAC : fillSpCellCfg() failed");
1652          return RFAILED;
1653       }
1654    }
1655    if(ueCfg->ambrCfg != NULLP)
1656    {
1657       MAC_ALLOC(schUeCfg->ambrCfg, sizeof(SchAmbrCfg));
1658       if(!schUeCfg->ambrCfg)
1659       {
1660          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in sendReconfigReqToSch");
1661          return RFAILED;
1662       }
1663       schUeCfg->ambrCfg->ulBr = ueCfg->ambrCfg->ulBr;
1664    }
1665    else
1666    {
1667       schUeCfg->ambrCfg = NULLP;
1668    }
1669    /* Fill DL modulation infor */
1670    schUeCfg->dlModInfo.modOrder = ueCfg->dlModInfo.modOrder;
1671    schUeCfg->dlModInfo.mcsIndex = ueCfg->dlModInfo.mcsIndex;
1672    schUeCfg->dlModInfo.mcsTable = ueCfg->dlModInfo.mcsTable;
1673
1674    /* Fill UL modulation infor */
1675    schUeCfg->ulModInfo.modOrder = ueCfg->ulModInfo.modOrder;
1676    schUeCfg->ulModInfo.mcsIndex = ueCfg->ulModInfo.mcsIndex;
1677    schUeCfg->ulModInfo.mcsTable = ueCfg->ulModInfo.mcsTable;
1678
1679    /* Fill sch Lc Cfg  to Add/ Mod/ Del */
1680    ret  = fillSchLcCfgList(schUeCfg, ueCfg);
1681    if(ret == RFAILED)
1682    {
1683       DU_LOG("\nERROR  -->  MAC : Failed to copy LCs at fillSchUeCfg()");
1684       return ret;
1685    }
1686    return ret;
1687 }
1688
1689 /*******************************************************************
1690  *
1691  * @brief Update UeUlCb Lc List
1692  *
1693  * @details
1694  *
1695  *    Function : updateMacUlCb
1696  *
1697  *    Functionality: Update UeUlCb Lc List
1698  *
1699  * @params[in] delIdx, UeUlCb pointer
1700  * @return void
1701  *
1702  * ****************************************************************/
1703
1704 void updateMacUlCb(uint8_t delIdx, UeUlCb *ulCb)
1705 {
1706    uint8_t lcIdx = 0;
1707
1708    for(lcIdx = delIdx; lcIdx < ulCb->numUlLc; lcIdx++)
1709    {
1710       /* Moving the array element to one step ahead */
1711       memcpy(&ulCb->lcCb[lcIdx], &ulCb->lcCb[lcIdx+1], sizeof(UlLcCb));
1712       memset(&ulCb->lcCb[lcIdx+1], 0, sizeof(UlLcCb));
1713    }
1714    /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1715 #if 0
1716    /*Checking the Memory Leakage of Last Index*/
1717    if(ulCb->lcCb[ulCb->numUlLc].snssai != NULLP)
1718    {
1719       DU_LOG("ERROR  --> MAC: updateMacUlCb Last index deleted :%d  memory is leaking",\
1720             ulCb->numUlLc);
1721       MAC_FREE(ulCb->lcCb[ulCb->numUlLc].snssai, sizeof(Snssai));
1722    }
1723    else
1724    {
1725       DU_LOG("INFO  --> MAC: updateMacUlCb Last index:%d (before deletion) memory is freed successfully",\
1726             ulCb->numUlLc);
1727    }
1728 #endif
1729 }
1730
1731 /*******************************************************************
1732  *
1733  * @brief Update UeDlCb Lc List
1734  *
1735  * @details
1736  *
1737  *    Function : updateMacDlCb
1738  *
1739  *    Functionality: Update UeDlCb Lc List
1740  *
1741  * @params[in] delIdx, UeDlCb pointer
1742  * @return void
1743  *
1744  * ****************************************************************/
1745
1746 void updateMacDlCb(uint8_t delIdx, UeDlCb *dlCb)
1747 {
1748    uint8_t lcIdx = 0;
1749
1750    for(lcIdx = delIdx; lcIdx < dlCb->numDlLc; lcIdx++)
1751    {
1752       /* Moving the array element to one step ahead */
1753       memcpy(&dlCb->lcCb[lcIdx], &dlCb->lcCb[lcIdx+1], sizeof(DlLcCb));
1754       memset(&dlCb->lcCb[lcIdx+1], 0, sizeof(DlLcCb));
1755    }
1756    /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1757 #if 0
1758    /*Checking the Memory Leakage of Last Index*/
1759    if(dlCb->lcCb[dlCb->numDlLc].snssai != NULLP)
1760    {
1761       DU_LOG("ERROR  --> MAC: updateMacDlCb Last Deleted index:%d memory is leaking",\
1762             dlCb->numDlLc);
1763       MAC_FREE(dlCb->lcCb[dlCb->numDlLc].snssai, sizeof(Snssai));
1764    }
1765    else
1766    {
1767       DU_LOG("INFO  --> MAC: updateMacDlCb Last index:%d (before deletion) memory is freed successfully",\
1768             dlCb->numDlLc);
1769    }
1770 #endif
1771 }
1772
1773 /*******************************************************************
1774  *
1775  * @brief Update Mac UL Lc List based on CONFIG_MOD/CONFIG_DEL
1776  *
1777  * @details
1778  *
1779  *    Function : updateMacUlLcCtxt
1780  *
1781  *    Functionality: Update UeUlCb Lc List
1782  *
1783  * @params[in]  UeUlCb pointer, ueLcCfg(received from DUAPP)
1784  * @return void
1785  *
1786  * ****************************************************************/
1787 void updateMacUlLcCtxt(UeUlCb *ulInfo, LcCfg *ueLcCfg)
1788 {
1789    uint8_t ueLcIdx = 0; 
1790
1791    /*Traversing UL LC to be updated/Deleted*/
1792    for(ueLcIdx = 0; ueLcIdx < ulInfo->numUlLc; ueLcIdx++)
1793    {
1794       if(ulInfo->lcCb[ueLcIdx].lcId == ueLcCfg->lcId)
1795       {
1796          if(ueLcCfg->configType == CONFIG_MOD)
1797          {
1798             /*Modify UL LC CB */
1799             ulInfo->lcCb[ueLcIdx].lcGrpId = ueLcCfg->ulLcCfg.lcGroup;
1800
1801             /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1802 #if 0
1803             /*Modifying/Copying PduSession ID and S-NSSAI into MAC's UECB*/
1804             if(ueLcCfg->drbQos)
1805             {
1806                ulInfo->lcCb[ueLcIdx].pduSessionId = ueLcCfg->drbQos->pduSessionId;
1807             }
1808             if(ueLcCfg->snssai)
1809             {
1810                if(ulInfo->lcCb[ueLcIdx].snssai == NULLP)
1811                {
1812                   MAC_ALLOC(ulInfo->lcCb[ueLcIdx].snssai, sizeof(Snssai));
1813                }
1814
1815                memcpy(ulInfo->lcCb[ueLcIdx].snssai, ueLcCfg->snssai, sizeof(Snssai));
1816             }
1817 #endif
1818             DU_LOG("\nINFO  -->  MAC: Successfully Modified LC context for lcId[%d], ueLcIdx:%d",\
1819                   ueLcCfg->lcId,ueLcIdx);
1820             break;
1821          }
1822          if(ueLcCfg->configType == CONFIG_DEL)
1823          {
1824             memset(&ulInfo->lcCb[ueLcIdx], 0, sizeof(UlLcCb));
1825             (ulInfo->numUlLc)--;
1826             updateMacUlCb(ueLcIdx, ulInfo);
1827             DU_LOG("\nINFO  -->  MAC: Successfully Deleted LC context for lcId[%d]", ueLcCfg->lcId);
1828             break;
1829          }
1830       }
1831    }
1832 }
1833
1834 /*******************************************************************
1835  *
1836  * @brief Update Mac DL Lc List based on CONFIG_MOD/CONFIG_DEL
1837  *
1838  * @details
1839  *
1840  *    Function : updateMacDlLcCtxt
1841  *
1842  *    Functionality: Update UeDlCb Lc List
1843  *
1844  * @params[in]  UeDlCb pointer, ueLcCfg(received from DUAPP)
1845  * @return void
1846  *
1847  * ****************************************************************/
1848 void updateMacDlLcCtxt(UeDlCb *dlInfo, LcCfg *ueLcCfg)
1849 {
1850    uint8_t ueLcIdx = 0; 
1851
1852    /*Traversing DL LC to be updated/Deleted*/
1853    for(ueLcIdx = 0; ueLcIdx < dlInfo->numDlLc; ueLcIdx++)
1854    {
1855       if(dlInfo->lcCb[ueLcIdx].lcId == ueLcCfg->lcId)
1856       {
1857          if(ueLcCfg->configType == CONFIG_MOD)
1858          {
1859             /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1860 #if 0
1861             /*Modifying/Copying PduSession ID and S-NSSAI into MAC's UECB*/
1862             if(ueLcCfg->drbQos)
1863             {
1864                dlInfo->lcCb[ueLcIdx].pduSessionId = ueLcCfg->drbQos->pduSessionId;
1865             }
1866             if(ueLcCfg->snssai)
1867             {
1868                if(dlInfo->lcCb[ueLcIdx].snssai == NULLP)
1869                {
1870                   MAC_ALLOC(dlInfo->lcCb[ueLcIdx].snssai, sizeof(Snssai));
1871                }
1872
1873                memcpy(dlInfo->lcCb[ueLcIdx].snssai, ueLcCfg->snssai, sizeof(Snssai));
1874             }
1875 #endif
1876             DU_LOG("\nINFO  -->  MAC: Successfully Modified LC context for lcId[%d], ueLcIdx:%d",\
1877                   ueLcCfg->lcId,ueLcIdx);
1878             break;
1879          }
1880          if(ueLcCfg->configType == CONFIG_DEL)
1881          {
1882             memset(&dlInfo->lcCb[ueLcIdx], 0, sizeof(DlLcCb));
1883             (dlInfo->numDlLc)--;
1884             updateMacDlCb(ueLcIdx, dlInfo);
1885             DU_LOG("\nINFO  -->  MAC: Successfully Deleted LC context for lcId[%d]", ueLcCfg->lcId);
1886             break;
1887          }
1888       }
1889    }
1890 }
1891 /*******************************************************************
1892  *
1893  * @brief Fills Logical channel Cfg List to Add/Mod/Del
1894  *
1895  * @details
1896  *
1897  *    Function : fillMacLcCfgList
1898  *
1899  *    Functionality: Fills Logical channel Cfg List to Add/Mod/Del
1900  *
1901  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
1902  * @return ROK     - success
1903  *         RFAILED - failure
1904  *
1905  * ****************************************************************/
1906
1907 uint8_t fillMacLcCfgList(MacUeCb *ueCb, MacUeCfg *ueCfg)
1908 {
1909    uint8_t lcIdx = 0;
1910
1911    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
1912    {
1913       if(ueCb->dlInfo.numDlLc < MAX_NUM_LC)
1914       {
1915          if(ueCfg->lcCfgList[lcIdx].configType == CONFIG_ADD)
1916          {
1917             /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1918 #if 0
1919             /*Copying PduSession ID and S-NSSAI into MAC's UECB*/
1920             if(ueCfg->lcCfgList[lcIdx].drbQos)
1921             {
1922                ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].pduSessionId = \
1923                                                                       ueCfg->lcCfgList[lcIdx].drbQos->pduSessionId;
1924
1925                ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].pduSessionId = \
1926                                                                       ueCfg->lcCfgList[lcIdx].drbQos->pduSessionId;
1927             }
1928             if(ueCfg->lcCfgList[lcIdx].snssai)
1929             {
1930                if(ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].snssai == NULLP)
1931                {
1932                   MAC_ALLOC(ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].snssai, sizeof(Snssai));
1933                }
1934                if(ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].snssai == NULLP)
1935                {
1936                   MAC_ALLOC(ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].snssai, sizeof(Snssai));
1937                }
1938
1939                memcpy(ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].snssai, \
1940                      ueCfg->lcCfgList[lcIdx].snssai, sizeof(Snssai));
1941
1942                memcpy(ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].snssai, \
1943                      ueCfg->lcCfgList[lcIdx].snssai, sizeof(Snssai));
1944
1945             }
1946 #endif
1947             /*Filling DL LC CB */
1948             ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcId = ueCfg->lcCfgList[lcIdx].lcId;
1949             ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcState = MAC_LC_STATE_ACTIVE;
1950             ueCb->dlInfo.numDlLc++;
1951             /*Filling UL LC CB */
1952             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcId = ueCfg->lcCfgList[lcIdx].lcId;
1953             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcGrpId = ueCfg->lcCfgList[lcIdx].ulLcCfg.lcGroup;
1954             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcActive = MAC_LC_STATE_ACTIVE;
1955             ueCb->ulInfo.numUlLc++;
1956          }/*End of Add Config */
1957          else
1958          {
1959             updateMacUlLcCtxt(&ueCb->ulInfo, &ueCfg->lcCfgList[lcIdx]);            
1960             updateMacDlLcCtxt(&ueCb->dlInfo, &ueCfg->lcCfgList[lcIdx]);            
1961          }/*End of Mod Config */
1962       }
1963    }
1964    return ROK;
1965 }
1966
1967 /*******************************************************************
1968  *
1969  * @brief Fills MAC UE Cb Cfg
1970  *
1971  * @details
1972  *
1973  *    Function : fillMacUeCb
1974  *
1975  *    Functionality: Fills MAC UE Cb Cfg
1976  *
1977  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
1978  *             cellIdx
1979  * @return ROK     - success
1980  *         RFAILED - failure
1981  *
1982  * ****************************************************************/
1983
1984 uint8_t fillMacUeCb(MacUeCb *ueCb, MacUeCfg *ueCfg, uint8_t cellIdx)
1985 {
1986    uint8_t ret = ROK;
1987
1988    ueCb->ueIdx = ueCfg->ueIdx;
1989    ueCb->crnti = ueCfg->crnti;
1990    ueCb->cellCb = macCb.macCell[cellIdx];
1991    if(ueCfg->spCellCfgPres)
1992    {
1993       ueCb->dlInfo.dlHarqEnt.numHarqProcs = \
1994       ueCfg->spCellCfg.servCellCfg.pdschServCellCfg.numHarqProcForPdsch; 
1995    }
1996    ueCb->state = UE_STATE_ACTIVE;
1997    /*TODO: To check the bsr value during implementation */
1998    if(ueCfg->macCellGrpCfgPres)
1999    {
2000       ueCb->bsrTmrCfg.periodicTimer = ueCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer;
2001       ueCb->bsrTmrCfg.retxTimer     = ueCfg->macCellGrpCfg.bsrTmrCfg.retxTimer;
2002       ueCb->bsrTmrCfg.srDelayTimer  = ueCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer;
2003    }
2004    ret = fillMacLcCfgList(ueCb, ueCfg);
2005    if(ret == RFAILED)
2006    {
2007       DU_LOG("\nERROR  -->  MAC: Failed while filing MAC LC List at fillMacUeCb()");
2008    }
2009    return ret;
2010 }
2011
2012 /*******************************************************************
2013  *
2014  * @brief Function to update Mac Ra Cb
2015  *
2016  * @details
2017  *
2018  *    Function : updateMacRaCb
2019  *
2020  *    Functionality: Function to update Mac Ra Cb
2021  *
2022  * @params[in] cellIdx, Mac Ue Cb
2023  * @return ROK     - success
2024  *         RFAILED - failure
2025  *
2026  * ****************************************************************/
2027
2028 uint8_t updateMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
2029 {
2030    uint8_t ueIdx;
2031    /* Copy RA Cb */
2032    for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
2033    {
2034       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == ueCb->crnti)
2035       {
2036          ueCb->raCb = &macCb.macCell[cellIdx]->macRaCb[ueIdx];
2037          break;
2038       }
2039    }
2040    return ROK;
2041 }
2042
2043 /*******************************************************************
2044  *
2045  * @brief Function to delete Mac Ra Cb
2046  *
2047  * @details
2048  *
2049  *    Function : deleteMacRaCb
2050  *
2051  *    Functionality: Function to delete Mac Ra Cb
2052  *
2053  * @params[in] cellIdx, Mac Ue Cb
2054  * @return void
2055  *
2056  * ****************************************************************/
2057
2058 void deleteMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
2059 {
2060    uint8_t ueIdx;
2061
2062    for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
2063    {
2064       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == ueCb->crnti)
2065       {
2066          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
2067          {
2068            MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
2069                      macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
2070          }
2071          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu)
2072          {
2073             MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
2074                       macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
2075          }
2076          memset(&macCb.macCell[cellIdx]->macRaCb[ueIdx], 0, sizeof(MacRaCbInfo));
2077          break;
2078       }
2079    }
2080                   
2081 }
2082
2083 /*******************************************************************
2084  *
2085  * @brief Creates UE Cb
2086  *
2087  * @details
2088  *
2089  *    Function : createUeCb
2090  *
2091  *    Functionality: Creates UE Cb
2092  *
2093  * @params[in] MAC UE Configuration
2094  * @return ROK     - success
2095  *         RFAILED - failure
2096  *
2097  * ****************************************************************/
2098 uint8_t createUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
2099 {
2100    uint8_t ret =ROK;
2101
2102    if((ueCb->ueIdx == ueCfg->ueIdx) && (ueCb->crnti == ueCfg->crnti)\
2103       &&(ueCb->state == UE_STATE_ACTIVE))
2104    {
2105       DU_LOG("\nERROR  -->  MAC : CRNTI %d already configured ", ueCfg->crnti);
2106       return ROKDUP;
2107    }
2108    else
2109    {
2110       memset(ueCb, 0, sizeof(MacUeCb));
2111       ret = fillMacUeCb(ueCb, ueCfg, cellIdx);
2112       if(ret != ROK)
2113       {
2114          DU_LOG("\nERROR  -->  MAC : Failed to create Ue Cb at createUeCb()");
2115          return ret;
2116       }
2117       else
2118       {
2119          macCb.macCell[cellIdx]->numActvUe++;
2120          updateMacRaCb(cellIdx, ueCb);
2121          return ROK;
2122       }
2123
2124    }
2125
2126 }
2127
2128 /*******************************************************************
2129  *
2130  * @brief Modify UE Cb Cfg
2131  *
2132  * @details
2133  *
2134  *    Function : modifyUeCb
2135  *
2136  *    Functionality: modify UE Cb
2137  *
2138  * @params[in] MAC UE Configuration
2139  * @return ROK     - success
2140  *         RFAILED - failure
2141  *
2142  * ****************************************************************/
2143 uint8_t modifyUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
2144 {
2145    uint8_t ret = ROK;
2146
2147    if((ueCb->ueIdx == ueCfg->ueIdx) && (ueCb->crnti == ueCfg->crnti)\
2148       &&(ueCb->state == UE_STATE_ACTIVE))
2149    {
2150       DU_LOG("\nINFO  -->  MAC : Modifying Ue config Req for CRNTI %d ", ueCfg->crnti);
2151       ret = fillMacUeCb(ueCb, ueCfg, cellIdx);
2152       if(ret != ROK)
2153       {
2154          DU_LOG("\nERROR  -->  MAC : Failed to modify MacUeCb at modifyUeCb()");
2155          return ret;
2156       }
2157       else
2158       {
2159          deleteMacRaCb(cellIdx, ueCb);
2160          return ROK;
2161       }
2162    }
2163    return RFAILED;
2164 }
2165
2166
2167 /*******************************************************************
2168  *
2169  * @brief Creates UE Cb and fills ueCfg
2170  *
2171  * @details
2172  *
2173  *    Function : procMacUeCfgData
2174  *
2175  *    Functionality: Creates UE Cb and fills ueCfg
2176  *
2177  * @params[in] MAC UE Configuration
2178  * @return ROK     - success
2179  *         RFAILED - failure
2180  *
2181  * ****************************************************************/
2182
2183 uint8_t procMacUeCfgData(Pst *pst, MacUeCfg *ueCfg)
2184 {
2185    uint8_t ret = ROK;
2186    uint16_t  cellIdx;
2187    MacUeCb   *ueCb = NULLP;
2188
2189
2190    GET_CELL_IDX(ueCfg->cellId, cellIdx);
2191
2192    /* Validate cell id */
2193    if(macCb.macCell[cellIdx]->cellId != ueCfg->cellId)
2194    {
2195       DU_LOG("\nERROR  -->  MAC : Cell Id %d not configured", ueCfg->cellId);
2196       return RFAILED;
2197    }
2198
2199    /* Check if max number of UE configured */
2200    if(macCb.macCell[cellIdx]->numActvUe > MAX_NUM_UE)
2201    {
2202       DU_LOG("\nERROR  -->  MAC : Max number of UE [%d] already configured", MAX_NUM_UE);
2203       return RFAILED;
2204    }
2205
2206    /* Check if UE already configured */
2207    ueCb = &macCb.macCell[cellIdx]->ueCb[ueCfg->ueIdx -1];
2208    switch(pst->event)
2209    {
2210       case EVENT_UE_CONFIG_RSP_TO_MAC:
2211          ret = createUeCb(cellIdx, ueCb, ueCfg);
2212          if(ret != ROK)
2213             DU_LOG("\nERROR  -->  MAC: AddUeConfigReq for cellIdx :%d failed in procMacUeCfgData()", cellIdx);
2214          break;
2215       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2216          ret = modifyUeCb(cellIdx, ueCb, ueCfg);
2217          if(ret != ROK)
2218             DU_LOG("\nERROR  -->  MAC: ModifyUeConfigReq for cellIdx :%d failed at procMacUeCfgData()", cellIdx);
2219          break;
2220       default:
2221          break;
2222    }
2223
2224    return ret;
2225 }
2226
2227 /*******************************************************************
2228  *
2229  * @brief Function to store the UeCfg Data 
2230  *
2231  * @details
2232  *
2233  *    Function : copyToTmpData
2234  *
2235  *    Functionality: Function to store the UeCfg Data
2236  *
2237  * @params[in] MacUeCfg pointer 
2238  * @return ROK     - success
2239  *         RFAILED - failure
2240  *
2241  * ****************************************************************/
2242
2243 uint8_t copyToTmpData(MacUeCfg *ueCfg)
2244 {
2245    uint8_t cellIdx;
2246    MacUeCfg *tmpData = NULLP;
2247
2248    MAC_ALLOC(tmpData, sizeof(MacUeCfg));
2249    if(!tmpData)
2250    {
2251       DU_LOG("\nERROR  -->  MAC: Memory Alloc Failed at copyToTmpData()");
2252       return RFAILED;
2253    }
2254    memcpy(tmpData, ueCfg, sizeof(MacUeCfg));
2255    GET_CELL_IDX(ueCfg->cellId, cellIdx);
2256    macCb.macCell[cellIdx]->ueCfgTmpData[ueCfg->ueIdx-1] = tmpData;
2257    return ROK;
2258 }
2259
2260 /*******************************************************************
2261  *
2262  * @brief Handles UE create requst from DU APP
2263  *
2264  * @details
2265  *
2266  *    Function : MacProcUeCreateReq
2267  *
2268  *    Functionality: Handles UE create requst from DU APP
2269  *
2270  * @params[in] 
2271  * @return ROK     - success
2272  *         RFAILED - failure
2273  *
2274  * ****************************************************************/
2275 uint8_t MacProcUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
2276 {
2277    uint8_t ret = ROK;
2278    SchUeCfg   schUeCfg;
2279    memset(&schUeCfg, 0, sizeof(SchUeCfg));
2280
2281    DU_LOG("\nINFO  -->  MAC : UE Create Request for CRNTI[%d]", ueCfg->crnti);
2282
2283    if(ueCfg)
2284    {
2285       /*Storing received ueCfg in ueCfgTmpData */
2286       ret = copyToTmpData(ueCfg);
2287       if(ret == ROK)
2288       {
2289          /*Sending Cfg Req to SCH */
2290          ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
2291          if(ret != ROK)
2292             DU_LOG("\nERROR  -->  MAC : Failed to fill Sch Ue Cfg at MacProcUeCreateReq()");
2293          else
2294          {
2295             /* Fill event and send UE create request to SCH */
2296             ret = sendUeReqToSch(pst, &schUeCfg);
2297             if(ret != ROK)
2298                DU_LOG("\nERROR  -->  MAC : Failed to send UE Create request to SCH");
2299          }
2300       }
2301       else 
2302       {
2303          DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE CFG ");
2304       }
2305    }
2306    else
2307    {
2308       DU_LOG("\nERROR  -->  MAC : MAC UE Create request processing failed");
2309       ret = RFAILED;
2310    }
2311    /* FREE shared memory */
2312    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
2313
2314    return ret;
2315 }
2316
2317 /*******************************************************************
2318  *
2319  * @brief Fill and Send UE create response from MAC to DU APP
2320  *
2321  * @details
2322  *
2323  *    Function : MacSendUeCreateRsp
2324  *
2325  *    Functionality: Fill and Send UE create response from MAC to DUAPP
2326  *
2327  * @params[in] MAC UE create result
2328  *             SCH UE create response
2329  * @return ROK     - success
2330  *         RFAILED - failure
2331  *
2332  * ****************************************************************/
2333 uint8_t MacSendUeCreateRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
2334 {
2335    MacUeCfgRsp   *cfgRsp;
2336    Pst        rspPst;
2337
2338    MAC_ALLOC_SHRABL_BUF(cfgRsp, sizeof(MacUeCfgRsp));
2339    if(!cfgRsp)
2340    {
2341       DU_LOG("\nERROR  -->  MAC: Memory allocation for UE config response failed");
2342       return RFAILED;
2343    }
2344
2345    /* Filling UE Config response */
2346    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
2347    cfgRsp->cellId = schCfgRsp->cellId;
2348    cfgRsp->ueIdx = schCfgRsp->ueIdx;
2349    cfgRsp->result = result;
2350
2351    /* Fill Post structure and send UE Create response*/
2352    memset(&rspPst, 0, sizeof(Pst));
2353    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_CREATE_RSP);
2354    return (*macDuUeCfgRspOpts[rspPst.selector])(&rspPst, cfgRsp); 
2355 }
2356
2357 /*******************************************************************
2358  *
2359  * @brief Fill and Send UE Reconfig response from MAC to DU APP
2360  *
2361  * @details
2362  *
2363  *    Function : MacSendUeReconfigRsp
2364  *
2365  *    Functionality: Fill and Send UE Reconfig response from MAC to DUAPP
2366  *
2367  * @params[in] MAC UE create result
2368  *             SCH UE create response
2369  * @return ROK     - success
2370  *         RFAILED - failure
2371  *
2372  * ****************************************************************/
2373 uint8_t MacSendUeReconfigRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
2374 {
2375    MacUeCfgRsp   *cfgRsp;
2376    Pst        rspPst;
2377
2378    MAC_ALLOC_SHRABL_BUF(cfgRsp, sizeof(MacUeCfgRsp));
2379    if(!cfgRsp)
2380    {
2381       DU_LOG("\nERROR  -->  MAC: Memory allocation for UE Reconfig response failed");
2382       return RFAILED;
2383    }
2384
2385    /* Filling UE Config response */
2386    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
2387    cfgRsp->cellId = schCfgRsp->cellId;
2388    cfgRsp->ueIdx = schCfgRsp->ueIdx;
2389    cfgRsp->result = result;
2390
2391    /* Fill Post structure and send UE Create response*/
2392    memset(&rspPst, 0, sizeof(Pst));
2393    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_RECONFIG_RSP);
2394    return (*macDuUeCfgRspOpts[rspPst.selector])(&rspPst, cfgRsp);
2395 }
2396
2397 /*******************************************************************
2398  *
2399  * @brief  Function to return Mac Ue Cfg pointer
2400  *
2401  * @details
2402  *
2403  *    Function : getMacUeCfg
2404  *
2405  *    Functionality:
2406  *      Function to return Mac Ue Cfg pointer
2407  *
2408  * @params[in] cellIdx, ueIdx
2409  *
2410  * @return MacUeCfg pointer - success
2411  *         NULLP - failure
2412  *
2413  * ****************************************************************/
2414
2415 MacUeCfg *getMacUeCfg(uint16_t cellIdx, uint8_t ueIdx)
2416 {
2417    MacUeCfg *ueCfg = NULLP;
2418    if(macCb.macCell[cellIdx])
2419    {
2420       ueCfg = macCb.macCell[cellIdx]->ueCfgTmpData[ueIdx-1];
2421    }
2422    else
2423    {
2424       DU_LOG("\nERROR  -->  MAC: Failed to get macCellCb in getMacUeCfg()");
2425    }
2426    return ueCfg;
2427 }
2428
2429 /*******************************************************************
2430  *
2431  * @brief  Processes UE create response from scheduler
2432  *
2433  * @details
2434  *
2435  *    Function : MacProcSchUeCfgRsp
2436  *
2437  *    Functionality:
2438  *      Processes UE create response from scheduler
2439  *      Sends UE create response to DU APP
2440  *
2441  * @params[in] Pst : Post structure
2442  *             schCfgRsp : Scheduler UE cfg response
2443  * @return ROK     - success
2444  *         RFAILED - failure
2445  *
2446  * ****************************************************************/
2447 uint8_t MacProcSchUeCfgRsp(Pst *pst, SchUeCfgRsp *schCfgRsp)
2448 {
2449    uint8_t result = MAC_DU_APP_RSP_NOK;
2450    uint8_t ret = ROK;
2451    uint16_t cellIdx;
2452    MacUeCfg *ueCfg = NULLP;
2453
2454 #ifdef CALL_FLOW_DEBUG_LOG
2455    switch(pst->event)
2456    {
2457       case EVENT_UE_CONFIG_RSP_TO_MAC:
2458          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_CONFIG_RSP_TO_MAC\n");
2459          break;
2460       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2461          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_RECONFIG_RSP_TO_MAC\n");
2462          break;
2463       default:
2464          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : Invalid Event\n");
2465          break;
2466    }
2467 #endif
2468    
2469    GET_CELL_IDX(schCfgRsp->cellId, cellIdx);
2470    ueCfg = getMacUeCfg(cellIdx, schCfgRsp->ueIdx);
2471    if(ueCfg == NULLP)
2472    {
2473       DU_LOG("\nERROR  -->  MAC : Failed to find the Mac Ue Cfg for event [%d] in MacProcSchUeCfgRsp()", pst->event);
2474       ret = RFAILED;
2475    }
2476
2477    switch(pst->event)
2478    {
2479       case EVENT_UE_CONFIG_RSP_TO_MAC:
2480          {
2481             if(schCfgRsp->rsp != RSP_NOK)
2482             {
2483                DU_LOG("\nINFO  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2484                if(ret == ROK)
2485                {
2486                   ret = procMacUeCfgData(pst, ueCfg);
2487                   if(ret == ROK)
2488                   {
2489                      result = MAC_DU_APP_RSP_OK;
2490                   }
2491                }
2492             }
2493             else
2494             {
2495                DU_LOG("\nERROR  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2496             }
2497             ret = MacSendUeCreateRsp(result, schCfgRsp);
2498          }
2499          break;
2500
2501       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2502          {
2503
2504             if(schCfgRsp->rsp != RSP_NOK)
2505             {
2506                DU_LOG("\nINFO  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()",\
2507                      schCfgRsp->crnti);
2508                if(ret == ROK)
2509                {
2510                   ret = procMacUeCfgData(pst, ueCfg);
2511                   if(ret == ROK)
2512                   {
2513                      result = MAC_DU_APP_RSP_OK;
2514                   }
2515                }
2516             }
2517             else
2518             {
2519                DU_LOG("\nERROR  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()",\
2520                schCfgRsp->crnti);
2521             }
2522             ret = MacSendUeReconfigRsp(result, schCfgRsp);
2523          }
2524          break;
2525    }
2526    MAC_FREE(ueCfg, sizeof(MacUeCfg));
2527    ueCfg = NULLP;
2528    return ret; 
2529 }
2530
2531 /*******************************************************************
2532  *
2533  * @brief Handles UE Reconfig requst from DU APP
2534  *
2535  * @details
2536  *
2537  *    Function : MacProcUeReconfigReq
2538  *
2539  *    Functionality: Handles UE Reconfig requst from DU APP
2540  *
2541  * @params[in] 
2542  * @return ROK     - success
2543  *         RFAILED - failure
2544  *
2545  * ****************************************************************/
2546 uint8_t MacProcUeReconfigReq(Pst *pst, MacUeCfg *ueCfg)
2547 {
2548    uint8_t ret = ROK;
2549    SchUeCfg   schUeCfg;
2550    memset(&schUeCfg, 0, sizeof(SchUeCfg));
2551
2552    DU_LOG("\nINFO  -->  MAC : UE Reconfig Request for CRNTI[%d]", ueCfg->crnti);
2553
2554    if(ueCfg)
2555    {
2556       /*Storing received ueCfg in ueCfgTmpData */
2557       ret = copyToTmpData(ueCfg);
2558       if(ret == ROK)
2559       {
2560          /*Sending Cfg Req to SCH */
2561          ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
2562          if(ret != ROK)
2563             DU_LOG("\nERROR  -->  MAC : Failed to fill sch Ue Cfg at MacProcUeReconfigReq()");
2564          else
2565          {
2566             /* Fill event and send UE create request to SCH */
2567             ret = sendUeReqToSch(pst, &schUeCfg);
2568             if(ret != ROK)
2569                DU_LOG("\nERROR  -->  MAC : Failed to send UE Reconfig Request to SCH");
2570          }
2571       }
2572       else 
2573       {
2574          DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE Cb ");
2575       }
2576    }
2577    else
2578    {
2579       DU_LOG("\nERROR  -->  MAC : MAC UE Create request processing failed");
2580       ret = RFAILED;
2581    }
2582    /* FREE shared memory */
2583    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
2584    return ROK;
2585 }
2586
2587 /*******************************************************************
2588 *
2589 * @brief Fill and Send UE Delete response from MAC to DU APP
2590 *
2591 * @details
2592 *
2593 *    Function : MacSendUeDeleteRsp 
2594 *
2595 *    Functionality: Fill and Send UE Delete response from MAC to DUAPP
2596 *
2597 * @params[in] MAC UE delete result
2598 *             SCH UE delete response
2599 * @return ROK     - success
2600 *         RFAILED - failure
2601 *
2602 * ****************************************************************/
2603
2604 uint8_t MacSendUeDeleteRsp(uint16_t cellId, uint16_t crnti, UeDeleteStatus result)
2605 {
2606    MacUeDeleteRsp *deleteRsp;
2607    Pst            rspPst;
2608
2609    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacUeDeleteRsp));
2610    if(!deleteRsp)
2611    {
2612       DU_LOG("\nERROR  -->  MAC : Memory allocation for UE delete response failed");
2613       return RFAILED;
2614    }
2615
2616    /* Filling UE delete response */
2617    deleteRsp->cellId = cellId;
2618    GET_UE_IDX(crnti,deleteRsp->ueId);
2619    deleteRsp->result = result;
2620
2621    /* Fill Post structure and send UE delete response*/
2622    memset(&rspPst, 0, sizeof(Pst));
2623    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_DELETE_RSP);
2624    return (*macDuUeDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
2625 }
2626
2627 /*******************************************************************
2628 *
2629 * @brief freeing the Pucch Resrc Cfg 
2630 *
2631 * @details
2632 *
2633 *    Function : deletePucchResourcesCfg 
2634 *
2635 *    Functionality: freeing the Pucch Resrc Cfg
2636 *
2637 * @params[in] PucchResrcCfg *resrcCfg
2638 * @return ROK     - success
2639 *         RFAILED - failure
2640 *
2641 * ****************************************************************/
2642
2643 void deletePucchResourcesCfg(PucchResrcCfg *resrcCfg)
2644 {
2645    uint8_t resrcIdx;
2646    for(resrcIdx =0; resrcIdx< resrcCfg->resrcToAddModListCount;resrcIdx++)
2647    {
2648       switch(resrcCfg->resrcToAddModList[resrcIdx].pucchFormat)
2649       {
2650          case PUCCH_FORMAT_0:
2651          {
2652             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format0, sizeof(PucchFormat0));
2653             break;
2654          }
2655          case PUCCH_FORMAT_1:
2656          {
2657             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format1, sizeof(PucchFormat1));
2658             break;
2659          }
2660          case PUCCH_FORMAT_2:
2661          {
2662             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
2663             break;
2664          }
2665          case PUCCH_FORMAT_3:
2666          {
2667             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
2668             break;
2669          }
2670          case PUCCH_FORMAT_4:
2671          {
2672             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format4, sizeof(PucchFormat4));
2673             break;
2674          }
2675       }
2676    }
2677
2678 }
2679
2680 /*******************************************************************
2681 *
2682 * @brief  Processes UE delete response from scheduler
2683 *
2684 * @details
2685 *
2686 *    Function : MacProcSchUeCfgRsp
2687 *
2688 *    Functionality:
2689 *      Processes UE create delete from scheduler
2690 *
2691 * @params[in] Pst : Post structure
2692 *             schUeDelRsp : Scheduler UE delete respons
2693 * @return ROK     - success
2694 *         RFAILED - failure
2695 *
2696 * ****************************************************************/
2697
2698 uint8_t MacProcSchUeDeleteRsp(Pst *pst, SchUeDeleteRsp *schUeDelRsp)
2699 {
2700    uint8_t ueIdx =0, isCrntiValid = 0;
2701    uint16_t cellIdx=0;
2702    uint8_t ret = RFAILED;
2703    UeDeleteStatus result;
2704
2705 #ifdef CALL_FLOW_DEBUG_LOG
2706    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_DELETE_RSP_TO_MAC\n");
2707 #endif   
2708
2709    if(schUeDelRsp)
2710    {
2711       if(schUeDelRsp->rsp == RSP_OK)
2712       {
2713          DU_LOG("\nINFO   -->  MAC : SCH UE Delete response for CRNTI[%d] is successful", schUeDelRsp->crnti);
2714          GET_CELL_IDX(schUeDelRsp->cellId, cellIdx);
2715          if(macCb.macCell[cellIdx])
2716          {
2717             CHECK_CRNTI(schUeDelRsp->crnti, isCrntiValid);
2718             if(!isCrntiValid)
2719             {
2720                /*C-RNTI value is out of Acceptable range*/
2721                DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): Invalid crnti[%d] ",schUeDelRsp->crnti);
2722                result = UEIDX_INVALID;
2723             }
2724             else
2725             {
2726                GET_UE_IDX(schUeDelRsp->crnti, ueIdx);
2727                if(macCb.macCell[cellIdx]->ueCb[ueIdx -1].crnti == schUeDelRsp->crnti)
2728                {
2729
2730                   /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
2731 #if 0
2732                   /*Looping around LCs to free S-NSSAI memory*/
2733                   for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueIdx -1].ulInfo.numUlLc); lcIdx++)
2734                   {
2735                      MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueIdx -1].ulInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
2736                   }
2737                   for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueIdx -1].dlInfo.numDlLc); lcIdx++)
2738                   {
2739                      MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueIdx -1].dlInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
2740                   }
2741 #endif
2742                   memset(&macCb.macCell[cellIdx]->ueCb[ueIdx -1], 0, sizeof(MacUeCb));
2743                   macCb.macCell[cellIdx]->numActvUe--;
2744                   result = SUCCESS;
2745                   ret = ROK;
2746                }
2747                else
2748                {
2749                   DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): crnti[%d] does not exist ",schUeDelRsp->crnti);
2750                   result = UEIDX_INVALID;
2751                }
2752             }
2753          }
2754          else
2755          {
2756             DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): cellId[%d] does not exist ",schUeDelRsp->cellId);
2757             result = CELLID_INVALID;
2758          }
2759       }
2760       else
2761       {
2762          result = (schUeDelRsp->cause == INVALID_CELLID) ? CELLID_INVALID : UEIDX_INVALID;
2763       }
2764       if(MacSendUeDeleteRsp(schUeDelRsp->cellId, schUeDelRsp->crnti, result) != ROK)
2765       {
2766          DU_LOG("\nERROR  -->  MAC: MacProcSchUeDeleteRsp(): Failed to send UE delete response");
2767       }
2768    }
2769    else
2770    {
2771       DU_LOG("\nERROR  -->  MAC: MacProcSchUeDeleteRsp(): Failed to receive UE delete response by SCH");
2772       ret = RFAILED;
2773    }
2774    return ret;
2775 }
2776
2777 /*******************************************************************
2778 *
2779 * @brief Sends UE delete req to Scheduler
2780 *
2781 * @details
2782 *
2783 *    Function : sendUeDelReqToSch
2784 *
2785 *    Functionality: sends UE delete req to Scheduler
2786 *
2787 * @params[in] Pst *pst,  MacUeDelete *ueDelete
2788 * @return ROK     - success
2789 *         RFAILED - failure
2790 *
2791 * ****************************************************************/
2792
2793 uint8_t sendUeDelReqToSch(Pst *pst, MacUeDelete *ueDelete)
2794 {
2795    if(ueDelete != NULLP)
2796    {
2797       Pst schPst;
2798       SchUeDelete schUeDel;
2799
2800       memset(&schUeDel, 0, sizeof(SchUeDelete));
2801       schUeDel.cellId = ueDelete->cellId;
2802       schUeDel.crnti  = ueDelete->crnti;
2803       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(MacUeDelete));
2804       FILL_PST_MAC_TO_SCH(schPst, EVENT_UE_DELETE_REQ_TO_SCH);
2805       return(*macSchUeDeleteReqOpts[schPst.selector])(&schPst, &schUeDel);
2806    }
2807    else
2808    {
2809       DU_LOG("\nERROR  --> SCH: sendUeDelReqToSch():MAC Ue Delete is NULL");
2810       return RFAILED;
2811    }
2812    return ROK;
2813 }
2814
2815 /*******************************************************************
2816  *
2817  * @brief Handles UE Delete requst from DU APP
2818  *
2819  * @details
2820  *
2821  *    Function : MacProcUeDeleteReq
2822  *
2823  *    Functionality: Handles UE Delete requst from DU APP
2824  *
2825  * @params[in] Pst *pst, MacUeDelete *ueDelete
2826  * @return ROK     - success
2827  *         RFAILED - failure
2828  *
2829  * ****************************************************************/
2830
2831 uint8_t MacProcUeDeleteReq(Pst *pst, MacUeDelete *ueDelete)
2832 {
2833    uint8_t ret = ROK;
2834    uint8_t cellIdx=0;
2835    UeDeleteStatus result=SUCCESS;
2836    MacUeCb  *ueCb = NULLP;
2837    MacCellCb *cellCb = NULLP;
2838
2839    DU_LOG("\nINFO   -->  MAC : UE Delete Request received for ueId[%d]", ueDelete->ueId);
2840
2841    if(ueDelete)
2842    {
2843       GET_CELL_IDX(ueDelete->cellId, cellIdx);     
2844       cellCb = macCb.macCell[cellIdx];
2845       if(cellCb)
2846       {
2847          ueCb = &cellCb->ueCb[ueDelete->ueId-1];
2848          if(ueCb->crnti == ueDelete->crnti)
2849          {
2850             ret = sendUeDelReqToSch(pst, ueDelete);
2851             if(ret != ROK)
2852             {
2853                DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to send UE Delete Request to SCH");
2854                ret = RFAILED;
2855             }
2856          }
2857          else
2858          {
2859             DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): CRNTI is not matched");
2860             result = UEIDX_INVALID;
2861          }
2862       }
2863       else
2864       {
2865          DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to find the MacUeCb of UeIdx = %d",ueDelete->ueId);
2866          result = CELLID_INVALID;
2867       }
2868
2869       if(result != SUCCESS)
2870       {
2871          MacSendUeDeleteRsp(ueDelete->cellId, ueDelete->crnti, result);
2872          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(MacUeDelete));
2873          ret = RFAILED;
2874       }
2875    }
2876    else
2877    {
2878       DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): MAC UE delete request processing failed");
2879       ret = RFAILED;
2880    }
2881    return ret;
2882 }
2883
2884 /**********************************************************************
2885   End of file
2886  **********************************************************************/