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