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