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