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