L1-L2 Integration fixes.[Issue-ID: ODUHIGH-252]
[o-du/l2.git] / src / du_app / du_cfg.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
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                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
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
19 /* This file contains all utility functions */
20 #include "common_def.h"
21 #include "legtp.h"
22 #include "lrg.h"
23 #include "lkw.x"
24 #include "lrg.x"
25 #include "du_app_mac_inf.h"
26 #include "du_app_rlc_inf.h"
27 #include "du_cfg.h"
28 #include "du_mgr.h"
29 #include "du_utils.h"
30 #include "OCTET_STRING.h"
31 #include "BIT_STRING.h"
32 #include "odu_common_codec.h"
33 #include "du_sys_info_hdl.h"
34 #include "MIB.h"
35 #include "SearchSpace.h"
36 #include "SIB-TypeInfo.h"
37 #include "SchedulingInfo.h"
38 #include "SI-SchedulingInfo.h"
39 #include "ConnEstFailureControl.h"
40 #include "PLMN-IdentityInfo.h"
41 #include "PDSCH-TimeDomainResourceAllocation.h"
42 #include "BCCH-Config.h"
43 #include "PagingCycle.h"
44 #include "PCCH-Config.h"
45 #include "TimeAlignmentTimer.h"
46 #include "RACH-ConfigGeneric.h"
47 #include "PUSCH-TimeDomainResourceAllocation.h"
48 #include "PUCCH-ConfigCommon.h"
49 #include "SubcarrierSpacing.h"
50 #include "TDD-UL-DL-Pattern.h"
51 #include "RACH-ConfigCommon.h"
52 #include "BWP-DownlinkCommon.h"
53 #include "BWP-UplinkCommon.h"
54
55 DuCfgParams duCfgParam;
56 char encBuf[ENC_BUF_MAX_LEN];
57
58
59 /* Filling Slot configuration as :
60  * 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
61  *   0   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
62  *   1   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
63  *   2   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
64  *   3   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    GD    GD    GD    UL
65  *   4   UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL
66  */
67
68 /*******************************************************************
69  *
70  * @brief Fills the Slot configuration 
71  *
72  * @details
73  *
74  *    Function : FillSlotConfig
75  *
76  *    Functionality:Fill the Slot configuration values
77  * 
78  *  @params[in] void
79  * @return ROK     - success
80  *         RFAILED - failure
81  *
82  * ****************************************************************/
83 void FillSlotConfig()
84 {
85    uint8_t slot;
86    uint8_t symbol;
87
88    for(slot = 0; slot <= 3; slot++)
89    {
90       for(symbol = 0; symbol < MAX_SYMB_PER_SLOT; symbol++)
91          duCfgParam.macCellCfg.tddCfg.slotCfg[slot][symbol] = DL_SLOT;
92    }
93
94    duCfgParam.macCellCfg.tddCfg.slotCfg[3][10] = GUARD_SLOT;
95    duCfgParam.macCellCfg.tddCfg.slotCfg[3][11] = GUARD_SLOT;
96    duCfgParam.macCellCfg.tddCfg.slotCfg[3][12] = GUARD_SLOT;
97    duCfgParam.macCellCfg.tddCfg.slotCfg[3][13] = UL_SLOT;
98
99    for(symbol = 0; symbol < MAX_SYMB_PER_SLOT; symbol++)
100       duCfgParam.macCellCfg.tddCfg.slotCfg[4][symbol] = UL_SLOT;
101
102 }
103
104 /*******************************************************************
105  *
106  * @brief Reads the CL Configuration.
107  *
108  * @details
109  *
110  *    Function : readMacCfg
111  *
112  *    Functionality:
113  *       - Fills up the cell configuration for CL.
114  *       - Calls FillSlotConfig()  
115  *
116  * @params[in] void
117  * @return ROK     - success
118  *         RFAILED - failure
119  *
120  * ****************************************************************/
121
122
123 /* This function is used to fill up the cell configuration for CL */
124 uint8_t readMacCfg()
125 {
126    duCfgParam.macCellCfg.carrierId = CARRIER_IDX;
127
128    /* Cell configuration */
129    duCfgParam.macCellCfg.cellId = NR_CELL_ID;
130    duCfgParam.macCellCfg.phyCellId = NR_PCI;
131    duCfgParam.macCellCfg.dupType = DUPLEX_MODE;
132
133    /* DL carrier configuration */
134    duCfgParam.macCellCfg.dlCarrCfg.pres = TRUE;
135    duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH;
136    duCfgParam.macCellCfg.dlCarrCfg.freq = NR_DL_ARFCN;
137    duCfgParam.macCellCfg.dlCarrCfg.k0[0] = 1;
138    duCfgParam.macCellCfg.dlCarrCfg.k0[1] = 1;
139    duCfgParam.macCellCfg.dlCarrCfg.k0[2] = 1;
140    duCfgParam.macCellCfg.dlCarrCfg.k0[3] = 1;
141    duCfgParam.macCellCfg.dlCarrCfg.k0[4] = 1;
142    duCfgParam.macCellCfg.dlCarrCfg.gridSize[0] = 273;
143    duCfgParam.macCellCfg.dlCarrCfg.gridSize[1] = 1;
144    duCfgParam.macCellCfg.dlCarrCfg.gridSize[2] = 1;
145    duCfgParam.macCellCfg.dlCarrCfg.gridSize[3] = 1;
146    duCfgParam.macCellCfg.dlCarrCfg.gridSize[4] = 1;
147    duCfgParam.macCellCfg.dlCarrCfg.numAnt = NUM_TX_ANT;
148
149    /* UL Carrier configuration */
150    duCfgParam.macCellCfg.ulCarrCfg.pres = TRUE;
151    duCfgParam.macCellCfg.ulCarrCfg.bw = BANDWIDTH;
152    duCfgParam.macCellCfg.ulCarrCfg.freq = NR_UL_ARFCN;
153    duCfgParam.macCellCfg.ulCarrCfg.k0[0] = 1;
154    duCfgParam.macCellCfg.ulCarrCfg.k0[1] = 1;
155    duCfgParam.macCellCfg.ulCarrCfg.k0[2] = 1;
156    duCfgParam.macCellCfg.ulCarrCfg.k0[3] = 1;
157    duCfgParam.macCellCfg.ulCarrCfg.k0[4] = 1;
158    duCfgParam.macCellCfg.ulCarrCfg.gridSize[0] = 1;
159    duCfgParam.macCellCfg.ulCarrCfg.gridSize[1] = 1;
160    duCfgParam.macCellCfg.ulCarrCfg.gridSize[2] = 1;
161    duCfgParam.macCellCfg.ulCarrCfg.gridSize[3] = 1;
162    duCfgParam.macCellCfg.ulCarrCfg.gridSize[4] = 1;
163    duCfgParam.macCellCfg.ulCarrCfg.numAnt = NUM_RX_ANT;
164
165    duCfgParam.macCellCfg.freqShft = FREQ_SHIFT_7P5KHZ;
166
167    /* SSB configuration */
168    duCfgParam.macCellCfg.ssbCfg.ssbPbchPwr = SSB_PBCH_PWR;
169    duCfgParam.macCellCfg.ssbCfg.bchPayloadFlag = BCH_PAYLOAD;
170    duCfgParam.macCellCfg.ssbCfg.scsCmn = SUBCARRIER_SPACING;
171    duCfgParam.macCellCfg.ssbCfg.ssbOffsetPointA = OFFSET_TO_POINT_A;
172    duCfgParam.macCellCfg.ssbCfg.betaPss = BETA_PSS;
173    duCfgParam.macCellCfg.ssbCfg.ssbPeriod = SSB_PRDCTY_MS_20;
174    duCfgParam.macCellCfg.ssbCfg.ssbScOffset = SSB_SUBCARRIER_OFFSET;
175    duCfgParam.macCellCfg.ssbCfg.ssbMask[0] = 1; /* only one SSB is transmitted */
176    duCfgParam.macCellCfg.ssbCfg.ssbMask[1] = 0;
177    if(BuildMibPdu() != ROK)
178    {
179       DU_LOG("\nFailed to build MIB PDU");
180       memset(&duCfgParam.macCellCfg.ssbCfg.mibPdu, 0, 3*sizeof(uint8_t));
181    }
182    else
183    {
184       for(uint8_t idx=0; idx<encBufSize; idx++)
185       {
186          duCfgParam.macCellCfg.ssbCfg.mibPdu[idx]=encBuf[idx];
187       }
188    }
189    duCfgParam.macCellCfg.ssbCfg.multCarrBand = SSB_MULT_CARRIER_BAND;
190    duCfgParam.macCellCfg.ssbCfg.multCellCarr = MULT_CELL_CARRIER;
191
192    /* PRACH configuration */
193    duCfgParam.macCellCfg.prachCfg.pres = TRUE;
194    duCfgParam.macCellCfg.prachCfg.prachCfgIdx = PRACH_CONFIG_IDX;
195    duCfgParam.macCellCfg.prachCfg.prachSeqLen = PRACH_SEQ_LEN;
196    duCfgParam.macCellCfg.prachCfg.prachSubcSpacing = PRACH_SUBCARRIER_SPACING;
197    duCfgParam.macCellCfg.prachCfg.prachRstSetCfg = PRACH_RESTRICTED_SET_CFG;
198    duCfgParam.macCellCfg.prachCfg.msg1Fdm = NUM_PRACH_FDM;
199    duCfgParam.macCellCfg.prachCfg.msg1FreqStart = PRACH_FREQ_START;
200    duCfgParam.macCellCfg.prachCfg.rootSeqLen    = ROOT_SEQ_LEN;
201    duCfgParam.macCellCfg.prachCfg.fdm[0].rootSeqIdx = ROOT_SEQ_IDX;
202    duCfgParam.macCellCfg.prachCfg.fdm[0].numRootSeq = NUM_ROOT_SEQ;
203    duCfgParam.macCellCfg.prachCfg.fdm[0].k1 = 0;
204    duCfgParam.macCellCfg.prachCfg.fdm[0].zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG;
205    duCfgParam.macCellCfg.prachCfg.fdm[0].numUnusedRootSeq = NUM_UNUSED_ROOT_SEQ;
206    if(duCfgParam.macCellCfg.prachCfg.fdm[0].numUnusedRootSeq != 0)
207    {
208         DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq, 
209         NUM_UNUSED_ROOT_SEQ * sizeof(uint8_t));
210         if(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq == NULLP)
211         {
212             DU_LOG("\nDU_APP : Memory allocation failed");
213             return RFAILED;
214         }
215         *(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq) = UNUSED_ROOT_SEQ;
216     }
217    duCfgParam.macCellCfg.prachCfg.ssbPerRach = SSB_PER_RACH;
218    duCfgParam.macCellCfg.prachCfg.prachMultCarrBand = PRACH_MULT_CARRIER_BAND;
219    duCfgParam.macCellCfg.prachCfg.raContResTmr = RA_CONT_RES_TIMER;
220    duCfgParam.macCellCfg.prachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB;
221    duCfgParam.macCellCfg.prachCfg.raRspWindow = RA_RSP_WINDOW;
222    duCfgParam.macCellCfg.prachCfg.prachRestrictedSet = PRACH_RESTRICTED_SET;
223    /* TDD configuration */
224    duCfgParam.macCellCfg.tddCfg.pres = TRUE;
225    duCfgParam.macCellCfg.tddCfg.tddPeriod = TDD_PERIODICITY;
226
227    FillSlotConfig();
228
229    /* RSSI Measurement configuration */
230    duCfgParam.macCellCfg.rssiUnit = RSS_MEASUREMENT_UNIT;
231
232    /* fill SIB1 configuration */
233    duCfgParam.macCellCfg.sib1Cfg.sib1PduLen = duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
234    DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu,duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
235    memcpy(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu, duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg, \
236          duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
237    duCfgParam.macCellCfg.sib1Cfg.sib1NewTxPeriod = SIB1_NEW_TX_PERIOD;
238    duCfgParam.macCellCfg.sib1Cfg.sib1RepetitionPeriod = SIB1_REPETITION_PERIOD;
239    duCfgParam.macCellCfg.sib1Cfg.coresetZeroIndex = CORESET_0_INDEX;
240    duCfgParam.macCellCfg.sib1Cfg.searchSpaceZeroIndex = SEARCHSPACE_0_INDEX;
241    duCfgParam.macCellCfg.sib1Cfg.sib1Mcs = SIB1_MCS;
242
243
244    /* fill Intial DL BWP */
245    duCfgParam.macCellCfg.initialDlBwp.bwp.firstPrb = 0;
246    duCfgParam.macCellCfg.initialDlBwp.bwp.numPrb = TOTAL_PRB_BW; /* configured to total BW */
247    duCfgParam.macCellCfg.initialDlBwp.bwp.scs = SUBCARRIER_SPACING; /* numerology is 0, 15Khz */
248    duCfgParam.macCellCfg.initialDlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
249    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId = SEARCHSPACE_1_INDEX;
250    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.coresetId = CORESET_0_INDEX;
251    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
252       SS_MONITORING_SLOT_SL1; /* sl1 - all slots */
253    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.duration = 0;
254    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
255       SS_MONITORING_SYMBOL;
256    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
257       candidate.aggLevel1       = 8;
258    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
259       candidate.aggLevel2       = 4;
260    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
261       candidate.aggLevel4       = 2;
262    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
263       candidate.aggLevel8       = 1;
264    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
265       candidate.aggLevel16      = 0;
266    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.k0 = PDSCH_K0;
267    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.mappingType = 
268       PDSCH_MAPPING_TYPE_A;
269    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.startSymbol = 
270       PDSCH_START_SYMBOL;
271    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.lengthSymbol =
272       PDSCH_LENGTH_SYMBOL;
273    /* ra-searchSpace ID is set to 1 */
274    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.raSearchSpaceId = SEARCHSPACE_1_INDEX;
275
276    /* fill Intial UL BWP */
277    duCfgParam.macCellCfg.initialUlBwp.bwp.firstPrb = 0;
278    duCfgParam.macCellCfg.initialUlBwp.bwp.numPrb = TOTAL_PRB_BW; /* configured to total BW */
279    duCfgParam.macCellCfg.initialUlBwp.bwp.scs = SUBCARRIER_SPACING; /* numerology is 0, 15Khz */
280    duCfgParam.macCellCfg.initialUlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
281    duCfgParam.macCellCfg.initialUlBwp.puschCommon.k2 = PUSCH_K2;
282    duCfgParam.macCellCfg.initialUlBwp.puschCommon.mappingType = 
283       PUSCH_MAPPING_TYPE_A;
284    duCfgParam.macCellCfg.initialUlBwp.puschCommon.startSymbol = 
285       PUSCH_START_SYMBOL;
286    duCfgParam.macCellCfg.initialUlBwp.puschCommon.lengthSymbol =
287       PUSCH_LENGTH_SYMBOL;
288
289    duCfgParam.macCellCfg.dmrsTypeAPos = DMRS_TYPE_A_POS; 
290    /* fill PUCCH config common */
291    duCfgParam.macCellCfg.initialUlBwp.pucchCommon.pucchResourceCommon = PUCCH_RSRC_COMMON;
292    duCfgParam.macCellCfg.initialUlBwp.pucchCommon.pucchGroupHopping = PUCCH_GROUP_HOPPING;
293
294    return ROK;
295 }
296
297 /*******************************************************************
298  *
299  * @brief Configures the DU Parameters
300  *
301  * @details
302  *
303  *    Function : fillDuPort
304  *
305  *    Functionality:
306  *       - fills the DU Ports.  
307  *
308  * @params[in] duPort array to be filled
309  * @return ROK     - success
310  *         RFAILED - failure
311  *
312  * ****************************************************************/
313 uint8_t fillDuPort(uint16_t *duPort)
314 {
315    duPort[F1_INTERFACE]   = DU_PORT;     /* DU Port idx  0 38472 */
316    duPort[E2_INTERFACE]   = RIC_PORT;    /* RIC Port idx 1 38482 */
317
318    return ROK;
319 }
320
321 /*******************************************************************
322  *
323  * @brief Configures the DU Parameters
324  *
325  * @details
326  *
327  *    Function : calcSliv
328  *
329  *    Functionality:
330  *       - calculate SLIV value from start and length field
331  *
332  * @params[in] start symbol
333  * @params[in] length of symbols
334  * @return SLIV value
335  *
336  * ****************************************************************/
337 uint16_t calcSliv(uint8_t startSymbol, uint8_t lengthSymbol)
338 {
339    uint16_t sliv = 0;
340    if((lengthSymbol-1) <= 7)
341    {
342       sliv = NUM_SYMBOLS_PER_SLOT * (lengthSymbol-1) + startSymbol;
343    }
344    else
345    {
346       sliv = NUM_SYMBOLS_PER_SLOT * (NUM_SYMBOLS_PER_SLOT - lengthSymbol + 1) \
347              + (NUM_SYMBOLS_PER_SLOT - 1 - startSymbol);
348    }
349    return sliv;
350 }
351
352
353 /*******************************************************************
354  *
355  * @brief Configures serving cell config common in sib1
356  *
357  * @details
358  *
359  *    Function : fillServCellCfgCommSib
360  *
361  *    Functionality:
362  *       - fills Serving cell config common for SIB1
363  *
364  * @params[in] SrvCellCfgCommSib pointer
365  * @return ROK     - success
366  *         RFAILED - failure
367  * 
368  ** ****************************************************************/
369 uint8_t fillServCellCfgCommSib(SrvCellCfgCommSib *srvCellCfgComm)
370 {
371    PdcchCfgCommon   pdcchCfg;
372    PdschCfgCommon   pdschCfg;
373    PcchCfg          pcchCfg;
374    RachCfgCommon    rachCfg;
375    PuschCfgCommon   puschCfg;
376    PucchCfgCommon   pucchCfg;
377    TddUlDlCfgCommon   tddCfg;
378
379    /* Configuring DL Config Common for SIB1*/
380    srvCellCfgComm->dlCfg.freqBandInd = NR_FREQ_BAND_IND; 
381    srvCellCfgComm->dlCfg.offsetToPointA = OFFSET_TO_POINT_A;
382    srvCellCfgComm->dlCfg.dlScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
383    srvCellCfgComm->dlCfg.dlScsCarrier.scs = SUBCARRIER_SPACING;
384    srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = SCS_CARRIER_BANDWIDTH;
385    srvCellCfgComm->dlCfg.locAndBw = FREQ_LOC_BW;
386
387    /* Configuring PDCCH Config Common For SIB1 */
388    pdcchCfg.present = BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup;
389    pdcchCfg.ctrlRsrcSetZero = PDCCH_CTRL_RSRC_SET_ZERO;
390    pdcchCfg.searchSpcZero = PDCCH_SEARCH_SPACE_ZERO;
391    pdcchCfg.searchSpcId = PDCCH_SEARCH_SPACE_ID;
392    pdcchCfg.ctrlRsrcSetId = PDCCH_CTRL_RSRC_SET_ID;
393    pdcchCfg.monitorSlotPrdAndOffPresent = \
394       SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
395    //pdcchCfg.monitorSlotPrdAndOff = \
396    SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
397    pdcchCfg.monitorSymbolsInSlot[0] = 128;
398    pdcchCfg.monitorSymbolsInSlot[1] = 0;
399    pdcchCfg.numCandAggLvl1 = SearchSpace__nrofCandidates__aggregationLevel1_n8;
400    pdcchCfg.numCandAggLvl2 = SearchSpace__nrofCandidates__aggregationLevel2_n4;
401    pdcchCfg.numCandAggLvl4 = SearchSpace__nrofCandidates__aggregationLevel4_n2;
402    pdcchCfg.numCandAggLvl8 = SearchSpace__nrofCandidates__aggregationLevel8_n1;
403    pdcchCfg.numCandAggLvl16 = SearchSpace__nrofCandidates__aggregationLevel16_n0;
404    pdcchCfg.searchSpcType = SearchSpace__searchSpaceType_PR_common;
405    pdcchCfg.commSrchSpcDciFrmt = PDCCH_SERACH_SPACE_DCI_FORMAT;
406    pdcchCfg.searchSpcSib1 = PDCCH_SEARCH_SPACE_ID_SIB1;
407    pdcchCfg.pagingSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
408    pdcchCfg.raSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
409    srvCellCfgComm->dlCfg.pdcchCfg = pdcchCfg;
410
411    /* Configuring PDSCH Config Common For SIB1 */
412    pdschCfg.present = BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup;
413    pdschCfg.k0 = PDSCH_K0;
414    pdschCfg.mapType = \
415       PDSCH_TimeDomainResourceAllocation__mappingType_typeA;
416    pdschCfg.sliv = calcSliv(PDSCH_START_SYMBOL,PDSCH_LENGTH_SYMBOL);
417    srvCellCfgComm->dlCfg.pdschCfg = pdschCfg;
418
419    /* Configuring BCCH Config for SIB1 */
420    srvCellCfgComm->dlCfg.bcchCfg.modPrdCoeff = \
421       BCCH_Config__modificationPeriodCoeff_n16;
422
423    /* Configuring PCCH Config for SIB1 */
424    pcchCfg.dfltPagingCycle = PagingCycle_rf64;
425    pcchCfg.nAndPagingFrmOffPresent = PCCH_Config__nAndPagingFrameOffset_PR_oneT;
426    pcchCfg.numPagingOcc = PCCH_Config__ns_four;
427    srvCellCfgComm->dlCfg.pcchCfg = pcchCfg;
428
429
430    /* Configuring UL Config Common */
431    srvCellCfgComm->ulCfg.ulScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
432    srvCellCfgComm->ulCfg.ulScsCarrier.scs = SUBCARRIER_SPACING;
433    srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = SCS_CARRIER_BANDWIDTH;
434    srvCellCfgComm->ulCfg.pMax = UL_P_MAX;
435    srvCellCfgComm->ulCfg.locAndBw = FREQ_LOC_BW;
436    srvCellCfgComm->ulCfg.timeAlignTimerComm = TimeAlignmentTimer_infinity;
437
438    /* Configuring RACH Config Common for SIB1 */
439    rachCfg.present = BWP_UplinkCommon__rach_ConfigCommon_PR_setup;
440    rachCfg.prachCfgIdx = PRACH_CONFIG_IDX;
441    rachCfg.msg1Fdm = RACH_ConfigGeneric__msg1_FDM_one;
442    rachCfg.msg1FreqStart = PRACH_FREQ_START;
443    rachCfg.zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG;
444    rachCfg.preambleRcvdTgtPwr = PRACH_PREAMBLE_RCVD_TGT_PWR;
445    rachCfg.preambleTransMax = RACH_ConfigGeneric__preambleTransMax_n200;
446    rachCfg.pwrRampingStep = RACH_ConfigGeneric__powerRampingStep_dB2;
447    rachCfg.raRspWindow = RACH_ConfigGeneric__ra_ResponseWindow_sl20;
448    rachCfg.numRaPreamble = NUM_RA_PREAMBLE;
449    rachCfg.ssbPerRachOccPresent = \
450       RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_one;
451    rachCfg.numSsbPerRachOcc = SSB_PER_RACH;
452    rachCfg.contResTimer = RACH_ConfigCommon__ra_ContentionResolutionTimer_sf64;
453    rachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB;
454    rachCfg.rootSeqIdxPresent = RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139;
455    rachCfg.rootSeqIdx = ROOT_SEQ_IDX;
456    rachCfg.msg1Scs = PRACH_SUBCARRIER_SPACING ;
457    rachCfg.restrictedSetCfg = PRACH_RESTRICTED_SET_CFG;
458    srvCellCfgComm->ulCfg.rachCfg = rachCfg;
459
460    /* Configuring PUSCH Config Common for SIB1 */
461    puschCfg.present = BWP_UplinkCommon__pusch_ConfigCommon_PR_setup;
462    puschCfg.k2 = PUSCH_K2;
463    puschCfg.mapType = PUSCH_TimeDomainResourceAllocation__mappingType_typeA;
464    puschCfg.sliv = calcSliv(PUSCH_START_SYMBOL,PUSCH_LENGTH_SYMBOL);
465    puschCfg.msg3DeltaPreamble = PUSCH_MSG3_DELTA_PREAMBLE;
466    puschCfg.p0NominalWithGrant = PUSCH_P0_NOMINAL_WITH_GRANT;
467    srvCellCfgComm->ulCfg.puschCfg = puschCfg;
468
469    /* Configuring PUCCH Config Common for SIB1 */
470    pucchCfg.present = BWP_UplinkCommon__pucch_ConfigCommon_PR_setup;
471    pucchCfg.rsrcComm = PUCCH_RSRC_COMMON;
472    pucchCfg.grpHop = PUCCH_ConfigCommon__pucch_GroupHopping_neither;
473    pucchCfg.p0Nominal = PUCCH_P0_NOMINAL;
474    srvCellCfgComm->ulCfg.pucchCfg = pucchCfg;
475
476    /* Configuring TDD UL DL config common */
477    tddCfg.refScs = SubcarrierSpacing_kHz30;
478    tddCfg.txPrd = TDD_UL_DL_Pattern__dl_UL_TransmissionPeriodicity_ms2p5;
479    tddCfg.numDlSlots = NUM_DL_SLOTS;
480    tddCfg.numDlSymbols = NUM_DL_SYMBOLS;
481    tddCfg.numUlSlots = NUM_UL_SLOTS;
482    tddCfg.numUlSymbols = NUM_UL_SYMBOLS;
483    srvCellCfgComm->tddCfg = tddCfg;
484
485    srvCellCfgComm->ssbPosInBurst = 192;
486    srvCellCfgComm->ssbPrdServingCell = SSB_PERIODICITY_20MS;
487    srvCellCfgComm->ssPbchBlockPwr = SSB_PBCH_PWR;
488
489    return ROK;
490 }
491
492 /*******************************************************************
493  *
494  * @brief Configures the DU Parameters
495  *
496  * @details
497  *
498  *    Function : readCfg
499  *
500  *    Functionality:
501  *       - Initializes the DuCfg members.  
502  *       - Calls readMacCfg()  
503  *
504  * @params[in] system task ID
505  * @return ROK     - success
506  *         RFAILED - failure
507  *
508  * ****************************************************************/
509
510 uint8_t readCfg()
511 {
512    uint8_t i,j,k;
513    uint32_t ipv4_du, ipv4_cu, ipv4_ric;
514    MibParams mib;
515    Sib1Params sib1;     
516
517    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
518    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
519    cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
520    fillDuPort(duCfgParam.sctpParams.duPort);
521
522    /* F1 DU IP Address and Port*/
523    duCfgParam.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
524
525    /* F1 CU IP Address and Port*/
526    duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
527    duCfgParam.sctpParams.cuPort = CU_PORT;
528
529    /* Fill RIC Params */
530    duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
531    duCfgParam.sctpParams.ricPort            = RIC_PORT;
532    /* EGTP Parameters */
533    duCfgParam.egtpParams.localIp.ipV4Pres = TRUE;
534    duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du;
535    duCfgParam.egtpParams.localPort = DU_EGTP_PORT;
536    duCfgParam.egtpParams.destIp.ipV4Pres = TRUE;
537    duCfgParam.egtpParams.destIp.ipV4Addr = ipv4_cu;
538    duCfgParam.egtpParams.destPort = CU_EGTP_PORT;
539    duCfgParam.egtpParams.minTunnelId = 0;
540    duCfgParam.egtpParams.maxTunnelId = 10;
541
542    duCfgParam.maxUe = 32; //TODO: Check
543    /* DU Info */        
544    duCfgParam.duId = DU_ID;     
545    strcpy((char*)duCfgParam.duName,DU_NAME);
546
547    /* Mib Params */
548    mib.sysFrmNum = SYS_FRAME_NUM;
549    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs15or60;
550    mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; 
551    mib.dmrs_TypeA_Position = MIB__dmrs_TypeA_Position_pos2;
552    mib.controlResourceSetZero = CORESET_ZERO;
553    mib.searchSpaceZero = SEARCH_SPACE_ZERO;
554    mib.cellBarred = MIB__cellBarred_barred;
555    mib.intraFreqReselection =
556       MIB__intraFreqReselection_notAllowed;
557    duCfgParam.mibParams = mib;
558
559    /* SIB1 Params */
560    memset(&sib1.plmn, 0, sizeof(Plmn));
561    sib1.plmn.mcc[0] = PLMN_MCC0;
562    sib1.plmn.mcc[1] = PLMN_MCC1;
563    sib1.plmn.mcc[2] = PLMN_MCC2;
564    sib1.plmn.mnc[0] = PLMN_MNC0;
565    sib1.plmn.mnc[1] = PLMN_MNC1;
566    sib1.tac = DU_TAC;
567    sib1.ranac = DU_RANAC;
568    sib1.cellIdentity = CELL_IDENTITY;
569    sib1.cellResvdForOpUse =\
570       PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
571    sib1.connEstFailCnt = ConnEstFailureControl__connEstFailCount_n3;
572    sib1.connEstFailOffValidity =\
573       ConnEstFailureControl__connEstFailOffsetValidity_s120;
574    sib1.siSchedInfo.winLen = SI_SchedulingInfo__si_WindowLength_s5;
575    sib1.siSchedInfo.broadcastSta = \
576       SchedulingInfo__si_BroadcastStatus_broadcasting;
577    sib1.siSchedInfo.preiodicity = SchedulingInfo__si_Periodicity_rf8;
578    sib1.siSchedInfo.sibType = SIB_TypeInfo__type_sibType2;
579    sib1.siSchedInfo.sibValTag = SIB1_VALUE_TAG;
580
581    fillServCellCfgCommSib(&sib1.srvCellCfgCommSib);
582
583    duCfgParam.sib1Params = sib1;
584
585    for(i=0; i<DEFAULT_CELLS; i++)
586    { 
587       memset(&duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn, 0, sizeof(Plmn));
588       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mcc[0] = PLMN_MCC0;
589       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mcc[1] = PLMN_MCC1;
590       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mcc[2] = PLMN_MCC2;
591       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mnc[0] = PLMN_MNC0;
592       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mnc[1] = PLMN_MNC1;
593
594       /*Cell ID */
595       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.cellId = NR_CELL_ID;
596       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrPci = NR_PCI;
597
598       /* List of Available PLMN */
599       for(j=0;j<MAX_PLMN;j++)
600       {
601          memset(&duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j], 0, sizeof(Plmn));
602          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mcc[0] = PLMN_MCC0;
603          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mcc[1] = PLMN_MCC1;
604          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mcc[2] = PLMN_MCC2;
605          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mnc[0] = PLMN_MNC0;
606          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mnc[1] = PLMN_MNC1;
607       }
608       /* List of Extended PLMN */
609       for(j=0;j<MAX_PLMN;j++)
610       {
611          memset(&duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j], 0, sizeof(Plmn));
612          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mcc[0] = PLMN_MCC0;
613          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mcc[1] = PLMN_MCC1;
614          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mcc[2] = PLMN_MCC2;
615          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mnc[0] = PLMN_MNC0;
616          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mnc[1] = PLMN_MNC1;
617       } 
618
619       /* TAC and EPSTAC */
620       duCfgParam.srvdCellLst[i].duCellInfo.tac = DU_TAC;
621       duCfgParam.srvdCellLst[i].duCellInfo.epsTac = DU_TAC; //to check and fill
622       /* NR Mode info */
623       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn = NR_UL_ARFCN;
624       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
625       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
626       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
627
628 #if 0
629       /* NR Mode info */
630       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn = NR_ARFCN;
631       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
632       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;           
633       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;           
634
635       for(j=0;j<MAXNRCELLBANDS;j++)
636       {
637          duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[j].nrFreqBand = NR_FREQ_BAND;
638          for(k=0;k<MAXNRCELLBANDS;k++)
639          {
640             duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[j].sulBand[k] = SUL_BAND;  
641          }
642       }
643 #endif
644       for(j=0;j<MAXNRCELLBANDS;j++)
645       {
646          duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[j].nrFreqBand = NR_FREQ_BAND;
647          for(k=0;k<MAXNRCELLBANDS;k++)
648          {
649             duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[j].sulBand[k] = SUL_BAND;
650          }
651       }
652       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.nrArfcn = NR_DL_ARFCN;
653       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
654       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
655       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
656       for(j=0;j<MAXNRCELLBANDS;j++)
657       {
658          duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[j].nrFreqBand = NR_FREQ_BAND;
659          for(k=0;k<MAXNRCELLBANDS;k++)
660          {
661             duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[j].sulBand[k] = SUL_BAND;
662          }
663       }
664
665       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrScs = SCS_15;
666       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrb = NRB_106;
667
668       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrScs = SCS_15;
669       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrb = NRB_106;
670
671 #if 0
672       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrTxBw.nrScs = SCS_15;
673       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrTxBw.nrb = NRB_106;
674 #endif
675       /*Measurement Config and Cell Config */ 
676       duCfgParam.srvdCellLst[i].duCellInfo.measTimeCfg = TIME_CFG; 
677
678       duCfgParam.srvdCellLst[i].duCellInfo.cellDir = DL_UL; 
679
680       duCfgParam.srvdCellLst[i].duCellInfo.cellType=CELL_TYPE;
681
682       /* Broadcast PLMN Identity */
683       for(j=0;j<MAXBPLMNNRMINUS1;j++)
684       { 
685          for(k=0;k<MAX_PLMN;k++)
686          {
687             memset(&duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k], 0, sizeof(Plmn));
688             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mcc[0] = PLMN_MCC0;
689             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mcc[1] = PLMN_MCC1;
690             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mcc[2] = PLMN_MCC2;
691             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mnc[0] = PLMN_MNC0;
692             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mnc[1] = PLMN_MNC1;                                         
693          }
694          /* Extended PLMN List */        
695          for(k=0;k<MAX_PLMN;k++)
696          {
697             memset(&duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k], 0, sizeof(Plmn));
698             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mcc[0] = PLMN_MCC0;
699             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mcc[1] = PLMN_MCC1;
700             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mcc[2] = PLMN_MCC2;
701             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mnc[0] = PLMN_MNC0;
702             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mnc[1] = PLMN_MNC1;
703          }
704
705          duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].tac = DU_TAC;
706          duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].nrCellId = NR_CELL_ID;
707          duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].ranac = NR_RANAC;
708       }
709
710       /*gnb DU System Info mib msg*/
711       BuildMibMsg();
712       DU_ALLOC(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg,\
713             strlen(encBuf));
714       if(!(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg))
715       {
716          DU_LOG("\nDU_APP: Memory allocation failure");
717          return RFAILED;
718       }
719       strcpy((char *)duCfgParam.srvdCellLst[i].duSysInfo.mibMsg, encBuf);
720       duCfgParam.srvdCellLst[i].duSysInfo.mibLen = encBufSize;
721
722       /*gnb DU System Info mib msg*/
723       BuildSib1Msg();
724       DU_ALLOC(duCfgParam.srvdCellLst[i].duSysInfo.sib1Msg,\
725             encBufSize);
726       if(!(duCfgParam.srvdCellLst[i].duSysInfo.sib1Msg))
727       {
728          DU_LOG("\nDU_APP: Memory allocation failure");
729          return RFAILED;
730       }
731       memcpy(duCfgParam.srvdCellLst[i].duSysInfo.sib1Msg,\
732             encBuf,encBufSize);
733       duCfgParam.srvdCellLst[i].duSysInfo.sib1Len = encBufSize;
734
735    }
736
737    if(readMacCfg() != ROK)
738    {
739       DU_LOG("\nDU_APP : Failed while reading MAC config");
740       return RFAILED;
741    }
742
743    return ROK;
744 }
745
746 /*******************************************************************
747  *
748  * @brief Reads config and posts message to du_app on completion
749  *
750  * @details
751  *
752  *    Function : main
753  *
754  *    Functionality:
755  *      - Calls readCfg()
756  *      - Post to du_app for further processing
757  *
758  * @params[in] void
759  * @return ROK     - success
760  *         RFAILED - failure
761  *
762  * ****************************************************************/
763 uint8_t duReadCfg()
764 {
765    Pst pst;
766    Buffer *mBuf;
767
768    memset(&duCfgParam, 0, sizeof(DuCfgParams));
769    //Read configs into duCfgParams
770    if(readCfg() != ROK)
771    {
772       DU_LOG("\nDU_APP : Reading configuration failed");
773       return RFAILED;
774    }
775
776    //Fill pst structure
777    memset(&(pst), 0, sizeof(Pst));
778    pst.srcEnt = (Ent)ENTDUAPP;
779    pst.srcInst = (Inst)DU_INST;
780    pst.srcProcId = DU_PROC;
781    pst.dstEnt = pst.srcEnt;
782    pst.dstInst = pst.srcInst;
783    pst.dstProcId = pst.srcProcId;
784    pst.event = EVTCFG;
785    pst.selector = ODU_SELECTOR_TC;
786    pst.pool= DU_POOL;
787
788
789    if(ODU_GET_MSG_BUF(DFLT_REGION, DU_POOL, &mBuf) != ROK)
790    {
791       DU_LOG("\nDU_APP : Memory allocation failed in duReadCfg");
792       return RFAILED;
793    }
794
795    if (ODU_POST_TASK(&pst, mBuf) != ROK)
796    {
797       DU_LOG("\nDU_APP : ODU_POST_TASK failed in duReadCfg");
798       return RFAILED;
799    }
800
801    return ROK;
802 }
803
804 /**********************************************************************
805   End of file
806  **********************************************************************/
807