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