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