6f193c0bbe0de3f0a40c4ff4aaaa38cbc232362d
[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    printf("\nReceived Scheduler gen config at MAC");
98    pst->dstInst = DEFAULT_CELLS + 1;
99    SchProcGenCfgReq(pst, cfg);
100
101    return ROK;
102 }
103
104 /**
105  * @brief Layer Manager Configuration response from Scheduler
106  *
107  * @details
108  *
109  *     Function : SchSendCfgCfm
110  *
111  *     This function sends general configurations response from
112  *     Scheduler to DU APP.
113  *
114  *  @param[in]  Pst *pst, the post structure
115  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
116  *  @return 
117  *      -# ROK
118  **/
119 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt  *cfm)
120 {
121    DU_LOG("\nDEBUG  -->  Sending Scheduler config confirm to DU APP");
122    pst->dstEnt = ENTDUAPP;
123    pst->dstInst = 0;
124    pst->srcInst = 0;
125    pst->selector = ODU_SELECTOR_LC;
126    RgMiLrgSchCfgCfm(pst, cfm);
127
128    return ROK;
129 }
130
131 /**
132  * @brief Layer Manager Configuration request handler.
133  *
134  * @details
135  *
136  *     Function : MacProcCellCfgReq
137  *
138  *     This function handles the gNB and cell configuration
139  *     request received from DU APP.
140  *     This API unapcks and forwards the config towards SCH
141  *
142  *  @param[in]  Pst           *pst
143  *  @param[in]  MacCellCfg    *macCellCfg
144  *  @return  
145  *      -# ROK
146  **/
147 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
148 {
149    Pst cfmPst;
150    uint16_t cellIdx;
151    uint8_t ret = ROK, sliceIdx = 0;
152    MacCellCb     *macCellCb;
153
154    memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
155
156    MAC_ALLOC(macCellCb, sizeof(MacCellCb));
157    if(macCellCb == NULLP)
158    {
159       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of macCellCfg\n");
160       return RFAILED;
161    }
162    memset(macCellCb, 0, sizeof(MacCellCb));
163
164    GET_CELL_IDX(macCellCfg->cellId, cellIdx);
165    macCb.macCell[cellIdx] = macCellCb;
166    macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
167    memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
168
169    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
170          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
171    if(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu == NULLP)
172    {
173       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
174       return RFAILED;
175    }
176    memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
177          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
178    
179    macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice = macCellCfg->plmnInfoList.numSupportedSlice;
180    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai, macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice\
181          * sizeof(Snssai*));
182    if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai == NULLP)
183    {
184       DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
185       return RFAILED;
186    }
187
188    if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai)
189    {
190       for(sliceIdx=0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice; sliceIdx++)
191       {
192          if(macCellCfg->plmnInfoList.snssai[sliceIdx])
193          {
194             MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
195             if(!macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx])
196             {
197                DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
198                return RFAILED;
199             }
200             memcpy(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], macCellCfg->plmnInfoList.snssai[sliceIdx],\
201             sizeof(Snssai));
202          }
203       }
204    }
205
206    /* Send cell cfg to scheduler */
207    ret = MacSchCellCfgReq(pst, macCellCfg);
208    if(ret != ROK)
209    {
210       MacCellCfgCfm macCellCfgCfm;
211       macCellCfgCfm.rsp = RSP_NOK;
212       macCellCfgCfm.cellId = macCellCfg->cellId;
213       /* Fill Pst */
214       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
215       cfmPst.selector  = ODU_SELECTOR_LC;
216
217       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
218    }
219    else
220    {
221       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
222    }
223    return ret;
224 } /* end of MacProcCellCfgReq */
225
226 /**
227  * @brief Layer Manager Configuration request handler.
228  *
229  * @details
230  *
231  *     Function : MacSchCellCfgReq
232  *
233  *     This function sends cell configuration to SCH
234  *
235  *  @param[in]  Pst           *pst
236  *  @param[in]  MacCellCfg    *macCellCfg
237  *  @return  
238  *      -# ROK
239  **/
240 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
241 {
242    SchCellCfg schCellCfg;
243    Pst        cfgPst;
244    uint8_t    ssbMaskIdx = 0, rsrcListIdx = 0, ret=0, sliceIdx=0;
245
246    memset(&cfgPst, 0, sizeof(Pst));
247    memset(&schCellCfg, 0, sizeof(SchCellCfg));
248    schCellCfg.cellId = macCellCfg->cellId;
249    schCellCfg.phyCellId = macCellCfg->phyCellId;
250    schCellCfg.numerology = macCellCfg->numerology;
251    schCellCfg.dupMode = macCellCfg->dupType;
252    schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
253    schCellCfg.dlFreq = macCellCfg->dlCarrCfg.freq;
254    schCellCfg.ulFreq = macCellCfg->ulCarrCfg.freq;
255
256    /* fill ssb scheduler parameters */
257    schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
258    schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
259    schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
260    schCellCfg.ssbSchCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
261    schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
262    for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
263    {
264       schCellCfg.ssbSchCfg.nSSBMask[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
265    }
266
267    /* fill SIB1 scheduler parameters */
268    schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
269    schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
270    schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
271    schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
272    schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
273
274    /* fill RACH config params */
275    schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
276    schCellCfg.schRachCfg.prachSubcSpacing = \
277                                             macCellCfg->prachCfg.prachSubcSpacing;
278    schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
279    schCellCfg.schRachCfg.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
280    schCellCfg.schRachCfg.rootSeqLen    = macCellCfg->prachCfg.rootSeqLen;
281    schCellCfg.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
282    schCellCfg.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
283    schCellCfg.schRachCfg.k1            = macCellCfg->prachCfg.fdm[0].k1;
284    schCellCfg.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
285    schCellCfg.schRachCfg.prachMultCarrBand = \
286                                              macCellCfg->prachCfg.prachMultCarrBand;
287    schCellCfg.schRachCfg.raContResTmr  = macCellCfg->prachCfg.raContResTmr;
288    schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
289    schCellCfg.schRachCfg.raRspWindow   = macCellCfg->prachCfg.raRspWindow;
290
291    /* fill initial DL BWP */
292    schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
293    schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
294    schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
295    schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
296    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
297       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
298    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
299       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
300    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
301       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
302    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
303       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
304    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
305       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
306    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
307       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
308    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
309       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
310    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
311       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
312    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
313       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
314    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
315       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
316    schCellCfg.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc;
317    for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
318    {
319       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 = 
320          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
321       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
322          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
323       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
324          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
325       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
326          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
327    }
328
329    /* fill initial UL BWP */
330    schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
331    schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
332    schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
333    schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
334    schCellCfg.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
335       macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
336    for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
337    {
338       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 = 
339          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
340       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
341          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
342       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
343          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
344       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
345          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
346    }
347
348    if(macCellCfg->plmnInfoList.snssai) 
349    {
350       schCellCfg.plmnInfoList.numSliceSupport = macCellCfg->plmnInfoList.numSupportedSlice;
351       MAC_ALLOC(schCellCfg.plmnInfoList.snssai, schCellCfg.plmnInfoList.numSliceSupport * sizeof(Snssai*));
352       if(!schCellCfg.plmnInfoList.snssai)
353       {
354          DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
355          return RFAILED;
356       }
357       for(sliceIdx=0; sliceIdx<schCellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
358       {
359          if(macCellCfg->plmnInfoList.snssai[sliceIdx])
360          {
361             MAC_ALLOC(schCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
362             if(!schCellCfg.plmnInfoList.snssai[sliceIdx])
363             {
364                DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
365                return RFAILED;
366             }
367             memcpy(schCellCfg.plmnInfoList.snssai[sliceIdx], macCellCfg->plmnInfoList.snssai[sliceIdx],  sizeof(Snssai));
368          }
369       }
370    }
371
372 #ifdef NR_TDD
373    memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
374 #endif
375
376    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
377
378    ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
379    return ret;
380 } /* end of MacSchCellCfgReq */
381
382
383 /*******************************************************************
384  *
385  * @brief Sends Cell config confirm to DU APP
386  *
387  * @details
388  *
389  *    Function : MacSendCellCfgCfm
390  *
391  *    Functionality:
392  *      Sends Cell config confirm to DU APP
393  *
394  * @params[in] Response status
395  * @return void
396  *
397  * ****************************************************************/
398 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
399 {
400    Pst pst;
401    uint16_t   cellIdx;
402    MacCellCfgCfm macCellCfgCfm;
403
404    memset(&pst, 0, sizeof(Pst));
405
406    GET_CELL_IDX(cellId, cellIdx);
407    macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
408    macCellCfgCfm.rsp = response;
409
410    /* Fill Pst */
411    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
412    pst.selector  = ODU_SELECTOR_LC;
413
414    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
415 }
416
417
418 /**
419  * @brief Layer Manager Configuration response handler.
420  *
421  * @details
422  *
423  *     Function : MacProcSchCellCfgCfm
424  *
425  *     This function processes cell configuration to SCH
426  *
427  *  @param[in]  Pst           *pst
428  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
429  *  @return  int
430  *      -# ROK
431  **/
432 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
433 {
434    uint16_t *cellId = NULLP;
435
436 #ifdef CALL_FLOW_DEBUG_LOG
437    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_SCH_CELL_CFG_CFM\n");
438 #endif
439
440    if(schCellCfgCfm->rsp == RSP_OK)
441    {
442       cellId = &schCellCfgCfm->cellId;
443 #ifdef INTEL_TIMER_MODE
444       sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
445 #else
446       sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
447 #endif
448    }
449    else
450    {
451       MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
452    }
453    return ROK;
454 }
455
456 /*******************************************************************
457  *
458  * @brief MAC handler for config response from PHY
459  *
460  * @details
461  *
462  *    Function : fapiMacConfigRsp
463  *
464  *    Functionality:
465  *     Processes config response from PHY and sends cell config
466  *     confirm to DU APP
467  *
468  * @params[in]
469  * @return void
470  *
471  * ****************************************************************/
472 void fapiMacConfigRsp(uint16_t cellId)
473 {
474    /* TODO : Processing of config response from PHY */
475
476    /* Send cell config cfm to DU APP */
477    MacSendCellCfgCfm(cellId, RSP_OK);
478 }
479
480 /*******************************************************************
481  *
482  * @brief Fill and Send Cell Delete response from MAC to DU APP
483  *
484  * @details
485  *
486  *    Function : MacSendCellDeleteRsp
487  *
488  *    Functionality: Fill and Send Cell Delete response from MAC to DUAPP
489  *
490  * @params[in] MAC Cell delete result
491  *             SCH Cell delete response
492  * @return ROK     - success
493  *         RFAILED - failure
494  *
495  * ****************************************************************/
496 uint8_t MacSendCellDeleteRsp(CellDeleteStatus result, uint8_t cellId)
497 {
498    MacCellDeleteRsp *deleteRsp=NULLP;
499    Pst            rspPst;
500
501    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
502    if(!deleteRsp)
503    {
504       DU_LOG("\nERROR  -->  MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
505       return RFAILED;
506    }
507
508    /* Filling CELL delete response */
509    
510    memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
511    deleteRsp->cellId = cellId;
512    deleteRsp->result = result;
513
514    /* Fill Post structure and send CELL delete response*/
515    memset(&rspPst, 0, sizeof(Pst));
516    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
517    return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
518 }
519
520 /*******************************************************************
521  *
522  * @brief  Processes CELL delete response from scheduler
523  *
524  * @details
525  *
526  *    Function : MacProcSchCellDeleteRsp
527  *
528  *    Functionality:
529  *      Processes CELL delete from scheduler
530  *
531  * @params[in] Pst : Post structure
532  *             schCellDelRsp : Scheduler CELL delete respons
533  * @return ROK     - success
534  *         RFAILED - failure
535  *
536  * * ****************************************************************/
537 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
538 {
539    uint8_t  ret = ROK, sliceIdx = 0;
540    uint16_t cellIdx=0;
541    CellDeleteStatus status;
542    
543 #ifdef CALL_FLOW_DEBUG_LOG
544    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_CELL_DELETE_RSP_TO_MAC\n");
545 #endif  
546
547    if(schCellDelRsp)
548    {
549       if(schCellDelRsp->rsp == RSP_OK)
550       {
551          DU_LOG("\nINFO   -->  MAC : SCH CELL Delete response for cellId[%d] is successful ", \
552          schCellDelRsp->cellId);
553          GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
554          if(macCb.macCell[cellIdx])
555          {
556             if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
557             {
558                status  = SUCCESSFUL_RSP;
559                if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai)
560                {
561                   for(sliceIdx = 0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice; sliceIdx++)
562                   {
563                      MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
564                   }
565                   MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai, macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.\
566                   numSupportedSlice * sizeof(Snssai*));
567                }
568                MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
569                   macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
570                MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
571             }
572             else
573             {
574                 DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
575                 status = CELL_ID_INVALID;
576                 ret = RFAILED;
577             }
578          }
579          else
580          {
581             DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
582             status = CELL_ID_INVALID;
583             ret = RFAILED;
584          }
585       }
586       else
587       {
588          DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
589          status = CELL_ID_INVALID;
590          ret = RFAILED;
591       }
592       if(MacSendCellDeleteRsp(status, schCellDelRsp->cellId) != ROK)
593       {
594          DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
595          ret = RFAILED;
596       }
597
598    }
599    else
600    {
601       DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
602       ret = RFAILED;
603    }
604    return ret;
605 }
606
607 /*******************************************************************
608  *
609  * @brief Sends Cell delete req to Scheduler
610  *
611  * @details
612  *
613  *    Function : sendCellDelReqToSch
614  *
615  *    Functionality: sends Cell delete req to Scheduler
616  *
617  * @params[in]  SchCellDelete *schCellDel
618  * @return ROK     - success
619  *         RFAILED - failure
620  *
621  * ****************************************************************/
622
623 uint8_t sendCellDelReqToSch(SchCellDelete *schCellDel)
624 {
625    Pst schPst;
626    FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
627    return(*macSchCellDeleteReqOpts[schPst.selector])(&schPst, schCellDel);
628 }
629
630 /*******************************************************************
631  *
632  * @brief Handles CELL Delete requst from DU APP
633  *
634  * @details
635  *
636  *    Function : MacProcCellDeleteReq
637  *
638  *    Functionality: Handles CELL Delete requst from DU APP
639  *
640  * @params[in] Pst *pst, MacCellDelete *cellDelete
641  * @return ROK     - success
642  *         RFAILED - failure
643  *
644  *
645  * ****************************************************************/
646 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDelete *cellDelete)
647 {
648    uint8_t ret = ROK, cellIdx=0;
649    SchCellDelete schCellDelete;
650
651    DU_LOG("\nINFO   -->  MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
652
653    if(cellDelete)
654    {
655       GET_CELL_IDX(cellDelete->cellId, cellIdx);
656       if(macCb.macCell[cellIdx])
657       {
658          if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
659          {
660             memset(&schCellDelete, 0, sizeof(SchCellDelete));
661             schCellDelete.cellId =  cellDelete->cellId;
662             ret = sendCellDelReqToSch(&schCellDelete);
663             if(ret != ROK)
664             {
665                DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
666                ret = RFAILED;
667             }
668          }
669          else
670          {
671             DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
672             cellDelete->cellId);
673             ret = RFAILED;
674          }
675       }
676       else
677       {
678          DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
679                cellDelete->cellId);
680          ret = RFAILED;
681       }
682
683       if(ret == RFAILED)
684       {
685           DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Sending failure response to DU");
686           if(MacSendCellDeleteRsp(CELL_ID_INVALID, cellDelete->cellId) != ROK)
687           {
688              DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
689              cellDelete->cellId);
690           }
691
692       }
693       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDelete));
694    }
695    else
696    {
697       DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
698       ret = RFAILED;
699    }
700    return ret;
701 }
702
703 /**
704  * @brief free the temporary slice cfg stored in macCb.
705  *
706  * @details
707  *
708  *     Function : freeMacSliceCfgReq 
709  *
710  *   free the temporary slice cfg stored in macCb
711  *
712  *  @param[in]  
713  *  @return  int
714  *      -# ROK
715  **/
716 void freeMacSliceCfgReq(MacSliceCfgReq *cfgReq,Pst *pst)
717 {
718    uint8_t cfgIdx = 0;
719    
720    if(cfgReq)
721    {
722       if(cfgReq->numOfConfiguredSlice)
723       {
724          for(cfgIdx = 0; cfgIdx<cfgReq->numOfConfiguredSlice; cfgIdx++)
725          {
726             if(cfgReq->listOfSliceCfg[cfgIdx])
727             {
728                MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio, sizeof(RrmPolicyRatio)); 
729             }
730             MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg[cfgIdx], sizeof(MacSliceRrmPolicy));
731          }
732          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg, cfgReq->numOfConfiguredSlice * sizeof(MacSliceRrmPolicy*));
733       }
734       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq, sizeof(MacSliceCfgReq));
735    }
736 }
737 /**
738  * @brief fill Mac Slice Config Rsp
739  *
740  * @details
741  *
742  *     Function : fillMacSliceCfgRsp 
743  *
744  *     This function   fill Mac Slice Config Rsp
745  *
746  *  @param[in]  SchSliceCfgRsp *sliceCfgRsp, MacSliceCfgRsp *macSliceCfgRsp,
747  *  uint8_t *count
748  *  @return  int
749  *      -# ROK
750  **/
751 uint8_t fillMacSliceCfgRsp(SchSliceCfgRsp *schSliceCfgRsp, MacSliceCfgRsp *macSliceCfgRsp)
752 {
753    
754     bool sliceFound = false;
755     uint8_t cfgIdx = 0;
756
757     macSliceCfgRsp->numSliceCfgRsp  = schSliceCfgRsp->numSliceCfgRsp;
758     MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp->listOfSliceCfgRsp,  macSliceCfgRsp->numSliceCfgRsp* sizeof(MacSliceRsp*));
759     if(macSliceCfgRsp->listOfSliceCfgRsp == NULLP)
760     {
761        DU_LOG("\nERROR  -->  MAC : Memory allocation failedi in fillMacSliceCfgRsp");
762        return RFAILED;
763     }
764
765     for(cfgIdx = 0; cfgIdx<schSliceCfgRsp->numSliceCfgRsp; cfgIdx++)
766     {
767        sliceFound = false;
768        if(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp == RSP_OK)
769        {
770           sliceFound = true;
771        }
772
773        MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(SliceRsp));
774        if(macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx] == NULLP)
775        {
776           DU_LOG("\nERROR  -->  MAC : Memory allocation failedi in fillMacSliceCfgRsp");
777           return RFAILED;
778        }
779
780        macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->snssai = schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->snssai;
781        if(sliceFound == true)
782           macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp    = MAC_DU_APP_RSP_OK;
783        else
784        {
785           macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp    = MAC_DU_APP_RSP_NOK;
786           macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->cause  = SLICE_NOT_PRESENT;
787        }
788     }
789     return ROK;
790 }
791
792 /**
793  * @brief send slice cfg response to duapp.
794  *
795  * @details
796  *
797  *     Function : MacSendSliceConfigRsp
798  *
799  *   sends  slice cfg response to duapp
800  *
801  *  @param[in] MacSliceCfgRsp macSliceCfgRsp 
802  *  @return  int
803  *      -# ROK
804  **/
805 uint8_t MacSendSliceConfigRsp(MacSliceCfgRsp *macSliceCfgRsp)
806 {
807     Pst  rspPst;
808     
809     memset(&rspPst, 0, sizeof(Pst));
810     FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_CFG_RSP);
811     return (*macDuSliceCfgRspOpts[rspPst.selector])(&rspPst, macSliceCfgRsp);
812
813 }
814 /**
815  * @brief free the slice cfg rsp received from sch.
816  *
817  * @details
818  *
819  *     Function : freeSchSliceCfgRsp 
820  *
821  *     This free the slice cfg rsp received from sch
822  *
823  *  @param[in]  SchSliceCfgRsp *sliceCfgrsp
824  *  @return  int
825  *      -# ROK
826  **/
827 void freeSchSliceCfgRsp(SchSliceCfgRsp *schSliceCfgRsp)
828 {
829    uint8_t cfgIdx = 0;
830
831    if(schSliceCfgRsp)
832    {
833       if(schSliceCfgRsp->numSliceCfgRsp)
834       {
835          for(cfgIdx = 0; cfgIdx< schSliceCfgRsp->numSliceCfgRsp; cfgIdx++)
836          {
837             MAC_FREE(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(SliceRsp));
838          }
839          MAC_FREE(schSliceCfgRsp->listOfSliceCfgRsp, schSliceCfgRsp->numSliceCfgRsp * sizeof(SliceRsp*));
840       }
841    }
842 }
843
844 /**
845  * @brief Mac process the slice cfg rsp received from sch.
846  *
847  * @details
848  *
849  *     Function : MacProcSchSliceCfgRsp 
850  *
851  *     This function  process the slice cfg rsp received from sch
852  *
853  *  @param[in]  Pst           *pst
854  *  @param[in]  SchSliceCfgRsp *sliceCfgrsp
855  *  @return  int
856  *      -# ROK
857  **/
858 uint8_t MacProcSchSliceCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceCfgRsp)
859 {
860    MacSliceCfgRsp *macSliceCfgRsp = NULLP;
861
862    if(schSliceCfgRsp)
863    {
864       MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp, sizeof(MacSliceCfgRsp));
865       if(macSliceCfgRsp == NULLP)
866       {
867           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceCfgRsp");
868           return RFAILED;
869       }
870       if(schSliceCfgRsp->listOfSliceCfgRsp)
871       {
872          if(fillMacSliceCfgRsp(schSliceCfgRsp, macSliceCfgRsp) != ROK)
873          {
874             DU_LOG("\nERROR  -->  MAC : Failed to fill the slice cfg response");
875             return RFAILED;
876          }
877          MacSendSliceConfigRsp(macSliceCfgRsp);
878       }
879       freeSchSliceCfgRsp(schSliceCfgRsp);
880    }
881    return ROK;
882 }
883
884 /**
885 * @brief send slice cfg response to duapp.
886 *
887 * @details
888 *
889 *     Function : MacSendSliceReconfigRsp 
890 *
891 *   sends  slice cfg response to duapp
892 *
893 *  @param[in] MacSliceCfgRsp macSliceRecfgRsp
894 *  @return  int
895 *      -# ROK
896 **/
897 uint8_t MacSendSliceReconfigRsp(MacSliceCfgRsp *macSliceRecfgRsp)
898 {
899    Pst  rspPst;
900
901    memset(&rspPst, 0, sizeof(Pst));
902    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_RECFG_RSP);
903    return (*macDuSliceReCfgRspOpts[rspPst.selector])(&rspPst, macSliceRecfgRsp);
904
905 }
906
907 /**
908  * @brief Mac process the slice cfg rsp received from sch.
909  *
910  * @details
911  *
912  *     Function : MacProcSchSliceReCfgRsp 
913  *
914  *     This function  process the slice cfg rsp received from sch
915  *
916  *  @param[in]  Pst           *pst
917  *  @param[in]  SchSliceCfgRsp *schSliceRecfgRsp
918  *  @return  int
919  *      -# ROK
920  **/
921 uint8_t MacProcSchSliceReCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceRecfgRsp)
922 {
923    MacSliceCfgRsp *macSliceReCfgRsp = NULLP;
924
925    if(schSliceRecfgRsp)
926    {
927       MAC_ALLOC_SHRABL_BUF(macSliceReCfgRsp, sizeof(MacSliceCfgRsp));
928       if(macSliceReCfgRsp == NULLP)
929       {
930           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceReCfgRsp");
931           return RFAILED;
932       }
933
934       if(schSliceRecfgRsp->listOfSliceCfgRsp)
935       {
936          if(fillMacSliceCfgRsp(schSliceRecfgRsp, macSliceReCfgRsp) != ROK)
937          {
938             DU_LOG("\nERROR  -->  MAC : Failed to fill the slice Recfg response");
939             return RFAILED;
940          }
941          MacSendSliceReconfigRsp(macSliceReCfgRsp);
942       }
943       freeSchSliceCfgRsp(schSliceRecfgRsp);
944    }
945    return ROK;
946 }
947 /**********************************************************************
948   End of file
949  **********************************************************************/