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