/******************************************************************************* ################################################################################ # Copyright (c) [2017-2019] [Radisys] # # # # Licensed under the Apache License, Version 2.0 (the "License"); # # you may not use this file except in compliance with the License. # # You may obtain a copy of the License at # # # # http://www.apache.org/licenses/LICENSE-2.0 # # # # Unless required by applicable law or agreed to in writing, software # # distributed under the License is distributed on an "AS IS" BASIS, # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # # limitations under the License. # ################################################################################ *******************************************************************************/ /* This file contains all utility functions */ #include "common_def.h" #include "legtp.h" #include "lrg.h" #include "lkw.x" #include "lrg.x" #include "du_app_mac_inf.h" #include "du_app_rlc_inf.h" #include "du_cfg.h" #include "du_mgr.h" #include "du_utils.h" #include "OCTET_STRING.h" #include "BIT_STRING.h" #include "odu_common_codec.h" #include "du_sys_info_hdl.h" #include "MIB.h" #include "SearchSpace.h" #include "SIB-TypeInfo.h" #include "SchedulingInfo.h" #include "SI-SchedulingInfo.h" #include "ConnEstFailureControl.h" #include "PLMN-IdentityInfo.h" #include "PDSCH-TimeDomainResourceAllocation.h" #include "BCCH-Config.h" #include "PagingCycle.h" #include "PCCH-Config.h" #include "TimeAlignmentTimer.h" #include "RACH-ConfigGeneric.h" #include "PUSCH-TimeDomainResourceAllocation.h" #include "PUCCH-ConfigCommon.h" #include "SubcarrierSpacing.h" #include "TDD-UL-DL-Pattern.h" #include "RACH-ConfigCommon.h" #include "BWP-DownlinkCommon.h" #include "BWP-UplinkCommon.h" extern DuCfgParams duCfgParam; extern char encBuf[ENC_BUF_MAX_LEN]; /* Filling Slot configuration as : * Slot Sym 0 Sym 1 Sym 2 Sym 3 Sym 4 Sym 5 Sym 6 Sym 7 Sym 8 Sym 9 Sym10 Sym11 Sym12 Sym13 * 0 DL DL DL DL DL DL DL DL DL DL DL DL DL DL * 1 DL DL DL DL DL DL DL DL DL DL DL DL DL DL * 2 DL DL DL DL DL DL DL DL DL DL DL DL DL DL * 3 DL DL DL DL DL DL DL DL DL DL GD GD GD UL * 4 UL UL UL UL UL UL UL UL UL UL UL UL UL UL */ /******************************************************************* * * @brief Fills the Slot configuration * * @details * * Function : FillSlotConfig * * Functionality:Fill the Slot configuration values * * @params[in] void * @return ROK - success * RFAILED - failure * * ****************************************************************/ void FillSlotConfig() { uint8_t slot; uint8_t symbol; for(slot = 0; slot <= 3; slot++) { for(symbol = 0; symbol < MAX_SYMB_PER_SLOT; symbol++) duCfgParam.macCellCfg.tddCfg.slotCfg[slot][symbol] = DL_SLOT; } duCfgParam.macCellCfg.tddCfg.slotCfg[3][10] = GUARD_SLOT; duCfgParam.macCellCfg.tddCfg.slotCfg[3][11] = GUARD_SLOT; duCfgParam.macCellCfg.tddCfg.slotCfg[3][12] = GUARD_SLOT; duCfgParam.macCellCfg.tddCfg.slotCfg[3][13] = UL_SLOT; for(symbol = 0; symbol < MAX_SYMB_PER_SLOT; symbol++) duCfgParam.macCellCfg.tddCfg.slotCfg[4][symbol] = UL_SLOT; } /******************************************************************* * * @brief Reads the CL Configuration. * * @details * * Function : readMacCfg * * Functionality: * - Fills up the cell configuration for CL. * - Calls FillSlotConfig() * * @params[in] void * @return ROK - success * RFAILED - failure * * ****************************************************************/ /* This function is used to fill up the cell configuration for CL */ uint8_t readMacCfg() { duCfgParam.macCellCfg.carrierId = CARRIER_IDX; /* Cell configuration */ duCfgParam.macCellCfg.cellId = NR_CELL_ID; duCfgParam.macCellCfg.phyCellId = NR_PCI; duCfgParam.macCellCfg.dupType = DUPLEX_MODE; /* DL carrier configuration */ duCfgParam.macCellCfg.dlCarrCfg.pres = TRUE; duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH; duCfgParam.macCellCfg.dlCarrCfg.freq = NR_DL_ARFCN; duCfgParam.macCellCfg.dlCarrCfg.k0[0] = 1; duCfgParam.macCellCfg.dlCarrCfg.k0[1] = 1; duCfgParam.macCellCfg.dlCarrCfg.k0[2] = 1; duCfgParam.macCellCfg.dlCarrCfg.k0[3] = 1; duCfgParam.macCellCfg.dlCarrCfg.k0[4] = 1; duCfgParam.macCellCfg.dlCarrCfg.gridSize[0] = 1; duCfgParam.macCellCfg.dlCarrCfg.gridSize[1] = 1; duCfgParam.macCellCfg.dlCarrCfg.gridSize[2] = 1; duCfgParam.macCellCfg.dlCarrCfg.gridSize[3] = 1; duCfgParam.macCellCfg.dlCarrCfg.gridSize[4] = 1; duCfgParam.macCellCfg.dlCarrCfg.numAnt = NUM_TX_ANT; /* UL Carrier configuration */ duCfgParam.macCellCfg.ulCarrCfg.pres = TRUE; duCfgParam.macCellCfg.ulCarrCfg.bw = BANDWIDTH; duCfgParam.macCellCfg.ulCarrCfg.freq = NR_UL_ARFCN; duCfgParam.macCellCfg.ulCarrCfg.k0[0] = 1; duCfgParam.macCellCfg.ulCarrCfg.k0[1] = 1; duCfgParam.macCellCfg.ulCarrCfg.k0[2] = 1; duCfgParam.macCellCfg.ulCarrCfg.k0[3] = 1; duCfgParam.macCellCfg.ulCarrCfg.k0[4] = 1; duCfgParam.macCellCfg.ulCarrCfg.gridSize[0] = 1; duCfgParam.macCellCfg.ulCarrCfg.gridSize[1] = 1; duCfgParam.macCellCfg.ulCarrCfg.gridSize[2] = 1; duCfgParam.macCellCfg.ulCarrCfg.gridSize[3] = 1; duCfgParam.macCellCfg.ulCarrCfg.gridSize[4] = 1; duCfgParam.macCellCfg.ulCarrCfg.numAnt = NUM_RX_ANT; duCfgParam.macCellCfg.freqShft = FREQ_SHIFT_7P5KHZ; /* SSB configuration */ duCfgParam.macCellCfg.ssbCfg.ssbPbchPwr = SSB_PBCH_PWR; duCfgParam.macCellCfg.ssbCfg.bchPayloadFlag = BCH_PAYLOAD; duCfgParam.macCellCfg.ssbCfg.scsCmn = SUBCARRIER_SPACING; duCfgParam.macCellCfg.ssbCfg.ssbOffsetPointA = OFFSET_TO_POINT_A; duCfgParam.macCellCfg.ssbCfg.betaPss = BETA_PSS; duCfgParam.macCellCfg.ssbCfg.ssbPeriod = SSB_PERIODICITY_20MS; duCfgParam.macCellCfg.ssbCfg.ssbScOffset = SSB_SUBCARRIER_OFFSET; duCfgParam.macCellCfg.ssbCfg.ssbMask[0] = 1; /* only one SSB is transmitted */ duCfgParam.macCellCfg.ssbCfg.ssbMask[1] = 0; if(BuildMibPdu() != ROK) { DU_LOG("\nFailed to build MIB PDU"); memset(&duCfgParam.macCellCfg.ssbCfg.mibPdu, 0, 3*sizeof(uint8_t)); } else { for(uint8_t idx=0; idxdlCfg.freqBandInd = NR_FREQ_BAND_IND; srvCellCfgComm->dlCfg.offsetToPointA = OFFSET_TO_POINT_A; srvCellCfgComm->dlCfg.dlScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET; srvCellCfgComm->dlCfg.dlScsCarrier.scs = SUBCARRIER_SPACING; srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = SCS_CARRIER_BANDWIDTH; srvCellCfgComm->dlCfg.locAndBw = FREQ_LOC_BW; /* Configuring PDCCH Config Common For SIB1 */ pdcchCfg.present = BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup; pdcchCfg.ctrlRsrcSetZero = PDCCH_CTRL_RSRC_SET_ZERO; pdcchCfg.searchSpcZero = PDCCH_SEARCH_SPACE_ZERO; pdcchCfg.searchSpcId = PDCCH_SEARCH_SPACE_ID; pdcchCfg.ctrlRsrcSetId = PDCCH_CTRL_RSRC_SET_ID; pdcchCfg.monitorSlotPrdAndOffPresent = \ SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1; //pdcchCfg.monitorSlotPrdAndOff = \ SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1; pdcchCfg.monitorSymbolsInSlot[0] = 128; pdcchCfg.monitorSymbolsInSlot[1] = 0; pdcchCfg.numCandAggLvl1 = SearchSpace__nrofCandidates__aggregationLevel1_n8; pdcchCfg.numCandAggLvl2 = SearchSpace__nrofCandidates__aggregationLevel2_n4; pdcchCfg.numCandAggLvl4 = SearchSpace__nrofCandidates__aggregationLevel4_n2; pdcchCfg.numCandAggLvl8 = SearchSpace__nrofCandidates__aggregationLevel8_n1; pdcchCfg.numCandAggLvl16 = SearchSpace__nrofCandidates__aggregationLevel16_n0; pdcchCfg.searchSpcType = SearchSpace__searchSpaceType_PR_common; pdcchCfg.commSrchSpcDciFrmt = PDCCH_SERACH_SPACE_DCI_FORMAT; pdcchCfg.searchSpcSib1 = PDCCH_SEARCH_SPACE_ID_SIB1; pdcchCfg.pagingSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING; pdcchCfg.raSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING; srvCellCfgComm->dlCfg.pdcchCfg = pdcchCfg; /* Configuring PDSCH Config Common For SIB1 */ pdschCfg.present = BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup; pdschCfg.k0 = PDSCH_K0; pdschCfg.mapType = \ PDSCH_TimeDomainResourceAllocation__mappingType_typeA; pdschCfg.sliv = calcSliv(PDSCH_START_SYMBOL,PDSCH_LENGTH_SYMBOL); srvCellCfgComm->dlCfg.pdschCfg = pdschCfg; /* Configuring BCCH Config for SIB1 */ srvCellCfgComm->dlCfg.bcchCfg.modPrdCoeff = \ BCCH_Config__modificationPeriodCoeff_n16; /* Configuring PCCH Config for SIB1 */ pcchCfg.dfltPagingCycle = PagingCycle_rf64; pcchCfg.nAndPagingFrmOffPresent = PCCH_Config__nAndPagingFrameOffset_PR_oneT; pcchCfg.numPagingOcc = PCCH_Config__ns_four; srvCellCfgComm->dlCfg.pcchCfg = pcchCfg; /* Configuring UL Config Common */ srvCellCfgComm->ulCfg.ulScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET; srvCellCfgComm->ulCfg.ulScsCarrier.scs = SUBCARRIER_SPACING; srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = SCS_CARRIER_BANDWIDTH; srvCellCfgComm->ulCfg.pMax = UL_P_MAX; srvCellCfgComm->ulCfg.locAndBw = FREQ_LOC_BW; srvCellCfgComm->ulCfg.timeAlignTimerComm = TimeAlignmentTimer_infinity; /* Configuring RACH Config Common for SIB1 */ rachCfg.present = BWP_UplinkCommon__rach_ConfigCommon_PR_setup; rachCfg.prachCfgIdx = PRACH_CONFIG_IDX; rachCfg.msg1Fdm = RACH_ConfigGeneric__msg1_FDM_one; rachCfg.msg1FreqStart = PRACH_FREQ_START; rachCfg.zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG; rachCfg.preambleRcvdTgtPwr = PRACH_PREAMBLE_RCVD_TGT_PWR; rachCfg.preambleTransMax = RACH_ConfigGeneric__preambleTransMax_n200; rachCfg.pwrRampingStep = RACH_ConfigGeneric__powerRampingStep_dB2; rachCfg.raRspWindow = RACH_ConfigGeneric__ra_ResponseWindow_sl20; rachCfg.numRaPreamble = NUM_RA_PREAMBLE; rachCfg.ssbPerRachOccPresent = \ RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_one; rachCfg.numSsbPerRachOcc = SSB_PER_RACH; rachCfg.contResTimer = RACH_ConfigCommon__ra_ContentionResolutionTimer_sf64; rachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB; rachCfg.rootSeqIdxPresent = RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139; rachCfg.rootSeqIdx = ROOT_SEQ_IDX; rachCfg.msg1Scs = PRACH_SUBCARRIER_SPACING ; rachCfg.restrictedSetCfg = PRACH_RESTRICTED_SET_CFG; srvCellCfgComm->ulCfg.rachCfg = rachCfg; /* Configuring PUSCH Config Common for SIB1 */ puschCfg.present = BWP_UplinkCommon__pusch_ConfigCommon_PR_setup; puschCfg.k2 = PUSCH_K2; puschCfg.mapType = PUSCH_TimeDomainResourceAllocation__mappingType_typeA; puschCfg.sliv = calcSliv(PUSCH_START_SYMBOL,PUSCH_LENGTH_SYMBOL); puschCfg.msg3DeltaPreamble = PUSCH_MSG3_DELTA_PREAMBLE; puschCfg.p0NominalWithGrant = PUSCH_P0_NOMINAL_WITH_GRANT; srvCellCfgComm->ulCfg.puschCfg = puschCfg; /* Configuring PUCCH Config Common for SIB1 */ pucchCfg.present = BWP_UplinkCommon__pucch_ConfigCommon_PR_setup; pucchCfg.rsrcComm = PUCCH_RSRC_COMMON; pucchCfg.grpHop = PUCCH_ConfigCommon__pucch_GroupHopping_neither; pucchCfg.p0Nominal = PUCCH_P0_NOMINAL; srvCellCfgComm->ulCfg.pucchCfg = pucchCfg; /* Configuring TDD UL DL config common */ tddCfg.refScs = SubcarrierSpacing_kHz30; tddCfg.txPrd = TDD_UL_DL_Pattern__dl_UL_TransmissionPeriodicity_ms2p5; tddCfg.numDlSlots = NUM_DL_SLOTS; tddCfg.numDlSymbols = NUM_DL_SYMBOLS; tddCfg.numUlSlots = NUM_UL_SLOTS; tddCfg.numUlSymbols = NUM_UL_SYMBOLS; srvCellCfgComm->tddCfg = tddCfg; srvCellCfgComm->ssbPosInBurst = 192; srvCellCfgComm->ssbPrdServingCell = SSB_PERIODICITY_20MS; srvCellCfgComm->ssPbchBlockPwr = SSB_PBCH_PWR; return ROK; } /******************************************************************* * * @brief Configures the DU Parameters * * @details * * Function : readCfg * * Functionality: * - Initializes the DuCfg members. * - Calls readMacCfg() * * @params[in] system task ID * @return ROK - success * RFAILED - failure * * ****************************************************************/ uint8_t readCfg() { uint8_t i,j,k; uint32_t ipv4_du, ipv4_cu, ipv4_ric; MibParams mib; Sib1Params sib1; cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du); cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu); cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric); fillDuPort(duCfgParam.sctpParams.duPort); /* F1 DU IP Address and Port*/ duCfgParam.sctpParams.duIpAddr.ipV4Addr = ipv4_du; /* F1 CU IP Address and Port*/ duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu; duCfgParam.sctpParams.cuPort = CU_PORT; /* Fill RIC Params */ duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric; duCfgParam.sctpParams.ricPort = RIC_PORT; /* EGTP Parameters */ duCfgParam.egtpParams.localIp.ipV4Pres = TRUE; duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du; duCfgParam.egtpParams.localPort = DU_EGTP_PORT; duCfgParam.egtpParams.destIp.ipV4Pres = TRUE; duCfgParam.egtpParams.destIp.ipV4Addr = ipv4_cu; duCfgParam.egtpParams.destPort = CU_EGTP_PORT; duCfgParam.egtpParams.minTunnelId = 0; duCfgParam.egtpParams.maxTunnelId = 10; duCfgParam.maxUe = 32; //TODO: Check /* DU Info */ duCfgParam.duId = DU_ID; strcpy((char*)duCfgParam.duName,DU_NAME); /* Mib Params */ mib.sysFrmNum = SYS_FRAME_NUM; mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs15or60; mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; mib.dmrs_TypeA_Position = MIB__dmrs_TypeA_Position_pos2; mib.controlResourceSetZero = CORESET_ZERO; mib.searchSpaceZero = SEARCH_SPACE_ZERO; mib.cellBarred = MIB__cellBarred_barred; mib.intraFreqReselection = MIB__intraFreqReselection_notAllowed; duCfgParam.mibParams = mib; /* SIB1 Params */ sib1.plmn.mcc[0] = PLMN_MCC0; sib1.plmn.mcc[1] = PLMN_MCC1; sib1.plmn.mcc[2] = PLMN_MCC2; sib1.plmn.mnc[0] = PLMN_MNC0; sib1.plmn.mnc[1] = PLMN_MNC1; sib1.plmn.mnc[2] = PLMN_MNC2; sib1.tac = DU_TAC; sib1.ranac = DU_RANAC; sib1.cellIdentity = CELL_IDENTITY; sib1.cellResvdForOpUse =\ PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved; sib1.connEstFailCnt = ConnEstFailureControl__connEstFailCount_n3; sib1.connEstFailOffValidity =\ ConnEstFailureControl__connEstFailOffsetValidity_s120; sib1.siSchedInfo.winLen = SI_SchedulingInfo__si_WindowLength_s5; sib1.siSchedInfo.broadcastSta = \ SchedulingInfo__si_BroadcastStatus_broadcasting; sib1.siSchedInfo.preiodicity = SchedulingInfo__si_Periodicity_rf8; sib1.siSchedInfo.sibType = SIB_TypeInfo__type_sibType2; sib1.siSchedInfo.sibValTag = SIB1_VALUE_TAG; fillServCellCfgCommSib(&sib1.srvCellCfgCommSib); duCfgParam.sib1Params = sib1; for(i=0; i