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