]>
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" |
d501c27c | 13 | #include "crypto/tls.h" |
6fc6879b | 14 | #include "radius/radius_client.h" |
df84268a | 15 | #include "common/ieee802_11_defs.h" |
29c832d0 | 16 | #include "common/ieee802_1x_defs.h" |
41d719d6 | 17 | #include "common/eapol_common.h" |
91d91abf | 18 | #include "common/dhcp.h" |
43b20b43 | 19 | #include "common/sae.h" |
03da66bd JM |
20 | #include "eap_common/eap_wsc_common.h" |
21 | #include "eap_server/eap.h" | |
6226e38d | 22 | #include "wpa_auth.h" |
97234b50 | 23 | #include "sta_info.h" |
ef721751 | 24 | #include "airtime_policy.h" |
6226e38d | 25 | #include "ap_config.h" |
6fc6879b JM |
26 | |
27 | ||
6fc6879b JM |
28 | static void hostapd_config_free_vlan(struct hostapd_bss_config *bss) |
29 | { | |
30 | struct hostapd_vlan *vlan, *prev; | |
31 | ||
32 | vlan = bss->vlan; | |
33 | prev = NULL; | |
34 | while (vlan) { | |
35 | prev = vlan; | |
36 | vlan = vlan->next; | |
37 | os_free(prev); | |
38 | } | |
39 | ||
40 | bss->vlan = NULL; | |
41 | } | |
42 | ||
43 | ||
6f234c1e JM |
44 | #ifndef DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES |
45 | #define DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES 0 | |
46 | #endif /* DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES */ | |
47 | ||
41d719d6 | 48 | void hostapd_config_defaults_bss(struct hostapd_bss_config *bss) |
6fc6879b | 49 | { |
695dbbea JM |
50 | dl_list_init(&bss->anqp_elem); |
51 | ||
6fc6879b JM |
52 | bss->logger_syslog_level = HOSTAPD_LEVEL_INFO; |
53 | bss->logger_stdout_level = HOSTAPD_LEVEL_INFO; | |
54 | bss->logger_syslog = (unsigned int) -1; | |
55 | bss->logger_stdout = (unsigned int) -1; | |
56 | ||
57 | bss->auth_algs = WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED; | |
58 | ||
59 | bss->wep_rekeying_period = 300; | |
60 | /* use key0 in individual key and key1 in broadcast key */ | |
61 | bss->broadcast_key_idx_min = 1; | |
62 | bss->broadcast_key_idx_max = 2; | |
63 | bss->eap_reauth_period = 3600; | |
64 | ||
65 | bss->wpa_group_rekey = 600; | |
66 | bss->wpa_gmk_rekey = 86400; | |
1a7963e3 | 67 | bss->wpa_deny_ptk0_rekey = PTK0_REKEY_ALLOW_ALWAYS; |
41f140d3 GK |
68 | bss->wpa_group_update_count = 4; |
69 | bss->wpa_pairwise_update_count = 4; | |
6f234c1e JM |
70 | bss->wpa_disable_eapol_key_retries = |
71 | DEFAULT_WPA_DISABLE_EAPOL_KEY_RETRIES; | |
6fc6879b JM |
72 | bss->wpa_key_mgmt = WPA_KEY_MGMT_PSK; |
73 | bss->wpa_pairwise = WPA_CIPHER_TKIP; | |
74 | bss->wpa_group = WPA_CIPHER_TKIP; | |
75 | bss->rsn_pairwise = 0; | |
76 | ||
77 | bss->max_num_sta = MAX_STA_COUNT; | |
78 | ||
79 | bss->dtim_period = 2; | |
80 | ||
81 | bss->radius_server_auth_port = 1812; | |
7b0f5500 | 82 | bss->eap_sim_db_timeout = 1; |
6bb11c7a | 83 | bss->eap_sim_id = 3; |
6fc6879b JM |
84 | bss->ap_max_inactivity = AP_MAX_INACTIVITY; |
85 | bss->eapol_version = EAPOL_VERSION; | |
b0194fe0 JM |
86 | |
87 | bss->max_listen_interval = 65535; | |
5d22a1d5 | 88 | |
df684d82 DH |
89 | bss->pwd_group = 19; /* ECC: GF(p=256) */ |
90 | ||
45c94154 JM |
91 | bss->assoc_sa_query_max_timeout = 1000; |
92 | bss->assoc_sa_query_retry_timeout = 201; | |
8dd9f9cd | 93 | bss->group_mgmt_cipher = WPA_CIPHER_AES_128_CMAC; |
1e5839e0 | 94 | #ifdef EAP_SERVER_FAST |
378eae5e JM |
95 | /* both anonymous and authenticated provisioning */ |
96 | bss->eap_fast_prov = 3; | |
a11c90a6 JM |
97 | bss->pac_key_lifetime = 7 * 24 * 60 * 60; |
98 | bss->pac_key_refresh_time = 1 * 24 * 60 * 60; | |
1e5839e0 | 99 | #endif /* EAP_SERVER_FAST */ |
d2da2249 JB |
100 | |
101 | /* Set to -1 as defaults depends on HT in setup */ | |
102 | bss->wmm_enabled = -1; | |
d7956add | 103 | |
4ec1fd8e | 104 | #ifdef CONFIG_IEEE80211R_AP |
d7956add | 105 | bss->ft_over_ds = 1; |
3a46cf93 MB |
106 | bss->rkh_pos_timeout = 86400; |
107 | bss->rkh_neg_timeout = 60; | |
108 | bss->rkh_pull_timeout = 1000; | |
109 | bss->rkh_pull_retries = 4; | |
83fe4bd3 | 110 | bss->r0_key_lifetime = 1209600; |
4ec1fd8e | 111 | #endif /* CONFIG_IEEE80211R_AP */ |
bde7ba6c JM |
112 | |
113 | bss->radius_das_time_window = 300; | |
d136c376 JM |
114 | |
115 | bss->sae_anti_clogging_threshold = 5; | |
d8b841eb | 116 | bss->sae_sync = 5; |
26bf70e3 | 117 | |
2977f519 JM |
118 | bss->gas_frag_limit = 1400; |
119 | ||
26bf70e3 JM |
120 | #ifdef CONFIG_FILS |
121 | dl_list_init(&bss->fils_realms); | |
91d91abf JM |
122 | bss->fils_hlp_wait_time = 30; |
123 | bss->dhcp_server_port = DHCP_SERVER_PORT; | |
124 | bss->dhcp_relay_port = DHCP_SERVER_PORT; | |
26bf70e3 | 125 | #endif /* CONFIG_FILS */ |
57a2aaca JM |
126 | |
127 | bss->broadcast_deauth = 1; | |
941caed9 JM |
128 | |
129 | #ifdef CONFIG_MBO | |
130 | bss->mbo_cell_data_conn_pref = -1; | |
131 | #endif /* CONFIG_MBO */ | |
d501c27c JM |
132 | |
133 | /* Disable TLS v1.3 by default for now to avoid interoperability issue. | |
134 | * This can be enabled by default once the implementation has been fully | |
135 | * completed and tested with other implementations. */ | |
136 | bss->tls_flags = TLS_CONN_DISABLE_TLSv1_3; | |
678d8410 | 137 | |
8d76e0ad JM |
138 | bss->max_auth_rounds = 100; |
139 | bss->max_auth_rounds_short = 50; | |
140 | ||
678d8410 | 141 | bss->send_probe_response = 1; |
6ae04d7b JM |
142 | |
143 | #ifdef CONFIG_HS20 | |
144 | bss->hs20_release = (HS20_VERSION >> 4) + 1; | |
145 | #endif /* CONFIG_HS20 */ | |
dd5d325b | 146 | |
29c832d0 | 147 | #ifdef CONFIG_MACSEC |
148 | bss->mka_priority = DEFAULT_PRIO_NOT_KEY_SERVER; | |
149 | bss->macsec_port = 1; | |
150 | #endif /* CONFIG_MACSEC */ | |
151 | ||
dd5d325b SV |
152 | /* Default to strict CRL checking. */ |
153 | bss->check_crl_strict = 1; | |
6fc6879b JM |
154 | } |
155 | ||
156 | ||
89111f3b | 157 | struct hostapd_config * hostapd_config_defaults(void) |
6fc6879b | 158 | { |
d2da2249 JB |
159 | #define ecw2cw(ecw) ((1 << (ecw)) - 1) |
160 | ||
6fc6879b JM |
161 | struct hostapd_config *conf; |
162 | struct hostapd_bss_config *bss; | |
594cf8b9 | 163 | const int aCWmin = 4, aCWmax = 10; |
3ae0800c | 164 | const struct hostapd_wmm_ac_params ac_bk = |
6fc6879b | 165 | { aCWmin, aCWmax, 7, 0, 0 }; /* background traffic */ |
3ae0800c | 166 | const struct hostapd_wmm_ac_params ac_be = |
6fc6879b | 167 | { aCWmin, aCWmax, 3, 0, 0 }; /* best effort traffic */ |
3ae0800c | 168 | const struct hostapd_wmm_ac_params ac_vi = /* video traffic */ |
f4e3860f | 169 | { aCWmin - 1, aCWmin, 2, 3008 / 32, 0 }; |
3ae0800c | 170 | const struct hostapd_wmm_ac_params ac_vo = /* voice traffic */ |
f4e3860f | 171 | { aCWmin - 2, aCWmin - 1, 2, 1504 / 32, 0 }; |
d2da2249 JB |
172 | const struct hostapd_tx_queue_params txq_bk = |
173 | { 7, ecw2cw(aCWmin), ecw2cw(aCWmax), 0 }; | |
174 | const struct hostapd_tx_queue_params txq_be = | |
175 | { 3, ecw2cw(aCWmin), 4 * (ecw2cw(aCWmin) + 1) - 1, 0}; | |
176 | const struct hostapd_tx_queue_params txq_vi = | |
177 | { 1, (ecw2cw(aCWmin) + 1) / 2 - 1, ecw2cw(aCWmin), 30}; | |
178 | const struct hostapd_tx_queue_params txq_vo = | |
179 | { 1, (ecw2cw(aCWmin) + 1) / 4 - 1, | |
180 | (ecw2cw(aCWmin) + 1) / 2 - 1, 15}; | |
181 | ||
182 | #undef ecw2cw | |
6fc6879b JM |
183 | |
184 | conf = os_zalloc(sizeof(*conf)); | |
185 | bss = os_zalloc(sizeof(*bss)); | |
186 | if (conf == NULL || bss == NULL) { | |
10656fc2 JM |
187 | wpa_printf(MSG_ERROR, "Failed to allocate memory for " |
188 | "configuration data."); | |
6fc6879b JM |
189 | os_free(conf); |
190 | os_free(bss); | |
191 | return NULL; | |
192 | } | |
ebd79f07 JM |
193 | conf->bss = os_calloc(1, sizeof(struct hostapd_bss_config *)); |
194 | if (conf->bss == NULL) { | |
195 | os_free(conf); | |
196 | os_free(bss); | |
197 | return NULL; | |
198 | } | |
199 | conf->bss[0] = bss; | |
6fc6879b | 200 | |
6fc6879b JM |
201 | bss->radius = os_zalloc(sizeof(*bss->radius)); |
202 | if (bss->radius == NULL) { | |
04c366cb | 203 | os_free(conf->bss); |
6fc6879b JM |
204 | os_free(conf); |
205 | os_free(bss); | |
206 | return NULL; | |
207 | } | |
208 | ||
209 | hostapd_config_defaults_bss(bss); | |
210 | ||
211 | conf->num_bss = 1; | |
6fc6879b JM |
212 | |
213 | conf->beacon_int = 100; | |
bf0021ed JM |
214 | conf->rts_threshold = -2; /* use driver default: 2347 */ |
215 | conf->fragm_threshold = -2; /* user driver default: 2346 */ | |
e0392f82 S |
216 | /* Set to invalid value means do not add Power Constraint IE */ |
217 | conf->local_pwr_constraint = -1; | |
6fc6879b | 218 | |
3ae0800c JM |
219 | conf->wmm_ac_params[0] = ac_be; |
220 | conf->wmm_ac_params[1] = ac_bk; | |
221 | conf->wmm_ac_params[2] = ac_vi; | |
222 | conf->wmm_ac_params[3] = ac_vo; | |
6fc6879b | 223 | |
d2da2249 JB |
224 | conf->tx_queue[0] = txq_vo; |
225 | conf->tx_queue[1] = txq_vi; | |
226 | conf->tx_queue[2] = txq_be; | |
227 | conf->tx_queue[3] = txq_bk; | |
228 | ||
fc14f567 | 229 | conf->ht_capab = HT_CAP_INFO_SMPS_DISABLED; |
de9289c8 | 230 | |
f1b44874 SE |
231 | conf->ap_table_max_size = 255; |
232 | conf->ap_table_expiration_time = 60; | |
a65a9b8d | 233 | conf->track_sta_max_age = 180; |
f1b44874 | 234 | |
c2aff6b1 | 235 | #ifdef CONFIG_TESTING_OPTIONS |
06df2aa6 JM |
236 | conf->ignore_probe_probability = 0.0; |
237 | conf->ignore_auth_probability = 0.0; | |
238 | conf->ignore_assoc_probability = 0.0; | |
239 | conf->ignore_reassoc_probability = 0.0; | |
240 | conf->corrupt_gtk_rekey_mic_probability = 0.0; | |
2b6e1216 | 241 | conf->ecsa_ie_only = 0; |
c2aff6b1 JB |
242 | #endif /* CONFIG_TESTING_OPTIONS */ |
243 | ||
857d9422 MM |
244 | conf->acs = 0; |
245 | conf->acs_ch_list.num = 0; | |
50f4f2a0 MK |
246 | #ifdef CONFIG_ACS |
247 | conf->acs_num_scans = 5; | |
248 | #endif /* CONFIG_ACS */ | |
249 | ||
83f30fab JC |
250 | #ifdef CONFIG_IEEE80211AX |
251 | conf->he_op.he_rts_threshold = HE_OPERATION_RTS_THRESHOLD_MASK >> | |
252 | HE_OPERATION_RTS_THRESHOLD_OFFSET; | |
4f3f3380 JC |
253 | /* Set default basic MCS/NSS set to single stream MCS 0-7 */ |
254 | conf->he_op.he_basic_mcs_nss_set = 0xfffc; | |
0cb39f4f JC |
255 | conf->he_op.he_bss_color_disabled = 1; |
256 | conf->he_op.he_bss_color_partial = 0; | |
257 | conf->he_op.he_bss_color = 1; | |
83f30fab JC |
258 | #endif /* CONFIG_IEEE80211AX */ |
259 | ||
ff936bc7 JM |
260 | /* The third octet of the country string uses an ASCII space character |
261 | * by default to indicate that the regulations encompass all | |
262 | * environments for the current frequency band in the country. */ | |
263 | conf->country[2] = ' '; | |
264 | ||
076f1ea1 BL |
265 | conf->rssi_reject_assoc_rssi = 0; |
266 | conf->rssi_reject_assoc_timeout = 30; | |
267 | ||
ef721751 THJ |
268 | #ifdef CONFIG_AIRTIME_POLICY |
269 | conf->airtime_update_interval = AIRTIME_DEFAULT_UPDATE_INTERVAL; | |
270 | #endif /* CONFIG_AIRTIME_POLICY */ | |
271 | ||
6fc6879b JM |
272 | return conf; |
273 | } | |
274 | ||
275 | ||
276 | int hostapd_mac_comp(const void *a, const void *b) | |
277 | { | |
278 | return os_memcmp(a, b, sizeof(macaddr)); | |
279 | } | |
280 | ||
281 | ||
6fc6879b JM |
282 | static int hostapd_config_read_wpa_psk(const char *fname, |
283 | struct hostapd_ssid *ssid) | |
284 | { | |
285 | FILE *f; | |
286 | char buf[128], *pos; | |
ec5c39a5 MK |
287 | const char *keyid; |
288 | char *context; | |
289 | char *context2; | |
290 | char *token; | |
291 | char *name; | |
292 | char *value; | |
6fc6879b JM |
293 | int line = 0, ret = 0, len, ok; |
294 | u8 addr[ETH_ALEN]; | |
295 | struct hostapd_wpa_psk *psk; | |
296 | ||
297 | if (!fname) | |
298 | return 0; | |
299 | ||
300 | f = fopen(fname, "r"); | |
301 | if (!f) { | |
10656fc2 | 302 | wpa_printf(MSG_ERROR, "WPA PSK file '%s' not found.", fname); |
6fc6879b JM |
303 | return -1; |
304 | } | |
305 | ||
306 | while (fgets(buf, sizeof(buf), f)) { | |
dbfa691d | 307 | int vlan_id = 0; |
fde8e794 | 308 | int wps = 0; |
dbfa691d | 309 | |
6fc6879b JM |
310 | line++; |
311 | ||
312 | if (buf[0] == '#') | |
313 | continue; | |
314 | pos = buf; | |
315 | while (*pos != '\0') { | |
316 | if (*pos == '\n') { | |
317 | *pos = '\0'; | |
318 | break; | |
319 | } | |
320 | pos++; | |
321 | } | |
322 | if (buf[0] == '\0') | |
323 | continue; | |
324 | ||
ec5c39a5 MK |
325 | context = NULL; |
326 | keyid = NULL; | |
327 | while ((token = str_token(buf, " ", &context))) { | |
328 | if (!os_strchr(token, '=')) | |
329 | break; | |
330 | context2 = NULL; | |
331 | name = str_token(token, "=", &context2); | |
2fae58fd JM |
332 | if (!name) |
333 | break; | |
ec5c39a5 MK |
334 | value = str_token(token, "", &context2); |
335 | if (!value) | |
336 | value = ""; | |
337 | if (!os_strcmp(name, "keyid")) { | |
338 | keyid = value; | |
fde8e794 TJ |
339 | } else if (!os_strcmp(name, "wps")) { |
340 | wps = atoi(value); | |
dbfa691d JM |
341 | } else if (!os_strcmp(name, "vlanid")) { |
342 | vlan_id = atoi(value); | |
ec5c39a5 MK |
343 | } else { |
344 | wpa_printf(MSG_ERROR, | |
345 | "Unrecognized '%s=%s' on line %d in '%s'", | |
346 | name, value, line, fname); | |
347 | ret = -1; | |
348 | break; | |
349 | } | |
350 | } | |
351 | ||
352 | if (ret == -1) | |
353 | break; | |
354 | ||
355 | if (!token) | |
356 | token = ""; | |
357 | if (hwaddr_aton(token, addr)) { | |
b27ed050 JM |
358 | wpa_printf(MSG_ERROR, |
359 | "Invalid MAC address '%s' on line %d in '%s'", | |
360 | token, line, fname); | |
6fc6879b JM |
361 | ret = -1; |
362 | break; | |
363 | } | |
364 | ||
365 | psk = os_zalloc(sizeof(*psk)); | |
366 | if (psk == NULL) { | |
10656fc2 | 367 | wpa_printf(MSG_ERROR, "WPA PSK allocation failed"); |
6fc6879b JM |
368 | ret = -1; |
369 | break; | |
370 | } | |
dbfa691d | 371 | psk->vlan_id = vlan_id; |
a8e16edc | 372 | if (is_zero_ether_addr(addr)) |
6fc6879b JM |
373 | psk->group = 1; |
374 | else | |
375 | os_memcpy(psk->addr, addr, ETH_ALEN); | |
376 | ||
ec5c39a5 MK |
377 | pos = str_token(buf, "", &context); |
378 | if (!pos) { | |
10656fc2 JM |
379 | wpa_printf(MSG_ERROR, "No PSK on line %d in '%s'", |
380 | line, fname); | |
6fc6879b JM |
381 | os_free(psk); |
382 | ret = -1; | |
383 | break; | |
384 | } | |
6fc6879b JM |
385 | |
386 | ok = 0; | |
387 | len = os_strlen(pos); | |
83818087 JM |
388 | if (len == 2 * PMK_LEN && |
389 | hexstr2bin(pos, psk->psk, PMK_LEN) == 0) | |
6fc6879b | 390 | ok = 1; |
f5da5810 JM |
391 | else if (len >= 8 && len < 64 && |
392 | pbkdf2_sha1(pos, ssid->ssid, ssid->ssid_len, | |
393 | 4096, psk->psk, PMK_LEN) == 0) | |
6fc6879b | 394 | ok = 1; |
6fc6879b | 395 | if (!ok) { |
b27ed050 JM |
396 | wpa_printf(MSG_ERROR, |
397 | "Invalid PSK '%s' on line %d in '%s'", | |
398 | pos, line, fname); | |
6fc6879b JM |
399 | os_free(psk); |
400 | ret = -1; | |
401 | break; | |
402 | } | |
403 | ||
ec5c39a5 MK |
404 | if (keyid) { |
405 | len = os_strlcpy(psk->keyid, keyid, sizeof(psk->keyid)); | |
406 | if ((size_t) len >= sizeof(psk->keyid)) { | |
407 | wpa_printf(MSG_ERROR, | |
408 | "PSK keyid too long on line %d in '%s'", | |
409 | line, fname); | |
410 | os_free(psk); | |
411 | ret = -1; | |
412 | break; | |
413 | } | |
414 | } | |
415 | ||
fde8e794 TJ |
416 | psk->wps = wps; |
417 | ||
6fc6879b JM |
418 | psk->next = ssid->wpa_psk; |
419 | ssid->wpa_psk = psk; | |
420 | } | |
421 | ||
422 | fclose(f); | |
423 | ||
424 | return ret; | |
425 | } | |
426 | ||
427 | ||
0ae687bd JM |
428 | static int hostapd_derive_psk(struct hostapd_ssid *ssid) |
429 | { | |
430 | ssid->wpa_psk = os_zalloc(sizeof(struct hostapd_wpa_psk)); | |
431 | if (ssid->wpa_psk == NULL) { | |
432 | wpa_printf(MSG_ERROR, "Unable to alloc space for PSK"); | |
433 | return -1; | |
434 | } | |
435 | wpa_hexdump_ascii(MSG_DEBUG, "SSID", | |
436 | (u8 *) ssid->ssid, ssid->ssid_len); | |
437 | wpa_hexdump_ascii_key(MSG_DEBUG, "PSK (ASCII passphrase)", | |
438 | (u8 *) ssid->wpa_passphrase, | |
439 | os_strlen(ssid->wpa_passphrase)); | |
440 | pbkdf2_sha1(ssid->wpa_passphrase, | |
441 | ssid->ssid, ssid->ssid_len, | |
442 | 4096, ssid->wpa_psk->psk, PMK_LEN); | |
443 | wpa_hexdump_key(MSG_DEBUG, "PSK (from passphrase)", | |
444 | ssid->wpa_psk->psk, PMK_LEN); | |
445 | return 0; | |
446 | } | |
447 | ||
448 | ||
43b20b43 JM |
449 | int hostapd_setup_sae_pt(struct hostapd_bss_config *conf) |
450 | { | |
451 | #ifdef CONFIG_SAE | |
452 | struct hostapd_ssid *ssid = &conf->ssid; | |
453 | struct sae_password_entry *pw; | |
454 | ||
e36a5894 | 455 | if ((conf->sae_pwe == 0 && !hostapd_sae_pw_id_in_use(conf)) || |
641d79f1 | 456 | conf->sae_pwe == 3 || |
e36a5894 | 457 | !wpa_key_mgmt_sae(conf->wpa_key_mgmt)) |
43b20b43 JM |
458 | return 0; /* PT not needed */ |
459 | ||
460 | sae_deinit_pt(ssid->pt); | |
461 | ssid->pt = NULL; | |
462 | if (ssid->wpa_passphrase) { | |
463 | ssid->pt = sae_derive_pt(conf->sae_groups, ssid->ssid, | |
464 | ssid->ssid_len, | |
465 | (const u8 *) ssid->wpa_passphrase, | |
466 | os_strlen(ssid->wpa_passphrase), | |
467 | NULL); | |
468 | if (!ssid->pt) | |
469 | return -1; | |
470 | } | |
471 | ||
472 | for (pw = conf->sae_passwords; pw; pw = pw->next) { | |
473 | sae_deinit_pt(pw->pt); | |
474 | pw->pt = sae_derive_pt(conf->sae_groups, ssid->ssid, | |
475 | ssid->ssid_len, | |
476 | (const u8 *) pw->password, | |
477 | os_strlen(pw->password), | |
478 | pw->identifier); | |
479 | if (!pw->pt) | |
480 | return -1; | |
481 | } | |
482 | #endif /* CONFIG_SAE */ | |
483 | ||
484 | return 0; | |
485 | } | |
486 | ||
487 | ||
6fc6879b JM |
488 | int hostapd_setup_wpa_psk(struct hostapd_bss_config *conf) |
489 | { | |
490 | struct hostapd_ssid *ssid = &conf->ssid; | |
491 | ||
43b20b43 JM |
492 | if (hostapd_setup_sae_pt(conf) < 0) |
493 | return -1; | |
494 | ||
6fc6879b JM |
495 | if (ssid->wpa_passphrase != NULL) { |
496 | if (ssid->wpa_psk != NULL) { | |
0ae687bd JM |
497 | wpa_printf(MSG_DEBUG, "Using pre-configured WPA PSK " |
498 | "instead of passphrase"); | |
499 | } else { | |
500 | wpa_printf(MSG_DEBUG, "Deriving WPA PSK based on " | |
501 | "passphrase"); | |
502 | if (hostapd_derive_psk(ssid) < 0) | |
503 | return -1; | |
6fc6879b | 504 | } |
6fc6879b | 505 | ssid->wpa_psk->group = 1; |
6fc6879b JM |
506 | } |
507 | ||
34e29dfd | 508 | return hostapd_config_read_wpa_psk(ssid->wpa_psk_file, &conf->ssid); |
6fc6879b JM |
509 | } |
510 | ||
511 | ||
6fc6879b JM |
512 | static void hostapd_config_free_radius(struct hostapd_radius_server *servers, |
513 | int num_servers) | |
514 | { | |
515 | int i; | |
516 | ||
517 | for (i = 0; i < num_servers; i++) { | |
518 | os_free(servers[i].shared_secret); | |
519 | } | |
520 | os_free(servers); | |
521 | } | |
522 | ||
523 | ||
af35e7af JM |
524 | struct hostapd_radius_attr * |
525 | hostapd_config_get_radius_attr(struct hostapd_radius_attr *attr, u8 type) | |
526 | { | |
527 | for (; attr; attr = attr->next) { | |
528 | if (attr->type == type) | |
529 | return attr; | |
530 | } | |
531 | return NULL; | |
532 | } | |
533 | ||
534 | ||
74707def TB |
535 | struct hostapd_radius_attr * hostapd_parse_radius_attr(const char *value) |
536 | { | |
537 | const char *pos; | |
538 | char syntax; | |
539 | struct hostapd_radius_attr *attr; | |
540 | size_t len; | |
541 | ||
542 | attr = os_zalloc(sizeof(*attr)); | |
543 | if (!attr) | |
544 | return NULL; | |
545 | ||
546 | attr->type = atoi(value); | |
547 | ||
548 | pos = os_strchr(value, ':'); | |
549 | if (!pos) { | |
550 | attr->val = wpabuf_alloc(1); | |
551 | if (!attr->val) { | |
552 | os_free(attr); | |
553 | return NULL; | |
554 | } | |
555 | wpabuf_put_u8(attr->val, 0); | |
556 | return attr; | |
557 | } | |
558 | ||
559 | pos++; | |
560 | if (pos[0] == '\0' || pos[1] != ':') { | |
561 | os_free(attr); | |
562 | return NULL; | |
563 | } | |
564 | syntax = *pos++; | |
565 | pos++; | |
566 | ||
567 | switch (syntax) { | |
568 | case 's': | |
569 | attr->val = wpabuf_alloc_copy(pos, os_strlen(pos)); | |
570 | break; | |
571 | case 'x': | |
572 | len = os_strlen(pos); | |
573 | if (len & 1) | |
574 | break; | |
575 | len /= 2; | |
576 | attr->val = wpabuf_alloc(len); | |
577 | if (!attr->val) | |
578 | break; | |
579 | if (hexstr2bin(pos, wpabuf_put(attr->val, len), len) < 0) { | |
580 | wpabuf_free(attr->val); | |
581 | os_free(attr); | |
582 | return NULL; | |
583 | } | |
584 | break; | |
585 | case 'd': | |
586 | attr->val = wpabuf_alloc(4); | |
587 | if (attr->val) | |
588 | wpabuf_put_be32(attr->val, atoi(pos)); | |
589 | break; | |
590 | default: | |
591 | os_free(attr); | |
592 | return NULL; | |
593 | } | |
594 | ||
595 | if (!attr->val) { | |
596 | os_free(attr); | |
597 | return NULL; | |
598 | } | |
599 | ||
600 | return attr; | |
601 | } | |
602 | ||
603 | ||
f4111ff3 | 604 | void hostapd_config_free_radius_attr(struct hostapd_radius_attr *attr) |
af35e7af JM |
605 | { |
606 | struct hostapd_radius_attr *prev; | |
607 | ||
608 | while (attr) { | |
609 | prev = attr; | |
610 | attr = attr->next; | |
611 | wpabuf_free(prev->val); | |
612 | os_free(prev); | |
613 | } | |
614 | } | |
615 | ||
616 | ||
d0ee16ed | 617 | void hostapd_config_free_eap_user(struct hostapd_eap_user *user) |
6fc6879b | 618 | { |
d0ee16ed | 619 | hostapd_config_free_radius_attr(user->accept_attr); |
6fc6879b | 620 | os_free(user->identity); |
b7175b4d | 621 | bin_clear_free(user->password, user->password_len); |
d52ead3d | 622 | bin_clear_free(user->salt, user->salt_len); |
6fc6879b JM |
623 | os_free(user); |
624 | } | |
625 | ||
626 | ||
78022c83 JM |
627 | void hostapd_config_free_eap_users(struct hostapd_eap_user *user) |
628 | { | |
629 | struct hostapd_eap_user *prev_user; | |
630 | ||
631 | while (user) { | |
632 | prev_user = user; | |
633 | user = user->next; | |
634 | hostapd_config_free_eap_user(prev_user); | |
635 | } | |
636 | } | |
637 | ||
638 | ||
6fc6879b JM |
639 | static void hostapd_config_free_wep(struct hostapd_wep_keys *keys) |
640 | { | |
641 | int i; | |
642 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
b7175b4d | 643 | bin_clear_free(keys->key[i], keys->len[i]); |
6fc6879b JM |
644 | keys->key[i] = NULL; |
645 | } | |
646 | } | |
647 | ||
648 | ||
891dfb33 ST |
649 | void hostapd_config_clear_wpa_psk(struct hostapd_wpa_psk **l) |
650 | { | |
651 | struct hostapd_wpa_psk *psk, *tmp; | |
652 | ||
653 | for (psk = *l; psk;) { | |
654 | tmp = psk; | |
655 | psk = psk->next; | |
656 | bin_clear_free(tmp, sizeof(*tmp)); | |
657 | } | |
658 | *l = NULL; | |
659 | } | |
660 | ||
661 | ||
695dbbea JM |
662 | static void hostapd_config_free_anqp_elem(struct hostapd_bss_config *conf) |
663 | { | |
664 | struct anqp_element *elem; | |
665 | ||
666 | while ((elem = dl_list_first(&conf->anqp_elem, struct anqp_element, | |
667 | list))) { | |
668 | dl_list_del(&elem->list); | |
669 | wpabuf_free(elem->payload); | |
670 | os_free(elem); | |
671 | } | |
672 | } | |
673 | ||
674 | ||
26bf70e3 JM |
675 | static void hostapd_config_free_fils_realms(struct hostapd_bss_config *conf) |
676 | { | |
677 | #ifdef CONFIG_FILS | |
678 | struct fils_realm *realm; | |
679 | ||
680 | while ((realm = dl_list_first(&conf->fils_realms, struct fils_realm, | |
681 | list))) { | |
682 | dl_list_del(&realm->list); | |
683 | os_free(realm); | |
684 | } | |
685 | #endif /* CONFIG_FILS */ | |
686 | } | |
687 | ||
688 | ||
9be19d0b JM |
689 | static void hostapd_config_free_sae_passwords(struct hostapd_bss_config *conf) |
690 | { | |
691 | struct sae_password_entry *pw, *tmp; | |
692 | ||
693 | pw = conf->sae_passwords; | |
694 | conf->sae_passwords = NULL; | |
695 | while (pw) { | |
696 | tmp = pw; | |
697 | pw = pw->next; | |
698 | str_clear_free(tmp->password); | |
699 | os_free(tmp->identifier); | |
43b20b43 JM |
700 | #ifdef CONFIG_SAE |
701 | sae_deinit_pt(tmp->pt); | |
702 | #endif /* CONFIG_SAE */ | |
9be19d0b JM |
703 | os_free(tmp); |
704 | } | |
705 | } | |
706 | ||
707 | ||
e00f780e JM |
708 | #ifdef CONFIG_DPP2 |
709 | static void hostapd_dpp_controller_conf_free(struct dpp_controller_conf *conf) | |
710 | { | |
711 | struct dpp_controller_conf *prev; | |
712 | ||
713 | while (conf) { | |
714 | prev = conf; | |
715 | conf = conf->next; | |
716 | os_free(prev); | |
717 | } | |
718 | } | |
719 | #endif /* CONFIG_DPP2 */ | |
720 | ||
721 | ||
55920658 | 722 | void hostapd_config_free_bss(struct hostapd_bss_config *conf) |
6fc6879b | 723 | { |
a00ace9f AO |
724 | #if defined(CONFIG_WPS) || defined(CONFIG_HS20) |
725 | size_t i; | |
726 | #endif | |
727 | ||
6fc6879b JM |
728 | if (conf == NULL) |
729 | return; | |
730 | ||
891dfb33 | 731 | hostapd_config_clear_wpa_psk(&conf->ssid.wpa_psk); |
6fc6879b | 732 | |
b7175b4d | 733 | str_clear_free(conf->ssid.wpa_passphrase); |
6fc6879b | 734 | os_free(conf->ssid.wpa_psk_file); |
43dd46b3 | 735 | hostapd_config_free_wep(&conf->ssid.wep); |
6fc6879b JM |
736 | #ifdef CONFIG_FULL_DYNAMIC_VLAN |
737 | os_free(conf->ssid.vlan_tagged_interface); | |
738 | #endif /* CONFIG_FULL_DYNAMIC_VLAN */ | |
43b20b43 JM |
739 | #ifdef CONFIG_SAE |
740 | sae_deinit_pt(conf->ssid.pt); | |
741 | #endif /* CONFIG_SAE */ | |
6fc6879b | 742 | |
78022c83 | 743 | hostapd_config_free_eap_users(conf->eap_user); |
ee431d77 | 744 | os_free(conf->eap_user_sqlite); |
6fc6879b | 745 | |
6fc6879b | 746 | os_free(conf->eap_req_id_text); |
2a5156a6 | 747 | os_free(conf->erp_domain); |
6fc6879b JM |
748 | os_free(conf->accept_mac); |
749 | os_free(conf->deny_mac); | |
750 | os_free(conf->nas_identifier); | |
5afaa067 JM |
751 | if (conf->radius) { |
752 | hostapd_config_free_radius(conf->radius->auth_servers, | |
753 | conf->radius->num_auth_servers); | |
754 | hostapd_config_free_radius(conf->radius->acct_servers, | |
755 | conf->radius->num_acct_servers); | |
756 | } | |
af35e7af JM |
757 | hostapd_config_free_radius_attr(conf->radius_auth_req_attr); |
758 | hostapd_config_free_radius_attr(conf->radius_acct_req_attr); | |
f4111ff3 | 759 | os_free(conf->radius_req_attr_sqlite); |
6fc6879b JM |
760 | os_free(conf->rsn_preauth_interfaces); |
761 | os_free(conf->ctrl_interface); | |
762 | os_free(conf->ca_cert); | |
763 | os_free(conf->server_cert); | |
e2722bf8 | 764 | os_free(conf->server_cert2); |
6fc6879b | 765 | os_free(conf->private_key); |
e2722bf8 | 766 | os_free(conf->private_key2); |
6fc6879b | 767 | os_free(conf->private_key_passwd); |
e2722bf8 | 768 | os_free(conf->private_key_passwd2); |
841205a1 | 769 | os_free(conf->check_cert_subject); |
080585c0 | 770 | os_free(conf->ocsp_stapling_response); |
5addb0df | 771 | os_free(conf->ocsp_stapling_response_multi); |
6fc6879b | 772 | os_free(conf->dh_file); |
f8995f8f | 773 | os_free(conf->openssl_ciphers); |
d01203ca | 774 | os_free(conf->openssl_ecdh_curves); |
6fc6879b JM |
775 | os_free(conf->pac_opaque_encr_key); |
776 | os_free(conf->eap_fast_a_id); | |
2d867244 | 777 | os_free(conf->eap_fast_a_id_info); |
6fc6879b JM |
778 | os_free(conf->eap_sim_db); |
779 | os_free(conf->radius_server_clients); | |
6fc6879b | 780 | os_free(conf->radius); |
b031338c | 781 | os_free(conf->radius_das_shared_secret); |
6fc6879b | 782 | hostapd_config_free_vlan(conf); |
39b97072 JM |
783 | os_free(conf->time_zone); |
784 | ||
4ec1fd8e | 785 | #ifdef CONFIG_IEEE80211R_AP |
6fc6879b JM |
786 | { |
787 | struct ft_remote_r0kh *r0kh, *r0kh_prev; | |
788 | struct ft_remote_r1kh *r1kh, *r1kh_prev; | |
789 | ||
790 | r0kh = conf->r0kh_list; | |
791 | conf->r0kh_list = NULL; | |
792 | while (r0kh) { | |
793 | r0kh_prev = r0kh; | |
794 | r0kh = r0kh->next; | |
795 | os_free(r0kh_prev); | |
796 | } | |
797 | ||
798 | r1kh = conf->r1kh_list; | |
799 | conf->r1kh_list = NULL; | |
800 | while (r1kh) { | |
801 | r1kh_prev = r1kh; | |
802 | r1kh = r1kh->next; | |
803 | os_free(r1kh_prev); | |
804 | } | |
805 | } | |
4ec1fd8e | 806 | #endif /* CONFIG_IEEE80211R_AP */ |
ad08c363 JM |
807 | |
808 | #ifdef CONFIG_WPS | |
809 | os_free(conf->wps_pin_requests); | |
810 | os_free(conf->device_name); | |
811 | os_free(conf->manufacturer); | |
812 | os_free(conf->model_name); | |
813 | os_free(conf->model_number); | |
814 | os_free(conf->serial_number); | |
ad08c363 JM |
815 | os_free(conf->config_methods); |
816 | os_free(conf->ap_pin); | |
62966253 | 817 | os_free(conf->extra_cred); |
4c29cae9 | 818 | os_free(conf->ap_settings); |
66819b07 DL |
819 | hostapd_config_clear_wpa_psk(&conf->multi_ap_backhaul_ssid.wpa_psk); |
820 | str_clear_free(conf->multi_ap_backhaul_ssid.wpa_passphrase); | |
f620268f JM |
821 | os_free(conf->upnp_iface); |
822 | os_free(conf->friendly_name); | |
823 | os_free(conf->manufacturer_url); | |
824 | os_free(conf->model_description); | |
825 | os_free(conf->model_url); | |
826 | os_free(conf->upc); | |
a00ace9f AO |
827 | for (i = 0; i < MAX_WPS_VENDOR_EXTENSIONS; i++) |
828 | wpabuf_free(conf->wps_vendor_ext[i]); | |
3d41dd7c | 829 | wpabuf_free(conf->wps_application_ext); |
ffdaa05a JM |
830 | wpabuf_free(conf->wps_nfc_dh_pubkey); |
831 | wpabuf_free(conf->wps_nfc_dh_privkey); | |
832 | wpabuf_free(conf->wps_nfc_dev_pw); | |
ad08c363 | 833 | #endif /* CONFIG_WPS */ |
4b2a77ab JM |
834 | |
835 | os_free(conf->roaming_consortium); | |
648cc711 | 836 | os_free(conf->venue_name); |
7e1d3ee9 | 837 | os_free(conf->venue_url); |
8047b186 | 838 | os_free(conf->nai_realm_data); |
550a3958 | 839 | os_free(conf->network_auth_type); |
7515adb2 | 840 | os_free(conf->anqp_3gpp_cell_net); |
26fac8b6 | 841 | os_free(conf->domain_name); |
695dbbea | 842 | hostapd_config_free_anqp_elem(conf); |
505a3694 JM |
843 | |
844 | #ifdef CONFIG_RADIUS_TEST | |
845 | os_free(conf->dump_msk_file); | |
846 | #endif /* CONFIG_RADIUS_TEST */ | |
df5934f1 JK |
847 | |
848 | #ifdef CONFIG_HS20 | |
a9277e85 | 849 | os_free(conf->hs20_oper_friendly_name); |
4065a309 | 850 | os_free(conf->hs20_wan_metrics); |
5ccc54aa | 851 | os_free(conf->hs20_connection_capability); |
df5934f1 | 852 | os_free(conf->hs20_operating_class); |
f7bd7a01 | 853 | os_free(conf->hs20_icons); |
ae6d15c7 | 854 | if (conf->hs20_osu_providers) { |
ae6d15c7 JM |
855 | for (i = 0; i < conf->hs20_osu_providers_count; i++) { |
856 | struct hs20_osu_provider *p; | |
857 | size_t j; | |
858 | p = &conf->hs20_osu_providers[i]; | |
859 | os_free(p->friendly_name); | |
860 | os_free(p->server_uri); | |
861 | os_free(p->method_list); | |
862 | for (j = 0; j < p->icons_count; j++) | |
863 | os_free(p->icons[j]); | |
864 | os_free(p->icons); | |
865 | os_free(p->osu_nai); | |
cad810a9 | 866 | os_free(p->osu_nai2); |
ae6d15c7 JM |
867 | os_free(p->service_desc); |
868 | } | |
869 | os_free(conf->hs20_osu_providers); | |
870 | } | |
0e450db2 | 871 | if (conf->hs20_operator_icon) { |
0e450db2 JM |
872 | for (i = 0; i < conf->hs20_operator_icon_count; i++) |
873 | os_free(conf->hs20_operator_icon[i]); | |
874 | os_free(conf->hs20_operator_icon); | |
875 | } | |
8d2a9921 | 876 | os_free(conf->subscr_remediation_url); |
7bd8c76a | 877 | os_free(conf->hs20_sim_provisioning_url); |
6cb8f4f3 | 878 | os_free(conf->t_c_filename); |
8760b984 | 879 | os_free(conf->t_c_server_url); |
df5934f1 | 880 | #endif /* CONFIG_HS20 */ |
b52f084c JM |
881 | |
882 | wpabuf_free(conf->vendor_elements); | |
a9112270 | 883 | wpabuf_free(conf->assocresp_elements); |
625f202a JM |
884 | |
885 | os_free(conf->sae_groups); | |
91cc34bf JM |
886 | #ifdef CONFIG_OWE |
887 | os_free(conf->owe_groups); | |
888 | #endif /* CONFIG_OWE */ | |
67fe933d | 889 | |
88cb27c7 DS |
890 | os_free(conf->wowlan_triggers); |
891 | ||
67fe933d | 892 | os_free(conf->server_id); |
ebd79f07 | 893 | |
bc02843e JM |
894 | #ifdef CONFIG_TESTING_OPTIONS |
895 | wpabuf_free(conf->own_ie_override); | |
3648d8a1 | 896 | wpabuf_free(conf->sae_commit_override); |
f2c4b44b | 897 | wpabuf_free(conf->rsnxe_override_eapol); |
8d84c75f JM |
898 | wpabuf_free(conf->gtk_rsc_override); |
899 | wpabuf_free(conf->igtk_rsc_override); | |
bc02843e JM |
900 | #endif /* CONFIG_TESTING_OPTIONS */ |
901 | ||
964f64e2 | 902 | os_free(conf->no_probe_resp_if_seen_on); |
0e2412d0 | 903 | os_free(conf->no_auth_if_seen_on); |
964f64e2 | 904 | |
26bf70e3 JM |
905 | hostapd_config_free_fils_realms(conf); |
906 | ||
56c75495 | 907 | #ifdef CONFIG_DPP |
5a5639b0 JM |
908 | os_free(conf->dpp_name); |
909 | os_free(conf->dpp_mud_url); | |
56c75495 JM |
910 | os_free(conf->dpp_connector); |
911 | wpabuf_free(conf->dpp_netaccesskey); | |
912 | wpabuf_free(conf->dpp_csign); | |
e00f780e JM |
913 | #ifdef CONFIG_DPP2 |
914 | hostapd_dpp_controller_conf_free(conf->dpp_controller); | |
915 | #endif /* CONFIG_DPP2 */ | |
56c75495 JM |
916 | #endif /* CONFIG_DPP */ |
917 | ||
9be19d0b | 918 | hostapd_config_free_sae_passwords(conf); |
2377c1ca | 919 | |
ef721751 THJ |
920 | #ifdef CONFIG_AIRTIME_POLICY |
921 | { | |
922 | struct airtime_sta_weight *wt, *wt_prev; | |
923 | ||
924 | wt = conf->airtime_weight_list; | |
925 | conf->airtime_weight_list = NULL; | |
926 | while (wt) { | |
927 | wt_prev = wt; | |
928 | wt = wt->next; | |
929 | os_free(wt_prev); | |
930 | } | |
931 | } | |
932 | #endif /* CONFIG_AIRTIME_POLICY */ | |
933 | ||
ebd79f07 | 934 | os_free(conf); |
6fc6879b JM |
935 | } |
936 | ||
937 | ||
1c6e69cc JM |
938 | /** |
939 | * hostapd_config_free - Free hostapd configuration | |
940 | * @conf: Configuration data from hostapd_config_read(). | |
941 | */ | |
6fc6879b JM |
942 | void hostapd_config_free(struct hostapd_config *conf) |
943 | { | |
944 | size_t i; | |
945 | ||
946 | if (conf == NULL) | |
947 | return; | |
948 | ||
949 | for (i = 0; i < conf->num_bss; i++) | |
ebd79f07 | 950 | hostapd_config_free_bss(conf->bss[i]); |
6fc6879b | 951 | os_free(conf->bss); |
79d6c85f JM |
952 | os_free(conf->supported_rates); |
953 | os_free(conf->basic_rates); | |
857d9422 | 954 | os_free(conf->acs_ch_list.range); |
59bb7264 | 955 | os_free(conf->acs_freq_list.range); |
0ecff8d7 | 956 | os_free(conf->driver_params); |
68fa00c3 JM |
957 | #ifdef CONFIG_ACS |
958 | os_free(conf->acs_chan_bias); | |
959 | #endif /* CONFIG_ACS */ | |
74e982d8 DS |
960 | wpabuf_free(conf->lci); |
961 | wpabuf_free(conf->civic); | |
6fc6879b JM |
962 | |
963 | os_free(conf); | |
964 | } | |
965 | ||
966 | ||
1c6e69cc JM |
967 | /** |
968 | * hostapd_maclist_found - Find a MAC address from a list | |
969 | * @list: MAC address list | |
970 | * @num_entries: Number of addresses in the list | |
971 | * @addr: Address to search for | |
972 | * @vlan_id: Buffer for returning VLAN ID or %NULL if not needed | |
973 | * Returns: 1 if address is in the list or 0 if not. | |
974 | * | |
975 | * Perform a binary search for given MAC address from a pre-sorted list. | |
976 | */ | |
271d2830 | 977 | int hostapd_maclist_found(struct mac_acl_entry *list, int num_entries, |
1889af2e | 978 | const u8 *addr, struct vlan_description *vlan_id) |
6fc6879b JM |
979 | { |
980 | int start, end, middle, res; | |
981 | ||
982 | start = 0; | |
983 | end = num_entries - 1; | |
984 | ||
985 | while (start <= end) { | |
986 | middle = (start + end) / 2; | |
271d2830 JM |
987 | res = os_memcmp(list[middle].addr, addr, ETH_ALEN); |
988 | if (res == 0) { | |
989 | if (vlan_id) | |
990 | *vlan_id = list[middle].vlan_id; | |
6fc6879b | 991 | return 1; |
271d2830 | 992 | } |
6fc6879b JM |
993 | if (res < 0) |
994 | start = middle + 1; | |
995 | else | |
996 | end = middle - 1; | |
997 | } | |
998 | ||
999 | return 0; | |
1000 | } | |
1001 | ||
1002 | ||
1003 | int hostapd_rate_found(int *list, int rate) | |
1004 | { | |
1005 | int i; | |
1006 | ||
1007 | if (list == NULL) | |
1008 | return 0; | |
1009 | ||
1010 | for (i = 0; list[i] >= 0; i++) | |
1011 | if (list[i] == rate) | |
1012 | return 1; | |
1013 | ||
1014 | return 0; | |
1015 | } | |
1016 | ||
1017 | ||
1889af2e MB |
1018 | int hostapd_vlan_valid(struct hostapd_vlan *vlan, |
1019 | struct vlan_description *vlan_desc) | |
6fc6879b JM |
1020 | { |
1021 | struct hostapd_vlan *v = vlan; | |
8e44c192 | 1022 | int i; |
1889af2e | 1023 | |
8e44c192 | 1024 | if (!vlan_desc->notempty || vlan_desc->untagged < 0 || |
1889af2e MB |
1025 | vlan_desc->untagged > MAX_VLAN_ID) |
1026 | return 0; | |
8e44c192 MB |
1027 | for (i = 0; i < MAX_NUM_TAGGED_VLAN; i++) { |
1028 | if (vlan_desc->tagged[i] < 0 || | |
1029 | vlan_desc->tagged[i] > MAX_VLAN_ID) | |
1030 | return 0; | |
1031 | } | |
1032 | if (!vlan_desc->untagged && !vlan_desc->tagged[0]) | |
1033 | return 0; | |
1889af2e | 1034 | |
6fc6879b | 1035 | while (v) { |
1889af2e MB |
1036 | if (!vlan_compare(&v->vlan_desc, vlan_desc) || |
1037 | v->vlan_id == VLAN_ID_WILDCARD) | |
80ebfd95 MB |
1038 | return 1; |
1039 | v = v->next; | |
1040 | } | |
1041 | return 0; | |
1042 | } | |
1043 | ||
1044 | ||
1045 | const char * hostapd_get_vlan_id_ifname(struct hostapd_vlan *vlan, int vlan_id) | |
1046 | { | |
1047 | struct hostapd_vlan *v = vlan; | |
1048 | while (v) { | |
1049 | if (v->vlan_id == vlan_id) | |
6fc6879b JM |
1050 | return v->ifname; |
1051 | v = v->next; | |
1052 | } | |
1053 | return NULL; | |
1054 | } | |
1055 | ||
1056 | ||
1057 | const u8 * hostapd_get_psk(const struct hostapd_bss_config *conf, | |
759fd76b | 1058 | const u8 *addr, const u8 *p2p_dev_addr, |
dbfa691d | 1059 | const u8 *prev_psk, int *vlan_id) |
6fc6879b JM |
1060 | { |
1061 | struct hostapd_wpa_psk *psk; | |
1062 | int next_ok = prev_psk == NULL; | |
1063 | ||
dbfa691d JM |
1064 | if (vlan_id) |
1065 | *vlan_id = 0; | |
1066 | ||
dc87541e | 1067 | if (p2p_dev_addr && !is_zero_ether_addr(p2p_dev_addr)) { |
759fd76b JM |
1068 | wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR |
1069 | " p2p_dev_addr=" MACSTR " prev_psk=%p", | |
1070 | MAC2STR(addr), MAC2STR(p2p_dev_addr), prev_psk); | |
dc87541e | 1071 | addr = NULL; /* Use P2P Device Address for matching */ |
759fd76b JM |
1072 | } else { |
1073 | wpa_printf(MSG_DEBUG, "Searching a PSK for " MACSTR | |
1074 | " prev_psk=%p", | |
1075 | MAC2STR(addr), prev_psk); | |
1076 | } | |
1077 | ||
6fc6879b JM |
1078 | for (psk = conf->ssid.wpa_psk; psk != NULL; psk = psk->next) { |
1079 | if (next_ok && | |
759fd76b JM |
1080 | (psk->group || |
1081 | (addr && os_memcmp(psk->addr, addr, ETH_ALEN) == 0) || | |
1082 | (!addr && p2p_dev_addr && | |
1083 | os_memcmp(psk->p2p_dev_addr, p2p_dev_addr, ETH_ALEN) == | |
dbfa691d JM |
1084 | 0))) { |
1085 | if (vlan_id) | |
1086 | *vlan_id = psk->vlan_id; | |
6fc6879b | 1087 | return psk->psk; |
dbfa691d | 1088 | } |
6fc6879b JM |
1089 | |
1090 | if (psk->psk == prev_psk) | |
1091 | next_ok = 1; | |
1092 | } | |
1093 | ||
1094 | return NULL; | |
1095 | } | |
eff0fd1e JM |
1096 | |
1097 | ||
1098 | static int hostapd_config_check_bss(struct hostapd_bss_config *bss, | |
08081ad8 JM |
1099 | struct hostapd_config *conf, |
1100 | int full_config) | |
eff0fd1e | 1101 | { |
08081ad8 | 1102 | if (full_config && bss->ieee802_1x && !bss->eap_server && |
eff0fd1e JM |
1103 | !bss->radius->auth_servers) { |
1104 | wpa_printf(MSG_ERROR, "Invalid IEEE 802.1X configuration (no " | |
1105 | "EAP authenticator configured)."); | |
1106 | return -1; | |
1107 | } | |
1108 | ||
1109 | if (bss->wpa) { | |
1110 | int wep, i; | |
1111 | ||
1112 | wep = bss->default_wep_key_len > 0 || | |
1113 | bss->individual_wep_key_len > 0; | |
1114 | for (i = 0; i < NUM_WEP_KEYS; i++) { | |
1115 | if (bss->ssid.wep.keys_set) { | |
1116 | wep = 1; | |
1117 | break; | |
1118 | } | |
1119 | } | |
1120 | ||
1121 | if (wep) { | |
1122 | wpa_printf(MSG_ERROR, "WEP configuration in a WPA network is not supported"); | |
1123 | return -1; | |
1124 | } | |
1125 | } | |
1126 | ||
08081ad8 JM |
1127 | if (full_config && bss->wpa && |
1128 | bss->wpa_psk_radius != PSK_RADIUS_IGNORED && | |
eff0fd1e JM |
1129 | bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH) { |
1130 | wpa_printf(MSG_ERROR, "WPA-PSK using RADIUS enabled, but no " | |
1131 | "RADIUS checking (macaddr_acl=2) enabled."); | |
1132 | return -1; | |
1133 | } | |
1134 | ||
08081ad8 | 1135 | if (full_config && bss->wpa && (bss->wpa_key_mgmt & WPA_KEY_MGMT_PSK) && |
eff0fd1e JM |
1136 | bss->ssid.wpa_psk == NULL && bss->ssid.wpa_passphrase == NULL && |
1137 | bss->ssid.wpa_psk_file == NULL && | |
1138 | (bss->wpa_psk_radius != PSK_RADIUS_REQUIRED || | |
1139 | bss->macaddr_acl != USE_EXTERNAL_RADIUS_AUTH)) { | |
1140 | wpa_printf(MSG_ERROR, "WPA-PSK enabled, but PSK or passphrase " | |
1141 | "is not configured."); | |
1142 | return -1; | |
1143 | } | |
1144 | ||
902c07a7 | 1145 | if (full_config && !is_zero_ether_addr(bss->bssid)) { |
eff0fd1e JM |
1146 | size_t i; |
1147 | ||
1148 | for (i = 0; i < conf->num_bss; i++) { | |
1149 | if (conf->bss[i] != bss && | |
1150 | (hostapd_mac_comp(conf->bss[i]->bssid, | |
1151 | bss->bssid) == 0)) { | |
1152 | wpa_printf(MSG_ERROR, "Duplicate BSSID " MACSTR | |
1153 | " on interface '%s' and '%s'.", | |
1154 | MAC2STR(bss->bssid), | |
1155 | conf->bss[i]->iface, bss->iface); | |
1156 | return -1; | |
1157 | } | |
1158 | } | |
1159 | } | |
1160 | ||
4ec1fd8e | 1161 | #ifdef CONFIG_IEEE80211R_AP |
08081ad8 | 1162 | if (full_config && wpa_key_mgmt_ft(bss->wpa_key_mgmt) && |
eff0fd1e JM |
1163 | (bss->nas_identifier == NULL || |
1164 | os_strlen(bss->nas_identifier) < 1 || | |
1165 | os_strlen(bss->nas_identifier) > FT_R0KH_ID_MAX_LEN)) { | |
1166 | wpa_printf(MSG_ERROR, "FT (IEEE 802.11r) requires " | |
1167 | "nas_identifier to be configured as a 1..48 octet " | |
1168 | "string"); | |
1169 | return -1; | |
1170 | } | |
4ec1fd8e | 1171 | #endif /* CONFIG_IEEE80211R_AP */ |
eff0fd1e | 1172 | |
08081ad8 JM |
1173 | if (full_config && conf->ieee80211n && |
1174 | conf->hw_mode == HOSTAPD_MODE_IEEE80211B) { | |
eff0fd1e JM |
1175 | bss->disable_11n = 1; |
1176 | wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) in 11b mode is not " | |
8c6f4a5a | 1177 | "allowed, disabling HT capabilities"); |
eff0fd1e JM |
1178 | } |
1179 | ||
08081ad8 | 1180 | if (full_config && conf->ieee80211n && |
eff0fd1e JM |
1181 | bss->ssid.security_policy == SECURITY_STATIC_WEP) { |
1182 | bss->disable_11n = 1; | |
1183 | wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WEP is not " | |
1184 | "allowed, disabling HT capabilities"); | |
1185 | } | |
1186 | ||
08081ad8 | 1187 | if (full_config && conf->ieee80211n && bss->wpa && |
eff0fd1e | 1188 | !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && |
30675c34 JM |
1189 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | |
1190 | WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) | |
1191 | { | |
eff0fd1e JM |
1192 | bss->disable_11n = 1; |
1193 | wpa_printf(MSG_ERROR, "HT (IEEE 802.11n) with WPA/WPA2 " | |
1194 | "requires CCMP/GCMP to be enabled, disabling HT " | |
1195 | "capabilities"); | |
1196 | } | |
eff0fd1e | 1197 | |
551817a5 WG |
1198 | #ifdef CONFIG_IEEE80211AC |
1199 | if (full_config && conf->ieee80211ac && | |
1200 | bss->ssid.security_policy == SECURITY_STATIC_WEP) { | |
1201 | bss->disable_11ac = 1; | |
1202 | wpa_printf(MSG_ERROR, | |
1203 | "VHT (IEEE 802.11ac) with WEP is not allowed, disabling VHT capabilities"); | |
1204 | } | |
59d7cff7 FM |
1205 | |
1206 | if (full_config && conf->ieee80211ac && bss->wpa && | |
1207 | !(bss->wpa_pairwise & WPA_CIPHER_CCMP) && | |
1208 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | | |
1209 | WPA_CIPHER_CCMP_256 | WPA_CIPHER_GCMP_256))) | |
1210 | { | |
1211 | bss->disable_11ac = 1; | |
1212 | wpa_printf(MSG_ERROR, | |
1213 | "VHT (IEEE 802.11ac) with WPA/WPA2 requires CCMP/GCMP to be enabled, disabling VHT capabilities"); | |
1214 | } | |
551817a5 WG |
1215 | #endif /* CONFIG_IEEE80211AC */ |
1216 | ||
c201f93a | 1217 | #ifdef CONFIG_WPS |
08081ad8 | 1218 | if (full_config && bss->wps_state && bss->ignore_broadcast_ssid) { |
eff0fd1e JM |
1219 | wpa_printf(MSG_INFO, "WPS: ignore_broadcast_ssid " |
1220 | "configuration forced WPS to be disabled"); | |
1221 | bss->wps_state = 0; | |
1222 | } | |
1223 | ||
08081ad8 JM |
1224 | if (full_config && bss->wps_state && |
1225 | bss->ssid.wep.keys_set && bss->wpa == 0) { | |
eff0fd1e JM |
1226 | wpa_printf(MSG_INFO, "WPS: WEP configuration forced WPS to be " |
1227 | "disabled"); | |
1228 | bss->wps_state = 0; | |
1229 | } | |
1230 | ||
08081ad8 | 1231 | if (full_config && bss->wps_state && bss->wpa && |
eff0fd1e | 1232 | (!(bss->wpa & 2) || |
a2660890 SSG |
1233 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | |
1234 | WPA_CIPHER_CCMP_256 | | |
1235 | WPA_CIPHER_GCMP_256)))) { | |
eff0fd1e | 1236 | wpa_printf(MSG_INFO, "WPS: WPA/TKIP configuration without " |
01a02593 | 1237 | "WPA2/CCMP/GCMP forced WPS to be disabled"); |
eff0fd1e JM |
1238 | bss->wps_state = 0; |
1239 | } | |
c201f93a | 1240 | #endif /* CONFIG_WPS */ |
eff0fd1e JM |
1241 | |
1242 | #ifdef CONFIG_HS20 | |
08081ad8 | 1243 | if (full_config && bss->hs20 && |
eff0fd1e | 1244 | (!(bss->wpa & 2) || |
30675c34 JM |
1245 | !(bss->rsn_pairwise & (WPA_CIPHER_CCMP | WPA_CIPHER_GCMP | |
1246 | WPA_CIPHER_CCMP_256 | | |
1247 | WPA_CIPHER_GCMP_256)))) { | |
eff0fd1e JM |
1248 | wpa_printf(MSG_ERROR, "HS 2.0: WPA2-Enterprise/CCMP " |
1249 | "configuration is required for Hotspot 2.0 " | |
1250 | "functionality"); | |
1251 | return -1; | |
1252 | } | |
1253 | #endif /* CONFIG_HS20 */ | |
1254 | ||
4c572281 JM |
1255 | #ifdef CONFIG_MBO |
1256 | if (full_config && bss->mbo_enabled && (bss->wpa & 2) && | |
1257 | bss->ieee80211w == NO_MGMT_FRAME_PROTECTION) { | |
1258 | wpa_printf(MSG_ERROR, | |
1259 | "MBO: PMF needs to be enabled whenever using WPA2 with MBO"); | |
1260 | return -1; | |
1261 | } | |
1262 | #endif /* CONFIG_MBO */ | |
1263 | ||
9c55fdb0 MV |
1264 | #ifdef CONFIG_OCV |
1265 | if (full_config && bss->ieee80211w == NO_MGMT_FRAME_PROTECTION && | |
1266 | bss->ocv) { | |
1267 | wpa_printf(MSG_ERROR, | |
1268 | "OCV: PMF needs to be enabled whenever using OCV"); | |
1269 | return -1; | |
1270 | } | |
1271 | #endif /* CONFIG_OCV */ | |
1272 | ||
eff0fd1e JM |
1273 | return 0; |
1274 | } | |
1275 | ||
1276 | ||
8884ce03 MM |
1277 | static int hostapd_config_check_cw(struct hostapd_config *conf, int queue) |
1278 | { | |
1279 | int tx_cwmin = conf->tx_queue[queue].cwmin; | |
1280 | int tx_cwmax = conf->tx_queue[queue].cwmax; | |
1281 | int ac_cwmin = conf->wmm_ac_params[queue].cwmin; | |
1282 | int ac_cwmax = conf->wmm_ac_params[queue].cwmax; | |
1283 | ||
1284 | if (tx_cwmin > tx_cwmax) { | |
1285 | wpa_printf(MSG_ERROR, | |
1286 | "Invalid TX queue cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)", | |
1287 | tx_cwmin, tx_cwmax); | |
1288 | return -1; | |
1289 | } | |
1290 | if (ac_cwmin > ac_cwmax) { | |
1291 | wpa_printf(MSG_ERROR, | |
1292 | "Invalid WMM AC cwMin/cwMax values. cwMin(%d) greater than cwMax(%d)", | |
1293 | ac_cwmin, ac_cwmax); | |
1294 | return -1; | |
1295 | } | |
1296 | return 0; | |
1297 | } | |
1298 | ||
1299 | ||
08081ad8 | 1300 | int hostapd_config_check(struct hostapd_config *conf, int full_config) |
eff0fd1e JM |
1301 | { |
1302 | size_t i; | |
1303 | ||
08081ad8 JM |
1304 | if (full_config && conf->ieee80211d && |
1305 | (!conf->country[0] || !conf->country[1])) { | |
eff0fd1e JM |
1306 | wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11d without " |
1307 | "setting the country_code"); | |
1308 | return -1; | |
1309 | } | |
1310 | ||
08081ad8 | 1311 | if (full_config && conf->ieee80211h && !conf->ieee80211d) { |
eff0fd1e JM |
1312 | wpa_printf(MSG_ERROR, "Cannot enable IEEE 802.11h without " |
1313 | "IEEE 802.11d enabled"); | |
1314 | return -1; | |
1315 | } | |
1316 | ||
e0392f82 S |
1317 | if (full_config && conf->local_pwr_constraint != -1 && |
1318 | !conf->ieee80211d) { | |
1319 | wpa_printf(MSG_ERROR, "Cannot add Power Constraint element without Country element"); | |
1320 | return -1; | |
1321 | } | |
1322 | ||
3d7ad2f6 C |
1323 | if (full_config && conf->spectrum_mgmt_required && |
1324 | conf->local_pwr_constraint == -1) { | |
1325 | wpa_printf(MSG_ERROR, "Cannot set Spectrum Management bit without Country and Power Constraint elements"); | |
1326 | return -1; | |
1327 | } | |
1328 | ||
ef721751 THJ |
1329 | #ifdef CONFIG_AIRTIME_POLICY |
1330 | if (full_config && conf->airtime_mode > AIRTIME_MODE_STATIC && | |
1331 | !conf->airtime_update_interval) { | |
1332 | wpa_printf(MSG_ERROR, "Airtime update interval cannot be zero"); | |
1333 | return -1; | |
1334 | } | |
1335 | #endif /* CONFIG_AIRTIME_POLICY */ | |
8884ce03 MM |
1336 | for (i = 0; i < NUM_TX_QUEUES; i++) { |
1337 | if (hostapd_config_check_cw(conf, i)) | |
1338 | return -1; | |
1339 | } | |
1340 | ||
eff0fd1e | 1341 | for (i = 0; i < conf->num_bss; i++) { |
08081ad8 | 1342 | if (hostapd_config_check_bss(conf->bss[i], conf, full_config)) |
eff0fd1e JM |
1343 | return -1; |
1344 | } | |
1345 | ||
1346 | return 0; | |
1347 | } | |
1348 | ||
1349 | ||
5d67bf15 JM |
1350 | void hostapd_set_security_params(struct hostapd_bss_config *bss, |
1351 | int full_config) | |
eff0fd1e JM |
1352 | { |
1353 | if (bss->individual_wep_key_len == 0) { | |
1354 | /* individual keys are not use; can use key idx0 for | |
1355 | * broadcast keys */ | |
1356 | bss->broadcast_key_idx_min = 0; | |
1357 | } | |
1358 | ||
1359 | if ((bss->wpa & 2) && bss->rsn_pairwise == 0) | |
1360 | bss->rsn_pairwise = bss->wpa_pairwise; | |
27781c0a JM |
1361 | if (bss->group_cipher) |
1362 | bss->wpa_group = bss->group_cipher; | |
1363 | else | |
1364 | bss->wpa_group = wpa_select_ap_group_cipher(bss->wpa, | |
1365 | bss->wpa_pairwise, | |
1366 | bss->rsn_pairwise); | |
90f837b0 JM |
1367 | if (!bss->wpa_group_rekey_set) |
1368 | bss->wpa_group_rekey = bss->wpa_group == WPA_CIPHER_TKIP ? | |
1369 | 600 : 86400; | |
eff0fd1e | 1370 | |
5d67bf15 JM |
1371 | if (full_config) { |
1372 | bss->radius->auth_server = bss->radius->auth_servers; | |
1373 | bss->radius->acct_server = bss->radius->acct_servers; | |
1374 | } | |
eff0fd1e JM |
1375 | |
1376 | if (bss->wpa && bss->ieee802_1x) { | |
1377 | bss->ssid.security_policy = SECURITY_WPA; | |
1378 | } else if (bss->wpa) { | |
1379 | bss->ssid.security_policy = SECURITY_WPA_PSK; | |
1380 | } else if (bss->ieee802_1x) { | |
1381 | int cipher = WPA_CIPHER_NONE; | |
1382 | bss->ssid.security_policy = SECURITY_IEEE_802_1X; | |
1383 | bss->ssid.wep.default_len = bss->default_wep_key_len; | |
13a3a20d | 1384 | if (full_config && bss->default_wep_key_len) { |
eff0fd1e JM |
1385 | cipher = bss->default_wep_key_len >= 13 ? |
1386 | WPA_CIPHER_WEP104 : WPA_CIPHER_WEP40; | |
13a3a20d JM |
1387 | } else if (full_config && bss->ssid.wep.keys_set) { |
1388 | if (bss->ssid.wep.len[0] >= 13) | |
1389 | cipher = WPA_CIPHER_WEP104; | |
1390 | else | |
1391 | cipher = WPA_CIPHER_WEP40; | |
1392 | } | |
eff0fd1e JM |
1393 | bss->wpa_group = cipher; |
1394 | bss->wpa_pairwise = cipher; | |
1395 | bss->rsn_pairwise = cipher; | |
13a3a20d JM |
1396 | if (full_config) |
1397 | bss->wpa_key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA; | |
eff0fd1e JM |
1398 | } else if (bss->ssid.wep.keys_set) { |
1399 | int cipher = WPA_CIPHER_WEP40; | |
1400 | if (bss->ssid.wep.len[0] >= 13) | |
1401 | cipher = WPA_CIPHER_WEP104; | |
1402 | bss->ssid.security_policy = SECURITY_STATIC_WEP; | |
1403 | bss->wpa_group = cipher; | |
1404 | bss->wpa_pairwise = cipher; | |
1405 | bss->rsn_pairwise = cipher; | |
13a3a20d JM |
1406 | if (full_config) |
1407 | bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE; | |
a14896e8 JM |
1408 | } else if (bss->osen) { |
1409 | bss->ssid.security_policy = SECURITY_OSEN; | |
1410 | bss->wpa_group = WPA_CIPHER_CCMP; | |
1411 | bss->wpa_pairwise = 0; | |
1412 | bss->rsn_pairwise = WPA_CIPHER_CCMP; | |
eff0fd1e JM |
1413 | } else { |
1414 | bss->ssid.security_policy = SECURITY_PLAINTEXT; | |
29767152 JM |
1415 | if (full_config) { |
1416 | bss->wpa_group = WPA_CIPHER_NONE; | |
1417 | bss->wpa_pairwise = WPA_CIPHER_NONE; | |
1418 | bss->rsn_pairwise = WPA_CIPHER_NONE; | |
13a3a20d | 1419 | bss->wpa_key_mgmt = WPA_KEY_MGMT_NONE; |
29767152 | 1420 | } |
eff0fd1e JM |
1421 | } |
1422 | } | |
42d30863 JM |
1423 | |
1424 | ||
1425 | int hostapd_sae_pw_id_in_use(struct hostapd_bss_config *conf) | |
1426 | { | |
1427 | int with_id = 0, without_id = 0; | |
1428 | struct sae_password_entry *pw; | |
1429 | ||
1430 | if (conf->ssid.wpa_passphrase) | |
1431 | without_id = 1; | |
1432 | ||
1433 | for (pw = conf->sae_passwords; pw; pw = pw->next) { | |
1434 | if (pw->identifier) | |
1435 | with_id = 1; | |
1436 | else | |
1437 | without_id = 1; | |
1438 | if (with_id && without_id) | |
1439 | break; | |
1440 | } | |
1441 | ||
1442 | if (with_id && !without_id) | |
1443 | return 2; | |
1444 | return with_id; | |
1445 | } |