2003-06-23 16:55:01 +00:00
|
|
|
/*-
|
2003-06-27 05:13:52 +00:00
|
|
|
* Copyright (c) 2001 Atsushi Onoe
|
2008-04-20 20:35:46 +00:00
|
|
|
* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
|
2003-06-23 16:55:01 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2003-06-27 05:13:52 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2003-06-23 16:55:01 +00:00
|
|
|
*
|
2003-06-27 05:13:52 +00:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2003-06-23 16:55:01 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* IEEE 802.11 generic crypto support.
|
|
|
|
*/
|
2008-04-20 20:35:46 +00:00
|
|
|
#include "opt_wlan.h"
|
|
|
|
|
2003-06-23 16:55:01 +00:00
|
|
|
#include <sys/param.h>
|
2008-04-20 20:35:46 +00:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
2003-06-23 16:55:01 +00:00
|
|
|
#include <sys/mbuf.h>
|
2004-12-08 17:26:47 +00:00
|
|
|
|
2003-06-23 16:55:01 +00:00
|
|
|
#include <sys/socket.h>
|
2004-12-08 17:26:47 +00:00
|
|
|
|
2003-06-23 16:55:01 +00:00
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_media.h>
|
2004-12-08 17:26:47 +00:00
|
|
|
#include <net/ethernet.h> /* XXX ETHER_HDR_LEN */
|
2003-06-23 16:55:01 +00:00
|
|
|
|
|
|
|
#include <net80211/ieee80211_var.h>
|
|
|
|
|
2008-04-20 20:35:46 +00:00
|
|
|
MALLOC_DEFINE(M_80211_CRYPTO, "80211crypto", "802.11 crypto state");
|
|
|
|
|
|
|
|
static int _ieee80211_crypto_delkey(struct ieee80211vap *,
|
|
|
|
struct ieee80211_key *);
|
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Table of registered cipher modules.
|
|
|
|
*/
|
|
|
|
static const struct ieee80211_cipher *ciphers[IEEE80211_CIPHER_MAX];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default "null" key management routines.
|
|
|
|
*/
|
|
|
|
static int
|
2008-09-21 23:16:19 +00:00
|
|
|
null_key_alloc(struct ieee80211vap *vap, struct ieee80211_key *k,
|
2005-08-08 18:46:36 +00:00
|
|
|
ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
if (!(&vap->iv_nw_keys[0] <= k &&
|
|
|
|
k < &vap->iv_nw_keys[IEEE80211_WEP_NKID])) {
|
2005-07-09 23:15:30 +00:00
|
|
|
/*
|
|
|
|
* Not in the global key table, the driver should handle this
|
|
|
|
* by allocating a slot in the h/w key table/cache. In
|
|
|
|
* lieu of that return key slot 0 for any unicast key
|
|
|
|
* request. We disallow the request if this is a group key.
|
|
|
|
* This default policy does the right thing for legacy hardware
|
|
|
|
* with a 4 key table. It also handles devices that pass
|
|
|
|
* packets through untouched when marked with the WEP bit
|
|
|
|
* and key index 0.
|
|
|
|
*/
|
2005-08-08 18:46:36 +00:00
|
|
|
if (k->wk_flags & IEEE80211_KEY_GROUP)
|
|
|
|
return 0;
|
|
|
|
*keyix = 0; /* NB: use key index 0 for ucast key */
|
|
|
|
} else {
|
2008-04-20 20:35:46 +00:00
|
|
|
*keyix = k - vap->iv_nw_keys;
|
2005-07-09 23:15:30 +00:00
|
|
|
}
|
2005-08-08 18:46:36 +00:00
|
|
|
*rxkeyix = IEEE80211_KEYIX_NONE; /* XXX maybe *keyix? */
|
|
|
|
return 1;
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
|
|
|
static int
|
2008-04-20 20:35:46 +00:00
|
|
|
null_key_delete(struct ieee80211vap *vap, const struct ieee80211_key *k)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
static int
|
2008-04-20 20:35:46 +00:00
|
|
|
null_key_set(struct ieee80211vap *vap, const struct ieee80211_key *k,
|
Update 802.11 wireless support:
o major overhaul of the way channels are handled: channels are now
fully enumerated and uniquely identify the operating characteristics;
these changes are visible to user applications which require changes
o make scanning support independent of the state machine to enable
background scanning and roaming
o move scanning support into loadable modules based on the operating
mode to enable different policies and reduce the memory footprint
on systems w/ constrained resources
o add background scanning in station mode (no support for adhoc/ibss
mode yet)
o significantly speedup sta mode scanning with a variety of techniques
o add roaming support when background scanning is supported; for now
we use a simple algorithm to trigger a roam: we threshold the rssi
and tx rate, if either drops too low we try to roam to a new ap
o add tx fragmentation support
o add first cut at 802.11n support: this code works with forthcoming
drivers but is incomplete; it's included now to establish a baseline
for other drivers to be developed and for user applications
o adjust max_linkhdr et. al. to reflect 802.11 requirements; this eliminates
prepending mbufs for traffic generated locally
o add support for Atheros protocol extensions; mainly the fast frames
encapsulation (note this can be used with any card that can tx+rx
large frames correctly)
o add sta support for ap's that beacon both WPA1+2 support
o change all data types from bsd-style to posix-style
o propagate noise floor data from drivers to net80211 and on to user apps
o correct various issues in the sta mode state machine related to handling
authentication and association failures
o enable the addition of sta mode power save support for drivers that need
net80211 support (not in this commit)
o remove old WI compatibility ioctls (wicontrol is officially dead)
o change the data structures returned for get sta info and get scan
results so future additions will not break user apps
o fixed tx rate is now maintained internally as an ieee rate and not an
index into the rate set; this needs to be extended to deal with
multi-mode operation
o add extended channel specifications to radiotap to enable 11n sniffing
Drivers:
o ath: add support for bg scanning, tx fragmentation, fast frames,
dynamic turbo (lightly tested), 11n (sniffing only and needs
new hal)
o awi: compile tested only
o ndis: lightly tested
o ipw: lightly tested
o iwi: add support for bg scanning (well tested but may have some
rough edges)
o ral, ural, rum: add suppoort for bg scanning, calibrate rssi data
o wi: lightly tested
This work is based on contributions by Atheros, kmacy, sephe, thompsa,
mlaier, kevlo, and others. Much of the scanning work was supported by
Atheros. The 11n work was supported by Marvell.
2007-06-11 03:36:55 +00:00
|
|
|
const uint8_t mac[IEEE80211_ADDR_LEN])
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2008-04-20 20:35:46 +00:00
|
|
|
static void null_key_update(struct ieee80211vap *vap) {}
|
2004-12-08 17:26:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Write-arounds for common operations.
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
cipher_detach(struct ieee80211_key *key)
|
|
|
|
{
|
|
|
|
key->wk_cipher->ic_detach(key);
|
|
|
|
}
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
static __inline void *
|
2008-04-20 20:35:46 +00:00
|
|
|
cipher_attach(struct ieee80211vap *vap, struct ieee80211_key *key)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
return key->wk_cipher->ic_attach(vap, key);
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Wrappers for driver key management methods.
|
|
|
|
*/
|
|
|
|
static __inline int
|
2008-04-20 20:35:46 +00:00
|
|
|
dev_key_alloc(struct ieee80211vap *vap,
|
2008-09-21 23:16:19 +00:00
|
|
|
struct ieee80211_key *key,
|
2005-08-08 18:46:36 +00:00
|
|
|
ieee80211_keyix *keyix, ieee80211_keyix *rxkeyix)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
return vap->iv_key_alloc(vap, key, keyix, rxkeyix);
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __inline int
|
2008-04-20 20:35:46 +00:00
|
|
|
dev_key_delete(struct ieee80211vap *vap,
|
2004-12-08 17:26:47 +00:00
|
|
|
const struct ieee80211_key *key)
|
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
return vap->iv_key_delete(vap, key);
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
static __inline int
|
2008-05-28 23:32:00 +00:00
|
|
|
dev_key_set(struct ieee80211vap *vap, const struct ieee80211_key *key)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
2008-05-28 23:32:00 +00:00
|
|
|
return vap->iv_key_set(vap, key, key->wk_macaddr);
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
2008-04-20 20:35:46 +00:00
|
|
|
* Setup crypto support for a device/shared instance.
|
2004-12-08 17:26:47 +00:00
|
|
|
*/
|
2003-06-23 16:55:01 +00:00
|
|
|
void
|
2004-12-08 17:26:47 +00:00
|
|
|
ieee80211_crypto_attach(struct ieee80211com *ic)
|
2003-06-23 16:55:01 +00:00
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
/* NB: we assume everything is pre-zero'd */
|
|
|
|
ciphers[IEEE80211_CIPHER_NONE] = &ieee80211_cipher_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Teardown crypto support.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ieee80211_crypto_detach(struct ieee80211com *ic)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup crypto support for a vap.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ieee80211_crypto_vattach(struct ieee80211vap *vap)
|
|
|
|
{
|
2004-12-08 17:26:47 +00:00
|
|
|
int i;
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/* NB: we assume everything is pre-zero'd */
|
2008-04-20 20:35:46 +00:00
|
|
|
vap->iv_max_keyix = IEEE80211_WEP_NKID;
|
|
|
|
vap->iv_def_txkey = IEEE80211_KEYIX_NONE;
|
2004-12-08 17:26:47 +00:00
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++)
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_resetkey(vap, &vap->iv_nw_keys[i],
|
2005-04-12 17:55:13 +00:00
|
|
|
IEEE80211_KEYIX_NONE);
|
2003-06-23 16:55:01 +00:00
|
|
|
/*
|
2004-12-08 17:26:47 +00:00
|
|
|
* Initialize the driver key support routines to noop entries.
|
|
|
|
* This is useful especially for the cipher test modules.
|
2003-06-23 16:55:01 +00:00
|
|
|
*/
|
2008-04-20 20:35:46 +00:00
|
|
|
vap->iv_key_alloc = null_key_alloc;
|
|
|
|
vap->iv_key_set = null_key_set;
|
|
|
|
vap->iv_key_delete = null_key_delete;
|
|
|
|
vap->iv_key_update_begin = null_key_update;
|
|
|
|
vap->iv_key_update_end = null_key_update;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
2008-04-20 20:35:46 +00:00
|
|
|
* Teardown crypto support for a vap.
|
2004-12-08 17:26:47 +00:00
|
|
|
*/
|
2003-06-23 16:55:01 +00:00
|
|
|
void
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_vdetach(struct ieee80211vap *vap)
|
2003-06-23 16:55:01 +00:00
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_delglobalkeys(vap);
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Register a crypto cipher module.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ieee80211_crypto_register(const struct ieee80211_cipher *cip)
|
|
|
|
{
|
|
|
|
if (cip->ic_cipher >= IEEE80211_CIPHER_MAX) {
|
|
|
|
printf("%s: cipher %s has an invalid cipher index %u\n",
|
|
|
|
__func__, cip->ic_name, cip->ic_cipher);
|
|
|
|
return;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
if (ciphers[cip->ic_cipher] != NULL && ciphers[cip->ic_cipher] != cip) {
|
|
|
|
printf("%s: cipher %s registered with a different template\n",
|
|
|
|
__func__, cip->ic_name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ciphers[cip->ic_cipher] = cip;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Unregister a crypto cipher module.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ieee80211_crypto_unregister(const struct ieee80211_cipher *cip)
|
2003-06-23 16:55:01 +00:00
|
|
|
{
|
2004-12-08 17:26:47 +00:00
|
|
|
if (cip->ic_cipher >= IEEE80211_CIPHER_MAX) {
|
|
|
|
printf("%s: cipher %s has an invalid cipher index %u\n",
|
|
|
|
__func__, cip->ic_name, cip->ic_cipher);
|
|
|
|
return;
|
2003-10-17 23:15:30 +00:00
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
if (ciphers[cip->ic_cipher] != NULL && ciphers[cip->ic_cipher] != cip) {
|
|
|
|
printf("%s: cipher %s registered with a different template\n",
|
|
|
|
__func__, cip->ic_name);
|
|
|
|
return;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
/* NB: don't complain about not being registered */
|
|
|
|
/* XXX disallow if references */
|
|
|
|
ciphers[cip->ic_cipher] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ieee80211_crypto_available(u_int cipher)
|
|
|
|
{
|
|
|
|
return cipher < IEEE80211_CIPHER_MAX && ciphers[cipher] != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX well-known names! */
|
2008-04-20 20:35:46 +00:00
|
|
|
static const char *cipher_modnames[IEEE80211_CIPHER_MAX] = {
|
2009-06-07 23:16:10 +00:00
|
|
|
[IEEE80211_CIPHER_WEP] = "wlan_wep",
|
|
|
|
[IEEE80211_CIPHER_TKIP] = "wlan_tkip",
|
|
|
|
[IEEE80211_CIPHER_AES_OCB] = "wlan_aes_ocb",
|
|
|
|
[IEEE80211_CIPHER_AES_CCM] = "wlan_ccmp",
|
|
|
|
[IEEE80211_CIPHER_TKIPMIC] = "#4", /* NB: reserved */
|
|
|
|
[IEEE80211_CIPHER_CKIP] = "wlan_ckip",
|
|
|
|
[IEEE80211_CIPHER_NONE] = "wlan_none",
|
2004-12-08 17:26:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Establish a relationship between the specified key and cipher
|
2005-04-12 17:55:13 +00:00
|
|
|
* and, if necessary, allocate a hardware index from the driver.
|
|
|
|
* Note that when a fixed key index is required it must be specified
|
|
|
|
* and we blindly assign it w/o consulting the driver (XXX).
|
2004-12-08 17:26:47 +00:00
|
|
|
*
|
|
|
|
* This must be the first call applied to a key; all the other key
|
|
|
|
* routines assume wk_cipher is setup.
|
|
|
|
*
|
|
|
|
* Locking must be handled by the caller using:
|
2008-04-20 20:35:46 +00:00
|
|
|
* ieee80211_key_update_begin(vap);
|
|
|
|
* ieee80211_key_update_end(vap);
|
2004-12-08 17:26:47 +00:00
|
|
|
*/
|
|
|
|
int
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_newkey(struct ieee80211vap *vap,
|
2005-04-12 17:55:13 +00:00
|
|
|
int cipher, int flags, struct ieee80211_key *key)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
struct ieee80211com *ic = vap->iv_ic;
|
2004-12-08 17:26:47 +00:00
|
|
|
const struct ieee80211_cipher *cip;
|
2005-08-08 18:46:36 +00:00
|
|
|
ieee80211_keyix keyix, rxkeyix;
|
2004-12-08 17:26:47 +00:00
|
|
|
void *keyctx;
|
|
|
|
int oflags;
|
|
|
|
|
2008-10-25 23:23:41 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
"%s: cipher %u flags 0x%x keyix %u\n",
|
|
|
|
__func__, cipher, flags, key->wk_keyix);
|
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Validate cipher and set reference to cipher routines.
|
|
|
|
*/
|
|
|
|
if (cipher >= IEEE80211_CIPHER_MAX) {
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
"%s: invalid cipher %u\n", __func__, cipher);
|
|
|
|
vap->iv_stats.is_crypto_badcipher++;
|
2004-12-08 17:26:47 +00:00
|
|
|
return 0;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
cip = ciphers[cipher];
|
|
|
|
if (cip == NULL) {
|
2003-06-23 16:55:01 +00:00
|
|
|
/*
|
2004-12-08 17:26:47 +00:00
|
|
|
* Auto-load cipher module if we have a well-known name
|
|
|
|
* for it. It might be better to use string names rather
|
|
|
|
* than numbers and craft a module name based on the cipher
|
|
|
|
* name; e.g. wlan_cipher_<cipher-name>.
|
2003-06-23 16:55:01 +00:00
|
|
|
*/
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
"%s: unregistered cipher %u, load module %s\n",
|
|
|
|
__func__, cipher, cipher_modnames[cipher]);
|
|
|
|
ieee80211_load_module(cipher_modnames[cipher]);
|
|
|
|
/*
|
|
|
|
* If cipher module loaded it should immediately
|
|
|
|
* call ieee80211_crypto_register which will fill
|
|
|
|
* in the entry in the ciphers array.
|
|
|
|
*/
|
|
|
|
cip = ciphers[cipher];
|
2004-12-08 17:26:47 +00:00
|
|
|
if (cip == NULL) {
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
"%s: unable to load cipher %u, module %s\n",
|
|
|
|
__func__, cipher, cipher_modnames[cipher]);
|
|
|
|
vap->iv_stats.is_crypto_nocipher++;
|
2004-12-08 17:26:47 +00:00
|
|
|
return 0;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
oflags = key->wk_flags;
|
2005-04-12 17:55:13 +00:00
|
|
|
flags &= IEEE80211_KEY_COMMON;
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* If the hardware does not support the cipher then
|
|
|
|
* fallback to a host-based implementation.
|
|
|
|
*/
|
2008-04-20 20:35:46 +00:00
|
|
|
if ((ic->ic_cryptocaps & (1<<cipher)) == 0) {
|
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-08 17:26:47 +00:00
|
|
|
"%s: no h/w support for cipher %s, falling back to s/w\n",
|
|
|
|
__func__, cip->ic_name);
|
2005-04-12 17:55:13 +00:00
|
|
|
flags |= IEEE80211_KEY_SWCRYPT;
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Hardware TKIP with software MIC is an important
|
|
|
|
* combination; we handle it by flagging each key,
|
|
|
|
* the cipher modules honor it.
|
|
|
|
*/
|
|
|
|
if (cipher == IEEE80211_CIPHER_TKIP &&
|
2008-04-20 20:35:46 +00:00
|
|
|
(ic->ic_cryptocaps & IEEE80211_CRYPTO_TKIPMIC) == 0) {
|
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-08 17:26:47 +00:00
|
|
|
"%s: no h/w support for TKIP MIC, falling back to s/w\n",
|
|
|
|
__func__);
|
2005-04-12 17:55:13 +00:00
|
|
|
flags |= IEEE80211_KEY_SWMIC;
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bind cipher to key instance. Note we do this
|
|
|
|
* after checking the device capabilities so the
|
|
|
|
* cipher module can optimize space usage based on
|
|
|
|
* whether or not it needs to do the cipher work.
|
|
|
|
*/
|
2005-04-12 17:55:13 +00:00
|
|
|
if (key->wk_cipher != cip || key->wk_flags != flags) {
|
|
|
|
/*
|
|
|
|
* Fillin the flags so cipher modules can see s/w
|
|
|
|
* crypto requirements and potentially allocate
|
|
|
|
* different state and/or attach different method
|
|
|
|
* pointers.
|
|
|
|
*/
|
|
|
|
key->wk_flags = flags;
|
2008-04-20 20:35:46 +00:00
|
|
|
keyctx = cip->ic_attach(vap, key);
|
2004-12-08 17:26:47 +00:00
|
|
|
if (keyctx == NULL) {
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-08 17:26:47 +00:00
|
|
|
"%s: unable to attach cipher %s\n",
|
|
|
|
__func__, cip->ic_name);
|
|
|
|
key->wk_flags = oflags; /* restore old flags */
|
2008-04-20 20:35:46 +00:00
|
|
|
vap->iv_stats.is_crypto_attachfail++;
|
2004-12-08 17:26:47 +00:00
|
|
|
return 0;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
cipher_detach(key);
|
|
|
|
key->wk_cipher = cip; /* XXX refcnt? */
|
|
|
|
key->wk_private = keyctx;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2005-04-12 17:55:13 +00:00
|
|
|
/*
|
|
|
|
* Commit to requested usage so driver can see the flags.
|
|
|
|
*/
|
|
|
|
key->wk_flags = flags;
|
2004-12-08 17:26:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ask the driver for a key index if we don't have one.
|
|
|
|
* Note that entries in the global key table always have
|
|
|
|
* an index; this means it's safe to call this routine
|
|
|
|
* for these entries just to setup the reference to the
|
|
|
|
* cipher template. Note also that when using software
|
|
|
|
* crypto we also call the driver to give us a key index.
|
|
|
|
*/
|
2008-09-21 23:16:19 +00:00
|
|
|
if ((key->wk_flags & IEEE80211_KEY_DEVKEY) == 0) {
|
2008-04-20 20:35:46 +00:00
|
|
|
if (!dev_key_alloc(vap, key, &keyix, &rxkeyix)) {
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
2008-09-21 23:16:19 +00:00
|
|
|
* Unable to setup driver state.
|
2004-12-08 17:26:47 +00:00
|
|
|
*/
|
2008-04-20 20:35:46 +00:00
|
|
|
vap->iv_stats.is_crypto_keyfail++;
|
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-08 17:26:47 +00:00
|
|
|
"%s: unable to setup cipher %s\n",
|
|
|
|
__func__, cip->ic_name);
|
|
|
|
return 0;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2008-09-21 23:16:19 +00:00
|
|
|
if (key->wk_flags != flags) {
|
|
|
|
/*
|
|
|
|
* Driver overrode flags we setup; typically because
|
|
|
|
* resources were unavailable to handle _this_ key.
|
|
|
|
* Re-attach the cipher context to allow cipher
|
|
|
|
* modules to handle differing requirements.
|
|
|
|
*/
|
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
"%s: driver override for cipher %s, flags "
|
|
|
|
"0x%x -> 0x%x\n", __func__, cip->ic_name,
|
|
|
|
oflags, key->wk_flags);
|
|
|
|
keyctx = cip->ic_attach(vap, key);
|
|
|
|
if (keyctx == NULL) {
|
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
"%s: unable to attach cipher %s with "
|
|
|
|
"flags 0x%x\n", __func__, cip->ic_name,
|
|
|
|
key->wk_flags);
|
|
|
|
key->wk_flags = oflags; /* restore old flags */
|
|
|
|
vap->iv_stats.is_crypto_attachfail++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
cipher_detach(key);
|
|
|
|
key->wk_cipher = cip; /* XXX refcnt? */
|
|
|
|
key->wk_private = keyctx;
|
|
|
|
}
|
2005-08-08 18:46:36 +00:00
|
|
|
key->wk_keyix = keyix;
|
|
|
|
key->wk_rxkeyix = rxkeyix;
|
2008-09-21 23:16:19 +00:00
|
|
|
key->wk_flags |= IEEE80211_KEY_DEVKEY;
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the key (no locking, for internal use).
|
|
|
|
*/
|
|
|
|
static int
|
2008-04-20 20:35:46 +00:00
|
|
|
_ieee80211_crypto_delkey(struct ieee80211vap *vap, struct ieee80211_key *key)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
|
|
|
KASSERT(key->wk_cipher != NULL, ("No cipher!"));
|
|
|
|
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-31 20:42:51 +00:00
|
|
|
"%s: %s keyix %u flags 0x%x rsc %ju tsc %ju len %u\n",
|
|
|
|
__func__, key->wk_cipher->ic_name,
|
|
|
|
key->wk_keyix, key->wk_flags,
|
2008-04-20 20:35:46 +00:00
|
|
|
key->wk_keyrsc[IEEE80211_NONQOS_TID], key->wk_keytsc,
|
|
|
|
key->wk_keylen);
|
2004-12-31 20:42:51 +00:00
|
|
|
|
2008-09-21 23:16:19 +00:00
|
|
|
if (key->wk_flags & IEEE80211_KEY_DEVKEY) {
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Remove hardware entry.
|
|
|
|
*/
|
|
|
|
/* XXX key cache */
|
2008-04-20 20:35:46 +00:00
|
|
|
if (!dev_key_delete(vap, key)) {
|
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-08 17:26:47 +00:00
|
|
|
"%s: driver did not delete key index %u\n",
|
2008-09-21 23:16:19 +00:00
|
|
|
__func__, key->wk_keyix);
|
2008-04-20 20:35:46 +00:00
|
|
|
vap->iv_stats.is_crypto_delkey++;
|
2004-12-08 17:26:47 +00:00
|
|
|
/* XXX recovery? */
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
cipher_detach(key);
|
|
|
|
memset(key, 0, sizeof(*key));
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_resetkey(vap, key, IEEE80211_KEYIX_NONE);
|
2004-12-08 17:26:47 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove the specified key.
|
|
|
|
*/
|
|
|
|
int
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_delkey(struct ieee80211vap *vap, struct ieee80211_key *key)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_key_update_begin(vap);
|
|
|
|
status = _ieee80211_crypto_delkey(vap, key);
|
|
|
|
ieee80211_key_update_end(vap);
|
2004-12-08 17:26:47 +00:00
|
|
|
return status;
|
|
|
|
}
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Clear the global key table.
|
|
|
|
*/
|
|
|
|
void
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_delglobalkeys(struct ieee80211vap *vap)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_key_update_begin(vap);
|
2004-12-08 17:26:47 +00:00
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++)
|
2008-04-20 20:35:46 +00:00
|
|
|
(void) _ieee80211_crypto_delkey(vap, &vap->iv_nw_keys[i]);
|
|
|
|
ieee80211_key_update_end(vap);
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-12-08 17:26:47 +00:00
|
|
|
* Set the contents of the specified key.
|
|
|
|
*
|
|
|
|
* Locking must be handled by the caller using:
|
2008-04-20 20:35:46 +00:00
|
|
|
* ieee80211_key_update_begin(vap);
|
|
|
|
* ieee80211_key_update_end(vap);
|
2003-06-23 16:55:01 +00:00
|
|
|
*/
|
2004-12-08 17:26:47 +00:00
|
|
|
int
|
2008-05-28 23:32:00 +00:00
|
|
|
ieee80211_crypto_setkey(struct ieee80211vap *vap, struct ieee80211_key *key)
|
2004-12-08 17:26:47 +00:00
|
|
|
{
|
|
|
|
const struct ieee80211_cipher *cip = key->wk_cipher;
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2004-12-08 17:26:47 +00:00
|
|
|
KASSERT(cip != NULL, ("No cipher!"));
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-31 20:42:51 +00:00
|
|
|
"%s: %s keyix %u flags 0x%x mac %s rsc %ju tsc %ju len %u\n",
|
|
|
|
__func__, cip->ic_name, key->wk_keyix,
|
2008-05-28 23:32:00 +00:00
|
|
|
key->wk_flags, ether_sprintf(key->wk_macaddr),
|
2008-04-20 20:35:46 +00:00
|
|
|
key->wk_keyrsc[IEEE80211_NONQOS_TID], key->wk_keytsc,
|
|
|
|
key->wk_keylen);
|
2004-12-31 20:42:51 +00:00
|
|
|
|
2008-09-21 23:16:19 +00:00
|
|
|
if ((key->wk_flags & IEEE80211_KEY_DEVKEY) == 0) {
|
|
|
|
/* XXX nothing allocated, should not happen */
|
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
"%s: no device key setup done; should not happen!\n",
|
|
|
|
__func__);
|
|
|
|
vap->iv_stats.is_crypto_setkey_nokey++;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
/*
|
|
|
|
* Give cipher a chance to validate key contents.
|
|
|
|
* XXX should happen before modifying state.
|
|
|
|
*/
|
|
|
|
if (!cip->ic_setkey(key)) {
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_CRYPTO,
|
2004-12-08 17:26:47 +00:00
|
|
|
"%s: cipher %s rejected key index %u len %u flags 0x%x\n",
|
|
|
|
__func__, cip->ic_name, key->wk_keyix,
|
|
|
|
key->wk_keylen, key->wk_flags);
|
2008-04-20 20:35:46 +00:00
|
|
|
vap->iv_stats.is_crypto_setkey_cipher++;
|
2004-12-08 17:26:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-05-28 23:32:00 +00:00
|
|
|
return dev_key_set(vap, key);
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add privacy headers appropriate for the specified key.
|
|
|
|
*/
|
|
|
|
struct ieee80211_key *
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_encap(struct ieee80211_node *ni, struct mbuf *m)
|
2003-06-23 16:55:01 +00:00
|
|
|
{
|
2008-04-20 20:35:46 +00:00
|
|
|
struct ieee80211vap *vap = ni->ni_vap;
|
2004-12-08 17:26:47 +00:00
|
|
|
struct ieee80211_key *k;
|
|
|
|
struct ieee80211_frame *wh;
|
|
|
|
const struct ieee80211_cipher *cip;
|
Update 802.11 wireless support:
o major overhaul of the way channels are handled: channels are now
fully enumerated and uniquely identify the operating characteristics;
these changes are visible to user applications which require changes
o make scanning support independent of the state machine to enable
background scanning and roaming
o move scanning support into loadable modules based on the operating
mode to enable different policies and reduce the memory footprint
on systems w/ constrained resources
o add background scanning in station mode (no support for adhoc/ibss
mode yet)
o significantly speedup sta mode scanning with a variety of techniques
o add roaming support when background scanning is supported; for now
we use a simple algorithm to trigger a roam: we threshold the rssi
and tx rate, if either drops too low we try to roam to a new ap
o add tx fragmentation support
o add first cut at 802.11n support: this code works with forthcoming
drivers but is incomplete; it's included now to establish a baseline
for other drivers to be developed and for user applications
o adjust max_linkhdr et. al. to reflect 802.11 requirements; this eliminates
prepending mbufs for traffic generated locally
o add support for Atheros protocol extensions; mainly the fast frames
encapsulation (note this can be used with any card that can tx+rx
large frames correctly)
o add sta support for ap's that beacon both WPA1+2 support
o change all data types from bsd-style to posix-style
o propagate noise floor data from drivers to net80211 and on to user apps
o correct various issues in the sta mode state machine related to handling
authentication and association failures
o enable the addition of sta mode power save support for drivers that need
net80211 support (not in this commit)
o remove old WI compatibility ioctls (wicontrol is officially dead)
o change the data structures returned for get sta info and get scan
results so future additions will not break user apps
o fixed tx rate is now maintained internally as an ieee rate and not an
index into the rate set; this needs to be extended to deal with
multi-mode operation
o add extended channel specifications to radiotap to enable 11n sniffing
Drivers:
o ath: add support for bg scanning, tx fragmentation, fast frames,
dynamic turbo (lightly tested), 11n (sniffing only and needs
new hal)
o awi: compile tested only
o ndis: lightly tested
o ipw: lightly tested
o iwi: add support for bg scanning (well tested but may have some
rough edges)
o ral, ural, rum: add suppoort for bg scanning, calibrate rssi data
o wi: lightly tested
This work is based on contributions by Atheros, kmacy, sephe, thompsa,
mlaier, kevlo, and others. Much of the scanning work was supported by
Atheros. The 11n work was supported by Marvell.
2007-06-11 03:36:55 +00:00
|
|
|
uint8_t keyid;
|
2004-12-08 17:26:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Multicast traffic always uses the multicast key.
|
|
|
|
* Otherwise if a unicast key is set we use that and
|
|
|
|
* it is always key index 0. When no unicast key is
|
|
|
|
* set we fall back to the default transmit key.
|
|
|
|
*/
|
|
|
|
wh = mtod(m, struct ieee80211_frame *);
|
|
|
|
if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
|
2007-03-11 06:36:10 +00:00
|
|
|
IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey)) {
|
2008-04-20 20:35:46 +00:00
|
|
|
if (vap->iv_def_txkey == IEEE80211_KEYIX_NONE) {
|
|
|
|
IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO,
|
|
|
|
wh->i_addr1,
|
|
|
|
"no default transmit key (%s) deftxkey %u",
|
|
|
|
__func__, vap->iv_def_txkey);
|
|
|
|
vap->iv_stats.is_tx_nodefkey++;
|
2004-12-08 17:26:47 +00:00
|
|
|
return NULL;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2008-04-20 20:35:46 +00:00
|
|
|
keyid = vap->iv_def_txkey;
|
|
|
|
k = &vap->iv_nw_keys[vap->iv_def_txkey];
|
2004-12-08 17:26:47 +00:00
|
|
|
} else {
|
2005-04-12 17:55:13 +00:00
|
|
|
keyid = 0;
|
2004-12-08 17:26:47 +00:00
|
|
|
k = &ni->ni_ucastkey;
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2004-12-08 17:26:47 +00:00
|
|
|
cip = k->wk_cipher;
|
2005-04-12 17:55:13 +00:00
|
|
|
return (cip->ic_encap(k, m, keyid<<6) ? k : NULL);
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-12-08 17:26:47 +00:00
|
|
|
* Validate and strip privacy headers (and trailer) for a
|
|
|
|
* received frame that has the WEP/Privacy bit set.
|
2003-06-23 16:55:01 +00:00
|
|
|
*/
|
2004-12-08 17:26:47 +00:00
|
|
|
struct ieee80211_key *
|
2008-04-20 20:35:46 +00:00
|
|
|
ieee80211_crypto_decap(struct ieee80211_node *ni, struct mbuf *m, int hdrlen)
|
2003-06-23 16:55:01 +00:00
|
|
|
{
|
2004-12-08 17:26:47 +00:00
|
|
|
#define IEEE80211_WEP_HDRLEN (IEEE80211_WEP_IVLEN + IEEE80211_WEP_KIDLEN)
|
|
|
|
#define IEEE80211_WEP_MINLEN \
|
2005-07-22 17:42:08 +00:00
|
|
|
(sizeof(struct ieee80211_frame) + \
|
2004-12-08 17:26:47 +00:00
|
|
|
IEEE80211_WEP_HDRLEN + IEEE80211_WEP_CRCLEN)
|
2008-04-20 20:35:46 +00:00
|
|
|
struct ieee80211vap *vap = ni->ni_vap;
|
2004-12-08 17:26:47 +00:00
|
|
|
struct ieee80211_key *k;
|
|
|
|
struct ieee80211_frame *wh;
|
|
|
|
const struct ieee80211_cipher *cip;
|
Update 802.11 wireless support:
o major overhaul of the way channels are handled: channels are now
fully enumerated and uniquely identify the operating characteristics;
these changes are visible to user applications which require changes
o make scanning support independent of the state machine to enable
background scanning and roaming
o move scanning support into loadable modules based on the operating
mode to enable different policies and reduce the memory footprint
on systems w/ constrained resources
o add background scanning in station mode (no support for adhoc/ibss
mode yet)
o significantly speedup sta mode scanning with a variety of techniques
o add roaming support when background scanning is supported; for now
we use a simple algorithm to trigger a roam: we threshold the rssi
and tx rate, if either drops too low we try to roam to a new ap
o add tx fragmentation support
o add first cut at 802.11n support: this code works with forthcoming
drivers but is incomplete; it's included now to establish a baseline
for other drivers to be developed and for user applications
o adjust max_linkhdr et. al. to reflect 802.11 requirements; this eliminates
prepending mbufs for traffic generated locally
o add support for Atheros protocol extensions; mainly the fast frames
encapsulation (note this can be used with any card that can tx+rx
large frames correctly)
o add sta support for ap's that beacon both WPA1+2 support
o change all data types from bsd-style to posix-style
o propagate noise floor data from drivers to net80211 and on to user apps
o correct various issues in the sta mode state machine related to handling
authentication and association failures
o enable the addition of sta mode power save support for drivers that need
net80211 support (not in this commit)
o remove old WI compatibility ioctls (wicontrol is officially dead)
o change the data structures returned for get sta info and get scan
results so future additions will not break user apps
o fixed tx rate is now maintained internally as an ieee rate and not an
index into the rate set; this needs to be extended to deal with
multi-mode operation
o add extended channel specifications to radiotap to enable 11n sniffing
Drivers:
o ath: add support for bg scanning, tx fragmentation, fast frames,
dynamic turbo (lightly tested), 11n (sniffing only and needs
new hal)
o awi: compile tested only
o ndis: lightly tested
o ipw: lightly tested
o iwi: add support for bg scanning (well tested but may have some
rough edges)
o ral, ural, rum: add suppoort for bg scanning, calibrate rssi data
o wi: lightly tested
This work is based on contributions by Atheros, kmacy, sephe, thompsa,
mlaier, kevlo, and others. Much of the scanning work was supported by
Atheros. The 11n work was supported by Marvell.
2007-06-11 03:36:55 +00:00
|
|
|
uint8_t keyid;
|
2004-12-08 17:26:47 +00:00
|
|
|
|
|
|
|
/* NB: this minimum size data frame could be bigger */
|
|
|
|
if (m->m_pkthdr.len < IEEE80211_WEP_MINLEN) {
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_DPRINTF(vap, IEEE80211_MSG_ANY,
|
2004-12-08 17:26:47 +00:00
|
|
|
"%s: WEP data frame too short, len %u\n",
|
|
|
|
__func__, m->m_pkthdr.len);
|
2008-04-20 20:35:46 +00:00
|
|
|
vap->iv_stats.is_rx_tooshort++; /* XXX need unique stat? */
|
2004-12-08 17:26:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Locate the key. If unicast and there is no unicast
|
|
|
|
* key then we fall back to the key id in the header.
|
|
|
|
* This assumes unicast keys are only configured when
|
|
|
|
* the key id in the header is meaningless (typically 0).
|
|
|
|
*/
|
|
|
|
wh = mtod(m, struct ieee80211_frame *);
|
2008-04-20 20:35:46 +00:00
|
|
|
m_copydata(m, hdrlen + IEEE80211_WEP_IVLEN, sizeof(keyid), &keyid);
|
2004-12-08 17:26:47 +00:00
|
|
|
if (IEEE80211_IS_MULTICAST(wh->i_addr1) ||
|
2007-03-11 06:36:10 +00:00
|
|
|
IEEE80211_KEY_UNDEFINED(&ni->ni_ucastkey))
|
2008-04-20 20:35:46 +00:00
|
|
|
k = &vap->iv_nw_keys[keyid >> 6];
|
2004-12-08 17:26:47 +00:00
|
|
|
else
|
|
|
|
k = &ni->ni_ucastkey;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insure crypto header is contiguous for all decap work.
|
|
|
|
*/
|
|
|
|
cip = k->wk_cipher;
|
|
|
|
if (m->m_len < hdrlen + cip->ic_header &&
|
|
|
|
(m = m_pullup(m, hdrlen + cip->ic_header)) == NULL) {
|
2008-04-20 20:35:46 +00:00
|
|
|
IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_CRYPTO, wh->i_addr2,
|
|
|
|
"unable to pullup %s header", cip->ic_name);
|
|
|
|
vap->iv_stats.is_rx_wepfail++; /* XXX */
|
Update 802.11 wireless support:
o major overhaul of the way channels are handled: channels are now
fully enumerated and uniquely identify the operating characteristics;
these changes are visible to user applications which require changes
o make scanning support independent of the state machine to enable
background scanning and roaming
o move scanning support into loadable modules based on the operating
mode to enable different policies and reduce the memory footprint
on systems w/ constrained resources
o add background scanning in station mode (no support for adhoc/ibss
mode yet)
o significantly speedup sta mode scanning with a variety of techniques
o add roaming support when background scanning is supported; for now
we use a simple algorithm to trigger a roam: we threshold the rssi
and tx rate, if either drops too low we try to roam to a new ap
o add tx fragmentation support
o add first cut at 802.11n support: this code works with forthcoming
drivers but is incomplete; it's included now to establish a baseline
for other drivers to be developed and for user applications
o adjust max_linkhdr et. al. to reflect 802.11 requirements; this eliminates
prepending mbufs for traffic generated locally
o add support for Atheros protocol extensions; mainly the fast frames
encapsulation (note this can be used with any card that can tx+rx
large frames correctly)
o add sta support for ap's that beacon both WPA1+2 support
o change all data types from bsd-style to posix-style
o propagate noise floor data from drivers to net80211 and on to user apps
o correct various issues in the sta mode state machine related to handling
authentication and association failures
o enable the addition of sta mode power save support for drivers that need
net80211 support (not in this commit)
o remove old WI compatibility ioctls (wicontrol is officially dead)
o change the data structures returned for get sta info and get scan
results so future additions will not break user apps
o fixed tx rate is now maintained internally as an ieee rate and not an
index into the rate set; this needs to be extended to deal with
multi-mode operation
o add extended channel specifications to radiotap to enable 11n sniffing
Drivers:
o ath: add support for bg scanning, tx fragmentation, fast frames,
dynamic turbo (lightly tested), 11n (sniffing only and needs
new hal)
o awi: compile tested only
o ndis: lightly tested
o ipw: lightly tested
o iwi: add support for bg scanning (well tested but may have some
rough edges)
o ral, ural, rum: add suppoort for bg scanning, calibrate rssi data
o wi: lightly tested
This work is based on contributions by Atheros, kmacy, sephe, thompsa,
mlaier, kevlo, and others. Much of the scanning work was supported by
Atheros. The 11n work was supported by Marvell.
2007-06-11 03:36:55 +00:00
|
|
|
return NULL;
|
2004-12-08 17:26:47 +00:00
|
|
|
}
|
2003-06-23 16:55:01 +00:00
|
|
|
|
2005-06-10 16:11:24 +00:00
|
|
|
return (cip->ic_decap(k, m, hdrlen) ? k : NULL);
|
2004-12-08 17:26:47 +00:00
|
|
|
#undef IEEE80211_WEP_MINLEN
|
|
|
|
#undef IEEE80211_WEP_HDRLEN
|
2003-06-23 16:55:01 +00:00
|
|
|
}
|
2008-05-28 23:33:29 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
load_ucastkey(void *arg, struct ieee80211_node *ni)
|
|
|
|
{
|
|
|
|
struct ieee80211vap *vap = ni->ni_vap;
|
|
|
|
struct ieee80211_key *k;
|
|
|
|
|
|
|
|
if (vap->iv_state != IEEE80211_S_RUN)
|
|
|
|
return;
|
|
|
|
k = &ni->ni_ucastkey;
|
2008-09-21 23:16:19 +00:00
|
|
|
if (k->wk_flags & IEEE80211_KEY_DEVKEY)
|
2008-05-28 23:33:29 +00:00
|
|
|
dev_key_set(vap, k);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Re-load all keys known to the 802.11 layer that may
|
|
|
|
* have hardware state backing them. This is used by
|
|
|
|
* drivers on resume to push keys down into the device.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ieee80211_crypto_reload_keys(struct ieee80211com *ic)
|
|
|
|
{
|
|
|
|
struct ieee80211vap *vap;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Keys in the global key table of each vap.
|
|
|
|
*/
|
|
|
|
/* NB: used only during resume so don't lock for now */
|
|
|
|
TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
|
|
|
|
if (vap->iv_state != IEEE80211_S_RUN)
|
|
|
|
continue;
|
|
|
|
for (i = 0; i < IEEE80211_WEP_NKID; i++) {
|
|
|
|
const struct ieee80211_key *k = &vap->iv_nw_keys[i];
|
2008-09-21 23:16:19 +00:00
|
|
|
if (k->wk_flags & IEEE80211_KEY_DEVKEY)
|
2008-05-28 23:33:29 +00:00
|
|
|
dev_key_set(vap, k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Unicast keys.
|
|
|
|
*/
|
|
|
|
ieee80211_iterate_nodes(&ic->ic_sta, load_ucastkey, NULL);
|
|
|
|
}
|