305c5783d3acf4c26847aaa5e3001c1a54d3ae3f
[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 /**
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    printf("\nReceived Scheduler gen config at MAC");
84    pst->dstInst = DEFAULT_CELLS + 1;
85    SchProcGenCfgReq(pst, cfg);
86
87    return ROK;
88 }
89
90 /**
91  * @brief Layer Manager Configuration response from Scheduler
92  *
93  * @details
94  *
95  *     Function : SchSendCfgCfm
96  *
97  *     This function sends general configurations response from
98  *     Scheduler to DU APP.
99  *
100  *  @param[in]  Pst *pst, the post structure
101  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
102  *  @return 
103  *      -# ROK
104  **/
105 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt  *cfm)
106 {
107    DU_LOG("\nDEBUG  -->  Sending Scheduler config confirm to DU APP");
108    pst->dstEnt = ENTDUAPP;
109    pst->dstInst = 0;
110    pst->srcInst = 0;
111    pst->selector = ODU_SELECTOR_LC;
112    RgMiLrgSchCfgCfm(pst, cfm);
113
114    return ROK;
115 }
116
117 /**
118  * @brief Layer Manager Configuration request handler.
119  *
120  * @details
121  *
122  *     Function : MacProcCellCfgReq
123  *
124  *     This function handles the gNB and cell configuration
125  *     request received from DU APP.
126  *     This API unapcks and forwards the config towards SCH
127  *
128  *  @param[in]  Pst           *pst
129  *  @param[in]  MacCellCfg    *macCellCfg
130  *  @return  
131  *      -# ROK
132  **/
133 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
134 {
135    Pst cfmPst;
136    uint16_t cellIdx;
137    uint8_t ret = ROK, sliceIdx = 0;
138    MacCellCb     *macCellCb;
139
140    memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
141
142    MAC_ALLOC(macCellCb, sizeof(MacCellCb));
143    if(macCellCb == NULLP)
144    {
145       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of macCellCfg\n");
146       return RFAILED;
147    }
148    memset(macCellCb, 0, sizeof(MacCellCb));
149
150    GET_CELL_IDX(macCellCfg->cellId, cellIdx);
151    macCb.macCell[cellIdx] = macCellCb;
152    macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
153    memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
154
155    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
156          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
157    if(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu == NULLP)
158    {
159       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
160       return RFAILED;
161    }
162    memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
163          macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
164    
165    macCb.macCell[cellIdx]->macCellCfg.numSupportedSlice = macCellCfg->numSupportedSlice;
166    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.snssai, macCb.macCell[cellIdx]->macCellCfg.numSupportedSlice\
167          * sizeof(Snssai*));
168    if(macCb.macCell[cellIdx]->macCellCfg.snssai == NULLP)
169    {
170       DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
171       return RFAILED;
172    }
173
174    if(macCb.macCell[cellIdx]->macCellCfg.snssai)
175    {
176       for(sliceIdx=0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.numSupportedSlice; sliceIdx++)
177       {
178          if(macCellCfg->snssai[sliceIdx])
179          {
180             MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.snssai[sliceIdx], sizeof(Snssai));
181             if(!macCb.macCell[cellIdx]->macCellCfg.snssai[sliceIdx])
182             {
183                DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
184                return RFAILED;
185             }
186             memcpy(macCb.macCell[cellIdx]->macCellCfg.snssai[sliceIdx], macCellCfg->snssai[sliceIdx], sizeof(Snssai));
187          }
188       }
189    }
190
191    /* Send cell cfg to scheduler */
192    ret = MacSchCellCfgReq(pst, macCellCfg);
193    if(ret != ROK)
194    {
195       MacCellCfgCfm macCellCfgCfm;
196       macCellCfgCfm.rsp = RSP_NOK;
197       macCellCfgCfm.cellId = macCellCfg->cellId;
198       /* Fill Pst */
199       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
200       cfmPst.selector  = ODU_SELECTOR_LC;
201
202       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
203    }
204    else
205    {
206       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
207    }
208    return ret;
209 } /* end of MacProcCellCfgReq */
210
211 /**
212  * @brief Layer Manager Configuration request handler.
213  *
214  * @details
215  *
216  *     Function : MacSchCellCfgReq
217  *
218  *     This function sends cell configuration to SCH
219  *
220  *  @param[in]  Pst           *pst
221  *  @param[in]  MacCellCfg    *macCellCfg
222  *  @return  
223  *      -# ROK
224  **/
225 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
226 {
227    SchCellCfg schCellCfg;
228    Pst        cfgPst;
229    uint8_t    ssbMaskIdx = 0, rsrcListIdx = 0, ret=0, sliceIdx=0;
230
231    memset(&cfgPst, 0, sizeof(Pst));
232    memset(&schCellCfg, 0, sizeof(SchCellCfg));
233    schCellCfg.cellId = macCellCfg->cellId;
234    schCellCfg.phyCellId = macCellCfg->phyCellId;
235    schCellCfg.numerology = macCellCfg->numerology;
236    schCellCfg.dupMode = macCellCfg->dupType;
237    schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
238    schCellCfg.dlFreq = macCellCfg->dlCarrCfg.freq;
239    schCellCfg.ulFreq = macCellCfg->ulCarrCfg.freq;
240
241    /* fill ssb scheduler parameters */
242    schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
243    schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
244    schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
245    schCellCfg.ssbSchCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
246    schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
247    for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
248    {
249       schCellCfg.ssbSchCfg.nSSBMask[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
250    }
251
252    /* fill SIB1 scheduler parameters */
253    schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
254    schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
255    schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
256    schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
257    schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
258
259    /* fill RACH config params */
260    schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
261    schCellCfg.schRachCfg.prachSubcSpacing = \
262                                             macCellCfg->prachCfg.prachSubcSpacing;
263    schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
264    schCellCfg.schRachCfg.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
265    schCellCfg.schRachCfg.rootSeqLen    = macCellCfg->prachCfg.rootSeqLen;
266    schCellCfg.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
267    schCellCfg.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
268    schCellCfg.schRachCfg.k1            = macCellCfg->prachCfg.fdm[0].k1;
269    schCellCfg.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
270    schCellCfg.schRachCfg.prachMultCarrBand = \
271                                              macCellCfg->prachCfg.prachMultCarrBand;
272    schCellCfg.schRachCfg.raContResTmr  = macCellCfg->prachCfg.raContResTmr;
273    schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
274    schCellCfg.schRachCfg.raRspWindow   = macCellCfg->prachCfg.raRspWindow;
275
276    /* fill initial DL BWP */
277    schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
278    schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
279    schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
280    schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
281    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
282       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
283    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
284       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
285    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
286       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
287    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
288       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
289    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
290       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
291    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
292       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
293    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
294       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
295    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
296       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
297    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
298       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
299    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
300       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
301    schCellCfg.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc;
302    for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
303    {
304       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 = 
305          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
306       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
307          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
308       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
309          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
310       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
311          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
312    }
313
314    /* fill initial UL BWP */
315    schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
316    schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
317    schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
318    schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
319    schCellCfg.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
320       macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
321    for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
322    {
323       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 = 
324          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
325       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
326          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
327       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
328          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
329       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
330          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
331    }
332
333    if(macCellCfg->snssai) 
334    {
335       schCellCfg.numSliceSupport = macCellCfg->numSupportedSlice;
336       MAC_ALLOC(schCellCfg.snssai, schCellCfg.numSliceSupport * sizeof(Snssai*));
337       if(!schCellCfg.snssai)
338       {
339          DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
340          return RFAILED;
341       }
342       for(sliceIdx=0; sliceIdx<schCellCfg.numSliceSupport; sliceIdx++)
343       {
344          if(macCellCfg->snssai[sliceIdx])
345          {
346             MAC_ALLOC(schCellCfg.snssai[sliceIdx], sizeof(Snssai));
347             if(!schCellCfg.snssai[sliceIdx])
348             {
349                DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
350                return RFAILED;
351             }
352             memcpy(schCellCfg.snssai[sliceIdx], macCellCfg->snssai[sliceIdx],  sizeof(Snssai));
353          }
354       }
355    }
356    if(macCellCfg->rrmPolicy)
357    {
358       MAC_ALLOC(schCellCfg.rrmPolicy, sizeof(SchRrmPolicy));
359       if(!schCellCfg.rrmPolicy)
360       {
361          DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
362          return RFAILED;
363       }
364       memcpy(schCellCfg.rrmPolicy, macCellCfg->rrmPolicy, sizeof(SchRrmPolicy));
365    }
366
367 #ifdef NR_TDD
368    memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
369 #endif
370
371    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
372
373    ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
374    return ret;
375 } /* end of MacSchCellCfgReq */
376
377
378 /*******************************************************************
379  *
380  * @brief Sends Cell config confirm to DU APP
381  *
382  * @details
383  *
384  *    Function : MacSendCellCfgCfm
385  *
386  *    Functionality:
387  *      Sends Cell config confirm to DU APP
388  *
389  * @params[in] Response status
390  * @return void
391  *
392  * ****************************************************************/
393 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
394 {
395    Pst pst;
396    uint16_t   cellIdx;
397    MacCellCfgCfm macCellCfgCfm;
398
399    memset(&pst, 0, sizeof(Pst));
400
401    GET_CELL_IDX(cellId, cellIdx);
402    macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
403    macCellCfgCfm.rsp = response;
404
405    /* Fill Pst */
406    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
407    pst.selector  = ODU_SELECTOR_LC;
408
409    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
410 }
411
412
413 /**
414  * @brief Layer Manager Configuration response handler.
415  *
416  * @details
417  *
418  *     Function : MacProcSchCellCfgCfm
419  *
420  *     This function processes cell configuration to SCH
421  *
422  *  @param[in]  Pst           *pst
423  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
424  *  @return  int
425  *      -# ROK
426  **/
427 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
428 {
429    uint16_t *cellId = NULLP;
430
431 #ifdef CALL_FLOW_DEBUG_LOG
432    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_SCH_CELL_CFG_CFM\n");
433 #endif
434
435    if(schCellCfgCfm->rsp == RSP_OK)
436    {
437       cellId = &schCellCfgCfm->cellId;
438 #ifdef INTEL_TIMER_MODE
439       sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
440 #else
441       sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
442 #endif
443    }
444    else
445    {
446       MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
447    }
448    return ROK;
449 }
450
451 /*******************************************************************
452  *
453  * @brief MAC handler for config response from PHY
454  *
455  * @details
456  *
457  *    Function : fapiMacConfigRsp
458  *
459  *    Functionality:
460  *     Processes config response from PHY and sends cell config
461  *     confirm to DU APP
462  *
463  * @params[in]
464  * @return void
465  *
466  * ****************************************************************/
467 void fapiMacConfigRsp(uint16_t cellId)
468 {
469    /* TODO : Processing of config response from PHY */
470
471    /* Send cell config cfm to DU APP */
472    MacSendCellCfgCfm(cellId, RSP_OK);
473 }
474
475 /*******************************************************************
476  *
477  * @brief Fill and Send Cell Delete response from MAC to DU APP
478  *
479  * @details
480  *
481  *    Function : MacSendCellDeleteRsp
482  *
483  *    Functionality: Fill and Send Cell Delete response from MAC to DUAPP
484  *
485  * @params[in] MAC Cell delete result
486  *             SCH Cell delete response
487  * @return ROK     - success
488  *         RFAILED - failure
489  *
490  * ****************************************************************/
491 uint8_t MacSendCellDeleteRsp(CellDeleteStatus result, uint8_t cellId)
492 {
493    MacCellDeleteRsp *deleteRsp=NULLP;
494    Pst            rspPst;
495
496    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
497    if(!deleteRsp)
498    {
499       DU_LOG("\nERROR  -->  MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
500       return RFAILED;
501    }
502
503    /* Filling CELL delete response */
504    
505    memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
506    deleteRsp->cellId = cellId;
507    deleteRsp->result = result;
508
509    /* Fill Post structure and send CELL delete response*/
510    memset(&rspPst, 0, sizeof(Pst));
511    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
512    return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
513 }
514
515 /*******************************************************************
516  *
517  * @brief  Processes CELL delete response from scheduler
518  *
519  * @details
520  *
521  *    Function : MacProcSchCellDeleteRsp
522  *
523  *    Functionality:
524  *      Processes CELL delete from scheduler
525  *
526  * @params[in] Pst : Post structure
527  *             schCellDelRsp : Scheduler CELL delete respons
528  * @return ROK     - success
529  *         RFAILED - failure
530  *
531  * * ****************************************************************/
532 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
533 {
534    uint8_t  ret = ROK, sliceIdx = 0;
535    uint16_t cellIdx=0;
536    CellDeleteStatus status;
537    
538 #ifdef CALL_FLOW_DEBUG_LOG
539    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_CELL_DELETE_RSP_TO_MAC\n");
540 #endif  
541
542    if(schCellDelRsp)
543    {
544       if(schCellDelRsp->rsp == RSP_OK)
545       {
546          DU_LOG("\nINFO   -->  MAC : SCH CELL Delete response for cellId[%d] is successful ", \
547          schCellDelRsp->cellId);
548          GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
549          if(macCb.macCell[cellIdx])
550          {
551             if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
552             {
553                status  = SUCCESSFUL_RSP;
554                if(macCb.macCell[cellIdx]->macCellCfg.snssai)
555                {
556                   for(sliceIdx = 0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.numSupportedSlice; sliceIdx++)
557                   {
558                      MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.snssai[sliceIdx], sizeof(Snssai));
559                   }
560                   MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.snssai, macCb.macCell[cellIdx]->macCellCfg.\
561                   numSupportedSlice * sizeof(Snssai*));
562                }
563                MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
564                   macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
565                MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
566             }
567             else
568             {
569                 DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
570                 status = CELL_ID_INVALID;
571                 ret = RFAILED;
572             }
573          }
574          else
575          {
576             DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
577             status = CELL_ID_INVALID;
578             ret = RFAILED;
579          }
580       }
581       else
582       {
583          DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
584          status = CELL_ID_INVALID;
585          ret = RFAILED;
586       }
587       if(MacSendCellDeleteRsp(status, schCellDelRsp->cellId) != ROK)
588       {
589          DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
590          ret = RFAILED;
591       }
592
593    }
594    else
595    {
596       DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
597       ret = RFAILED;
598    }
599    return ret;
600 }
601
602 /*******************************************************************
603  *
604  * @brief Sends Cell delete req to Scheduler
605  *
606  * @details
607  *
608  *    Function : sendCellDelReqToSch
609  *
610  *    Functionality: sends Cell delete req to Scheduler
611  *
612  * @params[in]  SchCellDelete *schCellDel
613  * @return ROK     - success
614  *         RFAILED - failure
615  *
616  * ****************************************************************/
617
618 uint8_t sendCellDelReqToSch(SchCellDelete *schCellDel)
619 {
620    Pst schPst;
621    FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
622    return(*macSchCellDeleteReqOpts[schPst.selector])(&schPst, schCellDel);
623 }
624
625 /*******************************************************************
626  *
627  * @brief Handles CELL Delete requst from DU APP
628  *
629  * @details
630  *
631  *    Function : MacProcCellDeleteReq
632  *
633  *    Functionality: Handles CELL Delete requst from DU APP
634  *
635  * @params[in] Pst *pst, MacCellDelete *cellDelete
636  * @return ROK     - success
637  *         RFAILED - failure
638  *
639  *
640  * ****************************************************************/
641 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDelete *cellDelete)
642 {
643    uint8_t ret = ROK, cellIdx=0;
644    SchCellDelete schCellDelete;
645
646    DU_LOG("\nINFO   -->  MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
647
648    if(cellDelete)
649    {
650       GET_CELL_IDX(cellDelete->cellId, cellIdx);
651       if(macCb.macCell[cellIdx])
652       {
653          if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
654          {
655             memset(&schCellDelete, 0, sizeof(SchCellDelete));
656             schCellDelete.cellId =  cellDelete->cellId;
657             ret = sendCellDelReqToSch(&schCellDelete);
658             if(ret != ROK)
659             {
660                DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
661                ret = RFAILED;
662             }
663          }
664          else
665          {
666             DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
667             cellDelete->cellId);
668             ret = RFAILED;
669          }
670       }
671       else
672       {
673          DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
674                cellDelete->cellId);
675          ret = RFAILED;
676       }
677
678       if(ret == RFAILED)
679       {
680           DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Sending failure response to DU");
681           if(MacSendCellDeleteRsp(CELL_ID_INVALID, cellDelete->cellId) != ROK)
682           {
683              DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
684              cellDelete->cellId);
685           }
686
687       }
688       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDelete));
689    }
690    else
691    {
692       DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
693       ret = RFAILED;
694    }
695    return ret;
696 }
697
698 /**********************************************************************
699   End of file
700  **********************************************************************/