[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-530] Handling of Ric action deletion
[o-du/l2.git] / src / 5gnrmac / mac_cfg_hdl.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 /* This file stores handler for MAC and SCH configuration requests */
19 /* header include files (.h) */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "lrg.x"
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "lwr_mac_upr_inf.h"
26 #include "mac.h"
27 #include "rlc_mac_inf.h"
28 #include "mac_upr_inf_api.h"
29 #include "lwr_mac.h"
30 #include "lwr_mac_fsm.h"
31 #include "mac_utils.h"
32 #include "lwr_mac_phy.h"
33
34 uint8_t ssbPeriodicity[6] = {5, 10, 20, 40, 80, 160};
35
36 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg  *macCellCfg);
37
38 packMacCellCfgConfirm packMacCellCfmOpts[] =
39 {
40    packMacCellCfgCfm,      /* packing for loosely coupled */
41    duHandleMacCellCfgCfm,      /* packing for tightly coupled */
42    packMacCellCfgCfm,    /* packing for light weight loosly coupled */
43 };
44
45 MacDuCellDeleteRspFunc macDuCellDeleteRspOpts[] =
46 {
47    packDuMacCellDeleteRsp,   /* packing for loosely coupled */
48    DuProcMacCellDeleteRsp,   /* packing for tightly coupled */
49    packDuMacCellDeleteRsp   /* packing for light weight loosly coupled */
50 };
51
52 MacDuSliceCfgRspFunc macDuSliceCfgRspOpts[] =
53 {
54    packDuMacSliceCfgRsp,   /* packing for loosely coupled */
55    DuProcMacSliceCfgRsp,   /* packing for tightly coupled */
56    packDuMacSliceCfgRsp   /* packing for light weight loosly coupled */
57 };
58
59 MacDuSliceRecfgRspFunc macDuSliceRecfgRspOpts[] =
60 {
61    packDuMacSliceRecfgRsp,   /* packing for loosely coupled */
62    DuProcMacSliceRecfgRsp,   /* packing for tightly coupled */
63    packDuMacSliceRecfgRsp    /* packing for light weight loosly coupled */
64 };
65
66 MacDuStatsRspFunc macDuStatsRspOpts[] =
67 {
68    packDuMacStatsRsp,   /* packing for loosely coupled */
69    DuProcMacStatsRsp,   /* packing for tightly coupled */
70    packDuMacStatsRsp   /* packing for light weight loosly coupled */
71 };
72
73 MacDuStatsDeleteRspFunc macDuStatsDeleteRspOpts[] =
74 {
75    packDuMacStatsDeleteRsp,   /* packing for loosely coupled */
76    DuProcMacStatsDeleteRsp,   /* packing for tightly coupled */
77    packDuMacStatsDeleteRsp   /* packing for light weight loosly coupled */
78 };
79
80 /**
81  * @brief Layer Manager  Configuration request handler for Scheduler
82  *
83  * @details
84  *
85  *     Function : MacSchGenCfgReq
86  *
87  *     This function receives general configurations for Scheduler
88  *     from DU APP and forwards to Scheduler.
89  *
90  *  @param[in]  Pst *pst, the post structure
91  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
92  *  @return 
93  *      -# ROK
94  **/
95 uint8_t MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
96 {
97    Pst schPst;
98
99    DU_LOG("\nINFO  -->  MAC : Received Scheduler gen config at MAC");
100    memset(&schPst, 0, sizeof(Pst));
101    FILL_PST_MAC_TO_SCH(schPst, EVENT_SCH_GEN_CFG);
102    
103    return(SchMessageRouter(&schPst, (void *)cfg));
104 }
105
106 /**
107  * @brief Layer Manager Configuration response from Scheduler
108  *
109  * @details
110  *
111  *     Function : SchSendCfgCfm
112  *
113  *     This function sends general configurations response from
114  *     Scheduler to DU APP.
115  *
116  *  @param[in]  Pst *pst, the post structure
117  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
118  *  @return 
119  *      -# ROK
120  **/
121 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt  *cfm)
122 {
123    DU_LOG("\nDEBUG  -->  MAC : Sending Scheduler config confirm to DU APP");
124    pst->dstEnt = ENTDUAPP;
125    pst->dstInst = 0;
126    pst->srcInst = 0;
127    pst->selector = ODU_SELECTOR_LC;
128    RgMiLrgSchCfgCfm(pst, cfm);
129
130    return ROK;
131 }
132
133 /**
134  * @brief Layer Manager Configuration request handler.
135  *
136  * @details
137  *
138  *     Function : MacProcCellCfgReq
139  *
140  *     This function handles the gNB and cell configuration
141  *     request received from DU APP.
142  *     This API unapcks and forwards the config towards SCH
143  *
144  *  @param[in]  Pst           *pst
145  *  @param[in]  MacCellCfg    *macCellCfg
146  *  @return  
147  *      -# ROK
148  **/
149 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
150 {
151    Pst cfmPst;
152    uint16_t cellIdx, scsInKhz = 0;
153    uint8_t ret = ROK, plmnIdx = 0,sliceIdx = 0;
154    MacCellCb     *macCellCb;
155
156    memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
157
158    MAC_ALLOC(macCellCb, sizeof(MacCellCb));
159    if(macCellCb == NULLP)
160    {
161       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of macCellCfg\n");
162       return RFAILED;
163    }
164    memset(macCellCb, 0, sizeof(MacCellCb));
165
166    GET_CELL_IDX(macCellCfg->cellId, cellIdx);
167    macCb.macCell[cellIdx] = macCellCb;
168    macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
169    scsInKhz = convertScsEnumValToScsVal(macCellCfg->cellCfg.subCarrSpacing);
170    
171    /*Ref : 3GPP 38.211 Table 4.2-1: SCS = (2 ^ numerology * 15kHz)*/
172    macCb.macCell[cellIdx]->numerology = log2(scsInKhz/BASE_SCS);
173    macCb.macCell[cellIdx]->numOfSlots = 10 * (1 << (macCb.macCell[cellIdx]->numerology));
174    memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
175
176    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, \
177          macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
178    if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu == NULLP)
179    {
180       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
181       return RFAILED;
182    }
183    memcpy(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, macCellCfg->cellCfg.sib1Cfg.sib1Pdu, \
184          macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
185
186    for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
187    {
188       macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice = macCellCfg->cellCfg.plmnInfoList[plmnIdx].numSupportedSlice;
189       MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai, macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice\
190             * sizeof(Snssai*));
191       if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai == NULLP)
192       {
193          DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
194          return RFAILED;
195       }
196
197       if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai)
198       {
199          for(sliceIdx=0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice; sliceIdx++)
200          {
201             if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
202             {
203                MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
204                if(!macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
205                {
206                   DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
207                   return RFAILED;
208                }
209                memcpy(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx],\
210                      sizeof(Snssai));
211             }
212          }
213       }
214    }
215    /* Send cell cfg to scheduler */
216    ret = MacSchCellCfgReq(pst, macCellCfg);
217    if(ret != ROK)
218    {
219       MacCellCfgCfm macCellCfgCfm;
220       macCellCfgCfm.rsp = RSP_NOK;
221       macCellCfgCfm.cellId = macCellCfg->cellId;
222       /* Fill Pst */
223       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
224       cfmPst.selector  = ODU_SELECTOR_LC;
225
226       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
227    }
228    else
229    {
230       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
231    }
232    return ret;
233 } /* end of MacProcCellCfgReq */
234
235 /**
236  * @brief Layer Manager Configuration request handler.
237  *
238  * @details
239  *
240  *     Function : MacSchCellCfgReq
241  *
242  *     This function sends cell configuration to SCH
243  *
244  *  @param[in]  Pst           *pst
245  *  @param[in]  MacCellCfg    *macCellCfg
246  *  @return  
247  *      -# ROK
248  **/
249 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
250 {
251    SchCellCfg schCellCfg;
252    Pst        cfgPst;
253    uint8_t    ssbMaskIdx = 0, rsrcListIdx = 0, sliceIdx=0, plmnIdx = 0;
254
255    memset(&cfgPst, 0, sizeof(Pst));
256    memset(&schCellCfg, 0, sizeof(SchCellCfg));
257    schCellCfg.cellId = macCellCfg->cellId;
258    schCellCfg.phyCellId = macCellCfg->cellCfg.phyCellId;
259
260    for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
261    {
262       schCellCfg.plmnInfoList[plmnIdx].plmn = macCellCfg->cellCfg.plmnInfoList[plmnIdx].plmn;
263       if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai) 
264       {
265          schCellCfg.plmnInfoList[plmnIdx].numSliceSupport = macCellCfg->cellCfg.plmnInfoList[plmnIdx].numSupportedSlice;
266          MAC_ALLOC(schCellCfg.plmnInfoList[plmnIdx].snssai, schCellCfg.plmnInfoList[plmnIdx].numSliceSupport * sizeof(Snssai*));
267          if(!schCellCfg.plmnInfoList[plmnIdx].snssai)
268          {
269             DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
270             return RFAILED;
271          }
272          for(sliceIdx=0; sliceIdx<schCellCfg.plmnInfoList[plmnIdx].numSliceSupport; sliceIdx++)
273          {
274             if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
275             {
276                MAC_ALLOC(schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
277                if(!schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
278                {
279                   DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
280                   return RFAILED;
281                }
282                memcpy(schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx],  sizeof(Snssai));
283             }
284          }
285       }
286    }
287
288    schCellCfg.dupMode = macCellCfg->cellCfg.dupType;
289    schCellCfg.dlBandwidth = macCellCfg->carrCfg.dlBw;
290    schCellCfg.ulBandwidth = macCellCfg->carrCfg.ulBw;
291
292    schCellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
293    schCellCfg.dlCfgCommon.schFreqInfoDlSib.schSpcCarrier[0].subCarrierSpacing = macCellCfg->ssbCfg.scsCmn;
294
295    /* fill initial DL BWP */
296    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->cellCfg.initialDlBwp.bwp.firstPrb;
297    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->cellCfg.initialDlBwp.bwp.numPrb;
298    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.scs = macCellCfg->cellCfg.initialDlBwp.bwp.scs;
299    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->cellCfg.initialDlBwp.bwp.cyclicPrefix;
300    
301    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
302       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
303    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
304       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
305    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
306       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
307    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
308       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.duration;
309    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
310       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
311    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
312       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
313    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
314       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
315    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
316       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
317    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
318       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
319    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
320       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
321    
322    schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->cellCfg.initialDlBwp.pdschCommon.numTimeDomAlloc;
323    for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->cellCfg.initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
324    {
325       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 = 
326          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
327       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
328          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
329       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
330          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
331       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
332          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
333    }
334
335    /* fill SIB1 scheduler parameters */
336    schCellCfg.dlCfgCommon.schPcchCfg.numPO  =  macCellCfg->cellCfg.sib1Cfg.pagingCfg.numPO;
337    schCellCfg.dlCfgCommon.schPcchCfg.poPresent = macCellCfg->cellCfg.sib1Cfg.pagingCfg.poPresent;
338    if(schCellCfg.dlCfgCommon.schPcchCfg.poPresent)
339    {
340       memcpy(schCellCfg.dlCfgCommon.schPcchCfg.pagingOcc, macCellCfg->cellCfg.sib1Cfg.pagingCfg.pagingOcc, MAX_PO_PER_PF);
341    }
342
343    /* fill initial UL BWP */
344    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->cellCfg.initialUlBwp.bwp.firstPrb;
345    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->cellCfg.initialUlBwp.bwp.numPrb;
346    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.scs = macCellCfg->cellCfg.initialUlBwp.bwp.scs;
347    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->cellCfg.initialUlBwp.bwp.cyclicPrefix;
348    /* fill RACH config params */
349    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.prachCfgIdx   = macCellCfg->prachCfg.prachCfgIdx;
350    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
351    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
352    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.zeroCorrZoneCfg = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg; 
353    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.raRspWindow = macCellCfg->prachCfg.raRspWindow;
354
355    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.totalNumRaPreamble = macCellCfg->prachCfg.totalNumRaPreamble;
356    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
357    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.numCbPreamblePerSsb = macCellCfg->prachCfg.numCbPreamblePerSsb;
358    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.raContResTmr = macCellCfg->prachCfg.raContResTmr;
359    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
360    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
361    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
362    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.msg1SubcSpacing = \
363                                             macCellCfg->prachCfg.prachSubcSpacing;
364
365    schCellCfg.ulCfgCommon.schInitialUlBwp.pucchCommon.pucchResourceCommon = \
366                                                                 macCellCfg->cellCfg.initialUlBwp.pucchCommon.pucchResourceCommon;
367    schCellCfg.ulCfgCommon.schInitialUlBwp.pucchCommon.pucchGroupHopping = \
368                                                                 macCellCfg->cellCfg.initialUlBwp.pucchCommon.pucchGroupHopping;
369    schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
370                                                                 macCellCfg->cellCfg.initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
371    for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->cellCfg.initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
372    {
373       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 = 
374          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
375       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
376          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
377       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
378          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
379       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
380          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
381    }
382
383 #ifdef NR_TDD
384    memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
385 #endif
386
387    /* fill ssb scheduler parameters */
388    for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
389    {
390       schCellCfg.ssbPosInBurst[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
391    }
392    schCellCfg.ssbPeriod    = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
393    schCellCfg.ssbFrequency = macCellCfg->cellCfg.ssbFreq;
394    schCellCfg.dmrsTypeAPos = macCellCfg->ssbCfg.dmrsTypeAPos;
395    schCellCfg.ssbScs       = macCellCfg->cellCfg.subCarrSpacing;
396    schCellCfg.pdcchCfgSib1.coresetZeroIndex = macCellCfg->cellCfg.sib1Cfg.pdcchCfgSib1.coresetZeroIndex;
397    schCellCfg.pdcchCfgSib1.searchSpaceZeroIndex = macCellCfg->cellCfg.sib1Cfg.pdcchCfgSib1.searchSpaceZeroIndex;
398    schCellCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
399    schCellCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
400    schCellCfg.sib1PduLen = macCellCfg->cellCfg.sib1Cfg.sib1PduLen;
401    
402    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
403
404    return(SchMessageRouter(&cfgPst, (void *)&schCellCfg));
405 } /* end of MacSchCellCfgReq */
406
407
408 /*******************************************************************
409  *
410  * @brief Sends Cell config confirm to DU APP
411  *
412  * @details
413  *
414  *    Function : MacSendCellCfgCfm
415  *
416  *    Functionality:
417  *      Sends Cell config confirm to DU APP
418  *
419  * @params[in] Response status
420  * @return void
421  *
422  * ****************************************************************/
423 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
424 {
425    Pst pst;
426    uint16_t   cellIdx;
427    MacCellCfgCfm macCellCfgCfm;
428
429    memset(&pst, 0, sizeof(Pst));
430
431    GET_CELL_IDX(cellId, cellIdx);
432    macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
433    macCellCfgCfm.rsp = response;
434
435    /* Fill Pst */
436    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
437    pst.selector  = ODU_SELECTOR_LC;
438
439    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
440 }
441
442
443 /**
444  * @brief Layer Manager Configuration response handler.
445  *
446  * @details
447  *
448  *     Function : MacProcSchCellCfgCfm
449  *
450  *     This function processes cell configuration to SCH
451  *
452  *  @param[in]  Pst           *pst
453  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
454  *  @return  int
455  *      -# ROK
456  **/
457 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
458 {
459    uint16_t *cellId = NULLP;
460
461 #ifdef CALL_FLOW_DEBUG_LOG
462    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_SCH_CELL_CFG_CFM\n");
463 #endif
464
465    if(schCellCfgCfm->rsp == RSP_OK)
466    {
467       cellId = &schCellCfgCfm->cellId;
468 #ifdef INTEL_TIMER_MODE
469       sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
470 #else
471       sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
472 #endif
473    }
474    else
475    {
476       MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
477    }
478    return ROK;
479 }
480
481 /*******************************************************************
482  *
483  * @brief MAC handler for config response from PHY
484  *
485  * @details
486  *
487  *    Function : fapiMacConfigRsp
488  *
489  *    Functionality:
490  *     Processes config response from PHY and sends cell config
491  *     confirm to DU APP
492  *
493  * @params[in]
494  * @return void
495  *
496  * ****************************************************************/
497 void fapiMacConfigRsp(uint16_t cellId)
498 {
499    /* TODO : Processing of config response from PHY */
500
501    /* Send cell config cfm to DU APP */
502    MacSendCellCfgCfm(cellId, RSP_OK);
503 }
504
505 /*******************************************************************
506  *
507  * @brief Fill and Send Cell Delete response from MAC to DU APP
508  *
509  * @details
510  *
511  *    Function : MacSendCellDeleteRsp
512  *
513  *    Functionality: Fill and Send Cell Delete response from MAC to DUAPP
514  *
515  * @params[in] MAC Cell delete result
516  *             SCH Cell delete response
517  * @return ROK     - success
518  *         RFAILED - failure
519  *
520  * ****************************************************************/
521 uint8_t MacSendCellDeleteRsp(CauseOfResult  status, uint8_t cellId)
522 {
523    MacCellDeleteRsp *deleteRsp=NULLP;
524    Pst            rspPst;
525
526    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
527    if(!deleteRsp)
528    {
529       DU_LOG("\nERROR  -->  MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
530       return RFAILED;
531    }
532
533    /* Filling CELL delete response */
534    
535    memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
536    deleteRsp->cellId = cellId;
537    deleteRsp->status = status;
538
539    /* Fill Post structure and send CELL delete response*/
540    memset(&rspPst, 0, sizeof(Pst));
541    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
542    return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
543 }
544
545 /*******************************************************************
546  *
547  * @brief  Processes CELL delete response from scheduler
548  *
549  * @details
550  *
551  *    Function : MacProcSchCellDeleteRsp
552  *
553  *    Functionality:
554  *      Processes CELL delete from scheduler
555  *
556  * @params[in] Pst : Post structure
557  *             schCellDelRsp : Scheduler CELL delete respons
558  * @return ROK     - success
559  *         RFAILED - failure
560  *
561  * * ****************************************************************/
562 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
563 {
564    uint8_t  ret = ROK, sliceIdx = 0, plmnIdx = 0;
565    uint16_t cellIdx=0;
566    CauseOfResult  cause;
567
568 #ifdef CALL_FLOW_DEBUG_LOG
569    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_CELL_DELETE_RSP_TO_MAC\n");
570 #endif  
571
572    if(schCellDelRsp)
573    {
574       if(schCellDelRsp->rsp == RSP_OK)
575       {
576          DU_LOG("\nINFO   -->  MAC : SCH CELL Delete response for cellId[%d] is successful ", \
577                schCellDelRsp->cellId);
578          GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
579          if(macCb.macCell[cellIdx])
580          {
581             if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
582             {
583                cause = SUCCESSFUL;
584                for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
585                {
586                   if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai)
587                   {
588                      for(sliceIdx = 0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice; sliceIdx++)
589                      {
590                         MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
591                      }
592                      MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai, macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].\
593                            numSupportedSlice * sizeof(Snssai*));
594                   }
595                }
596                MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, \
597                      macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
598                MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
599             }
600             else
601             {
602                DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
603                cause = CELLID_INVALID;
604                ret = RFAILED;
605             }
606          }
607          else
608          {
609             DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
610             cause = CELLID_INVALID;
611             ret = RFAILED;
612          }
613       }
614       else
615       {
616          DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
617          cause = CELLID_INVALID;
618          ret = RFAILED;
619       }
620       if(MacSendCellDeleteRsp(cause, schCellDelRsp->cellId) != ROK)
621       {
622          DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
623          ret = RFAILED;
624       }
625
626    }
627    else
628    {
629       DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
630       ret = RFAILED;
631    }
632    return ret;
633 }
634
635 /*******************************************************************
636  *
637  * @brief Sends Cell delete req to Scheduler
638  *
639  * @details
640  *
641  *    Function : sendCellDelReqToSch
642  *
643  *    Functionality: sends Cell delete req to Scheduler
644  *
645  * @params[in]  SchCellDelete *schCellDel
646  * @return ROK     - success
647  *         RFAILED - failure
648  *
649  * ****************************************************************/
650
651 uint8_t sendCellDelReqToSch(SchCellDeleteReq *schCellDelReq)
652 {
653    Pst schPst;
654    FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
655    return(SchMessageRouter(&schPst, (void *)schCellDelReq));
656 }
657
658 /*******************************************************************
659  *
660  * @brief Handles CELL Delete requst from DU APP
661  *
662  * @details
663  *
664  *    Function : MacProcCellDeleteReq
665  *
666  *    Functionality: Handles CELL Delete requst from DU APP
667  *
668  * @params[in] Pst *pst, MacCellDelete *cellDelete
669  * @return ROK     - success
670  *         RFAILED - failure
671  *
672  *
673  * ****************************************************************/
674 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDeleteReq *cellDelete)
675 {
676    uint8_t ret = ROK, cellIdx=0;
677    SchCellDeleteReq schCellDelete;
678
679    DU_LOG("\nINFO   -->  MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
680
681    if(cellDelete)
682    {
683       GET_CELL_IDX(cellDelete->cellId, cellIdx);
684       if(macCb.macCell[cellIdx])
685       {
686          if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
687          {
688             memset(&schCellDelete, 0, sizeof(SchCellDeleteReq ));
689             schCellDelete.cellId =  cellDelete->cellId;
690             ret = sendCellDelReqToSch(&schCellDelete);
691             if(ret != ROK)
692             {
693                DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
694                ret = RFAILED;
695             }
696          }
697          else
698          {
699             DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
700             cellDelete->cellId);
701             ret = RFAILED;
702          }
703       }
704       else
705       {
706          DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
707                cellDelete->cellId);
708          ret = RFAILED;
709       }
710
711       if(ret == RFAILED)
712       {
713           DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Sending failure response to DU");
714           if(MacSendCellDeleteRsp(CELLID_INVALID, cellDelete->cellId) != ROK)
715           {
716              DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
717              cellDelete->cellId);
718           }
719
720       }
721       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDeleteReq));
722    }
723    else
724    {
725       DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
726       ret = RFAILED;
727    }
728    return ret;
729 }
730
731 /**
732  * @brief free the temporary slice cfg stored in macCb.
733  *
734  * @details
735  *
736  *     Function : freeMacSliceCfgReq 
737  *
738  *   free the temporary slice cfg stored in macCb
739  *
740  *  @param[in]  
741  *  @return  int
742  *      -# ROK
743  **/
744 void freeMacSliceCfgReq(MacSliceCfgReq *cfgReq,Pst *pst)
745 {
746     uint8_t policyIdx = 0, memberListIdx=0;
747
748     if(cfgReq->numOfRrmPolicy)
749     {
750        if(cfgReq->listOfRrmPolicy)
751        {
752           for(policyIdx = 0; policyIdx<cfgReq->numOfRrmPolicy; policyIdx++)
753           {
754              if(cfgReq->listOfRrmPolicy[policyIdx])
755              {
756                 if(cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem)
757                 {
758                    if(cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList)
759                    {
760                       for(memberListIdx = 0; memberListIdx<cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem; memberListIdx++)
761                       {
762                          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList[memberListIdx], sizeof(RrmPolicyMemberList));
763                       }
764                       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList,\
765                       cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem * sizeof(RrmPolicyMemberList*));
766                    }
767                 }
768                 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx], sizeof(MacSliceRrmPolicy));
769              }
770           }
771           MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy, cfgReq->numOfRrmPolicy  * sizeof(MacSliceRrmPolicy*));
772        }
773     }
774
775 }
776
777 /**
778  * @brief send slice cfg response to duapp.
779  *
780  * @details
781  *
782  *     Function : MacSendSliceConfigRsp
783  *
784  *   sends  slice cfg response to duapp
785  *
786  *  @param[in] MacSliceCfgRsp macSliceCfgRsp 
787  *  @return  int
788  *      -# ROK
789  **/
790 uint8_t MacSendSliceConfigRsp(MacSliceCfgRsp *macSliceCfgRsp)
791 {
792     Pst  rspPst;
793     
794     memset(&rspPst, 0, sizeof(Pst));
795     FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_CFG_RSP);
796     return (*macDuSliceCfgRspOpts[rspPst.selector])(&rspPst, macSliceCfgRsp);
797
798 }
799
800 /**
801  * @brief Mac process the slice cfg rsp received from sch.
802  *
803  * @details
804  *
805  *     Function : MacProcSchSliceCfgRsp 
806  *
807  *     This function  process the slice cfg rsp received from sch
808  *
809  *  @param[in]  Pst           *pst
810  *  @param[in]  SchSliceCfgRsp *sliceCfgrsp
811  *  @return  int
812  *      -# ROK
813  **/
814
815 uint8_t MacProcSchSliceCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceCfgRsp)
816 {
817    MacSliceCfgRsp *macSliceCfgRsp = NULLP;
818
819    if(schSliceCfgRsp)
820    {
821       MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp, sizeof(MacSliceCfgRsp));
822       if(macSliceCfgRsp == NULLP)
823       {
824           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceCfgRsp");
825           return RFAILED;
826       }
827       macSliceCfgRsp->snssai = schSliceCfgRsp->snssai;
828       if(schSliceCfgRsp->rsp == RSP_OK)
829          macSliceCfgRsp->rsp    = MAC_DU_APP_RSP_OK;
830       else
831       {
832          macSliceCfgRsp->rsp    = MAC_DU_APP_RSP_NOK;
833       }
834       macSliceCfgRsp->cause  = schSliceCfgRsp->cause;
835       MacSendSliceConfigRsp(macSliceCfgRsp);
836    }
837    return ROK;
838 }
839
840 /**
841  * @brief send slice cfg response to duapp.
842  *
843  * @details
844  *
845  *     Function : MacSendSliceReconfigRsp 
846  *
847  *   sends  slice cfg response to duapp
848  *
849  *  @param[in] MacSliceRecfgRsp macSliceRecfgRsp
850  *  @return  int
851  *      -# ROK
852  **/
853 uint8_t MacSendSliceReconfigRsp(MacSliceRecfgRsp *macSliceRecfgRsp)
854 {
855    Pst  rspPst;
856
857    memset(&rspPst, 0, sizeof(Pst));
858    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_RECFG_RSP);
859    return (*macDuSliceRecfgRspOpts[rspPst.selector])(&rspPst, macSliceRecfgRsp);
860
861 }
862
863 /**
864  * @brief Mac process the slice cfg rsp received from sch.
865  *
866  * @details
867  *
868  *     Function : MacProcSchSliceRecfgRsp 
869  *
870  *     This function  process the slice cfg rsp received from sch
871  *
872  *  @param[in]  Pst           *pst
873  *  @param[in]  SchSliceCfgRsp *schSliceRecfgRsp
874  *  @return  int
875  *      -# ROK
876  **/
877 uint8_t MacProcSchSliceRecfgRsp(Pst *pst, SchSliceRecfgRsp *schSliceRecfgRsp)
878 {
879    MacSliceRecfgRsp *macSliceRecfgRsp = NULLP;
880
881    if(schSliceRecfgRsp)
882    {
883       MAC_ALLOC_SHRABL_BUF(macSliceRecfgRsp, sizeof(MacSliceRecfgRsp));
884       if(macSliceRecfgRsp == NULLP)
885       {
886           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceRecfgRsp");
887           return RFAILED;
888       }
889
890       macSliceRecfgRsp->snssai = schSliceRecfgRsp->snssai;
891       if(schSliceRecfgRsp->rsp == RSP_OK)
892          macSliceRecfgRsp->rsp    = MAC_DU_APP_RSP_OK;
893       else
894       {
895          macSliceRecfgRsp->rsp    = MAC_DU_APP_RSP_NOK;
896       }
897       macSliceRecfgRsp->cause  = schSliceRecfgRsp->cause;
898       MacSendSliceReconfigRsp(macSliceRecfgRsp);
899    }
900    return ROK;
901 }
902
903 /**
904  * @brief Mac process the downlink pcch indication received from DUAPP
905  *
906  * @details
907  *
908  *     Function : MacProcDlPcchInd 
909  *
910  *     This function process the downlink pcch indication received from DUAPP
911  *
912  *  @param[in]  Pst           *pst
913  *  @param[in]  DlPcchInd    *pcchInd 
914  *  @return  int
915  *      -# ROK
916  **/
917 uint8_t MacProcDlPcchInd(Pst *pst, DlPcchInd *pcchInd)
918 {
919    uint8_t ret = RFAILED;
920    uint16_t cellIdx = 0;
921    Pst       schPst;
922    SchPageInd *schPageInd = NULLP;
923
924    if(pcchInd)
925    {
926       DU_LOG("\nINFO   -->  MAC : Received DL PCCH IND from DU_APP for cellId[%d]", pcchInd->cellId);
927       
928       GET_CELL_IDX(pcchInd->cellId, cellIdx);
929
930       if(macCb.macCell[cellIdx] == NULLP || macCb.macCell[cellIdx]->cellId != pcchInd->cellId)
931       {
932          DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): CellId[%d] does not exist", pcchInd->cellId);
933       }
934       else
935       {
936          if((pcchInd->pcchPdu == NULLP) || (pcchInd->pduLen <= 0))
937          {
938             DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Received Pcch pdu is null");
939          }
940          else
941          {
942             MAC_ALLOC(schPageInd, sizeof(SchPageInd));
943             if(schPageInd == NULLP)
944             {
945                DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Failed to allocate memory");
946             }
947             else
948             {
949                schPageInd->cellId = pcchInd->cellId;
950                schPageInd->pf = pcchInd->pf;
951                schPageInd->i_s = pcchInd->i_s;
952                schPageInd->pduLen = pcchInd->pduLen;
953                
954                MAC_ALLOC(schPageInd->pagePdu, pcchInd->pduLen);
955                if(schPageInd->pagePdu == NULLP)
956                {
957                   DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Failed to allocate memory");
958                   MAC_FREE(schPageInd, sizeof(SchPageInd));
959                }
960                else
961                {
962                   memcpy(schPageInd->pagePdu, pcchInd->pcchPdu, pcchInd->pduLen);
963
964                   FILL_PST_MAC_TO_SCH(schPst, EVENT_PAGING_IND_TO_SCH);
965                   ret = SchMessageRouter(&schPst, (void *)schPageInd);
966                }
967             }
968          }
969       }
970       if((pcchInd->pcchPdu) && (pcchInd->pduLen > 0))
971       {
972          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd->pcchPdu, pcchInd->pduLen);
973       }
974       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd, sizeof(DlPcchInd));
975    }
976    else
977    {
978       DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Received Null pointer");
979    }
980    return ret;
981 }
982
983 /**
984  * @brief Mac process the downlink Broadcast Req received from DUAPP
985  *
986  * @details
987  *
988  *     Function : MacProcDlBroadcastReq 
989  *
990  *     This function process the downlink Broadcast Req received from DUAPP
991  *
992  *  @param[in]  Pst           *pst
993  *  @param[in]  DlBroadcastReq    *dlBroadcastReq 
994  *  @return  int
995  *      -# ROK
996  **/
997 uint8_t MacProcDlBroadcastReq(Pst *pst, MacDlBroadcastReq *dlBroadcastReq)
998 {
999    uint8_t ret = ROK, idx=0;
1000    uint16_t cellIdx = 0;
1001
1002    if(dlBroadcastReq)
1003    {
1004       DU_LOG("\nINFO   -->  MAC : Received DL braodcast req from DU_APP for cellId[%d]", dlBroadcastReq->cellId);
1005       
1006       GET_CELL_IDX(dlBroadcastReq->cellId, cellIdx);
1007
1008       if(macCb.macCell[cellIdx] == NULLP || macCb.macCell[cellIdx]->cellId != dlBroadcastReq->cellId)
1009       {
1010          ret = RFAILED;
1011          DU_LOG("\nERROR  -->  MAC : MacProcDlBroadcastReq(): CellId[%d] does not exist", dlBroadcastReq->cellId);
1012       }
1013       else
1014       {
1015          /*TODO - Complete the processing of DL Broadcast Request*/
1016       }
1017       for(idx = 0; idx<dlBroadcastReq->numSiBlock; idx++)
1018       {
1019          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlBroadcastReq->siSchedulingInfo[idx]->siAreaID, sizeof(uint8_t));
1020          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlBroadcastReq->siSchedulingInfo[idx], sizeof(SiSchedulingInfo));
1021       }
1022       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlBroadcastReq, sizeof(MacDlBroadcastReq));
1023    }
1024    else
1025    {
1026       ret = RFAILED;
1027       DU_LOG("\nERROR  -->  MAC : MacProcDlBroadcastReq(): Received Null pointer");
1028    }
1029    return ret;
1030 }
1031
1032 /**
1033  * @brief Fill and send statistics response to DU APP
1034  *
1035  * @details
1036  *
1037  *     Function : MacSendStatsRspToDuApp
1038  *
1039  *     Fill and send statistics response to DU APP
1040  *
1041  *  @param[in]  Response
1042  *  @param[in]  Cause of response
1043  *  @return  int
1044  *      -# ROK
1045  **/
1046 uint8_t MacSendStatsRspToDuApp(MacStatsRsp *statsRsp)
1047 {
1048    uint8_t ret = ROK;
1049    Pst  pst;
1050    MacStatsRsp *macStatsRsp = NULLP;
1051
1052     DU_LOG("\nINFO  -->  MAC : MacSendStatsRspToDuApp: Sending Statistics Response to DU APP");
1053
1054    /* Workaround : To skip corrupted memory, allocating a pointer that will
1055     * remain unused */
1056    uint8_t *dummyPtr = NULLP;
1057    MAC_ALLOC_SHRABL_BUF(dummyPtr, sizeof(uint8_t));
1058
1059    MAC_ALLOC_SHRABL_BUF(macStatsRsp, sizeof(MacStatsRsp));
1060    if(macStatsRsp == NULLP)
1061    {
1062       DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchStatsRsp");
1063       ret = RFAILED;
1064    }
1065    else
1066    {
1067       memcpy(macStatsRsp, statsRsp, sizeof(MacStatsRsp));
1068       memset(statsRsp, 0, sizeof(MacStatsRsp));
1069
1070       memset(&pst, 0, sizeof(Pst));
1071       FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_STATISTICS_RSP);
1072       if(((*macDuStatsRspOpts[pst.selector])(&pst, macStatsRsp))!= ROK)
1073       {
1074          DU_LOG("\nERROR  -->  MAC : Failed to send statistics response to DU APP");
1075          MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, macStatsRsp, sizeof(MacStatsRsp));
1076          ret = RFAILED;
1077       }
1078    }
1079
1080    /* Workaround : Freeing the dummy pointer */
1081    MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, dummyPtr, sizeof(uint8_t));
1082    return ret;
1083 }
1084
1085 /*******************************************************************
1086  *
1087  * @brief Rejects all statistics group requested by DU APP
1088  *
1089  * @details
1090  *
1091  *    Function : MacRejectAllStats
1092  *
1093  *    Functionality: Add all statistics group received in statistics
1094  *       request from DU APP, to Reject-Stats-Group-List in statistics
1095  *       response to DU APP
1096  *
1097  * @params[in]  Statistics request from DU APP
1098  *              Cause of rejection
1099  * @return ROK     - success
1100  *         RFAILED - failure
1101  *
1102  * ****************************************************************/
1103 uint8_t MacRejectAllStats(MacStatsReq *macStatsReq, CauseOfResult cause)
1104 {
1105    uint8_t grpIdx = 0;
1106    MacStatsRsp macStatsRsp;
1107
1108    memset(&macStatsRsp, 0, sizeof(MacStatsRsp));
1109
1110    /* Copying all stats group from stats request to stats response */
1111    macStatsRsp.subscriptionId = macStatsReq->subscriptionId;
1112    for(grpIdx = 0; grpIdx < macStatsReq->numStatsGroup; grpIdx++)
1113    {
1114       macStatsRsp.statsGrpRejectedList[grpIdx].groupId = macStatsReq->statsGrpList[grpIdx].groupId;
1115       macStatsRsp.statsGrpRejectedList[grpIdx].cause = cause;
1116    }
1117    macStatsRsp.numGrpRejected = macStatsReq->numStatsGroup;
1118
1119    return MacSendStatsRspToDuApp(&macStatsRsp);
1120 }
1121
1122 /**
1123  * @brief Mac process the statistics Req received from DUAPP
1124  *
1125  * @details
1126  *
1127  *     Function : MacProcStatsReq
1128  *
1129  *     This function process the statistics request from duapp:
1130  *     [Step 1] Basic validation. If fails, all stats group in stats request are
1131  *     rejected.
1132  *     [Step 2] If basic validations passed, traverse all stats group and
1133  *     validate each measurement types in each group.
1134  *     [Step 3] If any measurement type validation fails in a group, that group 
1135  *     is not configured and it is added to stats-group-rejected-list in
1136  *     mac-stats-response message.
1137  *     [Step 4] Even if one group passes all validation, it is sent to SCH in
1138  *     statistics request. The mac-stats-response message is added to
1139  *     pending-response list. This will be sent to DU APP after stats response
1140  *     is received from SCH.
1141  *     [Step 5] If none of the groups passes all validation, mac-stats-response
1142  *     is sent to du app with all group as part of stats-group-rejected-list.
1143  *
1144  *  @param[in]  Pst      *pst
1145  *  @param[in]  StatsReq *statsReq
1146  *  @return  int
1147  *      -# ROK
1148  **/
1149 uint8_t MacProcStatsReq(Pst *pst, MacStatsReq *macStatsReq)
1150 {
1151    uint8_t       macStatsGrpIdx = 0, macStatsIdx = 0, schStatsGrpIdx = 0, schStatsIdx = 0;
1152    uint8_t       ret = RFAILED;
1153    bool          measTypeInvalid = false;
1154    Pst           schPst;
1155    MacStatsGrpInfo *macStatsGrp = NULLP;
1156    SchStatsReq     *schStatsReq = NULLP;
1157    MacStatsRsp     *macStatsRsp = NULLP;
1158
1159    DU_LOG("\nINFO   -->  MAC : Received Statistics Request from DU_APP");
1160
1161    if(macStatsReq == NULLP)
1162    {
1163       DU_LOG("\nERROR  -->  MAC : MacProcStatsReq(): Received Null pointer");
1164       return RFAILED;
1165    }
1166    
1167    /* [Step 1] Basic validation. If fails, statistics response is sent to DU APP
1168     * that rejectes all stats */
1169
1170    /* If number of statistics request for which response is still pending
1171     * towards DU APP has reached its maximum limit */
1172    if(macCb.statistics.numPendingStatsRsp >= MAX_PENDING_STATS_RSP)
1173    {
1174       DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: Maximum number of statistics response is pending. \
1175          Cannot process new request."); 
1176       MacRejectAllStats(macStatsReq, RESOURCE_UNAVAILABLE);
1177       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macStatsReq, sizeof(MacStatsReq));
1178       return RFAILED;
1179    }
1180
1181    /* If memory resources are unavailable */
1182    MAC_ALLOC(schStatsReq, sizeof(SchStatsReq));
1183    if(schStatsReq == NULLP)
1184    {
1185       DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: Failed to allocate memory");
1186       MacRejectAllStats(macStatsReq, RESOURCE_UNAVAILABLE);
1187       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macStatsReq, sizeof(MacStatsReq));
1188       return RFAILED;
1189    }
1190
1191    /* Add stats response to pending response list */ 
1192    macStatsRsp = &macCb.statistics.pendingStatsRsp[macCb.statistics.numPendingStatsRsp];
1193    memset(macStatsRsp, 0, sizeof(MacStatsRsp));
1194
1195    /* [Step 2] Traverse all stats group and validate each measurement types in each group */
1196    schStatsReq->subscriptionId = macStatsReq->subscriptionId;
1197    schStatsReq->numStatsGroup = 0;
1198    for(macStatsGrpIdx = 0; macStatsGrpIdx < macStatsReq->numStatsGroup; macStatsGrpIdx++)
1199    {
1200       measTypeInvalid = false;
1201       schStatsIdx = 0;
1202       macStatsGrp = &macStatsReq->statsGrpList[macStatsGrpIdx];
1203
1204       for(macStatsIdx=0; macStatsIdx < macStatsGrp->numStats; macStatsIdx++)
1205       {
1206          /* Validate each measurement type */
1207          switch(macStatsGrp->statsList[macStatsIdx])
1208          {
1209             case MAC_DL_TOTAL_PRB_USAGE:
1210                {
1211                   schStatsReq->statsGrpList[schStatsGrpIdx].statsList[schStatsIdx] = SCH_DL_TOTAL_PRB_USAGE;
1212                   break;
1213                }
1214             case MAC_UL_TOTAL_PRB_USAGE:
1215                {
1216                   schStatsReq->statsGrpList[schStatsGrpIdx].statsList[schStatsIdx] = SCH_UL_TOTAL_PRB_USAGE;
1217                   break;
1218                }
1219             default:
1220                {
1221                   DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: Invalid measurement type [%d]", \
1222                      macStatsGrp->statsList[macStatsIdx]);
1223                   measTypeInvalid = true;
1224                }
1225          }
1226
1227          /* Even if one measurement type is invalid, this group is rejected */
1228          if(measTypeInvalid)
1229          {
1230             memset(&schStatsReq->statsGrpList[schStatsGrpIdx], 0, sizeof(SchStatsGrpInfo));
1231             break;
1232          }
1233          
1234          schStatsIdx++;
1235       }
1236
1237       /* If all measurement type is valid, add group info to send to SCH */
1238       if(!measTypeInvalid)
1239       {
1240          schStatsReq->statsGrpList[schStatsGrpIdx].groupId = macStatsGrp->groupId;
1241          schStatsReq->statsGrpList[schStatsGrpIdx].periodicity = macStatsGrp->periodicity;
1242          schStatsReq->statsGrpList[schStatsGrpIdx].numStats = schStatsIdx;
1243          schStatsGrpIdx++;
1244       }
1245       else
1246       {
1247          /* [Step 3] If any measurement type validation fails in a group, that group 
1248           * is not configured and it is added to stats-group-rejected-list in
1249           * mac-stats-response message */
1250          macStatsRsp->statsGrpRejectedList[macStatsRsp->numGrpRejected].groupId = macStatsGrp->groupId;
1251          macStatsRsp->statsGrpRejectedList[macStatsRsp->numGrpRejected].cause = PARAM_INVALID;
1252          macStatsRsp->numGrpRejected++;
1253       }
1254    }
1255    schStatsReq->numStatsGroup = schStatsGrpIdx;
1256
1257    macStatsRsp->subscriptionId = macStatsReq->subscriptionId;
1258
1259    if(schStatsReq->numStatsGroup)
1260    {
1261       /* [Step 4] Even if one group passes all validation, it is sent to SCH in
1262        * statistics request. The mac-stats-response message is added to
1263        * pending-response list. */     
1264       macCb.statistics.numPendingStatsRsp++;
1265
1266       FILL_PST_MAC_TO_SCH(schPst, EVENT_STATISTICS_REQ_TO_SCH);
1267       ret = SchMessageRouter(&schPst, (void *)schStatsReq);
1268    }
1269    else
1270    {
1271       /* [Step 5] If none of the groups passes all validation, mac-stats-response
1272        * is sent to du app with all group as part of stats-group-rejected-list. */
1273       DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: All statistics group found invalid");
1274       MAC_FREE(schStatsReq, sizeof(SchStatsReq));
1275       ret = MacSendStatsRspToDuApp(macStatsRsp);
1276    }
1277
1278    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macStatsReq, sizeof(MacStatsReq));
1279    return ret;
1280 }
1281
1282 /**
1283  * @brief Mac process the statistics rsp received from sch.
1284  *
1285  * @details
1286  *
1287  *     Function : MacProcSchStatsRsp
1288  *
1289  *     This function  process the statistics response received from sch
1290  *
1291  *  @param[in]  Pst           *pst
1292  *  @param[in]  SchStatsRsp *schStatsRsp
1293  *  @return  int
1294  *      -# ROK
1295  **/
1296 uint8_t MacProcSchStatsRsp(Pst *pst, SchStatsRsp *schStatsRsp)
1297 {
1298    uint8_t idx = 0, accptdIdx = 0, rjctdIdx = 0;
1299    uint8_t ret = RFAILED;
1300    MacStatsRsp *macStatsRsp = NULLP;
1301
1302    if(schStatsRsp)
1303    {
1304       /* Fetch pointer to statistics response from pending list saved at MAC 
1305        * during processing statistics request from DU APP */ 
1306       for(idx = 0; idx < macCb.statistics.numPendingStatsRsp; idx++)
1307       {
1308          if(macCb.statistics.pendingStatsRsp[idx].subscriptionId == schStatsRsp->subscriptionId)
1309          {
1310             macStatsRsp = &macCb.statistics.pendingStatsRsp[idx];
1311             break;
1312          }
1313       }
1314
1315       if(macStatsRsp == NULLP)
1316       {
1317          MAC_FREE(schStatsRsp, sizeof(SchStatsRsp));
1318          return RFAILED;
1319       }
1320       
1321       /* Copy Stats-group-accpeted list received from SCH */
1322       for(accptdIdx = 0; accptdIdx<schStatsRsp->numGrpAccepted && macStatsRsp->numGrpAccepted<MAX_NUM_STATS_GRP; accptdIdx++)
1323       {
1324          macStatsRsp->statsGrpAcceptedList[macStatsRsp->numGrpAccepted++] = schStatsRsp->statsGrpAcceptedList[accptdIdx];
1325       }
1326
1327       /* List together all stats group rejected by MAC and by SCH */
1328       for(rjctdIdx = 0; rjctdIdx < schStatsRsp->numGrpRejected && macStatsRsp->numGrpRejected<MAX_NUM_STATS_GRP; rjctdIdx++)
1329       {
1330          macStatsRsp->statsGrpRejectedList[macStatsRsp->numGrpRejected].groupId = \
1331             schStatsRsp->statsGrpRejectedList[rjctdIdx].groupId;
1332          macStatsRsp->statsGrpRejectedList[macStatsRsp->numGrpRejected].cause = \
1333             schStatsRsp->statsGrpRejectedList[rjctdIdx].cause;
1334          macStatsRsp->numGrpRejected++;
1335       }
1336       
1337       /* Send statistics response to DU APP */
1338       ret = MacSendStatsRspToDuApp(macStatsRsp);
1339    }
1340    MAC_FREE(schStatsRsp, sizeof(SchStatsRsp));
1341    return ret;
1342 }
1343
1344 /**
1345  * @brief Fill and send statistics delete response to DU APP
1346  *
1347  * @details
1348  *
1349  *     Function : MacSendStatsDeleteRspToDuApp
1350  *
1351  *     Fill and send statistics delete response to DU APP
1352  *  [Step-1] In SCH delete response is received, fill MAC stats delete 
1353  *    response with info from SCH stats delete response.
1354  *  [Step-2] If a failure occurs while processing MAC stats delete request, 
1355  *    then fill MAC stats delete rsp with failure using info from MAC stats delete request.
1356  *  [Step-3] Else if numStatsGroup > 0, then send stats delete response 
1357  *    with deletion status of each stats group.
1358  *  [Step-4] If numStatsGroup = 0, send Stats delete response 
1359  *    for deletion of complete subscription.
1360  *
1361  *  @param[in]  SchStatsDeleteRsp
1362  *  @param[in]  MacStatsDeleteReq
1363  *  @return  int
1364  *      -# ROK
1365  **/
1366 uint8_t MacSendStatsDeleteRspToDuApp(SchStatsDeleteRsp *schStatsDeleteRsp,  MacStatsDeleteReq *macStatsDeleteReq)
1367 {
1368    Pst  pst;
1369    uint8_t ret = ROK, idx=0;
1370    MacStatsDeleteRsp *macStatsDeleteRsp=NULLP;
1371
1372    MAC_ALLOC_SHRABL_BUF(macStatsDeleteRsp, sizeof(MacStatsDeleteRsp));
1373    if(macStatsDeleteRsp == NULLP)
1374    {
1375       DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchStatsDeleteRsp");
1376       ret = RFAILED;
1377    }
1378    
1379    if(schStatsDeleteRsp)
1380    {
1381       /* [Step-1] */ 
1382       macStatsDeleteRsp->subscriptionId = schStatsDeleteRsp->subscriptionId;
1383       macStatsDeleteRsp->numStatsGroupDeleted = schStatsDeleteRsp->numStatsGroupDeleted;
1384
1385       if(macStatsDeleteRsp->numStatsGroupDeleted)
1386       {
1387          /* [Step-3] */ 
1388          for(idx =0;idx<macStatsDeleteRsp->numStatsGroupDeleted; idx++)
1389          {
1390             if(schStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp == RSP_OK)
1391             {
1392                macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp =MAC_DU_APP_RSP_OK;
1393                macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause =schStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause;
1394             }
1395             else
1396             {
1397                macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp =MAC_DU_APP_RSP_NOK;
1398                macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause =schStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause;
1399             }
1400          }
1401       }
1402       else
1403       {
1404          /* [Step-4] */ 
1405          if(schStatsDeleteRsp->subsDelRsp == RSP_OK)
1406             macStatsDeleteRsp->subsDelRsp = MAC_DU_APP_RSP_OK;
1407          else
1408             macStatsDeleteRsp->subsDelRsp = MAC_DU_APP_RSP_NOK;
1409          macStatsDeleteRsp->subsDelCause = schStatsDeleteRsp->subsDelCause;
1410       }
1411    }
1412    else
1413    {
1414       /* [Step-2] */ 
1415       macStatsDeleteRsp->subscriptionId = macStatsDeleteReq->subscriptionId;
1416       macStatsDeleteRsp->numStatsGroupDeleted= macStatsDeleteReq->numStatsGroupToBeDeleted;
1417       
1418       if(macStatsDeleteRsp->numStatsGroupDeleted)
1419       {
1420          /* [Step-3] */ 
1421          for(idx =0;idx<macStatsDeleteRsp->numStatsGroupDeleted; idx++)
1422          {
1423             macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelRsp =MAC_DU_APP_RSP_NOK;
1424             macStatsDeleteRsp->statsGrpDelInfo[idx].statsGrpDelCause = RESOURCE_UNAVAILABLE;
1425          }
1426       }
1427       else
1428       {
1429          /* [Step-4] */ 
1430          macStatsDeleteRsp->subsDelRsp = MAC_DU_APP_RSP_NOK;
1431          macStatsDeleteRsp->subsDelCause = RESOURCE_UNAVAILABLE;
1432       }
1433    }
1434
1435    DU_LOG("\nINFO  -->  MAC : MacSendStatsDeleteRspToDuApp: Sending Delete Statistics Response to DU APP");
1436
1437    memset(&pst, 0, sizeof(Pst));
1438    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_STATS_DELETE_RSP);
1439    if(((*macDuStatsDeleteRspOpts[pst.selector])(&pst, macStatsDeleteRsp))!= ROK)
1440    {
1441       DU_LOG("\nERROR  -->  MAC : Failed to send statistics delete response to DU APP");
1442       MAC_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, macStatsDeleteRsp, sizeof(MacStatsDeleteRsp));
1443       ret = RFAILED;
1444    }
1445
1446    return ret;
1447 }
1448                  
1449 /**
1450  * @brief Mac process the statistics delete rsp received from sch.
1451  *
1452  * @details
1453  *
1454  *     Function : MacProcSchStatsDeleteRsp
1455  *
1456  *     This function  process the statistics delete response received from sch
1457  *
1458  *  @param[in]  Pst           *pst
1459  *  @param[in]  SchStatsDeleteRsp *schStatsDeleteRsp
1460  *  @return  int
1461  *      -# ROK
1462  **/
1463 uint8_t MacProcSchStatsDeleteRsp(Pst *pst, SchStatsDeleteRsp *schStatsDeleteRsp)
1464 {
1465    uint8_t ret = RFAILED;
1466
1467    if(schStatsDeleteRsp)
1468    {
1469       ret = MacSendStatsDeleteRspToDuApp(schStatsDeleteRsp, NULLP);
1470       MAC_FREE(schStatsDeleteRsp, sizeof(SchStatsDeleteRsp));
1471    }
1472    return ret;
1473 }
1474
1475 /**
1476  * @brief Mac process the statistics delete Req received from DUAPP
1477  *
1478  * @details
1479  *
1480  *     Function : MacProcStatsDeleteReq
1481  *
1482  *     Functionality: Process the statistics delete request from duapp
1483  *  @param[in]  Pst      *pst
1484  *  @param[in]  StatsDeleteReq *statsReq
1485  *  @return  int
1486  *      -# ROK
1487  **/
1488
1489 uint8_t MacProcStatsDeleteReq(Pst *pst, MacStatsDeleteReq *macStatsDeleteReq)
1490 {
1491    Pst       schPst;
1492    uint8_t   ret = RFAILED;
1493    SchStatsDeleteReq  *schStatsDeleteReq = NULLP;
1494  
1495    DU_LOG("\nINFO   -->  MAC : Received Statistics delete Request from DU_APP");
1496
1497    if(macStatsDeleteReq == NULLP)
1498    {
1499       DU_LOG("\nERROR  -->  MAC : MacProcStatsDeleteReq(): Received Null pointer");
1500       return RFAILED;
1501    }
1502    
1503    MAC_ALLOC(schStatsDeleteReq, sizeof(SchStatsDeleteReq));
1504    if(schStatsDeleteReq == NULLP)
1505    {
1506       DU_LOG("\nERROR  -->  MAC : MacProcStatsDeleteReq: Failed to allocate memory");
1507    }
1508    else
1509    {
1510       /* fill all the information in schStatsDeleteReq structure */
1511       schStatsDeleteReq->subscriptionId = macStatsDeleteReq->subscriptionId;
1512       schStatsDeleteReq->numStatsGroupToBeDeleted = macStatsDeleteReq->numStatsGroupToBeDeleted;
1513       memcpy(&schStatsDeleteReq->statsGrpIdToBeDelList, &macStatsDeleteReq->statsGrpIdToBeDelList, schStatsDeleteReq->numStatsGroupToBeDeleted*sizeof(uint8_t)); 
1514       FILL_PST_MAC_TO_SCH(schPst, EVENT_STATISTICS_DELETE_REQ_TO_SCH);
1515       ret = SchMessageRouter(&schPst, (void *)schStatsDeleteReq);
1516    }
1517
1518    if(ret != ROK)
1519    {
1520       ret = MacSendStatsDeleteRspToDuApp(NULLP, macStatsDeleteReq);
1521    }
1522
1523    MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macStatsDeleteReq, sizeof(MacStatsDeleteReq));
1524    return ret;
1525 }
1526
1527 /**********************************************************************
1528   End of file
1529  **********************************************************************/