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 contains UE management handling functionality for SCH */
20 #include "common_def.h"
27 #include "du_app_mac_inf.h"
28 #include "mac_sch_interface.h"
30 #include "sch_utils.h"
33 SchUeCfgRspFunc SchUeCfgRspOpts[] =
35 packSchUeCfgRsp, /* LC */
36 MacProcSchUeCfgRsp, /* TC */
37 packSchUeCfgRsp /* LWLC */
41 /*******************************************************************
43 * @brief Fill and send UE cfg response to MAC
47 * Function : SchSendUeCfgRspToMac
49 * Functionality: Fill and send UE cfg response to MAC
52 * @return ROK - success
55 * ****************************************************************/
56 void SchSendUeCfgRspToMac(SchUeCfg *ueCfg, Inst inst,\
57 SchMacRsp result, SchUeCfgRsp *cfgRsp)
61 DU_LOG("\nSCH: Sending UE Create response to MAC");
63 cfgRsp->cellId = ueCfg->cellId;
64 cfgRsp->crnti = ueCfg->crnti;
65 GET_UE_IDX(ueCfg->crnti, cfgRsp->ueIdx);
68 /* Filling response post */
69 memset(&rspPst, 0, sizeof(Pst));
70 FILL_PST_SCH_TO_MAC(rspPst, inst);
71 rspPst.event = EVENT_UE_CREATE_RSP_TO_MAC;
73 SchUeCfgRspOpts[rspPst.selector](&rspPst, cfgRsp);
76 /*******************************************************************
78 * @brief Hanles Ue create request from MAC
82 * Function : MacSchUeCreateReq
84 * Functionality: Hanles Ue create request from MAC
87 * @return ROK - success
90 * ****************************************************************/
91 uint8_t MacSchUeCreateReq(Pst *pst, SchUeCfg *ueCfg)
98 Inst inst = pst->dstInst - 1;
100 DU_LOG("\nSCH : UE Create Request for CRNTI[%d]", ueCfg->crnti);
102 memset(&cfgRsp, 0, sizeof(SchUeCfgRsp));
106 DU_LOG("\nSCH : UE create request failed");
110 /* Search of cell cb */
111 for(idx = 0; idx < MAX_NUM_CELL; idx++)
113 cellCb = schCb[inst].cells[idx];
114 if(cellCb->cellId == ueCfg->cellId)
117 if(idx == MAX_NUM_CELL)
119 DU_LOG("\nSCH : Ue create request failed. Invalid cell id %d", ueCfg->cellId);
120 SchSendUeCfgRspToMac(ueCfg, inst, RSP_NOK, &cfgRsp);
124 /* Check if max number of UE configured */
125 if(cellCb->numActvUe > MAX_NUM_UE)
127 DU_LOG("SCH : Max number of UE [%d] already configured", MAX_NUM_UE);
128 SchSendUeCfgRspToMac(ueCfg, inst, RSP_NOK, &cfgRsp);
132 /* Search if UE already configured */
133 GET_UE_IDX(ueCfg->crnti, ueIdx);
134 ueCb = &cellCb->ueCb[ueIdx -1];
137 if((ueCb->crnti == ueCfg->crnti) && (ueCb->state == SCH_UE_STATE_ACTIVE))
139 DU_LOG("\n SCH : CRNTI %d already configured ", ueCfg->crnti);
140 SchSendUeCfgRspToMac(ueCfg, inst, RSP_OK, &cfgRsp);
145 /* Fill received Ue Configuration in UeCb */
146 memset(ueCb, 0, sizeof(SchUeCb));
148 GET_UE_IDX(ueCfg->crnti, ueCb->ueIdx);
149 ueCb->crnti = ueCfg->crnti;
150 memcpy(&ueCb->ueCfg, ueCfg, sizeof(SchUeCfg));
151 ueCb->state = SCH_UE_STATE_ACTIVE;
154 ueCb->cellCb = cellCb;
155 ueCb->srRcvd = false;
156 for(idx=0; idx<MAX_NUM_LOGICAL_CHANNEL_GROUPS; idx++)
157 ueCb->bsrInfo[idx].dataVol = 0;
159 SchSendUeCfgRspToMac(ueCfg, inst, RSP_OK, &cfgRsp);
163 /*******************************************************************
165 * @brief Fills PUSCH UL allocation
169 * Function : schFillPuschAlloc
171 * Functionality: fills PUSCH info
174 * @return ROK - success
177 * ****************************************************************/
178 uint8_t schFillPuschAlloc(SchUeCb *ueCb, uint16_t pdcchSlot, uint32_t dataVol, SchPuschInfo *puschInfo)
180 uint16_t puschSlot = 0;
181 uint16_t startRb = 0;
184 uint8_t numPdschSymbols= 14;
188 SchCellCb *cellCb = ueCb->cellCb;
189 SchUlSlotInfo *schUlSlotInfo = NULLP;
190 uint8_t k2 = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].k2;
191 uint8_t startSymb = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].startSymbol;
192 uint8_t symbLen = ueCb->ueCfg.spCellCfg.servCellCfg.initUlBwp.puschCfg.timeDomRsrcAllocList[0].symbolLength;
194 puschSlot = (pdcchSlot + k2) % SCH_NUM_SLOTS;
196 startRb = cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb;
197 tbSize = schCalcTbSize((dataVol + buffer)/8); /* 2 bytes header + some buffer */
198 numRb = schCalcNumPrb(tbSize, mcs, numPdschSymbols);
199 /* increment PUSCH PRB */
201 cellCb->schUlSlotInfo[puschSlot]->puschCurrentPrb += numRb;
203 puschInfo->harqProcId = SCH_HARQ_PROC_ID;
204 puschInfo->resAllocType = SCH_ALLOC_TYPE_1;
205 puschInfo->fdAlloc.startPrb = startRb;
206 puschInfo->fdAlloc.numPrb = numRb;
207 puschInfo->tdAlloc.startSymb = startSymb;
208 puschInfo->tdAlloc.numSymb = symbLen;
209 puschInfo->tbInfo.mcs = mcs;
210 puschInfo->tbInfo.ndi = 1; /* new transmission */
211 puschInfo->tbInfo.rv = 0;
212 puschInfo->tbInfo.tbSize = tbSize;
213 puschInfo->dmrsMappingType = DMRS_MAP_TYPE_A; /* Setting Type-A */
214 puschInfo->nrOfDmrsSymbols = NUM_DMRS_SYMBOLS;
215 puschInfo->dmrsAddPos = DMRS_ADDITIONAL_POS;
217 /* Update pusch in cell */
218 for(idx=startSymb; idx<symbLen; idx++)
220 cellCb->schUlSlotInfo[puschSlot]->assignedPrb[idx] = startRb + numRb;
223 schUlSlotInfo = cellCb->schUlSlotInfo[puschSlot];
225 SCH_ALLOC(schUlSlotInfo->schPuschInfo, sizeof(SchPuschInfo));
226 if(!schUlSlotInfo->schPuschInfo)
228 DU_LOG("SCH: Memory allocation failed in schAllocMsg3Pusch");
231 memcpy(schUlSlotInfo->schPuschInfo, puschInfo, sizeof(SchPuschInfo));
236 /*******************************************************************
238 * @brief Fills DCI for UL grant
242 * Function : schFillUlDci
244 * Functionality: fills DCI for UL grant in response to BSR
247 * @return ROK - success
250 * ****************************************************************/
251 uint8_t schFillUlDci(SchUeCb *ueCb, SchPuschInfo puschInfo, DciInfo *dciInfo)
253 SchCellCb *cellCb = ueCb->cellCb;
254 SchControlRsrcSet coreset1 = ueCb->ueCfg.spCellCfg.servCellCfg.initDlBwp.pdcchCfg.cRSetToAddModList[0];
256 dciInfo->cellId = cellCb->cellId;
257 dciInfo->crnti = ueCb->crnti;
260 dciInfo->bwpCfg.subcarrierSpacing = cellCb->cellCfg.sib1SchCfg.bwp.subcarrierSpacing;
261 dciInfo->bwpCfg.cyclicPrefix = cellCb->cellCfg.sib1SchCfg.bwp.cyclicPrefix;
262 dciInfo->bwpCfg.freqAlloc.startPrb = 0;
263 dciInfo->bwpCfg.freqAlloc.numPrb = MAX_NUM_RB; /* whole of BW */
265 /*fill coreset cfg */
266 //Considering number of RBs in coreset1 is same as coreset0
267 dciInfo->coresetCfg.coreSetSize = coresetIdxTable[0][1];
268 //Considering coreset1 also starts from same symbol as coreset0
269 dciInfo->coresetCfg.startSymbolIndex = searchSpaceIdxTable[0][3];
270 dciInfo->coresetCfg.durationSymbols = coreset1.duration;
271 memcpy(dciInfo->coresetCfg.freqDomainResource, coreset1.freqDomainRsrc, FREQ_DOM_RSRC_SIZE);
273 dciInfo->coresetCfg.cceRegMappingType = coreset1.cceRegMappingType; /* non-interleaved */
274 dciInfo->coresetCfg.regBundleSize = 6; /* must be 6 for non-interleaved */
275 dciInfo->coresetCfg.interleaverSize = 0; /* NA for non-interleaved */
276 dciInfo->coresetCfg.coreSetType = 1; /* non PBCH coreset */
277 dciInfo->coresetCfg.shiftIndex = cellCb->cellCfg.phyCellId;
278 dciInfo->coresetCfg.precoderGranularity = coreset1.precoderGranularity;
279 dciInfo->coresetCfg.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
280 dciInfo->coresetCfg.aggregationLevel = 4; /* same as for sib1 */
282 dciInfo->formatType = FORMAT0_0;
285 dciInfo->format.format0_0.resourceAllocType = puschInfo.resAllocType;
286 dciInfo->format.format0_0.freqAlloc.startPrb = puschInfo.fdAlloc.startPrb;
287 dciInfo->format.format0_0.freqAlloc.numPrb = puschInfo.fdAlloc.numPrb;
288 dciInfo->format.format0_0.timeAlloc.startSymb = puschInfo.tdAlloc.startSymb;
289 dciInfo->format.format0_0.timeAlloc.numSymb = puschInfo.tdAlloc.numSymb;
290 dciInfo->format.format0_0.rowIndex = 0; /* row Index */
291 dciInfo->format.format0_0.mcs = puschInfo.tbInfo.mcs;
292 dciInfo->format.format0_0.harqProcId = puschInfo.harqProcId;
293 dciInfo->format.format0_0.puschHopFlag = FALSE; /* disabled */
294 dciInfo->format.format0_0.freqHopFlag = FALSE; /* disabled */
295 dciInfo->format.format0_0.ndi = puschInfo.tbInfo.ndi; /* new transmission */
296 dciInfo->format.format0_0.rv = puschInfo.tbInfo.rv;
297 dciInfo->format.format0_0.tpcCmd = 0; //Sphoorthi TODO: check
298 dciInfo->format.format0_0.sUlCfgd = FALSE; /* SUL not configured */
300 /* Fill DCI Structure */
301 dciInfo->dciInfo.rnti = ueCb->crnti;
302 dciInfo->dciInfo.scramblingId = cellCb->cellCfg.phyCellId;
303 dciInfo->dciInfo.scramblingRnti = 0;
304 dciInfo->dciInfo.cceIndex = 0; /* 0-3 for UL and 4-7 for DL */
305 dciInfo->dciInfo.aggregLevel = 4;
306 dciInfo->dciInfo.beamPdcchInfo.numPrgs = 1;
307 dciInfo->dciInfo.beamPdcchInfo.prgSize = 1;
308 dciInfo->dciInfo.beamPdcchInfo.digBfInterfaces = 0;
309 dciInfo->dciInfo.beamPdcchInfo.prg[0].pmIdx = 0;
310 dciInfo->dciInfo.beamPdcchInfo.prg[0].beamIdx[0] = 0;
311 dciInfo->dciInfo.txPdcchPower.powerValue = 0;
312 dciInfo->dciInfo.txPdcchPower.powerControlOffsetSS = 0;
313 dciInfo->dciInfo.pdschCfg = NULLP; /* No DL data being sent */
319 /**********************************************************************
321 **********************************************************************/