[Epic-ID: ODUHIGH-406][Task-ID: ODUHIGH-423]Fix for incorrect access of schCb instance
[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 SchCellCfgFunc SchCellCfgOpts[] =
46 {
47    packSchCellCfg,   /* packing for loosely coupled */
48    SchHdlCellCfgReq, /* packing for tightly coupled */
49    packSchCellCfg    /* packing for light weight loosly coupled */
50 };
51
52 MacSchCellDeleteReqFunc macSchCellDeleteReqOpts[]=
53 {
54    packMacSchCellDeleteReq,    /* packing for loosely coupled */
55    MacSchCellDeleteReq,        /* packing for tightly coupled */
56    packMacSchCellDeleteReq     /* packing for light weight loosely coupled */
57 };
58
59 MacDuCellDeleteRspFunc macDuCellDeleteRspOpts[] =
60 {
61    packDuMacCellDeleteRsp,   /* packing for loosely coupled */
62    DuProcMacCellDeleteRsp,   /* packing for tightly coupled */
63    packDuMacCellDeleteRsp   /* packing for light weight loosly coupled */
64 };
65
66 MacDuSliceCfgRspFunc macDuSliceCfgRspOpts[] =
67 {
68    packDuMacSliceCfgRsp,   /* packing for loosely coupled */
69    DuProcMacSliceCfgRsp,   /* packing for tightly coupled */
70    packDuMacSliceCfgRsp   /* packing for light weight loosly coupled */
71 };
72
73 MacDuSliceReCfgRspFunc macDuSliceReCfgRspOpts[] =
74 {
75    packDuMacSliceReCfgRsp,   /* packing for loosely coupled */
76    DuProcMacSliceReCfgRsp,   /* packing for tightly coupled */
77    packDuMacSliceReCfgRsp   /* 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    printf("\nReceived Scheduler gen config at MAC");
100    memset(&schPst, 0, sizeof(Pst));
101    FILL_PST_MAC_TO_SCH(schPst, EVENT_SCH_GEN_CFG);
102    SchProcGenCfgReq(&schPst, cfg);
103
104    return ROK;
105 }
106
107 /**
108  * @brief Layer Manager Configuration response from Scheduler
109  *
110  * @details
111  *
112  *     Function : SchSendCfgCfm
113  *
114  *     This function sends general configurations response from
115  *     Scheduler to DU APP.
116  *
117  *  @param[in]  Pst *pst, the post structure
118  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
119  *  @return 
120  *      -# ROK
121  **/
122 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt  *cfm)
123 {
124    DU_LOG("\nDEBUG  -->  Sending Scheduler config confirm to DU APP");
125    pst->dstEnt = ENTDUAPP;
126    pst->dstInst = 0;
127    pst->srcInst = 0;
128    pst->selector = ODU_SELECTOR_LC;
129    RgMiLrgSchCfgCfm(pst, cfm);
130
131    return ROK;
132 }
133
134 /**
135  * @brief Layer Manager Configuration request handler.
136  *
137  * @details
138  *
139  *     Function : MacProcCellCfgReq
140  *
141  *     This function handles the gNB and cell configuration
142  *     request received from DU APP.
143  *     This API unapcks and forwards the config towards SCH
144  *
145  *  @param[in]  Pst           *pst
146  *  @param[in]  MacCellCfg    *macCellCfg
147  *  @return  
148  *      -# ROK
149  **/
150 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
151 {
152    Pst cfmPst;
153    uint16_t cellIdx;
154    uint8_t ret = ROK, sliceIdx = 0;
155    MacCellCb     *macCellCb;
156
157    memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
158
159    MAC_ALLOC(macCellCb, sizeof(MacCellCb));
160    if(macCellCb == NULLP)
161    {
162       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of macCellCfg\n");
163       return RFAILED;
164    }
165    memset(macCellCb, 0, sizeof(MacCellCb));
166
167    GET_CELL_IDX(macCellCfg->cellId, cellIdx);
168    macCb.macCell[cellIdx] = macCellCb;
169    macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
170    memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
171
172    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
173          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
174    if(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu == NULLP)
175    {
176       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
177       return RFAILED;
178    }
179    memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
180          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
181    
182    macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice = macCellCfg->plmnInfoList.numSupportedSlice;
183    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai, macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice\
184          * sizeof(Snssai*));
185    if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai == NULLP)
186    {
187       DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
188       return RFAILED;
189    }
190
191    if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai)
192    {
193       for(sliceIdx=0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice; sliceIdx++)
194       {
195          if(macCellCfg->plmnInfoList.snssai[sliceIdx])
196          {
197             MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
198             if(!macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx])
199             {
200                DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
201                return RFAILED;
202             }
203             memcpy(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], macCellCfg->plmnInfoList.snssai[sliceIdx],\
204             sizeof(Snssai));
205          }
206       }
207    }
208
209    /* Send cell cfg to scheduler */
210    ret = MacSchCellCfgReq(pst, macCellCfg);
211    if(ret != ROK)
212    {
213       MacCellCfgCfm macCellCfgCfm;
214       macCellCfgCfm.rsp = RSP_NOK;
215       macCellCfgCfm.cellId = macCellCfg->cellId;
216       /* Fill Pst */
217       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
218       cfmPst.selector  = ODU_SELECTOR_LC;
219
220       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
221    }
222    else
223    {
224       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
225    }
226    return ret;
227 } /* end of MacProcCellCfgReq */
228
229 /**
230  * @brief Layer Manager Configuration request handler.
231  *
232  * @details
233  *
234  *     Function : MacSchCellCfgReq
235  *
236  *     This function sends cell configuration to SCH
237  *
238  *  @param[in]  Pst           *pst
239  *  @param[in]  MacCellCfg    *macCellCfg
240  *  @return  
241  *      -# ROK
242  **/
243 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
244 {
245    SchCellCfg schCellCfg;
246    Pst        cfgPst;
247    uint8_t    ssbMaskIdx = 0, rsrcListIdx = 0, ret=0, sliceIdx=0;
248
249    memset(&cfgPst, 0, sizeof(Pst));
250    memset(&schCellCfg, 0, sizeof(SchCellCfg));
251    schCellCfg.cellId = macCellCfg->cellId;
252    schCellCfg.phyCellId = macCellCfg->phyCellId;
253    schCellCfg.numerology = macCellCfg->numerology;
254    schCellCfg.dupMode = macCellCfg->dupType;
255    schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
256    schCellCfg.dlFreq = macCellCfg->dlCarrCfg.freq;
257    schCellCfg.ulFreq = macCellCfg->ulCarrCfg.freq;
258
259    /* fill ssb scheduler parameters */
260    schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
261    schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
262    schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
263    schCellCfg.ssbSchCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
264    schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
265    for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
266    {
267       schCellCfg.ssbSchCfg.nSSBMask[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
268    }
269    schCellCfg.ssbSchCfg.totNumSsb = countSetBits(schCellCfg.ssbSchCfg.nSSBMask[0]);
270
271    /* fill SIB1 scheduler parameters */
272    schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
273    schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
274    schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
275    schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
276    schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
277    schCellCfg.sib1SchCfg.pageCfg.numPO  =  macCellCfg->sib1Cfg.pagingCfg.numPO;
278    schCellCfg.sib1SchCfg.pageCfg.poPresent = macCellCfg->sib1Cfg.pagingCfg.poPresent;
279
280    if(schCellCfg.sib1SchCfg.pageCfg.poPresent)
281    {
282       memcpy(schCellCfg.sib1SchCfg.pageCfg.pagingOcc, macCellCfg->sib1Cfg.pagingCfg.pagingOcc, MAX_PO_PER_PF);
283    }
284
285    /* fill RACH config params */
286    schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
287    schCellCfg.schRachCfg.prachSubcSpacing = \
288                                             macCellCfg->prachCfg.prachSubcSpacing;
289    schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
290    schCellCfg.schRachCfg.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
291    schCellCfg.schRachCfg.rootSeqLen    = macCellCfg->prachCfg.rootSeqLen;
292    schCellCfg.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
293    schCellCfg.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
294    schCellCfg.schRachCfg.k1            = macCellCfg->prachCfg.fdm[0].k1;
295    schCellCfg.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
296    schCellCfg.schRachCfg.prachMultCarrBand = \
297                                              macCellCfg->prachCfg.prachMultCarrBand;
298    schCellCfg.schRachCfg.raContResTmr  = macCellCfg->prachCfg.raContResTmr;
299    schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
300    schCellCfg.schRachCfg.raRspWindow   = macCellCfg->prachCfg.raRspWindow;
301
302    /* fill initial DL BWP */
303    schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
304    schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
305    schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
306    schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
307    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
308       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
309    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
310       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
311    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
312       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
313    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
314       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
315    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
316       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
317    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
318       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
319    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
320       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
321    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
322       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
323    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
324       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
325    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
326       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
327    schCellCfg.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc;
328    for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
329    {
330       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 = 
331          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
332       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
333          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
334       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
335          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
336       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
337          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
338    }
339
340    /* fill initial UL BWP */
341    schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
342    schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
343    schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
344    schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
345    schCellCfg.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
346       macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
347    for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
348    {
349       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 = 
350          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
351       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
352          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
353       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
354          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
355       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
356          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
357    }
358
359    if(macCellCfg->plmnInfoList.snssai) 
360    {
361       schCellCfg.plmnInfoList.numSliceSupport = macCellCfg->plmnInfoList.numSupportedSlice;
362       MAC_ALLOC(schCellCfg.plmnInfoList.snssai, schCellCfg.plmnInfoList.numSliceSupport * sizeof(Snssai*));
363       if(!schCellCfg.plmnInfoList.snssai)
364       {
365          DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
366          return RFAILED;
367       }
368       for(sliceIdx=0; sliceIdx<schCellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
369       {
370          if(macCellCfg->plmnInfoList.snssai[sliceIdx])
371          {
372             MAC_ALLOC(schCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
373             if(!schCellCfg.plmnInfoList.snssai[sliceIdx])
374             {
375                DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
376                return RFAILED;
377             }
378             memcpy(schCellCfg.plmnInfoList.snssai[sliceIdx], macCellCfg->plmnInfoList.snssai[sliceIdx],  sizeof(Snssai));
379          }
380       }
381    }
382
383 #ifdef NR_TDD
384    memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
385 #endif
386
387    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
388
389    ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
390    return ret;
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(CellDeleteStatus result, 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->result = result;
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;
551    uint16_t cellIdx=0;
552    CellDeleteStatus status;
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                status  = SUCCESSFUL_RSP;
570                if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai)
571                {
572                   for(sliceIdx = 0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice; sliceIdx++)
573                   {
574                      MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
575                   }
576                   MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai, macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.\
577                   numSupportedSlice * sizeof(Snssai*));
578                }
579                MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
580                   macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
581                MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
582             }
583             else
584             {
585                 DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
586                 status = CELL_ID_INVALID;
587                 ret = RFAILED;
588             }
589          }
590          else
591          {
592             DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
593             status = CELL_ID_INVALID;
594             ret = RFAILED;
595          }
596       }
597       else
598       {
599          DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
600          status = CELL_ID_INVALID;
601          ret = RFAILED;
602       }
603       if(MacSendCellDeleteRsp(status, schCellDelRsp->cellId) != ROK)
604       {
605          DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
606          ret = RFAILED;
607       }
608
609    }
610    else
611    {
612       DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
613       ret = RFAILED;
614    }
615    return ret;
616 }
617
618 /*******************************************************************
619  *
620  * @brief Sends Cell delete req to Scheduler
621  *
622  * @details
623  *
624  *    Function : sendCellDelReqToSch
625  *
626  *    Functionality: sends Cell delete req to Scheduler
627  *
628  * @params[in]  SchCellDelete *schCellDel
629  * @return ROK     - success
630  *         RFAILED - failure
631  *
632  * ****************************************************************/
633
634 uint8_t sendCellDelReqToSch(SchCellDelete *schCellDel)
635 {
636    Pst schPst;
637    FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
638    return(*macSchCellDeleteReqOpts[schPst.selector])(&schPst, schCellDel);
639 }
640
641 /*******************************************************************
642  *
643  * @brief Handles CELL Delete requst from DU APP
644  *
645  * @details
646  *
647  *    Function : MacProcCellDeleteReq
648  *
649  *    Functionality: Handles CELL Delete requst from DU APP
650  *
651  * @params[in] Pst *pst, MacCellDelete *cellDelete
652  * @return ROK     - success
653  *         RFAILED - failure
654  *
655  *
656  * ****************************************************************/
657 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDelete *cellDelete)
658 {
659    uint8_t ret = ROK, cellIdx=0;
660    SchCellDelete schCellDelete;
661
662    DU_LOG("\nINFO   -->  MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
663
664    if(cellDelete)
665    {
666       GET_CELL_IDX(cellDelete->cellId, cellIdx);
667       if(macCb.macCell[cellIdx])
668       {
669          if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
670          {
671             memset(&schCellDelete, 0, sizeof(SchCellDelete));
672             schCellDelete.cellId =  cellDelete->cellId;
673             ret = sendCellDelReqToSch(&schCellDelete);
674             if(ret != ROK)
675             {
676                DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
677                ret = RFAILED;
678             }
679          }
680          else
681          {
682             DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
683             cellDelete->cellId);
684             ret = RFAILED;
685          }
686       }
687       else
688       {
689          DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
690                cellDelete->cellId);
691          ret = RFAILED;
692       }
693
694       if(ret == RFAILED)
695       {
696           DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Sending failure response to DU");
697           if(MacSendCellDeleteRsp(CELL_ID_INVALID, cellDelete->cellId) != ROK)
698           {
699              DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
700              cellDelete->cellId);
701           }
702
703       }
704       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDelete));
705    }
706    else
707    {
708       DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
709       ret = RFAILED;
710    }
711    return ret;
712 }
713
714 /**
715  * @brief free the temporary slice cfg stored in macCb.
716  *
717  * @details
718  *
719  *     Function : freeMacSliceCfgReq 
720  *
721  *   free the temporary slice cfg stored in macCb
722  *
723  *  @param[in]  
724  *  @return  int
725  *      -# ROK
726  **/
727 void freeMacSliceCfgReq(MacSliceCfgReq *cfgReq,Pst *pst)
728 {
729    uint8_t cfgIdx = 0;
730    
731    if(cfgReq)
732    {
733       if(cfgReq->numOfConfiguredSlice)
734       {
735          for(cfgIdx = 0; cfgIdx<cfgReq->numOfConfiguredSlice; cfgIdx++)
736          {
737             if(cfgReq->listOfSliceCfg[cfgIdx])
738             {
739                MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio, sizeof(RrmPolicyRatio)); 
740             }
741             MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg[cfgIdx], sizeof(MacSliceRrmPolicy));
742          }
743          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg, cfgReq->numOfConfiguredSlice * sizeof(MacSliceRrmPolicy*));
744       }
745       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq, sizeof(MacSliceCfgReq));
746    }
747 }
748 /**
749  * @brief fill Mac Slice Config Rsp
750  *
751  * @details
752  *
753  *     Function : fillMacSliceCfgRsp 
754  *
755  *     This function   fill Mac Slice Config Rsp
756  *
757  *  @param[in]  SchSliceCfgRsp *sliceCfgRsp, MacSliceCfgRsp *macSliceCfgRsp,
758  *  uint8_t *count
759  *  @return  int
760  *      -# ROK
761  **/
762 uint8_t fillMacSliceCfgRsp(SchSliceCfgRsp *schSliceCfgRsp, MacSliceCfgRsp *macSliceCfgRsp)
763 {
764    
765     bool sliceFound = false;
766     uint8_t cfgIdx = 0;
767
768     macSliceCfgRsp->numSliceCfgRsp  = schSliceCfgRsp->numSliceCfgRsp;
769     MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp->listOfSliceCfgRsp,  macSliceCfgRsp->numSliceCfgRsp* sizeof(MacSliceRsp*));
770     if(macSliceCfgRsp->listOfSliceCfgRsp == NULLP)
771     {
772        DU_LOG("\nERROR  -->  MAC : Memory allocation failedi in fillMacSliceCfgRsp");
773        return RFAILED;
774     }
775
776     for(cfgIdx = 0; cfgIdx<schSliceCfgRsp->numSliceCfgRsp; cfgIdx++)
777     {
778        sliceFound = false;
779        if(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp == RSP_OK)
780        {
781           sliceFound = true;
782        }
783
784        MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(SliceRsp));
785        if(macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx] == NULLP)
786        {
787           DU_LOG("\nERROR  -->  MAC : Memory allocation failedi in fillMacSliceCfgRsp");
788           return RFAILED;
789        }
790
791        macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->snssai = schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->snssai;
792        if(sliceFound == true)
793           macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp    = MAC_DU_APP_RSP_OK;
794        else
795        {
796           macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp    = MAC_DU_APP_RSP_NOK;
797           macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->cause  = SLICE_NOT_PRESENT;
798        }
799     }
800     return ROK;
801 }
802
803 /**
804  * @brief send slice cfg response to duapp.
805  *
806  * @details
807  *
808  *     Function : MacSendSliceConfigRsp
809  *
810  *   sends  slice cfg response to duapp
811  *
812  *  @param[in] MacSliceCfgRsp macSliceCfgRsp 
813  *  @return  int
814  *      -# ROK
815  **/
816 uint8_t MacSendSliceConfigRsp(MacSliceCfgRsp *macSliceCfgRsp)
817 {
818     Pst  rspPst;
819     
820     memset(&rspPst, 0, sizeof(Pst));
821     FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_CFG_RSP);
822     return (*macDuSliceCfgRspOpts[rspPst.selector])(&rspPst, macSliceCfgRsp);
823
824 }
825 /**
826  * @brief free the slice cfg rsp received from sch.
827  *
828  * @details
829  *
830  *     Function : freeSchSliceCfgRsp 
831  *
832  *     This free the slice cfg rsp received from sch
833  *
834  *  @param[in]  SchSliceCfgRsp *sliceCfgrsp
835  *  @return  int
836  *      -# ROK
837  **/
838 void freeSchSliceCfgRsp(SchSliceCfgRsp *schSliceCfgRsp)
839 {
840    uint8_t cfgIdx = 0;
841
842    if(schSliceCfgRsp)
843    {
844       if(schSliceCfgRsp->numSliceCfgRsp)
845       {
846          for(cfgIdx = 0; cfgIdx< schSliceCfgRsp->numSliceCfgRsp; cfgIdx++)
847          {
848             MAC_FREE(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(SliceRsp));
849          }
850          MAC_FREE(schSliceCfgRsp->listOfSliceCfgRsp, schSliceCfgRsp->numSliceCfgRsp * sizeof(SliceRsp*));
851       }
852    }
853 }
854
855 /**
856  * @brief Mac process the slice cfg rsp received from sch.
857  *
858  * @details
859  *
860  *     Function : MacProcSchSliceCfgRsp 
861  *
862  *     This function  process the slice cfg rsp received from sch
863  *
864  *  @param[in]  Pst           *pst
865  *  @param[in]  SchSliceCfgRsp *sliceCfgrsp
866  *  @return  int
867  *      -# ROK
868  **/
869 uint8_t MacProcSchSliceCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceCfgRsp)
870 {
871    MacSliceCfgRsp *macSliceCfgRsp = NULLP;
872
873    if(schSliceCfgRsp)
874    {
875       MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp, sizeof(MacSliceCfgRsp));
876       if(macSliceCfgRsp == NULLP)
877       {
878           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceCfgRsp");
879           return RFAILED;
880       }
881       if(schSliceCfgRsp->listOfSliceCfgRsp)
882       {
883          if(fillMacSliceCfgRsp(schSliceCfgRsp, macSliceCfgRsp) != ROK)
884          {
885             DU_LOG("\nERROR  -->  MAC : Failed to fill the slice cfg response");
886             return RFAILED;
887          }
888          MacSendSliceConfigRsp(macSliceCfgRsp);
889       }
890       freeSchSliceCfgRsp(schSliceCfgRsp);
891    }
892    return ROK;
893 }
894
895 /**
896 * @brief send slice cfg response to duapp.
897 *
898 * @details
899 *
900 *     Function : MacSendSliceReconfigRsp 
901 *
902 *   sends  slice cfg response to duapp
903 *
904 *  @param[in] MacSliceCfgRsp macSliceRecfgRsp
905 *  @return  int
906 *      -# ROK
907 **/
908 uint8_t MacSendSliceReconfigRsp(MacSliceCfgRsp *macSliceRecfgRsp)
909 {
910    Pst  rspPst;
911
912    memset(&rspPst, 0, sizeof(Pst));
913    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_RECFG_RSP);
914    return (*macDuSliceReCfgRspOpts[rspPst.selector])(&rspPst, macSliceRecfgRsp);
915
916 }
917
918 /**
919  * @brief Mac process the slice cfg rsp received from sch.
920  *
921  * @details
922  *
923  *     Function : MacProcSchSliceReCfgRsp 
924  *
925  *     This function  process the slice cfg rsp received from sch
926  *
927  *  @param[in]  Pst           *pst
928  *  @param[in]  SchSliceCfgRsp *schSliceRecfgRsp
929  *  @return  int
930  *      -# ROK
931  **/
932 uint8_t MacProcSchSliceReCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceRecfgRsp)
933 {
934    MacSliceCfgRsp *macSliceReCfgRsp = NULLP;
935
936    if(schSliceRecfgRsp)
937    {
938       MAC_ALLOC_SHRABL_BUF(macSliceReCfgRsp, sizeof(MacSliceCfgRsp));
939       if(macSliceReCfgRsp == NULLP)
940       {
941           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceReCfgRsp");
942           return RFAILED;
943       }
944
945       if(schSliceRecfgRsp->listOfSliceCfgRsp)
946       {
947          if(fillMacSliceCfgRsp(schSliceRecfgRsp, macSliceReCfgRsp) != ROK)
948          {
949             DU_LOG("\nERROR  -->  MAC : Failed to fill the slice Recfg response");
950             return RFAILED;
951          }
952          MacSendSliceReconfigRsp(macSliceReCfgRsp);
953       }
954       freeSchSliceCfgRsp(schSliceRecfgRsp);
955    }
956    return ROK;
957 }
958 /**********************************************************************
959   End of file
960  **********************************************************************/