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