f5ee3b34388cff0ab3e8448397f7f0ad76c4fd56
[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    /* TODO Added these below variable for local testing, once we will receive the
639     * configuration from O1 we can remove these variable */
640    Snssai snssai[NUM_OF_SUPPORTED_SLICE] = {{1,{2,3,4}},{5,{6,7,8}}};
641
642 #ifdef O1_ENABLE
643    if( getStartupConfig(&g_cfg) != ROK )
644    {
645       RETVALUE(RFAILED);
646    }
647    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
648    cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
649    cmInetAddr((S8*)g_cfg.RIC_IPV4_Addr, &ipv4_ric);
650
651    duCfgParam.sctpParams.cuPort = g_cfg.CU_Port;
652    duCfgParam.sctpParams.ricPort = g_cfg.RIC_Port;
653 #else   
654    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
655    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
656    cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
657
658    duCfgParam.sctpParams.cuPort = CU_PORT;
659    duCfgParam.sctpParams.ricPort = RIC_PORT;
660 #endif
661
662    fillDuPort(duCfgParam.sctpParams.duPort);
663
664    /* F1 DU IP Address and Port*/
665    duCfgParam.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
666
667    /* F1 CU IP Address and Port*/
668    duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
669
670    /* Fill RIC Params */
671    duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
672
673    /* EGTP Parameters */
674    duCfgParam.egtpParams.localIp.ipV4Pres = TRUE;
675    duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du;
676    duCfgParam.egtpParams.localPort = DU_EGTP_PORT;
677    duCfgParam.egtpParams.destIp.ipV4Pres = TRUE;
678    duCfgParam.egtpParams.destIp.ipV4Addr = ipv4_cu;
679    duCfgParam.egtpParams.destPort = CU_EGTP_PORT;
680    duCfgParam.egtpParams.minTunnelId = MIN_TEID;
681    duCfgParam.egtpParams.maxTunnelId = MAX_TEID;
682
683    duCfgParam.maxUe = 32; //TODO: Check
684    /* DU Info */        
685    duCfgParam.duId = DU_ID;     
686    strcpy((char*)duCfgParam.duName,DU_NAME);
687
688    /* Mib Params */
689    mib.sysFrmNum = SYS_FRAME_NUM;
690 #ifdef NR_TDD
691    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs30or120;
692 #else
693    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs15or60;
694 #endif
695    mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; //Kssb
696    mib.dmrs_TypeA_Position = MIB__dmrs_TypeA_Position_pos2;
697    mib.controlResourceSetZero = CORESET_0_INDEX;
698    mib.searchSpaceZero = SEARCHSPACE_0_INDEX;
699    mib.cellBarred = MIB__cellBarred_notBarred;
700    mib.intraFreqReselection =
701       MIB__intraFreqReselection_notAllowed;
702    duCfgParam.mibParams = mib;
703
704    /* SIB1 Params */
705    memset(&sib1.plmn, 0, sizeof(Plmn));
706    sib1.plmn.mcc[0] = PLMN_MCC0;
707    sib1.plmn.mcc[1] = PLMN_MCC1;
708    sib1.plmn.mcc[2] = PLMN_MCC2;
709    sib1.plmn.mnc[0] = PLMN_MNC0;
710    sib1.plmn.mnc[1] = PLMN_MNC1;
711    sib1.ranac = DU_RANAC;
712
713 #ifdef O1_ENABLE
714    sib1.tac =  cellParams.nRTAC;
715    sib1.cellIdentity =  CELL_IDENTITY *  cellParams.cellLocalId;
716       DU_LOG("\n*********DEBUG --> DU_APP: readCfg(): OAM CellLocalId=%d", \
717               sib1.cellIdentity);
718 #else
719    sib1.tac = DU_TAC;
720    sib1.cellIdentity = CELL_IDENTITY * NR_CELL_ID;
721 #endif
722    sib1.cellResvdForOpUse = PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
723    sib1.connEstFailCnt = ConnEstFailureControl__connEstFailCount_n3;
724    sib1.connEstFailOffValidity = ConnEstFailureControl__connEstFailOffsetValidity_s120;
725    sib1.siSchedInfo.winLen = SI_SchedulingInfo__si_WindowLength_s5;
726    sib1.siSchedInfo.broadcastSta = SchedulingInfo__si_BroadcastStatus_broadcasting;
727    sib1.siSchedInfo.preiodicity = SchedulingInfo__si_Periodicity_rf8;
728    sib1.siSchedInfo.sibType = SIB_TypeInfo__type_sibType2;
729    sib1.siSchedInfo.sibValTag = SIB1_VALUE_TAG;
730
731    fillServCellCfgCommSib(&sib1.srvCellCfgCommSib);
732
733    duCfgParam.sib1Params = sib1;
734
735    for(srvdCellIdx=0; srvdCellIdx<DEFAULT_CELLS; srvdCellIdx++)
736    { 
737       memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn, 0, sizeof(Plmn));
738       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[0] = PLMN_MCC0;
739       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[1] = PLMN_MCC1;
740       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[2] = PLMN_MCC2;
741       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mnc[0] = PLMN_MNC0;
742       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mnc[1] = PLMN_MNC1;
743
744       /*Cell ID */
745  #ifdef O1_ENABLE
746       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrPci = cellParams.nRPCI;
747  #else
748       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrPci = NR_PCI;
749 #endif
750       /* List of Available PLMN */
751       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
752       {
753          /* As per spec 38.473, Plmn identity consists of 3 digit from mcc
754           * followed by either 2 digit or 3 digits of mnc */ 
755
756          memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn, 0,\
757          sizeof(Plmn));
758  #ifdef O1_ENABLE
759          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[0] = cellParams.plmnList[srvdPlmnIdx].mcc[0];
760          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[1] = cellParams.plmnList[srvdPlmnIdx].mcc[1];
761          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[2] = cellParams.plmnList[srvdPlmnIdx].mcc[2];
762          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[0] = cellParams.plmnList[srvdPlmnIdx].mnc[0];
763          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[1] = cellParams.plmnList[srvdPlmnIdx].mnc[1];
764          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[2] = cellParams.plmnList[srvdPlmnIdx].mnc[2];
765  #else
766          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[0] = PLMN_MCC0;
767          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[1] = PLMN_MCC1;
768          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[2] = PLMN_MCC2;
769          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[0] = PLMN_MNC0;
770          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[1] = PLMN_MNC1;
771 #endif
772       }
773       /* List of Extended PLMN */
774       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
775       {
776          /* As per spec 38.473, Plmn identity consists of 3 digit from mcc
777           * followed by either 2 digit or 3 digits of mnc */ 
778
779          memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn, 0, sizeof(Plmn));
780          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[0] = PLMN_MCC0;
781          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[1] = PLMN_MCC1;
782          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[2] = PLMN_MCC2;
783          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mnc[0] = PLMN_MNC0;
784          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mnc[1] = PLMN_MNC1;
785       } 
786       /* List of Supporting Slices */
787       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
788       {
789          taiSliceSuppLst = &duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].\
790          taiSliceSuppLst;
791          
792          /* TODO Calculte the exact number of supported slices once will get
793           * cell configuration from O1 */
794          taiSliceSuppLst->numSupportedSlices = NUM_OF_SUPPORTED_SLICE;
795          if(taiSliceSuppLst->numSupportedSlices > MAX_NUM_OF_SLICE_ITEMS)
796          {
797             DU_LOG("\nERROR --> DU_APP: readCfg(): Number of supported slice [%d] is more than 1024",\
798             taiSliceSuppLst->numSupportedSlices);
799             return RFAILED;
800          }
801
802          DU_ALLOC(taiSliceSuppLst->snssai, taiSliceSuppLst->numSupportedSlices*sizeof(Snssai*));
803          if(taiSliceSuppLst->snssai == NULLP)
804          {
805             DU_LOG("\nERROR --> DU_APP: readCfg():Memory allocation failed");
806             return RFAILED;
807          }
808          
809          for(sliceIdx=0; sliceIdx<taiSliceSuppLst->numSupportedSlices; sliceIdx++)
810          {
811             DU_ALLOC(taiSliceSuppLst->snssai[sliceIdx], sizeof(Snssai));
812             if(taiSliceSuppLst->snssai[sliceIdx] == NULLP)
813             {
814                DU_LOG("\nERROR --> DU_APP: readCfg():Memory allocation failed");
815                return RFAILED;
816             }
817 #ifdef O1_ENABLE
818             memcpy(taiSliceSuppLst->snssai[sliceIdx]->sd, cellParams.plmnList[sliceIdx].sd, \
819 SD_SIZE*sizeof(uint8_t));
820             taiSliceSuppLst->snssai[sliceIdx]->sst = cellParams.plmnList[sliceIdx].sst;
821 #else
822             memcpy(taiSliceSuppLst->snssai[sliceIdx], &snssai[sliceIdx], sizeof(Snssai));
823 #endif
824          }
825       }
826       /* NR Mode info */
827 #ifdef O1_ENABLE
828       /* TAC and EPSTAC */
829       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.epsTac = cellParams.nRTAC; //to check and fill
830       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.tac = cellParams.nRTAC;
831       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn = cellParams.arfcnUL;
832       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulArfcn = cellParams.arfcnSUL;
833 #else
834       /* TAC and EPSTAC */
835       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.epsTac = DU_TAC; //to check and fill
836       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.tac = DU_TAC;
837       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn = NR_UL_ARFCN;
838       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
839 #endif
840       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
841       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
842
843 #if 0
844       /* NR Mode info */
845       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn = NR_ARFCN;
846       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
847       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;                 
848       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;         
849
850       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
851       {
852          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[freqBandIdx].nrFreqBand =\
853          NR_FREQ_BAND;
854          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
855          {
856             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[freqBandIdx].sulBand[bandIdx]\
857             = SUL_BAND;         
858          }
859       }
860 #endif
861       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
862       {
863          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[freqBandIdx].\
864          nrFreqBand = NR_FREQ_BAND;
865          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
866          {
867             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[freqBandIdx].\
868             sulBand[bandIdx] = SUL_BAND;
869          }
870       }
871 #ifdef O1_ENABLE
872       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.nrArfcn = cellParams.arfcnDL;
873       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulArfcn = cellParams.arfcnSUL;
874 #else
875       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.nrArfcn = NR_DL_ARFCN;
876       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
877 #endif
878       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
879       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
880       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
881       {
882          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[freqBandIdx].\
883          nrFreqBand = NR_FREQ_BAND;
884          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
885          {
886             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[freqBandIdx].\
887             sulBand[bandIdx] = SUL_BAND;
888          }
889       }
890
891       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrScs = SCS_15;
892       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrb = NRB_106;
893
894       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrScs = SCS_15;
895       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrb = NRB_106;
896
897       /*Measurement Config and Cell Config */ 
898       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.measTimeCfg = TIME_CFG; 
899
900       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellDir = DL_UL; 
901
902       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellType=CELL_TYPE;
903
904       /* Broadcast PLMN Identity */
905       for(brdcstPlmnIdx=0; brdcstPlmnIdx<MAX_BPLMN_NRCELL_MINUS_1; brdcstPlmnIdx++)
906       { 
907          for(plmnIdx=0; plmnIdx<MAX_PLMN; plmnIdx++)
908          {
909             memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx],\
910             0, sizeof(Plmn));
911             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[0] =\
912             PLMN_MCC0;
913             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[1] =\
914             PLMN_MCC1;
915             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[2] =\
916             PLMN_MCC2;
917             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mnc[0] =\
918             PLMN_MNC0;
919             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mnc[1] =\
920             PLMN_MNC1;
921          }
922          /* Extended PLMN List */        
923          for(plmnIdx=0; plmnIdx<MAX_PLMN; plmnIdx++)
924          {
925             memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
926             extPlmn[plmnIdx], 0, sizeof(Plmn));
927             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
928             extPlmn[plmnIdx].mcc[0] = PLMN_MCC0;
929             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
930             extPlmn[plmnIdx].mcc[1] = PLMN_MCC1;
931             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
932             extPlmn[plmnIdx].mcc[2] = PLMN_MCC2;
933             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
934             extPlmn[plmnIdx].mnc[0] = PLMN_MNC0;
935             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
936             extPlmn[plmnIdx].mnc[1] = PLMN_MNC1;
937          }
938 #ifdef O1_ENABLE
939          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].tac = cellParams.nRTAC;
940          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].nrCellId = cellParams.cellLocalId;
941 #else       
942          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].tac = DU_TAC;
943          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].nrCellId = NR_CELL_ID;
944 #endif     
945          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].ranac = NR_RANAC;
946       }
947
948       /*gnb DU System Info mib msg*/
949       BuildMibMsg();
950       DU_ALLOC(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg, encBufSize);
951       if(!(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg))
952       {
953          DU_LOG("\nERROR  -->  DU APP : Memory allocation failure at readCfg");
954          return RFAILED;
955       }
956       memcpy(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg, encBuf, encBufSize);
957       duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibLen = encBufSize;
958
959       /*gnb DU System Info mib msg*/
960       BuildSib1Msg();
961       DU_ALLOC(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg,\
962             encBufSize);
963       if(!(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg))
964       {
965          DU_LOG("\nERROR  -->  DU APP : Memory allocation failure at readCfg");
966          return RFAILED;
967       }
968       memcpy(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg,\
969             encBuf,encBufSize);
970       duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Len = encBufSize;
971
972    }
973
974    if(readMacCfg() != ROK)
975    {
976       DU_LOG("\nERROR  -->  DU_APP : Failed while reading MAC config");
977       return RFAILED;
978    }
979
980    return ROK;
981 }
982
983 /*******************************************************************
984  *
985  * @brief Copy Slice Cfg in temp structre in duCfgParams 
986  *
987  * @details
988  *
989  *    Function : cpyRrmPolicyInDuCfgParams
990  *
991  *    Functionality:
992  *      - Copy Slice Cfg in temp structre in duCfgParams 
993  *
994  * @params[in] RrmPolicy rrmPolicy[], uint8_t policyNum, uint8_t memberList
995  * @return ROK     - success
996  *         RFAILED - failure
997  *
998  * ****************************************************************/
999 #ifdef O1_ENABLE
1000 uint8_t cpyRrmPolicyInDuCfgParams(RrmPolicyList rrmPolicy[], uint8_t policyNum, CopyOfRecvdSliceCfg *tempSliceCfg)
1001 {
1002    uint8_t policyIdx = 0, memberListIdx = 0, count = 0;
1003
1004    if(policyNum)
1005    {
1006       tempSliceCfg->totalRrmPolicy = policyNum;
1007       DU_ALLOC(tempSliceCfg->rrmPolicy, tempSliceCfg->totalRrmPolicy * sizeof(RrmPolicy*));
1008       if(tempSliceCfg->rrmPolicy == NULLP)
1009       {
1010          DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1011          return RFAILED;
1012       }
1013
1014       for(policyIdx = 0; policyIdx<tempSliceCfg->totalRrmPolicy; policyIdx++)
1015       {
1016          DU_ALLOC(tempSliceCfg->rrmPolicy[policyIdx],  sizeof(RrmPolicy));
1017          if(tempSliceCfg->rrmPolicy[policyIdx] == NULLP)
1018          {
1019             DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1020             return RFAILED;
1021          }
1022          
1023          if(rrmPolicy[policyIdx].rRMMemberNum)
1024          {
1025             tempSliceCfg->rrmPolicy[policyIdx]->numMemberList = rrmPolicy[policyIdx].rRMMemberNum;  
1026             DU_ALLOC(tempSliceCfg->rrmPolicy[policyIdx]->memberList, tempSliceCfg->rrmPolicy[policyIdx]->numMemberList * sizeof(PolicyMemberList*))
1027             if(tempSliceCfg->rrmPolicy[policyIdx]->memberList == NULLP)
1028             {
1029                DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1030                return RFAILED;
1031             }
1032
1033             for(memberListIdx = 0; memberListIdx<tempSliceCfg->rrmPolicy[policyIdx]->numMemberList; memberListIdx++)
1034             {
1035                DU_ALLOC(tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx], sizeof(PolicyMemberList))
1036                if(tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx] == NULLP)
1037                {
1038                   DU_LOG("\nERROR  --> DU APP : Memory allocation failed in cpyRrmPolicyInDuCfgParams");
1039                   return RFAILED;
1040                }
1041                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->snssai.sd, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].sd, 3 * sizeof(uint8_t));
1042                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->snssai.sst, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].sst, sizeof(uint8_t));
1043                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->plmn.mcc, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].mcc, 3 * sizeof(uint8_t));
1044                memcpy(&tempSliceCfg->rrmPolicy[policyIdx]->memberList[memberListIdx]->plmn.mnc, &rrmPolicy[policyIdx].rRMPolicyMemberList[memberListIdx].mnc, 3 * sizeof(uint8_t));
1045                count++;
1046             }
1047          }
1048          
1049          tempSliceCfg->rrmPolicy[policyIdx]->rsrcType  = rrmPolicy[policyIdx].resourceType;
1050          tempSliceCfg->rrmPolicy[policyIdx]->policyMaxRatio = rrmPolicy[policyIdx].rRMPolicyMaxRatio;
1051          tempSliceCfg->rrmPolicy[policyIdx]->policyMinRatio = rrmPolicy[policyIdx].rRMPolicyMinRatio;
1052          tempSliceCfg->rrmPolicy[policyIdx]->policyDedicatedRatio = rrmPolicy[policyIdx].rRMPolicyDedicatedRatio;
1053
1054       }
1055       tempSliceCfg->totalSliceCount = count;
1056    }
1057    return ROK;
1058 }
1059 #endif
1060 /*******************************************************************
1061  *
1062  * @brief Reads config and posts message to du_app on completion
1063  *
1064  * @details
1065  *
1066  *    Function : main
1067  *
1068  *    Functionality:
1069  *      - Calls readCfg()
1070  *      - Post to du_app for further processing
1071  *
1072  * @params[in] void
1073  * @return ROK     - success
1074  *         RFAILED - failure
1075  *
1076  * ****************************************************************/
1077 uint8_t duReadCfg()
1078 {
1079    Pst pst;
1080    Buffer *mBuf;
1081
1082    memset(&duCfgParam, 0, sizeof(DuCfgParams));
1083
1084    //Read configs into duCfgParams
1085    if(readCfg() != ROK)
1086    {
1087       DU_LOG("\nERROR  -->  DU_APP : Reading configuration failed");
1088       return RFAILED;
1089    }
1090
1091    //Fill pst structure
1092    memset(&(pst), 0, sizeof(Pst));
1093    pst.srcEnt = (Ent)ENTDUAPP;
1094    pst.srcInst = (Inst)DU_INST;
1095    pst.srcProcId = DU_PROC;
1096    pst.dstEnt = pst.srcEnt;
1097    pst.dstInst = pst.srcInst;
1098    pst.dstProcId = pst.srcProcId;
1099    pst.event = EVTCFG;
1100    pst.selector = ODU_SELECTOR_TC;
1101    pst.pool= DU_POOL;
1102
1103
1104    if(ODU_GET_MSG_BUF(DFLT_REGION, DU_POOL, &mBuf) != ROK)
1105    {
1106       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in duReadCfg");
1107       return RFAILED;
1108    }
1109
1110    if (ODU_POST_TASK(&pst, mBuf) != ROK)
1111    {
1112       DU_LOG("\nERROR  -->  DU_APP : ODU_POST_TASK failed in duReadCfg");
1113       return RFAILED;
1114    }
1115
1116    return ROK;
1117 }
1118
1119 /**********************************************************************
1120   End of file
1121  **********************************************************************/
1122