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