Front Haul Interface Library update to third seed code contribution
[o-du/phy.git] / fhi_lib / app / src / config.c
1 /******************************************************************************
2 *
3 *   Copyright (c) 2019 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 "rte_common.h"
27 #include "config.h"
28 #include "common.h"
29 #include "debug.h"
30
31 #include <rte_ethdev.h>
32 #include <inttypes.h>
33
34 #define MAX_LINE_SIZE 512
35 /* Configuration file maximum supported line length */
36
37 #define KEY_APP_MODE        "appMode"
38 #define KEY_XRAN_MODE       "xranMode"
39 #define KEY_MU_NUMBER       "mu"
40 #define KEY_NDLABSFREPOINTA "nDLAbsFrePointA"
41 #define KEY_NULABSFREPOINTA "nULAbsFrePointA"
42 #define KEY_NDLBANDWIDTH    "nDLBandwidth"
43 #define KEY_NULBANDWIDTH    "nULBandwidth"
44 #define KEY_NDLFFTSIZE      "nDLFftSize"
45 #define KEY_NULFFTSIZE      "nULFftSize"
46
47 #define KEY_NFRAMEDUPLEXTYPE "nFrameDuplexType"
48 #define KEY_NTDDPERIOD       "nTddPeriod"
49
50 #define KEY_SSLOTCONFIG     "sSlotConfig"
51
52 #define KEY_CC_PER_PORT_NUM "ccNum"
53 #define KEY_ANT_NUM         "antNum"
54 #define KEY_UL_ANT_NUM      "antNumUL"
55
56 #define KEY_ANT_ELM_TRX_NUM "antElmTRx"
57
58 #define KEY_MU_MIMO_UES_NUM "muMimoUEs"
59 #define KEY_DLLAYERS_PER_UE "DlLayersPerUe"
60 #define KEY_ULLAYERS_PER_UE "UlLayersPerUe"
61 #define KEY_FILE_DLBFWUE    "DlBfwUe"
62 #define KEY_FILE_ULBFWUE    "UlBfwUe"
63
64 #define KEY_FILE_ULSRS      "antSrsC"
65
66
67 #define KEY_TTI_PERIOD      "ttiPeriod"
68
69 #define KEY_MTU_SIZE        "MTUSize"
70 #define KEY_IO_CORE         "ioCore"
71 #define KEY_SYSTEM_CORE         "systemCore"
72 #define KEY_PKT_PROC_CORE         "pktProcCore"
73 #define KEY_PKT_AUX_CORE         "pktAuxCore"
74 #define KEY_TIMING_CORE         "timingCore"
75
76 #define KEY_INSTANCE_ID     "instanceId"
77
78 #define KEY_LLS_CU_MAC      "llsCUMac"
79 #define KEY_RU_MAC          "ruMac"
80
81 #define KEY_FILE_NUMSLOTS   "numSlots"
82 #define KEY_FILE_AxC        "antC"
83 #define KEY_FILE_PRACH_AxC  "antPrachC"
84
85 #define KEY_PRACH_ENABLE   "rachEanble"
86 #define KEY_SRS_ENABLE     "srsEanble"
87
88 #define KEY_PRACH_CFGIDX   "prachConfigIndex"
89 #define KEY_SRS_SYM_IDX    "srsSym"
90
91 #define KEY_MAX_FRAME_ID   "maxFrameId"
92
93
94 #define KEY_IQ_SWAP        "iqswap"
95 #define KEY_HTONS_SWAP     "nebyteorderswap"
96 #define KEY_COMPRESSION    "compression"
97
98 #define KEY_BFW_NUM        "totalBFWeights"
99
100 #define KEY_TADV_CP_DL     "Tadv_cp_dl"
101 #define KEY_T2A_MIN_CP_DL  "T2a_min_cp_dl"
102 #define KEY_T2A_MAX_CP_DL  "T2a_max_cp_dl"
103 #define KEY_T2A_MIN_CP_UL  "T2a_min_cp_ul"
104 #define KEY_T2A_MAX_CP_UL  "T2a_max_cp_ul"
105 #define KEY_T2A_MIN_UP     "T2a_min_up"
106 #define KEY_T2A_MAX_UP     "T2a_max_up"
107 #define KEY_TA3_MIN        "Ta3_min"
108 #define KEY_TA3_MAX        "Ta3_max"
109 #define KEY_T1A_MIN_CP_DL  "T1a_min_cp_dl"
110 #define KEY_T1A_MAX_CP_DL  "T1a_max_cp_dl"
111 #define KEY_T1A_MIN_CP_UL  "T1a_min_cp_ul"
112 #define KEY_T1A_MAX_CP_UL  "T1a_max_cp_ul"
113 #define KEY_T1A_MIN_UP     "T1a_min_up"
114 #define KEY_T1A_MAX_UP     "T1a_max_up"
115 #define KEY_TA4_MIN        "Ta4_min"
116 #define KEY_TA4_MAX        "Ta4_max"
117
118
119 #define KEY_CP_ENABLE      "CPenable"
120 #define KEY_CP_VTAG        "c_plane_vlan_tag"
121 #define KEY_UP_VTAG        "u_plane_vlan_tag"
122 #define KEY_DEBUG_STOP     "debugStop"
123 #define KEY_DEBUG_STOP_CNT "debugStopCount"
124 #define KEY_BBDEV_MODE     "bbdevMode"
125 #define KEY_DYNA_SEC_ENA   "DynamicSectionEna"
126 #define KEY_ALPHA          "Gps_Alpha"
127 #define KEY_BETA           "Gps_Beta"
128
129 #define KEY_NPRBELEM_DL       "nPrbElemDl"
130 #define KEY_PRBELEM_DL        "PrbElemDl"
131
132 #define KEY_NPRBELEM_UL       "nPrbElemUl"
133 #define KEY_PRBELEM_UL        "PrbElemUl"
134
135 /**
136  * Set runtime configuration parameters to their defaults.
137  *
138  * @todo Initialize missing parameters.
139  */
140 static void init_config(RuntimeConfig* config)
141 {
142     memset(config , 0, sizeof(RuntimeConfig));
143 }
144
145 /** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - **/
146
147 static void trim(char* input)
148 {
149     uint32_t i;
150     for (i = 0; i<strlen(input); i++)
151         if (input[i] == ' ' || input[i] == '\n' || input[i] == '\t')
152             input[i] = '\0';
153 }
154
155 static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *value)
156 {
157     int32_t parse_res = 0;
158
159     if (strcmp(key, KEY_APP_MODE) == 0){
160         config->appMode = atoi(value);
161     } else if (strcmp(key, KEY_XRAN_MODE) == 0) {
162         config->xranCat = atoi(value);
163     } else if (strcmp(key, KEY_CC_PER_PORT_NUM) == 0) {
164         config->numCC= atoi(value);
165     } else if (strcmp(key, KEY_MU_NUMBER) == 0) {
166         config->mu_number= atoi(value);
167         printf("mu_number: %d\n",config->mu_number);
168     } else if (strcmp(key, KEY_NDLABSFREPOINTA) == 0) {
169         config->nDLAbsFrePointA = atoi(value);
170         printf("nDLAbsFrePointA: %d\n",config->nDLAbsFrePointA);
171     } else if (strcmp(key, KEY_NULABSFREPOINTA) == 0) {
172         config->nULAbsFrePointA = atoi(value);
173         printf("nULAbsFrePointA: %d\n",config->nULAbsFrePointA);
174     } else if (strcmp(key, KEY_NDLBANDWIDTH) == 0) {
175         config->nDLBandwidth = atoi(value);
176         printf("nDLBandwidth: %d\n",config->nDLBandwidth);
177     } else if (strcmp(key, KEY_NULBANDWIDTH) == 0) {
178         config->nULBandwidth = atoi(value);
179         printf("nULBandwidth: %d\n",config->nULBandwidth);
180     } else if (strcmp(key, KEY_NDLFFTSIZE) == 0) {
181         config->nDLFftSize = atoi(value);
182         printf("nDLFftSize: %d\n",config->nDLFftSize);
183     } else if (strcmp(key, KEY_NULFFTSIZE) == 0) {
184         config->nULFftSize = atoi(value);
185         printf("nULFftSize: %d\n",config->nULFftSize);
186     } else if (strcmp(key, KEY_NFRAMEDUPLEXTYPE) == 0) {
187         config->nFrameDuplexType = atoi(value);
188         printf("nFrameDuplexType: %d\n",config->nFrameDuplexType);
189     } else if (strcmp(key, KEY_NTDDPERIOD) == 0) {
190         config->nTddPeriod = atoi(value);
191         printf("nTddPeriod: %d\n",config->nTddPeriod);
192         if (config->nTddPeriod > XRAN_MAX_TDD_PERIODICITY)
193         {
194             printf("nTddPeriod is larger than max allowed, invalid!\n");
195             config->nTddPeriod = XRAN_MAX_TDD_PERIODICITY;
196         }
197     } else if (strncmp(key, KEY_SSLOTCONFIG, strlen(KEY_SSLOTCONFIG)) == 0) {
198         unsigned int slot_num = 0;
199         int i = 0;
200         sscanf(key,"sSlotConfig%u",&slot_num);
201         if (slot_num >= config->nTddPeriod){
202             printf("slot_num %d exceeds TddPeriod\n",slot_num);
203         }
204         else{
205             sscanf(value, "%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x",
206                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[0],
207                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[1],
208                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[2],
209                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[3],
210                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[4],
211                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[5],
212                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[6],
213                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[7],
214                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[8],
215                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[9],
216                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[10],
217                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[11],
218                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[12],
219                                            (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[13]);
220             printf("sSlotConfig%d: ",slot_num);
221             for (i = 0; i< 14; i++){
222                 printf("%d ",config->sSlotConfig[slot_num].nSymbolType[i]);
223             }
224             printf("\n");
225         }
226     } else if (strcmp(key, KEY_ANT_NUM) == 0) {
227         config->numAxc = atoi(value);
228     } else if (strcmp(key, KEY_UL_ANT_NUM) == 0) {
229         config->numUlAxc = atoi(value);
230     }else if (strcmp(key, KEY_ANT_ELM_TRX_NUM) == 0) {
231         config->antElmTRx = atoi(value);
232         printf("antElmTRx %d\n", config->antElmTRx);
233     } else if (strcmp(key, KEY_MU_MIMO_UES_NUM) == 0) {
234         config->muMimoUEs = atoi(value);
235     } else if (strcmp(key, KEY_DLLAYERS_PER_UE) == 0) {
236         config->DlLayersPerUe = atoi(value);
237     } else if (strcmp(key, KEY_ULLAYERS_PER_UE) == 0) {
238         config->UlLayersPerUe = atoi(value);
239     } else if (strcmp(key, KEY_TTI_PERIOD) == 0) {
240         config->ttiPeriod = atoi(value);
241     } else if (strcmp(key, KEY_IQ_SWAP) == 0) {
242         config->iqswap = atoi(value);
243     } else if (strcmp(key, KEY_HTONS_SWAP) == 0) {
244         config->nebyteorderswap = atoi(value);
245     } else if (strcmp(key, KEY_COMPRESSION) == 0) {
246         config->compression = atoi(value);
247     } else if (strcmp(key, KEY_MTU_SIZE) == 0) {
248         config->mtu = atoi(value);
249         printf("mtu %d\n", config->mtu);
250     } else if (strcmp(key, KEY_IO_CORE) == 0) {
251         config->io_core = atoi(value);
252         printf("io_core %d\n", config->io_core);
253     } else if (strcmp(key, KEY_SYSTEM_CORE) == 0) {
254         config->system_core = atoi(value);
255         printf("system_core -c %" PRIx64 "\n", config->system_core);
256     } else if (strcmp(key, KEY_PKT_PROC_CORE) == 0) {
257         config->pkt_proc_core = atoi(value);
258         printf("pkt_proc_core -c %" PRIx64 "\n", config->pkt_proc_core);
259     } else if (strcmp(key, KEY_PKT_AUX_CORE) == 0) {
260         config->pkt_aux_core = atoi(value);
261         printf("pkt_aux_core -c %" PRIx64 "\n", config->pkt_aux_core);
262     } else if (strcmp(key, KEY_TIMING_CORE) == 0) {
263         config->timing_core = atoi(value);
264         printf("timing_core -c %" PRIx64 "\n", config->timing_core);
265     }else if (strcmp(key, KEY_INSTANCE_ID) == 0) {
266         config->instance_id = atoi(value);
267         printf("instance_id %d\n", config->instance_id);
268     }else if (strcmp(key, KEY_LLS_CU_MAC) == 0) {
269         sscanf(value, "%02x:%02x:%02x:%02x:%02x:%02x", (uint32_t*)&config->o_du_addr.addr_bytes[0],
270                                            (uint32_t*)&config->o_du_addr.addr_bytes[1],
271                                            (uint32_t*)&config->o_du_addr.addr_bytes[2],
272                                            (uint32_t*)&config->o_du_addr.addr_bytes[3],
273                                            (uint32_t*)&config->o_du_addr.addr_bytes[4],
274                                            (uint32_t*)&config->o_du_addr.addr_bytes[5]);
275
276         printf("lls-CU MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
277             config->o_du_addr.addr_bytes[0],
278             config->o_du_addr.addr_bytes[1],
279             config->o_du_addr.addr_bytes[2],
280             config->o_du_addr.addr_bytes[3],
281             config->o_du_addr.addr_bytes[4],
282             config->o_du_addr.addr_bytes[5]);
283
284     } else if (strcmp(key, KEY_RU_MAC) == 0) {
285         sscanf(value, "%02x:%02x:%02x:%02x:%02x:%02x", (uint32_t*)&config->o_ru_addr.addr_bytes[0],
286                                            (uint32_t*)&config->o_ru_addr.addr_bytes[1],
287                                            (uint32_t*)&config->o_ru_addr.addr_bytes[2],
288                                            (uint32_t*)&config->o_ru_addr.addr_bytes[3],
289                                            (uint32_t*)&config->o_ru_addr.addr_bytes[4],
290                                            (uint32_t*)&config->o_ru_addr.addr_bytes[5]);
291
292         printf("RU MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
293             config->o_ru_addr.addr_bytes[0],
294             config->o_ru_addr.addr_bytes[1],
295             config->o_ru_addr.addr_bytes[2],
296             config->o_ru_addr.addr_bytes[3],
297             config->o_ru_addr.addr_bytes[4],
298             config->o_ru_addr.addr_bytes[5]);
299     } else if (strcmp(key, KEY_FILE_NUMSLOTS) == 0) {
300         config->numSlots = atoi(value);
301         printf("numSlots: %d\n",config->numSlots);
302     }else if (strncmp(key, KEY_FILE_AxC, strlen(KEY_FILE_AxC)) == 0) {
303         unsigned int ant_num = 0;
304         sscanf(key,"antC%02u",&ant_num);
305         if (ant_num >= MAX_ANT_CARRIER_SUPPORTED) {
306             printf("antC%d exceeds max antenna supported\n",ant_num);
307         } else {
308             strncpy(&config->ant_file[ant_num][0], value, strlen(value));
309             printf("antC%d: %s\n",ant_num, config->ant_file[ant_num]);
310         }
311     } else if (strncmp(key, KEY_FILE_DLBFWUE, strlen(KEY_FILE_DLBFWUE)) == 0) {
312         unsigned int ue_num = 0;
313         sscanf(key,"DlBfwUe%02u",&ue_num);
314         if (ue_num >= MAX_ANT_CARRIER_SUPPORTED) {
315             printf("DlBfwUe%d exceeds max streams supported\n",ue_num);
316         } else {
317             strncpy(&config->dl_bfw_file[ue_num][0], value, strlen(value));
318             printf("DlBfwUe%d: %s\n",ue_num, config->dl_bfw_file[ue_num]);
319         }
320     }else if (strncmp(key, KEY_FILE_ULBFWUE, strlen(KEY_FILE_ULBFWUE)) == 0) {
321         unsigned int ue_num = 0;
322         sscanf(key,"UlBfwUe%02u",&ue_num);
323         if (ue_num >= MAX_ANT_CARRIER_SUPPORTED) {
324             printf("UlBfwUe%d exceeds max streams supported\n",ue_num);
325         } else {
326             strncpy(&config->ul_bfw_file[ue_num][0], value, strlen(value));
327             printf("UlBfwUe%d: %s\n",ue_num, config->ul_bfw_file[ue_num]);
328         }
329     }else if (strncmp(key, KEY_FILE_ULSRS, strlen(KEY_FILE_ULSRS)) == 0) {
330         unsigned int srs_ant = 0;
331         sscanf(key,"antSrsC%02u",&srs_ant);
332         if (srs_ant >= MAX_ANT_CARRIER_SUPPORTED_CAT_B) {
333             printf("antSrsC%d exceeds max ant elemnets supported [%d]\n", srs_ant, MAX_ANT_CARRIER_SUPPORTED_CAT_B);
334         } else {
335             strncpy(&config->ul_srs_file[srs_ant][0], value, strlen(value));
336             printf("antSrsC%d: %s\n",srs_ant, config->ul_srs_file[srs_ant]);
337         }
338     } else if (strcmp(key, KEY_PRACH_ENABLE) == 0) {
339         config->enablePrach = atoi(value);
340         printf("Prach enable: %d\n",config->enablePrach);
341     }else if (strcmp(key, KEY_MAX_FRAME_ID) == 0) {
342         config->maxFrameId = atoi(value);
343         printf("maxFrameId: %d\n",config->maxFrameId);
344     } else if (strcmp(key, KEY_SRS_ENABLE) == 0) {
345         config->enableSrs = atoi(value);
346         printf("Srs enable: %d\n",config->enablePrach);
347     } else if (strcmp(key, KEY_PRACH_CFGIDX) == 0) {
348         config->prachConfigIndex = atoi(value);
349         printf("Prach config index: %d\n",config->prachConfigIndex);
350     } else if (strcmp(key, KEY_SRS_SYM_IDX) == 0) {
351         config->srsSymMask = atoi(value);
352         printf("Srs symbol [0-13]: %d\n",config->srsSymMask);
353     } else if (strncmp(key, KEY_FILE_PRACH_AxC, strlen(KEY_FILE_PRACH_AxC)) == 0) {
354         unsigned int ant_num = 0;
355         sscanf(key,"antPrachC%02u",&ant_num);
356         if (ant_num >= MAX_ANT_CARRIER_SUPPORTED)
357         {
358             printf("antC%d exceeds max antenna supported\n",ant_num);
359         }
360         else{
361             strncpy(&config->prach_file[ant_num][0], value, strlen(value));
362             printf("antPrachC%d: %s\n",ant_num, config->prach_file[ant_num]);
363         }
364     } else if (strcmp(key, KEY_BFW_NUM) == 0) {
365         config->totalBfWeights = atoi(value);
366         printf("%s : %d\n",KEY_BFW_NUM, config->totalBfWeights);
367         /* timing */
368     } else if (strcmp(key, KEY_TADV_CP_DL ) == 0) {
369         config->Tadv_cp_dl = atoi(value);
370         printf("Tadv_cp_dl: %d\n",config->Tadv_cp_dl);
371     } else if (strcmp(key, KEY_T2A_MIN_CP_DL ) == 0) {
372         config->T2a_min_cp_dl = atoi(value);
373         printf("T2a_min_cp_dl: %d\n",config->T2a_min_cp_dl);
374     } else if (strcmp(key, KEY_T2A_MAX_CP_DL ) == 0) {
375         config->T2a_max_cp_dl = atoi(value);
376         printf("T2a_max_cp_dl: %d\n",config->T2a_max_cp_dl);
377     } else if (strcmp(key, KEY_T2A_MIN_CP_UL ) == 0) {
378         config->T2a_min_cp_ul = atoi(value);
379         printf("T2a_min_cp_ul: %d\n",config->T2a_min_cp_ul);
380     } else if (strcmp(key, KEY_T2A_MAX_CP_UL ) == 0) {
381         config->T2a_max_cp_ul = atoi(value);
382         printf("T2a_max_cp_ul: %d\n",config->T2a_max_cp_ul);
383     } else if (strcmp(key, KEY_T2A_MIN_UP ) == 0) {
384         config->T2a_min_up = atoi(value);
385         printf("T2a_min_up: %d\n",config->T2a_min_up);
386     } else if (strcmp(key, KEY_T2A_MAX_UP ) == 0) {
387         config->T2a_max_up = atoi(value);
388         printf("T2a_max_up: %d\n",config->T2a_max_up);
389     } else if (strcmp(key, KEY_TA3_MIN ) == 0) {
390         config->Ta3_min = atoi(value);
391         printf("Ta3_min: %d\n",config->Ta3_min);
392     } else if (strcmp(key, KEY_TA3_MAX ) == 0) {
393         config->Ta3_max = atoi(value);
394         printf("Ta3_max: %d\n",config->Ta3_max);
395     } else if (strcmp(key, KEY_T1A_MIN_CP_DL ) == 0) {
396         config->T1a_min_cp_dl = atoi(value);
397         printf("T1a_min_cp_dl: %d\n",config->T1a_min_cp_dl);
398     } else if (strcmp(key, KEY_T1A_MAX_CP_DL ) == 0) {
399         config->T1a_max_cp_dl = atoi(value);
400         printf("T1a_max_cp_dl: %d\n",config->T1a_max_cp_dl);
401     } else if (strcmp(key, KEY_T1A_MIN_CP_UL ) == 0) {
402         config->T1a_min_cp_ul = atoi(value);
403         printf("T1a_min_cp_ul: %d\n",config->T1a_min_cp_ul);
404     } else if (strcmp(key, KEY_T1A_MAX_CP_UL ) == 0) {
405         config->T1a_max_cp_ul = atoi(value);
406         printf("T1a_max_cp_ul: %d\n",config->T1a_max_cp_ul);
407     } else if (strcmp(key, KEY_T1A_MIN_UP ) == 0) {
408         config->T1a_min_up = atoi(value);
409         printf("T1a_min_up: %d\n",config->T1a_min_up);
410     } else if (strcmp(key, KEY_T1A_MAX_UP ) == 0) {
411         config->T1a_max_up = atoi(value);
412         printf("T1a_max_up: %d\n",config->T1a_max_up);
413     } else if (strcmp(key, KEY_TA4_MIN ) == 0) {
414         config->Ta4_min = atoi(value);
415         printf("Ta4_min: %d\n",config->Ta4_min);
416     } else if (strcmp(key, KEY_TA4_MAX ) == 0) {
417         config->Ta4_max = atoi(value);
418         printf("Ta4_max: %d\n",config->Ta4_max);
419         /* end of timing */
420     } else if (strcmp(key, KEY_CP_ENABLE ) == 0) {
421         config->enableCP = atoi(value);
422         printf("CPenable: %d\n",config->enableCP);
423     } else if (strcmp(key, KEY_DEBUG_STOP ) == 0) {
424         config->debugStop = atoi(value);
425         printf("debugStop: %d\n",config->debugStop);
426     } else if (strcmp(key, KEY_DEBUG_STOP_CNT) == 0) {
427         config->debugStopCount = atoi(value);
428         printf("debugStopCount: %d\n",config->debugStopCount);
429     } else if (strcmp(key, KEY_BBDEV_MODE) == 0) {
430         config->bbdevMode = atoi(value);
431         printf("bbdevMode: %d\n",config->debugStopCount);
432     } else if (strcmp(key, KEY_DYNA_SEC_ENA) == 0) {
433         config->DynamicSectionEna = atoi(value);
434         printf("DynamicSectionEna: %d\n",config->DynamicSectionEna);
435     } else if (strcmp(key, KEY_ALPHA) == 0) {
436         config->GPS_Alpha = atoi(value);
437         printf("GPS_Alpha: %d\n",config->GPS_Alpha);
438     } else if (strcmp(key, KEY_BETA) == 0) {
439         config->GPS_Beta = atoi(value);
440         printf("GPS_Beta: %d\n",config->GPS_Beta);
441     } else if (strcmp(key, KEY_CP_VTAG ) == 0) {
442         config->cp_vlan_tag = atoi(value);
443         printf("cp_vlan_tag: %d\n",config->cp_vlan_tag);
444     } else if (strcmp(key, KEY_UP_VTAG ) == 0) {
445         config->up_vlan_tag = atoi(value);
446         printf("up_vlan_tag: %d\n",config->up_vlan_tag);
447     } else if (strcmp(key, KEY_NPRBELEM_UL ) == 0) {
448         config->PrbMapUl.nPrbElm = atoi(value);
449         if (config->PrbMapUl.nPrbElm > XRAN_MAX_PRBS)
450         {
451             printf("nTddPeriod is larger than max allowed, invalid!\n");
452             config->PrbMapUl.nPrbElm = XRAN_MAX_PRBS;
453         }
454         printf("nPrbElemUl: %d\n",config->PrbMapUl.nPrbElm);
455     } else if (strncmp(key, KEY_PRBELEM_UL, strlen(KEY_PRBELEM_UL)) == 0) {
456         unsigned int section_idx = 0;
457         sscanf(key,"PrbElemUl%u",&section_idx);
458         if (section_idx >= config->PrbMapUl.nPrbElm){
459             printf("section_idx %d exceeds nPrbElem\n",section_idx);
460         }
461         else{
462             struct xran_prb_elm *pPrbElem = &config->PrbMapUl.prbMap[section_idx];
463             sscanf(value, "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd",
464                 (int16_t*)&pPrbElem->nRBStart,
465                 (int16_t*)&pPrbElem->nRBSize,
466                 (int16_t*)&pPrbElem->nStartSymb,
467                 (int16_t*)&pPrbElem->numSymb,
468                 (int16_t*)&pPrbElem->nBeamIndex,
469                 (int16_t*)&pPrbElem->bf_weight_update,
470                 (int16_t*)&pPrbElem->compMethod,
471                 (int16_t*)&pPrbElem->iqWidth,
472                 (int16_t*)&pPrbElem->BeamFormingType);
473             printf("nPrbElemUl%d: ",section_idx);
474             printf("nRBStart %d,nRBSize %d,nStartSymb %d,numSymb %d,nBeamIndex %d, bf_weight_update %d compMethod %d, iqWidth %d BeamFormingType %d\n",
475                 pPrbElem->nRBStart,pPrbElem->nRBSize,pPrbElem->nStartSymb,pPrbElem->numSymb,pPrbElem->nBeamIndex, pPrbElem->bf_weight_update, pPrbElem->compMethod, pPrbElem->iqWidth, pPrbElem->BeamFormingType);
476         }
477     }else if (strcmp(key, KEY_NPRBELEM_DL ) == 0) {
478         config->PrbMapDl.nPrbElm = atoi(value);
479         if (config->PrbMapDl.nPrbElm > XRAN_MAX_PRBS)
480         {
481             printf("nTddPeriod is larger than max allowed, invalid!\n");
482             config->PrbMapDl.nPrbElm = XRAN_MAX_PRBS;
483         }
484         printf("nPrbElemDl: %d\n",config->PrbMapDl.nPrbElm);
485     } else if (strncmp(key, KEY_PRBELEM_DL, strlen(KEY_PRBELEM_DL)) == 0) {
486         unsigned int section_idx = 0;
487         sscanf(key,"PrbElemDl%u",&section_idx);
488         if (section_idx >= config->PrbMapDl.nPrbElm){
489             printf("section_idx %d exceeds nPrbElem\n",section_idx);
490         }
491         else{
492             struct xran_prb_elm *pPrbElem = &config->PrbMapDl.prbMap[section_idx];
493             sscanf(value, "%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd,%hd",
494                 (int16_t*)&pPrbElem->nRBStart,
495                 (int16_t*)&pPrbElem->nRBSize,
496                 (int16_t*)&pPrbElem->nStartSymb,
497                 (int16_t*)&pPrbElem->numSymb,
498                 (int16_t*)&pPrbElem->nBeamIndex,
499                 (int16_t*)&pPrbElem->bf_weight_update,
500                 (int16_t*)&pPrbElem->compMethod,
501                 (int16_t*)&pPrbElem->iqWidth,
502                 (int16_t*)&pPrbElem->BeamFormingType);
503             printf("nPrbElemDl%d: ",section_idx);
504             printf("nRBStart %d,nRBSize %d,nStartSymb %d,numSymb %d,nBeamIndex %d, bf_weight_update %d compMethod %d, iqWidth %d BeamFormingType %d\n",
505                 pPrbElem->nRBStart,pPrbElem->nRBSize,pPrbElem->nStartSymb,pPrbElem->numSymb,pPrbElem->nBeamIndex, pPrbElem->bf_weight_update, pPrbElem->compMethod, pPrbElem->iqWidth, pPrbElem->BeamFormingType);
506         }
507     } else {
508         printf("Unsupported configuration key [%s]\n", key);
509         return -1;
510     }
511
512     return 0;
513 }
514
515 int parseConfigFile(char *filename, RuntimeConfig *config)
516 {
517     char inputLine[MAX_LINE_SIZE] = {0};
518     int inputLen = 0;
519     int i;
520     int lineNum = 0;
521     char key[MAX_LINE_SIZE] = {0};
522     char value[MAX_LINE_SIZE] = {0};
523     FILE *file = fopen(filename, "r");
524
525     if (NULL == file) {
526         log_err("Error while opening config file from: %s", filename);
527         return -1;
528     }
529
530 //    init_config(config);
531
532     for (;;) {
533         if (fgets(inputLine, MAX_LINE_SIZE, file) == NULL) {
534             if (lineNum > 0) {
535                 printf("%d lines of config file has been read.\n", lineNum);
536                 break;
537             } else {
538                 printf("Configuration file reading error has occurred.\n");
539                 fclose(file);
540                 return -1;
541             }
542         }
543
544         if (inputLine[strlen(inputLine)-1] == '\n')
545             inputLine[strlen(inputLine)-1] == '\0';
546
547         lineNum++;
548         inputLen = strlen(inputLine);
549
550         for (i=0; i<inputLen; i++)
551             if (inputLine[i] == '#') {
552                 inputLine[i] = '\0';
553                 inputLen = i + 1;
554                 break;
555             }
556
557         for (i=0; i<inputLen; i++)
558             if (inputLine[i] == '=') {
559                 strncpy(key, inputLine, i);
560                 key[i] = '\0';
561                 trim(key);
562                 if ((i + 1 > inputLen - 1) || (i - 2 > inputLen)) {
563                     log_err("Parsing config file error at line %d", lineNum);
564                     fclose(file);
565                     return -1;
566                 }
567                 strncpy(value, &inputLine[i+1], (sizeof(value) - 1));
568                 value[inputLen-i-2] = '\0';
569                 trim(value);
570
571                 if (strlen(key) == 0 || strlen(value) == 0) {
572                     printf("Parsing config file error at line %d", lineNum);
573                     fclose(file);
574                     return -1;
575                 }
576
577                 if (fillConfigStruct(config, key, value) != 0) {
578                     fclose(file);
579                     return -1;
580                 }
581
582                 break;
583             }
584
585         memset(&inputLine[0], 0, sizeof(MAX_LINE_SIZE));
586         memset(&key[0], 0, sizeof(MAX_LINE_SIZE));
587         memset(&value[0], 0, sizeof(MAX_LINE_SIZE));
588     }
589     fclose(file);
590
591     return 0;
592 }