1 /******************************************************************************
3 * Copyright (c) 2019 Intel.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 *******************************************************************************/
24 * @author Intel Corporation
27 #include "rte_common.h"
32 #include <rte_ethdev.h>
34 #define MAX_LINE_SIZE 512
35 /* Configuration file maximum supported line length */
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"
47 #define KEY_NFRAMEDUPLEXTYPE "nFrameDuplexType"
48 #define KEY_NTDDPERIOD "nTddPeriod"
50 #define KEY_SSLOTCONFIG "sSlotConfig"
52 #define KEY_CC_PER_PORT_NUM "ccNum"
53 #define KEY_ANT_NUM "antNum"
54 #define KEY_TTI_PERIOD "ttiPeriod"
56 #define KEY_MTU_SIZE "MTUSize"
57 #define KEY_LLS_CU_MAC "llsCUMac"
58 #define KEY_RU_MAC "ruMac"
60 #define KEY_FILE_NUMSLOTS "numSlots"
61 #define KEY_FILE_AxC "antC"
62 #define KEY_FILE_PRACH_AxC "antPrachC"
65 #define KEY_PRACH_ENABLE "rachEanble"
66 #define KEY_PRACH_CFGIDX "prachConfigIndex"
68 #define KEY_IQ_SWAP "iqswap"
69 #define KEY_HTONS_SWAP "nebyteorderswap"
71 #define KEY_TADV_CP_DL "Tadv_cp_dl"
72 #define KEY_T2A_MIN_CP_DL "T2a_min_cp_dl"
73 #define KEY_T2A_MAX_CP_DL "T2a_max_cp_dl"
74 #define KEY_T2A_MIN_CP_UL "T2a_min_cp_ul"
75 #define KEY_T2A_MAX_CP_UL "T2a_max_cp_ul"
76 #define KEY_T2A_MIN_UP "T2a_min_up"
77 #define KEY_T2A_MAX_UP "T2a_max_up"
78 #define KEY_TA3_MIN "Ta3_min"
79 #define KEY_TA3_MAX "Ta3_max"
80 #define KEY_T1A_MIN_CP_DL "T1a_min_cp_dl"
81 #define KEY_T1A_MAX_CP_DL "T1a_max_cp_dl"
82 #define KEY_T1A_MIN_CP_UL "T1a_min_cp_ul"
83 #define KEY_T1A_MAX_CP_UL "T1a_max_cp_ul"
84 #define KEY_T1A_MIN_UP "T1a_min_up"
85 #define KEY_T1A_MAX_UP "T1a_max_up"
86 #define KEY_TA4_MIN "Ta4_min"
87 #define KEY_TA4_MAX "Ta4_max"
90 #define KEY_CP_ENABLE "CPenable"
91 #define KEY_CP_VTAG "c_plane_vlan_tag"
92 #define KEY_UP_VTAG "u_plane_vlan_tag"
93 #define KEY_DEBUG_STOP "debugStop"
94 #define KEY_DEBUG_STOP_CNT "debugStopCount"
95 #define KEY_BBDEV_MODE "bbdevMode"
96 #define KEY_DYNA_SEC_ENA "DynamicSectionEna"
100 * Set runtime configuration parameters to their defaults.
102 * @todo Initialize missing parameters.
104 static void init_config(RuntimeConfig* config)
106 memset(config , 0, sizeof(RuntimeConfig));
109 /** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - **/
111 static void trim(char* input)
114 for (i = 0; i<strlen(input); i++)
115 if (input[i] == ' ' || input[i] == '\n' || input[i] == '\t')
119 static int fillConfigStruct(RuntimeConfig *config, const char *key, const char *value)
121 int32_t parse_res = 0;
123 if (strcmp(key, KEY_APP_MODE) == 0){
124 config->appMode = atoi(value);
125 } else if (strcmp(key, KEY_XRAN_MODE) == 0) {
126 config->xranMode = atoi(value);
127 } else if (strcmp(key, KEY_CC_PER_PORT_NUM) == 0) {
128 config->numCC= atoi(value);
129 } else if (strcmp(key, KEY_MU_NUMBER) == 0) {
130 config->mu_number= atoi(value);
131 printf("mu_number: %d\n",config->mu_number);
132 } else if (strcmp(key, KEY_NDLABSFREPOINTA) == 0) {
133 config->nDLAbsFrePointA = atoi(value);
134 printf("nDLAbsFrePointA: %d\n",config->nDLAbsFrePointA);
135 } else if (strcmp(key, KEY_NULABSFREPOINTA) == 0) {
136 config->nULAbsFrePointA = atoi(value);
137 printf("nULAbsFrePointA: %d\n",config->nULAbsFrePointA);
138 } else if (strcmp(key, KEY_NDLBANDWIDTH) == 0) {
139 config->nDLBandwidth = atoi(value);
140 printf("nDLBandwidth: %d\n",config->nDLBandwidth);
141 } else if (strcmp(key, KEY_NULBANDWIDTH) == 0) {
142 config->nULBandwidth = atoi(value);
143 printf("nULBandwidth: %d\n",config->nULBandwidth);
144 } else if (strcmp(key, KEY_NDLFFTSIZE) == 0) {
145 config->nDLFftSize = atoi(value);
146 printf("nULFftSize: %d\n",config->nDLFftSize);
147 } else if (strcmp(key, KEY_NULFFTSIZE) == 0) {
148 config->nULFftSize = atoi(value);
149 printf("nULFftSize: %d\n",config->nULFftSize);
150 } else if (strcmp(key, KEY_NFRAMEDUPLEXTYPE) == 0) {
151 config->nFrameDuplexType = atoi(value);
152 printf("nFrameDuplexType: %d\n",config->nFrameDuplexType);
153 } else if (strcmp(key, KEY_NTDDPERIOD) == 0) {
154 config->nTddPeriod = atoi(value);
155 printf("nTddPeriod: %d\n",config->nTddPeriod);
156 if (config->nTddPeriod > XRAN_MAX_TDD_PERIODICITY)
158 printf("nTddPeriod is larger than max allowed, invalid!\n");
159 config->nTddPeriod = XRAN_MAX_TDD_PERIODICITY;
161 } else if (strncmp(key, KEY_SSLOTCONFIG, strlen(KEY_SSLOTCONFIG)) == 0) {
162 unsigned int slot_num = 0;
164 sscanf(key,"sSlotConfig%u",&slot_num);
165 if (slot_num >= config->nTddPeriod){
166 printf("slot_num %d exceeds TddPeriod\n",slot_num);
169 sscanf(value, "%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x",
170 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[0],
171 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[1],
172 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[2],
173 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[3],
174 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[4],
175 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[5],
176 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[6],
177 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[7],
178 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[8],
179 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[9],
180 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[10],
181 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[11],
182 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[12],
183 (uint32_t*)&config->sSlotConfig[slot_num].nSymbolType[13]);
184 printf("sSlotConfig%d: ",slot_num);
185 for (i = 0; i< 14; i++){
186 printf("%d ",config->sSlotConfig[slot_num].nSymbolType[i]);
190 } else if (strcmp(key, KEY_ANT_NUM) == 0) {
191 config->numAxc = atoi(value);
192 } else if (strcmp(key, KEY_TTI_PERIOD) == 0) {
193 config->ttiPeriod = atoi(value);
194 } else if (strcmp(key, KEY_IQ_SWAP) == 0) {
195 config->iqswap = atoi(value);
196 } else if (strcmp(key, KEY_HTONS_SWAP) == 0) {
197 config->nebyteorderswap = atoi(value);
198 } else if (strcmp(key, KEY_MTU_SIZE) == 0) {
199 config->mtu = atoi(value);
200 printf("mtu %d\n", config->mtu);
201 } else if (strcmp(key, KEY_LLS_CU_MAC) == 0) {
202 sscanf(value, "%02x:%02x:%02x:%02x:%02x:%02x", (uint32_t*)&config->o_du_addr.addr_bytes[0],
203 (uint32_t*)&config->o_du_addr.addr_bytes[1],
204 (uint32_t*)&config->o_du_addr.addr_bytes[2],
205 (uint32_t*)&config->o_du_addr.addr_bytes[3],
206 (uint32_t*)&config->o_du_addr.addr_bytes[4],
207 (uint32_t*)&config->o_du_addr.addr_bytes[5]);
209 printf("lls-CU MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
210 config->o_du_addr.addr_bytes[0],
211 config->o_du_addr.addr_bytes[1],
212 config->o_du_addr.addr_bytes[2],
213 config->o_du_addr.addr_bytes[3],
214 config->o_du_addr.addr_bytes[4],
215 config->o_du_addr.addr_bytes[5]);
217 } else if (strcmp(key, KEY_RU_MAC) == 0) {
218 sscanf(value, "%02x:%02x:%02x:%02x:%02x:%02x", (uint32_t*)&config->o_ru_addr.addr_bytes[0],
219 (uint32_t*)&config->o_ru_addr.addr_bytes[1],
220 (uint32_t*)&config->o_ru_addr.addr_bytes[2],
221 (uint32_t*)&config->o_ru_addr.addr_bytes[3],
222 (uint32_t*)&config->o_ru_addr.addr_bytes[4],
223 (uint32_t*)&config->o_ru_addr.addr_bytes[5]);
225 printf("RU MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
226 config->o_ru_addr.addr_bytes[0],
227 config->o_ru_addr.addr_bytes[1],
228 config->o_ru_addr.addr_bytes[2],
229 config->o_ru_addr.addr_bytes[3],
230 config->o_ru_addr.addr_bytes[4],
231 config->o_ru_addr.addr_bytes[5]);
232 } else if (strcmp(key, KEY_FILE_NUMSLOTS) == 0) {
233 config->numSlots = atoi(value);
234 printf("numSlots: %d\n",config->numSlots);
235 }else if (strncmp(key, KEY_FILE_AxC, strlen(KEY_FILE_AxC)) == 0) {
236 unsigned int ant_num = 0;
237 sscanf(key,"antC%02u",&ant_num);
238 if (ant_num >= MAX_ANT_CARRIER_SUPPORTED)
240 printf("antC%d exceeds max antenna supported\n",ant_num);
243 strncpy(&config->ant_file[ant_num][0], value, strlen(value));
244 printf("antC%d: %s\n",ant_num, config->ant_file[ant_num]);
246 } else if (strcmp(key, KEY_PRACH_ENABLE) == 0) {
247 config->enablePrach = atoi(value);
248 printf("Prach enable: %d\n",config->enablePrach);
249 } else if (strcmp(key, KEY_PRACH_CFGIDX) == 0) {
250 config->prachConfigIndex = atoi(value);
251 printf("Prach config index: %d\n",config->prachConfigIndex);
252 } else if (strncmp(key, KEY_FILE_PRACH_AxC, strlen(KEY_FILE_PRACH_AxC)) == 0) {
253 unsigned int ant_num = 0;
254 sscanf(key,"antPrachC%02u",&ant_num);
255 if (ant_num >= MAX_ANT_CARRIER_SUPPORTED)
257 printf("antC%d exceeds max antenna supported\n",ant_num);
260 strncpy(&config->prach_file[ant_num][0], value, strlen(value));
261 printf("antPrachC%d: %s\n",ant_num, config->prach_file[ant_num]);
264 } else if (strcmp(key, KEY_TADV_CP_DL ) == 0) {
265 config->Tadv_cp_dl = atoi(value);
266 printf("Tadv_cp_dl: %d\n",config->Tadv_cp_dl);
267 } else if (strcmp(key, KEY_T2A_MIN_CP_DL ) == 0) {
268 config->T2a_min_cp_dl = atoi(value);
269 printf("T2a_min_cp_dl: %d\n",config->T2a_min_cp_dl);
270 } else if (strcmp(key, KEY_T2A_MAX_CP_DL ) == 0) {
271 config->T2a_max_cp_dl = atoi(value);
272 printf("T2a_max_cp_dl: %d\n",config->T2a_max_cp_dl);
273 } else if (strcmp(key, KEY_T2A_MIN_CP_UL ) == 0) {
274 config->T2a_min_cp_ul = atoi(value);
275 printf("T2a_min_cp_ul: %d\n",config->T2a_min_cp_ul);
276 } else if (strcmp(key, KEY_T2A_MAX_CP_UL ) == 0) {
277 config->T2a_max_cp_ul = atoi(value);
278 printf("T2a_max_cp_ul: %d\n",config->T2a_max_cp_ul);
279 } else if (strcmp(key, KEY_T2A_MIN_UP ) == 0) {
280 config->T2a_min_up = atoi(value);
281 printf("T2a_min_up: %d\n",config->T2a_min_up);
282 } else if (strcmp(key, KEY_T2A_MAX_UP ) == 0) {
283 config->T2a_max_up = atoi(value);
284 printf("T2a_max_up: %d\n",config->T2a_max_up);
285 } else if (strcmp(key, KEY_TA3_MIN ) == 0) {
286 config->Ta3_min = atoi(value);
287 printf("Ta3_min: %d\n",config->Ta3_min);
288 } else if (strcmp(key, KEY_TA3_MAX ) == 0) {
289 config->Ta3_max = atoi(value);
290 printf("Ta3_max: %d\n",config->Ta3_max);
291 } else if (strcmp(key, KEY_T1A_MIN_CP_DL ) == 0) {
292 config->T1a_min_cp_dl = atoi(value);
293 printf("T1a_min_cp_dl: %d\n",config->T1a_min_cp_dl);
294 } else if (strcmp(key, KEY_T1A_MAX_CP_DL ) == 0) {
295 config->T1a_max_cp_dl = atoi(value);
296 printf("T1a_max_cp_dl: %d\n",config->T1a_max_cp_dl);
297 } else if (strcmp(key, KEY_T1A_MIN_CP_UL ) == 0) {
298 config->T1a_min_cp_ul = atoi(value);
299 printf("T1a_min_cp_ul: %d\n",config->T1a_min_cp_ul);
300 } else if (strcmp(key, KEY_T1A_MAX_CP_UL ) == 0) {
301 config->T1a_max_cp_ul = atoi(value);
302 printf("T1a_max_cp_ul: %d\n",config->T1a_max_cp_ul);
303 } else if (strcmp(key, KEY_T1A_MIN_UP ) == 0) {
304 config->T1a_min_up = atoi(value);
305 printf("T1a_min_up: %d\n",config->T1a_min_up);
306 } else if (strcmp(key, KEY_T1A_MAX_UP ) == 0) {
307 config->T1a_max_up = atoi(value);
308 printf("T1a_max_up: %d\n",config->T1a_max_up);
309 } else if (strcmp(key, KEY_TA4_MIN ) == 0) {
310 config->Ta4_min = atoi(value);
311 printf("Ta4_min: %d\n",config->Ta4_min);
312 } else if (strcmp(key, KEY_TA4_MAX ) == 0) {
313 config->Ta4_max = atoi(value);
314 printf("Ta4_max: %d\n",config->Ta4_max);
316 } else if (strcmp(key, KEY_CP_ENABLE ) == 0) {
317 config->enableCP = atoi(value);
318 printf("CPenable: %d\n",config->enableCP);
319 } else if (strcmp(key, KEY_DEBUG_STOP ) == 0) {
320 config->debugStop = atoi(value);
321 printf("debugStop: %d\n",config->debugStop);
322 } else if (strcmp(key, KEY_DEBUG_STOP_CNT) == 0) {
323 config->debugStopCount = atoi(value);
324 printf("debugStopCount: %d\n",config->debugStopCount);
325 } else if (strcmp(key, KEY_BBDEV_MODE) == 0) {
326 config->bbdevMode = atoi(value);
327 printf("bbdevMode: %d\n",config->debugStopCount);
328 } else if (strcmp(key, KEY_DYNA_SEC_ENA) == 0) {
329 config->DynamicSectionEna = atoi(value);
330 printf("DynamicSectionEna: %d\n",config->DynamicSectionEna);
331 } else if (strcmp(key, KEY_CP_VTAG ) == 0) {
332 config->cp_vlan_tag = atoi(value);
333 printf("cp_vlan_tag: %d\n",config->cp_vlan_tag);
334 } else if (strcmp(key, KEY_UP_VTAG ) == 0) {
335 config->up_vlan_tag = atoi(value);
336 printf("up_vlan_tag: %d\n",config->up_vlan_tag);
338 printf("Unsupported configuration key [%s]\n", key);
345 int parseConfigFile(char *filename, RuntimeConfig *config)
347 char inputLine[MAX_LINE_SIZE] = {0};
351 char key[MAX_LINE_SIZE] = {0};
352 char value[MAX_LINE_SIZE] = {0};
353 FILE *file = fopen(filename, "r");
356 log_err("Error while opening config file from: %s", filename);
360 // init_config(config);
363 if (fgets(inputLine, MAX_LINE_SIZE, file) == NULL) {
365 printf("%d lines of config file has been read.\n", lineNum);
368 printf("Configuration file reading error has occurred.\n");
374 if (inputLine[strlen(inputLine)-1] == '\n')
375 inputLine[strlen(inputLine)-1] == '\0';
378 inputLen = strlen(inputLine);
380 for (i=0; i<inputLen; i++)
381 if (inputLine[i] == '#') {
387 for (i=0; i<inputLen; i++)
388 if (inputLine[i] == '=') {
389 strncpy(key, inputLine, i);
392 if ((i + 1 > inputLen - 1) || (i - 2 > inputLen)) {
393 log_err("Parsing config file error at line %d", lineNum);
397 strncpy(value, &inputLine[i+1], (sizeof(value) - 1));
398 value[inputLen-i-2] = '\0';
401 if (strlen(key) == 0 || strlen(value) == 0) {
402 printf("Parsing config file error at line %d", lineNum);
407 if (fillConfigStruct(config, key, value) != 0) {
415 memset(&inputLine[0], 0, sizeof(MAX_LINE_SIZE));
416 memset(&key[0], 0, sizeof(MAX_LINE_SIZE));
417 memset(&value[0], 0, sizeof(MAX_LINE_SIZE));