[ Jira id - ODUHIGH-593 ] Pack and unpack function nomenclature correction
[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.mSlotPeriodicity = \
1219         macPdcchCfg.searchSpcToAddModList[idx].mSlotPeriodicityAndOffset.mSlotPeriodicity;
1220      schPdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset.mSlotOffset =
1221         macPdcchCfg.searchSpcToAddModList[idx].mSlotPeriodicityAndOffset.mSlotOffset;
1222       memcpy(&schPdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot,
1223          &macPdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, \
1224          MONITORING_SYMB_WITHIN_SLOT_SIZE);
1225       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1 = \
1226          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1;
1227       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2 = \
1228          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2;
1229       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4 = \
1230          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4;
1231       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8 = \
1232          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8;
1233       schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16 = \
1234          macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16;
1235       schPdcchCfg->searchSpcToAddModList[idx].searchSpaceType = \
1236          macPdcchCfg.searchSpcToAddModList[idx].searchSpaceType;
1237       schPdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat = \
1238          macPdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat;
1239    }
1240
1241    schPdcchCfg->numSearchSpcToRel = macPdcchCfg.numSearchSpcToRel;
1242    if(schPdcchCfg->numSearchSpcToRel > MAX_NUM_SEARCH_SPC)
1243    {
1244       DU_LOG("\nERROR  -->  MAC : Number of search space to release [%d] exceeds max [%d]", \
1245             schPdcchCfg->numSearchSpcToRel, MAX_NUM_SEARCH_SPC);
1246       return RFAILED;
1247    }
1248    for(idx = 0; idx < schPdcchCfg->numSearchSpcToRel; idx++)
1249    {
1250       /* TODO */
1251    }
1252
1253    return ROK;
1254 }
1255
1256 /*******************************************************************
1257  *
1258  * @brief Fill PDSCH cfg in Initial DL BWP for UE Cfg in Scheduler
1259  *
1260  * @details
1261  *
1262  *    Function : fillInitDlBwpPdschCfg
1263  *
1264  *    Functionality:
1265  *        Fill PDSCH cfg in Initial DL BWP for UE Cfg in Scheduler
1266  *
1267  * @params[in] macPdschCfg : Inital DL BWP PDSCH cfg at  MAC
1268  *             schPdschCfg : Inital DL BWP PDSCH cfg to be filled
1269  * @return ROK     - success
1270  *         RFAILED - failure
1271  *
1272  * ****************************************************************/
1273 uint8_t fillInitDlBwpPdschCfg(PdschConfig macPdschCfg, SchPdschConfig *schPdschCfg)
1274 {
1275    uint8_t   idx;
1276
1277    schPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
1278        macPdschCfg.dmrsDlCfgForPdschMapTypeA.addPos;
1279    schPdschCfg->resourceAllocType = macPdschCfg.resourceAllocType;
1280    schPdschCfg->numTimeDomRsrcAlloc = macPdschCfg.numTimeDomRsrcAlloc;
1281    if(schPdschCfg->numTimeDomRsrcAlloc > MAX_NUM_DL_ALLOC)
1282    {
1283       DU_LOG("\nERROR  -->  MAC : Number of time domain resource allocation [%d], exceeds\
1284             max limit [%d]", schPdschCfg->numTimeDomRsrcAlloc, MAX_NUM_DL_ALLOC);
1285       return RFAILED;
1286    }
1287
1288    for(idx = 0; idx < schPdschCfg->numTimeDomRsrcAlloc; idx++)
1289    {
1290       if(macPdschCfg.timeDomRsrcAllociList[idx].k0)
1291       {
1292          MAC_ALLOC(schPdschCfg->timeDomRsrcAllociList[idx].k0, sizeof(uint8_t));
1293          if(!schPdschCfg->timeDomRsrcAllociList[idx].k0)
1294          {
1295             DU_LOG("\nERROR  -->  MAC : Memory allocation failed for K0 in fillInitDlBwpPdschCfg()");
1296             return RFAILED;
1297          }
1298          *(schPdschCfg->timeDomRsrcAllociList[idx].k0) = *(macPdschCfg.timeDomRsrcAllociList[idx].k0);
1299       }
1300       schPdschCfg->timeDomRsrcAllociList[idx].mappingType = \
1301          macPdschCfg.timeDomRsrcAllociList[idx].mappingType;
1302       schPdschCfg->timeDomRsrcAllociList[idx].startSymbol = \
1303          macPdschCfg.timeDomRsrcAllociList[idx].startSymbol;
1304       schPdschCfg->timeDomRsrcAllociList[idx].symbolLength = \
1305          macPdschCfg.timeDomRsrcAllociList[idx].symbolLength;
1306    }
1307
1308    schPdschCfg->rbgSize = macPdschCfg.rbgSize;
1309    schPdschCfg->numCodeWordsSchByDci = macPdschCfg.numCodeWordsSchByDci;
1310    schPdschCfg->bundlingType = macPdschCfg.bundlingType;
1311    if(schPdschCfg->bundlingType == STATIC_BUNDLING_TYPE)
1312    {
1313       schPdschCfg->bundlingInfo.SchStaticBundling.size  = macPdschCfg.bundlingInfo.StaticBundling.size;
1314    }
1315    else if(schPdschCfg->bundlingType == DYNAMIC_BUNDLING_TYPE)
1316    {
1317       schPdschCfg->bundlingInfo.SchDynamicBundling.sizeSet1 = macPdschCfg.bundlingInfo.DynamicBundling.sizeSet1;
1318       schPdschCfg->bundlingInfo.SchDynamicBundling.sizeSet2 = macPdschCfg.bundlingInfo.DynamicBundling.sizeSet2;
1319    }
1320    return ROK;
1321 }
1322
1323 /*******************************************************************
1324  *
1325  * @brief Fill Initial DL BWP for SCH UE config
1326  *
1327  * @details
1328  *
1329  *    Function : fillInitialDlBwp
1330  *
1331  *    Functionality: Fill Initial DL BWP for SCH UE config
1332  *
1333  * @params[in] macInitDlBwp : Inital DL BWP cfg at MAC
1334  *             schInitDlBwp : Inital DL BWP cfg to be filled
1335  * @return ROK     - success
1336  *         RFAILED - failure
1337  *
1338  * ****************************************************************/
1339 uint8_t fillInitialDlBwp(InitialDlBwp macInitDlBwp, SchInitalDlBwp *schInitDlBwp)
1340 {
1341    schInitDlBwp->pdcchCfgPres = macInitDlBwp.pdcchPresent;
1342    if(schInitDlBwp->pdcchCfgPres)
1343    {
1344       if(fillInitDlBwpPdcchCfg(macInitDlBwp.pdcchCfg, &schInitDlBwp->pdcchCfg) != ROK)
1345       {
1346          DU_LOG("\nERROR  -->  MAC : fillInitDlBwpPdcchCfg() failed");
1347          return RFAILED;
1348       }
1349    }
1350
1351    schInitDlBwp->pdschCfgPres = macInitDlBwp.pdschPresent;
1352    if(schInitDlBwp->pdschCfgPres)
1353    {
1354       if(fillInitDlBwpPdschCfg(macInitDlBwp.pdschCfg,&schInitDlBwp->pdschCfg) != ROK)
1355       {
1356          DU_LOG("\nERROR  -->  MAC : fillInitDlBwpPdschCfg() failed");
1357          return RFAILED;
1358       }
1359    }
1360    return ROK;
1361 }
1362
1363 /*******************************************************************
1364  *
1365  * @brief Fills Sp Cell config to be sent to scheduler
1366  *
1367  * @details
1368  *
1369  *    Function : fillSpCellCfg 
1370  *
1371  *    Functionality: Fills Sp Cell config to be sent to scheduler
1372  *
1373  * @params[in] macSpCellCfg : SP cell cfg at MAC
1374  *             schSpCellCfg : SP cell cfg to be filled
1375  * @return ROK     - success
1376  *         RFAILED - failure
1377  *
1378  * ****************************************************************/
1379 uint8_t fillSpCellCfg(SpCellCfg macSpCellCfg, SchSpCellCfg *schSpCellCfg)
1380 {
1381    uint8_t   idx;
1382    SchServCellCfgInfo   *servCellCfg;
1383
1384    schSpCellCfg->servCellIdx = macSpCellCfg.servCellIdx;
1385    servCellCfg = &schSpCellCfg->servCellCfg;
1386
1387    /* Fill initial DL BWP */
1388    if(fillInitialDlBwp(macSpCellCfg.servCellCfg.initDlBwp, \
1389             &servCellCfg->initDlBwp) != ROK )
1390    {
1391       DU_LOG("\nERROR  -->  MAC : fillInitialDlBwp() failed");
1392       return RFAILED;
1393    }
1394
1395    servCellCfg->numDlBwpToAdd = macSpCellCfg.servCellCfg.numDlBwpToAdd;
1396    if(servCellCfg->numDlBwpToAdd > MAX_NUM_BWP)
1397    {
1398       DU_LOG("\nERROR  -->  MAC : Number of DL BWP to ADD [%d] exceeds max limit [%d]",\
1399             servCellCfg->numDlBwpToAdd, MAX_NUM_BWP);
1400       return RFAILED;
1401    }
1402    for(idx = 0; idx < servCellCfg->numDlBwpToAdd; idx++)
1403    {
1404       memcpy(&servCellCfg->dlBwpToAddList[idx], &macSpCellCfg.servCellCfg.dlBwpToAddList[idx], sizeof(DlBwpInfo));
1405    }
1406    servCellCfg->firstActvDlBwpId =  macSpCellCfg.servCellCfg.firstActvDlBwpId;
1407    servCellCfg->defaultDlBwpId = macSpCellCfg.servCellCfg.defaultDlBwpId;
1408    servCellCfg->bwpInactivityTmr = NULL;
1409    if(macSpCellCfg.servCellCfg.bwpInactivityTmr)
1410    {
1411       /* TODO : This is an optional parameter, not filled currently */
1412    }
1413
1414    /* Fill PDSCH serving cell config */
1415    if(fillPdschServCellCfg(macSpCellCfg.servCellCfg.pdschServCellCfg, \
1416             &servCellCfg->pdschServCellCfg) != ROK)
1417    {
1418       DU_LOG("\nERROR  -->  MAC : fillPdschServCellCfg() failed");
1419       return RFAILED;
1420    }
1421
1422    /* Fill Initail UL BWP */
1423    if(fillInitialUlBwp(macSpCellCfg.servCellCfg.initUlBwp, \
1424             &servCellCfg->initUlBwp) != ROK)
1425    {
1426       DU_LOG("\nERROR  -->  MAC : fillInitialUlBwp() failed");
1427       return RFAILED;
1428    }
1429
1430    servCellCfg->numUlBwpToAdd = macSpCellCfg.servCellCfg.numUlBwpToAdd;
1431    if(servCellCfg->numUlBwpToAdd > MAX_NUM_BWP)
1432    {
1433       DU_LOG("\nERROR  -->  MAC : Number of UL BWP to ADD [%d] exceeds max limit [%d]",\
1434             servCellCfg->numUlBwpToAdd, MAX_NUM_BWP);
1435       return RFAILED;
1436    }
1437    for(idx = 0; idx < servCellCfg->numUlBwpToAdd; idx++)
1438    {
1439       memcpy(&servCellCfg->ulBwpToAddList[idx], &macSpCellCfg.servCellCfg.ulBwpToAddList[idx], sizeof(UlBwpInfo));
1440    }
1441    servCellCfg->firstActvUlBwpId =  macSpCellCfg.servCellCfg.firstActvUlBwpId;
1442
1443    return ROK;
1444 }
1445
1446 /*******************************************************************
1447  *
1448  * @brief Fills Sp Cell Reconfig to be sent to scheduler
1449  *
1450  * @details
1451  *
1452  *    Function : fillSpCellRecfg 
1453  *
1454  *    Functionality: Fills Sp Cell Reconfig to be sent to scheduler
1455  *
1456  * @params[in] macSpCellRecfg : SP cell Recfg at MAC
1457  *             schSpCellRecfg : SP cell Recfg to be filled
1458  * @return ROK     - success
1459  *         RFAILED - failure
1460  *
1461  * ****************************************************************/
1462 uint8_t fillSpCellRecfg(SpCellRecfg macSpCellRecfg, SchSpCellRecfg *schSpCellRecfg)
1463 {
1464    uint8_t   idx;
1465    SchServCellRecfgInfo   *servCellRecfg;
1466
1467    schSpCellRecfg->servCellIdx = macSpCellRecfg.servCellIdx;
1468    servCellRecfg = &schSpCellRecfg->servCellRecfg;
1469
1470    /* Fill initial DL BWP */
1471    if(fillInitialDlBwp(macSpCellRecfg.servCellCfg.initDlBwp, \
1472             &servCellRecfg->initDlBwp) != ROK )
1473    {
1474       DU_LOG("\nERROR  -->  MAC : fillInitialDlBwp() failed");
1475       return RFAILED;
1476    }
1477
1478    servCellRecfg->numDlBwpToAddOrMod = macSpCellRecfg.servCellCfg.numDlBwpToAddOrMod;
1479    if(servCellRecfg->numDlBwpToAddOrMod > MAX_NUM_BWP)
1480    {
1481       DU_LOG("\nERROR  -->  MAC : Number of DL BWP to ADD/MOD [%d] exceeds max limit [%d]",\
1482             servCellRecfg->numDlBwpToAddOrMod, MAX_NUM_BWP);
1483       return RFAILED;
1484    }
1485    for(idx = 0; idx < servCellRecfg->numDlBwpToAddOrMod; idx++)
1486    {
1487       memcpy(&servCellRecfg->dlBwpToAddOrModList[idx], &macSpCellRecfg.servCellCfg.dlBwpToAddOrModList[idx], sizeof(DlBwpInfo));
1488    }
1489    servCellRecfg->numDlBwpToRel = macSpCellRecfg.servCellCfg.numDlBwpToRel;
1490    if(servCellRecfg->numDlBwpToRel > MAX_NUM_BWP)
1491    {
1492       DU_LOG("\nERROR  -->  MAC : Number of DL BWP to RELEASE [%d] exceeds max limit [%d]",\
1493             servCellRecfg->numDlBwpToRel, MAX_NUM_BWP);
1494       return RFAILED;
1495    }
1496    for(idx = 0; idx < servCellRecfg->numDlBwpToRel; idx++)
1497    {
1498       memcpy(&servCellRecfg->dlBwpToRelList[idx], &macSpCellRecfg.servCellCfg.dlBwpToRelList[idx], sizeof(DlBwpInfo));
1499    }
1500    servCellRecfg->firstActvDlBwpId =  macSpCellRecfg.servCellCfg.firstActvDlBwpId;
1501    servCellRecfg->defaultDlBwpId = macSpCellRecfg.servCellCfg.defaultDlBwpId;
1502    servCellRecfg->bwpInactivityTmr = NULL;
1503    if(macSpCellRecfg.servCellCfg.bwpInactivityTmr)
1504    {
1505       /* TODO : This is an optional parameter, not filled currently */
1506    }
1507
1508    /* Fill PDSCH serving cell config */
1509    if(fillPdschServCellCfg(macSpCellRecfg.servCellCfg.pdschServCellCfg, \
1510             &servCellRecfg->pdschServCellCfg) != ROK)
1511    {
1512       DU_LOG("\nERROR  -->  MAC : fillPdschServCellCfg() failed");
1513       return RFAILED;
1514    }
1515
1516    /* Fill Initail UL BWP */
1517    if(fillInitialUlBwp(macSpCellRecfg.servCellCfg.initUlBwp, \
1518             &servCellRecfg->initUlBwp) != ROK)
1519    {
1520       DU_LOG("\nERROR  -->  MAC : fillInitialUlBwp() failed");
1521       return RFAILED;
1522    }
1523
1524    servCellRecfg->numUlBwpToAddOrMod = macSpCellRecfg.servCellCfg.numUlBwpToAddOrMod;
1525    if(servCellRecfg->numUlBwpToAddOrMod > MAX_NUM_BWP)
1526    {
1527       DU_LOG("\nERROR  -->  MAC : Number of UL BWP to ADD/MOD [%d] exceeds max limit [%d]",\
1528             servCellRecfg->numUlBwpToAddOrMod, MAX_NUM_BWP);
1529       return RFAILED;
1530    }
1531    for(idx = 0; idx < servCellRecfg->numUlBwpToAddOrMod; idx++)
1532    {
1533       memcpy(&servCellRecfg->ulBwpToAddOrModList[idx], &macSpCellRecfg.servCellCfg.ulBwpToAddOrModList[idx], sizeof(UlBwpInfo));
1534    }
1535    servCellRecfg->numUlBwpToRel = macSpCellRecfg.servCellCfg.numUlBwpToRel;
1536    if(servCellRecfg->numUlBwpToRel > MAX_NUM_BWP)
1537    {
1538       DU_LOG("\nERROR  -->  MAC : Number of UL BWP to RELEASE [%d] exceeds max limit [%d]",\
1539             servCellRecfg->numUlBwpToRel, MAX_NUM_BWP);
1540       return RFAILED;
1541    }
1542    for(idx = 0; idx < servCellRecfg->numUlBwpToRel; idx++)
1543    {
1544       memcpy(&servCellRecfg->ulBwpToRelList[idx], &macSpCellRecfg.servCellCfg.ulBwpToRelList[idx], sizeof(UlBwpInfo));
1545    }
1546    servCellRecfg->firstActvUlBwpId =  macSpCellRecfg.servCellCfg.firstActvUlBwpId;
1547
1548    return ROK;
1549 }
1550
1551 /*******************************************************************
1552  *
1553  * @brief Sends UE configuration to Scheduler
1554  *
1555  * @details
1556  *
1557  *    Function : sendUeReqToSch
1558  *
1559  *    Functionality: sends UE configuration to Scheduler
1560  *
1561  * @params[in] Pst and Ue configuration
1562  * @return ROK     - success
1563  *         RFAILED - failure
1564  *
1565  * ****************************************************************/
1566
1567 uint8_t sendUeReqToSch(Pst *pst, void *schUeCfg)
1568 {
1569    Pst schPst;
1570    switch(pst->event)
1571    {
1572       case EVENT_MAC_UE_CREATE_REQ:
1573       {
1574          SchUeCfgReq *schUeCfgReq = NULLP;
1575          schUeCfgReq = (SchUeCfgReq *)schUeCfg;
1576          FILL_PST_MAC_TO_SCH(schPst, EVENT_ADD_UE_CONFIG_REQ_TO_SCH);
1577          return(SchMessageRouter(&schPst, (void *)schUeCfgReq));
1578       }
1579       case EVENT_MAC_UE_RECONFIG_REQ:
1580       {
1581          SchUeRecfgReq *schUeRecfgReq = NULLP;
1582          schUeRecfgReq = (SchUeRecfgReq *)schUeCfg;
1583          FILL_PST_MAC_TO_SCH(schPst, EVENT_MODIFY_UE_CONFIG_REQ_TO_SCH);
1584          return(SchMessageRouter(&schPst, (void *)schUeRecfgReq));
1585       }
1586       default: 
1587       {
1588          DU_LOG("\nERROR  -->  Invalid Pst received %d", pst->event);
1589          return RFAILED;
1590       }
1591    }
1592 }
1593
1594 /*******************************************************************
1595  *
1596  * @brief Fills Sch Drb Qos Information
1597  *
1598  * @details
1599  *
1600  *    Function : fillSchDrbQosInfo
1601  *
1602  *    Functionality: Fills Sch Drb Qos Information
1603  *
1604  * @params[in] macLcCfg : Logical channel Cfg at MAC
1605  *             schLcCfg : LC cfg to fill at scheduler
1606  * @return ROK     - success
1607  *         RFAILED - failure
1608  *
1609  * ****************************************************************/
1610 void fillSchDrbQosInfo(DrbQosInfo *macDrbQos, SchDrbQosInfo *schDrbQos)
1611 {
1612    schDrbQos->fiveQiType  = macDrbQos->fiveQiType;
1613    if(schDrbQos->fiveQiType == SCH_QOS_NON_DYNAMIC)
1614    {
1615       schDrbQos->u.nonDyn5Qi.fiveQi = macDrbQos->u.nonDyn5Qi.fiveQi;
1616       schDrbQos->u.nonDyn5Qi.avgWindow = macDrbQos->u.nonDyn5Qi.avgWindow;
1617       schDrbQos->u.nonDyn5Qi.maxDataBurstVol = macDrbQos->u.nonDyn5Qi.maxDataBurstVol;
1618       schDrbQos->u.nonDyn5Qi.priorLevel =  macDrbQos->u.nonDyn5Qi.priorLevel;
1619    }
1620    else if(schDrbQos->fiveQiType == SCH_QOS_DYNAMIC)
1621    {
1622       schDrbQos->u.dyn5Qi.priorLevel         = macDrbQos->u.dyn5Qi.priorLevel;
1623       schDrbQos->u.dyn5Qi.packetDelayBudget  = macDrbQos->u.dyn5Qi.packetDelayBudget;
1624       schDrbQos->u.dyn5Qi.packetErrRateScalar= macDrbQos->u.dyn5Qi.packetErrRateScalar;
1625       schDrbQos->u.dyn5Qi.packetErrRateExp   = macDrbQos->u.dyn5Qi.packetErrRateExp;
1626       schDrbQos->u.dyn5Qi.fiveQi             = macDrbQos->u.dyn5Qi.fiveQi;
1627       schDrbQos->u.dyn5Qi.delayCritical      = macDrbQos->u.dyn5Qi.delayCritical;
1628       schDrbQos->u.dyn5Qi.avgWindow          = macDrbQos->u.dyn5Qi.avgWindow;
1629       schDrbQos->u.dyn5Qi.maxDataBurstVol    = macDrbQos->u.dyn5Qi.maxDataBurstVol;
1630    }
1631    schDrbQos->ngRanRetPri.priorityLevel   = macDrbQos->ngRanRetPri.priorityLevel;
1632    schDrbQos->ngRanRetPri.preEmptionCap   = macDrbQos->ngRanRetPri.preEmptionCap;
1633    schDrbQos->ngRanRetPri.preEmptionVul   = macDrbQos->ngRanRetPri.preEmptionVul;
1634    schDrbQos->grbQosFlowInfo.maxFlowBitRateDl = macDrbQos->grbQosInfo.maxFlowBitRateDl;
1635    schDrbQos->grbQosFlowInfo.maxFlowBitRateUl = macDrbQos->grbQosInfo.maxFlowBitRateUl;
1636    schDrbQos->grbQosFlowInfo.guarFlowBitRateDl= macDrbQos->grbQosInfo.guarFlowBitRateDl;
1637    schDrbQos->grbQosFlowInfo.guarFlowBitRateUl= macDrbQos->grbQosInfo.guarFlowBitRateUl;
1638    schDrbQos->pduSessionId = macDrbQos->pduSessionId;
1639    schDrbQos->ulPduSessAggMaxBitRate = macDrbQos->ulPduSessAggMaxBitRate;
1640 }
1641
1642 /*******************************************************************
1643  *
1644  * @brief Fill SCH UL logical channel configuration
1645  *
1646  * @details
1647  *
1648  *    Function : fillSchUlLcCfg
1649  *
1650  *    Functionality: Fills Sch Ul Lc configuration
1651  *
1652  * @params[in] macLcCfg : Logical channel Cfg at MAC
1653  *             schLcCfg : LC cfg to fill at scheduler
1654  * @return void
1655  *
1656  * ****************************************************************/
1657
1658 void fillSchUlLcCfg(SchUlLcCfg *schUlLcCfg, UlLcCfg *macUlLcCfg) 
1659 {
1660    schUlLcCfg->priority= macUlLcCfg->priority;
1661    schUlLcCfg->lcGroup = macUlLcCfg->lcGroup;
1662    schUlLcCfg->schReqId= macUlLcCfg->schReqId;
1663    schUlLcCfg->pbr    = macUlLcCfg->pbr;    
1664    schUlLcCfg->bsd    = macUlLcCfg->bsd;    
1665 }
1666
1667 /*******************************************************************
1668  *
1669  * @brief Fill logical channel configuration
1670  *
1671  * @details
1672  *
1673  *    Function : fillLogicalChannelCfg
1674  *
1675  *    Functionality: Fill logical channel configuration
1676  *
1677  * @params[in] macLcCfg : Logical channel Cfg at MAC
1678  *             schLcCfg : LC cfg to fill at scheduler
1679  * @return ROK     - success
1680  *         RFAILED - failure
1681  *
1682  * ****************************************************************/
1683 uint8_t fillLogicalChannelCfg(SchLcCfg *schLcCfg, LcCfg *macLcCfg)
1684 {
1685    uint8_t sdIdx;
1686    uint8_t ret = ROK;
1687    schLcCfg->lcId = macLcCfg->lcId;
1688    schLcCfg->dlLcCfg.lcp = macLcCfg->dlLcCfg.lcp;
1689    fillSchUlLcCfg(&schLcCfg->ulLcCfg, &macLcCfg->ulLcCfg);
1690
1691    if(macLcCfg->drbQos)
1692    {
1693       if(!schLcCfg->drbQos)
1694       {
1695          MAC_ALLOC(schLcCfg->drbQos, sizeof(SchDrbQosInfo));
1696          if(!schLcCfg->drbQos)
1697          {
1698             DU_LOG("\nERROR  -->  MAC : Memory alloc failed at drbQos at fillLogicalChannelCfg()");
1699             ret = RFAILED;
1700          }
1701       }
1702       if(ret == ROK)
1703       {
1704          fillSchDrbQosInfo(macLcCfg->drbQos, schLcCfg->drbQos);
1705       }
1706       else
1707          return ret;
1708    }
1709    else
1710    {
1711       schLcCfg->drbQos = NULLP;
1712    }
1713
1714    if(ret == ROK)
1715    {
1716       if(macLcCfg->snssai)
1717       {
1718          if(!schLcCfg->snssai)
1719          {
1720             MAC_ALLOC(schLcCfg->snssai, sizeof(Snssai));
1721             if(!schLcCfg->snssai)
1722             {
1723                DU_LOG("\nERROR  -->  MAC : Memory alloc failed at snssai at fillLogicalChannelCfg()");
1724                ret = RFAILED;
1725             }
1726          }
1727          if(ret == ROK)
1728          {
1729             schLcCfg->snssai->sst = macLcCfg->snssai->sst;
1730             for(sdIdx = 0; sdIdx < SD_SIZE; sdIdx++)
1731             {
1732                schLcCfg->snssai->sd[sdIdx] = macLcCfg->snssai->sd[sdIdx];
1733             }
1734          }
1735       }
1736       else
1737       {
1738          schLcCfg->snssai = NULLP;
1739       }
1740    }
1741
1742    return ret;
1743 }
1744
1745 /*******************************************************************
1746  *
1747  * @brief Fills Logical channel Cfg List to Add
1748  *
1749  * @details
1750  *
1751  *    Function : fillSchLcCfgList
1752  *
1753  *    Functionality: Fills Logical channel Cfg List to Add
1754  *
1755  * @params[in] MAC UE Cb Cfg , MAC UE Configuration
1756  * @return ROK     - success
1757  *         RFAILED - failure
1758  *
1759  * ****************************************************************/
1760
1761 uint8_t fillSchLcCfgList(SchUeCfgReq *schUeCfg, MacUeCreateReq *ueCfg)
1762 {
1763    uint8_t lcIdx;
1764
1765    for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
1766    {
1767       if(fillLogicalChannelCfg(&schUeCfg->schLcCfg[lcIdx], &ueCfg->lcCfgList[lcIdx]) != ROK)
1768       {
1769          DU_LOG("\nERROR  -->  MAC : fillLogicalChannelCfg() failed for lc Idx[%d]", lcIdx);
1770          return RFAILED;
1771       }
1772       schUeCfg->numLcsToAdd++;
1773    }
1774    return ROK;
1775 }
1776
1777 /*******************************************************************
1778  *
1779  * @brief Fills Logical channel Recfg List to Add/Mod/Del
1780  *
1781  * @details
1782  *
1783  *    Function : fillSchLcRecfgList
1784  *
1785  *    Functionality: Fills Logical channel Recfg List to Add/Mod/Del
1786  *
1787  * @params[in] MAC UE Cb Recfg , MAC UE ReConfiguration
1788  * @return ROK     - success
1789  *         RFAILED - failure
1790  *
1791  * ****************************************************************/
1792
1793 uint8_t fillSchLcRecfgList(SchUeRecfgReq *schUeRecfg, MacUeRecfg *ueRecfg)
1794 {
1795    uint8_t lcIdx;
1796
1797     /*LC to ADD*/
1798    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToAdd; lcIdx++)
1799    {
1800       if(fillLogicalChannelCfg(&schUeRecfg->schLcCfgAdd[lcIdx], &ueRecfg->lcCfgAdd[lcIdx]) != ROK)
1801       {
1802          DU_LOG("\nERROR  -->  MAC : fillLogicalChannelCfg() failed for lc Idx[%d]", lcIdx);
1803          return RFAILED;
1804       }
1805       schUeRecfg->numLcsToAdd++;
1806    }
1807     /*LC to DEL*/
1808    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToDel; lcIdx++)
1809    {
1810       schUeRecfg->lcIdToDel[lcIdx] = ueRecfg->lcIdToDel[lcIdx];
1811       schUeRecfg->numLcsToDel++;
1812    }
1813     /*LC to MOD*/
1814    for(lcIdx = 0; lcIdx < ueRecfg->numLcsToMod; lcIdx++)
1815    {
1816       if(fillLogicalChannelCfg(&schUeRecfg->schLcCfgMod[lcIdx], &ueRecfg->lcCfgMod[lcIdx]) != ROK)
1817       {
1818          DU_LOG("\nERROR  -->  MAC : fillLogicalChannelCfg() failed for lc Idx[%d]", lcIdx);
1819          return RFAILED;
1820       }
1821       schUeRecfg->numLcsToMod++;
1822    }
1823    return ROK;
1824 }
1825
1826 /*******************************************************************
1827  *
1828  * @brief Fills and sends UE configuration to Scheduler
1829  *
1830  * @details
1831  *
1832  *    Function : fillSchUeCfg
1833  *
1834  *    Functionality: Fills and sends UE configuration to Scheduler
1835  *
1836  * @params[in] Ue configuration from DU APP
1837  * @return ROK     - success
1838  *         RFAILED - failure
1839  *
1840  * ****************************************************************/
1841 uint8_t fillSchUeCfg(SchUeCfgReq *schUeCfg, MacUeCreateReq *ueCfg)
1842 {
1843    uint8_t ret = ROK;
1844
1845    schUeCfg->cellId = ueCfg->cellId;
1846    schUeCfg->crnti = ueCfg->crnti;
1847    /* Copy MAC cell group config */
1848    if(ueCfg->macCellGrpCfgPres == true)
1849    {
1850       schUeCfg->macCellGrpCfgPres = true;
1851       memset(&schUeCfg->macCellGrpCfg, 0, sizeof(SchMacCellGrpCfg));
1852       if(fillMacCellGroupCfg(ueCfg->macCellGrpCfg, &schUeCfg->macCellGrpCfg) != ROK)
1853       {
1854          DU_LOG("\nERROR  -->  MAC : fillMacCellGroupCfg() failed");
1855          return RFAILED;
1856       }
1857    }
1858    if(ueCfg->phyCellGrpCfgPres == true)
1859    {
1860      schUeCfg->phyCellGrpCfgPres = true;
1861      /* Copy Physical cell group config */
1862       memset(&schUeCfg->phyCellGrpCfg, 0,sizeof(SchPhyCellGrpCfg));
1863       if(fillPhyCellGroupCfg(ueCfg->phyCellGrpCfg, &schUeCfg->phyCellGrpCfg) != ROK)
1864       {
1865          DU_LOG("\nERROR  -->  MAC : fillPhyCellGroupCfg() failed");
1866          return RFAILED;
1867       }
1868    }
1869
1870    if(ueCfg->spCellCfgPres == true)
1871    {
1872       schUeCfg->spCellCfgPres = true;
1873       /* Copy sp cell config */
1874       memset(&schUeCfg->spCellCfg, 0, sizeof(SchSpCellCfg));
1875       if(fillSpCellCfg(ueCfg->spCellCfg, &schUeCfg->spCellCfg) != ROK)
1876       {
1877          DU_LOG("\nERROR  -->  MAC : fillSpCellCfg() failed");
1878          return RFAILED;
1879       }
1880    }
1881    if(ueCfg->ambrCfg != NULLP)
1882    {
1883       MAC_ALLOC(schUeCfg->ambrCfg, sizeof(SchAmbrCfg));
1884       if(!schUeCfg->ambrCfg)
1885       {
1886          DU_LOG("\nERROR  -->  MAC : Memory allocation failed in sendReconfigReqToSch");
1887          return RFAILED;
1888       }
1889       schUeCfg->ambrCfg->ulBr = ueCfg->ambrCfg->ulBr;
1890    }
1891    else
1892    {
1893       schUeCfg->ambrCfg = NULLP;
1894    }
1895    /* Fill DL modulation infor */
1896    schUeCfg->dlModInfo.modOrder = ueCfg->dlModInfo.modOrder;
1897    schUeCfg->dlModInfo.mcsIndex = ueCfg->dlModInfo.mcsIndex;
1898    schUeCfg->dlModInfo.mcsTable = ueCfg->dlModInfo.mcsTable;
1899
1900    /* Fill UL modulation infor */
1901    schUeCfg->ulModInfo.modOrder = ueCfg->ulModInfo.modOrder;
1902    schUeCfg->ulModInfo.mcsIndex = ueCfg->ulModInfo.mcsIndex;
1903    schUeCfg->ulModInfo.mcsTable = ueCfg->ulModInfo.mcsTable;
1904
1905    /* Fill sch Lc Cfg  to Add*/
1906    ret  = fillSchLcCfgList(schUeCfg, ueCfg);
1907    if(ret == RFAILED)
1908    {
1909       DU_LOG("\nERROR  -->  MAC : Failed to copy LCs at fillSchUeCfg()");
1910       return ret;
1911    }
1912
1913    return ret;
1914 }
1915
1916 /*******************************************************************
1917  *
1918  * @brief Fills and sends UE Re-configuration to Scheduler
1919  *
1920  * @details
1921  *
1922  *    Function : fillSchUeRecfg
1923  *
1924  *    Functionality: Fills and sends UE Reconfiguration to Scheduler
1925  *
1926  * @params[in] Ue configuration from DU APP
1927  * @return ROK     - success
1928  *         RFAILED - failure
1929  *
1930  * ****************************************************************/
1931 uint8_t fillSchUeRecfg(SchUeRecfgReq *schUeRecfg, MacUeRecfg *ueRecfg)
1932 {
1933    uint8_t ret = ROK;
1934
1935    schUeRecfg->cellId = ueRecfg->cellId;
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    GET_UE_ID(schCfgRsp->crnti, cfgRsp->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    GET_UE_ID(schCfgRsp->crnti, recfgRsp->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 = 0, ueId = 0;
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    GET_UE_ID(schCfgRsp->crnti, ueId);
2996    ueCfg = getMacUeCfg(cellIdx, ueId);
2997    if(ueCfg == NULLP)
2998    {
2999       DU_LOG("\nERROR  -->  MAC : Failed to find the Mac Ue Cfg for event [%d] in MacProcSchUeCfgRsp()", pst->event);
3000       ret = RFAILED;
3001    }
3002
3003    if(schCfgRsp->rsp != RSP_NOK)
3004    {
3005       DU_LOG("\nINFO  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
3006       if(ret == ROK)
3007       {
3008          ret = procMacUeCfgData(pst, ueCfg, NULLP);
3009          if(ret == ROK)
3010          {
3011             result = MAC_DU_APP_RSP_OK;
3012          }
3013       }
3014    }
3015    else
3016    {
3017       DU_LOG("\nERROR  -->  MAC: SCH UeConfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()", schCfgRsp->crnti);
3018    }
3019    ret = MacSendUeCreateRsp(result, schCfgRsp);
3020    MAC_FREE(ueCfg, sizeof(MacUeCreateReq));
3021    ueCfg = NULLP;
3022    return ret; 
3023 }
3024
3025 /*******************************************************************
3026  *
3027  * @brief  Processes UE create response from scheduler
3028  *
3029  * @details
3030  *
3031  *    Function : MacProcSchUeRecfgRsp
3032  *
3033  *    Functionality:
3034  *      Processes UE ReConfig response from scheduler
3035  *      Sends UE Reconfig response to DU APP
3036  *
3037  * @params[in] Pst : Post structure
3038  *             schRecfgRsp : Scheduler UE Recfg response
3039  * @return ROK     - success
3040  *         RFAILED - failure
3041  *
3042  * ****************************************************************/
3043 uint8_t MacProcSchUeRecfgRsp(Pst *pst, SchUeRecfgRsp *schRecfgRsp)
3044 {
3045    uint8_t result = MAC_DU_APP_RSP_NOK;
3046    uint8_t ret = ROK;
3047    uint16_t cellIdx = 0, ueId = 0;
3048    MacUeRecfg *ueRecfg = NULLP;
3049    
3050 #ifdef CALL_FLOW_DEBUG_LOG
3051    switch(pst->event)
3052    {
3053       case EVENT_UE_RECONFIG_RSP_TO_MAC:
3054          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_RECONFIG_RSP_TO_MAC\n");
3055          break;
3056       default:
3057          DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : Invalid Event\n");
3058          break;
3059    }
3060 #endif
3061
3062    GET_CELL_IDX(schRecfgRsp->cellId, cellIdx);
3063    GET_UE_ID(schRecfgRsp->crnti, ueId);
3064    ueRecfg = getMacUeRecfg(cellIdx, ueId);
3065    if(ueRecfg == NULLP)
3066    {
3067       DU_LOG("\nERROR  -->  MAC : Failed to find the Mac Ue Cfg for event [%d] in MacProcSchUeCfgRsp()", pst->event);
3068       ret = RFAILED;
3069    }
3070
3071
3072    if(schRecfgRsp->rsp != RSP_NOK)
3073    {
3074       DU_LOG("\nINFO  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is success in MacProcSchUeCfgRsp()",\
3075             schRecfgRsp->crnti);
3076       if(ret == ROK)
3077       {
3078          ret = procMacUeCfgData(pst, NULLP, ueRecfg);
3079          if(ret == ROK)
3080          {
3081             result = MAC_DU_APP_RSP_OK;
3082          }
3083       }
3084    }
3085    else
3086    {
3087       DU_LOG("\nERROR  -->  MAC: SCH UeReconfigRsp for CRNTI[%d] is failed in MacProcSchUeCfgRsp()",\
3088             schRecfgRsp->crnti);
3089    }
3090    ret = MacSendUeReconfigRsp(result, schRecfgRsp);
3091    MAC_FREE(ueRecfg, sizeof(MacUeRecfg));
3092    ueRecfg = NULLP;
3093    return ret; 
3094 }
3095
3096 /*******************************************************************
3097  *
3098  * @brief Handles UE Reconfig requst from DU APP
3099  *
3100  * @details
3101  *
3102  *    Function : MacProcUeReconfigReq
3103  *
3104  *    Functionality: Handles UE Reconfig requst from DU APP
3105  *
3106  * @params[in] 
3107  * @return ROK     - success
3108  *         RFAILED - failure
3109  *
3110  * ****************************************************************/
3111 uint8_t MacProcUeReconfigReq(Pst *pst, MacUeRecfg *ueRecfg)
3112 {
3113    uint8_t ret = ROK;
3114    SchUeRecfgReq   schUeRecfg;
3115    memset(&schUeRecfg, 0, sizeof(SchUeRecfgReq));
3116
3117    DU_LOG("\nINFO  -->  MAC : UE Reconfig Request for CRNTI[%d]", ueRecfg->crnti);
3118
3119    if(ueRecfg)
3120    {
3121       /*Storing received ueRecfg in ueCfgTmpData */
3122       ret = copyToTmpData(NULLP, ueRecfg);
3123       if(ret == ROK)
3124       {
3125          /*Sending Cfg Req to SCH */
3126          ret = fillSchUeRecfg(&schUeRecfg, ueRecfg);
3127          if(ret != ROK)
3128             DU_LOG("\nERROR  -->  MAC : Failed to fill sch Ue Cfg at MacProcUeReconfigReq()");
3129          else
3130          {
3131             /* Fill event and send UE Reconfiguration request to SCH */
3132             ret = sendUeReqToSch(pst, &schUeRecfg);
3133             if(ret != ROK)
3134                DU_LOG("\nERROR  -->  MAC : Failed to send UE Reconfig Request to SCH");
3135          }
3136       }
3137       else 
3138       {
3139          DU_LOG("\nERROR  -->  MAC : Failed to store MAC UE Cb ");
3140       }
3141    }
3142    else
3143    {
3144       DU_LOG("\nERROR  -->  MAC : MAC UE Reconfiguration request processing failed");
3145       ret = RFAILED;
3146    }
3147    /* FREE shared memory */
3148    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueRecfg, sizeof(MacUeRecfg));
3149    return ROK;
3150 }
3151
3152 /*******************************************************************
3153 *
3154 * @brief Fill and Send UE Delete response from MAC to DU APP
3155 *
3156 * @details
3157 *
3158 *    Function : MacSendUeDeleteRsp 
3159 *
3160 *    Functionality: Fill and Send UE Delete response from MAC to DUAPP
3161 *
3162 * @params[in] MAC UE delete result
3163 *             SCH UE delete response
3164 * @return ROK     - success
3165 *         RFAILED - failure
3166 *
3167 * ****************************************************************/
3168
3169 uint8_t MacSendUeDeleteRsp(uint16_t cellId, uint16_t crnti, CauseOfResult  status)
3170 {
3171    MacUeDeleteRsp *deleteRsp;
3172    Pst            rspPst;
3173
3174    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacUeDeleteRsp));
3175    if(!deleteRsp)
3176    {
3177       DU_LOG("\nERROR  -->  MAC : Memory allocation for UE delete response failed");
3178       return RFAILED;
3179    }
3180
3181    /* Filling UE delete response */
3182    deleteRsp->cellId = cellId;
3183    GET_UE_ID(crnti, deleteRsp->ueId);
3184    deleteRsp->status = status;
3185
3186    /* Fill Post structure and send UE delete response*/
3187    memset(&rspPst, 0, sizeof(Pst));
3188    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_DELETE_RSP);
3189    return (*macDuUeDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
3190 }
3191
3192 /*******************************************************************
3193 *
3194 * @brief freeing the Pucch Resrc Cfg 
3195 *
3196 * @details
3197 *
3198 *    Function : deletePucchResourcesCfg 
3199 *
3200 *    Functionality: freeing the Pucch Resrc Cfg
3201 *
3202 * @params[in] PucchResrcCfg *resrcCfg
3203 * @return ROK     - success
3204 *         RFAILED - failure
3205 *
3206 * ****************************************************************/
3207
3208 void deletePucchResourcesCfg(PucchResrcCfg *resrcCfg)
3209 {
3210    uint8_t resrcIdx;
3211    for(resrcIdx =0; resrcIdx< resrcCfg->resrcToAddModListCount;resrcIdx++)
3212    {
3213       switch(resrcCfg->resrcToAddModList[resrcIdx].pucchFormat)
3214       {
3215          case PUCCH_FORMAT_0:
3216          {
3217             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format0, sizeof(PucchFormat0));
3218             break;
3219          }
3220          case PUCCH_FORMAT_1:
3221          {
3222             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format1, sizeof(PucchFormat1));
3223             break;
3224          }
3225          case PUCCH_FORMAT_2:
3226          {
3227             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format2, sizeof(PucchFormat2_3));
3228             break;
3229          }
3230          case PUCCH_FORMAT_3:
3231          {
3232             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format3, sizeof(PucchFormat2_3));
3233             break;
3234          }
3235          case PUCCH_FORMAT_4:
3236          {
3237             MAC_FREE(resrcCfg->resrcToAddModList[resrcIdx].PucchFormat.format4, sizeof(PucchFormat4));
3238             break;
3239          }
3240       }
3241    }
3242
3243 }
3244
3245 /*******************************************************************
3246 *
3247 * @brief  Processes UE delete response from scheduler
3248 *
3249 * @details
3250 *
3251 *    Function : MacProcSchUeDeleteRsp 
3252 *
3253 *    Functionality:
3254 *      Processes UE delete from scheduler
3255 *
3256 * @params[in] Pst : Post structure
3257 *             schUeDelRsp : Scheduler UE delete respons
3258 * @return ROK     - success
3259 *         RFAILED - failure
3260 *
3261 * ****************************************************************/
3262
3263 uint8_t MacProcSchUeDeleteRsp(Pst *pst, SchUeDeleteRsp *schUeDelRsp)
3264 {
3265    uint8_t ueId =0, isCrntiValid = 0, tbIdx =0, idx=0;
3266    uint16_t cellIdx=0;
3267    uint8_t ret = RFAILED;
3268    CauseOfResult  status;
3269    DlHarqEnt  *dlHarqEnt;
3270
3271 #ifdef CALL_FLOW_DEBUG_LOG
3272    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_UE_DELETE_RSP_TO_MAC\n");
3273 #endif   
3274
3275    if(schUeDelRsp)
3276    {
3277       if(schUeDelRsp->rsp == RSP_OK)
3278       {
3279          DU_LOG("\nINFO   -->  MAC : SCH UE Delete response for CRNTI[%d] is successful", schUeDelRsp->crnti);
3280          GET_CELL_IDX(schUeDelRsp->cellId, cellIdx);
3281          if(macCb.macCell[cellIdx])
3282          {
3283             CHECK_CRNTI(schUeDelRsp->crnti, isCrntiValid);
3284             if(!isCrntiValid)
3285             {
3286                /*C-RNTI value is out of Acceptable range*/
3287                DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): Invalid crnti[%d] ",schUeDelRsp->crnti);
3288                status = UEID_INVALID;
3289             }
3290             else
3291             {
3292                GET_UE_ID(schUeDelRsp->crnti, ueId);
3293                if(macCb.macCell[cellIdx]->ueCb[ueId -1].crnti == schUeDelRsp->crnti)
3294                {
3295
3296                   /*Commenting as S-NSSAI and PDU session will be stored in MAC DB in future scope*/
3297 #if 0
3298                   /*Looping around LCs to free S-NSSAI memory*/
3299                   for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueId -1].ulInfo.numUlLc); lcIdx++)
3300                   {
3301                      MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueId -1].ulInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
3302                   }
3303                   for(lcIdx = 0; lcIdx < (macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.numDlLc); lcIdx++)
3304                   {
3305                      MAC_FREE(macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.lcCb[lcIdx].snssai, sizeof(Snssai));
3306                   }
3307 #endif
3308                   dlHarqEnt = &macCb.macCell[cellIdx]->ueCb[ueId -1].dlInfo.dlHarqEnt;
3309                   for(idx =0 ; idx<MAX_NUM_HARQ_PROC; idx++)
3310                   {
3311                      tbIdx = 0;
3312                      while(dlHarqEnt->harqProcCb[idx].numTb)
3313                      {
3314
3315                         MAC_FREE(dlHarqEnt->harqProcCb[idx].tbInfo[tbIdx].tb, dlHarqEnt->harqProcCb[idx].tbInfo[tbIdx].tbSize);
3316                         dlHarqEnt->harqProcCb[idx].numTb--;
3317                         tbIdx++;
3318                      }
3319                   }
3320                   memset(&macCb.macCell[cellIdx]->ueCb[ueId -1], 0, sizeof(MacUeCb));
3321                   macCb.macCell[cellIdx]->numActvUe--;
3322                   status = SUCCESSFUL;
3323                   ret = ROK;
3324                }
3325                else
3326                {
3327                   DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): crnti[%d] does not exist ",schUeDelRsp->crnti);
3328                   status = UEID_INVALID;
3329                }
3330             }
3331          }
3332          else
3333          {
3334             DU_LOG("\nERROR  -->  MAC : MacProcSchUeDeleteRsp(): cellId[%d] does not exist ",schUeDelRsp->cellId);
3335             status = CELLID_INVALID;
3336          }
3337       }
3338       else
3339          status = schUeDelRsp->cause;
3340       
3341       if(MacSendUeDeleteRsp(schUeDelRsp->cellId, schUeDelRsp->crnti, status) != ROK)
3342       {
3343          DU_LOG("\nERROR  -->  MAC: MacProcSchUeDeleteRsp(): Failed to send UE delete response");
3344          ret = RFAILED;
3345       }
3346    }
3347    else
3348    {
3349       DU_LOG("\nERROR  -->  MAC: MacProcSchUeDeleteRsp(): Failed to receive UE delete response by SCH");
3350       ret = RFAILED;
3351    }
3352    return ret;
3353 }
3354
3355 /*******************************************************************
3356 *
3357 * @brief Sends UE delete req to Scheduler
3358 *
3359 * @details
3360 *
3361 *    Function : sendUeDelReqToSch
3362 *
3363 *    Functionality: sends UE delete req to Scheduler
3364 *
3365 * @params[in] Pst *pst,  MacUeDelete *ueDelete
3366 * @return ROK     - success
3367 *         RFAILED - failure
3368 *
3369 * ****************************************************************/
3370
3371 uint8_t sendUeDelReqToSch(Pst *pst, MacUeDelete *ueDelete)
3372 {
3373    if(ueDelete != NULLP)
3374    {
3375       Pst schPst;
3376       SchUeDelete schUeDel;
3377
3378       memset(&schUeDel, 0, sizeof(SchUeDelete));
3379       schUeDel.cellId = ueDelete->cellId;
3380       schUeDel.crnti  = ueDelete->crnti;
3381       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(MacUeDelete));
3382       FILL_PST_MAC_TO_SCH(schPst, EVENT_UE_DELETE_REQ_TO_SCH);
3383       return(SchMessageRouter(&schPst, (void *)&schUeDel));
3384    }
3385    else
3386    {
3387       DU_LOG("\nERROR  --> SCH: sendUeDelReqToSch():MAC Ue Delete is NULL");
3388       return RFAILED;
3389    }
3390    return ROK;
3391 }
3392
3393 /*******************************************************************
3394  *
3395  * @brief Handles UE Delete requst from DU APP
3396  *
3397  * @details
3398  *
3399  *    Function : MacProcUeDeleteReq
3400  *
3401  *    Functionality: Handles UE Delete requst from DU APP
3402  *
3403  * @params[in] Pst *pst, MacUeDelete *ueDelete
3404  * @return ROK     - success
3405  *         RFAILED - failure
3406  *
3407  * ****************************************************************/
3408
3409 uint8_t MacProcUeDeleteReq(Pst *pst, MacUeDelete *ueDelete)
3410 {
3411    uint8_t ret = ROK;
3412    uint8_t cellIdx=0;
3413    CauseOfResult  status =SUCCESSFUL;
3414    MacUeCb  *ueCb = NULLP;
3415    MacCellCb *cellCb = NULLP;
3416
3417    DU_LOG("\nINFO   -->  MAC : UE Delete Request received for ueId[%d]", ueDelete->ueId);
3418
3419    if(ueDelete)
3420    {
3421       GET_CELL_IDX(ueDelete->cellId, cellIdx);     
3422       cellCb = macCb.macCell[cellIdx];
3423       if(cellCb)
3424       {
3425          ueCb = &cellCb->ueCb[ueDelete->ueId-1];
3426          if(ueCb->crnti == ueDelete->crnti)
3427          {
3428             ret = sendUeDelReqToSch(pst, ueDelete);
3429             if(ret != ROK)
3430             {
3431                DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to send UE Delete Request to SCH");
3432                ret = RFAILED;
3433             }
3434          }
3435          else
3436          {
3437             DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): CRNTI is not matched");
3438             status = UEID_INVALID;
3439          }
3440       }
3441       else
3442       {
3443          DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): Failed to find the MacUeCb of UeId = %d",ueDelete->ueId);
3444          status = CELLID_INVALID;
3445       }
3446
3447       if(status!= SUCCESSFUL)
3448       {
3449          MacSendUeDeleteRsp(ueDelete->cellId, ueDelete->crnti, status);
3450          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueDelete, sizeof(MacUeDelete));
3451          ret = RFAILED;
3452       }
3453    }
3454    else
3455    {
3456       DU_LOG("\nERROR  -->  MAC : MacProcUeDeleteReq(): MAC UE delete request processing failed");
3457       ret = RFAILED;
3458    }
3459    return ret;
3460 }
3461
3462 /*******************************************************************
3463 *
3464 * @brief Fill and Send UE Reset response from MAC to DU APP
3465 *
3466 * @details
3467 *
3468 *    Function : MacSendUeResetRsp 
3469 *
3470 *    Functionality: Fill and Send UE Reset response from MAC to DUAPP
3471 *
3472 * @params[in] MAC UE Reset result
3473 *             SCH UE Reset response
3474 * @return ROK     - success
3475 *         RFAILED - failure
3476 *
3477 * ****************************************************************/
3478
3479 uint8_t MacSendUeResetRsp(uint16_t cellId, uint16_t ueId, CauseOfResult  status)
3480 {
3481    MacUeResetRsp *ResetRsp;
3482    Pst            rspPst;
3483
3484    MAC_ALLOC_SHRABL_BUF(ResetRsp, sizeof(MacUeResetRsp));
3485    if(!ResetRsp)
3486    {
3487       DU_LOG("\nERROR  -->  MAC : Memory allocation for UE Reset response failed");
3488       return RFAILED;
3489    }
3490
3491    /* Filling UE Reset response */
3492    ResetRsp->cellId = cellId;
3493    ResetRsp->ueId   = ueId;
3494    ResetRsp->status = status;
3495
3496    /* Fill Post structure and send UE Reset response*/
3497    memset(&rspPst, 0, sizeof(Pst));
3498    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_RESET_RSP);
3499    return (*macDuUeResetRspOpts[rspPst.selector])(&rspPst, ResetRsp);
3500 }
3501
3502 /*******************************************************************
3503  *
3504  * @brief Handles UE Reset request from DU APP
3505  *
3506  * @details
3507  *
3508  *    Function : MacProcUeResetReq
3509  *
3510  *    Functionality: Handles UE Reset requst from DU APP
3511  *
3512  * @params[in] Pst *pst, MacUeResetReq *ueReset
3513  * @return ROK     - success
3514  *         RFAILED - failure
3515  *
3516  * ****************************************************************/
3517
3518 uint8_t MacProcUeResetReq(Pst *pst, MacUeResetReq *ueReset)
3519 {
3520    uint8_t cellIdx=0;
3521    CauseOfResult  status =SUCCESSFUL;
3522    MacUeCb  *ueCb = NULLP;
3523    MacCellCb *cellCb = NULLP;
3524
3525    DU_LOG("\nINFO   -->  MAC : UE Reset Request received for ueId[%d]", ueReset->ueId);
3526
3527    if(ueReset)
3528    {
3529       GET_CELL_IDX(ueReset->cellId, cellIdx);     
3530       cellCb = macCb.macCell[cellIdx];
3531       if(cellCb)
3532       {
3533          ueCb = &cellCb->ueCb[ueReset->ueId-1];
3534          if(ueCb->ueId == ueReset->ueId)
3535          {
3536             /* TODO := complete the processing of UE reset request*/
3537          }
3538          else
3539          {
3540             DU_LOG("\nERROR  -->  MAC : MacProcUeResetReq(): UE ID [%d] not found in Cell Id [%d]", ueCb->ueId , ueReset->cellId);
3541             status = UEID_INVALID;
3542          }
3543       }
3544       else
3545       {
3546          DU_LOG("\nERROR  -->  MAC : MacProcUeResetReq(): Cell Id [%d] not found ",ueReset->cellId);
3547          status = CELLID_INVALID;
3548       }
3549
3550       MacSendUeResetRsp(ueReset->cellId, ueReset->ueId, status);
3551       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueReset, sizeof(MacUeResetReq));
3552    }
3553    else
3554    {
3555       DU_LOG("\nERROR  -->  MAC : MacProcUeResetReq(): MAC UE reset request processing failed");
3556       return  RFAILED;
3557    }
3558    return ROK;
3559 }
3560 /**********************************************************************
3561   End of file
3562  **********************************************************************/