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