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