2009-03-20 21:26:41 +01:00
|
|
|
/*
|
|
|
|
* wpa_supplicant - SME
|
2010-03-13 16:14:41 +01:00
|
|
|
* Copyright (c) 2009-2010, Jouni Malinen <j@w1.fi>
|
2009-03-20 21:26:41 +01:00
|
|
|
*
|
2012-02-11 15:46:35 +01:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2009-03-20 21:26:41 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "includes.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
2010-12-19 10:58:00 +01:00
|
|
|
#include "utils/eloop.h"
|
2009-11-29 16:51:55 +01:00
|
|
|
#include "common/ieee802_11_defs.h"
|
2010-04-07 09:31:06 +02:00
|
|
|
#include "common/ieee802_11_common.h"
|
2009-03-20 21:26:41 +01:00
|
|
|
#include "eapol_supp/eapol_supp_sm.h"
|
2009-11-29 16:51:55 +01:00
|
|
|
#include "common/wpa_common.h"
|
2009-11-29 17:28:08 +01:00
|
|
|
#include "rsn_supp/wpa.h"
|
|
|
|
#include "rsn_supp/pmksa_cache.h"
|
2009-03-20 21:26:41 +01:00
|
|
|
#include "config.h"
|
|
|
|
#include "wpa_supplicant_i.h"
|
2009-03-26 19:37:05 +01:00
|
|
|
#include "driver_i.h"
|
2009-03-20 21:26:41 +01:00
|
|
|
#include "wpas_glue.h"
|
|
|
|
#include "wps_supplicant.h"
|
2010-07-18 23:30:25 +02:00
|
|
|
#include "p2p_supplicant.h"
|
2009-09-13 19:53:32 +02:00
|
|
|
#include "notify.h"
|
2010-01-02 15:16:02 +01:00
|
|
|
#include "bss.h"
|
2010-01-03 17:48:11 +01:00
|
|
|
#include "scan.h"
|
2009-03-20 21:26:41 +01:00
|
|
|
#include "sme.h"
|
2011-10-03 17:10:23 +02:00
|
|
|
#include "hs20_supplicant.h"
|
2009-03-20 21:26:41 +01:00
|
|
|
|
2011-02-24 15:59:46 +01:00
|
|
|
#define SME_AUTH_TIMEOUT 5
|
|
|
|
#define SME_ASSOC_TIMEOUT 5
|
|
|
|
|
|
|
|
static void sme_auth_timer(void *eloop_ctx, void *timeout_ctx);
|
|
|
|
static void sme_assoc_timer(void *eloop_ctx, void *timeout_ctx);
|
2012-05-03 11:13:43 +02:00
|
|
|
static void sme_obss_scan_timeout(void *eloop_ctx, void *timeout_ctx);
|
2011-02-24 15:59:46 +01:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
static void sme_stop_sa_query(struct wpa_supplicant *wpa_s);
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
|
|
|
|
2009-03-20 21:26:41 +01:00
|
|
|
void sme_authenticate(struct wpa_supplicant *wpa_s,
|
2010-01-02 15:16:02 +01:00
|
|
|
struct wpa_bss *bss, struct wpa_ssid *ssid)
|
2009-03-20 21:26:41 +01:00
|
|
|
{
|
|
|
|
struct wpa_driver_auth_params params;
|
2009-09-13 19:53:32 +02:00
|
|
|
struct wpa_ssid *old_ssid;
|
2010-01-03 12:05:54 +01:00
|
|
|
#ifdef CONFIG_IEEE80211R
|
2009-03-20 21:26:41 +01:00
|
|
|
const u8 *ie;
|
2010-01-03 12:05:54 +01:00
|
|
|
#endif /* CONFIG_IEEE80211R */
|
2009-03-20 21:26:41 +01:00
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
const u8 *md = NULL;
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
2009-09-13 19:53:32 +02:00
|
|
|
int i, bssid_changed;
|
2009-03-20 21:26:41 +01:00
|
|
|
|
|
|
|
if (bss == NULL) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_ERROR, "SME: No scan result available for "
|
|
|
|
"the network");
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-02 15:59:19 +01:00
|
|
|
wpa_s->current_bss = bss;
|
|
|
|
|
2009-03-20 21:26:41 +01:00
|
|
|
os_memset(¶ms, 0, sizeof(params));
|
|
|
|
wpa_s->reassociate = 0;
|
|
|
|
|
|
|
|
params.freq = bss->freq;
|
|
|
|
params.bssid = bss->bssid;
|
2010-01-02 15:16:02 +01:00
|
|
|
params.ssid = bss->ssid;
|
|
|
|
params.ssid_len = bss->ssid_len;
|
2011-07-17 19:25:58 +02:00
|
|
|
params.p2p = ssid->p2p_group;
|
2009-03-20 21:26:41 +01:00
|
|
|
|
2009-11-17 18:25:05 +01:00
|
|
|
if (wpa_s->sme.ssid_len != params.ssid_len ||
|
|
|
|
os_memcmp(wpa_s->sme.ssid, params.ssid, params.ssid_len) != 0)
|
|
|
|
wpa_s->sme.prev_bssid_set = 0;
|
|
|
|
|
2009-03-20 21:26:41 +01:00
|
|
|
wpa_s->sme.freq = params.freq;
|
|
|
|
os_memcpy(wpa_s->sme.ssid, params.ssid, params.ssid_len);
|
|
|
|
wpa_s->sme.ssid_len = params.ssid_len;
|
|
|
|
|
2010-01-03 20:14:40 +01:00
|
|
|
params.auth_alg = WPA_AUTH_ALG_OPEN;
|
2009-03-20 21:26:41 +01:00
|
|
|
#ifdef IEEE8021X_EAPOL
|
|
|
|
if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
|
|
|
|
if (ssid->leap) {
|
|
|
|
if (ssid->non_leap == 0)
|
2010-01-03 20:14:40 +01:00
|
|
|
params.auth_alg = WPA_AUTH_ALG_LEAP;
|
2009-03-20 21:26:41 +01:00
|
|
|
else
|
2010-01-03 20:14:40 +01:00
|
|
|
params.auth_alg |= WPA_AUTH_ALG_LEAP;
|
2009-03-20 21:26:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* IEEE8021X_EAPOL */
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x",
|
|
|
|
params.auth_alg);
|
2009-03-20 21:26:41 +01:00
|
|
|
if (ssid->auth_alg) {
|
2010-01-03 20:14:40 +01:00
|
|
|
params.auth_alg = ssid->auth_alg;
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "Overriding auth_alg selection: "
|
|
|
|
"0x%x", params.auth_alg);
|
2009-03-20 21:26:41 +01:00
|
|
|
}
|
|
|
|
|
2009-04-04 15:58:16 +02:00
|
|
|
for (i = 0; i < NUM_WEP_KEYS; i++) {
|
|
|
|
if (ssid->wep_key_len[i])
|
|
|
|
params.wep_key[i] = ssid->wep_key[i];
|
|
|
|
params.wep_key_len[i] = ssid->wep_key_len[i];
|
|
|
|
}
|
|
|
|
params.wep_tx_keyidx = ssid->wep_tx_keyidx;
|
|
|
|
|
2009-09-13 19:53:32 +02:00
|
|
|
bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
|
2009-03-20 21:26:41 +01:00
|
|
|
os_memset(wpa_s->bssid, 0, ETH_ALEN);
|
|
|
|
os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN);
|
2009-09-13 19:53:32 +02:00
|
|
|
if (bssid_changed)
|
|
|
|
wpas_notify_bssid_changed(wpa_s);
|
2009-03-20 21:26:41 +01:00
|
|
|
|
2010-01-10 20:31:54 +01:00
|
|
|
if ((wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) ||
|
|
|
|
wpa_bss_get_ie(bss, WLAN_EID_RSN)) &&
|
2011-11-24 21:46:14 +01:00
|
|
|
wpa_key_mgmt_wpa(ssid->key_mgmt)) {
|
2009-03-20 21:26:41 +01:00
|
|
|
int try_opportunistic;
|
|
|
|
try_opportunistic = ssid->proactive_key_caching &&
|
|
|
|
(ssid->proto & WPA_PROTO_RSN);
|
|
|
|
if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid,
|
|
|
|
wpa_s->current_ssid,
|
|
|
|
try_opportunistic) == 0)
|
|
|
|
eapol_sm_notify_pmkid_attempt(wpa_s->eapol, 1);
|
|
|
|
wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie);
|
|
|
|
if (wpa_supplicant_set_suites(wpa_s, bss, ssid,
|
|
|
|
wpa_s->sme.assoc_req_ie,
|
|
|
|
&wpa_s->sme.assoc_req_ie_len)) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA "
|
|
|
|
"key management and encryption suites");
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
2011-11-24 21:46:14 +01:00
|
|
|
} else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) {
|
2009-03-20 21:26:41 +01:00
|
|
|
wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie);
|
|
|
|
if (wpa_supplicant_set_suites(wpa_s, NULL, ssid,
|
|
|
|
wpa_s->sme.assoc_req_ie,
|
|
|
|
&wpa_s->sme.assoc_req_ie_len)) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA "
|
|
|
|
"key management and encryption suites (no "
|
|
|
|
"scan results)");
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_WPS
|
|
|
|
} else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) {
|
|
|
|
struct wpabuf *wps_ie;
|
|
|
|
wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid));
|
|
|
|
if (wps_ie && wpabuf_len(wps_ie) <=
|
|
|
|
sizeof(wpa_s->sme.assoc_req_ie)) {
|
|
|
|
wpa_s->sme.assoc_req_ie_len = wpabuf_len(wps_ie);
|
|
|
|
os_memcpy(wpa_s->sme.assoc_req_ie, wpabuf_head(wps_ie),
|
|
|
|
wpa_s->sme.assoc_req_ie_len);
|
|
|
|
} else
|
|
|
|
wpa_s->sme.assoc_req_ie_len = 0;
|
|
|
|
wpabuf_free(wps_ie);
|
|
|
|
wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
|
|
|
|
#endif /* CONFIG_WPS */
|
|
|
|
} else {
|
|
|
|
wpa_supplicant_set_non_wpa_policy(wpa_s, ssid);
|
|
|
|
wpa_s->sme.assoc_req_ie_len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
2010-01-02 15:16:02 +01:00
|
|
|
ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
|
2009-03-20 21:26:41 +01:00
|
|
|
if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN)
|
|
|
|
md = ie + 2;
|
2010-04-10 10:36:35 +02:00
|
|
|
wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0);
|
2009-03-20 21:26:41 +01:00
|
|
|
if (md) {
|
|
|
|
/* Prepare for the next transition */
|
2010-04-09 15:26:20 +02:00
|
|
|
wpa_ft_prepare_auth_request(wpa_s->wpa, ie);
|
2009-03-20 21:26:41 +01:00
|
|
|
}
|
|
|
|
|
2011-11-24 21:46:14 +01:00
|
|
|
if (md && wpa_key_mgmt_ft(ssid->key_mgmt)) {
|
2009-03-20 21:26:41 +01:00
|
|
|
if (wpa_s->sme.assoc_req_ie_len + 5 <
|
|
|
|
sizeof(wpa_s->sme.assoc_req_ie)) {
|
|
|
|
struct rsn_mdie *mdie;
|
|
|
|
u8 *pos = wpa_s->sme.assoc_req_ie +
|
|
|
|
wpa_s->sme.assoc_req_ie_len;
|
|
|
|
*pos++ = WLAN_EID_MOBILITY_DOMAIN;
|
|
|
|
*pos++ = sizeof(*mdie);
|
|
|
|
mdie = (struct rsn_mdie *) pos;
|
|
|
|
os_memcpy(mdie->mobility_domain, md,
|
|
|
|
MOBILITY_DOMAIN_ID_LEN);
|
2010-04-09 15:41:57 +02:00
|
|
|
mdie->ft_capab = md[MOBILITY_DOMAIN_ID_LEN];
|
2009-03-20 21:26:41 +01:00
|
|
|
wpa_s->sme.assoc_req_ie_len += 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_s->sme.ft_used &&
|
2010-04-10 21:39:49 +02:00
|
|
|
os_memcmp(md, wpa_s->sme.mobility_domain, 2) == 0 &&
|
|
|
|
wpa_sm_has_ptk(wpa_s->wpa)) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying to use FT "
|
|
|
|
"over-the-air");
|
2010-01-03 20:14:40 +01:00
|
|
|
params.auth_alg = WPA_AUTH_ALG_FT;
|
2009-03-20 21:26:41 +01:00
|
|
|
params.ie = wpa_s->sme.ft_ies;
|
|
|
|
params.ie_len = wpa_s->sme.ft_ies_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211W
|
2010-01-03 20:02:51 +01:00
|
|
|
wpa_s->sme.mfp = ssid->ieee80211w;
|
2010-01-10 20:31:54 +01:00
|
|
|
if (ssid->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
|
2010-01-02 15:16:02 +01:00
|
|
|
const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN);
|
2009-03-20 21:26:41 +01:00
|
|
|
struct wpa_ie_data _ie;
|
|
|
|
if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &_ie) == 0 &&
|
|
|
|
_ie.capabilities &
|
|
|
|
(WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected AP supports "
|
|
|
|
"MFP: require MFP");
|
2009-03-20 21:26:41 +01:00
|
|
|
wpa_s->sme.mfp = MGMT_FRAME_PROTECTION_REQUIRED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
2010-07-18 23:30:25 +02:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (wpa_s->global->p2p) {
|
|
|
|
u8 *pos;
|
|
|
|
size_t len;
|
|
|
|
int res;
|
|
|
|
pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len;
|
|
|
|
len = sizeof(wpa_s->sme.assoc_req_ie) -
|
|
|
|
wpa_s->sme.assoc_req_ie_len;
|
2011-07-17 19:52:49 +02:00
|
|
|
res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len,
|
|
|
|
ssid->p2p_group);
|
2010-07-18 23:30:25 +02:00
|
|
|
if (res >= 0)
|
|
|
|
wpa_s->sme.assoc_req_ie_len += res;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2011-10-03 17:10:23 +02:00
|
|
|
#ifdef CONFIG_HS20
|
|
|
|
if (wpa_s->conf->hs20) {
|
|
|
|
struct wpabuf *hs20;
|
|
|
|
hs20 = wpabuf_alloc(20);
|
|
|
|
if (hs20) {
|
|
|
|
wpas_hs20_add_indication(hs20);
|
|
|
|
os_memcpy(wpa_s->sme.assoc_req_ie +
|
|
|
|
wpa_s->sme.assoc_req_ie_len,
|
|
|
|
wpabuf_head(hs20), wpabuf_len(hs20));
|
|
|
|
wpa_s->sme.assoc_req_ie_len += wpabuf_len(hs20);
|
|
|
|
wpabuf_free(hs20);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_HS20 */
|
|
|
|
|
2011-10-16 18:04:46 +02:00
|
|
|
#ifdef CONFIG_INTERWORKING
|
|
|
|
if (wpa_s->conf->interworking) {
|
|
|
|
u8 *pos = wpa_s->sme.assoc_req_ie;
|
|
|
|
if (wpa_s->sme.assoc_req_ie_len > 0 && pos[0] == WLAN_EID_RSN)
|
|
|
|
pos += 2 + pos[1];
|
|
|
|
os_memmove(pos + 6, pos,
|
|
|
|
wpa_s->sme.assoc_req_ie_len -
|
|
|
|
(pos - wpa_s->sme.assoc_req_ie));
|
|
|
|
wpa_s->sme.assoc_req_ie_len += 6;
|
|
|
|
*pos++ = WLAN_EID_EXT_CAPAB;
|
|
|
|
*pos++ = 4;
|
|
|
|
*pos++ = 0x00;
|
|
|
|
*pos++ = 0x00;
|
|
|
|
*pos++ = 0x00;
|
|
|
|
*pos++ = 0x80; /* Bit 31 - Interworking */
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_INTERWORKING */
|
|
|
|
|
2011-09-27 21:21:31 +02:00
|
|
|
wpa_supplicant_cancel_sched_scan(wpa_s);
|
2009-03-20 21:26:41 +01:00
|
|
|
wpa_supplicant_cancel_scan(wpa_s);
|
|
|
|
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_INFO, "SME: Trying to authenticate with " MACSTR
|
2009-03-20 21:26:41 +01:00
|
|
|
" (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid),
|
|
|
|
wpa_ssid_txt(params.ssid, params.ssid_len), params.freq);
|
|
|
|
|
|
|
|
wpa_clear_keys(wpa_s, bss->bssid);
|
|
|
|
wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
|
2009-09-13 19:53:32 +02:00
|
|
|
old_ssid = wpa_s->current_ssid;
|
2009-03-20 21:26:41 +01:00
|
|
|
wpa_s->current_ssid = ssid;
|
|
|
|
wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
|
|
|
|
wpa_supplicant_initiate_eapol(wpa_s);
|
2009-09-13 19:53:32 +02:00
|
|
|
if (old_ssid != wpa_s->current_ssid)
|
|
|
|
wpas_notify_network_changed(wpa_s);
|
2009-03-20 21:26:41 +01:00
|
|
|
|
2010-03-13 20:13:18 +01:00
|
|
|
wpa_s->sme.auth_alg = params.auth_alg;
|
2009-03-20 21:26:41 +01:00
|
|
|
if (wpa_drv_authenticate(wpa_s, ¶ms) < 0) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_INFO, "SME: Authentication request to the "
|
2009-03-20 21:26:41 +01:00
|
|
|
"driver failed");
|
2011-12-04 20:04:24 +01:00
|
|
|
wpas_connection_failed(wpa_s, bss->bssid);
|
2012-01-29 16:44:31 +01:00
|
|
|
wpa_supplicant_mark_disassoc(wpa_s);
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-24 15:59:46 +01:00
|
|
|
eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s,
|
|
|
|
NULL);
|
2009-03-20 21:26:41 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Association will be started based on the authentication event from
|
|
|
|
* the driver.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data)
|
|
|
|
{
|
|
|
|
struct wpa_ssid *ssid = wpa_s->current_ssid;
|
|
|
|
|
|
|
|
if (ssid == NULL) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event "
|
|
|
|
"when network is not selected");
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_s->wpa_state != WPA_AUTHENTICATING) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event "
|
|
|
|
"when not in authenticating state");
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_memcmp(wpa_s->pending_bssid, data->auth.peer, ETH_ALEN) != 0) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication with "
|
|
|
|
"unexpected peer " MACSTR,
|
|
|
|
MAC2STR(data->auth.peer));
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication response: peer=" MACSTR
|
|
|
|
" auth_type=%d status_code=%d",
|
|
|
|
MAC2STR(data->auth.peer), data->auth.auth_type,
|
|
|
|
data->auth.status_code);
|
2009-03-20 21:26:41 +01:00
|
|
|
wpa_hexdump(MSG_MSGDUMP, "SME: Authentication response IEs",
|
|
|
|
data->auth.ies, data->auth.ies_len);
|
|
|
|
|
2011-02-24 15:59:46 +01:00
|
|
|
eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL);
|
|
|
|
|
2009-03-20 21:26:41 +01:00
|
|
|
if (data->auth.status_code != WLAN_STATUS_SUCCESS) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication failed (status "
|
|
|
|
"code %d)", data->auth.status_code);
|
2010-08-17 15:39:33 +02:00
|
|
|
|
|
|
|
if (data->auth.status_code !=
|
|
|
|
WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG ||
|
|
|
|
wpa_s->sme.auth_alg == data->auth.auth_type ||
|
2010-11-25 21:00:04 +01:00
|
|
|
wpa_s->current_ssid->auth_alg == WPA_AUTH_ALG_LEAP) {
|
2010-11-26 10:36:03 +01:00
|
|
|
wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
|
2010-08-17 15:39:33 +02:00
|
|
|
return;
|
2010-11-25 21:00:04 +01:00
|
|
|
}
|
2010-08-17 15:39:33 +02:00
|
|
|
|
|
|
|
switch (data->auth.auth_type) {
|
|
|
|
case WLAN_AUTH_OPEN:
|
|
|
|
wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_SHARED;
|
|
|
|
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying SHARED auth");
|
2010-08-17 15:39:33 +02:00
|
|
|
wpa_supplicant_associate(wpa_s, wpa_s->current_bss,
|
|
|
|
wpa_s->current_ssid);
|
|
|
|
return;
|
|
|
|
|
|
|
|
case WLAN_AUTH_SHARED_KEY:
|
|
|
|
wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_LEAP;
|
|
|
|
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying LEAP auth");
|
2010-08-17 15:39:33 +02:00
|
|
|
wpa_supplicant_associate(wpa_s, wpa_s->current_bss,
|
|
|
|
wpa_s->current_ssid);
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
2009-03-20 21:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
if (data->auth.auth_type == WLAN_AUTH_FT) {
|
|
|
|
union wpa_event_data edata;
|
|
|
|
os_memset(&edata, 0, sizeof(edata));
|
|
|
|
edata.ft_ies.ies = data->auth.ies;
|
|
|
|
edata.ft_ies.ies_len = data->auth.ies_len;
|
|
|
|
os_memcpy(edata.ft_ies.target_ap, data->auth.peer, ETH_ALEN);
|
|
|
|
wpa_supplicant_event(wpa_s, EVENT_FT_RESPONSE, &edata);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
|
2010-03-13 16:14:41 +01:00
|
|
|
sme_associate(wpa_s, ssid->mode, data->auth.peer,
|
|
|
|
data->auth.auth_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode,
|
|
|
|
const u8 *bssid, u16 auth_type)
|
|
|
|
{
|
|
|
|
struct wpa_driver_associate_params params;
|
2010-04-07 09:31:06 +02:00
|
|
|
struct ieee802_11_elems elems;
|
2012-01-29 20:01:31 +01:00
|
|
|
#ifdef CONFIG_HT_OVERRIDES
|
|
|
|
struct ieee80211_ht_capabilities htcaps;
|
|
|
|
struct ieee80211_ht_capabilities htcaps_mask;
|
|
|
|
#endif /* CONFIG_HT_OVERRIDES */
|
2010-03-13 16:14:41 +01:00
|
|
|
|
2009-03-20 21:26:41 +01:00
|
|
|
os_memset(¶ms, 0, sizeof(params));
|
2010-03-13 16:14:41 +01:00
|
|
|
params.bssid = bssid;
|
2009-03-20 21:26:41 +01:00
|
|
|
params.ssid = wpa_s->sme.ssid;
|
|
|
|
params.ssid_len = wpa_s->sme.ssid_len;
|
|
|
|
params.freq = wpa_s->sme.freq;
|
2012-03-30 14:20:35 +02:00
|
|
|
params.bg_scan_period = wpa_s->current_ssid ?
|
|
|
|
wpa_s->current_ssid->bg_scan_period : -1;
|
2009-03-20 21:26:41 +01:00
|
|
|
params.wpa_ie = wpa_s->sme.assoc_req_ie_len ?
|
|
|
|
wpa_s->sme.assoc_req_ie : NULL;
|
|
|
|
params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len;
|
2010-12-13 20:08:53 +01:00
|
|
|
params.pairwise_suite = cipher_suite2driver(wpa_s->pairwise_cipher);
|
|
|
|
params.group_suite = cipher_suite2driver(wpa_s->group_cipher);
|
2012-01-29 20:01:31 +01:00
|
|
|
#ifdef CONFIG_HT_OVERRIDES
|
|
|
|
os_memset(&htcaps, 0, sizeof(htcaps));
|
|
|
|
os_memset(&htcaps_mask, 0, sizeof(htcaps_mask));
|
|
|
|
params.htcaps = (u8 *) &htcaps;
|
|
|
|
params.htcaps_mask = (u8 *) &htcaps_mask;
|
|
|
|
wpa_supplicant_apply_ht_overrides(wpa_s, wpa_s->current_ssid, ¶ms);
|
|
|
|
#endif /* CONFIG_HT_OVERRIDES */
|
2009-03-20 21:26:41 +01:00
|
|
|
#ifdef CONFIG_IEEE80211R
|
2010-03-13 16:14:41 +01:00
|
|
|
if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies) {
|
2009-03-20 21:26:41 +01:00
|
|
|
params.wpa_ie = wpa_s->sme.ft_ies;
|
|
|
|
params.wpa_ie_len = wpa_s->sme.ft_ies_len;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
2010-03-13 16:14:41 +01:00
|
|
|
params.mode = mode;
|
2009-03-20 21:26:41 +01:00
|
|
|
params.mgmt_frame_protection = wpa_s->sme.mfp;
|
2009-11-17 18:25:05 +01:00
|
|
|
if (wpa_s->sme.prev_bssid_set)
|
|
|
|
params.prev_bssid = wpa_s->sme.prev_bssid;
|
2009-03-20 21:26:41 +01:00
|
|
|
|
|
|
|
wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR
|
|
|
|
" (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid),
|
|
|
|
params.ssid ? wpa_ssid_txt(params.ssid, params.ssid_len) : "",
|
|
|
|
params.freq);
|
|
|
|
|
|
|
|
wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING);
|
|
|
|
|
2010-04-11 11:19:02 +02:00
|
|
|
if (params.wpa_ie == NULL ||
|
|
|
|
ieee802_11_parse_elems(params.wpa_ie, params.wpa_ie_len, &elems, 0)
|
2010-04-07 09:31:06 +02:00
|
|
|
< 0) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Could not parse own IEs?!");
|
2010-04-07 09:31:06 +02:00
|
|
|
os_memset(&elems, 0, sizeof(elems));
|
|
|
|
}
|
2011-09-02 19:40:23 +02:00
|
|
|
if (elems.rsn_ie) {
|
|
|
|
params.wpa_proto = WPA_PROTO_RSN;
|
2010-04-07 09:31:06 +02:00
|
|
|
wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.rsn_ie - 2,
|
|
|
|
elems.rsn_ie_len + 2);
|
2011-09-02 19:40:23 +02:00
|
|
|
} else if (elems.wpa_ie) {
|
|
|
|
params.wpa_proto = WPA_PROTO_WPA;
|
2010-04-07 09:31:06 +02:00
|
|
|
wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.wpa_ie - 2,
|
|
|
|
elems.wpa_ie_len + 2);
|
2011-09-02 19:40:23 +02:00
|
|
|
} else
|
2010-04-07 09:31:06 +02:00
|
|
|
wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
|
2011-07-17 19:52:49 +02:00
|
|
|
if (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group)
|
2010-07-18 23:30:25 +02:00
|
|
|
params.p2p = 1;
|
2010-04-07 09:31:06 +02:00
|
|
|
|
2010-07-28 19:18:52 +02:00
|
|
|
if (wpa_s->parent->set_sta_uapsd)
|
|
|
|
params.uapsd = wpa_s->parent->sta_uapsd;
|
|
|
|
else
|
|
|
|
params.uapsd = -1;
|
|
|
|
|
2009-03-20 21:26:41 +01:00
|
|
|
if (wpa_drv_associate(wpa_s, ¶ms) < 0) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_INFO, "SME: Association request to the "
|
|
|
|
"driver failed");
|
2010-11-26 16:37:22 +01:00
|
|
|
wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
|
|
|
|
os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
|
2009-03-20 21:26:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-24 15:59:46 +01:00
|
|
|
eloop_register_timeout(SME_ASSOC_TIMEOUT, 0, sme_assoc_timer, wpa_s,
|
|
|
|
NULL);
|
2009-03-20 21:26:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md,
|
|
|
|
const u8 *ies, size_t ies_len)
|
|
|
|
{
|
|
|
|
if (md == NULL || ies == NULL) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Remove mobility domain");
|
2009-03-20 21:26:41 +01:00
|
|
|
os_free(wpa_s->sme.ft_ies);
|
|
|
|
wpa_s->sme.ft_ies = NULL;
|
|
|
|
wpa_s->sme.ft_ies_len = 0;
|
|
|
|
wpa_s->sme.ft_used = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memcpy(wpa_s->sme.mobility_domain, md, MOBILITY_DOMAIN_ID_LEN);
|
|
|
|
wpa_hexdump(MSG_DEBUG, "SME: FT IEs", ies, ies_len);
|
|
|
|
os_free(wpa_s->sme.ft_ies);
|
|
|
|
wpa_s->sme.ft_ies = os_malloc(ies_len);
|
|
|
|
if (wpa_s->sme.ft_ies == NULL)
|
|
|
|
return -1;
|
|
|
|
os_memcpy(wpa_s->sme.ft_ies, ies, ies_len);
|
|
|
|
wpa_s->sme.ft_ies_len = ies_len;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-04-01 16:10:36 +02:00
|
|
|
|
|
|
|
|
2011-02-24 15:59:46 +01:00
|
|
|
static void sme_deauth(struct wpa_supplicant *wpa_s)
|
2009-04-01 16:10:36 +02:00
|
|
|
{
|
2009-09-13 19:53:32 +02:00
|
|
|
int bssid_changed;
|
|
|
|
|
|
|
|
bssid_changed = !is_zero_ether_addr(wpa_s->bssid);
|
2009-10-31 22:21:43 +01:00
|
|
|
|
|
|
|
if (wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid,
|
|
|
|
WLAN_REASON_DEAUTH_LEAVING) < 0) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_INFO, "SME: Deauth request to the driver "
|
|
|
|
"failed");
|
2009-10-31 22:21:43 +01:00
|
|
|
}
|
2009-11-17 18:25:05 +01:00
|
|
|
wpa_s->sme.prev_bssid_set = 0;
|
2009-10-31 22:21:43 +01:00
|
|
|
|
2010-11-26 10:36:03 +01:00
|
|
|
wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
|
2009-10-31 22:21:43 +01:00
|
|
|
wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
|
2009-04-01 16:10:36 +02:00
|
|
|
os_memset(wpa_s->bssid, 0, ETH_ALEN);
|
|
|
|
os_memset(wpa_s->pending_bssid, 0, ETH_ALEN);
|
2009-09-13 19:53:32 +02:00
|
|
|
if (bssid_changed)
|
|
|
|
wpas_notify_bssid_changed(wpa_s);
|
2009-04-01 16:10:36 +02:00
|
|
|
}
|
2009-04-23 23:08:24 +02:00
|
|
|
|
|
|
|
|
2011-02-24 15:59:46 +01:00
|
|
|
void sme_event_assoc_reject(struct wpa_supplicant *wpa_s,
|
|
|
|
union wpa_event_data *data)
|
|
|
|
{
|
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association with " MACSTR " failed: "
|
|
|
|
"status code %d", MAC2STR(wpa_s->pending_bssid),
|
|
|
|
data->assoc_reject.status_code);
|
|
|
|
|
|
|
|
eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For now, unconditionally terminate the previous authentication. In
|
|
|
|
* theory, this should not be needed, but mac80211 gets quite confused
|
|
|
|
* if the authentication is left pending.. Some roaming cases might
|
|
|
|
* benefit from using the previous authentication, so this could be
|
|
|
|
* optimized in the future.
|
|
|
|
*/
|
|
|
|
sme_deauth(wpa_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-23 23:08:24 +02:00
|
|
|
void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s,
|
|
|
|
union wpa_event_data *data)
|
|
|
|
{
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication timed out");
|
2010-11-26 10:36:03 +01:00
|
|
|
wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
|
2012-01-29 16:44:31 +01:00
|
|
|
wpa_supplicant_mark_disassoc(wpa_s);
|
2009-04-23 23:08:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s,
|
|
|
|
union wpa_event_data *data)
|
|
|
|
{
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association timed out");
|
2010-11-26 10:36:03 +01:00
|
|
|
wpas_connection_failed(wpa_s, wpa_s->pending_bssid);
|
2009-04-23 23:08:24 +02:00
|
|
|
wpa_supplicant_mark_disassoc(wpa_s);
|
|
|
|
}
|
2009-12-02 16:26:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
void sme_event_disassoc(struct wpa_supplicant *wpa_s,
|
|
|
|
union wpa_event_data *data)
|
|
|
|
{
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Disassociation event received");
|
2011-10-22 21:45:38 +02:00
|
|
|
if (wpa_s->sme.prev_bssid_set) {
|
2009-12-02 16:26:28 +01:00
|
|
|
/*
|
|
|
|
* cfg80211/mac80211 can get into somewhat confused state if
|
|
|
|
* the AP only disassociates us and leaves us in authenticated
|
|
|
|
* state. For now, force the state to be cleared to avoid
|
|
|
|
* confusing errors if we try to associate with the AP again.
|
|
|
|
*/
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Deauthenticate to clear "
|
|
|
|
"driver state");
|
2010-08-18 20:23:26 +02:00
|
|
|
wpa_drv_deauthenticate(wpa_s, wpa_s->sme.prev_bssid,
|
2009-12-02 16:26:28 +01:00
|
|
|
WLAN_REASON_DEAUTH_LEAVING);
|
|
|
|
}
|
|
|
|
}
|
2010-12-19 10:58:00 +01:00
|
|
|
|
|
|
|
|
2011-02-24 15:59:46 +01:00
|
|
|
static void sme_auth_timer(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = eloop_ctx;
|
|
|
|
if (wpa_s->wpa_state == WPA_AUTHENTICATING) {
|
|
|
|
wpa_msg(wpa_s, MSG_DEBUG, "SME: Authentication timeout");
|
|
|
|
sme_deauth(wpa_s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sme_assoc_timer(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = eloop_ctx;
|
|
|
|
if (wpa_s->wpa_state == WPA_ASSOCIATING) {
|
|
|
|
wpa_msg(wpa_s, MSG_DEBUG, "SME: Association timeout");
|
|
|
|
sme_deauth(wpa_s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_state_changed(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
|
|
|
/* Make sure timers are cleaned up appropriately. */
|
|
|
|
if (wpa_s->wpa_state != WPA_ASSOCIATING)
|
|
|
|
eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL);
|
|
|
|
if (wpa_s->wpa_state != WPA_AUTHENTICATING)
|
|
|
|
eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_disassoc_while_authenticating(struct wpa_supplicant *wpa_s,
|
|
|
|
const u8 *prev_pending_bssid)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* mac80211-workaround to force deauth on failed auth cmd,
|
|
|
|
* requires us to remain in authenticating state to allow the
|
|
|
|
* second authentication attempt to be continued properly.
|
|
|
|
*/
|
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Allow pending authentication "
|
|
|
|
"to proceed after disconnection event");
|
|
|
|
wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
|
|
|
|
os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-arm authentication timer in case auth fails for whatever reason.
|
|
|
|
*/
|
|
|
|
eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL);
|
|
|
|
eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_deinit(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
|
|
|
os_free(wpa_s->sme.ft_ies);
|
|
|
|
wpa_s->sme.ft_ies = NULL;
|
|
|
|
wpa_s->sme.ft_ies_len = 0;
|
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
sme_stop_sa_query(wpa_s);
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
|
|
|
eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL);
|
|
|
|
eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL);
|
2012-05-03 11:13:43 +02:00
|
|
|
eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sme_send_2040_bss_coex(struct wpa_supplicant *wpa_s,
|
|
|
|
const u8 *chan_list, u8 num_channels,
|
|
|
|
u8 num_intol)
|
|
|
|
{
|
|
|
|
struct ieee80211_2040_bss_coex_ie *bc_ie;
|
|
|
|
struct ieee80211_2040_intol_chan_report *ic_report;
|
|
|
|
struct wpabuf *buf;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "SME: Send 20/40 BSS Coexistence to " MACSTR,
|
|
|
|
MAC2STR(wpa_s->bssid));
|
|
|
|
|
|
|
|
buf = wpabuf_alloc(2 + /* action.category + action_code */
|
|
|
|
sizeof(struct ieee80211_2040_bss_coex_ie) +
|
|
|
|
sizeof(struct ieee80211_2040_intol_chan_report) +
|
|
|
|
num_channels);
|
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC);
|
|
|
|
wpabuf_put_u8(buf, WLAN_PA_20_40_BSS_COEX);
|
|
|
|
|
|
|
|
bc_ie = wpabuf_put(buf, sizeof(*bc_ie));
|
|
|
|
bc_ie->element_id = WLAN_EID_20_40_BSS_COEXISTENCE;
|
|
|
|
bc_ie->length = 1;
|
|
|
|
if (num_intol)
|
|
|
|
bc_ie->coex_param |= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ;
|
|
|
|
|
|
|
|
if (num_channels > 0) {
|
|
|
|
ic_report = wpabuf_put(buf, sizeof(*ic_report));
|
|
|
|
ic_report->element_id = WLAN_EID_20_40_BSS_INTOLERANT;
|
|
|
|
ic_report->length = num_channels + 1;
|
|
|
|
ic_report->op_class = 0;
|
|
|
|
os_memcpy(wpabuf_put(buf, num_channels), chan_list,
|
|
|
|
num_channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
|
|
|
|
wpa_s->own_addr, wpa_s->bssid,
|
|
|
|
wpabuf_head(buf), wpabuf_len(buf), 0) < 0) {
|
|
|
|
wpa_msg(wpa_s, MSG_INFO,
|
|
|
|
"SME: Failed to send 20/40 BSS Coexistence frame");
|
|
|
|
}
|
|
|
|
|
|
|
|
wpabuf_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enum wpas_band - Frequency band
|
|
|
|
* @WPAS_BAND_2GHZ: 2.4 GHz ISM band
|
|
|
|
* @WPAS_BAND_5GHZ: around 5 GHz band (4.9 - 5.7 GHz)
|
|
|
|
*/
|
|
|
|
enum wpas_band {
|
|
|
|
WPAS_BAND_2GHZ,
|
|
|
|
WPAS_BAND_5GHZ,
|
|
|
|
WPAS_BAND_INVALID
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* freq_to_channel - Convert frequency into channel info
|
|
|
|
* @channel: Buffer for returning channel number
|
|
|
|
* Returns: Band (2 or 5 GHz)
|
|
|
|
*/
|
|
|
|
static enum wpas_band freq_to_channel(int freq, u8 *channel)
|
|
|
|
{
|
|
|
|
enum wpas_band band = (freq <= 2484) ? WPAS_BAND_2GHZ : WPAS_BAND_5GHZ;
|
|
|
|
u8 chan = 0;
|
|
|
|
|
|
|
|
if (freq >= 2412 && freq <= 2472)
|
|
|
|
chan = (freq - 2407) / 5;
|
|
|
|
else if (freq == 2484)
|
|
|
|
chan = 14;
|
|
|
|
else if (freq >= 5180 && freq <= 5805)
|
|
|
|
chan = (freq - 5000) / 5;
|
|
|
|
|
|
|
|
*channel = chan;
|
|
|
|
return band;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int sme_proc_obss_scan(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
|
|
|
struct wpa_bss *bss;
|
|
|
|
const u8 *ie;
|
|
|
|
u16 ht_cap;
|
|
|
|
u8 chan_list[P2P_MAX_CHANNELS], channel;
|
|
|
|
u8 num_channels = 0, num_intol = 0, i;
|
|
|
|
|
|
|
|
if (!wpa_s->sme.sched_obss_scan)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wpa_s->sme.sched_obss_scan = 0;
|
|
|
|
if (!wpa_s->current_bss || wpa_s->wpa_state != WPA_COMPLETED)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether AP uses regulatory triplet or channel triplet in
|
|
|
|
* country info. Right now the operating class of the BSS channel
|
|
|
|
* width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12),
|
|
|
|
* based on the assumption that operating class triplet is not used in
|
|
|
|
* beacon frame. If the First Channel Number/Operating Extension
|
|
|
|
* Identifier octet has a positive integer value of 201 or greater,
|
|
|
|
* then its operating class triplet.
|
|
|
|
*
|
|
|
|
* TODO: If Supported Operating Classes element is present in beacon
|
|
|
|
* frame, have to lookup operating class in Annex E and fill them in
|
|
|
|
* 2040 coex frame.
|
|
|
|
*/
|
|
|
|
ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_COUNTRY);
|
|
|
|
if (ie && (ie[1] >= 6) && (ie[5] >= 201))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
os_memset(chan_list, 0, sizeof(chan_list));
|
|
|
|
|
|
|
|
dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
|
|
|
|
/* Skip other band bss */
|
|
|
|
if (freq_to_channel(bss->freq, &channel) != WPAS_BAND_2GHZ)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ie = wpa_bss_get_ie(bss, WLAN_EID_HT_CAP);
|
|
|
|
ht_cap = (ie && (ie[1] == 26)) ? WPA_GET_LE16(ie + 2) : 0;
|
|
|
|
|
|
|
|
if (!ht_cap || (ht_cap & HT_CAP_INFO_40MHZ_INTOLERANT)) {
|
|
|
|
/* Check whether the channel is already considered */
|
|
|
|
for (i = 0; i < num_channels; i++) {
|
|
|
|
if (channel == chan_list[i])
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i != num_channels)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ht_cap & HT_CAP_INFO_40MHZ_INTOLERANT)
|
|
|
|
num_intol++;
|
|
|
|
|
|
|
|
chan_list[num_channels++] = channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sme_send_2040_bss_coex(wpa_s, chan_list, num_channels, num_intol);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 14:51:18 +02:00
|
|
|
static struct hostapd_hw_modes * get_mode(struct hostapd_hw_modes *modes,
|
|
|
|
u16 num_modes,
|
|
|
|
enum hostapd_hw_mode mode)
|
|
|
|
{
|
|
|
|
u16 i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_modes; i++) {
|
|
|
|
if (modes[i].mode == mode)
|
|
|
|
return &modes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void wpa_setband_scan_freqs_list(struct wpa_supplicant *wpa_s,
|
|
|
|
enum hostapd_hw_mode band,
|
|
|
|
struct wpa_driver_scan_params *params)
|
|
|
|
{
|
|
|
|
/* Include only supported channels for the specified band */
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
int count, i;
|
|
|
|
|
|
|
|
mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band);
|
|
|
|
if (mode == NULL) {
|
|
|
|
/* No channels supported in this band - use empty list */
|
|
|
|
params->freqs = os_zalloc(sizeof(int));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
params->freqs = os_zalloc((mode->num_channels + 1) * sizeof(int));
|
|
|
|
if (params->freqs == NULL)
|
|
|
|
return;
|
|
|
|
for (count = 0, i = 0; i < mode->num_channels; i++) {
|
|
|
|
if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED)
|
|
|
|
continue;
|
|
|
|
params->freqs[count++] = mode->channels[i].freq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 11:13:43 +02:00
|
|
|
static void sme_obss_scan_timeout(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = eloop_ctx;
|
|
|
|
struct wpa_driver_scan_params params;
|
|
|
|
|
|
|
|
if (!wpa_s->current_bss) {
|
|
|
|
wpa_printf(MSG_DEBUG, "SME OBSS: Ignore scan request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
os_memset(¶ms, 0, sizeof(params));
|
2012-05-03 14:51:18 +02:00
|
|
|
wpa_setband_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, ¶ms);
|
2012-05-03 11:13:43 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "SME OBSS: Request an OBSS scan");
|
|
|
|
|
|
|
|
if (wpa_supplicant_trigger_scan(wpa_s, ¶ms))
|
|
|
|
wpa_printf(MSG_DEBUG, "SME OBSS: Failed to trigger scan");
|
|
|
|
else
|
|
|
|
wpa_s->sme.sched_obss_scan = 1;
|
2012-05-03 14:51:18 +02:00
|
|
|
os_free(params.freqs);
|
2012-05-03 11:13:43 +02:00
|
|
|
|
|
|
|
eloop_register_timeout(wpa_s->sme.obss_scan_int, 0,
|
|
|
|
sme_obss_scan_timeout, wpa_s, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_sched_obss_scan(struct wpa_supplicant *wpa_s, int enable)
|
|
|
|
{
|
|
|
|
const u8 *ie;
|
|
|
|
struct wpa_bss *bss = wpa_s->current_bss;
|
|
|
|
struct wpa_ssid *ssid = wpa_s->current_ssid;
|
|
|
|
|
|
|
|
eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL);
|
|
|
|
wpa_s->sme.sched_obss_scan = 0;
|
|
|
|
if (!enable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || ssid == NULL ||
|
|
|
|
ssid->mode != IEEE80211_MODE_INFRA)
|
|
|
|
return; /* Not using station SME in wpa_supplicant */
|
|
|
|
|
|
|
|
if (!wpa_s->hw.modes ||
|
|
|
|
!(wpa_s->hw.modes->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
|
|
|
|
return; /* Driver does not support HT40 */
|
|
|
|
|
|
|
|
if (bss == NULL || bss->freq < 2400 || bss->freq > 2500)
|
|
|
|
return; /* Not associated on 2.4 GHz band */
|
|
|
|
|
|
|
|
/* Check whether AP supports HT40 */
|
|
|
|
ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_HT_CAP);
|
|
|
|
if (!ie || ie[1] < 2 ||
|
|
|
|
!(WPA_GET_LE16(ie + 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET))
|
|
|
|
return; /* AP does not support HT40 */
|
|
|
|
|
|
|
|
ie = wpa_bss_get_ie(wpa_s->current_bss,
|
|
|
|
WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS);
|
|
|
|
if (!ie || ie[1] < 14)
|
|
|
|
return; /* AP does not request OBSS scans */
|
|
|
|
|
|
|
|
wpa_s->sme.obss_scan_int = WPA_GET_LE16(ie + 6);
|
|
|
|
if (wpa_s->sme.obss_scan_int < 10) {
|
|
|
|
wpa_printf(MSG_DEBUG, "SME: Invalid OBSS Scan Interval %u "
|
|
|
|
"replaced with the minimum 10 sec",
|
|
|
|
wpa_s->sme.obss_scan_int);
|
|
|
|
wpa_s->sme.obss_scan_int = 10;
|
|
|
|
}
|
|
|
|
wpa_printf(MSG_DEBUG, "SME: OBSS Scan Interval %u sec",
|
|
|
|
wpa_s->sme.obss_scan_int);
|
|
|
|
eloop_register_timeout(wpa_s->sme.obss_scan_int, 0,
|
|
|
|
sme_obss_scan_timeout, wpa_s, NULL);
|
2011-02-24 15:59:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-19 10:58:00 +01:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
|
|
|
|
static const unsigned int sa_query_max_timeout = 1000;
|
|
|
|
static const unsigned int sa_query_retry_timeout = 201;
|
|
|
|
|
|
|
|
static int sme_check_sa_query_timeout(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
|
|
|
u32 tu;
|
|
|
|
struct os_time now, passed;
|
|
|
|
os_get_time(&now);
|
|
|
|
os_time_sub(&now, &wpa_s->sme.sa_query_start, &passed);
|
|
|
|
tu = (passed.sec * 1000000 + passed.usec) / 1024;
|
|
|
|
if (sa_query_max_timeout < tu) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: SA Query timed out");
|
2010-12-19 10:58:00 +01:00
|
|
|
sme_stop_sa_query(wpa_s);
|
|
|
|
wpa_supplicant_deauthenticate(
|
|
|
|
wpa_s, WLAN_REASON_PREV_AUTH_NOT_VALID);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sme_send_sa_query_req(struct wpa_supplicant *wpa_s,
|
|
|
|
const u8 *trans_id)
|
|
|
|
{
|
|
|
|
u8 req[2 + WLAN_SA_QUERY_TR_ID_LEN];
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Sending SA Query Request to "
|
|
|
|
MACSTR, MAC2STR(wpa_s->bssid));
|
2010-12-19 10:58:00 +01:00
|
|
|
wpa_hexdump(MSG_DEBUG, "SME: SA Query Transaction ID",
|
|
|
|
trans_id, WLAN_SA_QUERY_TR_ID_LEN);
|
|
|
|
req[0] = WLAN_ACTION_SA_QUERY;
|
|
|
|
req[1] = WLAN_SA_QUERY_REQUEST;
|
|
|
|
os_memcpy(req + 2, trans_id, WLAN_SA_QUERY_TR_ID_LEN);
|
2010-12-29 12:59:17 +01:00
|
|
|
if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
|
2010-12-19 10:58:00 +01:00
|
|
|
wpa_s->own_addr, wpa_s->bssid,
|
2011-10-29 20:49:46 +02:00
|
|
|
req, sizeof(req), 0) < 0)
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_msg(wpa_s, MSG_INFO, "SME: Failed to send SA Query "
|
|
|
|
"Request");
|
2010-12-19 10:58:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sme_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
|
|
|
|
{
|
|
|
|
struct wpa_supplicant *wpa_s = eloop_ctx;
|
|
|
|
unsigned int timeout, sec, usec;
|
|
|
|
u8 *trans_id, *nbuf;
|
|
|
|
|
|
|
|
if (wpa_s->sme.sa_query_count > 0 &&
|
|
|
|
sme_check_sa_query_timeout(wpa_s))
|
|
|
|
return;
|
|
|
|
|
|
|
|
nbuf = os_realloc(wpa_s->sme.sa_query_trans_id,
|
|
|
|
(wpa_s->sme.sa_query_count + 1) *
|
|
|
|
WLAN_SA_QUERY_TR_ID_LEN);
|
|
|
|
if (nbuf == NULL)
|
|
|
|
return;
|
|
|
|
if (wpa_s->sme.sa_query_count == 0) {
|
|
|
|
/* Starting a new SA Query procedure */
|
|
|
|
os_get_time(&wpa_s->sme.sa_query_start);
|
|
|
|
}
|
|
|
|
trans_id = nbuf + wpa_s->sme.sa_query_count * WLAN_SA_QUERY_TR_ID_LEN;
|
|
|
|
wpa_s->sme.sa_query_trans_id = nbuf;
|
|
|
|
wpa_s->sme.sa_query_count++;
|
|
|
|
|
|
|
|
os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
|
|
|
|
|
|
|
|
timeout = sa_query_retry_timeout;
|
|
|
|
sec = ((timeout / 1000) * 1024) / 1000;
|
|
|
|
usec = (timeout % 1000) * 1024;
|
|
|
|
eloop_register_timeout(sec, usec, sme_sa_query_timer, wpa_s, NULL);
|
|
|
|
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association SA Query attempt %d",
|
|
|
|
wpa_s->sme.sa_query_count);
|
2010-12-19 10:58:00 +01:00
|
|
|
|
|
|
|
sme_send_sa_query_req(wpa_s, trans_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void sme_start_sa_query(struct wpa_supplicant *wpa_s)
|
|
|
|
{
|
|
|
|
sme_sa_query_timer(wpa_s, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-18 20:53:36 +01:00
|
|
|
static void sme_stop_sa_query(struct wpa_supplicant *wpa_s)
|
2010-12-19 10:58:00 +01:00
|
|
|
{
|
|
|
|
eloop_cancel_timeout(sme_sa_query_timer, wpa_s, NULL);
|
|
|
|
os_free(wpa_s->sme.sa_query_trans_id);
|
|
|
|
wpa_s->sme.sa_query_trans_id = NULL;
|
|
|
|
wpa_s->sme.sa_query_count = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_event_unprot_disconnect(struct wpa_supplicant *wpa_s, const u8 *sa,
|
|
|
|
const u8 *da, u16 reason_code)
|
|
|
|
{
|
|
|
|
struct wpa_ssid *ssid;
|
|
|
|
|
|
|
|
if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))
|
|
|
|
return;
|
|
|
|
if (wpa_s->wpa_state != WPA_COMPLETED)
|
|
|
|
return;
|
|
|
|
ssid = wpa_s->current_ssid;
|
|
|
|
if (ssid == NULL || ssid->ieee80211w == 0)
|
|
|
|
return;
|
|
|
|
if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0)
|
|
|
|
return;
|
|
|
|
if (reason_code != WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA &&
|
|
|
|
reason_code != WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA)
|
|
|
|
return;
|
|
|
|
if (wpa_s->sme.sa_query_count > 0)
|
|
|
|
return;
|
|
|
|
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Unprotected disconnect dropped - "
|
|
|
|
"possible AP/STA state mismatch - trigger SA Query");
|
2010-12-19 10:58:00 +01:00
|
|
|
sme_start_sa_query(wpa_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void sme_sa_query_rx(struct wpa_supplicant *wpa_s, const u8 *sa,
|
|
|
|
const u8 *data, size_t len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (wpa_s->sme.sa_query_trans_id == NULL ||
|
|
|
|
len < 1 + WLAN_SA_QUERY_TR_ID_LEN ||
|
|
|
|
data[0] != WLAN_SA_QUERY_RESPONSE)
|
|
|
|
return;
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Received SA Query response from "
|
|
|
|
MACSTR " (trans_id %02x%02x)", MAC2STR(sa), data[1], data[2]);
|
2010-12-19 10:58:00 +01:00
|
|
|
|
|
|
|
if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < wpa_s->sme.sa_query_count; i++) {
|
|
|
|
if (os_memcmp(wpa_s->sme.sa_query_trans_id +
|
|
|
|
i * WLAN_SA_QUERY_TR_ID_LEN,
|
|
|
|
data + 1, WLAN_SA_QUERY_TR_ID_LEN) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i >= wpa_s->sme.sa_query_count) {
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: No matching SA Query "
|
|
|
|
"transaction identifier found");
|
2010-12-19 10:58:00 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-10 19:14:46 +01:00
|
|
|
wpa_dbg(wpa_s, MSG_DEBUG, "SME: Reply to pending SA Query received "
|
|
|
|
"from " MACSTR, MAC2STR(sa));
|
2010-12-19 10:58:00 +01:00
|
|
|
sme_stop_sa_query(wpa_s);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|