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