1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
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 #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
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"
23 #include "du_app_mac_inf.h"
24 #include "mac_sch_interface.h"
25 #include "lwr_mac_upr_inf.h"
27 #include "rlc_mac_inf.h"
28 #include "mac_upr_inf_api.h"
30 #include "lwr_mac_fsm.h"
31 #include "mac_utils.h"
32 #include "lwr_mac_phy.h"
34 uint8_t ssbPeriodicity[6] = {5, 10, 20, 40, 80, 160};
36 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg);
38 packMacCellCfgConfirm packMacCellCfmOpts[] =
40 packMacCellCfgCfm, /* packing for loosely coupled */
41 duHandleMacCellCfgCfm, /* packing for tightly coupled */
42 packMacCellCfgCfm, /* packing for light weight loosly coupled */
45 SchCellCfgFunc SchCellCfgOpts[] =
47 packSchCellCfg, /* packing for loosely coupled */
48 SchHdlCellCfgReq, /* packing for tightly coupled */
49 packSchCellCfg /* packing for light weight loosly coupled */
52 MacSchCellDeleteReqFunc macSchCellDeleteReqOpts[]=
54 packMacSchCellDeleteReq, /* packing for loosely coupled */
55 MacSchCellDeleteReq, /* packing for tightly coupled */
56 packMacSchCellDeleteReq /* packing for light weight loosely coupled */
59 MacDuCellDeleteRspFunc macDuCellDeleteRspOpts[] =
61 packDuMacCellDeleteRsp, /* packing for loosely coupled */
62 DuProcMacCellDeleteRsp, /* packing for tightly coupled */
63 packDuMacCellDeleteRsp /* packing for light weight loosly coupled */
66 MacDuSliceCfgRspFunc macDuSliceCfgRspOpts[] =
68 packDuMacSliceCfgRsp, /* packing for loosely coupled */
69 DuProcMacSliceCfgRsp, /* packing for tightly coupled */
70 packDuMacSliceCfgRsp /* packing for light weight loosly coupled */
73 MacDuSliceReCfgRspFunc macDuSliceReCfgRspOpts[] =
75 packDuMacSliceReCfgRsp, /* packing for loosely coupled */
76 DuProcMacSliceReCfgRsp, /* packing for tightly coupled */
77 packDuMacSliceReCfgRsp /* packing for light weight loosly coupled */
80 MacSchPagingIndFunc macSchPagingIndOpts[] =
82 packMacSchPagingInd, /* packing for loosely coupled */
83 MacSchPagingInd, /* packing for tightly coupled */
84 packMacSchPagingInd /* packing for light weight loosely coupled */
88 * @brief Layer Manager Configuration request handler for Scheduler
92 * Function : MacSchGenCfgReq
94 * This function receives general configurations for Scheduler
95 * from DU APP and forwards to Scheduler.
97 * @param[in] Pst *pst, the post structure
98 * @param[in] RgMngmt *cfg, the configuration parameter's structure
102 uint8_t MacSchGenCfgReq(Pst *pst, RgMngmt *cfg)
106 printf("\nReceived Scheduler gen config at MAC");
107 memset(&schPst, 0, sizeof(Pst));
108 FILL_PST_MAC_TO_SCH(schPst, EVENT_SCH_GEN_CFG);
109 SchProcGenCfgReq(&schPst, cfg);
115 * @brief Layer Manager Configuration response from Scheduler
119 * Function : SchSendCfgCfm
121 * This function sends general configurations response from
122 * Scheduler to DU APP.
124 * @param[in] Pst *pst, the post structure
125 * @param[in] RgMngmt *cfm, the configuration confirm structure
129 uint8_t SchSendCfgCfm(Pst *pst, RgMngmt *cfm)
131 DU_LOG("\nDEBUG --> Sending Scheduler config confirm to DU APP");
132 pst->dstEnt = ENTDUAPP;
135 pst->selector = ODU_SELECTOR_LC;
136 RgMiLrgSchCfgCfm(pst, cfm);
142 * @brief Layer Manager Configuration request handler.
146 * Function : MacProcCellCfgReq
148 * This function handles the gNB and cell configuration
149 * request received from DU APP.
150 * This API unapcks and forwards the config towards SCH
152 * @param[in] Pst *pst
153 * @param[in] MacCellCfg *macCellCfg
157 uint8_t MacProcCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
161 uint8_t ret = ROK, sliceIdx = 0;
162 MacCellCb *macCellCb;
164 memset((uint8_t *)&cfmPst, 0, sizeof(Pst));
166 MAC_ALLOC(macCellCb, sizeof(MacCellCb));
167 if(macCellCb == NULLP)
169 DU_LOG("\nERROR --> MAC : macCellCb is NULL at handling of macCellCfg\n");
172 memset(macCellCb, 0, sizeof(MacCellCb));
174 GET_CELL_IDX(macCellCfg->cellId, cellIdx);
175 macCb.macCell[cellIdx] = macCellCb;
176 macCb.macCell[cellIdx]->cellId = macCellCfg->cellId;
177 memcpy(&macCb.macCell[cellIdx]->macCellCfg, macCellCfg, sizeof(MacCellCfg));
179 MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
180 macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
181 if(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu == NULLP)
183 DU_LOG("\nERROR --> MAC : macCellCb is NULL at handling of sib1Pdu of macCellCfg\n");
186 memcpy(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, macCellCfg->sib1Cfg.sib1Pdu, \
187 macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
189 macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice = macCellCfg->plmnInfoList.numSupportedSlice;
190 MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai, macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice\
192 if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai == NULLP)
194 DU_LOG("\nERROR --> MAC: Memory allocation failed at MacProcCellCfgReq");
198 if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai)
200 for(sliceIdx=0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice; sliceIdx++)
202 if(macCellCfg->plmnInfoList.snssai[sliceIdx])
204 MAC_ALLOC(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
205 if(!macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx])
207 DU_LOG("\nERROR --> MAC: Memory allocation failed at MacProcCellCfgReq");
210 memcpy(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], macCellCfg->plmnInfoList.snssai[sliceIdx],\
216 /* Send cell cfg to scheduler */
217 ret = MacSchCellCfgReq(pst, macCellCfg);
220 MacCellCfgCfm macCellCfgCfm;
221 macCellCfgCfm.rsp = RSP_NOK;
222 macCellCfgCfm.cellId = macCellCfg->cellId;
224 FILL_PST_MAC_TO_DUAPP(cfmPst, EVENT_MAC_CELL_CONFIG_CFM);
225 cfmPst.selector = ODU_SELECTOR_LC;
227 ret = (*packMacCellCfmOpts[cfmPst.selector])(&cfmPst,&macCellCfgCfm);
231 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, macCellCfg ,sizeof(MacCellCfg));
234 } /* end of MacProcCellCfgReq */
237 * @brief Layer Manager Configuration request handler.
241 * Function : MacSchCellCfgReq
243 * This function sends cell configuration to SCH
245 * @param[in] Pst *pst
246 * @param[in] MacCellCfg *macCellCfg
250 uint8_t MacSchCellCfgReq(Pst *pst, MacCellCfg *macCellCfg)
252 SchCellCfg schCellCfg;
254 uint8_t ssbMaskIdx = 0, rsrcListIdx = 0, ret=0, sliceIdx=0;
256 memset(&cfgPst, 0, sizeof(Pst));
257 memset(&schCellCfg, 0, sizeof(SchCellCfg));
258 schCellCfg.cellId = macCellCfg->cellId;
259 schCellCfg.phyCellId = macCellCfg->phyCellId;
260 schCellCfg.numerology = macCellCfg->numerology;
261 schCellCfg.dupMode = macCellCfg->dupType;
262 schCellCfg.bandwidth = macCellCfg->dlCarrCfg.bw;
263 schCellCfg.dlFreq = macCellCfg->dlCarrCfg.freq;
264 schCellCfg.ulFreq = macCellCfg->ulCarrCfg.freq;
266 /* fill ssb scheduler parameters */
267 schCellCfg.ssbSchCfg.ssbPbchPwr = macCellCfg->ssbCfg.ssbPbchPwr;
268 schCellCfg.ssbSchCfg.scsCommon = macCellCfg->ssbCfg.scsCmn;
269 schCellCfg.ssbSchCfg.ssbOffsetPointA = macCellCfg->ssbCfg.ssbOffsetPointA;
270 schCellCfg.ssbSchCfg.ssbPeriod = ssbPeriodicity[macCellCfg->ssbCfg.ssbPeriod];
271 schCellCfg.ssbSchCfg.ssbSubcOffset = macCellCfg->ssbCfg.ssbScOffset;
272 for(ssbMaskIdx=0; ssbMaskIdx<SSB_MASK_SIZE; ssbMaskIdx++)
274 schCellCfg.ssbSchCfg.nSSBMask[ssbMaskIdx] = macCellCfg->ssbCfg.ssbMask[ssbMaskIdx];
276 schCellCfg.ssbSchCfg.totNumSsb = countSetBits(schCellCfg.ssbSchCfg.nSSBMask[0]);
278 /* fill SIB1 scheduler parameters */
279 schCellCfg.sib1SchCfg.sib1PduLen = macCellCfg->sib1Cfg.sib1PduLen;
280 schCellCfg.sib1SchCfg.sib1RepetitionPeriod = macCellCfg->sib1Cfg.sib1RepetitionPeriod;
281 schCellCfg.sib1SchCfg.coresetZeroIndex = macCellCfg->sib1Cfg.coresetZeroIndex;
282 schCellCfg.sib1SchCfg.searchSpaceZeroIndex = macCellCfg->sib1Cfg.searchSpaceZeroIndex;
283 schCellCfg.sib1SchCfg.sib1Mcs = macCellCfg->sib1Cfg.sib1Mcs;
284 schCellCfg.sib1SchCfg.pageCfg.numPO = macCellCfg->sib1Cfg.pagingCfg.numPO;
285 schCellCfg.sib1SchCfg.pageCfg.poPresent = macCellCfg->sib1Cfg.pagingCfg.poPresent;
287 if(schCellCfg.sib1SchCfg.pageCfg.poPresent)
289 memcpy(schCellCfg.sib1SchCfg.pageCfg.pagingOcc, macCellCfg->sib1Cfg.pagingCfg.pagingOcc, MAX_PO_PER_PF);
292 /* fill RACH config params */
293 schCellCfg.schRachCfg.prachCfgIdx = macCellCfg->prachCfg.prachCfgIdx;
294 schCellCfg.schRachCfg.prachSubcSpacing = \
295 macCellCfg->prachCfg.prachSubcSpacing;
296 schCellCfg.schRachCfg.msg1FreqStart = macCellCfg->prachCfg.msg1FreqStart;
297 schCellCfg.schRachCfg.msg1Fdm = macCellCfg->prachCfg.msg1Fdm;
298 schCellCfg.schRachCfg.rootSeqLen = macCellCfg->prachCfg.rootSeqLen;
299 schCellCfg.schRachCfg.rootSeqIdx = macCellCfg->prachCfg.fdm[0].rootSeqIdx;
300 schCellCfg.schRachCfg.numRootSeq = macCellCfg->prachCfg.fdm[0].numRootSeq;
301 schCellCfg.schRachCfg.k1 = macCellCfg->prachCfg.fdm[0].k1;
302 schCellCfg.schRachCfg.totalNumRaPreamble = macCellCfg->prachCfg.totalNumRaPreamble;
303 schCellCfg.schRachCfg.ssbPerRach = macCellCfg->prachCfg.ssbPerRach;
304 schCellCfg.schRachCfg.numCbPreamblePerSsb = macCellCfg->prachCfg.numCbPreamblePerSsb;
305 schCellCfg.schRachCfg.prachMultCarrBand = macCellCfg->prachCfg.prachMultCarrBand;
306 schCellCfg.schRachCfg.raContResTmr = macCellCfg->prachCfg.raContResTmr;
307 schCellCfg.schRachCfg.rsrpThreshSsb = macCellCfg->prachCfg.rsrpThreshSsb;
308 schCellCfg.schRachCfg.raRspWindow = macCellCfg->prachCfg.raRspWindow;
310 /* fill initial DL BWP */
311 schCellCfg.schInitialDlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialDlBwp.bwp.firstPrb;
312 schCellCfg.schInitialDlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialDlBwp.bwp.numPrb;
313 schCellCfg.schInitialDlBwp.bwp.scs = macCellCfg->initialDlBwp.bwp.scs;
314 schCellCfg.schInitialDlBwp.bwp.cyclicPrefix = macCellCfg->initialDlBwp.bwp.cyclicPrefix;
315 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId =
316 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId;
317 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.coresetId =
318 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.coresetId;
319 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
320 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot;
321 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.duration =
322 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.duration;
323 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
324 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol;
325 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1 =
326 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel1;
327 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2 =
328 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel2;
329 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4 =
330 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel4;
331 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8 =
332 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel8;
333 schCellCfg.schInitialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16 =
334 macCellCfg->initialDlBwp.pdcchCommon.commonSearchSpace.candidate.aggLevel16;
335 schCellCfg.schInitialDlBwp.pdschCommon.numTimeDomAlloc = macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc;
336 for(rsrcListIdx = 0; rsrcListIdx<macCellCfg->initialDlBwp.pdschCommon.numTimeDomAlloc; rsrcListIdx++)
338 schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0 =
339 macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].k0;
340 schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
341 macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
342 schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
343 macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
344 schCellCfg.schInitialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol =
345 macCellCfg->initialDlBwp.pdschCommon.timeDomRsrcAllocList[rsrcListIdx].lengthSymbol;
348 /* fill initial UL BWP */
349 schCellCfg.schInitialUlBwp.bwp.freqAlloc.startPrb = macCellCfg->initialUlBwp.bwp.firstPrb;
350 schCellCfg.schInitialUlBwp.bwp.freqAlloc.numPrb = macCellCfg->initialUlBwp.bwp.numPrb;
351 schCellCfg.schInitialUlBwp.bwp.scs = macCellCfg->initialUlBwp.bwp.scs;
352 schCellCfg.schInitialUlBwp.bwp.cyclicPrefix = macCellCfg->initialUlBwp.bwp.cyclicPrefix;
353 schCellCfg.schInitialUlBwp.puschCommon.numTimeDomRsrcAlloc = \
354 macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc;
355 for(rsrcListIdx = 0; rsrcListIdx < macCellCfg->initialUlBwp.puschCommon.numTimeDomRsrcAlloc; rsrcListIdx++)
357 schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2 =
358 macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].k2;
359 schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType =
360 macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].mappingType;
361 schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol =
362 macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].startSymbol;
363 schCellCfg.schInitialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength =
364 macCellCfg->initialUlBwp.puschCommon.timeDomRsrcAllocList[rsrcListIdx].symbolLength;
367 if(macCellCfg->plmnInfoList.snssai)
369 schCellCfg.plmnInfoList.numSliceSupport = macCellCfg->plmnInfoList.numSupportedSlice;
370 MAC_ALLOC(schCellCfg.plmnInfoList.snssai, schCellCfg.plmnInfoList.numSliceSupport * sizeof(Snssai*));
371 if(!schCellCfg.plmnInfoList.snssai)
373 DU_LOG("\nERROR --> MAC: Memory allocation failed at MacSchCellCfgReq");
376 for(sliceIdx=0; sliceIdx<schCellCfg.plmnInfoList.numSliceSupport; sliceIdx++)
378 if(macCellCfg->plmnInfoList.snssai[sliceIdx])
380 MAC_ALLOC(schCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
381 if(!schCellCfg.plmnInfoList.snssai[sliceIdx])
383 DU_LOG("\nERROR --> MAC: Memory allocation failed at MacSchCellCfgReq");
386 memcpy(schCellCfg.plmnInfoList.snssai[sliceIdx], macCellCfg->plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
392 memcpy(&schCellCfg.tddCfg, &macCellCfg->tddCfg, sizeof(TDDCfg));
395 FILL_PST_MAC_TO_SCH(cfgPst, EVENT_SCH_CELL_CFG);
397 ret = (*SchCellCfgOpts[cfgPst.selector])(&cfgPst, &schCellCfg);
399 } /* end of MacSchCellCfgReq */
402 /*******************************************************************
404 * @brief Sends Cell config confirm to DU APP
408 * Function : MacSendCellCfgCfm
411 * Sends Cell config confirm to DU APP
413 * @params[in] Response status
416 * ****************************************************************/
417 void MacSendCellCfgCfm(uint16_t cellId, uint8_t response)
421 MacCellCfgCfm macCellCfgCfm;
423 memset(&pst, 0, sizeof(Pst));
425 GET_CELL_IDX(cellId, cellIdx);
426 macCellCfgCfm.cellId = macCb.macCell[cellIdx]->macCellCfg.cellId;
427 macCellCfgCfm.rsp = response;
430 FILL_PST_MAC_TO_DUAPP(pst, EVENT_MAC_CELL_CONFIG_CFM);
431 pst.selector = ODU_SELECTOR_LC;
433 (*packMacCellCfmOpts[pst.selector])(&pst,&macCellCfgCfm);
438 * @brief Layer Manager Configuration response handler.
442 * Function : MacProcSchCellCfgCfm
444 * This function processes cell configuration to SCH
446 * @param[in] Pst *pst
447 * @param[in] SchCellCfgCfm *schCellCfgCfm
451 uint8_t MacProcSchCellCfgCfm(Pst *pst, SchCellCfgCfm *schCellCfgCfm)
453 uint16_t *cellId = NULLP;
455 #ifdef CALL_FLOW_DEBUG_LOG
456 DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_SCH_CELL_CFG_CFM\n");
459 if(schCellCfgCfm->rsp == RSP_OK)
461 cellId = &schCellCfgCfm->cellId;
462 #ifdef INTEL_TIMER_MODE
463 sendToLowerMac(UL_IQ_SAMPLE, 0, (void *)cellId);
465 sendToLowerMac(CONFIG_REQUEST, 0, (void *)cellId);
470 MacSendCellCfgCfm(schCellCfgCfm->cellId, RSP_NOK);
475 /*******************************************************************
477 * @brief MAC handler for config response from PHY
481 * Function : fapiMacConfigRsp
484 * Processes config response from PHY and sends cell config
490 * ****************************************************************/
491 void fapiMacConfigRsp(uint16_t cellId)
493 /* TODO : Processing of config response from PHY */
495 /* Send cell config cfm to DU APP */
496 MacSendCellCfgCfm(cellId, RSP_OK);
499 /*******************************************************************
501 * @brief Fill and Send Cell Delete response from MAC to DU APP
505 * Function : MacSendCellDeleteRsp
507 * Functionality: Fill and Send Cell Delete response from MAC to DUAPP
509 * @params[in] MAC Cell delete result
510 * SCH Cell delete response
511 * @return ROK - success
514 * ****************************************************************/
515 uint8_t MacSendCellDeleteRsp(CellDeleteStatus result, uint8_t cellId)
517 MacCellDeleteRsp *deleteRsp=NULLP;
520 MAC_ALLOC_SHRABL_BUF(deleteRsp, sizeof(MacCellDeleteRsp));
523 DU_LOG("\nERROR --> MAC : MacSendCellDeleteRsp(): Memory allocation for Cell delete response failed");
527 /* Filling CELL delete response */
529 memset(deleteRsp, 0, sizeof(MacCellDeleteRsp));
530 deleteRsp->cellId = cellId;
531 deleteRsp->result = result;
533 /* Fill Post structure and send CELL delete response*/
534 memset(&rspPst, 0, sizeof(Pst));
535 FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_CELL_DELETE_RSP);
536 return (*macDuCellDeleteRspOpts[rspPst.selector])(&rspPst, deleteRsp);
539 /*******************************************************************
541 * @brief Processes CELL delete response from scheduler
545 * Function : MacProcSchCellDeleteRsp
548 * Processes CELL delete from scheduler
550 * @params[in] Pst : Post structure
551 * schCellDelRsp : Scheduler CELL delete respons
552 * @return ROK - success
555 * * ****************************************************************/
556 uint8_t MacProcSchCellDeleteRsp(Pst *pst, SchCellDeleteRsp *schCellDelRsp)
558 uint8_t ret = ROK, sliceIdx = 0;
560 CellDeleteStatus status;
562 #ifdef CALL_FLOW_DEBUG_LOG
563 DU_LOG("\nCall Flow: ENTSCH -> ENTMAC : EVENT_CELL_DELETE_RSP_TO_MAC\n");
568 if(schCellDelRsp->rsp == RSP_OK)
570 DU_LOG("\nINFO --> MAC : SCH CELL Delete response for cellId[%d] is successful ", \
571 schCellDelRsp->cellId);
572 GET_CELL_IDX(schCellDelRsp->cellId, cellIdx);
573 if(macCb.macCell[cellIdx])
575 if(macCb.macCell[cellIdx]->cellId == schCellDelRsp->cellId)
577 status = SUCCESSFUL_RSP;
578 if(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai)
580 for(sliceIdx = 0; sliceIdx<macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.numSupportedSlice; sliceIdx++)
582 MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
584 MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.snssai, macCb.macCell[cellIdx]->macCellCfg.plmnInfoList.\
585 numSupportedSlice * sizeof(Snssai*));
587 MAC_FREE(macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1Pdu, \
588 macCb.macCell[cellIdx]->macCellCfg.sib1Cfg.sib1PduLen);
589 MAC_FREE(macCb.macCell[cellIdx], sizeof(MacCellCb));
593 DU_LOG("ERROR --> MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
594 status = CELL_ID_INVALID;
600 DU_LOG("ERROR --> MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
601 status = CELL_ID_INVALID;
607 DU_LOG("ERROR --> MAC : MacProcSchCellDeleteRsp(): CellId[%d] does not exists", schCellDelRsp->cellId);
608 status = CELL_ID_INVALID;
611 if(MacSendCellDeleteRsp(status, schCellDelRsp->cellId) != ROK)
613 DU_LOG("\nERROR --> MAC: MacProcSchCellDeleteRsp(): Failed to send CELL delete response");
620 DU_LOG("\nERROR --> MAC: MacProcSchCellDeleteRsp(): schCellDelRsp is NULL");
626 /*******************************************************************
628 * @brief Sends Cell delete req to Scheduler
632 * Function : sendCellDelReqToSch
634 * Functionality: sends Cell delete req to Scheduler
636 * @params[in] SchCellDelete *schCellDel
637 * @return ROK - success
640 * ****************************************************************/
642 uint8_t sendCellDelReqToSch(SchCellDelete *schCellDel)
645 FILL_PST_MAC_TO_SCH(schPst, EVENT_CELL_DELETE_REQ_TO_SCH);
646 return(*macSchCellDeleteReqOpts[schPst.selector])(&schPst, schCellDel);
649 /*******************************************************************
651 * @brief Handles CELL Delete requst from DU APP
655 * Function : MacProcCellDeleteReq
657 * Functionality: Handles CELL Delete requst from DU APP
659 * @params[in] Pst *pst, MacCellDelete *cellDelete
660 * @return ROK - success
664 * ****************************************************************/
665 uint8_t MacProcCellDeleteReq(Pst *pst, MacCellDelete *cellDelete)
667 uint8_t ret = ROK, cellIdx=0;
668 SchCellDelete schCellDelete;
670 DU_LOG("\nINFO --> MAC : Cell Delete Request received for cellId[%d]", cellDelete->cellId);
674 GET_CELL_IDX(cellDelete->cellId, cellIdx);
675 if(macCb.macCell[cellIdx])
677 if(macCb.macCell[cellIdx]->cellId == cellDelete->cellId)
679 memset(&schCellDelete, 0, sizeof(SchCellDelete));
680 schCellDelete.cellId = cellDelete->cellId;
681 ret = sendCellDelReqToSch(&schCellDelete);
684 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Failed to send UE Delete Request to SCH");
690 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
697 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Failed to find the MacUeCb of CellId = %d",\
704 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Sending failure response to DU");
705 if(MacSendCellDeleteRsp(CELL_ID_INVALID, cellDelete->cellId) != ROK)
707 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): failed to send cell delete rsp for cellID[%d]",\
712 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cellDelete, sizeof(MacCellDelete));
716 DU_LOG("\nERROR --> MAC : MacProcCellDeleteReq(): Received MacCellDelete is NULL");
723 * @brief free the temporary slice cfg stored in macCb.
727 * Function : freeMacSliceCfgReq
729 * free the temporary slice cfg stored in macCb
735 void freeMacSliceCfgReq(MacSliceCfgReq *cfgReq,Pst *pst)
741 if(cfgReq->numOfConfiguredSlice)
743 for(cfgIdx = 0; cfgIdx<cfgReq->numOfConfiguredSlice; cfgIdx++)
745 if(cfgReq->listOfSliceCfg[cfgIdx])
747 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg[cfgIdx]->rrmPolicyRatio, sizeof(RrmPolicyRatio));
749 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg[cfgIdx], sizeof(MacSliceRrmPolicy));
751 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq->listOfSliceCfg, cfgReq->numOfConfiguredSlice * sizeof(MacSliceRrmPolicy*));
753 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, cfgReq, sizeof(MacSliceCfgReq));
757 * @brief fill Mac Slice Config Rsp
761 * Function : fillMacSliceCfgRsp
763 * This function fill Mac Slice Config Rsp
765 * @param[in] SchSliceCfgRsp *sliceCfgRsp, MacSliceCfgRsp *macSliceCfgRsp,
770 uint8_t fillMacSliceCfgRsp(SchSliceCfgRsp *schSliceCfgRsp, MacSliceCfgRsp *macSliceCfgRsp)
773 bool sliceFound = false;
776 macSliceCfgRsp->numSliceCfgRsp = schSliceCfgRsp->numSliceCfgRsp;
777 MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp->listOfSliceCfgRsp, macSliceCfgRsp->numSliceCfgRsp* sizeof(MacSliceRsp*));
778 if(macSliceCfgRsp->listOfSliceCfgRsp == NULLP)
780 DU_LOG("\nERROR --> MAC : Memory allocation failedi in fillMacSliceCfgRsp");
784 for(cfgIdx = 0; cfgIdx<schSliceCfgRsp->numSliceCfgRsp; cfgIdx++)
787 if(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp == RSP_OK)
792 MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(SliceRsp));
793 if(macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx] == NULLP)
795 DU_LOG("\nERROR --> MAC : Memory allocation failedi in fillMacSliceCfgRsp");
799 macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->snssai = schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->snssai;
800 if(sliceFound == true)
801 macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp = MAC_DU_APP_RSP_OK;
804 macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->rsp = MAC_DU_APP_RSP_NOK;
805 macSliceCfgRsp->listOfSliceCfgRsp[cfgIdx]->cause = SLICE_NOT_PRESENT;
812 * @brief send slice cfg response to duapp.
816 * Function : MacSendSliceConfigRsp
818 * sends slice cfg response to duapp
820 * @param[in] MacSliceCfgRsp macSliceCfgRsp
824 uint8_t MacSendSliceConfigRsp(MacSliceCfgRsp *macSliceCfgRsp)
828 memset(&rspPst, 0, sizeof(Pst));
829 FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_CFG_RSP);
830 return (*macDuSliceCfgRspOpts[rspPst.selector])(&rspPst, macSliceCfgRsp);
834 * @brief free the slice cfg rsp received from sch.
838 * Function : freeSchSliceCfgRsp
840 * This free the slice cfg rsp received from sch
842 * @param[in] SchSliceCfgRsp *sliceCfgrsp
846 void freeSchSliceCfgRsp(SchSliceCfgRsp *schSliceCfgRsp)
852 if(schSliceCfgRsp->numSliceCfgRsp)
854 for(cfgIdx = 0; cfgIdx< schSliceCfgRsp->numSliceCfgRsp; cfgIdx++)
856 MAC_FREE(schSliceCfgRsp->listOfSliceCfgRsp[cfgIdx], sizeof(SliceRsp));
858 MAC_FREE(schSliceCfgRsp->listOfSliceCfgRsp, schSliceCfgRsp->numSliceCfgRsp * sizeof(SliceRsp*));
864 * @brief Mac process the slice cfg rsp received from sch.
868 * Function : MacProcSchSliceCfgRsp
870 * This function process the slice cfg rsp received from sch
872 * @param[in] Pst *pst
873 * @param[in] SchSliceCfgRsp *sliceCfgrsp
877 uint8_t MacProcSchSliceCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceCfgRsp)
879 MacSliceCfgRsp *macSliceCfgRsp = NULLP;
883 MAC_ALLOC_SHRABL_BUF(macSliceCfgRsp, sizeof(MacSliceCfgRsp));
884 if(macSliceCfgRsp == NULLP)
886 DU_LOG("\nERROR --> MAC : Failed to allocate memory in MacProcSchSliceCfgRsp");
889 if(schSliceCfgRsp->listOfSliceCfgRsp)
891 if(fillMacSliceCfgRsp(schSliceCfgRsp, macSliceCfgRsp) != ROK)
893 DU_LOG("\nERROR --> MAC : Failed to fill the slice cfg response");
896 MacSendSliceConfigRsp(macSliceCfgRsp);
898 freeSchSliceCfgRsp(schSliceCfgRsp);
904 * @brief send slice cfg response to duapp.
908 * Function : MacSendSliceReconfigRsp
910 * sends slice cfg response to duapp
912 * @param[in] MacSliceCfgRsp macSliceRecfgRsp
916 uint8_t MacSendSliceReconfigRsp(MacSliceCfgRsp *macSliceRecfgRsp)
920 memset(&rspPst, 0, sizeof(Pst));
921 FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_SLICE_RECFG_RSP);
922 return (*macDuSliceReCfgRspOpts[rspPst.selector])(&rspPst, macSliceRecfgRsp);
927 * @brief Mac process the slice cfg rsp received from sch.
931 * Function : MacProcSchSliceReCfgRsp
933 * This function process the slice cfg rsp received from sch
935 * @param[in] Pst *pst
936 * @param[in] SchSliceCfgRsp *schSliceRecfgRsp
940 uint8_t MacProcSchSliceReCfgRsp(Pst *pst, SchSliceCfgRsp *schSliceRecfgRsp)
942 MacSliceCfgRsp *macSliceReCfgRsp = NULLP;
946 MAC_ALLOC_SHRABL_BUF(macSliceReCfgRsp, sizeof(MacSliceCfgRsp));
947 if(macSliceReCfgRsp == NULLP)
949 DU_LOG("\nERROR --> MAC : Failed to allocate memory in MacProcSchSliceReCfgRsp");
953 if(schSliceRecfgRsp->listOfSliceCfgRsp)
955 if(fillMacSliceCfgRsp(schSliceRecfgRsp, macSliceReCfgRsp) != ROK)
957 DU_LOG("\nERROR --> MAC : Failed to fill the slice Recfg response");
960 MacSendSliceReconfigRsp(macSliceReCfgRsp);
962 freeSchSliceCfgRsp(schSliceRecfgRsp);
968 * @brief Mac process the downlink pcch indication received from DUAPP
972 * Function : MacProcDlPcchInd
974 * This function process the downlink pcch indication received from DUAPP
976 * @param[in] Pst *pst
977 * @param[in] MacPcchInd *pcchInd
981 uint8_t MacProcDlPcchInd(Pst *pst, MacPcchInd *pcchInd)
983 uint8_t ret = RFAILED;
984 uint16_t cellIdx = 0;
986 SchPageInd *schPageInd = NULLP;
990 DU_LOG("\nINFO --> MAC : Recived pcch request from DU_APP for cellId[%d]", pcchInd->cellId);
992 GET_CELL_IDX(pcchInd->cellId, cellIdx);
994 if(macCb.macCell[cellIdx] == NULLP || macCb.macCell[cellIdx]->cellId != pcchInd->cellId)
996 DU_LOG("\nERROR --> MAC : MacProcDlPcchInd(): CellId[%d] does not exist", pcchInd->cellId);
1000 if((pcchInd->pcchPdu == NULLP) || (pcchInd->pduLen <= 0))
1002 DU_LOG("\nERROR --> MAC : MacProcDlPcchInd(): Received Pcch pdu is null");
1006 MAC_ALLOC(schPageInd, sizeof(SchPageInd));
1007 if(schPageInd == NULLP)
1009 DU_LOG("\nERROR --> MAC : MacProcDlPcchInd(): Failed to allocate memory");
1013 schPageInd->cellId = pcchInd->cellId;
1014 schPageInd->pf = pcchInd->pf;
1015 schPageInd->i_s = pcchInd->i_s;
1016 schPageInd->pduLen = pcchInd->pduLen;
1018 MAC_ALLOC(schPageInd->pagePdu, pcchInd->pduLen);
1019 if(schPageInd->pagePdu == NULLP)
1021 DU_LOG("\nERROR --> MAC : MacProcDlPcchInd(): Failed to allocate memory");
1022 MAC_FREE(schPageInd, sizeof(SchPageInd));
1026 memcpy(schPageInd->pagePdu, pcchInd->pcchPdu, pcchInd->pduLen);
1028 DU_LOG("\nINFO --> MAC : Sending paging indication to SCH");
1029 FILL_PST_MAC_TO_SCH(schPst, EVENT_PAGING_IND_TO_SCH);
1030 ret = (*macSchPagingIndOpts[schPst.selector])(&schPst, schPageInd);
1035 if((pcchInd->pcchPdu) && (pcchInd->pduLen > 0))
1037 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd->pcchPdu, pcchInd->pduLen);
1039 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, pcchInd, sizeof(MacPcchInd));
1043 DU_LOG("\nERROR --> MAC : MacProcDlPcchInd(): Received Null pointer");
1047 /**********************************************************************
1049 **********************************************************************/