Home | History | Annotate | Line # | Download | only in hostapd
config_file.c revision 1.1.1.1.6.1
      1 /*
      2  * hostapd / Configuration file parser
      3  * Copyright (c) 2003-2009, Jouni Malinen <j (at) w1.fi>
      4  *
      5  * This program is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU General Public License version 2 as
      7  * published by the Free Software Foundation.
      8  *
      9  * Alternatively, this software may be distributed under the terms of BSD
     10  * license.
     11  *
     12  * See README and COPYING for more details.
     13  */
     14 
     15 #include "utils/includes.h"
     16 #ifndef CONFIG_NATIVE_WINDOWS
     17 #include <grp.h>
     18 #endif /* CONFIG_NATIVE_WINDOWS */
     19 
     20 #include "utils/common.h"
     21 #include "utils/uuid.h"
     22 #include "common/ieee802_11_defs.h"
     23 #include "drivers/driver.h"
     24 #include "eap_server/eap.h"
     25 #include "radius/radius_client.h"
     26 #include "ap/wpa_auth.h"
     27 #include "ap/ap_config.h"
     28 #include "config_file.h"
     29 
     30 
     31 extern struct wpa_driver_ops *wpa_drivers[];
     32 
     33 
     34 #ifndef CONFIG_NO_VLAN
     35 static int hostapd_config_read_vlan_file(struct hostapd_bss_config *bss,
     36 					 const char *fname)
     37 {
     38 	FILE *f;
     39 	char buf[128], *pos, *pos2;
     40 	int line = 0, vlan_id;
     41 	struct hostapd_vlan *vlan;
     42 
     43 	f = fopen(fname, "r");
     44 	if (!f) {
     45 		wpa_printf(MSG_ERROR, "VLAN file '%s' not readable.", fname);
     46 		return -1;
     47 	}
     48 
     49 	while (fgets(buf, sizeof(buf), f)) {
     50 		line++;
     51 
     52 		if (buf[0] == '#')
     53 			continue;
     54 		pos = buf;
     55 		while (*pos != '\0') {
     56 			if (*pos == '\n') {
     57 				*pos = '\0';
     58 				break;
     59 			}
     60 			pos++;
     61 		}
     62 		if (buf[0] == '\0')
     63 			continue;
     64 
     65 		if (buf[0] == '*') {
     66 			vlan_id = VLAN_ID_WILDCARD;
     67 			pos = buf + 1;
     68 		} else {
     69 			vlan_id = strtol(buf, &pos, 10);
     70 			if (buf == pos || vlan_id < 1 ||
     71 			    vlan_id > MAX_VLAN_ID) {
     72 				wpa_printf(MSG_ERROR, "Invalid VLAN ID at "
     73 					   "line %d in '%s'", line, fname);
     74 				fclose(f);
     75 				return -1;
     76 			}
     77 		}
     78 
     79 		while (*pos == ' ' || *pos == '\t')
     80 			pos++;
     81 		pos2 = pos;
     82 		while (*pos2 != ' ' && *pos2 != '\t' && *pos2 != '\0')
     83 			pos2++;
     84 		*pos2 = '\0';
     85 		if (*pos == '\0' || os_strlen(pos) > IFNAMSIZ) {
     86 			wpa_printf(MSG_ERROR, "Invalid VLAN ifname at line %d "
     87 				   "in '%s'", line, fname);
     88 			fclose(f);
     89 			return -1;
     90 		}
     91 
     92 		vlan = os_malloc(sizeof(*vlan));
     93 		if (vlan == NULL) {
     94 			wpa_printf(MSG_ERROR, "Out of memory while reading "
     95 				   "VLAN interfaces from '%s'", fname);
     96 			fclose(f);
     97 			return -1;
     98 		}
     99 
    100 		os_memset(vlan, 0, sizeof(*vlan));
    101 		vlan->vlan_id = vlan_id;
    102 		os_strlcpy(vlan->ifname, pos, sizeof(vlan->ifname));
    103 		if (bss->vlan_tail)
    104 			bss->vlan_tail->next = vlan;
    105 		else
    106 			bss->vlan = vlan;
    107 		bss->vlan_tail = vlan;
    108 	}
    109 
    110 	fclose(f);
    111 
    112 	return 0;
    113 }
    114 #endif /* CONFIG_NO_VLAN */
    115 
    116 
    117 static int hostapd_acl_comp(const void *a, const void *b)
    118 {
    119 	const struct mac_acl_entry *aa = a;
    120 	const struct mac_acl_entry *bb = b;
    121 	return os_memcmp(aa->addr, bb->addr, sizeof(macaddr));
    122 }
    123 
    124 
    125 static int hostapd_config_read_maclist(const char *fname,
    126 				       struct mac_acl_entry **acl, int *num)
    127 {
    128 	FILE *f;
    129 	char buf[128], *pos;
    130 	int line = 0;
    131 	u8 addr[ETH_ALEN];
    132 	struct mac_acl_entry *newacl;
    133 	int vlan_id;
    134 
    135 	if (!fname)
    136 		return 0;
    137 
    138 	f = fopen(fname, "r");
    139 	if (!f) {
    140 		wpa_printf(MSG_ERROR, "MAC list file '%s' not found.", fname);
    141 		return -1;
    142 	}
    143 
    144 	while (fgets(buf, sizeof(buf), f)) {
    145 		line++;
    146 
    147 		if (buf[0] == '#')
    148 			continue;
    149 		pos = buf;
    150 		while (*pos != '\0') {
    151 			if (*pos == '\n') {
    152 				*pos = '\0';
    153 				break;
    154 			}
    155 			pos++;
    156 		}
    157 		if (buf[0] == '\0')
    158 			continue;
    159 
    160 		if (hwaddr_aton(buf, addr)) {
    161 			wpa_printf(MSG_ERROR, "Invalid MAC address '%s' at "
    162 				   "line %d in '%s'", buf, line, fname);
    163 			fclose(f);
    164 			return -1;
    165 		}
    166 
    167 		vlan_id = 0;
    168 		pos = buf;
    169 		while (*pos != '\0' && *pos != ' ' && *pos != '\t')
    170 			pos++;
    171 		while (*pos == ' ' || *pos == '\t')
    172 			pos++;
    173 		if (*pos != '\0')
    174 			vlan_id = atoi(pos);
    175 
    176 		newacl = os_realloc(*acl, (*num + 1) * sizeof(**acl));
    177 		if (newacl == NULL) {
    178 			wpa_printf(MSG_ERROR, "MAC list reallocation failed");
    179 			fclose(f);
    180 			return -1;
    181 		}
    182 
    183 		*acl = newacl;
    184 		os_memcpy((*acl)[*num].addr, addr, ETH_ALEN);
    185 		(*acl)[*num].vlan_id = vlan_id;
    186 		(*num)++;
    187 	}
    188 
    189 	fclose(f);
    190 
    191 	qsort(*acl, *num, sizeof(**acl), hostapd_acl_comp);
    192 
    193 	return 0;
    194 }
    195 
    196 
    197 #ifdef EAP_SERVER
    198 static int hostapd_config_read_eap_user(const char *fname,
    199 					struct hostapd_bss_config *conf)
    200 {
    201 	FILE *f;
    202 	char buf[512], *pos, *start, *pos2;
    203 	int line = 0, ret = 0, num_methods;
    204 	struct hostapd_eap_user *user, *tail = NULL;
    205 
    206 	if (!fname)
    207 		return 0;
    208 
    209 	f = fopen(fname, "r");
    210 	if (!f) {
    211 		wpa_printf(MSG_ERROR, "EAP user file '%s' not found.", fname);
    212 		return -1;
    213 	}
    214 
    215 	/* Lines: "user" METHOD,METHOD2 "password" (password optional) */
    216 	while (fgets(buf, sizeof(buf), f)) {
    217 		line++;
    218 
    219 		if (buf[0] == '#')
    220 			continue;
    221 		pos = buf;
    222 		while (*pos != '\0') {
    223 			if (*pos == '\n') {
    224 				*pos = '\0';
    225 				break;
    226 			}
    227 			pos++;
    228 		}
    229 		if (buf[0] == '\0')
    230 			continue;
    231 
    232 		user = NULL;
    233 
    234 		if (buf[0] != '"' && buf[0] != '*') {
    235 			wpa_printf(MSG_ERROR, "Invalid EAP identity (no \" in "
    236 				   "start) on line %d in '%s'", line, fname);
    237 			goto failed;
    238 		}
    239 
    240 		user = os_zalloc(sizeof(*user));
    241 		if (user == NULL) {
    242 			wpa_printf(MSG_ERROR, "EAP user allocation failed");
    243 			goto failed;
    244 		}
    245 		user->force_version = -1;
    246 
    247 		if (buf[0] == '*') {
    248 			pos = buf;
    249 		} else {
    250 			pos = buf + 1;
    251 			start = pos;
    252 			while (*pos != '"' && *pos != '\0')
    253 				pos++;
    254 			if (*pos == '\0') {
    255 				wpa_printf(MSG_ERROR, "Invalid EAP identity "
    256 					   "(no \" in end) on line %d in '%s'",
    257 					   line, fname);
    258 				goto failed;
    259 			}
    260 
    261 			user->identity = os_malloc(pos - start);
    262 			if (user->identity == NULL) {
    263 				wpa_printf(MSG_ERROR, "Failed to allocate "
    264 					   "memory for EAP identity");
    265 				goto failed;
    266 			}
    267 			os_memcpy(user->identity, start, pos - start);
    268 			user->identity_len = pos - start;
    269 
    270 			if (pos[0] == '"' && pos[1] == '*') {
    271 				user->wildcard_prefix = 1;
    272 				pos++;
    273 			}
    274 		}
    275 		pos++;
    276 		while (*pos == ' ' || *pos == '\t')
    277 			pos++;
    278 
    279 		if (*pos == '\0') {
    280 			wpa_printf(MSG_ERROR, "No EAP method on line %d in "
    281 				   "'%s'", line, fname);
    282 			goto failed;
    283 		}
    284 
    285 		start = pos;
    286 		while (*pos != ' ' && *pos != '\t' && *pos != '\0')
    287 			pos++;
    288 		if (*pos == '\0') {
    289 			pos = NULL;
    290 		} else {
    291 			*pos = '\0';
    292 			pos++;
    293 		}
    294 		num_methods = 0;
    295 		while (*start) {
    296 			char *pos3 = os_strchr(start, ',');
    297 			if (pos3) {
    298 				*pos3++ = '\0';
    299 			}
    300 			user->methods[num_methods].method =
    301 				eap_server_get_type(
    302 					start,
    303 					&user->methods[num_methods].vendor);
    304 			if (user->methods[num_methods].vendor ==
    305 			    EAP_VENDOR_IETF &&
    306 			    user->methods[num_methods].method == EAP_TYPE_NONE)
    307 			{
    308 				if (os_strcmp(start, "TTLS-PAP") == 0) {
    309 					user->ttls_auth |= EAP_TTLS_AUTH_PAP;
    310 					goto skip_eap;
    311 				}
    312 				if (os_strcmp(start, "TTLS-CHAP") == 0) {
    313 					user->ttls_auth |= EAP_TTLS_AUTH_CHAP;
    314 					goto skip_eap;
    315 				}
    316 				if (os_strcmp(start, "TTLS-MSCHAP") == 0) {
    317 					user->ttls_auth |=
    318 						EAP_TTLS_AUTH_MSCHAP;
    319 					goto skip_eap;
    320 				}
    321 				if (os_strcmp(start, "TTLS-MSCHAPV2") == 0) {
    322 					user->ttls_auth |=
    323 						EAP_TTLS_AUTH_MSCHAPV2;
    324 					goto skip_eap;
    325 				}
    326 				wpa_printf(MSG_ERROR, "Unsupported EAP type "
    327 					   "'%s' on line %d in '%s'",
    328 					   start, line, fname);
    329 				goto failed;
    330 			}
    331 
    332 			num_methods++;
    333 			if (num_methods >= EAP_USER_MAX_METHODS)
    334 				break;
    335 		skip_eap:
    336 			if (pos3 == NULL)
    337 				break;
    338 			start = pos3;
    339 		}
    340 		if (num_methods == 0 && user->ttls_auth == 0) {
    341 			wpa_printf(MSG_ERROR, "No EAP types configured on "
    342 				   "line %d in '%s'", line, fname);
    343 			goto failed;
    344 		}
    345 
    346 		if (pos == NULL)
    347 			goto done;
    348 
    349 		while (*pos == ' ' || *pos == '\t')
    350 			pos++;
    351 		if (*pos == '\0')
    352 			goto done;
    353 
    354 		if (os_strncmp(pos, "[ver=0]", 7) == 0) {
    355 			user->force_version = 0;
    356 			goto done;
    357 		}
    358 
    359 		if (os_strncmp(pos, "[ver=1]", 7) == 0) {
    360 			user->force_version = 1;
    361 			goto done;
    362 		}
    363 
    364 		if (os_strncmp(pos, "[2]", 3) == 0) {
    365 			user->phase2 = 1;
    366 			goto done;
    367 		}
    368 
    369 		if (*pos == '"') {
    370 			pos++;
    371 			start = pos;
    372 			while (*pos != '"' && *pos != '\0')
    373 				pos++;
    374 			if (*pos == '\0') {
    375 				wpa_printf(MSG_ERROR, "Invalid EAP password "
    376 					   "(no \" in end) on line %d in '%s'",
    377 					   line, fname);
    378 				goto failed;
    379 			}
    380 
    381 			user->password = os_malloc(pos - start);
    382 			if (user->password == NULL) {
    383 				wpa_printf(MSG_ERROR, "Failed to allocate "
    384 					   "memory for EAP password");
    385 				goto failed;
    386 			}
    387 			os_memcpy(user->password, start, pos - start);
    388 			user->password_len = pos - start;
    389 
    390 			pos++;
    391 		} else if (os_strncmp(pos, "hash:", 5) == 0) {
    392 			pos += 5;
    393 			pos2 = pos;
    394 			while (*pos2 != '\0' && *pos2 != ' ' &&
    395 			       *pos2 != '\t' && *pos2 != '#')
    396 				pos2++;
    397 			if (pos2 - pos != 32) {
    398 				wpa_printf(MSG_ERROR, "Invalid password hash "
    399 					   "on line %d in '%s'", line, fname);
    400 				goto failed;
    401 			}
    402 			user->password = os_malloc(16);
    403 			if (user->password == NULL) {
    404 				wpa_printf(MSG_ERROR, "Failed to allocate "
    405 					   "memory for EAP password hash");
    406 				goto failed;
    407 			}
    408 			if (hexstr2bin(pos, user->password, 16) < 0) {
    409 				wpa_printf(MSG_ERROR, "Invalid hash password "
    410 					   "on line %d in '%s'", line, fname);
    411 				goto failed;
    412 			}
    413 			user->password_len = 16;
    414 			user->password_hash = 1;
    415 			pos = pos2;
    416 		} else {
    417 			pos2 = pos;
    418 			while (*pos2 != '\0' && *pos2 != ' ' &&
    419 			       *pos2 != '\t' && *pos2 != '#')
    420 				pos2++;
    421 			if ((pos2 - pos) & 1) {
    422 				wpa_printf(MSG_ERROR, "Invalid hex password "
    423 					   "on line %d in '%s'", line, fname);
    424 				goto failed;
    425 			}
    426 			user->password = os_malloc((pos2 - pos) / 2);
    427 			if (user->password == NULL) {
    428 				wpa_printf(MSG_ERROR, "Failed to allocate "
    429 					   "memory for EAP password");
    430 				goto failed;
    431 			}
    432 			if (hexstr2bin(pos, user->password,
    433 				       (pos2 - pos) / 2) < 0) {
    434 				wpa_printf(MSG_ERROR, "Invalid hex password "
    435 					   "on line %d in '%s'", line, fname);
    436 				goto failed;
    437 			}
    438 			user->password_len = (pos2 - pos) / 2;
    439 			pos = pos2;
    440 		}
    441 
    442 		while (*pos == ' ' || *pos == '\t')
    443 			pos++;
    444 		if (os_strncmp(pos, "[2]", 3) == 0) {
    445 			user->phase2 = 1;
    446 		}
    447 
    448 	done:
    449 		if (tail == NULL) {
    450 			tail = conf->eap_user = user;
    451 		} else {
    452 			tail->next = user;
    453 			tail = user;
    454 		}
    455 		continue;
    456 
    457 	failed:
    458 		if (user) {
    459 			os_free(user->password);
    460 			os_free(user->identity);
    461 			os_free(user);
    462 		}
    463 		ret = -1;
    464 		break;
    465 	}
    466 
    467 	fclose(f);
    468 
    469 	return ret;
    470 }
    471 #endif /* EAP_SERVER */
    472 
    473 
    474 #ifndef CONFIG_NO_RADIUS
    475 static int
    476 hostapd_config_read_radius_addr(struct hostapd_radius_server **server,
    477 				int *num_server, const char *val, int def_port,
    478 				struct hostapd_radius_server **curr_serv)
    479 {
    480 	struct hostapd_radius_server *nserv;
    481 	int ret;
    482 	static int server_index = 1;
    483 
    484 	nserv = os_realloc(*server, (*num_server + 1) * sizeof(*nserv));
    485 	if (nserv == NULL)
    486 		return -1;
    487 
    488 	*server = nserv;
    489 	nserv = &nserv[*num_server];
    490 	(*num_server)++;
    491 	(*curr_serv) = nserv;
    492 
    493 	os_memset(nserv, 0, sizeof(*nserv));
    494 	nserv->port = def_port;
    495 	ret = hostapd_parse_ip_addr(val, &nserv->addr);
    496 	nserv->index = server_index++;
    497 
    498 	return ret;
    499 }
    500 #endif /* CONFIG_NO_RADIUS */
    501 
    502 
    503 static int hostapd_config_parse_key_mgmt(int line, const char *value)
    504 {
    505 	int val = 0, last;
    506 	char *start, *end, *buf;
    507 
    508 	buf = os_strdup(value);
    509 	if (buf == NULL)
    510 		return -1;
    511 	start = buf;
    512 
    513 	while (*start != '\0') {
    514 		while (*start == ' ' || *start == '\t')
    515 			start++;
    516 		if (*start == '\0')
    517 			break;
    518 		end = start;
    519 		while (*end != ' ' && *end != '\t' && *end != '\0')
    520 			end++;
    521 		last = *end == '\0';
    522 		*end = '\0';
    523 		if (os_strcmp(start, "WPA-PSK") == 0)
    524 			val |= WPA_KEY_MGMT_PSK;
    525 		else if (os_strcmp(start, "WPA-EAP") == 0)
    526 			val |= WPA_KEY_MGMT_IEEE8021X;
    527 #ifdef CONFIG_IEEE80211R
    528 		else if (os_strcmp(start, "FT-PSK") == 0)
    529 			val |= WPA_KEY_MGMT_FT_PSK;
    530 		else if (os_strcmp(start, "FT-EAP") == 0)
    531 			val |= WPA_KEY_MGMT_FT_IEEE8021X;
    532 #endif /* CONFIG_IEEE80211R */
    533 #ifdef CONFIG_IEEE80211W
    534 		else if (os_strcmp(start, "WPA-PSK-SHA256") == 0)
    535 			val |= WPA_KEY_MGMT_PSK_SHA256;
    536 		else if (os_strcmp(start, "WPA-EAP-SHA256") == 0)
    537 			val |= WPA_KEY_MGMT_IEEE8021X_SHA256;
    538 #endif /* CONFIG_IEEE80211W */
    539 		else {
    540 			wpa_printf(MSG_ERROR, "Line %d: invalid key_mgmt '%s'",
    541 				   line, start);
    542 			os_free(buf);
    543 			return -1;
    544 		}
    545 
    546 		if (last)
    547 			break;
    548 		start = end + 1;
    549 	}
    550 
    551 	os_free(buf);
    552 	if (val == 0) {
    553 		wpa_printf(MSG_ERROR, "Line %d: no key_mgmt values "
    554 			   "configured.", line);
    555 		return -1;
    556 	}
    557 
    558 	return val;
    559 }
    560 
    561 
    562 static int hostapd_config_parse_cipher(int line, const char *value)
    563 {
    564 	int val = 0, last;
    565 	char *start, *end, *buf;
    566 
    567 	buf = os_strdup(value);
    568 	if (buf == NULL)
    569 		return -1;
    570 	start = buf;
    571 
    572 	while (*start != '\0') {
    573 		while (*start == ' ' || *start == '\t')
    574 			start++;
    575 		if (*start == '\0')
    576 			break;
    577 		end = start;
    578 		while (*end != ' ' && *end != '\t' && *end != '\0')
    579 			end++;
    580 		last = *end == '\0';
    581 		*end = '\0';
    582 		if (os_strcmp(start, "CCMP") == 0)
    583 			val |= WPA_CIPHER_CCMP;
    584 		else if (os_strcmp(start, "TKIP") == 0)
    585 			val |= WPA_CIPHER_TKIP;
    586 		else if (os_strcmp(start, "WEP104") == 0)
    587 			val |= WPA_CIPHER_WEP104;
    588 		else if (os_strcmp(start, "WEP40") == 0)
    589 			val |= WPA_CIPHER_WEP40;
    590 		else if (os_strcmp(start, "NONE") == 0)
    591 			val |= WPA_CIPHER_NONE;
    592 		else {
    593 			wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
    594 				   line, start);
    595 			os_free(buf);
    596 			return -1;
    597 		}
    598 
    599 		if (last)
    600 			break;
    601 		start = end + 1;
    602 	}
    603 	os_free(buf);
    604 
    605 	if (val == 0) {
    606 		wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
    607 			   line);
    608 		return -1;
    609 	}
    610 	return val;
    611 }
    612 
    613 
    614 static int hostapd_config_read_wep(struct hostapd_wep_keys *wep, int keyidx,
    615 				   char *val)
    616 {
    617 	size_t len = os_strlen(val);
    618 
    619 	if (keyidx < 0 || keyidx > 3 || wep->key[keyidx] != NULL)
    620 		return -1;
    621 
    622 	if (val[0] == '"') {
    623 		if (len < 2 || val[len - 1] != '"')
    624 			return -1;
    625 		len -= 2;
    626 		wep->key[keyidx] = os_malloc(len);
    627 		if (wep->key[keyidx] == NULL)
    628 			return -1;
    629 		os_memcpy(wep->key[keyidx], val + 1, len);
    630 		wep->len[keyidx] = len;
    631 	} else {
    632 		if (len & 1)
    633 			return -1;
    634 		len /= 2;
    635 		wep->key[keyidx] = os_malloc(len);
    636 		if (wep->key[keyidx] == NULL)
    637 			return -1;
    638 		wep->len[keyidx] = len;
    639 		if (hexstr2bin(val, wep->key[keyidx], len) < 0)
    640 			return -1;
    641 	}
    642 
    643 	wep->keys_set++;
    644 
    645 	return 0;
    646 }
    647 
    648 
    649 static int hostapd_parse_rates(int **rate_list, char *val)
    650 {
    651 	int *list;
    652 	int count;
    653 	char *pos, *end;
    654 
    655 	os_free(*rate_list);
    656 	*rate_list = NULL;
    657 
    658 	pos = val;
    659 	count = 0;
    660 	while (*pos != '\0') {
    661 		if (*pos == ' ')
    662 			count++;
    663 		pos++;
    664 	}
    665 
    666 	list = os_malloc(sizeof(int) * (count + 2));
    667 	if (list == NULL)
    668 		return -1;
    669 	pos = val;
    670 	count = 0;
    671 	while (*pos != '\0') {
    672 		end = os_strchr(pos, ' ');
    673 		if (end)
    674 			*end = '\0';
    675 
    676 		list[count++] = atoi(pos);
    677 		if (!end)
    678 			break;
    679 		pos = end + 1;
    680 	}
    681 	list[count] = -1;
    682 
    683 	*rate_list = list;
    684 	return 0;
    685 }
    686 
    687 
    688 static int hostapd_config_bss(struct hostapd_config *conf, const char *ifname)
    689 {
    690 	struct hostapd_bss_config *bss;
    691 
    692 	if (*ifname == '\0')
    693 		return -1;
    694 
    695 	bss = os_realloc(conf->bss, (conf->num_bss + 1) *
    696 			 sizeof(struct hostapd_bss_config));
    697 	if (bss == NULL) {
    698 		wpa_printf(MSG_ERROR, "Failed to allocate memory for "
    699 			   "multi-BSS entry");
    700 		return -1;
    701 	}
    702 	conf->bss = bss;
    703 
    704 	bss = &(conf->bss[conf->num_bss]);
    705 	os_memset(bss, 0, sizeof(*bss));
    706 	bss->radius = os_zalloc(sizeof(*bss->radius));
    707 	if (bss->radius == NULL) {
    708 		wpa_printf(MSG_ERROR, "Failed to allocate memory for "
    709 			   "multi-BSS RADIUS data");
    710 		return -1;
    711 	}
    712 
    713 	conf->num_bss++;
    714 	conf->last_bss = bss;
    715 
    716 	hostapd_config_defaults_bss(bss);
    717 	os_strlcpy(bss->iface, ifname, sizeof(bss->iface));
    718 	os_memcpy(bss->ssid.vlan, bss->iface, IFNAMSIZ + 1);
    719 
    720 	return 0;
    721 }
    722 
    723 
    724 /* convert floats with one decimal place to value*10 int, i.e.,
    725  * "1.5" will return 15 */
    726 static int hostapd_config_read_int10(const char *value)
    727 {
    728 	int i, d;
    729 	char *pos;
    730 
    731 	i = atoi(value);
    732 	pos = os_strchr(value, '.');
    733 	d = 0;
    734 	if (pos) {
    735 		pos++;
    736 		if (*pos >= '0' && *pos <= '9')
    737 			d = *pos - '0';
    738 	}
    739 
    740 	return i * 10 + d;
    741 }
    742 
    743 
    744 static int valid_cw(int cw)
    745 {
    746 	return (cw == 1 || cw == 3 || cw == 7 || cw == 15 || cw == 31 ||
    747 		cw == 63 || cw == 127 || cw == 255 || cw == 511 || cw == 1023);
    748 }
    749 
    750 
    751 enum {
    752 	IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
    753 	IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
    754 	IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
    755 	IEEE80211_TX_QUEUE_DATA3 = 3 /* used for EDCA AC_BK data */
    756 };
    757 
    758 static int hostapd_config_tx_queue(struct hostapd_config *conf, char *name,
    759 				   char *val)
    760 {
    761 	int num;
    762 	char *pos;
    763 	struct hostapd_tx_queue_params *queue;
    764 
    765 	/* skip 'tx_queue_' prefix */
    766 	pos = name + 9;
    767 	if (os_strncmp(pos, "data", 4) == 0 &&
    768 	    pos[4] >= '0' && pos[4] <= '9' && pos[5] == '_') {
    769 		num = pos[4] - '0';
    770 		pos += 6;
    771 	} else if (os_strncmp(pos, "after_beacon_", 13) == 0 ||
    772 		   os_strncmp(pos, "beacon_", 7) == 0) {
    773 		wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
    774 		return 0;
    775 	} else {
    776 		wpa_printf(MSG_ERROR, "Unknown tx_queue name '%s'", pos);
    777 		return -1;
    778 	}
    779 
    780 	if (num >= NUM_TX_QUEUES) {
    781 		/* for backwards compatibility, do not trigger failure */
    782 		wpa_printf(MSG_INFO, "DEPRECATED: '%s' not used", name);
    783 		return 0;
    784 	}
    785 
    786 	queue = &conf->tx_queue[num];
    787 
    788 	if (os_strcmp(pos, "aifs") == 0) {
    789 		queue->aifs = atoi(val);
    790 		if (queue->aifs < 0 || queue->aifs > 255) {
    791 			wpa_printf(MSG_ERROR, "Invalid AIFS value %d",
    792 				   queue->aifs);
    793 			return -1;
    794 		}
    795 	} else if (os_strcmp(pos, "cwmin") == 0) {
    796 		queue->cwmin = atoi(val);
    797 		if (!valid_cw(queue->cwmin)) {
    798 			wpa_printf(MSG_ERROR, "Invalid cwMin value %d",
    799 				   queue->cwmin);
    800 			return -1;
    801 		}
    802 	} else if (os_strcmp(pos, "cwmax") == 0) {
    803 		queue->cwmax = atoi(val);
    804 		if (!valid_cw(queue->cwmax)) {
    805 			wpa_printf(MSG_ERROR, "Invalid cwMax value %d",
    806 				   queue->cwmax);
    807 			return -1;
    808 		}
    809 	} else if (os_strcmp(pos, "burst") == 0) {
    810 		queue->burst = hostapd_config_read_int10(val);
    811 	} else {
    812 		wpa_printf(MSG_ERROR, "Unknown tx_queue field '%s'", pos);
    813 		return -1;
    814 	}
    815 
    816 	return 0;
    817 }
    818 
    819 
    820 static int hostapd_config_wmm_ac(struct hostapd_config *conf, char *name,
    821 				 char *val)
    822 {
    823 	int num, v;
    824 	char *pos;
    825 	struct hostapd_wmm_ac_params *ac;
    826 
    827 	/* skip 'wme_ac_' or 'wmm_ac_' prefix */
    828 	pos = name + 7;
    829 	if (os_strncmp(pos, "be_", 3) == 0) {
    830 		num = 0;
    831 		pos += 3;
    832 	} else if (os_strncmp(pos, "bk_", 3) == 0) {
    833 		num = 1;
    834 		pos += 3;
    835 	} else if (os_strncmp(pos, "vi_", 3) == 0) {
    836 		num = 2;
    837 		pos += 3;
    838 	} else if (os_strncmp(pos, "vo_", 3) == 0) {
    839 		num = 3;
    840 		pos += 3;
    841 	} else {
    842 		wpa_printf(MSG_ERROR, "Unknown WMM name '%s'", pos);
    843 		return -1;
    844 	}
    845 
    846 	ac = &conf->wmm_ac_params[num];
    847 
    848 	if (os_strcmp(pos, "aifs") == 0) {
    849 		v = atoi(val);
    850 		if (v < 1 || v > 255) {
    851 			wpa_printf(MSG_ERROR, "Invalid AIFS value %d", v);
    852 			return -1;
    853 		}
    854 		ac->aifs = v;
    855 	} else if (os_strcmp(pos, "cwmin") == 0) {
    856 		v = atoi(val);
    857 		if (v < 0 || v > 12) {
    858 			wpa_printf(MSG_ERROR, "Invalid cwMin value %d", v);
    859 			return -1;
    860 		}
    861 		ac->cwmin = v;
    862 	} else if (os_strcmp(pos, "cwmax") == 0) {
    863 		v = atoi(val);
    864 		if (v < 0 || v > 12) {
    865 			wpa_printf(MSG_ERROR, "Invalid cwMax value %d", v);
    866 			return -1;
    867 		}
    868 		ac->cwmax = v;
    869 	} else if (os_strcmp(pos, "txop_limit") == 0) {
    870 		v = atoi(val);
    871 		if (v < 0 || v > 0xffff) {
    872 			wpa_printf(MSG_ERROR, "Invalid txop value %d", v);
    873 			return -1;
    874 		}
    875 		ac->txop_limit = v;
    876 	} else if (os_strcmp(pos, "acm") == 0) {
    877 		v = atoi(val);
    878 		if (v < 0 || v > 1) {
    879 			wpa_printf(MSG_ERROR, "Invalid acm value %d", v);
    880 			return -1;
    881 		}
    882 		ac->admission_control_mandatory = v;
    883 	} else {
    884 		wpa_printf(MSG_ERROR, "Unknown wmm_ac_ field '%s'", pos);
    885 		return -1;
    886 	}
    887 
    888 	return 0;
    889 }
    890 
    891 
    892 #ifdef CONFIG_IEEE80211R
    893 static int add_r0kh(struct hostapd_bss_config *bss, char *value)
    894 {
    895 	struct ft_remote_r0kh *r0kh;
    896 	char *pos, *next;
    897 
    898 	r0kh = os_zalloc(sizeof(*r0kh));
    899 	if (r0kh == NULL)
    900 		return -1;
    901 
    902 	/* 02:01:02:03:04:05 a.example.com 000102030405060708090a0b0c0d0e0f */
    903 	pos = value;
    904 	next = os_strchr(pos, ' ');
    905 	if (next)
    906 		*next++ = '\0';
    907 	if (next == NULL || hwaddr_aton(pos, r0kh->addr)) {
    908 		wpa_printf(MSG_ERROR, "Invalid R0KH MAC address: '%s'", pos);
    909 		os_free(r0kh);
    910 		return -1;
    911 	}
    912 
    913 	pos = next;
    914 	next = os_strchr(pos, ' ');
    915 	if (next)
    916 		*next++ = '\0';
    917 	if (next == NULL || next - pos > FT_R0KH_ID_MAX_LEN) {
    918 		wpa_printf(MSG_ERROR, "Invalid R0KH-ID: '%s'", pos);
    919 		os_free(r0kh);
    920 		return -1;
    921 	}
    922 	r0kh->id_len = next - pos - 1;
    923 	os_memcpy(r0kh->id, pos, r0kh->id_len);
    924 
    925 	pos = next;
    926 	if (hexstr2bin(pos, r0kh->key, sizeof(r0kh->key))) {
    927 		wpa_printf(MSG_ERROR, "Invalid R0KH key: '%s'", pos);
    928 		os_free(r0kh);
    929 		return -1;
    930 	}
    931 
    932 	r0kh->next = bss->r0kh_list;
    933 	bss->r0kh_list = r0kh;
    934 
    935 	return 0;
    936 }
    937 
    938 
    939 static int add_r1kh(struct hostapd_bss_config *bss, char *value)
    940 {
    941 	struct ft_remote_r1kh *r1kh;
    942 	char *pos, *next;
    943 
    944 	r1kh = os_zalloc(sizeof(*r1kh));
    945 	if (r1kh == NULL)
    946 		return -1;
    947 
    948 	/* 02:01:02:03:04:05 02:01:02:03:04:05
    949 	 * 000102030405060708090a0b0c0d0e0f */
    950 	pos = value;
    951 	next = os_strchr(pos, ' ');
    952 	if (next)
    953 		*next++ = '\0';
    954 	if (next == NULL || hwaddr_aton(pos, r1kh->addr)) {
    955 		wpa_printf(MSG_ERROR, "Invalid R1KH MAC address: '%s'", pos);
    956 		os_free(r1kh);
    957 		return -1;
    958 	}
    959 
    960 	pos = next;
    961 	next = os_strchr(pos, ' ');
    962 	if (next)
    963 		*next++ = '\0';
    964 	if (next == NULL || hwaddr_aton(pos, r1kh->id)) {
    965 		wpa_printf(MSG_ERROR, "Invalid R1KH-ID: '%s'", pos);
    966 		os_free(r1kh);
    967 		return -1;
    968 	}
    969 
    970 	pos = next;
    971 	if (hexstr2bin(pos, r1kh->key, sizeof(r1kh->key))) {
    972 		wpa_printf(MSG_ERROR, "Invalid R1KH key: '%s'", pos);
    973 		os_free(r1kh);
    974 		return -1;
    975 	}
    976 
    977 	r1kh->next = bss->r1kh_list;
    978 	bss->r1kh_list = r1kh;
    979 
    980 	return 0;
    981 }
    982 #endif /* CONFIG_IEEE80211R */
    983 
    984 
    985 #ifdef CONFIG_IEEE80211N
    986 static int hostapd_config_ht_capab(struct hostapd_config *conf,
    987 				   const char *capab)
    988 {
    989 	if (os_strstr(capab, "[LDPC]"))
    990 		conf->ht_capab |= HT_CAP_INFO_LDPC_CODING_CAP;
    991 	if (os_strstr(capab, "[HT40-]")) {
    992 		conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
    993 		conf->secondary_channel = -1;
    994 	}
    995 	if (os_strstr(capab, "[HT40+]")) {
    996 		conf->ht_capab |= HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
    997 		conf->secondary_channel = 1;
    998 	}
    999 	if (os_strstr(capab, "[SMPS-STATIC]")) {
   1000 		conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
   1001 		conf->ht_capab |= HT_CAP_INFO_SMPS_STATIC;
   1002 	}
   1003 	if (os_strstr(capab, "[SMPS-DYNAMIC]")) {
   1004 		conf->ht_capab &= ~HT_CAP_INFO_SMPS_MASK;
   1005 		conf->ht_capab |= HT_CAP_INFO_SMPS_DYNAMIC;
   1006 	}
   1007 	if (os_strstr(capab, "[GF]"))
   1008 		conf->ht_capab |= HT_CAP_INFO_GREEN_FIELD;
   1009 	if (os_strstr(capab, "[SHORT-GI-20]"))
   1010 		conf->ht_capab |= HT_CAP_INFO_SHORT_GI20MHZ;
   1011 	if (os_strstr(capab, "[SHORT-GI-40]"))
   1012 		conf->ht_capab |= HT_CAP_INFO_SHORT_GI40MHZ;
   1013 	if (os_strstr(capab, "[TX-STBC]"))
   1014 		conf->ht_capab |= HT_CAP_INFO_TX_STBC;
   1015 	if (os_strstr(capab, "[RX-STBC1]")) {
   1016 		conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
   1017 		conf->ht_capab |= HT_CAP_INFO_RX_STBC_1;
   1018 	}
   1019 	if (os_strstr(capab, "[RX-STBC12]")) {
   1020 		conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
   1021 		conf->ht_capab |= HT_CAP_INFO_RX_STBC_12;
   1022 	}
   1023 	if (os_strstr(capab, "[RX-STBC123]")) {
   1024 		conf->ht_capab &= ~HT_CAP_INFO_RX_STBC_MASK;
   1025 		conf->ht_capab |= HT_CAP_INFO_RX_STBC_123;
   1026 	}
   1027 	if (os_strstr(capab, "[DELAYED-BA]"))
   1028 		conf->ht_capab |= HT_CAP_INFO_DELAYED_BA;
   1029 	if (os_strstr(capab, "[MAX-AMSDU-7935]"))
   1030 		conf->ht_capab |= HT_CAP_INFO_MAX_AMSDU_SIZE;
   1031 	if (os_strstr(capab, "[DSSS_CCK-40]"))
   1032 		conf->ht_capab |= HT_CAP_INFO_DSSS_CCK40MHZ;
   1033 	if (os_strstr(capab, "[PSMP]"))
   1034 		conf->ht_capab |= HT_CAP_INFO_PSMP_SUPP;
   1035 	if (os_strstr(capab, "[LSIG-TXOP-PROT]"))
   1036 		conf->ht_capab |= HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT;
   1037 
   1038 	return 0;
   1039 }
   1040 #endif /* CONFIG_IEEE80211N */
   1041 
   1042 
   1043 static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
   1044 				    struct hostapd_config *conf)
   1045 {
   1046 	if (bss->ieee802_1x && !bss->eap_server &&
   1047 	    !bss->radius->auth_servers) {
   1048 		wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
   1049 			   "EAP authenticator configured).");
   1050 		return -1;
   1051 	}
   1052 
   1053 	if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
   1054 	    bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
   1055 	    bss->ssid.wpa_psk_file == NULL) {
   1056 		wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
   1057 			   "is not configured.");
   1058 		return -1;
   1059 	}
   1060 
   1061 	if (hostapd_mac_comp_empty(bss->bssid) != 0) {
   1062 		size_t i;
   1063 
   1064 		for (i = 0; i < conf->num_bss; i++) {
   1065 			if ((&conf->bss[i] != bss) &&
   1066 			    (hostapd_mac_comp(conf->bss[i].bssid,
   1067 					      bss->bssid) == 0)) {
   1068 				wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
   1069 					   " on interface '%s' and '%s'.",
   1070 					   MAC2STR(bss->bssid),
   1071 					   conf->bss[i].iface, bss->iface);
   1072 				return -1;
   1073 			}
   1074 		}
   1075 	}
   1076 
   1077 #ifdef CONFIG_IEEE80211R
   1078 	if ((bss->wpa_key_mgmt &
   1079 	     (WPA_KEY_MGMT_FT_PSK | WPA_KEY_MGMT_FT_IEEE8021X)) &&
   1080 	    (bss->nas_identifier == NULL ||
   1081 	     os_strlen(bss->nas_identifier) < 1 ||
   1082 	     os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
   1083 		wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
   1084 			   "nas_identifier to be configured as a 1..48 octet "
   1085 			   "string");
   1086 		return -1;
   1087 	}
   1088 #endif /* CONFIG_IEEE80211R */
   1089 
   1090 #ifdef CONFIG_IEEE80211N
   1091 	if (conf->ieee80211n &&
   1092 	    bss->ssid.security_policy == SECURITY_STATIC_WEP) {
   1093 		bss->disable_11n = 1;
   1094 		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
   1095 			   "allowed, disabling HT capabilities");
   1096 	}
   1097 
   1098 	if (conf->ieee80211n && bss->wpa &&
   1099 	    !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
   1100 	    !(bss->rsn_pairwise & WPA_CIPHER_CCMP)) {
   1101 		bss->disable_11n = 1;
   1102 		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
   1103 			   "requires CCMP to be enabled, disabling HT "
   1104 			   "capabilities");
   1105 	}
   1106 #endif /* CONFIG_IEEE80211N */
   1107 
   1108 #ifdef CONFIG_WPS2
   1109 	if (bss->wps_state && bss->ignore_broadcast_ssid) {
   1110 		wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
   1111 			   "configuration forced WPS to be disabled");
   1112 		bss->wps_state = 0;
   1113 	}
   1114 
   1115 	if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
   1116 		wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
   1117 			   "disabled");
   1118 		bss->wps_state = 0;
   1119 	}
   1120 #endif /* CONFIG_WPS2 */
   1121 
   1122 	return 0;
   1123 }
   1124 
   1125 
   1126 static int hostapd_config_check(struct hostapd_config *conf)
   1127 {
   1128 	size_t i;
   1129 
   1130 	if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
   1131 		wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
   1132 			   "setting the country_code");
   1133 		return -1;
   1134 	}
   1135 
   1136 	for (i = 0; i < conf->num_bss; i++) {
   1137 		if (hostapd_config_check_bss(&conf->bss[i], conf))
   1138 			return -1;
   1139 	}
   1140 
   1141 	return 0;
   1142 }
   1143 
   1144 
   1145 #ifdef CONFIG_INTERWORKING
   1146 static int parse_roaming_consortium(struct hostapd_bss_config *bss, char *pos,
   1147 				    int line)
   1148 {
   1149 	size_t len = os_strlen(pos);
   1150 	u8 oi[MAX_ROAMING_CONSORTIUM_LEN];
   1151 
   1152 	struct hostapd_roaming_consortium *rc;
   1153 
   1154 	if ((len & 1) || len < 2 * 3 || len / 2 > MAX_ROAMING_CONSORTIUM_LEN ||
   1155 	    hexstr2bin(pos, oi, len / 2)) {
   1156 		wpa_printf(MSG_ERROR, "Line %d: invalid roaming_consortium "
   1157 			   "'%s'", line, pos);
   1158 		return -1;
   1159 	}
   1160 	len /= 2;
   1161 
   1162 	rc = os_realloc(bss->roaming_consortium,
   1163 			sizeof(struct hostapd_roaming_consortium) *
   1164 			(bss->roaming_consortium_count + 1));
   1165 	if (rc == NULL)
   1166 		return -1;
   1167 
   1168 	os_memcpy(rc[bss->roaming_consortium_count].oi, oi, len);
   1169 	rc[bss->roaming_consortium_count].len = len;
   1170 
   1171 	bss->roaming_consortium = rc;
   1172 	bss->roaming_consortium_count++;
   1173 
   1174 	return 0;
   1175 }
   1176 #endif /* CONFIG_INTERWORKING */
   1177 
   1178 
   1179 /**
   1180  * hostapd_config_read - Read and parse a configuration file
   1181  * @fname: Configuration file name (including path, if needed)
   1182  * Returns: Allocated configuration data structure
   1183  */
   1184 struct hostapd_config * hostapd_config_read(const char *fname)
   1185 {
   1186 	struct hostapd_config *conf;
   1187 	struct hostapd_bss_config *bss;
   1188 	FILE *f;
   1189 	char buf[256], *pos;
   1190 	int line = 0;
   1191 	int errors = 0;
   1192 	int pairwise;
   1193 	size_t i;
   1194 
   1195 	f = fopen(fname, "r");
   1196 	if (f == NULL) {
   1197 		wpa_printf(MSG_ERROR, "Could not open configuration file '%s' "
   1198 			   "for reading.", fname);
   1199 		return NULL;
   1200 	}
   1201 
   1202 	conf = hostapd_config_defaults();
   1203 	if (conf == NULL) {
   1204 		fclose(f);
   1205 		return NULL;
   1206 	}
   1207 
   1208 	/* set default driver based on configuration */
   1209 	conf->driver = wpa_drivers[0];
   1210 	if (conf->driver == NULL) {
   1211 		wpa_printf(MSG_ERROR, "No driver wrappers registered!");
   1212 		hostapd_config_free(conf);
   1213 		fclose(f);
   1214 		return NULL;
   1215 	}
   1216 
   1217 	bss = conf->last_bss = conf->bss;
   1218 
   1219 	while (fgets(buf, sizeof(buf), f)) {
   1220 		bss = conf->last_bss;
   1221 		line++;
   1222 
   1223 		if (buf[0] == '#')
   1224 			continue;
   1225 		pos = buf;
   1226 		while (*pos != '\0') {
   1227 			if (*pos == '\n') {
   1228 				*pos = '\0';
   1229 				break;
   1230 			}
   1231 			pos++;
   1232 		}
   1233 		if (buf[0] == '\0')
   1234 			continue;
   1235 
   1236 		pos = os_strchr(buf, '=');
   1237 		if (pos == NULL) {
   1238 			wpa_printf(MSG_ERROR, "Line %d: invalid line '%s'",
   1239 				   line, buf);
   1240 			errors++;
   1241 			continue;
   1242 		}
   1243 		*pos = '\0';
   1244 		pos++;
   1245 
   1246 		if (os_strcmp(buf, "interface") == 0) {
   1247 			os_strlcpy(conf->bss[0].iface, pos,
   1248 				   sizeof(conf->bss[0].iface));
   1249 		} else if (os_strcmp(buf, "bridge") == 0) {
   1250 			os_strlcpy(bss->bridge, pos, sizeof(bss->bridge));
   1251 		} else if (os_strcmp(buf, "wds_bridge") == 0) {
   1252 			os_strlcpy(bss->wds_bridge, pos,
   1253 				   sizeof(bss->wds_bridge));
   1254 		} else if (os_strcmp(buf, "driver") == 0) {
   1255 			int j;
   1256 			/* clear to get error below if setting is invalid */
   1257 			conf->driver = NULL;
   1258 			for (j = 0; wpa_drivers[j]; j++) {
   1259 				if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
   1260 				{
   1261 					conf->driver = wpa_drivers[j];
   1262 					break;
   1263 				}
   1264 			}
   1265 			if (conf->driver == NULL) {
   1266 				wpa_printf(MSG_ERROR, "Line %d: invalid/"
   1267 					   "unknown driver '%s'", line, pos);
   1268 				errors++;
   1269 			}
   1270 		} else if (os_strcmp(buf, "debug") == 0) {
   1271 			wpa_printf(MSG_DEBUG, "Line %d: DEPRECATED: 'debug' "
   1272 				   "configuration variable is not used "
   1273 				   "anymore", line);
   1274 		} else if (os_strcmp(buf, "logger_syslog_level") == 0) {
   1275 			bss->logger_syslog_level = atoi(pos);
   1276 		} else if (os_strcmp(buf, "logger_stdout_level") == 0) {
   1277 			bss->logger_stdout_level = atoi(pos);
   1278 		} else if (os_strcmp(buf, "logger_syslog") == 0) {
   1279 			bss->logger_syslog = atoi(pos);
   1280 		} else if (os_strcmp(buf, "logger_stdout") == 0) {
   1281 			bss->logger_stdout = atoi(pos);
   1282 		} else if (os_strcmp(buf, "dump_file") == 0) {
   1283 			bss->dump_log_name = os_strdup(pos);
   1284 		} else if (os_strcmp(buf, "ssid") == 0) {
   1285 			bss->ssid.ssid_len = os_strlen(pos);
   1286 			if (bss->ssid.ssid_len > HOSTAPD_MAX_SSID_LEN ||
   1287 			    bss->ssid.ssid_len < 1) {
   1288 				wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
   1289 					   "'%s'", line, pos);
   1290 				errors++;
   1291 			} else {
   1292 				os_memcpy(bss->ssid.ssid, pos,
   1293 					  bss->ssid.ssid_len);
   1294 				bss->ssid.ssid[bss->ssid.ssid_len] = '\0';
   1295 				bss->ssid.ssid_set = 1;
   1296 			}
   1297 		} else if (os_strcmp(buf, "macaddr_acl") == 0) {
   1298 			bss->macaddr_acl = atoi(pos);
   1299 			if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
   1300 			    bss->macaddr_acl != DENY_UNLESS_ACCEPTED &&
   1301 			    bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
   1302 				wpa_printf(MSG_ERROR, "Line %d: unknown "
   1303 					   "macaddr_acl %d",
   1304 					   line, bss->macaddr_acl);
   1305 			}
   1306 		} else if (os_strcmp(buf, "accept_mac_file") == 0) {
   1307 			if (hostapd_config_read_maclist(pos, &bss->accept_mac,
   1308 							&bss->num_accept_mac))
   1309 			{
   1310 				wpa_printf(MSG_ERROR, "Line %d: Failed to "
   1311 					   "read accept_mac_file '%s'",
   1312 					   line, pos);
   1313 				errors++;
   1314 			}
   1315 		} else if (os_strcmp(buf, "deny_mac_file") == 0) {
   1316 			if (hostapd_config_read_maclist(pos, &bss->deny_mac,
   1317 							&bss->num_deny_mac)) {
   1318 				wpa_printf(MSG_ERROR, "Line %d: Failed to "
   1319 					   "read deny_mac_file '%s'",
   1320 					   line, pos);
   1321 				errors++;
   1322 			}
   1323 		} else if (os_strcmp(buf, "wds_sta") == 0) {
   1324 			bss->wds_sta = atoi(pos);
   1325 		} else if (os_strcmp(buf, "ap_isolate") == 0) {
   1326 			bss->isolate = atoi(pos);
   1327 		} else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
   1328 			bss->ap_max_inactivity = atoi(pos);
   1329 		} else if (os_strcmp(buf, "country_code") == 0) {
   1330 			os_memcpy(conf->country, pos, 2);
   1331 			/* FIX: make this configurable */
   1332 			conf->country[2] = ' ';
   1333 		} else if (os_strcmp(buf, "ieee80211d") == 0) {
   1334 			conf->ieee80211d = atoi(pos);
   1335 		} else if (os_strcmp(buf, "ieee8021x") == 0) {
   1336 			bss->ieee802_1x = atoi(pos);
   1337 		} else if (os_strcmp(buf, "eapol_version") == 0) {
   1338 			bss->eapol_version = atoi(pos);
   1339 			if (bss->eapol_version < 1 ||
   1340 			    bss->eapol_version > 2) {
   1341 				wpa_printf(MSG_ERROR, "Line %d: invalid EAPOL "
   1342 					   "version (%d): '%s'.",
   1343 					   line, bss->eapol_version, pos);
   1344 				errors++;
   1345 			} else
   1346 				wpa_printf(MSG_DEBUG, "eapol_version=%d",
   1347 					   bss->eapol_version);
   1348 #ifdef EAP_SERVER
   1349 		} else if (os_strcmp(buf, "eap_authenticator") == 0) {
   1350 			bss->eap_server = atoi(pos);
   1351 			wpa_printf(MSG_ERROR, "Line %d: obsolete "
   1352 				   "eap_authenticator used; this has been "
   1353 				   "renamed to eap_server", line);
   1354 		} else if (os_strcmp(buf, "eap_server") == 0) {
   1355 			bss->eap_server = atoi(pos);
   1356 		} else if (os_strcmp(buf, "eap_user_file") == 0) {
   1357 			if (hostapd_config_read_eap_user(pos, bss))
   1358 				errors++;
   1359 		} else if (os_strcmp(buf, "ca_cert") == 0) {
   1360 			os_free(bss->ca_cert);
   1361 			bss->ca_cert = os_strdup(pos);
   1362 		} else if (os_strcmp(buf, "server_cert") == 0) {
   1363 			os_free(bss->server_cert);
   1364 			bss->server_cert = os_strdup(pos);
   1365 		} else if (os_strcmp(buf, "private_key") == 0) {
   1366 			os_free(bss->private_key);
   1367 			bss->private_key = os_strdup(pos);
   1368 		} else if (os_strcmp(buf, "private_key_passwd") == 0) {
   1369 			os_free(bss->private_key_passwd);
   1370 			bss->private_key_passwd = os_strdup(pos);
   1371 		} else if (os_strcmp(buf, "check_crl") == 0) {
   1372 			bss->check_crl = atoi(pos);
   1373 		} else if (os_strcmp(buf, "dh_file") == 0) {
   1374 			os_free(bss->dh_file);
   1375 			bss->dh_file = os_strdup(pos);
   1376 		} else if (os_strcmp(buf, "fragment_size") == 0) {
   1377 			bss->fragment_size = atoi(pos);
   1378 #ifdef EAP_SERVER_FAST
   1379 		} else if (os_strcmp(buf, "pac_opaque_encr_key") == 0) {
   1380 			os_free(bss->pac_opaque_encr_key);
   1381 			bss->pac_opaque_encr_key = os_malloc(16);
   1382 			if (bss->pac_opaque_encr_key == NULL) {
   1383 				wpa_printf(MSG_ERROR, "Line %d: No memory for "
   1384 					   "pac_opaque_encr_key", line);
   1385 				errors++;
   1386 			} else if (hexstr2bin(pos, bss->pac_opaque_encr_key,
   1387 					      16)) {
   1388 				wpa_printf(MSG_ERROR, "Line %d: Invalid "
   1389 					   "pac_opaque_encr_key", line);
   1390 				errors++;
   1391 			}
   1392 		} else if (os_strcmp(buf, "eap_fast_a_id") == 0) {
   1393 			size_t idlen = os_strlen(pos);
   1394 			if (idlen & 1) {
   1395 				wpa_printf(MSG_ERROR, "Line %d: Invalid "
   1396 					   "eap_fast_a_id", line);
   1397 				errors++;
   1398 			} else {
   1399 				os_free(bss->eap_fast_a_id);
   1400 				bss->eap_fast_a_id = os_malloc(idlen / 2);
   1401 				if (bss->eap_fast_a_id == NULL ||
   1402 				    hexstr2bin(pos, bss->eap_fast_a_id,
   1403 					       idlen / 2)) {
   1404 					wpa_printf(MSG_ERROR, "Line %d: "
   1405 						   "Failed to parse "
   1406 						   "eap_fast_a_id", line);
   1407 					errors++;
   1408 				} else
   1409 					bss->eap_fast_a_id_len = idlen / 2;
   1410 			}
   1411 		} else if (os_strcmp(buf, "eap_fast_a_id_info") == 0) {
   1412 			os_free(bss->eap_fast_a_id_info);
   1413 			bss->eap_fast_a_id_info = os_strdup(pos);
   1414 		} else if (os_strcmp(buf, "eap_fast_prov") == 0) {
   1415 			bss->eap_fast_prov = atoi(pos);
   1416 		} else if (os_strcmp(buf, "pac_key_lifetime") == 0) {
   1417 			bss->pac_key_lifetime = atoi(pos);
   1418 		} else if (os_strcmp(buf, "pac_key_refresh_time") == 0) {
   1419 			bss->pac_key_refresh_time = atoi(pos);
   1420 #endif /* EAP_SERVER_FAST */
   1421 #ifdef EAP_SERVER_SIM
   1422 		} else if (os_strcmp(buf, "eap_sim_db") == 0) {
   1423 			os_free(bss->eap_sim_db);
   1424 			bss->eap_sim_db = os_strdup(pos);
   1425 		} else if (os_strcmp(buf, "eap_sim_aka_result_ind") == 0) {
   1426 			bss->eap_sim_aka_result_ind = atoi(pos);
   1427 #endif /* EAP_SERVER_SIM */
   1428 #ifdef EAP_SERVER_TNC
   1429 		} else if (os_strcmp(buf, "tnc") == 0) {
   1430 			bss->tnc = atoi(pos);
   1431 #endif /* EAP_SERVER_TNC */
   1432 #ifdef EAP_SERVER_PWD
   1433 		} else if (os_strcmp(buf, "pwd_group") == 0) {
   1434 			bss->pwd_group = atoi(pos);
   1435 #endif /* EAP_SERVER_PWD */
   1436 #endif /* EAP_SERVER */
   1437 		} else if (os_strcmp(buf, "eap_message") == 0) {
   1438 			char *term;
   1439 			bss->eap_req_id_text = os_strdup(pos);
   1440 			if (bss->eap_req_id_text == NULL) {
   1441 				wpa_printf(MSG_ERROR, "Line %d: Failed to "
   1442 					   "allocate memory for "
   1443 					   "eap_req_id_text", line);
   1444 				errors++;
   1445 				continue;
   1446 			}
   1447 			bss->eap_req_id_text_len =
   1448 				os_strlen(bss->eap_req_id_text);
   1449 			term = os_strstr(bss->eap_req_id_text, "\\0");
   1450 			if (term) {
   1451 				*term++ = '\0';
   1452 				os_memmove(term, term + 1,
   1453 					   bss->eap_req_id_text_len -
   1454 					   (term - bss->eap_req_id_text) - 1);
   1455 				bss->eap_req_id_text_len--;
   1456 			}
   1457 		} else if (os_strcmp(buf, "wep_key_len_broadcast") == 0) {
   1458 			bss->default_wep_key_len = atoi(pos);
   1459 			if (bss->default_wep_key_len > 13) {
   1460 				wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
   1461 					   "key len %lu (= %lu bits)", line,
   1462 					   (unsigned long)
   1463 					   bss->default_wep_key_len,
   1464 					   (unsigned long)
   1465 					   bss->default_wep_key_len * 8);
   1466 				errors++;
   1467 			}
   1468 		} else if (os_strcmp(buf, "wep_key_len_unicast") == 0) {
   1469 			bss->individual_wep_key_len = atoi(pos);
   1470 			if (bss->individual_wep_key_len < 0 ||
   1471 			    bss->individual_wep_key_len > 13) {
   1472 				wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
   1473 					   "key len %d (= %d bits)", line,
   1474 					   bss->individual_wep_key_len,
   1475 					   bss->individual_wep_key_len * 8);
   1476 				errors++;
   1477 			}
   1478 		} else if (os_strcmp(buf, "wep_rekey_period") == 0) {
   1479 			bss->wep_rekeying_period = atoi(pos);
   1480 			if (bss->wep_rekeying_period < 0) {
   1481 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1482 					   "period %d",
   1483 					   line, bss->wep_rekeying_period);
   1484 				errors++;
   1485 			}
   1486 		} else if (os_strcmp(buf, "eap_reauth_period") == 0) {
   1487 			bss->eap_reauth_period = atoi(pos);
   1488 			if (bss->eap_reauth_period < 0) {
   1489 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1490 					   "period %d",
   1491 					   line, bss->eap_reauth_period);
   1492 				errors++;
   1493 			}
   1494 		} else if (os_strcmp(buf, "eapol_key_index_workaround") == 0) {
   1495 			bss->eapol_key_index_workaround = atoi(pos);
   1496 #ifdef CONFIG_IAPP
   1497 		} else if (os_strcmp(buf, "iapp_interface") == 0) {
   1498 			bss->ieee802_11f = 1;
   1499 			os_strlcpy(bss->iapp_iface, pos,
   1500 				   sizeof(bss->iapp_iface));
   1501 #endif /* CONFIG_IAPP */
   1502 		} else if (os_strcmp(buf, "own_ip_addr") == 0) {
   1503 			if (hostapd_parse_ip_addr(pos, &bss->own_ip_addr)) {
   1504 				wpa_printf(MSG_ERROR, "Line %d: invalid IP "
   1505 					   "address '%s'", line, pos);
   1506 				errors++;
   1507 			}
   1508 		} else if (os_strcmp(buf, "nas_identifier") == 0) {
   1509 			bss->nas_identifier = os_strdup(pos);
   1510 #ifndef CONFIG_NO_RADIUS
   1511 		} else if (os_strcmp(buf, "auth_server_addr") == 0) {
   1512 			if (hostapd_config_read_radius_addr(
   1513 				    &bss->radius->auth_servers,
   1514 				    &bss->radius->num_auth_servers, pos, 1812,
   1515 				    &bss->radius->auth_server)) {
   1516 				wpa_printf(MSG_ERROR, "Line %d: invalid IP "
   1517 					   "address '%s'", line, pos);
   1518 				errors++;
   1519 			}
   1520 		} else if (bss->radius->auth_server &&
   1521 			   os_strcmp(buf, "auth_server_port") == 0) {
   1522 			bss->radius->auth_server->port = atoi(pos);
   1523 		} else if (bss->radius->auth_server &&
   1524 			   os_strcmp(buf, "auth_server_shared_secret") == 0) {
   1525 			int len = os_strlen(pos);
   1526 			if (len == 0) {
   1527 				/* RFC 2865, Ch. 3 */
   1528 				wpa_printf(MSG_ERROR, "Line %d: empty shared "
   1529 					   "secret is not allowed.", line);
   1530 				errors++;
   1531 			}
   1532 			bss->radius->auth_server->shared_secret =
   1533 				(u8 *) os_strdup(pos);
   1534 			bss->radius->auth_server->shared_secret_len = len;
   1535 		} else if (os_strcmp(buf, "acct_server_addr") == 0) {
   1536 			if (hostapd_config_read_radius_addr(
   1537 				    &bss->radius->acct_servers,
   1538 				    &bss->radius->num_acct_servers, pos, 1813,
   1539 				    &bss->radius->acct_server)) {
   1540 				wpa_printf(MSG_ERROR, "Line %d: invalid IP "
   1541 					   "address '%s'", line, pos);
   1542 				errors++;
   1543 			}
   1544 		} else if (bss->radius->acct_server &&
   1545 			   os_strcmp(buf, "acct_server_port") == 0) {
   1546 			bss->radius->acct_server->port = atoi(pos);
   1547 		} else if (bss->radius->acct_server &&
   1548 			   os_strcmp(buf, "acct_server_shared_secret") == 0) {
   1549 			int len = os_strlen(pos);
   1550 			if (len == 0) {
   1551 				/* RFC 2865, Ch. 3 */
   1552 				wpa_printf(MSG_ERROR, "Line %d: empty shared "
   1553 					   "secret is not allowed.", line);
   1554 				errors++;
   1555 			}
   1556 			bss->radius->acct_server->shared_secret =
   1557 				(u8 *) os_strdup(pos);
   1558 			bss->radius->acct_server->shared_secret_len = len;
   1559 		} else if (os_strcmp(buf, "radius_retry_primary_interval") ==
   1560 			   0) {
   1561 			bss->radius->retry_primary_interval = atoi(pos);
   1562 		} else if (os_strcmp(buf, "radius_acct_interim_interval") == 0)
   1563 		{
   1564 			bss->acct_interim_interval = atoi(pos);
   1565 #endif /* CONFIG_NO_RADIUS */
   1566 		} else if (os_strcmp(buf, "auth_algs") == 0) {
   1567 			bss->auth_algs = atoi(pos);
   1568 			if (bss->auth_algs == 0) {
   1569 				wpa_printf(MSG_ERROR, "Line %d: no "
   1570 					   "authentication algorithms allowed",
   1571 					   line);
   1572 				errors++;
   1573 			}
   1574 		} else if (os_strcmp(buf, "max_num_sta") == 0) {
   1575 			bss->max_num_sta = atoi(pos);
   1576 			if (bss->max_num_sta < 0 ||
   1577 			    bss->max_num_sta > MAX_STA_COUNT) {
   1578 				wpa_printf(MSG_ERROR, "Line %d: Invalid "
   1579 					   "max_num_sta=%d; allowed range "
   1580 					   "0..%d", line, bss->max_num_sta,
   1581 					   MAX_STA_COUNT);
   1582 				errors++;
   1583 			}
   1584 		} else if (os_strcmp(buf, "wpa") == 0) {
   1585 			bss->wpa = atoi(pos);
   1586 		} else if (os_strcmp(buf, "wpa_group_rekey") == 0) {
   1587 			bss->wpa_group_rekey = atoi(pos);
   1588 		} else if (os_strcmp(buf, "wpa_strict_rekey") == 0) {
   1589 			bss->wpa_strict_rekey = atoi(pos);
   1590 		} else if (os_strcmp(buf, "wpa_gmk_rekey") == 0) {
   1591 			bss->wpa_gmk_rekey = atoi(pos);
   1592 		} else if (os_strcmp(buf, "wpa_ptk_rekey") == 0) {
   1593 			bss->wpa_ptk_rekey = atoi(pos);
   1594 		} else if (os_strcmp(buf, "wpa_passphrase") == 0) {
   1595 			int len = os_strlen(pos);
   1596 			if (len < 8 || len > 63) {
   1597 				wpa_printf(MSG_ERROR, "Line %d: invalid WPA "
   1598 					   "passphrase length %d (expected "
   1599 					   "8..63)", line, len);
   1600 				errors++;
   1601 			} else {
   1602 				os_free(bss->ssid.wpa_passphrase);
   1603 				bss->ssid.wpa_passphrase = os_strdup(pos);
   1604 			}
   1605 		} else if (os_strcmp(buf, "wpa_psk") == 0) {
   1606 			os_free(bss->ssid.wpa_psk);
   1607 			bss->ssid.wpa_psk =
   1608 				os_zalloc(sizeof(struct hostapd_wpa_psk));
   1609 			if (bss->ssid.wpa_psk == NULL)
   1610 				errors++;
   1611 			else if (hexstr2bin(pos, bss->ssid.wpa_psk->psk,
   1612 					    PMK_LEN) ||
   1613 				 pos[PMK_LEN * 2] != '\0') {
   1614 				wpa_printf(MSG_ERROR, "Line %d: Invalid PSK "
   1615 					   "'%s'.", line, pos);
   1616 				errors++;
   1617 			} else {
   1618 				bss->ssid.wpa_psk->group = 1;
   1619 			}
   1620 		} else if (os_strcmp(buf, "wpa_psk_file") == 0) {
   1621 			os_free(bss->ssid.wpa_psk_file);
   1622 			bss->ssid.wpa_psk_file = os_strdup(pos);
   1623 			if (!bss->ssid.wpa_psk_file) {
   1624 				wpa_printf(MSG_ERROR, "Line %d: allocation "
   1625 					   "failed", line);
   1626 				errors++;
   1627 			}
   1628 		} else if (os_strcmp(buf, "wpa_key_mgmt") == 0) {
   1629 			bss->wpa_key_mgmt =
   1630 				hostapd_config_parse_key_mgmt(line, pos);
   1631 			if (bss->wpa_key_mgmt == -1)
   1632 				errors++;
   1633 		} else if (os_strcmp(buf, "wpa_pairwise") == 0) {
   1634 			bss->wpa_pairwise =
   1635 				hostapd_config_parse_cipher(line, pos);
   1636 			if (bss->wpa_pairwise == -1 ||
   1637 			    bss->wpa_pairwise == 0)
   1638 				errors++;
   1639 			else if (bss->wpa_pairwise &
   1640 				 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
   1641 				  WPA_CIPHER_WEP104)) {
   1642 				wpa_printf(MSG_ERROR, "Line %d: unsupported "
   1643 					   "pairwise cipher suite '%s'",
   1644 					   bss->wpa_pairwise, pos);
   1645 				errors++;
   1646 			}
   1647 		} else if (os_strcmp(buf, "rsn_pairwise") == 0) {
   1648 			bss->rsn_pairwise =
   1649 				hostapd_config_parse_cipher(line, pos);
   1650 			if (bss->rsn_pairwise == -1 ||
   1651 			    bss->rsn_pairwise == 0)
   1652 				errors++;
   1653 			else if (bss->rsn_pairwise &
   1654 				 (WPA_CIPHER_NONE | WPA_CIPHER_WEP40 |
   1655 				  WPA_CIPHER_WEP104)) {
   1656 				wpa_printf(MSG_ERROR, "Line %d: unsupported "
   1657 					   "pairwise cipher suite '%s'",
   1658 					   bss->rsn_pairwise, pos);
   1659 				errors++;
   1660 			}
   1661 #ifdef CONFIG_RSN_PREAUTH
   1662 		} else if (os_strcmp(buf, "rsn_preauth") == 0) {
   1663 			bss->rsn_preauth = atoi(pos);
   1664 		} else if (os_strcmp(buf, "rsn_preauth_interfaces") == 0) {
   1665 			bss->rsn_preauth_interfaces = os_strdup(pos);
   1666 #endif /* CONFIG_RSN_PREAUTH */
   1667 #ifdef CONFIG_PEERKEY
   1668 		} else if (os_strcmp(buf, "peerkey") == 0) {
   1669 			bss->peerkey = atoi(pos);
   1670 #endif /* CONFIG_PEERKEY */
   1671 #ifdef CONFIG_IEEE80211R
   1672 		} else if (os_strcmp(buf, "mobility_domain") == 0) {
   1673 			if (os_strlen(pos) != 2 * MOBILITY_DOMAIN_ID_LEN ||
   1674 			    hexstr2bin(pos, bss->mobility_domain,
   1675 				       MOBILITY_DOMAIN_ID_LEN) != 0) {
   1676 				wpa_printf(MSG_DEBUG, "Line %d: Invalid "
   1677 					   "mobility_domain '%s'", line, pos);
   1678 				errors++;
   1679 				continue;
   1680 			}
   1681 		} else if (os_strcmp(buf, "r1_key_holder") == 0) {
   1682 			if (os_strlen(pos) != 2 * FT_R1KH_ID_LEN ||
   1683 			    hexstr2bin(pos, bss->r1_key_holder,
   1684 				       FT_R1KH_ID_LEN) != 0) {
   1685 				wpa_printf(MSG_DEBUG, "Line %d: Invalid "
   1686 					   "r1_key_holder '%s'", line, pos);
   1687 				errors++;
   1688 				continue;
   1689 			}
   1690 		} else if (os_strcmp(buf, "r0_key_lifetime") == 0) {
   1691 			bss->r0_key_lifetime = atoi(pos);
   1692 		} else if (os_strcmp(buf, "reassociation_deadline") == 0) {
   1693 			bss->reassociation_deadline = atoi(pos);
   1694 		} else if (os_strcmp(buf, "r0kh") == 0) {
   1695 			if (add_r0kh(bss, pos) < 0) {
   1696 				wpa_printf(MSG_DEBUG, "Line %d: Invalid "
   1697 					   "r0kh '%s'", line, pos);
   1698 				errors++;
   1699 				continue;
   1700 			}
   1701 		} else if (os_strcmp(buf, "r1kh") == 0) {
   1702 			if (add_r1kh(bss, pos) < 0) {
   1703 				wpa_printf(MSG_DEBUG, "Line %d: Invalid "
   1704 					   "r1kh '%s'", line, pos);
   1705 				errors++;
   1706 				continue;
   1707 			}
   1708 		} else if (os_strcmp(buf, "pmk_r1_push") == 0) {
   1709 			bss->pmk_r1_push = atoi(pos);
   1710 		} else if (os_strcmp(buf, "ft_over_ds") == 0) {
   1711 			bss->ft_over_ds = atoi(pos);
   1712 #endif /* CONFIG_IEEE80211R */
   1713 #ifndef CONFIG_NO_CTRL_IFACE
   1714 		} else if (os_strcmp(buf, "ctrl_interface") == 0) {
   1715 			os_free(bss->ctrl_interface);
   1716 			bss->ctrl_interface = os_strdup(pos);
   1717 		} else if (os_strcmp(buf, "ctrl_interface_group") == 0) {
   1718 #ifndef CONFIG_NATIVE_WINDOWS
   1719 			struct group *grp;
   1720 			char *endp;
   1721 			const char *group = pos;
   1722 
   1723 			grp = getgrnam(group);
   1724 			if (grp) {
   1725 				bss->ctrl_interface_gid = grp->gr_gid;
   1726 				bss->ctrl_interface_gid_set = 1;
   1727 				wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d"
   1728 					   " (from group name '%s')",
   1729 					   bss->ctrl_interface_gid, group);
   1730 				continue;
   1731 			}
   1732 
   1733 			/* Group name not found - try to parse this as gid */
   1734 			bss->ctrl_interface_gid = strtol(group, &endp, 10);
   1735 			if (*group == '\0' || *endp != '\0') {
   1736 				wpa_printf(MSG_DEBUG, "Line %d: Invalid group "
   1737 					   "'%s'", line, group);
   1738 				errors++;
   1739 				continue;
   1740 			}
   1741 			bss->ctrl_interface_gid_set = 1;
   1742 			wpa_printf(MSG_DEBUG, "ctrl_interface_group=%d",
   1743 				   bss->ctrl_interface_gid);
   1744 #endif /* CONFIG_NATIVE_WINDOWS */
   1745 #endif /* CONFIG_NO_CTRL_IFACE */
   1746 #ifdef RADIUS_SERVER
   1747 		} else if (os_strcmp(buf, "radius_server_clients") == 0) {
   1748 			os_free(bss->radius_server_clients);
   1749 			bss->radius_server_clients = os_strdup(pos);
   1750 		} else if (os_strcmp(buf, "radius_server_auth_port") == 0) {
   1751 			bss->radius_server_auth_port = atoi(pos);
   1752 		} else if (os_strcmp(buf, "radius_server_ipv6") == 0) {
   1753 			bss->radius_server_ipv6 = atoi(pos);
   1754 #endif /* RADIUS_SERVER */
   1755 		} else if (os_strcmp(buf, "test_socket") == 0) {
   1756 			os_free(bss->test_socket);
   1757 			bss->test_socket = os_strdup(pos);
   1758 		} else if (os_strcmp(buf, "use_pae_group_addr") == 0) {
   1759 			bss->use_pae_group_addr = atoi(pos);
   1760 		} else if (os_strcmp(buf, "hw_mode") == 0) {
   1761 			if (os_strcmp(pos, "a") == 0)
   1762 				conf->hw_mode = HOSTAPD_MODE_IEEE80211A;
   1763 			else if (os_strcmp(pos, "b") == 0)
   1764 				conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
   1765 			else if (os_strcmp(pos, "g") == 0)
   1766 				conf->hw_mode = HOSTAPD_MODE_IEEE80211G;
   1767 			else {
   1768 				wpa_printf(MSG_ERROR, "Line %d: unknown "
   1769 					   "hw_mode '%s'", line, pos);
   1770 				errors++;
   1771 			}
   1772 		} else if (os_strcmp(buf, "channel") == 0) {
   1773 			conf->channel = atoi(pos);
   1774 		} else if (os_strcmp(buf, "beacon_int") == 0) {
   1775 			int val = atoi(pos);
   1776 			/* MIB defines range as 1..65535, but very small values
   1777 			 * cause problems with the current implementation.
   1778 			 * Since it is unlikely that this small numbers are
   1779 			 * useful in real life scenarios, do not allow beacon
   1780 			 * period to be set below 15 TU. */
   1781 			if (val < 15 || val > 65535) {
   1782 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1783 					   "beacon_int %d (expected "
   1784 					   "15..65535)", line, val);
   1785 				errors++;
   1786 			} else
   1787 				conf->beacon_int = val;
   1788 		} else if (os_strcmp(buf, "dtim_period") == 0) {
   1789 			bss->dtim_period = atoi(pos);
   1790 			if (bss->dtim_period < 1 || bss->dtim_period > 255) {
   1791 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1792 					   "dtim_period %d",
   1793 					   line, bss->dtim_period);
   1794 				errors++;
   1795 			}
   1796 		} else if (os_strcmp(buf, "rts_threshold") == 0) {
   1797 			conf->rts_threshold = atoi(pos);
   1798 			if (conf->rts_threshold < 0 ||
   1799 			    conf->rts_threshold > 2347) {
   1800 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1801 					   "rts_threshold %d",
   1802 					   line, conf->rts_threshold);
   1803 				errors++;
   1804 			}
   1805 		} else if (os_strcmp(buf, "fragm_threshold") == 0) {
   1806 			conf->fragm_threshold = atoi(pos);
   1807 			if (conf->fragm_threshold < 256 ||
   1808 			    conf->fragm_threshold > 2346) {
   1809 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1810 					   "fragm_threshold %d",
   1811 					   line, conf->fragm_threshold);
   1812 				errors++;
   1813 			}
   1814 		} else if (os_strcmp(buf, "send_probe_response") == 0) {
   1815 			int val = atoi(pos);
   1816 			if (val != 0 && val != 1) {
   1817 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1818 					   "send_probe_response %d (expected "
   1819 					   "0 or 1)", line, val);
   1820 			} else
   1821 				conf->send_probe_response = val;
   1822 		} else if (os_strcmp(buf, "supported_rates") == 0) {
   1823 			if (hostapd_parse_rates(&conf->supported_rates, pos)) {
   1824 				wpa_printf(MSG_ERROR, "Line %d: invalid rate "
   1825 					   "list", line);
   1826 				errors++;
   1827 			}
   1828 		} else if (os_strcmp(buf, "basic_rates") == 0) {
   1829 			if (hostapd_parse_rates(&conf->basic_rates, pos)) {
   1830 				wpa_printf(MSG_ERROR, "Line %d: invalid rate "
   1831 					   "list", line);
   1832 				errors++;
   1833 			}
   1834 		} else if (os_strcmp(buf, "preamble") == 0) {
   1835 			if (atoi(pos))
   1836 				conf->preamble = SHORT_PREAMBLE;
   1837 			else
   1838 				conf->preamble = LONG_PREAMBLE;
   1839 		} else if (os_strcmp(buf, "ignore_broadcast_ssid") == 0) {
   1840 			bss->ignore_broadcast_ssid = atoi(pos);
   1841 		} else if (os_strcmp(buf, "wep_default_key") == 0) {
   1842 			bss->ssid.wep.idx = atoi(pos);
   1843 			if (bss->ssid.wep.idx > 3) {
   1844 				wpa_printf(MSG_ERROR, "Invalid "
   1845 					   "wep_default_key index %d",
   1846 					   bss->ssid.wep.idx);
   1847 				errors++;
   1848 			}
   1849 		} else if (os_strcmp(buf, "wep_key0") == 0 ||
   1850 			   os_strcmp(buf, "wep_key1") == 0 ||
   1851 			   os_strcmp(buf, "wep_key2") == 0 ||
   1852 			   os_strcmp(buf, "wep_key3") == 0) {
   1853 			if (hostapd_config_read_wep(&bss->ssid.wep,
   1854 						    buf[7] - '0', pos)) {
   1855 				wpa_printf(MSG_ERROR, "Line %d: invalid WEP "
   1856 					   "key '%s'", line, buf);
   1857 				errors++;
   1858 			}
   1859 #ifndef CONFIG_NO_VLAN
   1860 		} else if (os_strcmp(buf, "dynamic_vlan") == 0) {
   1861 			bss->ssid.dynamic_vlan = atoi(pos);
   1862 		} else if (os_strcmp(buf, "vlan_file") == 0) {
   1863 			if (hostapd_config_read_vlan_file(bss, pos)) {
   1864 				wpa_printf(MSG_ERROR, "Line %d: failed to "
   1865 					   "read VLAN file '%s'", line, pos);
   1866 				errors++;
   1867 			}
   1868 #ifdef CONFIG_FULL_DYNAMIC_VLAN
   1869 		} else if (os_strcmp(buf, "vlan_tagged_interface") == 0) {
   1870 			bss->ssid.vlan_tagged_interface = os_strdup(pos);
   1871 #endif /* CONFIG_FULL_DYNAMIC_VLAN */
   1872 #endif /* CONFIG_NO_VLAN */
   1873 		} else if (os_strcmp(buf, "ap_table_max_size") == 0) {
   1874 			conf->ap_table_max_size = atoi(pos);
   1875 		} else if (os_strcmp(buf, "ap_table_expiration_time") == 0) {
   1876 			conf->ap_table_expiration_time = atoi(pos);
   1877 		} else if (os_strncmp(buf, "tx_queue_", 9) == 0) {
   1878 			if (hostapd_config_tx_queue(conf, buf, pos)) {
   1879 				wpa_printf(MSG_ERROR, "Line %d: invalid TX "
   1880 					   "queue item", line);
   1881 				errors++;
   1882 			}
   1883 		} else if (os_strcmp(buf, "wme_enabled") == 0 ||
   1884 			   os_strcmp(buf, "wmm_enabled") == 0) {
   1885 			bss->wmm_enabled = atoi(pos);
   1886 		} else if (os_strcmp(buf, "uapsd_advertisement_enabled") == 0) {
   1887 			bss->wmm_uapsd = atoi(pos);
   1888 		} else if (os_strncmp(buf, "wme_ac_", 7) == 0 ||
   1889 			   os_strncmp(buf, "wmm_ac_", 7) == 0) {
   1890 			if (hostapd_config_wmm_ac(conf, buf, pos)) {
   1891 				wpa_printf(MSG_ERROR, "Line %d: invalid WMM "
   1892 					   "ac item", line);
   1893 				errors++;
   1894 			}
   1895 		} else if (os_strcmp(buf, "bss") == 0) {
   1896 			if (hostapd_config_bss(conf, pos)) {
   1897 				wpa_printf(MSG_ERROR, "Line %d: invalid bss "
   1898 					   "item", line);
   1899 				errors++;
   1900 			}
   1901 		} else if (os_strcmp(buf, "bssid") == 0) {
   1902 			if (hwaddr_aton(pos, bss->bssid)) {
   1903 				wpa_printf(MSG_ERROR, "Line %d: invalid bssid "
   1904 					   "item", line);
   1905 				errors++;
   1906 			}
   1907 #ifdef CONFIG_IEEE80211W
   1908 		} else if (os_strcmp(buf, "ieee80211w") == 0) {
   1909 			bss->ieee80211w = atoi(pos);
   1910 		} else if (os_strcmp(buf, "assoc_sa_query_max_timeout") == 0) {
   1911 			bss->assoc_sa_query_max_timeout = atoi(pos);
   1912 			if (bss->assoc_sa_query_max_timeout == 0) {
   1913 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1914 					   "assoc_sa_query_max_timeout", line);
   1915 				errors++;
   1916 			}
   1917 		} else if (os_strcmp(buf, "assoc_sa_query_retry_timeout") == 0)
   1918 		{
   1919 			bss->assoc_sa_query_retry_timeout = atoi(pos);
   1920 			if (bss->assoc_sa_query_retry_timeout == 0) {
   1921 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1922 					   "assoc_sa_query_retry_timeout",
   1923 					   line);
   1924 				errors++;
   1925 			}
   1926 #endif /* CONFIG_IEEE80211W */
   1927 #ifdef CONFIG_IEEE80211N
   1928 		} else if (os_strcmp(buf, "ieee80211n") == 0) {
   1929 			conf->ieee80211n = atoi(pos);
   1930 		} else if (os_strcmp(buf, "ht_capab") == 0) {
   1931 			if (hostapd_config_ht_capab(conf, pos) < 0) {
   1932 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1933 					   "ht_capab", line);
   1934 				errors++;
   1935 			}
   1936 		} else if (os_strcmp(buf, "require_ht") == 0) {
   1937 			conf->require_ht = atoi(pos);
   1938 #endif /* CONFIG_IEEE80211N */
   1939 		} else if (os_strcmp(buf, "max_listen_interval") == 0) {
   1940 			bss->max_listen_interval = atoi(pos);
   1941 		} else if (os_strcmp(buf, "disable_pmksa_caching") == 0) {
   1942 			bss->disable_pmksa_caching = atoi(pos);
   1943 		} else if (os_strcmp(buf, "okc") == 0) {
   1944 			bss->okc = atoi(pos);
   1945 #ifdef CONFIG_WPS
   1946 		} else if (os_strcmp(buf, "wps_state") == 0) {
   1947 			bss->wps_state = atoi(pos);
   1948 			if (bss->wps_state < 0 || bss->wps_state > 2) {
   1949 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   1950 					   "wps_state", line);
   1951 				errors++;
   1952 			}
   1953 		} else if (os_strcmp(buf, "ap_setup_locked") == 0) {
   1954 			bss->ap_setup_locked = atoi(pos);
   1955 		} else if (os_strcmp(buf, "uuid") == 0) {
   1956 			if (uuid_str2bin(pos, bss->uuid)) {
   1957 				wpa_printf(MSG_ERROR, "Line %d: invalid UUID",
   1958 					   line);
   1959 				errors++;
   1960 			}
   1961 		} else if (os_strcmp(buf, "wps_pin_requests") == 0) {
   1962 			os_free(bss->wps_pin_requests);
   1963 			bss->wps_pin_requests = os_strdup(pos);
   1964 		} else if (os_strcmp(buf, "device_name") == 0) {
   1965 			if (os_strlen(pos) > 32) {
   1966 				wpa_printf(MSG_ERROR, "Line %d: Too long "
   1967 					   "device_name", line);
   1968 				errors++;
   1969 			}
   1970 			os_free(bss->device_name);
   1971 			bss->device_name = os_strdup(pos);
   1972 		} else if (os_strcmp(buf, "manufacturer") == 0) {
   1973 			if (os_strlen(pos) > 64) {
   1974 				wpa_printf(MSG_ERROR, "Line %d: Too long "
   1975 					   "manufacturer", line);
   1976 				errors++;
   1977 			}
   1978 			os_free(bss->manufacturer);
   1979 			bss->manufacturer = os_strdup(pos);
   1980 		} else if (os_strcmp(buf, "model_name") == 0) {
   1981 			if (os_strlen(pos) > 32) {
   1982 				wpa_printf(MSG_ERROR, "Line %d: Too long "
   1983 					   "model_name", line);
   1984 				errors++;
   1985 			}
   1986 			os_free(bss->model_name);
   1987 			bss->model_name = os_strdup(pos);
   1988 		} else if (os_strcmp(buf, "model_number") == 0) {
   1989 			if (os_strlen(pos) > 32) {
   1990 				wpa_printf(MSG_ERROR, "Line %d: Too long "
   1991 					   "model_number", line);
   1992 				errors++;
   1993 			}
   1994 			os_free(bss->model_number);
   1995 			bss->model_number = os_strdup(pos);
   1996 		} else if (os_strcmp(buf, "serial_number") == 0) {
   1997 			if (os_strlen(pos) > 32) {
   1998 				wpa_printf(MSG_ERROR, "Line %d: Too long "
   1999 					   "serial_number", line);
   2000 				errors++;
   2001 			}
   2002 			os_free(bss->serial_number);
   2003 			bss->serial_number = os_strdup(pos);
   2004 		} else if (os_strcmp(buf, "device_type") == 0) {
   2005 			if (wps_dev_type_str2bin(pos, bss->device_type))
   2006 				errors++;
   2007 		} else if (os_strcmp(buf, "config_methods") == 0) {
   2008 			os_free(bss->config_methods);
   2009 			bss->config_methods = os_strdup(pos);
   2010 		} else if (os_strcmp(buf, "os_version") == 0) {
   2011 			if (hexstr2bin(pos, bss->os_version, 4)) {
   2012 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   2013 					   "os_version", line);
   2014 				errors++;
   2015 			}
   2016 		} else if (os_strcmp(buf, "ap_pin") == 0) {
   2017 			os_free(bss->ap_pin);
   2018 			bss->ap_pin = os_strdup(pos);
   2019 		} else if (os_strcmp(buf, "skip_cred_build") == 0) {
   2020 			bss->skip_cred_build = atoi(pos);
   2021 		} else if (os_strcmp(buf, "extra_cred") == 0) {
   2022 			os_free(bss->extra_cred);
   2023 			bss->extra_cred =
   2024 				(u8 *) os_readfile(pos, &bss->extra_cred_len);
   2025 			if (bss->extra_cred == NULL) {
   2026 				wpa_printf(MSG_ERROR, "Line %d: could not "
   2027 					   "read Credentials from '%s'",
   2028 					   line, pos);
   2029 				errors++;
   2030 			}
   2031 		} else if (os_strcmp(buf, "wps_cred_processing") == 0) {
   2032 			bss->wps_cred_processing = atoi(pos);
   2033 		} else if (os_strcmp(buf, "ap_settings") == 0) {
   2034 			os_free(bss->ap_settings);
   2035 			bss->ap_settings =
   2036 				(u8 *) os_readfile(pos, &bss->ap_settings_len);
   2037 			if (bss->ap_settings == NULL) {
   2038 				wpa_printf(MSG_ERROR, "Line %d: could not "
   2039 					   "read AP Settings from '%s'",
   2040 					   line, pos);
   2041 				errors++;
   2042 			}
   2043 		} else if (os_strcmp(buf, "upnp_iface") == 0) {
   2044 			bss->upnp_iface = os_strdup(pos);
   2045 		} else if (os_strcmp(buf, "friendly_name") == 0) {
   2046 			os_free(bss->friendly_name);
   2047 			bss->friendly_name = os_strdup(pos);
   2048 		} else if (os_strcmp(buf, "manufacturer_url") == 0) {
   2049 			os_free(bss->manufacturer_url);
   2050 			bss->manufacturer_url = os_strdup(pos);
   2051 		} else if (os_strcmp(buf, "model_description") == 0) {
   2052 			os_free(bss->model_description);
   2053 			bss->model_description = os_strdup(pos);
   2054 		} else if (os_strcmp(buf, "model_url") == 0) {
   2055 			os_free(bss->model_url);
   2056 			bss->model_url = os_strdup(pos);
   2057 		} else if (os_strcmp(buf, "upc") == 0) {
   2058 			os_free(bss->upc);
   2059 			bss->upc = os_strdup(pos);
   2060 		} else if (os_strcmp(buf, "pbc_in_m1") == 0) {
   2061 			bss->pbc_in_m1 = atoi(pos);
   2062 #endif /* CONFIG_WPS */
   2063 #ifdef CONFIG_P2P_MANAGER
   2064 		} else if (os_strcmp(buf, "manage_p2p") == 0) {
   2065 			int manage = atoi(pos);
   2066 			if (manage)
   2067 				bss->p2p |= P2P_MANAGE;
   2068 			else
   2069 				bss->p2p &= ~P2P_MANAGE;
   2070 		} else if (os_strcmp(buf, "allow_cross_connection") == 0) {
   2071 			if (atoi(pos))
   2072 				bss->p2p |= P2P_ALLOW_CROSS_CONNECTION;
   2073 			else
   2074 				bss->p2p &= ~P2P_ALLOW_CROSS_CONNECTION;
   2075 #endif /* CONFIG_P2P_MANAGER */
   2076 		} else if (os_strcmp(buf, "disassoc_low_ack") == 0) {
   2077 			bss->disassoc_low_ack = atoi(pos);
   2078 		} else if (os_strcmp(buf, "tdls_prohibit") == 0) {
   2079 			int val = atoi(pos);
   2080 			if (val)
   2081 				bss->tdls |= TDLS_PROHIBIT;
   2082 			else
   2083 				bss->tdls &= ~TDLS_PROHIBIT;
   2084 		} else if (os_strcmp(buf, "tdls_prohibit_chan_switch") == 0) {
   2085 			int val = atoi(pos);
   2086 			if (val)
   2087 				bss->tdls |= TDLS_PROHIBIT_CHAN_SWITCH;
   2088 			else
   2089 				bss->tdls &= ~TDLS_PROHIBIT_CHAN_SWITCH;
   2090 #ifdef CONFIG_RSN_TESTING
   2091 		} else if (os_strcmp(buf, "rsn_testing") == 0) {
   2092 			extern int rsn_testing;
   2093 			rsn_testing = atoi(pos);
   2094 #endif /* CONFIG_RSN_TESTING */
   2095 		} else if (os_strcmp(buf, "time_advertisement") == 0) {
   2096 			bss->time_advertisement = atoi(pos);
   2097 		} else if (os_strcmp(buf, "time_zone") == 0) {
   2098 			size_t tz_len = os_strlen(pos);
   2099 			if (tz_len < 4 || tz_len > 255) {
   2100 				wpa_printf(MSG_DEBUG, "Line %d: invalid "
   2101 					   "time_zone", line);
   2102 				errors++;
   2103 				continue;
   2104 			}
   2105 			os_free(bss->time_zone);
   2106 			bss->time_zone = os_strdup(pos);
   2107 			if (bss->time_zone == NULL)
   2108 				errors++;
   2109 #ifdef CONFIG_INTERWORKING
   2110 		} else if (os_strcmp(buf, "interworking") == 0) {
   2111 			bss->interworking = atoi(pos);
   2112 		} else if (os_strcmp(buf, "access_network_type") == 0) {
   2113 			bss->access_network_type = atoi(pos);
   2114 			if (bss->access_network_type < 0 ||
   2115 			    bss->access_network_type > 15) {
   2116 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   2117 					   "access_network_type", line);
   2118 				errors++;
   2119 			}
   2120 		} else if (os_strcmp(buf, "internet") == 0) {
   2121 			bss->internet = atoi(pos);
   2122 		} else if (os_strcmp(buf, "asra") == 0) {
   2123 			bss->asra = atoi(pos);
   2124 		} else if (os_strcmp(buf, "esr") == 0) {
   2125 			bss->esr = atoi(pos);
   2126 		} else if (os_strcmp(buf, "uesa") == 0) {
   2127 			bss->uesa = atoi(pos);
   2128 		} else if (os_strcmp(buf, "venue_group") == 0) {
   2129 			bss->venue_group = atoi(pos);
   2130 			bss->venue_info_set = 1;
   2131 		} else if (os_strcmp(buf, "venue_type") == 0) {
   2132 			bss->venue_type = atoi(pos);
   2133 			bss->venue_info_set = 1;
   2134 		} else if (os_strcmp(buf, "hessid") == 0) {
   2135 			if (hwaddr_aton(pos, bss->hessid)) {
   2136 				wpa_printf(MSG_ERROR, "Line %d: invalid "
   2137 					   "hessid", line);
   2138 				errors++;
   2139 			}
   2140 		} else if (os_strcmp(buf, "roaming_consortium") == 0) {
   2141 			if (parse_roaming_consortium(bss, pos, line) < 0)
   2142 				errors++;
   2143 #endif /* CONFIG_INTERWORKING */
   2144 		} else {
   2145 			wpa_printf(MSG_ERROR, "Line %d: unknown configuration "
   2146 				   "item '%s'", line, buf);
   2147 			errors++;
   2148 		}
   2149 	}
   2150 
   2151 	fclose(f);
   2152 
   2153 	for (i = 0; i < conf->num_bss; i++) {
   2154 		bss = &conf->bss[i];
   2155 
   2156 		if (bss->individual_wep_key_len == 0) {
   2157 			/* individual keys are not use; can use key idx0 for
   2158 			 * broadcast keys */
   2159 			bss->broadcast_key_idx_min = 0;
   2160 		}
   2161 
   2162 		/* Select group cipher based on the enabled pairwise cipher
   2163 		 * suites */
   2164 		pairwise = 0;
   2165 		if (bss->wpa & 1)
   2166 			pairwise |= bss->wpa_pairwise;
   2167 		if (bss->wpa & 2) {
   2168 			if (bss->rsn_pairwise == 0)
   2169 				bss->rsn_pairwise = bss->wpa_pairwise;
   2170 			pairwise |= bss->rsn_pairwise;
   2171 		}
   2172 		if (pairwise & WPA_CIPHER_TKIP)
   2173 			bss->wpa_group = WPA_CIPHER_TKIP;
   2174 		else
   2175 			bss->wpa_group = WPA_CIPHER_CCMP;
   2176 
   2177 		bss->radius->auth_server = bss->radius->auth_servers;
   2178 		bss->radius->acct_server = bss->radius->acct_servers;
   2179 
   2180 		if (bss->wpa && bss->ieee802_1x) {
   2181 			bss->ssid.security_policy = SECURITY_WPA;
   2182 		} else if (bss->wpa) {
   2183 			bss->ssid.security_policy = SECURITY_WPA_PSK;
   2184 		} else if (bss->ieee802_1x) {
   2185 			int cipher = WPA_CIPHER_NONE;
   2186 			bss->ssid.security_policy = SECURITY_IEEE_802_1X;
   2187 			bss->ssid.wep.default_len = bss->default_wep_key_len;
   2188 			if (bss->default_wep_key_len)
   2189 				cipher = bss->default_wep_key_len >= 13 ?
   2190 					WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
   2191 			bss->wpa_group = cipher;
   2192 			bss->wpa_pairwise = cipher;
   2193 			bss->rsn_pairwise = cipher;
   2194 		} else if (bss->ssid.wep.keys_set) {
   2195 			int cipher = WPA_CIPHER_WEP40;
   2196 			if (bss->ssid.wep.len[0] >= 13)
   2197 				cipher = WPA_CIPHER_WEP104;
   2198 			bss->ssid.security_policy = SECURITY_STATIC_WEP;
   2199 			bss->wpa_group = cipher;
   2200 			bss->wpa_pairwise = cipher;
   2201 			bss->rsn_pairwise = cipher;
   2202 		} else {
   2203 			bss->ssid.security_policy = SECURITY_PLAINTEXT;
   2204 			bss->wpa_group = WPA_CIPHER_NONE;
   2205 			bss->wpa_pairwise = WPA_CIPHER_NONE;
   2206 			bss->rsn_pairwise = WPA_CIPHER_NONE;
   2207 		}
   2208 	}
   2209 
   2210 	if (hostapd_config_check(conf))
   2211 		errors++;
   2212 
   2213 #ifndef WPA_IGNORE_CONFIG_ERRORS
   2214 	if (errors) {
   2215 		wpa_printf(MSG_ERROR, "%d errors found in configuration file "
   2216 			   "'%s'", errors, fname);
   2217 		hostapd_config_free(conf);
   2218 		conf = NULL;
   2219 	}
   2220 #endif /* WPA_IGNORE_CONFIG_ERRORS */
   2221 
   2222 	return conf;
   2223 }
   2224