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