Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant - Driver event processing |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3 | * Copyright (c) 2003-2014, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5 | * This software may be distributed under the terms of the BSD license. |
| 6 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include "includes.h" |
| 10 | |
| 11 | #include "common.h" |
| 12 | #include "eapol_supp/eapol_supp_sm.h" |
| 13 | #include "rsn_supp/wpa.h" |
| 14 | #include "eloop.h" |
| 15 | #include "config.h" |
| 16 | #include "l2_packet/l2_packet.h" |
| 17 | #include "wpa_supplicant_i.h" |
| 18 | #include "driver_i.h" |
| 19 | #include "pcsc_funcs.h" |
| 20 | #include "rsn_supp/preauth.h" |
| 21 | #include "rsn_supp/pmksa_cache.h" |
| 22 | #include "common/wpa_ctrl.h" |
| 23 | #include "eap_peer/eap.h" |
| 24 | #include "ap/hostapd.h" |
| 25 | #include "p2p/p2p.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 26 | #include "wnm_sta.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 27 | #include "notify.h" |
| 28 | #include "common/ieee802_11_defs.h" |
| 29 | #include "common/ieee802_11_common.h" |
| 30 | #include "crypto/random.h" |
| 31 | #include "blacklist.h" |
| 32 | #include "wpas_glue.h" |
| 33 | #include "wps_supplicant.h" |
| 34 | #include "ibss_rsn.h" |
| 35 | #include "sme.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 36 | #include "gas_query.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "p2p_supplicant.h" |
| 38 | #include "bgscan.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 39 | #include "autoscan.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 40 | #include "ap.h" |
| 41 | #include "bss.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 42 | #include "scan.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 43 | #include "offchannel.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 44 | #include "interworking.h" |
| 45 | |
| 46 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 47 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 48 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 49 | int new_scan, int own_request); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 50 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 51 | |
| 52 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 53 | static int wpas_temp_disabled(struct wpa_supplicant *wpa_s, |
| 54 | struct wpa_ssid *ssid) |
| 55 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 56 | struct os_reltime now; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 57 | |
| 58 | if (ssid == NULL || ssid->disabled_until.sec == 0) |
| 59 | return 0; |
| 60 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 61 | os_get_reltime(&now); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 62 | if (ssid->disabled_until.sec > now.sec) |
| 63 | return ssid->disabled_until.sec - now.sec; |
| 64 | |
| 65 | wpas_clear_temp_disabled(wpa_s, ssid, 0); |
| 66 | |
| 67 | return 0; |
| 68 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 69 | |
| 70 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 71 | static struct wpa_bss * wpa_supplicant_get_new_bss( |
| 72 | struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 73 | { |
| 74 | struct wpa_bss *bss = NULL; |
| 75 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 76 | |
| 77 | if (ssid->ssid_len > 0) |
| 78 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); |
| 79 | if (!bss) |
| 80 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 81 | |
| 82 | return bss; |
| 83 | } |
| 84 | |
| 85 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 86 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s) |
| 87 | { |
| 88 | struct wpa_ssid *ssid, *old_ssid; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 89 | struct wpa_bss *bss; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 90 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 91 | |
| 92 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) |
| 93 | return 0; |
| 94 | |
| 95 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
| 96 | "information"); |
| 97 | ssid = wpa_supplicant_get_ssid(wpa_s); |
| 98 | if (ssid == NULL) { |
| 99 | wpa_msg(wpa_s, MSG_INFO, |
| 100 | "No network configuration found for the current AP"); |
| 101 | return -1; |
| 102 | } |
| 103 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 104 | if (wpas_network_disabled(wpa_s, ssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 105 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
| 106 | return -1; |
| 107 | } |
| 108 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 109 | if (disallowed_bssid(wpa_s, wpa_s->bssid) || |
| 110 | disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) { |
| 111 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed"); |
| 112 | return -1; |
| 113 | } |
| 114 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 115 | res = wpas_temp_disabled(wpa_s, ssid); |
| 116 | if (res > 0) { |
| 117 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily " |
| 118 | "disabled for %d second(s)", res); |
| 119 | return -1; |
| 120 | } |
| 121 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 122 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
| 123 | "current AP"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 124 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 125 | u8 wpa_ie[80]; |
| 126 | size_t wpa_ie_len = sizeof(wpa_ie); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 127 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
| 128 | wpa_ie, &wpa_ie_len) < 0) |
| 129 | wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 130 | } else { |
| 131 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 132 | } |
| 133 | |
| 134 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) |
| 135 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 136 | old_ssid = wpa_s->current_ssid; |
| 137 | wpa_s->current_ssid = ssid; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 138 | |
| 139 | bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); |
| 140 | if (!bss) { |
| 141 | wpa_supplicant_update_scan_results(wpa_s); |
| 142 | |
| 143 | /* Get the BSS from the new scan results */ |
| 144 | bss = wpa_supplicant_get_new_bss(wpa_s, wpa_s->bssid); |
| 145 | } |
| 146 | |
| 147 | if (bss) |
| 148 | wpa_s->current_bss = bss; |
| 149 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 150 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
| 151 | wpa_supplicant_initiate_eapol(wpa_s); |
| 152 | if (old_ssid != wpa_s->current_ssid) |
| 153 | wpas_notify_network_changed(wpa_s); |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 159 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 160 | { |
| 161 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 162 | |
| 163 | if (wpa_s->countermeasures) { |
| 164 | wpa_s->countermeasures = 0; |
| 165 | wpa_drv_set_countermeasures(wpa_s, 0); |
| 166 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); |
| 167 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | |
| 172 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) |
| 173 | { |
| 174 | int bssid_changed; |
| 175 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 176 | wnm_bss_keep_alive_deinit(wpa_s); |
| 177 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 178 | #ifdef CONFIG_IBSS_RSN |
| 179 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
| 180 | wpa_s->ibss_rsn = NULL; |
| 181 | #endif /* CONFIG_IBSS_RSN */ |
| 182 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 183 | #ifdef CONFIG_AP |
| 184 | wpa_supplicant_ap_deinit(wpa_s); |
| 185 | #endif /* CONFIG_AP */ |
| 186 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 187 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 188 | return; |
| 189 | |
| 190 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 191 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
| 192 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
| 193 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 194 | #ifdef CONFIG_SME |
| 195 | wpa_s->sme.prev_bssid_set = 0; |
| 196 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 197 | #ifdef CONFIG_P2P |
| 198 | os_memset(wpa_s->go_dev_addr, 0, ETH_ALEN); |
| 199 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 200 | wpa_s->current_bss = NULL; |
| 201 | wpa_s->assoc_freq = 0; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 202 | #ifdef CONFIG_IEEE80211R |
| 203 | #ifdef CONFIG_SME |
| 204 | if (wpa_s->sme.ft_ies) |
| 205 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); |
| 206 | #endif /* CONFIG_SME */ |
| 207 | #endif /* CONFIG_IEEE80211R */ |
| 208 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 209 | if (bssid_changed) |
| 210 | wpas_notify_bssid_changed(wpa_s); |
| 211 | |
| 212 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
| 213 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); |
| 214 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
| 215 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
| 216 | wpa_s->ap_ies_from_associnfo = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 217 | wpa_s->current_ssid = NULL; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 218 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 219 | wpa_s->key_mgmt = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | |
| 223 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s) |
| 224 | { |
| 225 | struct wpa_ie_data ie; |
| 226 | int pmksa_set = -1; |
| 227 | size_t i; |
| 228 | |
| 229 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || |
| 230 | ie.pmkid == NULL) |
| 231 | return; |
| 232 | |
| 233 | for (i = 0; i < ie.num_pmkid; i++) { |
| 234 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, |
| 235 | ie.pmkid + i * PMKID_LEN, |
| 236 | NULL, NULL, 0); |
| 237 | if (pmksa_set == 0) { |
| 238 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1); |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
| 244 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, |
| 249 | union wpa_event_data *data) |
| 250 | { |
| 251 | if (data == NULL) { |
| 252 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
| 253 | "event"); |
| 254 | return; |
| 255 | } |
| 256 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
| 257 | " index=%d preauth=%d", |
| 258 | MAC2STR(data->pmkid_candidate.bssid), |
| 259 | data->pmkid_candidate.index, |
| 260 | data->pmkid_candidate.preauth); |
| 261 | |
| 262 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, |
| 263 | data->pmkid_candidate.index, |
| 264 | data->pmkid_candidate.preauth); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) |
| 269 | { |
| 270 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 271 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) |
| 272 | return 0; |
| 273 | |
| 274 | #ifdef IEEE8021X_EAPOL |
| 275 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 276 | wpa_s->current_ssid && |
| 277 | !(wpa_s->current_ssid->eapol_flags & |
| 278 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
| 279 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { |
| 280 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either |
| 281 | * plaintext or static WEP keys). */ |
| 282 | return 0; |
| 283 | } |
| 284 | #endif /* IEEE8021X_EAPOL */ |
| 285 | |
| 286 | return 1; |
| 287 | } |
| 288 | |
| 289 | |
| 290 | /** |
| 291 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC |
| 292 | * @wpa_s: pointer to wpa_supplicant data |
| 293 | * @ssid: Configuration data for the network |
| 294 | * Returns: 0 on success, -1 on failure |
| 295 | * |
| 296 | * This function is called when starting authentication with a network that is |
| 297 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). |
| 298 | */ |
| 299 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, |
| 300 | struct wpa_ssid *ssid) |
| 301 | { |
| 302 | #ifdef IEEE8021X_EAPOL |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 303 | #ifdef PCSC_FUNCS |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 304 | int aka = 0, sim = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 305 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 306 | if ((ssid != NULL && ssid->eap.pcsc == NULL) || |
| 307 | wpa_s->scard != NULL || wpa_s->conf->external_sim) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 308 | return 0; |
| 309 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 310 | if (ssid == NULL || ssid->eap.eap_methods == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 311 | sim = 1; |
| 312 | aka = 1; |
| 313 | } else { |
| 314 | struct eap_method_type *eap = ssid->eap.eap_methods; |
| 315 | while (eap->vendor != EAP_VENDOR_IETF || |
| 316 | eap->method != EAP_TYPE_NONE) { |
| 317 | if (eap->vendor == EAP_VENDOR_IETF) { |
| 318 | if (eap->method == EAP_TYPE_SIM) |
| 319 | sim = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 320 | else if (eap->method == EAP_TYPE_AKA || |
| 321 | eap->method == EAP_TYPE_AKA_PRIME) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | aka = 1; |
| 323 | } |
| 324 | eap++; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) |
| 329 | sim = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 330 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL && |
| 331 | eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) == |
| 332 | NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 333 | aka = 0; |
| 334 | |
| 335 | if (!sim && !aka) { |
| 336 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
| 337 | "use SIM, but neither EAP-SIM nor EAP-AKA are " |
| 338 | "enabled"); |
| 339 | return 0; |
| 340 | } |
| 341 | |
| 342 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
| 343 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 344 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 345 | wpa_s->scard = scard_init(NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 346 | if (wpa_s->scard == NULL) { |
| 347 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
| 348 | "(pcsc-lite)"); |
| 349 | return -1; |
| 350 | } |
| 351 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); |
| 352 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 353 | #endif /* PCSC_FUNCS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | #endif /* IEEE8021X_EAPOL */ |
| 355 | |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | |
| 360 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 361 | |
| 362 | static int has_wep_key(struct wpa_ssid *ssid) |
| 363 | { |
| 364 | int i; |
| 365 | |
| 366 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 367 | if (ssid->wep_key_len[i]) |
| 368 | return 1; |
| 369 | } |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 375 | static int wpa_supplicant_match_privacy(struct wpa_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 376 | struct wpa_ssid *ssid) |
| 377 | { |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 378 | int privacy = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 379 | |
| 380 | if (ssid->mixed_cell) |
| 381 | return 1; |
| 382 | |
| 383 | #ifdef CONFIG_WPS |
| 384 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) |
| 385 | return 1; |
| 386 | #endif /* CONFIG_WPS */ |
| 387 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 388 | if (has_wep_key(ssid)) |
| 389 | privacy = 1; |
| 390 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 391 | #ifdef IEEE8021X_EAPOL |
| 392 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
| 393 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
| 394 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) |
| 395 | privacy = 1; |
| 396 | #endif /* IEEE8021X_EAPOL */ |
| 397 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 398 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 399 | privacy = 1; |
| 400 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 401 | if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) |
| 402 | privacy = 1; |
| 403 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 404 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
| 405 | return privacy; |
| 406 | return !privacy; |
| 407 | } |
| 408 | |
| 409 | |
| 410 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
| 411 | struct wpa_ssid *ssid, |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 412 | struct wpa_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 413 | { |
| 414 | struct wpa_ie_data ie; |
| 415 | int proto_match = 0; |
| 416 | const u8 *rsn_ie, *wpa_ie; |
| 417 | int ret; |
| 418 | int wep_ok; |
| 419 | |
| 420 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
| 421 | if (ret >= 0) |
| 422 | return ret; |
| 423 | |
| 424 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
| 425 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && |
| 426 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
| 427 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || |
| 428 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); |
| 429 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 430 | rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 431 | while ((ssid->proto & WPA_PROTO_RSN) && rsn_ie) { |
| 432 | proto_match++; |
| 433 | |
| 434 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { |
| 435 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - parse " |
| 436 | "failed"); |
| 437 | break; |
| 438 | } |
| 439 | |
| 440 | if (wep_ok && |
| 441 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) |
| 442 | { |
| 443 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
| 444 | "in RSN IE"); |
| 445 | return 1; |
| 446 | } |
| 447 | |
| 448 | if (!(ie.proto & ssid->proto)) { |
| 449 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - proto " |
| 450 | "mismatch"); |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { |
| 455 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - PTK " |
| 456 | "cipher mismatch"); |
| 457 | break; |
| 458 | } |
| 459 | |
| 460 | if (!(ie.group_cipher & ssid->group_cipher)) { |
| 461 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - GTK " |
| 462 | "cipher mismatch"); |
| 463 | break; |
| 464 | } |
| 465 | |
| 466 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
| 467 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - key mgmt " |
| 468 | "mismatch"); |
| 469 | break; |
| 470 | } |
| 471 | |
| 472 | #ifdef CONFIG_IEEE80211W |
| 473 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 474 | (ssid->ieee80211w == MGMT_FRAME_PROTECTION_DEFAULT ? |
| 475 | wpa_s->conf->pmf : ssid->ieee80211w) == |
| 476 | MGMT_FRAME_PROTECTION_REQUIRED) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 477 | wpa_dbg(wpa_s, MSG_DEBUG, " skip RSN IE - no mgmt " |
| 478 | "frame protection"); |
| 479 | break; |
| 480 | } |
| 481 | #endif /* CONFIG_IEEE80211W */ |
| 482 | |
| 483 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on RSN IE"); |
| 484 | return 1; |
| 485 | } |
| 486 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 487 | wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 488 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { |
| 489 | proto_match++; |
| 490 | |
| 491 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { |
| 492 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - parse " |
| 493 | "failed"); |
| 494 | break; |
| 495 | } |
| 496 | |
| 497 | if (wep_ok && |
| 498 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) |
| 499 | { |
| 500 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on TSN " |
| 501 | "in WPA IE"); |
| 502 | return 1; |
| 503 | } |
| 504 | |
| 505 | if (!(ie.proto & ssid->proto)) { |
| 506 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - proto " |
| 507 | "mismatch"); |
| 508 | break; |
| 509 | } |
| 510 | |
| 511 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { |
| 512 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - PTK " |
| 513 | "cipher mismatch"); |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | if (!(ie.group_cipher & ssid->group_cipher)) { |
| 518 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - GTK " |
| 519 | "cipher mismatch"); |
| 520 | break; |
| 521 | } |
| 522 | |
| 523 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
| 524 | wpa_dbg(wpa_s, MSG_DEBUG, " skip WPA IE - key mgmt " |
| 525 | "mismatch"); |
| 526 | break; |
| 527 | } |
| 528 | |
| 529 | wpa_dbg(wpa_s, MSG_DEBUG, " selected based on WPA IE"); |
| 530 | return 1; |
| 531 | } |
| 532 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 533 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && |
| 534 | !rsn_ie) { |
| 535 | wpa_dbg(wpa_s, MSG_DEBUG, " allow for non-WPA IEEE 802.1X"); |
| 536 | return 1; |
| 537 | } |
| 538 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 539 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
| 540 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
| 541 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no WPA/RSN proto match"); |
| 542 | return 0; |
| 543 | } |
| 544 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 545 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && |
| 546 | wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) { |
| 547 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN"); |
| 548 | return 1; |
| 549 | } |
| 550 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 551 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
| 552 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); |
| 553 | return 1; |
| 554 | } |
| 555 | |
| 556 | wpa_dbg(wpa_s, MSG_DEBUG, " reject due to mismatch with " |
| 557 | "WPA/WPA2"); |
| 558 | |
| 559 | return 0; |
| 560 | } |
| 561 | |
| 562 | |
| 563 | static int freq_allowed(int *freqs, int freq) |
| 564 | { |
| 565 | int i; |
| 566 | |
| 567 | if (freqs == NULL) |
| 568 | return 1; |
| 569 | |
| 570 | for (i = 0; freqs[i]; i++) |
| 571 | if (freqs[i] == freq) |
| 572 | return 1; |
| 573 | return 0; |
| 574 | } |
| 575 | |
| 576 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 577 | static int ht_supported(const struct hostapd_hw_modes *mode) |
| 578 | { |
| 579 | if (!(mode->flags & HOSTAPD_MODE_FLAG_HT_INFO_KNOWN)) { |
| 580 | /* |
| 581 | * The driver did not indicate whether it supports HT. Assume |
| 582 | * it does to avoid connection issues. |
| 583 | */ |
| 584 | return 1; |
| 585 | } |
| 586 | |
| 587 | /* |
| 588 | * IEEE Std 802.11n-2009 20.1.1: |
| 589 | * An HT non-AP STA shall support all EQM rates for one spatial stream. |
| 590 | */ |
| 591 | return mode->mcs_set[0] == 0xff; |
| 592 | } |
| 593 | |
| 594 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 595 | static int vht_supported(const struct hostapd_hw_modes *mode) |
| 596 | { |
| 597 | if (!(mode->flags & HOSTAPD_MODE_FLAG_VHT_INFO_KNOWN)) { |
| 598 | /* |
| 599 | * The driver did not indicate whether it supports VHT. Assume |
| 600 | * it does to avoid connection issues. |
| 601 | */ |
| 602 | return 1; |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * A VHT non-AP STA shall support MCS 0-7 for one spatial stream. |
| 607 | * TODO: Verify if this complies with the standard |
| 608 | */ |
| 609 | return (mode->vht_mcs_set[0] & 0x3) != 3; |
| 610 | } |
| 611 | |
| 612 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 613 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 614 | { |
| 615 | const struct hostapd_hw_modes *mode = NULL, *modes; |
| 616 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; |
| 617 | const u8 *rate_ie; |
| 618 | int i, j, k; |
| 619 | |
| 620 | if (bss->freq == 0) |
| 621 | return 1; /* Cannot do matching without knowing band */ |
| 622 | |
| 623 | modes = wpa_s->hw.modes; |
| 624 | if (modes == NULL) { |
| 625 | /* |
| 626 | * The driver does not provide any additional information |
| 627 | * about the utilized hardware, so allow the connection attempt |
| 628 | * to continue. |
| 629 | */ |
| 630 | return 1; |
| 631 | } |
| 632 | |
| 633 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 634 | for (j = 0; j < modes[i].num_channels; j++) { |
| 635 | int freq = modes[i].channels[j].freq; |
| 636 | if (freq == bss->freq) { |
| 637 | if (mode && |
| 638 | mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 639 | break; /* do not allow 802.11b replace |
| 640 | * 802.11g */ |
| 641 | mode = &modes[i]; |
| 642 | break; |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | |
| 647 | if (mode == NULL) |
| 648 | return 0; |
| 649 | |
| 650 | for (i = 0; i < (int) sizeof(scan_ie); i++) { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 651 | rate_ie = wpa_bss_get_ie(bss, scan_ie[i]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 652 | if (rate_ie == NULL) |
| 653 | continue; |
| 654 | |
| 655 | for (j = 2; j < rate_ie[1] + 2; j++) { |
| 656 | int flagged = !!(rate_ie[j] & 0x80); |
| 657 | int r = (rate_ie[j] & 0x7f) * 5; |
| 658 | |
| 659 | /* |
| 660 | * IEEE Std 802.11n-2009 7.3.2.2: |
| 661 | * The new BSS Membership selector value is encoded |
| 662 | * like a legacy basic rate, but it is not a rate and |
| 663 | * only indicates if the BSS members are required to |
| 664 | * support the mandatory features of Clause 20 [HT PHY] |
| 665 | * in order to join the BSS. |
| 666 | */ |
| 667 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 668 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { |
| 669 | if (!ht_supported(mode)) { |
| 670 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 671 | " hardware does not support " |
| 672 | "HT PHY"); |
| 673 | return 0; |
| 674 | } |
| 675 | continue; |
| 676 | } |
| 677 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 678 | /* There's also a VHT selector for 802.11ac */ |
| 679 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 680 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) { |
| 681 | if (!vht_supported(mode)) { |
| 682 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 683 | " hardware does not support " |
| 684 | "VHT PHY"); |
| 685 | return 0; |
| 686 | } |
| 687 | continue; |
| 688 | } |
| 689 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 690 | if (!flagged) |
| 691 | continue; |
| 692 | |
| 693 | /* check for legacy basic rates */ |
| 694 | for (k = 0; k < mode->num_rates; k++) { |
| 695 | if (mode->rates[k] == r) |
| 696 | break; |
| 697 | } |
| 698 | if (k == mode->num_rates) { |
| 699 | /* |
| 700 | * IEEE Std 802.11-2007 7.3.2.2 demands that in |
| 701 | * order to join a BSS all required rates |
| 702 | * have to be supported by the hardware. |
| 703 | */ |
| 704 | wpa_dbg(wpa_s, MSG_DEBUG, " hardware does " |
| 705 | "not support required rate %d.%d Mbps", |
| 706 | r / 10, r % 10); |
| 707 | return 0; |
| 708 | } |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | return 1; |
| 713 | } |
| 714 | |
| 715 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 716 | static int bss_is_dmg(struct wpa_bss *bss) |
| 717 | { |
| 718 | return bss->freq > 45000; |
| 719 | } |
| 720 | |
| 721 | |
| 722 | /* |
| 723 | * Test whether BSS is in an ESS. |
| 724 | * This is done differently in DMG (60 GHz) and non-DMG bands |
| 725 | */ |
| 726 | static int bss_is_ess(struct wpa_bss *bss) |
| 727 | { |
| 728 | if (bss_is_dmg(bss)) { |
| 729 | return (bss->caps & IEEE80211_CAP_DMG_MASK) == |
| 730 | IEEE80211_CAP_DMG_AP; |
| 731 | } |
| 732 | |
| 733 | return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == |
| 734 | IEEE80211_CAP_ESS); |
| 735 | } |
| 736 | |
| 737 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 738 | static struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 739 | int i, struct wpa_bss *bss, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 740 | struct wpa_ssid *group, |
| 741 | int only_first_ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 742 | { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 743 | u8 wpa_ie_len, rsn_ie_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 744 | int wpa; |
| 745 | struct wpa_blacklist *e; |
| 746 | const u8 *ie; |
| 747 | struct wpa_ssid *ssid; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 748 | int osen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 749 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 750 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 751 | wpa_ie_len = ie ? ie[1] : 0; |
| 752 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 753 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 754 | rsn_ie_len = ie ? ie[1] : 0; |
| 755 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 756 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 757 | osen = ie != NULL; |
| 758 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 759 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR " ssid='%s' " |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 760 | "wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d%s%s%s", |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 761 | i, MAC2STR(bss->bssid), wpa_ssid_txt(bss->ssid, bss->ssid_len), |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 762 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 763 | wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? " wps" : "", |
| 764 | (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
| 765 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) ? |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 766 | " p2p" : "", |
| 767 | osen ? " osen=1" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 768 | |
| 769 | e = wpa_blacklist_get(wpa_s, bss->bssid); |
| 770 | if (e) { |
| 771 | int limit = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 772 | if (wpa_supplicant_enabled_networks(wpa_s) == 1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 773 | /* |
| 774 | * When only a single network is enabled, we can |
| 775 | * trigger blacklisting on the first failure. This |
| 776 | * should not be done with multiple enabled networks to |
| 777 | * avoid getting forced to move into a worse ESS on |
| 778 | * single error if there are no other BSSes of the |
| 779 | * current ESS. |
| 780 | */ |
| 781 | limit = 0; |
| 782 | } |
| 783 | if (e->count > limit) { |
| 784 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
| 785 | "(count=%d limit=%d)", e->count, limit); |
| 786 | return NULL; |
| 787 | } |
| 788 | } |
| 789 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 790 | if (bss->ssid_len == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 791 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
| 792 | return NULL; |
| 793 | } |
| 794 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 795 | if (disallowed_bssid(wpa_s, bss->bssid)) { |
| 796 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed"); |
| 797 | return NULL; |
| 798 | } |
| 799 | |
| 800 | if (disallowed_ssid(wpa_s, bss->ssid, bss->ssid_len)) { |
| 801 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed"); |
| 802 | return NULL; |
| 803 | } |
| 804 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 805 | wpa = wpa_ie_len > 0 || rsn_ie_len > 0; |
| 806 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 807 | for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 808 | int check_ssid = wpa ? 1 : (ssid->ssid_len != 0); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 809 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 810 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 811 | if (wpas_network_disabled(wpa_s, ssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 812 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
| 813 | continue; |
| 814 | } |
| 815 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 816 | res = wpas_temp_disabled(wpa_s, ssid); |
| 817 | if (res > 0) { |
| 818 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled " |
| 819 | "temporarily for %d second(s)", res); |
| 820 | continue; |
| 821 | } |
| 822 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 823 | #ifdef CONFIG_WPS |
| 824 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && e && e->count > 0) { |
| 825 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - blacklisted " |
| 826 | "(WPS)"); |
| 827 | continue; |
| 828 | } |
| 829 | |
| 830 | if (wpa && ssid->ssid_len == 0 && |
| 831 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
| 832 | check_ssid = 0; |
| 833 | |
| 834 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 835 | /* Only allow wildcard SSID match if an AP |
| 836 | * advertises active WPS operation that matches |
| 837 | * with our mode. */ |
| 838 | check_ssid = 1; |
| 839 | if (ssid->ssid_len == 0 && |
| 840 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
| 841 | check_ssid = 0; |
| 842 | } |
| 843 | #endif /* CONFIG_WPS */ |
| 844 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 845 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
| 846 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) |
| 847 | check_ssid = 0; |
| 848 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 849 | if (check_ssid && |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 850 | (bss->ssid_len != ssid->ssid_len || |
| 851 | os_memcmp(bss->ssid, ssid->ssid, bss->ssid_len) != 0)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 852 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
| 853 | continue; |
| 854 | } |
| 855 | |
| 856 | if (ssid->bssid_set && |
| 857 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { |
| 858 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
| 859 | continue; |
| 860 | } |
| 861 | |
| 862 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss)) |
| 863 | continue; |
| 864 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 865 | if (!osen && !wpa && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 866 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
| 867 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && |
| 868 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { |
| 869 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-WPA network " |
| 870 | "not allowed"); |
| 871 | continue; |
| 872 | } |
| 873 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 874 | if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && |
| 875 | has_wep_key(ssid)) { |
| 876 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - ignore WPA/WPA2 AP for WEP network block"); |
| 877 | continue; |
| 878 | } |
| 879 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 880 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen) { |
| 881 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - non-OSEN network " |
| 882 | "not allowed"); |
| 883 | continue; |
| 884 | } |
| 885 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 886 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 887 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy " |
| 888 | "mismatch"); |
| 889 | continue; |
| 890 | } |
| 891 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 892 | if (!bss_is_ess(bss)) { |
| 893 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - not ESS network"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 894 | continue; |
| 895 | } |
| 896 | |
| 897 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
| 898 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - frequency not " |
| 899 | "allowed"); |
| 900 | continue; |
| 901 | } |
| 902 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 903 | if (!rate_match(wpa_s, bss)) { |
| 904 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - rate sets do " |
| 905 | "not match"); |
| 906 | continue; |
| 907 | } |
| 908 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 909 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 910 | if (ssid->p2p_group && |
| 911 | !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
| 912 | !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
| 913 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen"); |
| 914 | continue; |
| 915 | } |
| 916 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 917 | if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) { |
| 918 | struct wpabuf *p2p_ie; |
| 919 | u8 dev_addr[ETH_ALEN]; |
| 920 | |
| 921 | ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
| 922 | if (ie == NULL) { |
| 923 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P element"); |
| 924 | continue; |
| 925 | } |
| 926 | p2p_ie = wpa_bss_get_vendor_ie_multi( |
| 927 | bss, P2P_IE_VENDOR_TYPE); |
| 928 | if (p2p_ie == NULL) { |
| 929 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - could not fetch P2P element"); |
| 930 | continue; |
| 931 | } |
| 932 | |
| 933 | if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 |
| 934 | || os_memcmp(dev_addr, ssid->go_p2p_dev_addr, |
| 935 | ETH_ALEN) != 0) { |
| 936 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no matching GO P2P Device Address in P2P element"); |
| 937 | wpabuf_free(p2p_ie); |
| 938 | continue; |
| 939 | } |
| 940 | wpabuf_free(p2p_ie); |
| 941 | } |
| 942 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 943 | /* |
| 944 | * TODO: skip the AP if its P2P IE has Group Formation |
| 945 | * bit set in the P2P Group Capability Bitmap and we |
| 946 | * are not in Group Formation with that device. |
| 947 | */ |
| 948 | #endif /* CONFIG_P2P */ |
| 949 | |
| 950 | /* Matching configuration found */ |
| 951 | return ssid; |
| 952 | } |
| 953 | |
| 954 | /* No matching configuration found */ |
| 955 | return NULL; |
| 956 | } |
| 957 | |
| 958 | |
| 959 | static struct wpa_bss * |
| 960 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 961 | struct wpa_ssid *group, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 962 | struct wpa_ssid **selected_ssid, |
| 963 | int only_first_ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 964 | { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 965 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 966 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 967 | if (only_first_ssid) |
| 968 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d", |
| 969 | group->id); |
| 970 | else |
| 971 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", |
| 972 | group->priority); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 973 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 974 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 975 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 976 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
| 977 | only_first_ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 978 | if (!*selected_ssid) |
| 979 | continue; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 980 | wpa_dbg(wpa_s, MSG_DEBUG, " selected BSS " MACSTR |
| 981 | " ssid='%s'", |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 982 | MAC2STR(bss->bssid), |
| 983 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
| 984 | return bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | return NULL; |
| 988 | } |
| 989 | |
| 990 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 991 | struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
| 992 | struct wpa_ssid **selected_ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 993 | { |
| 994 | struct wpa_bss *selected = NULL; |
| 995 | int prio; |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 996 | struct wpa_ssid *next_ssid = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 997 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 998 | if (wpa_s->last_scan_res == NULL || |
| 999 | wpa_s->last_scan_res_used == 0) |
| 1000 | return NULL; /* no scan results from last update */ |
| 1001 | |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1002 | if (wpa_s->next_ssid) { |
| 1003 | struct wpa_ssid *ssid; |
| 1004 | |
| 1005 | /* check that next_ssid is still valid */ |
| 1006 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1007 | if (ssid == wpa_s->next_ssid) |
| 1008 | break; |
| 1009 | } |
| 1010 | next_ssid = ssid; |
| 1011 | wpa_s->next_ssid = NULL; |
| 1012 | } |
| 1013 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1014 | while (selected == NULL) { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1015 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { |
| 1016 | if (next_ssid && next_ssid->priority == |
| 1017 | wpa_s->conf->pssid[prio]->priority) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1018 | selected = wpa_supplicant_select_bss( |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1019 | wpa_s, next_ssid, selected_ssid, 1); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1020 | if (selected) |
| 1021 | break; |
| 1022 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1023 | selected = wpa_supplicant_select_bss( |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1024 | wpa_s, wpa_s->conf->pssid[prio], |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1025 | selected_ssid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1026 | if (selected) |
| 1027 | break; |
| 1028 | } |
| 1029 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1030 | if (selected == NULL && wpa_s->blacklist && |
| 1031 | !wpa_s->countermeasures) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1032 | wpa_dbg(wpa_s, MSG_DEBUG, "No APs found - clear " |
| 1033 | "blacklist and try again"); |
| 1034 | wpa_blacklist_clear(wpa_s); |
| 1035 | wpa_s->blacklist_cleared++; |
| 1036 | } else if (selected == NULL) |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | return selected; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, |
| 1045 | int timeout_sec, int timeout_usec) |
| 1046 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1047 | if (!wpa_supplicant_enabled_networks(wpa_s)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1048 | /* |
| 1049 | * No networks are enabled; short-circuit request so |
| 1050 | * we don't wait timeout seconds before transitioning |
| 1051 | * to INACTIVE state. |
| 1052 | */ |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 1053 | wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request " |
| 1054 | "since there are no enabled networks"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1055 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 1056 | return; |
| 1057 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1058 | |
| 1059 | wpa_s->scan_for_connection = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1060 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
| 1061 | } |
| 1062 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1063 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1064 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1065 | struct wpa_bss *selected, |
| 1066 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1067 | { |
| 1068 | if (wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { |
| 1069 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP |
| 1070 | "PBC session overlap"); |
| 1071 | #ifdef CONFIG_P2P |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 1072 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
| 1073 | wpa_s->p2p_in_provisioning) { |
| 1074 | eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, |
| 1075 | wpa_s, NULL); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1076 | return -1; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 1077 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1078 | #endif /* CONFIG_P2P */ |
| 1079 | |
| 1080 | #ifdef CONFIG_WPS |
| 1081 | wpas_wps_cancel(wpa_s); |
| 1082 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1083 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1086 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1087 | "Considering connect request: reassociate: %d selected: " |
| 1088 | MACSTR " bssid: " MACSTR " pending: " MACSTR |
| 1089 | " wpa_state: %s ssid=%p current_ssid=%p", |
| 1090 | wpa_s->reassociate, MAC2STR(selected->bssid), |
| 1091 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), |
| 1092 | wpa_supplicant_state_txt(wpa_s->wpa_state), |
| 1093 | ssid, wpa_s->current_ssid); |
| 1094 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1095 | /* |
| 1096 | * Do not trigger new association unless the BSSID has changed or if |
| 1097 | * reassociation is requested. If we are in process of associating with |
| 1098 | * the selected BSSID, do not trigger new attempt. |
| 1099 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1100 | if (wpa_s->reassociate || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1101 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && |
| 1102 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
| 1103 | wpa_s->wpa_state != WPA_AUTHENTICATING) || |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1104 | (!is_zero_ether_addr(wpa_s->pending_bssid) && |
| 1105 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != |
| 1106 | 0) || |
| 1107 | (is_zero_ether_addr(wpa_s->pending_bssid) && |
| 1108 | ssid != wpa_s->current_ssid)))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1109 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { |
| 1110 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1111 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1112 | } |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1113 | wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR, |
| 1114 | MAC2STR(selected->bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1115 | wpa_supplicant_associate(wpa_s, selected, ssid); |
| 1116 | } else { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1117 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to " |
| 1118 | "connect with the selected AP"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1119 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1120 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1121 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | |
| 1125 | static struct wpa_ssid * |
| 1126 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) |
| 1127 | { |
| 1128 | int prio; |
| 1129 | struct wpa_ssid *ssid; |
| 1130 | |
| 1131 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { |
| 1132 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) |
| 1133 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1134 | if (wpas_network_disabled(wpa_s, ssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1135 | continue; |
| 1136 | if (ssid->mode == IEEE80211_MODE_IBSS || |
| 1137 | ssid->mode == IEEE80211_MODE_AP) |
| 1138 | return ssid; |
| 1139 | } |
| 1140 | } |
| 1141 | return NULL; |
| 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
| 1146 | * on BSS added and BSS changed events */ |
| 1147 | static void wpa_supplicant_rsn_preauth_scan_results( |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1148 | struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1149 | { |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1150 | struct wpa_bss *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1151 | |
| 1152 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) |
| 1153 | return; |
| 1154 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1155 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1156 | const u8 *ssid, *rsn; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1157 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1158 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1159 | if (ssid == NULL) |
| 1160 | continue; |
| 1161 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1162 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1163 | if (rsn == NULL) |
| 1164 | continue; |
| 1165 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1166 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
| 1173 | struct wpa_bss *selected, |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1174 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1175 | { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1176 | struct wpa_bss *current_bss = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1177 | int min_diff; |
| 1178 | |
| 1179 | if (wpa_s->reassociate) |
| 1180 | return 1; /* explicit request to reassociate */ |
| 1181 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 1182 | return 1; /* we are not associated; continue */ |
| 1183 | if (wpa_s->current_ssid == NULL) |
| 1184 | return 1; /* unknown current SSID */ |
| 1185 | if (wpa_s->current_ssid != ssid) |
| 1186 | return 1; /* different network block */ |
| 1187 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1188 | if (wpas_driver_bss_selection(wpa_s)) |
| 1189 | return 0; /* Driver-based roaming */ |
| 1190 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1191 | if (wpa_s->current_ssid->ssid) |
| 1192 | current_bss = wpa_bss_get(wpa_s, wpa_s->bssid, |
| 1193 | wpa_s->current_ssid->ssid, |
| 1194 | wpa_s->current_ssid->ssid_len); |
| 1195 | if (!current_bss) |
| 1196 | current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1197 | |
| 1198 | if (!current_bss) |
| 1199 | return 1; /* current BSS not seen in scan results */ |
| 1200 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1201 | if (current_bss == selected) |
| 1202 | return 0; |
| 1203 | |
| 1204 | if (selected->last_update_idx > current_bss->last_update_idx) |
| 1205 | return 1; /* current BSS not seen in the last scan */ |
| 1206 | |
Dmitry Shmidt | 9e07767 | 2012-04-13 10:07:27 -0700 | [diff] [blame] | 1207 | #ifndef CONFIG_NO_ROAMING |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1208 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
| 1209 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR " level=%d", |
| 1210 | MAC2STR(current_bss->bssid), current_bss->level); |
| 1211 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR " level=%d", |
| 1212 | MAC2STR(selected->bssid), selected->level); |
| 1213 | |
| 1214 | if (wpa_s->current_ssid->bssid_set && |
| 1215 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == |
| 1216 | 0) { |
| 1217 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
| 1218 | "has preferred BSSID"); |
| 1219 | return 1; |
| 1220 | } |
| 1221 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1222 | if (current_bss->level < 0 && current_bss->level > selected->level) { |
| 1223 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " |
| 1224 | "signal level"); |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1228 | min_diff = 2; |
| 1229 | if (current_bss->level < 0) { |
| 1230 | if (current_bss->level < -85) |
| 1231 | min_diff = 1; |
| 1232 | else if (current_bss->level < -80) |
| 1233 | min_diff = 2; |
| 1234 | else if (current_bss->level < -75) |
| 1235 | min_diff = 3; |
| 1236 | else if (current_bss->level < -70) |
| 1237 | min_diff = 4; |
| 1238 | else |
| 1239 | min_diff = 5; |
| 1240 | } |
| 1241 | if (abs(current_bss->level - selected->level) < min_diff) { |
| 1242 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - too small difference " |
| 1243 | "in signal level"); |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
| 1247 | return 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1248 | #else /* CONFIG_NO_ROAMING */ |
Dmitry Shmidt | efdec2e | 2011-08-16 11:55:46 -0700 | [diff] [blame] | 1249 | return 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1250 | #endif /* CONFIG_NO_ROAMING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1253 | |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 1254 | /* Return != 0 if no scan results could be fetched or if scan results should not |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1255 | * be shared with other virtual interfaces. */ |
Dmitry Shmidt | f6c92c4 | 2012-01-26 12:57:43 -0800 | [diff] [blame] | 1256 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 1257 | union wpa_event_data *data, |
| 1258 | int own_request) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1259 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1260 | struct wpa_scan_results *scan_res = NULL; |
| 1261 | int ret = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1262 | int ap = 0; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 1263 | #ifndef CONFIG_NO_RANDOM_POOL |
| 1264 | size_t i, num; |
| 1265 | #endif /* CONFIG_NO_RANDOM_POOL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1266 | |
| 1267 | #ifdef CONFIG_AP |
| 1268 | if (wpa_s->ap_iface) |
| 1269 | ap = 1; |
| 1270 | #endif /* CONFIG_AP */ |
| 1271 | |
| 1272 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 1273 | |
| 1274 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
| 1275 | data ? &data->scan_info : |
| 1276 | NULL, 1); |
| 1277 | if (scan_res == NULL) { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1278 | if (wpa_s->conf->ap_scan == 2 || ap || |
| 1279 | wpa_s->scan_res_handler == scan_only_handler) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1280 | return -1; |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 1281 | if (!own_request) |
| 1282 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1283 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results - try " |
| 1284 | "scanning again"); |
| 1285 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1286 | ret = -1; |
| 1287 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | #ifndef CONFIG_NO_RANDOM_POOL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1291 | num = scan_res->num; |
| 1292 | if (num > 10) |
| 1293 | num = 10; |
| 1294 | for (i = 0; i < num; i++) { |
| 1295 | u8 buf[5]; |
| 1296 | struct wpa_scan_res *res = scan_res->res[i]; |
| 1297 | buf[0] = res->bssid[5]; |
| 1298 | buf[1] = res->qual & 0xff; |
| 1299 | buf[2] = res->noise & 0xff; |
| 1300 | buf[3] = res->level & 0xff; |
| 1301 | buf[4] = res->tsf & 0xff; |
| 1302 | random_add_randomness(buf, sizeof(buf)); |
| 1303 | } |
| 1304 | #endif /* CONFIG_NO_RANDOM_POOL */ |
| 1305 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1306 | if (own_request && wpa_s->scan_res_handler && |
| 1307 | (wpa_s->own_scan_running || !wpa_s->external_scan_running)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1308 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
| 1309 | struct wpa_scan_results *scan_res); |
| 1310 | |
| 1311 | scan_res_handler = wpa_s->scan_res_handler; |
| 1312 | wpa_s->scan_res_handler = NULL; |
| 1313 | scan_res_handler(wpa_s, scan_res); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1314 | ret = -2; |
| 1315 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | if (ap) { |
| 1319 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
| 1320 | #ifdef CONFIG_AP |
| 1321 | if (wpa_s->ap_iface->scan_cb) |
| 1322 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); |
| 1323 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1324 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1325 | } |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 1326 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1327 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)", |
| 1328 | wpa_s->own_scan_running, wpa_s->external_scan_running); |
| 1329 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 1330 | wpa_s->manual_scan_use_id && wpa_s->own_scan_running) { |
| 1331 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u", |
| 1332 | wpa_s->manual_scan_id); |
| 1333 | wpa_s->manual_scan_use_id = 0; |
| 1334 | } else { |
| 1335 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); |
| 1336 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1337 | wpas_notify_scan_results(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1338 | |
| 1339 | wpas_notify_scan_done(wpa_s, 1); |
| 1340 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1341 | if (!wpa_s->own_scan_running && wpa_s->external_scan_running) { |
| 1342 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1343 | wpa_scan_results_free(scan_res); |
| 1344 | return 0; |
| 1345 | } |
| 1346 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1347 | if (sme_proc_obss_scan(wpa_s) > 0) |
| 1348 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1349 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1350 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) |
| 1351 | goto scan_work_done; |
| 1352 | |
| 1353 | if (autoscan_notify_scan(wpa_s, scan_res)) |
| 1354 | goto scan_work_done; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1356 | if (wpa_s->disconnected) { |
| 1357 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1358 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1361 | if (!wpas_driver_bss_selection(wpa_s) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1362 | bgscan_notify_scan(wpa_s, scan_res) == 1) |
| 1363 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1364 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1365 | wpas_wps_update_ap_info(wpa_s, scan_res); |
| 1366 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1367 | wpa_scan_results_free(scan_res); |
| 1368 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1369 | if (wpa_s->scan_work) { |
| 1370 | struct wpa_radio_work *work = wpa_s->scan_work; |
| 1371 | wpa_s->scan_work = NULL; |
| 1372 | radio_work_done(work); |
| 1373 | } |
| 1374 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1375 | return wpas_select_network_from_last_scan(wpa_s, 1, own_request); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1376 | |
| 1377 | scan_work_done: |
| 1378 | wpa_scan_results_free(scan_res); |
| 1379 | if (wpa_s->scan_work) { |
| 1380 | struct wpa_radio_work *work = wpa_s->scan_work; |
| 1381 | wpa_s->scan_work = NULL; |
| 1382 | radio_work_done(work); |
| 1383 | } |
| 1384 | return ret; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1388 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1389 | int new_scan, int own_request) |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1390 | { |
| 1391 | struct wpa_bss *selected; |
| 1392 | struct wpa_ssid *ssid = NULL; |
| 1393 | |
| 1394 | selected = wpa_supplicant_pick_network(wpa_s, &ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1395 | |
| 1396 | if (selected) { |
| 1397 | int skip; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1398 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1399 | if (skip) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1400 | if (new_scan) |
| 1401 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1402 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1403 | } |
| 1404 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1405 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1406 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1407 | return -1; |
| 1408 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1409 | if (new_scan) |
| 1410 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 1411 | /* |
| 1412 | * Do not notify other virtual radios of scan results since we do not |
| 1413 | * want them to start other associations at the same time. |
| 1414 | */ |
| 1415 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1416 | } else { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1417 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
| 1418 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
| 1419 | if (ssid) { |
| 1420 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
| 1421 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1422 | if (new_scan) |
| 1423 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1424 | } else if (own_request) { |
| 1425 | /* |
| 1426 | * No SSID found. If SCAN results are as a result of |
| 1427 | * own scan request and not due to a scan request on |
| 1428 | * another shared interface, try another scan. |
| 1429 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1430 | int timeout_sec = wpa_s->scan_interval; |
| 1431 | int timeout_usec = 0; |
| 1432 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1433 | if (wpas_p2p_scan_no_go_seen(wpa_s) == 1) |
| 1434 | return 0; |
| 1435 | |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 1436 | if (wpa_s->p2p_in_provisioning || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1437 | wpa_s->show_group_started || |
| 1438 | wpa_s->p2p_in_invitation) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1439 | /* |
| 1440 | * Use shorter wait during P2P Provisioning |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 1441 | * state and during P2P join-a-group operation |
| 1442 | * to speed up group formation. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1443 | */ |
| 1444 | timeout_sec = 0; |
| 1445 | timeout_usec = 250000; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1446 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 1447 | timeout_usec); |
| 1448 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1449 | } |
| 1450 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1451 | #ifdef CONFIG_INTERWORKING |
| 1452 | if (wpa_s->conf->auto_interworking && |
| 1453 | wpa_s->conf->interworking && |
| 1454 | wpa_s->conf->cred) { |
| 1455 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " |
| 1456 | "start ANQP fetch since no matching " |
| 1457 | "networks found"); |
| 1458 | wpa_s->network_select = 1; |
| 1459 | wpa_s->auto_network_select = 1; |
| 1460 | interworking_start_fetch_anqp(wpa_s); |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 1461 | return 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1462 | } |
| 1463 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1464 | #ifdef CONFIG_WPS |
| 1465 | if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) { |
| 1466 | wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing"); |
| 1467 | timeout_sec = 0; |
| 1468 | timeout_usec = 500000; |
| 1469 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 1470 | timeout_usec); |
| 1471 | return 0; |
| 1472 | } |
| 1473 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1474 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
| 1475 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 1476 | timeout_usec); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1477 | } |
| 1478 | } |
| 1479 | return 0; |
| 1480 | } |
| 1481 | |
| 1482 | |
| 1483 | static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
| 1484 | union wpa_event_data *data) |
| 1485 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1486 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 1487 | |
| 1488 | if (_wpa_supplicant_event_scan_results(wpa_s, data, 1) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1489 | /* |
| 1490 | * If no scan results could be fetched, then no need to |
| 1491 | * notify those interfaces that did not actually request |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 1492 | * this scan. Similarly, if scan results started a new operation on this |
| 1493 | * interface, do not notify other interfaces to avoid concurrent |
| 1494 | * operations during a connection attempt. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1495 | */ |
| 1496 | return; |
| 1497 | } |
| 1498 | |
| 1499 | /* |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 1500 | * Check other interfaces to see if they share the same radio. If |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1501 | * so, they get updated with this same scan info. |
| 1502 | */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 1503 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 1504 | radio_list) { |
| 1505 | if (ifs != wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1506 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " |
| 1507 | "sibling", ifs->ifname); |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 1508 | _wpa_supplicant_event_scan_results(ifs, data, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1509 | } |
| 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 1514 | |
| 1515 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1516 | int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
| 1517 | { |
| 1518 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 1519 | return -1; |
| 1520 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1521 | struct os_reltime now; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1522 | |
| 1523 | if (wpa_s->last_scan_res_used <= 0) |
| 1524 | return -1; |
| 1525 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1526 | os_get_reltime(&now); |
| 1527 | if (os_reltime_expired(&now, &wpa_s->last_scan, 5)) { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1528 | wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); |
| 1529 | return -1; |
| 1530 | } |
| 1531 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1532 | return wpas_select_network_from_last_scan(wpa_s, 0, 1); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1533 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 1534 | } |
| 1535 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1536 | #ifdef CONFIG_WNM |
| 1537 | |
| 1538 | static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) |
| 1539 | { |
| 1540 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1541 | |
| 1542 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 1543 | return; |
| 1544 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1545 | if (!wpa_s->no_keep_alive) { |
| 1546 | wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, |
| 1547 | MAC2STR(wpa_s->bssid)); |
| 1548 | /* TODO: could skip this if normal data traffic has been sent */ |
| 1549 | /* TODO: Consider using some more appropriate data frame for |
| 1550 | * this */ |
| 1551 | if (wpa_s->l2) |
| 1552 | l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, |
| 1553 | (u8 *) "", 0); |
| 1554 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1555 | |
| 1556 | #ifdef CONFIG_SME |
| 1557 | if (wpa_s->sme.bss_max_idle_period) { |
| 1558 | unsigned int msec; |
| 1559 | msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ |
| 1560 | if (msec > 100) |
| 1561 | msec -= 100; |
| 1562 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, |
| 1563 | wnm_bss_keep_alive, wpa_s, NULL); |
| 1564 | } |
| 1565 | #endif /* CONFIG_SME */ |
| 1566 | } |
| 1567 | |
| 1568 | |
| 1569 | static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 1570 | const u8 *ies, size_t ies_len) |
| 1571 | { |
| 1572 | struct ieee802_11_elems elems; |
| 1573 | |
| 1574 | if (ies == NULL) |
| 1575 | return; |
| 1576 | |
| 1577 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) |
| 1578 | return; |
| 1579 | |
| 1580 | #ifdef CONFIG_SME |
| 1581 | if (elems.bss_max_idle_period) { |
| 1582 | unsigned int msec; |
| 1583 | wpa_s->sme.bss_max_idle_period = |
| 1584 | WPA_GET_LE16(elems.bss_max_idle_period); |
| 1585 | wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " |
| 1586 | "TU)%s", wpa_s->sme.bss_max_idle_period, |
| 1587 | (elems.bss_max_idle_period[2] & 0x01) ? |
| 1588 | " (protected keep-live required)" : ""); |
| 1589 | if (wpa_s->sme.bss_max_idle_period == 0) |
| 1590 | wpa_s->sme.bss_max_idle_period = 1; |
| 1591 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { |
| 1592 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); |
| 1593 | /* msec times 1000 */ |
| 1594 | msec = wpa_s->sme.bss_max_idle_period * 1024; |
| 1595 | if (msec > 100) |
| 1596 | msec -= 100; |
| 1597 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, |
| 1598 | wnm_bss_keep_alive, wpa_s, |
| 1599 | NULL); |
| 1600 | } |
| 1601 | } |
| 1602 | #endif /* CONFIG_SME */ |
| 1603 | } |
| 1604 | |
| 1605 | #endif /* CONFIG_WNM */ |
| 1606 | |
| 1607 | |
| 1608 | void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) |
| 1609 | { |
| 1610 | #ifdef CONFIG_WNM |
| 1611 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); |
| 1612 | #endif /* CONFIG_WNM */ |
| 1613 | } |
| 1614 | |
| 1615 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1616 | #ifdef CONFIG_INTERWORKING |
| 1617 | |
| 1618 | static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map, |
| 1619 | size_t len) |
| 1620 | { |
| 1621 | int res; |
| 1622 | |
| 1623 | wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len); |
| 1624 | res = wpa_drv_set_qos_map(wpa_s, qos_map, len); |
| 1625 | if (res) { |
| 1626 | wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver"); |
| 1627 | } |
| 1628 | |
| 1629 | return res; |
| 1630 | } |
| 1631 | |
| 1632 | |
| 1633 | static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 1634 | const u8 *ies, size_t ies_len) |
| 1635 | { |
| 1636 | struct ieee802_11_elems elems; |
| 1637 | |
| 1638 | if (ies == NULL) |
| 1639 | return; |
| 1640 | |
| 1641 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) |
| 1642 | return; |
| 1643 | |
| 1644 | if (elems.qos_map_set) { |
| 1645 | wpas_qos_map_set(wpa_s, elems.qos_map_set, |
| 1646 | elems.qos_map_set_len); |
| 1647 | } |
| 1648 | } |
| 1649 | |
| 1650 | #endif /* CONFIG_INTERWORKING */ |
| 1651 | |
| 1652 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1653 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
| 1654 | union wpa_event_data *data) |
| 1655 | { |
| 1656 | int l, len, found = 0, wpa_found, rsn_found; |
| 1657 | const u8 *p; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 1658 | #ifdef CONFIG_IEEE80211R |
| 1659 | u8 bssid[ETH_ALEN]; |
| 1660 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1661 | |
| 1662 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
| 1663 | if (data->assoc_info.req_ies) |
| 1664 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, |
| 1665 | data->assoc_info.req_ies_len); |
| 1666 | if (data->assoc_info.resp_ies) { |
| 1667 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
| 1668 | data->assoc_info.resp_ies_len); |
| 1669 | #ifdef CONFIG_TDLS |
| 1670 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, |
| 1671 | data->assoc_info.resp_ies_len); |
| 1672 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1673 | #ifdef CONFIG_WNM |
| 1674 | wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 1675 | data->assoc_info.resp_ies_len); |
| 1676 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1677 | #ifdef CONFIG_INTERWORKING |
| 1678 | interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 1679 | data->assoc_info.resp_ies_len); |
| 1680 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1681 | } |
| 1682 | if (data->assoc_info.beacon_ies) |
| 1683 | wpa_hexdump(MSG_DEBUG, "beacon_ies", |
| 1684 | data->assoc_info.beacon_ies, |
| 1685 | data->assoc_info.beacon_ies_len); |
| 1686 | if (data->assoc_info.freq) |
| 1687 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
| 1688 | data->assoc_info.freq); |
| 1689 | |
| 1690 | p = data->assoc_info.req_ies; |
| 1691 | l = data->assoc_info.req_ies_len; |
| 1692 | |
| 1693 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ |
| 1694 | while (p && l >= 2) { |
| 1695 | len = p[1] + 2; |
| 1696 | if (len > l) { |
| 1697 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 1698 | p, l); |
| 1699 | break; |
| 1700 | } |
| 1701 | if ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 1702 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || |
| 1703 | (p[0] == WLAN_EID_RSN && p[1] >= 2)) { |
| 1704 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) |
| 1705 | break; |
| 1706 | found = 1; |
| 1707 | wpa_find_assoc_pmkid(wpa_s); |
| 1708 | break; |
| 1709 | } |
| 1710 | l -= len; |
| 1711 | p += len; |
| 1712 | } |
| 1713 | if (!found && data->assoc_info.req_ies) |
| 1714 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
| 1715 | |
| 1716 | #ifdef CONFIG_IEEE80211R |
| 1717 | #ifdef CONFIG_SME |
| 1718 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1719 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || |
| 1720 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, |
| 1721 | data->assoc_info.resp_ies, |
| 1722 | data->assoc_info.resp_ies_len, |
| 1723 | bssid) < 0) { |
| 1724 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
| 1725 | "Reassociation Response failed"); |
| 1726 | wpa_supplicant_deauthenticate( |
| 1727 | wpa_s, WLAN_REASON_INVALID_IE); |
| 1728 | return -1; |
| 1729 | } |
| 1730 | } |
| 1731 | |
| 1732 | p = data->assoc_info.resp_ies; |
| 1733 | l = data->assoc_info.resp_ies_len; |
| 1734 | |
| 1735 | #ifdef CONFIG_WPS_STRICT |
| 1736 | if (p && wpa_s->current_ssid && |
| 1737 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
| 1738 | struct wpabuf *wps; |
| 1739 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); |
| 1740 | if (wps == NULL) { |
| 1741 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
| 1742 | "include WPS IE in (Re)Association Response"); |
| 1743 | return -1; |
| 1744 | } |
| 1745 | |
| 1746 | if (wps_validate_assoc_resp(wps) < 0) { |
| 1747 | wpabuf_free(wps); |
| 1748 | wpa_supplicant_deauthenticate( |
| 1749 | wpa_s, WLAN_REASON_INVALID_IE); |
| 1750 | return -1; |
| 1751 | } |
| 1752 | wpabuf_free(wps); |
| 1753 | } |
| 1754 | #endif /* CONFIG_WPS_STRICT */ |
| 1755 | |
| 1756 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
| 1757 | while (p && l >= 2) { |
| 1758 | len = p[1] + 2; |
| 1759 | if (len > l) { |
| 1760 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 1761 | p, l); |
| 1762 | break; |
| 1763 | } |
| 1764 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
| 1765 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { |
| 1766 | wpa_s->sme.ft_used = 1; |
| 1767 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, |
| 1768 | MOBILITY_DOMAIN_ID_LEN); |
| 1769 | break; |
| 1770 | } |
| 1771 | l -= len; |
| 1772 | p += len; |
| 1773 | } |
| 1774 | #endif /* CONFIG_SME */ |
| 1775 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 1776 | /* Process FT when SME is in the driver */ |
| 1777 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 1778 | wpa_ft_is_completed(wpa_s->wpa)) { |
| 1779 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0 || |
| 1780 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, |
| 1781 | data->assoc_info.resp_ies, |
| 1782 | data->assoc_info.resp_ies_len, |
| 1783 | bssid) < 0) { |
| 1784 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
| 1785 | "Reassociation Response failed"); |
| 1786 | wpa_supplicant_deauthenticate( |
| 1787 | wpa_s, WLAN_REASON_INVALID_IE); |
| 1788 | return -1; |
| 1789 | } |
| 1790 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done"); |
| 1791 | } |
| 1792 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1793 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
| 1794 | data->assoc_info.resp_ies_len); |
| 1795 | #endif /* CONFIG_IEEE80211R */ |
| 1796 | |
| 1797 | /* WPA/RSN IE from Beacon/ProbeResp */ |
| 1798 | p = data->assoc_info.beacon_ies; |
| 1799 | l = data->assoc_info.beacon_ies_len; |
| 1800 | |
| 1801 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. |
| 1802 | */ |
| 1803 | wpa_found = rsn_found = 0; |
| 1804 | while (p && l >= 2) { |
| 1805 | len = p[1] + 2; |
| 1806 | if (len > l) { |
| 1807 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", |
| 1808 | p, l); |
| 1809 | break; |
| 1810 | } |
| 1811 | if (!wpa_found && |
| 1812 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 1813 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { |
| 1814 | wpa_found = 1; |
| 1815 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); |
| 1816 | } |
| 1817 | |
| 1818 | if (!rsn_found && |
| 1819 | p[0] == WLAN_EID_RSN && p[1] >= 2) { |
| 1820 | rsn_found = 1; |
| 1821 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); |
| 1822 | } |
| 1823 | |
| 1824 | l -= len; |
| 1825 | p += len; |
| 1826 | } |
| 1827 | |
| 1828 | if (!wpa_found && data->assoc_info.beacon_ies) |
| 1829 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); |
| 1830 | if (!rsn_found && data->assoc_info.beacon_ies) |
| 1831 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); |
| 1832 | if (wpa_found || rsn_found) |
| 1833 | wpa_s->ap_ies_from_associnfo = 1; |
| 1834 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1835 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
| 1836 | wpa_s->assoc_freq != data->assoc_info.freq) { |
| 1837 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " |
| 1838 | "%u to %u MHz", |
| 1839 | wpa_s->assoc_freq, data->assoc_info.freq); |
| 1840 | wpa_supplicant_update_scan_results(wpa_s); |
| 1841 | } |
| 1842 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1843 | wpa_s->assoc_freq = data->assoc_info.freq; |
| 1844 | |
| 1845 | return 0; |
| 1846 | } |
| 1847 | |
| 1848 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1849 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) |
| 1850 | { |
| 1851 | const u8 *bss_wpa = NULL, *bss_rsn = NULL; |
| 1852 | |
| 1853 | if (!wpa_s->current_bss || !wpa_s->current_ssid) |
| 1854 | return -1; |
| 1855 | |
| 1856 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) |
| 1857 | return 0; |
| 1858 | |
| 1859 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
| 1860 | WPA_IE_VENDOR_TYPE); |
| 1861 | bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); |
| 1862 | |
| 1863 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, |
| 1864 | bss_wpa ? 2 + bss_wpa[1] : 0) || |
| 1865 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, |
| 1866 | bss_rsn ? 2 + bss_rsn[1] : 0)) |
| 1867 | return -1; |
| 1868 | |
| 1869 | return 0; |
| 1870 | } |
| 1871 | |
| 1872 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1873 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, |
| 1874 | union wpa_event_data *data) |
| 1875 | { |
| 1876 | u8 bssid[ETH_ALEN]; |
| 1877 | int ft_completed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1878 | |
| 1879 | #ifdef CONFIG_AP |
| 1880 | if (wpa_s->ap_iface) { |
| 1881 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], |
| 1882 | data->assoc_info.addr, |
| 1883 | data->assoc_info.req_ies, |
| 1884 | data->assoc_info.req_ies_len, |
| 1885 | data->assoc_info.reassoc); |
| 1886 | return; |
| 1887 | } |
| 1888 | #endif /* CONFIG_AP */ |
| 1889 | |
| 1890 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); |
| 1891 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
| 1892 | return; |
| 1893 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1894 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 1895 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1896 | wpa_supplicant_deauthenticate( |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1897 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 1898 | return; |
| 1899 | } |
| 1900 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1901 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1902 | if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1903 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
| 1904 | MACSTR, MAC2STR(bssid)); |
| 1905 | random_add_randomness(bssid, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1906 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
| 1907 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1908 | wpas_notify_bssid_changed(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1909 | |
| 1910 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
| 1911 | wpa_clear_keys(wpa_s, bssid); |
| 1912 | } |
| 1913 | if (wpa_supplicant_select_config(wpa_s) < 0) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1914 | wpa_supplicant_deauthenticate( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1915 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 1916 | return; |
| 1917 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1918 | |
Dmitry Shmidt | 1e1c48d | 2013-02-14 16:44:44 -0800 | [diff] [blame] | 1919 | #ifdef ANDROID |
| 1920 | if (wpa_s->conf->ap_scan == 1) { |
| 1921 | #else |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1922 | if (wpa_s->conf->ap_scan == 1 && |
| 1923 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { |
Dmitry Shmidt | 1e1c48d | 2013-02-14 16:44:44 -0800 | [diff] [blame] | 1924 | #endif |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1925 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0) |
| 1926 | wpa_msg(wpa_s, MSG_WARNING, |
| 1927 | "WPA/RSN IEs not updated"); |
| 1928 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | #ifdef CONFIG_SME |
| 1932 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); |
| 1933 | wpa_s->sme.prev_bssid_set = 1; |
| 1934 | #endif /* CONFIG_SME */ |
| 1935 | |
| 1936 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
| 1937 | if (wpa_s->current_ssid) { |
| 1938 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be |
| 1939 | * initialized before association, but for other modes, |
| 1940 | * initialize PC/SC here, if the current configuration needs |
| 1941 | * smartcard or SIM/USIM. */ |
| 1942 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); |
| 1943 | } |
| 1944 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); |
| 1945 | if (wpa_s->l2) |
| 1946 | l2_packet_notify_auth_start(wpa_s->l2); |
| 1947 | |
| 1948 | /* |
| 1949 | * Set portEnabled first to FALSE in order to get EAP state machine out |
| 1950 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE |
| 1951 | * state machine may transit to AUTHENTICATING state based on obsolete |
| 1952 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to |
| 1953 | * AUTHENTICATED without ever giving chance to EAP state machine to |
| 1954 | * reset the state. |
| 1955 | */ |
| 1956 | if (!ft_completed) { |
| 1957 | eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); |
| 1958 | eapol_sm_notify_portValid(wpa_s->eapol, FALSE); |
| 1959 | } |
| 1960 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || ft_completed) |
| 1961 | eapol_sm_notify_eap_success(wpa_s->eapol, FALSE); |
| 1962 | /* 802.1X::portControl = Auto */ |
| 1963 | eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE); |
| 1964 | wpa_s->eapol_received = 0; |
| 1965 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 1966 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
| 1967 | (wpa_s->current_ssid && |
| 1968 | wpa_s->current_ssid->mode == IEEE80211_MODE_IBSS)) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 1969 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE && |
| 1970 | (wpa_s->drv_flags & |
| 1971 | WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { |
| 1972 | /* |
| 1973 | * Set the key after having received joined-IBSS event |
| 1974 | * from the driver. |
| 1975 | */ |
| 1976 | wpa_supplicant_set_wpa_none_key(wpa_s, |
| 1977 | wpa_s->current_ssid); |
| 1978 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1979 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 1980 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 1981 | } else if (!ft_completed) { |
| 1982 | /* Timeout for receiving the first EAPOL packet */ |
| 1983 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); |
| 1984 | } |
| 1985 | wpa_supplicant_cancel_scan(wpa_s); |
| 1986 | |
| 1987 | if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
| 1988 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
| 1989 | /* |
| 1990 | * We are done; the driver will take care of RSN 4-way |
| 1991 | * handshake. |
| 1992 | */ |
| 1993 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 1994 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 1995 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); |
| 1996 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); |
| 1997 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) && |
| 1998 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
| 1999 | /* |
| 2000 | * The driver will take care of RSN 4-way handshake, so we need |
| 2001 | * to allow EAPOL supplicant to complete its work without |
| 2002 | * waiting for WPA supplicant. |
| 2003 | */ |
| 2004 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); |
| 2005 | } else if (ft_completed) { |
| 2006 | /* |
| 2007 | * FT protocol completed - make sure EAPOL state machine ends |
| 2008 | * up in authenticated. |
| 2009 | */ |
| 2010 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 2011 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 2012 | eapol_sm_notify_portValid(wpa_s->eapol, TRUE); |
| 2013 | eapol_sm_notify_eap_success(wpa_s->eapol, TRUE); |
| 2014 | } |
| 2015 | |
Jouni Malinen | a05074c | 2012-12-21 21:35:35 +0200 | [diff] [blame] | 2016 | wpa_s->last_eapol_matches_bssid = 0; |
| 2017 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2018 | if (wpa_s->pending_eapol_rx) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2019 | struct os_reltime now, age; |
| 2020 | os_get_reltime(&now); |
| 2021 | os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2022 | if (age.sec == 0 && age.usec < 100000 && |
| 2023 | os_memcmp(wpa_s->pending_eapol_rx_src, bssid, ETH_ALEN) == |
| 2024 | 0) { |
| 2025 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
| 2026 | "frame that was received just before " |
| 2027 | "association notification"); |
| 2028 | wpa_supplicant_rx_eapol( |
| 2029 | wpa_s, wpa_s->pending_eapol_rx_src, |
| 2030 | wpabuf_head(wpa_s->pending_eapol_rx), |
| 2031 | wpabuf_len(wpa_s->pending_eapol_rx)); |
| 2032 | } |
| 2033 | wpabuf_free(wpa_s->pending_eapol_rx); |
| 2034 | wpa_s->pending_eapol_rx = NULL; |
| 2035 | } |
| 2036 | |
| 2037 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 2038 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 2039 | wpa_s->current_ssid && |
| 2040 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2041 | /* Set static WEP keys again */ |
| 2042 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); |
| 2043 | } |
| 2044 | |
| 2045 | #ifdef CONFIG_IBSS_RSN |
| 2046 | if (wpa_s->current_ssid && |
| 2047 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && |
| 2048 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
| 2049 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
| 2050 | wpa_s->ibss_rsn == NULL) { |
| 2051 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s); |
| 2052 | if (!wpa_s->ibss_rsn) { |
| 2053 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); |
| 2054 | wpa_supplicant_deauthenticate( |
| 2055 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2056 | return; |
| 2057 | } |
| 2058 | |
| 2059 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); |
| 2060 | } |
| 2061 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2062 | |
| 2063 | wpas_wps_notify_assoc(wpa_s, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2067 | static int disconnect_reason_recoverable(u16 reason_code) |
| 2068 | { |
| 2069 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || |
| 2070 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || |
| 2071 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; |
| 2072 | } |
| 2073 | |
| 2074 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2075 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2076 | u16 reason_code, |
| 2077 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2078 | { |
| 2079 | const u8 *bssid; |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 2080 | |
| 2081 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 2082 | /* |
| 2083 | * At least Host AP driver and a Prism3 card seemed to be |
| 2084 | * generating streams of disconnected events when configuring |
| 2085 | * IBSS for WPA-None. Ignore them for now. |
| 2086 | */ |
| 2087 | return; |
| 2088 | } |
| 2089 | |
| 2090 | bssid = wpa_s->bssid; |
| 2091 | if (is_zero_ether_addr(bssid)) |
| 2092 | bssid = wpa_s->pending_bssid; |
| 2093 | |
| 2094 | if (!is_zero_ether_addr(bssid) || |
| 2095 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 2096 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
| 2097 | " reason=%d%s", |
| 2098 | MAC2STR(bssid), reason_code, |
| 2099 | locally_generated ? " locally_generated=1" : ""); |
| 2100 | } |
| 2101 | } |
| 2102 | |
| 2103 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2104 | static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code, |
| 2105 | int locally_generated) |
| 2106 | { |
| 2107 | if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE || |
| 2108 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) |
| 2109 | return 0; /* Not in 4-way handshake with PSK */ |
| 2110 | |
| 2111 | /* |
| 2112 | * It looks like connection was lost while trying to go through PSK |
| 2113 | * 4-way handshake. Filter out known disconnection cases that are caused |
| 2114 | * by something else than PSK mismatch to avoid confusing reports. |
| 2115 | */ |
| 2116 | |
| 2117 | if (locally_generated) { |
| 2118 | if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS) |
| 2119 | return 0; |
| 2120 | } |
| 2121 | |
| 2122 | return 1; |
| 2123 | } |
| 2124 | |
| 2125 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 2126 | static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, |
| 2127 | u16 reason_code, |
| 2128 | int locally_generated) |
| 2129 | { |
| 2130 | const u8 *bssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2131 | int authenticating; |
| 2132 | u8 prev_pending_bssid[ETH_ALEN]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2133 | struct wpa_bss *fast_reconnect = NULL; |
| 2134 | struct wpa_ssid *fast_reconnect_ssid = NULL; |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 2135 | struct wpa_ssid *last_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2136 | |
| 2137 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; |
| 2138 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); |
| 2139 | |
| 2140 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 2141 | /* |
| 2142 | * At least Host AP driver and a Prism3 card seemed to be |
| 2143 | * generating streams of disconnected events when configuring |
| 2144 | * IBSS for WPA-None. Ignore them for now. |
| 2145 | */ |
| 2146 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
| 2147 | "IBSS/WPA-None mode"); |
| 2148 | return; |
| 2149 | } |
| 2150 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2151 | if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2152 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
| 2153 | "pre-shared key may be incorrect"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2154 | if (wpas_p2p_4way_hs_failed(wpa_s) > 0) |
| 2155 | return; /* P2P group removed */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2156 | wpas_auth_failed(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2157 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 2158 | if (!wpa_s->disconnected && |
| 2159 | (!wpa_s->auto_reconnect_disabled || |
| 2160 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2161 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " |
| 2162 | "reconnect (wps=%d wpa_state=%d)", |
| 2163 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, |
| 2164 | wpa_s->wpa_state); |
| 2165 | if (wpa_s->wpa_state == WPA_COMPLETED && |
| 2166 | wpa_s->current_ssid && |
| 2167 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2168 | !locally_generated && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2169 | disconnect_reason_recoverable(reason_code)) { |
| 2170 | /* |
| 2171 | * It looks like the AP has dropped association with |
| 2172 | * us, but could allow us to get back in. Try to |
| 2173 | * reconnect to the same BSS without full scan to save |
| 2174 | * time for some common cases. |
| 2175 | */ |
| 2176 | fast_reconnect = wpa_s->current_bss; |
| 2177 | fast_reconnect_ssid = wpa_s->current_ssid; |
| 2178 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2179 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2180 | else |
| 2181 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " |
| 2182 | "immediate scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2183 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2184 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2185 | "try to re-connect"); |
| 2186 | wpa_s->reassociate = 0; |
| 2187 | wpa_s->disconnected = 1; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2188 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2189 | } |
| 2190 | bssid = wpa_s->bssid; |
| 2191 | if (is_zero_ether_addr(bssid)) |
| 2192 | bssid = wpa_s->pending_bssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2193 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 2194 | wpas_connection_failed(wpa_s, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2195 | wpa_sm_notify_disassoc(wpa_s->wpa); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2196 | if (locally_generated) |
| 2197 | wpa_s->disconnect_reason = -reason_code; |
| 2198 | else |
| 2199 | wpa_s->disconnect_reason = reason_code; |
| 2200 | wpas_notify_disconnect_reason(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2201 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
| 2202 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2203 | wpa_clear_keys(wpa_s, wpa_s->bssid); |
| 2204 | } |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 2205 | last_ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2206 | wpa_supplicant_mark_disassoc(wpa_s); |
| 2207 | |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 2208 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2209 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 2210 | wpa_s->current_ssid = last_ssid; |
| 2211 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2212 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2213 | if (fast_reconnect && |
| 2214 | !wpas_network_disabled(wpa_s, fast_reconnect_ssid) && |
| 2215 | !disallowed_bssid(wpa_s, fast_reconnect->bssid) && |
| 2216 | !disallowed_ssid(wpa_s, fast_reconnect->ssid, |
| 2217 | fast_reconnect->ssid_len) && |
| 2218 | !wpas_temp_disabled(wpa_s, fast_reconnect_ssid)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2219 | #ifndef CONFIG_NO_SCAN_PROCESSING |
| 2220 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); |
| 2221 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, |
| 2222 | fast_reconnect_ssid) < 0) { |
| 2223 | /* Recover through full scan */ |
| 2224 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
| 2225 | } |
| 2226 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2227 | } else if (fast_reconnect) { |
| 2228 | /* |
| 2229 | * Could not reconnect to the same BSS due to network being |
| 2230 | * disabled. Use a new scan to match the alternative behavior |
| 2231 | * above, i.e., to continue automatic reconnection attempt in a |
| 2232 | * way that enforces disabled network rules. |
| 2233 | */ |
| 2234 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2235 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | |
| 2239 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2240 | void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2241 | { |
| 2242 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2243 | |
| 2244 | if (!wpa_s->pending_mic_error_report) |
| 2245 | return; |
| 2246 | |
| 2247 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
| 2248 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
| 2249 | wpa_s->pending_mic_error_report = 0; |
| 2250 | } |
| 2251 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 2252 | |
| 2253 | |
| 2254 | static void |
| 2255 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, |
| 2256 | union wpa_event_data *data) |
| 2257 | { |
| 2258 | int pairwise; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2259 | struct os_reltime t; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2260 | |
| 2261 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); |
| 2262 | pairwise = (data && data->michael_mic_failure.unicast); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2263 | os_get_reltime(&t); |
| 2264 | if ((wpa_s->last_michael_mic_error.sec && |
| 2265 | !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2266 | wpa_s->pending_mic_error_report) { |
| 2267 | if (wpa_s->pending_mic_error_report) { |
| 2268 | /* |
| 2269 | * Send the pending MIC error report immediately since |
| 2270 | * we are going to start countermeasures and AP better |
| 2271 | * do the same. |
| 2272 | */ |
| 2273 | wpa_sm_key_request(wpa_s->wpa, 1, |
| 2274 | wpa_s->pending_mic_error_pairwise); |
| 2275 | } |
| 2276 | |
| 2277 | /* Send the new MIC error report immediately since we are going |
| 2278 | * to start countermeasures and AP better do the same. |
| 2279 | */ |
| 2280 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 2281 | |
| 2282 | /* initialize countermeasures */ |
| 2283 | wpa_s->countermeasures = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2284 | |
| 2285 | wpa_blacklist_add(wpa_s, wpa_s->bssid); |
| 2286 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2287 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); |
| 2288 | |
| 2289 | /* |
| 2290 | * Need to wait for completion of request frame. We do not get |
| 2291 | * any callback for the message completion, so just wait a |
| 2292 | * short while and hope for the best. */ |
| 2293 | os_sleep(0, 10000); |
| 2294 | |
| 2295 | wpa_drv_set_countermeasures(wpa_s, 1); |
| 2296 | wpa_supplicant_deauthenticate(wpa_s, |
| 2297 | WLAN_REASON_MICHAEL_MIC_FAILURE); |
| 2298 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, |
| 2299 | wpa_s, NULL); |
| 2300 | eloop_register_timeout(60, 0, |
| 2301 | wpa_supplicant_stop_countermeasures, |
| 2302 | wpa_s, NULL); |
| 2303 | /* TODO: mark the AP rejected for 60 second. STA is |
| 2304 | * allowed to associate with another AP.. */ |
| 2305 | } else { |
| 2306 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
| 2307 | if (wpa_s->mic_errors_seen) { |
| 2308 | /* |
| 2309 | * Reduce the effectiveness of Michael MIC error |
| 2310 | * reports as a means for attacking against TKIP if |
| 2311 | * more than one MIC failure is noticed with the same |
| 2312 | * PTK. We delay the transmission of the reports by a |
| 2313 | * random time between 0 and 60 seconds in order to |
| 2314 | * force the attacker wait 60 seconds before getting |
| 2315 | * the information on whether a frame resulted in a MIC |
| 2316 | * failure. |
| 2317 | */ |
| 2318 | u8 rval[4]; |
| 2319 | int sec; |
| 2320 | |
| 2321 | if (os_get_random(rval, sizeof(rval)) < 0) |
| 2322 | sec = os_random() % 60; |
| 2323 | else |
| 2324 | sec = WPA_GET_BE32(rval) % 60; |
| 2325 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
| 2326 | "report %d seconds", sec); |
| 2327 | wpa_s->pending_mic_error_report = 1; |
| 2328 | wpa_s->pending_mic_error_pairwise = pairwise; |
| 2329 | eloop_cancel_timeout( |
| 2330 | wpa_supplicant_delayed_mic_error_report, |
| 2331 | wpa_s, NULL); |
| 2332 | eloop_register_timeout( |
| 2333 | sec, os_random() % 1000000, |
| 2334 | wpa_supplicant_delayed_mic_error_report, |
| 2335 | wpa_s, NULL); |
| 2336 | } else { |
| 2337 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 2338 | } |
| 2339 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 2340 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 2341 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 2342 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2343 | wpa_s->last_michael_mic_error = t; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2344 | wpa_s->mic_errors_seen++; |
| 2345 | } |
| 2346 | |
| 2347 | |
| 2348 | #ifdef CONFIG_TERMINATE_ONLASTIF |
| 2349 | static int any_interfaces(struct wpa_supplicant *head) |
| 2350 | { |
| 2351 | struct wpa_supplicant *wpa_s; |
| 2352 | |
| 2353 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) |
| 2354 | if (!wpa_s->interface_removed) |
| 2355 | return 1; |
| 2356 | return 0; |
| 2357 | } |
| 2358 | #endif /* CONFIG_TERMINATE_ONLASTIF */ |
| 2359 | |
| 2360 | |
| 2361 | static void |
| 2362 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, |
| 2363 | union wpa_event_data *data) |
| 2364 | { |
| 2365 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) |
| 2366 | return; |
| 2367 | |
| 2368 | switch (data->interface_status.ievent) { |
| 2369 | case EVENT_INTERFACE_ADDED: |
| 2370 | if (!wpa_s->interface_removed) |
| 2371 | break; |
| 2372 | wpa_s->interface_removed = 0; |
| 2373 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
| 2374 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
| 2375 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
| 2376 | "driver after interface was added"); |
| 2377 | } |
| 2378 | break; |
| 2379 | case EVENT_INTERFACE_REMOVED: |
| 2380 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
| 2381 | wpa_s->interface_removed = 1; |
| 2382 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2383 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2384 | l2_packet_deinit(wpa_s->l2); |
| 2385 | wpa_s->l2 = NULL; |
| 2386 | #ifdef CONFIG_IBSS_RSN |
| 2387 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
| 2388 | wpa_s->ibss_rsn = NULL; |
| 2389 | #endif /* CONFIG_IBSS_RSN */ |
| 2390 | #ifdef CONFIG_TERMINATE_ONLASTIF |
| 2391 | /* check if last interface */ |
| 2392 | if (!any_interfaces(wpa_s->global->ifaces)) |
| 2393 | eloop_terminate(); |
| 2394 | #endif /* CONFIG_TERMINATE_ONLASTIF */ |
| 2395 | break; |
| 2396 | } |
| 2397 | } |
| 2398 | |
| 2399 | |
| 2400 | #ifdef CONFIG_PEERKEY |
| 2401 | static void |
| 2402 | wpa_supplicant_event_stkstart(struct wpa_supplicant *wpa_s, |
| 2403 | union wpa_event_data *data) |
| 2404 | { |
| 2405 | if (data == NULL) |
| 2406 | return; |
| 2407 | wpa_sm_stkstart(wpa_s->wpa, data->stkstart.peer); |
| 2408 | } |
| 2409 | #endif /* CONFIG_PEERKEY */ |
| 2410 | |
| 2411 | |
| 2412 | #ifdef CONFIG_TDLS |
| 2413 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, |
| 2414 | union wpa_event_data *data) |
| 2415 | { |
| 2416 | if (data == NULL) |
| 2417 | return; |
| 2418 | switch (data->tdls.oper) { |
| 2419 | case TDLS_REQUEST_SETUP: |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2420 | wpa_tdls_remove(wpa_s->wpa, data->tdls.peer); |
| 2421 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 2422 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); |
| 2423 | else |
| 2424 | wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2425 | break; |
| 2426 | case TDLS_REQUEST_TEARDOWN: |
Sunil Dutt | 6a9f522 | 2013-09-30 17:10:18 +0300 | [diff] [blame] | 2427 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 2428 | wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer, |
| 2429 | data->tdls.reason_code); |
| 2430 | else |
| 2431 | wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, |
| 2432 | data->tdls.peer); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2433 | break; |
| 2434 | } |
| 2435 | } |
| 2436 | #endif /* CONFIG_TDLS */ |
| 2437 | |
| 2438 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2439 | #ifdef CONFIG_WNM |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2440 | static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, |
| 2441 | union wpa_event_data *data) |
| 2442 | { |
| 2443 | if (data == NULL) |
| 2444 | return; |
| 2445 | switch (data->wnm.oper) { |
| 2446 | case WNM_OPER_SLEEP: |
| 2447 | wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " |
| 2448 | "(action=%d, intval=%d)", |
| 2449 | data->wnm.sleep_action, data->wnm.sleep_intval); |
| 2450 | ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2451 | data->wnm.sleep_intval, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2452 | break; |
| 2453 | } |
| 2454 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2455 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2456 | |
| 2457 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2458 | #ifdef CONFIG_IEEE80211R |
| 2459 | static void |
| 2460 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, |
| 2461 | union wpa_event_data *data) |
| 2462 | { |
| 2463 | if (data == NULL) |
| 2464 | return; |
| 2465 | |
| 2466 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, |
| 2467 | data->ft_ies.ies_len, |
| 2468 | data->ft_ies.ft_action, |
| 2469 | data->ft_ies.target_ap, |
| 2470 | data->ft_ies.ric_ies, |
| 2471 | data->ft_ies.ric_ies_len) < 0) { |
| 2472 | /* TODO: prevent MLME/driver from trying to associate? */ |
| 2473 | } |
| 2474 | } |
| 2475 | #endif /* CONFIG_IEEE80211R */ |
| 2476 | |
| 2477 | |
| 2478 | #ifdef CONFIG_IBSS_RSN |
| 2479 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, |
| 2480 | union wpa_event_data *data) |
| 2481 | { |
| 2482 | struct wpa_ssid *ssid; |
| 2483 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 2484 | return; |
| 2485 | if (data == NULL) |
| 2486 | return; |
| 2487 | ssid = wpa_s->current_ssid; |
| 2488 | if (ssid == NULL) |
| 2489 | return; |
| 2490 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 2491 | return; |
| 2492 | |
| 2493 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
| 2494 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2495 | |
| 2496 | |
| 2497 | static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s, |
| 2498 | union wpa_event_data *data) |
| 2499 | { |
| 2500 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2501 | |
| 2502 | if (ssid == NULL) |
| 2503 | return; |
| 2504 | |
| 2505 | /* check if the ssid is correctly configured as IBSS/RSN */ |
| 2506 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 2507 | return; |
| 2508 | |
| 2509 | ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame, |
| 2510 | data->rx_mgmt.frame_len); |
| 2511 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2512 | #endif /* CONFIG_IBSS_RSN */ |
| 2513 | |
| 2514 | |
| 2515 | #ifdef CONFIG_IEEE80211R |
| 2516 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, |
| 2517 | size_t len) |
| 2518 | { |
| 2519 | const u8 *sta_addr, *target_ap_addr; |
| 2520 | u16 status; |
| 2521 | |
| 2522 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); |
| 2523 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) |
| 2524 | return; /* only SME case supported for now */ |
| 2525 | if (len < 1 + 2 * ETH_ALEN + 2) |
| 2526 | return; |
| 2527 | if (data[0] != 2) |
| 2528 | return; /* Only FT Action Response is supported for now */ |
| 2529 | sta_addr = data + 1; |
| 2530 | target_ap_addr = data + 1 + ETH_ALEN; |
| 2531 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); |
| 2532 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
| 2533 | MACSTR " TargetAP " MACSTR " status %u", |
| 2534 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); |
| 2535 | |
| 2536 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { |
| 2537 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
| 2538 | " in FT Action Response", MAC2STR(sta_addr)); |
| 2539 | return; |
| 2540 | } |
| 2541 | |
| 2542 | if (status) { |
| 2543 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
| 2544 | "failure (status code %d)", status); |
| 2545 | /* TODO: report error to FT code(?) */ |
| 2546 | return; |
| 2547 | } |
| 2548 | |
| 2549 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, |
| 2550 | len - (1 + 2 * ETH_ALEN + 2), 1, |
| 2551 | target_ap_addr, NULL, 0) < 0) |
| 2552 | return; |
| 2553 | |
| 2554 | #ifdef CONFIG_SME |
| 2555 | { |
| 2556 | struct wpa_bss *bss; |
| 2557 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); |
| 2558 | if (bss) |
| 2559 | wpa_s->sme.freq = bss->freq; |
| 2560 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
| 2561 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
| 2562 | WLAN_AUTH_FT); |
| 2563 | } |
| 2564 | #endif /* CONFIG_SME */ |
| 2565 | } |
| 2566 | #endif /* CONFIG_IEEE80211R */ |
| 2567 | |
| 2568 | |
| 2569 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
| 2570 | struct unprot_deauth *e) |
| 2571 | { |
| 2572 | #ifdef CONFIG_IEEE80211W |
| 2573 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " |
| 2574 | "dropped: " MACSTR " -> " MACSTR |
| 2575 | " (reason code %u)", |
| 2576 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); |
| 2577 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); |
| 2578 | #endif /* CONFIG_IEEE80211W */ |
| 2579 | } |
| 2580 | |
| 2581 | |
| 2582 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, |
| 2583 | struct unprot_disassoc *e) |
| 2584 | { |
| 2585 | #ifdef CONFIG_IEEE80211W |
| 2586 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " |
| 2587 | "dropped: " MACSTR " -> " MACSTR |
| 2588 | " (reason code %u)", |
| 2589 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); |
| 2590 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); |
| 2591 | #endif /* CONFIG_IEEE80211W */ |
| 2592 | } |
| 2593 | |
| 2594 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2595 | static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr, |
| 2596 | u16 reason_code, int locally_generated, |
| 2597 | const u8 *ie, size_t ie_len, int deauth) |
| 2598 | { |
| 2599 | #ifdef CONFIG_AP |
| 2600 | if (wpa_s->ap_iface && addr) { |
| 2601 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr); |
| 2602 | return; |
| 2603 | } |
| 2604 | |
| 2605 | if (wpa_s->ap_iface) { |
| 2606 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode"); |
| 2607 | return; |
| 2608 | } |
| 2609 | #endif /* CONFIG_AP */ |
| 2610 | |
| 2611 | wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated); |
| 2612 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 2613 | if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || |
| 2614 | ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 2615 | (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && |
| 2616 | eapol_sm_failed(wpa_s->eapol))) && |
| 2617 | !wpa_s->eap_expected_failure)) |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2618 | wpas_auth_failed(wpa_s); |
| 2619 | |
| 2620 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2621 | if (deauth && reason_code > 0) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2622 | if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len, |
| 2623 | locally_generated) > 0) { |
| 2624 | /* |
| 2625 | * The interface was removed, so cannot continue |
| 2626 | * processing any additional operations after this. |
| 2627 | */ |
| 2628 | return; |
| 2629 | } |
| 2630 | } |
| 2631 | #endif /* CONFIG_P2P */ |
| 2632 | |
| 2633 | wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, |
| 2634 | locally_generated); |
| 2635 | } |
| 2636 | |
| 2637 | |
| 2638 | static void wpas_event_disassoc(struct wpa_supplicant *wpa_s, |
| 2639 | struct disassoc_info *info) |
| 2640 | { |
| 2641 | u16 reason_code = 0; |
| 2642 | int locally_generated = 0; |
| 2643 | const u8 *addr = NULL; |
| 2644 | const u8 *ie = NULL; |
| 2645 | size_t ie_len = 0; |
| 2646 | |
| 2647 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); |
| 2648 | |
| 2649 | if (info) { |
| 2650 | addr = info->addr; |
| 2651 | ie = info->ie; |
| 2652 | ie_len = info->ie_len; |
| 2653 | reason_code = info->reason_code; |
| 2654 | locally_generated = info->locally_generated; |
| 2655 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", reason_code, |
| 2656 | locally_generated ? " (locally generated)" : ""); |
| 2657 | if (addr) |
| 2658 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
| 2659 | MAC2STR(addr)); |
| 2660 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", |
| 2661 | ie, ie_len); |
| 2662 | } |
| 2663 | |
| 2664 | #ifdef CONFIG_AP |
| 2665 | if (wpa_s->ap_iface && info && info->addr) { |
| 2666 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr); |
| 2667 | return; |
| 2668 | } |
| 2669 | |
| 2670 | if (wpa_s->ap_iface) { |
| 2671 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode"); |
| 2672 | return; |
| 2673 | } |
| 2674 | #endif /* CONFIG_AP */ |
| 2675 | |
| 2676 | #ifdef CONFIG_P2P |
| 2677 | if (info) { |
| 2678 | wpas_p2p_disassoc_notif( |
| 2679 | wpa_s, info->addr, reason_code, info->ie, info->ie_len, |
| 2680 | locally_generated); |
| 2681 | } |
| 2682 | #endif /* CONFIG_P2P */ |
| 2683 | |
| 2684 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 2685 | sme_event_disassoc(wpa_s, info); |
| 2686 | |
| 2687 | wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated, |
| 2688 | ie, ie_len, 0); |
| 2689 | } |
| 2690 | |
| 2691 | |
| 2692 | static void wpas_event_deauth(struct wpa_supplicant *wpa_s, |
| 2693 | struct deauth_info *info) |
| 2694 | { |
| 2695 | u16 reason_code = 0; |
| 2696 | int locally_generated = 0; |
| 2697 | const u8 *addr = NULL; |
| 2698 | const u8 *ie = NULL; |
| 2699 | size_t ie_len = 0; |
| 2700 | |
| 2701 | wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification"); |
| 2702 | |
| 2703 | if (info) { |
| 2704 | addr = info->addr; |
| 2705 | ie = info->ie; |
| 2706 | ie_len = info->ie_len; |
| 2707 | reason_code = info->reason_code; |
| 2708 | locally_generated = info->locally_generated; |
| 2709 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u%s", |
| 2710 | reason_code, |
| 2711 | locally_generated ? " (locally generated)" : ""); |
| 2712 | if (addr) { |
| 2713 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
| 2714 | MAC2STR(addr)); |
| 2715 | } |
| 2716 | wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)", |
| 2717 | ie, ie_len); |
| 2718 | } |
| 2719 | |
| 2720 | wpa_reset_ft_completed(wpa_s->wpa); |
| 2721 | |
| 2722 | wpas_event_disconnect(wpa_s, addr, reason_code, |
| 2723 | locally_generated, ie, ie_len, 1); |
| 2724 | } |
| 2725 | |
| 2726 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame^] | 2727 | static const char * reg_init_str(enum reg_change_initiator init) |
| 2728 | { |
| 2729 | switch (init) { |
| 2730 | case REGDOM_SET_BY_CORE: |
| 2731 | return "CORE"; |
| 2732 | case REGDOM_SET_BY_USER: |
| 2733 | return "USER"; |
| 2734 | case REGDOM_SET_BY_DRIVER: |
| 2735 | return "DRIVER"; |
| 2736 | case REGDOM_SET_BY_COUNTRY_IE: |
| 2737 | return "COUNTRY_IE"; |
| 2738 | case REGDOM_BEACON_HINT: |
| 2739 | return "BEACON_HINT"; |
| 2740 | } |
| 2741 | return "?"; |
| 2742 | } |
| 2743 | |
| 2744 | |
| 2745 | static const char * reg_type_str(enum reg_type type) |
| 2746 | { |
| 2747 | switch (type) { |
| 2748 | case REGDOM_TYPE_UNKNOWN: |
| 2749 | return "UNKNOWN"; |
| 2750 | case REGDOM_TYPE_COUNTRY: |
| 2751 | return "COUNTRY"; |
| 2752 | case REGDOM_TYPE_WORLD: |
| 2753 | return "WORLD"; |
| 2754 | case REGDOM_TYPE_CUSTOM_WORLD: |
| 2755 | return "CUSTOM_WORLD"; |
| 2756 | case REGDOM_TYPE_INTERSECTION: |
| 2757 | return "INTERSECTION"; |
| 2758 | } |
| 2759 | return "?"; |
| 2760 | } |
| 2761 | |
| 2762 | |
| 2763 | static void wpa_supplicant_update_channel_list( |
| 2764 | struct wpa_supplicant *wpa_s, struct channel_list_changed *info) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2765 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2766 | struct wpa_supplicant *ifs; |
| 2767 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame^] | 2768 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s", |
| 2769 | reg_init_str(info->type), reg_type_str(info->type), |
| 2770 | info->alpha2[0] ? " alpha2=" : "", |
| 2771 | info->alpha2[0] ? info->alpha2 : ""); |
| 2772 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2773 | if (wpa_s->drv_priv == NULL) |
| 2774 | return; /* Ignore event during drv initialization */ |
| 2775 | |
| 2776 | free_hw_features(wpa_s); |
| 2777 | wpa_s->hw.modes = wpa_drv_get_hw_feature_data( |
| 2778 | wpa_s, &wpa_s->hw.num_modes, &wpa_s->hw.flags); |
| 2779 | |
| 2780 | #ifdef CONFIG_P2P |
| 2781 | wpas_p2p_update_channel_list(wpa_s); |
| 2782 | #endif /* CONFIG_P2P */ |
| 2783 | |
| 2784 | /* |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2785 | * Check other interfaces to see if they share the same radio. If |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2786 | * so, they get updated with this same hw mode info. |
| 2787 | */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2788 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 2789 | radio_list) { |
| 2790 | if (ifs != wpa_s) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2791 | wpa_printf(MSG_DEBUG, "%s: Updating hw mode", |
| 2792 | ifs->ifname); |
| 2793 | free_hw_features(ifs); |
| 2794 | ifs->hw.modes = wpa_drv_get_hw_feature_data( |
| 2795 | ifs, &ifs->hw.num_modes, &ifs->hw.flags); |
| 2796 | } |
| 2797 | } |
| 2798 | } |
| 2799 | |
| 2800 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2801 | static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s, |
| 2802 | const struct ieee80211_mgmt *mgmt, |
| 2803 | size_t len, int freq) |
| 2804 | { |
| 2805 | const u8 *payload; |
| 2806 | size_t plen; |
| 2807 | u8 category; |
| 2808 | |
| 2809 | if (len < IEEE80211_HDRLEN + 2) |
| 2810 | return; |
| 2811 | |
| 2812 | payload = &mgmt->u.action.category; |
| 2813 | category = *payload++; |
| 2814 | plen = (((const u8 *) mgmt) + len) - payload; |
| 2815 | |
| 2816 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR |
| 2817 | " Category=%u DataLen=%d freq=%d MHz", |
| 2818 | MAC2STR(mgmt->sa), category, (int) plen, freq); |
| 2819 | |
| 2820 | #ifdef CONFIG_IEEE80211R |
| 2821 | if (category == WLAN_ACTION_FT) { |
| 2822 | ft_rx_action(wpa_s, payload, plen); |
| 2823 | return; |
| 2824 | } |
| 2825 | #endif /* CONFIG_IEEE80211R */ |
| 2826 | |
| 2827 | #ifdef CONFIG_IEEE80211W |
| 2828 | #ifdef CONFIG_SME |
| 2829 | if (category == WLAN_ACTION_SA_QUERY) { |
| 2830 | sme_sa_query_rx(wpa_s, mgmt->sa, payload, plen); |
| 2831 | return; |
| 2832 | } |
| 2833 | #endif /* CONFIG_SME */ |
| 2834 | #endif /* CONFIG_IEEE80211W */ |
| 2835 | |
| 2836 | #ifdef CONFIG_WNM |
| 2837 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
| 2838 | ieee802_11_rx_wnm_action(wpa_s, mgmt, len); |
| 2839 | return; |
| 2840 | } |
| 2841 | #endif /* CONFIG_WNM */ |
| 2842 | |
| 2843 | #ifdef CONFIG_GAS |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2844 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
| 2845 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2846 | gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid, |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2847 | mgmt->u.action.category, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2848 | payload, plen, freq) == 0) |
| 2849 | return; |
| 2850 | #endif /* CONFIG_GAS */ |
| 2851 | |
| 2852 | #ifdef CONFIG_TDLS |
| 2853 | if (category == WLAN_ACTION_PUBLIC && plen >= 4 && |
| 2854 | payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { |
| 2855 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2856 | "TDLS: Received Discovery Response from " MACSTR, |
| 2857 | MAC2STR(mgmt->sa)); |
| 2858 | return; |
| 2859 | } |
| 2860 | #endif /* CONFIG_TDLS */ |
| 2861 | |
| 2862 | #ifdef CONFIG_INTERWORKING |
| 2863 | if (category == WLAN_ACTION_QOS && plen >= 1 && |
| 2864 | payload[0] == QOS_QOS_MAP_CONFIG) { |
| 2865 | const u8 *pos = payload + 1; |
| 2866 | size_t qlen = plen - 1; |
| 2867 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from " |
| 2868 | MACSTR, MAC2STR(mgmt->sa)); |
| 2869 | if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 && |
| 2870 | qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET && |
| 2871 | pos[1] <= qlen - 2 && pos[1] >= 16) |
| 2872 | wpas_qos_map_set(wpa_s, pos + 2, pos[1]); |
| 2873 | return; |
| 2874 | } |
| 2875 | #endif /* CONFIG_INTERWORKING */ |
| 2876 | |
| 2877 | #ifdef CONFIG_P2P |
| 2878 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
| 2879 | category, payload, plen, freq); |
| 2880 | #endif /* CONFIG_P2P */ |
| 2881 | } |
| 2882 | |
| 2883 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 2884 | static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s, |
| 2885 | union wpa_event_data *event) |
| 2886 | { |
| 2887 | #ifdef CONFIG_P2P |
| 2888 | struct wpa_supplicant *ifs; |
| 2889 | #endif /* CONFIG_P2P */ |
| 2890 | struct wpa_freq_range_list *list; |
| 2891 | char *str = NULL; |
| 2892 | |
| 2893 | list = &event->freq_range; |
| 2894 | |
| 2895 | if (list->num) |
| 2896 | str = freq_range_list_str(list); |
| 2897 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s", |
| 2898 | str ? str : ""); |
| 2899 | |
| 2900 | #ifdef CONFIG_P2P |
| 2901 | if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) { |
| 2902 | wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range", |
| 2903 | __func__); |
| 2904 | } else { |
| 2905 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event"); |
| 2906 | wpas_p2p_update_channel_list(wpa_s); |
| 2907 | } |
| 2908 | |
| 2909 | for (ifs = wpa_s->global->ifaces; ifs; ifs = ifs->next) { |
| 2910 | int freq; |
| 2911 | if (!ifs->current_ssid || |
| 2912 | !ifs->current_ssid->p2p_group || |
| 2913 | (ifs->current_ssid->mode != WPAS_MODE_P2P_GO && |
| 2914 | ifs->current_ssid->mode != WPAS_MODE_P2P_GROUP_FORMATION)) |
| 2915 | continue; |
| 2916 | |
| 2917 | freq = ifs->current_ssid->frequency; |
| 2918 | if (!freq_range_list_includes(list, freq)) { |
| 2919 | wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating frequency %d MHz in safe range", |
| 2920 | freq); |
| 2921 | continue; |
| 2922 | } |
| 2923 | |
| 2924 | wpa_dbg(ifs, MSG_DEBUG, "P2P GO operating in unsafe frequency %d MHz", |
| 2925 | freq); |
| 2926 | /* TODO: Consider using CSA or removing the group within |
| 2927 | * wpa_supplicant */ |
| 2928 | wpa_msg(ifs, MSG_INFO, P2P_EVENT_REMOVE_AND_REFORM_GROUP); |
| 2929 | } |
| 2930 | #endif /* CONFIG_P2P */ |
| 2931 | |
| 2932 | os_free(str); |
| 2933 | } |
| 2934 | |
| 2935 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2936 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
| 2937 | union wpa_event_data *data) |
| 2938 | { |
| 2939 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | |
| 2941 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
| 2942 | event != EVENT_INTERFACE_ENABLED && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2943 | event != EVENT_INTERFACE_STATUS && |
| 2944 | event != EVENT_SCHED_SCAN_STOPPED) { |
| 2945 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2946 | "Ignore event %s (%d) while interface is disabled", |
| 2947 | event_to_string(event), event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2948 | return; |
| 2949 | } |
| 2950 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2951 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 2952 | { |
| 2953 | int level = MSG_DEBUG; |
| 2954 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2955 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2956 | const struct ieee80211_hdr *hdr; |
| 2957 | u16 fc; |
| 2958 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
| 2959 | fc = le_to_host16(hdr->frame_control); |
| 2960 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 2961 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) |
| 2962 | level = MSG_EXCESSIVE; |
| 2963 | } |
| 2964 | |
| 2965 | wpa_dbg(wpa_s, level, "Event %s (%d) received", |
| 2966 | event_to_string(event), event); |
| 2967 | } |
| 2968 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2969 | |
| 2970 | switch (event) { |
| 2971 | case EVENT_AUTH: |
| 2972 | sme_event_auth(wpa_s, data); |
| 2973 | break; |
| 2974 | case EVENT_ASSOC: |
| 2975 | wpa_supplicant_event_assoc(wpa_s, data); |
| 2976 | break; |
| 2977 | case EVENT_DISASSOC: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2978 | wpas_event_disassoc(wpa_s, |
| 2979 | data ? &data->disassoc_info : NULL); |
| 2980 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2981 | case EVENT_DEAUTH: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2982 | wpas_event_deauth(wpa_s, |
| 2983 | data ? &data->deauth_info : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2984 | break; |
| 2985 | case EVENT_MICHAEL_MIC_FAILURE: |
| 2986 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); |
| 2987 | break; |
| 2988 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2989 | case EVENT_SCAN_STARTED: |
| 2990 | os_get_reltime(&wpa_s->scan_start_time); |
| 2991 | if (wpa_s->own_scan_requested) { |
| 2992 | struct os_reltime diff; |
| 2993 | |
| 2994 | os_reltime_sub(&wpa_s->scan_start_time, |
| 2995 | &wpa_s->scan_trigger_time, &diff); |
| 2996 | wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds", |
| 2997 | diff.sec, diff.usec); |
| 2998 | wpa_s->own_scan_requested = 0; |
| 2999 | wpa_s->own_scan_running = 1; |
| 3000 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 3001 | wpa_s->manual_scan_use_id) { |
| 3002 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED "id=%u", |
| 3003 | wpa_s->manual_scan_id); |
| 3004 | } else { |
| 3005 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); |
| 3006 | } |
| 3007 | } else { |
| 3008 | wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan"); |
| 3009 | wpa_s->external_scan_running = 1; |
| 3010 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); |
| 3011 | } |
| 3012 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3013 | case EVENT_SCAN_RESULTS: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3014 | if (os_reltime_initialized(&wpa_s->scan_start_time)) { |
| 3015 | struct os_reltime now, diff; |
| 3016 | os_get_reltime(&now); |
| 3017 | os_reltime_sub(&now, &wpa_s->scan_start_time, &diff); |
| 3018 | wpa_s->scan_start_time.sec = 0; |
| 3019 | wpa_s->scan_start_time.usec = 0; |
| 3020 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds", |
| 3021 | diff.sec, diff.usec); |
| 3022 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3023 | wpa_supplicant_event_scan_results(wpa_s, data); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3024 | wpa_s->own_scan_running = 0; |
| 3025 | wpa_s->external_scan_running = 0; |
| 3026 | radio_work_check_next(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3027 | break; |
| 3028 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 3029 | case EVENT_ASSOCINFO: |
| 3030 | wpa_supplicant_event_associnfo(wpa_s, data); |
| 3031 | break; |
| 3032 | case EVENT_INTERFACE_STATUS: |
| 3033 | wpa_supplicant_event_interface_status(wpa_s, data); |
| 3034 | break; |
| 3035 | case EVENT_PMKID_CANDIDATE: |
| 3036 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); |
| 3037 | break; |
| 3038 | #ifdef CONFIG_PEERKEY |
| 3039 | case EVENT_STKSTART: |
| 3040 | wpa_supplicant_event_stkstart(wpa_s, data); |
| 3041 | break; |
| 3042 | #endif /* CONFIG_PEERKEY */ |
| 3043 | #ifdef CONFIG_TDLS |
| 3044 | case EVENT_TDLS: |
| 3045 | wpa_supplicant_event_tdls(wpa_s, data); |
| 3046 | break; |
| 3047 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3048 | #ifdef CONFIG_WNM |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3049 | case EVENT_WNM: |
| 3050 | wpa_supplicant_event_wnm(wpa_s, data); |
| 3051 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3052 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3053 | #ifdef CONFIG_IEEE80211R |
| 3054 | case EVENT_FT_RESPONSE: |
| 3055 | wpa_supplicant_event_ft_response(wpa_s, data); |
| 3056 | break; |
| 3057 | #endif /* CONFIG_IEEE80211R */ |
| 3058 | #ifdef CONFIG_IBSS_RSN |
| 3059 | case EVENT_IBSS_RSN_START: |
| 3060 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); |
| 3061 | break; |
| 3062 | #endif /* CONFIG_IBSS_RSN */ |
| 3063 | case EVENT_ASSOC_REJECT: |
| 3064 | if (data->assoc_reject.bssid) |
| 3065 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT |
| 3066 | "bssid=" MACSTR " status_code=%u", |
| 3067 | MAC2STR(data->assoc_reject.bssid), |
| 3068 | data->assoc_reject.status_code); |
| 3069 | else |
| 3070 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT |
| 3071 | "status_code=%u", |
| 3072 | data->assoc_reject.status_code); |
| 3073 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 3074 | sme_event_assoc_reject(wpa_s, data); |
Jeff Johnson | b485b18 | 2012-10-21 18:19:27 -0700 | [diff] [blame] | 3075 | else { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3076 | const u8 *bssid = data->assoc_reject.bssid; |
| 3077 | if (bssid == NULL || is_zero_ether_addr(bssid)) |
| 3078 | bssid = wpa_s->pending_bssid; |
| 3079 | wpas_connection_failed(wpa_s, bssid); |
| 3080 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3081 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3082 | break; |
| 3083 | case EVENT_AUTH_TIMED_OUT: |
| 3084 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 3085 | sme_event_auth_timed_out(wpa_s, data); |
| 3086 | break; |
| 3087 | case EVENT_ASSOC_TIMED_OUT: |
| 3088 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 3089 | sme_event_assoc_timed_out(wpa_s, data); |
| 3090 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3091 | case EVENT_TX_STATUS: |
| 3092 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
| 3093 | " type=%d stype=%d", |
| 3094 | MAC2STR(data->tx_status.dst), |
| 3095 | data->tx_status.type, data->tx_status.stype); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3096 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3097 | if (wpa_s->ap_iface == NULL) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3098 | #ifdef CONFIG_OFFCHANNEL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3099 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 3100 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3101 | offchannel_send_action_tx_status( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3102 | wpa_s, data->tx_status.dst, |
| 3103 | data->tx_status.data, |
| 3104 | data->tx_status.data_len, |
| 3105 | data->tx_status.ack ? |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3106 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
| 3107 | OFFCHANNEL_SEND_ACTION_NO_ACK); |
| 3108 | #endif /* CONFIG_OFFCHANNEL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3109 | break; |
| 3110 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3111 | #endif /* CONFIG_AP */ |
| 3112 | #ifdef CONFIG_OFFCHANNEL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3113 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
| 3114 | MACSTR, MAC2STR(wpa_s->parent->pending_action_dst)); |
| 3115 | /* |
| 3116 | * Catch TX status events for Action frames we sent via group |
| 3117 | * interface in GO mode. |
| 3118 | */ |
| 3119 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 3120 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && |
| 3121 | os_memcmp(wpa_s->parent->pending_action_dst, |
| 3122 | data->tx_status.dst, ETH_ALEN) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3123 | offchannel_send_action_tx_status( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3124 | wpa_s->parent, data->tx_status.dst, |
| 3125 | data->tx_status.data, |
| 3126 | data->tx_status.data_len, |
| 3127 | data->tx_status.ack ? |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3128 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
| 3129 | OFFCHANNEL_SEND_ACTION_NO_ACK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3130 | break; |
| 3131 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3132 | #endif /* CONFIG_OFFCHANNEL */ |
| 3133 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3134 | switch (data->tx_status.type) { |
| 3135 | case WLAN_FC_TYPE_MGMT: |
| 3136 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, |
| 3137 | data->tx_status.data_len, |
| 3138 | data->tx_status.stype, |
| 3139 | data->tx_status.ack); |
| 3140 | break; |
| 3141 | case WLAN_FC_TYPE_DATA: |
| 3142 | ap_tx_status(wpa_s, data->tx_status.dst, |
| 3143 | data->tx_status.data, |
| 3144 | data->tx_status.data_len, |
| 3145 | data->tx_status.ack); |
| 3146 | break; |
| 3147 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3148 | #endif /* CONFIG_AP */ |
| 3149 | break; |
| 3150 | #ifdef CONFIG_AP |
| 3151 | case EVENT_EAPOL_TX_STATUS: |
| 3152 | ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, |
| 3153 | data->eapol_tx_status.data, |
| 3154 | data->eapol_tx_status.data_len, |
| 3155 | data->eapol_tx_status.ack); |
| 3156 | break; |
| 3157 | case EVENT_DRIVER_CLIENT_POLL_OK: |
| 3158 | ap_client_poll_ok(wpa_s, data->client_poll.addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3159 | break; |
| 3160 | case EVENT_RX_FROM_UNKNOWN: |
| 3161 | if (wpa_s->ap_iface == NULL) |
| 3162 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3163 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
| 3164 | data->rx_from_unknown.wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3165 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3166 | case EVENT_CH_SWITCH: |
| 3167 | if (!data) |
| 3168 | break; |
| 3169 | if (!wpa_s->ap_iface) { |
| 3170 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: Ignore channel switch " |
| 3171 | "event in non-AP mode"); |
| 3172 | break; |
| 3173 | } |
| 3174 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3175 | wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, |
| 3176 | data->ch_switch.ht_enabled, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 3177 | data->ch_switch.ch_offset, |
| 3178 | data->ch_switch.ch_width, |
| 3179 | data->ch_switch.cf1, |
| 3180 | data->ch_switch.cf2); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3181 | break; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3182 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3183 | case EVENT_RX_MGMT: { |
| 3184 | u16 fc, stype; |
| 3185 | const struct ieee80211_mgmt *mgmt; |
| 3186 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 3187 | #ifdef CONFIG_TESTING_OPTIONS |
| 3188 | if (wpa_s->ext_mgmt_frame_handling) { |
| 3189 | struct rx_mgmt *rx = &data->rx_mgmt; |
| 3190 | size_t hex_len = 2 * rx->frame_len + 1; |
| 3191 | char *hex = os_malloc(hex_len); |
| 3192 | if (hex) { |
| 3193 | wpa_snprintf_hex(hex, hex_len, |
| 3194 | rx->frame, rx->frame_len); |
| 3195 | wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s", |
| 3196 | rx->freq, rx->datarate, rx->ssi_signal, |
| 3197 | hex); |
| 3198 | os_free(hex); |
| 3199 | } |
| 3200 | break; |
| 3201 | } |
| 3202 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3203 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3204 | mgmt = (const struct ieee80211_mgmt *) |
| 3205 | data->rx_mgmt.frame; |
| 3206 | fc = le_to_host16(mgmt->frame_control); |
| 3207 | stype = WLAN_FC_GET_STYPE(fc); |
| 3208 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3209 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3210 | if (wpa_s->ap_iface == NULL) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3211 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3212 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3213 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
| 3214 | data->rx_mgmt.frame_len > 24) { |
| 3215 | const u8 *src = mgmt->sa; |
| 3216 | const u8 *ie = mgmt->u.probe_req.variable; |
| 3217 | size_t ie_len = data->rx_mgmt.frame_len - |
| 3218 | (mgmt->u.probe_req.variable - |
| 3219 | data->rx_mgmt.frame); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3220 | wpas_p2p_probe_req_rx( |
| 3221 | wpa_s, src, mgmt->da, |
| 3222 | mgmt->bssid, ie, ie_len, |
| 3223 | data->rx_mgmt.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3224 | break; |
| 3225 | } |
| 3226 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3227 | #ifdef CONFIG_IBSS_RSN |
| 3228 | if (stype == WLAN_FC_STYPE_AUTH && |
| 3229 | data->rx_mgmt.frame_len >= 30) { |
| 3230 | wpa_supplicant_event_ibss_auth(wpa_s, data); |
| 3231 | break; |
| 3232 | } |
| 3233 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3234 | |
| 3235 | if (stype == WLAN_FC_STYPE_ACTION) { |
| 3236 | wpas_event_rx_mgmt_action( |
| 3237 | wpa_s, mgmt, data->rx_mgmt.frame_len, |
| 3238 | data->rx_mgmt.freq); |
| 3239 | break; |
| 3240 | } |
| 3241 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3242 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
| 3243 | "management frame in non-AP mode"); |
| 3244 | break; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3245 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3246 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3247 | |
| 3248 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
| 3249 | data->rx_mgmt.frame_len > 24) { |
| 3250 | const u8 *ie = mgmt->u.probe_req.variable; |
| 3251 | size_t ie_len = data->rx_mgmt.frame_len - |
| 3252 | (mgmt->u.probe_req.variable - |
| 3253 | data->rx_mgmt.frame); |
| 3254 | |
| 3255 | wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, |
| 3256 | mgmt->bssid, ie, ie_len, |
| 3257 | data->rx_mgmt.ssi_signal); |
| 3258 | } |
| 3259 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3260 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3261 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3262 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3263 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3264 | case EVENT_RX_PROBE_REQ: |
| 3265 | if (data->rx_probe_req.sa == NULL || |
| 3266 | data->rx_probe_req.ie == NULL) |
| 3267 | break; |
| 3268 | #ifdef CONFIG_AP |
| 3269 | if (wpa_s->ap_iface) { |
| 3270 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], |
| 3271 | data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3272 | data->rx_probe_req.da, |
| 3273 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3274 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3275 | data->rx_probe_req.ie_len, |
| 3276 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3277 | break; |
| 3278 | } |
| 3279 | #endif /* CONFIG_AP */ |
| 3280 | #ifdef CONFIG_P2P |
| 3281 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3282 | data->rx_probe_req.da, |
| 3283 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3284 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3285 | data->rx_probe_req.ie_len, |
| 3286 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3287 | #endif /* CONFIG_P2P */ |
| 3288 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3289 | case EVENT_REMAIN_ON_CHANNEL: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3290 | #ifdef CONFIG_OFFCHANNEL |
| 3291 | offchannel_remain_on_channel_cb( |
| 3292 | wpa_s, data->remain_on_channel.freq, |
| 3293 | data->remain_on_channel.duration); |
| 3294 | #endif /* CONFIG_OFFCHANNEL */ |
| 3295 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3296 | wpas_p2p_remain_on_channel_cb( |
| 3297 | wpa_s, data->remain_on_channel.freq, |
| 3298 | data->remain_on_channel.duration); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3299 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3300 | break; |
| 3301 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3302 | #ifdef CONFIG_OFFCHANNEL |
| 3303 | offchannel_cancel_remain_on_channel_cb( |
| 3304 | wpa_s, data->remain_on_channel.freq); |
| 3305 | #endif /* CONFIG_OFFCHANNEL */ |
| 3306 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3307 | wpas_p2p_cancel_remain_on_channel_cb( |
| 3308 | wpa_s, data->remain_on_channel.freq); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3309 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3310 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3311 | case EVENT_EAPOL_RX: |
| 3312 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, |
| 3313 | data->eapol_rx.data, |
| 3314 | data->eapol_rx.data_len); |
| 3315 | break; |
| 3316 | case EVENT_SIGNAL_CHANGE: |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame^] | 3317 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE |
| 3318 | "above=%d signal=%d noise=%d txrate=%d", |
| 3319 | data->signal_change.above_threshold, |
| 3320 | data->signal_change.current_signal, |
| 3321 | data->signal_change.current_noise, |
| 3322 | data->signal_change.current_txrate); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3323 | bgscan_notify_signal_change( |
| 3324 | wpa_s, data->signal_change.above_threshold, |
| 3325 | data->signal_change.current_signal, |
| 3326 | data->signal_change.current_noise, |
| 3327 | data->signal_change.current_txrate); |
| 3328 | break; |
| 3329 | case EVENT_INTERFACE_ENABLED: |
| 3330 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
| 3331 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3332 | wpa_supplicant_update_mac_addr(wpa_s); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 3333 | if (wpa_s->p2p_mgmt) { |
| 3334 | wpa_supplicant_set_state(wpa_s, |
| 3335 | WPA_DISCONNECTED); |
| 3336 | break; |
| 3337 | } |
| 3338 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3339 | #ifdef CONFIG_AP |
| 3340 | if (!wpa_s->ap_iface) { |
| 3341 | wpa_supplicant_set_state(wpa_s, |
| 3342 | WPA_DISCONNECTED); |
| 3343 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 3344 | } else |
| 3345 | wpa_supplicant_set_state(wpa_s, |
| 3346 | WPA_COMPLETED); |
| 3347 | #else /* CONFIG_AP */ |
| 3348 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 3349 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 3350 | #endif /* CONFIG_AP */ |
| 3351 | } |
| 3352 | break; |
| 3353 | case EVENT_INTERFACE_DISABLED: |
| 3354 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 3355 | #ifdef CONFIG_P2P |
| 3356 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 3357 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group && |
| 3358 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) { |
| 3359 | /* |
| 3360 | * The interface was externally disabled. Remove |
| 3361 | * it assuming an external entity will start a |
| 3362 | * new session if needed. |
| 3363 | */ |
| 3364 | wpas_p2p_disconnect(wpa_s); |
| 3365 | break; |
| 3366 | } |
| 3367 | #endif /* CONFIG_P2P */ |
| 3368 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3369 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3370 | radio_remove_works(wpa_s, NULL, 0); |
| 3371 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3372 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
| 3373 | break; |
| 3374 | case EVENT_CHANNEL_LIST_CHANGED: |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame^] | 3375 | wpa_supplicant_update_channel_list( |
| 3376 | wpa_s, &data->channel_list_changed); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3377 | break; |
| 3378 | case EVENT_INTERFACE_UNAVAILABLE: |
| 3379 | #ifdef CONFIG_P2P |
| 3380 | wpas_p2p_interface_unavailable(wpa_s); |
| 3381 | #endif /* CONFIG_P2P */ |
| 3382 | break; |
| 3383 | case EVENT_BEST_CHANNEL: |
| 3384 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
| 3385 | "(%d %d %d)", |
| 3386 | data->best_chan.freq_24, data->best_chan.freq_5, |
| 3387 | data->best_chan.freq_overall); |
| 3388 | wpa_s->best_24_freq = data->best_chan.freq_24; |
| 3389 | wpa_s->best_5_freq = data->best_chan.freq_5; |
| 3390 | wpa_s->best_overall_freq = data->best_chan.freq_overall; |
| 3391 | #ifdef CONFIG_P2P |
| 3392 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, |
| 3393 | data->best_chan.freq_5, |
| 3394 | data->best_chan.freq_overall); |
| 3395 | #endif /* CONFIG_P2P */ |
| 3396 | break; |
| 3397 | case EVENT_UNPROT_DEAUTH: |
| 3398 | wpa_supplicant_event_unprot_deauth(wpa_s, |
| 3399 | &data->unprot_deauth); |
| 3400 | break; |
| 3401 | case EVENT_UNPROT_DISASSOC: |
| 3402 | wpa_supplicant_event_unprot_disassoc(wpa_s, |
| 3403 | &data->unprot_disassoc); |
| 3404 | break; |
| 3405 | case EVENT_STATION_LOW_ACK: |
| 3406 | #ifdef CONFIG_AP |
| 3407 | if (wpa_s->ap_iface && data) |
| 3408 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], |
| 3409 | data->low_ack.addr); |
| 3410 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3411 | #ifdef CONFIG_TDLS |
| 3412 | if (data) |
| 3413 | wpa_tdls_disable_link(wpa_s->wpa, data->low_ack.addr); |
| 3414 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3415 | break; |
| 3416 | case EVENT_IBSS_PEER_LOST: |
| 3417 | #ifdef CONFIG_IBSS_RSN |
| 3418 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); |
| 3419 | #endif /* CONFIG_IBSS_RSN */ |
| 3420 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3421 | case EVENT_DRIVER_GTK_REKEY: |
| 3422 | if (os_memcmp(data->driver_gtk_rekey.bssid, |
| 3423 | wpa_s->bssid, ETH_ALEN)) |
| 3424 | break; |
| 3425 | if (!wpa_s->wpa) |
| 3426 | break; |
| 3427 | wpa_sm_update_replay_ctr(wpa_s->wpa, |
| 3428 | data->driver_gtk_rekey.replay_ctr); |
| 3429 | break; |
| 3430 | case EVENT_SCHED_SCAN_STOPPED: |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3431 | wpa_s->pno = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3432 | wpa_s->sched_scanning = 0; |
| 3433 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 3434 | |
| 3435 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 3436 | break; |
| 3437 | |
| 3438 | /* |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3439 | * Start a new sched scan to continue searching for more SSIDs |
| 3440 | * either if timed out or PNO schedule scan is pending. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3441 | */ |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3442 | if (wpa_s->sched_scan_timed_out) { |
| 3443 | wpa_supplicant_req_sched_scan(wpa_s); |
| 3444 | } else if (wpa_s->pno_sched_pending) { |
| 3445 | wpa_s->pno_sched_pending = 0; |
| 3446 | wpas_start_pno(wpa_s); |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3447 | } |
| 3448 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3449 | break; |
| 3450 | case EVENT_WPS_BUTTON_PUSHED: |
| 3451 | #ifdef CONFIG_WPS |
| 3452 | wpas_wps_start_pbc(wpa_s, NULL, 0); |
| 3453 | #endif /* CONFIG_WPS */ |
| 3454 | break; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 3455 | case EVENT_AVOID_FREQUENCIES: |
| 3456 | wpa_supplicant_notify_avoid_freq(wpa_s, data); |
| 3457 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3458 | case EVENT_CONNECT_FAILED_REASON: |
| 3459 | #ifdef CONFIG_AP |
| 3460 | if (!wpa_s->ap_iface || !data) |
| 3461 | break; |
| 3462 | hostapd_event_connect_failed_reason( |
| 3463 | wpa_s->ap_iface->bss[0], |
| 3464 | data->connect_failed_reason.addr, |
| 3465 | data->connect_failed_reason.code); |
| 3466 | #endif /* CONFIG_AP */ |
| 3467 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3468 | default: |
| 3469 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
| 3470 | break; |
| 3471 | } |
| 3472 | } |