Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2003-2015, 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 | * This file implements functions for registering and unregistering |
| 9 | * %wpa_supplicant interfaces. In addition, this file contains number of |
| 10 | * functions for managing network connections. |
| 11 | */ |
| 12 | |
| 13 | #include "includes.h" |
| 14 | |
| 15 | #include "common.h" |
| 16 | #include "crypto/random.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 17 | #include "crypto/sha1.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include "eapol_supp/eapol_supp_sm.h" |
| 19 | #include "eap_peer/eap.h" |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 20 | #include "eap_peer/eap_proxy.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 21 | #include "eap_server/eap_methods.h" |
| 22 | #include "rsn_supp/wpa.h" |
| 23 | #include "eloop.h" |
| 24 | #include "config.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 25 | #include "utils/ext_password.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 26 | #include "l2_packet/l2_packet.h" |
| 27 | #include "wpa_supplicant_i.h" |
| 28 | #include "driver_i.h" |
| 29 | #include "ctrl_iface.h" |
| 30 | #include "pcsc_funcs.h" |
| 31 | #include "common/version.h" |
| 32 | #include "rsn_supp/preauth.h" |
| 33 | #include "rsn_supp/pmksa_cache.h" |
| 34 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 36 | #include "common/hw_features_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "p2p/p2p.h" |
| 38 | #include "blacklist.h" |
| 39 | #include "wpas_glue.h" |
| 40 | #include "wps_supplicant.h" |
| 41 | #include "ibss_rsn.h" |
| 42 | #include "sme.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 43 | #include "gas_query.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 44 | #include "ap.h" |
| 45 | #include "p2p_supplicant.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 46 | #include "wifi_display.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 47 | #include "notify.h" |
| 48 | #include "bgscan.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 49 | #include "autoscan.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 50 | #include "bss.h" |
| 51 | #include "scan.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 52 | #include "offchannel.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 53 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 54 | #include "wnm_sta.h" |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 55 | #include "wpas_kay.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 56 | #include "mesh.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 57 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 58 | const char *const wpa_supplicant_version = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 59 | "wpa_supplicant v" VERSION_STR "\n" |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 60 | "Copyright (c) 2003-2015, Jouni Malinen <j@w1.fi> and contributors"; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 61 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 62 | const char *const wpa_supplicant_license = |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 63 | "This software may be distributed under the terms of the BSD license.\n" |
| 64 | "See README for more details.\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 65 | #ifdef EAP_TLS_OPENSSL |
| 66 | "\nThis product includes software developed by the OpenSSL Project\n" |
| 67 | "for use in the OpenSSL Toolkit (http://www.openssl.org/)\n" |
| 68 | #endif /* EAP_TLS_OPENSSL */ |
| 69 | ; |
| 70 | |
| 71 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 72 | /* Long text divided into parts in order to fit in C89 strings size limits. */ |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 73 | const char *const wpa_supplicant_full_license1 = |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 74 | ""; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 75 | const char *const wpa_supplicant_full_license2 = |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 76 | "This software may be distributed under the terms of the BSD license.\n" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 77 | "\n" |
| 78 | "Redistribution and use in source and binary forms, with or without\n" |
| 79 | "modification, are permitted provided that the following conditions are\n" |
| 80 | "met:\n" |
| 81 | "\n"; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 82 | const char *const wpa_supplicant_full_license3 = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 83 | "1. Redistributions of source code must retain the above copyright\n" |
| 84 | " notice, this list of conditions and the following disclaimer.\n" |
| 85 | "\n" |
| 86 | "2. Redistributions in binary form must reproduce the above copyright\n" |
| 87 | " notice, this list of conditions and the following disclaimer in the\n" |
| 88 | " documentation and/or other materials provided with the distribution.\n" |
| 89 | "\n"; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 90 | const char *const wpa_supplicant_full_license4 = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 91 | "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n" |
| 92 | " names of its contributors may be used to endorse or promote products\n" |
| 93 | " derived from this software without specific prior written permission.\n" |
| 94 | "\n" |
| 95 | "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" |
| 96 | "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" |
| 97 | "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" |
| 98 | "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 99 | const char *const wpa_supplicant_full_license5 = |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 100 | "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" |
| 101 | "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" |
| 102 | "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" |
| 103 | "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" |
| 104 | "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" |
| 105 | "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" |
| 106 | "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" |
| 107 | "\n"; |
| 108 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
| 109 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 110 | /* Configure default/group WEP keys for static WEP */ |
| 111 | int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
| 112 | { |
| 113 | int i, set = 0; |
| 114 | |
| 115 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 116 | if (ssid->wep_key_len[i] == 0) |
| 117 | continue; |
| 118 | |
| 119 | set = 1; |
| 120 | wpa_drv_set_key(wpa_s, WPA_ALG_WEP, NULL, |
| 121 | i, i == ssid->wep_tx_keyidx, NULL, 0, |
| 122 | ssid->wep_key[i], ssid->wep_key_len[i]); |
| 123 | } |
| 124 | |
| 125 | return set; |
| 126 | } |
| 127 | |
| 128 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 129 | int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s, |
| 130 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 131 | { |
| 132 | u8 key[32]; |
| 133 | size_t keylen; |
| 134 | enum wpa_alg alg; |
| 135 | u8 seq[6] = { 0 }; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 136 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 137 | |
| 138 | /* IBSS/WPA-None uses only one key (Group) for both receiving and |
| 139 | * sending unicast and multicast packets. */ |
| 140 | |
| 141 | if (ssid->mode != WPAS_MODE_IBSS) { |
| 142 | wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid mode %d (not " |
| 143 | "IBSS/ad-hoc) for WPA-None", ssid->mode); |
| 144 | return -1; |
| 145 | } |
| 146 | |
| 147 | if (!ssid->psk_set) { |
| 148 | wpa_msg(wpa_s, MSG_INFO, "WPA: No PSK configured for " |
| 149 | "WPA-None"); |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | switch (wpa_s->group_cipher) { |
| 154 | case WPA_CIPHER_CCMP: |
| 155 | os_memcpy(key, ssid->psk, 16); |
| 156 | keylen = 16; |
| 157 | alg = WPA_ALG_CCMP; |
| 158 | break; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 159 | case WPA_CIPHER_GCMP: |
| 160 | os_memcpy(key, ssid->psk, 16); |
| 161 | keylen = 16; |
| 162 | alg = WPA_ALG_GCMP; |
| 163 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 164 | case WPA_CIPHER_TKIP: |
| 165 | /* WPA-None uses the same Michael MIC key for both TX and RX */ |
| 166 | os_memcpy(key, ssid->psk, 16 + 8); |
| 167 | os_memcpy(key + 16 + 8, ssid->psk + 16, 8); |
| 168 | keylen = 32; |
| 169 | alg = WPA_ALG_TKIP; |
| 170 | break; |
| 171 | default: |
| 172 | wpa_msg(wpa_s, MSG_INFO, "WPA: Invalid group cipher %d for " |
| 173 | "WPA-None", wpa_s->group_cipher); |
| 174 | return -1; |
| 175 | } |
| 176 | |
| 177 | /* TODO: should actually remember the previously used seq#, both for TX |
| 178 | * and RX from each STA.. */ |
| 179 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 180 | ret = wpa_drv_set_key(wpa_s, alg, NULL, 0, 1, seq, 6, key, keylen); |
| 181 | os_memset(key, 0, sizeof(key)); |
| 182 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
| 186 | static void wpa_supplicant_timeout(void *eloop_ctx, void *timeout_ctx) |
| 187 | { |
| 188 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 189 | const u8 *bssid = wpa_s->bssid; |
| 190 | if (is_zero_ether_addr(bssid)) |
| 191 | bssid = wpa_s->pending_bssid; |
| 192 | wpa_msg(wpa_s, MSG_INFO, "Authentication with " MACSTR " timed out.", |
| 193 | MAC2STR(bssid)); |
| 194 | wpa_blacklist_add(wpa_s, bssid); |
| 195 | wpa_sm_notify_disassoc(wpa_s->wpa); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 196 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 197 | wpa_s->reassociate = 1; |
| 198 | |
| 199 | /* |
| 200 | * If we timed out, the AP or the local radio may be busy. |
| 201 | * So, wait a second until scanning again. |
| 202 | */ |
| 203 | wpa_supplicant_req_scan(wpa_s, 1, 0); |
| 204 | } |
| 205 | |
| 206 | |
| 207 | /** |
| 208 | * wpa_supplicant_req_auth_timeout - Schedule a timeout for authentication |
| 209 | * @wpa_s: Pointer to wpa_supplicant data |
| 210 | * @sec: Number of seconds after which to time out authentication |
| 211 | * @usec: Number of microseconds after which to time out authentication |
| 212 | * |
| 213 | * This function is used to schedule a timeout for the current authentication |
| 214 | * attempt. |
| 215 | */ |
| 216 | void wpa_supplicant_req_auth_timeout(struct wpa_supplicant *wpa_s, |
| 217 | int sec, int usec) |
| 218 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 219 | if (wpa_s->conf->ap_scan == 0 && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 220 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) |
| 221 | return; |
| 222 | |
| 223 | wpa_dbg(wpa_s, MSG_DEBUG, "Setting authentication timeout: %d sec " |
| 224 | "%d usec", sec, usec); |
| 225 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
| 226 | eloop_register_timeout(sec, usec, wpa_supplicant_timeout, wpa_s, NULL); |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /** |
| 231 | * wpa_supplicant_cancel_auth_timeout - Cancel authentication timeout |
| 232 | * @wpa_s: Pointer to wpa_supplicant data |
| 233 | * |
| 234 | * This function is used to cancel authentication timeout scheduled with |
| 235 | * wpa_supplicant_req_auth_timeout() and it is called when authentication has |
| 236 | * been completed. |
| 237 | */ |
| 238 | void wpa_supplicant_cancel_auth_timeout(struct wpa_supplicant *wpa_s) |
| 239 | { |
| 240 | wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling authentication timeout"); |
| 241 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
| 242 | wpa_blacklist_del(wpa_s, wpa_s->bssid); |
| 243 | } |
| 244 | |
| 245 | |
| 246 | /** |
| 247 | * wpa_supplicant_initiate_eapol - Configure EAPOL state machine |
| 248 | * @wpa_s: Pointer to wpa_supplicant data |
| 249 | * |
| 250 | * This function is used to configure EAPOL state machine based on the selected |
| 251 | * authentication mode. |
| 252 | */ |
| 253 | void wpa_supplicant_initiate_eapol(struct wpa_supplicant *wpa_s) |
| 254 | { |
| 255 | #ifdef IEEE8021X_EAPOL |
| 256 | struct eapol_config eapol_conf; |
| 257 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 258 | |
| 259 | #ifdef CONFIG_IBSS_RSN |
| 260 | if (ssid->mode == WPAS_MODE_IBSS && |
| 261 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
| 262 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) { |
| 263 | /* |
| 264 | * RSN IBSS authentication is per-STA and we can disable the |
| 265 | * per-BSSID EAPOL authentication. |
| 266 | */ |
| 267 | eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized); |
| 268 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); |
| 269 | eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE); |
| 270 | return; |
| 271 | } |
| 272 | #endif /* CONFIG_IBSS_RSN */ |
| 273 | |
| 274 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
| 275 | eapol_sm_notify_eap_fail(wpa_s->eapol, FALSE); |
| 276 | |
| 277 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 278 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) |
| 279 | eapol_sm_notify_portControl(wpa_s->eapol, ForceAuthorized); |
| 280 | else |
| 281 | eapol_sm_notify_portControl(wpa_s->eapol, Auto); |
| 282 | |
| 283 | os_memset(&eapol_conf, 0, sizeof(eapol_conf)); |
| 284 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 285 | eapol_conf.accept_802_1x_keys = 1; |
| 286 | eapol_conf.required_keys = 0; |
| 287 | if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_UNICAST) { |
| 288 | eapol_conf.required_keys |= EAPOL_REQUIRE_KEY_UNICAST; |
| 289 | } |
| 290 | if (ssid->eapol_flags & EAPOL_FLAG_REQUIRE_KEY_BROADCAST) { |
| 291 | eapol_conf.required_keys |= |
| 292 | EAPOL_REQUIRE_KEY_BROADCAST; |
| 293 | } |
| 294 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 295 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 296 | eapol_conf.required_keys = 0; |
| 297 | } |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 298 | eapol_conf.fast_reauth = wpa_s->conf->fast_reauth; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 299 | eapol_conf.workaround = ssid->eap_workaround; |
| 300 | eapol_conf.eap_disabled = |
| 301 | !wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) && |
| 302 | wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 303 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPS; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 304 | eapol_conf.external_sim = wpa_s->conf->external_sim; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 305 | |
| 306 | #ifdef CONFIG_WPS |
| 307 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { |
| 308 | eapol_conf.wps |= EAPOL_LOCAL_WPS_IN_USE; |
| 309 | if (wpa_s->current_bss) { |
| 310 | struct wpabuf *ie; |
| 311 | ie = wpa_bss_get_vendor_ie_multi(wpa_s->current_bss, |
| 312 | WPS_IE_VENDOR_TYPE); |
| 313 | if (ie) { |
| 314 | if (wps_is_20(ie)) |
| 315 | eapol_conf.wps |= |
| 316 | EAPOL_PEER_IS_WPS20_AP; |
| 317 | wpabuf_free(ie); |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | #endif /* CONFIG_WPS */ |
| 322 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 323 | eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf); |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 324 | |
| 325 | ieee802_1x_alloc_kay_sm(wpa_s, ssid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 326 | #endif /* IEEE8021X_EAPOL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | |
| 330 | /** |
| 331 | * wpa_supplicant_set_non_wpa_policy - Set WPA parameters to non-WPA mode |
| 332 | * @wpa_s: Pointer to wpa_supplicant data |
| 333 | * @ssid: Configuration data for the network |
| 334 | * |
| 335 | * This function is used to configure WPA state machine and related parameters |
| 336 | * to a mode where WPA is not enabled. This is called as part of the |
| 337 | * authentication configuration when the selected network does not use WPA. |
| 338 | */ |
| 339 | void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s, |
| 340 | struct wpa_ssid *ssid) |
| 341 | { |
| 342 | int i; |
| 343 | |
| 344 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) |
| 345 | wpa_s->key_mgmt = WPA_KEY_MGMT_WPS; |
| 346 | else if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) |
| 347 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_NO_WPA; |
| 348 | else |
| 349 | wpa_s->key_mgmt = WPA_KEY_MGMT_NONE; |
| 350 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); |
| 351 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); |
| 352 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
| 353 | wpa_s->pairwise_cipher = WPA_CIPHER_NONE; |
| 354 | wpa_s->group_cipher = WPA_CIPHER_NONE; |
| 355 | wpa_s->mgmt_group_cipher = 0; |
| 356 | |
| 357 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 358 | if (ssid->wep_key_len[i] > 5) { |
| 359 | wpa_s->pairwise_cipher = WPA_CIPHER_WEP104; |
| 360 | wpa_s->group_cipher = WPA_CIPHER_WEP104; |
| 361 | break; |
| 362 | } else if (ssid->wep_key_len[i] > 0) { |
| 363 | wpa_s->pairwise_cipher = WPA_CIPHER_WEP40; |
| 364 | wpa_s->group_cipher = WPA_CIPHER_WEP40; |
| 365 | break; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, 0); |
| 370 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
| 371 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
| 372 | wpa_s->pairwise_cipher); |
| 373 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); |
| 374 | #ifdef CONFIG_IEEE80211W |
| 375 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, |
| 376 | wpa_s->mgmt_group_cipher); |
| 377 | #endif /* CONFIG_IEEE80211W */ |
| 378 | |
| 379 | pmksa_cache_clear_current(wpa_s->wpa); |
| 380 | } |
| 381 | |
| 382 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 383 | void free_hw_features(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 384 | { |
| 385 | int i; |
| 386 | if (wpa_s->hw.modes == NULL) |
| 387 | return; |
| 388 | |
| 389 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 390 | os_free(wpa_s->hw.modes[i].channels); |
| 391 | os_free(wpa_s->hw.modes[i].rates); |
| 392 | } |
| 393 | |
| 394 | os_free(wpa_s->hw.modes); |
| 395 | wpa_s->hw.modes = NULL; |
| 396 | } |
| 397 | |
| 398 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 399 | static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s) |
| 400 | { |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 401 | int i; |
| 402 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 403 | bgscan_deinit(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 404 | autoscan_deinit(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 405 | scard_deinit(wpa_s->scard); |
| 406 | wpa_s->scard = NULL; |
| 407 | wpa_sm_set_scard_ctx(wpa_s->wpa, NULL); |
| 408 | eapol_sm_register_scard_ctx(wpa_s->eapol, NULL); |
| 409 | l2_packet_deinit(wpa_s->l2); |
| 410 | wpa_s->l2 = NULL; |
| 411 | if (wpa_s->l2_br) { |
| 412 | l2_packet_deinit(wpa_s->l2_br); |
| 413 | wpa_s->l2_br = NULL; |
| 414 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 415 | #ifdef CONFIG_TESTING_OPTIONS |
| 416 | l2_packet_deinit(wpa_s->l2_test); |
| 417 | wpa_s->l2_test = NULL; |
| 418 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 419 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 420 | if (wpa_s->conf != NULL) { |
| 421 | struct wpa_ssid *ssid; |
| 422 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
| 423 | wpas_notify_network_removed(wpa_s, ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | os_free(wpa_s->confname); |
| 427 | wpa_s->confname = NULL; |
| 428 | |
Jouni Malinen | 5d1c8ad | 2013-04-23 12:34:56 -0700 | [diff] [blame] | 429 | os_free(wpa_s->confanother); |
| 430 | wpa_s->confanother = NULL; |
| 431 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 432 | wpa_sm_set_eapol(wpa_s->wpa, NULL); |
| 433 | eapol_sm_deinit(wpa_s->eapol); |
| 434 | wpa_s->eapol = NULL; |
| 435 | |
| 436 | rsn_preauth_deinit(wpa_s->wpa); |
| 437 | |
| 438 | #ifdef CONFIG_TDLS |
| 439 | wpa_tdls_deinit(wpa_s->wpa); |
| 440 | #endif /* CONFIG_TDLS */ |
| 441 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 442 | wmm_ac_clear_saved_tspecs(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 | pmksa_candidate_free(wpa_s->wpa); |
| 444 | wpa_sm_deinit(wpa_s->wpa); |
| 445 | wpa_s->wpa = NULL; |
| 446 | wpa_blacklist_clear(wpa_s); |
| 447 | |
| 448 | wpa_bss_deinit(wpa_s); |
| 449 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 450 | wpa_supplicant_cancel_delayed_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 451 | wpa_supplicant_cancel_scan(wpa_s); |
| 452 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 453 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL); |
| 454 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
| 455 | eloop_cancel_timeout(wpa_supplicant_delayed_mic_error_report, |
| 456 | wpa_s, NULL); |
| 457 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 458 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 459 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
| 460 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 461 | wpas_wps_deinit(wpa_s); |
| 462 | |
| 463 | wpabuf_free(wpa_s->pending_eapol_rx); |
| 464 | wpa_s->pending_eapol_rx = NULL; |
| 465 | |
| 466 | #ifdef CONFIG_IBSS_RSN |
| 467 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
| 468 | wpa_s->ibss_rsn = NULL; |
| 469 | #endif /* CONFIG_IBSS_RSN */ |
| 470 | |
| 471 | sme_deinit(wpa_s); |
| 472 | |
| 473 | #ifdef CONFIG_AP |
| 474 | wpa_supplicant_ap_deinit(wpa_s); |
| 475 | #endif /* CONFIG_AP */ |
| 476 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 477 | wpas_p2p_deinit(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 478 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 479 | #ifdef CONFIG_OFFCHANNEL |
| 480 | offchannel_deinit(wpa_s); |
| 481 | #endif /* CONFIG_OFFCHANNEL */ |
| 482 | |
| 483 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 484 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 485 | os_free(wpa_s->next_scan_freqs); |
| 486 | wpa_s->next_scan_freqs = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 487 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 488 | os_free(wpa_s->manual_scan_freqs); |
| 489 | wpa_s->manual_scan_freqs = NULL; |
| 490 | |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 491 | os_free(wpa_s->manual_sched_scan_freqs); |
| 492 | wpa_s->manual_sched_scan_freqs = NULL; |
| 493 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 494 | wpas_mac_addr_rand_scan_clear(wpa_s, MAC_ADDR_RAND_ALL); |
| 495 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame^] | 496 | /* |
| 497 | * Need to remove any pending gas-query radio work before the |
| 498 | * gas_query_deinit() call because gas_query::work has not yet been set |
| 499 | * for works that have not been started. gas_query_free() will be unable |
| 500 | * to cancel such pending radio works and once the pending gas-query |
| 501 | * radio work eventually gets removed, the deinit notification call to |
| 502 | * gas_query_start_cb() would result in dereferencing freed memory. |
| 503 | */ |
| 504 | if (wpa_s->radio) |
| 505 | radio_remove_works(wpa_s, "gas-query", 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 506 | gas_query_deinit(wpa_s->gas); |
| 507 | wpa_s->gas = NULL; |
| 508 | |
| 509 | free_hw_features(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 510 | |
Dmitry Shmidt | 5a1480c | 2014-05-12 09:46:02 -0700 | [diff] [blame] | 511 | ieee802_1x_dealloc_kay_sm(wpa_s); |
| 512 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 513 | os_free(wpa_s->bssid_filter); |
| 514 | wpa_s->bssid_filter = NULL; |
| 515 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 516 | os_free(wpa_s->disallow_aps_bssid); |
| 517 | wpa_s->disallow_aps_bssid = NULL; |
| 518 | os_free(wpa_s->disallow_aps_ssid); |
| 519 | wpa_s->disallow_aps_ssid = NULL; |
| 520 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 521 | wnm_bss_keep_alive_deinit(wpa_s); |
Dmitry Shmidt | 44c9578 | 2013-05-17 09:51:35 -0700 | [diff] [blame] | 522 | #ifdef CONFIG_WNM |
| 523 | wnm_deallocate_memory(wpa_s); |
| 524 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 525 | |
| 526 | ext_password_deinit(wpa_s->ext_pw); |
| 527 | wpa_s->ext_pw = NULL; |
| 528 | |
| 529 | wpabuf_free(wpa_s->last_gas_resp); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 530 | wpa_s->last_gas_resp = NULL; |
| 531 | wpabuf_free(wpa_s->prev_gas_resp); |
| 532 | wpa_s->prev_gas_resp = NULL; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 533 | |
| 534 | os_free(wpa_s->last_scan_res); |
| 535 | wpa_s->last_scan_res = NULL; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 536 | |
| 537 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 684785c | 2014-05-12 13:34:29 -0700 | [diff] [blame] | 538 | hs20_deinit(wpa_s); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 539 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 2e67f06 | 2014-07-16 09:55:28 -0700 | [diff] [blame] | 540 | |
| 541 | for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) { |
| 542 | wpabuf_free(wpa_s->vendor_elem[i]); |
| 543 | wpa_s->vendor_elem[i] = NULL; |
| 544 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 545 | |
| 546 | wmm_ac_notify_disassoc(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | |
| 550 | /** |
| 551 | * wpa_clear_keys - Clear keys configured for the driver |
| 552 | * @wpa_s: Pointer to wpa_supplicant data |
| 553 | * @addr: Previously used BSSID or %NULL if not available |
| 554 | * |
| 555 | * This function clears the encryption keys that has been previously configured |
| 556 | * for the driver. |
| 557 | */ |
| 558 | void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr) |
| 559 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 560 | int i, max; |
| 561 | |
| 562 | #ifdef CONFIG_IEEE80211W |
| 563 | max = 6; |
| 564 | #else /* CONFIG_IEEE80211W */ |
| 565 | max = 4; |
| 566 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 567 | |
| 568 | /* MLME-DELETEKEYS.request */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 569 | for (i = 0; i < max; i++) { |
| 570 | if (wpa_s->keys_cleared & BIT(i)) |
| 571 | continue; |
| 572 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, i, 0, NULL, 0, |
| 573 | NULL, 0); |
| 574 | } |
| 575 | if (!(wpa_s->keys_cleared & BIT(0)) && addr && |
| 576 | !is_zero_ether_addr(addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 577 | wpa_drv_set_key(wpa_s, WPA_ALG_NONE, addr, 0, 0, NULL, 0, NULL, |
| 578 | 0); |
| 579 | /* MLME-SETPROTECTION.request(None) */ |
| 580 | wpa_drv_mlme_setprotection( |
| 581 | wpa_s, addr, |
| 582 | MLME_SETPROTECTION_PROTECT_TYPE_NONE, |
| 583 | MLME_SETPROTECTION_KEY_TYPE_PAIRWISE); |
| 584 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 585 | wpa_s->keys_cleared = (u32) -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | |
| 589 | /** |
| 590 | * wpa_supplicant_state_txt - Get the connection state name as a text string |
| 591 | * @state: State (wpa_state; WPA_*) |
| 592 | * Returns: The state name as a printable text string |
| 593 | */ |
| 594 | const char * wpa_supplicant_state_txt(enum wpa_states state) |
| 595 | { |
| 596 | switch (state) { |
| 597 | case WPA_DISCONNECTED: |
| 598 | return "DISCONNECTED"; |
| 599 | case WPA_INACTIVE: |
| 600 | return "INACTIVE"; |
| 601 | case WPA_INTERFACE_DISABLED: |
| 602 | return "INTERFACE_DISABLED"; |
| 603 | case WPA_SCANNING: |
| 604 | return "SCANNING"; |
| 605 | case WPA_AUTHENTICATING: |
| 606 | return "AUTHENTICATING"; |
| 607 | case WPA_ASSOCIATING: |
| 608 | return "ASSOCIATING"; |
| 609 | case WPA_ASSOCIATED: |
| 610 | return "ASSOCIATED"; |
| 611 | case WPA_4WAY_HANDSHAKE: |
| 612 | return "4WAY_HANDSHAKE"; |
| 613 | case WPA_GROUP_HANDSHAKE: |
| 614 | return "GROUP_HANDSHAKE"; |
| 615 | case WPA_COMPLETED: |
| 616 | return "COMPLETED"; |
| 617 | default: |
| 618 | return "UNKNOWN"; |
| 619 | } |
| 620 | } |
| 621 | |
| 622 | |
| 623 | #ifdef CONFIG_BGSCAN |
| 624 | |
| 625 | static void wpa_supplicant_start_bgscan(struct wpa_supplicant *wpa_s) |
| 626 | { |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 627 | const char *name; |
| 628 | |
| 629 | if (wpa_s->current_ssid && wpa_s->current_ssid->bgscan) |
| 630 | name = wpa_s->current_ssid->bgscan; |
| 631 | else |
| 632 | name = wpa_s->conf->bgscan; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 633 | if (name == NULL || name[0] == '\0') |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 634 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 635 | if (wpas_driver_bss_selection(wpa_s)) |
| 636 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 637 | if (wpa_s->current_ssid == wpa_s->bgscan_ssid) |
| 638 | return; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 639 | #ifdef CONFIG_P2P |
| 640 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE) |
| 641 | return; |
| 642 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 643 | |
| 644 | bgscan_deinit(wpa_s); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 645 | if (wpa_s->current_ssid) { |
| 646 | if (bgscan_init(wpa_s, wpa_s->current_ssid, name)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 647 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize " |
| 648 | "bgscan"); |
| 649 | /* |
| 650 | * Live without bgscan; it is only used as a roaming |
| 651 | * optimization, so the initial connection is not |
| 652 | * affected. |
| 653 | */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 654 | } else { |
| 655 | struct wpa_scan_results *scan_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 656 | wpa_s->bgscan_ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 657 | scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, |
| 658 | 0); |
| 659 | if (scan_res) { |
| 660 | bgscan_notify_scan(wpa_s, scan_res); |
| 661 | wpa_scan_results_free(scan_res); |
| 662 | } |
| 663 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 664 | } else |
| 665 | wpa_s->bgscan_ssid = NULL; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | static void wpa_supplicant_stop_bgscan(struct wpa_supplicant *wpa_s) |
| 670 | { |
| 671 | if (wpa_s->bgscan_ssid != NULL) { |
| 672 | bgscan_deinit(wpa_s); |
| 673 | wpa_s->bgscan_ssid = NULL; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | #endif /* CONFIG_BGSCAN */ |
| 678 | |
| 679 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 680 | static void wpa_supplicant_start_autoscan(struct wpa_supplicant *wpa_s) |
| 681 | { |
| 682 | if (autoscan_init(wpa_s, 0)) |
| 683 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize autoscan"); |
| 684 | } |
| 685 | |
| 686 | |
| 687 | static void wpa_supplicant_stop_autoscan(struct wpa_supplicant *wpa_s) |
| 688 | { |
| 689 | autoscan_deinit(wpa_s); |
| 690 | } |
| 691 | |
| 692 | |
| 693 | void wpa_supplicant_reinit_autoscan(struct wpa_supplicant *wpa_s) |
| 694 | { |
| 695 | if (wpa_s->wpa_state == WPA_DISCONNECTED || |
| 696 | wpa_s->wpa_state == WPA_SCANNING) { |
| 697 | autoscan_deinit(wpa_s); |
| 698 | wpa_supplicant_start_autoscan(wpa_s); |
| 699 | } |
| 700 | } |
| 701 | |
| 702 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 703 | /** |
| 704 | * wpa_supplicant_set_state - Set current connection state |
| 705 | * @wpa_s: Pointer to wpa_supplicant data |
| 706 | * @state: The new connection state |
| 707 | * |
| 708 | * This function is called whenever the connection state changes, e.g., |
| 709 | * association is completed for WPA/WPA2 4-Way Handshake is started. |
| 710 | */ |
| 711 | void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, |
| 712 | enum wpa_states state) |
| 713 | { |
| 714 | enum wpa_states old_state = wpa_s->wpa_state; |
| 715 | |
| 716 | wpa_dbg(wpa_s, MSG_DEBUG, "State: %s -> %s", |
| 717 | wpa_supplicant_state_txt(wpa_s->wpa_state), |
| 718 | wpa_supplicant_state_txt(state)); |
| 719 | |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 720 | if (state == WPA_INTERFACE_DISABLED) { |
| 721 | /* Assure normal scan when interface is restored */ |
| 722 | wpa_s->normal_scans = 0; |
| 723 | } |
| 724 | |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 725 | if (state == WPA_COMPLETED) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 726 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 727 | /* Reinitialize normal_scan counter */ |
| 728 | wpa_s->normal_scans = 0; |
| 729 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 730 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 731 | if (state != WPA_SCANNING) |
| 732 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 733 | |
| 734 | if (state == WPA_COMPLETED && wpa_s->new_connection) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 735 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 736 | #if defined(CONFIG_CTRL_IFACE) || !defined(CONFIG_NO_STDOUT_DEBUG) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 737 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED "- Connection to " |
Dmitry Shmidt | 8f0dbf4 | 2013-11-08 13:35:41 -0800 | [diff] [blame] | 738 | MACSTR " completed [id=%d id_str=%s]", |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 739 | MAC2STR(wpa_s->bssid), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 740 | ssid ? ssid->id : -1, |
| 741 | ssid && ssid->id_str ? ssid->id_str : ""); |
| 742 | #endif /* CONFIG_CTRL_IFACE || !CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 743 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
Dmitry Shmidt | af9da31 | 2015-04-03 10:03:11 -0700 | [diff] [blame] | 744 | wpa_blacklist_clear(wpa_s); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 745 | wpa_s->extra_blacklist_count = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 746 | wpa_s->new_connection = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 747 | wpa_drv_set_operstate(wpa_s, 1); |
| 748 | #ifndef IEEE8021X_EAPOL |
| 749 | wpa_drv_set_supp_port(wpa_s, 1); |
| 750 | #endif /* IEEE8021X_EAPOL */ |
| 751 | wpa_s->after_wps = 0; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 752 | wpa_s->known_wps_freq = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 753 | wpas_p2p_completed(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 754 | |
| 755 | sme_sched_obss_scan(wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 756 | } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING || |
| 757 | state == WPA_ASSOCIATED) { |
| 758 | wpa_s->new_connection = 1; |
| 759 | wpa_drv_set_operstate(wpa_s, 0); |
| 760 | #ifndef IEEE8021X_EAPOL |
| 761 | wpa_drv_set_supp_port(wpa_s, 0); |
| 762 | #endif /* IEEE8021X_EAPOL */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 763 | sme_sched_obss_scan(wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 764 | } |
| 765 | wpa_s->wpa_state = state; |
| 766 | |
| 767 | #ifdef CONFIG_BGSCAN |
| 768 | if (state == WPA_COMPLETED) |
| 769 | wpa_supplicant_start_bgscan(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 770 | else if (state < WPA_ASSOCIATED) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 771 | wpa_supplicant_stop_bgscan(wpa_s); |
| 772 | #endif /* CONFIG_BGSCAN */ |
| 773 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 774 | if (state == WPA_AUTHENTICATING) |
| 775 | wpa_supplicant_stop_autoscan(wpa_s); |
| 776 | |
| 777 | if (state == WPA_DISCONNECTED || state == WPA_INACTIVE) |
| 778 | wpa_supplicant_start_autoscan(wpa_s); |
| 779 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 780 | if (old_state >= WPA_ASSOCIATED && wpa_s->wpa_state < WPA_ASSOCIATED) |
| 781 | wmm_ac_notify_disassoc(wpa_s); |
| 782 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 783 | if (wpa_s->wpa_state != old_state) { |
| 784 | wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state); |
| 785 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 786 | /* |
| 787 | * Notify the P2P Device interface about a state change in one |
| 788 | * of the interfaces. |
| 789 | */ |
| 790 | wpas_p2p_indicate_state_change(wpa_s); |
| 791 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 792 | if (wpa_s->wpa_state == WPA_COMPLETED || |
| 793 | old_state == WPA_COMPLETED) |
| 794 | wpas_notify_auth_changed(wpa_s); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | |
| 799 | void wpa_supplicant_terminate_proc(struct wpa_global *global) |
| 800 | { |
| 801 | int pending = 0; |
| 802 | #ifdef CONFIG_WPS |
| 803 | struct wpa_supplicant *wpa_s = global->ifaces; |
| 804 | while (wpa_s) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 805 | struct wpa_supplicant *next = wpa_s->next; |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 806 | if (wpas_wps_terminate_pending(wpa_s) == 1) |
| 807 | pending = 1; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 808 | #ifdef CONFIG_P2P |
| 809 | if (wpa_s->p2p_group_interface != NOT_P2P_GROUP_INTERFACE || |
| 810 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group)) |
| 811 | wpas_p2p_disconnect(wpa_s); |
| 812 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 813 | wpa_s = next; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 814 | } |
| 815 | #endif /* CONFIG_WPS */ |
| 816 | if (pending) |
| 817 | return; |
| 818 | eloop_terminate(); |
| 819 | } |
| 820 | |
| 821 | |
| 822 | static void wpa_supplicant_terminate(int sig, void *signal_ctx) |
| 823 | { |
| 824 | struct wpa_global *global = signal_ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 825 | wpa_supplicant_terminate_proc(global); |
| 826 | } |
| 827 | |
| 828 | |
| 829 | void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s) |
| 830 | { |
| 831 | enum wpa_states old_state = wpa_s->wpa_state; |
| 832 | |
| 833 | wpa_s->pairwise_cipher = 0; |
| 834 | wpa_s->group_cipher = 0; |
| 835 | wpa_s->mgmt_group_cipher = 0; |
| 836 | wpa_s->key_mgmt = 0; |
| 837 | if (wpa_s->wpa_state != WPA_INTERFACE_DISABLED) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 838 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 839 | |
| 840 | if (wpa_s->wpa_state != old_state) |
| 841 | wpas_notify_state_changed(wpa_s, wpa_s->wpa_state, old_state); |
| 842 | } |
| 843 | |
| 844 | |
| 845 | /** |
| 846 | * wpa_supplicant_reload_configuration - Reload configuration data |
| 847 | * @wpa_s: Pointer to wpa_supplicant data |
| 848 | * Returns: 0 on success or -1 if configuration parsing failed |
| 849 | * |
| 850 | * This function can be used to request that the configuration data is reloaded |
| 851 | * (e.g., after configuration file change). This function is reloading |
| 852 | * configuration only for one interface, so this may need to be called multiple |
| 853 | * times if %wpa_supplicant is controlling multiple interfaces and all |
| 854 | * interfaces need reconfiguration. |
| 855 | */ |
| 856 | int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s) |
| 857 | { |
| 858 | struct wpa_config *conf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 859 | int reconf_ctrl; |
| 860 | int old_ap_scan; |
| 861 | |
| 862 | if (wpa_s->confname == NULL) |
| 863 | return -1; |
Dmitry Shmidt | 64f47c5 | 2013-04-16 10:41:54 -0700 | [diff] [blame] | 864 | conf = wpa_config_read(wpa_s->confname, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 865 | if (conf == NULL) { |
| 866 | wpa_msg(wpa_s, MSG_ERROR, "Failed to parse the configuration " |
| 867 | "file '%s' - exiting", wpa_s->confname); |
| 868 | return -1; |
| 869 | } |
Dmitry Shmidt | 64f47c5 | 2013-04-16 10:41:54 -0700 | [diff] [blame] | 870 | wpa_config_read(wpa_s->confanother, conf); |
| 871 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 872 | conf->changed_parameters = (unsigned int) -1; |
| 873 | |
| 874 | reconf_ctrl = !!conf->ctrl_interface != !!wpa_s->conf->ctrl_interface |
| 875 | || (conf->ctrl_interface && wpa_s->conf->ctrl_interface && |
| 876 | os_strcmp(conf->ctrl_interface, |
| 877 | wpa_s->conf->ctrl_interface) != 0); |
| 878 | |
| 879 | if (reconf_ctrl && wpa_s->ctrl_iface) { |
| 880 | wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface); |
| 881 | wpa_s->ctrl_iface = NULL; |
| 882 | } |
| 883 | |
| 884 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 885 | if (wpa_s->current_ssid) { |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame^] | 886 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 887 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 888 | wpa_supplicant_deauthenticate(wpa_s, |
| 889 | WLAN_REASON_DEAUTH_LEAVING); |
| 890 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 891 | |
| 892 | /* |
| 893 | * TODO: should notify EAPOL SM about changes in opensc_engine_path, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 894 | * pkcs11_engine_path, pkcs11_module_path, openssl_ciphers. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 895 | */ |
| 896 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
| 897 | /* |
| 898 | * Clear forced success to clear EAP state for next |
| 899 | * authentication. |
| 900 | */ |
| 901 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
| 902 | } |
| 903 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
| 904 | wpa_sm_set_config(wpa_s->wpa, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 905 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 906 | wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth); |
| 907 | rsn_preauth_deinit(wpa_s->wpa); |
| 908 | |
| 909 | old_ap_scan = wpa_s->conf->ap_scan; |
| 910 | wpa_config_free(wpa_s->conf); |
| 911 | wpa_s->conf = conf; |
| 912 | if (old_ap_scan != wpa_s->conf->ap_scan) |
| 913 | wpas_notify_ap_scan_changed(wpa_s); |
| 914 | |
| 915 | if (reconf_ctrl) |
| 916 | wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s); |
| 917 | |
| 918 | wpa_supplicant_update_config(wpa_s); |
| 919 | |
| 920 | wpa_supplicant_clear_status(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 921 | if (wpa_supplicant_enabled_networks(wpa_s)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 922 | wpa_s->reassociate = 1; |
| 923 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 924 | } |
| 925 | wpa_dbg(wpa_s, MSG_DEBUG, "Reconfiguration completed"); |
| 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | |
| 930 | static void wpa_supplicant_reconfig(int sig, void *signal_ctx) |
| 931 | { |
| 932 | struct wpa_global *global = signal_ctx; |
| 933 | struct wpa_supplicant *wpa_s; |
| 934 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 935 | wpa_dbg(wpa_s, MSG_DEBUG, "Signal %d received - reconfiguring", |
| 936 | sig); |
| 937 | if (wpa_supplicant_reload_configuration(wpa_s) < 0) { |
| 938 | wpa_supplicant_terminate_proc(global); |
| 939 | } |
| 940 | } |
| 941 | } |
| 942 | |
| 943 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 944 | static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s, |
| 945 | struct wpa_ssid *ssid, |
| 946 | struct wpa_ie_data *ie) |
| 947 | { |
| 948 | int ret = wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie); |
| 949 | if (ret) { |
| 950 | if (ret == -2) { |
| 951 | wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE " |
| 952 | "from association info"); |
| 953 | } |
| 954 | return -1; |
| 955 | } |
| 956 | |
| 957 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Using WPA IE from AssocReq to set " |
| 958 | "cipher suites"); |
| 959 | if (!(ie->group_cipher & ssid->group_cipher)) { |
| 960 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled group " |
| 961 | "cipher 0x%x (mask 0x%x) - reject", |
| 962 | ie->group_cipher, ssid->group_cipher); |
| 963 | return -1; |
| 964 | } |
| 965 | if (!(ie->pairwise_cipher & ssid->pairwise_cipher)) { |
| 966 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled pairwise " |
| 967 | "cipher 0x%x (mask 0x%x) - reject", |
| 968 | ie->pairwise_cipher, ssid->pairwise_cipher); |
| 969 | return -1; |
| 970 | } |
| 971 | if (!(ie->key_mgmt & ssid->key_mgmt)) { |
| 972 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver used disabled key " |
| 973 | "management 0x%x (mask 0x%x) - reject", |
| 974 | ie->key_mgmt, ssid->key_mgmt); |
| 975 | return -1; |
| 976 | } |
| 977 | |
| 978 | #ifdef CONFIG_IEEE80211W |
| 979 | if (!(ie->capabilities & WPA_CAPABILITY_MFPC) && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 980 | wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 981 | wpa_msg(wpa_s, MSG_INFO, "WPA: Driver associated with an AP " |
| 982 | "that does not support management frame protection - " |
| 983 | "reject"); |
| 984 | return -1; |
| 985 | } |
| 986 | #endif /* CONFIG_IEEE80211W */ |
| 987 | |
| 988 | return 0; |
| 989 | } |
| 990 | |
| 991 | |
| 992 | /** |
| 993 | * wpa_supplicant_set_suites - Set authentication and encryption parameters |
| 994 | * @wpa_s: Pointer to wpa_supplicant data |
| 995 | * @bss: Scan results for the selected BSS, or %NULL if not available |
| 996 | * @ssid: Configuration data for the selected network |
| 997 | * @wpa_ie: Buffer for the WPA/RSN IE |
| 998 | * @wpa_ie_len: Maximum wpa_ie buffer size on input. This is changed to be the |
| 999 | * used buffer length in case the functions returns success. |
| 1000 | * Returns: 0 on success or -1 on failure |
| 1001 | * |
| 1002 | * This function is used to configure authentication and encryption parameters |
| 1003 | * based on the network configuration and scan result for the selected BSS (if |
| 1004 | * available). |
| 1005 | */ |
| 1006 | int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s, |
| 1007 | struct wpa_bss *bss, struct wpa_ssid *ssid, |
| 1008 | u8 *wpa_ie, size_t *wpa_ie_len) |
| 1009 | { |
| 1010 | struct wpa_ie_data ie; |
| 1011 | int sel, proto; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1012 | const u8 *bss_wpa, *bss_rsn, *bss_osen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1013 | |
| 1014 | if (bss) { |
| 1015 | bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 1016 | bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1017 | bss_osen = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1018 | } else |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1019 | bss_wpa = bss_rsn = bss_osen = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1020 | |
| 1021 | if (bss_rsn && (ssid->proto & WPA_PROTO_RSN) && |
| 1022 | wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie) == 0 && |
| 1023 | (ie.group_cipher & ssid->group_cipher) && |
| 1024 | (ie.pairwise_cipher & ssid->pairwise_cipher) && |
| 1025 | (ie.key_mgmt & ssid->key_mgmt)) { |
| 1026 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using IEEE 802.11i/D9.0"); |
| 1027 | proto = WPA_PROTO_RSN; |
| 1028 | } else if (bss_wpa && (ssid->proto & WPA_PROTO_WPA) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1029 | wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie) == 0 && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1030 | (ie.group_cipher & ssid->group_cipher) && |
| 1031 | (ie.pairwise_cipher & ssid->pairwise_cipher) && |
| 1032 | (ie.key_mgmt & ssid->key_mgmt)) { |
| 1033 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using IEEE 802.11i/D3.0"); |
| 1034 | proto = WPA_PROTO_WPA; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1035 | #ifdef CONFIG_HS20 |
| 1036 | } else if (bss_osen && (ssid->proto & WPA_PROTO_OSEN)) { |
| 1037 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using OSEN"); |
| 1038 | /* TODO: parse OSEN element */ |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 1039 | os_memset(&ie, 0, sizeof(ie)); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1040 | ie.group_cipher = WPA_CIPHER_CCMP; |
| 1041 | ie.pairwise_cipher = WPA_CIPHER_CCMP; |
| 1042 | ie.key_mgmt = WPA_KEY_MGMT_OSEN; |
| 1043 | proto = WPA_PROTO_OSEN; |
| 1044 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1045 | } else if (bss) { |
| 1046 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select WPA/RSN"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1047 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1048 | "WPA: ssid proto=0x%x pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", |
| 1049 | ssid->proto, ssid->pairwise_cipher, ssid->group_cipher, |
| 1050 | ssid->key_mgmt); |
| 1051 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: BSS " MACSTR " ssid='%s'%s%s%s", |
| 1052 | MAC2STR(bss->bssid), |
| 1053 | wpa_ssid_txt(bss->ssid, bss->ssid_len), |
| 1054 | bss_wpa ? " WPA" : "", |
| 1055 | bss_rsn ? " RSN" : "", |
| 1056 | bss_osen ? " OSEN" : ""); |
| 1057 | if (bss_rsn) { |
| 1058 | wpa_hexdump(MSG_DEBUG, "RSN", bss_rsn, 2 + bss_rsn[1]); |
| 1059 | if (wpa_parse_wpa_ie(bss_rsn, 2 + bss_rsn[1], &ie)) { |
| 1060 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1061 | "Could not parse RSN element"); |
| 1062 | } else { |
| 1063 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1064 | "RSN: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", |
| 1065 | ie.pairwise_cipher, ie.group_cipher, |
| 1066 | ie.key_mgmt); |
| 1067 | } |
| 1068 | } |
| 1069 | if (bss_wpa) { |
| 1070 | wpa_hexdump(MSG_DEBUG, "WPA", bss_wpa, 2 + bss_wpa[1]); |
| 1071 | if (wpa_parse_wpa_ie(bss_wpa, 2 + bss_wpa[1], &ie)) { |
| 1072 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1073 | "Could not parse WPA element"); |
| 1074 | } else { |
| 1075 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1076 | "WPA: pairwise_cipher=0x%x group_cipher=0x%x key_mgmt=0x%x", |
| 1077 | ie.pairwise_cipher, ie.group_cipher, |
| 1078 | ie.key_mgmt); |
| 1079 | } |
| 1080 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1081 | return -1; |
| 1082 | } else { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1083 | if (ssid->proto & WPA_PROTO_OSEN) |
| 1084 | proto = WPA_PROTO_OSEN; |
| 1085 | else if (ssid->proto & WPA_PROTO_RSN) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1086 | proto = WPA_PROTO_RSN; |
| 1087 | else |
| 1088 | proto = WPA_PROTO_WPA; |
| 1089 | if (wpa_supplicant_suites_from_ai(wpa_s, ssid, &ie) < 0) { |
| 1090 | os_memset(&ie, 0, sizeof(ie)); |
| 1091 | ie.group_cipher = ssid->group_cipher; |
| 1092 | ie.pairwise_cipher = ssid->pairwise_cipher; |
| 1093 | ie.key_mgmt = ssid->key_mgmt; |
| 1094 | #ifdef CONFIG_IEEE80211W |
| 1095 | ie.mgmt_group_cipher = |
| 1096 | ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION ? |
| 1097 | WPA_CIPHER_AES_128_CMAC : 0; |
| 1098 | #endif /* CONFIG_IEEE80211W */ |
| 1099 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Set cipher suites " |
| 1100 | "based on configuration"); |
| 1101 | } else |
| 1102 | proto = ie.proto; |
| 1103 | } |
| 1104 | |
| 1105 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected cipher suites: group %d " |
| 1106 | "pairwise %d key_mgmt %d proto %d", |
| 1107 | ie.group_cipher, ie.pairwise_cipher, ie.key_mgmt, proto); |
| 1108 | #ifdef CONFIG_IEEE80211W |
| 1109 | if (ssid->ieee80211w) { |
| 1110 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected mgmt group cipher %d", |
| 1111 | ie.mgmt_group_cipher); |
| 1112 | } |
| 1113 | #endif /* CONFIG_IEEE80211W */ |
| 1114 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1115 | wpa_s->wpa_proto = proto; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1116 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, proto); |
| 1117 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1118 | !!(ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN))); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1119 | |
| 1120 | if (bss || !wpa_s->ap_ies_from_associnfo) { |
| 1121 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, |
| 1122 | bss_wpa ? 2 + bss_wpa[1] : 0) || |
| 1123 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, |
| 1124 | bss_rsn ? 2 + bss_rsn[1] : 0)) |
| 1125 | return -1; |
| 1126 | } |
| 1127 | |
| 1128 | sel = ie.group_cipher & ssid->group_cipher; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1129 | wpa_s->group_cipher = wpa_pick_group_cipher(sel); |
| 1130 | if (wpa_s->group_cipher < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1131 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select group " |
| 1132 | "cipher"); |
| 1133 | return -1; |
| 1134 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1135 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s", |
| 1136 | wpa_cipher_txt(wpa_s->group_cipher)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1137 | |
| 1138 | sel = ie.pairwise_cipher & ssid->pairwise_cipher; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1139 | wpa_s->pairwise_cipher = wpa_pick_pairwise_cipher(sel, 1); |
| 1140 | if (wpa_s->pairwise_cipher < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1141 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select pairwise " |
| 1142 | "cipher"); |
| 1143 | return -1; |
| 1144 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1145 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s", |
| 1146 | wpa_cipher_txt(wpa_s->pairwise_cipher)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1147 | |
| 1148 | sel = ie.key_mgmt & ssid->key_mgmt; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1149 | #ifdef CONFIG_SAE |
| 1150 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) |
| 1151 | sel &= ~(WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE); |
| 1152 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1153 | if (0) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1154 | #ifdef CONFIG_SUITEB192 |
| 1155 | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
| 1156 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B_192; |
| 1157 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1158 | "WPA: using KEY_MGMT 802.1X with Suite B (192-bit)"); |
| 1159 | #endif /* CONFIG_SUITEB192 */ |
| 1160 | #ifdef CONFIG_SUITEB |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1161 | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SUITE_B) { |
| 1162 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SUITE_B; |
| 1163 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1164 | "WPA: using KEY_MGMT 802.1X with Suite B"); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1165 | #endif /* CONFIG_SUITEB */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1166 | #ifdef CONFIG_IEEE80211R |
| 1167 | } else if (sel & WPA_KEY_MGMT_FT_IEEE8021X) { |
| 1168 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_IEEE8021X; |
| 1169 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/802.1X"); |
| 1170 | } else if (sel & WPA_KEY_MGMT_FT_PSK) { |
| 1171 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_PSK; |
| 1172 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT FT/PSK"); |
| 1173 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1174 | #ifdef CONFIG_SAE |
| 1175 | } else if (sel & WPA_KEY_MGMT_SAE) { |
| 1176 | wpa_s->key_mgmt = WPA_KEY_MGMT_SAE; |
| 1177 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT SAE"); |
| 1178 | } else if (sel & WPA_KEY_MGMT_FT_SAE) { |
| 1179 | wpa_s->key_mgmt = WPA_KEY_MGMT_FT_SAE; |
| 1180 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: using KEY_MGMT FT/SAE"); |
| 1181 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1182 | #ifdef CONFIG_IEEE80211W |
| 1183 | } else if (sel & WPA_KEY_MGMT_IEEE8021X_SHA256) { |
| 1184 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X_SHA256; |
| 1185 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1186 | "WPA: using KEY_MGMT 802.1X with SHA256"); |
| 1187 | } else if (sel & WPA_KEY_MGMT_PSK_SHA256) { |
| 1188 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK_SHA256; |
| 1189 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1190 | "WPA: using KEY_MGMT PSK with SHA256"); |
| 1191 | #endif /* CONFIG_IEEE80211W */ |
| 1192 | } else if (sel & WPA_KEY_MGMT_IEEE8021X) { |
| 1193 | wpa_s->key_mgmt = WPA_KEY_MGMT_IEEE8021X; |
| 1194 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT 802.1X"); |
| 1195 | } else if (sel & WPA_KEY_MGMT_PSK) { |
| 1196 | wpa_s->key_mgmt = WPA_KEY_MGMT_PSK; |
| 1197 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-PSK"); |
| 1198 | } else if (sel & WPA_KEY_MGMT_WPA_NONE) { |
| 1199 | wpa_s->key_mgmt = WPA_KEY_MGMT_WPA_NONE; |
| 1200 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT WPA-NONE"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1201 | #ifdef CONFIG_HS20 |
| 1202 | } else if (sel & WPA_KEY_MGMT_OSEN) { |
| 1203 | wpa_s->key_mgmt = WPA_KEY_MGMT_OSEN; |
| 1204 | wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: using KEY_MGMT OSEN"); |
| 1205 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1206 | } else { |
| 1207 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to select " |
| 1208 | "authenticated key management type"); |
| 1209 | return -1; |
| 1210 | } |
| 1211 | |
| 1212 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
| 1213 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
| 1214 | wpa_s->pairwise_cipher); |
| 1215 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); |
| 1216 | |
| 1217 | #ifdef CONFIG_IEEE80211W |
| 1218 | sel = ie.mgmt_group_cipher; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1219 | if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1220 | !(ie.capabilities & WPA_CAPABILITY_MFPC)) |
| 1221 | sel = 0; |
| 1222 | if (sel & WPA_CIPHER_AES_128_CMAC) { |
| 1223 | wpa_s->mgmt_group_cipher = WPA_CIPHER_AES_128_CMAC; |
| 1224 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " |
| 1225 | "AES-128-CMAC"); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1226 | } else if (sel & WPA_CIPHER_BIP_GMAC_128) { |
| 1227 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_128; |
| 1228 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " |
| 1229 | "BIP-GMAC-128"); |
| 1230 | } else if (sel & WPA_CIPHER_BIP_GMAC_256) { |
| 1231 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_GMAC_256; |
| 1232 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " |
| 1233 | "BIP-GMAC-256"); |
| 1234 | } else if (sel & WPA_CIPHER_BIP_CMAC_256) { |
| 1235 | wpa_s->mgmt_group_cipher = WPA_CIPHER_BIP_CMAC_256; |
| 1236 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher " |
| 1237 | "BIP-CMAC-256"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1238 | } else { |
| 1239 | wpa_s->mgmt_group_cipher = 0; |
| 1240 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher"); |
| 1241 | } |
| 1242 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, |
| 1243 | wpa_s->mgmt_group_cipher); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1244 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1245 | wpas_get_ssid_pmf(wpa_s, ssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1246 | #endif /* CONFIG_IEEE80211W */ |
| 1247 | |
| 1248 | if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) { |
| 1249 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to generate WPA IE"); |
| 1250 | return -1; |
| 1251 | } |
| 1252 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1253 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt)) { |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1254 | int psk_set = 0; |
| 1255 | |
| 1256 | if (ssid->psk_set) { |
| 1257 | wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL); |
| 1258 | psk_set = 1; |
| 1259 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1260 | #ifndef CONFIG_NO_PBKDF2 |
| 1261 | if (bss && ssid->bssid_set && ssid->ssid_len == 0 && |
| 1262 | ssid->passphrase) { |
| 1263 | u8 psk[PMK_LEN]; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1264 | pbkdf2_sha1(ssid->passphrase, bss->ssid, bss->ssid_len, |
| 1265 | 4096, psk, PMK_LEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1266 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (from passphrase)", |
| 1267 | psk, PMK_LEN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1268 | wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1269 | psk_set = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1270 | os_memset(psk, 0, sizeof(psk)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1271 | } |
| 1272 | #endif /* CONFIG_NO_PBKDF2 */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1273 | #ifdef CONFIG_EXT_PASSWORD |
| 1274 | if (ssid->ext_psk) { |
| 1275 | struct wpabuf *pw = ext_password_get(wpa_s->ext_pw, |
| 1276 | ssid->ext_psk); |
| 1277 | char pw_str[64 + 1]; |
| 1278 | u8 psk[PMK_LEN]; |
| 1279 | |
| 1280 | if (pw == NULL) { |
| 1281 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: No PSK " |
| 1282 | "found from external storage"); |
| 1283 | return -1; |
| 1284 | } |
| 1285 | |
| 1286 | if (wpabuf_len(pw) < 8 || wpabuf_len(pw) > 64) { |
| 1287 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: Unexpected " |
| 1288 | "PSK length %d in external storage", |
| 1289 | (int) wpabuf_len(pw)); |
| 1290 | ext_password_free(pw); |
| 1291 | return -1; |
| 1292 | } |
| 1293 | |
| 1294 | os_memcpy(pw_str, wpabuf_head(pw), wpabuf_len(pw)); |
| 1295 | pw_str[wpabuf_len(pw)] = '\0'; |
| 1296 | |
| 1297 | #ifndef CONFIG_NO_PBKDF2 |
| 1298 | if (wpabuf_len(pw) >= 8 && wpabuf_len(pw) < 64 && bss) |
| 1299 | { |
| 1300 | pbkdf2_sha1(pw_str, bss->ssid, bss->ssid_len, |
| 1301 | 4096, psk, PMK_LEN); |
| 1302 | os_memset(pw_str, 0, sizeof(pw_str)); |
| 1303 | wpa_hexdump_key(MSG_MSGDUMP, "PSK (from " |
| 1304 | "external passphrase)", |
| 1305 | psk, PMK_LEN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1306 | wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1307 | psk_set = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1308 | os_memset(psk, 0, sizeof(psk)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1309 | } else |
| 1310 | #endif /* CONFIG_NO_PBKDF2 */ |
| 1311 | if (wpabuf_len(pw) == 2 * PMK_LEN) { |
| 1312 | if (hexstr2bin(pw_str, psk, PMK_LEN) < 0) { |
| 1313 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: " |
| 1314 | "Invalid PSK hex string"); |
| 1315 | os_memset(pw_str, 0, sizeof(pw_str)); |
| 1316 | ext_password_free(pw); |
| 1317 | return -1; |
| 1318 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1319 | wpa_sm_set_pmk(wpa_s->wpa, psk, PMK_LEN, NULL); |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1320 | psk_set = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1321 | os_memset(psk, 0, sizeof(psk)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1322 | } else { |
| 1323 | wpa_msg(wpa_s, MSG_INFO, "EXT PW: No suitable " |
| 1324 | "PSK available"); |
| 1325 | os_memset(pw_str, 0, sizeof(pw_str)); |
| 1326 | ext_password_free(pw); |
| 1327 | return -1; |
| 1328 | } |
| 1329 | |
| 1330 | os_memset(pw_str, 0, sizeof(pw_str)); |
| 1331 | ext_password_free(pw); |
| 1332 | } |
| 1333 | #endif /* CONFIG_EXT_PASSWORD */ |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1334 | |
| 1335 | if (!psk_set) { |
| 1336 | wpa_msg(wpa_s, MSG_INFO, |
| 1337 | "No PSK available for association"); |
| 1338 | return -1; |
| 1339 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1340 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1341 | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
| 1342 | |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1347 | static void wpas_ext_capab_byte(struct wpa_supplicant *wpa_s, u8 *pos, int idx) |
| 1348 | { |
| 1349 | *pos = 0x00; |
| 1350 | |
| 1351 | switch (idx) { |
| 1352 | case 0: /* Bits 0-7 */ |
| 1353 | break; |
| 1354 | case 1: /* Bits 8-15 */ |
| 1355 | break; |
| 1356 | case 2: /* Bits 16-23 */ |
| 1357 | #ifdef CONFIG_WNM |
| 1358 | *pos |= 0x02; /* Bit 17 - WNM-Sleep Mode */ |
| 1359 | *pos |= 0x08; /* Bit 19 - BSS Transition */ |
| 1360 | #endif /* CONFIG_WNM */ |
| 1361 | break; |
| 1362 | case 3: /* Bits 24-31 */ |
| 1363 | #ifdef CONFIG_WNM |
| 1364 | *pos |= 0x02; /* Bit 25 - SSID List */ |
| 1365 | #endif /* CONFIG_WNM */ |
| 1366 | #ifdef CONFIG_INTERWORKING |
| 1367 | if (wpa_s->conf->interworking) |
| 1368 | *pos |= 0x80; /* Bit 31 - Interworking */ |
| 1369 | #endif /* CONFIG_INTERWORKING */ |
| 1370 | break; |
| 1371 | case 4: /* Bits 32-39 */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1372 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1373 | if (wpa_s->drv_flags / WPA_DRIVER_FLAGS_QOS_MAPPING) |
| 1374 | *pos |= 0x01; /* Bit 32 - QoS Map */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1375 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1376 | break; |
| 1377 | case 5: /* Bits 40-47 */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1378 | #ifdef CONFIG_HS20 |
| 1379 | if (wpa_s->conf->hs20) |
| 1380 | *pos |= 0x40; /* Bit 46 - WNM-Notification */ |
| 1381 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1382 | break; |
| 1383 | case 6: /* Bits 48-55 */ |
| 1384 | break; |
| 1385 | } |
| 1386 | } |
| 1387 | |
| 1388 | |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 1389 | int wpas_build_ext_capab(struct wpa_supplicant *wpa_s, u8 *buf, size_t buflen) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1390 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1391 | u8 *pos = buf; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1392 | u8 len = 6, i; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1393 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1394 | if (len < wpa_s->extended_capa_len) |
| 1395 | len = wpa_s->extended_capa_len; |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 1396 | if (buflen < (size_t) len + 2) { |
| 1397 | wpa_printf(MSG_INFO, |
| 1398 | "Not enough room for building extended capabilities element"); |
| 1399 | return -1; |
| 1400 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1401 | |
| 1402 | *pos++ = WLAN_EID_EXT_CAPAB; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1403 | *pos++ = len; |
| 1404 | for (i = 0; i < len; i++, pos++) { |
| 1405 | wpas_ext_capab_byte(wpa_s, pos, i); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1406 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1407 | if (i < wpa_s->extended_capa_len) { |
| 1408 | *pos &= ~wpa_s->extended_capa_mask[i]; |
| 1409 | *pos |= wpa_s->extended_capa[i]; |
| 1410 | } |
| 1411 | } |
| 1412 | |
| 1413 | while (len > 0 && buf[1 + len] == 0) { |
| 1414 | len--; |
| 1415 | buf[1] = len; |
| 1416 | } |
| 1417 | if (len == 0) |
| 1418 | return 0; |
| 1419 | |
| 1420 | return 2 + len; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1424 | static int wpas_valid_bss(struct wpa_supplicant *wpa_s, |
| 1425 | struct wpa_bss *test_bss) |
| 1426 | { |
| 1427 | struct wpa_bss *bss; |
| 1428 | |
| 1429 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1430 | if (bss == test_bss) |
| 1431 | return 1; |
| 1432 | } |
| 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | static int wpas_valid_ssid(struct wpa_supplicant *wpa_s, |
| 1439 | struct wpa_ssid *test_ssid) |
| 1440 | { |
| 1441 | struct wpa_ssid *ssid; |
| 1442 | |
| 1443 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1444 | if (ssid == test_ssid) |
| 1445 | return 1; |
| 1446 | } |
| 1447 | |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
| 1451 | |
| 1452 | int wpas_valid_bss_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *test_bss, |
| 1453 | struct wpa_ssid *test_ssid) |
| 1454 | { |
| 1455 | if (test_bss && !wpas_valid_bss(wpa_s, test_bss)) |
| 1456 | return 0; |
| 1457 | |
| 1458 | return test_ssid == NULL || wpas_valid_ssid(wpa_s, test_ssid); |
| 1459 | } |
| 1460 | |
| 1461 | |
| 1462 | void wpas_connect_work_free(struct wpa_connect_work *cwork) |
| 1463 | { |
| 1464 | if (cwork == NULL) |
| 1465 | return; |
| 1466 | os_free(cwork); |
| 1467 | } |
| 1468 | |
| 1469 | |
| 1470 | void wpas_connect_work_done(struct wpa_supplicant *wpa_s) |
| 1471 | { |
| 1472 | struct wpa_connect_work *cwork; |
| 1473 | struct wpa_radio_work *work = wpa_s->connect_work; |
| 1474 | |
| 1475 | if (!work) |
| 1476 | return; |
| 1477 | |
| 1478 | wpa_s->connect_work = NULL; |
| 1479 | cwork = work->ctx; |
| 1480 | work->ctx = NULL; |
| 1481 | wpas_connect_work_free(cwork); |
| 1482 | radio_work_done(work); |
| 1483 | } |
| 1484 | |
| 1485 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1486 | int wpas_update_random_addr(struct wpa_supplicant *wpa_s, int style) |
| 1487 | { |
| 1488 | struct os_reltime now; |
| 1489 | u8 addr[ETH_ALEN]; |
| 1490 | |
| 1491 | os_get_reltime(&now); |
| 1492 | if (wpa_s->last_mac_addr_style == style && |
| 1493 | wpa_s->last_mac_addr_change.sec != 0 && |
| 1494 | !os_reltime_expired(&now, &wpa_s->last_mac_addr_change, |
| 1495 | wpa_s->conf->rand_addr_lifetime)) { |
| 1496 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1497 | "Previously selected random MAC address has not yet expired"); |
| 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | switch (style) { |
| 1502 | case 1: |
| 1503 | if (random_mac_addr(addr) < 0) |
| 1504 | return -1; |
| 1505 | break; |
| 1506 | case 2: |
| 1507 | os_memcpy(addr, wpa_s->perm_addr, ETH_ALEN); |
| 1508 | if (random_mac_addr_keep_oui(addr) < 0) |
| 1509 | return -1; |
| 1510 | break; |
| 1511 | default: |
| 1512 | return -1; |
| 1513 | } |
| 1514 | |
| 1515 | if (wpa_drv_set_mac_addr(wpa_s, addr) < 0) { |
| 1516 | wpa_msg(wpa_s, MSG_INFO, |
| 1517 | "Failed to set random MAC address"); |
| 1518 | return -1; |
| 1519 | } |
| 1520 | |
| 1521 | os_get_reltime(&wpa_s->last_mac_addr_change); |
| 1522 | wpa_s->mac_addr_changed = 1; |
| 1523 | wpa_s->last_mac_addr_style = style; |
| 1524 | |
| 1525 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { |
| 1526 | wpa_msg(wpa_s, MSG_INFO, |
| 1527 | "Could not update MAC address information"); |
| 1528 | return -1; |
| 1529 | } |
| 1530 | |
| 1531 | wpa_msg(wpa_s, MSG_DEBUG, "Using random MAC address " MACSTR, |
| 1532 | MAC2STR(addr)); |
| 1533 | |
| 1534 | return 0; |
| 1535 | } |
| 1536 | |
| 1537 | |
| 1538 | int wpas_update_random_addr_disassoc(struct wpa_supplicant *wpa_s) |
| 1539 | { |
| 1540 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING || |
| 1541 | !wpa_s->conf->preassoc_mac_addr) |
| 1542 | return 0; |
| 1543 | |
| 1544 | return wpas_update_random_addr(wpa_s, wpa_s->conf->preassoc_mac_addr); |
| 1545 | } |
| 1546 | |
| 1547 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1548 | static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit); |
| 1549 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1550 | /** |
| 1551 | * wpa_supplicant_associate - Request association |
| 1552 | * @wpa_s: Pointer to wpa_supplicant data |
| 1553 | * @bss: Scan results for the selected BSS, or %NULL if not available |
| 1554 | * @ssid: Configuration data for the selected network |
| 1555 | * |
| 1556 | * This function is used to request %wpa_supplicant to associate with a BSS. |
| 1557 | */ |
| 1558 | void wpa_supplicant_associate(struct wpa_supplicant *wpa_s, |
| 1559 | struct wpa_bss *bss, struct wpa_ssid *ssid) |
| 1560 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1561 | struct wpa_connect_work *cwork; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1562 | int rand_style; |
| 1563 | |
| 1564 | if (ssid->mac_addr == -1) |
| 1565 | rand_style = wpa_s->conf->mac_addr; |
| 1566 | else |
| 1567 | rand_style = ssid->mac_addr; |
| 1568 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1569 | wmm_ac_clear_saved_tspecs(wpa_s); |
| 1570 | wpa_s->reassoc_same_bss = 0; |
| 1571 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1572 | if (wpa_s->last_ssid == ssid) { |
| 1573 | wpa_dbg(wpa_s, MSG_DEBUG, "Re-association to the same ESS"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1574 | if (wpa_s->current_bss && wpa_s->current_bss == bss) { |
| 1575 | wmm_ac_save_tspecs(wpa_s); |
| 1576 | wpa_s->reassoc_same_bss = 1; |
| 1577 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1578 | } else if (rand_style > 0) { |
| 1579 | if (wpas_update_random_addr(wpa_s, rand_style) < 0) |
| 1580 | return; |
| 1581 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid); |
| 1582 | } else if (wpa_s->mac_addr_changed) { |
| 1583 | if (wpa_drv_set_mac_addr(wpa_s, NULL) < 0) { |
| 1584 | wpa_msg(wpa_s, MSG_INFO, |
| 1585 | "Could not restore permanent MAC address"); |
| 1586 | return; |
| 1587 | } |
| 1588 | wpa_s->mac_addr_changed = 0; |
| 1589 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) { |
| 1590 | wpa_msg(wpa_s, MSG_INFO, |
| 1591 | "Could not update MAC address information"); |
| 1592 | return; |
| 1593 | } |
| 1594 | wpa_msg(wpa_s, MSG_DEBUG, "Using permanent MAC address"); |
| 1595 | } |
| 1596 | wpa_s->last_ssid = ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1597 | |
| 1598 | #ifdef CONFIG_IBSS_RSN |
| 1599 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
| 1600 | wpa_s->ibss_rsn = NULL; |
| 1601 | #endif /* CONFIG_IBSS_RSN */ |
| 1602 | |
| 1603 | if (ssid->mode == WPAS_MODE_AP || ssid->mode == WPAS_MODE_P2P_GO || |
| 1604 | ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) { |
| 1605 | #ifdef CONFIG_AP |
| 1606 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_AP)) { |
| 1607 | wpa_msg(wpa_s, MSG_INFO, "Driver does not support AP " |
| 1608 | "mode"); |
| 1609 | return; |
| 1610 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 1611 | if (wpa_supplicant_create_ap(wpa_s, ssid) < 0) { |
| 1612 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 1613 | if (ssid->mode == WPAS_MODE_P2P_GROUP_FORMATION) |
| 1614 | wpas_p2p_ap_setup_failed(wpa_s); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 1615 | return; |
| 1616 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1617 | wpa_s->current_bss = bss; |
| 1618 | #else /* CONFIG_AP */ |
| 1619 | wpa_msg(wpa_s, MSG_ERROR, "AP mode support not included in " |
| 1620 | "the build"); |
| 1621 | #endif /* CONFIG_AP */ |
| 1622 | return; |
| 1623 | } |
| 1624 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1625 | if (ssid->mode == WPAS_MODE_MESH) { |
| 1626 | #ifdef CONFIG_MESH |
| 1627 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_MESH)) { |
| 1628 | wpa_msg(wpa_s, MSG_INFO, |
| 1629 | "Driver does not support mesh mode"); |
| 1630 | return; |
| 1631 | } |
| 1632 | if (bss) |
| 1633 | ssid->frequency = bss->freq; |
| 1634 | if (wpa_supplicant_join_mesh(wpa_s, ssid) < 0) { |
| 1635 | wpa_msg(wpa_s, MSG_ERROR, "Could not join mesh"); |
| 1636 | return; |
| 1637 | } |
| 1638 | wpa_s->current_bss = bss; |
| 1639 | wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_GROUP_STARTED |
| 1640 | "ssid=\"%s\" id=%d", |
| 1641 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len), |
| 1642 | ssid->id); |
| 1643 | #else /* CONFIG_MESH */ |
| 1644 | wpa_msg(wpa_s, MSG_ERROR, |
| 1645 | "mesh mode support not included in the build"); |
| 1646 | #endif /* CONFIG_MESH */ |
| 1647 | return; |
| 1648 | } |
| 1649 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1650 | #ifdef CONFIG_TDLS |
| 1651 | if (bss) |
| 1652 | wpa_tdls_ap_ies(wpa_s->wpa, (const u8 *) (bss + 1), |
| 1653 | bss->ie_len); |
| 1654 | #endif /* CONFIG_TDLS */ |
| 1655 | |
| 1656 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 1657 | ssid->mode == IEEE80211_MODE_INFRA) { |
| 1658 | sme_authenticate(wpa_s, bss, ssid); |
| 1659 | return; |
| 1660 | } |
| 1661 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1662 | if (wpa_s->connect_work) { |
| 1663 | wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since connect_work exist"); |
| 1664 | return; |
| 1665 | } |
| 1666 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1667 | if (radio_work_pending(wpa_s, "connect")) { |
| 1668 | wpa_dbg(wpa_s, MSG_DEBUG, "Reject wpa_supplicant_associate() call since pending work exist"); |
| 1669 | return; |
| 1670 | } |
| 1671 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1672 | cwork = os_zalloc(sizeof(*cwork)); |
| 1673 | if (cwork == NULL) |
| 1674 | return; |
| 1675 | |
| 1676 | cwork->bss = bss; |
| 1677 | cwork->ssid = ssid; |
| 1678 | |
| 1679 | if (radio_add_work(wpa_s, bss ? bss->freq : 0, "connect", 1, |
| 1680 | wpas_start_assoc_cb, cwork) < 0) { |
| 1681 | os_free(cwork); |
| 1682 | } |
| 1683 | } |
| 1684 | |
| 1685 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1686 | static int bss_is_ibss(struct wpa_bss *bss) |
| 1687 | { |
| 1688 | return (bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == |
| 1689 | IEEE80211_CAP_IBSS; |
| 1690 | } |
| 1691 | |
| 1692 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1693 | void ibss_mesh_setup_freq(struct wpa_supplicant *wpa_s, |
| 1694 | const struct wpa_ssid *ssid, |
| 1695 | struct hostapd_freq_params *freq) |
| 1696 | { |
| 1697 | enum hostapd_hw_mode hw_mode; |
| 1698 | struct hostapd_hw_modes *mode = NULL; |
| 1699 | int ht40plus[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, |
| 1700 | 184, 192 }; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1701 | int vht80[] = { 36, 52, 100, 116, 132, 149 }; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1702 | struct hostapd_channel_data *pri_chan = NULL, *sec_chan = NULL; |
| 1703 | u8 channel; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1704 | int i, chan_idx, ht40 = -1, res, obss_scan = 1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1705 | unsigned int j; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1706 | struct hostapd_freq_params vht_freq; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1707 | |
| 1708 | freq->freq = ssid->frequency; |
| 1709 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1710 | for (j = 0; j < wpa_s->last_scan_res_used; j++) { |
| 1711 | struct wpa_bss *bss = wpa_s->last_scan_res[j]; |
| 1712 | |
| 1713 | if (ssid->mode != WPAS_MODE_IBSS) |
| 1714 | break; |
| 1715 | |
| 1716 | /* Don't adjust control freq in case of fixed_freq */ |
| 1717 | if (ssid->fixed_freq) |
| 1718 | break; |
| 1719 | |
| 1720 | if (!bss_is_ibss(bss)) |
| 1721 | continue; |
| 1722 | |
| 1723 | if (ssid->ssid_len == bss->ssid_len && |
| 1724 | os_memcmp(ssid->ssid, bss->ssid, bss->ssid_len) == 0) { |
| 1725 | wpa_printf(MSG_DEBUG, |
| 1726 | "IBSS already found in scan results, adjust control freq: %d", |
| 1727 | bss->freq); |
| 1728 | freq->freq = bss->freq; |
| 1729 | obss_scan = 0; |
| 1730 | break; |
| 1731 | } |
| 1732 | } |
| 1733 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1734 | /* For IBSS check HT_IBSS flag */ |
| 1735 | if (ssid->mode == WPAS_MODE_IBSS && |
| 1736 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_HT_IBSS)) |
| 1737 | return; |
| 1738 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1739 | if (wpa_s->group_cipher == WPA_CIPHER_WEP40 || |
| 1740 | wpa_s->group_cipher == WPA_CIPHER_WEP104 || |
| 1741 | wpa_s->pairwise_cipher == WPA_CIPHER_TKIP) { |
| 1742 | wpa_printf(MSG_DEBUG, |
| 1743 | "IBSS: WEP/TKIP detected, do not try to enable HT"); |
| 1744 | return; |
| 1745 | } |
| 1746 | |
| 1747 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1748 | for (i = 0; wpa_s->hw.modes && i < wpa_s->hw.num_modes; i++) { |
| 1749 | if (wpa_s->hw.modes[i].mode == hw_mode) { |
| 1750 | mode = &wpa_s->hw.modes[i]; |
| 1751 | break; |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | if (!mode) |
| 1756 | return; |
| 1757 | |
| 1758 | freq->ht_enabled = ht_supported(mode); |
| 1759 | if (!freq->ht_enabled) |
| 1760 | return; |
| 1761 | |
| 1762 | /* Setup higher BW only for 5 GHz */ |
| 1763 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 1764 | return; |
| 1765 | |
| 1766 | for (chan_idx = 0; chan_idx < mode->num_channels; chan_idx++) { |
| 1767 | pri_chan = &mode->channels[chan_idx]; |
| 1768 | if (pri_chan->chan == channel) |
| 1769 | break; |
| 1770 | pri_chan = NULL; |
| 1771 | } |
| 1772 | if (!pri_chan) |
| 1773 | return; |
| 1774 | |
| 1775 | /* Check primary channel flags */ |
| 1776 | if (pri_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) |
| 1777 | return; |
| 1778 | |
| 1779 | /* Check/setup HT40+/HT40- */ |
| 1780 | for (j = 0; j < ARRAY_SIZE(ht40plus); j++) { |
| 1781 | if (ht40plus[j] == channel) { |
| 1782 | ht40 = 1; |
| 1783 | break; |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | /* Find secondary channel */ |
| 1788 | for (i = 0; i < mode->num_channels; i++) { |
| 1789 | sec_chan = &mode->channels[i]; |
| 1790 | if (sec_chan->chan == channel + ht40 * 4) |
| 1791 | break; |
| 1792 | sec_chan = NULL; |
| 1793 | } |
| 1794 | if (!sec_chan) |
| 1795 | return; |
| 1796 | |
| 1797 | /* Check secondary channel flags */ |
| 1798 | if (sec_chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) |
| 1799 | return; |
| 1800 | |
| 1801 | freq->channel = pri_chan->chan; |
| 1802 | |
| 1803 | switch (ht40) { |
| 1804 | case -1: |
| 1805 | if (!(pri_chan->flag & HOSTAPD_CHAN_HT40MINUS)) |
| 1806 | return; |
| 1807 | freq->sec_channel_offset = -1; |
| 1808 | break; |
| 1809 | case 1: |
| 1810 | if (!(pri_chan->flag & HOSTAPD_CHAN_HT40PLUS)) |
| 1811 | return; |
| 1812 | freq->sec_channel_offset = 1; |
| 1813 | break; |
| 1814 | default: |
| 1815 | break; |
| 1816 | } |
| 1817 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1818 | if (freq->sec_channel_offset && obss_scan) { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1819 | struct wpa_scan_results *scan_res; |
| 1820 | |
| 1821 | scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0); |
| 1822 | if (scan_res == NULL) { |
| 1823 | /* Back to HT20 */ |
| 1824 | freq->sec_channel_offset = 0; |
| 1825 | return; |
| 1826 | } |
| 1827 | |
| 1828 | res = check_40mhz_5g(mode, scan_res, pri_chan->chan, |
| 1829 | sec_chan->chan); |
| 1830 | switch (res) { |
| 1831 | case 0: |
| 1832 | /* Back to HT20 */ |
| 1833 | freq->sec_channel_offset = 0; |
| 1834 | break; |
| 1835 | case 1: |
| 1836 | /* Configuration allowed */ |
| 1837 | break; |
| 1838 | case 2: |
| 1839 | /* Switch pri/sec channels */ |
| 1840 | freq->freq = hw_get_freq(mode, sec_chan->chan); |
| 1841 | freq->sec_channel_offset = -freq->sec_channel_offset; |
| 1842 | freq->channel = sec_chan->chan; |
| 1843 | break; |
| 1844 | default: |
| 1845 | freq->sec_channel_offset = 0; |
| 1846 | break; |
| 1847 | } |
| 1848 | |
| 1849 | wpa_scan_results_free(scan_res); |
| 1850 | } |
| 1851 | |
| 1852 | wpa_printf(MSG_DEBUG, |
| 1853 | "IBSS/mesh: setup freq channel %d, sec_channel_offset %d", |
| 1854 | freq->channel, freq->sec_channel_offset); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1855 | |
| 1856 | /* Not sure if mesh is ready for VHT */ |
| 1857 | if (ssid->mode != WPAS_MODE_IBSS) |
| 1858 | return; |
| 1859 | |
| 1860 | /* For IBSS check VHT_IBSS flag */ |
| 1861 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_VHT_IBSS)) |
| 1862 | return; |
| 1863 | |
| 1864 | vht_freq = *freq; |
| 1865 | |
| 1866 | vht_freq.vht_enabled = vht_supported(mode); |
| 1867 | if (!vht_freq.vht_enabled) |
| 1868 | return; |
| 1869 | |
| 1870 | /* setup center_freq1, bandwidth */ |
| 1871 | for (j = 0; j < ARRAY_SIZE(vht80); j++) { |
| 1872 | if (freq->channel >= vht80[j] && |
| 1873 | freq->channel < vht80[j] + 16) |
| 1874 | break; |
| 1875 | } |
| 1876 | |
| 1877 | if (j == ARRAY_SIZE(vht80)) |
| 1878 | return; |
| 1879 | |
| 1880 | for (i = vht80[j]; i < vht80[j] + 16; i += 4) { |
| 1881 | struct hostapd_channel_data *chan; |
| 1882 | |
| 1883 | chan = hw_get_channel_chan(mode, i, NULL); |
| 1884 | if (!chan) |
| 1885 | return; |
| 1886 | |
| 1887 | /* Back to HT configuration if channel not usable */ |
| 1888 | if (chan->flag & (HOSTAPD_CHAN_DISABLED | HOSTAPD_CHAN_NO_IR)) |
| 1889 | return; |
| 1890 | } |
| 1891 | |
| 1892 | if (hostapd_set_freq_params(&vht_freq, mode->mode, freq->freq, |
| 1893 | freq->channel, freq->ht_enabled, |
| 1894 | vht_freq.vht_enabled, |
| 1895 | freq->sec_channel_offset, |
| 1896 | VHT_CHANWIDTH_80MHZ, |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1897 | vht80[j] + 6, 0, 0) != 0) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1898 | return; |
| 1899 | |
| 1900 | *freq = vht_freq; |
| 1901 | |
| 1902 | wpa_printf(MSG_DEBUG, "IBSS: VHT setup freq cf1 %d, cf2 %d, bw %d", |
| 1903 | freq->center_freq1, freq->center_freq2, freq->bandwidth); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1907 | static void wpas_start_assoc_cb(struct wpa_radio_work *work, int deinit) |
| 1908 | { |
| 1909 | struct wpa_connect_work *cwork = work->ctx; |
| 1910 | struct wpa_bss *bss = cwork->bss; |
| 1911 | struct wpa_ssid *ssid = cwork->ssid; |
| 1912 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 1913 | u8 wpa_ie[200]; |
| 1914 | size_t wpa_ie_len; |
| 1915 | int use_crypt, ret, i, bssid_changed; |
| 1916 | int algs = WPA_AUTH_ALG_OPEN; |
| 1917 | unsigned int cipher_pairwise, cipher_group; |
| 1918 | struct wpa_driver_associate_params params; |
| 1919 | int wep_keys_set = 0; |
| 1920 | int assoc_failed = 0; |
| 1921 | struct wpa_ssid *old_ssid; |
| 1922 | #ifdef CONFIG_HT_OVERRIDES |
| 1923 | struct ieee80211_ht_capabilities htcaps; |
| 1924 | struct ieee80211_ht_capabilities htcaps_mask; |
| 1925 | #endif /* CONFIG_HT_OVERRIDES */ |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 1926 | #ifdef CONFIG_VHT_OVERRIDES |
| 1927 | struct ieee80211_vht_capabilities vhtcaps; |
| 1928 | struct ieee80211_vht_capabilities vhtcaps_mask; |
| 1929 | #endif /* CONFIG_VHT_OVERRIDES */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1930 | |
| 1931 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 1932 | if (work->started) { |
| 1933 | wpa_s->connect_work = NULL; |
| 1934 | |
| 1935 | /* cancel possible auth. timeout */ |
| 1936 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, |
| 1937 | NULL); |
| 1938 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1939 | wpas_connect_work_free(cwork); |
| 1940 | return; |
| 1941 | } |
| 1942 | |
| 1943 | wpa_s->connect_work = work; |
| 1944 | |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 1945 | if (cwork->bss_removed || !wpas_valid_bss_ssid(wpa_s, bss, ssid)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1946 | wpa_dbg(wpa_s, MSG_DEBUG, "BSS/SSID entry for association not valid anymore - drop connection attempt"); |
| 1947 | wpas_connect_work_done(wpa_s); |
| 1948 | return; |
| 1949 | } |
| 1950 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1951 | os_memset(¶ms, 0, sizeof(params)); |
| 1952 | wpa_s->reassociate = 0; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 1953 | wpa_s->eap_expected_failure = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1954 | if (bss && |
| 1955 | (!wpas_driver_bss_selection(wpa_s) || wpas_wps_searching(wpa_s))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1956 | #ifdef CONFIG_IEEE80211R |
| 1957 | const u8 *ie, *md = NULL; |
| 1958 | #endif /* CONFIG_IEEE80211R */ |
| 1959 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR |
| 1960 | " (SSID='%s' freq=%d MHz)", MAC2STR(bss->bssid), |
| 1961 | wpa_ssid_txt(bss->ssid, bss->ssid_len), bss->freq); |
| 1962 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
| 1963 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
| 1964 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); |
| 1965 | if (bssid_changed) |
| 1966 | wpas_notify_bssid_changed(wpa_s); |
| 1967 | #ifdef CONFIG_IEEE80211R |
| 1968 | ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
| 1969 | if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN) |
| 1970 | md = ie + 2; |
| 1971 | wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0); |
| 1972 | if (md) { |
| 1973 | /* Prepare for the next transition */ |
| 1974 | wpa_ft_prepare_auth_request(wpa_s->wpa, ie); |
| 1975 | } |
| 1976 | #endif /* CONFIG_IEEE80211R */ |
| 1977 | #ifdef CONFIG_WPS |
| 1978 | } else if ((ssid->ssid == NULL || ssid->ssid_len == 0) && |
| 1979 | wpa_s->conf->ap_scan == 2 && |
| 1980 | (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 1981 | /* Use ap_scan==1 style network selection to find the network |
| 1982 | */ |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 1983 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1984 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1985 | wpa_s->reassociate = 1; |
| 1986 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1987 | return; |
| 1988 | #endif /* CONFIG_WPS */ |
| 1989 | } else { |
| 1990 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with SSID '%s'", |
| 1991 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 1992 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
| 1993 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1994 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1995 | wpa_supplicant_cancel_scan(wpa_s); |
| 1996 | |
| 1997 | /* Starting new association, so clear the possibly used WPA IE from the |
| 1998 | * previous association. */ |
| 1999 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
| 2000 | |
| 2001 | #ifdef IEEE8021X_EAPOL |
| 2002 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 2003 | if (ssid->leap) { |
| 2004 | if (ssid->non_leap == 0) |
| 2005 | algs = WPA_AUTH_ALG_LEAP; |
| 2006 | else |
| 2007 | algs |= WPA_AUTH_ALG_LEAP; |
| 2008 | } |
| 2009 | } |
| 2010 | #endif /* IEEE8021X_EAPOL */ |
| 2011 | wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", algs); |
| 2012 | if (ssid->auth_alg) { |
| 2013 | algs = ssid->auth_alg; |
| 2014 | wpa_dbg(wpa_s, MSG_DEBUG, "Overriding auth_alg selection: " |
| 2015 | "0x%x", algs); |
| 2016 | } |
| 2017 | |
| 2018 | if (bss && (wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) || |
| 2019 | wpa_bss_get_ie(bss, WLAN_EID_RSN)) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2020 | wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2021 | int try_opportunistic; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2022 | try_opportunistic = (ssid->proactive_key_caching < 0 ? |
| 2023 | wpa_s->conf->okc : |
| 2024 | ssid->proactive_key_caching) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2025 | (ssid->proto & WPA_PROTO_RSN); |
| 2026 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 2027 | ssid, try_opportunistic) == 0) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2028 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2029 | wpa_ie_len = sizeof(wpa_ie); |
| 2030 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, |
| 2031 | wpa_ie, &wpa_ie_len)) { |
| 2032 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " |
| 2033 | "key management and encryption suites"); |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 2034 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2035 | return; |
| 2036 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2037 | } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && bss && |
| 2038 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) { |
| 2039 | /* |
| 2040 | * Both WPA and non-WPA IEEE 802.1X enabled in configuration - |
| 2041 | * use non-WPA since the scan results did not indicate that the |
| 2042 | * AP is using WPA or WPA2. |
| 2043 | */ |
| 2044 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 2045 | wpa_ie_len = 0; |
| 2046 | wpa_s->wpa_proto = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2047 | } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2048 | wpa_ie_len = sizeof(wpa_ie); |
| 2049 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
| 2050 | wpa_ie, &wpa_ie_len)) { |
| 2051 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed to set WPA " |
| 2052 | "key management and encryption suites (no " |
| 2053 | "scan results)"); |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 2054 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2055 | return; |
| 2056 | } |
| 2057 | #ifdef CONFIG_WPS |
| 2058 | } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
| 2059 | struct wpabuf *wps_ie; |
| 2060 | wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid)); |
| 2061 | if (wps_ie && wpabuf_len(wps_ie) <= sizeof(wpa_ie)) { |
| 2062 | wpa_ie_len = wpabuf_len(wps_ie); |
| 2063 | os_memcpy(wpa_ie, wpabuf_head(wps_ie), wpa_ie_len); |
| 2064 | } else |
| 2065 | wpa_ie_len = 0; |
| 2066 | wpabuf_free(wps_ie); |
| 2067 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 2068 | if (!bss || (bss->caps & IEEE80211_CAP_PRIVACY)) |
| 2069 | params.wps = WPS_MODE_PRIVACY; |
| 2070 | else |
| 2071 | params.wps = WPS_MODE_OPEN; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2072 | wpa_s->wpa_proto = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2073 | #endif /* CONFIG_WPS */ |
| 2074 | } else { |
| 2075 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 2076 | wpa_ie_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2077 | wpa_s->wpa_proto = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2078 | } |
| 2079 | |
| 2080 | #ifdef CONFIG_P2P |
| 2081 | if (wpa_s->global->p2p) { |
| 2082 | u8 *pos; |
| 2083 | size_t len; |
| 2084 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2085 | pos = wpa_ie + wpa_ie_len; |
| 2086 | len = sizeof(wpa_ie) - wpa_ie_len; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2087 | res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len, |
| 2088 | ssid->p2p_group); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2089 | if (res >= 0) |
| 2090 | wpa_ie_len += res; |
| 2091 | } |
| 2092 | |
| 2093 | wpa_s->cross_connect_disallowed = 0; |
| 2094 | if (bss) { |
| 2095 | struct wpabuf *p2p; |
| 2096 | p2p = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 2097 | if (p2p) { |
| 2098 | wpa_s->cross_connect_disallowed = |
| 2099 | p2p_get_cross_connect_disallowed(p2p); |
| 2100 | wpabuf_free(p2p); |
| 2101 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: WLAN AP %s cross " |
| 2102 | "connection", |
| 2103 | wpa_s->cross_connect_disallowed ? |
| 2104 | "disallows" : "allows"); |
| 2105 | } |
| 2106 | } |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2107 | |
| 2108 | os_memset(wpa_s->p2p_ip_addr_info, 0, sizeof(wpa_s->p2p_ip_addr_info)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2109 | #endif /* CONFIG_P2P */ |
| 2110 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2111 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2112 | if (is_hs20_network(wpa_s, ssid, bss)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2113 | struct wpabuf *hs20; |
| 2114 | hs20 = wpabuf_alloc(20); |
| 2115 | if (hs20) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2116 | int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 2117 | size_t len; |
| 2118 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2119 | wpas_hs20_add_indication(hs20, pps_mo_id); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 2120 | len = sizeof(wpa_ie) - wpa_ie_len; |
| 2121 | if (wpabuf_len(hs20) <= len) { |
| 2122 | os_memcpy(wpa_ie + wpa_ie_len, |
| 2123 | wpabuf_head(hs20), wpabuf_len(hs20)); |
| 2124 | wpa_ie_len += wpabuf_len(hs20); |
| 2125 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2126 | wpabuf_free(hs20); |
| 2127 | } |
| 2128 | } |
| 2129 | #endif /* CONFIG_HS20 */ |
| 2130 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2131 | /* |
| 2132 | * Workaround: Add Extended Capabilities element only if the AP |
| 2133 | * included this element in Beacon/Probe Response frames. Some older |
| 2134 | * APs seem to have interoperability issues if this element is |
| 2135 | * included, so while the standard may require us to include the |
| 2136 | * element in all cases, it is justifiable to skip it to avoid |
| 2137 | * interoperability issues. |
| 2138 | */ |
| 2139 | if (!bss || wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB)) { |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 2140 | u8 ext_capab[18]; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2141 | int ext_capab_len; |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 2142 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
| 2143 | sizeof(ext_capab)); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 2144 | if (ext_capab_len > 0) { |
| 2145 | u8 *pos = wpa_ie; |
| 2146 | if (wpa_ie_len > 0 && pos[0] == WLAN_EID_RSN) |
| 2147 | pos += 2 + pos[1]; |
| 2148 | os_memmove(pos + ext_capab_len, pos, |
| 2149 | wpa_ie_len - (pos - wpa_ie)); |
| 2150 | wpa_ie_len += ext_capab_len; |
| 2151 | os_memcpy(pos, ext_capab, ext_capab_len); |
| 2152 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2153 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2154 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2155 | if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) { |
| 2156 | struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]; |
| 2157 | size_t len; |
| 2158 | |
| 2159 | len = sizeof(wpa_ie) - wpa_ie_len; |
| 2160 | if (wpabuf_len(buf) <= len) { |
| 2161 | os_memcpy(wpa_ie + wpa_ie_len, |
| 2162 | wpabuf_head(buf), wpabuf_len(buf)); |
| 2163 | wpa_ie_len += wpabuf_len(buf); |
| 2164 | } |
| 2165 | } |
| 2166 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2167 | wpa_clear_keys(wpa_s, bss ? bss->bssid : NULL); |
| 2168 | use_crypt = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2169 | cipher_pairwise = wpa_s->pairwise_cipher; |
| 2170 | cipher_group = wpa_s->group_cipher; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2171 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 2172 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 2173 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) |
| 2174 | use_crypt = 0; |
| 2175 | if (wpa_set_wep_keys(wpa_s, ssid)) { |
| 2176 | use_crypt = 1; |
| 2177 | wep_keys_set = 1; |
| 2178 | } |
| 2179 | } |
| 2180 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) |
| 2181 | use_crypt = 0; |
| 2182 | |
| 2183 | #ifdef IEEE8021X_EAPOL |
| 2184 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 2185 | if ((ssid->eapol_flags & |
| 2186 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
| 2187 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) == 0 && |
| 2188 | !wep_keys_set) { |
| 2189 | use_crypt = 0; |
| 2190 | } else { |
| 2191 | /* Assume that dynamic WEP-104 keys will be used and |
| 2192 | * set cipher suites in order for drivers to expect |
| 2193 | * encryption. */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2194 | cipher_pairwise = cipher_group = WPA_CIPHER_WEP104; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2195 | } |
| 2196 | } |
| 2197 | #endif /* IEEE8021X_EAPOL */ |
| 2198 | |
| 2199 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 2200 | /* Set the key before (and later after) association */ |
| 2201 | wpa_supplicant_set_wpa_none_key(wpa_s, ssid); |
| 2202 | } |
| 2203 | |
| 2204 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING); |
| 2205 | if (bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2206 | params.ssid = bss->ssid; |
| 2207 | params.ssid_len = bss->ssid_len; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2208 | if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set) { |
| 2209 | wpa_printf(MSG_DEBUG, "Limit connection to BSSID " |
| 2210 | MACSTR " freq=%u MHz based on scan results " |
| 2211 | "(bssid_set=%d)", |
| 2212 | MAC2STR(bss->bssid), bss->freq, |
| 2213 | ssid->bssid_set); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2214 | params.bssid = bss->bssid; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2215 | params.freq.freq = bss->freq; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2216 | } |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 2217 | params.bssid_hint = bss->bssid; |
| 2218 | params.freq_hint = bss->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2219 | } else { |
| 2220 | params.ssid = ssid->ssid; |
| 2221 | params.ssid_len = ssid->ssid_len; |
| 2222 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2223 | |
| 2224 | if (ssid->mode == WPAS_MODE_IBSS && ssid->bssid_set && |
| 2225 | wpa_s->conf->ap_scan == 2) { |
| 2226 | params.bssid = ssid->bssid; |
| 2227 | params.fixed_bssid = 1; |
| 2228 | } |
| 2229 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2230 | /* Initial frequency for IBSS/mesh */ |
| 2231 | if ((ssid->mode == WPAS_MODE_IBSS || ssid->mode == WPAS_MODE_MESH) && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2232 | ssid->frequency > 0 && params.freq.freq == 0) |
| 2233 | ibss_mesh_setup_freq(wpa_s, ssid, ¶ms.freq); |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 2234 | |
| 2235 | if (ssid->mode == WPAS_MODE_IBSS) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2236 | params.fixed_freq = ssid->fixed_freq; |
Dmitry Shmidt | 2ac5f60 | 2014-03-07 10:08:21 -0800 | [diff] [blame] | 2237 | if (ssid->beacon_int) |
| 2238 | params.beacon_int = ssid->beacon_int; |
| 2239 | else |
| 2240 | params.beacon_int = wpa_s->conf->beacon_int; |
| 2241 | } |
| 2242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2243 | params.wpa_ie = wpa_ie; |
| 2244 | params.wpa_ie_len = wpa_ie_len; |
| 2245 | params.pairwise_suite = cipher_pairwise; |
| 2246 | params.group_suite = cipher_group; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2247 | params.key_mgmt_suite = wpa_s->key_mgmt; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2248 | params.wpa_proto = wpa_s->wpa_proto; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2249 | params.auth_alg = algs; |
| 2250 | params.mode = ssid->mode; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2251 | params.bg_scan_period = ssid->bg_scan_period; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2252 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 2253 | if (ssid->wep_key_len[i]) |
| 2254 | params.wep_key[i] = ssid->wep_key[i]; |
| 2255 | params.wep_key_len[i] = ssid->wep_key_len[i]; |
| 2256 | } |
| 2257 | params.wep_tx_keyidx = ssid->wep_tx_keyidx; |
| 2258 | |
| 2259 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2260 | (params.key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 2261 | params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2262 | params.passphrase = ssid->passphrase; |
| 2263 | if (ssid->psk_set) |
| 2264 | params.psk = ssid->psk; |
| 2265 | } |
| 2266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2267 | if (wpa_s->conf->key_mgmt_offload) { |
| 2268 | if (params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 2269 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2270 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 2271 | params.key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2272 | params.req_key_mgmt_offload = |
| 2273 | ssid->proactive_key_caching < 0 ? |
| 2274 | wpa_s->conf->okc : ssid->proactive_key_caching; |
| 2275 | else |
| 2276 | params.req_key_mgmt_offload = 1; |
| 2277 | |
| 2278 | if ((params.key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 2279 | params.key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 2280 | params.key_mgmt_suite == WPA_KEY_MGMT_FT_PSK) && |
| 2281 | ssid->psk_set) |
| 2282 | params.psk = ssid->psk; |
| 2283 | } |
| 2284 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2285 | params.drop_unencrypted = use_crypt; |
| 2286 | |
| 2287 | #ifdef CONFIG_IEEE80211W |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2288 | params.mgmt_frame_protection = wpas_get_ssid_pmf(wpa_s, ssid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2289 | if (params.mgmt_frame_protection != NO_MGMT_FRAME_PROTECTION && bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2290 | const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 2291 | struct wpa_ie_data ie; |
| 2292 | if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ie) == 0 && |
| 2293 | ie.capabilities & |
| 2294 | (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) { |
| 2295 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Selected AP supports " |
| 2296 | "MFP: require MFP"); |
| 2297 | params.mgmt_frame_protection = |
| 2298 | MGMT_FRAME_PROTECTION_REQUIRED; |
| 2299 | } |
| 2300 | } |
| 2301 | #endif /* CONFIG_IEEE80211W */ |
| 2302 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2303 | params.p2p = ssid->p2p_group; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2304 | |
| 2305 | if (wpa_s->parent->set_sta_uapsd) |
| 2306 | params.uapsd = wpa_s->parent->sta_uapsd; |
| 2307 | else |
| 2308 | params.uapsd = -1; |
| 2309 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2310 | #ifdef CONFIG_HT_OVERRIDES |
| 2311 | os_memset(&htcaps, 0, sizeof(htcaps)); |
| 2312 | os_memset(&htcaps_mask, 0, sizeof(htcaps_mask)); |
| 2313 | params.htcaps = (u8 *) &htcaps; |
| 2314 | params.htcaps_mask = (u8 *) &htcaps_mask; |
| 2315 | wpa_supplicant_apply_ht_overrides(wpa_s, ssid, ¶ms); |
| 2316 | #endif /* CONFIG_HT_OVERRIDES */ |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2317 | #ifdef CONFIG_VHT_OVERRIDES |
| 2318 | os_memset(&vhtcaps, 0, sizeof(vhtcaps)); |
| 2319 | os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask)); |
| 2320 | params.vhtcaps = &vhtcaps; |
| 2321 | params.vhtcaps_mask = &vhtcaps_mask; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2322 | wpa_supplicant_apply_vht_overrides(wpa_s, ssid, ¶ms); |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 2323 | #endif /* CONFIG_VHT_OVERRIDES */ |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2324 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2325 | #ifdef CONFIG_P2P |
| 2326 | /* |
| 2327 | * If multi-channel concurrency is not supported, check for any |
| 2328 | * frequency conflict. In case of any frequency conflict, remove the |
| 2329 | * least prioritized connection. |
| 2330 | */ |
| 2331 | if (wpa_s->num_multichan_concurrent < 2) { |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 2332 | int freq, num; |
| 2333 | num = get_shared_radio_freqs(wpa_s, &freq, 1); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2334 | if (num > 0 && freq > 0 && freq != params.freq.freq) { |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 2335 | wpa_printf(MSG_DEBUG, |
| 2336 | "Assoc conflicting freq found (%d != %d)", |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2337 | freq, params.freq.freq); |
| 2338 | if (wpas_p2p_handle_frequency_conflicts( |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 2339 | wpa_s, params.freq.freq, ssid) < 0) { |
| 2340 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2341 | return; |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 2342 | } |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 2343 | } |
| 2344 | } |
| 2345 | #endif /* CONFIG_P2P */ |
| 2346 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2347 | ret = wpa_drv_associate(wpa_s, ¶ms); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2348 | if (ret < 0) { |
| 2349 | wpa_msg(wpa_s, MSG_INFO, "Association request to the driver " |
| 2350 | "failed"); |
| 2351 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SANE_ERROR_CODES) { |
| 2352 | /* |
| 2353 | * The driver is known to mean what is saying, so we |
| 2354 | * can stop right here; the association will not |
| 2355 | * succeed. |
| 2356 | */ |
| 2357 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2358 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2359 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
| 2360 | return; |
| 2361 | } |
| 2362 | /* try to continue anyway; new association will be tried again |
| 2363 | * after timeout */ |
| 2364 | assoc_failed = 1; |
| 2365 | } |
| 2366 | |
| 2367 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 2368 | /* Set the key after the association just in case association |
| 2369 | * cleared the previously configured key. */ |
| 2370 | wpa_supplicant_set_wpa_none_key(wpa_s, ssid); |
| 2371 | /* No need to timeout authentication since there is no key |
| 2372 | * management. */ |
| 2373 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 2374 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 2375 | #ifdef CONFIG_IBSS_RSN |
| 2376 | } else if (ssid->mode == WPAS_MODE_IBSS && |
| 2377 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
| 2378 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE) { |
| 2379 | /* |
| 2380 | * RSN IBSS authentication is per-STA and we can disable the |
| 2381 | * per-BSSID authentication. |
| 2382 | */ |
| 2383 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 2384 | #endif /* CONFIG_IBSS_RSN */ |
| 2385 | } else { |
| 2386 | /* Timeout for IEEE 802.11 authentication and association */ |
| 2387 | int timeout = 60; |
| 2388 | |
| 2389 | if (assoc_failed) { |
| 2390 | /* give IBSS a bit more time */ |
| 2391 | timeout = ssid->mode == WPAS_MODE_IBSS ? 10 : 5; |
| 2392 | } else if (wpa_s->conf->ap_scan == 1) { |
| 2393 | /* give IBSS a bit more time */ |
| 2394 | timeout = ssid->mode == WPAS_MODE_IBSS ? 20 : 10; |
| 2395 | } |
| 2396 | wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0); |
| 2397 | } |
| 2398 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2399 | if (wep_keys_set && |
| 2400 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2401 | /* Set static WEP keys again */ |
| 2402 | wpa_set_wep_keys(wpa_s, ssid); |
| 2403 | } |
| 2404 | |
| 2405 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) { |
| 2406 | /* |
| 2407 | * Do not allow EAP session resumption between different |
| 2408 | * network configurations. |
| 2409 | */ |
| 2410 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 2411 | } |
| 2412 | old_ssid = wpa_s->current_ssid; |
| 2413 | wpa_s->current_ssid = ssid; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 2414 | if (!wpas_driver_bss_selection(wpa_s) || ssid->bssid_set) |
| 2415 | wpa_s->current_bss = bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2416 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
| 2417 | wpa_supplicant_initiate_eapol(wpa_s); |
| 2418 | if (old_ssid != wpa_s->current_ssid) |
| 2419 | wpas_notify_network_changed(wpa_s); |
| 2420 | } |
| 2421 | |
| 2422 | |
| 2423 | static void wpa_supplicant_clear_connection(struct wpa_supplicant *wpa_s, |
| 2424 | const u8 *addr) |
| 2425 | { |
| 2426 | struct wpa_ssid *old_ssid; |
| 2427 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2428 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2429 | wpa_clear_keys(wpa_s, addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2430 | old_ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2431 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2432 | wpa_sm_set_config(wpa_s->wpa, NULL); |
| 2433 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
| 2434 | if (old_ssid != wpa_s->current_ssid) |
| 2435 | wpas_notify_network_changed(wpa_s); |
| 2436 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
| 2437 | } |
| 2438 | |
| 2439 | |
| 2440 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2441 | * wpa_supplicant_deauthenticate - Deauthenticate the current connection |
| 2442 | * @wpa_s: Pointer to wpa_supplicant data |
| 2443 | * @reason_code: IEEE 802.11 reason code for the deauthenticate frame |
| 2444 | * |
| 2445 | * This function is used to request %wpa_supplicant to deauthenticate from the |
| 2446 | * current AP. |
| 2447 | */ |
| 2448 | void wpa_supplicant_deauthenticate(struct wpa_supplicant *wpa_s, |
| 2449 | int reason_code) |
| 2450 | { |
| 2451 | u8 *addr = NULL; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2452 | union wpa_event_data event; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2453 | int zero_addr = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2454 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2455 | wpa_dbg(wpa_s, MSG_DEBUG, "Request to deauthenticate - bssid=" MACSTR |
| 2456 | " pending_bssid=" MACSTR " reason=%d state=%s", |
| 2457 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), |
| 2458 | reason_code, wpa_supplicant_state_txt(wpa_s->wpa_state)); |
| 2459 | |
| 2460 | if (!is_zero_ether_addr(wpa_s->bssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2461 | addr = wpa_s->bssid; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2462 | else if (!is_zero_ether_addr(wpa_s->pending_bssid) && |
| 2463 | (wpa_s->wpa_state == WPA_AUTHENTICATING || |
| 2464 | wpa_s->wpa_state == WPA_ASSOCIATING)) |
| 2465 | addr = wpa_s->pending_bssid; |
| 2466 | else if (wpa_s->wpa_state == WPA_ASSOCIATING) { |
| 2467 | /* |
| 2468 | * When using driver-based BSS selection, we may not know the |
| 2469 | * BSSID with which we are currently trying to associate. We |
| 2470 | * need to notify the driver of this disconnection even in such |
| 2471 | * a case, so use the all zeros address here. |
| 2472 | */ |
| 2473 | addr = wpa_s->bssid; |
| 2474 | zero_addr = 1; |
| 2475 | } |
| 2476 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 2477 | #ifdef CONFIG_TDLS |
| 2478 | wpa_tdls_teardown_peers(wpa_s->wpa); |
| 2479 | #endif /* CONFIG_TDLS */ |
| 2480 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2481 | #ifdef CONFIG_MESH |
| 2482 | if (wpa_s->ifmsh) { |
| 2483 | wpa_msg_ctrl(wpa_s, MSG_INFO, MESH_GROUP_REMOVED "%s", |
| 2484 | wpa_s->ifname); |
| 2485 | wpa_supplicant_leave_mesh(wpa_s); |
| 2486 | } |
| 2487 | #endif /* CONFIG_MESH */ |
| 2488 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2489 | if (addr) { |
| 2490 | wpa_drv_deauthenticate(wpa_s, addr, reason_code); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2491 | os_memset(&event, 0, sizeof(event)); |
| 2492 | event.deauth_info.reason_code = (u16) reason_code; |
| 2493 | event.deauth_info.locally_generated = 1; |
| 2494 | wpa_supplicant_event(wpa_s, EVENT_DEAUTH, &event); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2495 | if (zero_addr) |
| 2496 | addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | wpa_supplicant_clear_connection(wpa_s, addr); |
| 2500 | } |
| 2501 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2502 | static void wpa_supplicant_enable_one_network(struct wpa_supplicant *wpa_s, |
| 2503 | struct wpa_ssid *ssid) |
| 2504 | { |
| 2505 | if (!ssid || !ssid->disabled || ssid->disabled == 2) |
| 2506 | return; |
| 2507 | |
| 2508 | ssid->disabled = 0; |
| 2509 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
| 2510 | wpas_notify_network_enabled_changed(wpa_s, ssid); |
| 2511 | |
| 2512 | /* |
| 2513 | * Try to reassociate since there is no current configuration and a new |
| 2514 | * network was made available. |
| 2515 | */ |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 2516 | if (!wpa_s->current_ssid && !wpa_s->disconnected) |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2517 | wpa_s->reassociate = 1; |
| 2518 | } |
| 2519 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2520 | |
| 2521 | /** |
| 2522 | * wpa_supplicant_enable_network - Mark a configured network as enabled |
| 2523 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2524 | * @ssid: wpa_ssid structure for a configured network or %NULL |
| 2525 | * |
| 2526 | * Enables the specified network or all networks if no network specified. |
| 2527 | */ |
| 2528 | void wpa_supplicant_enable_network(struct wpa_supplicant *wpa_s, |
| 2529 | struct wpa_ssid *ssid) |
| 2530 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2531 | if (ssid == NULL) { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2532 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
| 2533 | wpa_supplicant_enable_one_network(wpa_s, ssid); |
| 2534 | } else |
| 2535 | wpa_supplicant_enable_one_network(wpa_s, ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2536 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 2537 | if (wpa_s->reassociate && !wpa_s->disconnected) { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2538 | if (wpa_s->sched_scanning) { |
| 2539 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to add " |
| 2540 | "new network to scan filters"); |
| 2541 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2544 | if (wpa_supplicant_fast_associate(wpa_s) != 1) |
| 2545 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2546 | } |
| 2547 | } |
| 2548 | |
| 2549 | |
| 2550 | /** |
| 2551 | * wpa_supplicant_disable_network - Mark a configured network as disabled |
| 2552 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2553 | * @ssid: wpa_ssid structure for a configured network or %NULL |
| 2554 | * |
| 2555 | * Disables the specified network or all networks if no network specified. |
| 2556 | */ |
| 2557 | void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s, |
| 2558 | struct wpa_ssid *ssid) |
| 2559 | { |
| 2560 | struct wpa_ssid *other_ssid; |
| 2561 | int was_disabled; |
| 2562 | |
| 2563 | if (ssid == NULL) { |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2564 | if (wpa_s->sched_scanning) |
| 2565 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 2566 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2567 | for (other_ssid = wpa_s->conf->ssid; other_ssid; |
| 2568 | other_ssid = other_ssid->next) { |
| 2569 | was_disabled = other_ssid->disabled; |
| 2570 | if (was_disabled == 2) |
| 2571 | continue; /* do not change persistent P2P group |
| 2572 | * data */ |
| 2573 | |
| 2574 | other_ssid->disabled = 1; |
| 2575 | |
| 2576 | if (was_disabled != other_ssid->disabled) |
| 2577 | wpas_notify_network_enabled_changed( |
| 2578 | wpa_s, other_ssid); |
| 2579 | } |
| 2580 | if (wpa_s->current_ssid) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2581 | wpa_supplicant_deauthenticate( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2582 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2583 | } else if (ssid->disabled != 2) { |
| 2584 | if (ssid == wpa_s->current_ssid) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2585 | wpa_supplicant_deauthenticate( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2586 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2587 | |
| 2588 | was_disabled = ssid->disabled; |
| 2589 | |
| 2590 | ssid->disabled = 1; |
| 2591 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2592 | if (was_disabled != ssid->disabled) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2593 | wpas_notify_network_enabled_changed(wpa_s, ssid); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 2594 | if (wpa_s->sched_scanning) { |
| 2595 | wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan " |
| 2596 | "to remove network from filters"); |
| 2597 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 2598 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 2599 | } |
| 2600 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2601 | } |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | /** |
| 2606 | * wpa_supplicant_select_network - Attempt association with a network |
| 2607 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2608 | * @ssid: wpa_ssid structure for a configured network or %NULL for any network |
| 2609 | */ |
| 2610 | void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s, |
| 2611 | struct wpa_ssid *ssid) |
| 2612 | { |
| 2613 | |
| 2614 | struct wpa_ssid *other_ssid; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2615 | int disconnected = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2617 | if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) { |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame^] | 2618 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 2619 | wpa_s->own_disconnect_req = 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2620 | wpa_supplicant_deauthenticate( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2621 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2622 | disconnected = 1; |
| 2623 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2624 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2625 | if (ssid) |
| 2626 | wpas_clear_temp_disabled(wpa_s, ssid, 1); |
| 2627 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2628 | /* |
| 2629 | * Mark all other networks disabled or mark all networks enabled if no |
| 2630 | * network specified. |
| 2631 | */ |
| 2632 | for (other_ssid = wpa_s->conf->ssid; other_ssid; |
| 2633 | other_ssid = other_ssid->next) { |
| 2634 | int was_disabled = other_ssid->disabled; |
| 2635 | if (was_disabled == 2) |
| 2636 | continue; /* do not change persistent P2P group data */ |
| 2637 | |
| 2638 | other_ssid->disabled = ssid ? (ssid->id != other_ssid->id) : 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2639 | if (was_disabled && !other_ssid->disabled) |
| 2640 | wpas_clear_temp_disabled(wpa_s, other_ssid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2641 | |
| 2642 | if (was_disabled != other_ssid->disabled) |
| 2643 | wpas_notify_network_enabled_changed(wpa_s, other_ssid); |
| 2644 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2645 | |
| 2646 | if (ssid && ssid == wpa_s->current_ssid && wpa_s->current_ssid) { |
| 2647 | /* We are already associated with the selected network */ |
| 2648 | wpa_printf(MSG_DEBUG, "Already associated with the " |
| 2649 | "selected network - do nothing"); |
| 2650 | return; |
| 2651 | } |
| 2652 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2653 | if (ssid) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2654 | wpa_s->current_ssid = ssid; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2655 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2656 | wpa_s->connect_without_scan = |
| 2657 | (ssid->mode == WPAS_MODE_MESH) ? ssid : NULL; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 2658 | |
| 2659 | /* |
| 2660 | * Don't optimize next scan freqs since a new ESS has been |
| 2661 | * selected. |
| 2662 | */ |
| 2663 | os_free(wpa_s->next_scan_freqs); |
| 2664 | wpa_s->next_scan_freqs = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2665 | } else { |
| 2666 | wpa_s->connect_without_scan = NULL; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2667 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2668 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2669 | wpa_s->disconnected = 0; |
| 2670 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2671 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2672 | if (wpa_s->connect_without_scan || |
| 2673 | wpa_supplicant_fast_associate(wpa_s) != 1) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2674 | wpa_supplicant_req_scan(wpa_s, 0, disconnected ? 100000 : 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2675 | |
| 2676 | if (ssid) |
| 2677 | wpas_notify_network_selected(wpa_s, ssid); |
| 2678 | } |
| 2679 | |
| 2680 | |
| 2681 | /** |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2682 | * wpas_set_pkcs11_engine_and_module_path - Set PKCS #11 engine and module path |
| 2683 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2684 | * @pkcs11_engine_path: PKCS #11 engine path or NULL |
| 2685 | * @pkcs11_module_path: PKCS #11 module path or NULL |
| 2686 | * Returns: 0 on success; -1 on failure |
| 2687 | * |
| 2688 | * Sets the PKCS #11 engine and module path. Both have to be NULL or a valid |
| 2689 | * path. If resetting the EAPOL state machine with the new PKCS #11 engine and |
| 2690 | * module path fails the paths will be reset to the default value (NULL). |
| 2691 | */ |
| 2692 | int wpas_set_pkcs11_engine_and_module_path(struct wpa_supplicant *wpa_s, |
| 2693 | const char *pkcs11_engine_path, |
| 2694 | const char *pkcs11_module_path) |
| 2695 | { |
| 2696 | char *pkcs11_engine_path_copy = NULL; |
| 2697 | char *pkcs11_module_path_copy = NULL; |
| 2698 | |
| 2699 | if (pkcs11_engine_path != NULL) { |
| 2700 | pkcs11_engine_path_copy = os_strdup(pkcs11_engine_path); |
| 2701 | if (pkcs11_engine_path_copy == NULL) |
| 2702 | return -1; |
| 2703 | } |
| 2704 | if (pkcs11_module_path != NULL) { |
| 2705 | pkcs11_module_path_copy = os_strdup(pkcs11_module_path); |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 2706 | if (pkcs11_module_path_copy == NULL) { |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2707 | os_free(pkcs11_engine_path_copy); |
| 2708 | return -1; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | os_free(wpa_s->conf->pkcs11_engine_path); |
| 2713 | os_free(wpa_s->conf->pkcs11_module_path); |
| 2714 | wpa_s->conf->pkcs11_engine_path = pkcs11_engine_path_copy; |
| 2715 | wpa_s->conf->pkcs11_module_path = pkcs11_module_path_copy; |
| 2716 | |
| 2717 | wpa_sm_set_eapol(wpa_s->wpa, NULL); |
| 2718 | eapol_sm_deinit(wpa_s->eapol); |
| 2719 | wpa_s->eapol = NULL; |
| 2720 | if (wpa_supplicant_init_eapol(wpa_s)) { |
| 2721 | /* Error -> Reset paths to the default value (NULL) once. */ |
| 2722 | if (pkcs11_engine_path != NULL && pkcs11_module_path != NULL) |
| 2723 | wpas_set_pkcs11_engine_and_module_path(wpa_s, NULL, |
| 2724 | NULL); |
| 2725 | |
| 2726 | return -1; |
| 2727 | } |
| 2728 | wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol); |
| 2729 | |
| 2730 | return 0; |
| 2731 | } |
| 2732 | |
| 2733 | |
| 2734 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2735 | * wpa_supplicant_set_ap_scan - Set AP scan mode for interface |
| 2736 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2737 | * @ap_scan: AP scan mode |
| 2738 | * Returns: 0 if succeed or -1 if ap_scan has an invalid value |
| 2739 | * |
| 2740 | */ |
| 2741 | int wpa_supplicant_set_ap_scan(struct wpa_supplicant *wpa_s, int ap_scan) |
| 2742 | { |
| 2743 | |
| 2744 | int old_ap_scan; |
| 2745 | |
| 2746 | if (ap_scan < 0 || ap_scan > 2) |
| 2747 | return -1; |
| 2748 | |
Dmitry Shmidt | 114c386 | 2011-08-16 11:52:06 -0700 | [diff] [blame] | 2749 | #ifdef ANDROID |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2750 | if (ap_scan == 2 && ap_scan != wpa_s->conf->ap_scan && |
| 2751 | wpa_s->wpa_state >= WPA_ASSOCIATING && |
| 2752 | wpa_s->wpa_state < WPA_COMPLETED) { |
| 2753 | wpa_printf(MSG_ERROR, "ap_scan = %d (%d) rejected while " |
| 2754 | "associating", wpa_s->conf->ap_scan, ap_scan); |
Dmitry Shmidt | 114c386 | 2011-08-16 11:52:06 -0700 | [diff] [blame] | 2755 | return 0; |
| 2756 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2757 | #endif /* ANDROID */ |
Dmitry Shmidt | 114c386 | 2011-08-16 11:52:06 -0700 | [diff] [blame] | 2758 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2759 | old_ap_scan = wpa_s->conf->ap_scan; |
| 2760 | wpa_s->conf->ap_scan = ap_scan; |
| 2761 | |
| 2762 | if (old_ap_scan != wpa_s->conf->ap_scan) |
| 2763 | wpas_notify_ap_scan_changed(wpa_s); |
| 2764 | |
| 2765 | return 0; |
| 2766 | } |
| 2767 | |
| 2768 | |
| 2769 | /** |
| 2770 | * wpa_supplicant_set_bss_expiration_age - Set BSS entry expiration age |
| 2771 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2772 | * @expire_age: Expiration age in seconds |
| 2773 | * Returns: 0 if succeed or -1 if expire_age has an invalid value |
| 2774 | * |
| 2775 | */ |
| 2776 | int wpa_supplicant_set_bss_expiration_age(struct wpa_supplicant *wpa_s, |
| 2777 | unsigned int bss_expire_age) |
| 2778 | { |
| 2779 | if (bss_expire_age < 10) { |
| 2780 | wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration age %u", |
| 2781 | bss_expire_age); |
| 2782 | return -1; |
| 2783 | } |
| 2784 | wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration age: %d sec", |
| 2785 | bss_expire_age); |
| 2786 | wpa_s->conf->bss_expiration_age = bss_expire_age; |
| 2787 | |
| 2788 | return 0; |
| 2789 | } |
| 2790 | |
| 2791 | |
| 2792 | /** |
| 2793 | * wpa_supplicant_set_bss_expiration_count - Set BSS entry expiration scan count |
| 2794 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2795 | * @expire_count: number of scans after which an unseen BSS is reclaimed |
| 2796 | * Returns: 0 if succeed or -1 if expire_count has an invalid value |
| 2797 | * |
| 2798 | */ |
| 2799 | int wpa_supplicant_set_bss_expiration_count(struct wpa_supplicant *wpa_s, |
| 2800 | unsigned int bss_expire_count) |
| 2801 | { |
| 2802 | if (bss_expire_count < 1) { |
| 2803 | wpa_msg(wpa_s, MSG_ERROR, "Invalid bss expiration count %u", |
| 2804 | bss_expire_count); |
| 2805 | return -1; |
| 2806 | } |
| 2807 | wpa_msg(wpa_s, MSG_DEBUG, "Setting bss expiration scan count: %u", |
| 2808 | bss_expire_count); |
| 2809 | wpa_s->conf->bss_expiration_scan_count = bss_expire_count; |
| 2810 | |
| 2811 | return 0; |
| 2812 | } |
| 2813 | |
| 2814 | |
| 2815 | /** |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2816 | * wpa_supplicant_set_scan_interval - Set scan interval |
| 2817 | * @wpa_s: wpa_supplicant structure for a network interface |
| 2818 | * @scan_interval: scan interval in seconds |
| 2819 | * Returns: 0 if succeed or -1 if scan_interval has an invalid value |
| 2820 | * |
| 2821 | */ |
| 2822 | int wpa_supplicant_set_scan_interval(struct wpa_supplicant *wpa_s, |
| 2823 | int scan_interval) |
| 2824 | { |
| 2825 | if (scan_interval < 0) { |
| 2826 | wpa_msg(wpa_s, MSG_ERROR, "Invalid scan interval %d", |
| 2827 | scan_interval); |
| 2828 | return -1; |
| 2829 | } |
| 2830 | wpa_msg(wpa_s, MSG_DEBUG, "Setting scan interval: %d sec", |
| 2831 | scan_interval); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2832 | wpa_supplicant_update_scan_int(wpa_s, scan_interval); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2833 | |
| 2834 | return 0; |
| 2835 | } |
| 2836 | |
| 2837 | |
| 2838 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2839 | * wpa_supplicant_set_debug_params - Set global debug params |
| 2840 | * @global: wpa_global structure |
| 2841 | * @debug_level: debug level |
| 2842 | * @debug_timestamp: determines if show timestamp in debug data |
| 2843 | * @debug_show_keys: determines if show keys in debug data |
| 2844 | * Returns: 0 if succeed or -1 if debug_level has wrong value |
| 2845 | */ |
| 2846 | int wpa_supplicant_set_debug_params(struct wpa_global *global, int debug_level, |
| 2847 | int debug_timestamp, int debug_show_keys) |
| 2848 | { |
| 2849 | |
| 2850 | int old_level, old_timestamp, old_show_keys; |
| 2851 | |
| 2852 | /* check for allowed debuglevels */ |
| 2853 | if (debug_level != MSG_EXCESSIVE && |
| 2854 | debug_level != MSG_MSGDUMP && |
| 2855 | debug_level != MSG_DEBUG && |
| 2856 | debug_level != MSG_INFO && |
| 2857 | debug_level != MSG_WARNING && |
| 2858 | debug_level != MSG_ERROR) |
| 2859 | return -1; |
| 2860 | |
| 2861 | old_level = wpa_debug_level; |
| 2862 | old_timestamp = wpa_debug_timestamp; |
| 2863 | old_show_keys = wpa_debug_show_keys; |
| 2864 | |
| 2865 | wpa_debug_level = debug_level; |
| 2866 | wpa_debug_timestamp = debug_timestamp ? 1 : 0; |
| 2867 | wpa_debug_show_keys = debug_show_keys ? 1 : 0; |
| 2868 | |
| 2869 | if (wpa_debug_level != old_level) |
| 2870 | wpas_notify_debug_level_changed(global); |
| 2871 | if (wpa_debug_timestamp != old_timestamp) |
| 2872 | wpas_notify_debug_timestamp_changed(global); |
| 2873 | if (wpa_debug_show_keys != old_show_keys) |
| 2874 | wpas_notify_debug_show_keys_changed(global); |
| 2875 | |
| 2876 | return 0; |
| 2877 | } |
| 2878 | |
| 2879 | |
| 2880 | /** |
| 2881 | * wpa_supplicant_get_ssid - Get a pointer to the current network structure |
| 2882 | * @wpa_s: Pointer to wpa_supplicant data |
| 2883 | * Returns: A pointer to the current network structure or %NULL on failure |
| 2884 | */ |
| 2885 | struct wpa_ssid * wpa_supplicant_get_ssid(struct wpa_supplicant *wpa_s) |
| 2886 | { |
| 2887 | struct wpa_ssid *entry; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 2888 | u8 ssid[SSID_MAX_LEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2889 | int res; |
| 2890 | size_t ssid_len; |
| 2891 | u8 bssid[ETH_ALEN]; |
| 2892 | int wired; |
| 2893 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2894 | res = wpa_drv_get_ssid(wpa_s, ssid); |
| 2895 | if (res < 0) { |
| 2896 | wpa_msg(wpa_s, MSG_WARNING, "Could not read SSID from " |
| 2897 | "driver"); |
| 2898 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2899 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2900 | ssid_len = res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2901 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2902 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2903 | wpa_msg(wpa_s, MSG_WARNING, "Could not read BSSID from " |
| 2904 | "driver"); |
| 2905 | return NULL; |
| 2906 | } |
| 2907 | |
| 2908 | wired = wpa_s->conf->ap_scan == 0 && |
| 2909 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED); |
| 2910 | |
| 2911 | entry = wpa_s->conf->ssid; |
| 2912 | while (entry) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2913 | if (!wpas_network_disabled(wpa_s, entry) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | ((ssid_len == entry->ssid_len && |
| 2915 | os_memcmp(ssid, entry->ssid, ssid_len) == 0) || wired) && |
| 2916 | (!entry->bssid_set || |
| 2917 | os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)) |
| 2918 | return entry; |
| 2919 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2920 | if (!wpas_network_disabled(wpa_s, entry) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2921 | (entry->key_mgmt & WPA_KEY_MGMT_WPS) && |
| 2922 | (entry->ssid == NULL || entry->ssid_len == 0) && |
| 2923 | (!entry->bssid_set || |
| 2924 | os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0)) |
| 2925 | return entry; |
| 2926 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2927 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2928 | if (!wpas_network_disabled(wpa_s, entry) && entry->bssid_set && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2929 | entry->ssid_len == 0 && |
| 2930 | os_memcmp(bssid, entry->bssid, ETH_ALEN) == 0) |
| 2931 | return entry; |
| 2932 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2933 | entry = entry->next; |
| 2934 | } |
| 2935 | |
| 2936 | return NULL; |
| 2937 | } |
| 2938 | |
| 2939 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2940 | static int select_driver(struct wpa_supplicant *wpa_s, int i) |
| 2941 | { |
| 2942 | struct wpa_global *global = wpa_s->global; |
| 2943 | |
| 2944 | if (wpa_drivers[i]->global_init && global->drv_priv[i] == NULL) { |
| 2945 | global->drv_priv[i] = wpa_drivers[i]->global_init(); |
| 2946 | if (global->drv_priv[i] == NULL) { |
| 2947 | wpa_printf(MSG_ERROR, "Failed to initialize driver " |
| 2948 | "'%s'", wpa_drivers[i]->name); |
| 2949 | return -1; |
| 2950 | } |
| 2951 | } |
| 2952 | |
| 2953 | wpa_s->driver = wpa_drivers[i]; |
| 2954 | wpa_s->global_drv_priv = global->drv_priv[i]; |
| 2955 | |
| 2956 | return 0; |
| 2957 | } |
| 2958 | |
| 2959 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2960 | static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s, |
| 2961 | const char *name) |
| 2962 | { |
| 2963 | int i; |
| 2964 | size_t len; |
| 2965 | const char *pos, *driver = name; |
| 2966 | |
| 2967 | if (wpa_s == NULL) |
| 2968 | return -1; |
| 2969 | |
| 2970 | if (wpa_drivers[0] == NULL) { |
| 2971 | wpa_msg(wpa_s, MSG_ERROR, "No driver interfaces build into " |
| 2972 | "wpa_supplicant"); |
| 2973 | return -1; |
| 2974 | } |
| 2975 | |
| 2976 | if (name == NULL) { |
| 2977 | /* default to first driver in the list */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2978 | return select_driver(wpa_s, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2979 | } |
| 2980 | |
| 2981 | do { |
| 2982 | pos = os_strchr(driver, ','); |
| 2983 | if (pos) |
| 2984 | len = pos - driver; |
| 2985 | else |
| 2986 | len = os_strlen(driver); |
| 2987 | |
| 2988 | for (i = 0; wpa_drivers[i]; i++) { |
| 2989 | if (os_strlen(wpa_drivers[i]->name) == len && |
| 2990 | os_strncmp(driver, wpa_drivers[i]->name, len) == |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2991 | 0) { |
| 2992 | /* First driver that succeeds wins */ |
| 2993 | if (select_driver(wpa_s, i) == 0) |
| 2994 | return 0; |
| 2995 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2996 | } |
| 2997 | |
| 2998 | driver = pos + 1; |
| 2999 | } while (pos); |
| 3000 | |
| 3001 | wpa_msg(wpa_s, MSG_ERROR, "Unsupported driver '%s'", name); |
| 3002 | return -1; |
| 3003 | } |
| 3004 | |
| 3005 | |
| 3006 | /** |
| 3007 | * wpa_supplicant_rx_eapol - Deliver a received EAPOL frame to wpa_supplicant |
| 3008 | * @ctx: Context pointer (wpa_s); this is the ctx variable registered |
| 3009 | * with struct wpa_driver_ops::init() |
| 3010 | * @src_addr: Source address of the EAPOL frame |
| 3011 | * @buf: EAPOL data starting from the EAPOL header (i.e., no Ethernet header) |
| 3012 | * @len: Length of the EAPOL data |
| 3013 | * |
| 3014 | * This function is called for each received EAPOL frame. Most driver |
| 3015 | * interfaces rely on more generic OS mechanism for receiving frames through |
| 3016 | * l2_packet, but if such a mechanism is not available, the driver wrapper may |
| 3017 | * take care of received EAPOL frames and deliver them to the core supplicant |
| 3018 | * code by calling this function. |
| 3019 | */ |
| 3020 | void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr, |
| 3021 | const u8 *buf, size_t len) |
| 3022 | { |
| 3023 | struct wpa_supplicant *wpa_s = ctx; |
| 3024 | |
| 3025 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR, MAC2STR(src_addr)); |
| 3026 | wpa_hexdump(MSG_MSGDUMP, "RX EAPOL", buf, len); |
| 3027 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3028 | #ifdef CONFIG_PEERKEY |
| 3029 | if (wpa_s->wpa_state > WPA_ASSOCIATED && wpa_s->current_ssid && |
| 3030 | wpa_s->current_ssid->peerkey && |
| 3031 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
| 3032 | wpa_sm_rx_eapol_peerkey(wpa_s->wpa, src_addr, buf, len) == 1) { |
| 3033 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: Processed PeerKey EAPOL-Key"); |
| 3034 | return; |
| 3035 | } |
| 3036 | #endif /* CONFIG_PEERKEY */ |
| 3037 | |
Jouni Malinen | a05074c | 2012-12-21 21:35:35 +0200 | [diff] [blame] | 3038 | if (wpa_s->wpa_state < WPA_ASSOCIATED || |
| 3039 | (wpa_s->last_eapol_matches_bssid && |
| 3040 | #ifdef CONFIG_AP |
| 3041 | !wpa_s->ap_iface && |
| 3042 | #endif /* CONFIG_AP */ |
| 3043 | os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) != 0)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3044 | /* |
| 3045 | * There is possible race condition between receiving the |
| 3046 | * association event and the EAPOL frame since they are coming |
| 3047 | * through different paths from the driver. In order to avoid |
| 3048 | * issues in trying to process the EAPOL frame before receiving |
| 3049 | * association information, lets queue it for processing until |
Jouni Malinen | a05074c | 2012-12-21 21:35:35 +0200 | [diff] [blame] | 3050 | * the association event is received. This may also be needed in |
| 3051 | * driver-based roaming case, so also use src_addr != BSSID as a |
| 3052 | * trigger if we have previously confirmed that the |
| 3053 | * Authenticator uses BSSID as the src_addr (which is not the |
| 3054 | * case with wired IEEE 802.1X). |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3055 | */ |
| 3056 | wpa_dbg(wpa_s, MSG_DEBUG, "Not associated - Delay processing " |
Jouni Malinen | a05074c | 2012-12-21 21:35:35 +0200 | [diff] [blame] | 3057 | "of received EAPOL frame (state=%s bssid=" MACSTR ")", |
| 3058 | wpa_supplicant_state_txt(wpa_s->wpa_state), |
| 3059 | MAC2STR(wpa_s->bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3060 | wpabuf_free(wpa_s->pending_eapol_rx); |
| 3061 | wpa_s->pending_eapol_rx = wpabuf_alloc_copy(buf, len); |
| 3062 | if (wpa_s->pending_eapol_rx) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3063 | os_get_reltime(&wpa_s->pending_eapol_rx_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3064 | os_memcpy(wpa_s->pending_eapol_rx_src, src_addr, |
| 3065 | ETH_ALEN); |
| 3066 | } |
| 3067 | return; |
| 3068 | } |
| 3069 | |
Jouni Malinen | a05074c | 2012-12-21 21:35:35 +0200 | [diff] [blame] | 3070 | wpa_s->last_eapol_matches_bssid = |
| 3071 | os_memcmp(src_addr, wpa_s->bssid, ETH_ALEN) == 0; |
| 3072 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3073 | #ifdef CONFIG_AP |
| 3074 | if (wpa_s->ap_iface) { |
| 3075 | wpa_supplicant_ap_rx_eapol(wpa_s, src_addr, buf, len); |
| 3076 | return; |
| 3077 | } |
| 3078 | #endif /* CONFIG_AP */ |
| 3079 | |
| 3080 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE) { |
| 3081 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignored received EAPOL frame since " |
| 3082 | "no key management is configured"); |
| 3083 | return; |
| 3084 | } |
| 3085 | |
| 3086 | if (wpa_s->eapol_received == 0 && |
| 3087 | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) || |
| 3088 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 3089 | wpa_s->wpa_state != WPA_COMPLETED) && |
| 3090 | (wpa_s->current_ssid == NULL || |
| 3091 | wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) { |
| 3092 | /* Timeout for completing IEEE 802.1X and WPA authentication */ |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3093 | int timeout = 10; |
| 3094 | |
| 3095 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 3096 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA || |
| 3097 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS) { |
| 3098 | /* Use longer timeout for IEEE 802.1X/EAP */ |
| 3099 | timeout = 70; |
| 3100 | } |
| 3101 | |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3102 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3103 | if (wpa_s->current_ssid && wpa_s->current_bss && |
| 3104 | (wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) && |
| 3105 | eap_is_wps_pin_enrollee(&wpa_s->current_ssid->eap)) { |
| 3106 | /* |
| 3107 | * Use shorter timeout if going through WPS AP iteration |
| 3108 | * for PIN config method with an AP that does not |
| 3109 | * advertise Selected Registrar. |
| 3110 | */ |
| 3111 | struct wpabuf *wps_ie; |
| 3112 | |
| 3113 | wps_ie = wpa_bss_get_vendor_ie_multi( |
| 3114 | wpa_s->current_bss, WPS_IE_VENDOR_TYPE); |
| 3115 | if (wps_ie && |
| 3116 | !wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 1)) |
| 3117 | timeout = 10; |
| 3118 | wpabuf_free(wps_ie); |
| 3119 | } |
Dmitry Shmidt | 8bd70b7 | 2015-05-26 16:02:19 -0700 | [diff] [blame] | 3120 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3121 | |
| 3122 | wpa_supplicant_req_auth_timeout(wpa_s, timeout, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3123 | } |
| 3124 | wpa_s->eapol_received++; |
| 3125 | |
| 3126 | if (wpa_s->countermeasures) { |
| 3127 | wpa_msg(wpa_s, MSG_INFO, "WPA: Countermeasures - dropped " |
| 3128 | "EAPOL packet"); |
| 3129 | return; |
| 3130 | } |
| 3131 | |
| 3132 | #ifdef CONFIG_IBSS_RSN |
| 3133 | if (wpa_s->current_ssid && |
| 3134 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS) { |
| 3135 | ibss_rsn_rx_eapol(wpa_s->ibss_rsn, src_addr, buf, len); |
| 3136 | return; |
| 3137 | } |
| 3138 | #endif /* CONFIG_IBSS_RSN */ |
| 3139 | |
| 3140 | /* Source address of the incoming EAPOL frame could be compared to the |
| 3141 | * current BSSID. However, it is possible that a centralized |
| 3142 | * Authenticator could be using another MAC address than the BSSID of |
| 3143 | * an AP, so just allow any address to be used for now. The replies are |
| 3144 | * still sent to the current BSSID (if available), though. */ |
| 3145 | |
| 3146 | os_memcpy(wpa_s->last_eapol_src, src_addr, ETH_ALEN); |
| 3147 | if (!wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) && |
| 3148 | eapol_sm_rx_eapol(wpa_s->eapol, src_addr, buf, len) > 0) |
| 3149 | return; |
| 3150 | wpa_drv_poll(wpa_s); |
| 3151 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) |
| 3152 | wpa_sm_rx_eapol(wpa_s->wpa, src_addr, buf, len); |
| 3153 | else if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
| 3154 | /* |
| 3155 | * Set portValid = TRUE here since we are going to skip 4-way |
| 3156 | * handshake processing which would normally set portValid. We |
| 3157 | * need this to allow the EAPOL state machines to be completed |
| 3158 | * without going through EAPOL-Key handshake. |
| 3159 | */ |
| 3160 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3165 | int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3166 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3167 | if ((!wpa_s->p2p_mgmt || |
| 3168 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) && |
| 3169 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_P2P_DEDICATED_INTERFACE)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3170 | l2_packet_deinit(wpa_s->l2); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3171 | wpa_s->l2 = l2_packet_init(wpa_s->ifname, |
| 3172 | wpa_drv_get_mac_addr(wpa_s), |
| 3173 | ETH_P_EAPOL, |
| 3174 | wpa_supplicant_rx_eapol, wpa_s, 0); |
| 3175 | if (wpa_s->l2 == NULL) |
| 3176 | return -1; |
| 3177 | } else { |
| 3178 | const u8 *addr = wpa_drv_get_mac_addr(wpa_s); |
| 3179 | if (addr) |
| 3180 | os_memcpy(wpa_s->own_addr, addr, ETH_ALEN); |
| 3181 | } |
| 3182 | |
| 3183 | if (wpa_s->l2 && l2_packet_get_own_addr(wpa_s->l2, wpa_s->own_addr)) { |
| 3184 | wpa_msg(wpa_s, MSG_ERROR, "Failed to get own L2 address"); |
| 3185 | return -1; |
| 3186 | } |
| 3187 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3188 | wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr); |
| 3189 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3190 | return 0; |
| 3191 | } |
| 3192 | |
| 3193 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3194 | static void wpa_supplicant_rx_eapol_bridge(void *ctx, const u8 *src_addr, |
| 3195 | const u8 *buf, size_t len) |
| 3196 | { |
| 3197 | struct wpa_supplicant *wpa_s = ctx; |
| 3198 | const struct l2_ethhdr *eth; |
| 3199 | |
| 3200 | if (len < sizeof(*eth)) |
| 3201 | return; |
| 3202 | eth = (const struct l2_ethhdr *) buf; |
| 3203 | |
| 3204 | if (os_memcmp(eth->h_dest, wpa_s->own_addr, ETH_ALEN) != 0 && |
| 3205 | !(eth->h_dest[0] & 0x01)) { |
| 3206 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR |
| 3207 | " (bridge - not for this interface - ignore)", |
| 3208 | MAC2STR(src_addr), MAC2STR(eth->h_dest)); |
| 3209 | return; |
| 3210 | } |
| 3211 | |
| 3212 | wpa_dbg(wpa_s, MSG_DEBUG, "RX EAPOL from " MACSTR " to " MACSTR |
| 3213 | " (bridge)", MAC2STR(src_addr), MAC2STR(eth->h_dest)); |
| 3214 | wpa_supplicant_rx_eapol(wpa_s, src_addr, buf + sizeof(*eth), |
| 3215 | len - sizeof(*eth)); |
| 3216 | } |
| 3217 | |
| 3218 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3219 | /** |
| 3220 | * wpa_supplicant_driver_init - Initialize driver interface parameters |
| 3221 | * @wpa_s: Pointer to wpa_supplicant data |
| 3222 | * Returns: 0 on success, -1 on failure |
| 3223 | * |
| 3224 | * This function is called to initialize driver interface parameters. |
| 3225 | * wpa_drv_init() must have been called before this function to initialize the |
| 3226 | * driver interface. |
| 3227 | */ |
| 3228 | int wpa_supplicant_driver_init(struct wpa_supplicant *wpa_s) |
| 3229 | { |
| 3230 | static int interface_count = 0; |
| 3231 | |
| 3232 | if (wpa_supplicant_update_mac_addr(wpa_s) < 0) |
| 3233 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3234 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3235 | wpa_dbg(wpa_s, MSG_DEBUG, "Own MAC address: " MACSTR, |
| 3236 | MAC2STR(wpa_s->own_addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3237 | os_memcpy(wpa_s->perm_addr, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3238 | wpa_sm_set_own_addr(wpa_s->wpa, wpa_s->own_addr); |
| 3239 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3240 | if (wpa_s->bridge_ifname[0]) { |
| 3241 | wpa_dbg(wpa_s, MSG_DEBUG, "Receiving packets from bridge " |
| 3242 | "interface '%s'", wpa_s->bridge_ifname); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3243 | wpa_s->l2_br = l2_packet_init_bridge( |
| 3244 | wpa_s->bridge_ifname, wpa_s->ifname, wpa_s->own_addr, |
| 3245 | ETH_P_EAPOL, wpa_supplicant_rx_eapol_bridge, wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3246 | if (wpa_s->l2_br == NULL) { |
| 3247 | wpa_msg(wpa_s, MSG_ERROR, "Failed to open l2_packet " |
| 3248 | "connection for the bridge interface '%s'", |
| 3249 | wpa_s->bridge_ifname); |
| 3250 | return -1; |
| 3251 | } |
| 3252 | } |
| 3253 | |
| 3254 | wpa_clear_keys(wpa_s, NULL); |
| 3255 | |
| 3256 | /* Make sure that TKIP countermeasures are not left enabled (could |
| 3257 | * happen if wpa_supplicant is killed during countermeasures. */ |
| 3258 | wpa_drv_set_countermeasures(wpa_s, 0); |
| 3259 | |
| 3260 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: flushing PMKID list in the driver"); |
| 3261 | wpa_drv_flush_pmkid(wpa_s); |
| 3262 | |
| 3263 | wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3264 | wpa_s->prev_scan_wildcard = 0; |
| 3265 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3266 | if (wpa_supplicant_enabled_networks(wpa_s)) { |
Dmitry Shmidt | 9e3f8ee | 2014-01-17 10:52:01 -0800 | [diff] [blame] | 3267 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 3268 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 3269 | interface_count = 0; |
| 3270 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3271 | #ifndef ANDROID |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 3272 | if (!wpa_s->p2p_mgmt && |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3273 | wpa_supplicant_delayed_sched_scan(wpa_s, |
| 3274 | interface_count % 3, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3275 | 100000)) |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3276 | wpa_supplicant_req_scan(wpa_s, interface_count % 3, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3277 | 100000); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3278 | #endif /* ANDROID */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3279 | interface_count++; |
| 3280 | } else |
| 3281 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 3282 | |
| 3283 | return 0; |
| 3284 | } |
| 3285 | |
| 3286 | |
| 3287 | static int wpa_supplicant_daemon(const char *pid_file) |
| 3288 | { |
| 3289 | wpa_printf(MSG_DEBUG, "Daemonize.."); |
| 3290 | return os_daemonize(pid_file); |
| 3291 | } |
| 3292 | |
| 3293 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 3294 | static struct wpa_supplicant * |
| 3295 | wpa_supplicant_alloc(struct wpa_supplicant *parent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3296 | { |
| 3297 | struct wpa_supplicant *wpa_s; |
| 3298 | |
| 3299 | wpa_s = os_zalloc(sizeof(*wpa_s)); |
| 3300 | if (wpa_s == NULL) |
| 3301 | return NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3302 | wpa_s->scan_req = INITIAL_SCAN_REQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3303 | wpa_s->scan_interval = 5; |
| 3304 | wpa_s->new_connection = 1; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 3305 | wpa_s->parent = parent ? parent : wpa_s; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3306 | wpa_s->sched_scanning = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3307 | |
| 3308 | return wpa_s; |
| 3309 | } |
| 3310 | |
| 3311 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3312 | #ifdef CONFIG_HT_OVERRIDES |
| 3313 | |
| 3314 | static int wpa_set_htcap_mcs(struct wpa_supplicant *wpa_s, |
| 3315 | struct ieee80211_ht_capabilities *htcaps, |
| 3316 | struct ieee80211_ht_capabilities *htcaps_mask, |
| 3317 | const char *ht_mcs) |
| 3318 | { |
| 3319 | /* parse ht_mcs into hex array */ |
| 3320 | int i; |
| 3321 | const char *tmp = ht_mcs; |
| 3322 | char *end = NULL; |
| 3323 | |
| 3324 | /* If ht_mcs is null, do not set anything */ |
| 3325 | if (!ht_mcs) |
| 3326 | return 0; |
| 3327 | |
| 3328 | /* This is what we are setting in the kernel */ |
| 3329 | os_memset(&htcaps->supported_mcs_set, 0, IEEE80211_HT_MCS_MASK_LEN); |
| 3330 | |
| 3331 | wpa_msg(wpa_s, MSG_DEBUG, "set_htcap, ht_mcs -:%s:-", ht_mcs); |
| 3332 | |
| 3333 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { |
| 3334 | errno = 0; |
| 3335 | long v = strtol(tmp, &end, 16); |
| 3336 | if (errno == 0) { |
| 3337 | wpa_msg(wpa_s, MSG_DEBUG, |
| 3338 | "htcap value[%i]: %ld end: %p tmp: %p", |
| 3339 | i, v, end, tmp); |
| 3340 | if (end == tmp) |
| 3341 | break; |
| 3342 | |
| 3343 | htcaps->supported_mcs_set[i] = v; |
| 3344 | tmp = end; |
| 3345 | } else { |
| 3346 | wpa_msg(wpa_s, MSG_ERROR, |
| 3347 | "Failed to parse ht-mcs: %s, error: %s\n", |
| 3348 | ht_mcs, strerror(errno)); |
| 3349 | return -1; |
| 3350 | } |
| 3351 | } |
| 3352 | |
| 3353 | /* |
| 3354 | * If we were able to parse any values, then set mask for the MCS set. |
| 3355 | */ |
| 3356 | if (i) { |
| 3357 | os_memset(&htcaps_mask->supported_mcs_set, 0xff, |
| 3358 | IEEE80211_HT_MCS_MASK_LEN - 1); |
| 3359 | /* skip the 3 reserved bits */ |
| 3360 | htcaps_mask->supported_mcs_set[IEEE80211_HT_MCS_MASK_LEN - 1] = |
| 3361 | 0x1f; |
| 3362 | } |
| 3363 | |
| 3364 | return 0; |
| 3365 | } |
| 3366 | |
| 3367 | |
| 3368 | static int wpa_disable_max_amsdu(struct wpa_supplicant *wpa_s, |
| 3369 | struct ieee80211_ht_capabilities *htcaps, |
| 3370 | struct ieee80211_ht_capabilities *htcaps_mask, |
| 3371 | int disabled) |
| 3372 | { |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 3373 | le16 msk; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3374 | |
| 3375 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_max_amsdu: %d", disabled); |
| 3376 | |
| 3377 | if (disabled == -1) |
| 3378 | return 0; |
| 3379 | |
| 3380 | msk = host_to_le16(HT_CAP_INFO_MAX_AMSDU_SIZE); |
| 3381 | htcaps_mask->ht_capabilities_info |= msk; |
| 3382 | if (disabled) |
| 3383 | htcaps->ht_capabilities_info &= msk; |
| 3384 | else |
| 3385 | htcaps->ht_capabilities_info |= msk; |
| 3386 | |
| 3387 | return 0; |
| 3388 | } |
| 3389 | |
| 3390 | |
| 3391 | static int wpa_set_ampdu_factor(struct wpa_supplicant *wpa_s, |
| 3392 | struct ieee80211_ht_capabilities *htcaps, |
| 3393 | struct ieee80211_ht_capabilities *htcaps_mask, |
| 3394 | int factor) |
| 3395 | { |
| 3396 | wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_factor: %d", factor); |
| 3397 | |
| 3398 | if (factor == -1) |
| 3399 | return 0; |
| 3400 | |
| 3401 | if (factor < 0 || factor > 3) { |
| 3402 | wpa_msg(wpa_s, MSG_ERROR, "ampdu_factor: %d out of range. " |
| 3403 | "Must be 0-3 or -1", factor); |
| 3404 | return -EINVAL; |
| 3405 | } |
| 3406 | |
| 3407 | htcaps_mask->a_mpdu_params |= 0x3; /* 2 bits for factor */ |
| 3408 | htcaps->a_mpdu_params &= ~0x3; |
| 3409 | htcaps->a_mpdu_params |= factor & 0x3; |
| 3410 | |
| 3411 | return 0; |
| 3412 | } |
| 3413 | |
| 3414 | |
| 3415 | static int wpa_set_ampdu_density(struct wpa_supplicant *wpa_s, |
| 3416 | struct ieee80211_ht_capabilities *htcaps, |
| 3417 | struct ieee80211_ht_capabilities *htcaps_mask, |
| 3418 | int density) |
| 3419 | { |
| 3420 | wpa_msg(wpa_s, MSG_DEBUG, "set_ampdu_density: %d", density); |
| 3421 | |
| 3422 | if (density == -1) |
| 3423 | return 0; |
| 3424 | |
| 3425 | if (density < 0 || density > 7) { |
| 3426 | wpa_msg(wpa_s, MSG_ERROR, |
| 3427 | "ampdu_density: %d out of range. Must be 0-7 or -1.", |
| 3428 | density); |
| 3429 | return -EINVAL; |
| 3430 | } |
| 3431 | |
| 3432 | htcaps_mask->a_mpdu_params |= 0x1C; |
| 3433 | htcaps->a_mpdu_params &= ~(0x1C); |
| 3434 | htcaps->a_mpdu_params |= (density << 2) & 0x1C; |
| 3435 | |
| 3436 | return 0; |
| 3437 | } |
| 3438 | |
| 3439 | |
| 3440 | static int wpa_set_disable_ht40(struct wpa_supplicant *wpa_s, |
| 3441 | struct ieee80211_ht_capabilities *htcaps, |
| 3442 | struct ieee80211_ht_capabilities *htcaps_mask, |
| 3443 | int disabled) |
| 3444 | { |
| 3445 | /* Masking these out disables HT40 */ |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 3446 | le16 msk = host_to_le16(HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET | |
| 3447 | HT_CAP_INFO_SHORT_GI40MHZ); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3448 | |
| 3449 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ht40: %d", disabled); |
| 3450 | |
| 3451 | if (disabled) |
| 3452 | htcaps->ht_capabilities_info &= ~msk; |
| 3453 | else |
| 3454 | htcaps->ht_capabilities_info |= msk; |
| 3455 | |
| 3456 | htcaps_mask->ht_capabilities_info |= msk; |
| 3457 | |
| 3458 | return 0; |
| 3459 | } |
| 3460 | |
| 3461 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3462 | static int wpa_set_disable_sgi(struct wpa_supplicant *wpa_s, |
| 3463 | struct ieee80211_ht_capabilities *htcaps, |
| 3464 | struct ieee80211_ht_capabilities *htcaps_mask, |
| 3465 | int disabled) |
| 3466 | { |
| 3467 | /* Masking these out disables SGI */ |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 3468 | le16 msk = host_to_le16(HT_CAP_INFO_SHORT_GI20MHZ | |
| 3469 | HT_CAP_INFO_SHORT_GI40MHZ); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3470 | |
| 3471 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_sgi: %d", disabled); |
| 3472 | |
| 3473 | if (disabled) |
| 3474 | htcaps->ht_capabilities_info &= ~msk; |
| 3475 | else |
| 3476 | htcaps->ht_capabilities_info |= msk; |
| 3477 | |
| 3478 | htcaps_mask->ht_capabilities_info |= msk; |
| 3479 | |
| 3480 | return 0; |
| 3481 | } |
| 3482 | |
| 3483 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 3484 | static int wpa_set_disable_ldpc(struct wpa_supplicant *wpa_s, |
| 3485 | struct ieee80211_ht_capabilities *htcaps, |
| 3486 | struct ieee80211_ht_capabilities *htcaps_mask, |
| 3487 | int disabled) |
| 3488 | { |
| 3489 | /* Masking these out disables LDPC */ |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 3490 | le16 msk = host_to_le16(HT_CAP_INFO_LDPC_CODING_CAP); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 3491 | |
| 3492 | wpa_msg(wpa_s, MSG_DEBUG, "set_disable_ldpc: %d", disabled); |
| 3493 | |
| 3494 | if (disabled) |
| 3495 | htcaps->ht_capabilities_info &= ~msk; |
| 3496 | else |
| 3497 | htcaps->ht_capabilities_info |= msk; |
| 3498 | |
| 3499 | htcaps_mask->ht_capabilities_info |= msk; |
| 3500 | |
| 3501 | return 0; |
| 3502 | } |
| 3503 | |
| 3504 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3505 | void wpa_supplicant_apply_ht_overrides( |
| 3506 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 3507 | struct wpa_driver_associate_params *params) |
| 3508 | { |
| 3509 | struct ieee80211_ht_capabilities *htcaps; |
| 3510 | struct ieee80211_ht_capabilities *htcaps_mask; |
| 3511 | |
| 3512 | if (!ssid) |
| 3513 | return; |
| 3514 | |
| 3515 | params->disable_ht = ssid->disable_ht; |
| 3516 | if (!params->htcaps || !params->htcaps_mask) |
| 3517 | return; |
| 3518 | |
| 3519 | htcaps = (struct ieee80211_ht_capabilities *) params->htcaps; |
| 3520 | htcaps_mask = (struct ieee80211_ht_capabilities *) params->htcaps_mask; |
| 3521 | wpa_set_htcap_mcs(wpa_s, htcaps, htcaps_mask, ssid->ht_mcs); |
| 3522 | wpa_disable_max_amsdu(wpa_s, htcaps, htcaps_mask, |
| 3523 | ssid->disable_max_amsdu); |
| 3524 | wpa_set_ampdu_factor(wpa_s, htcaps, htcaps_mask, ssid->ampdu_factor); |
| 3525 | wpa_set_ampdu_density(wpa_s, htcaps, htcaps_mask, ssid->ampdu_density); |
| 3526 | wpa_set_disable_ht40(wpa_s, htcaps, htcaps_mask, ssid->disable_ht40); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3527 | wpa_set_disable_sgi(wpa_s, htcaps, htcaps_mask, ssid->disable_sgi); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 3528 | wpa_set_disable_ldpc(wpa_s, htcaps, htcaps_mask, ssid->disable_ldpc); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 3529 | |
| 3530 | if (ssid->ht40_intolerant) { |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 3531 | le16 bit = host_to_le16(HT_CAP_INFO_40MHZ_INTOLERANT); |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 3532 | htcaps->ht_capabilities_info |= bit; |
| 3533 | htcaps_mask->ht_capabilities_info |= bit; |
| 3534 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | #endif /* CONFIG_HT_OVERRIDES */ |
| 3538 | |
| 3539 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3540 | #ifdef CONFIG_VHT_OVERRIDES |
| 3541 | void wpa_supplicant_apply_vht_overrides( |
| 3542 | struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 3543 | struct wpa_driver_associate_params *params) |
| 3544 | { |
| 3545 | struct ieee80211_vht_capabilities *vhtcaps; |
| 3546 | struct ieee80211_vht_capabilities *vhtcaps_mask; |
| 3547 | |
| 3548 | if (!ssid) |
| 3549 | return; |
| 3550 | |
| 3551 | params->disable_vht = ssid->disable_vht; |
| 3552 | |
| 3553 | vhtcaps = (void *) params->vhtcaps; |
| 3554 | vhtcaps_mask = (void *) params->vhtcaps_mask; |
| 3555 | |
| 3556 | if (!vhtcaps || !vhtcaps_mask) |
| 3557 | return; |
| 3558 | |
| 3559 | vhtcaps->vht_capabilities_info = ssid->vht_capa; |
| 3560 | vhtcaps_mask->vht_capabilities_info = ssid->vht_capa_mask; |
| 3561 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 3562 | #ifdef CONFIG_HT_OVERRIDES |
| 3563 | /* if max ampdu is <= 3, we have to make the HT cap the same */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3564 | if (ssid->vht_capa_mask & VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) { |
| 3565 | int max_ampdu; |
| 3566 | |
| 3567 | max_ampdu = (ssid->vht_capa & |
| 3568 | VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX) >> |
| 3569 | VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX_SHIFT; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 3570 | |
| 3571 | max_ampdu = max_ampdu < 3 ? max_ampdu : 3; |
| 3572 | wpa_set_ampdu_factor(wpa_s, |
| 3573 | (void *) params->htcaps, |
| 3574 | (void *) params->htcaps_mask, |
| 3575 | max_ampdu); |
| 3576 | } |
| 3577 | #endif /* CONFIG_HT_OVERRIDES */ |
| 3578 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 3579 | #define OVERRIDE_MCS(i) \ |
| 3580 | if (ssid->vht_tx_mcs_nss_ ##i >= 0) { \ |
| 3581 | vhtcaps_mask->vht_supported_mcs_set.tx_map |= \ |
| 3582 | 3 << 2 * (i - 1); \ |
| 3583 | vhtcaps->vht_supported_mcs_set.tx_map |= \ |
| 3584 | ssid->vht_tx_mcs_nss_ ##i << 2 * (i - 1); \ |
| 3585 | } \ |
| 3586 | if (ssid->vht_rx_mcs_nss_ ##i >= 0) { \ |
| 3587 | vhtcaps_mask->vht_supported_mcs_set.rx_map |= \ |
| 3588 | 3 << 2 * (i - 1); \ |
| 3589 | vhtcaps->vht_supported_mcs_set.rx_map |= \ |
| 3590 | ssid->vht_rx_mcs_nss_ ##i << 2 * (i - 1); \ |
| 3591 | } |
| 3592 | |
| 3593 | OVERRIDE_MCS(1); |
| 3594 | OVERRIDE_MCS(2); |
| 3595 | OVERRIDE_MCS(3); |
| 3596 | OVERRIDE_MCS(4); |
| 3597 | OVERRIDE_MCS(5); |
| 3598 | OVERRIDE_MCS(6); |
| 3599 | OVERRIDE_MCS(7); |
| 3600 | OVERRIDE_MCS(8); |
| 3601 | } |
| 3602 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 3603 | |
| 3604 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3605 | static int pcsc_reader_init(struct wpa_supplicant *wpa_s) |
| 3606 | { |
| 3607 | #ifdef PCSC_FUNCS |
| 3608 | size_t len; |
| 3609 | |
| 3610 | if (!wpa_s->conf->pcsc_reader) |
| 3611 | return 0; |
| 3612 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3613 | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3614 | if (!wpa_s->scard) |
| 3615 | return 1; |
| 3616 | |
| 3617 | if (wpa_s->conf->pcsc_pin && |
| 3618 | scard_set_pin(wpa_s->scard, wpa_s->conf->pcsc_pin) < 0) { |
| 3619 | scard_deinit(wpa_s->scard); |
| 3620 | wpa_s->scard = NULL; |
| 3621 | wpa_msg(wpa_s, MSG_ERROR, "PC/SC PIN validation failed"); |
| 3622 | return -1; |
| 3623 | } |
| 3624 | |
| 3625 | len = sizeof(wpa_s->imsi) - 1; |
| 3626 | if (scard_get_imsi(wpa_s->scard, wpa_s->imsi, &len)) { |
| 3627 | scard_deinit(wpa_s->scard); |
| 3628 | wpa_s->scard = NULL; |
| 3629 | wpa_msg(wpa_s, MSG_ERROR, "Could not read IMSI"); |
| 3630 | return -1; |
| 3631 | } |
| 3632 | wpa_s->imsi[len] = '\0'; |
| 3633 | |
| 3634 | wpa_s->mnc_len = scard_get_mnc_len(wpa_s->scard); |
| 3635 | |
| 3636 | wpa_printf(MSG_DEBUG, "SCARD: IMSI %s (MNC length %d)", |
| 3637 | wpa_s->imsi, wpa_s->mnc_len); |
| 3638 | |
| 3639 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); |
| 3640 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); |
| 3641 | #endif /* PCSC_FUNCS */ |
| 3642 | |
| 3643 | return 0; |
| 3644 | } |
| 3645 | |
| 3646 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3647 | int wpas_init_ext_pw(struct wpa_supplicant *wpa_s) |
| 3648 | { |
| 3649 | char *val, *pos; |
| 3650 | |
| 3651 | ext_password_deinit(wpa_s->ext_pw); |
| 3652 | wpa_s->ext_pw = NULL; |
| 3653 | eapol_sm_set_ext_pw_ctx(wpa_s->eapol, NULL); |
| 3654 | |
| 3655 | if (!wpa_s->conf->ext_password_backend) |
| 3656 | return 0; |
| 3657 | |
| 3658 | val = os_strdup(wpa_s->conf->ext_password_backend); |
| 3659 | if (val == NULL) |
| 3660 | return -1; |
| 3661 | pos = os_strchr(val, ':'); |
| 3662 | if (pos) |
| 3663 | *pos++ = '\0'; |
| 3664 | |
| 3665 | wpa_printf(MSG_DEBUG, "EXT PW: Initialize backend '%s'", val); |
| 3666 | |
| 3667 | wpa_s->ext_pw = ext_password_init(val, pos); |
| 3668 | os_free(val); |
| 3669 | if (wpa_s->ext_pw == NULL) { |
| 3670 | wpa_printf(MSG_DEBUG, "EXT PW: Failed to initialize backend"); |
| 3671 | return -1; |
| 3672 | } |
| 3673 | eapol_sm_set_ext_pw_ctx(wpa_s->eapol, wpa_s->ext_pw); |
| 3674 | |
| 3675 | return 0; |
| 3676 | } |
| 3677 | |
| 3678 | |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 3679 | static int wpas_set_wowlan_triggers(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3680 | const struct wpa_driver_capa *capa) |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3681 | { |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 3682 | struct wowlan_triggers *triggers; |
| 3683 | int ret = 0; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3684 | |
| 3685 | if (!wpa_s->conf->wowlan_triggers) |
| 3686 | return 0; |
| 3687 | |
Dmitry Shmidt | 0207e23 | 2014-09-03 14:58:37 -0700 | [diff] [blame] | 3688 | triggers = wpa_get_wowlan_triggers(wpa_s->conf->wowlan_triggers, capa); |
| 3689 | if (triggers) { |
| 3690 | ret = wpa_drv_wowlan(wpa_s, triggers); |
| 3691 | os_free(triggers); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3692 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3693 | return ret; |
| 3694 | } |
| 3695 | |
| 3696 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3697 | static struct wpa_radio * radio_add_interface(struct wpa_supplicant *wpa_s, |
| 3698 | const char *rn) |
| 3699 | { |
| 3700 | struct wpa_supplicant *iface = wpa_s->global->ifaces; |
| 3701 | struct wpa_radio *radio; |
| 3702 | |
| 3703 | while (rn && iface) { |
| 3704 | radio = iface->radio; |
| 3705 | if (radio && os_strcmp(rn, radio->name) == 0) { |
| 3706 | wpa_printf(MSG_DEBUG, "Add interface %s to existing radio %s", |
| 3707 | wpa_s->ifname, rn); |
| 3708 | dl_list_add(&radio->ifaces, &wpa_s->radio_list); |
| 3709 | return radio; |
| 3710 | } |
Dmitry Shmidt | 3cf6f79 | 2013-12-18 13:12:19 -0800 | [diff] [blame] | 3711 | |
| 3712 | iface = iface->next; |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3713 | } |
| 3714 | |
| 3715 | wpa_printf(MSG_DEBUG, "Add interface %s to a new radio %s", |
| 3716 | wpa_s->ifname, rn ? rn : "N/A"); |
| 3717 | radio = os_zalloc(sizeof(*radio)); |
| 3718 | if (radio == NULL) |
| 3719 | return NULL; |
| 3720 | |
| 3721 | if (rn) |
| 3722 | os_strlcpy(radio->name, rn, sizeof(radio->name)); |
| 3723 | dl_list_init(&radio->ifaces); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3724 | dl_list_init(&radio->work); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3725 | dl_list_add(&radio->ifaces, &wpa_s->radio_list); |
| 3726 | |
| 3727 | return radio; |
| 3728 | } |
| 3729 | |
| 3730 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3731 | static void radio_work_free(struct wpa_radio_work *work) |
| 3732 | { |
| 3733 | if (work->wpa_s->scan_work == work) { |
| 3734 | /* This should not really happen. */ |
| 3735 | wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as scan_work", |
| 3736 | work->type, work, work->started); |
| 3737 | work->wpa_s->scan_work = NULL; |
| 3738 | } |
| 3739 | |
| 3740 | #ifdef CONFIG_P2P |
| 3741 | if (work->wpa_s->p2p_scan_work == work) { |
| 3742 | /* This should not really happen. */ |
| 3743 | wpa_dbg(work->wpa_s, MSG_INFO, "Freeing radio work '%s'@%p (started=%d) that is marked as p2p_scan_work", |
| 3744 | work->type, work, work->started); |
| 3745 | work->wpa_s->p2p_scan_work = NULL; |
| 3746 | } |
| 3747 | #endif /* CONFIG_P2P */ |
| 3748 | |
| 3749 | dl_list_del(&work->list); |
| 3750 | os_free(work); |
| 3751 | } |
| 3752 | |
| 3753 | |
| 3754 | static void radio_start_next_work(void *eloop_ctx, void *timeout_ctx) |
| 3755 | { |
| 3756 | struct wpa_radio *radio = eloop_ctx; |
| 3757 | struct wpa_radio_work *work; |
| 3758 | struct os_reltime now, diff; |
| 3759 | struct wpa_supplicant *wpa_s; |
| 3760 | |
| 3761 | work = dl_list_first(&radio->work, struct wpa_radio_work, list); |
| 3762 | if (work == NULL) |
| 3763 | return; |
| 3764 | |
| 3765 | if (work->started) |
| 3766 | return; /* already started and still in progress */ |
| 3767 | |
| 3768 | wpa_s = dl_list_first(&radio->ifaces, struct wpa_supplicant, |
| 3769 | radio_list); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3770 | if (wpa_s && wpa_s->radio->external_scan_running) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3771 | wpa_printf(MSG_DEBUG, "Delay radio work start until externally triggered scan completes"); |
| 3772 | return; |
| 3773 | } |
| 3774 | |
| 3775 | os_get_reltime(&now); |
| 3776 | os_reltime_sub(&now, &work->time, &diff); |
| 3777 | wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting radio work '%s'@%p after %ld.%06ld second wait", |
| 3778 | work->type, work, diff.sec, diff.usec); |
| 3779 | work->started = 1; |
| 3780 | work->time = now; |
| 3781 | work->cb(work, 0); |
| 3782 | } |
| 3783 | |
| 3784 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3785 | /* |
| 3786 | * This function removes both started and pending radio works running on |
| 3787 | * the provided interface's radio. |
| 3788 | * Prior to the removal of the radio work, its callback (cb) is called with |
| 3789 | * deinit set to be 1. Each work's callback is responsible for clearing its |
| 3790 | * internal data and restoring to a correct state. |
| 3791 | * @wpa_s: wpa_supplicant data |
| 3792 | * @type: type of works to be removed |
| 3793 | * @remove_all: 1 to remove all the works on this radio, 0 to remove only |
| 3794 | * this interface's works. |
| 3795 | */ |
| 3796 | void radio_remove_works(struct wpa_supplicant *wpa_s, |
| 3797 | const char *type, int remove_all) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3798 | { |
| 3799 | struct wpa_radio_work *work, *tmp; |
| 3800 | struct wpa_radio *radio = wpa_s->radio; |
| 3801 | |
| 3802 | dl_list_for_each_safe(work, tmp, &radio->work, struct wpa_radio_work, |
| 3803 | list) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3804 | if (type && os_strcmp(type, work->type) != 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3805 | continue; |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3806 | |
| 3807 | /* skip other ifaces' works */ |
| 3808 | if (!remove_all && work->wpa_s != wpa_s) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3809 | continue; |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3810 | |
| 3811 | wpa_dbg(wpa_s, MSG_DEBUG, "Remove radio work '%s'@%p%s", |
| 3812 | work->type, work, work->started ? " (started)" : ""); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3813 | work->cb(work, 1); |
| 3814 | radio_work_free(work); |
| 3815 | } |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3816 | |
| 3817 | /* in case we removed the started work */ |
| 3818 | radio_work_check_next(wpa_s); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3822 | static void radio_remove_interface(struct wpa_supplicant *wpa_s) |
| 3823 | { |
| 3824 | struct wpa_radio *radio = wpa_s->radio; |
| 3825 | |
| 3826 | if (!radio) |
| 3827 | return; |
| 3828 | |
| 3829 | wpa_printf(MSG_DEBUG, "Remove interface %s from radio %s", |
| 3830 | wpa_s->ifname, radio->name); |
| 3831 | dl_list_del(&wpa_s->radio_list); |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 3832 | radio_remove_works(wpa_s, NULL, 0); |
| 3833 | wpa_s->radio = NULL; |
| 3834 | if (!dl_list_empty(&radio->ifaces)) |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3835 | return; /* Interfaces remain for this radio */ |
| 3836 | |
| 3837 | wpa_printf(MSG_DEBUG, "Remove radio %s", radio->name); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3838 | eloop_cancel_timeout(radio_start_next_work, radio, NULL); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3839 | os_free(radio); |
| 3840 | } |
| 3841 | |
| 3842 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3843 | void radio_work_check_next(struct wpa_supplicant *wpa_s) |
| 3844 | { |
| 3845 | struct wpa_radio *radio = wpa_s->radio; |
| 3846 | |
| 3847 | if (dl_list_empty(&radio->work)) |
| 3848 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3849 | if (wpa_s->ext_work_in_progress) { |
| 3850 | wpa_printf(MSG_DEBUG, |
| 3851 | "External radio work in progress - delay start of pending item"); |
| 3852 | return; |
| 3853 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3854 | eloop_cancel_timeout(radio_start_next_work, radio, NULL); |
| 3855 | eloop_register_timeout(0, 0, radio_start_next_work, radio, NULL); |
| 3856 | } |
| 3857 | |
| 3858 | |
| 3859 | /** |
| 3860 | * radio_add_work - Add a radio work item |
| 3861 | * @wpa_s: Pointer to wpa_supplicant data |
| 3862 | * @freq: Frequency of the offchannel operation in MHz or 0 |
| 3863 | * @type: Unique identifier for each type of work |
| 3864 | * @next: Force as the next work to be executed |
| 3865 | * @cb: Callback function for indicating when radio is available |
| 3866 | * @ctx: Context pointer for the work (work->ctx in cb()) |
| 3867 | * Returns: 0 on success, -1 on failure |
| 3868 | * |
| 3869 | * This function is used to request time for an operation that requires |
| 3870 | * exclusive radio control. Once the radio is available, the registered callback |
| 3871 | * function will be called. radio_work_done() must be called once the exclusive |
| 3872 | * radio operation has been completed, so that the radio is freed for other |
| 3873 | * operations. The special case of deinit=1 is used to free the context data |
| 3874 | * during interface removal. That does not allow the callback function to start |
| 3875 | * the radio operation, i.e., it must free any resources allocated for the radio |
| 3876 | * work and return. |
| 3877 | * |
| 3878 | * The @freq parameter can be used to indicate a single channel on which the |
| 3879 | * offchannel operation will occur. This may allow multiple radio work |
| 3880 | * operations to be performed in parallel if they apply for the same channel. |
| 3881 | * Setting this to 0 indicates that the work item may use multiple channels or |
| 3882 | * requires exclusive control of the radio. |
| 3883 | */ |
| 3884 | int radio_add_work(struct wpa_supplicant *wpa_s, unsigned int freq, |
| 3885 | const char *type, int next, |
| 3886 | void (*cb)(struct wpa_radio_work *work, int deinit), |
| 3887 | void *ctx) |
| 3888 | { |
| 3889 | struct wpa_radio_work *work; |
| 3890 | int was_empty; |
| 3891 | |
| 3892 | work = os_zalloc(sizeof(*work)); |
| 3893 | if (work == NULL) |
| 3894 | return -1; |
| 3895 | wpa_dbg(wpa_s, MSG_DEBUG, "Add radio work '%s'@%p", type, work); |
| 3896 | os_get_reltime(&work->time); |
| 3897 | work->freq = freq; |
| 3898 | work->type = type; |
| 3899 | work->wpa_s = wpa_s; |
| 3900 | work->cb = cb; |
| 3901 | work->ctx = ctx; |
| 3902 | |
| 3903 | was_empty = dl_list_empty(&wpa_s->radio->work); |
| 3904 | if (next) |
| 3905 | dl_list_add(&wpa_s->radio->work, &work->list); |
| 3906 | else |
| 3907 | dl_list_add_tail(&wpa_s->radio->work, &work->list); |
| 3908 | if (was_empty) { |
| 3909 | wpa_dbg(wpa_s, MSG_DEBUG, "First radio work item in the queue - schedule start immediately"); |
| 3910 | radio_work_check_next(wpa_s); |
| 3911 | } |
| 3912 | |
| 3913 | return 0; |
| 3914 | } |
| 3915 | |
| 3916 | |
| 3917 | /** |
| 3918 | * radio_work_done - Indicate that a radio work item has been completed |
| 3919 | * @work: Completed work |
| 3920 | * |
| 3921 | * This function is called once the callback function registered with |
| 3922 | * radio_add_work() has completed its work. |
| 3923 | */ |
| 3924 | void radio_work_done(struct wpa_radio_work *work) |
| 3925 | { |
| 3926 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 3927 | struct os_reltime now, diff; |
| 3928 | unsigned int started = work->started; |
| 3929 | |
| 3930 | os_get_reltime(&now); |
| 3931 | os_reltime_sub(&now, &work->time, &diff); |
| 3932 | wpa_dbg(wpa_s, MSG_DEBUG, "Radio work '%s'@%p %s in %ld.%06ld seconds", |
| 3933 | work->type, work, started ? "done" : "canceled", |
| 3934 | diff.sec, diff.usec); |
| 3935 | radio_work_free(work); |
| 3936 | if (started) |
| 3937 | radio_work_check_next(wpa_s); |
| 3938 | } |
| 3939 | |
| 3940 | |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 3941 | struct wpa_radio_work * |
| 3942 | radio_work_pending(struct wpa_supplicant *wpa_s, const char *type) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3943 | { |
| 3944 | struct wpa_radio_work *work; |
| 3945 | struct wpa_radio *radio = wpa_s->radio; |
| 3946 | |
| 3947 | dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) { |
| 3948 | if (work->wpa_s == wpa_s && os_strcmp(work->type, type) == 0) |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 3949 | return work; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3950 | } |
| 3951 | |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 3952 | return NULL; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3953 | } |
| 3954 | |
| 3955 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3956 | static int wpas_init_driver(struct wpa_supplicant *wpa_s, |
| 3957 | struct wpa_interface *iface) |
| 3958 | { |
| 3959 | const char *ifname, *driver, *rn; |
| 3960 | |
| 3961 | driver = iface->driver; |
| 3962 | next_driver: |
| 3963 | if (wpa_supplicant_set_driver(wpa_s, driver) < 0) |
| 3964 | return -1; |
| 3965 | |
| 3966 | wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname); |
| 3967 | if (wpa_s->drv_priv == NULL) { |
| 3968 | const char *pos; |
| 3969 | pos = driver ? os_strchr(driver, ',') : NULL; |
| 3970 | if (pos) { |
| 3971 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to initialize " |
| 3972 | "driver interface - try next driver wrapper"); |
| 3973 | driver = pos + 1; |
| 3974 | goto next_driver; |
| 3975 | } |
| 3976 | wpa_msg(wpa_s, MSG_ERROR, "Failed to initialize driver " |
| 3977 | "interface"); |
| 3978 | return -1; |
| 3979 | } |
| 3980 | if (wpa_drv_set_param(wpa_s, wpa_s->conf->driver_param) < 0) { |
| 3981 | wpa_msg(wpa_s, MSG_ERROR, "Driver interface rejected " |
| 3982 | "driver_param '%s'", wpa_s->conf->driver_param); |
| 3983 | return -1; |
| 3984 | } |
| 3985 | |
| 3986 | ifname = wpa_drv_get_ifname(wpa_s); |
| 3987 | if (ifname && os_strcmp(ifname, wpa_s->ifname) != 0) { |
| 3988 | wpa_dbg(wpa_s, MSG_DEBUG, "Driver interface replaced " |
| 3989 | "interface name with '%s'", ifname); |
| 3990 | os_strlcpy(wpa_s->ifname, ifname, sizeof(wpa_s->ifname)); |
| 3991 | } |
| 3992 | |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 3993 | rn = wpa_driver_get_radio_name(wpa_s); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3994 | if (rn && rn[0] == '\0') |
| 3995 | rn = NULL; |
| 3996 | |
| 3997 | wpa_s->radio = radio_add_interface(wpa_s, rn); |
| 3998 | if (wpa_s->radio == NULL) |
| 3999 | return -1; |
| 4000 | |
| 4001 | return 0; |
| 4002 | } |
| 4003 | |
| 4004 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4005 | static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s, |
| 4006 | struct wpa_interface *iface) |
| 4007 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4008 | struct wpa_driver_capa capa; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4009 | int capa_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4010 | |
| 4011 | wpa_printf(MSG_DEBUG, "Initializing interface '%s' conf '%s' driver " |
| 4012 | "'%s' ctrl_interface '%s' bridge '%s'", iface->ifname, |
| 4013 | iface->confname ? iface->confname : "N/A", |
| 4014 | iface->driver ? iface->driver : "default", |
| 4015 | iface->ctrl_interface ? iface->ctrl_interface : "N/A", |
| 4016 | iface->bridge_ifname ? iface->bridge_ifname : "N/A"); |
| 4017 | |
| 4018 | if (iface->confname) { |
| 4019 | #ifdef CONFIG_BACKEND_FILE |
| 4020 | wpa_s->confname = os_rel2abs_path(iface->confname); |
| 4021 | if (wpa_s->confname == NULL) { |
| 4022 | wpa_printf(MSG_ERROR, "Failed to get absolute path " |
| 4023 | "for configuration file '%s'.", |
| 4024 | iface->confname); |
| 4025 | return -1; |
| 4026 | } |
| 4027 | wpa_printf(MSG_DEBUG, "Configuration file '%s' -> '%s'", |
| 4028 | iface->confname, wpa_s->confname); |
| 4029 | #else /* CONFIG_BACKEND_FILE */ |
| 4030 | wpa_s->confname = os_strdup(iface->confname); |
| 4031 | #endif /* CONFIG_BACKEND_FILE */ |
Dmitry Shmidt | 64f47c5 | 2013-04-16 10:41:54 -0700 | [diff] [blame] | 4032 | wpa_s->conf = wpa_config_read(wpa_s->confname, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4033 | if (wpa_s->conf == NULL) { |
| 4034 | wpa_printf(MSG_ERROR, "Failed to read or parse " |
| 4035 | "configuration '%s'.", wpa_s->confname); |
| 4036 | return -1; |
| 4037 | } |
Dmitry Shmidt | 64f47c5 | 2013-04-16 10:41:54 -0700 | [diff] [blame] | 4038 | wpa_s->confanother = os_rel2abs_path(iface->confanother); |
| 4039 | wpa_config_read(wpa_s->confanother, wpa_s->conf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4040 | |
| 4041 | /* |
| 4042 | * Override ctrl_interface and driver_param if set on command |
| 4043 | * line. |
| 4044 | */ |
| 4045 | if (iface->ctrl_interface) { |
| 4046 | os_free(wpa_s->conf->ctrl_interface); |
| 4047 | wpa_s->conf->ctrl_interface = |
| 4048 | os_strdup(iface->ctrl_interface); |
| 4049 | } |
| 4050 | |
| 4051 | if (iface->driver_param) { |
| 4052 | os_free(wpa_s->conf->driver_param); |
| 4053 | wpa_s->conf->driver_param = |
| 4054 | os_strdup(iface->driver_param); |
| 4055 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4056 | |
| 4057 | if (iface->p2p_mgmt && !iface->ctrl_interface) { |
| 4058 | os_free(wpa_s->conf->ctrl_interface); |
| 4059 | wpa_s->conf->ctrl_interface = NULL; |
| 4060 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4061 | } else |
| 4062 | wpa_s->conf = wpa_config_alloc_empty(iface->ctrl_interface, |
| 4063 | iface->driver_param); |
| 4064 | |
| 4065 | if (wpa_s->conf == NULL) { |
| 4066 | wpa_printf(MSG_ERROR, "\nNo configuration found."); |
| 4067 | return -1; |
| 4068 | } |
| 4069 | |
| 4070 | if (iface->ifname == NULL) { |
| 4071 | wpa_printf(MSG_ERROR, "\nInterface name is required."); |
| 4072 | return -1; |
| 4073 | } |
| 4074 | if (os_strlen(iface->ifname) >= sizeof(wpa_s->ifname)) { |
| 4075 | wpa_printf(MSG_ERROR, "\nToo long interface name '%s'.", |
| 4076 | iface->ifname); |
| 4077 | return -1; |
| 4078 | } |
| 4079 | os_strlcpy(wpa_s->ifname, iface->ifname, sizeof(wpa_s->ifname)); |
| 4080 | |
| 4081 | if (iface->bridge_ifname) { |
| 4082 | if (os_strlen(iface->bridge_ifname) >= |
| 4083 | sizeof(wpa_s->bridge_ifname)) { |
| 4084 | wpa_printf(MSG_ERROR, "\nToo long bridge interface " |
| 4085 | "name '%s'.", iface->bridge_ifname); |
| 4086 | return -1; |
| 4087 | } |
| 4088 | os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname, |
| 4089 | sizeof(wpa_s->bridge_ifname)); |
| 4090 | } |
| 4091 | |
| 4092 | /* RSNA Supplicant Key Management - INITIALIZE */ |
| 4093 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
| 4094 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); |
| 4095 | |
| 4096 | /* Initialize driver interface and register driver event handler before |
| 4097 | * L2 receive handler so that association events are processed before |
| 4098 | * EAPOL-Key packets if both become available for the same select() |
| 4099 | * call. */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 4100 | if (wpas_init_driver(wpa_s, iface) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4101 | return -1; |
| 4102 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4103 | if (wpa_supplicant_init_wpa(wpa_s) < 0) |
| 4104 | return -1; |
| 4105 | |
| 4106 | wpa_sm_set_ifname(wpa_s->wpa, wpa_s->ifname, |
| 4107 | wpa_s->bridge_ifname[0] ? wpa_s->bridge_ifname : |
| 4108 | NULL); |
| 4109 | wpa_sm_set_fast_reauth(wpa_s->wpa, wpa_s->conf->fast_reauth); |
| 4110 | |
| 4111 | if (wpa_s->conf->dot11RSNAConfigPMKLifetime && |
| 4112 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, |
| 4113 | wpa_s->conf->dot11RSNAConfigPMKLifetime)) { |
| 4114 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
| 4115 | "dot11RSNAConfigPMKLifetime"); |
| 4116 | return -1; |
| 4117 | } |
| 4118 | |
| 4119 | if (wpa_s->conf->dot11RSNAConfigPMKReauthThreshold && |
| 4120 | wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, |
| 4121 | wpa_s->conf->dot11RSNAConfigPMKReauthThreshold)) { |
| 4122 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
| 4123 | "dot11RSNAConfigPMKReauthThreshold"); |
| 4124 | return -1; |
| 4125 | } |
| 4126 | |
| 4127 | if (wpa_s->conf->dot11RSNAConfigSATimeout && |
| 4128 | wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, |
| 4129 | wpa_s->conf->dot11RSNAConfigSATimeout)) { |
| 4130 | wpa_msg(wpa_s, MSG_ERROR, "Invalid WPA parameter value for " |
| 4131 | "dot11RSNAConfigSATimeout"); |
| 4132 | return -1; |
| 4133 | } |
| 4134 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4135 | wpa_s->hw.modes = wpa_drv_get_hw_feature_data(wpa_s, |
| 4136 | &wpa_s->hw.num_modes, |
| 4137 | &wpa_s->hw.flags); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4138 | if (wpa_s->hw.modes) { |
| 4139 | u16 i; |
| 4140 | |
| 4141 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 4142 | if (wpa_s->hw.modes[i].vht_capab) { |
| 4143 | wpa_s->hw_capab = CAPAB_VHT; |
| 4144 | break; |
| 4145 | } |
| 4146 | |
| 4147 | if (wpa_s->hw.modes[i].ht_capab & |
| 4148 | HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) |
| 4149 | wpa_s->hw_capab = CAPAB_HT40; |
| 4150 | else if (wpa_s->hw.modes[i].ht_capab && |
| 4151 | wpa_s->hw_capab == CAPAB_NO_HT_VHT) |
| 4152 | wpa_s->hw_capab = CAPAB_HT; |
| 4153 | } |
| 4154 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4155 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4156 | capa_res = wpa_drv_get_capa(wpa_s, &capa); |
| 4157 | if (capa_res == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4158 | wpa_s->drv_capa_known = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4159 | wpa_s->drv_flags = capa.flags; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4160 | wpa_s->drv_enc = capa.enc; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4161 | wpa_s->drv_smps_modes = capa.smps_modes; |
| 4162 | wpa_s->drv_rrm_flags = capa.rrm_flags; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4163 | wpa_s->probe_resp_offloads = capa.probe_resp_offloads; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4164 | wpa_s->max_scan_ssids = capa.max_scan_ssids; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4165 | wpa_s->max_sched_scan_ssids = capa.max_sched_scan_ssids; |
| 4166 | wpa_s->sched_scan_supported = capa.sched_scan_supported; |
| 4167 | wpa_s->max_match_sets = capa.max_match_sets; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4168 | wpa_s->max_remain_on_chan = capa.max_remain_on_chan; |
| 4169 | wpa_s->max_stations = capa.max_stations; |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 4170 | wpa_s->extended_capa = capa.extended_capa; |
| 4171 | wpa_s->extended_capa_mask = capa.extended_capa_mask; |
| 4172 | wpa_s->extended_capa_len = capa.extended_capa_len; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4173 | wpa_s->num_multichan_concurrent = |
| 4174 | capa.num_multichan_concurrent; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4175 | wpa_s->wmm_ac_supported = capa.wmm_ac_supported; |
| 4176 | |
| 4177 | if (capa.mac_addr_rand_scan_supported) |
| 4178 | wpa_s->mac_addr_rand_supported |= MAC_ADDR_RAND_SCAN; |
| 4179 | if (wpa_s->sched_scan_supported && |
| 4180 | capa.mac_addr_rand_sched_scan_supported) |
| 4181 | wpa_s->mac_addr_rand_supported |= |
| 4182 | (MAC_ADDR_RAND_SCHED_SCAN | MAC_ADDR_RAND_PNO); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4183 | } |
| 4184 | if (wpa_s->max_remain_on_chan == 0) |
| 4185 | wpa_s->max_remain_on_chan = 1000; |
| 4186 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4187 | /* |
| 4188 | * Only take p2p_mgmt parameters when P2P Device is supported. |
| 4189 | * Doing it here as it determines whether l2_packet_init() will be done |
| 4190 | * during wpa_supplicant_driver_init(). |
| 4191 | */ |
| 4192 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) |
| 4193 | wpa_s->p2p_mgmt = iface->p2p_mgmt; |
| 4194 | else |
| 4195 | iface->p2p_mgmt = 1; |
| 4196 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4197 | if (wpa_s->num_multichan_concurrent == 0) |
| 4198 | wpa_s->num_multichan_concurrent = 1; |
| 4199 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4200 | if (wpa_supplicant_driver_init(wpa_s) < 0) |
| 4201 | return -1; |
| 4202 | |
| 4203 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4204 | if ((!iface->p2p_mgmt || |
| 4205 | !(wpa_s->drv_flags & |
| 4206 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) && |
| 4207 | wpa_tdls_init(wpa_s->wpa)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4208 | return -1; |
| 4209 | #endif /* CONFIG_TDLS */ |
| 4210 | |
| 4211 | if (wpa_s->conf->country[0] && wpa_s->conf->country[1] && |
| 4212 | wpa_drv_set_country(wpa_s, wpa_s->conf->country)) { |
| 4213 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to set country"); |
| 4214 | return -1; |
| 4215 | } |
| 4216 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4217 | if (wpas_wps_init(wpa_s)) |
| 4218 | return -1; |
| 4219 | |
| 4220 | if (wpa_supplicant_init_eapol(wpa_s) < 0) |
| 4221 | return -1; |
| 4222 | wpa_sm_set_eapol(wpa_s->wpa, wpa_s->eapol); |
| 4223 | |
| 4224 | wpa_s->ctrl_iface = wpa_supplicant_ctrl_iface_init(wpa_s); |
| 4225 | if (wpa_s->ctrl_iface == NULL) { |
| 4226 | wpa_printf(MSG_ERROR, |
| 4227 | "Failed to initialize control interface '%s'.\n" |
| 4228 | "You may have another wpa_supplicant process " |
| 4229 | "already running or the file was\n" |
| 4230 | "left by an unclean termination of wpa_supplicant " |
| 4231 | "in which case you will need\n" |
| 4232 | "to manually remove this file before starting " |
| 4233 | "wpa_supplicant again.\n", |
| 4234 | wpa_s->conf->ctrl_interface); |
| 4235 | return -1; |
| 4236 | } |
| 4237 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4238 | wpa_s->gas = gas_query_init(wpa_s); |
| 4239 | if (wpa_s->gas == NULL) { |
| 4240 | wpa_printf(MSG_ERROR, "Failed to initialize GAS query"); |
| 4241 | return -1; |
| 4242 | } |
| 4243 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4244 | if (iface->p2p_mgmt && wpas_p2p_init(wpa_s->global, wpa_s) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4245 | wpa_msg(wpa_s, MSG_ERROR, "Failed to init P2P"); |
| 4246 | return -1; |
| 4247 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4248 | |
| 4249 | if (wpa_bss_init(wpa_s) < 0) |
| 4250 | return -1; |
| 4251 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4252 | /* |
| 4253 | * Set Wake-on-WLAN triggers, if configured. |
| 4254 | * Note: We don't restore/remove the triggers on shutdown (it doesn't |
| 4255 | * have effect anyway when the interface is down). |
| 4256 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4257 | if (capa_res == 0 && wpas_set_wowlan_triggers(wpa_s, &capa) < 0) |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4258 | return -1; |
| 4259 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4260 | #ifdef CONFIG_EAP_PROXY |
| 4261 | { |
| 4262 | size_t len; |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 4263 | wpa_s->mnc_len = eapol_sm_get_eap_proxy_imsi(wpa_s->eapol, wpa_s->imsi, |
| 4264 | &len); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4265 | if (wpa_s->mnc_len > 0) { |
| 4266 | wpa_s->imsi[len] = '\0'; |
| 4267 | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI %s (MNC length %d)", |
| 4268 | wpa_s->imsi, wpa_s->mnc_len); |
| 4269 | } else { |
| 4270 | wpa_printf(MSG_DEBUG, "eap_proxy: IMSI not available"); |
| 4271 | } |
| 4272 | } |
| 4273 | #endif /* CONFIG_EAP_PROXY */ |
| 4274 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4275 | if (pcsc_reader_init(wpa_s) < 0) |
| 4276 | return -1; |
| 4277 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4278 | if (wpas_init_ext_pw(wpa_s) < 0) |
| 4279 | return -1; |
| 4280 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4281 | wpas_rrm_reset(wpa_s); |
| 4282 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4283 | return 0; |
| 4284 | } |
| 4285 | |
| 4286 | |
| 4287 | static void wpa_supplicant_deinit_iface(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4288 | int notify, int terminate) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4289 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4290 | struct wpa_global *global = wpa_s->global; |
| 4291 | struct wpa_supplicant *iface, *prev; |
| 4292 | |
| 4293 | if (wpa_s == wpa_s->parent) |
| 4294 | wpas_p2p_group_remove(wpa_s, "*"); |
| 4295 | |
| 4296 | iface = global->ifaces; |
| 4297 | while (iface) { |
| 4298 | if (iface == wpa_s || iface->parent != wpa_s) { |
| 4299 | iface = iface->next; |
| 4300 | continue; |
| 4301 | } |
| 4302 | wpa_printf(MSG_DEBUG, |
| 4303 | "Remove remaining child interface %s from parent %s", |
| 4304 | iface->ifname, wpa_s->ifname); |
| 4305 | prev = iface; |
| 4306 | iface = iface->next; |
| 4307 | wpa_supplicant_remove_iface(global, prev, terminate); |
| 4308 | } |
| 4309 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 4310 | wpa_s->disconnected = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4311 | if (wpa_s->drv_priv) { |
| 4312 | wpa_supplicant_deauthenticate(wpa_s, |
| 4313 | WLAN_REASON_DEAUTH_LEAVING); |
| 4314 | |
| 4315 | wpa_drv_set_countermeasures(wpa_s, 0); |
| 4316 | wpa_clear_keys(wpa_s, NULL); |
| 4317 | } |
| 4318 | |
| 4319 | wpa_supplicant_cleanup(wpa_s); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 4320 | wpas_p2p_deinit_iface(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4321 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4322 | wpas_ctrl_radio_work_flush(wpa_s); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 4323 | radio_remove_interface(wpa_s); |
| 4324 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4325 | if (wpa_s->drv_priv) |
| 4326 | wpa_drv_deinit(wpa_s); |
Irfan Sheriff | 622b66d | 2011-08-03 09:11:49 -0700 | [diff] [blame] | 4327 | |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4328 | if (notify) |
| 4329 | wpas_notify_iface_removed(wpa_s); |
| 4330 | |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4331 | if (terminate) |
| 4332 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING); |
Irfan Sheriff | 622b66d | 2011-08-03 09:11:49 -0700 | [diff] [blame] | 4333 | |
| 4334 | if (wpa_s->ctrl_iface) { |
| 4335 | wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface); |
| 4336 | wpa_s->ctrl_iface = NULL; |
| 4337 | } |
| 4338 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4339 | #ifdef CONFIG_MESH |
| 4340 | if (wpa_s->ifmsh) { |
| 4341 | wpa_supplicant_mesh_iface_deinit(wpa_s, wpa_s->ifmsh); |
| 4342 | wpa_s->ifmsh = NULL; |
| 4343 | } |
| 4344 | #endif /* CONFIG_MESH */ |
| 4345 | |
Irfan Sheriff | 622b66d | 2011-08-03 09:11:49 -0700 | [diff] [blame] | 4346 | if (wpa_s->conf != NULL) { |
Irfan Sheriff | 622b66d | 2011-08-03 09:11:49 -0700 | [diff] [blame] | 4347 | wpa_config_free(wpa_s->conf); |
| 4348 | wpa_s->conf = NULL; |
| 4349 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4350 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame^] | 4351 | os_free(wpa_s->ssids_from_scan_req); |
| 4352 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4353 | os_free(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4354 | } |
| 4355 | |
| 4356 | |
| 4357 | /** |
| 4358 | * wpa_supplicant_add_iface - Add a new network interface |
| 4359 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4360 | * @iface: Interface configuration options |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4361 | * @parent: Parent interface or %NULL to assign new interface as parent |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4362 | * Returns: Pointer to the created interface or %NULL on failure |
| 4363 | * |
| 4364 | * This function is used to add new network interfaces for %wpa_supplicant. |
| 4365 | * This can be called before wpa_supplicant_run() to add interfaces before the |
| 4366 | * main event loop has been started. In addition, new interfaces can be added |
| 4367 | * dynamically while %wpa_supplicant is already running. This could happen, |
| 4368 | * e.g., when a hotplug network adapter is inserted. |
| 4369 | */ |
| 4370 | struct wpa_supplicant * wpa_supplicant_add_iface(struct wpa_global *global, |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4371 | struct wpa_interface *iface, |
| 4372 | struct wpa_supplicant *parent) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4373 | { |
| 4374 | struct wpa_supplicant *wpa_s; |
| 4375 | struct wpa_interface t_iface; |
| 4376 | struct wpa_ssid *ssid; |
| 4377 | |
| 4378 | if (global == NULL || iface == NULL) |
| 4379 | return NULL; |
| 4380 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4381 | wpa_s = wpa_supplicant_alloc(parent); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4382 | if (wpa_s == NULL) |
| 4383 | return NULL; |
| 4384 | |
| 4385 | wpa_s->global = global; |
| 4386 | |
| 4387 | t_iface = *iface; |
| 4388 | if (global->params.override_driver) { |
| 4389 | wpa_printf(MSG_DEBUG, "Override interface parameter: driver " |
| 4390 | "('%s' -> '%s')", |
| 4391 | iface->driver, global->params.override_driver); |
| 4392 | t_iface.driver = global->params.override_driver; |
| 4393 | } |
| 4394 | if (global->params.override_ctrl_interface) { |
| 4395 | wpa_printf(MSG_DEBUG, "Override interface parameter: " |
| 4396 | "ctrl_interface ('%s' -> '%s')", |
| 4397 | iface->ctrl_interface, |
| 4398 | global->params.override_ctrl_interface); |
| 4399 | t_iface.ctrl_interface = |
| 4400 | global->params.override_ctrl_interface; |
| 4401 | } |
| 4402 | if (wpa_supplicant_init_iface(wpa_s, &t_iface)) { |
| 4403 | wpa_printf(MSG_DEBUG, "Failed to add interface %s", |
| 4404 | iface->ifname); |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4405 | wpa_supplicant_deinit_iface(wpa_s, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4406 | return NULL; |
| 4407 | } |
| 4408 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4409 | if (iface->p2p_mgmt == 0) { |
| 4410 | /* Notify the control interfaces about new iface */ |
| 4411 | if (wpas_notify_iface_added(wpa_s)) { |
| 4412 | wpa_supplicant_deinit_iface(wpa_s, 1, 0); |
| 4413 | return NULL; |
| 4414 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4415 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4416 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) |
| 4417 | wpas_notify_network_added(wpa_s, ssid); |
| 4418 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4419 | |
| 4420 | wpa_s->next = global->ifaces; |
| 4421 | global->ifaces = wpa_s; |
| 4422 | |
| 4423 | wpa_dbg(wpa_s, MSG_DEBUG, "Added interface %s", wpa_s->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4424 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4425 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4426 | #ifdef CONFIG_P2P |
| 4427 | if (wpa_s->global->p2p == NULL && |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 4428 | !wpa_s->global->p2p_disabled && !wpa_s->conf->p2p_disabled && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4429 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && |
| 4430 | wpas_p2p_add_p2pdev_interface(wpa_s, iface->conf_p2p_dev) < 0) { |
| 4431 | wpa_printf(MSG_INFO, |
| 4432 | "P2P: Failed to enable P2P Device interface"); |
| 4433 | /* Try to continue without. P2P will be disabled. */ |
| 4434 | } |
| 4435 | #endif /* CONFIG_P2P */ |
| 4436 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4437 | return wpa_s; |
| 4438 | } |
| 4439 | |
| 4440 | |
| 4441 | /** |
| 4442 | * wpa_supplicant_remove_iface - Remove a network interface |
| 4443 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4444 | * @wpa_s: Pointer to the network interface to be removed |
| 4445 | * Returns: 0 if interface was removed, -1 if interface was not found |
| 4446 | * |
| 4447 | * This function can be used to dynamically remove network interfaces from |
| 4448 | * %wpa_supplicant, e.g., when a hotplug network adapter is ejected. In |
| 4449 | * addition, this function is used to remove all remaining interfaces when |
| 4450 | * %wpa_supplicant is terminated. |
| 4451 | */ |
| 4452 | int wpa_supplicant_remove_iface(struct wpa_global *global, |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4453 | struct wpa_supplicant *wpa_s, |
| 4454 | int terminate) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4455 | { |
| 4456 | struct wpa_supplicant *prev; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4457 | #ifdef CONFIG_MESH |
| 4458 | unsigned int mesh_if_created = wpa_s->mesh_if_created; |
| 4459 | char *ifname = NULL; |
| 4460 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4461 | |
| 4462 | /* Remove interface from the global list of interfaces */ |
| 4463 | prev = global->ifaces; |
| 4464 | if (prev == wpa_s) { |
| 4465 | global->ifaces = wpa_s->next; |
| 4466 | } else { |
| 4467 | while (prev && prev->next != wpa_s) |
| 4468 | prev = prev->next; |
| 4469 | if (prev == NULL) |
| 4470 | return -1; |
| 4471 | prev->next = wpa_s->next; |
| 4472 | } |
| 4473 | |
| 4474 | wpa_dbg(wpa_s, MSG_DEBUG, "Removing interface %s", wpa_s->ifname); |
| 4475 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4476 | #ifdef CONFIG_MESH |
| 4477 | if (mesh_if_created) { |
| 4478 | ifname = os_strdup(wpa_s->ifname); |
| 4479 | if (ifname == NULL) { |
| 4480 | wpa_dbg(wpa_s, MSG_ERROR, |
| 4481 | "mesh: Failed to malloc ifname"); |
| 4482 | return -1; |
| 4483 | } |
| 4484 | } |
| 4485 | #endif /* CONFIG_MESH */ |
| 4486 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4487 | if (global->p2p_group_formation == wpa_s) |
| 4488 | global->p2p_group_formation = NULL; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 4489 | if (global->p2p_invite_group == wpa_s) |
| 4490 | global->p2p_invite_group = NULL; |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4491 | wpa_supplicant_deinit_iface(wpa_s, 1, terminate); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4492 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4493 | #ifdef CONFIG_MESH |
| 4494 | if (mesh_if_created) { |
| 4495 | wpa_drv_if_remove(global->ifaces, WPA_IF_MESH, ifname); |
| 4496 | os_free(ifname); |
| 4497 | } |
| 4498 | #endif /* CONFIG_MESH */ |
| 4499 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4500 | return 0; |
| 4501 | } |
| 4502 | |
| 4503 | |
| 4504 | /** |
| 4505 | * wpa_supplicant_get_eap_mode - Get the current EAP mode |
| 4506 | * @wpa_s: Pointer to the network interface |
| 4507 | * Returns: Pointer to the eap mode or the string "UNKNOWN" if not found |
| 4508 | */ |
| 4509 | const char * wpa_supplicant_get_eap_mode(struct wpa_supplicant *wpa_s) |
| 4510 | { |
| 4511 | const char *eapol_method; |
| 4512 | |
| 4513 | if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) == 0 && |
| 4514 | wpa_s->key_mgmt != WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 4515 | return "NO-EAP"; |
| 4516 | } |
| 4517 | |
| 4518 | eapol_method = eapol_sm_get_method_name(wpa_s->eapol); |
| 4519 | if (eapol_method == NULL) |
| 4520 | return "UNKNOWN-EAP"; |
| 4521 | |
| 4522 | return eapol_method; |
| 4523 | } |
| 4524 | |
| 4525 | |
| 4526 | /** |
| 4527 | * wpa_supplicant_get_iface - Get a new network interface |
| 4528 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4529 | * @ifname: Interface name |
| 4530 | * Returns: Pointer to the interface or %NULL if not found |
| 4531 | */ |
| 4532 | struct wpa_supplicant * wpa_supplicant_get_iface(struct wpa_global *global, |
| 4533 | const char *ifname) |
| 4534 | { |
| 4535 | struct wpa_supplicant *wpa_s; |
| 4536 | |
| 4537 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) { |
| 4538 | if (os_strcmp(wpa_s->ifname, ifname) == 0) |
| 4539 | return wpa_s; |
| 4540 | } |
| 4541 | return NULL; |
| 4542 | } |
| 4543 | |
| 4544 | |
| 4545 | #ifndef CONFIG_NO_WPA_MSG |
| 4546 | static const char * wpa_supplicant_msg_ifname_cb(void *ctx) |
| 4547 | { |
| 4548 | struct wpa_supplicant *wpa_s = ctx; |
| 4549 | if (wpa_s == NULL) |
| 4550 | return NULL; |
| 4551 | return wpa_s->ifname; |
| 4552 | } |
| 4553 | #endif /* CONFIG_NO_WPA_MSG */ |
| 4554 | |
| 4555 | |
| 4556 | /** |
| 4557 | * wpa_supplicant_init - Initialize %wpa_supplicant |
| 4558 | * @params: Parameters for %wpa_supplicant |
| 4559 | * Returns: Pointer to global %wpa_supplicant data, or %NULL on failure |
| 4560 | * |
| 4561 | * This function is used to initialize %wpa_supplicant. After successful |
| 4562 | * initialization, the returned data pointer can be used to add and remove |
| 4563 | * network interfaces, and eventually, to deinitialize %wpa_supplicant. |
| 4564 | */ |
| 4565 | struct wpa_global * wpa_supplicant_init(struct wpa_params *params) |
| 4566 | { |
| 4567 | struct wpa_global *global; |
| 4568 | int ret, i; |
| 4569 | |
| 4570 | if (params == NULL) |
| 4571 | return NULL; |
| 4572 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4573 | #ifdef CONFIG_DRIVER_NDIS |
| 4574 | { |
| 4575 | void driver_ndis_init_ops(void); |
| 4576 | driver_ndis_init_ops(); |
| 4577 | } |
| 4578 | #endif /* CONFIG_DRIVER_NDIS */ |
| 4579 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4580 | #ifndef CONFIG_NO_WPA_MSG |
| 4581 | wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb); |
| 4582 | #endif /* CONFIG_NO_WPA_MSG */ |
| 4583 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4584 | if (params->wpa_debug_file_path) |
| 4585 | wpa_debug_open_file(params->wpa_debug_file_path); |
| 4586 | else |
| 4587 | wpa_debug_setup_stdout(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4588 | if (params->wpa_debug_syslog) |
| 4589 | wpa_debug_open_syslog(); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4590 | if (params->wpa_debug_tracing) { |
| 4591 | ret = wpa_debug_open_linux_tracing(); |
| 4592 | if (ret) { |
| 4593 | wpa_printf(MSG_ERROR, |
| 4594 | "Failed to enable trace logging"); |
| 4595 | return NULL; |
| 4596 | } |
| 4597 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4598 | |
| 4599 | ret = eap_register_methods(); |
| 4600 | if (ret) { |
| 4601 | wpa_printf(MSG_ERROR, "Failed to register EAP methods"); |
| 4602 | if (ret == -2) |
| 4603 | wpa_printf(MSG_ERROR, "Two or more EAP methods used " |
| 4604 | "the same EAP type."); |
| 4605 | return NULL; |
| 4606 | } |
| 4607 | |
| 4608 | global = os_zalloc(sizeof(*global)); |
| 4609 | if (global == NULL) |
| 4610 | return NULL; |
| 4611 | dl_list_init(&global->p2p_srv_bonjour); |
| 4612 | dl_list_init(&global->p2p_srv_upnp); |
| 4613 | global->params.daemonize = params->daemonize; |
| 4614 | global->params.wait_for_monitor = params->wait_for_monitor; |
| 4615 | global->params.dbus_ctrl_interface = params->dbus_ctrl_interface; |
| 4616 | if (params->pid_file) |
| 4617 | global->params.pid_file = os_strdup(params->pid_file); |
| 4618 | if (params->ctrl_interface) |
| 4619 | global->params.ctrl_interface = |
| 4620 | os_strdup(params->ctrl_interface); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4621 | if (params->ctrl_interface_group) |
| 4622 | global->params.ctrl_interface_group = |
| 4623 | os_strdup(params->ctrl_interface_group); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4624 | if (params->override_driver) |
| 4625 | global->params.override_driver = |
| 4626 | os_strdup(params->override_driver); |
| 4627 | if (params->override_ctrl_interface) |
| 4628 | global->params.override_ctrl_interface = |
| 4629 | os_strdup(params->override_ctrl_interface); |
| 4630 | wpa_debug_level = global->params.wpa_debug_level = |
| 4631 | params->wpa_debug_level; |
| 4632 | wpa_debug_show_keys = global->params.wpa_debug_show_keys = |
| 4633 | params->wpa_debug_show_keys; |
| 4634 | wpa_debug_timestamp = global->params.wpa_debug_timestamp = |
| 4635 | params->wpa_debug_timestamp; |
| 4636 | |
| 4637 | wpa_printf(MSG_DEBUG, "wpa_supplicant v" VERSION_STR); |
| 4638 | |
| 4639 | if (eloop_init()) { |
| 4640 | wpa_printf(MSG_ERROR, "Failed to initialize event loop"); |
| 4641 | wpa_supplicant_deinit(global); |
| 4642 | return NULL; |
| 4643 | } |
| 4644 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 4645 | random_init(params->entropy_file); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4646 | |
| 4647 | global->ctrl_iface = wpa_supplicant_global_ctrl_iface_init(global); |
| 4648 | if (global->ctrl_iface == NULL) { |
| 4649 | wpa_supplicant_deinit(global); |
| 4650 | return NULL; |
| 4651 | } |
| 4652 | |
| 4653 | if (wpas_notify_supplicant_initialized(global)) { |
| 4654 | wpa_supplicant_deinit(global); |
| 4655 | return NULL; |
| 4656 | } |
| 4657 | |
| 4658 | for (i = 0; wpa_drivers[i]; i++) |
| 4659 | global->drv_count++; |
| 4660 | if (global->drv_count == 0) { |
| 4661 | wpa_printf(MSG_ERROR, "No drivers enabled"); |
| 4662 | wpa_supplicant_deinit(global); |
| 4663 | return NULL; |
| 4664 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4665 | global->drv_priv = os_calloc(global->drv_count, sizeof(void *)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4666 | if (global->drv_priv == NULL) { |
| 4667 | wpa_supplicant_deinit(global); |
| 4668 | return NULL; |
| 4669 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4670 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4671 | #ifdef CONFIG_WIFI_DISPLAY |
| 4672 | if (wifi_display_init(global) < 0) { |
| 4673 | wpa_printf(MSG_ERROR, "Failed to initialize Wi-Fi Display"); |
| 4674 | wpa_supplicant_deinit(global); |
| 4675 | return NULL; |
| 4676 | } |
| 4677 | #endif /* CONFIG_WIFI_DISPLAY */ |
| 4678 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4679 | return global; |
| 4680 | } |
| 4681 | |
| 4682 | |
| 4683 | /** |
| 4684 | * wpa_supplicant_run - Run the %wpa_supplicant main event loop |
| 4685 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4686 | * Returns: 0 after successful event loop run, -1 on failure |
| 4687 | * |
| 4688 | * This function starts the main event loop and continues running as long as |
| 4689 | * there are any remaining events. In most cases, this function is running as |
| 4690 | * long as the %wpa_supplicant process in still in use. |
| 4691 | */ |
| 4692 | int wpa_supplicant_run(struct wpa_global *global) |
| 4693 | { |
| 4694 | struct wpa_supplicant *wpa_s; |
| 4695 | |
| 4696 | if (global->params.daemonize && |
| 4697 | wpa_supplicant_daemon(global->params.pid_file)) |
| 4698 | return -1; |
| 4699 | |
| 4700 | if (global->params.wait_for_monitor) { |
| 4701 | for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) |
| 4702 | if (wpa_s->ctrl_iface) |
| 4703 | wpa_supplicant_ctrl_iface_wait( |
| 4704 | wpa_s->ctrl_iface); |
| 4705 | } |
| 4706 | |
| 4707 | eloop_register_signal_terminate(wpa_supplicant_terminate, global); |
| 4708 | eloop_register_signal_reconfig(wpa_supplicant_reconfig, global); |
| 4709 | |
| 4710 | eloop_run(); |
| 4711 | |
| 4712 | return 0; |
| 4713 | } |
| 4714 | |
| 4715 | |
| 4716 | /** |
| 4717 | * wpa_supplicant_deinit - Deinitialize %wpa_supplicant |
| 4718 | * @global: Pointer to global data from wpa_supplicant_init() |
| 4719 | * |
| 4720 | * This function is called to deinitialize %wpa_supplicant and to free all |
| 4721 | * allocated resources. Remaining network interfaces will also be removed. |
| 4722 | */ |
| 4723 | void wpa_supplicant_deinit(struct wpa_global *global) |
| 4724 | { |
| 4725 | int i; |
| 4726 | |
| 4727 | if (global == NULL) |
| 4728 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4729 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4730 | #ifdef CONFIG_WIFI_DISPLAY |
| 4731 | wifi_display_deinit(global); |
| 4732 | #endif /* CONFIG_WIFI_DISPLAY */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4733 | |
| 4734 | while (global->ifaces) |
Dmitry Shmidt | e15c7b5 | 2011-08-03 15:04:35 -0700 | [diff] [blame] | 4735 | wpa_supplicant_remove_iface(global, global->ifaces, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4736 | |
| 4737 | if (global->ctrl_iface) |
| 4738 | wpa_supplicant_global_ctrl_iface_deinit(global->ctrl_iface); |
| 4739 | |
| 4740 | wpas_notify_supplicant_deinitialized(global); |
| 4741 | |
| 4742 | eap_peer_unregister_methods(); |
| 4743 | #ifdef CONFIG_AP |
| 4744 | eap_server_unregister_methods(); |
| 4745 | #endif /* CONFIG_AP */ |
| 4746 | |
| 4747 | for (i = 0; wpa_drivers[i] && global->drv_priv; i++) { |
| 4748 | if (!global->drv_priv[i]) |
| 4749 | continue; |
| 4750 | wpa_drivers[i]->global_deinit(global->drv_priv[i]); |
| 4751 | } |
| 4752 | os_free(global->drv_priv); |
| 4753 | |
| 4754 | random_deinit(); |
| 4755 | |
| 4756 | eloop_destroy(); |
| 4757 | |
| 4758 | if (global->params.pid_file) { |
| 4759 | os_daemonize_terminate(global->params.pid_file); |
| 4760 | os_free(global->params.pid_file); |
| 4761 | } |
| 4762 | os_free(global->params.ctrl_interface); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 4763 | os_free(global->params.ctrl_interface_group); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4764 | os_free(global->params.override_driver); |
| 4765 | os_free(global->params.override_ctrl_interface); |
| 4766 | |
Dmitry Shmidt | 4ce9c87 | 2013-10-24 11:08:13 -0700 | [diff] [blame] | 4767 | os_free(global->p2p_disallow_freq.range); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4768 | os_free(global->p2p_go_avoid_freq.range); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4769 | os_free(global->add_psk); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4770 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4771 | os_free(global); |
| 4772 | wpa_debug_close_syslog(); |
| 4773 | wpa_debug_close_file(); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4774 | wpa_debug_close_linux_tracing(); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4775 | } |
| 4776 | |
| 4777 | |
| 4778 | void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s) |
| 4779 | { |
| 4780 | if ((wpa_s->conf->changed_parameters & CFG_CHANGED_COUNTRY) && |
| 4781 | wpa_s->conf->country[0] && wpa_s->conf->country[1]) { |
| 4782 | char country[3]; |
| 4783 | country[0] = wpa_s->conf->country[0]; |
| 4784 | country[1] = wpa_s->conf->country[1]; |
| 4785 | country[2] = '\0'; |
| 4786 | if (wpa_drv_set_country(wpa_s, country) < 0) { |
| 4787 | wpa_printf(MSG_ERROR, "Failed to set country code " |
| 4788 | "'%s'", country); |
| 4789 | } |
| 4790 | } |
| 4791 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4792 | if (wpa_s->conf->changed_parameters & CFG_CHANGED_EXT_PW_BACKEND) |
| 4793 | wpas_init_ext_pw(wpa_s); |
| 4794 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4795 | #ifdef CONFIG_WPS |
| 4796 | wpas_wps_update_config(wpa_s); |
| 4797 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4798 | wpas_p2p_update_config(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4799 | wpa_s->conf->changed_parameters = 0; |
| 4800 | } |
| 4801 | |
| 4802 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4803 | void add_freq(int *freqs, int *num_freqs, int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4804 | { |
| 4805 | int i; |
| 4806 | |
| 4807 | for (i = 0; i < *num_freqs; i++) { |
| 4808 | if (freqs[i] == freq) |
| 4809 | return; |
| 4810 | } |
| 4811 | |
| 4812 | freqs[*num_freqs] = freq; |
| 4813 | (*num_freqs)++; |
| 4814 | } |
| 4815 | |
| 4816 | |
| 4817 | static int * get_bss_freqs_in_ess(struct wpa_supplicant *wpa_s) |
| 4818 | { |
| 4819 | struct wpa_bss *bss, *cbss; |
| 4820 | const int max_freqs = 10; |
| 4821 | int *freqs; |
| 4822 | int num_freqs = 0; |
| 4823 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4824 | freqs = os_calloc(max_freqs + 1, sizeof(int)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4825 | if (freqs == NULL) |
| 4826 | return NULL; |
| 4827 | |
| 4828 | cbss = wpa_s->current_bss; |
| 4829 | |
| 4830 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 4831 | if (bss == cbss) |
| 4832 | continue; |
| 4833 | if (bss->ssid_len == cbss->ssid_len && |
| 4834 | os_memcmp(bss->ssid, cbss->ssid, bss->ssid_len) == 0 && |
| 4835 | wpa_blacklist_get(wpa_s, bss->bssid) == NULL) { |
| 4836 | add_freq(freqs, &num_freqs, bss->freq); |
| 4837 | if (num_freqs == max_freqs) |
| 4838 | break; |
| 4839 | } |
| 4840 | } |
| 4841 | |
| 4842 | if (num_freqs == 0) { |
| 4843 | os_free(freqs); |
| 4844 | freqs = NULL; |
| 4845 | } |
| 4846 | |
| 4847 | return freqs; |
| 4848 | } |
| 4849 | |
| 4850 | |
| 4851 | void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 4852 | { |
| 4853 | int timeout; |
| 4854 | int count; |
| 4855 | int *freqs = NULL; |
| 4856 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4857 | wpas_connect_work_done(wpa_s); |
| 4858 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4859 | /* |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4860 | * Remove possible authentication timeout since the connection failed. |
| 4861 | */ |
| 4862 | eloop_cancel_timeout(wpa_supplicant_timeout, wpa_s, NULL); |
| 4863 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4864 | /* |
| 4865 | * There is no point in blacklisting the AP if this event is |
| 4866 | * generated based on local request to disconnect. |
| 4867 | */ |
| 4868 | if (wpa_s->own_disconnect_req) { |
| 4869 | wpa_s->own_disconnect_req = 0; |
| 4870 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4871 | "Ignore connection failure due to local request to disconnect"); |
| 4872 | return; |
| 4873 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 4874 | if (wpa_s->disconnected) { |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 4875 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore connection failure " |
| 4876 | "indication since interface has been put into " |
| 4877 | "disconnected state"); |
| 4878 | return; |
| 4879 | } |
| 4880 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4881 | /* |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4882 | * Add the failed BSSID into the blacklist and speed up next scan |
| 4883 | * attempt if there could be other APs that could accept association. |
| 4884 | * The current blacklist count indicates how many times we have tried |
| 4885 | * connecting to this AP and multiple attempts mean that other APs are |
| 4886 | * either not available or has already been tried, so that we can start |
| 4887 | * increasing the delay here to avoid constant scanning. |
| 4888 | */ |
| 4889 | count = wpa_blacklist_add(wpa_s, bssid); |
| 4890 | if (count == 1 && wpa_s->current_bss) { |
| 4891 | /* |
| 4892 | * This BSS was not in the blacklist before. If there is |
| 4893 | * another BSS available for the same ESS, we should try that |
| 4894 | * next. Otherwise, we may as well try this one once more |
| 4895 | * before allowing other, likely worse, ESSes to be considered. |
| 4896 | */ |
| 4897 | freqs = get_bss_freqs_in_ess(wpa_s); |
| 4898 | if (freqs) { |
| 4899 | wpa_dbg(wpa_s, MSG_DEBUG, "Another BSS in this ESS " |
| 4900 | "has been seen; try it next"); |
| 4901 | wpa_blacklist_add(wpa_s, bssid); |
| 4902 | /* |
| 4903 | * On the next scan, go through only the known channels |
| 4904 | * used in this ESS based on previous scans to speed up |
| 4905 | * common load balancing use case. |
| 4906 | */ |
| 4907 | os_free(wpa_s->next_scan_freqs); |
| 4908 | wpa_s->next_scan_freqs = freqs; |
| 4909 | } |
| 4910 | } |
| 4911 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4912 | /* |
| 4913 | * Add previous failure count in case the temporary blacklist was |
| 4914 | * cleared due to no other BSSes being available. |
| 4915 | */ |
| 4916 | count += wpa_s->extra_blacklist_count; |
| 4917 | |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 4918 | if (count > 3 && wpa_s->current_ssid) { |
| 4919 | wpa_printf(MSG_DEBUG, "Continuous association failures - " |
| 4920 | "consider temporary network disabling"); |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 4921 | wpas_auth_failed(wpa_s, "CONN_FAILED"); |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 4922 | } |
| 4923 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4924 | switch (count) { |
| 4925 | case 1: |
| 4926 | timeout = 100; |
| 4927 | break; |
| 4928 | case 2: |
| 4929 | timeout = 500; |
| 4930 | break; |
| 4931 | case 3: |
| 4932 | timeout = 1000; |
| 4933 | break; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4934 | case 4: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4935 | timeout = 5000; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4936 | break; |
| 4937 | default: |
| 4938 | timeout = 10000; |
| 4939 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4940 | } |
| 4941 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4942 | wpa_dbg(wpa_s, MSG_DEBUG, "Blacklist count %d --> request scan in %d " |
| 4943 | "ms", count, timeout); |
| 4944 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4945 | /* |
| 4946 | * TODO: if more than one possible AP is available in scan results, |
| 4947 | * could try the other ones before requesting a new scan. |
| 4948 | */ |
| 4949 | wpa_supplicant_req_scan(wpa_s, timeout / 1000, |
| 4950 | 1000 * (timeout % 1000)); |
| 4951 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4952 | |
| 4953 | |
| 4954 | int wpas_driver_bss_selection(struct wpa_supplicant *wpa_s) |
| 4955 | { |
| 4956 | return wpa_s->conf->ap_scan == 2 || |
| 4957 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION); |
| 4958 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4959 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4960 | |
| 4961 | #if defined(CONFIG_CTRL_IFACE) || defined(CONFIG_CTRL_IFACE_DBUS_NEW) |
| 4962 | int wpa_supplicant_ctrl_iface_ctrl_rsp_handle(struct wpa_supplicant *wpa_s, |
| 4963 | struct wpa_ssid *ssid, |
| 4964 | const char *field, |
| 4965 | const char *value) |
| 4966 | { |
| 4967 | #ifdef IEEE8021X_EAPOL |
| 4968 | struct eap_peer_config *eap = &ssid->eap; |
| 4969 | |
| 4970 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: response handle field=%s", field); |
| 4971 | wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: response value", |
| 4972 | (const u8 *) value, os_strlen(value)); |
| 4973 | |
| 4974 | switch (wpa_supplicant_ctrl_req_from_string(field)) { |
| 4975 | case WPA_CTRL_REQ_EAP_IDENTITY: |
| 4976 | os_free(eap->identity); |
| 4977 | eap->identity = (u8 *) os_strdup(value); |
| 4978 | eap->identity_len = os_strlen(value); |
| 4979 | eap->pending_req_identity = 0; |
| 4980 | if (ssid == wpa_s->current_ssid) |
| 4981 | wpa_s->reassociate = 1; |
| 4982 | break; |
| 4983 | case WPA_CTRL_REQ_EAP_PASSWORD: |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 4984 | bin_clear_free(eap->password, eap->password_len); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4985 | eap->password = (u8 *) os_strdup(value); |
| 4986 | eap->password_len = os_strlen(value); |
| 4987 | eap->pending_req_password = 0; |
| 4988 | if (ssid == wpa_s->current_ssid) |
| 4989 | wpa_s->reassociate = 1; |
| 4990 | break; |
| 4991 | case WPA_CTRL_REQ_EAP_NEW_PASSWORD: |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 4992 | bin_clear_free(eap->new_password, eap->new_password_len); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4993 | eap->new_password = (u8 *) os_strdup(value); |
| 4994 | eap->new_password_len = os_strlen(value); |
| 4995 | eap->pending_req_new_password = 0; |
| 4996 | if (ssid == wpa_s->current_ssid) |
| 4997 | wpa_s->reassociate = 1; |
| 4998 | break; |
| 4999 | case WPA_CTRL_REQ_EAP_PIN: |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 5000 | str_clear_free(eap->pin); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5001 | eap->pin = os_strdup(value); |
| 5002 | eap->pending_req_pin = 0; |
| 5003 | if (ssid == wpa_s->current_ssid) |
| 5004 | wpa_s->reassociate = 1; |
| 5005 | break; |
| 5006 | case WPA_CTRL_REQ_EAP_OTP: |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 5007 | bin_clear_free(eap->otp, eap->otp_len); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5008 | eap->otp = (u8 *) os_strdup(value); |
| 5009 | eap->otp_len = os_strlen(value); |
| 5010 | os_free(eap->pending_req_otp); |
| 5011 | eap->pending_req_otp = NULL; |
| 5012 | eap->pending_req_otp_len = 0; |
| 5013 | break; |
| 5014 | case WPA_CTRL_REQ_EAP_PASSPHRASE: |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 5015 | str_clear_free(eap->private_key_passwd); |
| 5016 | eap->private_key_passwd = os_strdup(value); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5017 | eap->pending_req_passphrase = 0; |
| 5018 | if (ssid == wpa_s->current_ssid) |
| 5019 | wpa_s->reassociate = 1; |
| 5020 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5021 | case WPA_CTRL_REQ_SIM: |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 5022 | str_clear_free(eap->external_sim_resp); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5023 | eap->external_sim_resp = os_strdup(value); |
| 5024 | break; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 5025 | case WPA_CTRL_REQ_PSK_PASSPHRASE: |
| 5026 | if (wpa_config_set(ssid, "psk", value, 0) < 0) |
| 5027 | return -1; |
| 5028 | ssid->mem_only_psk = 1; |
| 5029 | if (ssid->passphrase) |
| 5030 | wpa_config_update_psk(ssid); |
| 5031 | if (wpa_s->wpa_state == WPA_SCANNING && !wpa_s->scanning) |
| 5032 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 5033 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5034 | default: |
| 5035 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown field '%s'", field); |
| 5036 | return -1; |
| 5037 | } |
| 5038 | |
| 5039 | return 0; |
| 5040 | #else /* IEEE8021X_EAPOL */ |
| 5041 | wpa_printf(MSG_DEBUG, "CTRL_IFACE: IEEE 802.1X not included"); |
| 5042 | return -1; |
| 5043 | #endif /* IEEE8021X_EAPOL */ |
| 5044 | } |
| 5045 | #endif /* CONFIG_CTRL_IFACE || CONFIG_CTRL_IFACE_DBUS_NEW */ |
| 5046 | |
| 5047 | |
| 5048 | int wpas_network_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
| 5049 | { |
| 5050 | int i; |
| 5051 | unsigned int drv_enc; |
| 5052 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5053 | if (wpa_s->p2p_mgmt) |
| 5054 | return 1; /* no normal network profiles on p2p_mgmt interface */ |
| 5055 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5056 | if (ssid == NULL) |
| 5057 | return 1; |
| 5058 | |
| 5059 | if (ssid->disabled) |
| 5060 | return 1; |
| 5061 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5062 | if (wpa_s->drv_capa_known) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5063 | drv_enc = wpa_s->drv_enc; |
| 5064 | else |
| 5065 | drv_enc = (unsigned int) -1; |
| 5066 | |
| 5067 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 5068 | size_t len = ssid->wep_key_len[i]; |
| 5069 | if (len == 0) |
| 5070 | continue; |
| 5071 | if (len == 5 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP40)) |
| 5072 | continue; |
| 5073 | if (len == 13 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP104)) |
| 5074 | continue; |
| 5075 | if (len == 16 && (drv_enc & WPA_DRIVER_CAPA_ENC_WEP128)) |
| 5076 | continue; |
| 5077 | return 1; /* invalid WEP key */ |
| 5078 | } |
| 5079 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5080 | if (wpa_key_mgmt_wpa_psk(ssid->key_mgmt) && !ssid->psk_set && |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 5081 | (!ssid->passphrase || ssid->ssid_len != 0) && !ssid->ext_psk && |
| 5082 | !ssid->mem_only_psk) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5083 | return 1; |
| 5084 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5085 | return 0; |
| 5086 | } |
| 5087 | |
| 5088 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5089 | int wpas_get_ssid_pmf(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
| 5090 | { |
| 5091 | #ifdef CONFIG_IEEE80211W |
| 5092 | if (ssid == NULL || ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT) { |
| 5093 | if (wpa_s->conf->pmf == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 5094 | !(wpa_s->drv_enc & WPA_DRIVER_CAPA_ENC_BIP)) { |
| 5095 | /* |
| 5096 | * Driver does not support BIP -- ignore pmf=1 default |
| 5097 | * since the connection with PMF would fail and the |
| 5098 | * configuration does not require PMF to be enabled. |
| 5099 | */ |
| 5100 | return NO_MGMT_FRAME_PROTECTION; |
| 5101 | } |
| 5102 | |
| 5103 | return wpa_s->conf->pmf; |
| 5104 | } |
| 5105 | |
| 5106 | return ssid->ieee80211w; |
| 5107 | #else /* CONFIG_IEEE80211W */ |
| 5108 | return NO_MGMT_FRAME_PROTECTION; |
| 5109 | #endif /* CONFIG_IEEE80211W */ |
| 5110 | } |
| 5111 | |
| 5112 | |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 5113 | int wpas_is_p2p_prioritized(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5114 | { |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 5115 | if (wpa_s->global->conc_pref == WPA_CONC_PREF_P2P) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5116 | return 1; |
Dmitry Shmidt | 2fb777c | 2012-05-02 12:29:53 -0700 | [diff] [blame] | 5117 | if (wpa_s->global->conc_pref == WPA_CONC_PREF_STA) |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 5118 | return 0; |
Dmitry Shmidt | 687922c | 2012-03-26 14:02:32 -0700 | [diff] [blame] | 5119 | return -1; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5120 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5121 | |
| 5122 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5123 | void wpas_auth_failed(struct wpa_supplicant *wpa_s, char *reason) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5124 | { |
| 5125 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5126 | int dur; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5127 | struct os_reltime now; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5128 | |
| 5129 | if (ssid == NULL) { |
| 5130 | wpa_printf(MSG_DEBUG, "Authentication failure but no known " |
| 5131 | "SSID block"); |
| 5132 | return; |
| 5133 | } |
| 5134 | |
| 5135 | if (ssid->key_mgmt == WPA_KEY_MGMT_WPS) |
| 5136 | return; |
| 5137 | |
| 5138 | ssid->auth_failures++; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 5139 | |
| 5140 | #ifdef CONFIG_P2P |
| 5141 | if (ssid->p2p_group && |
| 5142 | (wpa_s->p2p_in_provisioning || wpa_s->show_group_started)) { |
| 5143 | /* |
| 5144 | * Skip the wait time since there is a short timeout on the |
| 5145 | * connection to a P2P group. |
| 5146 | */ |
| 5147 | return; |
| 5148 | } |
| 5149 | #endif /* CONFIG_P2P */ |
| 5150 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5151 | if (ssid->auth_failures > 50) |
| 5152 | dur = 300; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5153 | else if (ssid->auth_failures > 10) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5154 | dur = 120; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5155 | else if (ssid->auth_failures > 5) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5156 | dur = 90; |
| 5157 | else if (ssid->auth_failures > 3) |
| 5158 | dur = 60; |
| 5159 | else if (ssid->auth_failures > 2) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5160 | dur = 30; |
| 5161 | else if (ssid->auth_failures > 1) |
| 5162 | dur = 20; |
| 5163 | else |
| 5164 | dur = 10; |
| 5165 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5166 | if (ssid->auth_failures > 1 && |
| 5167 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) |
| 5168 | dur += os_random() % (ssid->auth_failures * 10); |
| 5169 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5170 | os_get_reltime(&now); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5171 | if (now.sec + dur <= ssid->disabled_until.sec) |
| 5172 | return; |
| 5173 | |
| 5174 | ssid->disabled_until.sec = now.sec + dur; |
| 5175 | |
| 5176 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TEMP_DISABLED |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5177 | "id=%d ssid=\"%s\" auth_failures=%u duration=%d reason=%s", |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5178 | ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len), |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 5179 | ssid->auth_failures, dur, reason); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | |
| 5183 | void wpas_clear_temp_disabled(struct wpa_supplicant *wpa_s, |
| 5184 | struct wpa_ssid *ssid, int clear_failures) |
| 5185 | { |
| 5186 | if (ssid == NULL) |
| 5187 | return; |
| 5188 | |
| 5189 | if (ssid->disabled_until.sec) { |
| 5190 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REENABLED |
| 5191 | "id=%d ssid=\"%s\"", |
| 5192 | ssid->id, wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 5193 | } |
| 5194 | ssid->disabled_until.sec = 0; |
| 5195 | ssid->disabled_until.usec = 0; |
| 5196 | if (clear_failures) |
| 5197 | ssid->auth_failures = 0; |
| 5198 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5199 | |
| 5200 | |
| 5201 | int disallowed_bssid(struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 5202 | { |
| 5203 | size_t i; |
| 5204 | |
| 5205 | if (wpa_s->disallow_aps_bssid == NULL) |
| 5206 | return 0; |
| 5207 | |
| 5208 | for (i = 0; i < wpa_s->disallow_aps_bssid_count; i++) { |
| 5209 | if (os_memcmp(wpa_s->disallow_aps_bssid + i * ETH_ALEN, |
| 5210 | bssid, ETH_ALEN) == 0) |
| 5211 | return 1; |
| 5212 | } |
| 5213 | |
| 5214 | return 0; |
| 5215 | } |
| 5216 | |
| 5217 | |
| 5218 | int disallowed_ssid(struct wpa_supplicant *wpa_s, const u8 *ssid, |
| 5219 | size_t ssid_len) |
| 5220 | { |
| 5221 | size_t i; |
| 5222 | |
| 5223 | if (wpa_s->disallow_aps_ssid == NULL || ssid == NULL) |
| 5224 | return 0; |
| 5225 | |
| 5226 | for (i = 0; i < wpa_s->disallow_aps_ssid_count; i++) { |
| 5227 | struct wpa_ssid_value *s = &wpa_s->disallow_aps_ssid[i]; |
| 5228 | if (ssid_len == s->ssid_len && |
| 5229 | os_memcmp(ssid, s->ssid, ssid_len) == 0) |
| 5230 | return 1; |
| 5231 | } |
| 5232 | |
| 5233 | return 0; |
| 5234 | } |
| 5235 | |
| 5236 | |
| 5237 | /** |
| 5238 | * wpas_request_connection - Request a new connection |
| 5239 | * @wpa_s: Pointer to the network interface |
| 5240 | * |
| 5241 | * This function is used to request a new connection to be found. It will mark |
| 5242 | * the interface to allow reassociation and request a new scan to find a |
| 5243 | * suitable network to connect to. |
| 5244 | */ |
| 5245 | void wpas_request_connection(struct wpa_supplicant *wpa_s) |
| 5246 | { |
| 5247 | wpa_s->normal_scans = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5248 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5249 | wpa_supplicant_reinit_autoscan(wpa_s); |
| 5250 | wpa_s->extra_blacklist_count = 0; |
| 5251 | wpa_s->disconnected = 0; |
| 5252 | wpa_s->reassociate = 1; |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 5253 | |
| 5254 | if (wpa_supplicant_fast_associate(wpa_s) != 1) |
| 5255 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5256 | else |
| 5257 | wpa_s->reattach = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5258 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 5259 | |
| 5260 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5261 | void dump_freq_data(struct wpa_supplicant *wpa_s, const char *title, |
| 5262 | struct wpa_used_freq_data *freqs_data, |
| 5263 | unsigned int len) |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 5264 | { |
| 5265 | unsigned int i; |
| 5266 | |
| 5267 | wpa_dbg(wpa_s, MSG_DEBUG, "Shared frequencies (len=%u): %s", |
| 5268 | len, title); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5269 | for (i = 0; i < len; i++) { |
| 5270 | struct wpa_used_freq_data *cur = &freqs_data[i]; |
| 5271 | wpa_dbg(wpa_s, MSG_DEBUG, "freq[%u]: %d, flags=0x%X", |
| 5272 | i, cur->freq, cur->flags); |
| 5273 | } |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 5274 | } |
| 5275 | |
| 5276 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5277 | /* |
| 5278 | * Find the operating frequencies of any of the virtual interfaces that |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5279 | * are using the same radio as the current interface, and in addition, get |
| 5280 | * information about the interface types that are using the frequency. |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5281 | */ |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5282 | int get_shared_radio_freqs_data(struct wpa_supplicant *wpa_s, |
| 5283 | struct wpa_used_freq_data *freqs_data, |
| 5284 | unsigned int len) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5285 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5286 | struct wpa_supplicant *ifs; |
| 5287 | u8 bssid[ETH_ALEN]; |
| 5288 | int freq; |
| 5289 | unsigned int idx = 0, i; |
| 5290 | |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 5291 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5292 | "Determining shared radio frequencies (max len %u)", len); |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5293 | os_memset(freqs_data, 0, sizeof(struct wpa_used_freq_data) * len); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5294 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 5295 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 5296 | radio_list) { |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5297 | if (idx == len) |
| 5298 | break; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5299 | |
| 5300 | if (ifs->current_ssid == NULL || ifs->assoc_freq == 0) |
| 5301 | continue; |
| 5302 | |
| 5303 | if (ifs->current_ssid->mode == WPAS_MODE_AP || |
| 5304 | ifs->current_ssid->mode == WPAS_MODE_P2P_GO) |
| 5305 | freq = ifs->current_ssid->frequency; |
| 5306 | else if (wpa_drv_get_bssid(ifs, bssid) == 0) |
| 5307 | freq = ifs->assoc_freq; |
| 5308 | else |
| 5309 | continue; |
| 5310 | |
| 5311 | /* Hold only distinct freqs */ |
| 5312 | for (i = 0; i < idx; i++) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5313 | if (freqs_data[i].freq == freq) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5314 | break; |
| 5315 | |
| 5316 | if (i == idx) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5317 | freqs_data[idx++].freq = freq; |
| 5318 | |
| 5319 | if (ifs->current_ssid->mode == WPAS_MODE_INFRA) { |
| 5320 | freqs_data[i].flags = ifs->current_ssid->p2p_group ? |
| 5321 | WPA_FREQ_USED_BY_P2P_CLIENT : |
| 5322 | WPA_FREQ_USED_BY_INFRA_STATION; |
| 5323 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5324 | } |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 5325 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5326 | dump_freq_data(wpa_s, "completed iteration", freqs_data, idx); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5327 | return idx; |
| 5328 | } |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 5329 | |
| 5330 | |
| 5331 | /* |
| 5332 | * Find the operating frequencies of any of the virtual interfaces that |
| 5333 | * are using the same radio as the current interface. |
| 5334 | */ |
| 5335 | int get_shared_radio_freqs(struct wpa_supplicant *wpa_s, |
| 5336 | int *freq_array, unsigned int len) |
| 5337 | { |
| 5338 | struct wpa_used_freq_data *freqs_data; |
| 5339 | int num, i; |
| 5340 | |
| 5341 | os_memset(freq_array, 0, sizeof(int) * len); |
| 5342 | |
| 5343 | freqs_data = os_calloc(len, sizeof(struct wpa_used_freq_data)); |
| 5344 | if (!freqs_data) |
| 5345 | return -1; |
| 5346 | |
| 5347 | num = get_shared_radio_freqs_data(wpa_s, freqs_data, len); |
| 5348 | for (i = 0; i < num; i++) |
| 5349 | freq_array[i] = freqs_data[i].freq; |
| 5350 | |
| 5351 | os_free(freqs_data); |
| 5352 | |
| 5353 | return num; |
| 5354 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5355 | |
| 5356 | |
| 5357 | static void wpas_rrm_neighbor_rep_timeout_handler(void *data, void *user_ctx) |
| 5358 | { |
| 5359 | struct rrm_data *rrm = data; |
| 5360 | |
| 5361 | if (!rrm->notify_neighbor_rep) { |
| 5362 | wpa_printf(MSG_ERROR, |
| 5363 | "RRM: Unexpected neighbor report timeout"); |
| 5364 | return; |
| 5365 | } |
| 5366 | |
| 5367 | wpa_printf(MSG_DEBUG, "RRM: Notifying neighbor report - NONE"); |
| 5368 | rrm->notify_neighbor_rep(rrm->neighbor_rep_cb_ctx, NULL); |
| 5369 | |
| 5370 | rrm->notify_neighbor_rep = NULL; |
| 5371 | rrm->neighbor_rep_cb_ctx = NULL; |
| 5372 | } |
| 5373 | |
| 5374 | |
| 5375 | /* |
| 5376 | * wpas_rrm_reset - Clear and reset all RRM data in wpa_supplicant |
| 5377 | * @wpa_s: Pointer to wpa_supplicant |
| 5378 | */ |
| 5379 | void wpas_rrm_reset(struct wpa_supplicant *wpa_s) |
| 5380 | { |
| 5381 | wpa_s->rrm.rrm_used = 0; |
| 5382 | |
| 5383 | eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler, &wpa_s->rrm, |
| 5384 | NULL); |
| 5385 | if (wpa_s->rrm.notify_neighbor_rep) |
| 5386 | wpas_rrm_neighbor_rep_timeout_handler(&wpa_s->rrm, NULL); |
| 5387 | wpa_s->rrm.next_neighbor_rep_token = 1; |
| 5388 | } |
| 5389 | |
| 5390 | |
| 5391 | /* |
| 5392 | * wpas_rrm_process_neighbor_rep - Handle incoming neighbor report |
| 5393 | * @wpa_s: Pointer to wpa_supplicant |
| 5394 | * @report: Neighbor report buffer, prefixed by a 1-byte dialog token |
| 5395 | * @report_len: Length of neighbor report buffer |
| 5396 | */ |
| 5397 | void wpas_rrm_process_neighbor_rep(struct wpa_supplicant *wpa_s, |
| 5398 | const u8 *report, size_t report_len) |
| 5399 | { |
| 5400 | struct wpabuf *neighbor_rep; |
| 5401 | |
| 5402 | wpa_hexdump(MSG_DEBUG, "RRM: New Neighbor Report", report, report_len); |
| 5403 | if (report_len < 1) |
| 5404 | return; |
| 5405 | |
| 5406 | if (report[0] != wpa_s->rrm.next_neighbor_rep_token - 1) { |
| 5407 | wpa_printf(MSG_DEBUG, |
| 5408 | "RRM: Discarding neighbor report with token %d (expected %d)", |
| 5409 | report[0], wpa_s->rrm.next_neighbor_rep_token - 1); |
| 5410 | return; |
| 5411 | } |
| 5412 | |
| 5413 | eloop_cancel_timeout(wpas_rrm_neighbor_rep_timeout_handler, &wpa_s->rrm, |
| 5414 | NULL); |
| 5415 | |
| 5416 | if (!wpa_s->rrm.notify_neighbor_rep) { |
| 5417 | wpa_printf(MSG_ERROR, "RRM: Unexpected neighbor report"); |
| 5418 | return; |
| 5419 | } |
| 5420 | |
| 5421 | /* skipping the first byte, which is only an id (dialog token) */ |
| 5422 | neighbor_rep = wpabuf_alloc(report_len - 1); |
| 5423 | if (neighbor_rep == NULL) |
| 5424 | return; |
| 5425 | wpabuf_put_data(neighbor_rep, report + 1, report_len - 1); |
| 5426 | wpa_printf(MSG_DEBUG, "RRM: Notifying neighbor report (token = %d)", |
| 5427 | report[0]); |
| 5428 | wpa_s->rrm.notify_neighbor_rep(wpa_s->rrm.neighbor_rep_cb_ctx, |
| 5429 | neighbor_rep); |
| 5430 | wpa_s->rrm.notify_neighbor_rep = NULL; |
| 5431 | wpa_s->rrm.neighbor_rep_cb_ctx = NULL; |
| 5432 | } |
| 5433 | |
| 5434 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5435 | #if defined(__CYGWIN__) || defined(CONFIG_NATIVE_WINDOWS) |
| 5436 | /* Workaround different, undefined for Windows, error codes used here */ |
| 5437 | #define ENOTCONN -1 |
| 5438 | #define EOPNOTSUPP -1 |
| 5439 | #define ECANCELED -1 |
| 5440 | #endif |
| 5441 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5442 | /** |
| 5443 | * wpas_rrm_send_neighbor_rep_request - Request a neighbor report from our AP |
| 5444 | * @wpa_s: Pointer to wpa_supplicant |
| 5445 | * @ssid: if not null, this is sent in the request. Otherwise, no SSID IE |
| 5446 | * is sent in the request. |
| 5447 | * @cb: Callback function to be called once the requested report arrives, or |
| 5448 | * timed out after RRM_NEIGHBOR_REPORT_TIMEOUT seconds. |
| 5449 | * In the former case, 'neighbor_rep' is a newly allocated wpabuf, and it's |
| 5450 | * the requester's responsibility to free it. |
| 5451 | * In the latter case NULL will be sent in 'neighbor_rep'. |
| 5452 | * @cb_ctx: Context value to send the callback function |
| 5453 | * Returns: 0 in case of success, negative error code otherwise |
| 5454 | * |
| 5455 | * In case there is a previous request which has not been answered yet, the |
| 5456 | * new request fails. The caller may retry after RRM_NEIGHBOR_REPORT_TIMEOUT. |
| 5457 | * Request must contain a callback function. |
| 5458 | */ |
| 5459 | int wpas_rrm_send_neighbor_rep_request(struct wpa_supplicant *wpa_s, |
| 5460 | const struct wpa_ssid *ssid, |
| 5461 | void (*cb)(void *ctx, |
| 5462 | struct wpabuf *neighbor_rep), |
| 5463 | void *cb_ctx) |
| 5464 | { |
| 5465 | struct wpabuf *buf; |
| 5466 | const u8 *rrm_ie; |
| 5467 | |
| 5468 | if (wpa_s->wpa_state != WPA_COMPLETED || wpa_s->current_ssid == NULL) { |
| 5469 | wpa_printf(MSG_DEBUG, "RRM: No connection, no RRM."); |
| 5470 | return -ENOTCONN; |
| 5471 | } |
| 5472 | |
| 5473 | if (!wpa_s->rrm.rrm_used) { |
| 5474 | wpa_printf(MSG_DEBUG, "RRM: No RRM in current connection."); |
| 5475 | return -EOPNOTSUPP; |
| 5476 | } |
| 5477 | |
| 5478 | rrm_ie = wpa_bss_get_ie(wpa_s->current_bss, |
| 5479 | WLAN_EID_RRM_ENABLED_CAPABILITIES); |
| 5480 | if (!rrm_ie || !(wpa_s->current_bss->caps & IEEE80211_CAP_RRM) || |
| 5481 | !(rrm_ie[2] & WLAN_RRM_CAPS_NEIGHBOR_REPORT)) { |
| 5482 | wpa_printf(MSG_DEBUG, |
| 5483 | "RRM: No network support for Neighbor Report."); |
| 5484 | return -EOPNOTSUPP; |
| 5485 | } |
| 5486 | |
| 5487 | if (!cb) { |
| 5488 | wpa_printf(MSG_DEBUG, |
| 5489 | "RRM: Neighbor Report request must provide a callback."); |
| 5490 | return -EINVAL; |
| 5491 | } |
| 5492 | |
| 5493 | /* Refuse if there's a live request */ |
| 5494 | if (wpa_s->rrm.notify_neighbor_rep) { |
| 5495 | wpa_printf(MSG_DEBUG, |
| 5496 | "RRM: Currently handling previous Neighbor Report."); |
| 5497 | return -EBUSY; |
| 5498 | } |
| 5499 | |
| 5500 | /* 3 = action category + action code + dialog token */ |
| 5501 | buf = wpabuf_alloc(3 + (ssid ? 2 + ssid->ssid_len : 0)); |
| 5502 | if (buf == NULL) { |
| 5503 | wpa_printf(MSG_DEBUG, |
| 5504 | "RRM: Failed to allocate Neighbor Report Request"); |
| 5505 | return -ENOMEM; |
| 5506 | } |
| 5507 | |
| 5508 | wpa_printf(MSG_DEBUG, "RRM: Neighbor report request (for %s), token=%d", |
| 5509 | (ssid ? wpa_ssid_txt(ssid->ssid, ssid->ssid_len) : ""), |
| 5510 | wpa_s->rrm.next_neighbor_rep_token); |
| 5511 | |
| 5512 | wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT); |
| 5513 | wpabuf_put_u8(buf, WLAN_RRM_NEIGHBOR_REPORT_REQUEST); |
| 5514 | wpabuf_put_u8(buf, wpa_s->rrm.next_neighbor_rep_token); |
| 5515 | if (ssid) { |
| 5516 | wpabuf_put_u8(buf, WLAN_EID_SSID); |
| 5517 | wpabuf_put_u8(buf, ssid->ssid_len); |
| 5518 | wpabuf_put_data(buf, ssid->ssid, ssid->ssid_len); |
| 5519 | } |
| 5520 | |
| 5521 | wpa_s->rrm.next_neighbor_rep_token++; |
| 5522 | |
| 5523 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 5524 | wpa_s->own_addr, wpa_s->bssid, |
| 5525 | wpabuf_head(buf), wpabuf_len(buf), 0) < 0) { |
| 5526 | wpa_printf(MSG_DEBUG, |
| 5527 | "RRM: Failed to send Neighbor Report Request"); |
| 5528 | wpabuf_free(buf); |
| 5529 | return -ECANCELED; |
| 5530 | } |
| 5531 | |
| 5532 | wpa_s->rrm.neighbor_rep_cb_ctx = cb_ctx; |
| 5533 | wpa_s->rrm.notify_neighbor_rep = cb; |
| 5534 | eloop_register_timeout(RRM_NEIGHBOR_REPORT_TIMEOUT, 0, |
| 5535 | wpas_rrm_neighbor_rep_timeout_handler, |
| 5536 | &wpa_s->rrm, NULL); |
| 5537 | |
| 5538 | wpabuf_free(buf); |
| 5539 | return 0; |
| 5540 | } |
| 5541 | |
| 5542 | |
| 5543 | void wpas_rrm_handle_link_measurement_request(struct wpa_supplicant *wpa_s, |
| 5544 | const u8 *src, |
| 5545 | const u8 *frame, size_t len, |
| 5546 | int rssi) |
| 5547 | { |
| 5548 | struct wpabuf *buf; |
| 5549 | const struct rrm_link_measurement_request *req; |
| 5550 | struct rrm_link_measurement_report report; |
| 5551 | |
| 5552 | if (wpa_s->wpa_state != WPA_COMPLETED) { |
| 5553 | wpa_printf(MSG_INFO, |
| 5554 | "RRM: Ignoring link measurement request. Not associated"); |
| 5555 | return; |
| 5556 | } |
| 5557 | |
| 5558 | if (!wpa_s->rrm.rrm_used) { |
| 5559 | wpa_printf(MSG_INFO, |
| 5560 | "RRM: Ignoring link measurement request. Not RRM network"); |
| 5561 | return; |
| 5562 | } |
| 5563 | |
| 5564 | if (!(wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION)) { |
| 5565 | wpa_printf(MSG_INFO, |
| 5566 | "RRM: Measurement report failed. TX power insertion not supported"); |
| 5567 | return; |
| 5568 | } |
| 5569 | |
| 5570 | req = (const struct rrm_link_measurement_request *) frame; |
| 5571 | if (len < sizeof(*req)) { |
| 5572 | wpa_printf(MSG_INFO, |
| 5573 | "RRM: Link measurement report failed. Request too short"); |
| 5574 | return; |
| 5575 | } |
| 5576 | |
| 5577 | os_memset(&report, 0, sizeof(report)); |
| 5578 | report.tpc.eid = WLAN_EID_TPC_REPORT; |
| 5579 | report.tpc.len = 2; |
| 5580 | report.rsni = 255; /* 255 indicates that RSNI is not available */ |
| 5581 | report.dialog_token = req->dialog_token; |
| 5582 | |
| 5583 | /* |
| 5584 | * It's possible to estimate RCPI based on RSSI in dBm. This |
| 5585 | * calculation will not reflect the correct value for high rates, |
| 5586 | * but it's good enough for Action frames which are transmitted |
| 5587 | * with up to 24 Mbps rates. |
| 5588 | */ |
| 5589 | if (!rssi) |
| 5590 | report.rcpi = 255; /* not available */ |
| 5591 | else if (rssi < -110) |
| 5592 | report.rcpi = 0; |
| 5593 | else if (rssi > 0) |
| 5594 | report.rcpi = 220; |
| 5595 | else |
| 5596 | report.rcpi = (rssi + 110) * 2; |
| 5597 | |
| 5598 | /* action_category + action_code */ |
| 5599 | buf = wpabuf_alloc(2 + sizeof(report)); |
| 5600 | if (buf == NULL) { |
| 5601 | wpa_printf(MSG_ERROR, |
| 5602 | "RRM: Link measurement report failed. Buffer allocation failed"); |
| 5603 | return; |
| 5604 | } |
| 5605 | |
| 5606 | wpabuf_put_u8(buf, WLAN_ACTION_RADIO_MEASUREMENT); |
| 5607 | wpabuf_put_u8(buf, WLAN_RRM_LINK_MEASUREMENT_REPORT); |
| 5608 | wpabuf_put_data(buf, &report, sizeof(report)); |
| 5609 | wpa_hexdump(MSG_DEBUG, "RRM: Link measurement report:", |
| 5610 | wpabuf_head(buf), wpabuf_len(buf)); |
| 5611 | |
| 5612 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, src, |
| 5613 | wpa_s->own_addr, wpa_s->bssid, |
| 5614 | wpabuf_head(buf), wpabuf_len(buf), 0)) { |
| 5615 | wpa_printf(MSG_ERROR, |
| 5616 | "RRM: Link measurement report failed. Send action failed"); |
| 5617 | } |
| 5618 | wpabuf_free(buf); |
| 5619 | } |