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