JIRA-ID:[ODUHIGH-295]- Tunnel creation in EGTP
[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    memset(&schUeCfg->macCellGrpCfg, 0, sizeof(SchMacCellGrpCfg));
1610    if(fillMacCellGroupCfg(ueCfg->macCellGrpCfg, &schUeCfg->macCellGrpCfg) != ROK)
1611    {
1612       DU_LOG("\nERROR  -->  MAC : fillMacCellGroupCfg() failed");
1613       return RFAILED;
1614    }
1615
1616    /* Copy Physical cell group config */
1617    memset(&schUeCfg->phyCellGrpCfg, 0,sizeof(SchPhyCellGrpCfg));
1618    if(fillPhyCellGroupCfg(ueCfg->phyCellGrpCfg, &schUeCfg->phyCellGrpCfg) != ROK)
1619    {
1620       DU_LOG("\nERROR  -->  MAC : fillPhyCellGroupCfg() failed");
1621       return RFAILED;
1622    }
1623
1624    /* Copy sp cell config */
1625    memset(&schUeCfg->spCellCfg, 0, sizeof(SchSpCellCfg));
1626    if(fillSpCellCfg(ueCfg->spCellCfg, &schUeCfg->spCellCfg) != ROK)
1627    {
1628       DU_LOG("\nERROR  -->  MAC : fillSpCellCfg() failed");
1629       return RFAILED;
1630    }
1631
1632    if(ueCfg->ambrCfg != NULLP)
1633    {
1634       MAC_ALLOC(schUeCfg->ambrCfg, sizeof(SchAmbrCfg));
1635       if(!schUeCfg->ambrCfg)
1636       {
1637          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in sendReconfigReqToSch");
1638          return RFAILED;
1639       }
1640       schUeCfg->ambrCfg->ulBr = ueCfg->ambrCfg->ulBr;
1641    }
1642    else
1643       schUeCfg->ambrCfg = NULLP;
1644
1645    /* Fill DL modulation infor */
1646    schUeCfg->dlModInfo.modOrder = ueCfg->dlModInfo.modOrder;
1647    schUeCfg->dlModInfo.mcsIndex = ueCfg->dlModInfo.mcsIndex;
1648    schUeCfg->dlModInfo.mcsTable = ueCfg->dlModInfo.mcsTable;
1649
1650    /* Fill UL modulation infor */
1651    schUeCfg->ulModInfo.modOrder = ueCfg->ulModInfo.modOrder;
1652    schUeCfg->ulModInfo.mcsIndex = ueCfg->ulModInfo.mcsIndex;
1653    schUeCfg->ulModInfo.mcsTable = ueCfg->ulModInfo.mcsTable;
1654
1655    /* Fill sch Lc Cfg  to Add/ Mod/ Del */
1656    ret  = fillSchLcCfgList(schUeCfg, ueCfg);
1657    if(ret == RFAILED)
1658    {
1659       DU_LOG("\nERROR  -->  MAC : Failed to copy LCs at fillSchUeCfg()");
1660       return ret;
1661    }
1662    return ret;
1663 }
1664
1665 /*******************************************************************
1666  *
1667  * @brief Update UeUlCb Lc List
1668  *
1669  * @details
1670  *
1671  *    Function : updateMacUlCb
1672  *
1673  *    Functionality: Update UeUlCb Lc List
1674  *
1675  * @params[in] delIdx, UeUlCb pointer
1676  * @return void
1677  *
1678  * ****************************************************************/
1679
1680 void updateMacUlCb(uint8_t delIdx, UeUlCb *ulCb)
1681 {
1682    uint8_t lcIdx = 0;
1683
1684    for(lcIdx = delIdx; lcIdx < ulCb->numUlLc; lcIdx++)
1685    {
1686       /* Moving the array element to one step ahead */
1687       memcpy(&ulCb->lcCb[lcIdx], &ulCb->lcCb[lcIdx+1], sizeof(UlLcCb));
1688       memset(&ulCb->lcCb[lcIdx+1], 0, sizeof(UlLcCb));
1689    }
1690 }
1691
1692 /*******************************************************************
1693  *
1694  * @brief Update UeDlCb Lc List
1695  *
1696  * @details
1697  *
1698  *    Function : updateMacDlCb
1699  *
1700  *    Functionality: Update UeDlCb Lc List
1701  *
1702  * @params[in] delIdx, UeDlCb pointer
1703  * @return void
1704  *
1705  * ****************************************************************/
1706
1707 void updateMacDlCb(uint8_t delIdx, UeDlCb *dlCb)
1708 {
1709    uint8_t lcIdx = 0;
1710
1711    for(lcIdx = delIdx; lcIdx < dlCb->numDlLc; lcIdx++)
1712    {
1713       /* Moving the array element to one step ahead */
1714       memcpy(&dlCb->lcCb[lcIdx], &dlCb->lcCb[lcIdx+1], sizeof(DlLcCb));
1715       memset(&dlCb->lcCb[lcIdx+1], 0, sizeof(DlLcCb));
1716    }
1717 }
1718
1719 /*******************************************************************
1720  *
1721  * @brief Fills Logical channel Cfg List to Add/Mod/Del
1722  *
1723  * @details
1724  *
1725  *    Function : fillMacLcCfgList
1726  *
1727  *    Functionality: Fills Logical channel Cfg List to Add/Mod/Del
1728  *
1729  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
1730  * @return ROK     - success
1731  *         RFAILED - failure
1732  *
1733  * ****************************************************************/
1734
1735 uint8_t fillMacLcCfgList(MacUeCb *ueCb, MacUeCfg *ueCfg)
1736 {
1737    uint8_t lcIdx, ueLcIdx;
1738
1739    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
1740    {
1741       if(ueCb->dlInfo.numDlLc < MAX_NUM_LC)
1742       {
1743          if(ueCfg->lcCfgList[lcIdx].configType == CONFIG_ADD)
1744          {
1745             /*Filling DL LC CB */
1746             ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcId = ueCfg->lcCfgList[lcIdx].lcId;
1747             ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcState = MAC_LC_STATE_ACTIVE;
1748             ueCb->dlInfo.numDlLc++;
1749             /*Filling UL LC CB */
1750             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcId = ueCfg->lcCfgList[lcIdx].lcId;
1751             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcGrpId = ueCfg->lcCfgList[lcIdx].ulLcCfg.lcGroup;
1752             ueCb->ulInfo.lcCb[ueCb->ulInfo.numUlLc].lcActive = MAC_LC_STATE_ACTIVE;
1753             ueCb->ulInfo.numUlLc++;
1754          }/*End of Add Config */
1755          else
1756          { 
1757             //searching for Lc to be Mod
1758             for(ueLcIdx = 0; ueLcIdx < ueCb->ulInfo.numUlLc; ueLcIdx++)
1759             {
1760                if(ueCb->ulInfo.lcCb[ueLcIdx].lcId == ueCfg->lcCfgList[lcIdx].lcId)
1761                {
1762                   if(ueCfg->lcCfgList[lcIdx].configType == CONFIG_MOD)
1763                   {
1764                      /*Nothing to Modify in DL LC CB */
1765                      /*Modify UL LC CB */
1766                      ueCb->ulInfo.lcCb[ueLcIdx].lcGrpId = ueCfg->lcCfgList[lcIdx].ulLcCfg.lcGroup;
1767                      DU_LOG("\nINFO  -->  MAC: Successfully Modified LC context for lcId[%d]", ueCfg->lcCfgList[lcIdx].lcId);
1768                      break;
1769                   }
1770                   if(ueCfg->lcCfgList[lcIdx].configType == CONFIG_DEL)
1771                   {
1772                      memset(&ueCb->dlInfo.lcCb[ueLcIdx], 0, sizeof(DlLcCb));
1773                      (ueCb->dlInfo.numDlLc)--;
1774                      updateMacDlCb(ueLcIdx, &ueCb->dlInfo);
1775
1776                      memset(&ueCb->ulInfo.lcCb[ueLcIdx], 0, sizeof(UlLcCb));
1777                      (ueCb->ulInfo.numUlLc)--;
1778                      updateMacUlCb(ueLcIdx, &ueCb->ulInfo);
1779                      DU_LOG("\nINFO  -->  MAC: Successfully Deleted LC context for lcId[%d]", ueCfg->lcCfgList[lcIdx].lcId);
1780                      break;
1781                   }
1782                }
1783             }
1784          }/*End of Mod Config */
1785       }
1786    }
1787    return ROK;
1788 }
1789
1790 /*******************************************************************
1791  *
1792  * @brief Fills MAC UE Cb Cfg
1793  *
1794  * @details
1795  *
1796  *    Function : fillMacUeCb
1797  *
1798  *    Functionality: Fills MAC UE Cb Cfg
1799  *
1800  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
1801  *             cellIdx
1802  * @return ROK     - success
1803  *         RFAILED - failure
1804  *
1805  * ****************************************************************/
1806
1807 uint8_t fillMacUeCb(MacUeCb *ueCb, MacUeCfg *ueCfg, uint8_t cellIdx)
1808 {
1809    uint8_t ret = ROK;
1810
1811    ueCb->ueIdx = ueCfg->ueIdx;
1812    ueCb->crnti = ueCfg->crnti;
1813    ueCb->cellCb = macCb.macCell[cellIdx];
1814    ueCb->dlInfo.dlHarqEnt.numHarqProcs = \
1815       ueCfg->spCellCfg.servCellCfg.pdschServCellCfg.numHarqProcForPdsch; 
1816    ueCb->state = UE_STATE_ACTIVE;
1817    /*TODO: To check the bsr value during implementation */
1818    ueCb->bsrTmrCfg.periodicTimer = ueCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer;
1819    ueCb->bsrTmrCfg.retxTimer     = ueCfg->macCellGrpCfg.bsrTmrCfg.retxTimer;
1820    ueCb->bsrTmrCfg.srDelayTimer  = ueCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer;
1821    ret = fillMacLcCfgList(ueCb, ueCfg);
1822    if(ret == RFAILED)
1823    {
1824       DU_LOG("\nERROR  -->  MAC: Failed while filing MAC LC List at fillMacUeCb()");
1825    }
1826    return ret;
1827 }
1828
1829 /*******************************************************************
1830  *
1831  * @brief Function to update Mac Ra Cb
1832  *
1833  * @details
1834  *
1835  *    Function : updateMacRaCb
1836  *
1837  *    Functionality: Function to update Mac Ra Cb
1838  *
1839  * @params[in] cellIdx, Mac Ue Cb
1840  * @return ROK     - success
1841  *         RFAILED - failure
1842  *
1843  * ****************************************************************/
1844
1845 uint8_t updateMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
1846 {
1847    uint8_t ueIdx;
1848    /* Copy RA Cb */
1849    for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
1850    {
1851       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == ueCb->crnti)
1852       {
1853          ueCb->raCb = &macCb.macCell[cellIdx]->macRaCb[ueIdx];
1854          break;
1855       }
1856    }
1857    return ROK;
1858 }
1859
1860 /*******************************************************************
1861  *
1862  * @brief Function to delete Mac Ra Cb
1863  *
1864  * @details
1865  *
1866  *    Function : deleteMacRaCb
1867  *
1868  *    Functionality: Function to delete Mac Ra Cb
1869  *
1870  * @params[in] cellIdx, Mac Ue Cb
1871  * @return void
1872  *
1873  * ****************************************************************/
1874
1875 void deleteMacRaCb(uint16_t cellIdx, MacUeCb *ueCb)
1876 {
1877    uint8_t ueIdx;
1878
1879    for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
1880    {
1881       if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == ueCb->crnti)
1882       {
1883          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu)
1884          {
1885            MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4Pdu, \
1886                      macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4PduLen);
1887          }
1888          if(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu)
1889          {
1890             MAC_FREE(macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TxPdu, \
1891                       macCb.macCell[cellIdx]->macRaCb[ueIdx].msg4TbSize);
1892          }
1893          memset(&macCb.macCell[cellIdx]->macRaCb[ueIdx], 0, sizeof(MacRaCbInfo));
1894          break;
1895       }
1896    }
1897                   
1898 }
1899
1900 /*******************************************************************
1901  *
1902  * @brief Creates UE Cb
1903  *
1904  * @details
1905  *
1906  *    Function : createUeCb
1907  *
1908  *    Functionality: Creates UE Cb
1909  *
1910  * @params[in] MAC UE Configuration
1911  * @return ROK     - success
1912  *         RFAILED - failure
1913  *
1914  * ****************************************************************/
1915 uint8_t createUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
1916 {
1917    uint8_t ret =ROK;
1918
1919    if((ueCb->ueIdx == ueCfg->ueIdx) && (ueCb->crnti == ueCfg->crnti)\
1920       &&(ueCb->state == UE_STATE_ACTIVE))
1921    {
1922       DU_LOG("\nERROR  -->  MAC : CRNTI %d already configured ", ueCfg->crnti);
1923       return ROKDUP;
1924    }
1925    else
1926    {
1927       memset(ueCb, 0, sizeof(MacUeCb));
1928       ret = fillMacUeCb(ueCb, ueCfg, cellIdx);
1929       if(ret != ROK)
1930       {
1931          DU_LOG("\nERROR  -->  MAC : Failed to create Ue Cb at createUeCb()");
1932          return ret;
1933       }
1934       else
1935       {
1936          macCb.macCell[cellIdx]->numActvUe++;
1937          updateMacRaCb(cellIdx, ueCb);
1938          return ROK;
1939       }
1940
1941    }
1942
1943 }
1944
1945 /*******************************************************************
1946  *
1947  * @brief Modify UE Cb Cfg
1948  *
1949  * @details
1950  *
1951  *    Function : modifyUeCb
1952  *
1953  *    Functionality: modify UE Cb
1954  *
1955  * @params[in] MAC UE Configuration
1956  * @return ROK     - success
1957  *         RFAILED - failure
1958  *
1959  * ****************************************************************/
1960 uint8_t modifyUeCb(uint8_t cellIdx, MacUeCb *ueCb, MacUeCfg *ueCfg)
1961 {
1962    uint8_t ret = ROK;
1963
1964    if((ueCb->ueIdx == ueCfg->ueIdx) && (ueCb->crnti == ueCfg->crnti)\
1965       &&(ueCb->state == UE_STATE_ACTIVE))
1966    {
1967       DU_LOG("\nINFO  -->  MAC : Modifying Ue config Req for CRNTI %d ", ueCfg->crnti);
1968       ret = fillMacUeCb(ueCb, ueCfg, cellIdx);
1969       if(ret != ROK)
1970       {
1971          DU_LOG("\nERROR  -->  MAC : Failed to modify MacUeCb at modifyUeCb()");
1972          return ret;
1973       }
1974       else
1975       {
1976          deleteMacRaCb(cellIdx, ueCb);
1977          return ROK;
1978       }
1979    }
1980    return RFAILED;
1981 }
1982
1983
1984 /*******************************************************************
1985  *
1986  * @brief Creates UE Cb and fills ueCfg
1987  *
1988  * @details
1989  *
1990  *    Function : procMacUeCfgData
1991  *
1992  *    Functionality: Creates UE Cb and fills ueCfg
1993  *
1994  * @params[in] MAC UE Configuration
1995  * @return ROK     - success
1996  *         RFAILED - failure
1997  *
1998  * ****************************************************************/
1999
2000 uint8_t procMacUeCfgData(Pst *pst, MacUeCfg *ueCfg)
2001 {
2002    uint8_t ret = ROK;
2003    uint16_t  cellIdx;
2004    MacUeCb   *ueCb = NULLP;
2005
2006
2007    GET_CELL_IDX(ueCfg->cellId, cellIdx);
2008
2009    /* Validate cell id */
2010    if(macCb.macCell[cellIdx]->cellId != ueCfg->cellId)
2011    {
2012       DU_LOG("\nERROR  -->  MAC : Cell Id %d not configured", ueCfg->cellId);
2013       return RFAILED;
2014    }
2015
2016    /* Check if max number of UE configured */
2017    if(macCb.macCell[cellIdx]->numActvUe > MAX_NUM_UE)
2018    {
2019       DU_LOG("\nERROR  -->  MAC : Max number of UE [%d] already configured", MAX_NUM_UE);
2020       return RFAILED;
2021    }
2022
2023    /* Check if UE already configured */
2024    ueCb = &macCb.macCell[cellIdx]->ueCb[ueCfg->ueIdx -1];
2025    switch(pst->event)
2026    {
2027       case EVENT_UE_CONFIG_RSP_TO_MAC:
2028          ret = createUeCb(cellIdx, ueCb, ueCfg);
2029          if(ret != ROK)
2030             DU_LOG("\nERROR  -->  MAC: AddUeConfigReq for cellIdx :%d failed in procMacUeCfgData()", cellIdx);
2031          break;
2032       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2033          ret = modifyUeCb(cellIdx, ueCb, ueCfg);
2034          if(ret != ROK)
2035             DU_LOG("\nERROR  -->  MAC: ModifyUeConfigReq for cellIdx :%d failed at procMacUeCfgData()", cellIdx);
2036          break;
2037       default:
2038          break;
2039    }
2040
2041    return ret;
2042 }
2043
2044 /*******************************************************************
2045  *
2046  * @brief Function to store the UeCfg Data 
2047  *
2048  * @details
2049  *
2050  *    Function : copyToTmpData
2051  *
2052  *    Functionality: Function to store the UeCfg Data
2053  *
2054  * @params[in] MacUeCfg pointer 
2055  * @return ROK     - success
2056  *         RFAILED - failure
2057  *
2058  * ****************************************************************/
2059
2060 uint8_t copyToTmpData(MacUeCfg *ueCfg)
2061 {
2062    uint8_t cellIdx;
2063    MacUeCfg *tmpData = NULLP;
2064
2065    MAC_ALLOC(tmpData, sizeof(MacUeCfg));
2066    if(!tmpData)
2067    {
2068       DU_LOG("\nERROR  -->  MAC: Memory Alloc Failed at copyToTmpData()");
2069       return RFAILED;
2070    }
2071    memcpy(tmpData, ueCfg, sizeof(MacUeCfg));
2072    GET_CELL_IDX(ueCfg->cellId, cellIdx);
2073    macCb.macCell[cellIdx]->ueCfgTmpData[ueCfg->ueIdx-1] = tmpData;
2074    return ROK;
2075 }
2076
2077 /*******************************************************************
2078  *
2079  * @brief Handles UE create requst from DU APP
2080  *
2081  * @details
2082  *
2083  *    Function : MacProcUeCreateReq
2084  *
2085  *    Functionality: Handles UE create requst from DU APP
2086  *
2087  * @params[in] 
2088  * @return ROK     - success
2089  *         RFAILED - failure
2090  *
2091  * ****************************************************************/
2092 uint8_t MacProcUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
2093 {
2094    uint8_t ret = ROK;
2095    SchUeCfg   schUeCfg;
2096    memset(&schUeCfg, 0, sizeof(SchUeCfg));
2097
2098    DU_LOG("\nINFO  -->  MAC : UE Create Request for CRNTI[%d]", ueCfg->crnti);
2099
2100    if(ueCfg)
2101    {
2102       /*Storing received ueCfg in ueCfgTmpData */
2103       ret = copyToTmpData(ueCfg);
2104       if(ret == ROK)
2105       {
2106          /*Sending Cfg Req to SCH */
2107          ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
2108          if(ret != ROK)
2109             DU_LOG("\nERROR  -->  MAC : Failed to fill Sch Ue Cfg at MacProcUeCreateReq()");
2110          else
2111          {
2112             /* Fill event and send UE create request to SCH */
2113             ret = sendUeReqToSch(pst, &schUeCfg);
2114             if(ret != ROK)
2115                DU_LOG("\nERROR  -->  MAC : Failed to send UE Create request to SCH");
2116          }
2117       }
2118       else 
2119       {
2120          DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE CFG ");
2121       }
2122    }
2123    else
2124    {
2125       DU_LOG("\nERROR  -->  MAC : MAC UE Create request processing failed");
2126       ret = RFAILED;
2127    }
2128    /* FREE shared memory */
2129    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
2130
2131    return ret;
2132 }
2133
2134 /*******************************************************************
2135  *
2136  * @brief Fill and Send UE create response from MAC to DU APP
2137  *
2138  * @details
2139  *
2140  *    Function : MacSendUeCreateRsp
2141  *
2142  *    Functionality: Fill and Send UE create response from MAC to DUAPP
2143  *
2144  * @params[in] MAC UE create result
2145  *             SCH UE create response
2146  * @return ROK     - success
2147  *         RFAILED - failure
2148  *
2149  * ****************************************************************/
2150 uint8_t MacSendUeCreateRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
2151 {
2152    MacUeCfgRsp   *cfgRsp;
2153    Pst        rspPst;
2154
2155    MAC_ALLOC_SHRABL_BUF(cfgRsp, sizeof(MacUeCfgRsp));
2156    if(!cfgRsp)
2157    {
2158       DU_LOG("\nERROR  -->  MAC: Memory allocation for UE config response failed");
2159       return RFAILED;
2160    }
2161
2162    /* Filling UE Config response */
2163    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
2164    cfgRsp->cellId = schCfgRsp->cellId;
2165    cfgRsp->ueIdx = schCfgRsp->ueIdx;
2166    cfgRsp->result = result;
2167
2168    /* Fill Post structure and send UE Create response*/
2169    memset(&rspPst, 0, sizeof(Pst));
2170    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_CREATE_RSP);
2171    return (*macDuUeCfgRspOpts[rspPst.selector])(&rspPst, cfgRsp); 
2172 }
2173
2174 /*******************************************************************
2175  *
2176  * @brief Fill and Send UE Reconfig response from MAC to DU APP
2177  *
2178  * @details
2179  *
2180  *    Function : MacSendUeReconfigRsp
2181  *
2182  *    Functionality: Fill and Send UE Reconfig response from MAC to DUAPP
2183  *
2184  * @params[in] MAC UE create result
2185  *             SCH UE create response
2186  * @return ROK     - success
2187  *         RFAILED - failure
2188  *
2189  * ****************************************************************/
2190 uint8_t MacSendUeReconfigRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
2191 {
2192    MacUeCfgRsp   *cfgRsp;
2193    Pst        rspPst;
2194
2195    MAC_ALLOC_SHRABL_BUF(cfgRsp, sizeof(MacUeCfgRsp));
2196    if(!cfgRsp)
2197    {
2198       DU_LOG("\nERROR  -->  MAC: Memory allocation for UE Reconfig response failed");
2199       return RFAILED;
2200    }
2201
2202    /* Filling UE Config response */
2203    memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
2204    cfgRsp->cellId = schCfgRsp->cellId;
2205    cfgRsp->ueIdx = schCfgRsp->ueIdx;
2206    cfgRsp->result = result;
2207
2208    /* Fill Post structure and send UE Create response*/
2209    memset(&rspPst, 0, sizeof(Pst));
2210    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_RECONFIG_RSP);
2211    return (*macDuUeCfgRspOpts[rspPst.selector])(&rspPst, cfgRsp);
2212 }
2213
2214 /*******************************************************************
2215  *
2216  * @brief  Function to return Mac Ue Cfg pointer
2217  *
2218  * @details
2219  *
2220  *    Function : getMacUeCfg
2221  *
2222  *    Functionality:
2223  *      Function to return Mac Ue Cfg pointer
2224  *
2225  * @params[in] cellIdx, ueIdx
2226  *
2227  * @return MacUeCfg pointer - success
2228  *         NULLP - failure
2229  *
2230  * ****************************************************************/
2231
2232 MacUeCfg *getMacUeCfg(uint16_t cellIdx, uint8_t ueIdx)
2233 {
2234    MacUeCfg *ueCfg = NULLP;
2235    if(macCb.macCell[cellIdx])
2236    {
2237       ueCfg = macCb.macCell[cellIdx]->ueCfgTmpData[ueIdx-1];
2238    }
2239    else
2240    {
2241       DU_LOG("\nERROR  -->  MAC: Failed to get macCellCb in getMacUeCfg()");
2242    }
2243    return ueCfg;
2244 }
2245
2246 /*******************************************************************
2247  *
2248  * @brief  Processes UE create response from scheduler
2249  *
2250  * @details
2251  *
2252  *    Function : MacProcSchUeCfgRsp
2253  *
2254  *    Functionality:
2255  *      Processes UE create response from scheduler
2256  *      Sends UE create response to DU APP
2257  *
2258  * @params[in] Pst : Post structure
2259  *             schCfgRsp : Scheduler UE cfg response
2260  * @return ROK     - success
2261  *         RFAILED - failure
2262  *
2263  * ****************************************************************/
2264 uint8_t MacProcSchUeCfgRsp(Pst *pst, SchUeCfgRsp *schCfgRsp)
2265 {
2266    uint8_t result = MAC_DU_APP_RSP_NOK;
2267    uint8_t ret = ROK;
2268    uint16_t cellIdx;
2269    MacUeCfg *ueCfg = NULLP;
2270
2271    GET_CELL_IDX(schCfgRsp->cellId, cellIdx);
2272    ueCfg = getMacUeCfg(cellIdx, schCfgRsp->ueIdx);
2273    if(ueCfg == NULLP)
2274    {
2275       DU_LOG("\nERROR  -->  MAC : Failed to find the Mac Ue Cfg for event [%d] in MacProcSchUeCfgRsp()", pst->event);
2276       ret = RFAILED;
2277    }
2278
2279    switch(pst->event)
2280    {
2281       case EVENT_UE_CONFIG_RSP_TO_MAC:
2282       {
2283          if(schCfgRsp->rsp != RSP_NOK)
2284          {
2285             DU_LOG("\nINFO  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2286             if(ret == ROK)
2287             {
2288                ret = procMacUeCfgData(pst, ueCfg);
2289                if(ret == ROK)
2290                {
2291                   result = MAC_DU_APP_RSP_OK;
2292                }
2293             }
2294          }
2295          else
2296          {
2297             DU_LOG("\nERROR  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2298          }
2299          ret = MacSendUeCreateRsp(result, schCfgRsp);
2300       }
2301       break;
2302
2303       case EVENT_UE_RECONFIG_RSP_TO_MAC:
2304       {
2305          if(schCfgRsp->rsp != RSP_NOK)
2306          {
2307             DU_LOG("\nINFO  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2308             if(ret == ROK)
2309             {
2310                ret = procMacUeCfgData(pst, ueCfg);
2311                if(ret == ROK)
2312                {
2313                   result = MAC_DU_APP_RSP_OK;
2314                }
2315             }
2316          }
2317          else
2318          {
2319             DU_LOG("\nERROR  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
2320          }
2321          ret = MacSendUeReconfigRsp(result, schCfgRsp);
2322       }
2323       break;
2324       
2325       default:
2326       break;
2327    }
2328    MAC_FREE(ueCfg, sizeof(MacUeCfg));
2329    ueCfg = NULLP;
2330    
2331    return ret; 
2332 }
2333
2334 /*******************************************************************
2335  *
2336  * @brief Handles UE Reconfig requst from DU APP
2337  *
2338  * @details
2339  *
2340  *    Function : MacProcUeReconfigReq
2341  *
2342  *    Functionality: Handles UE Reconfig requst from DU APP
2343  *
2344  * @params[in] 
2345  * @return ROK     - success
2346  *         RFAILED - failure
2347  *
2348  * ****************************************************************/
2349 uint8_t MacProcUeReconfigReq(Pst *pst, MacUeCfg *ueCfg)
2350 {
2351    uint8_t ret = ROK;
2352    SchUeCfg   schUeCfg;
2353    memset(&schUeCfg, 0, sizeof(SchUeCfg));
2354
2355    DU_LOG("\nINFO  -->  MAC : UE Reconfig Request for CRNTI[%d]", ueCfg->crnti);
2356
2357    if(ueCfg)
2358    {
2359       /*Storing received ueCfg in ueCfgTmpData */
2360       ret = copyToTmpData(ueCfg);
2361       if(ret == ROK)
2362       {
2363          /*Sending Cfg Req to SCH */
2364          ret = fillSchUeCfg(pst, &schUeCfg, ueCfg);
2365          if(ret != ROK)
2366             DU_LOG("\nERROR  -->  MAC : Failed to fill sch Ue Cfg at MacProcUeReconfigReq()");
2367          else
2368          {
2369             /* Fill event and send UE create request to SCH */
2370             ret = sendUeReqToSch(pst, &schUeCfg);
2371             if(ret != ROK)
2372                DU_LOG("\nERROR  -->  MAC : Failed to send UE Reconfig Request to SCH");
2373          }
2374       }
2375       else 
2376       {
2377          DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE Cb ");
2378       }
2379    }
2380    else
2381    {
2382       DU_LOG("\nERROR  -->  MAC : MAC UE Create request processing failed");
2383       ret = RFAILED;
2384    }
2385    /* FREE shared memory */
2386    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
2387    return ROK;
2388 }
2389
2390
2391 /**********************************************************************
2392   End of file
2393  **********************************************************************/