Encoding of MSG3 UL grant in RAR PDU [Issue-ID: ODUHIGH-342]
[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;
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    /* Send cell cfg to scheduler */
166    ret = MacSchCellCfgReq(pst, macCellCfg);
167    if(ret != ROK)
168    {
169       MacCellCfgCfm macCellCfgCfm;
170       macCellCfgCfm.rsp = RSP_NOK;
171       macCellCfgCfm.cellId = macCellCfg->cellId;
172       /* Fill Pst */
173       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
174       cfmPst.selector  = ODU_SELECTOR_LC;
175
176       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
177    }
178    else
179    {
180       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
181    }
182    return ret;
183 } /* end of MacProcCellCfgReq */
184
185 /**
186  * @brief Layer Manager Configuration request handler.
187  *
188  * @details
189  *
190  *     Function : MacSchCellCfgReq
191  *
192  *     This function sends cell configuration to SCH
193  *
194  *  @param[in]  Pst           *pst
195  *  @param[in]  MacCellCfg    *macCellCfg
196  *  @return  
197  *      -# ROK
198  **/
199 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
200 {
201    SchCellCfg schCellCfg;
202    Pst        cfgPst;
203    uint8_t    ssbMaskIdx = 0, rsrcListIdx = 0, ret=0;
204
205    memset(&cfgPst, 0, sizeof(Pst));
206    memset(&schCellCfg, 0, sizeof(SchCellCfg));
207    schCellCfg.cellId = macCellCfg->cellId;
208    schCellCfg.phyCellId = macCellCfg->phyCellId;
209    schCellCfg.numerology = macCellCfg->numerology;
210    schCellCfg.dupMode = macCellCfg->dupType;
211    schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
212    schCellCfg.dlFreq = macCellCfg->dlCarrCfg.freq;
213    schCellCfg.ulFreq = macCellCfg->ulCarrCfg.freq;
214
215    /* fill ssb scheduler parameters */
216    schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
217    schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
218    schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
219    schCellCfg.ssbSchCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
220    schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
221    for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
222    {
223       schCellCfg.ssbSchCfg.nSSBMask[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
224    }
225
226    /* fill SIB1 scheduler parameters */
227    schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
228    schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
229    schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
230    schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
231    schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
232
233    /* fill RACH config params */
234    schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
235    schCellCfg.schRachCfg.prachSubcSpacing = \
236                                             macCellCfg->prachCfg.prachSubcSpacing;
237    schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
238    schCellCfg.schRachCfg.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
239    schCellCfg.schRachCfg.rootSeqLen    = macCellCfg->prachCfg.rootSeqLen;
240    schCellCfg.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
241    schCellCfg.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
242    schCellCfg.schRachCfg.k1            = macCellCfg->prachCfg.fdm[0].k1;
243    schCellCfg.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
244    schCellCfg.schRachCfg.prachMultCarrBand = \
245                                              macCellCfg->prachCfg.prachMultCarrBand;
246    schCellCfg.schRachCfg.raContResTmr  = macCellCfg->prachCfg.raContResTmr;
247    schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
248    schCellCfg.schRachCfg.raRspWindow   = macCellCfg->prachCfg.raRspWindow;
249
250    /* fill initial DL BWP */
251    schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
252    schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
253    schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
254    schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
255    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
256       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
257    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
258       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
259    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
260       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
261    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
262       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
263    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
264       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
265    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
266       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
267    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
268       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
269    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
270       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
271    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
272       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
273    schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
274       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
275    schCellCfg.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc;
276    for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
277    {
278       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 = 
279          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
280       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
281          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
282       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
283          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
284       schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
285          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
286    }
287
288    /* fill initial UL BWP */
289    schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
290    schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
291    schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
292    schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
293    schCellCfg.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
294       macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
295    for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
296    {
297       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 = 
298          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
299       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
300          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
301       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
302          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
303       schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
304          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
305    }
306 #ifdef NR_TDD
307    memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
308 #endif
309
310    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
311
312    ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
313    return ret;
314 } /* end of MacSchCellCfgReq */
315
316
317 /*******************************************************************
318  *
319  * @brief Sends Cell config confirm to DU APP
320  *
321  * @details
322  *
323  *    Function : MacSendCellCfgCfm
324  *
325  *    Functionality:
326  *      Sends Cell config confirm to DU APP
327  *
328  * @params[in] Response status
329  * @return void
330  *
331  * ****************************************************************/
332 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
333 {
334    Pst pst;
335    uint16_t   cellIdx;
336    MacCellCfgCfm macCellCfgCfm;
337
338    memset(&pst, 0, sizeof(Pst));
339
340    GET_CELL_IDX(cellId, cellIdx);
341    macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
342    macCellCfgCfm.rsp = response;
343
344    /* Fill Pst */
345    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
346    pst.selector  = ODU_SELECTOR_LC;
347
348    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
349 }
350
351
352 /**
353  * @brief Layer Manager Configuration response handler.
354  *
355  * @details
356  *
357  *     Function : MacProcSchCellCfgCfm
358  *
359  *     This function processes cell configuration to SCH
360  *
361  *  @param[in]  Pst           *pst
362  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
363  *  @return  int
364  *      -# ROK
365  **/
366 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
367 {
368    uint16_t *cellId = NULLP;
369
370 #ifdef CALL_FLOW_DEBUG_LOG
371    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_SCH_CELL_CFG_CFM\n");
372 #endif
373
374    if(schCellCfgCfm->rsp == RSP_OK)
375    {
376       cellId = &schCellCfgCfm->cellId;
377 #ifdef INTEL_TIMER_MODE
378       sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
379 #else
380       sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
381 #endif
382    }
383    else
384    {
385       MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
386    }
387    return ROK;
388 }
389
390 /*******************************************************************
391  *
392  * @brief MAC handler for config response from PHY
393  *
394  * @details
395  *
396  *    Function : fapiMacConfigRsp
397  *
398  *    Functionality:
399  *     Processes config response from PHY and sends cell config
400  *     confirm to DU APP
401  *
402  * @params[in]
403  * @return void
404  *
405  * ****************************************************************/
406 void fapiMacConfigRsp(uint16_t cellId)
407 {
408    /* TODO : Processing of config response from PHY */
409
410    /* Send cell config cfm to DU APP */
411    MacSendCellCfgCfm(cellId, RSP_OK);
412 }
413
414 /*******************************************************************
415  *
416  * @brief Fill and Send Cell Delete response from MAC to DU APP
417  *
418  * @details
419  *
420  *    Function : MacSendCellDeleteRsp
421  *
422  *    Functionality: Fill and Send Cell Delete response from MAC to DUAPP
423  *
424  * @params[in] MAC Cell delete result
425  *             SCH Cell delete response
426  * @return ROK     - success
427  *         RFAILED - failure
428  *
429  * ****************************************************************/
430 uint8_t MacSendCellDeleteRsp(CellDeleteStatus result, uint8_t cellId)
431 {
432    MacCellDeleteRsp *deleteRsp=NULLP;
433    Pst            rspPst;
434
435    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
436    if(!deleteRsp)
437    {
438       DU_LOG("\nERROR  -->  MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
439       return RFAILED;
440    }
441
442    /* Filling CELL delete response */
443    
444    memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
445    deleteRsp->cellId = cellId;
446    deleteRsp->result = result;
447
448    /* Fill Post structure and send CELL delete response*/
449    memset(&rspPst, 0, sizeof(Pst));
450    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
451    return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
452 }
453
454 /*******************************************************************
455  *
456  * @brief  Processes CELL delete response from scheduler
457  *
458  * @details
459  *
460  *    Function : MacProcSchCellDeleteRsp
461  *
462  *    Functionality:
463  *      Processes CELL delete from scheduler
464  *
465  * @params[in] Pst : Post structure
466  *             schCellDelRsp : Scheduler CELL delete respons
467  * @return ROK     - success
468  *         RFAILED - failure
469  *
470  * * ****************************************************************/
471 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
472 {
473    uint8_t  ret = ROK;
474    uint16_t cellIdx=0;
475    CellDeleteStatus status;
476    
477 #ifdef CALL_FLOW_DEBUG_LOG
478    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_CELL_DELETE_RSP_TO_MAC\n");
479 #endif  
480
481    if(schCellDelRsp)
482    {
483       if(schCellDelRsp->rsp == RSP_OK)
484       {
485          DU_LOG("\nINFO   -->  MAC : SCH CELL Delete response for cellId[%d] is successful ", \
486          schCellDelRsp->cellId);
487          GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
488          if(macCb.macCell[cellIdx])
489          {
490             if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
491             {
492                status  = SUCCESSFUL_RSP;
493                MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
494                   macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
495                MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
496             }
497             else
498             {
499                 DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
500                 status = CELL_ID_INVALID;
501                 ret = RFAILED;
502             }
503          }
504          else
505          {
506             DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
507             status = CELL_ID_INVALID;
508             ret = RFAILED;
509          }
510       }
511       else
512       {
513          DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
514          status = CELL_ID_INVALID;
515          ret = RFAILED;
516       }
517       if(MacSendCellDeleteRsp(status, schCellDelRsp->cellId) != ROK)
518       {
519          DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
520          ret = RFAILED;
521       }
522
523    }
524    else
525    {
526       DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
527       ret = RFAILED;
528    }
529    return ret;
530 }
531
532 /*******************************************************************
533  *
534  * @brief Sends Cell delete req to Scheduler
535  *
536  * @details
537  *
538  *    Function : sendCellDelReqToSch
539  *
540  *    Functionality: sends Cell delete req to Scheduler
541  *
542  * @params[in]  SchCellDelete *schCellDel
543  * @return ROK     - success
544  *         RFAILED - failure
545  *
546  * ****************************************************************/
547
548 uint8_t sendCellDelReqToSch(SchCellDelete *schCellDel)
549 {
550    Pst schPst;
551    FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
552    return(*macSchCellDeleteReqOpts[schPst.selector])(&schPst, schCellDel);
553 }
554
555 /*******************************************************************
556  *
557  * @brief Handles CELL Delete requst from DU APP
558  *
559  * @details
560  *
561  *    Function : MacProcCellDeleteReq
562  *
563  *    Functionality: Handles CELL Delete requst from DU APP
564  *
565  * @params[in] Pst *pst, MacCellDelete *cellDelete
566  * @return ROK     - success
567  *         RFAILED - failure
568  *
569  *
570  * ****************************************************************/
571 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDelete *cellDelete)
572 {
573    uint8_t ret = ROK, cellIdx=0;
574    SchCellDelete schCellDelete;
575
576    DU_LOG("\nINFO   -->  MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
577
578    if(cellDelete)
579    {
580       GET_CELL_IDX(cellDelete->cellId, cellIdx);
581       if(macCb.macCell[cellIdx])
582       {
583          if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
584          {
585             memset(&schCellDelete, 0, sizeof(SchCellDelete));
586             schCellDelete.cellId =  cellDelete->cellId;
587             ret = sendCellDelReqToSch(&schCellDelete);
588             if(ret != ROK)
589             {
590                DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
591                ret = RFAILED;
592             }
593          }
594          else
595          {
596             DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
597             cellDelete->cellId);
598             ret = RFAILED;
599          }
600       }
601       else
602       {
603          DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
604                cellDelete->cellId);
605          ret = RFAILED;
606       }
607
608       if(ret == RFAILED)
609       {
610           DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Sending failure response to DU");
611           if(MacSendCellDeleteRsp(CELL_ID_INVALID, cellDelete->cellId) != ROK)
612           {
613              DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
614              cellDelete->cellId);
615           }
616
617       }
618       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDelete));
619    }
620    else
621    {
622       DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
623       ret = RFAILED;
624    }
625    return ret;
626 }
627
628 /**********************************************************************
629   End of file
630  **********************************************************************/