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