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 DU APP */
19 #include "common_def.h"
29 #include "du_app_mac_inf.h"
30 #include "du_app_rlc_inf.h"
33 #include<ProtocolIE-Field.h>
36 #include "du_f1ap_msg_hdl.h"
37 #include "du_ue_mgr.h"
43 DuMacDlCcchInd packMacDlCcchIndOpts[] =
45 packMacDlCcchInd, /* Loose coupling */
46 MacProcDlCcchInd, /* TIght coupling */
47 packMacDlCcchInd /* Light weight-loose coupling */
50 DuMacUeCreateReq packMacUeCreateReqOpts[] =
52 packDuMacUeCreateReq, /* Loose coupling */
53 MacProcUeCreateReq, /* TIght coupling */
54 packDuMacUeCreateReq, /* Light weight-loose coupling */
57 DuRlcUlUeCreateReq packRlcUlUeCreateReqOpts[] =
59 packDuRlcUlUeCreateReq, /* Loose coupling */
60 RlcUlProcUeCreateReq, /* TIght coupling */
61 packDuRlcUlUeCreateReq, /* Light weight-loose coupling */
64 DuDlRrcMsgToRlcFunc duSendDlRrcMsgToRlcOpts[] =
66 packDlRrcMsgToRlc, /* Loose coupling */
67 RlcProcDlRrcMsgTransfer, /* Tight coupling */
68 packDlRrcMsgToRlc /* Light weight-loose coupling */
71 /*******************************************************************
73 * @brief Handles EGTP data from CU
77 * Function : duHdlEgtpData
80 * Processes EGTP header and sends data to RLC
82 * @params[in] Pointer to EGTP Message
83 * @return ROK - success
86 * ****************************************************************/
87 uint8_t duHdlEgtpDlData(EgtpMsg *egtpMsg)
90 /* TODO : Extract RbId/UeID/CellID/SduId from database
91 using tunnel id in egtp header */
93 DU_LOG("\nDU_APP : Processing DL data");
96 KwuDatReqInfo datReqInfo;
98 datReqInfo.rlcId.rbId = RB_ID;
99 datReqInfo.rlcId.rbType = CM_LTE_DRB;
100 datReqInfo.rlcId.ueId = UE_ID;
101 datReqInfo.rlcId.cellId = NR_CELL_ID;
103 datReqInfo.sduId = ++sduId;
104 datReqInfo.lcType = CM_LTE_LCH_DTCH;
106 /* Filling pst and Sending to RLC DL */
107 pst.selector = ODU_SELECTOR_LWLC;
108 pst.srcEnt = ENTDUAPP;
110 pst.dstInst = RLC_DL_INST;
111 pst.dstProcId = DU_PROC;
112 pst.srcProcId = DU_PROC;
113 pst.region = duCb.init.region;
115 cmPkKwuDatReq(&pst, &datReqInfo, egtpMsg->msg);
117 //duBuildAndSendDlRrcMsgToRlc();
122 /*******************************************************************
124 * @brief Handles UL data and send to CU
128 * Function : duHdlRlcUlData
131 * Processes UL Data from RLC and sends to CU
133 * @params[in] Pointer to EGTP Message
134 * @return ROK - success
137 *****************************************************************/
139 uint8_t duHdlRlcUlData(Pst *pst, KwuDatIndInfo* datInd, Buffer *mBuf)
141 DU_LOG("\nDU_APP : Received UL Data at DU_APP");
143 /* Send UL data to CU via EGTP */
144 duSendEgtpDatInd(mBuf);
145 ODU_PUT_MSG_BUF(mBuf);
150 /******************************************************************
152 * @brief Builds and Sends DL CCCH Ind to MAC
156 * Function : duBuildAndSendDlCcchInd
158 * Functionality: Builds and sends DL CCCH Ind Msg to MAC
160 * @params[in] dlCcchMsg - uint8_t*
161 * @return ROK - success
164 * ****************************************************************/
165 uint8_t duBuildAndSendDlCcchInd(uint16_t *cellId, uint16_t *crnti, \
166 DlCcchMsgType msgType, uint8_t *dlCcchMsg, uint16_t dlCcchMsgSize)
170 DlCcchIndInfo *dlCcchIndInfo = NULLP;
172 memset(&pst, 0, sizeof(Pst));
174 DU_LOG("\nDU APP : Building and Sending DL CCCH Ind to MAC");
176 DU_ALLOC_SHRABL_BUF(dlCcchIndInfo, sizeof(DlCcchIndInfo));
180 DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
184 dlCcchIndInfo->cellId = *cellId;
185 dlCcchIndInfo->crnti = *crnti;
186 dlCcchIndInfo->msgType = msgType;
187 dlCcchIndInfo->dlCcchMsgLen = dlCcchMsgSize;
189 DU_ALLOC_SHRABL_BUF(dlCcchIndInfo->dlCcchMsg, dlCcchIndInfo->dlCcchMsgLen);
190 if(!dlCcchIndInfo->dlCcchMsg)
192 DU_LOG("\nDU APP : Memory alloc failed while building DL CCCH Ind");
193 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, sizeof(DlCcchIndInfo));
196 for(idx2 = 0; idx2 < dlCcchIndInfo->dlCcchMsgLen; idx2++)
198 dlCcchIndInfo->dlCcchMsg[idx2] = dlCcchMsg[idx2];
200 DU_FREE(dlCcchMsg, dlCcchMsgSize);
203 FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_DL_CCCH_IND);
204 ret = (*packMacDlCcchIndOpts[pst.selector])(&pst, dlCcchIndInfo);
207 DU_LOG("\nDU_APP : Failure in sending DL CCCH to MAC");
208 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo->dlCcchMsg,\
209 dlCcchIndInfo->dlCcchMsgLen);
210 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlCcchIndInfo, \
211 sizeof(DlCcchIndInfo));
219 /*******************************************************************
221 * @brief Build and Send DL RRC Message transfer to RLC
225 * Function : duBuildAndSendDlRrcMsgToRlc
228 * Build and Send DL RRC Message transfer to RLC
230 * @params[in] Cell ID
232 * Logical Channgel ID
235 * @return ROK - success
238 * ****************************************************************/
239 uint8_t duBuildAndSendDlRrcMsgToRlc(uint16_t cellId, RlcUeCfg ueCfg, \
240 uint8_t lcId, bool deliveryStaReq, uint16_t rrcMsgLen, uint8_t *rrcMsg)
245 RlcDlRrcMsgInfo *dlRrcMsgInfo;
247 DU_ALLOC_SHRABL_BUF(dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
250 DU_LOG("\nDU APP : Memory allocation failed for dlRrcMsgInfo in \
251 duBuildAndSendDlRrcMsgToRlc");
252 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rrcMsg, rrcMsgLen);
256 /* Filling up the RRC msg info */
257 dlRrcMsgInfo->cellId = cellId;
258 dlRrcMsgInfo->ueIdx = ueCfg.ueIdx;
259 for(lcIdx = 0; lcIdx <= MAX_NUM_LOGICAL_CHANNELS; lcIdx++)
261 if(ueCfg.rlcBearerCfg[lcIdx].lcId == lcId)
263 dlRrcMsgInfo->rbType = ueCfg.rlcBearerCfg[lcIdx].rbType;
264 dlRrcMsgInfo->rbId = ueCfg.rlcBearerCfg[lcIdx].rbId;
265 dlRrcMsgInfo->lcType = ueCfg.rlcBearerCfg[lcIdx].lcType;
266 dlRrcMsgInfo->lcId = ueCfg.rlcBearerCfg[lcIdx].lcId;
270 dlRrcMsgInfo->execDup = false;
271 dlRrcMsgInfo->deliveryStaRpt = deliveryStaReq;
272 dlRrcMsgInfo->rrcMsg = rrcMsg;
273 dlRrcMsgInfo->msgLen = rrcMsgLen;
275 /* Filling post structure and sending msg */
276 memset(&pst, 0, sizeof(Pst));
277 FILL_PST_DUAPP_TO_RLC(pst, RLC_DL_INST, EVENT_DL_RRC_MSG_TRANS_TO_RLC);
278 ret = (*duSendDlRrcMsgToRlcOpts[pst.selector])(&pst, dlRrcMsgInfo);
281 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rrcMsg, rrcMsgLen);
282 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, dlRrcMsgInfo, sizeof(RlcDlRrcMsgInfo));
289 /*******************************************************************
291 * @brief Process UE context setup request from CU
295 * Function : procUeCintextSetupReq
297 * Functionality: Process UE context setup request from CU
299 * @params[in] F1AP message
300 * @return ROK - success
303 * ****************************************************************/
304 uint8_t procUeContextSetupReq(F1AP_PDU_t *f1apMsg)
307 uint8_t ieIdx, byteIdx, ueIdx;
308 uint8_t *rrcMsg = NULLP;
310 uint16_t cellId, cellIdx;
311 uint32_t gnbDuUeF1apId; /* GNB DU UE F1AP ID */
312 uint32_t gnbCuUeF1apId; /* GNB CU UE F1AP ID */
313 bool deliveryStaReq = false; /* RRC msg delivery status request */
314 DuUeCb *ueCb = NULLP;
315 UEContextSetupRequest_t *ueSetReq = NULLP;
317 ueSetReq = &f1apMsg->choice.initiatingMessage->value.choice.UEContextSetupRequest;
319 /* TODO : fetch remaining values from f1ap msg */
320 for(ieIdx=0; ieIdx < ueSetReq->protocolIEs.list.count; ieIdx++)
322 switch(ueSetReq->protocolIEs.list.array[ieIdx]->id)
324 case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
326 gnbCuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_CU_UE_F1AP_ID;
329 case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
331 gnbDuUeF1apId = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.GNB_DU_UE_F1AP_ID;
334 case ProtocolIE_ID_id_ServCellIndex:
336 cellIdx = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.ServCellIndex;
339 case ProtocolIE_ID_id_RRCContainer:
341 rrcMsgLen = ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.size;
342 DU_ALLOC_SHRABL_BUF(rrcMsg, rrcMsgLen);
345 DU_LOG("\nDU APP : Memory allocation failed for RRC Msg in procUeCtxtSetupReq");
348 memcpy(rrcMsg, ueSetReq->protocolIEs.list.array[ieIdx]->value.choice.RRCContainer.buf,\
352 case ProtocolIE_ID_id_RRCDeliveryStatusRequest:
354 deliveryStaReq = true;
364 cellId = duCb.actvCellLst[cellIdx]->cellId;
365 for(ueIdx = 0; ueIdx < MAX_NUM_UE; ueIdx++)
367 if((duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbCuUeF1apId == gnbCuUeF1apId) &&
368 (duCb.actvCellLst[cellIdx]->ueCb[ueIdx].gnbDuUeF1apId == gnbDuUeF1apId &&
369 duCb.actvCellLst[cellIdx]->ueCb[ueIdx].ueState == UE_ACTIVE))
371 ueCb = &duCb.actvCellLst[cellIdx]->ueCb[ueIdx];
376 /* TODO : send RB config to MAC/RLC */
378 /* Sending DL RRC Message to RLC */
379 if(ueIdx != MAX_NUM_UE)
381 ret = duBuildAndSendDlRrcMsgToRlc(cellId, ueCb->rlcUeCfg, SRB_ID_1, \
382 deliveryStaReq, rrcMsgLen, rrcMsg);
386 DU_LOG("\nDU APP : No UE found for CuUeF1apId[%d] and DuUeF1apId[%d]", \
387 gnbCuUeF1apId, gnbDuUeF1apId);
388 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rrcMsg, rrcMsgLen);
395 /******************************************************************
397 * @brief Processes DL RRC Message Transfer sent by CU
401 * Function : procDlRrcMsgTrans
403 * Functionality: Processes DL RRC Message Transfer sent by CU
405 * @params[in] F1AP_PDU_t ASN decoded F1AP message
406 * @return ROK - success
409 * ****************************************************************/
410 uint8_t procDlRrcMsgTrans(F1AP_PDU_t *f1apMsg)
412 DLRRCMessageTransfer_t *dlRrcMsg = NULLP;
413 uint8_t *dlCcchMsg = NULLP;
414 uint8_t idx, ret, srbId;
415 uint16_t idx2, crnti, cellId, dlCcchMsgSize;
416 uint32_t gnbCuUeF1apId, gnbDuUeF1apId;
419 DU_LOG("\nDU_APP : DL RRC message transfer Recevied");
420 dlRrcMsg = &f1apMsg->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
424 for(idx=0; idx<dlRrcMsg->protocolIEs.list.count; idx++)
426 switch(dlRrcMsg->protocolIEs.list.array[idx]->id)
428 case ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID:
430 gnbCuUeF1apId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_CU_UE_F1AP_ID;
433 case ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID:
435 gnbDuUeF1apId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.GNB_DU_UE_F1AP_ID;
438 case ProtocolIE_ID_id_SRBID:
440 srbId = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.SRBID;
443 case ProtocolIE_ID_id_ExecuteDuplication:
446 case ProtocolIE_ID_id_RRCContainer:
448 if(dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size > 0)
450 dlCcchMsgSize = dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size;
451 DU_ALLOC(dlCcchMsg, dlCcchMsgSize);
452 for(idx2 = 0; idx2 < dlCcchMsgSize; idx2++)
455 dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.buf[idx2];
460 DU_LOG("\nDU_APP : RRC Container Size is invalid:%ld",\
461 dlRrcMsg->protocolIEs.list.array[idx]->value.choice.RRCContainer.size);
467 DU_LOG("\nDU_APP : Invalid IE received in DL RRC Msg Transfer:%ld",
468 dlRrcMsg->protocolIEs.list.array[idx]->id);
472 for(idx=0; idx<duCb.numUe; idx++)
474 if(gnbDuUeF1apId == duCb.ueCcchCtxt[idx].gnbDuUeF1apId)
476 crnti = duCb.ueCcchCtxt[idx].crnti;
477 cellId = duCb.ueCcchCtxt[idx].cellId;
481 if(srbId == SRB_ID_1) //RRC connection setup
483 ret = duBuildAndSendDlCcchInd(&cellId, &crnti, RRC_SETUP, dlCcchMsg, dlCcchMsgSize);
486 DU_LOG("\nDU_APP: Falied at duBuildAndSendDlCcchInd()");
490 if(duCb.actvCellLst[cellId-1]->numActvUes < MAX_NUM_UE)
492 ret = duCreateUeCb(&duCb.ueCcchCtxt[idx], gnbCuUeF1apId);
495 DU_LOG("\nDU_APP: Failed at duCreateUeCb for cellId [%d]", duCb.ueCcchCtxt[idx].cellId);
501 DU_LOG("\nDU_APP: Max Active UEs has reached");
509 /******************************************************************
511 * @brief Generates GNB DU Ue F1AP ID
515 * Function : genGnbDuUeF1apId
517 * Functionality: Generates GNB DU Ue F1AP ID
520 * @return gnbDuF1apId
522 * ****************************************************************/
523 uint32_t genGnbDuUeF1apId()
525 static uint32_t gnbDuUeF1apId = 0;
527 return ++gnbDuUeF1apId;
530 /******************************************************************
532 * @brief Processes UL CCCH Ind recvd from MAC
536 * Function : duProcUlCcchInd
538 * Functionality: Processes UL CCCH Ind recvd from MAC
540 * @params[in] UlCcchIndInfo *ulCcchIndInfo
541 * @return ROK - success
544 * ****************************************************************/
545 uint8_t duProcUlCcchInd(UlCcchIndInfo *ulCcchIndInfo)
549 uint32_t gnbDuUeF1apId = 0;
551 gnbDuUeF1apId = genGnbDuUeF1apId();
553 /* Store Ue mapping */
554 duCb.ueCcchCtxt[duCb.numUe].gnbDuUeF1apId = gnbDuUeF1apId;
555 duCb.ueCcchCtxt[duCb.numUe].crnti = ulCcchIndInfo->crnti;
556 duCb.ueCcchCtxt[duCb.numUe].cellId = ulCcchIndInfo->cellId;
560 ret = (BuildAndSendInitialRrcMsgTransfer(gnbDuUeF1apId, ulCcchIndInfo->crnti, ulCcchIndInfo->ulCcchMsgLen,
561 ulCcchIndInfo->ulCcchMsg));
564 DU_LOG("\nDU_APP : BuildAndSendInitialRrcMsgTransfer failed");
567 DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo->ulCcchMsg, ulCcchIndInfo->ulCcchMsgLen);
568 DU_FREE_SHRABL_BUF(MAC_MEM_REGION, MAC_POOL, ulCcchIndInfo, sizeof(UlCcchIndInfo));
574 /******************************************************************
576 * @brief Fills Initial DL Bandwidth Part
580 * Function : fillInitDlBwp
582 * Functionality: Fills Initial DL Bandwidth Part
585 *****************************************************************/
586 void fillInitDlBwp(InitialDlBwp *initDlBwp)
589 uint8_t freqDomainResource[FREQ_DOM_RSRC_SIZE] = {0};
590 uint8_t coreset0EndPrb, coreset1StartPrb, coreset1NumPrb;
595 /* Filling PDCCH Config */
596 initDlBwp->pdcchPresent = TRUE;
597 if(initDlBwp->pdcchPresent)
599 initDlBwp->pdcchCfg.numCRsetToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
600 memset(initDlBwp->pdcchCfg.cRSetToAddModList, 0, MAX_NUM_CRSET);
601 if(initDlBwp->pdcchCfg.numCRsetToAddMod <= MAX_NUM_CRSET)
603 initDlBwp->pdcchCfg.cRSetToAddModList[idx].cRSetId = \
604 PDCCH_CTRL_RSRC_SET_ONE_ID;
605 memset(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, 0,\
607 coreset0EndPrb = CORESET0_END_PRB;
608 coreset1StartPrb = coreset0EndPrb +6;
609 coreset1NumPrb = CORESET1_NUM_PRB;
610 /* calculate the PRBs */
611 schAllocFreqDomRscType0(((coreset1StartPrb)/6), (coreset1NumPrb/6), freqDomainResource);
612 memcpy(initDlBwp->pdcchCfg.cRSetToAddModList[idx].freqDomainRsrc, freqDomainResource,
615 initDlBwp->pdcchCfg.cRSetToAddModList[idx].duration = \
616 PDCCH_CTRL_RSRC_SET_ONE_DURATION;
617 initDlBwp->pdcchCfg.cRSetToAddModList[idx].cceRegMappingType = \
618 CCE_REG_MAPPINGTYPE_PR_NONINTERLEAVED;
619 initDlBwp->pdcchCfg.cRSetToAddModList[idx].precoderGranularity = \
621 initDlBwp->pdcchCfg.cRSetToAddModList[idx].dmrsScramblingId = \
624 initDlBwp->pdcchCfg.numCRsetToRel = 0;
625 /* Filling Serach Space */
626 initDlBwp->pdcchCfg.numSearchSpcToAddMod = PDCCH_CTRL_RSRC_SET_ONE_ID;
627 memset(initDlBwp->pdcchCfg.searchSpcToAddModList, 0, MAX_NUM_CRSET);
628 if(initDlBwp->pdcchCfg.numSearchSpcToAddMod <= MAX_NUM_CRSET)
630 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceId =\
631 PDCCH_SRCH_SPC_TWO_ID;
632 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].cRSetId = \
633 PDCCH_CTRL_RSRC_SET_ONE_ID;
634 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].\
635 mSlotPeriodicityAndOffset = SLOTPERIODICITYANDOFFSET_PR_SL1;
636 memset(initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot, 0,\
637 MONITORING_SYMB_WITHIN_SLOT_SIZE);
638 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].mSymbolsWithinSlot[idx] =\
639 PDCCH_SYMBOL_WITHIN_SLOT;
640 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel1 =\
642 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel2 =\
644 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel4 =\
646 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel8 =\
648 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].numCandidatesAggLevel16 =\
650 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].searchSpaceType = \
651 SEARCHSPACETYPE_PR_UE_SPECIFIC;
652 initDlBwp->pdcchCfg.searchSpcToAddModList[idx].ueSpecificDciFormat =\
653 PDCCH_SRCH_SPC_TWO_UE_SPEC_DCI_FORMAT;
655 initDlBwp->pdcchCfg.numSearchSpcToRel = 0;
659 /* Filling PDSCH Config */
660 initDlBwp->pdschPresent = TRUE;
661 if(initDlBwp->pdschPresent)
663 initDlBwp->pdschCfg.dmrsDlCfgForPdschMapTypeA.addPos = ADDITIONALPOSITION_POS0;
664 initDlBwp->pdschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
665 initDlBwp->pdschCfg.numTimeDomRsrcAlloc = 1;
666 initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].mappingType = \
668 initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbol = PDSCH_START_SYMBOL;
669 initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].symbolLength = PDSCH_LENGTH_SYMBOL;
670 initDlBwp->pdschCfg.timeDomRsrcAllociList[idx].startSymbolAndLength = \
671 calcSliv(PDSCH_START_SYMBOL, PDSCH_LENGTH_SYMBOL);
672 initDlBwp->pdschCfg.rbgSize = RBG_SIZE_CONFIG1;
673 initDlBwp->pdschCfg.numCodeWordsSchByDci = CODEWORDS_SCHED_BY_DCI_N1;
674 initDlBwp->pdschCfg.bundlingType = TYPE_STATIC_BUNDLING;
680 /******************************************************************
682 * @brief Fills Initial UL Bandwidth Part
686 * Function : fillInitUlBwp
688 * Functionality: Fills Initial UL Bandwidth Part
691 *****************************************************************/
692 void fillInitUlBwp(InitialUlBwp *initUlBwp)
697 initUlBwp->pucchPresent = FALSE;
699 /*Filling PUSCH Config */
700 initUlBwp->puschPresent = TRUE;
701 if(initUlBwp->puschPresent)
703 initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.addPos = ADDITIONALPOSITION_POS0;
704 initUlBwp->puschCfg.dmrsUlCfgForPuschMapTypeA.transPrecodDisabled. \
705 scramblingId0 = SCRAMBLING_ID;
706 initUlBwp->puschCfg.resourceAllocType = RESOURCEALLOCATION_TYPE1;
707 initUlBwp->puschCfg.numTimeDomRsrcAlloc = 1;
709 if(initUlBwp->puschCfg.numTimeDomRsrcAlloc <= MAX_NUM_UL_ALLOC)
711 initUlBwp->puschCfg.timeDomRsrcAllocList[idx].k2 = PUSCH_K2;
712 initUlBwp->puschCfg.timeDomRsrcAllocList[idx].mappingType =\
714 initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbol = PUSCH_START_SYMBOL;
715 initUlBwp->puschCfg.timeDomRsrcAllocList[idx].symbolLength = PUSCH_LENGTH_SYMBOL;
716 initUlBwp->puschCfg.timeDomRsrcAllocList[idx].startSymbolAndLength =\
717 calcSliv(PUSCH_START_SYMBOL, PUSCH_LENGTH_SYMBOL);
719 initUlBwp->puschCfg.transformPrecoder = TRANSFORM_PRECODER_DISABLED;
724 DU_LOG("\n DUAPP: Memory is NULL of InitalUlBwp");
728 /******************************************************************
730 * @brief Fills SpCell Group Info
734 * Function : fillSpCellGrpInfo
736 * Functionality: Fills Sp Cell Group Info
739 *****************************************************************/
740 void fillSpCellGrpInfo(SpCellCfg *spCell)
744 spCell->servCellIdx = SERV_CELL_IDX;
745 /* Filling Initial Dl Bwp */
746 fillInitDlBwp(&spCell->servCellCfg.initDlBwp);
748 spCell->servCellCfg.numDlBwpToAdd = 0;
749 spCell->servCellCfg.firstActvDlBwpId = ACTIVE_DL_BWP_ID;
750 spCell->servCellCfg.defaultDlBwpId = ACTIVE_DL_BWP_ID;
751 spCell->servCellCfg.bwpInactivityTmr = NULLP;
752 spCell->servCellCfg.pdschServCellCfg.maxMimoLayers = NULLP;
753 spCell->servCellCfg.pdschServCellCfg.maxCodeBlkGrpPerTb = NULLP;
754 spCell->servCellCfg.pdschServCellCfg.codeBlkGrpFlushInd = NULLP;
755 spCell->servCellCfg.pdschServCellCfg.xOverhead = NULLP;
756 spCell->servCellCfg.pdschServCellCfg.numHarqProcForPdsch =\
757 NUM_HARQ_PROC_FOR_PDSCH_N_16;
758 /* Filling Initial UL Bwp*/
759 fillInitUlBwp(&spCell->servCellCfg.initUlBwp);
760 spCell->servCellCfg.numUlBwpToAdd = 0;
761 spCell->servCellCfg.firstActvUlBwpId = ACTIVE_DL_BWP_ID;
765 DU_LOG("\n DU_APP: Memory is NULL for SpCellGrp");
769 /******************************************************************
771 * @brief Fills Physical Cell Group Info
775 * Function : fillPhyCellGrpInfo
777 * Functionality: Fills Physical Cell Group Info
780 *****************************************************************/
781 void fillPhyCellGrpInfo(PhyCellGrpCfg *cellGrp)
785 cellGrp->pdschHarqAckCodebook = PDSCH_HARQ_ACK_CODEBOOK_DYNAMIC;
786 cellGrp->pNrFr1 = P_NR_FR1;
790 DU_LOG("\nDUAPP: Memory is NULL for Physical Cell Group");
794 /******************************************************************
796 * @brief Fills Mac Cell Group Info
800 * Function : fillMacCellGrpInfo
802 * Functionality: Fills Mac Cell Group Info
805 *****************************************************************/
806 void fillMacCellGrpInfo(MacCellGrpCfg *cellGrp)
812 /* Filling Scheduling Request Config */
813 cellGrp->schReqCfg.addModListCount = 1;
814 if(cellGrp->schReqCfg.addModListCount <= MAX_NUM_SR_CFG_PER_CELL_GRP)
816 for(idx = 0; idx < cellGrp->schReqCfg.addModListCount; idx++)
818 cellGrp->schReqCfg.addModList[idx].schedReqId = SCH_REQ_ID;
819 cellGrp->schReqCfg.addModList[idx].srProhibitTmr = SR_PROHIBIT_MS_32;
820 cellGrp->schReqCfg.addModList[idx].srTransMax = SR_TRANS_MAX_N_16;
823 cellGrp->schReqCfg.relListCount = 0;
825 /* Filling Tag config */
826 cellGrp->tagCfg.addModListCount = 1;
827 if(cellGrp->tagCfg.addModListCount <= MAC_NUM_TAGS)
829 for(idx = 0; idx < cellGrp->tagCfg.addModListCount; idx++)
831 cellGrp->tagCfg.addModList[idx].tagId = TAG_ID;
832 cellGrp->tagCfg.addModList[idx].timeAlignTimer = TIME_ALIGNMENT_TIMER_INFINITY;
835 cellGrp->tagCfg.relListCount = 0;
837 /* Filling BSR config */
838 cellGrp->bsrTmrCfg.periodicTimer = PERIODIC_BSR_TMR;
839 cellGrp->bsrTmrCfg.retxTimer = RETX_BSR_TMR;
840 cellGrp->bsrTmrCfg.srDelayTimer = SR_DELAY_TMR;
842 /* Filling PHR config */
843 cellGrp->phrCfgSetupPres = true;
844 cellGrp->phrCfg.periodicTimer = PHR_PERIODIC_TIMER_INFINITY;
845 cellGrp->phrCfg.prohibitTimer = PHR_PROHIBIT_TIMER_SF_0;
846 cellGrp->phrCfg.txPowerFactor = PHR_TX_PWR_FACTOR_CHANGE_INFINITY;
847 cellGrp->phrCfg.multiplePHR = false;
848 cellGrp->phrCfg.dummy = false;
849 cellGrp->phrCfg.phrType2OtherCell = false;
850 cellGrp->phrCfg.phrOtherCG = PHR_MODE_OTHER_CG_REAL;
855 DU_LOG("\nDUAPP: Memory is NULL for Master Cell Group");
859 /******************************************************************
861 * @brief Fills Logical Channel Config List
865 * Function : fillLcCfgList
867 * Functionality: Fills Logical channel Config List
870 *****************************************************************/
871 void fillLcCfgList(LcCfg *lcCfgInfo)
875 lcCfgInfo->lcId = SRB_ID_1;
876 lcCfgInfo->drbQos = NULLP;
877 lcCfgInfo->snssai = NULLP;
878 lcCfgInfo->ulLcCfg = NULLP;
879 lcCfgInfo->dlLcCfg.lcp = LC_PRIORITY_1;
882 /* TODO: To be filled on receving UE CONTEXT SETUP from CU */
883 /* Filling Qos characteristics */
884 lcCfgInfo->drbQos.fiveQiType = QoS_Characteristics_PR_non_Dynamic_5QI;
885 lcCfgInfo->drbQos.u.nonDyn5Qi.fiveQi = 0;
886 lcCfgInfo->drbQos.u.nonDyn5Qi.priorLevel = 0;
887 lcCfgInfo->drbQos.u.nonDyn5Qi.avgWindow = 0;
888 lcCfgInfo->drbQos.u.nonDyn5Qi.maxDataBurstVol = 0;
891 lcCfgInfo->drbQos.ngRanRetPri.priorityLevel = PriorityLevel_highest;
892 lcCfgInfo->drbQos.ngRanRetPri.preEmptionCap = \
893 Pre_emptionCapability_may_trigger_pre_emption;
894 lcCfgInfo->drbQos.ngRanRetPri.preEmptionVul = \
895 Pre_emptionVulnerability_not_pre_emptable;
897 /* Filling Grb Qos */
898 lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateDl = 0;
899 lcCfgInfo->drbQos.grbQosInfo.maxFlowBitRateUl = 0;
900 lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateDl = 0;
901 lcCfgInfo->drbQos.grbQosInfo.guarFlowBitRateUl = 0;
903 /* Filling S-NSSAI */
904 /* TODO :To be filled when UE Context Setup Request is sent from CU */
905 /* Filling UL Logical Channel Config */
906 lcCfgInfo->ulLcCfg.priority = 0;
907 lcCfgInfo->ulLcCfg.lcGroup = 0;
908 lcCfgInfo->ulLcCfg.schReqId = 0;
909 lcCfgInfo->ulLcCfg.pbr = 0;
910 lcCfgInfo->ulLcCfg.bsd = 0;
912 /* Filling DL Logical Channel Config */
913 lcCfgInfo->dlLcCfg.lcp = 0;
918 DU_LOG("\n Memory is null for LcCfgList");
922 /******************************************************************
924 * @brief Fills MacUeCfg structure
928 * Function : fillMacUeCfg
930 * Functionality: Fills MacUeCfg
933 *****************************************************************/
934 void fillMacUeCfg(uint16_t cellId, uint8_t ueIdx,\
935 uint16_t crnti, MacUeCfg *ueCfg)
938 ueCfg->cellId = cellId;
939 ueCfg->ueIdx = ueIdx;
940 ueCfg->crnti = crnti;
941 /* Filling MacCellGroup Config */
942 fillMacCellGrpInfo(&ueCfg->macCellGrpCfg);
943 /* Filling PhyCellGroup Config */
944 fillPhyCellGrpInfo(&ueCfg->phyCellGrpCfg);
945 /* Filling SpCellGroup Config */
946 fillSpCellGrpInfo(&ueCfg->spCellCfg);
947 /* Filling AMBR for UL and DL */
948 ueCfg->maxAggrBitRate = NULLP;
949 /* Filling LC Context */
950 ueCfg->numLcs = SRB_ID_1;
951 if(ueCfg->numLcs < MAX_NUM_LOGICAL_CHANNELS)
953 for(idx = 0; idx < ueCfg->numLcs; idx++)
955 fillLcCfgList(&ueCfg->lcCfgList[idx]);
961 /******************************************************************
963 * @brief Fills Rlc AM Information
967 * Function : fillAmInfo
969 * Functionality: Fills Rlc AM Information
972 *****************************************************************/
973 void fillAmInfo(AmBearerCfg *amCfg)
976 amCfg->dlAmCfg.snLenDl = AM_SIZE_12;
977 amCfg->dlAmCfg.pollRetxTmr = POLL_RETX_TMR_45MS;
978 amCfg->dlAmCfg.pollPdu = POLL_PDU_TMR_INFINITY;
979 amCfg->dlAmCfg.pollByte = POLL_BYTES_INFINITY;
980 amCfg->dlAmCfg.maxRetxTh = RETX_TH_8;
983 amCfg->ulAmCfg.snLenUl = AM_SIZE_12;
984 amCfg->ulAmCfg.reAssemTmr = RE_ASM_40MS;
985 amCfg->ulAmCfg.statProhTmr = PROH_35MS;
989 /******************************************************************
991 * @brief Fills RLC UM Bi Directional Information
995 * Function : fillUmBiDirInfo
997 * Functionality: Fills RLC UM Bi Directional Information
1000 *****************************************************************/
1001 void fillUmBiDirInfo(UmBiDirBearerCfg *umBiDirCfg)
1003 /* UL UM BI DIR INFO */
1004 umBiDirCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1005 umBiDirCfg->ulUmCfg.reAssemTmr = RE_ASM_40MS;
1007 /* DL UM BI DIR INFO */
1008 umBiDirCfg->dlUmCfg.snLenDlUm = UM_SIZE_12;
1012 /******************************************************************
1014 * @brief Fills RLC UM Uni Directional UL Information
1018 * Function : fillUmUniDirUlInfo
1020 * Functionality: Fills RLC UM Uni Directional Info
1023 *****************************************************************/
1024 void fillUmUniDirUlInfo(UmUniDirUlBearerCfg *umUniDirUlCfg)
1026 umUniDirUlCfg->ulUmCfg.snLenUlUm = UM_SIZE_12;
1027 umUniDirUlCfg->ulUmCfg.reAssemTmr = RE_ASM_40MS;
1030 /******************************************************************
1032 * @brief Fills RLC UM Uni Directional DL Information
1036 * Function : fillUmUniDirDlInfo
1038 * Functionality: Fills RLC UM Uni Directional DL Info
1041 *****************************************************************/
1042 void fillUmUniDirDlInfo(UmUniDirDlBearerCfg *umUniDirDlCfg)
1044 umUniDirDlCfg->dlUmCfg.snLenDlUm = UM_SIZE_12;
1047 /******************************************************************
1049 * @brief Fills RlcBearerCfg structure
1053 * Function : fillRlcBearerCfg
1055 * Functionality: Fills Rlc Bearer Cfg
1058 *****************************************************************/
1059 void fillRlcBearerCfg(uint16_t cellId, uint8_t ueIdx, RlcUeCfg *ueCfg)
1062 ueCfg->cellId = cellId;
1063 ueCfg->ueIdx = ueIdx;
1064 ueCfg->numLcs = SRB_ID_1;
1066 for(idx = 0; idx < ueCfg->numLcs; idx++)
1068 ueCfg->rlcBearerCfg[idx].rbId = RB_ID_SRB;
1069 ueCfg->rlcBearerCfg[idx].rbType = RB_TYPE_SRB;
1070 ueCfg->rlcBearerCfg[idx].lcId = SRB_ID_1;
1071 ueCfg->rlcBearerCfg[idx].lcType = LCH_DCCH;
1072 ueCfg->rlcBearerCfg[idx].rlcMode = RLC_AM;
1073 switch(ueCfg->rlcBearerCfg[idx].rlcMode)
1076 memset(&ueCfg->rlcBearerCfg[idx].u.amCfg, 0, sizeof(AmBearerCfg));
1077 fillAmInfo(&ueCfg->rlcBearerCfg[idx].u.amCfg);
1079 case RLC_UM_BI_DIRECTIONAL:
1080 memset(&ueCfg->rlcBearerCfg[idx].u.umBiDirCfg, 0, sizeof(UmBiDirBearerCfg));
1081 fillUmBiDirInfo(&ueCfg->rlcBearerCfg[idx].u.umBiDirCfg);
1083 case RLC_UM_UNI_DIRECTIONAL_UL:
1084 memset(&ueCfg->rlcBearerCfg[idx].u.umUniDirUlCfg, 0, sizeof(UmUniDirUlBearerCfg));
1085 fillUmUniDirUlInfo(&ueCfg->rlcBearerCfg[idx].u.umUniDirUlCfg);
1087 case RLC_UM_UNI_DIRECTIONAL_DL:
1088 memset(&ueCfg->rlcBearerCfg[idx].u.umUniDirDlCfg, 0, sizeof(UmUniDirDlBearerCfg));
1089 fillUmUniDirDlInfo(&ueCfg->rlcBearerCfg[idx].u.umUniDirDlCfg);
1092 DU_LOG("\nDU_APP: Rlc Mode invalid %d", ueCfg->rlcBearerCfg[idx].rlcMode);
1098 /******************************************************************
1100 * @brief creates UE context
1104 * Function : duCreateUeCb
1106 * Functionality: Creates UE Conetxt
1108 * @params[in] UeCcchCtxt Pointer
1111 * @return ROK - success
1113 * ****************************************************************/
1114 uint8_t duCreateUeCb(UeCcchCtxt *ueCcchCtxt, uint32_t gnbCuUeF1apId)
1116 uint8_t cellIdx = 0;
1120 for(cellIdx = 0; cellIdx < MAX_NUM_CELL; cellIdx++)
1122 if(ueCcchCtxt->cellId == duCb.actvCellLst[cellIdx]->cellId)
1124 GET_UE_IDX(ueCcchCtxt->crnti, ueIdx);
1125 DU_LOG("\nDU_APP: Filling UeCb for ueIdx [%d]", ueIdx);
1127 duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbDuUeF1apId = ueCcchCtxt->gnbDuUeF1apId;
1128 duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].gnbCuUeF1apId = gnbCuUeF1apId;
1129 duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].ueState = UE_ACTIVE;
1131 /* Filling Mac Ue Config */
1132 memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg, 0, sizeof(MacUeCfg));
1133 ret = duBuildAndSendUeCreateReqToMac(ueCcchCtxt->cellId, ueIdx, ueCcchCtxt->crnti,\
1134 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].macUeCfg);
1136 DU_LOG("\nDU_APP: Failed to send UE create request to MAC");
1138 /* Filling Rlc Ue Config */
1139 memset(&duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg, 0, sizeof(RlcUeCfg));
1140 ret = duBuildAndSendUeCreateReqToRlc(ueCcchCtxt->cellId, ueIdx, \
1141 &duCb.actvCellLst[cellIdx]->ueCb[ueIdx-1].rlcUeCfg);
1143 DU_LOG("\nDU_APP: Failed to send UE create request to RLC");
1145 duCb.actvCellLst[cellIdx]->numActvUes++;
1146 memset(ueCcchCtxt, 0, sizeof(UeCcchCtxt));
1152 /******************************************************************
1154 * @brief Builds and Send UE Create Request to MAC
1158 * Function : duBuildAndSendUeCreateReqToMac
1160 * Functionality: Builds and Send UE Create Request to MAC
1162 * @Params[in] cellId,
1164 * @return ROK - success
1167 * ****************************************************************/
1169 uint8_t duBuildAndSendUeCreateReqToMac(uint16_t cellId, uint8_t ueIdx,\
1170 uint16_t crnti, MacUeCfg *duMacUeCfg)
1173 MacUeCfg *macUeCfg = NULLP;
1175 memset(&pst, 0, sizeof(Pst));
1177 fillMacUeCfg(cellId, ueIdx, crnti, duMacUeCfg);
1180 FILL_PST_DUAPP_TO_MAC(pst, EVENT_MAC_UE_CREATE_REQ);
1182 /* Copying ueCb to a sharable buffer */
1183 DU_ALLOC_SHRABL_BUF(macUeCfg, sizeof(MacUeCfg));
1186 memset(macUeCfg, 0, sizeof(MacUeCfg));
1187 memcpy(macUeCfg, &duCb.actvCellLst[cellId - 1]->ueCb[ueIdx -1].macUeCfg, sizeof(MacUeCfg));
1188 DU_LOG("\nDU_APP: Sending UE create request to MAC");
1190 /* Processing one Ue at a time to MAC */
1191 ret = (*packMacUeCreateReqOpts[pst.selector])(&pst, macUeCfg);
1194 DU_LOG("\nDU_APP : Failure in sending Ue Create Req to MAC");
1195 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, macUeCfg, sizeof(MacUeCfg));
1201 DU_LOG("\n DU_APP: Memory alloc failed at duBuildAndSendUeCreateReqToMac()");
1207 /*******************************************************************
1209 * @brief Handle UE create response from MAC
1213 * Function : DuHandleMacUeCreateRsp
1215 * Functionality: Handle UE create response from MAC
1217 * @params[in] Pointer to MacUeCfgRsp and Pst
1218 * @return ROK - success
1221 * ****************************************************************/
1222 uint8_t DuHandleMacUeCreateRsp(Pst *pst, MacUeCfgRsp *cfgRsp)
1224 if(cfgRsp->result == MAC_DU_APP_RSP_OK)
1226 DU_LOG("\nDU APP : MAC UE Create Response : SUCCESS [UE IDX : %d]", cfgRsp->ueIdx);
1230 DU_LOG("\nDU APP : MAC UE Create Response : FAILURE [UE IDX : %d]", cfgRsp->ueIdx);
1235 /*******************************************************************
1237 * @brief Processes UE create Req to RLC UL
1241 * Function : duBuildAndSendUeCreateReqToRlc
1244 * Processes UE create Req to RLC UL
1246 * @params[in] cellId,
1248 * Pointer to RlcUeCfg
1249 * @return ROK - success
1252 *****************************************************************/
1254 uint8_t duBuildAndSendUeCreateReqToRlc(uint16_t cellId, uint8_t ueIdx, RlcUeCfg *duRlcUeCfg)
1257 RlcUeCfg *rlcUeCfg = NULLP;
1259 memset(&pst, 0, sizeof(Pst));
1261 fillRlcBearerCfg(cellId, ueIdx, duRlcUeCfg);
1262 FILL_PST_DUAPP_TO_RLC(pst, RLC_UL_INST, EVENT_RLC_UL_UE_CREATE_REQ);
1264 /* Copying ueCfg to a sharable buffer */
1265 DU_ALLOC_SHRABL_BUF(rlcUeCfg, sizeof(RlcUeCfg));
1268 memset(rlcUeCfg, 0, sizeof(RlcUeCfg));
1269 memcpy(rlcUeCfg, duRlcUeCfg, sizeof(RlcUeCfg));
1270 /* Processing one Ue at a time to RLC */
1271 DU_LOG("\nDU_APP: Sending UE create request to RLC UL");
1272 ret = (*packRlcUlUeCreateReqOpts[pst.selector])(&pst, rlcUeCfg);
1275 DU_LOG("\nDU_APP : Failure in sending Ue Create Req to RLC");
1276 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, rlcUeCfg, sizeof(RlcUeCfg));
1282 DU_LOG("\n DU_APP: Memory alloc failed at duBuildAndSendUeCreateReqToRlc()");
1290 /*******************************************************************
1292 * @brief Processes UE create Rsp received from RLC UL
1296 * Function : DuProcRlcUlUeCfgRsp
1299 * Processes UE create Rsp received from RLC UL
1301 * @params[in] Post structure
1302 * Pointer to RlcCfgCfm
1303 * @return ROK - success
1306 *****************************************************************/
1308 uint8_t DuProcRlcUlUeCreateRsp(Pst *pst, RlcUeCfgRsp *cfgRsp)
1314 if(cfgRsp->result == RLC_DU_APP_RSP_OK)
1316 DU_LOG("\nDU_APP: RLC UE Create Response : SUCCESS [UE IDX:%d]", cfgRsp->ueIdx);
1320 DU_LOG("\nDU_APP: RLC UE Create Response : FAILED [UE IDX:%d, REASON :%d]",\
1321 cfgRsp->ueIdx, cfgRsp->reason);
1324 DU_FREE_SHRABL_BUF(DU_APP_MEM_REGION, DU_POOL, cfgRsp, sizeof(RlcUeCfgRsp));
1328 DU_LOG("\nDU_APP: Received RLC Ue Create Response is NULL");
1333 /**********************************************************************
1335 ***********************************************************************/