2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* hostapd / IEEE 802.11 Management
|
2011-08-28 22:07:02 +02:00
|
|
|
* Copyright (c) 2002-2011, Jouni Malinen <j@w1.fi>
|
2008-02-28 02:34:43 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of BSD
|
|
|
|
* license.
|
|
|
|
*
|
|
|
|
* See README and COPYING for more details.
|
|
|
|
*/
|
|
|
|
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "utils/includes.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_NATIVE_WINDOWS
|
|
|
|
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
2009-11-29 22:04:43 +01:00
|
|
|
#include "crypto/crypto.h"
|
2009-12-24 23:35:10 +01:00
|
|
|
#include "drivers/driver.h"
|
2009-12-25 23:31:51 +01:00
|
|
|
#include "common/ieee802_11_defs.h"
|
|
|
|
#include "common/ieee802_11_common.h"
|
2009-11-29 22:04:43 +01:00
|
|
|
#include "common/wpa_ctrl.h"
|
|
|
|
#include "radius/radius.h"
|
|
|
|
#include "radius/radius_client.h"
|
2010-07-18 23:30:25 +02:00
|
|
|
#include "p2p/p2p.h"
|
2010-05-26 17:46:08 +02:00
|
|
|
#include "wps/wps.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "hostapd.h"
|
|
|
|
#include "beacon.h"
|
|
|
|
#include "ieee802_11_auth.h"
|
|
|
|
#include "sta_info.h"
|
|
|
|
#include "ieee802_1x.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "wpa_auth.h"
|
2009-12-25 00:12:50 +01:00
|
|
|
#include "wmm.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
#include "ap_list.h"
|
|
|
|
#include "accounting.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "ap_config.h"
|
|
|
|
#include "ap_mlme.h"
|
2010-10-08 17:16:07 +02:00
|
|
|
#include "p2p_hostapd.h"
|
2010-11-24 14:19:50 +01:00
|
|
|
#include "ap_drv_ops.h"
|
2009-12-25 23:05:40 +01:00
|
|
|
#include "ieee802_11.h"
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid)
|
|
|
|
{
|
|
|
|
u8 *pos = eid;
|
|
|
|
int i, num, count;
|
|
|
|
|
|
|
|
if (hapd->iface->current_rates == NULL)
|
|
|
|
return eid;
|
|
|
|
|
|
|
|
*pos++ = WLAN_EID_SUPP_RATES;
|
|
|
|
num = hapd->iface->num_rates;
|
2011-02-09 14:08:47 +01:00
|
|
|
if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
|
|
|
|
num++;
|
2008-02-28 02:34:43 +01:00
|
|
|
if (num > 8) {
|
|
|
|
/* rest of the rates are encoded in Extended supported
|
|
|
|
* rates element */
|
|
|
|
num = 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pos++ = num;
|
|
|
|
count = 0;
|
|
|
|
for (i = 0, count = 0; i < hapd->iface->num_rates && count < num;
|
|
|
|
i++) {
|
|
|
|
count++;
|
|
|
|
*pos = hapd->iface->current_rates[i].rate / 5;
|
|
|
|
if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
|
|
|
|
*pos |= 0x80;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
2011-02-09 14:08:47 +01:00
|
|
|
if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
|
|
|
|
hapd->iface->num_rates < 8)
|
|
|
|
*pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid)
|
|
|
|
{
|
|
|
|
u8 *pos = eid;
|
|
|
|
int i, num, count;
|
|
|
|
|
|
|
|
if (hapd->iface->current_rates == NULL)
|
|
|
|
return eid;
|
|
|
|
|
|
|
|
num = hapd->iface->num_rates;
|
2011-02-09 14:08:47 +01:00
|
|
|
if (hapd->iconf->ieee80211n && hapd->iconf->require_ht)
|
|
|
|
num++;
|
2008-02-28 02:34:43 +01:00
|
|
|
if (num <= 8)
|
|
|
|
return eid;
|
|
|
|
num -= 8;
|
|
|
|
|
|
|
|
*pos++ = WLAN_EID_EXT_SUPP_RATES;
|
|
|
|
*pos++ = num;
|
|
|
|
count = 0;
|
|
|
|
for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8;
|
|
|
|
i++) {
|
|
|
|
count++;
|
|
|
|
if (count <= 8)
|
|
|
|
continue; /* already in SuppRates IE */
|
|
|
|
*pos = hapd->iface->current_rates[i].rate / 5;
|
|
|
|
if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC)
|
|
|
|
*pos |= 0x80;
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
|
2011-02-09 14:08:47 +01:00
|
|
|
if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
|
|
|
|
hapd->iface->num_rates >= 8)
|
|
|
|
*pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
u16 hostapd_own_capab_info(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
int probe)
|
|
|
|
{
|
|
|
|
int capab = WLAN_CAPABILITY_ESS;
|
|
|
|
int privacy;
|
|
|
|
|
|
|
|
if (hapd->iface->num_sta_no_short_preamble == 0 &&
|
|
|
|
hapd->iconf->preamble == SHORT_PREAMBLE)
|
|
|
|
capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
|
|
|
|
|
|
|
|
privacy = hapd->conf->ssid.wep.keys_set;
|
|
|
|
|
|
|
|
if (hapd->conf->ieee802_1x &&
|
|
|
|
(hapd->conf->default_wep_key_len ||
|
|
|
|
hapd->conf->individual_wep_key_len))
|
|
|
|
privacy = 1;
|
|
|
|
|
|
|
|
if (hapd->conf->wpa)
|
|
|
|
privacy = 1;
|
|
|
|
|
|
|
|
if (sta) {
|
|
|
|
int policy, def_klen;
|
|
|
|
if (probe && sta->ssid_probe) {
|
|
|
|
policy = sta->ssid_probe->security_policy;
|
|
|
|
def_klen = sta->ssid_probe->wep.default_len;
|
|
|
|
} else {
|
|
|
|
policy = sta->ssid->security_policy;
|
|
|
|
def_klen = sta->ssid->wep.default_len;
|
|
|
|
}
|
|
|
|
privacy = policy != SECURITY_PLAINTEXT;
|
|
|
|
if (policy == SECURITY_IEEE_802_1X && def_klen == 0)
|
|
|
|
privacy = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (privacy)
|
|
|
|
capab |= WLAN_CAPABILITY_PRIVACY;
|
|
|
|
|
|
|
|
if (hapd->iface->current_mode &&
|
|
|
|
hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G &&
|
|
|
|
hapd->iface->num_sta_no_short_slot_time == 0)
|
|
|
|
capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
|
|
|
|
|
|
|
|
return capab;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ieee802_11_print_ssid(char *buf, const u8 *ssid, u8 len)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (len > HOSTAPD_MAX_SSID_LEN)
|
|
|
|
len = HOSTAPD_MAX_SSID_LEN;
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (ssid[i] >= 32 && ssid[i] < 127)
|
|
|
|
buf[i] = ssid[i];
|
|
|
|
else
|
|
|
|
buf[i] = '.';
|
|
|
|
}
|
|
|
|
buf[len] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta,
|
2009-12-13 22:25:30 +01:00
|
|
|
u16 auth_transaction, const u8 *challenge,
|
|
|
|
int iswep)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"authentication (shared key, transaction %d)",
|
|
|
|
auth_transaction);
|
|
|
|
|
|
|
|
if (auth_transaction == 1) {
|
|
|
|
if (!sta->challenge) {
|
|
|
|
/* Generate a pseudo-random challenge */
|
|
|
|
u8 key[8];
|
2011-04-11 17:33:48 +02:00
|
|
|
struct os_time now;
|
2008-02-28 02:34:43 +01:00
|
|
|
int r;
|
|
|
|
sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN);
|
|
|
|
if (sta->challenge == NULL)
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
|
2011-04-11 17:33:48 +02:00
|
|
|
os_get_time(&now);
|
|
|
|
r = os_random();
|
|
|
|
os_memcpy(key, &now.sec, 4);
|
2008-02-28 02:34:43 +01:00
|
|
|
os_memcpy(key + 4, &r, 4);
|
2009-08-16 18:57:50 +02:00
|
|
|
rc4_skip(key, sizeof(key), 0,
|
|
|
|
sta->challenge, WLAN_AUTH_CHALLENGE_LEN);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auth_transaction != 3)
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
|
|
|
|
/* Transaction 3 */
|
|
|
|
if (!iswep || !sta->challenge || !challenge ||
|
|
|
|
os_memcmp(sta->challenge, challenge, WLAN_AUTH_CHALLENGE_LEN)) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO,
|
|
|
|
"shared key authentication - invalid "
|
|
|
|
"challenge-response");
|
|
|
|
return WLAN_STATUS_CHALLENGE_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"authentication OK (shared key)");
|
|
|
|
#ifdef IEEE80211_REQUIRE_AUTH_ACK
|
|
|
|
/* Station will be marked authenticated if it ACKs the
|
|
|
|
* authentication reply. */
|
|
|
|
#else
|
|
|
|
sta->flags |= WLAN_STA_AUTH;
|
|
|
|
wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
|
|
|
|
#endif
|
|
|
|
os_free(sta->challenge);
|
|
|
|
sta->challenge = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void send_auth_reply(struct hostapd_data *hapd,
|
|
|
|
const u8 *dst, const u8 *bssid,
|
|
|
|
u16 auth_alg, u16 auth_transaction, u16 resp,
|
|
|
|
const u8 *ies, size_t ies_len)
|
|
|
|
{
|
|
|
|
struct ieee80211_mgmt *reply;
|
|
|
|
u8 *buf;
|
|
|
|
size_t rlen;
|
|
|
|
|
|
|
|
rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len;
|
|
|
|
buf = os_zalloc(rlen);
|
|
|
|
if (buf == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
reply = (struct ieee80211_mgmt *) buf;
|
|
|
|
reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
|
|
|
|
WLAN_FC_STYPE_AUTH);
|
|
|
|
os_memcpy(reply->da, dst, ETH_ALEN);
|
|
|
|
os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
|
|
|
|
os_memcpy(reply->bssid, bssid, ETH_ALEN);
|
|
|
|
|
|
|
|
reply->u.auth.auth_alg = host_to_le16(auth_alg);
|
|
|
|
reply->u.auth.auth_transaction = host_to_le16(auth_transaction);
|
|
|
|
reply->u.auth.status_code = host_to_le16(resp);
|
|
|
|
|
|
|
|
if (ies && ies_len)
|
|
|
|
os_memcpy(reply->u.auth.variable, ies, ies_len);
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR
|
|
|
|
" auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu)",
|
|
|
|
MAC2STR(dst), auth_alg, auth_transaction,
|
|
|
|
resp, (unsigned long) ies_len);
|
2011-11-19 18:02:05 +01:00
|
|
|
if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0)
|
2008-02-28 02:34:43 +01:00
|
|
|
perror("send_auth_reply: send");
|
|
|
|
|
|
|
|
os_free(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid,
|
|
|
|
u16 auth_transaction, u16 status,
|
|
|
|
const u8 *ies, size_t ies_len)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = ctx;
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, auth_transaction,
|
|
|
|
status, ies, ies_len);
|
|
|
|
|
|
|
|
if (status != WLAN_STATUS_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, dst);
|
|
|
|
if (sta == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
|
|
|
|
sta->flags |= WLAN_STA_AUTH;
|
|
|
|
mlme_authenticate_indication(hapd, sta);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
|
|
|
|
|
2009-12-13 22:25:30 +01:00
|
|
|
static void handle_auth(struct hostapd_data *hapd,
|
|
|
|
const struct ieee80211_mgmt *mgmt, size_t len)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
u16 auth_alg, auth_transaction, status_code;
|
|
|
|
u16 resp = WLAN_STATUS_SUCCESS;
|
|
|
|
struct sta_info *sta = NULL;
|
|
|
|
int res;
|
|
|
|
u16 fc;
|
2009-12-13 22:25:30 +01:00
|
|
|
const u8 *challenge = NULL;
|
2008-02-28 02:34:43 +01:00
|
|
|
u32 session_timeout, acct_interim_interval;
|
|
|
|
int vlan_id = 0;
|
|
|
|
u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
|
|
|
|
size_t resp_ies_len = 0;
|
|
|
|
|
|
|
|
if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
|
|
|
|
printf("handle_auth - too short payload (len=%lu)\n",
|
|
|
|
(unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
|
|
|
|
auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
|
|
|
|
status_code = le_to_host16(mgmt->u.auth.status_code);
|
|
|
|
fc = le_to_host16(mgmt->frame_control);
|
|
|
|
|
|
|
|
if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) +
|
|
|
|
2 + WLAN_AUTH_CHALLENGE_LEN &&
|
|
|
|
mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE &&
|
|
|
|
mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN)
|
|
|
|
challenge = &mgmt->u.auth.variable[2];
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d "
|
|
|
|
"auth_transaction=%d status_code=%d wep=%d%s",
|
|
|
|
MAC2STR(mgmt->sa), auth_alg, auth_transaction,
|
|
|
|
status_code, !!(fc & WLAN_FC_ISWEP),
|
|
|
|
challenge ? " challenge" : "");
|
|
|
|
|
|
|
|
if (hapd->tkip_countermeasures) {
|
|
|
|
resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) &&
|
|
|
|
auth_alg == WLAN_AUTH_OPEN) ||
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
2011-11-24 21:46:14 +01:00
|
|
|
(hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) &&
|
2008-02-28 02:34:43 +01:00
|
|
|
auth_alg == WLAN_AUTH_FT) ||
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) &&
|
|
|
|
auth_alg == WLAN_AUTH_SHARED_KEY))) {
|
|
|
|
printf("Unsupported authentication algorithm (%d)\n",
|
|
|
|
auth_alg);
|
|
|
|
resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(auth_transaction == 1 ||
|
|
|
|
(auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) {
|
|
|
|
printf("Unknown authentication transaction number (%d)\n",
|
|
|
|
auth_transaction);
|
|
|
|
resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) {
|
|
|
|
printf("Station " MACSTR " not allowed to authenticate.\n",
|
|
|
|
MAC2STR(mgmt->sa));
|
|
|
|
resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = hostapd_allowed_address(hapd, mgmt->sa, (u8 *) mgmt, len,
|
|
|
|
&session_timeout,
|
|
|
|
&acct_interim_interval, &vlan_id);
|
|
|
|
if (res == HOSTAPD_ACL_REJECT) {
|
|
|
|
printf("Station " MACSTR " not allowed to authenticate.\n",
|
|
|
|
MAC2STR(mgmt->sa));
|
|
|
|
resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
if (res == HOSTAPD_ACL_PENDING) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
|
|
|
|
" waiting for an external authentication",
|
|
|
|
MAC2STR(mgmt->sa));
|
|
|
|
/* Authentication code will re-send the authentication frame
|
|
|
|
* after it has received (and cached) information from the
|
|
|
|
* external source. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sta = ap_sta_add(hapd, mgmt->sa);
|
|
|
|
if (!sta) {
|
|
|
|
resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vlan_id > 0) {
|
|
|
|
if (hostapd_get_vlan_id_ifname(hapd->conf->vlan,
|
2009-09-30 19:44:04 +02:00
|
|
|
vlan_id) == NULL) {
|
2008-02-28 02:34:43 +01:00
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
|
|
|
|
HOSTAPD_LEVEL_INFO, "Invalid VLAN ID "
|
|
|
|
"%d received from RADIUS server",
|
|
|
|
vlan_id);
|
|
|
|
resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
sta->vlan_id = vlan_id;
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS,
|
|
|
|
HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
sta->flags &= ~WLAN_STA_PREAUTH;
|
|
|
|
ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
|
|
|
|
|
2009-11-28 22:03:20 +01:00
|
|
|
if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval)
|
2008-02-28 02:34:43 +01:00
|
|
|
sta->acct_interim_interval = acct_interim_interval;
|
|
|
|
if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT)
|
|
|
|
ap_sta_session_timeout(hapd, sta, session_timeout);
|
|
|
|
else
|
|
|
|
ap_sta_no_session_timeout(hapd, sta);
|
|
|
|
|
|
|
|
switch (auth_alg) {
|
|
|
|
case WLAN_AUTH_OPEN:
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"authentication OK (open system)");
|
|
|
|
#ifdef IEEE80211_REQUIRE_AUTH_ACK
|
|
|
|
/* Station will be marked authenticated if it ACKs the
|
|
|
|
* authentication reply. */
|
|
|
|
#else
|
|
|
|
sta->flags |= WLAN_STA_AUTH;
|
|
|
|
wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
|
|
|
|
sta->auth_alg = WLAN_AUTH_OPEN;
|
|
|
|
mlme_authenticate_indication(hapd, sta);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case WLAN_AUTH_SHARED_KEY:
|
|
|
|
resp = auth_shared_key(hapd, sta, auth_transaction, challenge,
|
|
|
|
fc & WLAN_FC_ISWEP);
|
|
|
|
sta->auth_alg = WLAN_AUTH_SHARED_KEY;
|
|
|
|
mlme_authenticate_indication(hapd, sta);
|
|
|
|
if (sta->challenge && auth_transaction == 1) {
|
|
|
|
resp_ies[0] = WLAN_EID_CHALLENGE;
|
|
|
|
resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN;
|
|
|
|
os_memcpy(resp_ies + 2, sta->challenge,
|
|
|
|
WLAN_AUTH_CHALLENGE_LEN);
|
|
|
|
resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
case WLAN_AUTH_FT:
|
|
|
|
sta->auth_alg = WLAN_AUTH_FT;
|
|
|
|
if (sta->wpa_sm == NULL)
|
|
|
|
sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
|
|
|
|
sta->addr);
|
|
|
|
if (sta->wpa_sm == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
|
|
|
|
"state machine");
|
|
|
|
resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid,
|
|
|
|
auth_transaction, mgmt->u.auth.variable,
|
|
|
|
len - IEEE80211_HDRLEN -
|
|
|
|
sizeof(mgmt->u.auth),
|
|
|
|
handle_auth_ft_finish, hapd);
|
|
|
|
/* handle_auth_ft_finish() callback will complete auth. */
|
|
|
|
return;
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg,
|
|
|
|
auth_transaction + 1, resp, resp_ies, resp_ies_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-25 14:35:00 +01:00
|
|
|
static int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta)
|
|
|
|
{
|
2009-03-25 14:54:25 +01:00
|
|
|
int i, j = 32, aid;
|
|
|
|
|
2009-03-25 14:35:00 +01:00
|
|
|
/* get a unique AID */
|
|
|
|
if (sta->aid > 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, " old AID %d", sta->aid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-25 14:54:25 +01:00
|
|
|
for (i = 0; i < AID_WORDS; i++) {
|
|
|
|
if (hapd->sta_aid[i] == (u32) -1)
|
|
|
|
continue;
|
|
|
|
for (j = 0; j < 32; j++) {
|
|
|
|
if (!(hapd->sta_aid[i] & BIT(j)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (j < 32)
|
2009-03-25 14:35:00 +01:00
|
|
|
break;
|
|
|
|
}
|
2009-03-25 14:54:25 +01:00
|
|
|
if (j == 32)
|
|
|
|
return -1;
|
|
|
|
aid = i * 32 + j + 1;
|
|
|
|
if (aid > 2007)
|
|
|
|
return -1;
|
2009-03-25 14:35:00 +01:00
|
|
|
|
2009-03-25 14:54:25 +01:00
|
|
|
sta->aid = aid;
|
|
|
|
hapd->sta_aid[i] |= BIT(j);
|
2009-03-25 14:35:00 +01:00
|
|
|
wpa_printf(MSG_DEBUG, " new AID %d", sta->aid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
const u8 *ssid_ie, size_t ssid_ie_len)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2009-11-29 21:14:57 +01:00
|
|
|
if (ssid_ie == NULL)
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
if (ssid_ie_len != hapd->conf->ssid.ssid_len ||
|
|
|
|
os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) {
|
|
|
|
char ssid_txt[33];
|
|
|
|
ieee802_11_print_ssid(ssid_txt, ssid_ie, ssid_ie_len);
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO,
|
|
|
|
"Station tried to associate with unknown SSID "
|
|
|
|
"'%s'", ssid_txt);
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
2008-02-28 02:54:06 +01:00
|
|
|
}
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
return WLAN_STATUS_SUCCESS;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
const u8 *wmm_ie, size_t wmm_ie_len)
|
|
|
|
{
|
2009-03-04 11:33:24 +01:00
|
|
|
sta->flags &= ~WLAN_STA_WMM;
|
2009-11-29 21:14:57 +01:00
|
|
|
if (wmm_ie && hapd->conf->wmm_enabled) {
|
|
|
|
if (hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len))
|
2008-02-28 02:34:43 +01:00
|
|
|
hostapd_logger(hapd, sta->addr,
|
|
|
|
HOSTAPD_MODULE_WPA,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
2009-03-04 11:33:24 +01:00
|
|
|
"invalid WMM element in association "
|
2008-02-28 02:34:43 +01:00
|
|
|
"request");
|
|
|
|
else
|
2009-03-04 11:33:24 +01:00
|
|
|
sta->flags |= WLAN_STA_WMM;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2009-11-29 21:14:57 +01:00
|
|
|
return WLAN_STATUS_SUCCESS;
|
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
|
|
|
|
static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
struct ieee802_11_elems *elems)
|
|
|
|
{
|
|
|
|
if (!elems->supp_rates) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
2008-02-28 02:34:43 +01:00
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"No supported rates element in AssocReq");
|
2009-11-29 21:14:57 +01:00
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
if (elems->supp_rates_len > sizeof(sta->supported_rates)) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
2008-02-28 02:34:43 +01:00
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"Invalid supported rates element length %d",
|
2009-11-29 21:14:57 +01:00
|
|
|
elems->supp_rates_len);
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
|
2009-11-29 21:14:57 +01:00
|
|
|
os_memcpy(sta->supported_rates, elems->supp_rates,
|
|
|
|
elems->supp_rates_len);
|
|
|
|
sta->supported_rates_len = elems->supp_rates_len;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
if (elems->ext_supp_rates) {
|
|
|
|
if (elems->supp_rates_len + elems->ext_supp_rates_len >
|
2008-02-28 02:34:43 +01:00
|
|
|
sizeof(sta->supported_rates)) {
|
2009-11-29 21:14:57 +01:00
|
|
|
hostapd_logger(hapd, sta->addr,
|
2008-02-28 02:34:43 +01:00
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"Invalid supported rates element length"
|
2009-11-29 21:14:57 +01:00
|
|
|
" %d+%d", elems->supp_rates_len,
|
|
|
|
elems->ext_supp_rates_len);
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
os_memcpy(sta->supported_rates + elems->supp_rates_len,
|
|
|
|
elems->ext_supp_rates, elems->ext_supp_rates_len);
|
|
|
|
sta->supported_rates_len += elems->ext_supp_rates_len;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
return WLAN_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta,
|
2009-12-13 22:25:30 +01:00
|
|
|
const u8 *ies, size_t ies_len, int reassoc)
|
2009-11-29 21:14:57 +01:00
|
|
|
{
|
|
|
|
struct ieee802_11_elems elems;
|
|
|
|
u16 resp;
|
2009-12-13 22:11:11 +01:00
|
|
|
const u8 *wpa_ie;
|
2009-11-29 21:14:57 +01:00
|
|
|
size_t wpa_ie_len;
|
|
|
|
|
|
|
|
if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "Station sent an invalid "
|
|
|
|
"association request");
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len);
|
|
|
|
if (resp != WLAN_STATUS_SUCCESS)
|
|
|
|
return resp;
|
|
|
|
resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len);
|
|
|
|
if (resp != WLAN_STATUS_SUCCESS)
|
|
|
|
return resp;
|
|
|
|
resp = copy_supp_rates(hapd, sta, &elems);
|
|
|
|
if (resp != WLAN_STATUS_SUCCESS)
|
|
|
|
return resp;
|
2009-12-06 18:41:47 +01:00
|
|
|
#ifdef CONFIG_IEEE80211N
|
2011-02-21 16:27:16 +01:00
|
|
|
resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities,
|
2009-11-29 21:14:57 +01:00
|
|
|
elems.ht_capabilities_len);
|
|
|
|
if (resp != WLAN_STATUS_SUCCESS)
|
|
|
|
return resp;
|
2011-02-09 14:08:47 +01:00
|
|
|
if (hapd->iconf->ieee80211n && hapd->iconf->require_ht &&
|
|
|
|
!(sta->flags & WLAN_STA_HT)) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "Station does not support "
|
|
|
|
"mandatory HT PHY - reject association");
|
|
|
|
return WLAN_STATUS_ASSOC_DENIED_NO_HT;
|
|
|
|
}
|
2009-12-06 18:41:47 +01:00
|
|
|
#endif /* CONFIG_IEEE80211N */
|
2009-11-29 21:14:57 +01:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) {
|
|
|
|
wpa_ie = elems.rsn_ie;
|
|
|
|
wpa_ie_len = elems.rsn_ie_len;
|
|
|
|
} else if ((hapd->conf->wpa & WPA_PROTO_WPA) &&
|
|
|
|
elems.wpa_ie) {
|
|
|
|
wpa_ie = elems.wpa_ie;
|
|
|
|
wpa_ie_len = elems.wpa_ie_len;
|
|
|
|
} else {
|
|
|
|
wpa_ie = NULL;
|
|
|
|
wpa_ie_len = 0;
|
|
|
|
}
|
2009-11-29 21:14:57 +01:00
|
|
|
|
2008-11-23 18:34:26 +01:00
|
|
|
#ifdef CONFIG_WPS
|
2011-08-28 18:16:59 +02:00
|
|
|
sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
|
2010-04-15 11:55:34 +02:00
|
|
|
if (hapd->conf->wps_state && elems.wps_ie) {
|
|
|
|
wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association "
|
|
|
|
"Request - assume WPS is used");
|
|
|
|
sta->flags |= WLAN_STA_WPS;
|
|
|
|
wpabuf_free(sta->wps_ie);
|
2010-05-26 17:17:13 +02:00
|
|
|
sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
|
|
|
|
WPS_IE_VENDOR_TYPE);
|
2011-08-28 18:16:59 +02:00
|
|
|
if (sta->wps_ie && wps_is_20(sta->wps_ie)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0");
|
|
|
|
sta->flags |= WLAN_STA_WPS2;
|
|
|
|
}
|
2010-04-15 11:55:34 +02:00
|
|
|
wpa_ie = NULL;
|
|
|
|
wpa_ie_len = 0;
|
2010-05-26 16:16:14 +02:00
|
|
|
if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in "
|
|
|
|
"(Re)Association Request - reject");
|
|
|
|
return WLAN_STATUS_INVALID_IE;
|
|
|
|
}
|
2010-04-15 11:55:34 +02:00
|
|
|
} else if (hapd->conf->wps_state && wpa_ie == NULL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in "
|
|
|
|
"(Re)Association Request - possible WPS use");
|
|
|
|
sta->flags |= WLAN_STA_MAYBE_WPS;
|
2008-11-23 18:34:26 +01:00
|
|
|
} else
|
|
|
|
#endif /* CONFIG_WPS */
|
2008-02-28 02:34:43 +01:00
|
|
|
if (hapd->conf->wpa && wpa_ie == NULL) {
|
2009-11-29 21:14:57 +01:00
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO,
|
|
|
|
"No WPA/RSN IE in association request");
|
|
|
|
return WLAN_STATUS_INVALID_IE;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hapd->conf->wpa && wpa_ie) {
|
|
|
|
int res;
|
|
|
|
wpa_ie -= 2;
|
|
|
|
wpa_ie_len += 2;
|
|
|
|
if (sta->wpa_sm == NULL)
|
|
|
|
sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
|
|
|
|
sta->addr);
|
|
|
|
if (sta->wpa_sm == NULL) {
|
2009-11-29 21:14:57 +01:00
|
|
|
wpa_printf(MSG_WARNING, "Failed to initialize WPA "
|
|
|
|
"state machine");
|
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
|
|
|
|
wpa_ie, wpa_ie_len,
|
|
|
|
elems.mdie, elems.mdie_len);
|
|
|
|
if (res == WPA_INVALID_GROUP)
|
|
|
|
resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
|
|
|
|
else if (res == WPA_INVALID_PAIRWISE)
|
|
|
|
resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
|
|
|
|
else if (res == WPA_INVALID_AKMP)
|
|
|
|
resp = WLAN_STATUS_AKMP_NOT_VALID;
|
|
|
|
else if (res == WPA_ALLOC_FAIL)
|
|
|
|
resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
|
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION)
|
2008-12-26 10:25:05 +01:00
|
|
|
resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
|
2008-02-28 02:34:43 +01:00
|
|
|
else if (res == WPA_INVALID_MGMT_GROUP_CIPHER)
|
2008-12-26 10:25:05 +01:00
|
|
|
resp = WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION;
|
2008-02-28 02:34:43 +01:00
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
else if (res == WPA_INVALID_MDIE)
|
|
|
|
resp = WLAN_STATUS_INVALID_MDIE;
|
|
|
|
else if (res != WPA_IE_OK)
|
|
|
|
resp = WLAN_STATUS_INVALID_IE;
|
|
|
|
if (resp != WLAN_STATUS_SUCCESS)
|
2009-11-29 21:14:57 +01:00
|
|
|
return resp;
|
2008-06-17 10:21:11 +02:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
2008-12-26 11:30:34 +01:00
|
|
|
if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
|
|
|
|
sta->sa_query_count > 0)
|
|
|
|
ap_check_sa_query_timeout(hapd, sta);
|
2008-12-26 11:55:35 +01:00
|
|
|
if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
|
|
|
|
(!reassoc || sta->auth_alg != WLAN_AUTH_FT)) {
|
2008-08-31 10:04:47 +02:00
|
|
|
/*
|
2008-12-26 10:46:21 +01:00
|
|
|
* STA has already been associated with MFP and SA
|
|
|
|
* Query timeout has not been reached. Reject the
|
|
|
|
* association attempt temporarily and start SA Query,
|
|
|
|
* if one is not pending.
|
2008-08-31 10:04:47 +02:00
|
|
|
*/
|
|
|
|
|
2008-12-26 10:46:21 +01:00
|
|
|
if (sta->sa_query_count == 0)
|
|
|
|
ap_sta_start_sa_query(hapd, sta);
|
2008-08-31 10:04:47 +02:00
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
|
2008-08-31 10:04:47 +02:00
|
|
|
}
|
|
|
|
|
2008-06-17 10:21:11 +02:00
|
|
|
if (wpa_auth_uses_mfp(sta->wpa_sm))
|
|
|
|
sta->flags |= WLAN_STA_MFP;
|
|
|
|
else
|
|
|
|
sta->flags &= ~WLAN_STA_MFP;
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
if (sta->auth_alg == WLAN_AUTH_FT) {
|
|
|
|
if (!reassoc) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried "
|
|
|
|
"to use association (not "
|
|
|
|
"re-association) with FT auth_alg",
|
|
|
|
MAC2STR(sta->addr));
|
2009-11-29 21:14:57 +01:00
|
|
|
return WLAN_STATUS_UNSPECIFIED_FAILURE;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies,
|
|
|
|
ies_len);
|
2008-02-28 02:34:43 +01:00
|
|
|
if (resp != WLAN_STATUS_SUCCESS)
|
2009-11-29 21:14:57 +01:00
|
|
|
return resp;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
2009-11-29 21:14:57 +01:00
|
|
|
|
2008-12-22 13:05:53 +01:00
|
|
|
#ifdef CONFIG_IEEE80211N
|
|
|
|
if ((sta->flags & WLAN_STA_HT) &&
|
|
|
|
wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) {
|
2009-11-29 21:14:57 +01:00
|
|
|
hostapd_logger(hapd, sta->addr,
|
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO,
|
|
|
|
"Station tried to use TKIP with HT "
|
|
|
|
"association");
|
|
|
|
return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
|
2008-12-22 13:05:53 +01:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211N */
|
2008-11-30 16:22:51 +01:00
|
|
|
} else
|
|
|
|
wpa_auth_sta_no_wpa(sta->wpa_sm);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2010-07-18 23:30:25 +02:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (elems.p2p) {
|
|
|
|
wpabuf_free(sta->p2p_ie);
|
|
|
|
sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len,
|
|
|
|
P2P_IE_VENDOR_TYPE);
|
2010-07-18 23:30:25 +02:00
|
|
|
|
2010-07-18 23:30:25 +02:00
|
|
|
} else {
|
|
|
|
wpabuf_free(sta->p2p_ie);
|
|
|
|
sta->p2p_ie = NULL;
|
|
|
|
}
|
2010-10-19 17:10:28 +02:00
|
|
|
|
|
|
|
p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len);
|
2010-07-18 23:30:25 +02:00
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
return WLAN_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void send_deauth(struct hostapd_data *hapd, const u8 *addr,
|
|
|
|
u16 reason_code)
|
|
|
|
{
|
|
|
|
int send_len;
|
|
|
|
struct ieee80211_mgmt reply;
|
|
|
|
|
|
|
|
os_memset(&reply, 0, sizeof(reply));
|
|
|
|
reply.frame_control =
|
|
|
|
IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH);
|
|
|
|
os_memcpy(reply.da, addr, ETH_ALEN);
|
|
|
|
os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN);
|
|
|
|
os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN);
|
|
|
|
|
|
|
|
send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth);
|
|
|
|
reply.u.deauth.reason_code = host_to_le16(reason_code);
|
|
|
|
|
2011-11-19 18:02:05 +01:00
|
|
|
if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0)
|
2009-11-29 21:14:57 +01:00
|
|
|
wpa_printf(MSG_INFO, "Failed to send deauth: %s",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta,
|
2009-12-13 22:25:30 +01:00
|
|
|
u16 status_code, int reassoc, const u8 *ies,
|
2009-11-29 21:14:57 +01:00
|
|
|
size_t ies_len)
|
|
|
|
{
|
|
|
|
int send_len;
|
|
|
|
u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
|
|
|
|
struct ieee80211_mgmt *reply;
|
|
|
|
u8 *p;
|
|
|
|
|
|
|
|
os_memset(buf, 0, sizeof(buf));
|
|
|
|
reply = (struct ieee80211_mgmt *) buf;
|
|
|
|
reply->frame_control =
|
|
|
|
IEEE80211_FC(WLAN_FC_TYPE_MGMT,
|
|
|
|
(reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
|
|
|
|
WLAN_FC_STYPE_ASSOC_RESP));
|
|
|
|
os_memcpy(reply->da, sta->addr, ETH_ALEN);
|
|
|
|
os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN);
|
|
|
|
os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN);
|
|
|
|
|
|
|
|
send_len = IEEE80211_HDRLEN;
|
|
|
|
send_len += sizeof(reply->u.assoc_resp);
|
|
|
|
reply->u.assoc_resp.capab_info =
|
|
|
|
host_to_le16(hostapd_own_capab_info(hapd, sta, 0));
|
|
|
|
reply->u.assoc_resp.status_code = host_to_le16(status_code);
|
|
|
|
reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0)
|
|
|
|
| BIT(14) | BIT(15));
|
|
|
|
/* Supported rates */
|
|
|
|
p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable);
|
|
|
|
/* Extended supported rates */
|
|
|
|
p = hostapd_eid_ext_supp_rates(hapd, p);
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
if (status_code == WLAN_STATUS_SUCCESS) {
|
|
|
|
/* IEEE 802.11r: Mobility Domain Information, Fast BSS
|
|
|
|
* Transition Information, RSN, [RIC Response] */
|
|
|
|
p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p,
|
|
|
|
buf + sizeof(buf) - p,
|
|
|
|
sta->auth_alg, ies, ies_len);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY)
|
|
|
|
p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
2010-05-02 09:53:01 +02:00
|
|
|
#ifdef CONFIG_IEEE80211N
|
|
|
|
p = hostapd_eid_ht_capabilities(hapd, p);
|
|
|
|
p = hostapd_eid_ht_operation(hapd, p);
|
|
|
|
#endif /* CONFIG_IEEE80211N */
|
|
|
|
|
2011-01-28 18:21:59 +01:00
|
|
|
p = hostapd_eid_ext_capab(hapd, p);
|
|
|
|
|
2010-05-02 09:53:01 +02:00
|
|
|
if (sta->flags & WLAN_STA_WMM)
|
|
|
|
p = hostapd_eid_wmm(hapd, p);
|
|
|
|
|
2010-05-26 17:46:08 +02:00
|
|
|
#ifdef CONFIG_WPS
|
2011-11-24 21:05:33 +01:00
|
|
|
if ((sta->flags & WLAN_STA_WPS) ||
|
|
|
|
((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa)) {
|
2010-05-26 17:46:08 +02:00
|
|
|
struct wpabuf *wps = wps_build_assoc_resp_ie();
|
|
|
|
if (wps) {
|
|
|
|
os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps));
|
|
|
|
p += wpabuf_len(wps);
|
|
|
|
wpabuf_free(wps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_WPS */
|
|
|
|
|
2010-07-18 23:30:25 +02:00
|
|
|
#ifdef CONFIG_P2P
|
|
|
|
if (sta->p2p_ie) {
|
|
|
|
struct wpabuf *p2p_resp_ie;
|
|
|
|
enum p2p_status_code status;
|
|
|
|
switch (status_code) {
|
|
|
|
case WLAN_STATUS_SUCCESS:
|
|
|
|
status = P2P_SC_SUCCESS;
|
|
|
|
break;
|
|
|
|
case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
|
|
|
|
status = P2P_SC_FAIL_LIMIT_REACHED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
status = P2P_SC_FAIL_INVALID_PARAMS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status);
|
|
|
|
if (p2p_resp_ie) {
|
|
|
|
os_memcpy(p, wpabuf_head(p2p_resp_ie),
|
|
|
|
wpabuf_len(p2p_resp_ie));
|
|
|
|
p += wpabuf_len(p2p_resp_ie);
|
|
|
|
wpabuf_free(p2p_resp_ie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_P2P */
|
|
|
|
|
2010-07-18 23:30:26 +02:00
|
|
|
#ifdef CONFIG_P2P_MANAGER
|
|
|
|
if (hapd->conf->p2p & P2P_MANAGE)
|
|
|
|
p = hostapd_eid_p2p_manage(hapd, p);
|
|
|
|
#endif /* CONFIG_P2P_MANAGER */
|
|
|
|
|
2009-11-29 21:14:57 +01:00
|
|
|
send_len += p - reply->u.assoc_resp.variable;
|
|
|
|
|
2011-11-19 18:02:05 +01:00
|
|
|
if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0)
|
2009-11-29 21:14:57 +01:00
|
|
|
wpa_printf(MSG_INFO, "Failed to send assoc resp: %s",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_assoc(struct hostapd_data *hapd,
|
2009-12-13 22:25:30 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt, size_t len,
|
|
|
|
int reassoc)
|
2009-11-29 21:14:57 +01:00
|
|
|
{
|
|
|
|
u16 capab_info, listen_interval;
|
|
|
|
u16 resp = WLAN_STATUS_SUCCESS;
|
2009-12-13 22:25:30 +01:00
|
|
|
const u8 *pos;
|
2009-11-29 21:14:57 +01:00
|
|
|
int left, i;
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
|
|
|
|
sizeof(mgmt->u.assoc_req))) {
|
|
|
|
printf("handle_assoc(reassoc=%d) - too short payload (len=%lu)"
|
|
|
|
"\n", reassoc, (unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reassoc) {
|
|
|
|
capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info);
|
|
|
|
listen_interval = le_to_host16(
|
|
|
|
mgmt->u.reassoc_req.listen_interval);
|
|
|
|
wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR
|
|
|
|
" capab_info=0x%02x listen_interval=%d current_ap="
|
|
|
|
MACSTR,
|
|
|
|
MAC2STR(mgmt->sa), capab_info, listen_interval,
|
|
|
|
MAC2STR(mgmt->u.reassoc_req.current_ap));
|
|
|
|
left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req));
|
|
|
|
pos = mgmt->u.reassoc_req.variable;
|
|
|
|
} else {
|
|
|
|
capab_info = le_to_host16(mgmt->u.assoc_req.capab_info);
|
|
|
|
listen_interval = le_to_host16(
|
|
|
|
mgmt->u.assoc_req.listen_interval);
|
|
|
|
wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR
|
|
|
|
" capab_info=0x%02x listen_interval=%d",
|
|
|
|
MAC2STR(mgmt->sa), capab_info, listen_interval);
|
|
|
|
left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req));
|
|
|
|
pos = mgmt->u.assoc_req.variable;
|
|
|
|
}
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, mgmt->sa);
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
if (sta && sta->auth_alg == WLAN_AUTH_FT &&
|
|
|
|
(sta->flags & WLAN_STA_AUTH) == 0) {
|
|
|
|
wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate "
|
|
|
|
"prior to authentication since it is using "
|
|
|
|
"over-the-DS FT", MAC2STR(mgmt->sa));
|
|
|
|
} else
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
|
|
|
if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "Station tried to "
|
|
|
|
"associate before authentication "
|
|
|
|
"(aid=%d flags=0x%x)",
|
|
|
|
sta ? sta->aid : -1,
|
|
|
|
sta ? sta->flags : 0);
|
|
|
|
send_deauth(hapd, mgmt->sa,
|
|
|
|
WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hapd->tkip_countermeasures) {
|
|
|
|
resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (listen_interval > hapd->conf->max_listen_interval) {
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"Too large Listen Interval (%d)",
|
|
|
|
listen_interval);
|
|
|
|
resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* followed by SSID and Supported rates; and HT capabilities if 802.11n
|
|
|
|
* is used */
|
|
|
|
resp = check_assoc_ies(hapd, sta, pos, left, reassoc);
|
|
|
|
if (resp != WLAN_STATUS_SUCCESS)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (hostapd_get_aid(hapd, sta) < 0) {
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "No room for more AIDs");
|
|
|
|
resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
sta->capability = capab_info;
|
|
|
|
sta->listen_interval = listen_interval;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
|
|
|
|
sta->flags |= WLAN_STA_NONERP;
|
|
|
|
for (i = 0; i < sta->supported_rates_len; i++) {
|
|
|
|
if ((sta->supported_rates[i] & 0x7f) > 22) {
|
|
|
|
sta->flags &= ~WLAN_STA_NONERP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) {
|
|
|
|
sta->nonerp_set = 1;
|
|
|
|
hapd->iface->num_sta_non_erp++;
|
|
|
|
if (hapd->iface->num_sta_non_erp == 1)
|
|
|
|
ieee802_11_set_beacons(hapd->iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) &&
|
|
|
|
!sta->no_short_slot_time_set) {
|
|
|
|
sta->no_short_slot_time_set = 1;
|
|
|
|
hapd->iface->num_sta_no_short_slot_time++;
|
|
|
|
if (hapd->iface->current_mode->mode ==
|
|
|
|
HOSTAPD_MODE_IEEE80211G &&
|
|
|
|
hapd->iface->num_sta_no_short_slot_time == 1)
|
|
|
|
ieee802_11_set_beacons(hapd->iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
|
|
|
|
sta->flags |= WLAN_STA_SHORT_PREAMBLE;
|
|
|
|
else
|
|
|
|
sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
|
|
|
|
|
|
|
|
if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) &&
|
|
|
|
!sta->no_short_preamble_set) {
|
|
|
|
sta->no_short_preamble_set = 1;
|
|
|
|
hapd->iface->num_sta_no_short_preamble++;
|
|
|
|
if (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G
|
|
|
|
&& hapd->iface->num_sta_no_short_preamble == 1)
|
|
|
|
ieee802_11_set_beacons(hapd->iface);
|
|
|
|
}
|
|
|
|
|
2009-12-06 18:41:47 +01:00
|
|
|
#ifdef CONFIG_IEEE80211N
|
2009-11-29 21:14:57 +01:00
|
|
|
update_ht_state(hapd, sta);
|
2009-12-06 18:41:47 +01:00
|
|
|
#endif /* CONFIG_IEEE80211N */
|
2008-08-21 17:18:38 +02:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"association OK (aid %d)", sta->aid);
|
|
|
|
/* Station will be marked associated, after it acknowledges AssocResp
|
|
|
|
*/
|
2011-04-15 18:26:28 +02:00
|
|
|
sta->flags |= WLAN_STA_ASSOC_REQ_OK;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
2008-12-26 14:56:30 +01:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out "
|
|
|
|
"SA Query procedure", reassoc ? "re" : "");
|
|
|
|
/* TODO: Send a protected Disassociate frame to the STA using
|
|
|
|
* the old key and Reason Code "Previous Authentication no
|
|
|
|
* longer valid". Make sure this is only sent protected since
|
|
|
|
* unprotected frame would be received by the STA that is now
|
|
|
|
* trying to associate.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
2008-08-30 17:25:44 +02:00
|
|
|
if (reassoc) {
|
|
|
|
os_memcpy(sta->previous_ap, mgmt->u.reassoc_req.current_ap,
|
|
|
|
ETH_ALEN);
|
|
|
|
}
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sta->last_assoc_req)
|
|
|
|
os_free(sta->last_assoc_req);
|
|
|
|
sta->last_assoc_req = os_malloc(len);
|
|
|
|
if (sta->last_assoc_req)
|
|
|
|
os_memcpy(sta->last_assoc_req, mgmt, len);
|
|
|
|
|
|
|
|
/* Make sure that the previously registered inactivity timer will not
|
|
|
|
* remove the STA immediately. */
|
|
|
|
sta->timeout_next = STA_NULLFUNC;
|
|
|
|
|
|
|
|
fail:
|
2009-11-29 21:14:57 +01:00
|
|
|
send_assoc_resp(hapd, sta, resp, reassoc, pos, left);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_disassoc(struct hostapd_data *hapd,
|
2009-12-13 22:05:39 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt, size_t len)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) {
|
|
|
|
printf("handle_disassoc - too short payload (len=%lu)\n",
|
|
|
|
(unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
|
|
|
|
MAC2STR(mgmt->sa),
|
|
|
|
le_to_host16(mgmt->u.disassoc.reason_code));
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, mgmt->sa);
|
|
|
|
if (sta == NULL) {
|
|
|
|
printf("Station " MACSTR " trying to disassociate, but it "
|
|
|
|
"is not associated.\n", MAC2STR(mgmt->sa));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-03 21:17:41 +01:00
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
2011-04-15 18:26:28 +02:00
|
|
|
sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK);
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "disassociated");
|
|
|
|
sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
|
|
|
|
ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
|
|
|
|
/* Stop Accounting and IEEE 802.1X sessions, but leave the STA
|
|
|
|
* authenticated. */
|
|
|
|
accounting_sta_stop(hapd, sta);
|
|
|
|
ieee802_1x_free_station(sta);
|
2010-11-24 14:36:02 +01:00
|
|
|
hostapd_drv_sta_remove(hapd, sta->addr);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (sta->timeout_next == STA_NULLFUNC ||
|
|
|
|
sta->timeout_next == STA_DISASSOC) {
|
|
|
|
sta->timeout_next = STA_DEAUTH;
|
|
|
|
eloop_cancel_timeout(ap_handle_timer, hapd, sta);
|
|
|
|
eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer,
|
|
|
|
hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
mlme_disassociate_indication(
|
|
|
|
hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_deauth(struct hostapd_data *hapd,
|
2009-12-13 22:05:39 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt, size_t len)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) {
|
2011-11-03 21:04:17 +01:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short "
|
|
|
|
"payload (len=%lu)", (unsigned long) len);
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-03 21:04:17 +01:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR
|
2011-02-24 16:44:45 +01:00
|
|
|
" reason_code=%d",
|
|
|
|
MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, mgmt->sa);
|
|
|
|
if (sta == NULL) {
|
2011-11-03 21:04:17 +01:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
|
|
|
|
"to deauthenticate, but it is not authenticated",
|
2011-02-24 16:44:45 +01:00
|
|
|
MAC2STR(mgmt->sa));
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-03 21:17:41 +01:00
|
|
|
ap_sta_set_authorized(hapd, sta, 0);
|
2011-04-15 18:26:28 +02:00
|
|
|
sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC |
|
|
|
|
WLAN_STA_ASSOC_REQ_OK);
|
2008-02-28 02:34:43 +01:00
|
|
|
wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG, "deauthenticated");
|
|
|
|
mlme_deauthenticate_indication(
|
|
|
|
hapd, sta, le_to_host16(mgmt->u.deauth.reason_code));
|
|
|
|
sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
|
|
|
|
ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
|
|
|
|
ap_free_sta(hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_beacon(struct hostapd_data *hapd,
|
2009-12-13 22:25:30 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt, size_t len,
|
2008-02-28 02:34:43 +01:00
|
|
|
struct hostapd_frame_info *fi)
|
|
|
|
{
|
|
|
|
struct ieee802_11_elems elems;
|
|
|
|
|
|
|
|
if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) {
|
|
|
|
printf("handle_beacon - too short payload (len=%lu)\n",
|
|
|
|
(unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-10-29 20:33:46 +01:00
|
|
|
(void) ieee802_11_parse_elems(mgmt->u.beacon.variable,
|
2008-02-28 02:34:43 +01:00
|
|
|
len - (IEEE80211_HDRLEN +
|
|
|
|
sizeof(mgmt->u.beacon)), &elems,
|
|
|
|
0);
|
|
|
|
|
|
|
|
ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-31 10:04:47 +02:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
2008-12-30 17:04:29 +01:00
|
|
|
|
2008-12-26 10:46:21 +01:00
|
|
|
static void hostapd_sa_query_action(struct hostapd_data *hapd,
|
2009-12-13 22:25:30 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt,
|
|
|
|
size_t len)
|
2008-08-31 10:04:47 +02:00
|
|
|
{
|
2009-12-13 22:25:30 +01:00
|
|
|
const u8 *end;
|
2008-08-31 10:04:47 +02:00
|
|
|
|
2008-12-26 10:46:21 +01:00
|
|
|
end = mgmt->u.action.u.sa_query_resp.trans_id +
|
|
|
|
WLAN_SA_QUERY_TR_ID_LEN;
|
2008-08-31 10:04:47 +02:00
|
|
|
if (((u8 *) mgmt) + len < end) {
|
2008-12-26 10:46:21 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action "
|
2008-08-31 10:04:47 +02:00
|
|
|
"frame (len=%lu)", (unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-17 16:30:43 +02:00
|
|
|
ieee802_11_sa_query_action(hapd, mgmt->sa,
|
|
|
|
mgmt->u.action.u.sa_query_resp.action,
|
|
|
|
mgmt->u.action.u.sa_query_resp.trans_id);
|
2008-08-31 10:04:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-05-08 11:51:28 +02:00
|
|
|
static int robust_action_frame(u8 category)
|
|
|
|
{
|
|
|
|
return category != WLAN_ACTION_PUBLIC &&
|
|
|
|
category != WLAN_ACTION_HT;
|
|
|
|
}
|
2009-05-26 16:08:43 +02:00
|
|
|
#endif /* CONFIG_IEEE80211W */
|
2009-05-08 11:51:28 +02:00
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
static void handle_action(struct hostapd_data *hapd,
|
2009-12-13 22:25:30 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt, size_t len)
|
2008-02-28 02:34:43 +01:00
|
|
|
{
|
2011-10-23 11:42:55 +02:00
|
|
|
#if defined(CONFIG_IEEE80211W) || defined(CONFIG_IEEE80211R)
|
2009-05-08 11:51:28 +02:00
|
|
|
struct sta_info *sta;
|
2011-10-23 11:42:55 +02:00
|
|
|
sta = ap_get_sta(hapd, mgmt->sa);
|
|
|
|
#endif /* CONFIG_IEEE80211W || CONFIG_IEEE80211R */
|
2009-05-08 11:51:28 +02:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (len < IEEE80211_HDRLEN + 1) {
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"handle_action - too short payload (len=%lu)",
|
|
|
|
(unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-08 11:51:28 +02:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
|
|
|
if (sta && (sta->flags & WLAN_STA_MFP) &&
|
|
|
|
!(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP) &&
|
|
|
|
robust_action_frame(mgmt->u.action.category))) {
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"Dropped unprotected Robust Action frame from "
|
|
|
|
"an MFP STA");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
switch (mgmt->u.action.category) {
|
|
|
|
#ifdef CONFIG_IEEE80211R
|
|
|
|
case WLAN_ACTION_FT:
|
|
|
|
{
|
|
|
|
if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored FT Action "
|
|
|
|
"frame from unassociated STA " MACSTR,
|
|
|
|
MAC2STR(mgmt->sa));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action,
|
|
|
|
len - IEEE80211_HDRLEN))
|
|
|
|
break;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211R */
|
2008-08-31 10:06:58 +02:00
|
|
|
case WLAN_ACTION_WMM:
|
2009-03-04 11:33:24 +01:00
|
|
|
hostapd_wmm_action(hapd, mgmt, len);
|
2008-02-28 02:34:43 +01:00
|
|
|
return;
|
2008-08-31 10:04:47 +02:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
2008-12-26 10:46:21 +01:00
|
|
|
case WLAN_ACTION_SA_QUERY:
|
|
|
|
hostapd_sa_query_action(hapd, mgmt, len);
|
2008-08-31 10:04:47 +02:00
|
|
|
return;
|
|
|
|
#endif /* CONFIG_IEEE80211W */
|
2010-04-11 19:33:33 +02:00
|
|
|
case WLAN_ACTION_PUBLIC:
|
|
|
|
if (hapd->public_action_cb) {
|
|
|
|
hapd->public_action_cb(hapd->public_action_cb_ctx,
|
|
|
|
(u8 *) mgmt, len,
|
|
|
|
hapd->iface->freq);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-18 23:30:25 +02:00
|
|
|
case WLAN_ACTION_VENDOR_SPECIFIC:
|
|
|
|
if (hapd->vendor_action_cb) {
|
|
|
|
if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx,
|
|
|
|
(u8 *) mgmt, len,
|
|
|
|
hapd->iface->freq) == 0)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"handle_action - unknown action category %d or invalid "
|
|
|
|
"frame",
|
|
|
|
mgmt->u.action.category);
|
|
|
|
if (!(mgmt->da[0] & 0x01) && !(mgmt->u.action.category & 0x80) &&
|
|
|
|
!(mgmt->sa[0] & 0x01)) {
|
2009-12-13 22:25:30 +01:00
|
|
|
struct ieee80211_mgmt *resp;
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
/*
|
|
|
|
* IEEE 802.11-REVma/D9.0 - 7.3.1.11
|
|
|
|
* Return the Action frame to the source without change
|
|
|
|
* except that MSB of the Category set to 1.
|
|
|
|
*/
|
|
|
|
wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action "
|
|
|
|
"frame back to sender");
|
2009-12-13 22:25:30 +01:00
|
|
|
resp = os_malloc(len);
|
|
|
|
if (resp == NULL)
|
|
|
|
return;
|
|
|
|
os_memcpy(resp, mgmt, len);
|
|
|
|
os_memcpy(resp->da, resp->sa, ETH_ALEN);
|
|
|
|
os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
|
|
|
|
os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
|
|
|
|
resp->u.action.category |= 0x80;
|
|
|
|
|
2011-11-19 18:02:05 +01:00
|
|
|
hostapd_drv_send_mlme(hapd, resp, len, 0);
|
2009-12-13 22:25:30 +01:00
|
|
|
os_free(resp);
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ieee802_11_mgmt - process incoming IEEE 802.11 management frames
|
|
|
|
* @hapd: hostapd BSS data structure (the BSS to which the management frame was
|
|
|
|
* sent to)
|
|
|
|
* @buf: management frame data (starting from IEEE 802.11 header)
|
|
|
|
* @len: length of frame data in octets
|
2009-01-02 21:28:04 +01:00
|
|
|
* @fi: meta data about received frame (signal level, etc.)
|
2008-02-28 02:34:43 +01:00
|
|
|
*
|
|
|
|
* Process all incoming IEEE 802.11 management frames. This will be called for
|
|
|
|
* each frame received from the kernel driver through wlan#ap interface. In
|
|
|
|
* addition, it can be called to re-inserted pending frames (e.g., when using
|
|
|
|
* external RADIUS server as an MAC ACL).
|
|
|
|
*/
|
2009-12-13 22:25:30 +01:00
|
|
|
void ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len,
|
2008-02-28 02:34:43 +01:00
|
|
|
struct hostapd_frame_info *fi)
|
|
|
|
{
|
2009-12-13 22:05:39 +01:00
|
|
|
struct ieee80211_mgmt *mgmt;
|
2008-02-28 02:34:43 +01:00
|
|
|
int broadcast;
|
2009-12-13 22:05:39 +01:00
|
|
|
u16 fc, stype;
|
|
|
|
|
2011-01-17 11:21:29 +01:00
|
|
|
if (len < 24)
|
|
|
|
return;
|
|
|
|
|
2009-12-13 22:05:39 +01:00
|
|
|
mgmt = (struct ieee80211_mgmt *) buf;
|
|
|
|
fc = le_to_host16(mgmt->frame_control);
|
|
|
|
stype = WLAN_FC_GET_STYPE(fc);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (stype == WLAN_FC_STYPE_BEACON) {
|
|
|
|
handle_beacon(hapd, mgmt, len, fi);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
broadcast = mgmt->bssid[0] == 0xff && mgmt->bssid[1] == 0xff &&
|
|
|
|
mgmt->bssid[2] == 0xff && mgmt->bssid[3] == 0xff &&
|
|
|
|
mgmt->bssid[4] == 0xff && mgmt->bssid[5] == 0xff;
|
|
|
|
|
|
|
|
if (!broadcast &&
|
2008-11-21 19:48:58 +01:00
|
|
|
os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) {
|
2008-02-28 02:34:43 +01:00
|
|
|
printf("MGMT: BSSID=" MACSTR " not our address\n",
|
|
|
|
MAC2STR(mgmt->bssid));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (stype == WLAN_FC_STYPE_PROBE_REQ) {
|
|
|
|
handle_probe_req(hapd, mgmt, len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) {
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"MGMT: DA=" MACSTR " not our address",
|
|
|
|
MAC2STR(mgmt->da));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (stype) {
|
|
|
|
case WLAN_FC_STYPE_AUTH:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::auth");
|
|
|
|
handle_auth(hapd, mgmt, len);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_ASSOC_REQ:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
|
|
|
|
handle_assoc(hapd, mgmt, len, 0);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_REASSOC_REQ:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
|
|
|
|
handle_assoc(hapd, mgmt, len, 1);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_DISASSOC:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::disassoc");
|
|
|
|
handle_disassoc(hapd, mgmt, len);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_DEAUTH:
|
2011-11-03 21:04:17 +01:00
|
|
|
wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth");
|
2008-02-28 02:34:43 +01:00
|
|
|
handle_deauth(hapd, mgmt, len);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_ACTION:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::action");
|
|
|
|
handle_action(hapd, mgmt, len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"unknown mgmt frame subtype %d", stype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_auth_cb(struct hostapd_data *hapd,
|
2009-12-13 22:05:39 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt,
|
2008-02-28 02:34:43 +01:00
|
|
|
size_t len, int ok)
|
|
|
|
{
|
|
|
|
u16 auth_alg, auth_transaction, status_code;
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_NOTICE,
|
|
|
|
"did not acknowledge authentication response");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
|
|
|
|
printf("handle_auth_cb - too short payload (len=%lu)\n",
|
|
|
|
(unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
|
|
|
|
auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction);
|
|
|
|
status_code = le_to_host16(mgmt->u.auth.status_code);
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, mgmt->da);
|
|
|
|
if (!sta) {
|
|
|
|
printf("handle_auth_cb: STA " MACSTR " not found\n",
|
|
|
|
MAC2STR(mgmt->da));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status_code == WLAN_STATUS_SUCCESS &&
|
|
|
|
((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
|
|
|
|
(auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO, "authenticated");
|
|
|
|
sta->flags |= WLAN_STA_AUTH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_assoc_cb(struct hostapd_data *hapd,
|
2009-12-13 22:05:39 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt,
|
2008-02-28 02:34:43 +01:00
|
|
|
size_t len, int reassoc, int ok)
|
|
|
|
{
|
|
|
|
u16 status;
|
|
|
|
struct sta_info *sta;
|
|
|
|
int new_assoc = 1;
|
2009-11-29 12:04:21 +01:00
|
|
|
struct ieee80211_ht_capabilities ht_cap;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"did not acknowledge association response");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
|
|
|
|
sizeof(mgmt->u.assoc_resp))) {
|
|
|
|
printf("handle_assoc_cb(reassoc=%d) - too short payload "
|
|
|
|
"(len=%lu)\n", reassoc, (unsigned long) len);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reassoc)
|
|
|
|
status = le_to_host16(mgmt->u.reassoc_resp.status_code);
|
|
|
|
else
|
|
|
|
status = le_to_host16(mgmt->u.assoc_resp.status_code);
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, mgmt->da);
|
|
|
|
if (!sta) {
|
|
|
|
printf("handle_assoc_cb: STA " MACSTR " not found\n",
|
|
|
|
MAC2STR(mgmt->da));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (status != WLAN_STATUS_SUCCESS)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Stop previous accounting session, if one is started, and allocate
|
|
|
|
* new session id for the new session. */
|
|
|
|
accounting_sta_stop(hapd, sta);
|
|
|
|
|
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_INFO,
|
2008-11-23 10:12:17 +01:00
|
|
|
"associated (aid %d)",
|
|
|
|
sta->aid);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (sta->flags & WLAN_STA_ASSOC)
|
|
|
|
new_assoc = 0;
|
|
|
|
sta->flags |= WLAN_STA_ASSOC;
|
2010-03-13 20:43:00 +01:00
|
|
|
if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa) ||
|
|
|
|
sta->auth_alg == WLAN_AUTH_FT) {
|
|
|
|
/*
|
|
|
|
* Open, static WEP, or FT protocol; no separate authorization
|
|
|
|
* step.
|
|
|
|
*/
|
2011-02-02 15:52:32 +01:00
|
|
|
ap_sta_set_authorized(hapd, sta, 1);
|
2009-04-03 19:40:07 +02:00
|
|
|
}
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (reassoc)
|
|
|
|
mlme_reassociate_indication(hapd, sta);
|
|
|
|
else
|
|
|
|
mlme_associate_indication(hapd, sta);
|
|
|
|
|
2008-08-31 10:04:47 +02:00
|
|
|
#ifdef CONFIG_IEEE80211W
|
2008-12-26 10:46:21 +01:00
|
|
|
sta->sa_query_timed_out = 0;
|
2008-08-31 10:04:47 +02:00
|
|
|
#endif /* CONFIG_IEEE80211W */
|
|
|
|
|
2009-09-26 20:30:43 +02:00
|
|
|
/*
|
|
|
|
* Remove the STA entry in order to make sure the STA PS state gets
|
|
|
|
* cleared and configuration gets updated in case of reassociation back
|
|
|
|
* to the same AP.
|
|
|
|
*/
|
2010-11-24 14:36:02 +01:00
|
|
|
hostapd_drv_sta_remove(hapd, sta->addr);
|
2009-09-26 20:30:43 +02:00
|
|
|
|
2009-12-06 18:41:47 +01:00
|
|
|
#ifdef CONFIG_IEEE80211N
|
|
|
|
if (sta->flags & WLAN_STA_HT)
|
|
|
|
hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap);
|
|
|
|
#endif /* CONFIG_IEEE80211N */
|
|
|
|
|
2010-11-24 15:50:06 +01:00
|
|
|
if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability,
|
|
|
|
sta->supported_rates, sta->supported_rates_len,
|
|
|
|
sta->listen_interval,
|
2011-07-12 19:26:52 +02:00
|
|
|
sta->flags & WLAN_STA_HT ? &ht_cap : NULL,
|
|
|
|
sta->flags)) {
|
2008-02-28 02:34:43 +01:00
|
|
|
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_NOTICE,
|
|
|
|
"Could not add STA to kernel driver");
|
2011-10-15 11:41:28 +02:00
|
|
|
|
|
|
|
ap_sta_disconnect(hapd, sta, sta->addr,
|
|
|
|
WLAN_REASON_DISASSOC_AP_BUSY);
|
|
|
|
|
|
|
|
goto fail;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
|
|
|
|
2010-11-09 02:44:02 +01:00
|
|
|
if (sta->flags & WLAN_STA_WDS)
|
2010-11-24 15:50:06 +01:00
|
|
|
hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
|
2010-11-09 02:44:02 +01:00
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
if (sta->eapol_sm == NULL) {
|
|
|
|
/*
|
|
|
|
* This STA does not use RADIUS server for EAP authentication,
|
|
|
|
* so bind it to the selected VLAN interface now, since the
|
|
|
|
* interface selection is not going to change anymore.
|
|
|
|
*/
|
2010-04-15 22:44:10 +02:00
|
|
|
if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
|
|
|
|
goto fail;
|
2008-02-28 02:34:43 +01:00
|
|
|
} else if (sta->vlan_id) {
|
|
|
|
/* VLAN ID already set (e.g., by PMKSA caching), so bind STA */
|
2010-04-15 22:44:10 +02:00
|
|
|
if (ap_sta_bind_vlan(hapd, sta, 0) < 0)
|
|
|
|
goto fail;
|
2008-02-28 02:34:43 +01:00
|
|
|
}
|
2009-05-11 12:49:57 +02:00
|
|
|
|
2010-11-24 15:50:06 +01:00
|
|
|
hostapd_set_sta_flags(hapd, sta);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
if (sta->auth_alg == WLAN_AUTH_FT)
|
|
|
|
wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
|
|
|
|
else
|
|
|
|
wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
|
2009-12-24 22:42:13 +01:00
|
|
|
hapd->new_assoc_sta_cb(hapd, sta, !new_assoc);
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
/* Copy of the association request is not needed anymore */
|
|
|
|
if (sta->last_assoc_req) {
|
|
|
|
os_free(sta->last_assoc_req);
|
|
|
|
sta->last_assoc_req = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-28 22:07:02 +02:00
|
|
|
static void handle_deauth_cb(struct hostapd_data *hapd,
|
|
|
|
const struct ieee80211_mgmt *mgmt,
|
|
|
|
size_t len, int ok)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
if (mgmt->da[0] & 0x01)
|
|
|
|
return;
|
|
|
|
sta = ap_get_sta(hapd, mgmt->da);
|
|
|
|
if (!sta) {
|
|
|
|
wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR
|
|
|
|
" not found", MAC2STR(mgmt->da));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth",
|
|
|
|
MAC2STR(sta->addr));
|
|
|
|
else
|
|
|
|
wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
|
|
|
|
"deauth", MAC2STR(sta->addr));
|
|
|
|
|
|
|
|
ap_sta_deauth_cb(hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void handle_disassoc_cb(struct hostapd_data *hapd,
|
|
|
|
const struct ieee80211_mgmt *mgmt,
|
|
|
|
size_t len, int ok)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
if (mgmt->da[0] & 0x01)
|
|
|
|
return;
|
|
|
|
sta = ap_get_sta(hapd, mgmt->da);
|
|
|
|
if (!sta) {
|
|
|
|
wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR
|
|
|
|
" not found", MAC2STR(mgmt->da));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (ok)
|
|
|
|
wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc",
|
|
|
|
MAC2STR(sta->addr));
|
|
|
|
else
|
|
|
|
wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge "
|
|
|
|
"disassoc", MAC2STR(sta->addr));
|
|
|
|
|
|
|
|
ap_sta_disassoc_cb(hapd, sta);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-08 15:33:00 +01:00
|
|
|
/**
|
|
|
|
* ieee802_11_mgmt_cb - Process management frame TX status callback
|
|
|
|
* @hapd: hostapd BSS data structure (the BSS from which the management frame
|
|
|
|
* was sent from)
|
|
|
|
* @buf: management frame data (starting from IEEE 802.11 header)
|
|
|
|
* @len: length of frame data in octets
|
|
|
|
* @stype: management frame subtype from frame control field
|
|
|
|
* @ok: Whether the frame was ACK'ed
|
|
|
|
*/
|
2009-12-13 22:05:39 +01:00
|
|
|
void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len,
|
2008-02-28 02:34:43 +01:00
|
|
|
u16 stype, int ok)
|
|
|
|
{
|
2009-12-13 22:05:39 +01:00
|
|
|
const struct ieee80211_mgmt *mgmt;
|
|
|
|
mgmt = (const struct ieee80211_mgmt *) buf;
|
2008-02-28 02:34:43 +01:00
|
|
|
|
|
|
|
switch (stype) {
|
|
|
|
case WLAN_FC_STYPE_AUTH:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::auth cb");
|
|
|
|
handle_auth_cb(hapd, mgmt, len, ok);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_ASSOC_RESP:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb");
|
|
|
|
handle_assoc_cb(hapd, mgmt, len, 0, ok);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_REASSOC_RESP:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb");
|
|
|
|
handle_assoc_cb(hapd, mgmt, len, 1, ok);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_PROBE_RESP:
|
2010-07-05 21:21:48 +02:00
|
|
|
wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb");
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_DEAUTH:
|
2011-08-28 22:07:02 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::deauth cb");
|
|
|
|
handle_deauth_cb(hapd, mgmt, len, ok);
|
|
|
|
break;
|
|
|
|
case WLAN_FC_STYPE_DISASSOC:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::disassoc cb");
|
|
|
|
handle_disassoc_cb(hapd, mgmt, len, ok);
|
2008-02-28 02:34:43 +01:00
|
|
|
break;
|
2008-08-31 10:04:47 +02:00
|
|
|
case WLAN_FC_STYPE_ACTION:
|
|
|
|
wpa_printf(MSG_DEBUG, "mgmt::action cb");
|
|
|
|
break;
|
2008-02-28 02:34:43 +01:00
|
|
|
default:
|
|
|
|
printf("unknown mgmt cb frame subtype %d\n", stype);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta,
|
|
|
|
char *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-13 22:05:39 +01:00
|
|
|
|
|
|
|
void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
|
|
|
|
const u8 *buf, size_t len, int ack)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
struct hostapd_iface *iface = hapd->iface;
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, addr);
|
|
|
|
if (sta == NULL && iface->num_bss > 1) {
|
|
|
|
size_t j;
|
|
|
|
for (j = 0; j < iface->num_bss; j++) {
|
|
|
|
hapd = iface->bss[j];
|
|
|
|
sta = ap_get_sta(hapd, addr);
|
|
|
|
if (sta)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sta == NULL)
|
|
|
|
return;
|
|
|
|
if (sta->flags & WLAN_STA_PENDING_POLL) {
|
|
|
|
wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending "
|
|
|
|
"activity poll", MAC2STR(sta->addr),
|
|
|
|
ack ? "ACKed" : "did not ACK");
|
|
|
|
if (ack)
|
|
|
|
sta->flags &= ~WLAN_STA_PENDING_POLL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ieee802_1x_tx_status(hapd, sta, buf, len, ack);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-19 12:00:30 +01:00
|
|
|
void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst,
|
|
|
|
const u8 *data, size_t len, int ack)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
struct hostapd_iface *iface = hapd->iface;
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, dst);
|
|
|
|
if (sta == NULL && iface->num_bss > 1) {
|
|
|
|
size_t j;
|
|
|
|
for (j = 0; j < iface->num_bss; j++) {
|
|
|
|
hapd = iface->bss[j];
|
|
|
|
sta = ap_get_sta(hapd, dst);
|
|
|
|
if (sta)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sta == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-20 20:03:08 +02:00
|
|
|
void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr)
|
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
struct hostapd_iface *iface = hapd->iface;
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, addr);
|
|
|
|
if (sta == NULL && iface->num_bss > 1) {
|
|
|
|
size_t j;
|
|
|
|
for (j = 0; j < iface->num_bss; j++) {
|
|
|
|
hapd = iface->bss[j];
|
|
|
|
sta = ap_get_sta(hapd, addr);
|
|
|
|
if (sta)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (sta == NULL)
|
|
|
|
return;
|
|
|
|
if (!(sta->flags & WLAN_STA_PENDING_POLL))
|
|
|
|
return;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending "
|
|
|
|
"activity poll", MAC2STR(sta->addr));
|
|
|
|
sta->flags &= ~WLAN_STA_PENDING_POLL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-24 10:46:22 +01:00
|
|
|
void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
|
|
|
|
int wds)
|
2009-12-13 22:05:39 +01:00
|
|
|
{
|
|
|
|
struct sta_info *sta;
|
|
|
|
|
|
|
|
sta = ap_get_sta(hapd, src);
|
2009-12-24 10:46:22 +01:00
|
|
|
if (sta && (sta->flags & WLAN_STA_ASSOC)) {
|
|
|
|
if (wds && !(sta->flags & WLAN_STA_WDS)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for "
|
|
|
|
"STA " MACSTR " (aid %u)",
|
|
|
|
MAC2STR(sta->addr), sta->aid);
|
|
|
|
sta->flags |= WLAN_STA_WDS;
|
2010-11-24 15:50:06 +01:00
|
|
|
hostapd_set_wds_sta(hapd, sta->addr, sta->aid, 1);
|
2009-12-24 10:46:22 +01:00
|
|
|
}
|
2009-12-13 22:05:39 +01:00
|
|
|
return;
|
2009-12-24 10:46:22 +01:00
|
|
|
}
|
2009-12-13 22:05:39 +01:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA "
|
|
|
|
MACSTR, MAC2STR(src));
|
2010-12-05 02:40:36 +01:00
|
|
|
if (src[0] & 0x01) {
|
|
|
|
/* Broadcast bit set in SA?! Ignore the frame silently. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-15 18:26:28 +02:00
|
|
|
if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Association Response to the STA has "
|
|
|
|
"already been sent, but no TX status yet known - "
|
|
|
|
"ignore Class 3 frame issue with " MACSTR,
|
|
|
|
MAC2STR(src));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-12-13 22:05:39 +01:00
|
|
|
if (sta && (sta->flags & WLAN_STA_AUTH))
|
2010-11-24 14:36:02 +01:00
|
|
|
hostapd_drv_sta_disassoc(
|
2009-12-13 22:05:39 +01:00
|
|
|
hapd, src,
|
|
|
|
WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
|
|
|
|
else
|
2010-11-24 14:36:02 +01:00
|
|
|
hostapd_drv_sta_deauth(
|
2009-12-13 22:05:39 +01:00
|
|
|
hapd, src,
|
|
|
|
WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-28 02:34:43 +01:00
|
|
|
#endif /* CONFIG_NATIVE_WINDOWS */
|