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