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