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