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 *******************************************************************************/
19 /* This file contains UE management handling functionality for MAC */
21 /* header include files (.h) */
22 #include "common_def.h"
25 #include "du_app_mac_inf.h"
26 #include "mac_sch_interface.h"
27 #include "lwr_mac_upr_inf.h"
29 #include "mac_utils.h"
31 /* function pointers for packing slot ind from mac to sch */
32 MacSchUeCreateReqFunc macSchUeCreateReqOpts[] =
34 packMacSchUeCreateReq, /* packing for loosely coupled */
35 MacSchUeCreateReq, /* packing for tightly coupled */
36 packMacSchUeCreateReq /* packing for light weight loosely coupled */
39 DuMacUeCreateRspFunc DuMacUeCreateRspOpts[] =
41 packDuMacUeCreateRsp, /* packing for loosely coupled */
42 DuHandleMacUeCreateRsp, /* packing for tightly coupled */
43 packDuMacUeCreateRsp, /* packing for light weight loosly coupled */
46 /*******************************************************************
48 * @brief Fills mac cell group config to be sent to scheduler
52 * Function : fillMacCellGroupCfg
54 * Functionality: Fills mac cell group config to be sent to sch
56 * @params[in] macCellGrp : mac cell group config at MAC
57 * *macCellGrpCfg : mac cell group cfg to be filled
58 * @return ROK - success
61 * ****************************************************************/
62 uint8_t fillMacCellGroupCfg(MacCellGrpCfg macCellGrp, SchMacCellGrpCfg *macCellGrpCfg)
65 SchSchedReqCfg *schedReqCfg;
68 /* Copy scheduling request config */
69 schedReqCfg = &macCellGrpCfg->schedReqCfg;
70 schedReqCfg->addModListCount = macCellGrp.schReqCfg.addModListCount;
71 if(schedReqCfg->addModListCount > MAX_NUM_SR_CFG_PER_CELL_GRP)
73 DU_LOG("\nMAC : Scheduling Request Add/Mod Count %d exceeds max limit %d", \
74 schedReqCfg->addModListCount, MAX_NUM_SR_CFG_PER_CELL_GRP);
77 for(idx = 0; idx < schedReqCfg->addModListCount; idx++)
79 schedReqCfg->addModList[idx].schedReqId = \
80 macCellGrp.schReqCfg.addModList[idx].schedReqId;
81 schedReqCfg->addModList[idx].srProhibitTmr = \
82 macCellGrp.schReqCfg.addModList[idx].srProhibitTmr;
83 schedReqCfg->addModList[idx].srTransMax = \
84 macCellGrp.schReqCfg.addModList[idx].srTransMax;
86 schedReqCfg->relListCount = macCellGrp.schReqCfg.relListCount;
89 tagCfg = &macCellGrpCfg->tagCfg;
90 tagCfg->addModListCount = macCellGrp.tagCfg.addModListCount;
91 if(tagCfg->addModListCount > MAX_NUM_TAGS)
93 DU_LOG("\nMAC : Scheduling Request Add/Mod Count %d exceeds max limit %d", \
94 tagCfg->addModListCount, MAX_NUM_TAGS);
97 for(idx = 0; idx < tagCfg->addModListCount; idx++)
99 tagCfg->addModList[idx].tagId = \
100 macCellGrp.tagCfg.addModList[idx].tagId;
101 tagCfg->addModList[idx].timeAlignmentTmr = \
102 macCellGrp.tagCfg.addModList[idx].timeAlignTimer;
104 tagCfg->relListCount = macCellGrp.tagCfg.relListCount;
106 /* Copy PHR config */
107 if(macCellGrp.phrCfgSetupPres)
109 macCellGrpCfg->phrCfg.periodicTmr = macCellGrp.phrCfg.periodicTimer;
110 macCellGrpCfg->phrCfg.prohibitTmr = macCellGrp.phrCfg.prohibitTimer;
111 macCellGrpCfg->phrCfg.txpowerFactorChange = macCellGrp.phrCfg.txPowerFactor;
112 macCellGrpCfg->phrCfg.multiplePhr = macCellGrp.phrCfg.multiplePHR;
113 macCellGrpCfg->phrCfg.dummy = macCellGrp.phrCfg.dummy;
114 macCellGrpCfg->phrCfg.type2OtherCell = macCellGrp.phrCfg.phrType2OtherCell;
115 macCellGrpCfg->phrCfg.modeOtherCG = macCellGrp.phrCfg.phrOtherCG;
121 /*******************************************************************
123 * @brief Fills phy cell group config to be sent to scheduler
127 * Function : fillPhyCellGroupCfg
129 * Functionality: Fills phy cell group config to be sent to sch
131 * @params[in] macUeCfg : Phy cell group config at MAC
132 * *schPhyCellGrp : phy cell group config to be filled
133 * @return ROK - success
136 * ****************************************************************/
137 uint8_t fillPhyCellGroupCfg(PhyCellGrpCfg macUeCfg, SchPhyCellGrpCfg *schPhyCellGrp)
139 schPhyCellGrp->pdschHarqAckCodebook = macUeCfg.pdschHarqAckCodebook;
140 schPhyCellGrp->pNrFr1 = macUeCfg.pNrFr1;
145 /*******************************************************************
147 * @brief Fills PDSCh serving cell config to send to scheduler
151 * Function : fillPdschServCellCfg
153 * Functionality: Fills PDSCh serving cell config to send to scheduler
155 * @params[in] macPdschCfg : Pdsch serving cell config at MAC
156 * *schPdschCfg : Pdsch serving cell config to be filled
157 * @return ROK - success
160 * ****************************************************************/
161 uint8_t fillPdschServCellCfg(PdschServCellCfg macPdschCfg, SchPdschServCellCfg *schPdschCfg)
163 schPdschCfg->maxMimoLayers = NULL;
164 if(macPdschCfg.maxMimoLayers)
166 /* TODO : Optional parameter */
169 schPdschCfg->numHarqProcForPdsch = \
170 macPdschCfg.numHarqProcForPdsch;
172 schPdschCfg->maxCodeBlkGrpPerTb = NULL;
173 if(macPdschCfg.maxCodeBlkGrpPerTb)
175 /* TODO : Optional parameter */
178 schPdschCfg->codeBlkGrpFlushInd = NULL;
179 if(macPdschCfg.codeBlkGrpFlushInd)
181 /* TODO : Optional parameter */
184 schPdschCfg->xOverhead = NULL;
185 if(macPdschCfg.xOverhead)
187 /* TODO : Optional parameter */
193 /*******************************************************************
195 * @brief Fills PUSCH cofig in initial UL BWP config for SCH UE Cfg
199 * Function : fillInitalUlBwpPuschCfg
202 * Fills PUSCH cofig in initial UL BWP config for SCH UE Cfg
204 * @params[in] macPuschCfg : Initial UL-BWP PUSCH cfg at MAC
205 * schPuschCfg : Initial UL-BWP PUSCH cfg to be filled
206 * @return ROK - success
209 * ****************************************************************/
210 uint8_t fillInitalUlBwpPuschCfg(PuschCfg macPuschCfg, SchPuschCfg *schPuschCfg)
214 schPuschCfg->dmrsUlCfgForPuschMapTypeA.addPos = \
215 macPuschCfg.dmrsUlCfgForPuschMapTypeA.addPos;
216 schPuschCfg->dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0 = \
217 macPuschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled.scramblingId0;
218 schPuschCfg->resourceAllocType = macPuschCfg.resourceAllocType;
220 schPuschCfg->numTimeDomRsrcAlloc = macPuschCfg.numTimeDomRsrcAlloc;
221 if(schPuschCfg->numTimeDomRsrcAlloc > MAX_NUM_UL_ALLOC)
223 DU_LOG("\nMAC : Number of Time domain resource allocation [%d] exceeds max limit [%d]",\
224 schPuschCfg->numTimeDomRsrcAlloc, MAX_NUM_UL_ALLOC);
227 for(idx = 0; idx < schPuschCfg->numTimeDomRsrcAlloc; idx++)
229 schPuschCfg->timeDomRsrcAllocList[idx].k2 = \
230 macPuschCfg.timeDomRsrcAllocList[idx].k2;
231 schPuschCfg->timeDomRsrcAllocList[idx].mappingType = \
232 macPuschCfg.timeDomRsrcAllocList[idx].mappingType;
233 schPuschCfg->timeDomRsrcAllocList[idx].startSymbol = \
234 macPuschCfg.timeDomRsrcAllocList[idx].startSymbol;
235 schPuschCfg->timeDomRsrcAllocList[idx].symbolLength = \
236 macPuschCfg.timeDomRsrcAllocList[idx].symbolLength;
239 schPuschCfg->transformPrecoder = macPuschCfg.transformPrecoder;
243 /*******************************************************************
245 * @brief Fills initail UL BWP config to send to scheduler
249 * Function : fillInitialUlBwp
251 * Functionality: Fills initail UL BWP config to send to sch
253 * @params[in] macInitUlBwp : Initial UL BWP cfg at MAC
254 * schInitUlBwp : Initial UL BWP cfg to be filled
255 * @return ROK - success
258 * ****************************************************************/
259 uint8_t fillInitialUlBwp(InitialUlBwp macInitUlBwp, SchInitialUlBwp *schInitUlBwp)
261 schInitUlBwp->pucchCfgPres = macInitUlBwp.pucchPresent;
262 if(schInitUlBwp->pucchCfgPres)
264 /* TODO : Optional parameter */
267 schInitUlBwp->puschCfgPres = macInitUlBwp.puschPresent;
268 if(schInitUlBwp->puschCfgPres)
270 if(fillInitalUlBwpPuschCfg(macInitUlBwp.puschCfg, &schInitUlBwp->puschCfg) != ROK)
272 DU_LOG("\nMAC : fillInitalUlBwpPuschCfg() failed");
279 /*******************************************************************
281 * @brief Fill PDCCH cfg in Initial DL BWP for UE Cfg in Scheduler
285 * Function : fillInitDlBwpPdcchCfg
288 * Fill PDCCH cfg in Initial DL BWP for UE Cfg in Scheduler
290 * @params[in] macPdcchCfg : Inital DL BWP PDCCH cfg in MAC
291 * schPdcchCfg : Inital DL BWP PDCCH cfg to be filled
292 * @return ROK - success
295 * ****************************************************************/
296 uint8_t fillInitDlBwpPdcchCfg(PdcchConfig macPdcchCfg, SchPdcchConfig *schPdcchCfg)
300 /* Fill CORESET info */
301 schPdcchCfg->numCRsetToAddMod = macPdcchCfg.numCRsetToAddMod;
302 if(schPdcchCfg->numCRsetToAddMod > MAX_NUM_CRSET)
304 DU_LOG("\nMAC : Number of CORESET to ADD/MOD [%d] exceeds max limit [%d]",\
305 schPdcchCfg->numCRsetToAddMod, MAX_NUM_CRSET);
309 for(idx = 0; idx < schPdcchCfg->numCRsetToAddMod; idx++)
311 schPdcchCfg->cRSetToAddModList[idx].cRSetId = \
312 macPdcchCfg.cRSetToAddModList[idx].cRSetId;
313 memcpy(&schPdcchCfg->cRSetToAddModList[idx].freqDomainRsrc,\
314 &macPdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
315 schPdcchCfg->cRSetToAddModList[idx].duration = \
316 macPdcchCfg.cRSetToAddModList[idx].duration;
317 schPdcchCfg->cRSetToAddModList[idx].cceRegMappingType = \
318 macPdcchCfg.cRSetToAddModList[idx].cceRegMappingType;
319 schPdcchCfg->cRSetToAddModList[idx].precoderGranularity = \
320 macPdcchCfg.cRSetToAddModList[idx].precoderGranularity;
321 schPdcchCfg->cRSetToAddModList[idx].dmrsScramblingId = \
322 macPdcchCfg.cRSetToAddModList[idx].dmrsScramblingId;
325 schPdcchCfg->numCRsetToRel = macPdcchCfg.numCRsetToRel;
326 if(schPdcchCfg->numCRsetToAddMod > MAX_NUM_CRSET)
328 DU_LOG("\nMAC : Number of CORESET to release [%d] exceeds max limit [%d]",\
329 schPdcchCfg->numCRsetToRel, MAX_NUM_CRSET);
333 for(idx = 0; idx < schPdcchCfg->numCRsetToRel; idx++)
338 /* Fill Search space info */
339 schPdcchCfg->numSearchSpcToAddMod = macPdcchCfg.numSearchSpcToAddMod;
340 if(schPdcchCfg->numSearchSpcToAddMod > MAX_NUM_SEARCH_SPC)
342 DU_LOG("\nMAC : Number of search space to ADD/MOD [%d] exceeds max [%d]", \
343 schPdcchCfg->numSearchSpcToAddMod, MAX_NUM_SEARCH_SPC);
346 for(idx = 0; idx < schPdcchCfg->numSearchSpcToAddMod; idx++)
348 schPdcchCfg->searchSpcToAddModList[idx].searchSpaceId = \
349 macPdcchCfg.searchSpcToAddModList[idx].searchSpaceId;
350 schPdcchCfg->searchSpcToAddModList[idx].cRSetId = \
351 macPdcchCfg.searchSpcToAddModList[idx].cRSetId;
352 schPdcchCfg->searchSpcToAddModList[idx].mSlotPeriodicityAndOffset = \
353 macPdcchCfg.searchSpcToAddModList[idx].mSlotPeriodicityAndOffset;
354 memcpy(&schPdcchCfg->searchSpcToAddModList[idx].mSymbolsWithinSlot,
355 &macPdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, \
356 MONITORING_SYMB_WITHIN_SLOT_SIZE);
357 schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel1 = \
358 macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1;
359 schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel2 = \
360 macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2;
361 schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel4 = \
362 macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4;
363 schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel8 = \
364 macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8;
365 schPdcchCfg->searchSpcToAddModList[idx].numCandidatesAggLevel16 = \
366 macPdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16;
367 schPdcchCfg->searchSpcToAddModList[idx].searchSpaceType = \
368 macPdcchCfg.searchSpcToAddModList[idx].searchSpaceType;
369 schPdcchCfg->searchSpcToAddModList[idx].ueSpecificDciFormat = \
370 macPdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat;
373 schPdcchCfg->numSearchSpcToRel = macPdcchCfg.numSearchSpcToRel;
374 if(schPdcchCfg->numSearchSpcToRel > MAX_NUM_SEARCH_SPC)
376 DU_LOG("\nMAC : Number of search space to release [%d] exceeds max [%d]", \
377 schPdcchCfg->numSearchSpcToRel, MAX_NUM_SEARCH_SPC);
380 for(idx = 0; idx < schPdcchCfg->numSearchSpcToRel; idx++)
388 /*******************************************************************
390 * @brief Fill PDSCH cfg in Initial DL BWP for UE Cfg in Scheduler
394 * Function : fillInitDlBwpPdschCfg
397 * Fill PDSCH cfg in Initial DL BWP for UE Cfg in Scheduler
399 * @params[in] macPdschCfg : Inital DL BWP PDSCH cfg at MAC
400 * schPdschCfg : Inital DL BWP PDSCH cfg to be filled
401 * @return ROK - success
404 * ****************************************************************/
405 uint8_t fillInitDlBwpPdschCfg(PdschConfig macPdschCfg, SchPdschConfig *schPdschCfg)
409 schPdschCfg->dmrsDlCfgForPdschMapTypeA.addPos = \
410 macPdschCfg.dmrsDlCfgForPdschMapTypeA.addPos;
411 schPdschCfg->resourceAllocType = macPdschCfg.resourceAllocType;
412 schPdschCfg->numTimeDomRsrcAlloc = macPdschCfg.numTimeDomRsrcAlloc;
413 if(schPdschCfg->numTimeDomRsrcAlloc > MAX_NUM_DL_ALLOC)
415 DU_LOG("\nMAC : Number of time domain resource allocation [%d], exceeds\
416 max limit [%d]", schPdschCfg->numTimeDomRsrcAlloc, MAX_NUM_DL_ALLOC);
420 for(idx = 0; idx < schPdschCfg->numTimeDomRsrcAlloc; idx++)
422 schPdschCfg->timeDomRsrcAllociList[idx].mappingType = \
423 macPdschCfg.timeDomRsrcAllociList[idx].mappingType;
424 schPdschCfg->timeDomRsrcAllociList[idx].startSymbol = \
425 macPdschCfg.timeDomRsrcAllociList[idx].startSymbol;
426 schPdschCfg->timeDomRsrcAllociList[idx].symbolLength = \
427 macPdschCfg.timeDomRsrcAllociList[idx].symbolLength;
430 schPdschCfg->rbgSize = macPdschCfg.rbgSize;
431 schPdschCfg->numCodeWordsSchByDci = macPdschCfg.numCodeWordsSchByDci;
432 schPdschCfg->bundlingType = macPdschCfg.bundlingType;
437 /*******************************************************************
439 * @brief Fill Initial DL BWP for SCH UE config
443 * Function : fillInitialDlBwp
445 * Functionality: Fill Initial DL BWP for SCH UE config
447 * @params[in] macInitDlBwp : Inital DL BWP cfg at MAC
448 * schInitDlBwp : Inital DL BWP cfg to be filled
449 * @return ROK - success
452 * ****************************************************************/
453 uint8_t fillInitialDlBwp(InitialDlBwp macInitDlBwp, SchInitalDlBwp *schInitDlBwp)
455 schInitDlBwp->pdcchCfgPres = macInitDlBwp.pdcchPresent;
456 if(schInitDlBwp->pdcchCfgPres)
458 if(fillInitDlBwpPdcchCfg(macInitDlBwp.pdcchCfg, &schInitDlBwp->pdcchCfg) != ROK)
460 DU_LOG("\nMAC : fillInitDlBwpPdcchCfg() failed");
465 schInitDlBwp->pdschCfgPres = macInitDlBwp.pdschPresent;
466 if(schInitDlBwp->pdschCfgPres)
468 if(fillInitDlBwpPdschCfg(macInitDlBwp.pdschCfg,&schInitDlBwp->pdschCfg) != ROK)
470 DU_LOG("\nMAC : fillInitDlBwpPdschCfg() failed");
477 /*******************************************************************
479 * @brief Fills Sp Cell config to be sent to scheduler
483 * Function : fillSpCellCfg
485 * Functionality: Fills Sp Cell config to be sent to scheduler
487 * @params[in] macSpCellCfg : SP cell cfg at MAC
488 * schSpCellCfg : SP cell cfg to be filled
489 * @return ROK - success
492 * ****************************************************************/
493 uint8_t fillSpCellCfg(SpCellCfg macSpCellCfg, SchSpCellCfg *schSpCellCfg)
496 SchServCellCfgInfo *servCellCfg;
498 schSpCellCfg->servCellIdx = macSpCellCfg.servCellIdx;
499 servCellCfg = &schSpCellCfg->servCellCfg;
501 /* Fill initial DL BWP */
502 if(fillInitialDlBwp(macSpCellCfg.servCellCfg.initDlBwp, \
503 &servCellCfg->initDlBwp) != ROK )
505 DU_LOG("\nMAC : fillInitialDlBwp() failed");
509 servCellCfg->numDlBwpToAdd = macSpCellCfg.servCellCfg.numDlBwpToAdd;
510 if(servCellCfg->numDlBwpToAdd > MAX_NUM_BWP)
512 DU_LOG("\nMAC : Number of DL BWP to ADD/MOD [%d] exceeds max limit [%d]",\
513 servCellCfg->numDlBwpToAdd, MAX_NUM_BWP);
516 for(idx = 0; idx < servCellCfg->numDlBwpToAdd; idx++)
518 /* TODO : As of now numDlBwpToAdd = 0 */
521 servCellCfg->firstActvDlBwpId = macSpCellCfg.servCellCfg.firstActvDlBwpId;
522 servCellCfg->defaultDlBwpId = macSpCellCfg.servCellCfg.defaultDlBwpId;
523 servCellCfg->bwpInactivityTmr = NULL;
524 if(macSpCellCfg.servCellCfg.bwpInactivityTmr)
526 /* TODO : This is an optional parameter, not filled currently */
529 /* Fill PDSCH serving cell config */
530 if(fillPdschServCellCfg(macSpCellCfg.servCellCfg.pdschServCellCfg, \
531 &servCellCfg->pdschServCellCfg) != ROK)
533 DU_LOG("\nMAC : fillPdschServCellCfg() failed");
537 /* Fill Initail UL BWP */
538 if(fillInitialUlBwp(macSpCellCfg.servCellCfg.initUlBwp, \
539 &servCellCfg->initUlBwp) != ROK)
541 DU_LOG("\nMAC : fillInitialUlBwp() failed");
545 servCellCfg->numUlBwpToAdd = macSpCellCfg.servCellCfg.numUlBwpToAdd;
546 if(servCellCfg->numUlBwpToAdd > MAX_NUM_BWP)
548 DU_LOG("\nMAC : Number of UL BWP to ADD/MOD [%d] exceeds max limit [%d]",\
549 servCellCfg->numUlBwpToAdd, MAX_NUM_BWP);
552 for(idx = 0; idx < servCellCfg->numUlBwpToAdd; idx++)
554 /* TODO : As of now numDlBwpToAdd = 0 */
556 servCellCfg->firstActvUlBwpId = macSpCellCfg.servCellCfg.firstActvUlBwpId;
562 /*******************************************************************
564 * @brief Fill logical channel configuration
568 * Function : fillLogicalChannelCfg
570 * Functionality: Fill logical channel configuration
572 * @params[in] macLcCfg : Logical channel Cfg at MAC
573 * schLcCfg : LC cfg to fill at scheduler
574 * @return ROK - success
577 * ****************************************************************/
578 uint8_t fillLogicalChannelCfg(LcCfg macLcCfg, SchLcCfg *schLcCfg)
580 schLcCfg->lcId = macLcCfg.lcId;
581 schLcCfg->dlLcCfg.lcp = macLcCfg.dlLcCfg.lcp;
583 schLcCfg->drbQos = NULL;
586 /* TODO : Optional Parameter */
589 schLcCfg->snssai = NULL;
592 /* TODO : Optional Parameter */
595 schLcCfg->ulLcCfg = NULL;
598 /* TODO : Optional Parameter */
604 /*******************************************************************
606 * @brief Fills and sends UE configuration to Scheduler
610 * Function : sendAddUeCreateReqToSch
612 * Functionality: Fills and sends UE configuration to Scheduler
614 * @params[in] Ue configuration from DU APP
615 * @return ROK - success
618 * ****************************************************************/
619 uint8_t sendAddUeCreateReqToSch(MacUeCfg *ueCfg)
625 schUeCfg.cellId = ueCfg->cellId;
626 schUeCfg.crnti = ueCfg->crnti;
628 /* Copy MAC cell group config */
629 memset(&schUeCfg.macCellGrpCfg, 0, sizeof(SchMacCellGrpCfg));
630 if(fillMacCellGroupCfg(ueCfg->macCellGrpCfg, &schUeCfg.macCellGrpCfg) != ROK)
632 DU_LOG("\nMAC : fillMacCellGroupCfg() failed");
636 /* Copy Physical cell group config */
637 memset(&schUeCfg.phyCellGrpCfg, 0,sizeof(SchPhyCellGrpCfg));
638 if(fillPhyCellGroupCfg(ueCfg->phyCellGrpCfg, &schUeCfg.phyCellGrpCfg) != ROK)
640 DU_LOG("\nMAC : fillPhyCellGroupCfg() failed");
644 /* Copy sp cell config */
645 memset(&schUeCfg.spCellCfg, 0, sizeof(SchSpCellCfg));
646 if(fillSpCellCfg(ueCfg->spCellCfg, &schUeCfg.spCellCfg) != ROK)
648 DU_LOG("\nMAC : fillSpCellCfg() failed");
652 schUeCfg.aggrMaxBitRate = NULL;
653 if(ueCfg->maxAggrBitRate != NULL)
656 MAC_ALLOC(schUeCfg.aggrMaxBitRate, sizeof(SchAggrMaxBitRate));
657 if(!schUeCfg.aggrMaxBitRate)
659 DU_LOG("\nMAC : Memory allocation failed in sendAddUeCreateReqToSch");
662 schUeCfg.aggrMaxBitRate->ulBitRate = ueCfg->maxAggrBitRate->ulBits;
663 schUeCfg.aggrMaxBitRate->dlBitRate = ueCfg->maxAggrBitRate->dlBits;
666 schUeCfg.numLc = ueCfg->numLcs;
667 if(schUeCfg.numLc > MAX_NUM_LC)
669 DU_LOG("\nMAC : Number of Logical channels %d exceeds max limit %d",\
670 schUeCfg.numLc, MAX_NUM_LC);
672 for(idx = 0; idx < schUeCfg.numLc; idx++)
674 if(fillLogicalChannelCfg(ueCfg->lcCfgList[idx], &schUeCfg.lcCfgList[idx]) != ROK)
676 DU_LOG("\nMAC : fillLogicalChannelCfg() failed");
681 /* Fill event and send UE create request to SCH */
682 FILL_PST_MAC_TO_SCH(pst, EVENT_UE_CREATE_REQ_TO_SCH);
683 return(*macSchUeCreateReqOpts[pst.selector])(&pst, &schUeCfg);
686 /*******************************************************************
688 * @brief Creates UE Cb and fills ueCfg
692 * Function : createUeCb
694 * Functionality: Creates UE Cb and fills ueCfg
696 * @params[in] MAC UE Configuration
697 * @return ROK - success
700 * ****************************************************************/
701 uint8_t createUeCb(MacUeCfg *ueCfg)
703 uint16_t ueIdx, lcIdx, cellIdx;
706 GET_CELL_IDX(ueCfg->cellId, cellIdx);
708 /* Validate cell id */
709 if(macCb.macCell[cellIdx]->cellId != ueCfg->cellId)
711 DU_LOG("\nMAC : Cell Id %d not configured", ueCfg->cellId);
715 /* Check if max number of UE configured */
716 if(macCb.macCell[cellIdx]->numActvUe > MAX_NUM_UE)
718 DU_LOG("MAC : Max number of UE [%d] already configured", MAX_NUM_UE);
722 /* Check if UE already configured */
723 ueCb = &macCb.macCell[cellIdx]->ueCb[ueCfg->ueIdx -1];
726 if((ueCb->ueIdx == ueCfg->ueIdx) && (ueCb->crnti == ueCfg->crnti) &&\
727 (ueCb->state == UE_STATE_ACTIVE))
729 DU_LOG("\n MAC : CRNTI %d already configured ", ueCfg->crnti);
734 /* Fill received Ue Configuration in UeCb */
735 memset(ueCb, 0, sizeof(MacUeCb));
737 ueCb->crnti = ueCfg->crnti;
738 ueCb->cellCb = macCb.macCell[cellIdx];
739 ueCb->dlInfo.dlHarqEnt.numHarqProcs = \
740 ueCfg->spCellCfg.servCellCfg.pdschServCellCfg.numHarqProcForPdsch;
741 ueCb->state = UE_STATE_ACTIVE;
744 switch(ueCfg->macCellGrpCfg.bsrTmrCfg.periodicTimer)
747 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_1MS;
750 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_5MS;
753 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_10MS;
756 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_16MS;
759 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_20MS;
762 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_32MS;
765 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_40MS;
768 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_60MS;
771 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_80MS;
774 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_128MS;
777 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_160MS;
780 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_320MS;
783 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_640MS;
786 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_1280MS;
789 ueCb->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR_2560MS;
792 DU_LOG("\nMAC : Invalid BSR Periodic Timer");
796 switch(ueCfg->macCellGrpCfg.bsrTmrCfg.retxTimer)
799 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_10MS;
802 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_20MS;
805 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_40MS;
808 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_80MS;
811 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_160MS;
814 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_320MS;
817 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_640MS;
820 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_1280MS;
823 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_2560MS;
826 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_5120MS;
829 ueCb->bsrTmrCfg.retxTimer = RETX_BSR_TMR_10240MS;
832 DU_LOG("\nMAC : Invalid BSR retransmission timer");
836 switch(ueCfg->macCellGrpCfg.bsrTmrCfg.srDelayTimer)
839 ueCb->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR_20MS;
842 ueCb->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR_40MS;
845 ueCb->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR_64MS;
848 ueCb->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR_128MS;
851 ueCb->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR_512MS;
854 ueCb->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR_1024MS;
857 ueCb->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR_2560MS;
860 DU_LOG("\nMAC : Invalid SR delay timer");
865 if(ueCfg->numLcs > MAX_NUM_LC)
867 DU_LOG("\nMAC : Number of LC to configure[%d] exceeds limit[%d]",\
868 ueCfg->numLcs, MAX_NUM_LC);
872 for(lcIdx = 0; lcIdx < ueCfg->numLcs; lcIdx++)
874 ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcId = ueCfg->lcCfgList[lcIdx].lcId;
875 ueCb->dlInfo.lcCb[ueCb->dlInfo.numDlLc].lcState = MAC_LC_STATE_ACTIVE;
876 ueCb->dlInfo.numDlLc++;
880 for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
882 if(macCb.macCell[cellIdx]->macRaCb[ueIdx].crnti == ueCb->crnti)
884 ueCb->raCb = &macCb.macCell[cellIdx]->macRaCb[ueIdx];
889 macCb.macCell[cellIdx]->numActvUe++;
894 /*******************************************************************
896 * @brief Handles UE create requst from DU APP
900 * Function : MacProcUeCreateReq
902 * Functionality: Handles UE create requst from DU APP
905 * @return ROK - success
908 * ****************************************************************/
909 uint8_t MacProcUeCreateReq(Pst *pst, MacUeCfg *ueCfg)
913 DU_LOG("\nMAC : UE Create Request for CRNTI[%d]", ueCfg->crnti);
917 ret = createUeCb(ueCfg);
920 ret = sendAddUeCreateReqToSch(ueCfg);
923 DU_LOG("\nMAC : Failed to send UE Create request to scheduler");
928 DU_LOG("\nMAC : Failed to create MAC UE Cb ");
933 DU_LOG("\nMAC : MAC UE Create request processing failed");
936 /* FREE shared memory */
937 MAC_FREE_SHRABL_BUF(pst->region, pst->pool, ueCfg, sizeof(MacUeCfg));
942 /*******************************************************************
944 * @brief Fill and Send UE create response from MAC to DU APP
948 * Function : MacSendUeCreateRsp
950 * Functionality: Fill and Send UE create response from MAC to DUAPP
952 * @params[in] MAC UE create result
953 * SCH UE create response
954 * @return ROK - success
957 * ****************************************************************/
958 uint8_t MacSendUeCreateRsp(MacRsp result, SchUeCfgRsp *schCfgRsp)
963 MAC_ALLOC_SHRABL_BUF(cfgRsp, sizeof(MacUeCfgRsp));
966 DU_LOG("\nMAC: Memory allocation for UE config response failed");
970 /* Filling UE Config response */
971 memset(cfgRsp, 0, sizeof(MacUeCfgRsp));
972 cfgRsp->cellId = schCfgRsp->cellId;
973 cfgRsp->ueIdx = schCfgRsp->ueIdx;
974 cfgRsp->result = result;
976 /* Fill Post structure and send UE Create response*/
977 memset(&rspPst, 0, sizeof(Pst));
978 FILL_PST_MAC_TO_DUAPP(rspPst, EVENT_MAC_UE_CREATE_RSP);
979 return DuMacUeCreateRspOpts[rspPst.selector](&rspPst, cfgRsp);
984 /*******************************************************************
986 * @brief Processes UE create response from scheduler
990 * Function : MacProcSchUeCfgRsp
993 * Processes UE create response from scheduler
994 * Sends UE create response to DU APP
996 * @params[in] Pst : Post structure
997 * schCfgRsp : Scheduler UE cfg response
998 * @return ROK - success
1001 * ****************************************************************/
1002 uint8_t MacProcSchUeCfgRsp(Pst *pst, SchUeCfgRsp *schCfgRsp)
1004 uint8_t result = MAC_DU_APP_RSP_NOK;
1008 GET_CELL_IDX(schCfgRsp->cellId, cellIdx);
1010 if(schCfgRsp->rsp == RSP_NOK)
1012 DU_LOG("\nMAC : SCH UE Create Response : FAILURE [CRNTI %d]", schCfgRsp->crnti);
1013 memset(&macCb.macCell[cellIdx]->ueCb[schCfgRsp->ueIdx -1], 0, sizeof(MacUeCb));
1014 macCb.macCell[cellIdx]->numActvUe--;
1015 result = MAC_DU_APP_RSP_NOK;
1019 DU_LOG("\nMAC : SCH UE Create Response : SUCCESS [CRNTI %d]", schCfgRsp->crnti);
1020 result = MAC_DU_APP_RSP_OK;
1022 ret = MacSendUeCreateRsp(result, schCfgRsp);
1027 /**********************************************************************
1029 **********************************************************************/