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