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