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