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