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