RARandSib1Transmission
[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
232    /* fill Intial DL BWP */
233    duCfgParam.macCellCfg.initialBwp.bwp.firstPrb = 0;
234    duCfgParam.macCellCfg.initialBwp.bwp.numPrb = TOTAL_PRB_BW; /* configured to total BW */
235    duCfgParam.macCellCfg.initialBwp.bwp.scs = SUBCARRIER_SPACING; /* numerology is 0, 15Khz */
236    duCfgParam.macCellCfg.initialBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
237    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.searchSpaceId = SEARCHSPACE_1_INDEX;
238    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.coresetId = CORESET_0_INDEX;
239    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.monitoringSlot =
240            SS_MONITORING_SLOT_SL1; /* sl1 - all slots */
241    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.duration = 0;
242    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.monitoringSymbol =
243            SS_MONITORING_SYMBOL;
244    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.
245            candidate.aggLevel1  = 8;
246    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.
247            candidate.aggLevel2  = 4;
248    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.
249            candidate.aggLevel4  = 2;
250    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.
251            candidate.aggLevel8  = 1;
252    duCfgParam.macCellCfg.initialBwp.pdcchCommon.raSearchSpace.
253            candidate.aggLevel16 = 0;
254
255    /* This should be calculated based on
256       (number of mandatory parameters) + (number of otional parameters being filled) */
257    duCfgParam.macCellCfg.numTlv = 39;
258
259    RETVALUE(ROK);
260 }
261
262 /*******************************************************************
263 *
264 * @brief Configures the DU Parameters
265 *
266 * @details
267 *
268 *    Function : fillDuPort
269 *
270 *    Functionality:
271 *       - fills the DU Ports.  
272 *
273 * @params[in] duPort array to be filled
274 * @return ROK     - success
275 *         RFAILED - failure
276 *
277 * ****************************************************************/
278 S16 fillDuPort(U16 *duPort)
279 {
280         duPort[F1_INTERFACE]   = DU_PORT;     /* DU Port idx  0 38472 */
281         duPort[E2_INTERFACE]   = RIC_PORT;    /* RIC Port idx 1 38482 */
282
283         RETVALUE(ROK);
284 }
285
286
287
288 /*******************************************************************
289  *
290  * @brief Configures serving cell config common in sib1
291  *
292  * @details
293  *
294  *    Function : fillServCellCfgCommSib
295  *
296  *    Functionality:
297  *       - fills Serving cell config common for SIB1
298  *
299  * @params[in] SrvCellCfgCommSib pointer
300  * @return ROK     - success
301  *         RFAILED - failure
302  * 
303  ** ****************************************************************/
304 S16 fillServCellCfgCommSib(SrvCellCfgCommSib *srvCellCfgComm)
305 {
306    PdcchCfgCommon   pdcchCfg;
307    PdschCfgCommon   pdschCfg;
308    PcchCfg          pcchCfg;
309    RachCfgCommon    rachCfg;
310    PuschCfgCommon   puschCfg;
311    PucchCfgCommon   pucchCfg;
312    TddUlDlCfgCommon   tddCfg;
313
314    /* Configuring DL Config Common for SIB1*/
315    srvCellCfgComm->dlCfg.freqBandInd = NR_FREQ_BAND_IND; 
316    srvCellCfgComm->dlCfg.offsetToPointA = OFFSET_TO_POINT_A;
317    srvCellCfgComm->dlCfg.dlScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
318    srvCellCfgComm->dlCfg.dlScsCarrier.scs = SUBCARRIER_SPACING;
319    srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = SCS_CARRIER_BANDWIDTH;
320    srvCellCfgComm->dlCfg.locAndBw = FREQ_LOC_BW;
321    
322    /* Configuring PDCCH Config Common For SIB1 */
323    pdcchCfg.present = BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup;
324    pdcchCfg.ctrlRsrcSetZero = PDCCH_CTRL_RSRC_SET_ZERO;
325    pdcchCfg.searchSpcZero = PDCCH_SEARCH_SPACE_ZERO;
326    pdcchCfg.searchSpcId = PDCCH_SEARCH_SPACE_ID;
327    pdcchCfg.ctrlRsrcSetId = PDCCH_CTRL_RSRC_SET_ID;
328    pdcchCfg.monitorSlotPrdAndOffPresent = \
329       SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
330    //pdcchCfg.monitorSlotPrdAndOff = \
331       SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
332    pdcchCfg.monitorSymbolsInSlot[0] = 128;
333    pdcchCfg.monitorSymbolsInSlot[1] = 0;
334    pdcchCfg.numCandAggLvl1 = SearchSpace__nrofCandidates__aggregationLevel1_n8;
335    pdcchCfg.numCandAggLvl2 = SearchSpace__nrofCandidates__aggregationLevel2_n4;
336    pdcchCfg.numCandAggLvl4 = SearchSpace__nrofCandidates__aggregationLevel4_n2;
337    pdcchCfg.numCandAggLvl8 = SearchSpace__nrofCandidates__aggregationLevel8_n1;
338    pdcchCfg.numCandAggLvl16 = SearchSpace__nrofCandidates__aggregationLevel16_n0;
339    pdcchCfg.searchSpcType = SearchSpace__searchSpaceType_PR_common;
340    pdcchCfg.commSrchSpcDciFrmt = PDCCH_SERACH_SPACE_DCI_FORMAT;
341    pdcchCfg.searchSpcSib1 = PDCCH_SEARCH_SPACE_ID_SIB1;
342    pdcchCfg.pagingSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
343    pdcchCfg.raSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
344    srvCellCfgComm->dlCfg.pdcchCfg = pdcchCfg;
345
346    /* Configuring PDSCH Config Common For SIB1 */
347    pdschCfg.present = BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup;
348    pdschCfg.k0 = PDSCH_K0;
349    pdschCfg.mapType = \
350       PDSCH_TimeDomainResourceAllocation__mappingType_typeA;
351    pdschCfg.startSymbAndLen = PDSCH_START_SYMB_AND_LEN;
352    srvCellCfgComm->dlCfg.pdschCfg = pdschCfg;
353
354    /* Configuring BCCH Config for SIB1 */
355    srvCellCfgComm->dlCfg.bcchCfg.modPrdCoeff = \
356       BCCH_Config__modificationPeriodCoeff_n16;
357
358    /* Configuring PCCH Config for SIB1 */
359    pcchCfg.dfltPagingCycle = PagingCycle_rf64;
360    pcchCfg.nAndPagingFrmOffPresent = PCCH_Config__nAndPagingFrameOffset_PR_oneT;
361    pcchCfg.numPagingOcc = PCCH_Config__ns_four;
362    srvCellCfgComm->dlCfg.pcchCfg = pcchCfg;
363
364
365    /* Configuring UL Config Common */
366    srvCellCfgComm->ulCfg.ulScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
367    srvCellCfgComm->ulCfg.ulScsCarrier.scs = SUBCARRIER_SPACING;
368    srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = SCS_CARRIER_BANDWIDTH;
369    srvCellCfgComm->ulCfg.pMax = UL_P_MAX;
370    srvCellCfgComm->ulCfg.locAndBw = FREQ_LOC_BW;
371    srvCellCfgComm->ulCfg.timeAlignTimerComm = TimeAlignmentTimer_infinity;
372
373    /* Configuring RACH Config Common for SIB1 */
374    rachCfg.present = BWP_UplinkCommon__rach_ConfigCommon_PR_setup;
375    rachCfg.prachCfgIdx = PRACH_CONFIG_IDX;
376    rachCfg.msg1Fdm = RACH_ConfigGeneric__msg1_FDM_one;
377    rachCfg.msg1FreqStart = PRACH_FREQ_START;
378    rachCfg.zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG;
379    rachCfg.preambleRcvdTgtPwr = PRACH_PREAMBLE_RCVD_TGT_PWR;
380    rachCfg.preambleTransMax = RACH_ConfigGeneric__preambleTransMax_n200;
381    rachCfg.pwrRampingStep = RACH_ConfigGeneric__powerRampingStep_dB2;
382    rachCfg.raRspWindow = RACH_ConfigGeneric__ra_ResponseWindow_sl20;
383    rachCfg.numRaPreamble = NUM_RA_PREAMBLE;
384    rachCfg.ssbPerRachOccPresent = \
385       RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_one;
386    rachCfg.numSsbPerRachOcc = SSB_PER_RACH;
387    rachCfg.contResTimer = RACH_ConfigCommon__ra_ContentionResolutionTimer_sf64;
388    rachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB;
389    rachCfg.rootSeqIdxPresent = RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139;
390    rachCfg.rootSeqIdx = ROOT_SEQ_IDX;
391    rachCfg.msg1Scs = PRACH_SUBCARRIER_SPACING ;
392    rachCfg.restrictedSetCfg = PRACH_RESTRICTED_SET_CFG;
393    srvCellCfgComm->ulCfg.rachCfg = rachCfg;
394
395    /* Configuring PUSCH Config Common for SIB1 */
396    puschCfg.present = BWP_UplinkCommon__pusch_ConfigCommon_PR_setup;
397    puschCfg.k2 = PUSCH_K0;
398    puschCfg.mapType = PUSCH_TimeDomainResourceAllocation__mappingType_typeA;
399    puschCfg.startSymbAndLen = PUSCH_START_SYMB_AND_LEN;
400    puschCfg.msg3DeltaPreamble = PUSCH_MSG3_DELTA_PREAMBLE;
401    puschCfg.p0NominalWithGrant = PUSCH_P0_NOMINAL_WITH_GRANT;
402    srvCellCfgComm->ulCfg.puschCfg = puschCfg;
403
404    /* Configuring PUCCH Config Common for SIB1 */
405    pucchCfg.present = BWP_UplinkCommon__pucch_ConfigCommon_PR_setup;
406    pucchCfg.rsrcComm = PUCCH_RSRC_COMMON;
407    pucchCfg.grpHop = PUCCH_ConfigCommon__pucch_GroupHopping_neither;
408    pucchCfg.p0Nominal = PUCCH_P0_NOMINAL;
409    srvCellCfgComm->ulCfg.pucchCfg = pucchCfg;
410
411    /* Configuring TDD UL DL config common */
412    tddCfg.refScs = SubcarrierSpacing_kHz30;
413    tddCfg.txPrd = TDD_UL_DL_Pattern__dl_UL_TransmissionPeriodicity_ms2p5;
414    tddCfg.numDlSlots = NUM_DL_SLOTS;
415    tddCfg.numDlSymbols = NUM_DL_SYMBOLS;
416    tddCfg.numUlSlots = NUM_UL_SLOTS;
417    tddCfg.numUlSymbols = NUM_UL_SYMBOLS;
418    srvCellCfgComm->tddCfg = tddCfg;
419
420    srvCellCfgComm->ssbPosInBurst = 192;
421    srvCellCfgComm->ssbPrdServingCell = SSB_PERIODICITY;
422    srvCellCfgComm->ssPbchBlockPwr = SSB_PBCH_PWR;
423
424    return ROK;
425 }
426
427 /*******************************************************************
428  *
429  * @brief Configures the DU Parameters
430  *
431  * @details
432  *
433  *    Function : readCfg
434  *
435  *    Functionality:
436  *       - Initializes the DuCfg members.  
437  *       - Calls readMacCfg()  
438  *
439  * @params[in] system task ID
440  * @return ROK     - success
441  *         RFAILED - failure
442  *
443  * ****************************************************************/
444
445 S16 readCfg()
446 {
447    U8 i,j,k;
448    U32 ipv4_du, ipv4_cu, ipv4_ric;
449         MibParams mib;
450    Sib1Params sib1;     
451
452    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
453    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
454         cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
455         fillDuPort(duCfgParam.sctpParams.duPort);
456
457    /* F1 DU IP Address and Port*/
458    duCfgParam.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
459
460    /* F1 CU IP Address and Port*/
461    duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
462    duCfgParam.sctpParams.cuPort = CU_PORT;
463
464         /* Fill RIC Params */
465         duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
466         duCfgParam.sctpParams.ricPort            = RIC_PORT;
467    /* EGTP Parameters */
468    duCfgParam.egtpParams.localIp.ipV4Pres = TRUE;
469    duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du;
470    duCfgParam.egtpParams.localPort = DU_EGTP_PORT;
471    duCfgParam.egtpParams.destIp.ipV4Pres = TRUE;
472    duCfgParam.egtpParams.destIp.ipV4Addr = ipv4_cu;
473    duCfgParam.egtpParams.destPort = CU_EGTP_PORT;
474    duCfgParam.egtpParams.minTunnelId = 0;
475    duCfgParam.egtpParams.maxTunnelId = 10;
476
477    duCfgParam.maxUe = 32; //TODO: Check
478    /* DU Info */        
479    duCfgParam.duId = DU_ID;     
480    strcpy((char*)duCfgParam.duName,DU_NAME);
481
482    /* Mib Params */
483         mib.sysFrmNum = SYS_FRAME_NUM;
484         mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs15or60;
485         mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; 
486         mib.dmrs_TypeA_Position = MIB__dmrs_TypeA_Position_pos2;
487         mib.controlResourceSetZero = CORESET_ZERO;
488         mib.searchSpaceZero = SEARCH_SPACE_ZERO;
489         mib.cellBarred = MIB__cellBarred_barred;
490         mib.intraFreqReselection =
491                 MIB__intraFreqReselection_notAllowed;
492         duCfgParam.mibParams = mib;
493
494    /* SIB1 Params */
495         sib1.plmn.mcc[0] = PLMN_MCC0;
496         sib1.plmn.mcc[1] = PLMN_MCC1;
497         sib1.plmn.mcc[2] = PLMN_MCC2;
498         sib1.plmn.mnc[0] = PLMN_MNC0;
499         sib1.plmn.mnc[1] = PLMN_MNC1;
500         sib1.plmn.mnc[2] = PLMN_MNC2;
501         sib1.tac = DU_TAC;
502         sib1.ranac = DU_RANAC;
503         sib1.cellIdentity = CELL_IDENTITY;
504         sib1.cellResvdForOpUse =\
505                 PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
506    sib1.connEstFailCnt = ConnEstFailureControl__connEstFailCount_n3;
507    sib1.connEstFailOffValidity =\
508       ConnEstFailureControl__connEstFailOffsetValidity_s120;
509    sib1.siSchedInfo.winLen = SI_SchedulingInfo__si_WindowLength_s5;
510    sib1.siSchedInfo.broadcastSta = \
511       SchedulingInfo__si_BroadcastStatus_broadcasting;
512    sib1.siSchedInfo.preiodicity = SchedulingInfo__si_Periodicity_rf8;
513    sib1.siSchedInfo.sibType = SIB_TypeInfo__type_sibType2;
514    sib1.siSchedInfo.sibValTag = SIB1_VALUE_TAG;
515
516    fillServCellCfgCommSib(&sib1.srvCellCfgCommSib);
517
518         duCfgParam.sib1Params = sib1;
519
520    for(i=0; i<DEFAULT_CELLS; i++)
521    { 
522       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mcc[0] = PLMN_MCC0;
523       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mcc[1] = PLMN_MCC1;
524       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mcc[2] = PLMN_MCC2;
525       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mnc[0] = PLMN_MNC0;
526       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mnc[1] = PLMN_MNC1;
527       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.plmn.mnc[2] = PLMN_MNC2;
528
529       /*Cell ID */
530       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrCgi.cellId = NR_CELL_ID;
531       duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.nrPci = NR_PCI;
532
533       /* List of Available PLMN */
534       for(j=0;j<MAX_PLMN;j++)
535       {
536          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mcc[0] = PLMN_MCC0;
537          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mcc[1] = PLMN_MCC1;
538          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mcc[2] = PLMN_MCC2;
539          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mnc[0] = PLMN_MNC0;
540          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mnc[1] = PLMN_MNC1;
541          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.plmn[j].mnc[2] = PLMN_MNC2;
542       }
543       /* List of Extended PLMN */
544       for(j=0;j<MAX_PLMN;j++)
545       {
546          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mcc[0] = PLMN_MCC0;
547          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mcc[1] = PLMN_MCC1;
548          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mcc[2] = PLMN_MCC2;
549          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mnc[0] = PLMN_MNC0;
550          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mnc[1] = PLMN_MNC1;
551          duCfgParam.srvdCellLst[i].duCellInfo.cellInfo.extPlmn[j].mnc[2] = PLMN_MNC2;
552       } 
553
554       /* TAC and EPSTAC */
555       duCfgParam.srvdCellLst[i].duCellInfo.tac = DU_TAC;
556       duCfgParam.srvdCellLst[i].duCellInfo.epsTac = DU_TAC; //to check and fill
557       /* NR Mode info */
558       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn = NR_ARFCN;
559       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
560       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_120;
561       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_66;
562
563 #if 0
564       /* NR Mode info */
565       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn = NR_ARFCN;
566       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
567       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;           
568       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb = NRB_160;           
569
570       for(j=0;j<MAXNRCELLBANDS;j++)
571       {
572          duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[j].nrFreqBand = NR_FREQ_BAND;
573          for(k=0;k<MAXNRCELLBANDS;k++)
574          {
575             duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[j].sulBand[k] = SUL_BAND;  
576          }
577       }
578 #endif
579       for(j=0;j<MAXNRCELLBANDS;j++)
580       {
581          duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[j].nrFreqBand = NR_FREQ_BAND;
582          for(k=0;k<MAXNRCELLBANDS;k++)
583          {
584             duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[j].sulBand[k] = SUL_BAND;
585          }
586       }
587       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.nrArfcn = NR_ARFCN;
588       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
589       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_120;
590       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_66;
591       for(j=0;j<MAXNRCELLBANDS;j++)
592       {
593          duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[j].nrFreqBand = NR_FREQ_BAND;
594          for(k=0;k<MAXNRCELLBANDS;k++)
595          {
596             duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[j].sulBand[k] = SUL_BAND;
597          }
598       }
599
600       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrScs = SCS_120;
601       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrb = NRB_66;
602
603       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrScs = SCS_120;
604       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrb = NRB_66;
605
606 #if 0
607       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrTxBw.nrScs = SCS_15;
608       duCfgParam.srvdCellLst[i].duCellInfo.f1Mode.mode.tdd.nrTxBw.nrb = NRB_160;
609 #endif
610       /*Measurement Config and Cell Config */ 
611       duCfgParam.srvdCellLst[i].duCellInfo.measTimeCfg = TIME_CFG; 
612
613       duCfgParam.srvdCellLst[i].duCellInfo.cellDir = DL_UL; 
614
615       duCfgParam.srvdCellLst[i].duCellInfo.cellType=CELL_TYPE;
616
617       /* Broadcast PLMN Identity */
618       for(j=0;j<MAXBPLMNNRMINUS1;j++)
619       {  
620          for(k=0;k<MAX_PLMN;k++)
621          {
622             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mcc[0] = PLMN_MCC0;
623             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mcc[1] = PLMN_MCC1;
624             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mcc[2] = PLMN_MCC2;
625             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mnc[0] = PLMN_MNC0;
626             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mnc[1] = PLMN_MNC1;                                         
627             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].plmn[k].mnc[2] = PLMN_MNC2;
628          }
629          /* Extended PLMN List */        
630          for(k=0;k<MAX_PLMN;k++)
631          {
632             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mcc[0] = PLMN_MCC0;
633             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mcc[1] = PLMN_MCC1;
634             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mcc[2] = PLMN_MCC2;
635             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mnc[0] = PLMN_MNC0;
636             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mnc[1] = PLMN_MNC1;
637             duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].extPlmn[k].mnc[2] = PLMN_MNC2;
638          }
639
640          duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].tac = DU_TAC;
641          duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].nrCellId = NR_CELL_ID;
642          duCfgParam.srvdCellLst[i].duCellInfo.brdcstPlmnInfo[j].ranac = NR_RANAC;
643       }
644
645       /*gnb DU System Info mib msg*/
646            BuildMibMsg();
647                 DU_ALLOC(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg,\
648                                 strlen(encBuf));
649            if(!(duCfgParam.srvdCellLst[i].duSysInfo.mibMsg))
650                 {
651          DU_LOG("\nDU_APP: Memory allocation failure");
652                         return RFAILED;
653                 }
654       strcpy((char *)duCfgParam.srvdCellLst[i].duSysInfo.mibMsg, encBuf);
655       duCfgParam.srvdCellLst[i].duSysInfo.mibLen = encBufSize;
656
657       /*gnb DU System Info mib msg*/
658       BuildSib1Msg();
659                 DU_ALLOC(duCfgParam.srvdCellLst[i].duSysInfo.sib1Msg,\
660                                 encBufSize);
661            if(!(duCfgParam.srvdCellLst[i].duSysInfo.sib1Msg))
662                 {
663          DU_LOG("\nDU_APP: Memory allocation failure");
664                         return RFAILED;
665                 }
666                 memcpy(duCfgParam.srvdCellLst[i].duSysInfo.sib1Msg,\
667                        encBuf,encBufSize);
668                 duCfgParam.srvdCellLst[i].duSysInfo.sib1Len = encBufSize;
669
670    }
671
672    if(readMacCfg() != ROK)
673    {
674       DU_LOG("\nDU_APP : Failed while reading MAC config");
675       RETVALUE(RFAILED);
676    }
677
678    RETVALUE(ROK);
679 }
680
681 /*******************************************************************
682  *
683  * @brief Reads config and posts message to du_app on completion
684  *
685  * @details
686  *
687  *    Function : main
688  *
689  *    Functionality:
690  *      - Calls readCfg()
691  *      - Post to du_app for further processing
692  *
693  * @params[in] void
694  * @return ROK     - success
695  *         RFAILED - failure
696  *
697  * ****************************************************************/
698 S16 duReadCfg()
699 {
700    Pst pst;
701    Buffer *mBuf;
702
703    cmMemset((U8 *)&duCfgParam, 0, sizeof(DuCfgParams));
704    //Read configs into duCfgParams
705    if(readCfg() != ROK)
706    {
707       DU_LOG("\nDU_APP : Reading configuration failed");
708       RETVALUE(RFAILED);
709    }
710
711    //Fill pst structure
712    cmMemset((U8 *)&(pst), 0, sizeof(Pst));
713    pst.srcEnt = (Ent)ENTDUAPP;
714    pst.srcInst = (Inst)DU_INST;
715    pst.srcProcId = DU_PROC;
716    pst.dstEnt = pst.srcEnt;
717    pst.dstInst = pst.srcInst;
718    pst.dstProcId = pst.srcProcId;
719    pst.event = EVTCFG;
720    pst.selector = DU_SELECTOR_TC;
721    pst.pool= DU_POOL;
722
723
724    if(SGetMsg(DFLT_REGION, DU_POOL, &mBuf) != ROK)
725    {
726       DU_LOG("\nDU_APP : Memory allocation failed in duReadCfg");
727       return RFAILED;
728    }
729
730    if (SPstTsk(&pst, mBuf) != ROK)
731    {
732       DU_LOG("\nDU_APP : SPstTsk failed in duReadCfg");
733       return RFAILED;
734    }
735
736    return ROK;
737 }
738
739 /*******************************************************************
740  *
741  * @brief Converts bit strings to integer
742  *
743  * @details
744  *
745  *    Function : bitStringToInt
746  *
747  *    Functionality:
748  *      - Converts ASN bit string format IEs to integer type
749  *
750  * @params[in] void
751  * @return ROK     - success
752  *         RFAILED - failure
753  *
754  * ****************************************************************/
755 S16 bitStringToInt(BIT_STRING_t *bitString, U16 *val)
756 {
757    U16 idx;
758    if(bitString->buf == NULL || bitString->size <= 0)
759    {
760       DU_LOG("\nDU_APP : Bit string is empty");
761       return RFAILED;
762    }
763
764    for(idx=0; idx< bitString->size-1; idx++)
765    {
766       *val |= bitString->buf[idx];
767       *val <<= 8;
768    }
769
770    *val |= bitString->buf[idx];
771         *val >>= bitString->bits_unused;
772
773    return ROK;
774 }
775
776
777 /**********************************************************************
778   End of file
779  **********************************************************************/
780