[Epic-ID: ODUHIGH-516][Task-ID: ODUHIGH-523] Statistics Request API and Timer Based...
[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 /**
67  * @brief Layer Manager  Configuration request handler for Scheduler
68  *
69  * @details
70  *
71  *     Function : MacSchGenCfgReq
72  *
73  *     This function receives general configurations for Scheduler
74  *     from DU APP and forwards to Scheduler.
75  *
76  *  @param[in]  Pst *pst, the post structure
77  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
78  *  @return 
79  *      -# ROK
80  **/
81 uint8_t MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
82 {
83    Pst schPst;
84
85    DU_LOG("\nINFO  -->  MAC : Received Scheduler gen config at MAC");
86    memset(&schPst, 0, sizeof(Pst));
87    FILL_PST_MAC_TO_SCH(schPst, EVENT_SCH_GEN_CFG);
88    
89    return(SchMessageRouter(&schPst, (void *)cfg));
90 }
91
92 /**
93  * @brief Layer Manager Configuration response from Scheduler
94  *
95  * @details
96  *
97  *     Function : SchSendCfgCfm
98  *
99  *     This function sends general configurations response from
100  *     Scheduler to DU APP.
101  *
102  *  @param[in]  Pst *pst, the post structure
103  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
104  *  @return 
105  *      -# ROK
106  **/
107 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt  *cfm)
108 {
109    DU_LOG("\nDEBUG  -->  MAC : Sending Scheduler config confirm to DU APP");
110    pst->dstEnt = ENTDUAPP;
111    pst->dstInst = 0;
112    pst->srcInst = 0;
113    pst->selector = ODU_SELECTOR_LC;
114    RgMiLrgSchCfgCfm(pst, cfm);
115
116    return ROK;
117 }
118
119 /**
120  * @brief Layer Manager Configuration request handler.
121  *
122  * @details
123  *
124  *     Function : MacProcCellCfgReq
125  *
126  *     This function handles the gNB and cell configuration
127  *     request received from DU APP.
128  *     This API unapcks and forwards the config towards SCH
129  *
130  *  @param[in]  Pst           *pst
131  *  @param[in]  MacCellCfg    *macCellCfg
132  *  @return  
133  *      -# ROK
134  **/
135 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
136 {
137    Pst cfmPst;
138    uint16_t cellIdx, scsInKhz = 0;
139    uint8_t ret = ROK, plmnIdx = 0,sliceIdx = 0;
140    MacCellCb     *macCellCb;
141
142    memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
143
144    MAC_ALLOC(macCellCb, sizeof(MacCellCb));
145    if(macCellCb == NULLP)
146    {
147       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of macCellCfg\n");
148       return RFAILED;
149    }
150    memset(macCellCb, 0, sizeof(MacCellCb));
151
152    GET_CELL_IDX(macCellCfg->cellId, cellIdx);
153    macCb.macCell[cellIdx] = macCellCb;
154    macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
155    scsInKhz = convertScsEnumValToScsVal(macCellCfg->cellCfg.subCarrSpacing);
156    
157    /*Ref : 3GPP 38.211 Table 4.2-1: SCS = (2 ^ numerology * 15kHz)*/
158    macCb.macCell[cellIdx]->numerology = log2(scsInKhz/BASE_SCS);
159    macCb.macCell[cellIdx]->numOfSlots = 10 * (1 << (macCb.macCell[cellIdx]->numerology));
160    memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
161
162    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, \
163          macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
164    if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu == NULLP)
165    {
166       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
167       return RFAILED;
168    }
169    memcpy(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, macCellCfg->cellCfg.sib1Cfg.sib1Pdu, \
170          macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
171
172    for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
173    {
174       macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice = macCellCfg->cellCfg.plmnInfoList[plmnIdx].numSupportedSlice;
175       MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai, macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice\
176             * sizeof(Snssai*));
177       if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai == NULLP)
178       {
179          DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
180          return RFAILED;
181       }
182
183       if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai)
184       {
185          for(sliceIdx=0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice; sliceIdx++)
186          {
187             if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
188             {
189                MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
190                if(!macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
191                {
192                   DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
193                   return RFAILED;
194                }
195                memcpy(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx],\
196                      sizeof(Snssai));
197             }
198          }
199       }
200    }
201    /* Send cell cfg to scheduler */
202    ret = MacSchCellCfgReq(pst, macCellCfg);
203    if(ret != ROK)
204    {
205       MacCellCfgCfm macCellCfgCfm;
206       macCellCfgCfm.rsp = RSP_NOK;
207       macCellCfgCfm.cellId = macCellCfg->cellId;
208       /* Fill Pst */
209       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
210       cfmPst.selector  = ODU_SELECTOR_LC;
211
212       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
213    }
214    else
215    {
216       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
217    }
218    return ret;
219 } /* end of MacProcCellCfgReq */
220
221 /**
222  * @brief Layer Manager Configuration request handler.
223  *
224  * @details
225  *
226  *     Function : MacSchCellCfgReq
227  *
228  *     This function sends cell configuration to SCH
229  *
230  *  @param[in]  Pst           *pst
231  *  @param[in]  MacCellCfg    *macCellCfg
232  *  @return  
233  *      -# ROK
234  **/
235 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
236 {
237    SchCellCfg schCellCfg;
238    Pst        cfgPst;
239    uint8_t    ssbMaskIdx = 0, rsrcListIdx = 0, sliceIdx=0, plmnIdx = 0;
240
241    memset(&cfgPst, 0, sizeof(Pst));
242    memset(&schCellCfg, 0, sizeof(SchCellCfg));
243    schCellCfg.cellId = macCellCfg->cellId;
244    schCellCfg.phyCellId = macCellCfg->cellCfg.phyCellId;
245
246    for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
247    {
248       schCellCfg.plmnInfoList[plmnIdx].plmn = macCellCfg->cellCfg.plmnInfoList[plmnIdx].plmn;
249       if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai) 
250       {
251          schCellCfg.plmnInfoList[plmnIdx].numSliceSupport = macCellCfg->cellCfg.plmnInfoList[plmnIdx].numSupportedSlice;
252          MAC_ALLOC(schCellCfg.plmnInfoList[plmnIdx].snssai, schCellCfg.plmnInfoList[plmnIdx].numSliceSupport * sizeof(Snssai*));
253          if(!schCellCfg.plmnInfoList[plmnIdx].snssai)
254          {
255             DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
256             return RFAILED;
257          }
258          for(sliceIdx=0; sliceIdx<schCellCfg.plmnInfoList[plmnIdx].numSliceSupport; sliceIdx++)
259          {
260             if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
261             {
262                MAC_ALLOC(schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
263                if(!schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
264                {
265                   DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
266                   return RFAILED;
267                }
268                memcpy(schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx],  sizeof(Snssai));
269             }
270          }
271       }
272    }
273
274    schCellCfg.dupMode = macCellCfg->cellCfg.dupType;
275    schCellCfg.dlBandwidth = macCellCfg->carrCfg.dlBw;
276    schCellCfg.ulBandwidth = macCellCfg->carrCfg.ulBw;
277
278    schCellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
279    schCellCfg.dlCfgCommon.schFreqInfoDlSib.schSpcCarrier[0].subCarrierSpacing = macCellCfg->ssbCfg.scsCmn;
280
281    /* fill initial DL BWP */
282    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->cellCfg.initialDlBwp.bwp.firstPrb;
283    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->cellCfg.initialDlBwp.bwp.numPrb;
284    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.scs = macCellCfg->cellCfg.initialDlBwp.bwp.scs;
285    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->cellCfg.initialDlBwp.bwp.cyclicPrefix;
286    
287    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
288       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
289    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
290       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
291    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
292       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
293    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
294       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.duration;
295    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
296       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
297    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
298       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
299    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
300       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
301    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
302       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
303    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
304       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
305    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
306       macCellCfg->cellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
307    
308    schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->cellCfg.initialDlBwp.pdschCommon.numTimeDomAlloc;
309    for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->cellCfg.initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
310    {
311       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 = 
312          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
313       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
314          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
315       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
316          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
317       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
318          macCellCfg->cellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
319    }
320
321    /* fill SIB1 scheduler parameters */
322    schCellCfg.dlCfgCommon.schPcchCfg.numPO  =  macCellCfg->cellCfg.sib1Cfg.pagingCfg.numPO;
323    schCellCfg.dlCfgCommon.schPcchCfg.poPresent = macCellCfg->cellCfg.sib1Cfg.pagingCfg.poPresent;
324    if(schCellCfg.dlCfgCommon.schPcchCfg.poPresent)
325    {
326       memcpy(schCellCfg.dlCfgCommon.schPcchCfg.pagingOcc, macCellCfg->cellCfg.sib1Cfg.pagingCfg.pagingOcc, MAX_PO_PER_PF);
327    }
328
329    /* fill initial UL BWP */
330    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->cellCfg.initialUlBwp.bwp.firstPrb;
331    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->cellCfg.initialUlBwp.bwp.numPrb;
332    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.scs = macCellCfg->cellCfg.initialUlBwp.bwp.scs;
333    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->cellCfg.initialUlBwp.bwp.cyclicPrefix;
334    /* fill RACH config params */
335    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.prachCfgIdx   = macCellCfg->prachCfg.prachCfgIdx;
336    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
337    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
338    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.zeroCorrZoneCfg = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg; 
339    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.raRspWindow = macCellCfg->prachCfg.raRspWindow;
340
341    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.totalNumRaPreamble = macCellCfg->prachCfg.totalNumRaPreamble;
342    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
343    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.numCbPreamblePerSsb = macCellCfg->prachCfg.numCbPreamblePerSsb;
344    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.raContResTmr = macCellCfg->prachCfg.raContResTmr;
345    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
346    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
347    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
348    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.msg1SubcSpacing = \
349                                             macCellCfg->prachCfg.prachSubcSpacing;
350
351    schCellCfg.ulCfgCommon.schInitialUlBwp.pucchCommon.pucchResourceCommon = \
352                                                                 macCellCfg->cellCfg.initialUlBwp.pucchCommon.pucchResourceCommon;
353    schCellCfg.ulCfgCommon.schInitialUlBwp.pucchCommon.pucchGroupHopping = \
354                                                                 macCellCfg->cellCfg.initialUlBwp.pucchCommon.pucchGroupHopping;
355    schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
356                                                                 macCellCfg->cellCfg.initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
357    for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->cellCfg.initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
358    {
359       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 = 
360          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
361       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
362          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
363       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
364          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
365       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
366          macCellCfg->cellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
367    }
368
369 #ifdef NR_TDD
370    memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
371 #endif
372
373    /* fill ssb scheduler parameters */
374    for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
375    {
376       schCellCfg.ssbPosInBurst[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
377    }
378    schCellCfg.ssbPeriod    = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
379    schCellCfg.ssbFrequency = macCellCfg->cellCfg.ssbFreq;
380    schCellCfg.dmrsTypeAPos = macCellCfg->ssbCfg.dmrsTypeAPos;
381    schCellCfg.ssbScs       = macCellCfg->cellCfg.subCarrSpacing;
382    schCellCfg.pdcchCfgSib1.coresetZeroIndex = macCellCfg->cellCfg.sib1Cfg.pdcchCfgSib1.coresetZeroIndex;
383    schCellCfg.pdcchCfgSib1.searchSpaceZeroIndex = macCellCfg->cellCfg.sib1Cfg.pdcchCfgSib1.searchSpaceZeroIndex;
384    schCellCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
385    schCellCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
386    schCellCfg.sib1PduLen = macCellCfg->cellCfg.sib1Cfg.sib1PduLen;
387    
388    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
389
390    return(SchMessageRouter(&cfgPst, (void *)&schCellCfg));
391 } /* end of MacSchCellCfgReq */
392
393
394 /*******************************************************************
395  *
396  * @brief Sends Cell config confirm to DU APP
397  *
398  * @details
399  *
400  *    Function : MacSendCellCfgCfm
401  *
402  *    Functionality:
403  *      Sends Cell config confirm to DU APP
404  *
405  * @params[in] Response status
406  * @return void
407  *
408  * ****************************************************************/
409 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
410 {
411    Pst pst;
412    uint16_t   cellIdx;
413    MacCellCfgCfm macCellCfgCfm;
414
415    memset(&pst, 0, sizeof(Pst));
416
417    GET_CELL_IDX(cellId, cellIdx);
418    macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
419    macCellCfgCfm.rsp = response;
420
421    /* Fill Pst */
422    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
423    pst.selector  = ODU_SELECTOR_LC;
424
425    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
426 }
427
428
429 /**
430  * @brief Layer Manager Configuration response handler.
431  *
432  * @details
433  *
434  *     Function : MacProcSchCellCfgCfm
435  *
436  *     This function processes cell configuration to SCH
437  *
438  *  @param[in]  Pst           *pst
439  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
440  *  @return  int
441  *      -# ROK
442  **/
443 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
444 {
445    uint16_t *cellId = NULLP;
446
447 #ifdef CALL_FLOW_DEBUG_LOG
448    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_SCH_CELL_CFG_CFM\n");
449 #endif
450
451    if(schCellCfgCfm->rsp == RSP_OK)
452    {
453       cellId = &schCellCfgCfm->cellId;
454 #ifdef INTEL_TIMER_MODE
455       sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
456 #else
457       sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
458 #endif
459    }
460    else
461    {
462       MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
463    }
464    return ROK;
465 }
466
467 /*******************************************************************
468  *
469  * @brief MAC handler for config response from PHY
470  *
471  * @details
472  *
473  *    Function : fapiMacConfigRsp
474  *
475  *    Functionality:
476  *     Processes config response from PHY and sends cell config
477  *     confirm to DU APP
478  *
479  * @params[in]
480  * @return void
481  *
482  * ****************************************************************/
483 void fapiMacConfigRsp(uint16_t cellId)
484 {
485    /* TODO : Processing of config response from PHY */
486
487    /* Send cell config cfm to DU APP */
488    MacSendCellCfgCfm(cellId, RSP_OK);
489 }
490
491 /*******************************************************************
492  *
493  * @brief Fill and Send Cell Delete response from MAC to DU APP
494  *
495  * @details
496  *
497  *    Function : MacSendCellDeleteRsp
498  *
499  *    Functionality: Fill and Send Cell Delete response from MAC to DUAPP
500  *
501  * @params[in] MAC Cell delete result
502  *             SCH Cell delete response
503  * @return ROK     - success
504  *         RFAILED - failure
505  *
506  * ****************************************************************/
507 uint8_t MacSendCellDeleteRsp(CauseOfResult  status, uint8_t cellId)
508 {
509    MacCellDeleteRsp *deleteRsp=NULLP;
510    Pst            rspPst;
511
512    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
513    if(!deleteRsp)
514    {
515       DU_LOG("\nERROR  -->  MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
516       return RFAILED;
517    }
518
519    /* Filling CELL delete response */
520    
521    memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
522    deleteRsp->cellId = cellId;
523    deleteRsp->status = status;
524
525    /* Fill Post structure and send CELL delete response*/
526    memset(&rspPst, 0, sizeof(Pst));
527    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
528    return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
529 }
530
531 /*******************************************************************
532  *
533  * @brief  Processes CELL delete response from scheduler
534  *
535  * @details
536  *
537  *    Function : MacProcSchCellDeleteRsp
538  *
539  *    Functionality:
540  *      Processes CELL delete from scheduler
541  *
542  * @params[in] Pst : Post structure
543  *             schCellDelRsp : Scheduler CELL delete respons
544  * @return ROK     - success
545  *         RFAILED - failure
546  *
547  * * ****************************************************************/
548 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
549 {
550    uint8_t  ret = ROK, sliceIdx = 0, plmnIdx = 0;
551    uint16_t cellIdx=0;
552    CauseOfResult  cause;
553
554 #ifdef CALL_FLOW_DEBUG_LOG
555    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_CELL_DELETE_RSP_TO_MAC\n");
556 #endif  
557
558    if(schCellDelRsp)
559    {
560       if(schCellDelRsp->rsp == RSP_OK)
561       {
562          DU_LOG("\nINFO   -->  MAC : SCH CELL Delete response for cellId[%d] is successful ", \
563                schCellDelRsp->cellId);
564          GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
565          if(macCb.macCell[cellIdx])
566          {
567             if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
568             {
569                cause = SUCCESSFUL;
570                for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
571                {
572                   if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai)
573                   {
574                      for(sliceIdx = 0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice; sliceIdx++)
575                      {
576                         MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
577                      }
578                      MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai, macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].\
579                            numSupportedSlice * sizeof(Snssai*));
580                   }
581                }
582                MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, \
583                      macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
584                MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
585             }
586             else
587             {
588                DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
589                cause = CELLID_INVALID;
590                ret = RFAILED;
591             }
592          }
593          else
594          {
595             DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
596             cause = CELLID_INVALID;
597             ret = RFAILED;
598          }
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       if(MacSendCellDeleteRsp(cause, schCellDelRsp->cellId) != ROK)
607       {
608          DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
609          ret = RFAILED;
610       }
611
612    }
613    else
614    {
615       DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
616       ret = RFAILED;
617    }
618    return ret;
619 }
620
621 /*******************************************************************
622  *
623  * @brief Sends Cell delete req to Scheduler
624  *
625  * @details
626  *
627  *    Function : sendCellDelReqToSch
628  *
629  *    Functionality: sends Cell delete req to Scheduler
630  *
631  * @params[in]  SchCellDelete *schCellDel
632  * @return ROK     - success
633  *         RFAILED - failure
634  *
635  * ****************************************************************/
636
637 uint8_t sendCellDelReqToSch(SchCellDeleteReq *schCellDelReq)
638 {
639    Pst schPst;
640    FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
641    return(SchMessageRouter(&schPst, (void *)schCellDelReq));
642 }
643
644 /*******************************************************************
645  *
646  * @brief Handles CELL Delete requst from DU APP
647  *
648  * @details
649  *
650  *    Function : MacProcCellDeleteReq
651  *
652  *    Functionality: Handles CELL Delete requst from DU APP
653  *
654  * @params[in] Pst *pst, MacCellDelete *cellDelete
655  * @return ROK     - success
656  *         RFAILED - failure
657  *
658  *
659  * ****************************************************************/
660 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDeleteReq *cellDelete)
661 {
662    uint8_t ret = ROK, cellIdx=0;
663    SchCellDeleteReq schCellDelete;
664
665    DU_LOG("\nINFO   -->  MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
666
667    if(cellDelete)
668    {
669       GET_CELL_IDX(cellDelete->cellId, cellIdx);
670       if(macCb.macCell[cellIdx])
671       {
672          if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
673          {
674             memset(&schCellDelete, 0, sizeof(SchCellDeleteReq ));
675             schCellDelete.cellId =  cellDelete->cellId;
676             ret = sendCellDelReqToSch(&schCellDelete);
677             if(ret != ROK)
678             {
679                DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
680                ret = RFAILED;
681             }
682          }
683          else
684          {
685             DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
686             cellDelete->cellId);
687             ret = RFAILED;
688          }
689       }
690       else
691       {
692          DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
693                cellDelete->cellId);
694          ret = RFAILED;
695       }
696
697       if(ret == RFAILED)
698       {
699           DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Sending failure response to DU");
700           if(MacSendCellDeleteRsp(CELLID_INVALID, cellDelete->cellId) != ROK)
701           {
702              DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
703              cellDelete->cellId);
704           }
705
706       }
707       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDeleteReq));
708    }
709    else
710    {
711       DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
712       ret = RFAILED;
713    }
714    return ret;
715 }
716
717 /**
718  * @brief free the temporary slice cfg stored in macCb.
719  *
720  * @details
721  *
722  *     Function : freeMacSliceCfgReq 
723  *
724  *   free the temporary slice cfg stored in macCb
725  *
726  *  @param[in]  
727  *  @return  int
728  *      -# ROK
729  **/
730 void freeMacSliceCfgReq(MacSliceCfgReq *cfgReq,Pst *pst)
731 {
732     uint8_t policyIdx = 0, memberListIdx=0;
733
734     if(cfgReq->numOfRrmPolicy)
735     {
736        if(cfgReq->listOfRrmPolicy)
737        {
738           for(policyIdx = 0; policyIdx<cfgReq->numOfRrmPolicy; policyIdx++)
739           {
740              if(cfgReq->listOfRrmPolicy[policyIdx])
741              {
742                 if(cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem)
743                 {
744                    if(cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList)
745                    {
746                       for(memberListIdx = 0; memberListIdx<cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem; memberListIdx++)
747                       {
748                          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList[memberListIdx], sizeof(RrmPolicyMemberList));
749                       }
750                       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList,\
751                       cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem * sizeof(RrmPolicyMemberList*));
752                    }
753                 }
754                 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx], sizeof(MacSliceRrmPolicy));
755              }
756           }
757           MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy, cfgReq->numOfRrmPolicy  * sizeof(MacSliceRrmPolicy*));
758        }
759     }
760
761 }
762
763 /**
764  * @brief send slice cfg response to duapp.
765  *
766  * @details
767  *
768  *     Function : MacSendSliceConfigRsp
769  *
770  *   sends  slice cfg response to duapp
771  *
772  *  @param[in] MacSliceCfgRsp macSliceCfgRsp 
773  *  @return  int
774  *      -# ROK
775  **/
776 uint8_t MacSendSliceConfigRsp(MacSliceCfgRsp *macSliceCfgRsp)
777 {
778     Pst  rspPst;
779     
780     memset(&rspPst, 0, sizeof(Pst));
781     FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_CFG_RSP);
782     return (*macDuSliceCfgRspOpts[rspPst.selector])(&rspPst, macSliceCfgRsp);
783
784 }
785
786 /**
787  * @brief Mac process the slice cfg rsp received from sch.
788  *
789  * @details
790  *
791  *     Function : MacProcSchSliceCfgRsp 
792  *
793  *     This function  process the slice cfg rsp received from sch
794  *
795  *  @param[in]  Pst           *pst
796  *  @param[in]  SchSliceCfgRsp *sliceCfgrsp
797  *  @return  int
798  *      -# ROK
799  **/
800
801 uint8_t MacProcSchSliceCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceCfgRsp)
802 {
803    MacSliceCfgRsp *macSliceCfgRsp = NULLP;
804
805    if(schSliceCfgRsp)
806    {
807       MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp, sizeof(MacSliceCfgRsp));
808       if(macSliceCfgRsp == NULLP)
809       {
810           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceCfgRsp");
811           return RFAILED;
812       }
813       macSliceCfgRsp->snssai = schSliceCfgRsp->snssai;
814       if(schSliceCfgRsp->rsp == RSP_OK)
815          macSliceCfgRsp->rsp    = MAC_DU_APP_RSP_OK;
816       else
817       {
818          macSliceCfgRsp->rsp    = MAC_DU_APP_RSP_NOK;
819       }
820       macSliceCfgRsp->cause  = schSliceCfgRsp->cause;
821       MacSendSliceConfigRsp(macSliceCfgRsp);
822    }
823    return ROK;
824 }
825
826 /**
827  * @brief send slice cfg response to duapp.
828  *
829  * @details
830  *
831  *     Function : MacSendSliceReconfigRsp 
832  *
833  *   sends  slice cfg response to duapp
834  *
835  *  @param[in] MacSliceRecfgRsp macSliceRecfgRsp
836  *  @return  int
837  *      -# ROK
838  **/
839 uint8_t MacSendSliceReconfigRsp(MacSliceRecfgRsp *macSliceRecfgRsp)
840 {
841    Pst  rspPst;
842
843    memset(&rspPst, 0, sizeof(Pst));
844    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_RECFG_RSP);
845    return (*macDuSliceRecfgRspOpts[rspPst.selector])(&rspPst, macSliceRecfgRsp);
846
847 }
848
849 /**
850  * @brief Mac process the slice cfg rsp received from sch.
851  *
852  * @details
853  *
854  *     Function : MacProcSchSliceRecfgRsp 
855  *
856  *     This function  process the slice cfg rsp received from sch
857  *
858  *  @param[in]  Pst           *pst
859  *  @param[in]  SchSliceCfgRsp *schSliceRecfgRsp
860  *  @return  int
861  *      -# ROK
862  **/
863 uint8_t MacProcSchSliceRecfgRsp(Pst *pst, SchSliceRecfgRsp *schSliceRecfgRsp)
864 {
865    MacSliceRecfgRsp *macSliceRecfgRsp = NULLP;
866
867    if(schSliceRecfgRsp)
868    {
869       MAC_ALLOC_SHRABL_BUF(macSliceRecfgRsp, sizeof(MacSliceRecfgRsp));
870       if(macSliceRecfgRsp == NULLP)
871       {
872           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceRecfgRsp");
873           return RFAILED;
874       }
875
876       macSliceRecfgRsp->snssai = schSliceRecfgRsp->snssai;
877       if(schSliceRecfgRsp->rsp == RSP_OK)
878          macSliceRecfgRsp->rsp    = MAC_DU_APP_RSP_OK;
879       else
880       {
881          macSliceRecfgRsp->rsp    = MAC_DU_APP_RSP_NOK;
882       }
883       macSliceRecfgRsp->cause  = schSliceRecfgRsp->cause;
884       MacSendSliceReconfigRsp(macSliceRecfgRsp);
885    }
886    return ROK;
887 }
888
889 /**
890  * @brief Mac process the downlink pcch indication received from DUAPP
891  *
892  * @details
893  *
894  *     Function : MacProcDlPcchInd 
895  *
896  *     This function process the downlink pcch indication received from DUAPP
897  *
898  *  @param[in]  Pst           *pst
899  *  @param[in]  DlPcchInd    *pcchInd 
900  *  @return  int
901  *      -# ROK
902  **/
903 uint8_t MacProcDlPcchInd(Pst *pst, DlPcchInd *pcchInd)
904 {
905    uint8_t ret = RFAILED;
906    uint16_t cellIdx = 0;
907    Pst       schPst;
908    SchPageInd *schPageInd = NULLP;
909
910    if(pcchInd)
911    {
912       DU_LOG("\nINFO   -->  MAC : Received DL PCCH IND from DU_APP for cellId[%d]", pcchInd->cellId);
913       
914       GET_CELL_IDX(pcchInd->cellId, cellIdx);
915
916       if(macCb.macCell[cellIdx] == NULLP || macCb.macCell[cellIdx]->cellId != pcchInd->cellId)
917       {
918          DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): CellId[%d] does not exist", pcchInd->cellId);
919       }
920       else
921       {
922          if((pcchInd->pcchPdu == NULLP) || (pcchInd->pduLen <= 0))
923          {
924             DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Received Pcch pdu is null");
925          }
926          else
927          {
928             MAC_ALLOC(schPageInd, sizeof(SchPageInd));
929             if(schPageInd == NULLP)
930             {
931                DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Failed to allocate memory");
932             }
933             else
934             {
935                schPageInd->cellId = pcchInd->cellId;
936                schPageInd->pf = pcchInd->pf;
937                schPageInd->i_s = pcchInd->i_s;
938                schPageInd->pduLen = pcchInd->pduLen;
939                
940                MAC_ALLOC(schPageInd->pagePdu, pcchInd->pduLen);
941                if(schPageInd->pagePdu == NULLP)
942                {
943                   DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Failed to allocate memory");
944                   MAC_FREE(schPageInd, sizeof(SchPageInd));
945                }
946                else
947                {
948                   memcpy(schPageInd->pagePdu, pcchInd->pcchPdu, pcchInd->pduLen);
949
950                   FILL_PST_MAC_TO_SCH(schPst, EVENT_PAGING_IND_TO_SCH);
951                   ret = SchMessageRouter(&schPst, (void *)schPageInd);
952                }
953             }
954          }
955       }
956       if((pcchInd->pcchPdu) && (pcchInd->pduLen > 0))
957       {
958          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd->pcchPdu, pcchInd->pduLen);
959       }
960       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd, sizeof(DlPcchInd));
961    }
962    else
963    {
964       DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Received Null pointer");
965    }
966    return ret;
967 }
968
969 /**
970  * @brief Mac process the downlink Broadcast Req received from DUAPP
971  *
972  * @details
973  *
974  *     Function : MacProcDlBroadcastReq 
975  *
976  *     This function process the downlink Broadcast Req received from DUAPP
977  *
978  *  @param[in]  Pst           *pst
979  *  @param[in]  DlBroadcastReq    *dlBroadcastReq 
980  *  @return  int
981  *      -# ROK
982  **/
983 uint8_t MacProcDlBroadcastReq(Pst *pst, MacDlBroadcastReq *dlBroadcastReq)
984 {
985    uint8_t ret = ROK, idx=0;
986    uint16_t cellIdx = 0;
987
988    if(dlBroadcastReq)
989    {
990       DU_LOG("\nINFO   -->  MAC : Received DL braodcast req from DU_APP for cellId[%d]", dlBroadcastReq->cellId);
991       
992       GET_CELL_IDX(dlBroadcastReq->cellId, cellIdx);
993
994       if(macCb.macCell[cellIdx] == NULLP || macCb.macCell[cellIdx]->cellId != dlBroadcastReq->cellId)
995       {
996          ret = RFAILED;
997          DU_LOG("\nERROR  -->  MAC : MacProcDlBroadcastReq(): CellId[%d] does not exist", dlBroadcastReq->cellId);
998       }
999       else
1000       {
1001          /*TODO - Complete the processing of DL Broadcast Request*/
1002       }
1003       for(idx = 0; idx<dlBroadcastReq->numSiBlock; idx++)
1004       {
1005          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlBroadcastReq->siSchedulingInfo[idx]->siAreaID, sizeof(uint8_t));
1006          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlBroadcastReq->siSchedulingInfo[idx], sizeof(SiSchedulingInfo));
1007       }
1008       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, dlBroadcastReq, sizeof(MacDlBroadcastReq));
1009    }
1010    else
1011    {
1012       ret = RFAILED;
1013       DU_LOG("\nERROR  -->  MAC : MacProcDlBroadcastReq(): Received Null pointer");
1014    }
1015    return ret;
1016 }
1017
1018 /**
1019  * @brief Mac process the statistics Req received from DUAPP
1020  *
1021  * @details
1022  *
1023  *     Function : MacProcStatsReq
1024  *
1025  *     This function process the statistics request from duapp
1026  *
1027  *  @param[in]  Pst      *pst
1028  *  @param[in]  StatsReq *statsReq
1029  *  @return  int
1030  *      -# ROK
1031  **/
1032 uint8_t MacProcStatsReq(Pst *pst, MacStatsReq *macStatsReq)
1033 {
1034    uint8_t   macStatsIdx = 0, schStatsIdx = 0;
1035    uint8_t   ret = RFAILED;
1036    bool      measTypeInvalid = false;
1037    Pst       schPst;
1038    SchStatsReq  *schStatsReq = NULLP;
1039    CauseOfResult cause;
1040
1041    if(macStatsReq)
1042    {
1043       DU_LOG("\nINFO   -->  MAC : Received Statistics Request from DU_APP");
1044
1045       MAC_ALLOC(schStatsReq, sizeof(SchStatsReq));
1046       if(schStatsReq == NULLP)
1047       {
1048          DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: Failed to allocate memory");
1049          cause = RESOURCE_UNAVAILABLE;
1050       }
1051       else
1052       {
1053          schStatsReq->numStats = 0;
1054          for(macStatsIdx=0; macStatsIdx < macStatsReq->numStats; macStatsIdx++)
1055          {
1056             /* Checking each measurement type to send only SCH related
1057              * measurement config to SCH
1058              * This will be useful in future when some measurement type will
1059              * be configured for SCH and rest for only MAC */
1060             switch(macStatsReq->statsList[macStatsIdx].type)
1061             {
1062                case MAC_DL_TOTAL_PRB_USAGE:
1063                   {
1064                      schStatsReq->statsList[schStatsIdx].type = SCH_DL_TOTAL_PRB_USAGE;
1065                      break;
1066                   }
1067                case MAC_UL_TOTAL_PRB_USAGE:
1068                   {
1069                      schStatsReq->statsList[schStatsIdx].type = SCH_UL_TOTAL_PRB_USAGE;
1070                      break;
1071                   }
1072                default:
1073                   {
1074                      DU_LOG("\nERROR  -->  MAC : MacProcStatsReq: Invalid measurement type [%d]", \
1075                         macStatsReq->statsList[macStatsIdx].type);
1076                      measTypeInvalid = true;
1077                   }
1078             }
1079
1080             if(!measTypeInvalid)
1081             {
1082                schStatsReq->statsList[schStatsIdx].periodicity = macStatsReq->statsList[macStatsIdx].periodicity;
1083                schStatsIdx++;
1084                measTypeInvalid = false;
1085             }
1086          }
1087          schStatsReq->numStats = schStatsIdx;
1088
1089          /* If no measurement types are valid, it is failure scenario.
1090           * Even if one measurement type is valid, send to SCH */
1091          if(schStatsReq->numStats)
1092          {
1093             FILL_PST_MAC_TO_SCH(schPst, EVENT_STATISTICS_REQ_TO_SCH);
1094             ret = SchMessageRouter(&schPst, (void *)schStatsReq);
1095          }
1096          else
1097          {
1098             cause = PARAM_INVALID;
1099          }
1100       }
1101       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macStatsReq, sizeof(MacStatsReq));
1102    }
1103    else
1104    {
1105       DU_LOG("\nERROR  -->  MAC : MacProcStatsReq(): Received Null pointer");
1106       cause = PARAM_INVALID;
1107    }
1108
1109    if(ret == RFAILED)
1110    {
1111       /* Send negative acknowledgment to DU APP. TBD in next gerrit */
1112    }
1113    return ret;
1114 }
1115
1116 /**********************************************************************
1117   End of file
1118  **********************************************************************/