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