[Jira Id - ODUHIGH-373 ] Implementation of RRM Policy Configuration Per Slice
[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 "ConfigInterface.h"
57 extern StartupConfig g_cfg;
58 #endif
59
60 DuCfgParams duCfgParam;
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.cellId = NR_CELL_ID;
152    duCfgParam.macCellCfg.phyCellId = NR_PCI;
153    duCfgParam.macCellCfg.numerology = NR_NUMEROLOGY;
154    duCfgParam.macCellCfg.dupType = DUPLEX_MODE;
155
156    /* DL carrier configuration */
157    duCfgParam.macCellCfg.dlCarrCfg.pres = TRUE;
158 #ifdef NR_TDD
159    duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH_100MHZ;
160 #else
161    duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH_20MHZ;
162 #endif
163    duCfgParam.macCellCfg.dlCarrCfg.freq = NR_DL_ARFCN;
164    duCfgParam.macCellCfg.dlCarrCfg.k0[0] = 1;
165    duCfgParam.macCellCfg.dlCarrCfg.k0[1] = 1;
166    duCfgParam.macCellCfg.dlCarrCfg.k0[2] = 1;
167    duCfgParam.macCellCfg.dlCarrCfg.k0[3] = 1;
168    duCfgParam.macCellCfg.dlCarrCfg.k0[4] = 1;
169    duCfgParam.macCellCfg.dlCarrCfg.gridSize[0] = 273;
170    duCfgParam.macCellCfg.dlCarrCfg.gridSize[1] = 1;
171    duCfgParam.macCellCfg.dlCarrCfg.gridSize[2] = 1;
172    duCfgParam.macCellCfg.dlCarrCfg.gridSize[3] = 1;
173    duCfgParam.macCellCfg.dlCarrCfg.gridSize[4] = 1;
174    duCfgParam.macCellCfg.dlCarrCfg.numAnt = NUM_TX_ANT;
175
176    /* UL Carrier configuration */
177    duCfgParam.macCellCfg.ulCarrCfg.pres = TRUE;
178 #ifdef NR_TDD
179    duCfgParam.macCellCfg.dlCarrCfg.bw = BANDWIDTH_100MHZ;
180 #else
181    duCfgParam.macCellCfg.ulCarrCfg.bw = BANDWIDTH_20MHZ;
182 #endif
183    duCfgParam.macCellCfg.ulCarrCfg.freq = NR_UL_ARFCN;
184    duCfgParam.macCellCfg.ulCarrCfg.k0[0] = 1;
185    duCfgParam.macCellCfg.ulCarrCfg.k0[1] = 1;
186    duCfgParam.macCellCfg.ulCarrCfg.k0[2] = 1;
187    duCfgParam.macCellCfg.ulCarrCfg.k0[3] = 1;
188    duCfgParam.macCellCfg.ulCarrCfg.k0[4] = 1;
189    duCfgParam.macCellCfg.ulCarrCfg.gridSize[0] = 1;
190    duCfgParam.macCellCfg.ulCarrCfg.gridSize[1] = 1;
191    duCfgParam.macCellCfg.ulCarrCfg.gridSize[2] = 1;
192    duCfgParam.macCellCfg.ulCarrCfg.gridSize[3] = 1;
193    duCfgParam.macCellCfg.ulCarrCfg.gridSize[4] = 1;
194    duCfgParam.macCellCfg.ulCarrCfg.numAnt = NUM_RX_ANT;
195
196    duCfgParam.macCellCfg.freqShft = FREQ_SHIFT_7P5KHZ;
197
198    /* SSB configuration */
199    duCfgParam.macCellCfg.ssbCfg.ssbPbchPwr = SSB_PBCH_PWR;
200    duCfgParam.macCellCfg.ssbCfg.bchPayloadFlag = BCH_PAYLOAD;
201 #ifdef NR_TDD
202    duCfgParam.macCellCfg.ssbCfg.scsCmn = SCS_30KHZ;
203 #else
204    duCfgParam.macCellCfg.ssbCfg.scsCmn = SCS_15KHZ;
205 #endif
206    duCfgParam.macCellCfg.ssbCfg.ssbOffsetPointA = OFFSET_TO_POINT_A;
207    duCfgParam.macCellCfg.ssbCfg.betaPss = BETA_PSS;
208    duCfgParam.macCellCfg.ssbCfg.ssbPeriod = SSB_PRDCTY_MS_20;
209    duCfgParam.macCellCfg.ssbCfg.ssbScOffset = SSB_SUBCARRIER_OFFSET;
210    duCfgParam.macCellCfg.ssbCfg.ssbMask[0] = 1; /* only one SSB is transmitted */
211    duCfgParam.macCellCfg.ssbCfg.ssbMask[1] = 0;
212    if(BuildMibPdu() != ROK)
213    {
214       DU_LOG("\nERROR  -->  Failed to build MIB PDU");
215       memset(&duCfgParam.macCellCfg.ssbCfg.mibPdu, 0, 3*sizeof(uint8_t));
216    }
217    else
218    {
219       memcpy(&duCfgParam.macCellCfg.ssbCfg.mibPdu, encBuf,encBufSize);
220    }
221    duCfgParam.macCellCfg.ssbCfg.multCarrBand = SSB_MULT_CARRIER_BAND;
222    duCfgParam.macCellCfg.ssbCfg.multCellCarr = MULT_CELL_CARRIER;
223
224    /* PRACH configuration */
225    duCfgParam.macCellCfg.prachCfg.pres = TRUE;
226    duCfgParam.macCellCfg.prachCfg.prachCfgIdx = PRACH_CONFIG_IDX;
227    duCfgParam.macCellCfg.prachCfg.prachSeqLen = PRACH_SEQ_LEN;
228    duCfgParam.macCellCfg.prachCfg.prachSubcSpacing = PRACH_SUBCARRIER_SPACING;
229    duCfgParam.macCellCfg.prachCfg.prachRstSetCfg = PRACH_RESTRICTED_SET_CFG;
230    duCfgParam.macCellCfg.prachCfg.msg1Fdm = NUM_PRACH_FDM;
231    duCfgParam.macCellCfg.prachCfg.msg1FreqStart = PRACH_FREQ_START;
232    duCfgParam.macCellCfg.prachCfg.rootSeqLen    = ROOT_SEQ_LEN;
233    duCfgParam.macCellCfg.prachCfg.fdm[0].rootSeqIdx = ROOT_SEQ_IDX;
234    duCfgParam.macCellCfg.prachCfg.fdm[0].numRootSeq = NUM_ROOT_SEQ;
235    duCfgParam.macCellCfg.prachCfg.fdm[0].k1 = 0;
236    duCfgParam.macCellCfg.prachCfg.fdm[0].zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG;
237    duCfgParam.macCellCfg.prachCfg.fdm[0].numUnusedRootSeq = NUM_UNUSED_ROOT_SEQ;
238    if(duCfgParam.macCellCfg.prachCfg.fdm[0].numUnusedRootSeq != 0)
239    {
240         DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq, 
241         NUM_UNUSED_ROOT_SEQ * sizeof(uint8_t));
242         if(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq == NULLP)
243         {
244             DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed at readMacCfg");
245             return RFAILED;
246         }
247         *(duCfgParam.macCellCfg.prachCfg.fdm[0].unsuedRootSeq) = UNUSED_ROOT_SEQ;
248     }
249    duCfgParam.macCellCfg.prachCfg.ssbPerRach = SSB_PER_RACH;
250    duCfgParam.macCellCfg.prachCfg.prachMultCarrBand = PRACH_MULT_CARRIER_BAND;
251    duCfgParam.macCellCfg.prachCfg.raContResTmr = RA_CONT_RES_TIMER;
252    duCfgParam.macCellCfg.prachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB;
253    duCfgParam.macCellCfg.prachCfg.raRspWindow = RA_RSP_WINDOW;
254    duCfgParam.macCellCfg.prachCfg.prachRestrictedSet = PRACH_RESTRICTED_SET;
255 #ifdef NR_TDD   
256    /* TDD configuration */
257    duCfgParam.macCellCfg.tddCfg.pres = TRUE;
258    duCfgParam.macCellCfg.tddCfg.tddPeriod = TDD_PERIODICITY;
259
260    FillSlotConfig();
261
262 #endif
263    /* RSSI Measurement configuration */
264    duCfgParam.macCellCfg.rssiUnit = RSS_MEASUREMENT_UNIT;
265
266    /* fill SIB1 configuration */
267    duCfgParam.macCellCfg.sib1Cfg.sib1PduLen = duCfgParam.srvdCellLst[0].duSysInfo.sib1Len;
268    DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu,duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
269    memcpy(duCfgParam.macCellCfg.sib1Cfg.sib1Pdu, duCfgParam.srvdCellLst[0].duSysInfo.sib1Msg, \
270          duCfgParam.srvdCellLst[0].duSysInfo.sib1Len);
271    duCfgParam.macCellCfg.sib1Cfg.sib1RepetitionPeriod = SIB1_REPETITION_PERIOD;
272    duCfgParam.macCellCfg.sib1Cfg.coresetZeroIndex = CORESET_0_INDEX;
273    duCfgParam.macCellCfg.sib1Cfg.searchSpaceZeroIndex = SEARCHSPACE_0_INDEX;
274    duCfgParam.macCellCfg.sib1Cfg.sib1Mcs = SIB1_MCS;
275
276
277    /* fill Intial DL BWP */
278    duCfgParam.macCellCfg.initialDlBwp.bwp.firstPrb = 0;
279    duCfgParam.macCellCfg.initialDlBwp.bwp.numPrb = TOTAL_PRB_20MHZ_MU0; /* configured to total BW */
280 #ifdef NR_TDD
281    duCfgParam.macCellCfg.initialDlBwp.bwp.scs = SCS_30KHZ; /* numerology is 1, 30Khz */
282 #else
283    duCfgParam.macCellCfg.initialDlBwp.bwp.scs = SCS_15KHZ; /* numerology is 0, 15Khz */
284 #endif
285    duCfgParam.macCellCfg.initialDlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
286    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.searchSpaceId = SEARCHSPACE_1_INDEX;
287    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.coresetId = CORESET_0_INDEX;
288    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSlot =
289       SS_MONITORING_SLOT_SL1; /* sl1 - all slots */
290    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.duration = 0;
291    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.monitoringSymbol =
292       SS_MONITORING_SYMBOL;
293    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
294       candidate.aggLevel1       = 8;
295    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
296       candidate.aggLevel2       = 4;
297    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
298       candidate.aggLevel4       = 2;
299    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
300       candidate.aggLevel8       = 1;
301    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.commonSearchSpace.
302       candidate.aggLevel16      = 0;
303
304    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.numTimeDomAlloc = 2;
305    idx = 0;
306    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].k0 = PDSCH_K0_CFG1;
307    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].mappingType = 
308       PDSCH_MAPPING_TYPE_A;
309    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].startSymbol = 
310       PDSCH_START_SYMBOL;
311    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].lengthSymbol =
312       PDSCH_LENGTH_SYMBOL;
313  
314    idx++;
315    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].k0 = PDSCH_K0_CFG2;
316    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].mappingType = 
317       PDSCH_MAPPING_TYPE_A;
318    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].startSymbol = 
319       PDSCH_START_SYMBOL;
320    duCfgParam.macCellCfg.initialDlBwp.pdschCommon.timeDomRsrcAllocList[idx].lengthSymbol =
321       PDSCH_LENGTH_SYMBOL;
322
323    /* ra-searchSpace ID is set to 1 */
324    duCfgParam.macCellCfg.initialDlBwp.pdcchCommon.raSearchSpaceId = SEARCHSPACE_1_INDEX;
325
326    /* fill Intial UL BWP */
327    duCfgParam.macCellCfg.initialUlBwp.bwp.firstPrb = 0;
328    duCfgParam.macCellCfg.initialUlBwp.bwp.numPrb = TOTAL_PRB_20MHZ_MU0; /* configured to total BW */
329 #ifdef NR_TDD
330    duCfgParam.macCellCfg.initialUlBwp.bwp.scs = SCS_30KHZ; /* numerology is 1, 30Khz */
331 #else
332    duCfgParam.macCellCfg.initialUlBwp.bwp.scs = SCS_15KHZ; /* numerology is 0, 15Khz */
333 #endif
334    duCfgParam.macCellCfg.initialUlBwp.bwp.cyclicPrefix = NORMAL_CYCLIC_PREFIX;
335    duCfgParam.macCellCfg.initialUlBwp.puschCommon.numTimeDomRsrcAlloc = 2;
336    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].k2 = PUSCH_K2_CFG1;
337    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].mappingType = 
338       PUSCH_MAPPING_TYPE_A;
339    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].startSymbol = 
340       PUSCH_START_SYMBOL;
341    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[0].symbolLength =
342       PUSCH_LENGTH_SYMBOL;
343
344    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].k2 = PUSCH_K2_CFG2;
345    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].mappingType = 
346       PUSCH_MAPPING_TYPE_A;
347    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].startSymbol = 
348       PUSCH_START_SYMBOL;
349    duCfgParam.macCellCfg.initialUlBwp.puschCommon.timeDomRsrcAllocList[1].symbolLength =
350       PUSCH_LENGTH_SYMBOL;
351
352    duCfgParam.macCellCfg.dmrsTypeAPos = DMRS_TYPE_A_POS; 
353
354    /* fill PUCCH config common */
355    duCfgParam.macCellCfg.initialUlBwp.pucchCommon.pucchResourceCommon = PUCCH_RSRC_COMMON;
356    duCfgParam.macCellCfg.initialUlBwp.pucchCommon.pucchGroupHopping = PUCCH_GROUP_HOPPING;
357    
358    /* SNSSAI And RRM policy Configuration */
359    taiSliceSuppLst = &duCfgParam.srvdCellLst[0].duCellInfo.cellInfo.srvdPlmn[0].taiSliceSuppLst;
360    duCfgParam.macCellCfg.numSupportedSlice = taiSliceSuppLst->numSupportedSlices;
361    if(taiSliceSuppLst->snssai)
362    {
363       DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.snssai, (duCfgParam.macCellCfg.numSupportedSlice) * sizeof(Snssai*));
364       if(duCfgParam.macCellCfg.snssai == NULLP)
365       {
366          DU_LOG("\nERROR  --> DU_APP: Memory allocation failed at readMacCfg");
367          return RFAILED;
368       }
369    }
370    for(sliceIdx=0; sliceIdx<taiSliceSuppLst->numSupportedSlices; sliceIdx++)
371    {
372       if(taiSliceSuppLst->snssai[sliceIdx] != NULLP)
373       {
374          DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.snssai[sliceIdx], sizeof(Snssai));
375          if(duCfgParam.macCellCfg.snssai[sliceIdx] == NULLP)
376          {
377             DU_LOG("\nERROR  --> DU_APP: Memory allocation failed at readMacCfg");
378             return RFAILED;
379          }
380          memcpy(duCfgParam.macCellCfg.snssai[sliceIdx], taiSliceSuppLst->snssai[sliceIdx], sizeof(Snssai));
381       }
382    }
383    
384    DU_ALLOC_SHRABL_BUF(duCfgParam.macCellCfg.rrmPolicy, sizeof(RrmPolicy));
385    if(duCfgParam.macCellCfg.rrmPolicy == NULLP)
386    {
387       DU_LOG("\nERROR  --> DU_APP: Memory allocation failed at readMacCfg");
388       return RFAILED;
389    }
390    memset(duCfgParam.macCellCfg.rrmPolicy, 0, sizeof(RrmPolicy));
391    /* TODO Check the exact data type of resource type once will receive the
392     * information from O1 interface */
393    duCfgParam.macCellCfg.rrmPolicy->rsrcType = RSRC_PRB;
394    memcpy(&duCfgParam.macCellCfg.rrmPolicy->memberList.snssai, duCfgParam.macCellCfg.snssai[DEDICATED_SLICE_INDEX],\
395    sizeof(Snssai));
396    duCfgParam.macCellCfg.rrmPolicy->policyMaxRatio = MAX_RATIO;
397    duCfgParam.macCellCfg.rrmPolicy->policyMinRatio = MIN_RATIO;
398    duCfgParam.macCellCfg.rrmPolicy->policyDedicatedRatio = DEDICATED_RATIO;
399
400    return ROK;
401 }
402
403 /*******************************************************************
404  *
405  * @brief Configures the DU Parameters
406  *
407  * @details
408  *
409  *    Function : fillDuPort
410  *
411  *    Functionality:
412  *       - fills the DU Ports.  
413  *
414  * @params[in] duPort array to be filled
415  * @return ROK     - success
416  *         RFAILED - failure
417  *
418  * ****************************************************************/
419 uint8_t fillDuPort(uint16_t *duPort)
420 {
421
422 #ifdef O1_ENABLE
423    duPort[F1_INTERFACE]   = g_cfg.DU_Port;
424    duPort[E2_INTERFACE]   = g_cfg.RIC_Port;
425 #else
426    duPort[F1_INTERFACE]   = DU_PORT;     /* DU Port idx  0 38472 */
427    duPort[E2_INTERFACE]   = RIC_PORT;    /* RIC Port idx 1 38482 */
428 #endif
429    return ROK;
430 }
431
432 /*******************************************************************
433  *
434  * @brief Configures the DU Parameters
435  *
436  * @details
437  *
438  *    Function : calcSliv
439  *
440  *    Functionality:
441  *       - calculate SLIV value from start and length field
442  *
443  * @params[in] start symbol
444  * @params[in] length of symbols
445  * @return SLIV value
446  *
447  * ****************************************************************/
448 uint16_t calcSliv(uint8_t startSymbol, uint8_t lengthSymbol)
449 {
450    uint16_t sliv = 0;
451    if((lengthSymbol-1) <= 7)
452    {
453       sliv = NUM_SYMBOLS_PER_SLOT * (lengthSymbol-1) + startSymbol;
454    }
455    else
456    {
457       sliv = NUM_SYMBOLS_PER_SLOT * (NUM_SYMBOLS_PER_SLOT - lengthSymbol + 1) \
458              + (NUM_SYMBOLS_PER_SLOT - 1 - startSymbol);
459    }
460    return sliv;
461 }
462
463
464 /*******************************************************************
465  *
466  * @brief Configures serving cell config common in sib1
467  *
468  * @details
469  *
470  *    Function : fillServCellCfgCommSib
471  *
472  *    Functionality:
473  *       - fills Serving cell config common for SIB1
474  *
475  * @params[in] SrvCellCfgCommSib pointer
476  * @return ROK     - success
477  *         RFAILED - failure
478  * 
479  ** ****************************************************************/
480 uint8_t fillServCellCfgCommSib(SrvCellCfgCommSib *srvCellCfgComm)
481 {
482    PdcchCfgCommon   pdcchCfg;
483    PdschCfgCommon   pdschCfg;
484    PcchCfg          pcchCfg;
485    RachCfgCommon    rachCfg;
486    PuschCfgCommon   puschCfg;
487    PucchCfgCommon   pucchCfg;
488    TddUlDlCfgCommon   tddCfg;
489
490    /* Configuring DL Config Common for SIB1*/
491    srvCellCfgComm->dlCfg.freqBandInd = NR_FREQ_BAND; 
492    srvCellCfgComm->dlCfg.offsetToPointA = OFFSET_TO_POINT_A;
493    srvCellCfgComm->dlCfg.dlScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
494 #ifdef NR_TDD
495    srvCellCfgComm->dlCfg.dlScsCarrier.scs = SCS_30KHZ;
496    srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = BANDWIDTH_100MHZ;
497 #else
498    srvCellCfgComm->dlCfg.dlScsCarrier.scs = SCS_15KHZ;
499    srvCellCfgComm->dlCfg.dlScsCarrier.scsBw = BANDWIDTH_20MHZ;
500 #endif
501    srvCellCfgComm->dlCfg.locAndBw = FREQ_LOC_BW;
502
503    /* Configuring PDCCH Config Common For SIB1 */
504    pdcchCfg.present = BWP_DownlinkCommon__pdcch_ConfigCommon_PR_setup;
505    pdcchCfg.ctrlRsrcSetZero = CORESET_0_INDEX;
506    pdcchCfg.searchSpcZero = SEARCHSPACE_0_INDEX;
507    pdcchCfg.searchSpcId = PDCCH_SEARCH_SPACE_ID;
508    pdcchCfg.ctrlRsrcSetId = PDCCH_CTRL_RSRC_SET_ID;
509    pdcchCfg.monitorSlotPrdAndOffPresent = \
510       
511       SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
512    //pdcchCfg.monitorSlotPrdAndOff = \
513    SearchSpace__monitoringSlotPeriodicityAndOffset_PR_sl1;
514    pdcchCfg.monitorSymbolsInSlot[0] = 128;
515    pdcchCfg.monitorSymbolsInSlot[1] = 0;
516    pdcchCfg.numCandAggLvl1 = SearchSpace__nrofCandidates__aggregationLevel1_n8;
517    pdcchCfg.numCandAggLvl2 = SearchSpace__nrofCandidates__aggregationLevel2_n4;
518    pdcchCfg.numCandAggLvl4 = SearchSpace__nrofCandidates__aggregationLevel4_n2;
519    pdcchCfg.numCandAggLvl8 = SearchSpace__nrofCandidates__aggregationLevel8_n1;
520    pdcchCfg.numCandAggLvl16 = SearchSpace__nrofCandidates__aggregationLevel16_n0;
521    pdcchCfg.searchSpcType = SearchSpace__searchSpaceType_PR_common;
522    pdcchCfg.commSrchSpcDciFrmt = PDCCH_SERACH_SPACE_DCI_FORMAT;
523    pdcchCfg.searchSpcSib1 = PDCCH_SEARCH_SPACE_ID_SIB1;
524    pdcchCfg.pagingSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
525    pdcchCfg.raSearchSpc = PDCCH_SEARCH_SPACE_ID_PAGING;
526    srvCellCfgComm->dlCfg.pdcchCfg = pdcchCfg;
527
528    /* Configuring PDSCH Config Common For SIB1 */
529    pdschCfg.present = BWP_DownlinkCommon__pdsch_ConfigCommon_PR_setup;
530    pdschCfg.numTimeDomRsrcAlloc = 2;
531    pdschCfg.timeDomAlloc[0].k0 = PDSCH_K0_CFG1;
532    pdschCfg.timeDomAlloc[0].mapType = \
533       PDSCH_TimeDomainResourceAllocation__mappingType_typeA;
534    pdschCfg.timeDomAlloc[0].sliv = calcSliv(PDSCH_START_SYMBOL,PDSCH_LENGTH_SYMBOL);
535
536    pdschCfg.timeDomAlloc[1].k0 = PDSCH_K0_CFG2;
537    pdschCfg.timeDomAlloc[1].mapType = \
538       PDSCH_TimeDomainResourceAllocation__mappingType_typeA;
539    pdschCfg.timeDomAlloc[1].sliv = calcSliv(PDSCH_START_SYMBOL,PDSCH_LENGTH_SYMBOL);
540
541    srvCellCfgComm->dlCfg.pdschCfg = pdschCfg;
542
543    /* Configuring BCCH Config for SIB1 */
544    srvCellCfgComm->dlCfg.bcchCfg.modPrdCoeff = \
545       BCCH_Config__modificationPeriodCoeff_n16;
546
547    /* Configuring PCCH Config for SIB1 */
548    pcchCfg.dfltPagingCycle = PagingCycle_rf256;
549    pcchCfg.nAndPagingFrmOffPresent = PCCH_Config__nAndPagingFrameOffset_PR_oneT;
550    pcchCfg.numPagingOcc = PCCH_Config__ns_four;
551    srvCellCfgComm->dlCfg.pcchCfg = pcchCfg;
552
553
554    /* Configuring UL Config Common */
555    srvCellCfgComm->ulCfg.ulScsCarrier.scsOffset = SSB_SUBCARRIER_OFFSET;
556 #ifdef NR_TDD
557    srvCellCfgComm->ulCfg.ulScsCarrier.scs = SCS_30KHZ;
558    srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = BANDWIDTH_100MHZ;
559 #else
560    srvCellCfgComm->ulCfg.ulScsCarrier.scs = SCS_15KHZ;
561    srvCellCfgComm->ulCfg.ulScsCarrier.scsBw = BANDWIDTH_20MHZ;
562 #endif
563    srvCellCfgComm->ulCfg.pMax = UL_P_MAX;
564    srvCellCfgComm->ulCfg.locAndBw = FREQ_LOC_BW;
565    srvCellCfgComm->ulCfg.timeAlignTimerComm = TimeAlignmentTimer_infinity;
566
567    /* Configuring RACH Config Common for SIB1 */
568    rachCfg.present = BWP_UplinkCommon__rach_ConfigCommon_PR_setup;
569    rachCfg.prachCfgIdx = PRACH_CONFIG_IDX;
570    rachCfg.msg1Fdm = RACH_ConfigGeneric__msg1_FDM_one;
571    rachCfg.msg1FreqStart = PRACH_FREQ_START;
572    rachCfg.zeroCorrZoneCfg = ZERO_CORRELATION_ZONE_CFG;
573    rachCfg.preambleRcvdTgtPwr = PRACH_PREAMBLE_RCVD_TGT_PWR;
574    rachCfg.preambleTransMax = RACH_ConfigGeneric__preambleTransMax_n200;
575    rachCfg.pwrRampingStep = RACH_ConfigGeneric__powerRampingStep_dB2;
576    rachCfg.raRspWindow = RACH_ConfigGeneric__ra_ResponseWindow_sl10;
577    rachCfg.numRaPreamble = NUM_RA_PREAMBLE;
578    rachCfg.ssbPerRachOccPresent = \
579       RACH_ConfigCommon__ssb_perRACH_OccasionAndCB_PreamblesPerSSB_PR_one;
580    rachCfg.numSsbPerRachOcc = SSB_PER_RACH;
581    rachCfg.contResTimer = RACH_ConfigCommon__ra_ContentionResolutionTimer_sf64;
582    rachCfg.rsrpThreshSsb = RSRP_THRESHOLD_SSB;
583    rachCfg.rootSeqIdxPresent = RACH_ConfigCommon__prach_RootSequenceIndex_PR_l139;
584    rachCfg.rootSeqIdx = ROOT_SEQ_IDX;
585    rachCfg.msg1Scs = PRACH_SUBCARRIER_SPACING ;
586    rachCfg.restrictedSetCfg = PRACH_RESTRICTED_SET_CFG;
587    srvCellCfgComm->ulCfg.rachCfg = rachCfg;
588
589    /* Configuring PUSCH Config Common for SIB1 */
590    puschCfg.puschCfgPresent = BWP_UplinkCommon__pusch_ConfigCommon_PR_setup;
591    puschCfg.numTimeDomRsrcAlloc = 2;
592    puschCfg.timeDomAllocList[0].k2 = PUSCH_K2_CFG1;
593    puschCfg.timeDomAllocList[0].mapType = PUSCH_TimeDomainResourceAllocation__mappingType_typeA;
594    puschCfg.timeDomAllocList[0].sliv = calcSliv(PUSCH_START_SYMBOL,PUSCH_LENGTH_SYMBOL);
595    puschCfg.timeDomAllocList[1].k2 = PUSCH_K2_CFG2;
596    puschCfg.timeDomAllocList[1].mapType = PUSCH_TimeDomainResourceAllocation__mappingType_typeA;
597    puschCfg.timeDomAllocList[1].sliv = calcSliv(PUSCH_START_SYMBOL,PUSCH_LENGTH_SYMBOL);
598    puschCfg.msg3DeltaPreamble = PUSCH_MSG3_DELTA_PREAMBLE;
599    puschCfg.p0NominalWithGrant = PUSCH_P0_NOMINAL_WITH_GRANT;
600    srvCellCfgComm->ulCfg.puschCfg = puschCfg;
601
602    /* Configuring PUCCH Config Common for SIB1 */
603    pucchCfg.present = BWP_UplinkCommon__pucch_ConfigCommon_PR_setup;
604    pucchCfg.rsrcComm = PUCCH_RSRC_COMMON;
605    pucchCfg.grpHop = PUCCH_ConfigCommon__pucch_GroupHopping_neither;
606    pucchCfg.p0Nominal = PUCCH_P0_NOMINAL;
607    srvCellCfgComm->ulCfg.pucchCfg = pucchCfg;
608
609    /* Configuring TDD UL DL config common */
610    tddCfg.refScs = SubcarrierSpacing_kHz30;
611    tddCfg.txPrd = TDD_UL_DL_Pattern__dl_UL_TransmissionPeriodicity_ms5;
612    tddCfg.numDlSlots = NUM_DL_SLOTS;
613    tddCfg.numDlSymbols = NUM_DL_SYMBOLS;
614    tddCfg.numUlSlots = NUM_UL_SLOTS;
615    tddCfg.numUlSymbols = NUM_UL_SYMBOLS;
616    srvCellCfgComm->tddCfg = tddCfg;
617
618    srvCellCfgComm->ssbPosInBurst = 192;
619    srvCellCfgComm->ssbPrdServingCell = SSB_PERIODICITY_20MS;
620    srvCellCfgComm->ssPbchBlockPwr = SSB_PBCH_PWR;
621
622    return ROK;
623 }
624
625 /*******************************************************************
626  *
627  * @brief Configures the DU Parameters
628  *
629  * @details
630  *
631  *    Function : readCfg
632  *
633  *    Functionality:
634  *       - Initializes the DuCfg members.  
635  *       - Calls readMacCfg()  
636  *
637  * @params[in] system task ID
638  * @return ROK     - success
639  *         RFAILED - failure
640  *
641  * ****************************************************************/
642
643 uint8_t readCfg()
644 {
645    uint8_t srvdCellIdx, bandIdx, sliceIdx, plmnIdx;
646    uint8_t brdcstPlmnIdx, freqBandIdx, srvdPlmnIdx;
647    uint32_t ipv4_du, ipv4_cu, ipv4_ric;
648    MibParams mib;
649    Sib1Params sib1;
650    F1TaiSliceSuppLst *taiSliceSuppLst;
651
652    /* TODO Added these below variable for local testing, once we will receive the
653     * configuration from O1 we can remove these variable */
654    Snssai snssai[NUM_OF_SUPPORTED_SLICE] = {{1,{2,3,4}},{5,{6,7,8}}};
655
656 #ifdef O1_ENABLE
657    if( getStartupConfig(&g_cfg) != ROK )
658    {
659       RETVALUE(RFAILED);
660    }
661    cmInetAddr((S8*)g_cfg.DU_IPV4_Addr, &ipv4_du);
662    cmInetAddr((S8*)g_cfg.CU_IPV4_Addr, &ipv4_cu);
663    cmInetAddr((S8*)g_cfg.RIC_IPV4_Addr, &ipv4_ric);
664
665    duCfgParam.sctpParams.cuPort = g_cfg.CU_Port;
666    duCfgParam.sctpParams.ricPort = g_cfg.RIC_Port;
667 #else   
668    cmInetAddr((S8*)DU_IP_V4_ADDR, &ipv4_du);
669    cmInetAddr((S8*)CU_IP_V4_ADDR, &ipv4_cu);
670    cmInetAddr((S8*)RIC_IP_V4_ADDR, &ipv4_ric);
671
672    duCfgParam.sctpParams.cuPort = CU_PORT;
673    duCfgParam.sctpParams.ricPort = RIC_PORT;
674 #endif
675
676    fillDuPort(duCfgParam.sctpParams.duPort);
677
678    /* F1 DU IP Address and Port*/
679    duCfgParam.sctpParams.duIpAddr.ipV4Addr = ipv4_du;
680
681    /* F1 CU IP Address and Port*/
682    duCfgParam.sctpParams.cuIpAddr.ipV4Addr = ipv4_cu;
683
684    /* Fill RIC Params */
685    duCfgParam.sctpParams.ricIpAddr.ipV4Addr = ipv4_ric;
686
687    /* EGTP Parameters */
688    duCfgParam.egtpParams.localIp.ipV4Pres = TRUE;
689    duCfgParam.egtpParams.localIp.ipV4Addr = ipv4_du;
690    duCfgParam.egtpParams.localPort = DU_EGTP_PORT;
691    duCfgParam.egtpParams.destIp.ipV4Pres = TRUE;
692    duCfgParam.egtpParams.destIp.ipV4Addr = ipv4_cu;
693    duCfgParam.egtpParams.destPort = CU_EGTP_PORT;
694    duCfgParam.egtpParams.minTunnelId = MIN_TEID;
695    duCfgParam.egtpParams.maxTunnelId = MAX_TEID;
696
697    duCfgParam.maxUe = 32; //TODO: Check
698    /* DU Info */        
699    duCfgParam.duId = DU_ID;     
700    strcpy((char*)duCfgParam.duName,DU_NAME);
701
702    /* Mib Params */
703    mib.sysFrmNum = SYS_FRAME_NUM;
704 #ifdef NR_TDD
705    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs30or120;
706 #else
707    mib.subCarrierSpacingCommon = MIB__subCarrierSpacingCommon_scs15or60;
708 #endif
709    mib.ssb_SubcarrierOffset = SSB_SC_OFFSET; //Kssb
710    mib.dmrs_TypeA_Position = MIB__dmrs_TypeA_Position_pos2;
711    mib.controlResourceSetZero = CORESET_0_INDEX;
712    mib.searchSpaceZero = SEARCHSPACE_0_INDEX;
713    mib.cellBarred = MIB__cellBarred_notBarred;
714    mib.intraFreqReselection =
715       MIB__intraFreqReselection_notAllowed;
716    duCfgParam.mibParams = mib;
717
718    /* SIB1 Params */
719    memset(&sib1.plmn, 0, sizeof(Plmn));
720    sib1.plmn.mcc[0] = PLMN_MCC0;
721    sib1.plmn.mcc[1] = PLMN_MCC1;
722    sib1.plmn.mcc[2] = PLMN_MCC2;
723    sib1.plmn.mnc[0] = PLMN_MNC0;
724    sib1.plmn.mnc[1] = PLMN_MNC1;
725    sib1.tac = DU_TAC;
726    sib1.ranac = DU_RANAC;
727    sib1.cellIdentity = CELL_IDENTITY;
728    sib1.cellResvdForOpUse = PLMN_IdentityInfo__cellReservedForOperatorUse_notReserved;
729    sib1.connEstFailCnt = ConnEstFailureControl__connEstFailCount_n3;
730    sib1.connEstFailOffValidity = ConnEstFailureControl__connEstFailOffsetValidity_s120;
731    sib1.siSchedInfo.winLen = SI_SchedulingInfo__si_WindowLength_s5;
732    sib1.siSchedInfo.broadcastSta = SchedulingInfo__si_BroadcastStatus_broadcasting;
733    sib1.siSchedInfo.preiodicity = SchedulingInfo__si_Periodicity_rf8;
734    sib1.siSchedInfo.sibType = SIB_TypeInfo__type_sibType2;
735    sib1.siSchedInfo.sibValTag = SIB1_VALUE_TAG;
736
737    fillServCellCfgCommSib(&sib1.srvCellCfgCommSib);
738
739    duCfgParam.sib1Params = sib1;
740
741    for(srvdCellIdx=0; srvdCellIdx<DEFAULT_CELLS; srvdCellIdx++)
742    { 
743       memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn, 0, sizeof(Plmn));
744       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[0] = PLMN_MCC0;
745       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[1] = PLMN_MCC1;
746       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mcc[2] = PLMN_MCC2;
747       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mnc[0] = PLMN_MNC0;
748       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.plmn.mnc[1] = PLMN_MNC1;
749
750       /*Cell ID */
751       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrCgi.cellId = NR_CELL_ID;
752       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.nrPci = NR_PCI;
753
754       /* List of Available PLMN */
755       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
756       {
757          /* As per spec 38.473, Plmn identity consists of 3 digit from mcc
758           * followed by either 2 digit or 3 digits of mnc */ 
759
760          memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn, 0,\
761          sizeof(Plmn));
762          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[0] = PLMN_MCC0;
763          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[1] = PLMN_MCC1;
764          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mcc[2] = PLMN_MCC2;
765          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[0] = PLMN_MNC0;
766          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].plmn.mnc[1] = PLMN_MNC1;
767       }
768       /* List of Extended PLMN */
769       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
770       {
771          /* As per spec 38.473, Plmn identity consists of 3 digit from mcc
772           * followed by either 2 digit or 3 digits of mnc */ 
773
774          memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn, 0, sizeof(Plmn));
775          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[0] = PLMN_MCC0;
776          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[1] = PLMN_MCC1;
777          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mcc[2] = PLMN_MCC2;
778          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mnc[0] = PLMN_MNC0;
779          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].extPlmn.mnc[1] = PLMN_MNC1;
780       } 
781       /* List of Supporting Slices */
782       for(srvdPlmnIdx=0; srvdPlmnIdx<MAX_PLMN; srvdPlmnIdx++)
783       {
784          taiSliceSuppLst = &duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellInfo.srvdPlmn[srvdPlmnIdx].\
785          taiSliceSuppLst;
786          
787          /* TODO Calculte the exact number of supported slices once will get
788           * cell configuration from O1 */
789          taiSliceSuppLst->numSupportedSlices = NUM_OF_SUPPORTED_SLICE;
790          if(taiSliceSuppLst->numSupportedSlices > MAX_NUM_OF_SLICE_ITEMS)
791          {
792             DU_LOG("\nERROR --> DU_APP: readCfg(): Number of supported slice [%d] is more than 1024",\
793             taiSliceSuppLst->numSupportedSlices);
794             return RFAILED;
795          }
796
797          DU_ALLOC(taiSliceSuppLst->snssai, taiSliceSuppLst->numSupportedSlices*sizeof(Snssai*));
798          if(taiSliceSuppLst->snssai == NULLP)
799          {
800             DU_LOG("\nERROR --> DU_APP: readCfg():Memory allocation failed");
801             return RFAILED;
802          }
803          
804          for(sliceIdx=0; sliceIdx<taiSliceSuppLst->numSupportedSlices; sliceIdx++)
805          {
806             DU_ALLOC(taiSliceSuppLst->snssai[sliceIdx], sizeof(Snssai));
807             if(taiSliceSuppLst->snssai[sliceIdx] == NULLP)
808             {
809                DU_LOG("\nERROR --> DU_APP: readCfg():Memory allocation failed");
810                return RFAILED;
811             }
812             memcpy(taiSliceSuppLst->snssai[sliceIdx], &snssai[sliceIdx], sizeof(Snssai));
813          }
814       }
815       /* TAC and EPSTAC */
816       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.tac = DU_TAC;
817       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.epsTac = DU_TAC; //to check and fill
818       /* NR Mode info */
819       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.nrArfcn = NR_UL_ARFCN;
820       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
821       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
822       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
823
824 #if 0
825       /* NR Mode info */
826       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.nrArfcn = NR_ARFCN;
827       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
828       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;                 
829       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;         
830
831       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
832       {
833          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[freqBandIdx].nrFreqBand =\
834          NR_FREQ_BAND;
835          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
836          {
837             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.tdd.nrFreqInfo.freqBand[freqBandIdx].sulBand[bandIdx]\
838             = SUL_BAND;         
839          }
840       }
841 #endif
842       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
843       {
844          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[freqBandIdx].\
845          nrFreqBand = NR_FREQ_BAND;
846          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
847          {
848             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulNrFreqInfo.freqBand[freqBandIdx].\
849             sulBand[bandIdx] = SUL_BAND;
850          }
851       }
852       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.nrArfcn = NR_DL_ARFCN;
853       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulArfcn = SUL_ARFCN;
854       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrScs = SCS_15;
855       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.sulInfo.sulTxBw.nrb = NRB_106;
856       for(freqBandIdx=0; freqBandIdx<MAX_NRCELL_BANDS; freqBandIdx++)
857       {
858          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[freqBandIdx].\
859          nrFreqBand = NR_FREQ_BAND;
860          for(bandIdx=0; bandIdx<MAX_NRCELL_BANDS; bandIdx++)
861          {
862             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlNrFreqInfo.freqBand[freqBandIdx].\
863             sulBand[bandIdx] = SUL_BAND;
864          }
865       }
866
867       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrScs = SCS_15;
868       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.ulTxBw.nrb = NRB_106;
869
870       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrScs = SCS_15;
871       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.f1Mode.mode.fdd.dlTxBw.nrb = NRB_106;
872
873       /*Measurement Config and Cell Config */ 
874       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.measTimeCfg = TIME_CFG; 
875
876       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellDir = DL_UL; 
877
878       duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.cellType=CELL_TYPE;
879
880       /* Broadcast PLMN Identity */
881       for(brdcstPlmnIdx=0; brdcstPlmnIdx<MAX_BPLMN_NRCELL_MINUS_1; brdcstPlmnIdx++)
882       { 
883          for(plmnIdx=0; plmnIdx<MAX_PLMN; plmnIdx++)
884          {
885             memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx],\
886             0, sizeof(Plmn));
887             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[0] =\
888             PLMN_MCC0;
889             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[1] =\
890             PLMN_MCC1;
891             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mcc[2] =\
892             PLMN_MCC2;
893             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mnc[0] =\
894             PLMN_MNC0;
895             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].plmn[plmnIdx].mnc[1] =\
896             PLMN_MNC1;
897          }
898          /* Extended PLMN List */        
899          for(plmnIdx=0; plmnIdx<MAX_PLMN; plmnIdx++)
900          {
901             memset(&duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
902             extPlmn[plmnIdx], 0, sizeof(Plmn));
903             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
904             extPlmn[plmnIdx].mcc[0] = PLMN_MCC0;
905             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
906             extPlmn[plmnIdx].mcc[1] = PLMN_MCC1;
907             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
908             extPlmn[plmnIdx].mcc[2] = PLMN_MCC2;
909             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
910             extPlmn[plmnIdx].mnc[0] = PLMN_MNC0;
911             duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].\
912             extPlmn[plmnIdx].mnc[1] = PLMN_MNC1;
913          }
914
915          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].tac = DU_TAC;
916          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].nrCellId = NR_CELL_ID;
917          duCfgParam.srvdCellLst[srvdCellIdx].duCellInfo.brdcstPlmnInfo[brdcstPlmnIdx].ranac = NR_RANAC;
918       }
919
920       /*gnb DU System Info mib msg*/
921       BuildMibMsg();
922       DU_ALLOC(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg, encBufSize);
923       if(!(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg))
924       {
925          DU_LOG("\nERROR  -->  DU APP : Memory allocation failure at readCfg");
926          return RFAILED;
927       }
928       memcpy(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibMsg, encBuf, encBufSize);
929       duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.mibLen = encBufSize;
930
931       /*gnb DU System Info mib msg*/
932       BuildSib1Msg();
933       DU_ALLOC(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg,\
934             encBufSize);
935       if(!(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg))
936       {
937          DU_LOG("\nERROR  -->  DU APP : Memory allocation failure at readCfg");
938          return RFAILED;
939       }
940       memcpy(duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Msg,\
941             encBuf,encBufSize);
942       duCfgParam.srvdCellLst[srvdCellIdx].duSysInfo.sib1Len = encBufSize;
943
944    }
945
946    if(readMacCfg() != ROK)
947    {
948       DU_LOG("\nERROR  -->  DU_APP : Failed while reading MAC config");
949       return RFAILED;
950    }
951
952    return ROK;
953 }
954
955 /*******************************************************************
956  *
957  * @brief Reads config and posts message to du_app on completion
958  *
959  * @details
960  *
961  *    Function : main
962  *
963  *    Functionality:
964  *      - Calls readCfg()
965  *      - Post to du_app for further processing
966  *
967  * @params[in] void
968  * @return ROK     - success
969  *         RFAILED - failure
970  *
971  * ****************************************************************/
972 uint8_t duReadCfg()
973 {
974    Pst pst;
975    Buffer *mBuf;
976
977    memset(&duCfgParam, 0, sizeof(DuCfgParams));
978
979    //Read configs into duCfgParams
980    if(readCfg() != ROK)
981    {
982       DU_LOG("\nERROR  -->  DU_APP : Reading configuration failed");
983       return RFAILED;
984    }
985
986    //Fill pst structure
987    memset(&(pst), 0, sizeof(Pst));
988    pst.srcEnt = (Ent)ENTDUAPP;
989    pst.srcInst = (Inst)DU_INST;
990    pst.srcProcId = DU_PROC;
991    pst.dstEnt = pst.srcEnt;
992    pst.dstInst = pst.srcInst;
993    pst.dstProcId = pst.srcProcId;
994    pst.event = EVTCFG;
995    pst.selector = ODU_SELECTOR_TC;
996    pst.pool= DU_POOL;
997
998
999    if(ODU_GET_MSG_BUF(DFLT_REGION, DU_POOL, &mBuf) != ROK)
1000    {
1001       DU_LOG("\nERROR  -->  DU_APP : Memory allocation failed in duReadCfg");
1002       return RFAILED;
1003    }
1004
1005    if (ODU_POST_TASK(&pst, mBuf) != ROK)
1006    {
1007       DU_LOG("\nERROR  -->  DU_APP : ODU_POST_TASK failed in duReadCfg");
1008       return RFAILED;
1009    }
1010
1011    return ROK;
1012 }
1013
1014 /**********************************************************************
1015   End of file
1016  **********************************************************************/
1017