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