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