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