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