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