Revert "[Epic-ID: ODUHIGH-462][Task-ID: ODUHIGH-472] Implementation of drx timer"
[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
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    return ret;
1714 }
1715
1716 /*******************************************************************
1717  *
1718  * @brief Update UeUlCb Lc List
1719  *
1720  * @details
1721  *
1722  *    Function : updateMacUlCb
1723  *
1724  *    Functionality: Update UeUlCb Lc List
1725  *
1726  * @params[in] delIdx, UeUlCb pointer
1727  * @return void
1728  *
1729  * ****************************************************************/
1730
1731 void updateMacUlCb(uint8_t delIdx, UeUlCb *ulCb)
1732 {
1733    uint8_t lcIdx = 0;
1734
1735    for(lcIdx = delIdx; lcIdx < ulCb->numUlLc; lcIdx++)
1736    {
1737       /* Moving the array element to one step ahead */
1738       memcpy(&ulCb->lcCb[lcIdx], &ulCb->lcCb[lcIdx+1], sizeof(UlLcCb));
1739       memset(&ulCb->lcCb[lcIdx+1], 0, sizeof(UlLcCb));
1740    }
1741    /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1742 #if 0
1743    /*Checking the Memory Leakage of Last Index*/
1744    if(ulCb->lcCb[ulCb->numUlLc].snssai != NULLP)
1745    {
1746       DU_LOG("ERROR  --> MAC: updateMacUlCb Last index deleted :%d  memory is leaking",\
1747             ulCb->numUlLc);
1748       MAC_FREE(ulCb->lcCb[ulCb->numUlLc].snssai, sizeof(Snssai));
1749    }
1750    else
1751    {
1752       DU_LOG("INFO  --> MAC: updateMacUlCb Last index:%d (before deletion) memory is freed successfully",\
1753             ulCb->numUlLc);
1754    }
1755 #endif
1756 }
1757
1758 /*******************************************************************
1759  *
1760  * @brief Update UeDlCb Lc List
1761  *
1762  * @details
1763  *
1764  *    Function : updateMacDlCb
1765  *
1766  *    Functionality: Update UeDlCb Lc List
1767  *
1768  * @params[in] delIdx, UeDlCb pointer
1769  * @return void
1770  *
1771  * ****************************************************************/
1772
1773 void updateMacDlCb(uint8_t delIdx, UeDlCb *dlCb)
1774 {
1775    uint8_t lcIdx = 0;
1776
1777    for(lcIdx = delIdx; lcIdx < dlCb->numDlLc; lcIdx++)
1778    {
1779       /* Moving the array element to one step ahead */
1780       memcpy(&dlCb->lcCb[lcIdx], &dlCb->lcCb[lcIdx+1], sizeof(DlLcCb));
1781       memset(&dlCb->lcCb[lcIdx+1], 0, sizeof(DlLcCb));
1782    }
1783    /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1784 #if 0
1785    /*Checking the Memory Leakage of Last Index*/
1786    if(dlCb->lcCb[dlCb->numDlLc].snssai != NULLP)
1787    {
1788       DU_LOG("ERROR  --> MAC: updateMacDlCb Last Deleted index:%d memory is leaking",\
1789             dlCb->numDlLc);
1790       MAC_FREE(dlCb->lcCb[dlCb->numDlLc].snssai, sizeof(Snssai));
1791    }
1792    else
1793    {
1794       DU_LOG("INFO  --> MAC: updateMacDlCb Last index:%d (before deletion) memory is freed successfully",\
1795             dlCb->numDlLc);
1796    }
1797 #endif
1798 }
1799
1800 /*******************************************************************
1801  *
1802  * @brief Update Mac UL Lc List based on CONFIG_MOD/CONFIG_DEL
1803  *
1804  * @details
1805  *
1806  *    Function : updateMacUlLcCtxt
1807  *
1808  *    Functionality: Update UeUlCb Lc List
1809  *
1810  * @params[in]  UeUlCb pointer, ueLcCfg(received from DUAPP)
1811  * @return void
1812  *
1813  * ****************************************************************/
1814 void updateMacUlLcCtxt(UeUlCb *ulInfo, LcCfg *ueLcCfg)
1815 {
1816    uint8_t ueLcIdx = 0; 
1817
1818    /*Traversing UL LC to be updated/Deleted*/
1819    for(ueLcIdx = 0; ueLcIdx < ulInfo->numUlLc; ueLcIdx++)
1820    {
1821       if(ulInfo->lcCb[ueLcIdx].lcId == ueLcCfg->lcId)
1822       {
1823          if(ueLcCfg->configType == CONFIG_MOD)
1824          {
1825             /*Modify UL LC CB */
1826             ulInfo->lcCb[ueLcIdx].lcGrpId = ueLcCfg->ulLcCfg.lcGroup;
1827
1828             /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1829 #if 0
1830             /*Modifying/Copying PduSession ID and S-NSSAI into MAC's UECB*/
1831             if(ueLcCfg->drbQos)
1832             {
1833                ulInfo->lcCb[ueLcIdx].pduSessionId = ueLcCfg->drbQos->pduSessionId;
1834             }
1835             if(ueLcCfg->snssai)
1836             {
1837                if(ulInfo->lcCb[ueLcIdx].snssai == NULLP)
1838                {
1839                   MAC_ALLOC(ulInfo->lcCb[ueLcIdx].snssai, sizeof(Snssai));
1840                }
1841
1842                memcpy(ulInfo->lcCb[ueLcIdx].snssai, ueLcCfg->snssai, sizeof(Snssai));
1843             }
1844 #endif
1845             DU_LOG("\nINFO  -->  MAC: Successfully Modified LC context for lcId[%d], ueLcIdx:%d",\
1846                   ueLcCfg->lcId,ueLcIdx);
1847             break;
1848          }
1849          if(ueLcCfg->configType == CONFIG_DEL)
1850          {
1851             memset(&ulInfo->lcCb[ueLcIdx], 0, sizeof(UlLcCb));
1852             (ulInfo->numUlLc)--;
1853             updateMacUlCb(ueLcIdx, ulInfo);
1854             DU_LOG("\nINFO  -->  MAC: Successfully Deleted LC context for lcId[%d]", ueLcCfg->lcId);
1855             break;
1856          }
1857       }
1858    }
1859 }
1860
1861 /*******************************************************************
1862  *
1863  * @brief Update Mac DL Lc List based on CONFIG_MOD/CONFIG_DEL
1864  *
1865  * @details
1866  *
1867  *    Function : updateMacDlLcCtxt
1868  *
1869  *    Functionality: Update UeDlCb Lc List
1870  *
1871  * @params[in]  UeDlCb pointer, ueLcCfg(received from DUAPP)
1872  * @return void
1873  *
1874  * ****************************************************************/
1875 void updateMacDlLcCtxt(UeDlCb *dlInfo, LcCfg *ueLcCfg)
1876 {
1877    uint8_t ueLcIdx = 0; 
1878
1879    /*Traversing DL LC to be updated/Deleted*/
1880    for(ueLcIdx = 0; ueLcIdx < dlInfo->numDlLc; ueLcIdx++)
1881    {
1882       if(dlInfo->lcCb[ueLcIdx].lcId == ueLcCfg->lcId)
1883       {
1884          if(ueLcCfg->configType == CONFIG_MOD)
1885          {
1886             /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1887 #if 0
1888             /*Modifying/Copying PduSession ID and S-NSSAI into MAC's UECB*/
1889             if(ueLcCfg->drbQos)
1890             {
1891                dlInfo->lcCb[ueLcIdx].pduSessionId = ueLcCfg->drbQos->pduSessionId;
1892             }
1893             if(ueLcCfg->snssai)
1894             {
1895                if(dlInfo->lcCb[ueLcIdx].snssai == NULLP)
1896                {
1897                   MAC_ALLOC(dlInfo->lcCb[ueLcIdx].snssai, sizeof(Snssai));
1898                }
1899
1900                memcpy(dlInfo->lcCb[ueLcIdx].snssai, ueLcCfg->snssai, sizeof(Snssai));
1901             }
1902 #endif
1903             DU_LOG("\nINFO  -->  MAC: Successfully Modified LC context for lcId[%d], ueLcIdx:%d",\
1904                   ueLcCfg->lcId,ueLcIdx);
1905             break;
1906          }
1907          if(ueLcCfg->configType == CONFIG_DEL)
1908          {
1909             memset(&dlInfo->lcCb[ueLcIdx], 0, sizeof(DlLcCb));
1910             (dlInfo->numDlLc)--;
1911             updateMacDlCb(ueLcIdx, dlInfo);
1912             DU_LOG("\nINFO  -->  MAC: Successfully Deleted LC context for lcId[%d]", ueLcCfg->lcId);
1913             break;
1914          }
1915       }
1916    }
1917 }
1918 /*******************************************************************
1919  *
1920  * @brief Fills Logical channel Cfg List to Add/Mod/Del
1921  *
1922  * @details
1923  *
1924  *    Function : fillMacLcCfgList
1925  *
1926  *    Functionality: Fills Logical channel Cfg List to Add/Mod/Del
1927  *
1928  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
1929  * @return ROK     - success
1930  *         RFAILED - failure
1931  *
1932  * ****************************************************************/
1933
1934 uint8_t fillMacLcCfgList(MacUeCb *ueCb, MacUeCfg *ueCfg)
1935 {
1936    uint8_t lcIdx = 0;
1937
1938    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
1939    {
1940       if(ueCb->dlInfo.numDlLc < MAX_NUM_LC)
1941       {
1942          if(ueCfg->lcCfgList[lcIdx].configType == CONFIG_ADD)
1943          {
1944             /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
1945 #if 0
1946             /*Copying PduSession ID and S-NSSAI into MAC's UECB*/
1947             if(ueCfg->lcCfgList[lcIdx].drbQos)
1948             {
1949                ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].pduSessionId = \
1950                                                                       ueCfg->lcCfgList[lcIdx].drbQos->pduSessionId;
1951
1952                ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].pduSessionId = \
1953                                                                       ueCfg->lcCfgList[lcIdx].drbQos->pduSessionId;
1954             }
1955             if(ueCfg->lcCfgList[lcIdx].snssai)
1956             {
1957                if(ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].snssai == NULLP)
1958                {
1959                   MAC_ALLOC(ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].snssai, sizeof(Snssai));
1960                }
1961                if(ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].snssai == NULLP)
1962                {
1963                   MAC_ALLOC(ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].snssai, sizeof(Snssai));
1964                }
1965
1966                memcpy(ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].snssai, \
1967                      ueCfg->lcCfgList[lcIdx].snssai, sizeof(Snssai));
1968
1969                memcpy(ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].snssai, \
1970                      ueCfg->lcCfgList[lcIdx].snssai, sizeof(Snssai));
1971
1972             }
1973 #endif
1974             /*Filling DL LC CB */
1975             ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcId = ueCfg->lcCfgList[lcIdx].lcId;
1976             ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcState = MAC_LC_STATE_ACTIVE;
1977             ueCb->dlInfo.numDlLc++;
1978             /*Filling UL LC CB */
1979             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcId = ueCfg->lcCfgList[lcIdx].lcId;
1980             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcGrpId = ueCfg->lcCfgList[lcIdx].ulLcCfg.lcGroup;
1981             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcActive = MAC_LC_STATE_ACTIVE;
1982             ueCb->ulInfo.numUlLc++;
1983          }/*End of Add Config */
1984          else
1985          {
1986             updateMacUlLcCtxt(&ueCb->ulInfo, &ueCfg->lcCfgList[lcIdx]);            
1987             updateMacDlLcCtxt(&ueCb->dlInfo, &ueCfg->lcCfgList[lcIdx]);            
1988          }/*End of Mod Config */
1989       }
1990    }
1991    return ROK;
1992 }
1993
1994 /*******************************************************************
1995  *
1996  * @brief Fills MAC UE Cb Cfg
1997  *
1998  * @details
1999  *
2000  *    Function : fillMacUeCb
2001  *
2002  *    Functionality: Fills MAC UE Cb Cfg
2003  *
2004  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
2005  *             cellIdx
2006  * @return ROK     - success
2007  *         RFAILED - failure
2008  *
2009  * ****************************************************************/
2010
2011 uint8_t fillMacUeCb(MacUeCb *ueCb, MacUeCfg *ueCfg, uint8_t cellIdx)
2012 {
2013    uint8_t ret = ROK;
2014
2015    ueCb->ueId = ueCfg->ueId;
2016    ueCb->crnti = ueCfg->crnti;
2017    ueCb->cellCb = macCb.macCell[cellIdx];
2018    if(ueCfg->spCellCfgPres)
2019    {
2020       ueCb->dlInfo.dlHarqEnt.numHarqProcs = \
2021       ueCfg->spCellCfg.servCellCfg.pdschServCellCfg.numHarqProcForPdsch; 
2022    }
2023
2024    /*TODO: To check the bsr value during implementation */
2025    if(ueCfg->macCellGrpCfgPres)
2026    {
2027       ueCb->bsrTmrCfg.periodicTimer = ueCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer;
2028       ueCb->bsrTmrCfg.retxTimer     = ueCfg->macCellGrpCfg.bsrTmrCfg.retxTimer;
2029       ueCb->bsrTmrCfg.srDelayTimer  = ueCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer;
2030    }
2031    ret = fillMacLcCfgList(ueCb, ueCfg);
2032    if(ret == RFAILED)
2033    {
2034       DU_LOG("\nERROR  -->  MAC: Failed while filing MAC LC List at fillMacUeCb()");
2035    }
2036    ueCb->transmissionAction = ueCfg->transmissionAction;
2037
2038    return ret;
2039 }
2040
2041 /*******************************************************************
2042  *
2043  * @brief Function to update Mac Ra Cb
2044  *
2045  * @details
2046  *
2047  *    Function : updateMacRaCb
2048  *
2049  *    Functionality: Function to update Mac Ra Cb
2050  *
2051  * @params[in] cellIdx, Mac Ue Cb
2052  * @return ROK     - success
2053  *         RFAILED - failure
2054  *
2055  * ****************************************************************/
2056
2057 uint8_t updateMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
2058 {
2059    /* Copy RA Cb */
2060    if(macCb.macCell[cellIdx]->macRaCb[ueCb->ueId-1].crnti == ueCb->crnti)
2061    {
2062       ueCb->raCb = &macCb.macCell[cellIdx]->macRaCb[ueCb->ueId-1];
2063    }
2064    else
2065    {
2066       DU_LOG("\nERROR  -->  MAC : No RA CB found for UE ID [%d]", ueCb->ueId);
2067       return RFAILED;
2068    }
2069    return ROK;
2070 }
2071
2072 /*******************************************************************
2073  *
2074  * @brief Function to delete Mac Ra Cb
2075  *
2076  * @details
2077  *
2078  *    Function : deleteMacRaCb
2079  *
2080  *    Functionality: Function to delete Mac Ra Cb
2081  *
2082  * @params[in] cellIdx, Mac Ue Cb
2083  * @return void
2084  *
2085  * ****************************************************************/
2086
2087 void deleteMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
2088 {
2089    uint8_t tbIdx;
2090    MacRaCbInfo *raCb = ueCb->raCb;
2091    DlHarqProcCb *hqProcCb;
2092
2093    if(raCb && (raCb->crnti == ueCb->crnti))
2094    {
2095       hqProcCb = &raCb->msg4HqInfo;
2096       MAC_FREE(raCb->msg4Pdu, raCb->msg4PduLen);
2097       for(tbIdx = 0; tbIdx < raCb->msg4HqInfo.numTb; tbIdx++)
2098       {
2099          MAC_FREE(raCb->msg4HqInfo.tbInfo[tbIdx].tb, \
2100                raCb->msg4HqInfo.tbInfo[tbIdx].tbSize - TX_PAYLOAD_HDR_LEN);
2101       }
2102       memset(raCb, 0, sizeof(MacRaCbInfo));
2103    }
2104 }
2105
2106 /*******************************************************************
2107  *
2108  * @brief Creates UE Cb
2109  *
2110  * @details
2111  *
2112  *    Function : createUeCb
2113  *
2114  *    Functionality: Creates UE Cb
2115  *
2116  * @params[in] MAC UE Configuration
2117  * @return ROK     - success
2118  *         RFAILED - failure
2119  *
2120  * ****************************************************************/
2121 uint8_t createUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
2122 {
2123    uint8_t ret = ROK;
2124    uint8_t hqProcIdx = 0;
2125
2126    if((ueCb->ueId == ueCfg->ueId) && (ueCb->crnti == ueCfg->crnti)\
2127       &&(ueCb->state == UE_STATE_ACTIVE))
2128    {
2129       DU_LOG("\nERROR  -->  MAC : CRNTI %d already configured ", ueCfg->crnti);
2130       return ROKDUP;
2131    }
2132    else
2133    {
2134       memset(ueCb, 0, sizeof(MacUeCb));
2135       ret = fillMacUeCb(ueCb, ueCfg, cellIdx);
2136       if(ret != ROK)
2137       {
2138          DU_LOG("\nERROR  -->  MAC : Failed to create Ue Cb at createUeCb()");
2139          return ret;
2140       }
2141       else
2142       {
2143          /* Initialize all DL HARQ PROC ID to MAX NUM OF HARQ PROC */
2144          for(hqProcIdx = 0; hqProcIdx <  MAX_NUM_HARQ_PROC; hqProcIdx++)
2145          {
2146             ueCb->dlInfo.dlHarqEnt.harqProcCb[hqProcIdx].procId = MAX_NUM_HARQ_PROC;
2147          }
2148
2149          /* If UE has not requested for RACH yet, it means UE context is created for a
2150           * UE in handover */
2151          if(macCb.macCell[cellIdx]->macRaCb[ueCb->ueId-1].crnti == ueCb->crnti)
2152          {
2153             ueCb->state = UE_STATE_ACTIVE;
2154             macCb.macCell[cellIdx]->numActvUe++;
2155             updateMacRaCb(cellIdx, ueCb);
2156          }
2157          else
2158             ueCb->state = UE_HANDIN_IN_PROGRESS;
2159
2160          return ROK;
2161       }
2162    }
2163    return ROK;
2164 }
2165
2166 /*******************************************************************
2167  *
2168  * @brief Modify UE Cb Cfg
2169  *
2170  * @details
2171  *
2172  *    Function : modifyUeCb
2173  *
2174  *    Functionality: modify UE Cb
2175  *
2176  * @params[in] MAC UE Configuration
2177  * @return ROK     - success
2178  *         RFAILED - failure
2179  *
2180  * ****************************************************************/
2181 uint8_t modifyUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
2182 {
2183    uint8_t ret = ROK;
2184
2185    if((ueCb->ueId == ueCfg->ueId) && (ueCb->crnti == ueCfg->crnti)\
2186          &&(ueCb->state == UE_STATE_ACTIVE))
2187    {
2188       DU_LOG("\nINFO  -->  MAC : Modifying Ue config Req for CRNTI %d ", ueCfg->crnti);
2189       ret = fillMacUeCb(ueCb, ueCfg, cellIdx);
2190       if(ret != ROK)
2191       {
2192          DU_LOG("\nERROR  -->  MAC : Failed to modify MacUeCb at modifyUeCb()");
2193          return ret;
2194       }
2195       else
2196       {
2197          return ROK;
2198       }
2199    }
2200    return RFAILED;
2201 }
2202
2203
2204 /*******************************************************************
2205  *
2206  * @brief Creates UE Cb and fills ueCfg
2207  *
2208  * @details
2209  *
2210  *    Function : procMacUeCfgData
2211  *
2212  *    Functionality: Creates UE Cb and fills ueCfg
2213  *
2214  * @params[in] MAC UE Configuration
2215  * @return ROK     - success
2216  *         RFAILED - failure
2217  *
2218  * ****************************************************************/
2219
2220 uint8_t procMacUeCfgData(Pst *pst, MacUeCfg *ueCfg)
2221 {
2222    uint8_t ret = ROK;
2223    uint16_t  cellIdx;
2224    MacUeCb   *ueCb = NULLP;
2225
2226
2227    GET_CELL_IDX(ueCfg->cellId, cellIdx);
2228
2229    /* Validate cell id */
2230    if(macCb.macCell[cellIdx]->cellId != ueCfg->cellId)
2231    {
2232       DU_LOG("\nERROR  -->  MAC : Cell Id %d not configured", ueCfg->cellId);
2233       return RFAILED;
2234    }
2235
2236    /* Check if max number of UE configured */
2237    if(macCb.macCell[cellIdx]->numActvUe > MAX_NUM_UE)
2238    {
2239       DU_LOG("\nERROR  -->  MAC : Max number of UE [%d] already configured", MAX_NUM_UE);
2240       return RFAILED;
2241    }
2242
2243    /* Check if UE already configured */
2244    ueCb = &macCb.macCell[cellIdx]->ueCb[ueCfg->ueId -1];
2245
2246    switch(pst->event)
2247    {
2248       case EVENT_UE_CONFIG_RSP_TO_MAC:
2249          {
2250             ret = createUeCb(cellIdx, ueCb, ueCfg);
2251             if(ret != ROK)
2252                DU_LOG("\nERROR  -->  MAC: AddUeConfigReq for cellIdx :%d failed in procMacUeCfgData()", cellIdx);
2253             break;
2254          }
2255
2256       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2257          {
2258             ret = modifyUeCb(cellIdx, ueCb, ueCfg);
2259             if(ret != ROK)
2260                DU_LOG("\nERROR  -->  MAC: ModifyUeConfigReq for cellIdx :%d failed at procMacUeCfgData()", cellIdx);
2261             break;
2262          }
2263
2264       default:
2265          break;
2266    }
2267
2268    return ret;
2269 }
2270
2271 /*******************************************************************
2272  *
2273  * @brief Function to store the UeCfg Data 
2274  *
2275  * @details
2276  *
2277  *    Function : copyToTmpData
2278  *
2279  *    Functionality: Function to store the UeCfg Data
2280  *
2281  * @params[in] MacUeCfg pointer 
2282  * @return ROK     - success
2283  *         RFAILED - failure
2284  *
2285  * ****************************************************************/
2286
2287 uint8_t copyToTmpData(MacUeCfg *ueCfg)
2288 {
2289    uint8_t cellIdx;
2290    MacUeCfg *tmpData = NULLP;
2291
2292    MAC_ALLOC(tmpData, sizeof(MacUeCfg));
2293    if(!tmpData)
2294    {
2295       DU_LOG("\nERROR  -->  MAC: Memory Alloc Failed at copyToTmpData()");
2296       return RFAILED;
2297    }
2298    memcpy(tmpData, ueCfg, sizeof(MacUeCfg));
2299    GET_CELL_IDX(ueCfg->cellId, cellIdx);
2300    macCb.macCell[cellIdx]->ueCfgTmpData[ueCfg->ueId-1] = tmpData;
2301    return ROK;
2302 }
2303
2304 /*******************************************************************
2305  *
2306  * @brief Handles UE create requst from DU APP
2307  *
2308  * @details
2309  *
2310  *    Function : MacProcUeCreateReq
2311  *
2312  *    Functionality: Handles UE create requst from DU APP
2313  *
2314  * @params[in] 
2315  * @return ROK     - success
2316  *         RFAILED - failure
2317  *
2318  * ****************************************************************/
2319 uint8_t MacProcUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
2320 {
2321    uint8_t ret = ROK;
2322    SchUeCfg   schUeCfg;
2323    memset(&schUeCfg, 0, sizeof(SchUeCfg));
2324
2325    DU_LOG("\nINFO  -->  MAC : UE Create Request for CRNTI[%d]", ueCfg->crnti);
2326
2327    if(ueCfg)
2328    {
2329       /* If CRNTI = 0, MAC must allot a CRNTI to this UE. This scenario hits in
2330        * case of UE in handover */
2331       if(ueCfg->crnti == 0)
2332       {
2333          GET_CRNTI(ueCfg->crnti, ueCfg->ueId);
2334       }
2335
2336       /*Storing received ueCfg in ueCfgTmpData */
2337       ret = copyToTmpData(ueCfg);
2338       if(ret == ROK)
2339       {
2340          /*Sending Cfg Req to SCH */
2341          ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
2342          if(ret != ROK)
2343             DU_LOG("\nERROR  -->  MAC : Failed to fill Sch Ue Cfg at MacProcUeCreateReq()");
2344          else
2345          {
2346             /* Fill event and send UE create request to SCH */
2347             ret = sendUeReqToSch(pst, &schUeCfg);
2348             if(ret != ROK)
2349                DU_LOG("\nERROR  -->  MAC : Failed to send UE Create request to SCH");
2350          }
2351       }
2352       else 
2353       {
2354          DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE CFG ");
2355       }
2356    }
2357    else
2358    {
2359       DU_LOG("\nERROR  -->  MAC : MAC UE Create request processing failed");
2360       ret = RFAILED;
2361    }
2362    /* FREE shared memory */
2363    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
2364
2365    return ret;
2366 }
2367
2368 /*******************************************************************
2369  *
2370  * @brief Fill and Send UE create response from MAC to DU APP
2371  *
2372  * @details
2373  *
2374  *    Function : MacSendUeCreateRsp
2375  *
2376  *    Functionality: Fill and Send UE create response from MAC to DUAPP
2377  *
2378  * @params[in] MAC UE create result
2379  *             SCH UE create response
2380  * @return ROK     - success
2381  *         RFAILED - failure
2382  *
2383  * ****************************************************************/
2384 uint8_t MacSendUeCreateRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
2385 {
2386    MacUeCfgRsp   *cfgRsp;
2387    Pst        rspPst;
2388
2389    MAC_ALLOC_SHRABL_BUF(cfgRsp, sizeof(MacUeCfgRsp));
2390    if(!cfgRsp)
2391    {
2392       DU_LOG("\nERROR  -->  MAC: Memory allocation for UE config response failed");
2393       return RFAILED;
2394    }
2395
2396    /* Filling UE Config response */
2397    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
2398    cfgRsp->cellId = schCfgRsp->cellId;
2399    cfgRsp->ueId = schCfgRsp->ueId;
2400    cfgRsp->result = result;
2401
2402    /* Fill Post structure and send UE Create response*/
2403    memset(&rspPst, 0, sizeof(Pst));
2404    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_CREATE_RSP);
2405    return (*macDuUeCfgRspOpts[rspPst.selector])(&rspPst, cfgRsp); 
2406 }
2407
2408 /*******************************************************************
2409  *
2410  * @brief Fill and Send UE Reconfig response from MAC to DU APP
2411  *
2412  * @details
2413  *
2414  *    Function : MacSendUeReconfigRsp
2415  *
2416  *    Functionality: Fill and Send UE Reconfig response from MAC to DUAPP
2417  *
2418  * @params[in] MAC UE create result
2419  *             SCH UE create response
2420  * @return ROK     - success
2421  *         RFAILED - failure
2422  *
2423  * ****************************************************************/
2424 uint8_t MacSendUeReconfigRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
2425 {
2426    MacUeCfgRsp   *cfgRsp;
2427    Pst        rspPst;
2428
2429    MAC_ALLOC_SHRABL_BUF(cfgRsp, sizeof(MacUeCfgRsp));
2430    if(!cfgRsp)
2431    {
2432       DU_LOG("\nERROR  -->  MAC: Memory allocation for UE Reconfig response failed");
2433       return RFAILED;
2434    }
2435
2436    /* Filling UE Config response */
2437    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
2438    cfgRsp->cellId = schCfgRsp->cellId;
2439    cfgRsp->ueId = schCfgRsp->ueId;
2440    cfgRsp->result = result;
2441
2442    /* Fill Post structure and send UE Create response*/
2443    memset(&rspPst, 0, sizeof(Pst));
2444    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_RECONFIG_RSP);
2445    return (*macDuUeCfgRspOpts[rspPst.selector])(&rspPst, cfgRsp);
2446 }
2447
2448 /*******************************************************************
2449  *
2450  * @brief  Function to return Mac Ue Cfg pointer
2451  *
2452  * @details
2453  *
2454  *    Function : getMacUeCfg
2455  *
2456  *    Functionality:
2457  *      Function to return Mac Ue Cfg pointer
2458  *
2459  * @params[in] cellIdx, ueId
2460  *
2461  * @return MacUeCfg pointer - success
2462  *         NULLP - failure
2463  *
2464  * ****************************************************************/
2465
2466 MacUeCfg *getMacUeCfg(uint16_t cellIdx, uint8_t ueId)
2467 {
2468    MacUeCfg *ueCfg = NULLP;
2469    if(macCb.macCell[cellIdx])
2470    {
2471       ueCfg = macCb.macCell[cellIdx]->ueCfgTmpData[ueId-1];
2472    }
2473    else
2474    {
2475       DU_LOG("\nERROR  -->  MAC: Failed to get macCellCb in getMacUeCfg()");
2476    }
2477    return ueCfg;
2478 }
2479
2480 /*******************************************************************
2481  *
2482  * @brief  Processes UE create response from scheduler
2483  *
2484  * @details
2485  *
2486  *    Function : MacProcSchUeCfgRsp
2487  *
2488  *    Functionality:
2489  *      Processes UE create response from scheduler
2490  *      Sends UE create response to DU APP
2491  *
2492  * @params[in] Pst : Post structure
2493  *             schCfgRsp : Scheduler UE cfg response
2494  * @return ROK     - success
2495  *         RFAILED - failure
2496  *
2497  * ****************************************************************/
2498 uint8_t MacProcSchUeCfgRsp(Pst *pst, SchUeCfgRsp *schCfgRsp)
2499 {
2500    uint8_t result = MAC_DU_APP_RSP_NOK;
2501    uint8_t ret = ROK;
2502    uint16_t cellIdx;
2503    MacUeCfg *ueCfg = NULLP;
2504
2505 #ifdef CALL_FLOW_DEBUG_LOG
2506    switch(pst->event)
2507    {
2508       case EVENT_UE_CONFIG_RSP_TO_MAC:
2509          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_CONFIG_RSP_TO_MAC\n");
2510          break;
2511       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2512          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_RECONFIG_RSP_TO_MAC\n");
2513          break;
2514       default:
2515          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : Invalid Event\n");
2516          break;
2517    }
2518 #endif
2519    
2520    GET_CELL_IDX(schCfgRsp->cellId, cellIdx);
2521    ueCfg = getMacUeCfg(cellIdx, schCfgRsp->ueId);
2522    if(ueCfg == NULLP)
2523    {
2524       DU_LOG("\nERROR  -->  MAC : Failed to find the Mac Ue Cfg for event [%d] in MacProcSchUeCfgRsp()", pst->event);
2525       ret = RFAILED;
2526    }
2527
2528    switch(pst->event)
2529    {
2530       case EVENT_UE_CONFIG_RSP_TO_MAC:
2531          {
2532             if(schCfgRsp->rsp != RSP_NOK)
2533             {
2534                DU_LOG("\nINFO  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2535                if(ret == ROK)
2536                {
2537                   ret = procMacUeCfgData(pst, ueCfg);
2538                   if(ret == ROK)
2539                   {
2540                      result = MAC_DU_APP_RSP_OK;
2541                   }
2542                }
2543             }
2544             else
2545             {
2546                DU_LOG("\nERROR  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2547             }
2548             ret = MacSendUeCreateRsp(result, schCfgRsp);
2549          }
2550          break;
2551
2552       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2553          {
2554
2555             if(schCfgRsp->rsp != RSP_NOK)
2556             {
2557                DU_LOG("\nINFO  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()",\
2558                      schCfgRsp->crnti);
2559                if(ret == ROK)
2560                {
2561                   ret = procMacUeCfgData(pst, ueCfg);
2562                   if(ret == ROK)
2563                   {
2564                      result = MAC_DU_APP_RSP_OK;
2565                   }
2566                }
2567             }
2568             else
2569             {
2570                DU_LOG("\nERROR  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()",\
2571                schCfgRsp->crnti);
2572             }
2573             ret = MacSendUeReconfigRsp(result, schCfgRsp);
2574          }
2575          break;
2576    }
2577    MAC_FREE(ueCfg, sizeof(MacUeCfg));
2578    ueCfg = NULLP;
2579    return ret; 
2580 }
2581
2582 /*******************************************************************
2583  *
2584  * @brief Handles UE Reconfig requst from DU APP
2585  *
2586  * @details
2587  *
2588  *    Function : MacProcUeReconfigReq
2589  *
2590  *    Functionality: Handles UE Reconfig requst from DU APP
2591  *
2592  * @params[in] 
2593  * @return ROK     - success
2594  *         RFAILED - failure
2595  *
2596  * ****************************************************************/
2597 uint8_t MacProcUeReconfigReq(Pst *pst, MacUeCfg *ueCfg)
2598 {
2599    uint8_t ret = ROK;
2600    SchUeCfg   schUeCfg;
2601    memset(&schUeCfg, 0, sizeof(SchUeCfg));
2602
2603    DU_LOG("\nINFO  -->  MAC : UE Reconfig Request for CRNTI[%d]", ueCfg->crnti);
2604
2605    if(ueCfg)
2606    {
2607       /*Storing received ueCfg in ueCfgTmpData */
2608       ret = copyToTmpData(ueCfg);
2609       if(ret == ROK)
2610       {
2611          /*Sending Cfg Req to SCH */
2612          ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
2613          if(ret != ROK)
2614             DU_LOG("\nERROR  -->  MAC : Failed to fill sch Ue Cfg at MacProcUeReconfigReq()");
2615          else
2616          {
2617             /* Fill event and send UE create request to SCH */
2618             ret = sendUeReqToSch(pst, &schUeCfg);
2619             if(ret != ROK)
2620                DU_LOG("\nERROR  -->  MAC : Failed to send UE Reconfig Request to SCH");
2621          }
2622       }
2623       else 
2624       {
2625          DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE Cb ");
2626       }
2627    }
2628    else
2629    {
2630       DU_LOG("\nERROR  -->  MAC : MAC UE Create request processing failed");
2631       ret = RFAILED;
2632    }
2633    /* FREE shared memory */
2634    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
2635    return ROK;
2636 }
2637
2638 /*******************************************************************
2639 *
2640 * @brief Fill and Send UE Delete response from MAC to DU APP
2641 *
2642 * @details
2643 *
2644 *    Function : MacSendUeDeleteRsp 
2645 *
2646 *    Functionality: Fill and Send UE Delete response from MAC to DUAPP
2647 *
2648 * @params[in] MAC UE delete result
2649 *             SCH UE delete response
2650 * @return ROK     - success
2651 *         RFAILED - failure
2652 *
2653 * ****************************************************************/
2654
2655 uint8_t MacSendUeDeleteRsp(uint16_t cellId, uint16_t crnti, UeDeleteStatus result)
2656 {
2657    MacUeDeleteRsp *deleteRsp;
2658    Pst            rspPst;
2659
2660    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacUeDeleteRsp));
2661    if(!deleteRsp)
2662    {
2663       DU_LOG("\nERROR  -->  MAC : Memory allocation for UE delete response failed");
2664       return RFAILED;
2665    }
2666
2667    /* Filling UE delete response */
2668    deleteRsp->cellId = cellId;
2669    GET_UE_ID(crnti, deleteRsp->ueId);
2670    deleteRsp->result = result;
2671
2672    /* Fill Post structure and send UE delete response*/
2673    memset(&rspPst, 0, sizeof(Pst));
2674    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_DELETE_RSP);
2675    return (*macDuUeDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
2676 }
2677
2678 /*******************************************************************
2679 *
2680 * @brief freeing the Pucch Resrc Cfg 
2681 *
2682 * @details
2683 *
2684 *    Function : deletePucchResourcesCfg 
2685 *
2686 *    Functionality: freeing the Pucch Resrc Cfg
2687 *
2688 * @params[in] PucchResrcCfg *resrcCfg
2689 * @return ROK     - success
2690 *         RFAILED - failure
2691 *
2692 * ****************************************************************/
2693
2694 void deletePucchResourcesCfg(PucchResrcCfg *resrcCfg)
2695 {
2696    uint8_t resrcIdx;
2697    for(resrcIdx =0; resrcIdx< resrcCfg->resrcToAddModListCount;resrcIdx++)
2698    {
2699       switch(resrcCfg->resrcToAddModList[resrcIdx].pucchFormat)
2700       {
2701          case PUCCH_FORMAT_0:
2702          {
2703             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format0, sizeof(PucchFormat0));
2704             break;
2705          }
2706          case PUCCH_FORMAT_1:
2707          {
2708             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format1, sizeof(PucchFormat1));
2709             break;
2710          }
2711          case PUCCH_FORMAT_2:
2712          {
2713             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
2714             break;
2715          }
2716          case PUCCH_FORMAT_3:
2717          {
2718             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
2719             break;
2720          }
2721          case PUCCH_FORMAT_4:
2722          {
2723             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format4, sizeof(PucchFormat4));
2724             break;
2725          }
2726       }
2727    }
2728
2729 }
2730
2731 /*******************************************************************
2732 *
2733 * @brief  Processes UE delete response from scheduler
2734 *
2735 * @details
2736 *
2737 *    Function : MacProcSchUeDeleteRsp 
2738 *
2739 *    Functionality:
2740 *      Processes UE delete from scheduler
2741 *
2742 * @params[in] Pst : Post structure
2743 *             schUeDelRsp : Scheduler UE delete respons
2744 * @return ROK     - success
2745 *         RFAILED - failure
2746 *
2747 * ****************************************************************/
2748
2749 uint8_t MacProcSchUeDeleteRsp(Pst *pst, SchUeDeleteRsp *schUeDelRsp)
2750 {
2751    uint8_t ueId =0, isCrntiValid = 0, tbIdx =0, idx=0;
2752    uint16_t cellIdx=0;
2753    uint8_t ret = RFAILED;
2754    UeDeleteStatus result;
2755    DlHarqEnt  *dlHarqEnt;
2756
2757 #ifdef CALL_FLOW_DEBUG_LOG
2758    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_DELETE_RSP_TO_MAC\n");
2759 #endif   
2760
2761    if(schUeDelRsp)
2762    {
2763       if(schUeDelRsp->rsp == RSP_OK)
2764       {
2765          DU_LOG("\nINFO   -->  MAC : SCH UE Delete response for CRNTI[%d] is successful", schUeDelRsp->crnti);
2766          GET_CELL_IDX(schUeDelRsp->cellId, cellIdx);
2767          if(macCb.macCell[cellIdx])
2768          {
2769             CHECK_CRNTI(schUeDelRsp->crnti, isCrntiValid);
2770             if(!isCrntiValid)
2771             {
2772                /*C-RNTI value is out of Acceptable range*/
2773                DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): Invalid crnti[%d] ",schUeDelRsp->crnti);
2774                result = UEID_INVALID;
2775             }
2776             else
2777             {
2778                GET_UE_ID(schUeDelRsp->crnti, ueId);
2779                if(macCb.macCell[cellIdx]->ueCb[ueId -1].crnti == schUeDelRsp->crnti)
2780                {
2781
2782                   /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
2783 #if 0
2784                   /*Looping around LCs to free S-NSSAI memory*/
2785                   for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueId -1].ulInfo.numUlLc); lcIdx++)
2786                   {
2787                      MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueId -1].ulInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
2788                   }
2789                   for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.numDlLc); lcIdx++)
2790                   {
2791                      MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
2792                   }
2793 #endif
2794                   dlHarqEnt = &macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.dlHarqEnt;
2795                   for(idx =0 ; idx<MAX_NUM_HARQ_PROC; idx++)
2796                   {
2797                      tbIdx = 0;
2798                      while(dlHarqEnt->harqProcCb[idx].numTb)
2799                      {
2800
2801                         MAC_FREE(dlHarqEnt->harqProcCb[idx].tbInfo[tbIdx].tb, dlHarqEnt->harqProcCb[idx].tbInfo[tbIdx].tbSize);
2802                         dlHarqEnt->harqProcCb[idx].numTb--;
2803                         tbIdx++;
2804                      }
2805                   }
2806                   memset(&macCb.macCell[cellIdx]->ueCb[ueId -1], 0, sizeof(MacUeCb));
2807                   macCb.macCell[cellIdx]->numActvUe--;
2808                   result = DEL_SUCCESSFUL;
2809                   ret = ROK;
2810                }
2811                else
2812                {
2813                   DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): crnti[%d] does not exist ",schUeDelRsp->crnti);
2814                   result = UEID_INVALID;
2815                }
2816             }
2817          }
2818          else
2819          {
2820             DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): cellId[%d] does not exist ",schUeDelRsp->cellId);
2821             result = CELLID_INVALID;
2822          }
2823       }
2824       else
2825       {
2826          result = (schUeDelRsp->cause == INVALID_CELLID) ? CELLID_INVALID : UEID_INVALID;
2827       }
2828       if(MacSendUeDeleteRsp(schUeDelRsp->cellId, schUeDelRsp->crnti, result) != ROK)
2829       {
2830          DU_LOG("\nERROR  -->  MAC: MacProcSchUeDeleteRsp(): Failed to send UE delete response");
2831       }
2832    }
2833    else
2834    {
2835       DU_LOG("\nERROR  -->  MAC: MacProcSchUeDeleteRsp(): Failed to receive UE delete response by SCH");
2836       ret = RFAILED;
2837    }
2838    return ret;
2839 }
2840
2841 /*******************************************************************
2842 *
2843 * @brief Sends UE delete req to Scheduler
2844 *
2845 * @details
2846 *
2847 *    Function : sendUeDelReqToSch
2848 *
2849 *    Functionality: sends UE delete req to Scheduler
2850 *
2851 * @params[in] Pst *pst,  MacUeDelete *ueDelete
2852 * @return ROK     - success
2853 *         RFAILED - failure
2854 *
2855 * ****************************************************************/
2856
2857 uint8_t sendUeDelReqToSch(Pst *pst, MacUeDelete *ueDelete)
2858 {
2859    if(ueDelete != NULLP)
2860    {
2861       Pst schPst;
2862       SchUeDelete schUeDel;
2863
2864       memset(&schUeDel, 0, sizeof(SchUeDelete));
2865       schUeDel.cellId = ueDelete->cellId;
2866       schUeDel.crnti  = ueDelete->crnti;
2867       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(MacUeDelete));
2868       FILL_PST_MAC_TO_SCH(schPst, EVENT_UE_DELETE_REQ_TO_SCH);
2869       return(*macSchUeDeleteReqOpts[schPst.selector])(&schPst, &schUeDel);
2870    }
2871    else
2872    {
2873       DU_LOG("\nERROR  --> SCH: sendUeDelReqToSch():MAC Ue Delete is NULL");
2874       return RFAILED;
2875    }
2876    return ROK;
2877 }
2878
2879 /*******************************************************************
2880  *
2881  * @brief Handles UE Delete requst from DU APP
2882  *
2883  * @details
2884  *
2885  *    Function : MacProcUeDeleteReq
2886  *
2887  *    Functionality: Handles UE Delete requst from DU APP
2888  *
2889  * @params[in] Pst *pst, MacUeDelete *ueDelete
2890  * @return ROK     - success
2891  *         RFAILED - failure
2892  *
2893  * ****************************************************************/
2894
2895 uint8_t MacProcUeDeleteReq(Pst *pst, MacUeDelete *ueDelete)
2896 {
2897    uint8_t ret = ROK;
2898    uint8_t cellIdx=0;
2899    UeDeleteStatus result=DEL_SUCCESSFUL;
2900    MacUeCb  *ueCb = NULLP;
2901    MacCellCb *cellCb = NULLP;
2902
2903    DU_LOG("\nINFO   -->  MAC : UE Delete Request received for ueId[%d]", ueDelete->ueId);
2904
2905    if(ueDelete)
2906    {
2907       GET_CELL_IDX(ueDelete->cellId, cellIdx);     
2908       cellCb = macCb.macCell[cellIdx];
2909       if(cellCb)
2910       {
2911          ueCb = &cellCb->ueCb[ueDelete->ueId-1];
2912          if(ueCb->crnti == ueDelete->crnti)
2913          {
2914             ret = sendUeDelReqToSch(pst, ueDelete);
2915             if(ret != ROK)
2916             {
2917                DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to send UE Delete Request to SCH");
2918                ret = RFAILED;
2919             }
2920          }
2921          else
2922          {
2923             DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): CRNTI is not matched");
2924             result = UEID_INVALID;
2925          }
2926       }
2927       else
2928       {
2929          DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to find the MacUeCb of UeId = %d",ueDelete->ueId);
2930          result = CELLID_INVALID;
2931       }
2932
2933       if(result != DEL_SUCCESSFUL)
2934       {
2935          MacSendUeDeleteRsp(ueDelete->cellId, ueDelete->crnti, result);
2936          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(MacUeDelete));
2937          ret = RFAILED;
2938       }
2939    }
2940    else
2941    {
2942       DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): MAC UE delete request processing failed");
2943       ret = RFAILED;
2944    }
2945    return ret;
2946 }
2947
2948 /**********************************************************************
2949   End of file
2950  **********************************************************************/