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