[Epic-ID: ODUHIGH-488][Task-ID: ODUHIGH-501] WG8 Alignment | Ue reset req and rsp
[o-du/l2.git] / src / 5gnrmac / mac_cfg_hdl.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18 /* This file stores handler for MAC and SCH configuration requests */
19 /* header include files (.h) */
20 #include "common_def.h"
21 #include "lrg.h"
22 #include "lrg.x"
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "lwr_mac_upr_inf.h"
26 #include "mac.h"
27 #include "rlc_mac_inf.h"
28 #include "mac_upr_inf_api.h"
29 #include "lwr_mac.h"
30 #include "lwr_mac_fsm.h"
31 #include "mac_utils.h"
32 #include "lwr_mac_phy.h"
33
34 uint8_t ssbPeriodicity[6] = {5, 10, 20, 40, 80, 160};
35
36 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg  *macCellCfg);
37
38 packMacCellCfgConfirm packMacCellCfmOpts[] =
39 {
40    packMacCellCfgCfm,      /* packing for loosely coupled */
41    duHandleMacCellCfgCfm,      /* packing for tightly coupled */
42    packMacCellCfgCfm,    /* packing for light weight loosly coupled */
43 };
44
45 MacDuCellDeleteRspFunc macDuCellDeleteRspOpts[] =
46 {
47    packDuMacCellDeleteRsp,   /* packing for loosely coupled */
48    DuProcMacCellDeleteRsp,   /* packing for tightly coupled */
49    packDuMacCellDeleteRsp   /* packing for light weight loosly coupled */
50 };
51
52 MacDuSliceCfgRspFunc macDuSliceCfgRspOpts[] =
53 {
54    packDuMacSliceCfgRsp,   /* packing for loosely coupled */
55    DuProcMacSliceCfgRsp,   /* packing for tightly coupled */
56    packDuMacSliceCfgRsp   /* packing for light weight loosly coupled */
57 };
58
59 MacDuSliceRecfgRspFunc macDuSliceRecfgRspOpts[] =
60 {
61    packDuMacSliceRecfgRsp,   /* packing for loosely coupled */
62    DuProcMacSliceRecfgRsp,   /* packing for tightly coupled */
63    packDuMacSliceRecfgRsp    /* packing for light weight loosly coupled */
64 };
65
66 /**
67  * @brief Layer Manager  Configuration request handler for Scheduler
68  *
69  * @details
70  *
71  *     Function : MacSchGenCfgReq
72  *
73  *     This function receives general configurations for Scheduler
74  *     from DU APP and forwards to Scheduler.
75  *
76  *  @param[in]  Pst *pst, the post structure
77  *  @param[in]  RgMngmt *cfg, the configuration parameter's structure
78  *  @return 
79  *      -# ROK
80  **/
81 uint8_t MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
82 {
83    Pst schPst;
84
85    DU_LOG("\nINFO  -->  MAC : Received Scheduler gen config at MAC");
86    memset(&schPst, 0, sizeof(Pst));
87    FILL_PST_MAC_TO_SCH(schPst, EVENT_SCH_GEN_CFG);
88    
89    return(SchMessageRouter(&schPst, (void *)cfg));
90 }
91
92 /**
93  * @brief Layer Manager Configuration response from Scheduler
94  *
95  * @details
96  *
97  *     Function : SchSendCfgCfm
98  *
99  *     This function sends general configurations response from
100  *     Scheduler to DU APP.
101  *
102  *  @param[in]  Pst *pst, the post structure
103  *  @param[in]  RgMngmt *cfm, the configuration confirm structure
104  *  @return 
105  *      -# ROK
106  **/
107 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt  *cfm)
108 {
109    DU_LOG("\nDEBUG  -->  MAC : Sending Scheduler config confirm to DU APP");
110    pst->dstEnt = ENTDUAPP;
111    pst->dstInst = 0;
112    pst->srcInst = 0;
113    pst->selector = ODU_SELECTOR_LC;
114    RgMiLrgSchCfgCfm(pst, cfm);
115
116    return ROK;
117 }
118
119 /**
120  * @brief Layer Manager Configuration request handler.
121  *
122  * @details
123  *
124  *     Function : MacProcCellCfgReq
125  *
126  *     This function handles the gNB and cell configuration
127  *     request received from DU APP.
128  *     This API unapcks and forwards the config towards SCH
129  *
130  *  @param[in]  Pst           *pst
131  *  @param[in]  MacCellCfg    *macCellCfg
132  *  @return  
133  *      -# ROK
134  **/
135 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
136 {
137    Pst cfmPst;
138    uint16_t cellIdx;
139    uint8_t ret = ROK, plmnIdx = 0,sliceIdx = 0;
140    MacCellCb     *macCellCb;
141
142    memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
143
144    MAC_ALLOC(macCellCb, sizeof(MacCellCb));
145    if(macCellCb == NULLP)
146    {
147       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of macCellCfg\n");
148       return RFAILED;
149    }
150    memset(macCellCb, 0, sizeof(MacCellCb));
151
152    GET_CELL_IDX(macCellCfg->cellId, cellIdx);
153    macCb.macCell[cellIdx] = macCellCb;
154    macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
155    macCb.macCell[cellIdx]->numOfSlots = 10 * (1 << macCellCfg->cellCfg.numerology);
156    memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
157
158    MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, \
159          macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
160    if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu == NULLP)
161    {
162       DU_LOG("\nERROR  -->  MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
163       return RFAILED;
164    }
165    memcpy(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, macCellCfg->cellCfg.sib1Cfg.sib1Pdu, \
166          macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
167
168    for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
169    {
170       macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice = macCellCfg->cellCfg.plmnInfoList[plmnIdx].numSupportedSlice;
171       MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai, macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice\
172             * sizeof(Snssai*));
173       if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai == NULLP)
174       {
175          DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
176          return RFAILED;
177       }
178
179       if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai)
180       {
181          for(sliceIdx=0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice; sliceIdx++)
182          {
183             if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
184             {
185                MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
186                if(!macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
187                {
188                   DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacProcCellCfgReq");
189                   return RFAILED;
190                }
191                memcpy(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx],\
192                      sizeof(Snssai));
193             }
194          }
195       }
196    }
197    /* Send cell cfg to scheduler */
198    ret = MacSchCellCfgReq(pst, macCellCfg);
199    if(ret != ROK)
200    {
201       MacCellCfgCfm macCellCfgCfm;
202       macCellCfgCfm.rsp = RSP_NOK;
203       macCellCfgCfm.cellId = macCellCfg->cellId;
204       /* Fill Pst */
205       FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
206       cfmPst.selector  = ODU_SELECTOR_LC;
207
208       ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
209    }
210    else
211    {
212       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
213    }
214    return ret;
215 } /* end of MacProcCellCfgReq */
216
217 /**
218  * @brief Layer Manager Configuration request handler.
219  *
220  * @details
221  *
222  *     Function : MacSchCellCfgReq
223  *
224  *     This function sends cell configuration to SCH
225  *
226  *  @param[in]  Pst           *pst
227  *  @param[in]  MacCellCfg    *macCellCfg
228  *  @return  
229  *      -# ROK
230  **/
231 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
232 {
233    SchCellCfg schCellCfg;
234    Pst        cfgPst;
235    uint8_t    ssbMaskIdx = 0, rsrcListIdx = 0, sliceIdx=0, plmnIdx = 0;
236
237    memset(&cfgPst, 0, sizeof(Pst));
238    memset(&schCellCfg, 0, sizeof(SchCellCfg));
239    schCellCfg.cellId = macCellCfg->cellId;
240    schCellCfg.phyCellId = macCellCfg->cellCfg.phyCellId;
241
242    for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
243    {
244       schCellCfg.plmnInfoList[plmnIdx].plmn = macCellCfg->cellCfg.plmnInfoList[plmnIdx].plmn;
245       if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai) 
246       {
247          schCellCfg.plmnInfoList[plmnIdx].numSliceSupport = macCellCfg->cellCfg.plmnInfoList[plmnIdx].numSupportedSlice;
248          MAC_ALLOC(schCellCfg.plmnInfoList[plmnIdx].snssai, schCellCfg.plmnInfoList[plmnIdx].numSliceSupport * sizeof(Snssai*));
249          if(!schCellCfg.plmnInfoList[plmnIdx].snssai)
250          {
251             DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
252             return RFAILED;
253          }
254          for(sliceIdx=0; sliceIdx<schCellCfg.plmnInfoList[plmnIdx].numSliceSupport; sliceIdx++)
255          {
256             if(macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
257             {
258                MAC_ALLOC(schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
259                if(!schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx])
260                {
261                   DU_LOG("\nERROR  --> MAC: Memory allocation failed at MacSchCellCfgReq");
262                   return RFAILED;
263                }
264                memcpy(schCellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], macCellCfg->cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx],  sizeof(Snssai));
265             }
266          }
267       }
268    }
269
270    schCellCfg.dupMode = macCellCfg->cellCfg.dupType;
271    schCellCfg.numerology = macCellCfg->cellCfg.numerology;
272    schCellCfg.dlBandwidth = macCellCfg->carrCfg.dlBw;
273    schCellCfg.ulBandwidth = macCellCfg->carrCfg.ulBw;
274
275    schCellCfg.dlCfgCommon.schFreqInfoDlSib.offsetToPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
276
277    /* fill initial DL BWP */
278    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
279    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
280    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
281    schCellCfg.dlCfgCommon.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
282    
283    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
284       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
285    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
286       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
287    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
288       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
289    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
290       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
291    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
292       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
293    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
294       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
295    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
296       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
297    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
298       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
299    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
300       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
301    schCellCfg.dlCfgCommon.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
302       macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
303    
304    schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc;
305    for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
306    {
307       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 = 
308          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
309       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
310          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
311       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
312          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
313       schCellCfg.dlCfgCommon.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
314          macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
315    }
316
317    /* fill SIB1 scheduler parameters */
318    schCellCfg.dlCfgCommon.schPcchCfg.numPO  =  macCellCfg->cellCfg.sib1Cfg.pagingCfg.numPO;
319    schCellCfg.dlCfgCommon.schPcchCfg.poPresent = macCellCfg->cellCfg.sib1Cfg.pagingCfg.poPresent;
320    if(schCellCfg.dlCfgCommon.schPcchCfg.poPresent)
321    {
322       memcpy(schCellCfg.dlCfgCommon.schPcchCfg.pagingOcc, macCellCfg->cellCfg.sib1Cfg.pagingCfg.pagingOcc, MAX_PO_PER_PF);
323    }
324
325    /* fill initial UL BWP */
326    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
327    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
328    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
329    schCellCfg.ulCfgCommon.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
330    /* fill RACH config params */
331    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.prachCfgIdx   = macCellCfg->prachCfg.prachCfgIdx;
332    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1Fdm       = macCellCfg->prachCfg.msg1Fdm;
333    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
334    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.zeroCorrZoneCfg = macCellCfg->prachCfg.fdm[0].zeroCorrZoneCfg; 
335    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.prachCfgGeneric.raRspWindow = macCellCfg->prachCfg.raRspWindow;
336
337    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.totalNumRaPreamble = macCellCfg->prachCfg.totalNumRaPreamble;
338    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.ssbPerRach    = macCellCfg->prachCfg.ssbPerRach;
339    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.numCbPreamblePerSsb = macCellCfg->prachCfg.numCbPreamblePerSsb;
340    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.raContResTmr = macCellCfg->prachCfg.raContResTmr;
341    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
342    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.rootSeqIdx    = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
343    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.numRootSeq    = macCellCfg->prachCfg.fdm[0].numRootSeq;
344    schCellCfg.ulCfgCommon.schInitialUlBwp.schRachCfg.msg1SubcSpacing = \
345                                             macCellCfg->prachCfg.prachSubcSpacing;
346
347    schCellCfg.ulCfgCommon.schInitialUlBwp.pucchCommon.pucchResourceCommon = \
348                                                                 macCellCfg->initialUlBwp.pucchCommon.pucchResourceCommon;
349    schCellCfg.ulCfgCommon.schInitialUlBwp.pucchCommon.pucchGroupHopping = \
350                                                                 macCellCfg->initialUlBwp.pucchCommon.pucchGroupHopping;
351    schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
352                                                                 macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
353    for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
354    {
355       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 = 
356          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
357       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
358          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
359       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
360          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
361       schCellCfg.ulCfgCommon.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
362          macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
363    }
364
365 #ifdef NR_TDD
366    memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
367 #endif
368
369    /* fill ssb scheduler parameters */
370    for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
371    {
372       schCellCfg.ssbPosInBurst[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
373    }
374    schCellCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
375    schCellCfg.ssbFrequency = macCellCfg->cellCfg.ssbFreq;
376    schCellCfg.dmrsTypeAPos = macCellCfg->ssbCfg.dmrsTypeAPos;
377    schCellCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
378    schCellCfg.pdcchCfgSib1.coresetZeroIndex = macCellCfg->cellCfg.sib1Cfg.pdcchCfgSib1.coresetZeroIndex;
379    schCellCfg.pdcchCfgSib1.searchSpaceZeroIndex = macCellCfg->cellCfg.sib1Cfg.pdcchCfgSib1.searchSpaceZeroIndex;
380    schCellCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
381    schCellCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
382    schCellCfg.sib1PduLen = macCellCfg->cellCfg.sib1Cfg.sib1PduLen;
383    
384    FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
385
386    return(SchMessageRouter(&cfgPst, (void *)&schCellCfg));
387 } /* end of MacSchCellCfgReq */
388
389
390 /*******************************************************************
391  *
392  * @brief Sends Cell config confirm to DU APP
393  *
394  * @details
395  *
396  *    Function : MacSendCellCfgCfm
397  *
398  *    Functionality:
399  *      Sends Cell config confirm to DU APP
400  *
401  * @params[in] Response status
402  * @return void
403  *
404  * ****************************************************************/
405 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
406 {
407    Pst pst;
408    uint16_t   cellIdx;
409    MacCellCfgCfm macCellCfgCfm;
410
411    memset(&pst, 0, sizeof(Pst));
412
413    GET_CELL_IDX(cellId, cellIdx);
414    macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
415    macCellCfgCfm.rsp = response;
416
417    /* Fill Pst */
418    FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
419    pst.selector  = ODU_SELECTOR_LC;
420
421    (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
422 }
423
424
425 /**
426  * @brief Layer Manager Configuration response handler.
427  *
428  * @details
429  *
430  *     Function : MacProcSchCellCfgCfm
431  *
432  *     This function processes cell configuration to SCH
433  *
434  *  @param[in]  Pst           *pst
435  *  @param[in]  SchCellCfgCfm *schCellCfgCfm
436  *  @return  int
437  *      -# ROK
438  **/
439 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
440 {
441    uint16_t *cellId = NULLP;
442
443 #ifdef CALL_FLOW_DEBUG_LOG
444    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_SCH_CELL_CFG_CFM\n");
445 #endif
446
447    if(schCellCfgCfm->rsp == RSP_OK)
448    {
449       cellId = &schCellCfgCfm->cellId;
450 #ifdef INTEL_TIMER_MODE
451       sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
452 #else
453       sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
454 #endif
455    }
456    else
457    {
458       MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
459    }
460    return ROK;
461 }
462
463 /*******************************************************************
464  *
465  * @brief MAC handler for config response from PHY
466  *
467  * @details
468  *
469  *    Function : fapiMacConfigRsp
470  *
471  *    Functionality:
472  *     Processes config response from PHY and sends cell config
473  *     confirm to DU APP
474  *
475  * @params[in]
476  * @return void
477  *
478  * ****************************************************************/
479 void fapiMacConfigRsp(uint16_t cellId)
480 {
481    /* TODO : Processing of config response from PHY */
482
483    /* Send cell config cfm to DU APP */
484    MacSendCellCfgCfm(cellId, RSP_OK);
485 }
486
487 /*******************************************************************
488  *
489  * @brief Fill and Send Cell Delete response from MAC to DU APP
490  *
491  * @details
492  *
493  *    Function : MacSendCellDeleteRsp
494  *
495  *    Functionality: Fill and Send Cell Delete response from MAC to DUAPP
496  *
497  * @params[in] MAC Cell delete result
498  *             SCH Cell delete response
499  * @return ROK     - success
500  *         RFAILED - failure
501  *
502  * ****************************************************************/
503 uint8_t MacSendCellDeleteRsp(CauseOfResult  status, uint8_t cellId)
504 {
505    MacCellDeleteRsp *deleteRsp=NULLP;
506    Pst            rspPst;
507
508    MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
509    if(!deleteRsp)
510    {
511       DU_LOG("\nERROR  -->  MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
512       return RFAILED;
513    }
514
515    /* Filling CELL delete response */
516    
517    memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
518    deleteRsp->cellId = cellId;
519    deleteRsp->status = status;
520
521    /* Fill Post structure and send CELL delete response*/
522    memset(&rspPst, 0, sizeof(Pst));
523    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
524    return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
525 }
526
527 /*******************************************************************
528  *
529  * @brief  Processes CELL delete response from scheduler
530  *
531  * @details
532  *
533  *    Function : MacProcSchCellDeleteRsp
534  *
535  *    Functionality:
536  *      Processes CELL delete from scheduler
537  *
538  * @params[in] Pst : Post structure
539  *             schCellDelRsp : Scheduler CELL delete respons
540  * @return ROK     - success
541  *         RFAILED - failure
542  *
543  * * ****************************************************************/
544 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
545 {
546    uint8_t  ret = ROK, sliceIdx = 0, plmnIdx = 0;
547    uint16_t cellIdx=0;
548    CauseOfResult  cause;
549
550 #ifdef CALL_FLOW_DEBUG_LOG
551    DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_CELL_DELETE_RSP_TO_MAC\n");
552 #endif  
553
554    if(schCellDelRsp)
555    {
556       if(schCellDelRsp->rsp == RSP_OK)
557       {
558          DU_LOG("\nINFO   -->  MAC : SCH CELL Delete response for cellId[%d] is successful ", \
559                schCellDelRsp->cellId);
560          GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
561          if(macCb.macCell[cellIdx])
562          {
563             if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
564             {
565                cause = SUCCESSFUL;
566                for(plmnIdx = 0; plmnIdx < MAX_PLMN; plmnIdx++)
567                {
568                   if(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai)
569                   {
570                      for(sliceIdx = 0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].numSupportedSlice; sliceIdx++)
571                      {
572                         MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai[sliceIdx], sizeof(Snssai));
573                      }
574                      MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].snssai, macCb.macCell[cellIdx]->macCellCfg.cellCfg.plmnInfoList[plmnIdx].\
575                            numSupportedSlice * sizeof(Snssai*));
576                   }
577                }
578                MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1Pdu, \
579                      macCb.macCell[cellIdx]->macCellCfg.cellCfg.sib1Cfg.sib1PduLen);
580                MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
581             }
582             else
583             {
584                DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
585                cause = CELLID_INVALID;
586                ret = RFAILED;
587             }
588          }
589          else
590          {
591             DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
592             cause = CELLID_INVALID;
593             ret = RFAILED;
594          }
595       }
596       else
597       {
598          DU_LOG("ERROR  -->  MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
599          cause = CELLID_INVALID;
600          ret = RFAILED;
601       }
602       if(MacSendCellDeleteRsp(cause, schCellDelRsp->cellId) != ROK)
603       {
604          DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
605          ret = RFAILED;
606       }
607
608    }
609    else
610    {
611       DU_LOG("\nERROR  -->  MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
612       ret = RFAILED;
613    }
614    return ret;
615 }
616
617 /*******************************************************************
618  *
619  * @brief Sends Cell delete req to Scheduler
620  *
621  * @details
622  *
623  *    Function : sendCellDelReqToSch
624  *
625  *    Functionality: sends Cell delete req to Scheduler
626  *
627  * @params[in]  SchCellDelete *schCellDel
628  * @return ROK     - success
629  *         RFAILED - failure
630  *
631  * ****************************************************************/
632
633 uint8_t sendCellDelReqToSch(SchCellDeleteReq *schCellDelReq)
634 {
635    Pst schPst;
636    FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
637    return(SchMessageRouter(&schPst, (void *)schCellDelReq));
638 }
639
640 /*******************************************************************
641  *
642  * @brief Handles CELL Delete requst from DU APP
643  *
644  * @details
645  *
646  *    Function : MacProcCellDeleteReq
647  *
648  *    Functionality: Handles CELL Delete requst from DU APP
649  *
650  * @params[in] Pst *pst, MacCellDelete *cellDelete
651  * @return ROK     - success
652  *         RFAILED - failure
653  *
654  *
655  * ****************************************************************/
656 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDeleteReq *cellDelete)
657 {
658    uint8_t ret = ROK, cellIdx=0;
659    SchCellDeleteReq schCellDelete;
660
661    DU_LOG("\nINFO   -->  MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
662
663    if(cellDelete)
664    {
665       GET_CELL_IDX(cellDelete->cellId, cellIdx);
666       if(macCb.macCell[cellIdx])
667       {
668          if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
669          {
670             memset(&schCellDelete, 0, sizeof(SchCellDeleteReq ));
671             schCellDelete.cellId =  cellDelete->cellId;
672             ret = sendCellDelReqToSch(&schCellDelete);
673             if(ret != ROK)
674             {
675                DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
676                ret = RFAILED;
677             }
678          }
679          else
680          {
681             DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
682             cellDelete->cellId);
683             ret = RFAILED;
684          }
685       }
686       else
687       {
688          DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
689                cellDelete->cellId);
690          ret = RFAILED;
691       }
692
693       if(ret == RFAILED)
694       {
695           DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Sending failure response to DU");
696           if(MacSendCellDeleteRsp(CELLID_INVALID, cellDelete->cellId) != ROK)
697           {
698              DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
699              cellDelete->cellId);
700           }
701
702       }
703       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDeleteReq));
704    }
705    else
706    {
707       DU_LOG("\nERROR  -->  MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
708       ret = RFAILED;
709    }
710    return ret;
711 }
712
713 /**
714  * @brief free the temporary slice cfg stored in macCb.
715  *
716  * @details
717  *
718  *     Function : freeMacSliceCfgReq 
719  *
720  *   free the temporary slice cfg stored in macCb
721  *
722  *  @param[in]  
723  *  @return  int
724  *      -# ROK
725  **/
726 void freeMacSliceCfgReq(MacSliceCfgReq *cfgReq,Pst *pst)
727 {
728     uint8_t policyIdx = 0, memberListIdx=0;
729
730     if(cfgReq->numOfRrmPolicy)
731     {
732        if(cfgReq->listOfRrmPolicy)
733        {
734           for(policyIdx = 0; policyIdx<cfgReq->numOfRrmPolicy; policyIdx++)
735           {
736              if(cfgReq->listOfRrmPolicy[policyIdx])
737              {
738                 if(cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem)
739                 {
740                    if(cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList)
741                    {
742                       for(memberListIdx = 0; memberListIdx<cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem; memberListIdx++)
743                       {
744                          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList[memberListIdx], sizeof(RrmPolicyMemberList));
745                       }
746                       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx]->rRMPolicyMemberList,\
747                       cfgReq->listOfRrmPolicy[policyIdx]->numOfRrmPolicyMem * sizeof(RrmPolicyMemberList*));
748                    }
749                 }
750                 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy[policyIdx], sizeof(MacSliceRrmPolicy));
751              }
752           }
753           MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfRrmPolicy, cfgReq->numOfRrmPolicy  * sizeof(MacSliceRrmPolicy*));
754        }
755     }
756
757 }
758
759 /**
760  * @brief send slice cfg response to duapp.
761  *
762  * @details
763  *
764  *     Function : MacSendSliceConfigRsp
765  *
766  *   sends  slice cfg response to duapp
767  *
768  *  @param[in] MacSliceCfgRsp macSliceCfgRsp 
769  *  @return  int
770  *      -# ROK
771  **/
772 uint8_t MacSendSliceConfigRsp(MacSliceCfgRsp *macSliceCfgRsp)
773 {
774     Pst  rspPst;
775     
776     memset(&rspPst, 0, sizeof(Pst));
777     FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_CFG_RSP);
778     return (*macDuSliceCfgRspOpts[rspPst.selector])(&rspPst, macSliceCfgRsp);
779
780 }
781
782 /**
783  * @brief Mac process the slice cfg rsp received from sch.
784  *
785  * @details
786  *
787  *     Function : MacProcSchSliceCfgRsp 
788  *
789  *     This function  process the slice cfg rsp received from sch
790  *
791  *  @param[in]  Pst           *pst
792  *  @param[in]  SchSliceCfgRsp *sliceCfgrsp
793  *  @return  int
794  *      -# ROK
795  **/
796
797 uint8_t MacProcSchSliceCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceCfgRsp)
798 {
799    MacSliceCfgRsp *macSliceCfgRsp = NULLP;
800
801    if(schSliceCfgRsp)
802    {
803       MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp, sizeof(MacSliceCfgRsp));
804       if(macSliceCfgRsp == NULLP)
805       {
806           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceCfgRsp");
807           return RFAILED;
808       }
809       macSliceCfgRsp->snssai = schSliceCfgRsp->snssai;
810       if(schSliceCfgRsp->rsp == RSP_OK)
811          macSliceCfgRsp->rsp    = MAC_DU_APP_RSP_OK;
812       else
813       {
814          macSliceCfgRsp->rsp    = MAC_DU_APP_RSP_NOK;
815       }
816       macSliceCfgRsp->cause  = schSliceCfgRsp->cause;
817       MacSendSliceConfigRsp(macSliceCfgRsp);
818    }
819    return ROK;
820 }
821
822 /**
823  * @brief send slice cfg response to duapp.
824  *
825  * @details
826  *
827  *     Function : MacSendSliceReconfigRsp 
828  *
829  *   sends  slice cfg response to duapp
830  *
831  *  @param[in] MacSliceRecfgRsp macSliceRecfgRsp
832  *  @return  int
833  *      -# ROK
834  **/
835 uint8_t MacSendSliceReconfigRsp(MacSliceRecfgRsp *macSliceRecfgRsp)
836 {
837    Pst  rspPst;
838
839    memset(&rspPst, 0, sizeof(Pst));
840    FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_RECFG_RSP);
841    return (*macDuSliceRecfgRspOpts[rspPst.selector])(&rspPst, macSliceRecfgRsp);
842
843 }
844
845 /**
846  * @brief Mac process the slice cfg rsp received from sch.
847  *
848  * @details
849  *
850  *     Function : MacProcSchSliceRecfgRsp 
851  *
852  *     This function  process the slice cfg rsp received from sch
853  *
854  *  @param[in]  Pst           *pst
855  *  @param[in]  SchSliceCfgRsp *schSliceRecfgRsp
856  *  @return  int
857  *      -# ROK
858  **/
859 uint8_t MacProcSchSliceRecfgRsp(Pst *pst, SchSliceRecfgRsp *schSliceRecfgRsp)
860 {
861    MacSliceRecfgRsp *macSliceRecfgRsp = NULLP;
862
863    if(schSliceRecfgRsp)
864    {
865       MAC_ALLOC_SHRABL_BUF(macSliceRecfgRsp, sizeof(MacSliceRecfgRsp));
866       if(macSliceRecfgRsp == NULLP)
867       {
868           DU_LOG("\nERROR  -->  MAC : Failed to allocate memory in MacProcSchSliceRecfgRsp");
869           return RFAILED;
870       }
871
872       macSliceRecfgRsp->snssai = schSliceRecfgRsp->snssai;
873       if(schSliceRecfgRsp->rsp == RSP_OK)
874          macSliceRecfgRsp->rsp    = MAC_DU_APP_RSP_OK;
875       else
876       {
877          macSliceRecfgRsp->rsp    = MAC_DU_APP_RSP_NOK;
878       }
879       macSliceRecfgRsp->cause  = schSliceRecfgRsp->cause;
880       MacSendSliceReconfigRsp(macSliceRecfgRsp);
881    }
882    return ROK;
883 }
884
885 /**
886  * @brief Mac process the downlink pcch indication received from DUAPP
887  *
888  * @details
889  *
890  *     Function : MacProcDlPcchInd 
891  *
892  *     This function process the downlink pcch indication received from DUAPP
893  *
894  *  @param[in]  Pst           *pst
895  *  @param[in]  DlPcchInd    *pcchInd 
896  *  @return  int
897  *      -# ROK
898  **/
899 uint8_t MacProcDlPcchInd(Pst *pst, DlPcchInd *pcchInd)
900 {
901    uint8_t ret = RFAILED;
902    uint16_t cellIdx = 0;
903    Pst       schPst;
904    SchPageInd *schPageInd = NULLP;
905
906    if(pcchInd)
907    {
908       DU_LOG("\nINFO   -->  MAC : Received DL PCCH IND from DU_APP for cellId[%d]", pcchInd->cellId);
909       
910       GET_CELL_IDX(pcchInd->cellId, cellIdx);
911
912       if(macCb.macCell[cellIdx] == NULLP || macCb.macCell[cellIdx]->cellId != pcchInd->cellId)
913       {
914          DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): CellId[%d] does not exist", pcchInd->cellId);
915       }
916       else
917       {
918          if((pcchInd->pcchPdu == NULLP) || (pcchInd->pduLen <= 0))
919          {
920             DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Received Pcch pdu is null");
921          }
922          else
923          {
924             MAC_ALLOC(schPageInd, sizeof(SchPageInd));
925             if(schPageInd == NULLP)
926             {
927                DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Failed to allocate memory");
928             }
929             else
930             {
931                schPageInd->cellId = pcchInd->cellId;
932                schPageInd->pf = pcchInd->pf;
933                schPageInd->i_s = pcchInd->i_s;
934                schPageInd->pduLen = pcchInd->pduLen;
935                
936                MAC_ALLOC(schPageInd->pagePdu, pcchInd->pduLen);
937                if(schPageInd->pagePdu == NULLP)
938                {
939                   DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Failed to allocate memory");
940                   MAC_FREE(schPageInd, sizeof(SchPageInd));
941                }
942                else
943                {
944                   memcpy(schPageInd->pagePdu, pcchInd->pcchPdu, pcchInd->pduLen);
945
946                   FILL_PST_MAC_TO_SCH(schPst, EVENT_PAGING_IND_TO_SCH);
947                   ret = SchMessageRouter(&schPst, (void *)schPageInd);
948                }
949             }
950          }
951       }
952       if((pcchInd->pcchPdu) && (pcchInd->pduLen > 0))
953       {
954          MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd->pcchPdu, pcchInd->pduLen);
955       }
956       MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd, sizeof(DlPcchInd));
957    }
958    else
959    {
960       DU_LOG("\nERROR  -->  MAC : MacProcDlPcchInd(): Received Null pointer");
961    }
962    return ret;
963 }
964 /**********************************************************************
965   End of file
966  **********************************************************************/