ap_config.c revision fb79edc9df1f20461e90e478363d207348213d35
1/*
2 * hostapd / Configuration helper functions
3 * Copyright (c) 2003-2013, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "crypto/sha1.h"
13#include "radius/radius_client.h"
14#include "common/ieee802_11_defs.h"
15#include "common/eapol_common.h"
16#include "eap_common/eap_wsc_common.h"
17#include "eap_server/eap.h"
18#include "wpa_auth.h"
19#include "sta_info.h"
20#include "ap_config.h"
21
22
23static void hostapd_config_free_vlan(struct hostapd_bss_config *bss)
24{
25	struct hostapd_vlan *vlan, *prev;
26
27	vlan = bss->vlan;
28	prev = NULL;
29	while (vlan) {
30		prev = vlan;
31		vlan = vlan->next;
32		os_free(prev);
33	}
34
35	bss->vlan = NULL;
36}
37
38
39void hostapd_config_defaults_bss(struct hostapd_bss_config *bss)
40{
41	bss->logger_syslog_level = HOSTAPD_LEVEL_INFO;
42	bss->logger_stdout_level = HOSTAPD_LEVEL_INFO;
43	bss->logger_syslog = (unsigned int) -1;
44	bss->logger_stdout = (unsigned int) -1;
45
46	bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED;
47
48	bss->wep_rekeying_period = 300;
49	/* use key0 in individual key and key1 in broadcast key */
50	bss->broadcast_key_idx_min = 1;
51	bss->broadcast_key_idx_max = 2;
52	bss->eap_reauth_period = 3600;
53
54	bss->wpa_group_rekey = 600;
55	bss->wpa_gmk_rekey = 86400;
56	bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK;
57	bss->wpa_pairwise = WPA_CIPHER_TKIP;
58	bss->wpa_group = WPA_CIPHER_TKIP;
59	bss->rsn_pairwise = 0;
60
61	bss->max_num_sta = MAX_STA_COUNT;
62
63	bss->dtim_period = 2;
64
65	bss->radius_server_auth_port = 1812;
66	bss->ap_max_inactivity = AP_MAX_INACTIVITY;
67	bss->eapol_version = EAPOL_VERSION;
68
69	bss->max_listen_interval = 65535;
70
71	bss->pwd_group = 19; /* ECC: GF(p=256) */
72
73#ifdef CONFIG_IEEE80211W
74	bss->assoc_sa_query_max_timeout = 1000;
75	bss->assoc_sa_query_retry_timeout = 201;
76#endif /* CONFIG_IEEE80211W */
77#ifdef EAP_SERVER_FAST
78	 /* both anonymous and authenticated provisioning */
79	bss->eap_fast_prov = 3;
80	bss->pac_key_lifetime = 7 * 24 * 60 * 60;
81	bss->pac_key_refresh_time = 1 * 24 * 60 * 60;
82#endif /* EAP_SERVER_FAST */
83
84	/* Set to -1 as defaults depends on HT in setup */
85	bss->wmm_enabled = -1;
86
87#ifdef CONFIG_IEEE80211R
88	bss->ft_over_ds = 1;
89#endif /* CONFIG_IEEE80211R */
90
91	bss->radius_das_time_window = 300;
92
93	bss->sae_anti_clogging_threshold = 5;
94}
95
96
97struct hostapd_config * hostapd_config_defaults(void)
98{
99#define ecw2cw(ecw) ((1 << (ecw)) - 1)
100
101	struct hostapd_config *conf;
102	struct hostapd_bss_config *bss;
103	const int aCWmin = 4, aCWmax = 10;
104	const struct hostapd_wmm_ac_params ac_bk =
105		{ aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */
106	const struct hostapd_wmm_ac_params ac_be =
107		{ aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */
108	const struct hostapd_wmm_ac_params ac_vi = /* video traffic */
109		{ aCWmin - 1, aCWmin, 2, 3000 / 32, 0 };
110	const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */
111		{ aCWmin - 2, aCWmin - 1, 2, 1500 / 32, 0 };
112	const struct hostapd_tx_queue_params txq_bk =
113		{ 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 };
114	const struct hostapd_tx_queue_params txq_be =
115		{ 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0};
116	const struct hostapd_tx_queue_params txq_vi =
117		{ 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30};
118	const struct hostapd_tx_queue_params txq_vo =
119		{ 1, (ecw2cw(aCWmin) + 1) / 4 - 1,
120		  (ecw2cw(aCWmin) + 1) / 2 - 1, 15};
121
122#undef ecw2cw
123
124	conf = os_zalloc(sizeof(*conf));
125	bss = os_zalloc(sizeof(*bss));
126	if (conf == NULL || bss == NULL) {
127		wpa_printf(MSG_ERROR, "Failed to allocate memory for "
128			   "configuration data.");
129		os_free(conf);
130		os_free(bss);
131		return NULL;
132	}
133	conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *));
134	if (conf->bss == NULL) {
135		os_free(conf);
136		os_free(bss);
137		return NULL;
138	}
139	conf->bss[0] = bss;
140
141	bss->radius = os_zalloc(sizeof(*bss->radius));
142	if (bss->radius == NULL) {
143		os_free(conf);
144		os_free(bss);
145		return NULL;
146	}
147
148	hostapd_config_defaults_bss(bss);
149
150	conf->num_bss = 1;
151
152	conf->beacon_int = 100;
153	conf->rts_threshold = -1; /* use driver default: 2347 */
154	conf->fragm_threshold = -1; /* user driver default: 2346 */
155	conf->send_probe_response = 1;
156
157	conf->wmm_ac_params[0] = ac_be;
158	conf->wmm_ac_params[1] = ac_bk;
159	conf->wmm_ac_params[2] = ac_vi;
160	conf->wmm_ac_params[3] = ac_vo;
161
162	conf->tx_queue[0] = txq_vo;
163	conf->tx_queue[1] = txq_vi;
164	conf->tx_queue[2] = txq_be;
165	conf->tx_queue[3] = txq_bk;
166
167	conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED;
168
169	conf->ap_table_max_size = 255;
170	conf->ap_table_expiration_time = 60;
171
172#ifdef CONFIG_TESTING_OPTIONS
173	conf->ignore_probe_probability = 0.0d;
174	conf->ignore_auth_probability = 0.0d;
175	conf->ignore_assoc_probability = 0.0d;
176	conf->ignore_reassoc_probability = 0.0d;
177	conf->corrupt_gtk_rekey_mic_probability = 0.0d;
178#endif /* CONFIG_TESTING_OPTIONS */
179
180#ifdef CONFIG_ACS
181	conf->acs_num_scans = 5;
182#endif /* CONFIG_ACS */
183
184	return conf;
185}
186
187
188int hostapd_mac_comp(const void *a, const void *b)
189{
190	return os_memcmp(a, b, sizeof(macaddr));
191}
192
193
194int hostapd_mac_comp_empty(const void *a)
195{
196	macaddr empty = { 0 };
197	return os_memcmp(a, empty, sizeof(macaddr));
198}
199
200
201static int hostapd_config_read_wpa_psk(const char *fname,
202				       struct hostapd_ssid *ssid)
203{
204	FILE *f;
205	char buf[128], *pos;
206	int line = 0, ret = 0, len, ok;
207	u8 addr[ETH_ALEN];
208	struct hostapd_wpa_psk *psk;
209
210	if (!fname)
211		return 0;
212
213	f = fopen(fname, "r");
214	if (!f) {
215		wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname);
216		return -1;
217	}
218
219	while (fgets(buf, sizeof(buf), f)) {
220		line++;
221
222		if (buf[0] == '#')
223			continue;
224		pos = buf;
225		while (*pos != '\0') {
226			if (*pos == '\n') {
227				*pos = '\0';
228				break;
229			}
230			pos++;
231		}
232		if (buf[0] == '\0')
233			continue;
234
235		if (hwaddr_aton(buf, addr)) {
236			wpa_printf(MSG_ERROR, "Invalid MAC address '%s' on "
237				   "line %d in '%s'", buf, line, fname);
238			ret = -1;
239			break;
240		}
241
242		psk = os_zalloc(sizeof(*psk));
243		if (psk == NULL) {
244			wpa_printf(MSG_ERROR, "WPA PSK allocation failed");
245			ret = -1;
246			break;
247		}
248		if (is_zero_ether_addr(addr))
249			psk->group = 1;
250		else
251			os_memcpy(psk->addr, addr, ETH_ALEN);
252
253		pos = buf + 17;
254		if (*pos == '\0') {
255			wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'",
256				   line, fname);
257			os_free(psk);
258			ret = -1;
259			break;
260		}
261		pos++;
262
263		ok = 0;
264		len = os_strlen(pos);
265		if (len == 64 && hexstr2bin(pos, psk->psk, PMK_LEN) == 0)
266			ok = 1;
267		else if (len >= 8 && len < 64) {
268			pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len,
269				    4096, psk->psk, PMK_LEN);
270			ok = 1;
271		}
272		if (!ok) {
273			wpa_printf(MSG_ERROR, "Invalid PSK '%s' on line %d in "
274				   "'%s'", pos, line, fname);
275			os_free(psk);
276			ret = -1;
277			break;
278		}
279
280		psk->next = ssid->wpa_psk;
281		ssid->wpa_psk = psk;
282	}
283
284	fclose(f);
285
286	return ret;
287}
288
289
290static int hostapd_derive_psk(struct hostapd_ssid *ssid)
291{
292	ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk));
293	if (ssid->wpa_psk == NULL) {
294		wpa_printf(MSG_ERROR, "Unable to alloc space for PSK");
295		return -1;
296	}
297	wpa_hexdump_ascii(MSG_DEBUG, "SSID",
298			  (u8 *) ssid->ssid, ssid->ssid_len);
299	wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)",
300			      (u8 *) ssid->wpa_passphrase,
301			      os_strlen(ssid->wpa_passphrase));
302	pbkdf2_sha1(ssid->wpa_passphrase,
303		    ssid->ssid, ssid->ssid_len,
304		    4096, ssid->wpa_psk->psk, PMK_LEN);
305	wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)",
306			ssid->wpa_psk->psk, PMK_LEN);
307	return 0;
308}
309
310
311int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf)
312{
313	struct hostapd_ssid *ssid = &conf->ssid;
314
315	if (ssid->wpa_passphrase != NULL) {
316		if (ssid->wpa_psk != NULL) {
317			wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK "
318				   "instead of passphrase");
319		} else {
320			wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on "
321				   "passphrase");
322			if (hostapd_derive_psk(ssid) < 0)
323				return -1;
324		}
325		ssid->wpa_psk->group = 1;
326	}
327
328	if (ssid->wpa_psk_file) {
329		if (hostapd_config_read_wpa_psk(ssid->wpa_psk_file,
330						&conf->ssid))
331			return -1;
332	}
333
334	return 0;
335}
336
337
338int hostapd_wep_key_cmp(struct hostapd_wep_keys *a, struct hostapd_wep_keys *b)
339{
340	int i;
341
342	if (a->idx != b->idx || a->default_len != b->default_len)
343		return 1;
344	for (i = 0; i < NUM_WEP_KEYS; i++)
345		if (a->len[i] != b->len[i] ||
346		    os_memcmp(a->key[i], b->key[i], a->len[i]) != 0)
347			return 1;
348	return 0;
349}
350
351
352static void hostapd_config_free_radius(struct hostapd_radius_server *servers,
353				       int num_servers)
354{
355	int i;
356
357	for (i = 0; i < num_servers; i++) {
358		os_free(servers[i].shared_secret);
359	}
360	os_free(servers);
361}
362
363
364struct hostapd_radius_attr *
365hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type)
366{
367	for (; attr; attr = attr->next) {
368		if (attr->type == type)
369			return attr;
370	}
371	return NULL;
372}
373
374
375static void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr)
376{
377	struct hostapd_radius_attr *prev;
378
379	while (attr) {
380		prev = attr;
381		attr = attr->next;
382		wpabuf_free(prev->val);
383		os_free(prev);
384	}
385}
386
387
388static void hostapd_config_free_eap_user(struct hostapd_eap_user *user)
389{
390	os_free(user->identity);
391	os_free(user->password);
392	os_free(user);
393}
394
395
396static void hostapd_config_free_wep(struct hostapd_wep_keys *keys)
397{
398	int i;
399	for (i = 0; i < NUM_WEP_KEYS; i++) {
400		os_free(keys->key[i]);
401		keys->key[i] = NULL;
402	}
403}
404
405
406void hostapd_config_free_bss(struct hostapd_bss_config *conf)
407{
408	struct hostapd_wpa_psk *psk, *prev;
409	struct hostapd_eap_user *user, *prev_user;
410
411	if (conf == NULL)
412		return;
413
414	psk = conf->ssid.wpa_psk;
415	while (psk) {
416		prev = psk;
417		psk = psk->next;
418		os_free(prev);
419	}
420
421	os_free(conf->ssid.wpa_passphrase);
422	os_free(conf->ssid.wpa_psk_file);
423	hostapd_config_free_wep(&conf->ssid.wep);
424#ifdef CONFIG_FULL_DYNAMIC_VLAN
425	os_free(conf->ssid.vlan_tagged_interface);
426#endif /* CONFIG_FULL_DYNAMIC_VLAN */
427
428	user = conf->eap_user;
429	while (user) {
430		prev_user = user;
431		user = user->next;
432		hostapd_config_free_eap_user(prev_user);
433	}
434	os_free(conf->eap_user_sqlite);
435
436	os_free(conf->eap_req_id_text);
437	os_free(conf->accept_mac);
438	os_free(conf->deny_mac);
439	os_free(conf->nas_identifier);
440	if (conf->radius) {
441		hostapd_config_free_radius(conf->radius->auth_servers,
442					   conf->radius->num_auth_servers);
443		hostapd_config_free_radius(conf->radius->acct_servers,
444					   conf->radius->num_acct_servers);
445	}
446	hostapd_config_free_radius_attr(conf->radius_auth_req_attr);
447	hostapd_config_free_radius_attr(conf->radius_acct_req_attr);
448	os_free(conf->rsn_preauth_interfaces);
449	os_free(conf->ctrl_interface);
450	os_free(conf->ca_cert);
451	os_free(conf->server_cert);
452	os_free(conf->private_key);
453	os_free(conf->private_key_passwd);
454	os_free(conf->ocsp_stapling_response);
455	os_free(conf->dh_file);
456	os_free(conf->pac_opaque_encr_key);
457	os_free(conf->eap_fast_a_id);
458	os_free(conf->eap_fast_a_id_info);
459	os_free(conf->eap_sim_db);
460	os_free(conf->radius_server_clients);
461	os_free(conf->test_socket);
462	os_free(conf->radius);
463	os_free(conf->radius_das_shared_secret);
464	hostapd_config_free_vlan(conf);
465	os_free(conf->time_zone);
466
467#ifdef CONFIG_IEEE80211R
468	{
469		struct ft_remote_r0kh *r0kh, *r0kh_prev;
470		struct ft_remote_r1kh *r1kh, *r1kh_prev;
471
472		r0kh = conf->r0kh_list;
473		conf->r0kh_list = NULL;
474		while (r0kh) {
475			r0kh_prev = r0kh;
476			r0kh = r0kh->next;
477			os_free(r0kh_prev);
478		}
479
480		r1kh = conf->r1kh_list;
481		conf->r1kh_list = NULL;
482		while (r1kh) {
483			r1kh_prev = r1kh;
484			r1kh = r1kh->next;
485			os_free(r1kh_prev);
486		}
487	}
488#endif /* CONFIG_IEEE80211R */
489
490#ifdef CONFIG_WPS
491	os_free(conf->wps_pin_requests);
492	os_free(conf->device_name);
493	os_free(conf->manufacturer);
494	os_free(conf->model_name);
495	os_free(conf->model_number);
496	os_free(conf->serial_number);
497	os_free(conf->config_methods);
498	os_free(conf->ap_pin);
499	os_free(conf->extra_cred);
500	os_free(conf->ap_settings);
501	os_free(conf->upnp_iface);
502	os_free(conf->friendly_name);
503	os_free(conf->manufacturer_url);
504	os_free(conf->model_description);
505	os_free(conf->model_url);
506	os_free(conf->upc);
507	wpabuf_free(conf->wps_nfc_dh_pubkey);
508	wpabuf_free(conf->wps_nfc_dh_privkey);
509	wpabuf_free(conf->wps_nfc_dev_pw);
510#endif /* CONFIG_WPS */
511
512	os_free(conf->roaming_consortium);
513	os_free(conf->venue_name);
514	os_free(conf->nai_realm_data);
515	os_free(conf->network_auth_type);
516	os_free(conf->anqp_3gpp_cell_net);
517	os_free(conf->domain_name);
518
519#ifdef CONFIG_RADIUS_TEST
520	os_free(conf->dump_msk_file);
521#endif /* CONFIG_RADIUS_TEST */
522
523#ifdef CONFIG_HS20
524	os_free(conf->hs20_oper_friendly_name);
525	os_free(conf->hs20_wan_metrics);
526	os_free(conf->hs20_connection_capability);
527	os_free(conf->hs20_operating_class);
528#endif /* CONFIG_HS20 */
529
530	wpabuf_free(conf->vendor_elements);
531
532	os_free(conf->sae_groups);
533
534	os_free(conf->server_id);
535
536	os_free(conf);
537}
538
539
540/**
541 * hostapd_config_free - Free hostapd configuration
542 * @conf: Configuration data from hostapd_config_read().
543 */
544void hostapd_config_free(struct hostapd_config *conf)
545{
546	size_t i;
547
548	if (conf == NULL)
549		return;
550
551	for (i = 0; i < conf->num_bss; i++)
552		hostapd_config_free_bss(conf->bss[i]);
553	os_free(conf->bss);
554	os_free(conf->supported_rates);
555	os_free(conf->basic_rates);
556
557	os_free(conf);
558}
559
560
561/**
562 * hostapd_maclist_found - Find a MAC address from a list
563 * @list: MAC address list
564 * @num_entries: Number of addresses in the list
565 * @addr: Address to search for
566 * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed
567 * Returns: 1 if address is in the list or 0 if not.
568 *
569 * Perform a binary search for given MAC address from a pre-sorted list.
570 */
571int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries,
572			  const u8 *addr, int *vlan_id)
573{
574	int start, end, middle, res;
575
576	start = 0;
577	end = num_entries - 1;
578
579	while (start <= end) {
580		middle = (start + end) / 2;
581		res = os_memcmp(list[middle].addr, addr, ETH_ALEN);
582		if (res == 0) {
583			if (vlan_id)
584				*vlan_id = list[middle].vlan_id;
585			return 1;
586		}
587		if (res < 0)
588			start = middle + 1;
589		else
590			end = middle - 1;
591	}
592
593	return 0;
594}
595
596
597int hostapd_rate_found(int *list, int rate)
598{
599	int i;
600
601	if (list == NULL)
602		return 0;
603
604	for (i = 0; list[i] >= 0; i++)
605		if (list[i] == rate)
606			return 1;
607
608	return 0;
609}
610
611
612int hostapd_vlan_id_valid(struct hostapd_vlan *vlan, int vlan_id)
613{
614	struct hostapd_vlan *v = vlan;
615	while (v) {
616		if (v->vlan_id == vlan_id || v->vlan_id == VLAN_ID_WILDCARD)
617			return 1;
618		v = v->next;
619	}
620	return 0;
621}
622
623
624const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id)
625{
626	struct hostapd_vlan *v = vlan;
627	while (v) {
628		if (v->vlan_id == vlan_id)
629			return v->ifname;
630		v = v->next;
631	}
632	return NULL;
633}
634
635
636const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf,
637			   const u8 *addr, const u8 *p2p_dev_addr,
638			   const u8 *prev_psk)
639{
640	struct hostapd_wpa_psk *psk;
641	int next_ok = prev_psk == NULL;
642
643	if (p2p_dev_addr) {
644		wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
645			   " p2p_dev_addr=" MACSTR " prev_psk=%p",
646			   MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk);
647		if (!is_zero_ether_addr(p2p_dev_addr))
648			addr = NULL; /* Use P2P Device Address for matching */
649	} else {
650		wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR
651			   " prev_psk=%p",
652			   MAC2STR(addr), prev_psk);
653	}
654
655	for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) {
656		if (next_ok &&
657		    (psk->group ||
658		     (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) ||
659		     (!addr && p2p_dev_addr &&
660		      os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) ==
661		      0)))
662			return psk->psk;
663
664		if (psk->psk == prev_psk)
665			next_ok = 1;
666	}
667
668	return NULL;
669}
670
671
672static int hostapd_config_check_bss(struct hostapd_bss_config *bss,
673				    struct hostapd_config *conf)
674{
675	if (bss->ieee802_1x && !bss->eap_server &&
676	    !bss->radius->auth_servers) {
677		wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no "
678			   "EAP authenticator configured).");
679		return -1;
680	}
681
682	if (bss->wpa) {
683		int wep, i;
684
685		wep = bss->default_wep_key_len > 0 ||
686		       bss->individual_wep_key_len > 0;
687		for (i = 0; i < NUM_WEP_KEYS; i++) {
688			if (bss->ssid.wep.keys_set) {
689				wep = 1;
690				break;
691			}
692		}
693
694		if (wep) {
695			wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported");
696			return -1;
697		}
698	}
699
700	if (bss->wpa && bss->wpa_psk_radius != PSK_RADIUS_IGNORED &&
701	    bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) {
702		wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no "
703			   "RADIUS checking (macaddr_acl=2) enabled.");
704		return -1;
705	}
706
707	if (bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) &&
708	    bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL &&
709	    bss->ssid.wpa_psk_file == NULL &&
710	    (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED ||
711	     bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) {
712		wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase "
713			   "is not configured.");
714		return -1;
715	}
716
717	if (hostapd_mac_comp_empty(bss->bssid) != 0) {
718		size_t i;
719
720		for (i = 0; i < conf->num_bss; i++) {
721			if (conf->bss[i] != bss &&
722			    (hostapd_mac_comp(conf->bss[i]->bssid,
723					      bss->bssid) == 0)) {
724				wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR
725					   " on interface '%s' and '%s'.",
726					   MAC2STR(bss->bssid),
727					   conf->bss[i]->iface, bss->iface);
728				return -1;
729			}
730		}
731	}
732
733#ifdef CONFIG_IEEE80211R
734	if (wpa_key_mgmt_ft(bss->wpa_key_mgmt) &&
735	    (bss->nas_identifier == NULL ||
736	     os_strlen(bss->nas_identifier) < 1 ||
737	     os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) {
738		wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires "
739			   "nas_identifier to be configured as a 1..48 octet "
740			   "string");
741		return -1;
742	}
743#endif /* CONFIG_IEEE80211R */
744
745#ifdef CONFIG_IEEE80211N
746	if (conf->ieee80211n && conf->hw_mode == HOSTAPD_MODE_IEEE80211B) {
747		bss->disable_11n = 1;
748		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not "
749			   "allowed, disabling HT capabilites");
750	}
751
752	if (conf->ieee80211n &&
753	    bss->ssid.security_policy == SECURITY_STATIC_WEP) {
754		bss->disable_11n = 1;
755		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not "
756			   "allowed, disabling HT capabilities");
757	}
758
759	if (conf->ieee80211n && bss->wpa &&
760	    !(bss->wpa_pairwise & WPA_CIPHER_CCMP) &&
761	    !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
762				   WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256)))
763	{
764		bss->disable_11n = 1;
765		wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 "
766			   "requires CCMP/GCMP to be enabled, disabling HT "
767			   "capabilities");
768	}
769#endif /* CONFIG_IEEE80211N */
770
771#ifdef CONFIG_WPS2
772	if (bss->wps_state && bss->ignore_broadcast_ssid) {
773		wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid "
774			   "configuration forced WPS to be disabled");
775		bss->wps_state = 0;
776	}
777
778	if (bss->wps_state && bss->ssid.wep.keys_set && bss->wpa == 0) {
779		wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be "
780			   "disabled");
781		bss->wps_state = 0;
782	}
783
784	if (bss->wps_state && bss->wpa &&
785	    (!(bss->wpa & 2) ||
786	     !(bss->rsn_pairwise & WPA_CIPHER_CCMP))) {
787		wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without "
788			   "WPA2/CCMP forced WPS to be disabled");
789		bss->wps_state = 0;
790	}
791#endif /* CONFIG_WPS2 */
792
793#ifdef CONFIG_HS20
794	if (bss->hs20 &&
795	    (!(bss->wpa & 2) ||
796	     !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP |
797				    WPA_CIPHER_CCMP_256 |
798				    WPA_CIPHER_GCMP_256)))) {
799		wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP "
800			   "configuration is required for Hotspot 2.0 "
801			   "functionality");
802		return -1;
803	}
804#endif /* CONFIG_HS20 */
805
806	return 0;
807}
808
809
810int hostapd_config_check(struct hostapd_config *conf)
811{
812	size_t i;
813
814	if (conf->ieee80211d && (!conf->country[0] || !conf->country[1])) {
815		wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without "
816			   "setting the country_code");
817		return -1;
818	}
819
820	if (conf->ieee80211h && !conf->ieee80211d) {
821		wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without "
822			   "IEEE 802.11d enabled");
823		return -1;
824	}
825
826	for (i = 0; i < conf->num_bss; i++) {
827		if (hostapd_config_check_bss(conf->bss[i], conf))
828			return -1;
829	}
830
831	return 0;
832}
833
834
835void hostapd_set_security_params(struct hostapd_bss_config *bss)
836{
837	if (bss->individual_wep_key_len == 0) {
838		/* individual keys are not use; can use key idx0 for
839		 * broadcast keys */
840		bss->broadcast_key_idx_min = 0;
841	}
842
843	if ((bss->wpa & 2) && bss->rsn_pairwise == 0)
844		bss->rsn_pairwise = bss->wpa_pairwise;
845	bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, bss->wpa_pairwise,
846						    bss->rsn_pairwise);
847
848	bss->radius->auth_server = bss->radius->auth_servers;
849	bss->radius->acct_server = bss->radius->acct_servers;
850
851	if (bss->wpa && bss->ieee802_1x) {
852		bss->ssid.security_policy = SECURITY_WPA;
853	} else if (bss->wpa) {
854		bss->ssid.security_policy = SECURITY_WPA_PSK;
855	} else if (bss->ieee802_1x) {
856		int cipher = WPA_CIPHER_NONE;
857		bss->ssid.security_policy = SECURITY_IEEE_802_1X;
858		bss->ssid.wep.default_len = bss->default_wep_key_len;
859		if (bss->default_wep_key_len)
860			cipher = bss->default_wep_key_len >= 13 ?
861				WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40;
862		bss->wpa_group = cipher;
863		bss->wpa_pairwise = cipher;
864		bss->rsn_pairwise = cipher;
865	} else if (bss->ssid.wep.keys_set) {
866		int cipher = WPA_CIPHER_WEP40;
867		if (bss->ssid.wep.len[0] >= 13)
868			cipher = WPA_CIPHER_WEP104;
869		bss->ssid.security_policy = SECURITY_STATIC_WEP;
870		bss->wpa_group = cipher;
871		bss->wpa_pairwise = cipher;
872		bss->rsn_pairwise = cipher;
873	} else {
874		bss->ssid.security_policy = SECURITY_PLAINTEXT;
875		bss->wpa_group = WPA_CIPHER_NONE;
876		bss->wpa_pairwise = WPA_CIPHER_NONE;
877		bss->rsn_pairwise = WPA_CIPHER_NONE;
878	}
879}
880