O-RAN E Maintenance Release contribution for ODULOW
[o-du/phy.git] / fhi_lib / app / src / config.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2020 Intel.
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 /**
20  * @brief
21  * @file
22  * @ingroup
23  * @author Intel Corporation
24  **/
25
26 #include <inttypes.h>
27 #include <immintrin.h>
28 #include "rte_common.h"
29 #include "config.h"
30 #include "common.h"
31 #include "debug.h"
32
33 #include <rte_ethdev.h>
34
35 #define MAX_LINE_SIZE 512
36 /* Configuration file maximum supported line length */
37
38 #define KEY_APP_MODE        "appMode"
39 #define KEY_XRAN_MODE       "xranMode"
40 #define KEY_XRAN_TECH       "xranRanTech"
41 #define KEY_MU_NUMBER       "mu"
42 #define KEY_NDLABSFREPOINTA "nDLAbsFrePointA"
43 #define KEY_NULABSFREPOINTA "nULAbsFrePointA"
44 #define KEY_NDLBANDWIDTH    "nDLBandwidth"
45 #define KEY_NULBANDWIDTH    "nULBandwidth"
46 #define KEY_NDLFFTSIZE      "nDLFftSize"
47 #define KEY_NULFFTSIZE      "nULFftSize"
48
49 #define KEY_DU_PORT_ID_BITWIDTH    "DU_Port_ID_bitwidth"
50 #define KEY_BANDSECTOR_ID_BITWIDTH "BandSector_ID_bitwidth"
51 #define KEY_CC_ID_BITWIDTH         "CC_ID_bitwidth"
52 #define KEY_RU_PORT_ID_BITWIDTH    "RU_Port_ID_bitwidth"
53
54 #define KEY_NFRAMEDUPLEXTYPE "nFrameDuplexType"
55 #define KEY_NTDDPERIOD       "nTddPeriod"
56
57 #define KEY_SSLOTCONFIG     "sSlotConfig"
58
59 #define KEY_XU_NUM          "oXuNum"
60 #define KEY_XU_ETH_LINK_SPD "oXuEthLinkSpeed"
61 #define KEY_XU_ETH_LINE_NUM "oXuLinesNumber"
62 #define KEY_XU_CP_ON_ONE_VF "oXuCPon1Vf"
63 #define KEY_XU_RXQ_VF       "oXuRxqNumber"
64 #define KEY_OWDM_INIT_EN    "oXuOwdmInitEn"
65 #define KEY_OWDM_MEAS_METH  "oXuOwdmMeasMeth"
66 #define KEY_OWDM_NUM_SAMPS  "oXuOwdmNumSamps"
67 #define KEY_OWDM_FLTR_TYPE  "oXuOwdmFltrType"
68 #define KEY_OWDM_RSP_TO     "oXuOwdmRespTimeOut"
69 #define KEY_OWDM_MEAS_ST    "oXuOwdmMeasState"
70 #define KEY_OWDM_MEAS_ID    "oXuOwdmMeasId"
71 #define KEY_OWDM_EN         "oXuOwdmEnabled"
72 #define KEY_OWDM_PL_LENGTH  "oXuOwdmPlLength"
73 #define KEY_CC_PER_PORT_NUM "ccNum"
74 #define KEY_ANT_NUM         "antNum"
75 #define KEY_UL_ANT_NUM      "antNumUL"
76
77 #define KEY_ANT_ELM_TRX_NUM "antElmTRx"
78
79 #define KEY_MU_MIMO_UES_NUM "muMimoUEs"
80 #define KEY_DLLAYERS_PER_UE "DlLayersPerUe"
81 #define KEY_ULLAYERS_PER_UE "UlLayersPerUe"
82 #define KEY_FILE_DLBFWUE    "DlBfwUe"
83 #define KEY_FILE_ULBFWUE    "UlBfwUe"
84
85 #define KEY_FILE_O_XU_CFG   "oXuCfgFile"
86 #define KEY_O_XU_PCIE_BUS   "PciBusAddoXu"
87 #define KEY_O_XU_REM_MAC    "oXuRem"
88
89 #define KEY_FILE_ULSRS      "antSrsC"
90
91
92 #define KEY_TTI_PERIOD      "ttiPeriod"
93
94 #define KEY_MTU_SIZE        "MTUSize"
95 #define KEY_MAIN_CORE        "mainCore"
96 #define KEY_IO_CORE         "ioCore"
97 #define KEY_IO_WORKER       "ioWorker"
98 #define KEY_IO_WORKER_64_127 "ioWorker_64_127"
99 #define KEY_IO_SLEEP        "ioSleep"
100 #define KEY_SYSTEM_CORE     "systemCore"
101 #define KEY_IOVA_MODE       "iovaMode"
102 #define KEY_DPDK_MEM_SZ      "dpdkMemorySize"
103
104 #define KEY_INSTANCE_ID     "instanceId"
105
106 #define KEY_DU_MAC          "duMac"
107 #define KEY_RU_MAC          "ruMac"
108
109 #define KEY_FILE_NUMSLOTS   "numSlots"
110 #define KEY_FILE_AxC        "antC"
111 #define KEY_FILE_PRACH_AxC  "antPrachC"
112
113 #define KEY_FILE_SLOT_TX     "SlotNumTx"
114 #define KEY_FILE_SLOT_RX     "SlotNumRx"
115
116 #define KEY_PRACH_ENABLE   "rachEanble"
117 #define KEY_SRS_ENABLE     "srsEanble"
118 #define KEY_PUSCH_MASK_ENABLE "puschMaskEnable"
119 #define KEY_PUSCH_MASK_SLOT "puschMaskSlot"
120
121 #define KEY_PRACH_CFGIDX   "prachConfigIndex"
122 #define KEY_SRS_SYM_IDX    "srsSym"
123
124 #define KEY_MAX_FRAME_ID   "maxFrameId"
125
126
127 #define KEY_IQ_SWAP        "iqswap"
128 #define KEY_HTONS_SWAP     "nebyteorderswap"
129 #define KEY_COMPRESSION    "compression"
130 #define KEY_COMP_TYPE      "compType"
131 #define KEY_PRACH_COMPMETH "prachCompMethod"
132 #define KEY_PRACH_IQ       "prachiqWidth"
133
134
135 #define KEY_BFW_NUM        "totalBFWeights"
136
137 #define KEY_TADV_CP_DL     "Tadv_cp_dl"
138 #define KEY_T2A_MIN_CP_DL  "T2a_min_cp_dl"
139 #define KEY_T2A_MAX_CP_DL  "T2a_max_cp_dl"
140 #define KEY_T2A_MIN_CP_UL  "T2a_min_cp_ul"
141 #define KEY_T2A_MAX_CP_UL  "T2a_max_cp_ul"
142 #define KEY_T2A_MIN_UP     "T2a_min_up"
143 #define KEY_T2A_MAX_UP     "T2a_max_up"
144 #define KEY_TA3_MIN        "Ta3_min"
145 #define KEY_TA3_MAX        "Ta3_max"
146 #define KEY_T1A_MIN_CP_DL  "T1a_min_cp_dl"
147 #define KEY_T1A_MAX_CP_DL  "T1a_max_cp_dl"
148 #define KEY_T1A_MIN_CP_UL  "T1a_min_cp_ul"
149 #define KEY_T1A_MAX_CP_UL  "T1a_max_cp_ul"
150 #define KEY_T1A_MIN_UP     "T1a_min_up"
151 #define KEY_T1A_MAX_UP     "T1a_max_up"
152 #define KEY_TA4_MIN        "Ta4_min"
153 #define KEY_TA4_MAX        "Ta4_max"
154
155
156 #define KEY_CP_ENABLE      "CPenable"
157 #define KEY_CP_VTAG        "c_plane_vlan_tag"
158 #define KEY_UP_VTAG        "u_plane_vlan_tag"
159 #define KEY_DEBUG_STOP     "debugStop"
160 #define KEY_DEBUG_STOP_CNT "debugStopCount"
161 #define KEY_BBDEV_MODE     "bbdevMode"
162 #define KEY_DYNA_SEC_ENA   "DynamicSectionEna"
163 #define KEY_ALPHA          "Gps_Alpha"
164 #define KEY_BETA           "Gps_Beta"
165
166 #define KEY_NPRBELEM_DL       "nPrbElemDl"
167 #define KEY_PRBELEM_DL        "PrbElemDl"
168 #define KEY_PRBELEM_DL_CC_M   "PrbElemDlCCMask"
169 #define KEY_PRBELEM_DL_ANT_M  "PrbElemDlAntCMask"
170 #define KEY_EXTBFW_DL         "ExtBfwDl"
171
172 #define KEY_NPRBELEM_UL       "nPrbElemUl"
173 #define KEY_PRBELEM_UL        "PrbElemUl"
174 #define KEY_PRBELEM_UL_CC_M   "PrbElemUlCCMask"
175 #define KEY_PRBELEM_UL_ANT_M  "PrbElemUlAntCMask"
176 #define KEY_EXTBFW_UL         "ExtBfwUl"
177 #define KEY_NPRBELEM_SRS       "nPrbElemSrs"
178 #define KEY_PRBELEM_SRS        "PrbElemSrs"
179 #define KEY_MAX_SEC_SYM        "max_sections_per_symbol"
180 #define KEY_MAX_SEC_SLOT       "max_sections_per_slot"
181
182 typedef int (*fillConfigStruct_fn)(void* cbPram, const char *key, const char *value);
183
184 struct slot_cfg_to_pars {
185     RuntimeConfig *config;
186     int32_t direction;
187     int32_t slot_idx;
188 };
189
190 /**
191  * Set runtime configuration parameters to their defaults.
192  *
193  * @todo Initialize missing parameters.
194  */
195 static void init_config(RuntimeConfig* config)
196 {
197     memset(config , 0, sizeof(RuntimeConfig));
198 }
199
200 static int32_t
201 parseFileViaCb (char *filename, fillConfigStruct_fn cbFn, void* cbParm);
202
203 /** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - **/
204
205 static void trim(char* input)
206 {
207     uint32_t i;
208     for (i = 0; i<strlen(input); i++)
209         if (input[i] == ' ' || input[i] == '\n' || input[i] == '\t')
210             input[i] = '\0';
211 }
212
213
214 static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *value)
215 {
216     int32_t parse_res = 0;
217     static uint32_t section_idx_dl  = 0;
218     static uint32_t section_idx_ul  = 0;
219     static uint32_t section_idx_srs = 0;
220
221     if (strcmp(key, KEY_APP_MODE) == 0){
222         config->appMode = atoi(value);
223     } else if (strcmp(key, KEY_XRAN_TECH) == 0) {
224         config->xranTech = atoi(value);
225     } else if (strcmp(key, KEY_XRAN_MODE) == 0) {
226         config->xranCat = atoi(value);
227     } else if (strcmp(key, KEY_CC_PER_PORT_NUM) == 0) {
228         config->numCC= atoi(value);
229     } else if (strcmp(key, KEY_MU_NUMBER) == 0) {
230         config->mu_number= atoi(value);
231         printf("mu_number: %d\n",config->mu_number);
232     } else if (strcmp(key, KEY_NDLABSFREPOINTA) == 0) {
233         config->nDLAbsFrePointA = atoi(value);
234         printf("nDLAbsFrePointA: %d\n",config->nDLAbsFrePointA);
235     } else if (strcmp(key, KEY_NULABSFREPOINTA) == 0) {
236         config->nULAbsFrePointA = atoi(value);
237         printf("nULAbsFrePointA: %d\n",config->nULAbsFrePointA);
238     } else if (strcmp(key, KEY_NDLBANDWIDTH) == 0) {
239         config->nDLBandwidth = atoi(value);
240         printf("nDLBandwidth: %d\n",config->nDLBandwidth);
241     } else if (strcmp(key, KEY_NULBANDWIDTH) == 0) {
242         config->nULBandwidth = atoi(value);
243         printf("nULBandwidth: %d\n",config->nULBandwidth);
244     } else if (strcmp(key, KEY_NDLFFTSIZE) == 0) {
245         config->nDLFftSize = atoi(value);
246         printf("nDLFftSize: %d\n",config->nDLFftSize);
247     } else if (strcmp(key, KEY_NULFFTSIZE) == 0) {
248         config->nULFftSize = atoi(value);
249         printf("nULFftSize: %d\n",config->nULFftSize);
250     } else if (strcmp(key, KEY_NFRAMEDUPLEXTYPE) == 0) {
251         config->nFrameDuplexType = atoi(value);
252         printf("nFrameDuplexType: %d\n",config->nFrameDuplexType);
253     } else if (strcmp(key, KEY_DU_PORT_ID_BITWIDTH) == 0) {
254         config->DU_Port_ID_bitwidth = atoi(value);
255         printf("DU_Port_ID_bitwidth: %d\n",config->DU_Port_ID_bitwidth);
256     } else if (strcmp(key, KEY_BANDSECTOR_ID_BITWIDTH) == 0) {
257         config->BandSector_ID_bitwidth = atoi(value);
258         printf("BandSector_ID_bitwidth: %d\n",config->BandSector_ID_bitwidth);
259     } else if (strcmp(key, KEY_CC_ID_BITWIDTH) == 0) {
260         config->CC_ID_bitwidth = atoi(value);
261         printf("CC_ID_bitwidth: %d\n",config->CC_ID_bitwidth);
262     } else if (strcmp(key, KEY_RU_PORT_ID_BITWIDTH) == 0) {
263         config->RU_Port_ID_bitwidth = atoi(value);
264         printf("RU_Port_ID_bitwidth: %d\n",config->RU_Port_ID_bitwidth);
265     } else if (strcmp(key, KEY_NTDDPERIOD) == 0) {
266         config->nTddPeriod = atoi(value);
267         printf("nTddPeriod: %d\n",config->nTddPeriod);
268         if (config->nTddPeriod > XRAN_MAX_TDD_PERIODICITY)
269         {
270             printf("nTddPeriod is larger than max allowed, invalid!\n");
271             config->nTddPeriod = XRAN_MAX_TDD_PERIODICITY;
272         }
273     } else if (strncmp(key, KEY_SSLOTCONFIG, strlen(KEY_SSLOTCONFIG)) == 0) {
274         unsigned int slot_num = 0;
275         int i = 0;
276         sscanf(key,"sSlotConfig%u",&slot_num);
277         if (slot_num >= config->nTddPeriod){
278             printf("slot_num %d exceeds TddPeriod\n",slot_num);
279         }
280         else{
281             sscanf(value, "%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx,%02hhx",
282                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[0],
283                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[1],
284                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[2],
285                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[3],
286                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[4],
287                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[5],
288                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[6],
289                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[7],
290                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[8],
291                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[9],
292                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[10],
293                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[11],
294                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[12],
295                                            (uint8_t *)&config->sSlotConfig[slot_num].nSymbolType[13]);
296             printf("sSlotConfig%d: ",slot_num);
297             for (i = 0; i< 14; i++){
298                 printf("%d ",config->sSlotConfig[slot_num].nSymbolType[i]);
299             }
300             printf("\n");
301         }
302     } else if (strcmp(key, KEY_ANT_NUM) == 0) {
303         config->numAxc = atoi(value);
304     } else if (strcmp(key, KEY_UL_ANT_NUM) == 0) {
305         config->numUlAxc = atoi(value);
306     }else if (strcmp(key, KEY_ANT_ELM_TRX_NUM) == 0) {
307         config->antElmTRx = atoi(value);
308         printf("antElmTRx %d\n", config->antElmTRx);
309     } else if (strcmp(key, KEY_MU_MIMO_UES_NUM) == 0) {
310         config->muMimoUEs = atoi(value);
311     } else if (strcmp(key, KEY_DLLAYERS_PER_UE) == 0) {
312         config->DlLayersPerUe = atoi(value);
313     } else if (strcmp(key, KEY_ULLAYERS_PER_UE) == 0) {
314         config->UlLayersPerUe = atoi(value);
315     } else if (strcmp(key, KEY_TTI_PERIOD) == 0) {
316         config->ttiPeriod = atoi(value);
317     } else if (strcmp(key, KEY_IQ_SWAP) == 0) {
318         config->iqswap = atoi(value);
319     } else if (strcmp(key, KEY_HTONS_SWAP) == 0) {
320         config->nebyteorderswap = atoi(value);
321     } else if (strcmp(key, KEY_COMPRESSION) == 0) {
322         config->compression = atoi(value);
323     } else if (strcmp(key, KEY_COMP_TYPE) == 0) {
324         config->CompHdrType = atoi(value);
325     } else if (strcmp(key, KEY_PRACH_COMPMETH) == 0) {
326         config->prachCompMethod = atoi(value);
327     } else if (strcmp(key, KEY_PRACH_IQ) == 0) {
328         config->prachiqWidth = atoi(value);  
329     } else if (strcmp(key, KEY_MTU_SIZE) == 0) {
330         config->mtu = atoi(value);
331         printf("mtu %d\n", config->mtu);
332     } else if (strcmp(key, KEY_IO_SLEEP) == 0) {
333         config->io_sleep = atoi(value);
334         printf("io_sleep %d \n", config->io_sleep);
335     } else if (strcmp(key, KEY_IO_CORE) == 0) {
336         config->io_core = atoi(value);
337         printf("io_core %d [core id]\n", config->io_core);
338     } else if (strcmp(key, KEY_MAIN_CORE) == 0) {
339         config->io_core = atoi(value);
340         printf("io_core %d [core id]\n", config->io_core);
341     } else if (strcmp(key, KEY_IO_WORKER) == 0) {
342         config->io_worker = strtoll(value, NULL, 0);
343         printf("io_worker 0x%lx [mask]\n", config->io_worker);
344     } else if (strcmp(key, KEY_IO_WORKER_64_127) == 0) {
345         config->io_worker_64_127 = strtoll(value, NULL, 0);
346         printf("io_worker_64_127 0x%lx [mask]\n", config->io_worker_64_127);
347     } else if (strcmp(key, KEY_SYSTEM_CORE) == 0) {
348         config->system_core = atoi(value);
349         printf("system core %d [core id]\n", config->system_core);
350     } else if (strcmp(key, KEY_IOVA_MODE) == 0) {
351         config->iova_mode = atoi(value);
352         printf("iova_mode %d\n", config->iova_mode);
353     } else if (strcmp(key, KEY_INSTANCE_ID) == 0) {
354         config->instance_id = atoi(value);
355         printf("instance_id %d\n", config->instance_id);
356     } else if (strncmp(key, KEY_DU_MAC, strlen(KEY_DU_MAC)) == 0) {
357         unsigned int vf_num = 0;
358         sscanf(key,"duMac%02u",&vf_num);
359         if (vf_num >= XRAN_VF_MAX) {
360             printf("duMac%d exceeds max antenna supported\n",vf_num);
361         } else {
362             printf("duMac%d: %s\n",vf_num, value);
363             sscanf(value, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", (uint8_t*)&config->o_du_addr[vf_num].addr_bytes[0],
364                                                (uint8_t*)&config->o_du_addr[vf_num].addr_bytes[1],
365                                                (uint8_t*)&config->o_du_addr[vf_num].addr_bytes[2],
366                                                (uint8_t*)&config->o_du_addr[vf_num].addr_bytes[3],
367                                                (uint8_t*)&config->o_du_addr[vf_num].addr_bytes[4],
368                                                (uint8_t*)&config->o_du_addr[vf_num].addr_bytes[5]);
369
370             printf("[vf %d]O-DU MAC address: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
371                 vf_num,
372                 config->o_du_addr[vf_num].addr_bytes[0],
373                 config->o_du_addr[vf_num].addr_bytes[1],
374                 config->o_du_addr[vf_num].addr_bytes[2],
375                 config->o_du_addr[vf_num].addr_bytes[3],
376                 config->o_du_addr[vf_num].addr_bytes[4],
377                 config->o_du_addr[vf_num].addr_bytes[5]);
378         }
379     } else if (strncmp(key, KEY_RU_MAC, strlen(KEY_RU_MAC)) == 0) {
380         unsigned int vf_num = 0;
381         sscanf(key,"ruMac%02u",&vf_num);
382         if (vf_num >= XRAN_VF_MAX) {
383             printf("ruMac%d exceeds max antenna supported\n",vf_num);
384         } else {
385             printf("ruMac%d: %s\n",vf_num, value);
386
387             sscanf(value, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", (uint8_t*)&config->o_ru_addr[vf_num].addr_bytes[0],
388                                                (uint8_t*)&config->o_ru_addr[vf_num].addr_bytes[1],
389                                                (uint8_t*)&config->o_ru_addr[vf_num].addr_bytes[2],
390                                                (uint8_t*)&config->o_ru_addr[vf_num].addr_bytes[3],
391                                                (uint8_t*)&config->o_ru_addr[vf_num].addr_bytes[4],
392                                                (uint8_t*)&config->o_ru_addr[vf_num].addr_bytes[5]);
393
394             printf("[vf %d]RU MAC address: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
395                 vf_num,
396                 config->o_ru_addr[vf_num].addr_bytes[0],
397                 config->o_ru_addr[vf_num].addr_bytes[1],
398                 config->o_ru_addr[vf_num].addr_bytes[2],
399                 config->o_ru_addr[vf_num].addr_bytes[3],
400                 config->o_ru_addr[vf_num].addr_bytes[4],
401                 config->o_ru_addr[vf_num].addr_bytes[5]);
402         }
403     } else if (strcmp(key, KEY_FILE_NUMSLOTS) == 0) {
404         config->numSlots = atoi(value);
405         printf("numSlots: %d\n",config->numSlots);
406     }else if (strncmp(key, KEY_FILE_AxC, strlen(KEY_FILE_AxC)) == 0) {
407         unsigned int ant_num = 0;
408         sscanf(key,"antC%02u",&ant_num);
409         if (ant_num >= MAX_ANT_CARRIER_SUPPORTED) {
410             printf("antC%d exceeds max antenna supported\n",ant_num);
411         } else {
412             strncpy(&config->ant_file[ant_num][0], value, strlen(value));
413             printf("antC%d: %s\n",ant_num, config->ant_file[ant_num]);
414         }
415     } else if (strncmp(key, KEY_FILE_DLBFWUE, strlen(KEY_FILE_DLBFWUE)) == 0) {
416         unsigned int ue_num = 0;
417         sscanf(key,"DlBfwUe%02u",&ue_num);
418         if (ue_num >= MAX_ANT_CARRIER_SUPPORTED) {
419             printf("DlBfwUe%d exceeds max streams supported\n",ue_num);
420         } else {
421             strncpy(&config->dl_bfw_file[ue_num][0], value, strlen(value));
422             printf("DlBfwUe%d: %s\n",ue_num, config->dl_bfw_file[ue_num]);
423         }
424     }else if (strncmp(key, KEY_FILE_ULBFWUE, strlen(KEY_FILE_ULBFWUE)) == 0) {
425         unsigned int ue_num = 0;
426         sscanf(key,"UlBfwUe%02u",&ue_num);
427         if (ue_num >= MAX_ANT_CARRIER_SUPPORTED) {
428             printf("UlBfwUe%d exceeds max streams supported\n",ue_num);
429         } else {
430             strncpy(&config->ul_bfw_file[ue_num][0], value, strlen(value));
431             printf("UlBfwUe%d: %s\n",ue_num, config->ul_bfw_file[ue_num]);
432         }
433     }else if (strncmp(key, KEY_FILE_ULSRS, strlen(KEY_FILE_ULSRS)) == 0) {
434         unsigned int srs_ant = 0;
435         sscanf(key,"antSrsC%02u",&srs_ant);
436         if (srs_ant >= MAX_ANT_CARRIER_SUPPORTED_CAT_B) {
437             printf("antSrsC%d exceeds max ant elemnets supported [%d]\n", srs_ant, MAX_ANT_CARRIER_SUPPORTED_CAT_B);
438         } else {
439             strncpy(&config->ul_srs_file[srs_ant][0], value, strlen(value));
440             printf("antSrsC%d: %s\n",srs_ant, config->ul_srs_file[srs_ant]);
441         }
442     } else if (strncmp(key, KEY_FILE_SLOT_TX, strlen(KEY_FILE_SLOT_TX)) == 0) {
443         unsigned int slot_num = 0;
444         unsigned int direction = XRAN_DIR_DL;
445         sscanf(key,"SlotNumTx%02u",&slot_num);
446         if (slot_num >= XRAN_N_FE_BUF_LEN) {
447             printf("SlotNumTx%d exceeds max slots supported\n",slot_num);
448         } else {
449             config->SlotNum_fileEnabled = 1;
450             strncpy(&config->SlotNum_file[direction][slot_num][0], value, strlen(value));
451             printf("SlotNumTx%d: %s\n",slot_num, config->SlotNum_file[direction][slot_num]);
452         }
453     }else if (strncmp(key, KEY_FILE_SLOT_RX, strlen(KEY_FILE_SLOT_RX)) == 0) {
454         unsigned int slot_num = 0;
455         unsigned int direction = XRAN_DIR_UL;
456         sscanf(key,"SlotNumRx%02u",&slot_num);
457         if (slot_num >= XRAN_N_FE_BUF_LEN) {
458             printf("SlotNumRx%d exceeds max slots supported\n",slot_num);
459         } else {
460             config->SlotNum_fileEnabled = 1;
461             strncpy(&config->SlotNum_file[direction][slot_num][0], value, strlen(value));
462             printf("SlotNumRx%d: %s\n",slot_num, config->SlotNum_file[direction][slot_num]);
463         }
464     } else if (strcmp(key, KEY_PRACH_ENABLE) == 0) {
465         config->enablePrach = atoi(value);
466         printf("Prach enable: %d\n",config->enablePrach);
467     }else if (strcmp(key, KEY_MAX_FRAME_ID) == 0) {
468         config->maxFrameId = atoi(value);
469         printf("maxFrameId: %d\n",config->maxFrameId);
470     } else if (strcmp(key, KEY_SRS_ENABLE) == 0) {
471         config->enableSrs = atoi(value);
472         printf("Srs enable: %d\n",config->enableSrs);
473     } else if (strcmp(key, KEY_PUSCH_MASK_ENABLE) == 0) {
474         config->puschMaskEnable = atoi(value);
475         printf("PUSCH mask enable: %d\n",config->puschMaskEnable);
476     } else if (strcmp(key, KEY_PUSCH_MASK_SLOT) == 0) {
477         config->puschMaskSlot = atoi(value);
478         printf("PUSCH mask enable: %d\n",config->puschMaskSlot);
479     } else if (strcmp(key, KEY_PRACH_CFGIDX) == 0) {
480         config->prachConfigIndex = atoi(value);
481         printf("Prach config index: %d\n",config->prachConfigIndex);
482     } else if (strcmp(key, KEY_SRS_SYM_IDX) == 0) {
483         config->srsSymMask = atoi(value);
484         printf("Srs symbol [0-13]: %d\n",config->srsSymMask);
485     } else if (strncmp(key, KEY_FILE_PRACH_AxC, strlen(KEY_FILE_PRACH_AxC)) == 0) {
486         unsigned int ant_num = 0;
487         sscanf(key,"antPrachC%02u",&ant_num);
488         if (ant_num >= MAX_ANT_CARRIER_SUPPORTED)
489         {
490             printf("antC%d exceeds max antenna supported\n",ant_num);
491         }
492         else{
493             strncpy(&config->prach_file[ant_num][0], value, strlen(value));
494             printf("antPrachC%d: %s\n",ant_num, config->prach_file[ant_num]);
495         }
496     } else if (strcmp(key, KEY_BFW_NUM) == 0) {
497         config->totalBfWeights = atoi(value);
498         printf("%s : %d\n",KEY_BFW_NUM, config->totalBfWeights);
499         /* timing */
500     } else if (strcmp(key, KEY_TADV_CP_DL ) == 0) {
501         config->Tadv_cp_dl = atoi(value);
502         printf("Tadv_cp_dl: %d\n",config->Tadv_cp_dl);
503     } else if (strcmp(key, KEY_T2A_MIN_CP_DL ) == 0) {
504         config->T2a_min_cp_dl = atoi(value);
505         printf("T2a_min_cp_dl: %d\n",config->T2a_min_cp_dl);
506     } else if (strcmp(key, KEY_T2A_MAX_CP_DL ) == 0) {
507         config->T2a_max_cp_dl = atoi(value);
508         printf("T2a_max_cp_dl: %d\n",config->T2a_max_cp_dl);
509     } else if (strcmp(key, KEY_T2A_MIN_CP_UL ) == 0) {
510         config->T2a_min_cp_ul = atoi(value);
511         printf("T2a_min_cp_ul: %d\n",config->T2a_min_cp_ul);
512     } else if (strcmp(key, KEY_T2A_MAX_CP_UL ) == 0) {
513         config->T2a_max_cp_ul = atoi(value);
514         printf("T2a_max_cp_ul: %d\n",config->T2a_max_cp_ul);
515     } else if (strcmp(key, KEY_T2A_MIN_UP ) == 0) {
516         config->T2a_min_up = atoi(value);
517         printf("T2a_min_up: %d\n",config->T2a_min_up);
518     } else if (strcmp(key, KEY_T2A_MAX_UP ) == 0) {
519         config->T2a_max_up = atoi(value);
520         printf("T2a_max_up: %d\n",config->T2a_max_up);
521     } else if (strcmp(key, KEY_TA3_MIN ) == 0) {
522         config->Ta3_min = atoi(value);
523         printf("Ta3_min: %d\n",config->Ta3_min);
524     } else if (strcmp(key, KEY_TA3_MAX ) == 0) {
525         config->Ta3_max = atoi(value);
526         printf("Ta3_max: %d\n",config->Ta3_max);
527     } else if (strcmp(key, KEY_T1A_MIN_CP_DL ) == 0) {
528         config->T1a_min_cp_dl = atoi(value);
529         printf("T1a_min_cp_dl: %d\n",config->T1a_min_cp_dl);
530     } else if (strcmp(key, KEY_T1A_MAX_CP_DL ) == 0) {
531         config->T1a_max_cp_dl = atoi(value);
532         printf("T1a_max_cp_dl: %d\n",config->T1a_max_cp_dl);
533     } else if (strcmp(key, KEY_T1A_MIN_CP_UL ) == 0) {
534         config->T1a_min_cp_ul = atoi(value);
535         printf("T1a_min_cp_ul: %d\n",config->T1a_min_cp_ul);
536     } else if (strcmp(key, KEY_T1A_MAX_CP_UL ) == 0) {
537         config->T1a_max_cp_ul = atoi(value);
538         printf("T1a_max_cp_ul: %d\n",config->T1a_max_cp_ul);
539     } else if (strcmp(key, KEY_T1A_MIN_UP ) == 0) {
540         config->T1a_min_up = atoi(value);
541         printf("T1a_min_up: %d\n",config->T1a_min_up);
542     } else if (strcmp(key, KEY_T1A_MAX_UP ) == 0) {
543         config->T1a_max_up = atoi(value);
544         printf("T1a_max_up: %d\n",config->T1a_max_up);
545     } else if (strcmp(key, KEY_TA4_MIN ) == 0) {
546         config->Ta4_min = atoi(value);
547         printf("Ta4_min: %d\n",config->Ta4_min);
548     } else if (strcmp(key, KEY_TA4_MAX ) == 0) {
549         config->Ta4_max = atoi(value);
550         printf("Ta4_max: %d\n",config->Ta4_max);
551         /* end of timing */
552     } else if (strcmp(key, KEY_CP_ENABLE ) == 0) {
553         config->enableCP = atoi(value);
554         printf("CPenable: %d\n",config->enableCP);
555     } else if (strcmp(key, KEY_DEBUG_STOP ) == 0) {
556         config->debugStop = atoi(value);
557         printf("debugStop: %d\n",config->debugStop);
558     } else if (strcmp(key, KEY_DEBUG_STOP_CNT) == 0) {
559         config->debugStopCount = atoi(value);
560         printf("debugStopCount: %d\n",config->debugStopCount);
561     } else if (strcmp(key, KEY_BBDEV_MODE) == 0) {
562         config->bbdevMode = atoi(value);
563         printf("bbdevMode: %d\n",config->debugStopCount);
564     } else if (strcmp(key, KEY_DYNA_SEC_ENA) == 0) {
565         config->DynamicSectionEna = atoi(value);
566         printf("DynamicSectionEna: %d\n",config->DynamicSectionEna);
567     } else if (strcmp(key, KEY_ALPHA) == 0) {
568         config->GPS_Alpha = atoi(value);
569         printf("GPS_Alpha: %d\n",config->GPS_Alpha);
570     } else if (strcmp(key, KEY_BETA) == 0) {
571         config->GPS_Beta = atoi(value);
572         printf("GPS_Beta: %d\n",config->GPS_Beta);
573     } else if (strcmp(key, KEY_CP_VTAG ) == 0) {
574         config->cp_vlan_tag = atoi(value);
575         printf("cp_vlan_tag: %d\n",config->cp_vlan_tag);
576     } else if (strcmp(key, KEY_UP_VTAG ) == 0) {
577         config->up_vlan_tag = atoi(value);
578         printf("up_vlan_tag: %d\n",config->up_vlan_tag);
579     } else if (strcmp(key, KEY_MAX_SEC_SYM ) == 0) {
580         config->max_sections_per_symbol = atoi(value);
581         printf("max_sections_per_symbol: %d\n",config->max_sections_per_symbol);
582     } else if (strcmp(key, KEY_MAX_SEC_SLOT ) == 0) {
583         config->max_sections_per_slot = atoi(value);
584         printf("max_sections_per_slot: %d\n",config->max_sections_per_slot);
585     } else if (strcmp(key, KEY_NPRBELEM_UL ) == 0) {
586         config->p_PrbMapUl->nPrbElm = atoi(value);
587         if (config->p_PrbMapUl->nPrbElm > XRAN_MAX_SECTIONS_PER_SLOT)
588         {
589             printf("nTddPeriod is larger than max allowed, invalid!\n");
590             config->p_PrbMapUl->nPrbElm = XRAN_MAX_SECTIONS_PER_SLOT;
591         }
592         printf("nPrbElemUl: %d\n",config->p_PrbMapUl->nPrbElm);
593     } else if (strncmp(key, KEY_PRBELEM_UL, strlen(KEY_PRBELEM_UL)) == 0) {
594         sscanf(key,"PrbElemUl%u",&section_idx_ul);
595         if (section_idx_ul >= config->p_PrbMapUl->nPrbElm){
596             printf("section_idx %d exceeds nPrbElemUl\n",section_idx_ul);
597         }
598         else{
599             struct xran_prb_elm *pPrbElem = &config->p_PrbMapUl->prbMap[section_idx_ul];
600             sscanf(value, "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd",
601                 (int16_t*)&pPrbElem->nRBStart,
602                 (int16_t*)&pPrbElem->nRBSize,
603                 (int16_t*)&pPrbElem->nStartSymb,
604                 (int16_t*)&pPrbElem->numSymb,
605                 (int16_t*)&pPrbElem->nBeamIndex,
606                 (int16_t*)&pPrbElem->bf_weight_update,
607                 (int16_t*)&pPrbElem->compMethod,
608                 (int16_t*)&pPrbElem->iqWidth,
609                 (int16_t*)&pPrbElem->BeamFormingType);
610             printf("nPrbElemUl%d: ",section_idx_ul);
611             printf("nRBStart %d,nRBSize %d,nStartSymb %d,numSymb %d,nBeamIndex %d, bf_weight_update %d compMethod %d, iqWidth %d BeamFormingType %d\n",
612                 pPrbElem->nRBStart,pPrbElem->nRBSize,pPrbElem->nStartSymb,pPrbElem->numSymb,pPrbElem->nBeamIndex, pPrbElem->bf_weight_update, pPrbElem->compMethod, pPrbElem->iqWidth, pPrbElem->BeamFormingType);
613         }
614     } else if(strncmp(key, KEY_EXTBFW_UL, strlen(KEY_EXTBFW_UL)) == 0) {
615         sscanf(key, "ExtBfwUl%u", &section_idx_ul);
616         if(section_idx_ul >= config->p_PrbMapUl->nPrbElm) {
617             printf("section_idx %d of bfw exceeds nPrbElemUl\n",section_idx_ul);
618         }
619         else{
620             struct xran_prb_elm *pPrbElem = &config->p_PrbMapUl->prbMap[section_idx_ul];
621             sscanf(value, "%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",
622                 (uint8_t*)&pPrbElem->bf_weight.numBundPrb,
623                 (uint8_t*)&pPrbElem->bf_weight.numSetBFWs,
624                 (uint8_t*)&pPrbElem->bf_weight.RAD,
625                 (uint8_t*)&pPrbElem->bf_weight.disableBFWs,
626                 (uint8_t*)&pPrbElem->bf_weight.bfwIqWidth,
627                 (uint8_t*)&pPrbElem->bf_weight.bfwCompMeth);
628             printf(KEY_EXTBFW_UL"%d: ", section_idx_ul);
629             printf("numBundPrb %d, numSetBFW %d, RAD %d, disableBFW %d, bfwIqWidth %d, bfwCompMeth %d\n",
630                 pPrbElem->bf_weight.numBundPrb, pPrbElem->bf_weight.numSetBFWs, pPrbElem->bf_weight.RAD, pPrbElem->bf_weight.disableBFWs, pPrbElem->bf_weight.bfwIqWidth, pPrbElem->bf_weight.bfwCompMeth);
631         }
632     }else if (strcmp(key, KEY_NPRBELEM_DL ) == 0) {
633         config->p_PrbMapDl->nPrbElm = atoi(value);
634         if (config->p_PrbMapDl->nPrbElm > XRAN_MAX_SECTIONS_PER_SLOT)
635         {
636             printf("nPrbElm is larger than max allowed, invalid!\n");
637             config->p_PrbMapDl->nPrbElm = XRAN_MAX_SECTIONS_PER_SLOT;
638         }
639         printf("nPrbElemDl: %d\n",config->p_PrbMapDl->nPrbElm);
640     } else if (strncmp(key, KEY_PRBELEM_DL, strlen(KEY_PRBELEM_DL)) == 0) {
641         sscanf(key,"PrbElemDl%u",&section_idx_dl);
642         if (section_idx_dl >= config->p_PrbMapDl->nPrbElm){
643             printf("section_idx %d exceeds nPrbElemDl\n",section_idx_dl);
644         }
645         else{
646             struct xran_prb_elm *pPrbElem = &config->p_PrbMapDl->prbMap[section_idx_dl];
647             sscanf(value, "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd",
648                 (int16_t*)&pPrbElem->nRBStart,
649                 (int16_t*)&pPrbElem->nRBSize,
650                 (int16_t*)&pPrbElem->nStartSymb,
651                 (int16_t*)&pPrbElem->numSymb,
652                 (int16_t*)&pPrbElem->nBeamIndex,
653                 (int16_t*)&pPrbElem->bf_weight_update,
654                 (int16_t*)&pPrbElem->compMethod,
655                 (int16_t*)&pPrbElem->iqWidth,
656                 (int16_t*)&pPrbElem->BeamFormingType,
657                 (int16_t*)&pPrbElem->ScaleFactor,
658                 (int16_t*)&pPrbElem->reMask);
659             printf("nPrbElemDl%d: ",section_idx_dl);
660             printf("nRBStart %d,nRBSize %d,nStartSymb %d,numSymb %d,nBeamIndex %d, bf_weight_update %d compMethod %d, iqWidth %d BeamFormingType %d ScaleFactor %d reMask %d\n",
661                 pPrbElem->nRBStart,pPrbElem->nRBSize,pPrbElem->nStartSymb,pPrbElem->numSymb,pPrbElem->nBeamIndex, pPrbElem->bf_weight_update, pPrbElem->compMethod, pPrbElem->iqWidth, pPrbElem->BeamFormingType, pPrbElem->ScaleFactor, pPrbElem->reMask);
662         }
663     } else if(strncmp(key, KEY_EXTBFW_DL, strlen(KEY_EXTBFW_DL)) == 0) {
664         sscanf(key, "ExtBfwDl%u", &section_idx_dl);
665         if(section_idx_dl >= config->p_PrbMapDl->nPrbElm) {
666             printf("section_idx %d of bfw exceeds nPrbElemUl\n",section_idx_dl);
667         }
668         else{
669             struct xran_prb_elm *pPrbElem = &config->p_PrbMapDl->prbMap[section_idx_dl];
670             sscanf(value, "%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",
671                 (uint8_t*)&pPrbElem->bf_weight.numBundPrb,
672                 (uint8_t*)&pPrbElem->bf_weight.numSetBFWs,
673                 (uint8_t*)&pPrbElem->bf_weight.RAD,
674                 (uint8_t*)&pPrbElem->bf_weight.disableBFWs,
675                 (uint8_t*)&pPrbElem->bf_weight.bfwIqWidth,
676                 (uint8_t*)&pPrbElem->bf_weight.bfwCompMeth);
677             printf(KEY_EXTBFW_DL"%d: ", section_idx_dl);
678             printf("numBundPrb %d, numSetBFW %d, RAD %d, disableBFW %d, bfwIqWidth %d, bfwCompMeth %d\n",
679                 pPrbElem->bf_weight.numBundPrb, pPrbElem->bf_weight.numSetBFWs, pPrbElem->bf_weight.RAD, pPrbElem->bf_weight.disableBFWs, pPrbElem->bf_weight.bfwIqWidth, pPrbElem->bf_weight.bfwCompMeth);
680         }
681     } else if (strcmp(key, KEY_NPRBELEM_SRS ) == 0) {
682         config->p_PrbMapSrs->nPrbElm = atoi(value);
683         if (config->p_PrbMapSrs->nPrbElm > XRAN_MAX_SECTIONS_PER_SLOT)
684         {
685             printf("nPrbElm is larger than max allowed, invalid!\n");
686             config->p_PrbMapSrs->nPrbElm = XRAN_MAX_SECTIONS_PER_SLOT;
687         }
688         printf("nPrbElemSrs: %d\n",config->p_PrbMapSrs->nPrbElm);
689     } else if (strncmp(key, KEY_PRBELEM_SRS, strlen(KEY_PRBELEM_SRS)) == 0) {
690         sscanf(key,"PrbElemSrs%u",&section_idx_srs);
691         if (section_idx_srs >= config->p_PrbMapSrs->nPrbElm) {
692             printf("section_idx %d exceeds nPrbElemSrs\n",section_idx_srs);
693         }else {
694             struct xran_prb_elm *pPrbElem = &config->p_PrbMapSrs->prbMap[section_idx_srs];
695             sscanf(value, "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd",
696                 (int16_t*)&pPrbElem->nRBStart,
697                 (int16_t*)&pPrbElem->nRBSize,
698                 (int16_t*)&pPrbElem->nStartSymb,
699                 (int16_t*)&pPrbElem->numSymb,
700                 (int16_t*)&pPrbElem->nBeamIndex,
701                 (int16_t*)&pPrbElem->bf_weight_update,
702                 (int16_t*)&pPrbElem->compMethod,
703                 (int16_t*)&pPrbElem->iqWidth,
704                 (int16_t*)&pPrbElem->BeamFormingType);
705             printf("nPrbElemSrs%d: ",section_idx_srs);
706             printf("nRBStart %d,nRBSize %d,nStartSymb %d,numSymb %d,nBeamIndex %d, bf_weight_update %d compMethod %d, iqWidth %d BeamFormingType %d\n",
707                 pPrbElem->nRBStart,pPrbElem->nRBSize,pPrbElem->nStartSymb,pPrbElem->numSymb,pPrbElem->nBeamIndex, pPrbElem->bf_weight_update, pPrbElem->compMethod, pPrbElem->iqWidth, pPrbElem->BeamFormingType);
708         }
709     }else {
710         printf("Unsupported configuration key [%s]\n", key);
711         return -1;
712     }
713
714     return 0;
715 }
716
717 static int
718 fillUsecaseStruct(UsecaseConfig *config, const char *key, const char *value)
719 {
720     int32_t parse_res = 0;
721     if (strcmp(key, KEY_APP_MODE) == 0){
722         config->appMode = atoi(value);
723         printf("appMode %d \n", config->appMode);
724     } else if (strcmp(key, KEY_XU_NUM) == 0){
725         config->oXuNum = atoi(value);
726         printf("oXuNum %d \n", config->oXuNum);
727     } else if (strcmp(key, KEY_XU_ETH_LINK_SPD) == 0){
728         config->EthLinkSpeed = atoi(value);
729         printf("EthLinkSpeed %d \n", config->EthLinkSpeed);
730     } else if (strcmp(key, KEY_XU_ETH_LINE_NUM) == 0){
731         config->EthLinesNumber = atoi(value);
732         printf("EthLinkSpeed %d \n", config->EthLinesNumber);
733     } else if (strcmp(key, KEY_XU_RXQ_VF) == 0){
734         config->num_rxq = atoi(value);
735         printf("oXuRxqNumber %d \n", config->num_rxq);
736     } else if (strcmp(key, KEY_XU_CP_ON_ONE_VF) == 0) {
737         config->one_vf_cu_plane = atoi(value);
738         printf("oXuCPon1Vf %d \n", config->one_vf_cu_plane);
739     } else if (strcmp(key, KEY_IO_SLEEP) == 0) {
740         config->io_sleep = atoi(value);
741         printf("io_sleep %d \n", config->io_sleep);
742     } else if (strcmp(key, KEY_IO_CORE) == 0) {
743         config->io_core = atoi(value);
744         printf("io_core %d [core id]\n", config->io_core);
745     } else if (strcmp(key, KEY_MAIN_CORE) == 0) {
746         config->main_core = atoi(value);
747         printf("main_core %d [core id]\n", config->main_core);
748     } else if (strcmp(key, KEY_IO_WORKER) == 0) {
749         config->io_worker = strtoll(value, NULL, 0);
750         printf("io_worker 0x%lx [mask]\n", config->io_worker);
751     } else if (strcmp(key, KEY_IO_WORKER_64_127) == 0) {
752         config->io_worker_64_127 = strtoll(value, NULL, 0);
753         printf("io_worker_64_127 0x%lx [mask]\n", config->io_worker_64_127);
754     } else if (strcmp(key, KEY_SYSTEM_CORE) == 0) {
755         config->system_core = atoi(value);
756         printf("system core %d [core id]\n", config->system_core);
757     } else if (strcmp(key, KEY_IOVA_MODE) == 0) {
758         config->iova_mode = atoi(value);
759         printf("iova_mode %d\n", config->iova_mode);
760     } else if (strcmp(key, KEY_DPDK_MEM_SZ) == 0) {
761         config->dpdk_mem_sz = atoi(value);
762         printf("dpdk_mem_sz %d\n", config->dpdk_mem_sz);
763     } else if (strcmp(key, KEY_INSTANCE_ID) == 0) {
764         config->instance_id = atoi(value);
765         printf("instance_id %d\n", config->instance_id);
766     }else if (strncmp(key, KEY_FILE_O_XU_CFG, strlen(KEY_FILE_O_XU_CFG)) == 0) {
767         unsigned int o_xu_id = 0;
768         sscanf(key,"oXuCfgFile%02u",&o_xu_id);
769         if (o_xu_id >= XRAN_PORTS_NUM) {
770             printf("oXuCfgFile%d exceeds max O-XU supported\n",o_xu_id);
771         } else {
772             strncpy(&config->o_xu_cfg_file[o_xu_id][0], value, strlen(value));
773             printf("oXuCfgFile%d: %s\n",o_xu_id, config->o_xu_cfg_file[o_xu_id]);
774         }
775     } else if (strncmp(key, KEY_OWDM_INIT_EN, strlen(KEY_OWDM_INIT_EN)) == 0) {
776         config->owdmInitEn = atoi(value);
777         printf("owdmInitEn %d\n", config->owdmInitEn);
778     } else if (strncmp(key, KEY_OWDM_MEAS_METH, strlen(KEY_OWDM_MEAS_METH)) == 0) {
779         config->owdmMeasMeth =  atoi(value);
780         printf("owdmMeasMeth %d\n", config->owdmMeasMeth);
781     } else if (strncmp(key, KEY_OWDM_NUM_SAMPS, strlen(KEY_OWDM_NUM_SAMPS)) == 0) {
782         config->owdmNumSamps =  atoi(value);
783         printf("owdmNumSamps %d\n", config->owdmNumSamps);
784     } else if (strncmp(key, KEY_OWDM_FLTR_TYPE, strlen(KEY_OWDM_FLTR_TYPE)) == 0) {
785         config->owdmFltType =  atoi(value);
786         printf("owdmFltType %d\n", config->owdmFltType);
787     } else if (strncmp(key, KEY_OWDM_RSP_TO, strlen(KEY_OWDM_RSP_TO)) == 0) {
788         config->owdmRspTo =  atol(value);
789         printf("owdmRspTo %lu\n", config->owdmRspTo);
790     } else if (strncmp(key, KEY_OWDM_MEAS_ID, strlen(KEY_OWDM_MEAS_ID)) == 0) {
791         config->owdmMeasId =  atoi(value);
792         printf("owdmMeasId %d\n", config->owdmMeasId);
793     } else if (strncmp(key, KEY_OWDM_EN, strlen(KEY_OWDM_EN)) == 0) {
794         config->owdmEnable =  atoi(value);
795         printf("owdmEnable %d\n", config->owdmEnable);
796     } else if (strncmp(key, KEY_OWDM_PL_LENGTH, strlen(KEY_OWDM_PL_LENGTH)) == 0) {
797         config->owdmPlLength = atoi(value);
798         printf("owdmPlLength %d\n", config->owdmPlLength);
799     } else if (strncmp(key, KEY_OWDM_MEAS_ST, strlen(KEY_OWDM_MEAS_ST)) == 0) {
800         config->owdmMeasState =  atoi(value);
801         printf("owdmMeasState %d\n", config->owdmMeasState);
802     } else if (strncmp(key, KEY_O_XU_PCIE_BUS, strlen(KEY_O_XU_PCIE_BUS)) == 0) {
803         unsigned int o_xu_id = 0;
804         unsigned int vf_num = 0;
805         sscanf(key,"PciBusAddoXu%02uVf%02u",&o_xu_id, &vf_num);
806         if (o_xu_id >= XRAN_PORTS_NUM || vf_num >= XRAN_VF_MAX){
807             printf("PciBusAddoXu%dVf%d exceeds max O-XU supported\n",o_xu_id, vf_num);
808         } else {
809             strncpy(&config->o_xu_pcie_bus_addr[o_xu_id][vf_num][0], value, strlen(value));
810             printf("PciBusAddoXu%dVf%d: %s\n",o_xu_id, vf_num, &config->o_xu_pcie_bus_addr[o_xu_id][vf_num][0]);
811         }
812     } else if (strncmp(key, KEY_O_XU_REM_MAC, strlen(KEY_O_XU_REM_MAC)) == 0) {
813         unsigned int xu_num = 0;
814         unsigned int vf_num = 0;
815
816         sscanf(key,"oXuRem%02uMac%02u",&xu_num, &vf_num);
817
818         if (xu_num >= XRAN_PORTS_NUM || vf_num >= XRAN_VF_MAX) {
819             printf("oXuRem%02uMac%02u exceeds max supported\n",xu_num, vf_num);
820         } else {
821             printf("oXuRem%02uMac%02u: %s\n",xu_num, vf_num, value);
822             sscanf(value, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", (uint8_t*)&config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[0],
823                                                (uint8_t*)&config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[1],
824                                                (uint8_t*)&config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[2],
825                                                (uint8_t*)&config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[3],
826                                                (uint8_t*)&config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[4],
827                                                (uint8_t*)&config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[5]);
828
829             printf("[xu %d vf %d]RU MAC address: %02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx\n",
830                 xu_num,
831                 vf_num,
832                 config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[0],
833                 config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[1],
834                 config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[2],
835                 config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[3],
836                 config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[4],
837                 config->remote_o_xu_addr[xu_num][vf_num].addr_bytes[5]);
838         }
839     } else {
840         printf("Unsupported configuration key [%s]\n", key);
841         return -1;
842     }
843
844     return 0;
845 }
846
847 static int
848 fillSlotStructAsCb(void* cbParam, const char *key, const char *value)
849 {
850     struct slot_cfg_to_pars *p_slot_cfg = (struct slot_cfg_to_pars*) cbParam;
851     RuntimeConfig *config  = p_slot_cfg->config;
852     int32_t  direction     = p_slot_cfg->direction;
853     int32_t  slot_idx      = p_slot_cfg->slot_idx;
854     uint32_t section_idx   = 0;
855
856     //printf("Dir %d slot %d\n", direction, slot_idx);
857
858     if (strcmp(key, KEY_NPRBELEM_UL ) == 0) {
859         config->p_SlotPrbMap[direction][slot_idx]->nPrbElm = atoi(value);
860         if (config->p_SlotPrbMap[direction][slot_idx]->nPrbElm > XRAN_MAX_SECTIONS_PER_SLOT)
861         {
862             printf("nTddPeriod is larger than max allowed, invalid!\n");
863             config->p_SlotPrbMap[direction][slot_idx]->nPrbElm  = XRAN_MAX_SECTIONS_PER_SLOT;
864         }
865         printf("nPrbElemUl: %d\n",config->p_SlotPrbMap[direction][slot_idx]->nPrbElm );
866     } else if (strncmp(key, KEY_PRBELEM_UL_ANT_M, strlen(KEY_PRBELEM_UL_ANT_M)) == 0) {
867         sscanf(key,"PrbElemUlAntCMask%u",&section_idx);
868         if (section_idx >= config->p_SlotPrbMap[direction][slot_idx]->nPrbElm){
869             printf("section_idx %d exceeds nPrbElemul\n",section_idx);
870         }
871         else{
872             sscanf(value, "%lx",(uint64_t*)&config->SlotPrbAntCMask[direction][slot_idx][section_idx]);
873             printf("%s%u 0x%lx\n",KEY_PRBELEM_UL_ANT_M, section_idx, config->SlotPrbAntCMask[direction][slot_idx][section_idx]);
874         }
875     }  else if (strncmp(key, KEY_PRBELEM_UL_CC_M, strlen(KEY_PRBELEM_UL_CC_M)) == 0) {
876         sscanf(key,"PrbElemUlCCMask%u",&section_idx);
877         if (section_idx >= config->p_SlotPrbMap[direction][slot_idx]->nPrbElm){
878             printf("section_idx %d exceeds nPrbElemUL\n",section_idx);
879         }
880         else{
881             sscanf(value, "%02hx",(uint16_t*)&config->SlotPrbCCmask[direction][slot_idx][section_idx]);
882             printf("%s%u 0x%02x\n",KEY_PRBELEM_UL_CC_M, section_idx, config->SlotPrbCCmask[direction][slot_idx][section_idx]);
883         }
884     } else if (strncmp(key, KEY_PRBELEM_UL, strlen(KEY_PRBELEM_UL)) == 0) {
885         sscanf(key,"PrbElemUl%u",&section_idx);
886         if (section_idx >=  config->p_SlotPrbMap[direction][slot_idx]->nPrbElm) {
887             printf("section_idx %d exceeds nPrbElemUl\n",section_idx);
888         }
889         else {
890             struct xran_prb_elm *pPrbElem = &config->p_SlotPrbMap[direction][slot_idx]->prbMap[section_idx];
891             sscanf(value, "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd",
892                 (int16_t*)&pPrbElem->nRBStart,
893                 (int16_t*)&pPrbElem->nRBSize,
894                 (int16_t*)&pPrbElem->nStartSymb,
895                 (int16_t*)&pPrbElem->numSymb,
896                 (int16_t*)&pPrbElem->nBeamIndex,
897                 (int16_t*)&pPrbElem->bf_weight_update,
898                 (int16_t*)&pPrbElem->compMethod,
899                 (int16_t*)&pPrbElem->iqWidth,
900                 (int16_t*)&pPrbElem->BeamFormingType);
901             printf("nPrbElemUl%d: ",section_idx);
902             printf("nRBStart %d,nRBSize %d,nStartSymb %d,numSymb %d,nBeamIndex %d, bf_weight_update %d compMethod %d, iqWidth %d BeamFormingType %d\n",
903                 pPrbElem->nRBStart,pPrbElem->nRBSize,pPrbElem->nStartSymb,pPrbElem->numSymb,pPrbElem->nBeamIndex, pPrbElem->bf_weight_update, pPrbElem->compMethod, pPrbElem->iqWidth, pPrbElem->BeamFormingType);
904         }
905     } else if(strncmp(key, KEY_EXTBFW_UL, strlen(KEY_EXTBFW_UL)) == 0) {
906         sscanf(key, "ExtBfwUl%u", &section_idx);
907         if(section_idx >= config->p_SlotPrbMap[direction][slot_idx]->nPrbElm) {
908             printf("section_idx %d of bfw exceeds nPrbElemUl\n",section_idx);
909         }else{
910             struct xran_prb_elm *pPrbElem = &config->p_SlotPrbMap[direction][slot_idx]->prbMap[section_idx];
911             sscanf(value, "%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",
912                 (uint8_t*)&pPrbElem->bf_weight.numBundPrb,
913                 (uint8_t*)&pPrbElem->bf_weight.numSetBFWs,
914                 (uint8_t*)&pPrbElem->bf_weight.RAD,
915                 (uint8_t*)&pPrbElem->bf_weight.disableBFWs,
916                 (uint8_t*)&pPrbElem->bf_weight.bfwIqWidth,
917                 (uint8_t*)&pPrbElem->bf_weight.bfwCompMeth);
918             printf(KEY_EXTBFW_UL"%d: ", section_idx);
919             printf("numBundPrb %d, numSetBFW %d, RAD %d, disableBFW %d, bfwIqWidth %d, bfwCompMeth %d\n",
920                 pPrbElem->bf_weight.numBundPrb, pPrbElem->bf_weight.numSetBFWs, pPrbElem->bf_weight.RAD, pPrbElem->bf_weight.disableBFWs, pPrbElem->bf_weight.bfwIqWidth, pPrbElem->bf_weight.bfwCompMeth);
921         }
922     }else if (strcmp(key, KEY_NPRBELEM_DL ) == 0) {
923         config->p_SlotPrbMap[direction][slot_idx]->nPrbElm = atoi(value);
924         if (config->p_SlotPrbMap[direction][slot_idx]->nPrbElm > XRAN_MAX_SECTIONS_PER_SLOT)
925         {
926             printf("nTddPeriod is larger than max allowed, invalid!\n");
927             config->p_SlotPrbMap[direction][slot_idx]->nPrbElm = XRAN_MAX_SECTIONS_PER_SLOT;
928         }
929         printf("nPrbElemDl: %d\n",config->p_SlotPrbMap[direction][slot_idx]->nPrbElm);
930     } else if (strncmp(key, KEY_PRBELEM_DL_ANT_M, strlen(KEY_PRBELEM_DL_ANT_M)) == 0) {
931         sscanf(key,"PrbElemDlAntCMask%u",&section_idx);
932         if (section_idx >= config->p_SlotPrbMap[direction][slot_idx]->nPrbElm){
933             printf("section_idx %d exceeds nPrbElemDl\n",section_idx);
934         }
935         else{
936             sscanf(value, "%lx",(uint64_t*)&config->SlotPrbAntCMask[direction][slot_idx][section_idx]);
937             printf("%s%u 0x%lx\n",KEY_PRBELEM_DL_ANT_M, section_idx, config->SlotPrbAntCMask[direction][slot_idx][section_idx]);
938         }
939     }  else if (strncmp(key, KEY_PRBELEM_DL_CC_M, strlen(KEY_PRBELEM_DL_CC_M)) == 0) {
940         sscanf(key,"PrbElemDlCCMask%u",&section_idx);
941         if (section_idx >= config->p_SlotPrbMap[direction][slot_idx]->nPrbElm){
942             printf("section_idx %d exceeds nPrbElemDl\n",section_idx);
943         }
944         else{
945             sscanf(value, "%02hx",(uint16_t*)&config->SlotPrbCCmask[direction][slot_idx][section_idx]);
946             printf("%s%u 0x%02x\n",KEY_PRBELEM_DL_CC_M, section_idx, config->SlotPrbCCmask[direction][slot_idx][section_idx]);
947         }
948     } else if (strncmp(key, KEY_PRBELEM_DL, strlen(KEY_PRBELEM_DL)) == 0) {
949         sscanf(key,"PrbElemDl%u",&section_idx);
950         if (section_idx >= config->p_SlotPrbMap[direction][slot_idx]->nPrbElm){
951             printf("section_idx %d exceeds nPrbElemDl\n",section_idx);
952         }
953         else{
954             struct xran_prb_elm *pPrbElem = &config->p_SlotPrbMap[direction][slot_idx]->prbMap[section_idx];
955             sscanf(value, "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd",
956                 (int16_t*)&pPrbElem->nRBStart,
957                 (int16_t*)&pPrbElem->nRBSize,
958                 (int16_t*)&pPrbElem->nStartSymb,
959                 (int16_t*)&pPrbElem->numSymb,
960                 (int16_t*)&pPrbElem->nBeamIndex,
961                 (int16_t*)&pPrbElem->bf_weight_update,
962                 (int16_t*)&pPrbElem->compMethod,
963                 (int16_t*)&pPrbElem->iqWidth,
964                 (int16_t*)&pPrbElem->BeamFormingType);
965             printf("nPrbElemDl%d: ",section_idx);
966             printf("nRBStart %d,nRBSize %d,nStartSymb %d,numSymb %d,nBeamIndex %d, bf_weight_update %d compMethod %d, iqWidth %d BeamFormingType %d\n",
967                 pPrbElem->nRBStart,pPrbElem->nRBSize,pPrbElem->nStartSymb,pPrbElem->numSymb,pPrbElem->nBeamIndex, pPrbElem->bf_weight_update, pPrbElem->compMethod, pPrbElem->iqWidth, pPrbElem->BeamFormingType);
968         }
969     } else if(strncmp(key, KEY_EXTBFW_DL, strlen(KEY_EXTBFW_DL)) == 0) {
970         sscanf(key, "ExtBfwDl%u", &section_idx);
971         if(section_idx >= config->p_SlotPrbMap[direction][slot_idx]->nPrbElm) {
972             printf("section_idx %d of bfw exceeds nPrbElemUl\n",section_idx);
973         }
974         else{
975             struct xran_prb_elm *pPrbElem = &config->p_SlotPrbMap[direction][slot_idx]->prbMap[section_idx];
976             sscanf(value, "%hhu,%hhu,%hhu,%hhu,%hhu,%hhu",
977                 (uint8_t*)&pPrbElem->bf_weight.numBundPrb,
978                 (uint8_t*)&pPrbElem->bf_weight.numSetBFWs,
979                 (uint8_t*)&pPrbElem->bf_weight.RAD,
980                 (uint8_t*)&pPrbElem->bf_weight.disableBFWs,
981                 (uint8_t*)&pPrbElem->bf_weight.bfwIqWidth,
982                 (uint8_t*)&pPrbElem->bf_weight.bfwCompMeth);
983             printf(KEY_EXTBFW_DL"%d: ",section_idx);
984             printf("numBundPrb %d, numSetBFW %d, RAD %d, disableBFW %d, bfwIqWidth %d, bfwCompMeth %d\n",
985                 pPrbElem->bf_weight.numBundPrb, pPrbElem->bf_weight.numSetBFWs, pPrbElem->bf_weight.RAD, pPrbElem->bf_weight.disableBFWs, pPrbElem->bf_weight.bfwIqWidth, pPrbElem->bf_weight.bfwCompMeth);
986         }
987     } else {
988         printf("Unsupported configuration key [%s]\n", key);
989         return -1;
990     }
991
992     return 0;
993 }
994
995 struct xran_prb_map*
996 config_malloc_prb_map(void)
997 {
998     uint32_t size = sizeof(struct xran_prb_map)  + (XRAN_MAX_SECTIONS_PER_SLOT -1) * sizeof(struct xran_prb_elm);
999     void *ret = NULL;
1000
1001     ret = malloc(size);
1002
1003     if(ret) {
1004         memset(ret, 0, size);
1005         return (struct xran_prb_map*)ret;
1006     } else {
1007         rte_panic("xran_prb_map alloc failed");
1008     }
1009 }
1010
1011 int32_t
1012 config_init(RuntimeConfig *p_o_xu_cfg)
1013 {
1014     int32_t i, j, k, z;
1015     memset(p_o_xu_cfg, 0, sizeof(RuntimeConfig));
1016
1017     p_o_xu_cfg->p_PrbMapDl  = config_malloc_prb_map();
1018     p_o_xu_cfg->p_PrbMapUl  = config_malloc_prb_map();
1019     p_o_xu_cfg->p_PrbMapSrs = config_malloc_prb_map();
1020
1021     for (i= 0; i < XRAN_DIR_MAX; i++){
1022         for (j= 0; j < XRAN_N_FE_BUF_LEN; j++){
1023            p_o_xu_cfg->p_SlotPrbMap[i][j] = config_malloc_prb_map();
1024         }
1025     }
1026
1027     for (i = 0; i < XRAN_DIR_MAX; i++) {
1028         for (j = 0; j < XRAN_N_FE_BUF_LEN; j++) {
1029             for (k = 0; k < XRAN_MAX_SECTOR_NR; k++) {
1030                 for (z = 0; z < XRAN_MAX_ANTENNA_NR; z++) {
1031                     p_o_xu_cfg->p_RunSlotPrbMap[i][j][k][z] = config_malloc_prb_map();
1032                     p_o_xu_cfg->p_RunSrsSlotPrbMap[i][j][k][z] = config_malloc_prb_map();
1033                 }
1034             }
1035         }
1036     }
1037
1038     return 0;
1039 }
1040
1041
1042 int
1043 parseConfigFile(char *filename, RuntimeConfig *config)
1044 {
1045     char inputLine[MAX_LINE_SIZE] = {0};
1046     int inputLen = 0;
1047     int i;
1048     int lineNum = 0;
1049     char key[MAX_LINE_SIZE] = {0};
1050     char value[MAX_LINE_SIZE] = {0};
1051     FILE *file = fopen(filename, "r");
1052
1053     if (NULL == file) {
1054         log_err("Error while opening config file from: %s", filename);
1055         return -1;
1056     }
1057
1058 //    init_config(config);
1059
1060     for (;;) {
1061         if (fgets(inputLine, MAX_LINE_SIZE, file) == NULL) {
1062             if (lineNum > 0) {
1063                 printf("%d lines of config file has been read.\n", lineNum);
1064                 break;
1065             } else {
1066                 printf("Configuration file reading error has occurred.\n");
1067                 fclose(file);
1068                 return -1;
1069             }
1070         }
1071
1072         if (inputLine[strlen(inputLine)-1] == '\n')
1073             inputLine[strlen(inputLine)-1] == '\0';
1074
1075         lineNum++;
1076         inputLen = strlen(inputLine);
1077
1078         for (i=0; i<inputLen; i++)
1079             if (inputLine[i] == '#') {
1080                 inputLine[i] = '\0';
1081                 inputLen = i + 1;
1082                 break;
1083             }
1084
1085         for (i=0; i<inputLen; i++)
1086             if (inputLine[i] == '=') {
1087                 strncpy(key, inputLine, i);
1088                 key[i] = '\0';
1089                 trim(key);
1090                 if ((i + 1 > inputLen - 1) || (i - 2 > inputLen)) {
1091                     log_err("Parsing config file error at line %d", lineNum);
1092                     fclose(file);
1093                     return -1;
1094                 }
1095                 strncpy(value, &inputLine[i+1], (sizeof(value) - 1));
1096                 value[inputLen-i-2] = '\0';
1097                 trim(value);
1098
1099                 if (strlen(key) == 0 || strlen(value) == 0) {
1100                     printf("Parsing config file error at line %d", lineNum);
1101                     fclose(file);
1102                     return -1;
1103                 }
1104
1105                 if (fillConfigStruct(config, key, value) != 0) {
1106                     fclose(file);
1107                     return -1;
1108                 }
1109
1110                 break;
1111             }
1112
1113         memset(&inputLine[0], 0, sizeof(MAX_LINE_SIZE));
1114         memset(&key[0], 0, sizeof(MAX_LINE_SIZE));
1115         memset(&value[0], 0, sizeof(MAX_LINE_SIZE));
1116     }
1117     fclose(file);
1118
1119     return 0;
1120 }
1121
1122 int32_t
1123 parseSlotConfigFile(char *dir, RuntimeConfig *config)
1124 {
1125     int32_t ret     = 0;
1126     char filename[512];
1127     size_t len;
1128     int32_t slot_idx = 0;
1129     int32_t cc_idx = 0;
1130     int32_t ant_idx = 0;
1131     int32_t direction = 0;
1132     struct slot_cfg_to_pars slot_cfg_param;
1133
1134     for (direction = 0; direction < XRAN_DIR_MAX; direction++) {
1135         for (slot_idx = 0; slot_idx  < config->numSlots; slot_idx++){
1136             memset(filename, 0, sizeof(filename));
1137             printf("dir (%s)\n",dir);
1138             len = strlen(dir) + 1;
1139             if (len > 511) {
1140                 printf("parseSlotConfigFile: Name of directory, %s is too long.  Maximum is 511 characters!!\n", dir);
1141                 return -1;
1142             } else {
1143                 strncpy(filename, dir, len);
1144             }
1145             strncat(filename, "/", 1);
1146             len +=1;
1147             len = (sizeof(filename)) - len;
1148
1149             if(len > strlen(config->SlotNum_file[direction][slot_idx])){
1150                 strncat(filename, config->SlotNum_file[direction][slot_idx], RTE_MIN (len, strlen(config->SlotNum_file[direction][slot_idx])));
1151             } else {
1152                 printf("File name error\n");
1153                 return -1;
1154             }
1155             printf("slot_file[%d][%d] (%s)\n",direction, slot_idx, filename);
1156             printf("\n=================== Slot%s %d===================\n", ((direction == XRAN_DIR_UL) ? "RX" : "TX"), slot_idx);
1157
1158             slot_cfg_param.direction = direction;
1159             slot_cfg_param.slot_idx  = slot_idx;
1160             slot_cfg_param.config    = config;
1161
1162             if (parseFileViaCb(filename, fillSlotStructAsCb,  (void*)&slot_cfg_param)) {
1163                 printf("Configuration file error\n");
1164                 return -1;
1165             }
1166         }
1167     }
1168
1169     return ret;
1170 }
1171
1172 int32_t
1173 parseFileViaCb (char *filename, fillConfigStruct_fn cbFn, void* cbParm)
1174 {
1175     char inputLine[MAX_LINE_SIZE] = {0};
1176     int inputLen = 0;
1177     int i;
1178     int lineNum = 0;
1179     char key[MAX_LINE_SIZE] = {0};
1180     char value[MAX_LINE_SIZE] = {0};
1181     FILE *file = fopen(filename, "r");
1182
1183     if (NULL == file) {
1184         log_err("Error while opening config file from: %s", filename);
1185         return -1;
1186     }
1187
1188     for (;;) {
1189         if (fgets(inputLine, MAX_LINE_SIZE, file) == NULL) {
1190             if (lineNum > 0) {
1191                 printf("%d lines of config file has been read.\n", lineNum);
1192                 break;
1193             } else {
1194                 printf("Configuration file reading error has occurred.\n");
1195                 fclose(file);
1196                 return -1;
1197             }
1198         }
1199
1200         if (inputLine[strlen(inputLine)-1] == '\n')
1201             inputLine[strlen(inputLine)-1] == '\0';
1202
1203         lineNum++;
1204         inputLen = strlen(inputLine);
1205
1206         for (i=0; i<inputLen; i++)
1207             if (inputLine[i] == '#') {
1208                 inputLine[i] = '\0';
1209                 inputLen = i + 1;
1210                 break;
1211             }
1212
1213         for (i=0; i<inputLen; i++)
1214             if (inputLine[i] == '=') {
1215                 strncpy(key, inputLine, i);
1216                 key[i] = '\0';
1217                 trim(key);
1218                 if ((i + 1 > inputLen - 1) || (i - 2 > inputLen)) {
1219                     log_err("Parsing config file error at line %d", lineNum);
1220                     fclose(file);
1221                     return -1;
1222                 }
1223                 strncpy(value, &inputLine[i+1], (sizeof(value) - 1));
1224                 value[inputLen-i-2] = '\0';
1225                 trim(value);
1226
1227                 if (strlen(key) == 0 || strlen(value) == 0) {
1228                     printf("Parsing config file error at line %d", lineNum);
1229                     fclose(file);
1230                     return -1;
1231                 }
1232
1233                 if(cbFn){
1234                     if (cbFn(cbParm, key, value) != 0) {
1235                         fclose(file);
1236                         return -1;
1237                     }
1238                 } else {
1239                     printf("cbFn==NULL\n");
1240                     fclose(file);
1241                     return -1;
1242                 }
1243
1244                 break;
1245             }
1246
1247         memset(&inputLine[0], 0, sizeof(MAX_LINE_SIZE));
1248         memset(&key[0], 0, sizeof(MAX_LINE_SIZE));
1249         memset(&value[0], 0, sizeof(MAX_LINE_SIZE));
1250     }
1251     fclose(file);
1252
1253     return 0;
1254 }
1255
1256 int parseUsecaseFile(char *filename, UsecaseConfig *usecase_cfg)
1257 {
1258     char inputLine[MAX_LINE_SIZE] = {0};
1259     int inputLen = 0;
1260     int i;
1261     int lineNum = 0;
1262     char key[MAX_LINE_SIZE] = {0};
1263     char value[MAX_LINE_SIZE] = {0};
1264     FILE *file = fopen(filename, "r");
1265
1266     if (NULL == file) {
1267         log_err("Error while opening config file from: %s", filename);
1268         return -1;
1269     }
1270
1271     for (;;) {
1272         if (fgets(inputLine, MAX_LINE_SIZE, file) == NULL) {
1273             if (lineNum > 0) {
1274                 printf("%d lines of config file has been read.\n", lineNum);
1275                 break;
1276             } else {
1277                 printf("Configuration file reading error has occurred.\n");
1278                 fclose(file);
1279                 return -1;
1280             }
1281         }
1282
1283         if (inputLine[strlen(inputLine)-1] == '\n')
1284             inputLine[strlen(inputLine)-1] == '\0';
1285
1286         lineNum++;
1287         inputLen = strlen(inputLine);
1288
1289         for (i=0; i<inputLen; i++)
1290             if (inputLine[i] == '#') {
1291                 inputLine[i] = '\0';
1292                 inputLen = i + 1;
1293                 break;
1294             }
1295
1296         for (i=0; i<inputLen; i++)
1297             if (inputLine[i] == '=') {
1298                 strncpy(key, inputLine, i);
1299                 key[i] = '\0';
1300                 trim(key);
1301                 if ((i + 1 > inputLen - 1) || (i - 2 > inputLen)) {
1302                     log_err("Parsing config file error at line %d", lineNum);
1303                     fclose(file);
1304                     return -1;
1305                 }
1306                 strncpy(value, &inputLine[i+1], (sizeof(value) - 1));
1307                 value[inputLen-i-2] = '\0';
1308                 trim(value);
1309
1310                 if (strlen(key) == 0 || strlen(value) == 0) {
1311                     printf("Parsing config file error at line %d", lineNum);
1312                     fclose(file);
1313                     return -1;
1314                 }
1315
1316                 if (fillUsecaseStruct(usecase_cfg, key, value) != 0) {
1317                     fclose(file);
1318                     return -1;
1319                 }
1320
1321                 break;
1322             }
1323
1324         memset(&inputLine[0], 0, sizeof(MAX_LINE_SIZE));
1325         memset(&key[0], 0, sizeof(MAX_LINE_SIZE));
1326         memset(&value[0], 0, sizeof(MAX_LINE_SIZE));
1327     }
1328     fclose(file);
1329
1330     return 0;
1331 }