3ddf9004d118111e06420a18a92574c7fbca8357
[o-du/l2.git] / src / du_app / du_cfg.c
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17  *******************************************************************************/
18
19 /* This file contains all utility functions */
20 #include "common_def.h"
21 #include "legtp.h"
22 #include "lrg.h"
23 #include "lkw.x"
24 #include "lrg.x"
25 #include "du_app_mac_inf.h"
26 #include "du_app_rlc_inf.h"
27 #include "du_cfg.h"
28 #include "du_mgr.h"
29 #include "du_utils.h"
30 #include "OCTET_STRING.h"
31 #include "BIT_STRING.h"
32 #include "odu_common_codec.h"
33 #include "du_sys_info_hdl.h"
34 #include "MIB.h"
35 #include "SearchSpace.h"
36 #include "SIB-TypeInfo.h"
37 #include "SchedulingInfo.h"
38 #include "SI-SchedulingInfo.h"
39 #include "ConnEstFailureControl.h"
40 #include "PLMN-IdentityInfo.h"
41 #include "PDSCH-TimeDomainResourceAllocation.h"
42 #include "BCCH-Config.h"
43 #include "PagingCycle.h"
44 #include "PCCH-Config.h"
45 #include "TimeAlignmentTimer.h"
46 #include "RACH-ConfigGeneric.h"
47 #include "PUSCH-TimeDomainResourceAllocation.h"
48 #include "PUCCH-ConfigCommon.h"
49 #include "SubcarrierSpacing.h"
50 #include "TDD-UL-DL-Pattern.h"
51 #include "RACH-ConfigCommon.h"
52 #include "BWP-DownlinkCommon.h"
53 #include "BWP-UplinkCommon.h"
54
55 #ifdef O1_ENABLE
56 #include "CmInterface.h"
57 extern StartupConfig g_cfg;
58 extern NRCellDU cellParams;
59 #endif
60
61 char encBuf[ENC_BUF_MAX_LEN];
62
63
64 /* Filling Slot configuration as :
65  * 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
66  *   0   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
67  *   1   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
68  *   2   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
69      3   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
70      4   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
71      5   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
72      6   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL
73      7   DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    DL    F     UL
74      8   UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL
75      9   UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL    UL  
76  */
77
78 #ifdef NR_TDD
79 /*******************************************************************
80  *
81  * @brief Fills the Slot configuration 
82  *
83  * @details
84  *
85  *    Function : FillSlotConfig
86  *
87  *    Functionality:Fill the Slot configuration values
88  * 
89  *  @params[in] void
90  * @return ROK     - success
91  *         RFAILED - failure
92  *
93  * ****************************************************************/
94 void FillSlotConfig()
95 {
96    uint8_t slot = 0;
97    uint8_t symbol =0;
98    
99    memset(duCfgParam.macCellCfg.tddCfg.slotCfg, 0, sizeof(duCfgParam.macCellCfg.tddCfg.slotCfg[slot][symbol]* \
100                            MAX_TDD_PERIODICITY_SLOTS*MAX_SYMB_PER_SLOT));
101    
102    //Filling the DL Slots and initializing flexi slot
103    for(slot = 0; slot <= NUM_DL_SLOTS; slot++)
104    {
105       for(symbol =0; symbol < MAX_SYMB_PER_SLOT; symbol++)
106       {
107          duCfgParam.macCellCfg.tddCfg.slotCfg[slot][symbol] = DL_SLOT;
108       }
109    }
110   
111    //Filling UL Slots
112    for(slot = NUM_DL_SLOTS+1; slot <= NUM_DL_SLOTS+NUM_UL_SLOTS; slot++)
113    {
114       for(symbol = 0; symbol < MAX_SYMB_PER_SLOT; symbol++)
115          duCfgParam.macCellCfg.tddCfg.slotCfg[slot][symbol] = UL_SLOT;
116    } 
117    //Updating Flexi Slot
118    slot = NUM_DL_SLOTS;
119    duCfgParam.macCellCfg.tddCfg.slotCfg[slot][12] = FLEXI_SLOT;
120    duCfgParam.macCellCfg.tddCfg.slotCfg[slot][13] = UL_SLOT;
121
122 }
123 #endif
124 /*******************************************************************
125  * @brief Reads the CL Configuration.
126  *
127  * @details
128  *
129  *    Function : readMacCfg
130  *
131  *    Functionality:
132  *       - Fills up the cell configuration for CL.
133  *       - Calls FillSlotConfig()  
134  *
135  * @params[in] void
136  * @return ROK     - success
137  *         RFAILED - failure
138  *
139  * ****************************************************************/
140
141
142 /* This function is used to fill up the cell configuration for CL */
143 uint8_t readMacCfg()
144 {
145    uint8_t idx=0, sliceIdx=0;
146    F1TaiSliceSuppLst *taiSliceSuppLst;
147
148    duCfgParam.macCellCfg.carrierId = CARRIER_IDX;
149
150    /* Cell configuration */
151    duCfgParam.macCellCfg.numerology = NR_NUMEROLOGY;
152    duCfgParam.macCellCfg.dupType = DUPLEX_MODE;
153
154    /* DL carrier configuration */
155    duCfgParam.macCellCfg.dlCarrCfg.pres = TRUE;
156 #ifdef O1_ENABLE
157    duCfgParam.macCellCfg.cellId = cellParams.cellLocalId;
158    duCfgParam.macCellCfg.phyCellId = cellParams.nRPCI;
159    duCfgParam.macCellCfg.dlCarrCfg.bw = cellParams.bSChannelBwUL;
160    duCfgParam.macCellCfg.dlCarrCfg.freq = cellParams.bSChannelBwDL;
161 #else
162    duCfgParam.macCellCfg.cellId = NR_CELL_ID;
163    duCfgParam.macCellCfg.phyCellId = NR_PCI;
164    duCfgParam.macCellCfg.dlCarrCfg.bw = NR_BANDWIDTH;
165    duCfgParam.macCellCfg.dlCarrCfg.freq = NR_DL_ARFCN;
166 #endif
167    
168    duCfgParam.macCellCfg.dlCarrCfg.k0[0] = 1;
169    duCfgParam.macCellCfg.dlCarrCfg.k0[1] = 1;
170    duCfgParam.macCellCfg.dlCarrCfg.k0[2] = 1;
171    duCfgParam.macCellCfg.dlCarrCfg.k0[3] = 1;
172    duCfgParam.macCellCfg.dlCarrCfg.k0[4] = 1;
173    duCfgParam.macCellCfg.dlCarrCfg.gridSize[0] = 273;
174    duCfgParam.macCellCfg.dlCarrCfg.gridSize[1] = 1;
175    duCfgParam.macCellCfg.dlCarrCfg.gridSize[2] = 1;
176    duCfgParam.macCellCfg.dlCarrCfg.gridSize[3] = 1;
177    duCfgParam.macCellCfg.dlCarrCfg.gridSize[4] = 1;
178    duCfgParam.macCellCfg.dlCarrCfg.numAnt = NUM_TX_ANT;
179
180    /* UL Carrier configuration */
181    duCfgParam.macCellCfg.ulCarrCfg.pres = TRUE;
182 #ifdef O1_ENABLE
183    duCfgParam.macCellCfg.ulCarrCfg.bw = cellParams.bSChannelBwUL;
184    duCfgParam.macCellCfg.ulCarrCfg.freq = cellParams.bSChannelBwDL;
185 #else   
186    duCfgParam.macCellCfg.ulCarrCfg.bw = NR_BANDWIDTH;
187    duCfgParam.macCellCfg.ulCarrCfg.freq =  NR_UL_ARFCN;
188 #endif   
189    duCfgParam.macCellCfg.ulCarrCfg.k0[0] = 1;
190    duCfgParam.macCellCfg.ulCarrCfg.k0[1] = 1;
191    duCfgParam.macCellCfg.ulCarrCfg.k0[2] = 1;
192    duCfgParam.macCellCfg.ulCarrCfg.k0[3] = 1;
193    duCfgParam.macCellCfg.ulCarrCfg.k0[4] = 1;
194    duCfgParam.macCellCfg.ulCarrCfg.gridSize[0] = 1;
195    duCfgParam.macCellCfg.ulCarrCfg.gridSize[1] = 1;
196    duCfgParam.macCellCfg.ulCarrCfg.gridSize[2] = 1;
197    duCfgParam.macCellCfg.ulCarrCfg.gridSize[3] = 1;
198    duCfgParam.macCellCfg.ulCarrCfg.gridSize[4] = 1;
199    duCfgParam.macCellCfg.ulCarrCfg.numAnt = NUM_RX_ANT;
200
201    duCfgParam.macCellCfg.freqShft = FREQ_SHIFT_7P5KHZ;
202
203    /* SSB configuration */
204    duCfgParam.macCellCfg.ssbCfg.ssbPbchPwr = SSB_PBCH_PWR;
205    duCfgParam.macCellCfg.ssbCfg.bchPayloadFlag = BCH_PAYLOAD;
206    duCfgParam.macCellCfg.ssbCfg.ssbOffsetPointA = OFFSET_TO_POINT_A;
207    duCfgParam.macCellCfg.ssbCfg.betaPss = BETA_PSS;
208 #ifdef O1_ENABLE
209    duCfgParam.macCellCfg.ssbCfg.scsCmn = cellParams.ssbSubCarrierSpacing;
210    duCfgParam.macCellCfg.ssbCfg.ssbPeriod = cellParams.ssbPeriodicity;
211    duCfgParam.macCellCfg.ssbCfg.ssbScOffset = cellParams.ssbOffset;
212 #else
213    duCfgParam.macCellCfg.ssbCfg.scsCmn = NR_SCS;
214    duCfgParam.macCellCfg.ssbCfg.ssbPeriod = SSB_PRDCTY_MS_20;
215    duCfgParam.macCellCfg.ssbCfg.ssbScOffset = SSB_SUBCARRIER_OFFSET;
216 #endif
217    duCfgParam.macCellCfg.ssbCfg.ssbMask[0] = 1; /* only one SSB is transmitted */
218    duCfgParam.macCellCfg.ssbCfg.ssbMask[1] = 0;
219    if(BuildMibPdu() != ROK)
220    {
221       DU_LOG("\nERROR  -->  Failed to build MIB PDU");
222       memset(&duCfgParam.macCellCfg.ssbCfg.mibPdu, 0, 3*sizeof(uint8_t));
223    }
224    else
225    {
226       memcpy(&duCfgParam.macCellCfg.ssbCfg.mibPdu, encBuf,encBufSize);
227    }
228    duCfgParam.macCellCfg.ssbCfg.multCarrBand = SSB_MULT_CARRIER_BAND;
229    duCfgParam.macCellCfg.ssbCfg.multCellCarr = MULT_CELL_CARRIER;
230
231    /* PRACH configuration */
232    duCfgParam.macCellCfg.prachCfg.pres = TRUE;
233    duCfgParam.macCellCfg.prachCfg.prachCfgIdx = PRACH_CONFIG_IDX;
234    duCfgParam.macCellCfg.prachCfg.prachSeqLen = PRACH_SEQ_LEN;
235    duCfgParam.macCellCfg.prachCfg.prachSubcSpacing = fetchScsValue(PRACH_SUBCARRIER_SPACING);
236    duCfgParam.macCellCfg.prachCfg.prachRstSetCfg = PRACH_RESTRICTED_SET_CFG;
237    duCfgParam.macCellCfg.prachCfg.msg1Fdm = NUM_PRACH_FDM;
238    duCfgParam.macCellCfg.prachCfg.msg1FreqStart = PRACH_FREQ_START;
239    duCfgParam.macCellCfg.prachCfg.rootSeqLen    = ROOT_SEQ_LEN;
240    duCfgParam.macCellCfg.prachCfg.fdm[0].rootSeqIdx = ROOT_SEQ_IDX;
241    duCfgParam.macCellCfg.prachCfg.fdm[0].numRootSeq = NUM_ROOT_SEQ;
242    duCfgParam.macCellCfg.prachCfg.fdm[0].k1 = 0;
243    duCfgParam.macCellCfg.prachCfg.fdm[0].zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG;
244    duCfgParam.macCellCfg.prachCfg.fdm[0].numUnusedRootSeq = NUM_UNUSED_ROOT_SEQ;
245    if(duCfgParam.macCellCfg.prachCfg.fdm[0].numUnusedRootSeq != 0)
246    {
247         DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq, 
248         NUM_UNUSED_ROOT_SEQ * sizeof(uint8_t));
249         if(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq == NULLP)
250         {
251             DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed at readMacCfg");
252             return RFAILED;
253         }
254         *(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq) = UNUSED_ROOT_SEQ;
255     }
256    duCfgParam.macCellCfg.prachCfg.ssbPerRach = SSB_PER_RACH;
257    duCfgParam.macCellCfg.prachCfg.prachMultCarrBand = PRACH_MULT_CARRIER_BAND;
258    duCfgParam.macCellCfg.prachCfg.raContResTmr = RA_CONT_RES_TIMER;
259    duCfgParam.macCellCfg.prachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB;
260    duCfgParam.macCellCfg.prachCfg.raRspWindow = RA_RSP_WINDOW;
261    duCfgParam.macCellCfg.prachCfg.prachRestrictedSet = PRACH_RESTRICTED_SET;
262 #ifdef NR_TDD   
263    /* TDD configuration */
264    duCfgParam.macCellCfg.tddCfg.pres = TRUE;
265    duCfgParam.macCellCfg.tddCfg.tddPeriod = TDD_PERIODICITY;
266
267    FillSlotConfig();
268
269 #endif
270    /* RSSI Measurement configuration */
271    duCfgParam.macCellCfg.rssiUnit = RSS_MEASUREMENT_UNIT;
272
273    /* fill SIB1 configuration */
274    duCfgParam.macCellCfg.sib1Cfg.sib1PduLen = duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
275    DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu,duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
276    memcpy(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu, duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg, \
277          duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
278    duCfgParam.macCellCfg.sib1Cfg.sib1RepetitionPeriod = SIB1_REPETITION_PERIOD;
279    duCfgParam.macCellCfg.sib1Cfg.coresetZeroIndex = CORESET_0_INDEX;
280    duCfgParam.macCellCfg.sib1Cfg.searchSpaceZeroIndex = SEARCHSPACE_0_INDEX;
281    duCfgParam.macCellCfg.sib1Cfg.sib1Mcs = DEFAULT_MCS;
282
283
284    /* fill Intial DL BWP */
285    duCfgParam.macCellCfg.initialDlBwp.bwp.firstPrb = 0;
286    duCfgParam.macCellCfg.initialDlBwp.bwp.numPrb = TOTAL_PRB_20MHZ_MU0; /* configured to total BW */
287    duCfgParam.macCellCfg.initialDlBwp.bwp.scs = duCfgParam.macCellCfg.ssbCfg.scsCmn;
288    duCfgParam.macCellCfg.initialDlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
289    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId = SEARCHSPACE_1_INDEX;
290    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.coresetId = CORESET_0_INDEX;
291    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
292       SS_MONITORING_SLOT_SL1; /* sl1 - all slots */
293    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.duration = 0;
294    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
295       SS_MONITORING_SYMBOL;
296    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
297       candidate.aggLevel1       = 8;
298    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
299       candidate.aggLevel2       = 4;
300    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
301       candidate.aggLevel4       = 2;
302    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
303       candidate.aggLevel8       = 1;
304    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
305       candidate.aggLevel16      = 0;
306
307    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.numTimeDomAlloc = 2;
308    idx = 0;
309    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].k0 = PDSCH_K0_CFG1;
310    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].mappingType = 
311       PDSCH_MAPPING_TYPE_A;
312    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].startSymbol = 
313       PDSCH_START_SYMBOL;
314    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].lengthSymbol =
315       PDSCH_LENGTH_SYMBOL;
316  
317    idx++;
318    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].k0 = PDSCH_K0_CFG2;
319    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].mappingType = 
320       PDSCH_MAPPING_TYPE_A;
321    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].startSymbol = 
322       PDSCH_START_SYMBOL;
323    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].lengthSymbol =
324       PDSCH_LENGTH_SYMBOL;
325
326    /* ra-searchSpace ID is set to 1 */
327    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.raSearchSpaceId = SEARCHSPACE_1_INDEX;
328
329    /* fill Intial UL BWP */
330    duCfgParam.macCellCfg.initialUlBwp.bwp.firstPrb = 0;
331    duCfgParam.macCellCfg.initialUlBwp.bwp.numPrb = TOTAL_PRB_20MHZ_MU0; /* configured to total BW */
332    duCfgParam.macCellCfg.initialUlBwp.bwp.scs = duCfgParam.macCellCfg.ssbCfg.scsCmn;
333    duCfgParam.macCellCfg.initialUlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
334    duCfgParam.macCellCfg.initialUlBwp.puschCommon.numTimeDomRsrcAlloc = 2;
335    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].k2 = PUSCH_K2_CFG1;
336    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].mappingType = 
337       PUSCH_MAPPING_TYPE_A;
338    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].startSymbol = 
339       PUSCH_START_SYMBOL;
340    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].symbolLength =
341       PUSCH_LENGTH_SYMBOL;
342
343    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].k2 = PUSCH_K2_CFG2;
344    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].mappingType = 
345       PUSCH_MAPPING_TYPE_A;
346    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].startSymbol = 
347       PUSCH_START_SYMBOL;
348    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].symbolLength =
349       PUSCH_LENGTH_SYMBOL;
350
351    duCfgParam.macCellCfg.dmrsTypeAPos = DMRS_TYPE_A_POS; 
352
353    /* fill PUCCH config common */
354    duCfgParam.macCellCfg.initialUlBwp.pucchCommon.pucchResourceCommon = PUCCH_RSRC_COMMON;
355    duCfgParam.macCellCfg.initialUlBwp.pucchCommon.pucchGroupHopping = PUCCH_GROUP_HOPPING;
356    
357    /* Plmn And SNSSAI Configuration */
358    memset(&duCfgParam.macCellCfg.plmnInfoList.plmn, &duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].plmn,\
359    sizeof(Plmn));
360    taiSliceSuppLst = &duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst;
361    duCfgParam.macCellCfg.plmnInfoList.numSupportedSlice = taiSliceSuppLst->numSupportedSlices;
362    if(taiSliceSuppLst->snssai)
363    {
364       DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.plmnInfoList.snssai, (duCfgParam.macCellCfg.plmnInfoList.numSupportedSlice) * sizeof(Snssai*));
365       if(duCfgParam.macCellCfg.plmnInfoList.snssai == NULLP)
366       {
367          DU_LOG("\nERROR  --> DU_APP: Memory allocation failed at readMacCfg");
368          return RFAILED;
369       }
370    }
371    for(sliceIdx=0; sliceIdx<taiSliceSuppLst->numSupportedSlices; sliceIdx++)
372    {
373       if(taiSliceSuppLst->snssai[sliceIdx] != NULLP)
374       {
375          DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.plmnInfoList.snssai[sliceIdx], sizeof(Snssai));
376          if(duCfgParam.macCellCfg.plmnInfoList.snssai[sliceIdx] == NULLP)
377          {
378             DU_LOG("\nERROR  --> DU_APP: Memory allocation failed at readMacCfg");
379             return RFAILED;
380          }
381          memcpy(duCfgParam.macCellCfg.plmnInfoList.snssai[sliceIdx], taiSliceSuppLst->snssai[sliceIdx], sizeof(Snssai));
382       }
383    }
384    return ROK;
385 }
386
387 /*******************************************************************
388  *
389  * @brief Configures the DU Parameters
390  *
391  * @details
392  *
393  *    Function : fillDuPort
394  *
395  *    Functionality:
396  *       - fills the DU Ports.  
397  *
398  * @params[in] duPort array to be filled
399  * @return ROK     - success
400  *         RFAILED - failure
401  *
402  * ****************************************************************/
403 uint8_t fillDuPort(uint16_t *duPort)
404 {
405
406 #ifdef O1_ENABLE
407    duPort[F1_INTERFACE]   = g_cfg.DU_Port;
408    duPort[E2_INTERFACE]   = g_cfg.RIC_Port;
409 #else
410    duPort[F1_INTERFACE]   = DU_PORT;     /* DU Port idx  0 38472 */
411    duPort[E2_INTERFACE]   = RIC_PORT;    /* RIC Port idx 1 38482 */
412 #endif
413    return ROK;
414 }
415
416 /*******************************************************************
417  *
418  * @brief Configures the DU Parameters
419  *
420  * @details
421  *
422  *    Function : calcSliv
423  *
424  *    Functionality:
425  *       - calculate SLIV value from start and length field
426  *
427  * @params[in] start symbol
428  * @params[in] length of symbols
429  * @return SLIV value
430  *
431  * ****************************************************************/
432 uint16_t calcSliv(uint8_t startSymbol, uint8_t lengthSymbol)
433 {
434    uint16_t sliv = 0;
435    if((lengthSymbol-1) <= 7)
436    {
437       sliv = NUM_SYMBOLS_PER_SLOT * (lengthSymbol-1) + startSymbol;
438    }
439    else
440    {
441       sliv = NUM_SYMBOLS_PER_SLOT * (NUM_SYMBOLS_PER_SLOT - lengthSymbol + 1) \
442              + (NUM_SYMBOLS_PER_SLOT - 1 - startSymbol);
443    }
444    return sliv;
445 }
446
447
448 /*******************************************************************
449  *
450  * @brief Configures serving cell config common in sib1
451  *
452  * @details
453  *
454  *    Function : fillServCellCfgCommSib
455  *
456  *    Functionality:
457  *       - fills Serving cell config common for SIB1
458  *
459  * @params[in] SrvCellCfgCommSib pointer
460  * @return ROK     - success
461  *         RFAILED - failure
462  * 
463  ** ****************************************************************/
464 uint8_t fillServCellCfgCommSib(SrvCellCfgCommSib *srvCellCfgComm)
465 {
466    PdcchCfgCommon   pdcchCfg;
467    PdschCfgCommon   pdschCfg;
468    PcchCfg          pcchCfg;
469    RachCfgCommon    rachCfg;
470    PuschCfgCommon   puschCfg;
471    PucchCfgCommon   pucchCfg;
472    TddUlDlCfgCommon   tddCfg;
473
474    /* Configuring DL Config Common for SIB1*/
475    srvCellCfgComm->dlCfg.freqBandInd = NR_FREQ_BAND; 
476    srvCellCfgComm->dlCfg.offsetToPointA = OFFSET_TO_POINT_A;
477 #ifdef O1_ENABLE
478    srvCellCfgComm->dlCfg.dlScsCarrier.scsOffset =  cellParams.ssbOffset;
479    srvCellCfgComm->dlCfg.dlScsCarrier.scs = cellParams.ssbSubCarrierSpacing;
480    srvCellCfgComm->dlCfg.dlScsCarrier.scsBw =  cellParams.bSChannelBwUL;
481 #else
482    srvCellCfgComm->dlCfg.dlScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
483    srvCellCfgComm->dlCfg.dlScsCarrier.scs = NR_SCS;
484    srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = NR_BANDWIDTH;
485 #endif   
486    srvCellCfgComm->dlCfg.locAndBw = FREQ_LOC_BW;
487
488    /* Configuring PDCCH Config Common For SIB1 */
489    pdcchCfg.present = BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup;
490    pdcchCfg.ctrlRsrcSetZero = CORESET_0_INDEX;
491    pdcchCfg.searchSpcZero = SEARCHSPACE_0_INDEX;
492    pdcchCfg.searchSpcId = PDCCH_SEARCH_SPACE_ID;
493    pdcchCfg.ctrlRsrcSetId = PDCCH_CTRL_RSRC_SET_ID;
494    pdcchCfg.monitorSlotPrdAndOffPresent = \
495       
496       SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
497    //pdcchCfg.monitorSlotPrdAndOff = \
498    SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
499    pdcchCfg.monitorSymbolsInSlot[0] = 128;
500    pdcchCfg.monitorSymbolsInSlot[1] = 0;
501    pdcchCfg.numCandAggLvl1 = SearchSpace__nrofCandidates__aggregationLevel1_n8;
502    pdcchCfg.numCandAggLvl2 = SearchSpace__nrofCandidates__aggregationLevel2_n4;
503    pdcchCfg.numCandAggLvl4 = SearchSpace__nrofCandidates__aggregationLevel4_n2;
504    pdcchCfg.numCandAggLvl8 = SearchSpace__nrofCandidates__aggregationLevel8_n1;
505    pdcchCfg.numCandAggLvl16 = SearchSpace__nrofCandidates__aggregationLevel16_n0;
506    pdcchCfg.searchSpcType = SearchSpace__searchSpaceType_PR_common;
507    pdcchCfg.commSrchSpcDciFrmt = PDCCH_SERACH_SPACE_DCI_FORMAT;
508    pdcchCfg.searchSpcSib1 = PDCCH_SEARCH_SPACE_ID_SIB1;
509    pdcchCfg.pagingSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
510    pdcchCfg.raSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
511    srvCellCfgComm->dlCfg.pdcchCfg = pdcchCfg;
512
513    /* Configuring PDSCH Config Common For SIB1 */
514    pdschCfg.present = BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup;
515    pdschCfg.numTimeDomRsrcAlloc = 2;
516    pdschCfg.timeDomAlloc[0].k0 = PDSCH_K0_CFG1;
517    pdschCfg.timeDomAlloc[0].mapType = \
518       PDSCH_TimeDomainResourceAllocation__mappingType_typeA;
519    pdschCfg.timeDomAlloc[0].sliv = calcSliv(PDSCH_START_SYMBOL,PDSCH_LENGTH_SYMBOL);
520
521    pdschCfg.timeDomAlloc[1].k0 = PDSCH_K0_CFG2;
522    pdschCfg.timeDomAlloc[1].mapType = \
523       PDSCH_TimeDomainResourceAllocation__mappingType_typeA;
524    pdschCfg.timeDomAlloc[1].sliv = calcSliv(PDSCH_START_SYMBOL,PDSCH_LENGTH_SYMBOL);
525
526    srvCellCfgComm->dlCfg.pdschCfg = pdschCfg;
527
528    /* Configuring BCCH Config for SIB1 */
529    srvCellCfgComm->dlCfg.bcchCfg.modPrdCoeff = \
530       BCCH_Config__modificationPeriodCoeff_n16;
531
532    /* Configuring PCCH Config for SIB1 */
533    pcchCfg.dfltPagingCycle = PagingCycle_rf256;
534    pcchCfg.nAndPagingFrmOffPresent = PCCH_Config__nAndPagingFrameOffset_PR_oneT;
535    pcchCfg.numPagingOcc = PCCH_Config__ns_four;
536    srvCellCfgComm->dlCfg.pcchCfg = pcchCfg;
537
538
539    /* Configuring UL Config Common */
540 #ifdef O1_ENABLE
541    srvCellCfgComm->ulCfg.ulScsCarrier.scsOffset =  cellParams.ssbOffset;
542    srvCellCfgComm->ulCfg.ulScsCarrier.scs = cellParams.ssbSubCarrierSpacing;
543    srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = cellParams.bSChannelBwUL; 
544 #else
545    srvCellCfgComm->ulCfg.ulScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
546    srvCellCfgComm->ulCfg.ulScsCarrier.scs = NR_SCS;
547    srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = NR_BANDWIDTH;
548 #endif   
549    srvCellCfgComm->ulCfg.pMax = UL_P_MAX;
550    srvCellCfgComm->ulCfg.locAndBw = FREQ_LOC_BW;
551    srvCellCfgComm->ulCfg.timeAlignTimerComm = TimeAlignmentTimer_infinity;
552
553    /* Configuring RACH Config Common for SIB1 */
554    rachCfg.present = BWP_UplinkCommon__rach_ConfigCommon_PR_setup;
555    rachCfg.prachCfgIdx = PRACH_CONFIG_IDX;
556    rachCfg.msg1Fdm = RACH_ConfigGeneric__msg1_FDM_one;
557    rachCfg.msg1FreqStart = PRACH_FREQ_START;
558    rachCfg.zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG;
559    rachCfg.preambleRcvdTgtPwr = PRACH_PREAMBLE_RCVD_TGT_PWR;
560    rachCfg.preambleTransMax = RACH_ConfigGeneric__preambleTransMax_n200;
561    rachCfg.pwrRampingStep = RACH_ConfigGeneric__powerRampingStep_dB2;
562    rachCfg.raRspWindow = RACH_ConfigGeneric__ra_ResponseWindow_sl10;
563    rachCfg.numRaPreamble = NUM_RA_PREAMBLE;
564    rachCfg.ssbPerRachOccPresent = \
565       RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_one;
566    rachCfg.numSsbPerRachOcc = SSB_PER_RACH;
567    rachCfg.contResTimer = RACH_ConfigCommon__ra_ContentionResolutionTimer_sf64;
568    rachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB;
569    rachCfg.rootSeqIdxPresent = RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139;
570    rachCfg.rootSeqIdx = ROOT_SEQ_IDX;
571    rachCfg.msg1Scs = PRACH_SUBCARRIER_SPACING ;
572    rachCfg.restrictedSetCfg = PRACH_RESTRICTED_SET_CFG;
573    srvCellCfgComm->ulCfg.rachCfg = rachCfg;
574
575    /* Configuring PUSCH Config Common for SIB1 */
576    puschCfg.puschCfgPresent = BWP_UplinkCommon__pusch_ConfigCommon_PR_setup;
577    puschCfg.numTimeDomRsrcAlloc = 2;
578    puschCfg.timeDomAllocList[0].k2 = PUSCH_K2_CFG1;
579    puschCfg.timeDomAllocList[0].mapType = PUSCH_TimeDomainResourceAllocation__mappingType_typeA;
580    puschCfg.timeDomAllocList[0].sliv = calcSliv(PUSCH_START_SYMBOL,PUSCH_LENGTH_SYMBOL);
581    puschCfg.timeDomAllocList[1].k2 = PUSCH_K2_CFG2;
582    puschCfg.timeDomAllocList[1].mapType = PUSCH_TimeDomainResourceAllocation__mappingType_typeA;
583    puschCfg.timeDomAllocList[1].sliv = calcSliv(PUSCH_START_SYMBOL,PUSCH_LENGTH_SYMBOL);
584    puschCfg.msg3DeltaPreamble = PUSCH_MSG3_DELTA_PREAMBLE;
585    puschCfg.p0NominalWithGrant = PUSCH_P0_NOMINAL_WITH_GRANT;
586    srvCellCfgComm->ulCfg.puschCfg = puschCfg;
587
588    /* Configuring PUCCH Config Common for SIB1 */
589    pucchCfg.present = BWP_UplinkCommon__pucch_ConfigCommon_PR_setup;
590    pucchCfg.rsrcComm = PUCCH_RSRC_COMMON;
591    pucchCfg.grpHop = PUCCH_ConfigCommon__pucch_GroupHopping_neither;
592    pucchCfg.p0Nominal = PUCCH_P0_NOMINAL;
593    srvCellCfgComm->ulCfg.pucchCfg = pucchCfg;
594
595    /* Configuring TDD UL DL config common */
596    tddCfg.refScs = SubcarrierSpacing_kHz30;
597    tddCfg.txPrd = TDD_UL_DL_Pattern__dl_UL_TransmissionPeriodicity_ms5;
598    tddCfg.numDlSlots = NUM_DL_SLOTS;
599    tddCfg.numDlSymbols = NUM_DL_SYMBOLS;
600    tddCfg.numUlSlots = NUM_UL_SLOTS;
601    tddCfg.numUlSymbols = NUM_UL_SYMBOLS;
602    srvCellCfgComm->tddCfg = tddCfg;
603
604    srvCellCfgComm->ssbPosInBurst = 192;
605    srvCellCfgComm->ssbPrdServingCell = SSB_PERIODICITY_20MS;
606    srvCellCfgComm->ssPbchBlockPwr = SSB_PBCH_PWR;
607
608    return ROK;
609 }
610
611 /*******************************************************************
612  *
613  * @brief Configures the DU Parameters
614  *
615  * @details
616  *
617  *    Function : readCfg
618  *
619  *    Functionality:
620  *       - Initializes the DuCfg members.  
621  *       - Calls readMacCfg()  
622  *
623  * @params[in] system task ID
624  * @return ROK     - success
625  *         RFAILED - failure
626  *
627  * ****************************************************************/
628
629 uint8_t readCfg()
630 {
631    uint8_t srvdCellIdx, bandIdx, sliceIdx, plmnIdx;
632    uint8_t brdcstPlmnIdx, freqBandIdx, srvdPlmnIdx;
633    uint32_t ipv4_du, ipv4_cu, ipv4_ric;
634    MibParams mib;
635    Sib1Params sib1;
636    F1TaiSliceSuppLst *taiSliceSuppLst;
637
638 #ifndef O1_ENABLE
639    /* Note: Added these below variable for local testing*/
640    Snssai snssai[NUM_OF_SUPPORTED_SLICE] = {{1,{2,3,4}},{5,{6,7,8}}};
641 #endif
642
643 #ifdef O1_ENABLE
644    if( getStartupConfig(&g_cfg) != ROK )
645    {
646       RETVALUE(RFAILED);
647    }
648    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
649    cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
650    cmInetAddr((S8*)g_cfg.RIC_IPV4_Addr, &ipv4_ric);
651
652    duCfgParam.sctpParams.cuPort = g_cfg.CU_Port;
653    duCfgParam.sctpParams.ricPort = g_cfg.RIC_Port;
654 #else   
655    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
656    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
657    cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
658
659    duCfgParam.sctpParams.cuPort = CU_PORT;
660    duCfgParam.sctpParams.ricPort = RIC_PORT;
661 #endif
662
663    fillDuPort(duCfgParam.sctpParams.duPort);
664
665    /* F1 DU IP Address and Port*/
666    duCfgParam.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
667
668    /* F1 CU IP Address and Port*/
669    duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
670
671    /* Fill RIC Params */
672    duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
673
674    /* EGTP Parameters */
675    duCfgParam.egtpParams.localIp.ipV4Pres = TRUE;
676    duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du;
677    duCfgParam.egtpParams.localPort = DU_EGTP_PORT;
678    duCfgParam.egtpParams.destIp.ipV4Pres = TRUE;
679    duCfgParam.egtpParams.destIp.ipV4Addr = ipv4_cu;
680    duCfgParam.egtpParams.destPort = CU_EGTP_PORT;
681    duCfgParam.egtpParams.minTunnelId = MIN_TEID;
682    duCfgParam.egtpParams.maxTunnelId = MAX_TEID;
683
684    duCfgParam.maxUe = 32; //TODO: Check
685    /* DU Info */        
686    duCfgParam.duId = DU_ID;     
687    strcpy((char*)duCfgParam.duName,DU_NAME);
688
689    /* Mib Params */
690    mib.sysFrmNum = SYS_FRAME_NUM;
691 #ifdef NR_TDD
692    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs30or120;
693 #else
694    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs15or60;
695 #endif
696    mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; //Kssb
697    mib.dmrs_TypeA_Position = MIB__dmrs_TypeA_Position_pos2;
698    mib.controlResourceSetZero = CORESET_0_INDEX;
699    mib.searchSpaceZero = SEARCHSPACE_0_INDEX;
700    mib.cellBarred = MIB__cellBarred_notBarred;
701    mib.intraFreqReselection =
702       MIB__intraFreqReselection_notAllowed;
703    duCfgParam.mibParams = mib;
704
705    /* SIB1 Params */
706    memset(&sib1.plmn, 0, sizeof(Plmn));
707    sib1.plmn.mcc[0] = PLMN_MCC0;
708    sib1.plmn.mcc[1] = PLMN_MCC1;
709    sib1.plmn.mcc[2] = PLMN_MCC2;
710    sib1.plmn.mnc[0] = PLMN_MNC0;
711    sib1.plmn.mnc[1] = PLMN_MNC1;
712    sib1.ranac = DU_RANAC;
713
714 #ifdef O1_ENABLE
715    sib1.tac =  cellParams.nRTAC;
716    sib1.cellIdentity =  CELL_IDENTITY *  cellParams.cellLocalId;
717       DU_LOG("\n*********DEBUG --> DU_APP: readCfg(): OAM CellLocalId=%d", \
718               sib1.cellIdentity);
719 #else
720    sib1.tac = DU_TAC;
721    sib1.cellIdentity = CELL_IDENTITY * NR_CELL_ID;
722 #endif
723    sib1.cellResvdForOpUse = PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
724    sib1.connEstFailCnt = ConnEstFailureControl__connEstFailCount_n3;
725    sib1.connEstFailOffValidity = ConnEstFailureControl__connEstFailOffsetValidity_s120;
726    sib1.siSchedInfo.winLen = SI_SchedulingInfo__si_WindowLength_s5;
727    sib1.siSchedInfo.broadcastSta = SchedulingInfo__si_BroadcastStatus_broadcasting;
728    sib1.siSchedInfo.preiodicity = SchedulingInfo__si_Periodicity_rf8;
729    sib1.siSchedInfo.sibType = SIB_TypeInfo__type_sibType2;
730    sib1.siSchedInfo.sibValTag = SIB1_VALUE_TAG;
731
732    fillServCellCfgCommSib(&sib1.srvCellCfgCommSib);
733
734    duCfgParam.sib1Params = sib1;
735
736    for(srvdCellIdx=0; srvdCellIdx<DEFAULT_CELLS; srvdCellIdx++)
737    { 
738       memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn, 0, sizeof(Plmn));
739       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[0] = PLMN_MCC0;
740       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[1] = PLMN_MCC1;
741       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[2] = PLMN_MCC2;
742       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mnc[0] = PLMN_MNC0;
743       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mnc[1] = PLMN_MNC1;
744
745       /*Cell ID */
746  #ifdef O1_ENABLE
747       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrPci = cellParams.nRPCI;
748  #else
749       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrPci = NR_PCI;
750 #endif
751       /* List of Available PLMN */
752       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
753       {
754          /* As per spec 38.473, Plmn identity consists of 3 digit from mcc
755           * followed by either 2 digit or 3 digits of mnc */ 
756
757          memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn, 0,\
758          sizeof(Plmn));
759  #ifdef O1_ENABLE
760          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[0] = cellParams.plmnList[srvdPlmnIdx].mcc[0];
761          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[1] = cellParams.plmnList[srvdPlmnIdx].mcc[1];
762          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[2] = cellParams.plmnList[srvdPlmnIdx].mcc[2];
763          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[0] = cellParams.plmnList[srvdPlmnIdx].mnc[0];
764          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[1] = cellParams.plmnList[srvdPlmnIdx].mnc[1];
765          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[2] = cellParams.plmnList[srvdPlmnIdx].mnc[2];
766  #else
767          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[0] = PLMN_MCC0;
768          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[1] = PLMN_MCC1;
769          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[2] = PLMN_MCC2;
770          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[0] = PLMN_MNC0;
771          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[1] = PLMN_MNC1;
772 #endif
773       }
774       /* List of Extended PLMN */
775       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
776       {
777          /* As per spec 38.473, Plmn identity consists of 3 digit from mcc
778           * followed by either 2 digit or 3 digits of mnc */ 
779
780          memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn, 0, sizeof(Plmn));
781          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[0] = PLMN_MCC0;
782          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[1] = PLMN_MCC1;
783          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[2] = PLMN_MCC2;
784          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mnc[0] = PLMN_MNC0;
785          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mnc[1] = PLMN_MNC1;
786       } 
787       /* List of Supporting Slices */
788       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
789       {
790          taiSliceSuppLst = &duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].\
791          taiSliceSuppLst;
792          
793          /* TODO Calculte the exact number of supported slices once will get
794           * cell configuration from O1 */
795          taiSliceSuppLst->numSupportedSlices = NUM_OF_SUPPORTED_SLICE;
796          if(taiSliceSuppLst->numSupportedSlices > MAX_NUM_OF_SLICE_ITEMS)
797          {
798             DU_LOG("\nERROR --> DU_APP: readCfg(): Number of supported slice [%d] is more than 1024",\
799             taiSliceSuppLst->numSupportedSlices);
800             return RFAILED;
801          }
802
803          DU_ALLOC(taiSliceSuppLst->snssai, taiSliceSuppLst->numSupportedSlices*sizeof(Snssai*));
804          if(taiSliceSuppLst->snssai == NULLP)
805          {
806             DU_LOG("\nERROR --> DU_APP: readCfg():Memory allocation failed");
807             return RFAILED;
808          }
809          
810          for(sliceIdx=0; sliceIdx<taiSliceSuppLst->numSupportedSlices; sliceIdx++)
811          {
812             DU_ALLOC(taiSliceSuppLst->snssai[sliceIdx], sizeof(Snssai));
813             if(taiSliceSuppLst->snssai[sliceIdx] == NULLP)
814             {
815                DU_LOG("\nERROR --> DU_APP: readCfg():Memory allocation failed");
816                return RFAILED;
817             }
818 #ifdef O1_ENABLE
819             memcpy(taiSliceSuppLst->snssai[sliceIdx]->sd, cellParams.plmnList[sliceIdx].sd, \
820 SD_SIZE*sizeof(uint8_t));
821             taiSliceSuppLst->snssai[sliceIdx]->sst = cellParams.plmnList[sliceIdx].sst;
822 #else
823             memcpy(taiSliceSuppLst->snssai[sliceIdx], &snssai[sliceIdx], sizeof(Snssai));
824 #endif
825          }
826       }
827       /* NR Mode info */
828 #ifdef O1_ENABLE
829       /* TAC and EPSTAC */
830       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.epsTac = cellParams.nRTAC; //to check and fill
831       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.tac = cellParams.nRTAC;
832       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn = cellParams.arfcnUL;
833       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulArfcn = cellParams.arfcnSUL;
834 #else
835       /* TAC and EPSTAC */
836       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.epsTac = DU_TAC; //to check and fill
837       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.tac = DU_TAC;
838       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn = NR_UL_ARFCN;
839       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
840 #endif
841       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
842       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
843
844 #if 0
845       /* NR Mode info */
846       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn = NR_ARFCN;
847       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
848       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;                 
849       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;         
850
851       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
852       {
853          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[freqBandIdx].nrFreqBand =\
854          NR_FREQ_BAND;
855          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
856          {
857             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[freqBandIdx].sulBand[bandIdx]\
858             = SUL_BAND;         
859          }
860       }
861 #endif
862       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
863       {
864          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[freqBandIdx].\
865          nrFreqBand = NR_FREQ_BAND;
866          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
867          {
868             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[freqBandIdx].\
869             sulBand[bandIdx] = SUL_BAND;
870          }
871       }
872 #ifdef O1_ENABLE
873       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.nrArfcn = cellParams.arfcnDL;
874       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulArfcn = cellParams.arfcnSUL;
875 #else
876       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.nrArfcn = NR_DL_ARFCN;
877       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
878 #endif
879       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
880       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
881       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
882       {
883          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[freqBandIdx].\
884          nrFreqBand = NR_FREQ_BAND;
885          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
886          {
887             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[freqBandIdx].\
888             sulBand[bandIdx] = SUL_BAND;
889          }
890       }
891
892       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrScs = SCS_15;
893       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrb = NRB_106;
894
895       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrScs = SCS_15;
896       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrb = NRB_106;
897
898       /*Measurement Config and Cell Config */ 
899       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.measTimeCfg = TIME_CFG; 
900
901       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellDir = DL_UL; 
902
903       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellType=CELL_TYPE;
904
905       /* Broadcast PLMN Identity */
906       for(brdcstPlmnIdx=0; brdcstPlmnIdx<MAX_BPLMN_NRCELL_MINUS_1; brdcstPlmnIdx++)
907       { 
908          for(plmnIdx=0; plmnIdx<MAX_PLMN; plmnIdx++)
909          {
910             memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx],\
911             0, sizeof(Plmn));
912             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[0] =\
913             PLMN_MCC0;
914             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[1] =\
915             PLMN_MCC1;
916             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[2] =\
917             PLMN_MCC2;
918             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mnc[0] =\
919             PLMN_MNC0;
920             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mnc[1] =\
921             PLMN_MNC1;
922          }
923          /* Extended PLMN List */        
924          for(plmnIdx=0; plmnIdx<MAX_PLMN; plmnIdx++)
925          {
926             memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
927             extPlmn[plmnIdx], 0, sizeof(Plmn));
928             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
929             extPlmn[plmnIdx].mcc[0] = PLMN_MCC0;
930             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
931             extPlmn[plmnIdx].mcc[1] = PLMN_MCC1;
932             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
933             extPlmn[plmnIdx].mcc[2] = PLMN_MCC2;
934             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
935             extPlmn[plmnIdx].mnc[0] = PLMN_MNC0;
936             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
937             extPlmn[plmnIdx].mnc[1] = PLMN_MNC1;
938          }
939 #ifdef O1_ENABLE
940          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].tac = cellParams.nRTAC;
941          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].nrCellId = cellParams.cellLocalId;
942 #else       
943          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].tac = DU_TAC;
944          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].nrCellId = NR_CELL_ID;
945 #endif     
946          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].ranac = NR_RANAC;
947       }
948
949       /*gnb DU System Info mib msg*/
950       BuildMibMsg();
951       DU_ALLOC(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg, encBufSize);
952       if(!(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg))
953       {
954          DU_LOG("\nERROR  -->  DU APP : Memory allocation failure at readCfg");
955          return RFAILED;
956       }
957       memcpy(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg, encBuf, encBufSize);
958       duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibLen = encBufSize;
959
960       /*gnb DU System Info mib msg*/
961       BuildSib1Msg();
962       DU_ALLOC(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg,\
963             encBufSize);
964       if(!(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg))
965       {
966          DU_LOG("\nERROR  -->  DU APP : Memory allocation failure at readCfg");
967          return RFAILED;
968       }
969       memcpy(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg,\
970             encBuf,encBufSize);
971       duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Len = encBufSize;
972
973    }
974
975    if(readMacCfg() != ROK)
976    {
977       DU_LOG("\nERROR  -->  DU_APP : Failed while reading MAC config");
978       return RFAILED;
979    }
980
981    return ROK;
982 }
983
984 /*******************************************************************
985  *
986  * @brief Copy Slice Cfg in temp structre in duCfgParams 
987  *
988  * @details
989  *
990  *    Function : cpyRrmPolicyInDuCfgParams
991  *
992  *    Functionality:
993  *      - Copy Slice Cfg in temp structre in duCfgParams 
994  *
995  * @params[in] RrmPolicy rrmPolicy[], uint8_t policyNum, uint8_t memberList
996  * @return ROK     - success
997  *         RFAILED - failure
998  *
999  * ****************************************************************/
1000 #ifdef O1_ENABLE
1001 uint8_t cpyRrmPolicyInDuCfgParams(RrmPolicyList rrmPolicy[], uint8_t policyNum, CopyOfRecvdSliceCfg *tempSliceCfg)
1002 {
1003    uint8_t policyIdx = 0, memberListIdx = 0, count = 0;
1004
1005    if(policyNum)
1006    {
1007       tempSliceCfg->totalRrmPolicy = policyNum;
1008       DU_ALLOC(tempSliceCfg->rrmPolicy, tempSliceCfg->totalRrmPolicy * sizeof(RrmPolicy*));
1009       if(tempSliceCfg->rrmPolicy == NULLP)
1010       {
1011          DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1012          return RFAILED;
1013       }
1014
1015       for(policyIdx = 0; policyIdx<tempSliceCfg->totalRrmPolicy; policyIdx++)
1016       {
1017          DU_ALLOC(tempSliceCfg->rrmPolicy[policyIdx],  sizeof(RrmPolicy));
1018          if(tempSliceCfg->rrmPolicy[policyIdx] == NULLP)
1019          {
1020             DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1021             return RFAILED;
1022          }
1023          
1024          if(rrmPolicy[policyIdx].rRMMemberNum)
1025          {
1026             tempSliceCfg->rrmPolicy[policyIdx]->numMemberList = rrmPolicy[policyIdx].rRMMemberNum;  
1027             DU_ALLOC(tempSliceCfg->rrmPolicy[policyIdx]->memberList, tempSliceCfg->rrmPolicy[policyIdx]->numMemberList * sizeof(PolicyMemberList*))
1028             if(tempSliceCfg->rrmPolicy[policyIdx]->memberList == NULLP)
1029             {
1030                DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1031                return RFAILED;
1032             }
1033
1034             for(memberListIdx = 0; memberListIdx<tempSliceCfg->rrmPolicy[policyIdx]->numMemberList; memberListIdx++)
1035             {
1036                DU_ALLOC(tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx], sizeof(PolicyMemberList))
1037                if(tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx] == NULLP)
1038                {
1039                   DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1040                   return RFAILED;
1041                }
1042                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->snssai.sd, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].sd, 3 * sizeof(uint8_t));
1043                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->snssai.sst, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].sst, sizeof(uint8_t));
1044                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->plmn.mcc, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].mcc, 3 * sizeof(uint8_t));
1045                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->plmn.mnc, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].mnc, 3 * sizeof(uint8_t));
1046                count++;
1047             }
1048          }
1049          
1050          tempSliceCfg->rrmPolicy[policyIdx]->rsrcType  = rrmPolicy[policyIdx].resourceType;
1051          tempSliceCfg->rrmPolicy[policyIdx]->policyMaxRatio = rrmPolicy[policyIdx].rRMPolicyMaxRatio;
1052          tempSliceCfg->rrmPolicy[policyIdx]->policyMinRatio = rrmPolicy[policyIdx].rRMPolicyMinRatio;
1053          tempSliceCfg->rrmPolicy[policyIdx]->policyDedicatedRatio = rrmPolicy[policyIdx].rRMPolicyDedicatedRatio;
1054
1055       }
1056       tempSliceCfg->totalSliceCount = count;
1057    }
1058    return ROK;
1059 }
1060 #endif
1061 /*******************************************************************
1062  *
1063  * @brief Reads config and posts message to du_app on completion
1064  *
1065  * @details
1066  *
1067  *    Function : main
1068  *
1069  *    Functionality:
1070  *      - Calls readCfg()
1071  *      - Post to du_app for further processing
1072  *
1073  * @params[in] void
1074  * @return ROK     - success
1075  *         RFAILED - failure
1076  *
1077  * ****************************************************************/
1078 uint8_t duReadCfg()
1079 {
1080    Pst pst;
1081    Buffer *mBuf;
1082
1083    memset(&duCfgParam, 0, sizeof(DuCfgParams));
1084
1085    //Read configs into duCfgParams
1086    if(readCfg() != ROK)
1087    {
1088       DU_LOG("\nERROR  -->  DU_APP : Reading configuration failed");
1089       return RFAILED;
1090    }
1091
1092    //Fill pst structure
1093    memset(&(pst), 0, sizeof(Pst));
1094    pst.srcEnt = (Ent)ENTDUAPP;
1095    pst.srcInst = (Inst)DU_INST;
1096    pst.srcProcId = DU_PROC;
1097    pst.dstEnt = pst.srcEnt;
1098    pst.dstInst = pst.srcInst;
1099    pst.dstProcId = pst.srcProcId;
1100    pst.event = EVTCFG;
1101    pst.selector = ODU_SELECTOR_TC;
1102    pst.pool= DU_POOL;
1103
1104
1105    if(ODU_GET_MSG_BUF(DFLT_REGION, DU_POOL, &mBuf) != ROK)
1106    {
1107       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in duReadCfg");
1108       return RFAILED;
1109    }
1110
1111    if (ODU_POST_TASK(&pst, mBuf) != ROK)
1112    {
1113       DU_LOG("\nERROR  -->  DU_APP : ODU_POST_TASK failed in duReadCfg");
1114       return RFAILED;
1115    }
1116
1117    return ROK;
1118 }
1119
1120 /**********************************************************************
1121   End of file
1122  **********************************************************************/
1123