mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2025-04-21 12:27:27 +03:00
fix up hostapd for mac80211
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@9554 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
78
package/mac80211/src/net/mac80211/Kconfig
Normal file
78
package/mac80211/src/net/mac80211/Kconfig
Normal file
@@ -0,0 +1,78 @@
|
||||
config MAC80211
|
||||
tristate "Generic IEEE 802.11 Networking Stack (mac80211)"
|
||||
depends on EXPERIMENTAL
|
||||
select CRYPTO
|
||||
select CRYPTO_ECB
|
||||
select CRYPTO_ARC4
|
||||
select CRYPTO_AES
|
||||
select CRC32
|
||||
select WIRELESS_EXT
|
||||
select CFG80211
|
||||
select NET_SCH_FIFO
|
||||
---help---
|
||||
This option enables the hardware independent IEEE 802.11
|
||||
networking stack.
|
||||
|
||||
config MAC80211_LEDS
|
||||
bool "Enable LED triggers"
|
||||
depends on MAC80211 && LEDS_TRIGGERS
|
||||
---help---
|
||||
This option enables a few LED triggers for different
|
||||
packet receive/transmit events.
|
||||
|
||||
config MAC80211_DEBUGFS
|
||||
bool "Export mac80211 internals in DebugFS"
|
||||
depends on MAC80211 && DEBUG_FS
|
||||
---help---
|
||||
Select this to see extensive information about
|
||||
the internal state of mac80211 in debugfs.
|
||||
|
||||
Say N unless you know you need this.
|
||||
|
||||
config MAC80211_DEBUG
|
||||
bool "Enable debugging output"
|
||||
depends on MAC80211
|
||||
---help---
|
||||
This option will enable debug tracing output for the
|
||||
ieee80211 network stack.
|
||||
|
||||
If you are not trying to debug or develop the ieee80211
|
||||
subsystem, you most likely want to say N here.
|
||||
|
||||
config MAC80211_VERBOSE_DEBUG
|
||||
bool "Verbose debugging output"
|
||||
depends on MAC80211_DEBUG
|
||||
|
||||
config MAC80211_LOWTX_FRAME_DUMP
|
||||
bool "Debug frame dumping"
|
||||
depends on MAC80211_DEBUG
|
||||
---help---
|
||||
Selecting this option will cause the stack to
|
||||
print a message for each frame that is handed
|
||||
to the lowlevel driver for transmission. This
|
||||
message includes all MAC addresses and the
|
||||
frame control field.
|
||||
|
||||
If unsure, say N and insert the debugging code
|
||||
you require into the driver you are debugging.
|
||||
|
||||
config TKIP_DEBUG
|
||||
bool "TKIP debugging"
|
||||
depends on MAC80211_DEBUG
|
||||
|
||||
config MAC80211_DEBUG_COUNTERS
|
||||
bool "Extra statistics for TX/RX debugging"
|
||||
depends on MAC80211_DEBUG
|
||||
|
||||
config MAC80211_IBSS_DEBUG
|
||||
bool "Support for IBSS testing"
|
||||
depends on MAC80211_DEBUG
|
||||
---help---
|
||||
Say Y here if you intend to debug the IBSS code.
|
||||
|
||||
config MAC80211_VERBOSE_PS_DEBUG
|
||||
bool "Verbose powersave mode debugging"
|
||||
depends on MAC80211_DEBUG
|
||||
---help---
|
||||
Say Y here to print out verbose powersave
|
||||
mode debug messages.
|
||||
26
package/mac80211/src/net/mac80211/Makefile
Normal file
26
package/mac80211/src/net/mac80211/Makefile
Normal file
@@ -0,0 +1,26 @@
|
||||
obj-$(CONFIG_MAC80211) += mac80211.o rc80211_simple.o
|
||||
|
||||
mac80211-objs-$(CONFIG_MAC80211_LEDS) += ieee80211_led.o
|
||||
mac80211-objs-$(CONFIG_MAC80211_DEBUGFS) += debugfs.o debugfs_sta.o debugfs_netdev.o debugfs_key.o
|
||||
mac80211-objs-$(CONFIG_NET_SCHED) += wme.o
|
||||
|
||||
mac80211-objs := \
|
||||
ieee80211.o \
|
||||
ieee80211_ioctl.o \
|
||||
sta_info.o \
|
||||
wep.o \
|
||||
wpa.o \
|
||||
ieee80211_sta.o \
|
||||
ieee80211_iface.o \
|
||||
ieee80211_rate.o \
|
||||
michael.o \
|
||||
regdomain.o \
|
||||
tkip.o \
|
||||
aes_ccm.o \
|
||||
cfg.o \
|
||||
rx.o \
|
||||
tx.o \
|
||||
key.o \
|
||||
util.o \
|
||||
event.o \
|
||||
$(mac80211-objs-y)
|
||||
155
package/mac80211/src/net/mac80211/aes_ccm.c
Normal file
155
package/mac80211/src/net/mac80211/aes_ccm.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2003-2004, Instant802 Networks, Inc.
|
||||
* Copyright 2005-2006, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/crypto.h>
|
||||
#include <linux/err.h>
|
||||
#include <asm/scatterlist.h>
|
||||
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_key.h"
|
||||
#include "aes_ccm.h"
|
||||
|
||||
|
||||
static void ieee80211_aes_encrypt(struct crypto_cipher *tfm,
|
||||
const u8 pt[16], u8 ct[16])
|
||||
{
|
||||
crypto_cipher_encrypt_one(tfm, ct, pt);
|
||||
}
|
||||
|
||||
|
||||
static inline void aes_ccm_prepare(struct crypto_cipher *tfm, u8 *b_0, u8 *aad,
|
||||
u8 *b, u8 *s_0, u8 *a)
|
||||
{
|
||||
int i;
|
||||
|
||||
ieee80211_aes_encrypt(tfm, b_0, b);
|
||||
|
||||
/* Extra Authenticate-only data (always two AES blocks) */
|
||||
for (i = 0; i < AES_BLOCK_LEN; i++)
|
||||
aad[i] ^= b[i];
|
||||
ieee80211_aes_encrypt(tfm, aad, b);
|
||||
|
||||
aad += AES_BLOCK_LEN;
|
||||
|
||||
for (i = 0; i < AES_BLOCK_LEN; i++)
|
||||
aad[i] ^= b[i];
|
||||
ieee80211_aes_encrypt(tfm, aad, a);
|
||||
|
||||
/* Mask out bits from auth-only-b_0 */
|
||||
b_0[0] &= 0x07;
|
||||
|
||||
/* S_0 is used to encrypt T (= MIC) */
|
||||
b_0[14] = 0;
|
||||
b_0[15] = 0;
|
||||
ieee80211_aes_encrypt(tfm, b_0, s_0);
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch,
|
||||
u8 *b_0, u8 *aad, u8 *data, size_t data_len,
|
||||
u8 *cdata, u8 *mic)
|
||||
{
|
||||
int i, j, last_len, num_blocks;
|
||||
u8 *pos, *cpos, *b, *s_0, *e;
|
||||
|
||||
b = scratch;
|
||||
s_0 = scratch + AES_BLOCK_LEN;
|
||||
e = scratch + 2 * AES_BLOCK_LEN;
|
||||
|
||||
num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
|
||||
last_len = data_len % AES_BLOCK_LEN;
|
||||
aes_ccm_prepare(tfm, b_0, aad, b, s_0, b);
|
||||
|
||||
/* Process payload blocks */
|
||||
pos = data;
|
||||
cpos = cdata;
|
||||
for (j = 1; j <= num_blocks; j++) {
|
||||
int blen = (j == num_blocks && last_len) ?
|
||||
last_len : AES_BLOCK_LEN;
|
||||
|
||||
/* Authentication followed by encryption */
|
||||
for (i = 0; i < blen; i++)
|
||||
b[i] ^= pos[i];
|
||||
ieee80211_aes_encrypt(tfm, b, b);
|
||||
|
||||
b_0[14] = (j >> 8) & 0xff;
|
||||
b_0[15] = j & 0xff;
|
||||
ieee80211_aes_encrypt(tfm, b_0, e);
|
||||
for (i = 0; i < blen; i++)
|
||||
*cpos++ = *pos++ ^ e[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < CCMP_MIC_LEN; i++)
|
||||
mic[i] = b[i] ^ s_0[i];
|
||||
}
|
||||
|
||||
|
||||
int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch,
|
||||
u8 *b_0, u8 *aad, u8 *cdata, size_t data_len,
|
||||
u8 *mic, u8 *data)
|
||||
{
|
||||
int i, j, last_len, num_blocks;
|
||||
u8 *pos, *cpos, *b, *s_0, *a;
|
||||
|
||||
b = scratch;
|
||||
s_0 = scratch + AES_BLOCK_LEN;
|
||||
a = scratch + 2 * AES_BLOCK_LEN;
|
||||
|
||||
num_blocks = (data_len + AES_BLOCK_LEN - 1) / AES_BLOCK_LEN;
|
||||
last_len = data_len % AES_BLOCK_LEN;
|
||||
aes_ccm_prepare(tfm, b_0, aad, b, s_0, a);
|
||||
|
||||
/* Process payload blocks */
|
||||
cpos = cdata;
|
||||
pos = data;
|
||||
for (j = 1; j <= num_blocks; j++) {
|
||||
int blen = (j == num_blocks && last_len) ?
|
||||
last_len : AES_BLOCK_LEN;
|
||||
|
||||
/* Decryption followed by authentication */
|
||||
b_0[14] = (j >> 8) & 0xff;
|
||||
b_0[15] = j & 0xff;
|
||||
ieee80211_aes_encrypt(tfm, b_0, b);
|
||||
for (i = 0; i < blen; i++) {
|
||||
*pos = *cpos++ ^ b[i];
|
||||
a[i] ^= *pos++;
|
||||
}
|
||||
|
||||
ieee80211_aes_encrypt(tfm, a, a);
|
||||
}
|
||||
|
||||
for (i = 0; i < CCMP_MIC_LEN; i++) {
|
||||
if ((mic[i] ^ s_0[i]) != a[i])
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
struct crypto_cipher * ieee80211_aes_key_setup_encrypt(const u8 key[])
|
||||
{
|
||||
struct crypto_cipher *tfm;
|
||||
|
||||
tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
|
||||
if (IS_ERR(tfm))
|
||||
return NULL;
|
||||
|
||||
crypto_cipher_setkey(tfm, key, ALG_CCMP_KEY_LEN);
|
||||
|
||||
return tfm;
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_aes_key_free(struct crypto_cipher *tfm)
|
||||
{
|
||||
if (tfm)
|
||||
crypto_free_cipher(tfm);
|
||||
}
|
||||
26
package/mac80211/src/net/mac80211/aes_ccm.h
Normal file
26
package/mac80211/src/net/mac80211/aes_ccm.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2003-2004, Instant802 Networks, Inc.
|
||||
* Copyright 2006, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef AES_CCM_H
|
||||
#define AES_CCM_H
|
||||
|
||||
#include <linux/crypto.h>
|
||||
|
||||
#define AES_BLOCK_LEN 16
|
||||
|
||||
struct crypto_cipher * ieee80211_aes_key_setup_encrypt(const u8 key[]);
|
||||
void ieee80211_aes_ccm_encrypt(struct crypto_cipher *tfm, u8 *scratch,
|
||||
u8 *b_0, u8 *aad, u8 *data, size_t data_len,
|
||||
u8 *cdata, u8 *mic);
|
||||
int ieee80211_aes_ccm_decrypt(struct crypto_cipher *tfm, u8 *scratch,
|
||||
u8 *b_0, u8 *aad, u8 *cdata, size_t data_len,
|
||||
u8 *mic, u8 *data);
|
||||
void ieee80211_aes_key_free(struct crypto_cipher *tfm);
|
||||
|
||||
#endif /* AES_CCM_H */
|
||||
105
package/mac80211/src/net/mac80211/cfg.c
Normal file
105
package/mac80211/src/net/mac80211/cfg.c
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* mac80211 configuration hooks for cfg80211
|
||||
*
|
||||
* Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* This file is GPLv2 as found in COPYING.
|
||||
*/
|
||||
|
||||
#include <linux/nl80211.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <net/cfg80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "cfg.h"
|
||||
|
||||
static enum ieee80211_if_types
|
||||
nl80211_type_to_mac80211_type(enum nl80211_iftype type)
|
||||
{
|
||||
switch (type) {
|
||||
case NL80211_IFTYPE_UNSPECIFIED:
|
||||
return IEEE80211_IF_TYPE_STA;
|
||||
case NL80211_IFTYPE_ADHOC:
|
||||
return IEEE80211_IF_TYPE_IBSS;
|
||||
case NL80211_IFTYPE_STATION:
|
||||
return IEEE80211_IF_TYPE_STA;
|
||||
case NL80211_IFTYPE_MONITOR:
|
||||
return IEEE80211_IF_TYPE_MNTR;
|
||||
default:
|
||||
return IEEE80211_IF_TYPE_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
|
||||
enum nl80211_iftype type)
|
||||
{
|
||||
struct ieee80211_local *local = wiphy_priv(wiphy);
|
||||
enum ieee80211_if_types itype;
|
||||
|
||||
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
|
||||
return -ENODEV;
|
||||
|
||||
itype = nl80211_type_to_mac80211_type(type);
|
||||
if (itype == IEEE80211_IF_TYPE_INVALID)
|
||||
return -EINVAL;
|
||||
|
||||
return ieee80211_if_add(local->mdev, name, NULL, itype);
|
||||
}
|
||||
|
||||
static int ieee80211_del_iface(struct wiphy *wiphy, int ifindex)
|
||||
{
|
||||
struct ieee80211_local *local = wiphy_priv(wiphy);
|
||||
struct net_device *dev;
|
||||
char *name;
|
||||
|
||||
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
|
||||
return -ENODEV;
|
||||
|
||||
/* we're under RTNL */
|
||||
dev = __dev_get_by_index(ifindex);
|
||||
if (!dev)
|
||||
return 0;
|
||||
|
||||
name = dev->name;
|
||||
|
||||
return ieee80211_if_remove(local->mdev, name, -1);
|
||||
}
|
||||
|
||||
static int ieee80211_change_iface(struct wiphy *wiphy, int ifindex,
|
||||
enum nl80211_iftype type)
|
||||
{
|
||||
struct ieee80211_local *local = wiphy_priv(wiphy);
|
||||
struct net_device *dev;
|
||||
enum ieee80211_if_types itype;
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
|
||||
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED))
|
||||
return -ENODEV;
|
||||
|
||||
/* we're under RTNL */
|
||||
dev = __dev_get_by_index(ifindex);
|
||||
if (!dev)
|
||||
return -ENODEV;
|
||||
|
||||
if (netif_running(dev))
|
||||
return -EBUSY;
|
||||
|
||||
itype = nl80211_type_to_mac80211_type(type);
|
||||
if (itype == IEEE80211_IF_TYPE_INVALID)
|
||||
return -EINVAL;
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
|
||||
if (sdata->type == IEEE80211_IF_TYPE_VLAN)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
ieee80211_if_reinit(dev);
|
||||
ieee80211_if_set_type(dev, itype);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct cfg80211_ops mac80211_config_ops = {
|
||||
.add_virtual_intf = ieee80211_add_iface,
|
||||
.del_virtual_intf = ieee80211_del_iface,
|
||||
.change_virtual_intf = ieee80211_change_iface,
|
||||
};
|
||||
9
package/mac80211/src/net/mac80211/cfg.h
Normal file
9
package/mac80211/src/net/mac80211/cfg.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* mac80211 configuration hooks for cfg80211
|
||||
*/
|
||||
#ifndef __CFG_H
|
||||
#define __CFG_H
|
||||
|
||||
extern struct cfg80211_ops mac80211_config_ops;
|
||||
|
||||
#endif /* __CFG_H */
|
||||
418
package/mac80211/src/net/mac80211/debugfs.c
Normal file
418
package/mac80211/src/net/mac80211/debugfs.c
Normal file
@@ -0,0 +1,418 @@
|
||||
/*
|
||||
* mac80211 debugfs for wireless PHYs
|
||||
*
|
||||
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* GPLv2
|
||||
*
|
||||
*/
|
||||
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
#include "debugfs.h"
|
||||
|
||||
int mac80211_open_file_generic(struct inode *inode, struct file *file)
|
||||
{
|
||||
file->private_data = inode->i_private;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *ieee80211_mode_str(int mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case MODE_IEEE80211A:
|
||||
return "IEEE 802.11a";
|
||||
case MODE_IEEE80211B:
|
||||
return "IEEE 802.11b";
|
||||
case MODE_IEEE80211G:
|
||||
return "IEEE 802.11g";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
static ssize_t modes_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct ieee80211_local *local = file->private_data;
|
||||
struct ieee80211_hw_mode *mode;
|
||||
char buf[150], *p = buf;
|
||||
|
||||
/* FIXME: locking! */
|
||||
list_for_each_entry(mode, &local->modes_list, list) {
|
||||
p += scnprintf(p, sizeof(buf)+buf-p,
|
||||
"%s\n", ieee80211_mode_str(mode->mode));
|
||||
}
|
||||
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
|
||||
}
|
||||
|
||||
static const struct file_operations modes_ops = {
|
||||
.read = modes_read,
|
||||
.open = mac80211_open_file_generic,
|
||||
};
|
||||
|
||||
#define DEBUGFS_READONLY_FILE(name, buflen, fmt, value...) \
|
||||
static ssize_t name## _read(struct file *file, char __user *userbuf, \
|
||||
size_t count, loff_t *ppos) \
|
||||
{ \
|
||||
struct ieee80211_local *local = file->private_data; \
|
||||
char buf[buflen]; \
|
||||
int res; \
|
||||
\
|
||||
res = scnprintf(buf, buflen, fmt "\n", ##value); \
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
|
||||
} \
|
||||
\
|
||||
static const struct file_operations name## _ops = { \
|
||||
.read = name## _read, \
|
||||
.open = mac80211_open_file_generic, \
|
||||
};
|
||||
|
||||
#define DEBUGFS_ADD(name) \
|
||||
local->debugfs.name = debugfs_create_file(#name, 0444, phyd, \
|
||||
local, &name## _ops);
|
||||
|
||||
#define DEBUGFS_DEL(name) \
|
||||
debugfs_remove(local->debugfs.name); \
|
||||
local->debugfs.name = NULL;
|
||||
|
||||
|
||||
DEBUGFS_READONLY_FILE(channel, 20, "%d",
|
||||
local->hw.conf.channel);
|
||||
DEBUGFS_READONLY_FILE(frequency, 20, "%d",
|
||||
local->hw.conf.freq);
|
||||
DEBUGFS_READONLY_FILE(antenna_sel_tx, 20, "%d",
|
||||
local->hw.conf.antenna_sel_tx);
|
||||
DEBUGFS_READONLY_FILE(antenna_sel_rx, 20, "%d",
|
||||
local->hw.conf.antenna_sel_rx);
|
||||
DEBUGFS_READONLY_FILE(bridge_packets, 20, "%d",
|
||||
local->bridge_packets);
|
||||
DEBUGFS_READONLY_FILE(rts_threshold, 20, "%d",
|
||||
local->rts_threshold);
|
||||
DEBUGFS_READONLY_FILE(fragmentation_threshold, 20, "%d",
|
||||
local->fragmentation_threshold);
|
||||
DEBUGFS_READONLY_FILE(short_retry_limit, 20, "%d",
|
||||
local->short_retry_limit);
|
||||
DEBUGFS_READONLY_FILE(long_retry_limit, 20, "%d",
|
||||
local->long_retry_limit);
|
||||
DEBUGFS_READONLY_FILE(total_ps_buffered, 20, "%d",
|
||||
local->total_ps_buffered);
|
||||
DEBUGFS_READONLY_FILE(mode, 20, "%s",
|
||||
ieee80211_mode_str(local->hw.conf.phymode));
|
||||
DEBUGFS_READONLY_FILE(wep_iv, 20, "%#06x",
|
||||
local->wep_iv & 0xffffff);
|
||||
DEBUGFS_READONLY_FILE(rate_ctrl_alg, 100, "%s",
|
||||
local->rate_ctrl ? local->rate_ctrl->ops->name : "<unset>");
|
||||
|
||||
/* statistics stuff */
|
||||
|
||||
static inline int rtnl_lock_local(struct ieee80211_local *local)
|
||||
{
|
||||
rtnl_lock();
|
||||
if (unlikely(local->reg_state != IEEE80211_DEV_REGISTERED)) {
|
||||
rtnl_unlock();
|
||||
return -ENODEV;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define DEBUGFS_STATS_FILE(name, buflen, fmt, value...) \
|
||||
DEBUGFS_READONLY_FILE(stats_ ##name, buflen, fmt, ##value)
|
||||
|
||||
static ssize_t format_devstat_counter(struct ieee80211_local *local,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos,
|
||||
int (*printvalue)(struct ieee80211_low_level_stats *stats, char *buf,
|
||||
int buflen))
|
||||
{
|
||||
struct ieee80211_low_level_stats stats;
|
||||
char buf[20];
|
||||
int res;
|
||||
|
||||
if (!local->ops->get_stats)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
res = rtnl_lock_local(local);
|
||||
if (res)
|
||||
return res;
|
||||
|
||||
res = local->ops->get_stats(local_to_hw(local), &stats);
|
||||
rtnl_unlock();
|
||||
if (!res)
|
||||
res = printvalue(&stats, buf, sizeof(buf));
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
||||
}
|
||||
|
||||
#define DEBUGFS_DEVSTATS_FILE(name) \
|
||||
static int print_devstats_##name(struct ieee80211_low_level_stats *stats,\
|
||||
char *buf, int buflen) \
|
||||
{ \
|
||||
return scnprintf(buf, buflen, "%u\n", stats->name); \
|
||||
} \
|
||||
static ssize_t stats_ ##name## _read(struct file *file, \
|
||||
char __user *userbuf, \
|
||||
size_t count, loff_t *ppos) \
|
||||
{ \
|
||||
return format_devstat_counter(file->private_data, \
|
||||
userbuf, \
|
||||
count, \
|
||||
ppos, \
|
||||
print_devstats_##name); \
|
||||
} \
|
||||
\
|
||||
static const struct file_operations stats_ ##name## _ops = { \
|
||||
.read = stats_ ##name## _read, \
|
||||
.open = mac80211_open_file_generic, \
|
||||
};
|
||||
|
||||
#define DEBUGFS_STATS_ADD(name) \
|
||||
local->debugfs.stats.name = debugfs_create_file(#name, 0444, statsd,\
|
||||
local, &stats_ ##name## _ops);
|
||||
|
||||
#define DEBUGFS_STATS_DEL(name) \
|
||||
debugfs_remove(local->debugfs.stats.name); \
|
||||
local->debugfs.stats.name = NULL;
|
||||
|
||||
DEBUGFS_STATS_FILE(transmitted_fragment_count, 20, "%u",
|
||||
local->dot11TransmittedFragmentCount);
|
||||
DEBUGFS_STATS_FILE(multicast_transmitted_frame_count, 20, "%u",
|
||||
local->dot11MulticastTransmittedFrameCount);
|
||||
DEBUGFS_STATS_FILE(failed_count, 20, "%u",
|
||||
local->dot11FailedCount);
|
||||
DEBUGFS_STATS_FILE(retry_count, 20, "%u",
|
||||
local->dot11RetryCount);
|
||||
DEBUGFS_STATS_FILE(multiple_retry_count, 20, "%u",
|
||||
local->dot11MultipleRetryCount);
|
||||
DEBUGFS_STATS_FILE(frame_duplicate_count, 20, "%u",
|
||||
local->dot11FrameDuplicateCount);
|
||||
DEBUGFS_STATS_FILE(received_fragment_count, 20, "%u",
|
||||
local->dot11ReceivedFragmentCount);
|
||||
DEBUGFS_STATS_FILE(multicast_received_frame_count, 20, "%u",
|
||||
local->dot11MulticastReceivedFrameCount);
|
||||
DEBUGFS_STATS_FILE(transmitted_frame_count, 20, "%u",
|
||||
local->dot11TransmittedFrameCount);
|
||||
DEBUGFS_STATS_FILE(wep_undecryptable_count, 20, "%u",
|
||||
local->dot11WEPUndecryptableCount);
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
DEBUGFS_STATS_FILE(tx_handlers_drop, 20, "%u",
|
||||
local->tx_handlers_drop);
|
||||
DEBUGFS_STATS_FILE(tx_handlers_queued, 20, "%u",
|
||||
local->tx_handlers_queued);
|
||||
DEBUGFS_STATS_FILE(tx_handlers_drop_unencrypted, 20, "%u",
|
||||
local->tx_handlers_drop_unencrypted);
|
||||
DEBUGFS_STATS_FILE(tx_handlers_drop_fragment, 20, "%u",
|
||||
local->tx_handlers_drop_fragment);
|
||||
DEBUGFS_STATS_FILE(tx_handlers_drop_wep, 20, "%u",
|
||||
local->tx_handlers_drop_wep);
|
||||
DEBUGFS_STATS_FILE(tx_handlers_drop_not_assoc, 20, "%u",
|
||||
local->tx_handlers_drop_not_assoc);
|
||||
DEBUGFS_STATS_FILE(tx_handlers_drop_unauth_port, 20, "%u",
|
||||
local->tx_handlers_drop_unauth_port);
|
||||
DEBUGFS_STATS_FILE(rx_handlers_drop, 20, "%u",
|
||||
local->rx_handlers_drop);
|
||||
DEBUGFS_STATS_FILE(rx_handlers_queued, 20, "%u",
|
||||
local->rx_handlers_queued);
|
||||
DEBUGFS_STATS_FILE(rx_handlers_drop_nullfunc, 20, "%u",
|
||||
local->rx_handlers_drop_nullfunc);
|
||||
DEBUGFS_STATS_FILE(rx_handlers_drop_defrag, 20, "%u",
|
||||
local->rx_handlers_drop_defrag);
|
||||
DEBUGFS_STATS_FILE(rx_handlers_drop_short, 20, "%u",
|
||||
local->rx_handlers_drop_short);
|
||||
DEBUGFS_STATS_FILE(rx_handlers_drop_passive_scan, 20, "%u",
|
||||
local->rx_handlers_drop_passive_scan);
|
||||
DEBUGFS_STATS_FILE(tx_expand_skb_head, 20, "%u",
|
||||
local->tx_expand_skb_head);
|
||||
DEBUGFS_STATS_FILE(tx_expand_skb_head_cloned, 20, "%u",
|
||||
local->tx_expand_skb_head_cloned);
|
||||
DEBUGFS_STATS_FILE(rx_expand_skb_head, 20, "%u",
|
||||
local->rx_expand_skb_head);
|
||||
DEBUGFS_STATS_FILE(rx_expand_skb_head2, 20, "%u",
|
||||
local->rx_expand_skb_head2);
|
||||
DEBUGFS_STATS_FILE(rx_handlers_fragments, 20, "%u",
|
||||
local->rx_handlers_fragments);
|
||||
DEBUGFS_STATS_FILE(tx_status_drop, 20, "%u",
|
||||
local->tx_status_drop);
|
||||
|
||||
static ssize_t stats_wme_rx_queue_read(struct file *file,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct ieee80211_local *local = file->private_data;
|
||||
char buf[NUM_RX_DATA_QUEUES*15], *p = buf;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += scnprintf(p, sizeof(buf)+buf-p,
|
||||
"%u\n", local->wme_rx_queue[i]);
|
||||
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
|
||||
}
|
||||
|
||||
static const struct file_operations stats_wme_rx_queue_ops = {
|
||||
.read = stats_wme_rx_queue_read,
|
||||
.open = mac80211_open_file_generic,
|
||||
};
|
||||
|
||||
static ssize_t stats_wme_tx_queue_read(struct file *file,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct ieee80211_local *local = file->private_data;
|
||||
char buf[NUM_TX_DATA_QUEUES*15], *p = buf;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
|
||||
p += scnprintf(p, sizeof(buf)+buf-p,
|
||||
"%u\n", local->wme_tx_queue[i]);
|
||||
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, p-buf);
|
||||
}
|
||||
|
||||
static const struct file_operations stats_wme_tx_queue_ops = {
|
||||
.read = stats_wme_tx_queue_read,
|
||||
.open = mac80211_open_file_generic,
|
||||
};
|
||||
#endif
|
||||
|
||||
DEBUGFS_DEVSTATS_FILE(dot11ACKFailureCount);
|
||||
DEBUGFS_DEVSTATS_FILE(dot11RTSFailureCount);
|
||||
DEBUGFS_DEVSTATS_FILE(dot11FCSErrorCount);
|
||||
DEBUGFS_DEVSTATS_FILE(dot11RTSSuccessCount);
|
||||
|
||||
|
||||
void debugfs_hw_add(struct ieee80211_local *local)
|
||||
{
|
||||
struct dentry *phyd = local->hw.wiphy->debugfsdir;
|
||||
struct dentry *statsd;
|
||||
|
||||
if (!phyd)
|
||||
return;
|
||||
|
||||
local->debugfs.stations = debugfs_create_dir("stations", phyd);
|
||||
local->debugfs.keys = debugfs_create_dir("keys", phyd);
|
||||
|
||||
DEBUGFS_ADD(channel);
|
||||
DEBUGFS_ADD(frequency);
|
||||
DEBUGFS_ADD(antenna_sel_tx);
|
||||
DEBUGFS_ADD(antenna_sel_rx);
|
||||
DEBUGFS_ADD(bridge_packets);
|
||||
DEBUGFS_ADD(rts_threshold);
|
||||
DEBUGFS_ADD(fragmentation_threshold);
|
||||
DEBUGFS_ADD(short_retry_limit);
|
||||
DEBUGFS_ADD(long_retry_limit);
|
||||
DEBUGFS_ADD(total_ps_buffered);
|
||||
DEBUGFS_ADD(mode);
|
||||
DEBUGFS_ADD(wep_iv);
|
||||
DEBUGFS_ADD(modes);
|
||||
|
||||
statsd = debugfs_create_dir("statistics", phyd);
|
||||
local->debugfs.statistics = statsd;
|
||||
|
||||
/* if the dir failed, don't put all the other things into the root! */
|
||||
if (!statsd)
|
||||
return;
|
||||
|
||||
DEBUGFS_STATS_ADD(transmitted_fragment_count);
|
||||
DEBUGFS_STATS_ADD(multicast_transmitted_frame_count);
|
||||
DEBUGFS_STATS_ADD(failed_count);
|
||||
DEBUGFS_STATS_ADD(retry_count);
|
||||
DEBUGFS_STATS_ADD(multiple_retry_count);
|
||||
DEBUGFS_STATS_ADD(frame_duplicate_count);
|
||||
DEBUGFS_STATS_ADD(received_fragment_count);
|
||||
DEBUGFS_STATS_ADD(multicast_received_frame_count);
|
||||
DEBUGFS_STATS_ADD(transmitted_frame_count);
|
||||
DEBUGFS_STATS_ADD(wep_undecryptable_count);
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
DEBUGFS_STATS_ADD(tx_handlers_drop);
|
||||
DEBUGFS_STATS_ADD(tx_handlers_queued);
|
||||
DEBUGFS_STATS_ADD(tx_handlers_drop_unencrypted);
|
||||
DEBUGFS_STATS_ADD(tx_handlers_drop_fragment);
|
||||
DEBUGFS_STATS_ADD(tx_handlers_drop_wep);
|
||||
DEBUGFS_STATS_ADD(tx_handlers_drop_not_assoc);
|
||||
DEBUGFS_STATS_ADD(tx_handlers_drop_unauth_port);
|
||||
DEBUGFS_STATS_ADD(rx_handlers_drop);
|
||||
DEBUGFS_STATS_ADD(rx_handlers_queued);
|
||||
DEBUGFS_STATS_ADD(rx_handlers_drop_nullfunc);
|
||||
DEBUGFS_STATS_ADD(rx_handlers_drop_defrag);
|
||||
DEBUGFS_STATS_ADD(rx_handlers_drop_short);
|
||||
DEBUGFS_STATS_ADD(rx_handlers_drop_passive_scan);
|
||||
DEBUGFS_STATS_ADD(tx_expand_skb_head);
|
||||
DEBUGFS_STATS_ADD(tx_expand_skb_head_cloned);
|
||||
DEBUGFS_STATS_ADD(rx_expand_skb_head);
|
||||
DEBUGFS_STATS_ADD(rx_expand_skb_head2);
|
||||
DEBUGFS_STATS_ADD(rx_handlers_fragments);
|
||||
DEBUGFS_STATS_ADD(tx_status_drop);
|
||||
DEBUGFS_STATS_ADD(wme_tx_queue);
|
||||
DEBUGFS_STATS_ADD(wme_rx_queue);
|
||||
#endif
|
||||
DEBUGFS_STATS_ADD(dot11ACKFailureCount);
|
||||
DEBUGFS_STATS_ADD(dot11RTSFailureCount);
|
||||
DEBUGFS_STATS_ADD(dot11FCSErrorCount);
|
||||
DEBUGFS_STATS_ADD(dot11RTSSuccessCount);
|
||||
}
|
||||
|
||||
void debugfs_hw_del(struct ieee80211_local *local)
|
||||
{
|
||||
DEBUGFS_DEL(channel);
|
||||
DEBUGFS_DEL(frequency);
|
||||
DEBUGFS_DEL(antenna_sel_tx);
|
||||
DEBUGFS_DEL(antenna_sel_rx);
|
||||
DEBUGFS_DEL(bridge_packets);
|
||||
DEBUGFS_DEL(rts_threshold);
|
||||
DEBUGFS_DEL(fragmentation_threshold);
|
||||
DEBUGFS_DEL(short_retry_limit);
|
||||
DEBUGFS_DEL(long_retry_limit);
|
||||
DEBUGFS_DEL(total_ps_buffered);
|
||||
DEBUGFS_DEL(mode);
|
||||
DEBUGFS_DEL(wep_iv);
|
||||
DEBUGFS_DEL(modes);
|
||||
|
||||
DEBUGFS_STATS_DEL(transmitted_fragment_count);
|
||||
DEBUGFS_STATS_DEL(multicast_transmitted_frame_count);
|
||||
DEBUGFS_STATS_DEL(failed_count);
|
||||
DEBUGFS_STATS_DEL(retry_count);
|
||||
DEBUGFS_STATS_DEL(multiple_retry_count);
|
||||
DEBUGFS_STATS_DEL(frame_duplicate_count);
|
||||
DEBUGFS_STATS_DEL(received_fragment_count);
|
||||
DEBUGFS_STATS_DEL(multicast_received_frame_count);
|
||||
DEBUGFS_STATS_DEL(transmitted_frame_count);
|
||||
DEBUGFS_STATS_DEL(wep_undecryptable_count);
|
||||
DEBUGFS_STATS_DEL(num_scans);
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
DEBUGFS_STATS_DEL(tx_handlers_drop);
|
||||
DEBUGFS_STATS_DEL(tx_handlers_queued);
|
||||
DEBUGFS_STATS_DEL(tx_handlers_drop_unencrypted);
|
||||
DEBUGFS_STATS_DEL(tx_handlers_drop_fragment);
|
||||
DEBUGFS_STATS_DEL(tx_handlers_drop_wep);
|
||||
DEBUGFS_STATS_DEL(tx_handlers_drop_not_assoc);
|
||||
DEBUGFS_STATS_DEL(tx_handlers_drop_unauth_port);
|
||||
DEBUGFS_STATS_DEL(rx_handlers_drop);
|
||||
DEBUGFS_STATS_DEL(rx_handlers_queued);
|
||||
DEBUGFS_STATS_DEL(rx_handlers_drop_nullfunc);
|
||||
DEBUGFS_STATS_DEL(rx_handlers_drop_defrag);
|
||||
DEBUGFS_STATS_DEL(rx_handlers_drop_short);
|
||||
DEBUGFS_STATS_DEL(rx_handlers_drop_passive_scan);
|
||||
DEBUGFS_STATS_DEL(tx_expand_skb_head);
|
||||
DEBUGFS_STATS_DEL(tx_expand_skb_head_cloned);
|
||||
DEBUGFS_STATS_DEL(rx_expand_skb_head);
|
||||
DEBUGFS_STATS_DEL(rx_expand_skb_head2);
|
||||
DEBUGFS_STATS_DEL(rx_handlers_fragments);
|
||||
DEBUGFS_STATS_DEL(tx_status_drop);
|
||||
DEBUGFS_STATS_DEL(wme_tx_queue);
|
||||
DEBUGFS_STATS_DEL(wme_rx_queue);
|
||||
#endif
|
||||
DEBUGFS_STATS_DEL(dot11ACKFailureCount);
|
||||
DEBUGFS_STATS_DEL(dot11RTSFailureCount);
|
||||
DEBUGFS_STATS_DEL(dot11FCSErrorCount);
|
||||
DEBUGFS_STATS_DEL(dot11RTSSuccessCount);
|
||||
|
||||
debugfs_remove(local->debugfs.statistics);
|
||||
local->debugfs.statistics = NULL;
|
||||
debugfs_remove(local->debugfs.stations);
|
||||
local->debugfs.stations = NULL;
|
||||
debugfs_remove(local->debugfs.keys);
|
||||
local->debugfs.keys = NULL;
|
||||
}
|
||||
16
package/mac80211/src/net/mac80211/debugfs.h
Normal file
16
package/mac80211/src/net/mac80211/debugfs.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#ifndef __MAC80211_DEBUGFS_H
|
||||
#define __MAC80211_DEBUGFS_H
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
extern void debugfs_hw_add(struct ieee80211_local *local);
|
||||
extern void debugfs_hw_del(struct ieee80211_local *local);
|
||||
extern int mac80211_open_file_generic(struct inode *inode, struct file *file);
|
||||
#else
|
||||
static inline void debugfs_hw_add(struct ieee80211_local *local)
|
||||
{
|
||||
return;
|
||||
}
|
||||
static inline void debugfs_hw_del(struct ieee80211_local *local) {}
|
||||
#endif
|
||||
|
||||
#endif /* __MAC80211_DEBUGFS_H */
|
||||
279
package/mac80211/src/net/mac80211/debugfs_key.c
Normal file
279
package/mac80211/src/net/mac80211/debugfs_key.c
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
* Copyright 2003-2005 Devicescape Software, Inc.
|
||||
* Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
|
||||
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kobject.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_key.h"
|
||||
#include "debugfs.h"
|
||||
#include "debugfs_key.h"
|
||||
|
||||
#define KEY_READ(name, prop, buflen, format_string) \
|
||||
static ssize_t key_##name##_read(struct file *file, \
|
||||
char __user *userbuf, \
|
||||
size_t count, loff_t *ppos) \
|
||||
{ \
|
||||
char buf[buflen]; \
|
||||
struct ieee80211_key *key = file->private_data; \
|
||||
int res = scnprintf(buf, buflen, format_string, key->prop); \
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
|
||||
}
|
||||
#define KEY_READ_D(name) KEY_READ(name, name, 20, "%d\n")
|
||||
#define KEY_READ_X(name) KEY_READ(name, name, 20, "0x%x\n")
|
||||
|
||||
#define KEY_OPS(name) \
|
||||
static const struct file_operations key_ ##name## _ops = { \
|
||||
.read = key_##name##_read, \
|
||||
.open = mac80211_open_file_generic, \
|
||||
}
|
||||
|
||||
#define KEY_FILE(name, format) \
|
||||
KEY_READ_##format(name) \
|
||||
KEY_OPS(name)
|
||||
|
||||
#define KEY_CONF_READ(name, buflen, format_string) \
|
||||
KEY_READ(conf_##name, conf.name, buflen, format_string)
|
||||
#define KEY_CONF_READ_D(name) KEY_CONF_READ(name, 20, "%d\n")
|
||||
|
||||
#define KEY_CONF_OPS(name) \
|
||||
static const struct file_operations key_ ##name## _ops = { \
|
||||
.read = key_conf_##name##_read, \
|
||||
.open = mac80211_open_file_generic, \
|
||||
}
|
||||
|
||||
#define KEY_CONF_FILE(name, format) \
|
||||
KEY_CONF_READ_##format(name) \
|
||||
KEY_CONF_OPS(name)
|
||||
|
||||
KEY_CONF_FILE(keylen, D);
|
||||
KEY_CONF_FILE(keyidx, D);
|
||||
KEY_CONF_FILE(hw_key_idx, D);
|
||||
KEY_FILE(flags, X);
|
||||
KEY_FILE(tx_rx_count, D);
|
||||
KEY_READ(ifindex, sdata->dev->ifindex, 20, "%d\n");
|
||||
KEY_OPS(ifindex);
|
||||
|
||||
static ssize_t key_algorithm_read(struct file *file,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char *alg;
|
||||
struct ieee80211_key *key = file->private_data;
|
||||
|
||||
switch (key->conf.alg) {
|
||||
case ALG_WEP:
|
||||
alg = "WEP\n";
|
||||
break;
|
||||
case ALG_TKIP:
|
||||
alg = "TKIP\n";
|
||||
break;
|
||||
case ALG_CCMP:
|
||||
alg = "CCMP\n";
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return simple_read_from_buffer(userbuf, count, ppos, alg, strlen(alg));
|
||||
}
|
||||
KEY_OPS(algorithm);
|
||||
|
||||
static ssize_t key_tx_spec_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
const u8 *tpn;
|
||||
char buf[20];
|
||||
int len;
|
||||
struct ieee80211_key *key = file->private_data;
|
||||
|
||||
switch (key->conf.alg) {
|
||||
case ALG_WEP:
|
||||
len = scnprintf(buf, sizeof(buf), "\n");
|
||||
break;
|
||||
case ALG_TKIP:
|
||||
len = scnprintf(buf, sizeof(buf), "%08x %04x\n",
|
||||
key->u.tkip.iv32,
|
||||
key->u.tkip.iv16);
|
||||
break;
|
||||
case ALG_CCMP:
|
||||
tpn = key->u.ccmp.tx_pn;
|
||||
len = scnprintf(buf, sizeof(buf), "%02x%02x%02x%02x%02x%02x\n",
|
||||
tpn[0], tpn[1], tpn[2], tpn[3], tpn[4], tpn[5]);
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, len);
|
||||
}
|
||||
KEY_OPS(tx_spec);
|
||||
|
||||
static ssize_t key_rx_spec_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct ieee80211_key *key = file->private_data;
|
||||
char buf[14*NUM_RX_DATA_QUEUES+1], *p = buf;
|
||||
int i, len;
|
||||
const u8 *rpn;
|
||||
|
||||
switch (key->conf.alg) {
|
||||
case ALG_WEP:
|
||||
len = scnprintf(buf, sizeof(buf), "\n");
|
||||
break;
|
||||
case ALG_TKIP:
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += scnprintf(p, sizeof(buf)+buf-p,
|
||||
"%08x %04x\n",
|
||||
key->u.tkip.iv32_rx[i],
|
||||
key->u.tkip.iv16_rx[i]);
|
||||
len = p - buf;
|
||||
break;
|
||||
case ALG_CCMP:
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
|
||||
rpn = key->u.ccmp.rx_pn[i];
|
||||
p += scnprintf(p, sizeof(buf)+buf-p,
|
||||
"%02x%02x%02x%02x%02x%02x\n",
|
||||
rpn[0], rpn[1], rpn[2],
|
||||
rpn[3], rpn[4], rpn[5]);
|
||||
}
|
||||
len = p - buf;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, len);
|
||||
}
|
||||
KEY_OPS(rx_spec);
|
||||
|
||||
static ssize_t key_replays_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct ieee80211_key *key = file->private_data;
|
||||
char buf[20];
|
||||
int len;
|
||||
|
||||
if (key->conf.alg != ALG_CCMP)
|
||||
return 0;
|
||||
len = scnprintf(buf, sizeof(buf), "%u\n", key->u.ccmp.replays);
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, len);
|
||||
}
|
||||
KEY_OPS(replays);
|
||||
|
||||
static ssize_t key_key_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct ieee80211_key *key = file->private_data;
|
||||
int i, res, bufsize = 2 * key->conf.keylen + 2;
|
||||
char *buf = kmalloc(bufsize, GFP_KERNEL);
|
||||
char *p = buf;
|
||||
|
||||
for (i = 0; i < key->conf.keylen; i++)
|
||||
p += scnprintf(p, bufsize + buf - p, "%02x", key->conf.key[i]);
|
||||
p += scnprintf(p, bufsize+buf-p, "\n");
|
||||
res = simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
kfree(buf);
|
||||
return res;
|
||||
}
|
||||
KEY_OPS(key);
|
||||
|
||||
#define DEBUGFS_ADD(name) \
|
||||
key->debugfs.name = debugfs_create_file(#name, 0400,\
|
||||
key->debugfs.dir, key, &key_##name##_ops);
|
||||
|
||||
void ieee80211_debugfs_key_add(struct ieee80211_local *local,
|
||||
struct ieee80211_key *key)
|
||||
{
|
||||
static int keycount;
|
||||
char buf[20];
|
||||
|
||||
if (!local->debugfs.keys)
|
||||
return;
|
||||
|
||||
sprintf(buf, "%d", keycount);
|
||||
keycount++;
|
||||
key->debugfs.dir = debugfs_create_dir(buf,
|
||||
local->debugfs.keys);
|
||||
|
||||
if (!key->debugfs.dir)
|
||||
return;
|
||||
|
||||
DEBUGFS_ADD(keylen);
|
||||
DEBUGFS_ADD(flags);
|
||||
DEBUGFS_ADD(keyidx);
|
||||
DEBUGFS_ADD(hw_key_idx);
|
||||
DEBUGFS_ADD(tx_rx_count);
|
||||
DEBUGFS_ADD(algorithm);
|
||||
DEBUGFS_ADD(tx_spec);
|
||||
DEBUGFS_ADD(rx_spec);
|
||||
DEBUGFS_ADD(replays);
|
||||
DEBUGFS_ADD(key);
|
||||
DEBUGFS_ADD(ifindex);
|
||||
};
|
||||
|
||||
#define DEBUGFS_DEL(name) \
|
||||
debugfs_remove(key->debugfs.name); key->debugfs.name = NULL;
|
||||
|
||||
void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
|
||||
{
|
||||
if (!key)
|
||||
return;
|
||||
|
||||
DEBUGFS_DEL(keylen);
|
||||
DEBUGFS_DEL(flags);
|
||||
DEBUGFS_DEL(keyidx);
|
||||
DEBUGFS_DEL(hw_key_idx);
|
||||
DEBUGFS_DEL(tx_rx_count);
|
||||
DEBUGFS_DEL(algorithm);
|
||||
DEBUGFS_DEL(tx_spec);
|
||||
DEBUGFS_DEL(rx_spec);
|
||||
DEBUGFS_DEL(replays);
|
||||
DEBUGFS_DEL(key);
|
||||
DEBUGFS_DEL(ifindex);
|
||||
|
||||
debugfs_remove(key->debugfs.stalink);
|
||||
key->debugfs.stalink = NULL;
|
||||
debugfs_remove(key->debugfs.dir);
|
||||
key->debugfs.dir = NULL;
|
||||
}
|
||||
void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
char buf[50];
|
||||
|
||||
if (!sdata->debugfsdir)
|
||||
return;
|
||||
|
||||
sprintf(buf, "../keys/%d", sdata->default_key->conf.keyidx);
|
||||
sdata->debugfs.default_key =
|
||||
debugfs_create_symlink("default_key", sdata->debugfsdir, buf);
|
||||
}
|
||||
void ieee80211_debugfs_key_remove_default(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
if (!sdata)
|
||||
return;
|
||||
|
||||
debugfs_remove(sdata->debugfs.default_key);
|
||||
sdata->debugfs.default_key = NULL;
|
||||
}
|
||||
void ieee80211_debugfs_key_sta_link(struct ieee80211_key *key,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
char buf[50];
|
||||
|
||||
if (!key->debugfs.dir)
|
||||
return;
|
||||
|
||||
sprintf(buf, "../../stations/" MAC_FMT, MAC_ARG(sta->addr));
|
||||
key->debugfs.stalink =
|
||||
debugfs_create_symlink("station", key->debugfs.dir, buf);
|
||||
}
|
||||
|
||||
void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
debugfs_remove(key->debugfs.stalink);
|
||||
key->debugfs.stalink = NULL;
|
||||
}
|
||||
34
package/mac80211/src/net/mac80211/debugfs_key.h
Normal file
34
package/mac80211/src/net/mac80211/debugfs_key.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef __MAC80211_DEBUGFS_KEY_H
|
||||
#define __MAC80211_DEBUGFS_KEY_H
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
void ieee80211_debugfs_key_add(struct ieee80211_local *local,
|
||||
struct ieee80211_key *key);
|
||||
void ieee80211_debugfs_key_remove(struct ieee80211_key *key);
|
||||
void ieee80211_debugfs_key_add_default(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_debugfs_key_remove_default(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_debugfs_key_sta_link(struct ieee80211_key *key,
|
||||
struct sta_info *sta);
|
||||
void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
|
||||
struct sta_info *sta);
|
||||
#else
|
||||
static inline void ieee80211_debugfs_key_add(struct ieee80211_local *local,
|
||||
struct ieee80211_key *key)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_key_remove(struct ieee80211_key *key)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_key_add_default(
|
||||
struct ieee80211_sub_if_data *sdata)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_key_remove_default(
|
||||
struct ieee80211_sub_if_data *sdata)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_key_sta_link(
|
||||
struct ieee80211_key *key, struct sta_info *sta)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_key_sta_del(struct ieee80211_key *key,
|
||||
struct sta_info *sta)
|
||||
{}
|
||||
#endif
|
||||
|
||||
#endif /* __MAC80211_DEBUGFS_KEY_H */
|
||||
424
package/mac80211/src/net/mac80211/debugfs_netdev.c
Normal file
424
package/mac80211/src/net/mac80211/debugfs_netdev.c
Normal file
@@ -0,0 +1,424 @@
|
||||
/*
|
||||
* Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
|
||||
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <net/mac80211.h>
|
||||
#include <net/cfg80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
#include "debugfs.h"
|
||||
#include "debugfs_netdev.h"
|
||||
|
||||
static ssize_t ieee80211_if_read(
|
||||
struct ieee80211_sub_if_data *sdata,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos,
|
||||
ssize_t (*format)(const struct ieee80211_sub_if_data *, char *, int))
|
||||
{
|
||||
char buf[70];
|
||||
ssize_t ret = -EINVAL;
|
||||
|
||||
read_lock(&dev_base_lock);
|
||||
if (sdata->dev->reg_state == NETREG_REGISTERED) {
|
||||
ret = (*format)(sdata, buf, sizeof(buf));
|
||||
ret = simple_read_from_buffer(userbuf, count, ppos, buf, ret);
|
||||
}
|
||||
read_unlock(&dev_base_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define IEEE80211_IF_FMT(name, field, format_string) \
|
||||
static ssize_t ieee80211_if_fmt_##name( \
|
||||
const struct ieee80211_sub_if_data *sdata, char *buf, \
|
||||
int buflen) \
|
||||
{ \
|
||||
return scnprintf(buf, buflen, format_string, sdata->field); \
|
||||
}
|
||||
#define IEEE80211_IF_FMT_DEC(name, field) \
|
||||
IEEE80211_IF_FMT(name, field, "%d\n")
|
||||
#define IEEE80211_IF_FMT_HEX(name, field) \
|
||||
IEEE80211_IF_FMT(name, field, "%#x\n")
|
||||
#define IEEE80211_IF_FMT_SIZE(name, field) \
|
||||
IEEE80211_IF_FMT(name, field, "%zd\n")
|
||||
|
||||
#define IEEE80211_IF_FMT_ATOMIC(name, field) \
|
||||
static ssize_t ieee80211_if_fmt_##name( \
|
||||
const struct ieee80211_sub_if_data *sdata, \
|
||||
char *buf, int buflen) \
|
||||
{ \
|
||||
return scnprintf(buf, buflen, "%d\n", atomic_read(&sdata->field));\
|
||||
}
|
||||
|
||||
#define IEEE80211_IF_FMT_MAC(name, field) \
|
||||
static ssize_t ieee80211_if_fmt_##name( \
|
||||
const struct ieee80211_sub_if_data *sdata, char *buf, \
|
||||
int buflen) \
|
||||
{ \
|
||||
return scnprintf(buf, buflen, MAC_FMT "\n", MAC_ARG(sdata->field));\
|
||||
}
|
||||
|
||||
#define __IEEE80211_IF_FILE(name) \
|
||||
static ssize_t ieee80211_if_read_##name(struct file *file, \
|
||||
char __user *userbuf, \
|
||||
size_t count, loff_t *ppos) \
|
||||
{ \
|
||||
return ieee80211_if_read(file->private_data, \
|
||||
userbuf, count, ppos, \
|
||||
ieee80211_if_fmt_##name); \
|
||||
} \
|
||||
static const struct file_operations name##_ops = { \
|
||||
.read = ieee80211_if_read_##name, \
|
||||
.open = mac80211_open_file_generic, \
|
||||
}
|
||||
|
||||
#define IEEE80211_IF_FILE(name, field, format) \
|
||||
IEEE80211_IF_FMT_##format(name, field) \
|
||||
__IEEE80211_IF_FILE(name)
|
||||
|
||||
/* common attributes */
|
||||
IEEE80211_IF_FILE(channel_use, channel_use, DEC);
|
||||
IEEE80211_IF_FILE(drop_unencrypted, drop_unencrypted, DEC);
|
||||
IEEE80211_IF_FILE(eapol, eapol, DEC);
|
||||
IEEE80211_IF_FILE(ieee8021_x, ieee802_1x, DEC);
|
||||
|
||||
/* STA/IBSS attributes */
|
||||
IEEE80211_IF_FILE(state, u.sta.state, DEC);
|
||||
IEEE80211_IF_FILE(bssid, u.sta.bssid, MAC);
|
||||
IEEE80211_IF_FILE(prev_bssid, u.sta.prev_bssid, MAC);
|
||||
IEEE80211_IF_FILE(ssid_len, u.sta.ssid_len, SIZE);
|
||||
IEEE80211_IF_FILE(aid, u.sta.aid, DEC);
|
||||
IEEE80211_IF_FILE(ap_capab, u.sta.ap_capab, HEX);
|
||||
IEEE80211_IF_FILE(capab, u.sta.capab, HEX);
|
||||
IEEE80211_IF_FILE(extra_ie_len, u.sta.extra_ie_len, SIZE);
|
||||
IEEE80211_IF_FILE(auth_tries, u.sta.auth_tries, DEC);
|
||||
IEEE80211_IF_FILE(assoc_tries, u.sta.assoc_tries, DEC);
|
||||
IEEE80211_IF_FILE(auth_algs, u.sta.auth_algs, HEX);
|
||||
IEEE80211_IF_FILE(auth_alg, u.sta.auth_alg, DEC);
|
||||
IEEE80211_IF_FILE(auth_transaction, u.sta.auth_transaction, DEC);
|
||||
|
||||
static ssize_t ieee80211_if_fmt_flags(
|
||||
const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
|
||||
{
|
||||
return scnprintf(buf, buflen, "%s%s%s%s%s%s%s\n",
|
||||
sdata->u.sta.flags & IEEE80211_STA_SSID_SET ? "SSID\n" : "",
|
||||
sdata->u.sta.flags & IEEE80211_STA_BSSID_SET ? "BSSID\n" : "",
|
||||
sdata->u.sta.flags & IEEE80211_STA_PREV_BSSID_SET ? "prev BSSID\n" : "",
|
||||
sdata->u.sta.flags & IEEE80211_STA_AUTHENTICATED ? "AUTH\n" : "",
|
||||
sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED ? "ASSOC\n" : "",
|
||||
sdata->u.sta.flags & IEEE80211_STA_PROBEREQ_POLL ? "PROBEREQ POLL\n" : "",
|
||||
sdata->flags & IEEE80211_SDATA_USE_PROTECTION ? "CTS prot\n" : "");
|
||||
}
|
||||
__IEEE80211_IF_FILE(flags);
|
||||
|
||||
/* AP attributes */
|
||||
IEEE80211_IF_FILE(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
|
||||
IEEE80211_IF_FILE(dtim_period, u.ap.dtim_period, DEC);
|
||||
IEEE80211_IF_FILE(dtim_count, u.ap.dtim_count, DEC);
|
||||
IEEE80211_IF_FILE(num_beacons, u.ap.num_beacons, DEC);
|
||||
IEEE80211_IF_FILE(force_unicast_rateidx, u.ap.force_unicast_rateidx, DEC);
|
||||
IEEE80211_IF_FILE(max_ratectrl_rateidx, u.ap.max_ratectrl_rateidx, DEC);
|
||||
|
||||
static ssize_t ieee80211_if_fmt_num_buffered_multicast(
|
||||
const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
|
||||
{
|
||||
return scnprintf(buf, buflen, "%u\n",
|
||||
skb_queue_len(&sdata->u.ap.ps_bc_buf));
|
||||
}
|
||||
__IEEE80211_IF_FILE(num_buffered_multicast);
|
||||
|
||||
static ssize_t ieee80211_if_fmt_beacon_head_len(
|
||||
const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
|
||||
{
|
||||
if (sdata->u.ap.beacon_head)
|
||||
return scnprintf(buf, buflen, "%d\n",
|
||||
sdata->u.ap.beacon_head_len);
|
||||
return scnprintf(buf, buflen, "\n");
|
||||
}
|
||||
__IEEE80211_IF_FILE(beacon_head_len);
|
||||
|
||||
static ssize_t ieee80211_if_fmt_beacon_tail_len(
|
||||
const struct ieee80211_sub_if_data *sdata, char *buf, int buflen)
|
||||
{
|
||||
if (sdata->u.ap.beacon_tail)
|
||||
return scnprintf(buf, buflen, "%d\n",
|
||||
sdata->u.ap.beacon_tail_len);
|
||||
return scnprintf(buf, buflen, "\n");
|
||||
}
|
||||
__IEEE80211_IF_FILE(beacon_tail_len);
|
||||
|
||||
/* WDS attributes */
|
||||
IEEE80211_IF_FILE(peer, u.wds.remote_addr, MAC);
|
||||
|
||||
#define DEBUGFS_ADD(name, type)\
|
||||
sdata->debugfs.type.name = debugfs_create_file(#name, 0444,\
|
||||
sdata->debugfsdir, sdata, &name##_ops);
|
||||
|
||||
static void add_sta_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_ADD(channel_use, sta);
|
||||
DEBUGFS_ADD(drop_unencrypted, sta);
|
||||
DEBUGFS_ADD(eapol, sta);
|
||||
DEBUGFS_ADD(ieee8021_x, sta);
|
||||
DEBUGFS_ADD(state, sta);
|
||||
DEBUGFS_ADD(bssid, sta);
|
||||
DEBUGFS_ADD(prev_bssid, sta);
|
||||
DEBUGFS_ADD(ssid_len, sta);
|
||||
DEBUGFS_ADD(aid, sta);
|
||||
DEBUGFS_ADD(ap_capab, sta);
|
||||
DEBUGFS_ADD(capab, sta);
|
||||
DEBUGFS_ADD(extra_ie_len, sta);
|
||||
DEBUGFS_ADD(auth_tries, sta);
|
||||
DEBUGFS_ADD(assoc_tries, sta);
|
||||
DEBUGFS_ADD(auth_algs, sta);
|
||||
DEBUGFS_ADD(auth_alg, sta);
|
||||
DEBUGFS_ADD(auth_transaction, sta);
|
||||
DEBUGFS_ADD(flags, sta);
|
||||
}
|
||||
|
||||
static void add_ap_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_ADD(channel_use, ap);
|
||||
DEBUGFS_ADD(drop_unencrypted, ap);
|
||||
DEBUGFS_ADD(eapol, ap);
|
||||
DEBUGFS_ADD(ieee8021_x, ap);
|
||||
DEBUGFS_ADD(num_sta_ps, ap);
|
||||
DEBUGFS_ADD(dtim_period, ap);
|
||||
DEBUGFS_ADD(dtim_count, ap);
|
||||
DEBUGFS_ADD(num_beacons, ap);
|
||||
DEBUGFS_ADD(force_unicast_rateidx, ap);
|
||||
DEBUGFS_ADD(max_ratectrl_rateidx, ap);
|
||||
DEBUGFS_ADD(num_buffered_multicast, ap);
|
||||
DEBUGFS_ADD(beacon_head_len, ap);
|
||||
DEBUGFS_ADD(beacon_tail_len, ap);
|
||||
}
|
||||
|
||||
static void add_wds_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_ADD(channel_use, wds);
|
||||
DEBUGFS_ADD(drop_unencrypted, wds);
|
||||
DEBUGFS_ADD(eapol, wds);
|
||||
DEBUGFS_ADD(ieee8021_x, wds);
|
||||
DEBUGFS_ADD(peer, wds);
|
||||
}
|
||||
|
||||
static void add_vlan_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_ADD(channel_use, vlan);
|
||||
DEBUGFS_ADD(drop_unencrypted, vlan);
|
||||
DEBUGFS_ADD(eapol, vlan);
|
||||
DEBUGFS_ADD(ieee8021_x, vlan);
|
||||
}
|
||||
|
||||
static void add_monitor_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
}
|
||||
|
||||
static void add_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
if (!sdata->debugfsdir)
|
||||
return;
|
||||
|
||||
switch (sdata->type) {
|
||||
case IEEE80211_IF_TYPE_STA:
|
||||
case IEEE80211_IF_TYPE_IBSS:
|
||||
add_sta_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_AP:
|
||||
add_ap_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_WDS:
|
||||
add_wds_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_MNTR:
|
||||
add_monitor_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_VLAN:
|
||||
add_vlan_files(sdata);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define DEBUGFS_DEL(name, type) \
|
||||
do { \
|
||||
debugfs_remove(sdata->debugfs.type.name); \
|
||||
sdata->debugfs.type.name = NULL; \
|
||||
} while (0)
|
||||
|
||||
static void del_sta_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_DEL(channel_use, sta);
|
||||
DEBUGFS_DEL(drop_unencrypted, sta);
|
||||
DEBUGFS_DEL(eapol, sta);
|
||||
DEBUGFS_DEL(ieee8021_x, sta);
|
||||
DEBUGFS_DEL(state, sta);
|
||||
DEBUGFS_DEL(bssid, sta);
|
||||
DEBUGFS_DEL(prev_bssid, sta);
|
||||
DEBUGFS_DEL(ssid_len, sta);
|
||||
DEBUGFS_DEL(aid, sta);
|
||||
DEBUGFS_DEL(ap_capab, sta);
|
||||
DEBUGFS_DEL(capab, sta);
|
||||
DEBUGFS_DEL(extra_ie_len, sta);
|
||||
DEBUGFS_DEL(auth_tries, sta);
|
||||
DEBUGFS_DEL(assoc_tries, sta);
|
||||
DEBUGFS_DEL(auth_algs, sta);
|
||||
DEBUGFS_DEL(auth_alg, sta);
|
||||
DEBUGFS_DEL(auth_transaction, sta);
|
||||
DEBUGFS_DEL(flags, sta);
|
||||
}
|
||||
|
||||
static void del_ap_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_DEL(channel_use, ap);
|
||||
DEBUGFS_DEL(drop_unencrypted, ap);
|
||||
DEBUGFS_DEL(eapol, ap);
|
||||
DEBUGFS_DEL(ieee8021_x, ap);
|
||||
DEBUGFS_DEL(num_sta_ps, ap);
|
||||
DEBUGFS_DEL(dtim_period, ap);
|
||||
DEBUGFS_DEL(dtim_count, ap);
|
||||
DEBUGFS_DEL(num_beacons, ap);
|
||||
DEBUGFS_DEL(force_unicast_rateidx, ap);
|
||||
DEBUGFS_DEL(max_ratectrl_rateidx, ap);
|
||||
DEBUGFS_DEL(num_buffered_multicast, ap);
|
||||
DEBUGFS_DEL(beacon_head_len, ap);
|
||||
DEBUGFS_DEL(beacon_tail_len, ap);
|
||||
}
|
||||
|
||||
static void del_wds_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_DEL(channel_use, wds);
|
||||
DEBUGFS_DEL(drop_unencrypted, wds);
|
||||
DEBUGFS_DEL(eapol, wds);
|
||||
DEBUGFS_DEL(ieee8021_x, wds);
|
||||
DEBUGFS_DEL(peer, wds);
|
||||
}
|
||||
|
||||
static void del_vlan_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
DEBUGFS_DEL(channel_use, vlan);
|
||||
DEBUGFS_DEL(drop_unencrypted, vlan);
|
||||
DEBUGFS_DEL(eapol, vlan);
|
||||
DEBUGFS_DEL(ieee8021_x, vlan);
|
||||
}
|
||||
|
||||
static void del_monitor_files(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
}
|
||||
|
||||
static void del_files(struct ieee80211_sub_if_data *sdata, int type)
|
||||
{
|
||||
if (!sdata->debugfsdir)
|
||||
return;
|
||||
|
||||
switch (type) {
|
||||
case IEEE80211_IF_TYPE_STA:
|
||||
case IEEE80211_IF_TYPE_IBSS:
|
||||
del_sta_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_AP:
|
||||
del_ap_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_WDS:
|
||||
del_wds_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_MNTR:
|
||||
del_monitor_files(sdata);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_VLAN:
|
||||
del_vlan_files(sdata);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int notif_registered;
|
||||
|
||||
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
char buf[10+IFNAMSIZ];
|
||||
|
||||
if (!notif_registered)
|
||||
return;
|
||||
|
||||
sprintf(buf, "netdev:%s", sdata->dev->name);
|
||||
sdata->debugfsdir = debugfs_create_dir(buf,
|
||||
sdata->local->hw.wiphy->debugfsdir);
|
||||
}
|
||||
|
||||
void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
del_files(sdata, sdata->type);
|
||||
debugfs_remove(sdata->debugfsdir);
|
||||
sdata->debugfsdir = NULL;
|
||||
}
|
||||
|
||||
void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
|
||||
int oldtype)
|
||||
{
|
||||
del_files(sdata, oldtype);
|
||||
add_files(sdata);
|
||||
}
|
||||
|
||||
static int netdev_notify(struct notifier_block * nb,
|
||||
unsigned long state,
|
||||
void *ndev)
|
||||
{
|
||||
struct net_device *dev = ndev;
|
||||
struct dentry *dir;
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
char buf[10+IFNAMSIZ];
|
||||
|
||||
if (state != NETDEV_CHANGENAME)
|
||||
return 0;
|
||||
|
||||
if (!dev->ieee80211_ptr || !dev->ieee80211_ptr->wiphy)
|
||||
return 0;
|
||||
|
||||
if (dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
|
||||
return 0;
|
||||
|
||||
sprintf(buf, "netdev:%s", dev->name);
|
||||
dir = sdata->debugfsdir;
|
||||
if (!debugfs_rename(dir->d_parent, dir, dir->d_parent, buf))
|
||||
printk(KERN_ERR "mac80211: debugfs: failed to rename debugfs "
|
||||
"dir to %s\n", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct notifier_block mac80211_debugfs_netdev_notifier = {
|
||||
.notifier_call = netdev_notify,
|
||||
};
|
||||
|
||||
void ieee80211_debugfs_netdev_init(void)
|
||||
{
|
||||
int err;
|
||||
|
||||
err = register_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
|
||||
if (err) {
|
||||
printk(KERN_ERR
|
||||
"mac80211: failed to install netdev notifier,"
|
||||
" disabling per-netdev debugfs!\n");
|
||||
} else
|
||||
notif_registered = 1;
|
||||
}
|
||||
|
||||
void ieee80211_debugfs_netdev_exit(void)
|
||||
{
|
||||
unregister_netdevice_notifier(&mac80211_debugfs_netdev_notifier);
|
||||
notif_registered = 0;
|
||||
}
|
||||
30
package/mac80211/src/net/mac80211/debugfs_netdev.h
Normal file
30
package/mac80211/src/net/mac80211/debugfs_netdev.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/* routines exported for debugfs handling */
|
||||
|
||||
#ifndef __IEEE80211_DEBUGFS_NETDEV_H
|
||||
#define __IEEE80211_DEBUGFS_NETDEV_H
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
void ieee80211_debugfs_add_netdev(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_debugfs_remove_netdev(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_debugfs_change_if_type(struct ieee80211_sub_if_data *sdata,
|
||||
int oldtype);
|
||||
void ieee80211_debugfs_netdev_init(void);
|
||||
void ieee80211_debugfs_netdev_exit(void);
|
||||
#else
|
||||
static inline void ieee80211_debugfs_add_netdev(
|
||||
struct ieee80211_sub_if_data *sdata)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_remove_netdev(
|
||||
struct ieee80211_sub_if_data *sdata)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_change_if_type(
|
||||
struct ieee80211_sub_if_data *sdata, int oldtype)
|
||||
{}
|
||||
static inline void ieee80211_debugfs_netdev_init(void)
|
||||
{}
|
||||
|
||||
static inline void ieee80211_debugfs_netdev_exit(void)
|
||||
{}
|
||||
#endif
|
||||
|
||||
#endif /* __IEEE80211_DEBUGFS_NETDEV_H */
|
||||
244
package/mac80211/src/net/mac80211/debugfs_sta.c
Normal file
244
package/mac80211/src/net/mac80211/debugfs_sta.c
Normal file
@@ -0,0 +1,244 @@
|
||||
/*
|
||||
* Copyright 2003-2005 Devicescape Software, Inc.
|
||||
* Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
|
||||
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/ieee80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "debugfs.h"
|
||||
#include "debugfs_sta.h"
|
||||
#include "sta_info.h"
|
||||
|
||||
/* sta attributtes */
|
||||
|
||||
#define STA_READ(name, buflen, field, format_string) \
|
||||
static ssize_t sta_ ##name## _read(struct file *file, \
|
||||
char __user *userbuf, \
|
||||
size_t count, loff_t *ppos) \
|
||||
{ \
|
||||
int res; \
|
||||
struct sta_info *sta = file->private_data; \
|
||||
char buf[buflen]; \
|
||||
res = scnprintf(buf, buflen, format_string, sta->field); \
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
|
||||
}
|
||||
#define STA_READ_D(name, field) STA_READ(name, 20, field, "%d\n")
|
||||
#define STA_READ_U(name, field) STA_READ(name, 20, field, "%u\n")
|
||||
#define STA_READ_LU(name, field) STA_READ(name, 20, field, "%lu\n")
|
||||
#define STA_READ_S(name, field) STA_READ(name, 20, field, "%s\n")
|
||||
|
||||
#define STA_READ_RATE(name, field) \
|
||||
static ssize_t sta_##name##_read(struct file *file, \
|
||||
char __user *userbuf, \
|
||||
size_t count, loff_t *ppos) \
|
||||
{ \
|
||||
struct sta_info *sta = file->private_data; \
|
||||
struct ieee80211_local *local = wdev_priv(sta->dev->ieee80211_ptr);\
|
||||
struct ieee80211_hw_mode *mode = local->oper_hw_mode; \
|
||||
char buf[20]; \
|
||||
int res = scnprintf(buf, sizeof(buf), "%d\n", \
|
||||
(sta->field >= 0 && \
|
||||
sta->field < mode->num_rates) ? \
|
||||
mode->rates[sta->field].rate : -1); \
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res); \
|
||||
}
|
||||
|
||||
#define STA_OPS(name) \
|
||||
static const struct file_operations sta_ ##name## _ops = { \
|
||||
.read = sta_##name##_read, \
|
||||
.open = mac80211_open_file_generic, \
|
||||
}
|
||||
|
||||
#define STA_FILE(name, field, format) \
|
||||
STA_READ_##format(name, field) \
|
||||
STA_OPS(name)
|
||||
|
||||
STA_FILE(aid, aid, D);
|
||||
STA_FILE(dev, dev->name, S);
|
||||
STA_FILE(rx_packets, rx_packets, LU);
|
||||
STA_FILE(tx_packets, tx_packets, LU);
|
||||
STA_FILE(rx_bytes, rx_bytes, LU);
|
||||
STA_FILE(tx_bytes, tx_bytes, LU);
|
||||
STA_FILE(rx_duplicates, num_duplicates, LU);
|
||||
STA_FILE(rx_fragments, rx_fragments, LU);
|
||||
STA_FILE(rx_dropped, rx_dropped, LU);
|
||||
STA_FILE(tx_fragments, tx_fragments, LU);
|
||||
STA_FILE(tx_filtered, tx_filtered_count, LU);
|
||||
STA_FILE(txrate, txrate, RATE);
|
||||
STA_FILE(last_txrate, last_txrate, RATE);
|
||||
STA_FILE(tx_retry_failed, tx_retry_failed, LU);
|
||||
STA_FILE(tx_retry_count, tx_retry_count, LU);
|
||||
STA_FILE(last_rssi, last_rssi, D);
|
||||
STA_FILE(last_signal, last_signal, D);
|
||||
STA_FILE(last_noise, last_noise, D);
|
||||
STA_FILE(channel_use, channel_use, D);
|
||||
STA_FILE(wep_weak_iv_count, wep_weak_iv_count, D);
|
||||
|
||||
static ssize_t sta_flags_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[100];
|
||||
struct sta_info *sta = file->private_data;
|
||||
int res = scnprintf(buf, sizeof(buf), "%s%s%s%s%s%s%s%s%s",
|
||||
sta->flags & WLAN_STA_AUTH ? "AUTH\n" : "",
|
||||
sta->flags & WLAN_STA_ASSOC ? "ASSOC\n" : "",
|
||||
sta->flags & WLAN_STA_PS ? "PS\n" : "",
|
||||
sta->flags & WLAN_STA_TIM ? "TIM\n" : "",
|
||||
sta->flags & WLAN_STA_PERM ? "PERM\n" : "",
|
||||
sta->flags & WLAN_STA_AUTHORIZED ? "AUTHORIZED\n" : "",
|
||||
sta->flags & WLAN_STA_SHORT_PREAMBLE ? "SHORT PREAMBLE\n" : "",
|
||||
sta->flags & WLAN_STA_WME ? "WME\n" : "",
|
||||
sta->flags & WLAN_STA_WDS ? "WDS\n" : "");
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
||||
}
|
||||
STA_OPS(flags);
|
||||
|
||||
static ssize_t sta_num_ps_buf_frames_read(struct file *file,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[20];
|
||||
struct sta_info *sta = file->private_data;
|
||||
int res = scnprintf(buf, sizeof(buf), "%u\n",
|
||||
skb_queue_len(&sta->ps_tx_buf));
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
||||
}
|
||||
STA_OPS(num_ps_buf_frames);
|
||||
|
||||
static ssize_t sta_last_ack_rssi_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[100];
|
||||
struct sta_info *sta = file->private_data;
|
||||
int res = scnprintf(buf, sizeof(buf), "%d %d %d\n",
|
||||
sta->last_ack_rssi[0],
|
||||
sta->last_ack_rssi[1],
|
||||
sta->last_ack_rssi[2]);
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
||||
}
|
||||
STA_OPS(last_ack_rssi);
|
||||
|
||||
static ssize_t sta_last_ack_ms_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[20];
|
||||
struct sta_info *sta = file->private_data;
|
||||
int res = scnprintf(buf, sizeof(buf), "%d\n",
|
||||
sta->last_ack ?
|
||||
jiffies_to_msecs(jiffies - sta->last_ack) : -1);
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
||||
}
|
||||
STA_OPS(last_ack_ms);
|
||||
|
||||
static ssize_t sta_inactive_ms_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[20];
|
||||
struct sta_info *sta = file->private_data;
|
||||
int res = scnprintf(buf, sizeof(buf), "%d\n",
|
||||
jiffies_to_msecs(jiffies - sta->last_rx));
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, res);
|
||||
}
|
||||
STA_OPS(inactive_ms);
|
||||
|
||||
static ssize_t sta_last_seq_ctrl_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
|
||||
int i;
|
||||
struct sta_info *sta = file->private_data;
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += scnprintf(p, sizeof(buf)+buf-p, "%x ",
|
||||
le16_to_cpu(sta->last_seq_ctrl[i]));
|
||||
p += scnprintf(p, sizeof(buf)+buf-p, "\n");
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
}
|
||||
STA_OPS(last_seq_ctrl);
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
static ssize_t sta_wme_rx_queue_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[15*NUM_RX_DATA_QUEUES], *p = buf;
|
||||
int i;
|
||||
struct sta_info *sta = file->private_data;
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
|
||||
sta->wme_rx_queue[i]);
|
||||
p += scnprintf(p, sizeof(buf)+buf-p, "\n");
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
}
|
||||
STA_OPS(wme_rx_queue);
|
||||
|
||||
static ssize_t sta_wme_tx_queue_read(struct file *file, char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
char buf[15*NUM_TX_DATA_QUEUES], *p = buf;
|
||||
int i;
|
||||
struct sta_info *sta = file->private_data;
|
||||
for (i = 0; i < NUM_TX_DATA_QUEUES; i++)
|
||||
p += scnprintf(p, sizeof(buf)+buf-p, "%u ",
|
||||
sta->wme_tx_queue[i]);
|
||||
p += scnprintf(p, sizeof(buf)+buf-p, "\n");
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, p - buf);
|
||||
}
|
||||
STA_OPS(wme_tx_queue);
|
||||
#endif
|
||||
|
||||
#define DEBUGFS_ADD(name) \
|
||||
sta->debugfs.name = debugfs_create_file(#name, 0444, \
|
||||
sta->debugfs.dir, sta, &sta_ ##name## _ops);
|
||||
|
||||
#define DEBUGFS_DEL(name) \
|
||||
debugfs_remove(sta->debugfs.name);\
|
||||
sta->debugfs.name = NULL;
|
||||
|
||||
|
||||
void ieee80211_sta_debugfs_add(struct sta_info *sta)
|
||||
{
|
||||
char buf[3*6];
|
||||
struct dentry *stations_dir = sta->local->debugfs.stations;
|
||||
|
||||
if (!stations_dir)
|
||||
return;
|
||||
|
||||
sprintf(buf, MAC_FMT, MAC_ARG(sta->addr));
|
||||
|
||||
sta->debugfs.dir = debugfs_create_dir(buf, stations_dir);
|
||||
if (!sta->debugfs.dir)
|
||||
return;
|
||||
|
||||
DEBUGFS_ADD(flags);
|
||||
DEBUGFS_ADD(num_ps_buf_frames);
|
||||
DEBUGFS_ADD(last_ack_rssi);
|
||||
DEBUGFS_ADD(last_ack_ms);
|
||||
DEBUGFS_ADD(inactive_ms);
|
||||
DEBUGFS_ADD(last_seq_ctrl);
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
DEBUGFS_ADD(wme_rx_queue);
|
||||
DEBUGFS_ADD(wme_tx_queue);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ieee80211_sta_debugfs_remove(struct sta_info *sta)
|
||||
{
|
||||
DEBUGFS_DEL(flags);
|
||||
DEBUGFS_DEL(num_ps_buf_frames);
|
||||
DEBUGFS_DEL(last_ack_rssi);
|
||||
DEBUGFS_DEL(last_ack_ms);
|
||||
DEBUGFS_DEL(inactive_ms);
|
||||
DEBUGFS_DEL(last_seq_ctrl);
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
DEBUGFS_DEL(wme_rx_queue);
|
||||
DEBUGFS_DEL(wme_tx_queue);
|
||||
#endif
|
||||
|
||||
debugfs_remove(sta->debugfs.dir);
|
||||
sta->debugfs.dir = NULL;
|
||||
}
|
||||
12
package/mac80211/src/net/mac80211/debugfs_sta.h
Normal file
12
package/mac80211/src/net/mac80211/debugfs_sta.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __MAC80211_DEBUGFS_STA_H
|
||||
#define __MAC80211_DEBUGFS_STA_H
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
void ieee80211_sta_debugfs_add(struct sta_info *sta);
|
||||
void ieee80211_sta_debugfs_remove(struct sta_info *sta);
|
||||
#else
|
||||
static inline void ieee80211_sta_debugfs_add(struct sta_info *sta) {}
|
||||
static inline void ieee80211_sta_debugfs_remove(struct sta_info *sta) {}
|
||||
#endif
|
||||
|
||||
#endif /* __MAC80211_DEBUGFS_STA_H */
|
||||
42
package/mac80211/src/net/mac80211/event.c
Normal file
42
package/mac80211/src/net/mac80211/event.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* mac80211 - events
|
||||
*/
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include <net/iw_handler.h>
|
||||
#include "ieee80211_i.h"
|
||||
|
||||
/*
|
||||
* indicate a failed Michael MIC to userspace; the passed packet
|
||||
* (in the variable hdr) must be long enough to extract the TKIP
|
||||
* fields like TSC
|
||||
*/
|
||||
void mac80211_ev_michael_mic_failure(struct net_device *dev, int keyidx,
|
||||
struct ieee80211_hdr *hdr)
|
||||
{
|
||||
union iwreq_data wrqu;
|
||||
char *buf = kmalloc(128, GFP_ATOMIC);
|
||||
|
||||
if (buf) {
|
||||
/* TODO: needed parameters: count, key type, TSC */
|
||||
sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
|
||||
"keyid=%d %scast addr=" MAC_FMT ")",
|
||||
keyidx, hdr->addr1[0] & 0x01 ? "broad" : "uni",
|
||||
MAC_ARG(hdr->addr2));
|
||||
memset(&wrqu, 0, sizeof(wrqu));
|
||||
wrqu.data.length = strlen(buf);
|
||||
wireless_send_event(dev, IWEVCUSTOM, &wrqu, buf);
|
||||
kfree(buf);
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: re-add support for sending MIC failure indication
|
||||
* with all info via nl80211
|
||||
*/
|
||||
}
|
||||
1249
package/mac80211/src/net/mac80211/ieee80211.c
Normal file
1249
package/mac80211/src/net/mac80211/ieee80211.c
Normal file
File diff suppressed because it is too large
Load Diff
91
package/mac80211/src/net/mac80211/ieee80211_common.h
Normal file
91
package/mac80211/src/net/mac80211/ieee80211_common.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* IEEE 802.11 driver (80211.o) -- hostapd interface
|
||||
* Copyright 2002-2004, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef IEEE80211_COMMON_H
|
||||
#define IEEE80211_COMMON_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
/*
|
||||
* This is common header information with user space. It is used on all
|
||||
* frames sent to wlan#ap interface.
|
||||
*/
|
||||
|
||||
#define IEEE80211_FI_VERSION 0x80211001
|
||||
|
||||
struct ieee80211_frame_info {
|
||||
__be32 version;
|
||||
__be32 length;
|
||||
__be64 mactime;
|
||||
__be64 hosttime;
|
||||
__be32 phytype;
|
||||
__be32 channel;
|
||||
__be32 datarate;
|
||||
__be32 antenna;
|
||||
__be32 priority;
|
||||
__be32 ssi_type;
|
||||
__be32 ssi_signal;
|
||||
__be32 ssi_noise;
|
||||
__be32 preamble;
|
||||
__be32 encoding;
|
||||
|
||||
/* Note: this structure is otherwise identical to capture format used
|
||||
* in linux-wlan-ng, but this additional field is used to provide meta
|
||||
* data about the frame to hostapd. This was the easiest method for
|
||||
* providing this information, but this might change in the future. */
|
||||
__be32 msg_type;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
enum ieee80211_msg_type {
|
||||
ieee80211_msg_normal = 0,
|
||||
ieee80211_msg_tx_callback_ack = 1,
|
||||
ieee80211_msg_tx_callback_fail = 2,
|
||||
/* hole at 3, was ieee80211_msg_passive_scan but unused */
|
||||
/* hole at 4, was ieee80211_msg_wep_frame_unknown_key but now unused */
|
||||
ieee80211_msg_michael_mic_failure = 5,
|
||||
/* hole at 6, was monitor but never sent to userspace */
|
||||
ieee80211_msg_sta_not_assoc = 7,
|
||||
/* 8 was ieee80211_msg_set_aid_for_sta */
|
||||
/* 9 was ieee80211_msg_key_threshold_notification */
|
||||
/* 11 was ieee80211_msg_radar */
|
||||
};
|
||||
|
||||
struct ieee80211_msg_key_notification {
|
||||
int tx_rx_count;
|
||||
char ifname[IFNAMSIZ];
|
||||
u8 addr[ETH_ALEN]; /* ff:ff:ff:ff:ff:ff for broadcast keys */
|
||||
};
|
||||
|
||||
|
||||
enum ieee80211_phytype {
|
||||
ieee80211_phytype_fhss_dot11_97 = 1,
|
||||
ieee80211_phytype_dsss_dot11_97 = 2,
|
||||
ieee80211_phytype_irbaseband = 3,
|
||||
ieee80211_phytype_dsss_dot11_b = 4,
|
||||
ieee80211_phytype_pbcc_dot11_b = 5,
|
||||
ieee80211_phytype_ofdm_dot11_g = 6,
|
||||
ieee80211_phytype_pbcc_dot11_g = 7,
|
||||
ieee80211_phytype_ofdm_dot11_a = 8,
|
||||
};
|
||||
|
||||
enum ieee80211_ssi_type {
|
||||
ieee80211_ssi_none = 0,
|
||||
ieee80211_ssi_norm = 1, /* normalized, 0-1000 */
|
||||
ieee80211_ssi_dbm = 2,
|
||||
ieee80211_ssi_raw = 3, /* raw SSI */
|
||||
};
|
||||
|
||||
struct ieee80211_radar_info {
|
||||
int channel;
|
||||
int radar;
|
||||
int radar_type;
|
||||
};
|
||||
|
||||
#endif /* IEEE80211_COMMON_H */
|
||||
803
package/mac80211/src/net/mac80211/ieee80211_i.h
Normal file
803
package/mac80211/src/net/mac80211/ieee80211_i.h
Normal file
@@ -0,0 +1,803 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005, Devicescape Software, Inc.
|
||||
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef IEEE80211_I_H
|
||||
#define IEEE80211_I_H
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/workqueue.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <net/wireless.h>
|
||||
#include "ieee80211_key.h"
|
||||
#include "sta_info.h"
|
||||
|
||||
/* ieee80211.o internal definitions, etc. These are not included into
|
||||
* low-level drivers. */
|
||||
|
||||
#ifndef ETH_P_PAE
|
||||
#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
|
||||
#endif /* ETH_P_PAE */
|
||||
|
||||
#define WLAN_FC_DATA_PRESENT(fc) (((fc) & 0x4c) == 0x08)
|
||||
|
||||
struct ieee80211_local;
|
||||
|
||||
#define BIT(x) (1 << (x))
|
||||
|
||||
#define IEEE80211_ALIGN32_PAD(a) ((4 - ((a) & 3)) & 3)
|
||||
|
||||
/* Maximum number of broadcast/multicast frames to buffer when some of the
|
||||
* associated stations are using power saving. */
|
||||
#define AP_MAX_BC_BUFFER 128
|
||||
|
||||
/* Maximum number of frames buffered to all STAs, including multicast frames.
|
||||
* Note: increasing this limit increases the potential memory requirement. Each
|
||||
* frame can be up to about 2 kB long. */
|
||||
#define TOTAL_MAX_TX_BUFFER 512
|
||||
|
||||
/* Required encryption head and tailroom */
|
||||
#define IEEE80211_ENCRYPT_HEADROOM 8
|
||||
#define IEEE80211_ENCRYPT_TAILROOM 12
|
||||
|
||||
/* IEEE 802.11 (Ch. 9.5 Defragmentation) requires support for concurrent
|
||||
* reception of at least three fragmented frames. This limit can be increased
|
||||
* by changing this define, at the cost of slower frame reassembly and
|
||||
* increased memory use (about 2 kB of RAM per entry). */
|
||||
#define IEEE80211_FRAGMENT_MAX 4
|
||||
|
||||
struct ieee80211_fragment_entry {
|
||||
unsigned long first_frag_time;
|
||||
unsigned int seq;
|
||||
unsigned int rx_queue;
|
||||
unsigned int last_frag;
|
||||
unsigned int extra_len;
|
||||
struct sk_buff_head skb_list;
|
||||
int ccmp; /* Whether fragments were encrypted with CCMP */
|
||||
u8 last_pn[6]; /* PN of the last fragment if CCMP was used */
|
||||
};
|
||||
|
||||
|
||||
struct ieee80211_sta_bss {
|
||||
struct list_head list;
|
||||
struct ieee80211_sta_bss *hnext;
|
||||
atomic_t users;
|
||||
|
||||
u8 bssid[ETH_ALEN];
|
||||
u8 ssid[IEEE80211_MAX_SSID_LEN];
|
||||
size_t ssid_len;
|
||||
u16 capability; /* host byte order */
|
||||
int hw_mode;
|
||||
int channel;
|
||||
int freq;
|
||||
int rssi, signal, noise;
|
||||
u8 *wpa_ie;
|
||||
size_t wpa_ie_len;
|
||||
u8 *rsn_ie;
|
||||
size_t rsn_ie_len;
|
||||
u8 *wmm_ie;
|
||||
size_t wmm_ie_len;
|
||||
#define IEEE80211_MAX_SUPP_RATES 32
|
||||
u8 supp_rates[IEEE80211_MAX_SUPP_RATES];
|
||||
size_t supp_rates_len;
|
||||
int beacon_int;
|
||||
u64 timestamp;
|
||||
|
||||
int probe_resp;
|
||||
unsigned long last_update;
|
||||
|
||||
/* during assocation, we save an ERP value from a probe response so
|
||||
* that we can feed ERP info to the driver when handling the
|
||||
* association completes. these fields probably won't be up-to-date
|
||||
* otherwise, you probably don't want to use them. */
|
||||
int has_erp_value;
|
||||
u8 erp_value;
|
||||
};
|
||||
|
||||
|
||||
typedef enum {
|
||||
TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
|
||||
} ieee80211_txrx_result;
|
||||
|
||||
/* flags used in struct ieee80211_txrx_data.flags */
|
||||
/* whether the MSDU was fragmented */
|
||||
#define IEEE80211_TXRXD_FRAGMENTED BIT(0)
|
||||
#define IEEE80211_TXRXD_TXUNICAST BIT(1)
|
||||
#define IEEE80211_TXRXD_TXPS_BUFFERED BIT(2)
|
||||
#define IEEE80211_TXRXD_TXPROBE_LAST_FRAG BIT(3)
|
||||
#define IEEE80211_TXRXD_RXIN_SCAN BIT(4)
|
||||
/* frame is destined to interface currently processed (incl. multicast frames) */
|
||||
#define IEEE80211_TXRXD_RXRA_MATCH BIT(5)
|
||||
#define IEEE80211_TXRXD_TX_INJECTED BIT(6)
|
||||
struct ieee80211_txrx_data {
|
||||
struct sk_buff *skb;
|
||||
struct net_device *dev;
|
||||
struct ieee80211_local *local;
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
struct sta_info *sta;
|
||||
u16 fc, ethertype;
|
||||
struct ieee80211_key *key;
|
||||
unsigned int flags;
|
||||
union {
|
||||
struct {
|
||||
struct ieee80211_tx_control *control;
|
||||
struct ieee80211_hw_mode *mode;
|
||||
struct ieee80211_rate *rate;
|
||||
/* use this rate (if set) for last fragment; rate can
|
||||
* be set to lower rate for the first fragments, e.g.,
|
||||
* when using CTS protection with IEEE 802.11g. */
|
||||
struct ieee80211_rate *last_frag_rate;
|
||||
int last_frag_hwrate;
|
||||
|
||||
/* Extra fragments (in addition to the first fragment
|
||||
* in skb) */
|
||||
int num_extra_frag;
|
||||
struct sk_buff **extra_frag;
|
||||
} tx;
|
||||
struct {
|
||||
struct ieee80211_rx_status *status;
|
||||
int sent_ps_buffered;
|
||||
int queue;
|
||||
int load;
|
||||
u32 tkip_iv32;
|
||||
u16 tkip_iv16;
|
||||
} rx;
|
||||
} u;
|
||||
};
|
||||
|
||||
/* flags used in struct ieee80211_tx_packet_data.flags */
|
||||
#define IEEE80211_TXPD_REQ_TX_STATUS BIT(0)
|
||||
#define IEEE80211_TXPD_DO_NOT_ENCRYPT BIT(1)
|
||||
#define IEEE80211_TXPD_REQUEUE BIT(2)
|
||||
/* Stored in sk_buff->cb */
|
||||
struct ieee80211_tx_packet_data {
|
||||
int ifindex;
|
||||
unsigned long jiffies;
|
||||
unsigned int flags;
|
||||
u8 queue;
|
||||
};
|
||||
|
||||
struct ieee80211_tx_stored_packet {
|
||||
struct ieee80211_tx_control control;
|
||||
struct sk_buff *skb;
|
||||
int num_extra_frag;
|
||||
struct sk_buff **extra_frag;
|
||||
int last_frag_rateidx;
|
||||
int last_frag_hwrate;
|
||||
struct ieee80211_rate *last_frag_rate;
|
||||
unsigned int last_frag_rate_ctrl_probe;
|
||||
};
|
||||
|
||||
typedef ieee80211_txrx_result (*ieee80211_tx_handler)
|
||||
(struct ieee80211_txrx_data *tx);
|
||||
|
||||
typedef ieee80211_txrx_result (*ieee80211_rx_handler)
|
||||
(struct ieee80211_txrx_data *rx);
|
||||
|
||||
struct ieee80211_if_ap {
|
||||
u8 *beacon_head, *beacon_tail;
|
||||
int beacon_head_len, beacon_tail_len;
|
||||
|
||||
struct list_head vlans;
|
||||
|
||||
u8 ssid[IEEE80211_MAX_SSID_LEN];
|
||||
size_t ssid_len;
|
||||
|
||||
/* yes, this looks ugly, but guarantees that we can later use
|
||||
* bitmap_empty :)
|
||||
* NB: don't ever use set_bit, use bss_tim_set/bss_tim_clear! */
|
||||
u8 tim[sizeof(unsigned long) * BITS_TO_LONGS(IEEE80211_MAX_AID + 1)];
|
||||
atomic_t num_sta_ps; /* number of stations in PS mode */
|
||||
struct sk_buff_head ps_bc_buf;
|
||||
int dtim_period, dtim_count;
|
||||
int force_unicast_rateidx; /* forced TX rateidx for unicast frames */
|
||||
int max_ratectrl_rateidx; /* max TX rateidx for rate control */
|
||||
int num_beacons; /* number of TXed beacon frames for this BSS */
|
||||
};
|
||||
|
||||
struct ieee80211_if_wds {
|
||||
u8 remote_addr[ETH_ALEN];
|
||||
struct sta_info *sta;
|
||||
};
|
||||
|
||||
struct ieee80211_if_vlan {
|
||||
struct ieee80211_sub_if_data *ap;
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
/* flags used in struct ieee80211_if_sta.flags */
|
||||
#define IEEE80211_STA_SSID_SET BIT(0)
|
||||
#define IEEE80211_STA_BSSID_SET BIT(1)
|
||||
#define IEEE80211_STA_PREV_BSSID_SET BIT(2)
|
||||
#define IEEE80211_STA_AUTHENTICATED BIT(3)
|
||||
#define IEEE80211_STA_ASSOCIATED BIT(4)
|
||||
#define IEEE80211_STA_PROBEREQ_POLL BIT(5)
|
||||
#define IEEE80211_STA_CREATE_IBSS BIT(6)
|
||||
#define IEEE80211_STA_MIXED_CELL BIT(7)
|
||||
#define IEEE80211_STA_WMM_ENABLED BIT(8)
|
||||
#define IEEE80211_STA_AUTO_SSID_SEL BIT(10)
|
||||
#define IEEE80211_STA_AUTO_BSSID_SEL BIT(11)
|
||||
#define IEEE80211_STA_AUTO_CHANNEL_SEL BIT(12)
|
||||
struct ieee80211_if_sta {
|
||||
enum {
|
||||
IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
|
||||
IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
|
||||
IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
|
||||
} state;
|
||||
struct timer_list timer;
|
||||
struct work_struct work;
|
||||
u8 bssid[ETH_ALEN], prev_bssid[ETH_ALEN];
|
||||
u8 ssid[IEEE80211_MAX_SSID_LEN];
|
||||
size_t ssid_len;
|
||||
u16 aid;
|
||||
u16 ap_capab, capab;
|
||||
u8 *extra_ie; /* to be added to the end of AssocReq */
|
||||
size_t extra_ie_len;
|
||||
|
||||
/* The last AssocReq/Resp IEs */
|
||||
u8 *assocreq_ies, *assocresp_ies;
|
||||
size_t assocreq_ies_len, assocresp_ies_len;
|
||||
|
||||
int auth_tries, assoc_tries;
|
||||
|
||||
unsigned int flags;
|
||||
#define IEEE80211_STA_REQ_SCAN 0
|
||||
#define IEEE80211_STA_REQ_AUTH 1
|
||||
#define IEEE80211_STA_REQ_RUN 2
|
||||
unsigned long request;
|
||||
struct sk_buff_head skb_queue;
|
||||
|
||||
int key_management_enabled;
|
||||
unsigned long last_probe;
|
||||
|
||||
#define IEEE80211_AUTH_ALG_OPEN BIT(0)
|
||||
#define IEEE80211_AUTH_ALG_SHARED_KEY BIT(1)
|
||||
#define IEEE80211_AUTH_ALG_LEAP BIT(2)
|
||||
unsigned int auth_algs; /* bitfield of allowed auth algs */
|
||||
int auth_alg; /* currently used IEEE 802.11 authentication algorithm */
|
||||
int auth_transaction;
|
||||
|
||||
unsigned long ibss_join_req;
|
||||
struct sk_buff *probe_resp; /* ProbeResp template for IBSS */
|
||||
u32 supp_rates_bits;
|
||||
|
||||
int wmm_last_param_set;
|
||||
};
|
||||
|
||||
|
||||
/* flags used in struct ieee80211_sub_if_data.flags */
|
||||
#define IEEE80211_SDATA_ALLMULTI BIT(0)
|
||||
#define IEEE80211_SDATA_PROMISC BIT(1)
|
||||
#define IEEE80211_SDATA_USE_PROTECTION BIT(2) /* CTS protect ERP frames */
|
||||
/* use short preamble with IEEE 802.11b: this flag is set when the AP or beacon
|
||||
* generator reports that there are no present stations that cannot support short
|
||||
* preambles */
|
||||
#define IEEE80211_SDATA_SHORT_PREAMBLE BIT(3)
|
||||
#define IEEE80211_SDATA_USERSPACE_MLME BIT(4)
|
||||
struct ieee80211_sub_if_data {
|
||||
struct list_head list;
|
||||
enum ieee80211_if_types type;
|
||||
|
||||
struct wireless_dev wdev;
|
||||
|
||||
/* keys */
|
||||
struct list_head key_list;
|
||||
|
||||
struct net_device *dev;
|
||||
struct ieee80211_local *local;
|
||||
|
||||
unsigned int flags;
|
||||
|
||||
int drop_unencrypted;
|
||||
int eapol; /* 0 = process EAPOL frames as normal data frames,
|
||||
* 1 = send EAPOL frames through wlan#ap to hostapd
|
||||
* (default) */
|
||||
int ieee802_1x; /* IEEE 802.1X PAE - drop packet to/from unauthorized
|
||||
* port */
|
||||
|
||||
u16 sequence;
|
||||
|
||||
/* Fragment table for host-based reassembly */
|
||||
struct ieee80211_fragment_entry fragments[IEEE80211_FRAGMENT_MAX];
|
||||
unsigned int fragment_next;
|
||||
|
||||
#define NUM_DEFAULT_KEYS 4
|
||||
struct ieee80211_key *keys[NUM_DEFAULT_KEYS];
|
||||
struct ieee80211_key *default_key;
|
||||
|
||||
struct ieee80211_if_ap *bss; /* BSS that this device belongs to */
|
||||
|
||||
union {
|
||||
struct ieee80211_if_ap ap;
|
||||
struct ieee80211_if_wds wds;
|
||||
struct ieee80211_if_vlan vlan;
|
||||
struct ieee80211_if_sta sta;
|
||||
} u;
|
||||
int channel_use;
|
||||
int channel_use_raw;
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct dentry *debugfsdir;
|
||||
union {
|
||||
struct {
|
||||
struct dentry *channel_use;
|
||||
struct dentry *drop_unencrypted;
|
||||
struct dentry *eapol;
|
||||
struct dentry *ieee8021_x;
|
||||
struct dentry *state;
|
||||
struct dentry *bssid;
|
||||
struct dentry *prev_bssid;
|
||||
struct dentry *ssid_len;
|
||||
struct dentry *aid;
|
||||
struct dentry *ap_capab;
|
||||
struct dentry *capab;
|
||||
struct dentry *extra_ie_len;
|
||||
struct dentry *auth_tries;
|
||||
struct dentry *assoc_tries;
|
||||
struct dentry *auth_algs;
|
||||
struct dentry *auth_alg;
|
||||
struct dentry *auth_transaction;
|
||||
struct dentry *flags;
|
||||
} sta;
|
||||
struct {
|
||||
struct dentry *channel_use;
|
||||
struct dentry *drop_unencrypted;
|
||||
struct dentry *eapol;
|
||||
struct dentry *ieee8021_x;
|
||||
struct dentry *num_sta_ps;
|
||||
struct dentry *dtim_period;
|
||||
struct dentry *dtim_count;
|
||||
struct dentry *num_beacons;
|
||||
struct dentry *force_unicast_rateidx;
|
||||
struct dentry *max_ratectrl_rateidx;
|
||||
struct dentry *num_buffered_multicast;
|
||||
struct dentry *beacon_head_len;
|
||||
struct dentry *beacon_tail_len;
|
||||
} ap;
|
||||
struct {
|
||||
struct dentry *channel_use;
|
||||
struct dentry *drop_unencrypted;
|
||||
struct dentry *eapol;
|
||||
struct dentry *ieee8021_x;
|
||||
struct dentry *peer;
|
||||
} wds;
|
||||
struct {
|
||||
struct dentry *channel_use;
|
||||
struct dentry *drop_unencrypted;
|
||||
struct dentry *eapol;
|
||||
struct dentry *ieee8021_x;
|
||||
} vlan;
|
||||
struct {
|
||||
struct dentry *mode;
|
||||
} monitor;
|
||||
struct dentry *default_key;
|
||||
} debugfs;
|
||||
#endif
|
||||
};
|
||||
|
||||
#define IEEE80211_DEV_TO_SUB_IF(dev) netdev_priv(dev)
|
||||
|
||||
enum {
|
||||
IEEE80211_RX_MSG = 1,
|
||||
IEEE80211_TX_STATUS_MSG = 2,
|
||||
};
|
||||
|
||||
struct ieee80211_local {
|
||||
/* embed the driver visible part.
|
||||
* don't cast (use the static inlines below), but we keep
|
||||
* it first anyway so they become a no-op */
|
||||
struct ieee80211_hw hw;
|
||||
|
||||
const struct ieee80211_ops *ops;
|
||||
|
||||
/* List of registered struct ieee80211_hw_mode */
|
||||
struct list_head modes_list;
|
||||
|
||||
struct net_device *mdev; /* wmaster# - "master" 802.11 device */
|
||||
int open_count;
|
||||
int monitors;
|
||||
unsigned int filter_flags; /* FIF_* */
|
||||
struct iw_statistics wstats;
|
||||
u8 wstats_flags;
|
||||
int tx_headroom; /* required headroom for hardware/radiotap */
|
||||
|
||||
enum {
|
||||
IEEE80211_DEV_UNINITIALIZED = 0,
|
||||
IEEE80211_DEV_REGISTERED,
|
||||
IEEE80211_DEV_UNREGISTERED,
|
||||
} reg_state;
|
||||
|
||||
/* Tasklet and skb queue to process calls from IRQ mode. All frames
|
||||
* added to skb_queue will be processed, but frames in
|
||||
* skb_queue_unreliable may be dropped if the total length of these
|
||||
* queues increases over the limit. */
|
||||
#define IEEE80211_IRQSAFE_QUEUE_LIMIT 128
|
||||
struct tasklet_struct tasklet;
|
||||
struct sk_buff_head skb_queue;
|
||||
struct sk_buff_head skb_queue_unreliable;
|
||||
|
||||
/* Station data structures */
|
||||
rwlock_t sta_lock; /* protects STA data structures */
|
||||
int num_sta; /* number of stations in sta_list */
|
||||
struct list_head sta_list;
|
||||
struct sta_info *sta_hash[STA_HASH_SIZE];
|
||||
struct timer_list sta_cleanup;
|
||||
|
||||
unsigned long state[NUM_TX_DATA_QUEUES];
|
||||
struct ieee80211_tx_stored_packet pending_packet[NUM_TX_DATA_QUEUES];
|
||||
struct tasklet_struct tx_pending_tasklet;
|
||||
|
||||
/* number of interfaces with corresponding IFF_ flags */
|
||||
atomic_t iff_allmultis, iff_promiscs;
|
||||
|
||||
struct rate_control_ref *rate_ctrl;
|
||||
|
||||
/* Supported and basic rate filters for different modes. These are
|
||||
* pointers to -1 terminated lists and rates in 100 kbps units. */
|
||||
int *supp_rates[NUM_IEEE80211_MODES];
|
||||
int *basic_rates[NUM_IEEE80211_MODES];
|
||||
|
||||
int rts_threshold;
|
||||
int fragmentation_threshold;
|
||||
int short_retry_limit; /* dot11ShortRetryLimit */
|
||||
int long_retry_limit; /* dot11LongRetryLimit */
|
||||
|
||||
struct crypto_blkcipher *wep_tx_tfm;
|
||||
struct crypto_blkcipher *wep_rx_tfm;
|
||||
u32 wep_iv;
|
||||
|
||||
int bridge_packets; /* bridge packets between associated stations and
|
||||
* deliver multicast frames both back to wireless
|
||||
* media and to the local net stack */
|
||||
|
||||
ieee80211_rx_handler *rx_pre_handlers;
|
||||
ieee80211_rx_handler *rx_handlers;
|
||||
ieee80211_tx_handler *tx_handlers;
|
||||
|
||||
struct list_head interfaces;
|
||||
|
||||
int sta_scanning;
|
||||
int scan_channel_idx;
|
||||
enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
|
||||
unsigned long last_scan_completed;
|
||||
struct delayed_work scan_work;
|
||||
struct net_device *scan_dev;
|
||||
struct ieee80211_channel *oper_channel, *scan_channel;
|
||||
struct ieee80211_hw_mode *oper_hw_mode, *scan_hw_mode;
|
||||
u8 scan_ssid[IEEE80211_MAX_SSID_LEN];
|
||||
size_t scan_ssid_len;
|
||||
struct list_head sta_bss_list;
|
||||
struct ieee80211_sta_bss *sta_bss_hash[STA_HASH_SIZE];
|
||||
spinlock_t sta_bss_lock;
|
||||
#define IEEE80211_SCAN_MATCH_SSID BIT(0)
|
||||
#define IEEE80211_SCAN_WPA_ONLY BIT(1)
|
||||
#define IEEE80211_SCAN_EXTRA_INFO BIT(2)
|
||||
int scan_flags;
|
||||
|
||||
/* SNMP counters */
|
||||
/* dot11CountersTable */
|
||||
u32 dot11TransmittedFragmentCount;
|
||||
u32 dot11MulticastTransmittedFrameCount;
|
||||
u32 dot11FailedCount;
|
||||
u32 dot11RetryCount;
|
||||
u32 dot11MultipleRetryCount;
|
||||
u32 dot11FrameDuplicateCount;
|
||||
u32 dot11ReceivedFragmentCount;
|
||||
u32 dot11MulticastReceivedFrameCount;
|
||||
u32 dot11TransmittedFrameCount;
|
||||
u32 dot11WEPUndecryptableCount;
|
||||
|
||||
#ifdef CONFIG_MAC80211_LEDS
|
||||
int tx_led_counter, rx_led_counter;
|
||||
struct led_trigger *tx_led, *rx_led, *assoc_led;
|
||||
char tx_led_name[32], rx_led_name[32], assoc_led_name[32];
|
||||
#endif
|
||||
|
||||
u32 channel_use;
|
||||
u32 channel_use_raw;
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct work_struct sta_debugfs_add;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
/* TX/RX handler statistics */
|
||||
unsigned int tx_handlers_drop;
|
||||
unsigned int tx_handlers_queued;
|
||||
unsigned int tx_handlers_drop_unencrypted;
|
||||
unsigned int tx_handlers_drop_fragment;
|
||||
unsigned int tx_handlers_drop_wep;
|
||||
unsigned int tx_handlers_drop_not_assoc;
|
||||
unsigned int tx_handlers_drop_unauth_port;
|
||||
unsigned int rx_handlers_drop;
|
||||
unsigned int rx_handlers_queued;
|
||||
unsigned int rx_handlers_drop_nullfunc;
|
||||
unsigned int rx_handlers_drop_defrag;
|
||||
unsigned int rx_handlers_drop_short;
|
||||
unsigned int rx_handlers_drop_passive_scan;
|
||||
unsigned int tx_expand_skb_head;
|
||||
unsigned int tx_expand_skb_head_cloned;
|
||||
unsigned int rx_expand_skb_head;
|
||||
unsigned int rx_expand_skb_head2;
|
||||
unsigned int rx_handlers_fragments;
|
||||
unsigned int tx_status_drop;
|
||||
unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
|
||||
unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
|
||||
#define I802_DEBUG_INC(c) (c)++
|
||||
#else /* CONFIG_MAC80211_DEBUG_COUNTERS */
|
||||
#define I802_DEBUG_INC(c) do { } while (0)
|
||||
#endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
|
||||
|
||||
|
||||
int total_ps_buffered; /* total number of all buffered unicast and
|
||||
* multicast packets for power saving stations
|
||||
*/
|
||||
int wifi_wme_noack_test;
|
||||
unsigned int wmm_acm; /* bit field of ACM bits (BIT(802.1D tag)) */
|
||||
|
||||
unsigned int enabled_modes; /* bitfield of allowed modes;
|
||||
* (1 << MODE_*) */
|
||||
unsigned int hw_modes; /* bitfield of supported hardware modes;
|
||||
* (1 << MODE_*) */
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct local_debugfsdentries {
|
||||
struct dentry *channel;
|
||||
struct dentry *frequency;
|
||||
struct dentry *antenna_sel_tx;
|
||||
struct dentry *antenna_sel_rx;
|
||||
struct dentry *bridge_packets;
|
||||
struct dentry *rts_threshold;
|
||||
struct dentry *fragmentation_threshold;
|
||||
struct dentry *short_retry_limit;
|
||||
struct dentry *long_retry_limit;
|
||||
struct dentry *total_ps_buffered;
|
||||
struct dentry *mode;
|
||||
struct dentry *wep_iv;
|
||||
struct dentry *modes;
|
||||
struct dentry *statistics;
|
||||
struct local_debugfsdentries_statsdentries {
|
||||
struct dentry *transmitted_fragment_count;
|
||||
struct dentry *multicast_transmitted_frame_count;
|
||||
struct dentry *failed_count;
|
||||
struct dentry *retry_count;
|
||||
struct dentry *multiple_retry_count;
|
||||
struct dentry *frame_duplicate_count;
|
||||
struct dentry *received_fragment_count;
|
||||
struct dentry *multicast_received_frame_count;
|
||||
struct dentry *transmitted_frame_count;
|
||||
struct dentry *wep_undecryptable_count;
|
||||
struct dentry *num_scans;
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
struct dentry *tx_handlers_drop;
|
||||
struct dentry *tx_handlers_queued;
|
||||
struct dentry *tx_handlers_drop_unencrypted;
|
||||
struct dentry *tx_handlers_drop_fragment;
|
||||
struct dentry *tx_handlers_drop_wep;
|
||||
struct dentry *tx_handlers_drop_not_assoc;
|
||||
struct dentry *tx_handlers_drop_unauth_port;
|
||||
struct dentry *rx_handlers_drop;
|
||||
struct dentry *rx_handlers_queued;
|
||||
struct dentry *rx_handlers_drop_nullfunc;
|
||||
struct dentry *rx_handlers_drop_defrag;
|
||||
struct dentry *rx_handlers_drop_short;
|
||||
struct dentry *rx_handlers_drop_passive_scan;
|
||||
struct dentry *tx_expand_skb_head;
|
||||
struct dentry *tx_expand_skb_head_cloned;
|
||||
struct dentry *rx_expand_skb_head;
|
||||
struct dentry *rx_expand_skb_head2;
|
||||
struct dentry *rx_handlers_fragments;
|
||||
struct dentry *tx_status_drop;
|
||||
struct dentry *wme_tx_queue;
|
||||
struct dentry *wme_rx_queue;
|
||||
#endif
|
||||
struct dentry *dot11ACKFailureCount;
|
||||
struct dentry *dot11RTSFailureCount;
|
||||
struct dentry *dot11FCSErrorCount;
|
||||
struct dentry *dot11RTSSuccessCount;
|
||||
} stats;
|
||||
struct dentry *stations;
|
||||
struct dentry *keys;
|
||||
} debugfs;
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline struct ieee80211_local *hw_to_local(
|
||||
struct ieee80211_hw *hw)
|
||||
{
|
||||
return container_of(hw, struct ieee80211_local, hw);
|
||||
}
|
||||
|
||||
static inline struct ieee80211_hw *local_to_hw(
|
||||
struct ieee80211_local *local)
|
||||
{
|
||||
return &local->hw;
|
||||
}
|
||||
|
||||
enum ieee80211_link_state_t {
|
||||
IEEE80211_LINK_STATE_XOFF = 0,
|
||||
IEEE80211_LINK_STATE_PENDING,
|
||||
};
|
||||
|
||||
struct sta_attribute {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(const struct sta_info *, char *buf);
|
||||
ssize_t (*store)(struct sta_info *, const char *buf, size_t count);
|
||||
};
|
||||
|
||||
static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
|
||||
{
|
||||
/*
|
||||
* This format has been mandated by the IEEE specifications,
|
||||
* so this line may not be changed to use the __set_bit() format.
|
||||
*/
|
||||
bss->tim[aid / 8] |= (1 << (aid % 8));
|
||||
}
|
||||
|
||||
static inline void bss_tim_set(struct ieee80211_local *local,
|
||||
struct ieee80211_if_ap *bss, u16 aid)
|
||||
{
|
||||
read_lock_bh(&local->sta_lock);
|
||||
__bss_tim_set(bss, aid);
|
||||
read_unlock_bh(&local->sta_lock);
|
||||
}
|
||||
|
||||
static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
|
||||
{
|
||||
/*
|
||||
* This format has been mandated by the IEEE specifications,
|
||||
* so this line may not be changed to use the __clear_bit() format.
|
||||
*/
|
||||
bss->tim[aid / 8] &= ~(1 << (aid % 8));
|
||||
}
|
||||
|
||||
static inline void bss_tim_clear(struct ieee80211_local *local,
|
||||
struct ieee80211_if_ap *bss, u16 aid)
|
||||
{
|
||||
read_lock_bh(&local->sta_lock);
|
||||
__bss_tim_clear(bss, aid);
|
||||
read_unlock_bh(&local->sta_lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* ieee80211_is_erp_rate - Check if a rate is an ERP rate
|
||||
* @phymode: The PHY-mode for this rate (MODE_IEEE80211...)
|
||||
* @rate: Transmission rate to check, in 100 kbps
|
||||
*
|
||||
* Check if a given rate is an Extended Rate PHY (ERP) rate.
|
||||
*/
|
||||
static inline int ieee80211_is_erp_rate(int phymode, int rate)
|
||||
{
|
||||
if (phymode == MODE_IEEE80211G) {
|
||||
if (rate != 10 && rate != 20 &&
|
||||
rate != 55 && rate != 110)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
|
||||
{
|
||||
return compare_ether_addr(raddr, addr) == 0 ||
|
||||
is_broadcast_ether_addr(raddr);
|
||||
}
|
||||
|
||||
|
||||
/* ieee80211.c */
|
||||
int ieee80211_hw_config(struct ieee80211_local *local);
|
||||
int ieee80211_if_config(struct net_device *dev);
|
||||
int ieee80211_if_config_beacon(struct net_device *dev);
|
||||
void ieee80211_prepare_rates(struct ieee80211_local *local,
|
||||
struct ieee80211_hw_mode *mode);
|
||||
void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx);
|
||||
int ieee80211_if_update_wds(struct net_device *dev, u8 *remote_addr);
|
||||
void ieee80211_if_setup(struct net_device *dev);
|
||||
struct ieee80211_rate *ieee80211_get_rate(struct ieee80211_local *local,
|
||||
int phymode, int hwrate);
|
||||
|
||||
/* ieee80211_ioctl.c */
|
||||
extern const struct iw_handler_def ieee80211_iw_handler_def;
|
||||
|
||||
|
||||
/* Least common multiple of the used rates (in 100 kbps). This is used to
|
||||
* calculate rate_inv values for each rate so that only integers are needed. */
|
||||
#define CHAN_UTIL_RATE_LCM 95040
|
||||
/* 1 usec is 1/8 * (95040/10) = 1188 */
|
||||
#define CHAN_UTIL_PER_USEC 1188
|
||||
/* Amount of bits to shift the result right to scale the total utilization
|
||||
* to values that will not wrap around 32-bit integers. */
|
||||
#define CHAN_UTIL_SHIFT 9
|
||||
/* Theoretical maximum of channel utilization counter in 10 ms (stat_time=1):
|
||||
* (CHAN_UTIL_PER_USEC * 10000) >> CHAN_UTIL_SHIFT = 23203. So dividing the
|
||||
* raw value with about 23 should give utilization in 10th of a percentage
|
||||
* (1/1000). However, utilization is only estimated and not all intervals
|
||||
* between frames etc. are calculated. 18 seems to give numbers that are closer
|
||||
* to the real maximum. */
|
||||
#define CHAN_UTIL_PER_10MS 18
|
||||
#define CHAN_UTIL_HDR_LONG (202 * CHAN_UTIL_PER_USEC)
|
||||
#define CHAN_UTIL_HDR_SHORT (40 * CHAN_UTIL_PER_USEC)
|
||||
|
||||
|
||||
/* ieee80211_ioctl.c */
|
||||
int ieee80211_set_compression(struct ieee80211_local *local,
|
||||
struct net_device *dev, struct sta_info *sta);
|
||||
int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq);
|
||||
/* ieee80211_sta.c */
|
||||
void ieee80211_sta_timer(unsigned long data);
|
||||
void ieee80211_sta_work(struct work_struct *work);
|
||||
void ieee80211_sta_scan_work(struct work_struct *work);
|
||||
void ieee80211_sta_rx_mgmt(struct net_device *dev, struct sk_buff *skb,
|
||||
struct ieee80211_rx_status *rx_status);
|
||||
int ieee80211_sta_set_ssid(struct net_device *dev, char *ssid, size_t len);
|
||||
int ieee80211_sta_get_ssid(struct net_device *dev, char *ssid, size_t *len);
|
||||
int ieee80211_sta_set_bssid(struct net_device *dev, u8 *bssid);
|
||||
int ieee80211_sta_req_scan(struct net_device *dev, u8 *ssid, size_t ssid_len);
|
||||
void ieee80211_sta_req_auth(struct net_device *dev,
|
||||
struct ieee80211_if_sta *ifsta);
|
||||
int ieee80211_sta_scan_results(struct net_device *dev, char *buf, size_t len);
|
||||
void ieee80211_sta_rx_scan(struct net_device *dev, struct sk_buff *skb,
|
||||
struct ieee80211_rx_status *rx_status);
|
||||
void ieee80211_rx_bss_list_init(struct net_device *dev);
|
||||
void ieee80211_rx_bss_list_deinit(struct net_device *dev);
|
||||
int ieee80211_sta_set_extra_ie(struct net_device *dev, char *ie, size_t len);
|
||||
struct sta_info * ieee80211_ibss_add_sta(struct net_device *dev,
|
||||
struct sk_buff *skb, u8 *bssid,
|
||||
u8 *addr);
|
||||
int ieee80211_sta_deauthenticate(struct net_device *dev, u16 reason);
|
||||
int ieee80211_sta_disassociate(struct net_device *dev, u16 reason);
|
||||
void ieee80211_erp_info_change_notify(struct net_device *dev, u8 changes);
|
||||
void ieee80211_reset_erp_info(struct net_device *dev);
|
||||
|
||||
/* ieee80211_iface.c */
|
||||
int ieee80211_if_add(struct net_device *dev, const char *name,
|
||||
struct net_device **new_dev, int type);
|
||||
void ieee80211_if_set_type(struct net_device *dev, int type);
|
||||
void ieee80211_if_reinit(struct net_device *dev);
|
||||
void __ieee80211_if_del(struct ieee80211_local *local,
|
||||
struct ieee80211_sub_if_data *sdata);
|
||||
int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
|
||||
void ieee80211_if_free(struct net_device *dev);
|
||||
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
|
||||
|
||||
/* regdomain.c */
|
||||
void ieee80211_regdomain_init(void);
|
||||
void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode);
|
||||
|
||||
/* rx handling */
|
||||
extern ieee80211_rx_handler ieee80211_rx_pre_handlers[];
|
||||
extern ieee80211_rx_handler ieee80211_rx_handlers[];
|
||||
|
||||
/* tx handling */
|
||||
extern ieee80211_tx_handler ieee80211_tx_handlers[];
|
||||
void ieee80211_clear_tx_pending(struct ieee80211_local *local);
|
||||
void ieee80211_tx_pending(unsigned long data);
|
||||
int ieee80211_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
|
||||
int ieee80211_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
|
||||
int ieee80211_subif_start_xmit(struct sk_buff *skb, struct net_device *dev);
|
||||
|
||||
/* utility functions/constants */
|
||||
extern void *mac80211_wiphy_privid; /* for wiphy privid */
|
||||
extern const unsigned char rfc1042_header[6];
|
||||
extern const unsigned char bridge_tunnel_header[6];
|
||||
u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len);
|
||||
int ieee80211_is_eapol(const struct sk_buff *skb);
|
||||
int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
|
||||
int rate, int erp, int short_preamble);
|
||||
void mac80211_ev_michael_mic_failure(struct net_device *dev, int keyidx,
|
||||
struct ieee80211_hdr *hdr);
|
||||
|
||||
#endif /* IEEE80211_I_H */
|
||||
301
package/mac80211/src/net/mac80211/ieee80211_iface.c
Normal file
301
package/mac80211/src/net/mac80211/ieee80211_iface.c
Normal file
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005-2006, Devicescape Software, Inc.
|
||||
* Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "sta_info.h"
|
||||
#include "debugfs_netdev.h"
|
||||
|
||||
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Default values for sub-interface parameters */
|
||||
sdata->drop_unencrypted = 0;
|
||||
sdata->eapol = 1;
|
||||
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++)
|
||||
skb_queue_head_init(&sdata->fragments[i].skb_list);
|
||||
|
||||
INIT_LIST_HEAD(&sdata->key_list);
|
||||
}
|
||||
|
||||
static void ieee80211_if_sdata_deinit(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
|
||||
__skb_queue_purge(&sdata->fragments[i].skb_list);
|
||||
}
|
||||
}
|
||||
|
||||
/* Must be called with rtnl lock held. */
|
||||
int ieee80211_if_add(struct net_device *dev, const char *name,
|
||||
struct net_device **new_dev, int type)
|
||||
{
|
||||
struct net_device *ndev;
|
||||
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
||||
struct ieee80211_sub_if_data *sdata = NULL;
|
||||
int ret;
|
||||
|
||||
ASSERT_RTNL();
|
||||
ndev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
|
||||
name, ieee80211_if_setup);
|
||||
if (!ndev)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = dev_alloc_name(ndev, ndev->name);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
|
||||
memcpy(ndev->dev_addr, local->hw.wiphy->perm_addr, ETH_ALEN);
|
||||
ndev->base_addr = dev->base_addr;
|
||||
ndev->irq = dev->irq;
|
||||
ndev->mem_start = dev->mem_start;
|
||||
ndev->mem_end = dev->mem_end;
|
||||
SET_NETDEV_DEV(ndev, wiphy_dev(local->hw.wiphy));
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
|
||||
ndev->ieee80211_ptr = &sdata->wdev;
|
||||
sdata->wdev.wiphy = local->hw.wiphy;
|
||||
sdata->type = IEEE80211_IF_TYPE_AP;
|
||||
sdata->dev = ndev;
|
||||
sdata->local = local;
|
||||
ieee80211_if_sdata_init(sdata);
|
||||
|
||||
ret = register_netdevice(ndev);
|
||||
if (ret)
|
||||
goto fail;
|
||||
|
||||
ieee80211_debugfs_add_netdev(sdata);
|
||||
ieee80211_if_set_type(ndev, type);
|
||||
|
||||
/* we're under RTNL so all this is fine */
|
||||
if (unlikely(local->reg_state == IEEE80211_DEV_UNREGISTERED)) {
|
||||
__ieee80211_if_del(local, sdata);
|
||||
return -ENODEV;
|
||||
}
|
||||
list_add_tail_rcu(&sdata->list, &local->interfaces);
|
||||
|
||||
if (new_dev)
|
||||
*new_dev = ndev;
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
free_netdev(ndev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ieee80211_if_set_type(struct net_device *dev, int type)
|
||||
{
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
int oldtype = sdata->type;
|
||||
|
||||
/*
|
||||
* We need to call this function on the master interface
|
||||
* which already has a hard_start_xmit routine assigned
|
||||
* which must not be changed.
|
||||
*/
|
||||
if (dev != sdata->local->mdev)
|
||||
dev->hard_start_xmit = ieee80211_subif_start_xmit;
|
||||
|
||||
/*
|
||||
* Called even when register_netdevice fails, it would
|
||||
* oops if assigned before initialising the rest.
|
||||
*/
|
||||
dev->uninit = ieee80211_if_reinit;
|
||||
|
||||
/* most have no BSS pointer */
|
||||
sdata->bss = NULL;
|
||||
sdata->type = type;
|
||||
|
||||
switch (type) {
|
||||
case IEEE80211_IF_TYPE_WDS:
|
||||
/* nothing special */
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_VLAN:
|
||||
sdata->u.vlan.ap = NULL;
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_AP:
|
||||
sdata->u.ap.dtim_period = 2;
|
||||
sdata->u.ap.force_unicast_rateidx = -1;
|
||||
sdata->u.ap.max_ratectrl_rateidx = -1;
|
||||
skb_queue_head_init(&sdata->u.ap.ps_bc_buf);
|
||||
sdata->bss = &sdata->u.ap;
|
||||
INIT_LIST_HEAD(&sdata->u.ap.vlans);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_STA:
|
||||
case IEEE80211_IF_TYPE_IBSS: {
|
||||
struct ieee80211_sub_if_data *msdata;
|
||||
struct ieee80211_if_sta *ifsta;
|
||||
|
||||
ifsta = &sdata->u.sta;
|
||||
INIT_WORK(&ifsta->work, ieee80211_sta_work);
|
||||
setup_timer(&ifsta->timer, ieee80211_sta_timer,
|
||||
(unsigned long) sdata);
|
||||
skb_queue_head_init(&ifsta->skb_queue);
|
||||
|
||||
ifsta->capab = WLAN_CAPABILITY_ESS;
|
||||
ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
|
||||
IEEE80211_AUTH_ALG_SHARED_KEY;
|
||||
ifsta->flags |= IEEE80211_STA_CREATE_IBSS |
|
||||
IEEE80211_STA_WMM_ENABLED |
|
||||
IEEE80211_STA_AUTO_BSSID_SEL |
|
||||
IEEE80211_STA_AUTO_CHANNEL_SEL;
|
||||
|
||||
msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev);
|
||||
sdata->bss = &msdata->u.ap;
|
||||
break;
|
||||
}
|
||||
case IEEE80211_IF_TYPE_MNTR:
|
||||
dev->type = ARPHRD_IEEE80211_RADIOTAP;
|
||||
dev->hard_start_xmit = ieee80211_monitor_start_xmit;
|
||||
break;
|
||||
default:
|
||||
printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x",
|
||||
dev->name, __FUNCTION__, type);
|
||||
}
|
||||
ieee80211_debugfs_change_if_type(sdata, oldtype);
|
||||
}
|
||||
|
||||
/* Must be called with rtnl lock held. */
|
||||
void ieee80211_if_reinit(struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
struct sta_info *sta;
|
||||
struct sk_buff *skb;
|
||||
|
||||
ASSERT_RTNL();
|
||||
|
||||
ieee80211_free_keys(sdata);
|
||||
|
||||
ieee80211_if_sdata_deinit(sdata);
|
||||
|
||||
switch (sdata->type) {
|
||||
case IEEE80211_IF_TYPE_INVALID:
|
||||
/* cannot happen */
|
||||
WARN_ON(1);
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_AP: {
|
||||
/* Remove all virtual interfaces that use this BSS
|
||||
* as their sdata->bss */
|
||||
struct ieee80211_sub_if_data *tsdata, *n;
|
||||
|
||||
list_for_each_entry_safe(tsdata, n, &local->interfaces, list) {
|
||||
if (tsdata != sdata && tsdata->bss == &sdata->u.ap) {
|
||||
printk(KERN_DEBUG "%s: removing virtual "
|
||||
"interface %s because its BSS interface"
|
||||
" is being removed\n",
|
||||
sdata->dev->name, tsdata->dev->name);
|
||||
list_del_rcu(&tsdata->list);
|
||||
/*
|
||||
* We have lots of time and can afford
|
||||
* to sync for each interface
|
||||
*/
|
||||
synchronize_rcu();
|
||||
__ieee80211_if_del(local, tsdata);
|
||||
}
|
||||
}
|
||||
|
||||
kfree(sdata->u.ap.beacon_head);
|
||||
kfree(sdata->u.ap.beacon_tail);
|
||||
|
||||
while ((skb = skb_dequeue(&sdata->u.ap.ps_bc_buf))) {
|
||||
local->total_ps_buffered--;
|
||||
dev_kfree_skb(skb);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case IEEE80211_IF_TYPE_WDS:
|
||||
sta = sta_info_get(local, sdata->u.wds.remote_addr);
|
||||
if (sta) {
|
||||
sta_info_free(sta);
|
||||
sta_info_put(sta);
|
||||
} else {
|
||||
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: Someone had deleted my STA "
|
||||
"entry for the WDS link\n", dev->name);
|
||||
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
|
||||
}
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_STA:
|
||||
case IEEE80211_IF_TYPE_IBSS:
|
||||
kfree(sdata->u.sta.extra_ie);
|
||||
sdata->u.sta.extra_ie = NULL;
|
||||
kfree(sdata->u.sta.assocreq_ies);
|
||||
sdata->u.sta.assocreq_ies = NULL;
|
||||
kfree(sdata->u.sta.assocresp_ies);
|
||||
sdata->u.sta.assocresp_ies = NULL;
|
||||
if (sdata->u.sta.probe_resp) {
|
||||
dev_kfree_skb(sdata->u.sta.probe_resp);
|
||||
sdata->u.sta.probe_resp = NULL;
|
||||
}
|
||||
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_MNTR:
|
||||
dev->type = ARPHRD_ETHER;
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_VLAN:
|
||||
sdata->u.vlan.ap = NULL;
|
||||
break;
|
||||
}
|
||||
|
||||
/* remove all STAs that are bound to this virtual interface */
|
||||
sta_info_flush(local, dev);
|
||||
|
||||
memset(&sdata->u, 0, sizeof(sdata->u));
|
||||
ieee80211_if_sdata_init(sdata);
|
||||
}
|
||||
|
||||
/* Must be called with rtnl lock held. */
|
||||
void __ieee80211_if_del(struct ieee80211_local *local,
|
||||
struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
struct net_device *dev = sdata->dev;
|
||||
|
||||
ieee80211_debugfs_remove_netdev(sdata);
|
||||
unregister_netdevice(dev);
|
||||
/* Except master interface, the net_device will be freed by
|
||||
* net_device->destructor (i. e. ieee80211_if_free). */
|
||||
}
|
||||
|
||||
/* Must be called with rtnl lock held. */
|
||||
int ieee80211_if_remove(struct net_device *dev, const char *name, int id)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
||||
struct ieee80211_sub_if_data *sdata, *n;
|
||||
|
||||
ASSERT_RTNL();
|
||||
|
||||
list_for_each_entry_safe(sdata, n, &local->interfaces, list) {
|
||||
if ((sdata->type == id || id == -1) &&
|
||||
strcmp(name, sdata->dev->name) == 0 &&
|
||||
sdata->dev != local->mdev) {
|
||||
list_del_rcu(&sdata->list);
|
||||
synchronize_rcu();
|
||||
__ieee80211_if_del(local, sdata);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
void ieee80211_if_free(struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
|
||||
ieee80211_if_sdata_deinit(sdata);
|
||||
free_netdev(dev);
|
||||
}
|
||||
1120
package/mac80211/src/net/mac80211/ieee80211_ioctl.c
Normal file
1120
package/mac80211/src/net/mac80211/ieee80211_ioctl.c
Normal file
File diff suppressed because it is too large
Load Diff
127
package/mac80211/src/net/mac80211/ieee80211_key.h
Normal file
127
package/mac80211/src/net/mac80211/ieee80211_key.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright 2002-2004, Instant802 Networks, Inc.
|
||||
* Copyright 2005, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef IEEE80211_KEY_H
|
||||
#define IEEE80211_KEY_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/crypto.h>
|
||||
#include <net/mac80211.h>
|
||||
|
||||
/* ALG_TKIP
|
||||
* struct ieee80211_key::key is encoded as a 256-bit (32 byte) data block:
|
||||
* Temporal Encryption Key (128 bits)
|
||||
* Temporal Authenticator Tx MIC Key (64 bits)
|
||||
* Temporal Authenticator Rx MIC Key (64 bits)
|
||||
*/
|
||||
|
||||
#define WEP_IV_LEN 4
|
||||
#define WEP_ICV_LEN 4
|
||||
|
||||
#define ALG_TKIP_KEY_LEN 32
|
||||
/* Starting offsets for each key */
|
||||
#define ALG_TKIP_TEMP_ENCR_KEY 0
|
||||
#define ALG_TKIP_TEMP_AUTH_TX_MIC_KEY 16
|
||||
#define ALG_TKIP_TEMP_AUTH_RX_MIC_KEY 24
|
||||
#define TKIP_IV_LEN 8
|
||||
#define TKIP_ICV_LEN 4
|
||||
|
||||
#define ALG_CCMP_KEY_LEN 16
|
||||
#define CCMP_HDR_LEN 8
|
||||
#define CCMP_MIC_LEN 8
|
||||
#define CCMP_TK_LEN 16
|
||||
#define CCMP_PN_LEN 6
|
||||
|
||||
#define NUM_RX_DATA_QUEUES 17
|
||||
|
||||
struct ieee80211_local;
|
||||
struct ieee80211_sub_if_data;
|
||||
struct sta_info;
|
||||
|
||||
#define KEY_FLAG_UPLOADED_TO_HARDWARE (1<<0)
|
||||
|
||||
struct ieee80211_key {
|
||||
struct ieee80211_local *local;
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
struct sta_info *sta;
|
||||
|
||||
struct list_head list;
|
||||
|
||||
unsigned int flags;
|
||||
|
||||
union {
|
||||
struct {
|
||||
/* last used TSC */
|
||||
u32 iv32;
|
||||
u16 iv16;
|
||||
u16 p1k[5];
|
||||
int tx_initialized;
|
||||
|
||||
/* last received RSC */
|
||||
u32 iv32_rx[NUM_RX_DATA_QUEUES];
|
||||
u16 iv16_rx[NUM_RX_DATA_QUEUES];
|
||||
u16 p1k_rx[NUM_RX_DATA_QUEUES][5];
|
||||
int rx_initialized[NUM_RX_DATA_QUEUES];
|
||||
} tkip;
|
||||
struct {
|
||||
u8 tx_pn[6];
|
||||
u8 rx_pn[NUM_RX_DATA_QUEUES][6];
|
||||
struct crypto_cipher *tfm;
|
||||
u32 replays; /* dot11RSNAStatsCCMPReplays */
|
||||
/* scratch buffers for virt_to_page() (crypto API) */
|
||||
#ifndef AES_BLOCK_LEN
|
||||
#define AES_BLOCK_LEN 16
|
||||
#endif
|
||||
u8 tx_crypto_buf[6 * AES_BLOCK_LEN];
|
||||
u8 rx_crypto_buf[6 * AES_BLOCK_LEN];
|
||||
} ccmp;
|
||||
} u;
|
||||
|
||||
/* number of times this key has been used */
|
||||
int tx_rx_count;
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct {
|
||||
struct dentry *stalink;
|
||||
struct dentry *dir;
|
||||
struct dentry *keylen;
|
||||
struct dentry *flags;
|
||||
struct dentry *keyidx;
|
||||
struct dentry *hw_key_idx;
|
||||
struct dentry *tx_rx_count;
|
||||
struct dentry *algorithm;
|
||||
struct dentry *tx_spec;
|
||||
struct dentry *rx_spec;
|
||||
struct dentry *replays;
|
||||
struct dentry *key;
|
||||
struct dentry *ifindex;
|
||||
} debugfs;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* key config, must be last because it contains key
|
||||
* material as variable length member
|
||||
*/
|
||||
struct ieee80211_key_conf conf;
|
||||
};
|
||||
|
||||
struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
|
||||
struct sta_info *sta,
|
||||
enum ieee80211_key_alg alg,
|
||||
int idx,
|
||||
size_t key_len,
|
||||
const u8 *key_data);
|
||||
void ieee80211_key_free(struct ieee80211_key *key);
|
||||
void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx);
|
||||
void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata);
|
||||
|
||||
#endif /* IEEE80211_KEY_H */
|
||||
126
package/mac80211/src/net/mac80211/ieee80211_led.c
Normal file
126
package/mac80211/src/net/mac80211/ieee80211_led.c
Normal file
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Copyright 2006, Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* just for IFNAMSIZ */
|
||||
#include <linux/if.h>
|
||||
#include "ieee80211_led.h"
|
||||
|
||||
void ieee80211_led_rx(struct ieee80211_local *local)
|
||||
{
|
||||
if (unlikely(!local->rx_led))
|
||||
return;
|
||||
if (local->rx_led_counter++ % 2 == 0)
|
||||
led_trigger_event(local->rx_led, LED_OFF);
|
||||
else
|
||||
led_trigger_event(local->rx_led, LED_FULL);
|
||||
}
|
||||
|
||||
/* q is 1 if a packet was enqueued, 0 if it has been transmitted */
|
||||
void ieee80211_led_tx(struct ieee80211_local *local, int q)
|
||||
{
|
||||
if (unlikely(!local->tx_led))
|
||||
return;
|
||||
/* not sure how this is supposed to work ... */
|
||||
local->tx_led_counter += 2*q-1;
|
||||
if (local->tx_led_counter % 2 == 0)
|
||||
led_trigger_event(local->tx_led, LED_OFF);
|
||||
else
|
||||
led_trigger_event(local->tx_led, LED_FULL);
|
||||
}
|
||||
|
||||
void ieee80211_led_assoc(struct ieee80211_local *local, bool associated)
|
||||
{
|
||||
if (unlikely(!local->assoc_led))
|
||||
return;
|
||||
if (associated)
|
||||
led_trigger_event(local->assoc_led, LED_FULL);
|
||||
else
|
||||
led_trigger_event(local->assoc_led, LED_OFF);
|
||||
}
|
||||
|
||||
void ieee80211_led_init(struct ieee80211_local *local)
|
||||
{
|
||||
local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
|
||||
if (local->rx_led) {
|
||||
snprintf(local->rx_led_name, sizeof(local->rx_led_name),
|
||||
"%srx", wiphy_name(local->hw.wiphy));
|
||||
local->rx_led->name = local->rx_led_name;
|
||||
if (led_trigger_register(local->rx_led)) {
|
||||
kfree(local->rx_led);
|
||||
local->rx_led = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
local->tx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
|
||||
if (local->tx_led) {
|
||||
snprintf(local->tx_led_name, sizeof(local->tx_led_name),
|
||||
"%stx", wiphy_name(local->hw.wiphy));
|
||||
local->tx_led->name = local->tx_led_name;
|
||||
if (led_trigger_register(local->tx_led)) {
|
||||
kfree(local->tx_led);
|
||||
local->tx_led = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
local->assoc_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
|
||||
if (local->assoc_led) {
|
||||
snprintf(local->assoc_led_name, sizeof(local->assoc_led_name),
|
||||
"%sassoc", wiphy_name(local->hw.wiphy));
|
||||
local->assoc_led->name = local->assoc_led_name;
|
||||
if (led_trigger_register(local->assoc_led)) {
|
||||
kfree(local->assoc_led);
|
||||
local->assoc_led = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ieee80211_led_exit(struct ieee80211_local *local)
|
||||
{
|
||||
if (local->assoc_led) {
|
||||
led_trigger_unregister(local->assoc_led);
|
||||
kfree(local->assoc_led);
|
||||
}
|
||||
if (local->tx_led) {
|
||||
led_trigger_unregister(local->tx_led);
|
||||
kfree(local->tx_led);
|
||||
}
|
||||
if (local->rx_led) {
|
||||
led_trigger_unregister(local->rx_led);
|
||||
kfree(local->rx_led);
|
||||
}
|
||||
}
|
||||
|
||||
char *__ieee80211_get_assoc_led_name(struct ieee80211_hw *hw)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
|
||||
if (local->assoc_led)
|
||||
return local->assoc_led_name;
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(__ieee80211_get_assoc_led_name);
|
||||
|
||||
char *__ieee80211_get_tx_led_name(struct ieee80211_hw *hw)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
|
||||
if (local->tx_led)
|
||||
return local->tx_led_name;
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(__ieee80211_get_tx_led_name);
|
||||
|
||||
char *__ieee80211_get_rx_led_name(struct ieee80211_hw *hw)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
|
||||
if (local->rx_led)
|
||||
return local->rx_led_name;
|
||||
return NULL;
|
||||
}
|
||||
EXPORT_SYMBOL(__ieee80211_get_rx_led_name);
|
||||
38
package/mac80211/src/net/mac80211/ieee80211_led.h
Normal file
38
package/mac80211/src/net/mac80211/ieee80211_led.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright 2006, Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/list.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/leds.h>
|
||||
#include "ieee80211_i.h"
|
||||
|
||||
#ifdef CONFIG_MAC80211_LEDS
|
||||
extern void ieee80211_led_rx(struct ieee80211_local *local);
|
||||
extern void ieee80211_led_tx(struct ieee80211_local *local, int q);
|
||||
extern void ieee80211_led_assoc(struct ieee80211_local *local,
|
||||
bool associated);
|
||||
extern void ieee80211_led_init(struct ieee80211_local *local);
|
||||
extern void ieee80211_led_exit(struct ieee80211_local *local);
|
||||
#else
|
||||
static inline void ieee80211_led_rx(struct ieee80211_local *local)
|
||||
{
|
||||
}
|
||||
static inline void ieee80211_led_tx(struct ieee80211_local *local, int q)
|
||||
{
|
||||
}
|
||||
static inline void ieee80211_led_assoc(struct ieee80211_local *local,
|
||||
bool associated)
|
||||
{
|
||||
}
|
||||
static inline void ieee80211_led_init(struct ieee80211_local *local)
|
||||
{
|
||||
}
|
||||
static inline void ieee80211_led_exit(struct ieee80211_local *local)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
180
package/mac80211/src/net/mac80211/ieee80211_rate.c
Normal file
180
package/mac80211/src/net/mac80211/ieee80211_rate.c
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005-2006, Devicescape Software, Inc.
|
||||
* Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include "ieee80211_rate.h"
|
||||
#include "ieee80211_i.h"
|
||||
|
||||
struct rate_control_alg {
|
||||
struct list_head list;
|
||||
struct rate_control_ops *ops;
|
||||
};
|
||||
|
||||
static LIST_HEAD(rate_ctrl_algs);
|
||||
static DEFINE_MUTEX(rate_ctrl_mutex);
|
||||
|
||||
int ieee80211_rate_control_register(struct rate_control_ops *ops)
|
||||
{
|
||||
struct rate_control_alg *alg;
|
||||
|
||||
alg = kzalloc(sizeof(*alg), GFP_KERNEL);
|
||||
if (alg == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
alg->ops = ops;
|
||||
|
||||
mutex_lock(&rate_ctrl_mutex);
|
||||
list_add_tail(&alg->list, &rate_ctrl_algs);
|
||||
mutex_unlock(&rate_ctrl_mutex);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_rate_control_register);
|
||||
|
||||
void ieee80211_rate_control_unregister(struct rate_control_ops *ops)
|
||||
{
|
||||
struct rate_control_alg *alg;
|
||||
|
||||
mutex_lock(&rate_ctrl_mutex);
|
||||
list_for_each_entry(alg, &rate_ctrl_algs, list) {
|
||||
if (alg->ops == ops) {
|
||||
list_del(&alg->list);
|
||||
break;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&rate_ctrl_mutex);
|
||||
kfree(alg);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_rate_control_unregister);
|
||||
|
||||
static struct rate_control_ops *
|
||||
ieee80211_try_rate_control_ops_get(const char *name)
|
||||
{
|
||||
struct rate_control_alg *alg;
|
||||
struct rate_control_ops *ops = NULL;
|
||||
|
||||
mutex_lock(&rate_ctrl_mutex);
|
||||
list_for_each_entry(alg, &rate_ctrl_algs, list) {
|
||||
if (!name || !strcmp(alg->ops->name, name))
|
||||
if (try_module_get(alg->ops->module)) {
|
||||
ops = alg->ops;
|
||||
break;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&rate_ctrl_mutex);
|
||||
return ops;
|
||||
}
|
||||
|
||||
/* Get the rate control algorithm. If `name' is NULL, get the first
|
||||
* available algorithm. */
|
||||
static struct rate_control_ops *
|
||||
ieee80211_rate_control_ops_get(const char *name)
|
||||
{
|
||||
struct rate_control_ops *ops;
|
||||
|
||||
ops = ieee80211_try_rate_control_ops_get(name);
|
||||
if (!ops) {
|
||||
request_module("rc80211_%s", name ? name : "default");
|
||||
ops = ieee80211_try_rate_control_ops_get(name);
|
||||
}
|
||||
return ops;
|
||||
}
|
||||
|
||||
static void ieee80211_rate_control_ops_put(struct rate_control_ops *ops)
|
||||
{
|
||||
module_put(ops->module);
|
||||
}
|
||||
|
||||
struct rate_control_ref *rate_control_alloc(const char *name,
|
||||
struct ieee80211_local *local)
|
||||
{
|
||||
struct rate_control_ref *ref;
|
||||
|
||||
ref = kmalloc(sizeof(struct rate_control_ref), GFP_KERNEL);
|
||||
if (!ref)
|
||||
goto fail_ref;
|
||||
kref_init(&ref->kref);
|
||||
ref->ops = ieee80211_rate_control_ops_get(name);
|
||||
if (!ref->ops)
|
||||
goto fail_ops;
|
||||
ref->priv = ref->ops->alloc(local);
|
||||
if (!ref->priv)
|
||||
goto fail_priv;
|
||||
return ref;
|
||||
|
||||
fail_priv:
|
||||
ieee80211_rate_control_ops_put(ref->ops);
|
||||
fail_ops:
|
||||
kfree(ref);
|
||||
fail_ref:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void rate_control_release(struct kref *kref)
|
||||
{
|
||||
struct rate_control_ref *ctrl_ref;
|
||||
|
||||
ctrl_ref = container_of(kref, struct rate_control_ref, kref);
|
||||
ctrl_ref->ops->free(ctrl_ref->priv);
|
||||
ieee80211_rate_control_ops_put(ctrl_ref->ops);
|
||||
kfree(ctrl_ref);
|
||||
}
|
||||
|
||||
struct rate_control_ref *rate_control_get(struct rate_control_ref *ref)
|
||||
{
|
||||
kref_get(&ref->kref);
|
||||
return ref;
|
||||
}
|
||||
|
||||
void rate_control_put(struct rate_control_ref *ref)
|
||||
{
|
||||
kref_put(&ref->kref, rate_control_release);
|
||||
}
|
||||
|
||||
int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
|
||||
const char *name)
|
||||
{
|
||||
struct rate_control_ref *ref, *old;
|
||||
|
||||
ASSERT_RTNL();
|
||||
if (local->open_count || netif_running(local->mdev))
|
||||
return -EBUSY;
|
||||
|
||||
ref = rate_control_alloc(name, local);
|
||||
if (!ref) {
|
||||
printk(KERN_WARNING "%s: Failed to select rate control "
|
||||
"algorithm\n", wiphy_name(local->hw.wiphy));
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
old = local->rate_ctrl;
|
||||
local->rate_ctrl = ref;
|
||||
if (old) {
|
||||
rate_control_put(old);
|
||||
sta_info_flush(local, NULL);
|
||||
}
|
||||
|
||||
printk(KERN_DEBUG "%s: Selected rate control "
|
||||
"algorithm '%s'\n", wiphy_name(local->hw.wiphy),
|
||||
ref->ops->name);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rate_control_deinitialize(struct ieee80211_local *local)
|
||||
{
|
||||
struct rate_control_ref *ref;
|
||||
|
||||
ref = local->rate_ctrl;
|
||||
local->rate_ctrl = NULL;
|
||||
rate_control_put(ref);
|
||||
}
|
||||
148
package/mac80211/src/net/mac80211/ieee80211_rate.h
Normal file
148
package/mac80211/src/net/mac80211/ieee80211_rate.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005, Devicescape Software, Inc.
|
||||
* Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef IEEE80211_RATE_H
|
||||
#define IEEE80211_RATE_H
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/types.h>
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "sta_info.h"
|
||||
|
||||
#define RATE_CONTROL_NUM_DOWN 20
|
||||
#define RATE_CONTROL_NUM_UP 15
|
||||
|
||||
|
||||
struct rate_control_extra {
|
||||
/* values from rate_control_get_rate() to the caller: */
|
||||
struct ieee80211_rate *probe; /* probe with this rate, or NULL for no
|
||||
* probing */
|
||||
struct ieee80211_rate *nonerp;
|
||||
|
||||
/* parameters from the caller to rate_control_get_rate(): */
|
||||
struct ieee80211_hw_mode *mode;
|
||||
u16 ethertype;
|
||||
};
|
||||
|
||||
|
||||
struct rate_control_ops {
|
||||
struct module *module;
|
||||
const char *name;
|
||||
void (*tx_status)(void *priv, struct net_device *dev,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_tx_status *status);
|
||||
struct ieee80211_rate *(*get_rate)(void *priv, struct net_device *dev,
|
||||
struct sk_buff *skb,
|
||||
struct rate_control_extra *extra);
|
||||
void (*rate_init)(void *priv, void *priv_sta,
|
||||
struct ieee80211_local *local, struct sta_info *sta);
|
||||
void (*clear)(void *priv);
|
||||
|
||||
void *(*alloc)(struct ieee80211_local *local);
|
||||
void (*free)(void *priv);
|
||||
void *(*alloc_sta)(void *priv, gfp_t gfp);
|
||||
void (*free_sta)(void *priv, void *priv_sta);
|
||||
|
||||
int (*add_attrs)(void *priv, struct kobject *kobj);
|
||||
void (*remove_attrs)(void *priv, struct kobject *kobj);
|
||||
void (*add_sta_debugfs)(void *priv, void *priv_sta,
|
||||
struct dentry *dir);
|
||||
void (*remove_sta_debugfs)(void *priv, void *priv_sta);
|
||||
};
|
||||
|
||||
struct rate_control_ref {
|
||||
struct rate_control_ops *ops;
|
||||
void *priv;
|
||||
struct kref kref;
|
||||
};
|
||||
|
||||
int ieee80211_rate_control_register(struct rate_control_ops *ops);
|
||||
void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
|
||||
|
||||
/* Get a reference to the rate control algorithm. If `name' is NULL, get the
|
||||
* first available algorithm. */
|
||||
struct rate_control_ref *rate_control_alloc(const char *name,
|
||||
struct ieee80211_local *local);
|
||||
struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
|
||||
void rate_control_put(struct rate_control_ref *ref);
|
||||
|
||||
static inline void rate_control_tx_status(struct ieee80211_local *local,
|
||||
struct net_device *dev,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_tx_status *status)
|
||||
{
|
||||
struct rate_control_ref *ref = local->rate_ctrl;
|
||||
ref->ops->tx_status(ref->priv, dev, skb, status);
|
||||
}
|
||||
|
||||
|
||||
static inline struct ieee80211_rate *
|
||||
rate_control_get_rate(struct ieee80211_local *local, struct net_device *dev,
|
||||
struct sk_buff *skb, struct rate_control_extra *extra)
|
||||
{
|
||||
struct rate_control_ref *ref = local->rate_ctrl;
|
||||
return ref->ops->get_rate(ref->priv, dev, skb, extra);
|
||||
}
|
||||
|
||||
|
||||
static inline void rate_control_rate_init(struct sta_info *sta,
|
||||
struct ieee80211_local *local)
|
||||
{
|
||||
struct rate_control_ref *ref = sta->rate_ctrl;
|
||||
ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
|
||||
}
|
||||
|
||||
|
||||
static inline void rate_control_clear(struct ieee80211_local *local)
|
||||
{
|
||||
struct rate_control_ref *ref = local->rate_ctrl;
|
||||
ref->ops->clear(ref->priv);
|
||||
}
|
||||
|
||||
static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
|
||||
gfp_t gfp)
|
||||
{
|
||||
return ref->ops->alloc_sta(ref->priv, gfp);
|
||||
}
|
||||
|
||||
static inline void rate_control_free_sta(struct rate_control_ref *ref,
|
||||
void *priv)
|
||||
{
|
||||
ref->ops->free_sta(ref->priv, priv);
|
||||
}
|
||||
|
||||
static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
|
||||
{
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct rate_control_ref *ref = sta->rate_ctrl;
|
||||
if (sta->debugfs.dir && ref->ops->add_sta_debugfs)
|
||||
ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
|
||||
sta->debugfs.dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
|
||||
{
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct rate_control_ref *ref = sta->rate_ctrl;
|
||||
if (ref->ops->remove_sta_debugfs)
|
||||
ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* functions for rate control related to a device */
|
||||
int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
|
||||
const char *name);
|
||||
void rate_control_deinitialize(struct ieee80211_local *local);
|
||||
|
||||
#endif /* IEEE80211_RATE_H */
|
||||
3143
package/mac80211/src/net/mac80211/ieee80211_sta.c
Normal file
3143
package/mac80211/src/net/mac80211/ieee80211_sta.c
Normal file
File diff suppressed because it is too large
Load Diff
277
package/mac80211/src/net/mac80211/key.c
Normal file
277
package/mac80211/src/net/mac80211/key.c
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005-2006, Devicescape Software, Inc.
|
||||
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
|
||||
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/rcupdate.h>
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "debugfs_key.h"
|
||||
#include "aes_ccm.h"
|
||||
|
||||
|
||||
/*
|
||||
* Key handling basics
|
||||
*
|
||||
* Key handling in mac80211 is done based on per-interface (sub_if_data)
|
||||
* keys and per-station keys. Since each station belongs to an interface,
|
||||
* each station key also belongs to that interface.
|
||||
*
|
||||
* Hardware acceleration is done on a best-effort basis, for each key
|
||||
* that is eligible the hardware is asked to enable that key but if
|
||||
* it cannot do that they key is simply kept for software encryption.
|
||||
* There is currently no way of knowing this except by looking into
|
||||
* debugfs.
|
||||
*
|
||||
* All operations here are called under RTNL so no extra locking is
|
||||
* required.
|
||||
*/
|
||||
|
||||
static const u8 bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
static const u8 zero_addr[ETH_ALEN];
|
||||
|
||||
static const u8 *get_mac_for_key(struct ieee80211_key *key)
|
||||
{
|
||||
const u8 *addr = bcast_addr;
|
||||
|
||||
/*
|
||||
* If we're an AP we won't ever receive frames with a non-WEP
|
||||
* group key so we tell the driver that by using the zero MAC
|
||||
* address to indicate a transmit-only key.
|
||||
*/
|
||||
if (key->conf.alg != ALG_WEP &&
|
||||
(key->sdata->type == IEEE80211_IF_TYPE_AP ||
|
||||
key->sdata->type == IEEE80211_IF_TYPE_VLAN))
|
||||
addr = zero_addr;
|
||||
|
||||
if (key->sta)
|
||||
addr = key->sta->addr;
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
static void ieee80211_key_enable_hw_accel(struct ieee80211_key *key)
|
||||
{
|
||||
const u8 *addr;
|
||||
int ret;
|
||||
|
||||
if (!key->local->ops->set_key)
|
||||
return;
|
||||
|
||||
addr = get_mac_for_key(key);
|
||||
|
||||
ret = key->local->ops->set_key(local_to_hw(key->local), SET_KEY,
|
||||
key->sdata->dev->dev_addr, addr,
|
||||
&key->conf);
|
||||
|
||||
if (!ret)
|
||||
key->flags |= KEY_FLAG_UPLOADED_TO_HARDWARE;
|
||||
|
||||
if (ret && ret != -ENOSPC && ret != -EOPNOTSUPP)
|
||||
printk(KERN_ERR "mac80211-%s: failed to set key "
|
||||
"(%d, " MAC_FMT ") to hardware (%d)\n",
|
||||
wiphy_name(key->local->hw.wiphy),
|
||||
key->conf.keyidx, MAC_ARG(addr), ret);
|
||||
}
|
||||
|
||||
static void ieee80211_key_disable_hw_accel(struct ieee80211_key *key)
|
||||
{
|
||||
const u8 *addr;
|
||||
int ret;
|
||||
|
||||
if (!key->local->ops->set_key)
|
||||
return;
|
||||
|
||||
if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
|
||||
return;
|
||||
|
||||
addr = get_mac_for_key(key);
|
||||
|
||||
ret = key->local->ops->set_key(local_to_hw(key->local), DISABLE_KEY,
|
||||
key->sdata->dev->dev_addr, addr,
|
||||
&key->conf);
|
||||
|
||||
if (ret)
|
||||
printk(KERN_ERR "mac80211-%s: failed to remove key "
|
||||
"(%d, " MAC_FMT ") from hardware (%d)\n",
|
||||
wiphy_name(key->local->hw.wiphy),
|
||||
key->conf.keyidx, MAC_ARG(addr), ret);
|
||||
|
||||
key->flags &= ~KEY_FLAG_UPLOADED_TO_HARDWARE;
|
||||
}
|
||||
|
||||
struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
|
||||
struct sta_info *sta,
|
||||
enum ieee80211_key_alg alg,
|
||||
int idx,
|
||||
size_t key_len,
|
||||
const u8 *key_data)
|
||||
{
|
||||
struct ieee80211_key *key;
|
||||
|
||||
BUG_ON(idx < 0 || idx >= NUM_DEFAULT_KEYS);
|
||||
|
||||
key = kzalloc(sizeof(struct ieee80211_key) + key_len, GFP_KERNEL);
|
||||
if (!key)
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Default to software encryption; we'll later upload the
|
||||
* key to the hardware if possible.
|
||||
*/
|
||||
key->conf.flags = 0;
|
||||
key->flags = 0;
|
||||
|
||||
key->conf.alg = alg;
|
||||
key->conf.keyidx = idx;
|
||||
key->conf.keylen = key_len;
|
||||
memcpy(key->conf.key, key_data, key_len);
|
||||
|
||||
key->local = sdata->local;
|
||||
key->sdata = sdata;
|
||||
key->sta = sta;
|
||||
|
||||
if (alg == ALG_CCMP) {
|
||||
/*
|
||||
* Initialize AES key state here as an optimization so that
|
||||
* it does not need to be initialized for every packet.
|
||||
*/
|
||||
key->u.ccmp.tfm = ieee80211_aes_key_setup_encrypt(key_data);
|
||||
if (!key->u.ccmp.tfm) {
|
||||
ieee80211_key_free(key);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
ieee80211_debugfs_key_add(key->local, key);
|
||||
|
||||
/* remove key first */
|
||||
if (sta)
|
||||
ieee80211_key_free(sta->key);
|
||||
else
|
||||
ieee80211_key_free(sdata->keys[idx]);
|
||||
|
||||
if (sta) {
|
||||
ieee80211_debugfs_key_sta_link(key, sta);
|
||||
|
||||
/*
|
||||
* some hardware cannot handle TKIP with QoS, so
|
||||
* we indicate whether QoS could be in use.
|
||||
*/
|
||||
if (sta->flags & WLAN_STA_WME)
|
||||
key->conf.flags |= IEEE80211_KEY_FLAG_WMM_STA;
|
||||
} else {
|
||||
if (sdata->type == IEEE80211_IF_TYPE_STA) {
|
||||
struct sta_info *ap;
|
||||
|
||||
/* same here, the AP could be using QoS */
|
||||
ap = sta_info_get(key->local, key->sdata->u.sta.bssid);
|
||||
if (ap) {
|
||||
if (ap->flags & WLAN_STA_WME)
|
||||
key->conf.flags |=
|
||||
IEEE80211_KEY_FLAG_WMM_STA;
|
||||
sta_info_put(ap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* enable hwaccel if appropriate */
|
||||
if (netif_running(key->sdata->dev))
|
||||
ieee80211_key_enable_hw_accel(key);
|
||||
|
||||
if (sta)
|
||||
rcu_assign_pointer(sta->key, key);
|
||||
else
|
||||
rcu_assign_pointer(sdata->keys[idx], key);
|
||||
|
||||
list_add(&key->list, &sdata->key_list);
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
void ieee80211_key_free(struct ieee80211_key *key)
|
||||
{
|
||||
if (!key)
|
||||
return;
|
||||
|
||||
if (key->sta) {
|
||||
rcu_assign_pointer(key->sta->key, NULL);
|
||||
} else {
|
||||
if (key->sdata->default_key == key)
|
||||
ieee80211_set_default_key(key->sdata, -1);
|
||||
if (key->conf.keyidx >= 0 &&
|
||||
key->conf.keyidx < NUM_DEFAULT_KEYS)
|
||||
rcu_assign_pointer(key->sdata->keys[key->conf.keyidx],
|
||||
NULL);
|
||||
else
|
||||
WARN_ON(1);
|
||||
}
|
||||
|
||||
/* wait for all key users to complete */
|
||||
synchronize_rcu();
|
||||
|
||||
/* remove from hwaccel if appropriate */
|
||||
ieee80211_key_disable_hw_accel(key);
|
||||
|
||||
if (key->conf.alg == ALG_CCMP)
|
||||
ieee80211_aes_key_free(key->u.ccmp.tfm);
|
||||
ieee80211_debugfs_key_remove(key);
|
||||
|
||||
list_del(&key->list);
|
||||
|
||||
kfree(key);
|
||||
}
|
||||
|
||||
void ieee80211_set_default_key(struct ieee80211_sub_if_data *sdata, int idx)
|
||||
{
|
||||
struct ieee80211_key *key = NULL;
|
||||
|
||||
if (idx >= 0 && idx < NUM_DEFAULT_KEYS)
|
||||
key = sdata->keys[idx];
|
||||
|
||||
if (sdata->default_key != key) {
|
||||
ieee80211_debugfs_key_remove_default(sdata);
|
||||
|
||||
rcu_assign_pointer(sdata->default_key, key);
|
||||
|
||||
if (sdata->default_key)
|
||||
ieee80211_debugfs_key_add_default(sdata);
|
||||
}
|
||||
}
|
||||
|
||||
void ieee80211_free_keys(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
struct ieee80211_key *key, *tmp;
|
||||
|
||||
list_for_each_entry_safe(key, tmp, &sdata->key_list, list)
|
||||
ieee80211_key_free(key);
|
||||
}
|
||||
|
||||
void ieee80211_enable_keys(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
struct ieee80211_key *key;
|
||||
|
||||
WARN_ON(!netif_running(sdata->dev));
|
||||
if (!netif_running(sdata->dev))
|
||||
return;
|
||||
|
||||
list_for_each_entry(key, &sdata->key_list, list)
|
||||
ieee80211_key_enable_hw_accel(key);
|
||||
}
|
||||
|
||||
void ieee80211_disable_keys(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
struct ieee80211_key *key;
|
||||
|
||||
list_for_each_entry(key, &sdata->key_list, list)
|
||||
ieee80211_key_disable_hw_accel(key);
|
||||
}
|
||||
104
package/mac80211/src/net/mac80211/michael.c
Normal file
104
package/mac80211/src/net/mac80211/michael.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Michael MIC implementation - optimized for TKIP MIC operations
|
||||
* Copyright 2002-2003, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#include "michael.h"
|
||||
|
||||
static inline u32 rotr(u32 val, int bits)
|
||||
{
|
||||
return (val >> bits) | (val << (32 - bits));
|
||||
}
|
||||
|
||||
|
||||
static inline u32 rotl(u32 val, int bits)
|
||||
{
|
||||
return (val << bits) | (val >> (32 - bits));
|
||||
}
|
||||
|
||||
|
||||
static inline u32 xswap(u32 val)
|
||||
{
|
||||
return ((val & 0xff00ff00) >> 8) | ((val & 0x00ff00ff) << 8);
|
||||
}
|
||||
|
||||
|
||||
#define michael_block(l, r) \
|
||||
do { \
|
||||
r ^= rotl(l, 17); \
|
||||
l += r; \
|
||||
r ^= xswap(l); \
|
||||
l += r; \
|
||||
r ^= rotl(l, 3); \
|
||||
l += r; \
|
||||
r ^= rotr(l, 2); \
|
||||
l += r; \
|
||||
} while (0)
|
||||
|
||||
|
||||
static inline u32 michael_get32(u8 *data)
|
||||
{
|
||||
return data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
|
||||
}
|
||||
|
||||
|
||||
static inline void michael_put32(u32 val, u8 *data)
|
||||
{
|
||||
data[0] = val & 0xff;
|
||||
data[1] = (val >> 8) & 0xff;
|
||||
data[2] = (val >> 16) & 0xff;
|
||||
data[3] = (val >> 24) & 0xff;
|
||||
}
|
||||
|
||||
|
||||
void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
|
||||
u8 *data, size_t data_len, u8 *mic)
|
||||
{
|
||||
u32 l, r, val;
|
||||
size_t block, blocks, left;
|
||||
|
||||
l = michael_get32(key);
|
||||
r = michael_get32(key + 4);
|
||||
|
||||
/* A pseudo header (DA, SA, Priority, 0, 0, 0) is used in Michael MIC
|
||||
* calculation, but it is _not_ transmitted */
|
||||
l ^= michael_get32(da);
|
||||
michael_block(l, r);
|
||||
l ^= da[4] | (da[5] << 8) | (sa[0] << 16) | (sa[1] << 24);
|
||||
michael_block(l, r);
|
||||
l ^= michael_get32(&sa[2]);
|
||||
michael_block(l, r);
|
||||
l ^= priority;
|
||||
michael_block(l, r);
|
||||
|
||||
/* Real data */
|
||||
blocks = data_len / 4;
|
||||
left = data_len % 4;
|
||||
|
||||
for (block = 0; block < blocks; block++) {
|
||||
l ^= michael_get32(&data[block * 4]);
|
||||
michael_block(l, r);
|
||||
}
|
||||
|
||||
/* Partial block of 0..3 bytes and padding: 0x5a + 4..7 zeros to make
|
||||
* total length a multiple of 4. */
|
||||
val = 0x5a;
|
||||
while (left > 0) {
|
||||
val <<= 8;
|
||||
left--;
|
||||
val |= data[blocks * 4 + left];
|
||||
}
|
||||
l ^= val;
|
||||
michael_block(l, r);
|
||||
/* last block is zero, so l ^ 0 = l */
|
||||
michael_block(l, r);
|
||||
|
||||
michael_put32(l, mic);
|
||||
michael_put32(r, mic + 4);
|
||||
}
|
||||
20
package/mac80211/src/net/mac80211/michael.h
Normal file
20
package/mac80211/src/net/mac80211/michael.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Michael MIC implementation - optimized for TKIP MIC operations
|
||||
* Copyright 2002-2003, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef MICHAEL_H
|
||||
#define MICHAEL_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#define MICHAEL_MIC_LEN 8
|
||||
|
||||
void michael_mic(u8 *key, u8 *da, u8 *sa, u8 priority,
|
||||
u8 *data, size_t data_len, u8 *mic);
|
||||
|
||||
#endif /* MICHAEL_H */
|
||||
430
package/mac80211/src/net/mac80211/rc80211_simple.c
Normal file
430
package/mac80211/src/net/mac80211/rc80211_simple.c
Normal file
@@ -0,0 +1,430 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/compiler.h>
|
||||
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
#include "debugfs.h"
|
||||
|
||||
|
||||
/* This is a minimal implementation of TX rate controlling that can be used
|
||||
* as the default when no improved mechanisms are available. */
|
||||
|
||||
|
||||
#define RATE_CONTROL_EMERG_DEC 2
|
||||
#define RATE_CONTROL_INTERVAL (HZ / 20)
|
||||
#define RATE_CONTROL_MIN_TX 10
|
||||
|
||||
MODULE_ALIAS("rc80211_default");
|
||||
|
||||
static void rate_control_rate_inc(struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
struct ieee80211_hw_mode *mode;
|
||||
int i = sta->txrate;
|
||||
int maxrate;
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
|
||||
if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
|
||||
/* forced unicast rate - do not change STA rate */
|
||||
return;
|
||||
}
|
||||
|
||||
mode = local->oper_hw_mode;
|
||||
maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
|
||||
|
||||
if (i > mode->num_rates)
|
||||
i = mode->num_rates - 2;
|
||||
|
||||
while (i + 1 < mode->num_rates) {
|
||||
i++;
|
||||
if (sta->supp_rates & BIT(i) &&
|
||||
mode->rates[i].flags & IEEE80211_RATE_SUPPORTED &&
|
||||
(maxrate < 0 || i <= maxrate)) {
|
||||
sta->txrate = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void rate_control_rate_dec(struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
struct ieee80211_hw_mode *mode;
|
||||
int i = sta->txrate;
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
|
||||
if (sdata->bss && sdata->bss->force_unicast_rateidx > -1) {
|
||||
/* forced unicast rate - do not change STA rate */
|
||||
return;
|
||||
}
|
||||
|
||||
mode = local->oper_hw_mode;
|
||||
if (i > mode->num_rates)
|
||||
i = mode->num_rates;
|
||||
|
||||
while (i > 0) {
|
||||
i--;
|
||||
if (sta->supp_rates & BIT(i) &&
|
||||
mode->rates[i].flags & IEEE80211_RATE_SUPPORTED) {
|
||||
sta->txrate = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct ieee80211_rate *
|
||||
rate_control_lowest_rate(struct ieee80211_local *local,
|
||||
struct ieee80211_hw_mode *mode)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < mode->num_rates; i++) {
|
||||
struct ieee80211_rate *rate = &mode->rates[i];
|
||||
|
||||
if (rate->flags & IEEE80211_RATE_SUPPORTED)
|
||||
return rate;
|
||||
}
|
||||
|
||||
printk(KERN_DEBUG "rate_control_lowest_rate - no supported rates "
|
||||
"found\n");
|
||||
return &mode->rates[0];
|
||||
}
|
||||
|
||||
|
||||
struct global_rate_control {
|
||||
int dummy;
|
||||
};
|
||||
|
||||
struct sta_rate_control {
|
||||
unsigned long last_rate_change;
|
||||
u32 tx_num_failures;
|
||||
u32 tx_num_xmit;
|
||||
|
||||
unsigned long avg_rate_update;
|
||||
u32 tx_avg_rate_sum;
|
||||
u32 tx_avg_rate_num;
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct dentry *tx_avg_rate_sum_dentry;
|
||||
struct dentry *tx_avg_rate_num_dentry;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
static void rate_control_simple_tx_status(void *priv, struct net_device *dev,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_tx_status *status)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
struct sta_info *sta;
|
||||
struct sta_rate_control *srctrl;
|
||||
|
||||
sta = sta_info_get(local, hdr->addr1);
|
||||
|
||||
if (!sta)
|
||||
return;
|
||||
|
||||
srctrl = sta->rate_ctrl_priv;
|
||||
srctrl->tx_num_xmit++;
|
||||
if (status->excessive_retries) {
|
||||
srctrl->tx_num_failures++;
|
||||
sta->tx_retry_failed++;
|
||||
sta->tx_num_consecutive_failures++;
|
||||
sta->tx_num_mpdu_fail++;
|
||||
} else {
|
||||
sta->last_ack_rssi[0] = sta->last_ack_rssi[1];
|
||||
sta->last_ack_rssi[1] = sta->last_ack_rssi[2];
|
||||
sta->last_ack_rssi[2] = status->ack_signal;
|
||||
sta->tx_num_consecutive_failures = 0;
|
||||
sta->tx_num_mpdu_ok++;
|
||||
}
|
||||
sta->tx_retry_count += status->retry_count;
|
||||
sta->tx_num_mpdu_fail += status->retry_count;
|
||||
|
||||
if (time_after(jiffies,
|
||||
srctrl->last_rate_change + RATE_CONTROL_INTERVAL) &&
|
||||
srctrl->tx_num_xmit > RATE_CONTROL_MIN_TX) {
|
||||
u32 per_failed;
|
||||
srctrl->last_rate_change = jiffies;
|
||||
|
||||
per_failed = (100 * sta->tx_num_mpdu_fail) /
|
||||
(sta->tx_num_mpdu_fail + sta->tx_num_mpdu_ok);
|
||||
/* TODO: calculate average per_failed to make adjusting
|
||||
* parameters easier */
|
||||
#if 0
|
||||
if (net_ratelimit()) {
|
||||
printk(KERN_DEBUG "MPDU fail=%d ok=%d per_failed=%d\n",
|
||||
sta->tx_num_mpdu_fail, sta->tx_num_mpdu_ok,
|
||||
per_failed);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXX: Make these configurable once we have an
|
||||
* interface to the rate control algorithms
|
||||
*/
|
||||
if (per_failed > RATE_CONTROL_NUM_DOWN) {
|
||||
rate_control_rate_dec(local, sta);
|
||||
} else if (per_failed < RATE_CONTROL_NUM_UP) {
|
||||
rate_control_rate_inc(local, sta);
|
||||
}
|
||||
srctrl->tx_avg_rate_sum += status->control.rate->rate;
|
||||
srctrl->tx_avg_rate_num++;
|
||||
srctrl->tx_num_failures = 0;
|
||||
srctrl->tx_num_xmit = 0;
|
||||
} else if (sta->tx_num_consecutive_failures >=
|
||||
RATE_CONTROL_EMERG_DEC) {
|
||||
rate_control_rate_dec(local, sta);
|
||||
}
|
||||
|
||||
if (srctrl->avg_rate_update + 60 * HZ < jiffies) {
|
||||
srctrl->avg_rate_update = jiffies;
|
||||
if (srctrl->tx_avg_rate_num > 0) {
|
||||
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: STA " MAC_FMT " Average rate: "
|
||||
"%d (%d/%d)\n",
|
||||
dev->name, MAC_ARG(sta->addr),
|
||||
srctrl->tx_avg_rate_sum /
|
||||
srctrl->tx_avg_rate_num,
|
||||
srctrl->tx_avg_rate_sum,
|
||||
srctrl->tx_avg_rate_num);
|
||||
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
|
||||
srctrl->tx_avg_rate_sum = 0;
|
||||
srctrl->tx_avg_rate_num = 0;
|
||||
}
|
||||
}
|
||||
|
||||
sta_info_put(sta);
|
||||
}
|
||||
|
||||
|
||||
static struct ieee80211_rate *
|
||||
rate_control_simple_get_rate(void *priv, struct net_device *dev,
|
||||
struct sk_buff *skb,
|
||||
struct rate_control_extra *extra)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
struct ieee80211_hw_mode *mode = extra->mode;
|
||||
struct sta_info *sta;
|
||||
int rateidx, nonerp_idx;
|
||||
u16 fc;
|
||||
|
||||
memset(extra, 0, sizeof(*extra));
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA ||
|
||||
(hdr->addr1[0] & 0x01)) {
|
||||
/* Send management frames and broadcast/multicast data using
|
||||
* lowest rate. */
|
||||
/* TODO: this could probably be improved.. */
|
||||
return rate_control_lowest_rate(local, mode);
|
||||
}
|
||||
|
||||
sta = sta_info_get(local, hdr->addr1);
|
||||
|
||||
if (!sta)
|
||||
return rate_control_lowest_rate(local, mode);
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
if (sdata->bss && sdata->bss->force_unicast_rateidx > -1)
|
||||
sta->txrate = sdata->bss->force_unicast_rateidx;
|
||||
|
||||
rateidx = sta->txrate;
|
||||
|
||||
if (rateidx >= mode->num_rates)
|
||||
rateidx = mode->num_rates - 1;
|
||||
|
||||
sta->last_txrate = rateidx;
|
||||
nonerp_idx = rateidx;
|
||||
while (nonerp_idx > 0 &&
|
||||
((mode->rates[nonerp_idx].flags & IEEE80211_RATE_ERP) ||
|
||||
!(mode->rates[nonerp_idx].flags & IEEE80211_RATE_SUPPORTED) ||
|
||||
!(sta->supp_rates & BIT(nonerp_idx))))
|
||||
nonerp_idx--;
|
||||
extra->nonerp = &mode->rates[nonerp_idx];
|
||||
|
||||
sta_info_put(sta);
|
||||
|
||||
return &mode->rates[rateidx];
|
||||
}
|
||||
|
||||
|
||||
static void rate_control_simple_rate_init(void *priv, void *priv_sta,
|
||||
struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
struct ieee80211_hw_mode *mode;
|
||||
int i;
|
||||
sta->txrate = 0;
|
||||
mode = local->oper_hw_mode;
|
||||
/* TODO: This routine should consider using RSSI from previous packets
|
||||
* as we need to have IEEE 802.1X auth succeed immediately after assoc..
|
||||
* Until that method is implemented, we will use the lowest supported rate
|
||||
* as a workaround, */
|
||||
for (i = 0; i < mode->num_rates; i++) {
|
||||
if ((sta->supp_rates & BIT(i)) &&
|
||||
(mode->rates[i].flags & IEEE80211_RATE_SUPPORTED)) {
|
||||
sta->txrate = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void * rate_control_simple_alloc(struct ieee80211_local *local)
|
||||
{
|
||||
struct global_rate_control *rctrl;
|
||||
|
||||
rctrl = kzalloc(sizeof(*rctrl), GFP_ATOMIC);
|
||||
|
||||
return rctrl;
|
||||
}
|
||||
|
||||
|
||||
static void rate_control_simple_free(void *priv)
|
||||
{
|
||||
struct global_rate_control *rctrl = priv;
|
||||
kfree(rctrl);
|
||||
}
|
||||
|
||||
|
||||
static void rate_control_simple_clear(void *priv)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void * rate_control_simple_alloc_sta(void *priv, gfp_t gfp)
|
||||
{
|
||||
struct sta_rate_control *rctrl;
|
||||
|
||||
rctrl = kzalloc(sizeof(*rctrl), gfp);
|
||||
|
||||
return rctrl;
|
||||
}
|
||||
|
||||
|
||||
static void rate_control_simple_free_sta(void *priv, void *priv_sta)
|
||||
{
|
||||
struct sta_rate_control *rctrl = priv_sta;
|
||||
kfree(rctrl);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
|
||||
static int open_file_generic(struct inode *inode, struct file *file)
|
||||
{
|
||||
file->private_data = inode->i_private;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static ssize_t sta_tx_avg_rate_sum_read(struct file *file,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct sta_rate_control *srctrl = file->private_data;
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%d\n", srctrl->tx_avg_rate_sum);
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
|
||||
}
|
||||
|
||||
static const struct file_operations sta_tx_avg_rate_sum_ops = {
|
||||
.read = sta_tx_avg_rate_sum_read,
|
||||
.open = open_file_generic,
|
||||
};
|
||||
|
||||
static ssize_t sta_tx_avg_rate_num_read(struct file *file,
|
||||
char __user *userbuf,
|
||||
size_t count, loff_t *ppos)
|
||||
{
|
||||
struct sta_rate_control *srctrl = file->private_data;
|
||||
char buf[20];
|
||||
|
||||
sprintf(buf, "%d\n", srctrl->tx_avg_rate_num);
|
||||
return simple_read_from_buffer(userbuf, count, ppos, buf, strlen(buf));
|
||||
}
|
||||
|
||||
static const struct file_operations sta_tx_avg_rate_num_ops = {
|
||||
.read = sta_tx_avg_rate_num_read,
|
||||
.open = open_file_generic,
|
||||
};
|
||||
|
||||
static void rate_control_simple_add_sta_debugfs(void *priv, void *priv_sta,
|
||||
struct dentry *dir)
|
||||
{
|
||||
struct sta_rate_control *srctrl = priv_sta;
|
||||
|
||||
srctrl->tx_avg_rate_num_dentry =
|
||||
debugfs_create_file("rc_simple_sta_tx_avg_rate_num", 0400,
|
||||
dir, srctrl, &sta_tx_avg_rate_num_ops);
|
||||
srctrl->tx_avg_rate_sum_dentry =
|
||||
debugfs_create_file("rc_simple_sta_tx_avg_rate_sum", 0400,
|
||||
dir, srctrl, &sta_tx_avg_rate_sum_ops);
|
||||
}
|
||||
|
||||
static void rate_control_simple_remove_sta_debugfs(void *priv, void *priv_sta)
|
||||
{
|
||||
struct sta_rate_control *srctrl = priv_sta;
|
||||
|
||||
debugfs_remove(srctrl->tx_avg_rate_sum_dentry);
|
||||
debugfs_remove(srctrl->tx_avg_rate_num_dentry);
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct rate_control_ops rate_control_simple = {
|
||||
.module = THIS_MODULE,
|
||||
.name = "simple",
|
||||
.tx_status = rate_control_simple_tx_status,
|
||||
.get_rate = rate_control_simple_get_rate,
|
||||
.rate_init = rate_control_simple_rate_init,
|
||||
.clear = rate_control_simple_clear,
|
||||
.alloc = rate_control_simple_alloc,
|
||||
.free = rate_control_simple_free,
|
||||
.alloc_sta = rate_control_simple_alloc_sta,
|
||||
.free_sta = rate_control_simple_free_sta,
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
.add_sta_debugfs = rate_control_simple_add_sta_debugfs,
|
||||
.remove_sta_debugfs = rate_control_simple_remove_sta_debugfs,
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
static int __init rate_control_simple_init(void)
|
||||
{
|
||||
return ieee80211_rate_control_register(&rate_control_simple);
|
||||
}
|
||||
|
||||
|
||||
static void __exit rate_control_simple_exit(void)
|
||||
{
|
||||
ieee80211_rate_control_unregister(&rate_control_simple);
|
||||
}
|
||||
|
||||
|
||||
subsys_initcall(rate_control_simple_init);
|
||||
module_exit(rate_control_simple_exit);
|
||||
|
||||
MODULE_DESCRIPTION("Simple rate control algorithm for ieee80211");
|
||||
MODULE_LICENSE("GPL");
|
||||
152
package/mac80211/src/net/mac80211/regdomain.c
Normal file
152
package/mac80211/src/net/mac80211/regdomain.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005-2006, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This regulatory domain control implementation is known to be incomplete
|
||||
* and confusing. mac80211 regulatory domain control will be significantly
|
||||
* reworked in the not-too-distant future.
|
||||
*
|
||||
* For now, drivers wishing to control which channels are and aren't available
|
||||
* are advised as follows:
|
||||
* - set the IEEE80211_HW_DEFAULT_REG_DOMAIN_CONFIGURED flag
|
||||
* - continue to include *ALL* possible channels in the modes registered
|
||||
* through ieee80211_register_hwmode()
|
||||
* - for each allowable ieee80211_channel structure registered in the above
|
||||
* call, set the flag member to some meaningful value such as
|
||||
* IEEE80211_CHAN_W_SCAN | IEEE80211_CHAN_W_ACTIVE_SCAN |
|
||||
* IEEE80211_CHAN_W_IBSS.
|
||||
* - leave flag as 0 for non-allowable channels
|
||||
*
|
||||
* The usual implementation is for a driver to read a device EEPROM to
|
||||
* determine which regulatory domain it should be operating under, then
|
||||
* looking up the allowable channels in a driver-local table, then performing
|
||||
* the above.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
|
||||
static int ieee80211_regdom = 0x10; /* FCC */
|
||||
module_param(ieee80211_regdom, int, 0444);
|
||||
MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
|
||||
|
||||
/*
|
||||
* If firmware is upgraded by the vendor, additional channels can be used based
|
||||
* on the new Japanese regulatory rules. This is indicated by setting
|
||||
* ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
|
||||
* module.
|
||||
*/
|
||||
static int ieee80211_japan_5ghz /* = 0 */;
|
||||
module_param(ieee80211_japan_5ghz, int, 0444);
|
||||
MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
|
||||
|
||||
|
||||
struct ieee80211_channel_range {
|
||||
short start_freq;
|
||||
short end_freq;
|
||||
unsigned char power_level;
|
||||
unsigned char antenna_max;
|
||||
};
|
||||
|
||||
static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
|
||||
{ 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
|
||||
{ 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
|
||||
{ 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
|
||||
{ 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
|
||||
{ 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
|
||||
{ 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
|
||||
{ 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
||||
static const struct ieee80211_channel_range *channel_range =
|
||||
ieee80211_fcc_channels;
|
||||
|
||||
|
||||
static void ieee80211_unmask_channel(int mode, struct ieee80211_channel *chan)
|
||||
{
|
||||
int i;
|
||||
|
||||
chan->flag = 0;
|
||||
|
||||
for (i = 0; channel_range[i].start_freq; i++) {
|
||||
const struct ieee80211_channel_range *r = &channel_range[i];
|
||||
if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
|
||||
if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
|
||||
chan->freq >= 5260 && chan->freq <= 5320) {
|
||||
/*
|
||||
* Skip new channels in Japan since the
|
||||
* firmware was not marked having been upgraded
|
||||
* by the vendor.
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ieee80211_regdom == 0x10 &&
|
||||
(chan->freq == 5190 || chan->freq == 5210 ||
|
||||
chan->freq == 5230)) {
|
||||
/* Skip MKK channels when in FCC domain. */
|
||||
continue;
|
||||
}
|
||||
|
||||
chan->flag |= IEEE80211_CHAN_W_SCAN |
|
||||
IEEE80211_CHAN_W_ACTIVE_SCAN |
|
||||
IEEE80211_CHAN_W_IBSS;
|
||||
chan->power_level = r->power_level;
|
||||
chan->antenna_max = r->antenna_max;
|
||||
|
||||
if (ieee80211_regdom == 64 &&
|
||||
(chan->freq == 5170 || chan->freq == 5190 ||
|
||||
chan->freq == 5210 || chan->freq == 5230)) {
|
||||
/*
|
||||
* New regulatory rules in Japan have backwards
|
||||
* compatibility with old channels in 5.15-5.25
|
||||
* GHz band, but the station is not allowed to
|
||||
* use active scan on these old channels.
|
||||
*/
|
||||
chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
|
||||
}
|
||||
|
||||
if (ieee80211_regdom == 64 &&
|
||||
(chan->freq == 5260 || chan->freq == 5280 ||
|
||||
chan->freq == 5300 || chan->freq == 5320)) {
|
||||
/*
|
||||
* IBSS is not allowed on 5.25-5.35 GHz band
|
||||
* due to radar detection requirements.
|
||||
*/
|
||||
chan->flag &= ~IEEE80211_CHAN_W_IBSS;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_set_default_regdomain(struct ieee80211_hw_mode *mode)
|
||||
{
|
||||
int c;
|
||||
for (c = 0; c < mode->num_channels; c++)
|
||||
ieee80211_unmask_channel(mode->mode, &mode->channels[c]);
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_regdomain_init(void)
|
||||
{
|
||||
if (ieee80211_regdom == 0x40)
|
||||
channel_range = ieee80211_mkk_channels;
|
||||
}
|
||||
|
||||
1579
package/mac80211/src/net/mac80211/rx.c
Normal file
1579
package/mac80211/src/net/mac80211/rx.c
Normal file
File diff suppressed because it is too large
Load Diff
406
package/mac80211/src/net/mac80211/sta_info.c
Normal file
406
package/mac80211/src/net/mac80211/sta_info.c
Normal file
@@ -0,0 +1,406 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/if_arp.h>
|
||||
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
#include "sta_info.h"
|
||||
#include "debugfs_sta.h"
|
||||
|
||||
/* Caller must hold local->sta_lock */
|
||||
static void sta_info_hash_add(struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
sta->hnext = local->sta_hash[STA_HASH(sta->addr)];
|
||||
local->sta_hash[STA_HASH(sta->addr)] = sta;
|
||||
}
|
||||
|
||||
|
||||
/* Caller must hold local->sta_lock */
|
||||
static int sta_info_hash_del(struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
struct sta_info *s;
|
||||
|
||||
s = local->sta_hash[STA_HASH(sta->addr)];
|
||||
if (!s)
|
||||
return -ENOENT;
|
||||
if (s == sta) {
|
||||
local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (s->hnext && s->hnext != sta)
|
||||
s = s->hnext;
|
||||
if (s->hnext) {
|
||||
s->hnext = sta->hnext;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
struct sta_info *sta_info_get(struct ieee80211_local *local, u8 *addr)
|
||||
{
|
||||
struct sta_info *sta;
|
||||
|
||||
read_lock_bh(&local->sta_lock);
|
||||
sta = local->sta_hash[STA_HASH(addr)];
|
||||
while (sta) {
|
||||
if (memcmp(sta->addr, addr, ETH_ALEN) == 0) {
|
||||
__sta_info_get(sta);
|
||||
break;
|
||||
}
|
||||
sta = sta->hnext;
|
||||
}
|
||||
read_unlock_bh(&local->sta_lock);
|
||||
|
||||
return sta;
|
||||
}
|
||||
EXPORT_SYMBOL(sta_info_get);
|
||||
|
||||
int sta_info_min_txrate_get(struct ieee80211_local *local)
|
||||
{
|
||||
struct sta_info *sta;
|
||||
struct ieee80211_hw_mode *mode;
|
||||
int min_txrate = 9999999;
|
||||
int i;
|
||||
|
||||
read_lock_bh(&local->sta_lock);
|
||||
mode = local->oper_hw_mode;
|
||||
for (i = 0; i < STA_HASH_SIZE; i++) {
|
||||
sta = local->sta_hash[i];
|
||||
while (sta) {
|
||||
if (sta->txrate < min_txrate)
|
||||
min_txrate = sta->txrate;
|
||||
sta = sta->hnext;
|
||||
}
|
||||
}
|
||||
read_unlock_bh(&local->sta_lock);
|
||||
if (min_txrate == 9999999)
|
||||
min_txrate = 0;
|
||||
|
||||
return mode->rates[min_txrate].rate;
|
||||
}
|
||||
|
||||
|
||||
static void sta_info_release(struct kref *kref)
|
||||
{
|
||||
struct sta_info *sta = container_of(kref, struct sta_info, kref);
|
||||
struct ieee80211_local *local = sta->local;
|
||||
struct sk_buff *skb;
|
||||
|
||||
/* free sta structure; it has already been removed from
|
||||
* hash table etc. external structures. Make sure that all
|
||||
* buffered frames are release (one might have been added
|
||||
* after sta_info_free() was called). */
|
||||
while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
|
||||
local->total_ps_buffered--;
|
||||
dev_kfree_skb_any(skb);
|
||||
}
|
||||
while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
|
||||
dev_kfree_skb_any(skb);
|
||||
}
|
||||
rate_control_free_sta(sta->rate_ctrl, sta->rate_ctrl_priv);
|
||||
rate_control_put(sta->rate_ctrl);
|
||||
kfree(sta);
|
||||
}
|
||||
|
||||
|
||||
void sta_info_put(struct sta_info *sta)
|
||||
{
|
||||
kref_put(&sta->kref, sta_info_release);
|
||||
}
|
||||
EXPORT_SYMBOL(sta_info_put);
|
||||
|
||||
|
||||
struct sta_info * sta_info_add(struct ieee80211_local *local,
|
||||
struct net_device *dev, u8 *addr, gfp_t gfp)
|
||||
{
|
||||
struct sta_info *sta;
|
||||
|
||||
sta = kzalloc(sizeof(*sta), gfp);
|
||||
if (!sta)
|
||||
return NULL;
|
||||
|
||||
kref_init(&sta->kref);
|
||||
|
||||
sta->rate_ctrl = rate_control_get(local->rate_ctrl);
|
||||
sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl, gfp);
|
||||
if (!sta->rate_ctrl_priv) {
|
||||
rate_control_put(sta->rate_ctrl);
|
||||
kfree(sta);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memcpy(sta->addr, addr, ETH_ALEN);
|
||||
sta->local = local;
|
||||
sta->dev = dev;
|
||||
skb_queue_head_init(&sta->ps_tx_buf);
|
||||
skb_queue_head_init(&sta->tx_filtered);
|
||||
__sta_info_get(sta); /* sta used by caller, decremented by
|
||||
* sta_info_put() */
|
||||
write_lock_bh(&local->sta_lock);
|
||||
list_add(&sta->list, &local->sta_list);
|
||||
local->num_sta++;
|
||||
sta_info_hash_add(local, sta);
|
||||
if (local->ops->sta_notify)
|
||||
local->ops->sta_notify(local_to_hw(local), dev->ifindex,
|
||||
STA_NOTIFY_ADD, addr);
|
||||
write_unlock_bh(&local->sta_lock);
|
||||
|
||||
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: Added STA " MAC_FMT "\n",
|
||||
wiphy_name(local->hw.wiphy), MAC_ARG(addr));
|
||||
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
/* debugfs entry adding might sleep, so schedule process
|
||||
* context task for adding entry for STAs that do not yet
|
||||
* have one. */
|
||||
queue_work(local->hw.workqueue, &local->sta_debugfs_add);
|
||||
#endif
|
||||
|
||||
return sta;
|
||||
}
|
||||
|
||||
/* Caller must hold local->sta_lock */
|
||||
void sta_info_remove(struct sta_info *sta)
|
||||
{
|
||||
struct ieee80211_local *local = sta->local;
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
|
||||
/* don't do anything if we've been removed already */
|
||||
if (sta_info_hash_del(local, sta))
|
||||
return;
|
||||
|
||||
list_del(&sta->list);
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
|
||||
if (sta->flags & WLAN_STA_PS) {
|
||||
sta->flags &= ~WLAN_STA_PS;
|
||||
if (sdata->bss)
|
||||
atomic_dec(&sdata->bss->num_sta_ps);
|
||||
}
|
||||
local->num_sta--;
|
||||
sta_info_remove_aid_ptr(sta);
|
||||
|
||||
}
|
||||
|
||||
void sta_info_free(struct sta_info *sta)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
struct ieee80211_local *local = sta->local;
|
||||
|
||||
might_sleep();
|
||||
|
||||
write_lock_bh(&local->sta_lock);
|
||||
sta_info_remove(sta);
|
||||
write_unlock_bh(&local->sta_lock);
|
||||
|
||||
while ((skb = skb_dequeue(&sta->ps_tx_buf)) != NULL) {
|
||||
local->total_ps_buffered--;
|
||||
dev_kfree_skb(skb);
|
||||
}
|
||||
while ((skb = skb_dequeue(&sta->tx_filtered)) != NULL) {
|
||||
dev_kfree_skb(skb);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: Removed STA " MAC_FMT "\n",
|
||||
wiphy_name(local->hw.wiphy), MAC_ARG(sta->addr));
|
||||
#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
|
||||
|
||||
ieee80211_key_free(sta->key);
|
||||
sta->key = NULL;
|
||||
|
||||
if (local->ops->sta_notify)
|
||||
local->ops->sta_notify(local_to_hw(local), sta->dev->ifindex,
|
||||
STA_NOTIFY_REMOVE, sta->addr);
|
||||
|
||||
rate_control_remove_sta_debugfs(sta);
|
||||
ieee80211_sta_debugfs_remove(sta);
|
||||
|
||||
sta_info_put(sta);
|
||||
}
|
||||
|
||||
|
||||
static inline int sta_info_buffer_expired(struct ieee80211_local *local,
|
||||
struct sta_info *sta,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
struct ieee80211_tx_packet_data *pkt_data;
|
||||
int timeout;
|
||||
|
||||
if (!skb)
|
||||
return 0;
|
||||
|
||||
pkt_data = (struct ieee80211_tx_packet_data *) skb->cb;
|
||||
|
||||
/* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
|
||||
timeout = (sta->listen_interval * local->hw.conf.beacon_int * 32 /
|
||||
15625) * HZ;
|
||||
if (timeout < STA_TX_BUFFER_EXPIRE)
|
||||
timeout = STA_TX_BUFFER_EXPIRE;
|
||||
return time_after(jiffies, pkt_data->jiffies + timeout);
|
||||
}
|
||||
|
||||
|
||||
static void sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
unsigned long flags;
|
||||
struct sk_buff *skb;
|
||||
|
||||
if (skb_queue_empty(&sta->ps_tx_buf))
|
||||
return;
|
||||
|
||||
for (;;) {
|
||||
spin_lock_irqsave(&sta->ps_tx_buf.lock, flags);
|
||||
skb = skb_peek(&sta->ps_tx_buf);
|
||||
if (sta_info_buffer_expired(local, sta, skb)) {
|
||||
skb = __skb_dequeue(&sta->ps_tx_buf);
|
||||
if (skb_queue_empty(&sta->ps_tx_buf))
|
||||
sta->flags &= ~WLAN_STA_TIM;
|
||||
} else
|
||||
skb = NULL;
|
||||
spin_unlock_irqrestore(&sta->ps_tx_buf.lock, flags);
|
||||
|
||||
if (skb) {
|
||||
local->total_ps_buffered--;
|
||||
printk(KERN_DEBUG "Buffered frame expired (STA "
|
||||
MAC_FMT ")\n", MAC_ARG(sta->addr));
|
||||
dev_kfree_skb(skb);
|
||||
} else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void sta_info_cleanup(unsigned long data)
|
||||
{
|
||||
struct ieee80211_local *local = (struct ieee80211_local *) data;
|
||||
struct sta_info *sta;
|
||||
|
||||
read_lock_bh(&local->sta_lock);
|
||||
list_for_each_entry(sta, &local->sta_list, list) {
|
||||
__sta_info_get(sta);
|
||||
sta_info_cleanup_expire_buffered(local, sta);
|
||||
sta_info_put(sta);
|
||||
}
|
||||
read_unlock_bh(&local->sta_lock);
|
||||
|
||||
local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
|
||||
add_timer(&local->sta_cleanup);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
static void sta_info_debugfs_add_task(struct work_struct *work)
|
||||
{
|
||||
struct ieee80211_local *local =
|
||||
container_of(work, struct ieee80211_local, sta_debugfs_add);
|
||||
struct sta_info *sta, *tmp;
|
||||
|
||||
while (1) {
|
||||
sta = NULL;
|
||||
read_lock_bh(&local->sta_lock);
|
||||
list_for_each_entry(tmp, &local->sta_list, list) {
|
||||
if (!tmp->debugfs.dir) {
|
||||
sta = tmp;
|
||||
__sta_info_get(sta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
read_unlock_bh(&local->sta_lock);
|
||||
|
||||
if (!sta)
|
||||
break;
|
||||
|
||||
ieee80211_sta_debugfs_add(sta);
|
||||
rate_control_add_sta_debugfs(sta);
|
||||
sta_info_put(sta);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void sta_info_init(struct ieee80211_local *local)
|
||||
{
|
||||
rwlock_init(&local->sta_lock);
|
||||
INIT_LIST_HEAD(&local->sta_list);
|
||||
|
||||
init_timer(&local->sta_cleanup);
|
||||
local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
|
||||
local->sta_cleanup.data = (unsigned long) local;
|
||||
local->sta_cleanup.function = sta_info_cleanup;
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
INIT_WORK(&local->sta_debugfs_add, sta_info_debugfs_add_task);
|
||||
#endif
|
||||
}
|
||||
|
||||
int sta_info_start(struct ieee80211_local *local)
|
||||
{
|
||||
add_timer(&local->sta_cleanup);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sta_info_stop(struct ieee80211_local *local)
|
||||
{
|
||||
del_timer(&local->sta_cleanup);
|
||||
sta_info_flush(local, NULL);
|
||||
}
|
||||
|
||||
void sta_info_remove_aid_ptr(struct sta_info *sta)
|
||||
{
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
|
||||
if (sta->aid <= 0)
|
||||
return;
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
|
||||
|
||||
if (sdata->local->ops->set_tim)
|
||||
sdata->local->ops->set_tim(local_to_hw(sdata->local),
|
||||
sta->aid, 0);
|
||||
if (sdata->bss)
|
||||
__bss_tim_clear(sdata->bss, sta->aid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* sta_info_flush - flush matching STA entries from the STA table
|
||||
* @local: local interface data
|
||||
* @dev: matching rule for the net device (sta->dev) or %NULL to match all STAs
|
||||
*/
|
||||
void sta_info_flush(struct ieee80211_local *local, struct net_device *dev)
|
||||
{
|
||||
struct sta_info *sta, *tmp;
|
||||
LIST_HEAD(tmp_list);
|
||||
|
||||
write_lock_bh(&local->sta_lock);
|
||||
list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
|
||||
if (!dev || dev == sta->dev) {
|
||||
__sta_info_get(sta);
|
||||
sta_info_remove(sta);
|
||||
list_add_tail(&sta->list, &tmp_list);
|
||||
}
|
||||
write_unlock_bh(&local->sta_lock);
|
||||
|
||||
list_for_each_entry_safe(sta, tmp, &tmp_list, list) {
|
||||
sta_info_free(sta);
|
||||
sta_info_put(sta);
|
||||
}
|
||||
}
|
||||
156
package/mac80211/src/net/mac80211/sta_info.h
Normal file
156
package/mac80211/src/net/mac80211/sta_info.h
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef STA_INFO_H
|
||||
#define STA_INFO_H
|
||||
|
||||
#include <linux/list.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/kref.h>
|
||||
#include "ieee80211_key.h"
|
||||
|
||||
/* Stations flags (struct sta_info::flags) */
|
||||
#define WLAN_STA_AUTH BIT(0)
|
||||
#define WLAN_STA_ASSOC BIT(1)
|
||||
#define WLAN_STA_PS BIT(2)
|
||||
#define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */
|
||||
#define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */
|
||||
#define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is
|
||||
* controlling whether STA is authorized to
|
||||
* send and receive non-IEEE 802.1X frames
|
||||
*/
|
||||
#define WLAN_STA_SHORT_PREAMBLE BIT(7)
|
||||
/* whether this is an AP that we are associated with as a client */
|
||||
#define WLAN_STA_ASSOC_AP BIT(8)
|
||||
#define WLAN_STA_WME BIT(9)
|
||||
#define WLAN_STA_WDS BIT(27)
|
||||
|
||||
|
||||
struct sta_info {
|
||||
struct kref kref;
|
||||
struct list_head list;
|
||||
struct sta_info *hnext; /* next entry in hash table list */
|
||||
|
||||
struct ieee80211_local *local;
|
||||
|
||||
u8 addr[ETH_ALEN];
|
||||
u16 aid; /* STA's unique AID (1..2007), 0 = not yet assigned */
|
||||
u32 flags; /* WLAN_STA_ */
|
||||
|
||||
struct sk_buff_head ps_tx_buf; /* buffer of TX frames for station in
|
||||
* power saving state */
|
||||
int pspoll; /* whether STA has send a PS Poll frame */
|
||||
struct sk_buff_head tx_filtered; /* buffer of TX frames that were
|
||||
* already given to low-level driver,
|
||||
* but were filtered */
|
||||
int clear_dst_mask;
|
||||
|
||||
unsigned long rx_packets, tx_packets; /* number of RX/TX MSDUs */
|
||||
unsigned long rx_bytes, tx_bytes;
|
||||
unsigned long tx_retry_failed, tx_retry_count;
|
||||
unsigned long tx_filtered_count;
|
||||
|
||||
unsigned int wep_weak_iv_count; /* number of RX frames with weak IV */
|
||||
|
||||
unsigned long last_rx;
|
||||
u32 supp_rates; /* bitmap of supported rates in local->curr_rates */
|
||||
int txrate; /* index in local->curr_rates */
|
||||
int last_txrate; /* last rate used to send a frame to this STA */
|
||||
int last_nonerp_idx;
|
||||
|
||||
struct net_device *dev; /* which net device is this station associated
|
||||
* to */
|
||||
|
||||
struct ieee80211_key *key;
|
||||
|
||||
u32 tx_num_consecutive_failures;
|
||||
u32 tx_num_mpdu_ok;
|
||||
u32 tx_num_mpdu_fail;
|
||||
|
||||
struct rate_control_ref *rate_ctrl;
|
||||
void *rate_ctrl_priv;
|
||||
|
||||
/* last received seq/frag number from this STA (per RX queue) */
|
||||
__le16 last_seq_ctrl[NUM_RX_DATA_QUEUES];
|
||||
unsigned long num_duplicates; /* number of duplicate frames received
|
||||
* from this STA */
|
||||
unsigned long tx_fragments; /* number of transmitted MPDUs */
|
||||
unsigned long rx_fragments; /* number of received MPDUs */
|
||||
unsigned long rx_dropped; /* number of dropped MPDUs from this STA */
|
||||
|
||||
int last_rssi; /* RSSI of last received frame from this STA */
|
||||
int last_signal; /* signal of last received frame from this STA */
|
||||
int last_noise; /* noise of last received frame from this STA */
|
||||
int last_ack_rssi[3]; /* RSSI of last received ACKs from this STA */
|
||||
unsigned long last_ack;
|
||||
int channel_use;
|
||||
int channel_use_raw;
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
|
||||
unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
|
||||
#endif /* CONFIG_MAC80211_DEBUG_COUNTERS */
|
||||
|
||||
u16 listen_interval;
|
||||
|
||||
#ifdef CONFIG_MAC80211_DEBUGFS
|
||||
struct sta_info_debugfsdentries {
|
||||
struct dentry *dir;
|
||||
struct dentry *flags;
|
||||
struct dentry *num_ps_buf_frames;
|
||||
struct dentry *last_ack_rssi;
|
||||
struct dentry *last_ack_ms;
|
||||
struct dentry *inactive_ms;
|
||||
struct dentry *last_seq_ctrl;
|
||||
#ifdef CONFIG_MAC80211_DEBUG_COUNTERS
|
||||
struct dentry *wme_rx_queue;
|
||||
struct dentry *wme_tx_queue;
|
||||
#endif
|
||||
} debugfs;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/* Maximum number of concurrently registered stations */
|
||||
#define MAX_STA_COUNT 2007
|
||||
|
||||
#define STA_HASH_SIZE 256
|
||||
#define STA_HASH(sta) (sta[5])
|
||||
|
||||
|
||||
/* Maximum number of frames to buffer per power saving station */
|
||||
#define STA_MAX_TX_BUFFER 128
|
||||
|
||||
/* Minimum buffered frame expiry time. If STA uses listen interval that is
|
||||
* smaller than this value, the minimum value here is used instead. */
|
||||
#define STA_TX_BUFFER_EXPIRE (10 * HZ)
|
||||
|
||||
/* How often station data is cleaned up (e.g., expiration of buffered frames)
|
||||
*/
|
||||
#define STA_INFO_CLEANUP_INTERVAL (10 * HZ)
|
||||
|
||||
static inline void __sta_info_get(struct sta_info *sta)
|
||||
{
|
||||
kref_get(&sta->kref);
|
||||
}
|
||||
|
||||
struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr);
|
||||
int sta_info_min_txrate_get(struct ieee80211_local *local);
|
||||
void sta_info_put(struct sta_info *sta);
|
||||
struct sta_info * sta_info_add(struct ieee80211_local *local,
|
||||
struct net_device *dev, u8 *addr, gfp_t gfp);
|
||||
void sta_info_remove(struct sta_info *sta);
|
||||
void sta_info_free(struct sta_info *sta);
|
||||
void sta_info_init(struct ieee80211_local *local);
|
||||
int sta_info_start(struct ieee80211_local *local);
|
||||
void sta_info_stop(struct ieee80211_local *local);
|
||||
void sta_info_remove_aid_ptr(struct sta_info *sta);
|
||||
void sta_info_flush(struct ieee80211_local *local, struct net_device *dev);
|
||||
|
||||
#endif /* STA_INFO_H */
|
||||
347
package/mac80211/src/net/mac80211/tkip.c
Normal file
347
package/mac80211/src/net/mac80211/tkip.c
Normal file
@@ -0,0 +1,347 @@
|
||||
/*
|
||||
* Copyright 2002-2004, Instant802 Networks, Inc.
|
||||
* Copyright 2005, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/netdevice.h>
|
||||
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_key.h"
|
||||
#include "tkip.h"
|
||||
#include "wep.h"
|
||||
|
||||
|
||||
/* TKIP key mixing functions */
|
||||
|
||||
|
||||
#define PHASE1_LOOP_COUNT 8
|
||||
|
||||
|
||||
/* 2-byte by 2-byte subset of the full AES S-box table; second part of this
|
||||
* table is identical to first part but byte-swapped */
|
||||
static const u16 tkip_sbox[256] =
|
||||
{
|
||||
0xC6A5, 0xF884, 0xEE99, 0xF68D, 0xFF0D, 0xD6BD, 0xDEB1, 0x9154,
|
||||
0x6050, 0x0203, 0xCEA9, 0x567D, 0xE719, 0xB562, 0x4DE6, 0xEC9A,
|
||||
0x8F45, 0x1F9D, 0x8940, 0xFA87, 0xEF15, 0xB2EB, 0x8EC9, 0xFB0B,
|
||||
0x41EC, 0xB367, 0x5FFD, 0x45EA, 0x23BF, 0x53F7, 0xE496, 0x9B5B,
|
||||
0x75C2, 0xE11C, 0x3DAE, 0x4C6A, 0x6C5A, 0x7E41, 0xF502, 0x834F,
|
||||
0x685C, 0x51F4, 0xD134, 0xF908, 0xE293, 0xAB73, 0x6253, 0x2A3F,
|
||||
0x080C, 0x9552, 0x4665, 0x9D5E, 0x3028, 0x37A1, 0x0A0F, 0x2FB5,
|
||||
0x0E09, 0x2436, 0x1B9B, 0xDF3D, 0xCD26, 0x4E69, 0x7FCD, 0xEA9F,
|
||||
0x121B, 0x1D9E, 0x5874, 0x342E, 0x362D, 0xDCB2, 0xB4EE, 0x5BFB,
|
||||
0xA4F6, 0x764D, 0xB761, 0x7DCE, 0x527B, 0xDD3E, 0x5E71, 0x1397,
|
||||
0xA6F5, 0xB968, 0x0000, 0xC12C, 0x4060, 0xE31F, 0x79C8, 0xB6ED,
|
||||
0xD4BE, 0x8D46, 0x67D9, 0x724B, 0x94DE, 0x98D4, 0xB0E8, 0x854A,
|
||||
0xBB6B, 0xC52A, 0x4FE5, 0xED16, 0x86C5, 0x9AD7, 0x6655, 0x1194,
|
||||
0x8ACF, 0xE910, 0x0406, 0xFE81, 0xA0F0, 0x7844, 0x25BA, 0x4BE3,
|
||||
0xA2F3, 0x5DFE, 0x80C0, 0x058A, 0x3FAD, 0x21BC, 0x7048, 0xF104,
|
||||
0x63DF, 0x77C1, 0xAF75, 0x4263, 0x2030, 0xE51A, 0xFD0E, 0xBF6D,
|
||||
0x814C, 0x1814, 0x2635, 0xC32F, 0xBEE1, 0x35A2, 0x88CC, 0x2E39,
|
||||
0x9357, 0x55F2, 0xFC82, 0x7A47, 0xC8AC, 0xBAE7, 0x322B, 0xE695,
|
||||
0xC0A0, 0x1998, 0x9ED1, 0xA37F, 0x4466, 0x547E, 0x3BAB, 0x0B83,
|
||||
0x8CCA, 0xC729, 0x6BD3, 0x283C, 0xA779, 0xBCE2, 0x161D, 0xAD76,
|
||||
0xDB3B, 0x6456, 0x744E, 0x141E, 0x92DB, 0x0C0A, 0x486C, 0xB8E4,
|
||||
0x9F5D, 0xBD6E, 0x43EF, 0xC4A6, 0x39A8, 0x31A4, 0xD337, 0xF28B,
|
||||
0xD532, 0x8B43, 0x6E59, 0xDAB7, 0x018C, 0xB164, 0x9CD2, 0x49E0,
|
||||
0xD8B4, 0xACFA, 0xF307, 0xCF25, 0xCAAF, 0xF48E, 0x47E9, 0x1018,
|
||||
0x6FD5, 0xF088, 0x4A6F, 0x5C72, 0x3824, 0x57F1, 0x73C7, 0x9751,
|
||||
0xCB23, 0xA17C, 0xE89C, 0x3E21, 0x96DD, 0x61DC, 0x0D86, 0x0F85,
|
||||
0xE090, 0x7C42, 0x71C4, 0xCCAA, 0x90D8, 0x0605, 0xF701, 0x1C12,
|
||||
0xC2A3, 0x6A5F, 0xAEF9, 0x69D0, 0x1791, 0x9958, 0x3A27, 0x27B9,
|
||||
0xD938, 0xEB13, 0x2BB3, 0x2233, 0xD2BB, 0xA970, 0x0789, 0x33A7,
|
||||
0x2DB6, 0x3C22, 0x1592, 0xC920, 0x8749, 0xAAFF, 0x5078, 0xA57A,
|
||||
0x038F, 0x59F8, 0x0980, 0x1A17, 0x65DA, 0xD731, 0x84C6, 0xD0B8,
|
||||
0x82C3, 0x29B0, 0x5A77, 0x1E11, 0x7BCB, 0xA8FC, 0x6DD6, 0x2C3A,
|
||||
};
|
||||
|
||||
|
||||
static inline u16 Mk16(u8 x, u8 y)
|
||||
{
|
||||
return ((u16) x << 8) | (u16) y;
|
||||
}
|
||||
|
||||
|
||||
static inline u8 Hi8(u16 v)
|
||||
{
|
||||
return v >> 8;
|
||||
}
|
||||
|
||||
|
||||
static inline u8 Lo8(u16 v)
|
||||
{
|
||||
return v & 0xff;
|
||||
}
|
||||
|
||||
|
||||
static inline u16 Hi16(u32 v)
|
||||
{
|
||||
return v >> 16;
|
||||
}
|
||||
|
||||
|
||||
static inline u16 Lo16(u32 v)
|
||||
{
|
||||
return v & 0xffff;
|
||||
}
|
||||
|
||||
|
||||
static inline u16 RotR1(u16 v)
|
||||
{
|
||||
return (v >> 1) | ((v & 0x0001) << 15);
|
||||
}
|
||||
|
||||
|
||||
static inline u16 tkip_S(u16 val)
|
||||
{
|
||||
u16 a = tkip_sbox[Hi8(val)];
|
||||
|
||||
return tkip_sbox[Lo8(val)] ^ Hi8(a) ^ (Lo8(a) << 8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* P1K := Phase1(TA, TK, TSC)
|
||||
* TA = transmitter address (48 bits)
|
||||
* TK = dot11DefaultKeyValue or dot11KeyMappingValue (128 bits)
|
||||
* TSC = TKIP sequence counter (48 bits, only 32 msb bits used)
|
||||
* P1K: 80 bits
|
||||
*/
|
||||
static void tkip_mixing_phase1(const u8 *ta, const u8 *tk, u32 tsc_IV32,
|
||||
u16 *p1k)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
p1k[0] = Lo16(tsc_IV32);
|
||||
p1k[1] = Hi16(tsc_IV32);
|
||||
p1k[2] = Mk16(ta[1], ta[0]);
|
||||
p1k[3] = Mk16(ta[3], ta[2]);
|
||||
p1k[4] = Mk16(ta[5], ta[4]);
|
||||
|
||||
for (i = 0; i < PHASE1_LOOP_COUNT; i++) {
|
||||
j = 2 * (i & 1);
|
||||
p1k[0] += tkip_S(p1k[4] ^ Mk16(tk[ 1 + j], tk[ 0 + j]));
|
||||
p1k[1] += tkip_S(p1k[0] ^ Mk16(tk[ 5 + j], tk[ 4 + j]));
|
||||
p1k[2] += tkip_S(p1k[1] ^ Mk16(tk[ 9 + j], tk[ 8 + j]));
|
||||
p1k[3] += tkip_S(p1k[2] ^ Mk16(tk[13 + j], tk[12 + j]));
|
||||
p1k[4] += tkip_S(p1k[3] ^ Mk16(tk[ 1 + j], tk[ 0 + j])) + i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void tkip_mixing_phase2(const u16 *p1k, const u8 *tk, u16 tsc_IV16,
|
||||
u8 *rc4key)
|
||||
{
|
||||
u16 ppk[6];
|
||||
int i;
|
||||
|
||||
ppk[0] = p1k[0];
|
||||
ppk[1] = p1k[1];
|
||||
ppk[2] = p1k[2];
|
||||
ppk[3] = p1k[3];
|
||||
ppk[4] = p1k[4];
|
||||
ppk[5] = p1k[4] + tsc_IV16;
|
||||
|
||||
ppk[0] += tkip_S(ppk[5] ^ Mk16(tk[ 1], tk[ 0]));
|
||||
ppk[1] += tkip_S(ppk[0] ^ Mk16(tk[ 3], tk[ 2]));
|
||||
ppk[2] += tkip_S(ppk[1] ^ Mk16(tk[ 5], tk[ 4]));
|
||||
ppk[3] += tkip_S(ppk[2] ^ Mk16(tk[ 7], tk[ 6]));
|
||||
ppk[4] += tkip_S(ppk[3] ^ Mk16(tk[ 9], tk[ 8]));
|
||||
ppk[5] += tkip_S(ppk[4] ^ Mk16(tk[11], tk[10]));
|
||||
ppk[0] += RotR1(ppk[5] ^ Mk16(tk[13], tk[12]));
|
||||
ppk[1] += RotR1(ppk[0] ^ Mk16(tk[15], tk[14]));
|
||||
ppk[2] += RotR1(ppk[1]);
|
||||
ppk[3] += RotR1(ppk[2]);
|
||||
ppk[4] += RotR1(ppk[3]);
|
||||
ppk[5] += RotR1(ppk[4]);
|
||||
|
||||
rc4key[0] = Hi8(tsc_IV16);
|
||||
rc4key[1] = (Hi8(tsc_IV16) | 0x20) & 0x7f;
|
||||
rc4key[2] = Lo8(tsc_IV16);
|
||||
rc4key[3] = Lo8((ppk[5] ^ Mk16(tk[1], tk[0])) >> 1);
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
rc4key[4 + 2 * i] = Lo8(ppk[i]);
|
||||
rc4key[5 + 2 * i] = Hi8(ppk[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Add TKIP IV and Ext. IV at @pos. @iv0, @iv1, and @iv2 are the first octets
|
||||
* of the IV. Returns pointer to the octet following IVs (i.e., beginning of
|
||||
* the packet payload). */
|
||||
u8 * ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
|
||||
u8 iv0, u8 iv1, u8 iv2)
|
||||
{
|
||||
*pos++ = iv0;
|
||||
*pos++ = iv1;
|
||||
*pos++ = iv2;
|
||||
*pos++ = (key->conf.keyidx << 6) | (1 << 5) /* Ext IV */;
|
||||
*pos++ = key->u.tkip.iv32 & 0xff;
|
||||
*pos++ = (key->u.tkip.iv32 >> 8) & 0xff;
|
||||
*pos++ = (key->u.tkip.iv32 >> 16) & 0xff;
|
||||
*pos++ = (key->u.tkip.iv32 >> 24) & 0xff;
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_tkip_gen_phase1key(struct ieee80211_key *key, u8 *ta,
|
||||
u16 *phase1key)
|
||||
{
|
||||
tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
|
||||
key->u.tkip.iv32, phase1key);
|
||||
}
|
||||
|
||||
void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta,
|
||||
u8 *rc4key)
|
||||
{
|
||||
/* Calculate per-packet key */
|
||||
if (key->u.tkip.iv16 == 0 || !key->u.tkip.tx_initialized) {
|
||||
/* IV16 wrapped around - perform TKIP phase 1 */
|
||||
tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
|
||||
key->u.tkip.iv32, key->u.tkip.p1k);
|
||||
key->u.tkip.tx_initialized = 1;
|
||||
}
|
||||
|
||||
tkip_mixing_phase2(key->u.tkip.p1k,
|
||||
&key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
|
||||
key->u.tkip.iv16, rc4key);
|
||||
}
|
||||
|
||||
/* Encrypt packet payload with TKIP using @key. @pos is a pointer to the
|
||||
* beginning of the buffer containing payload. This payload must include
|
||||
* headroom of eight octets for IV and Ext. IV and taildroom of four octets
|
||||
* for ICV. @payload_len is the length of payload (_not_ including extra
|
||||
* headroom and tailroom). @ta is the transmitter addresses. */
|
||||
void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
|
||||
struct ieee80211_key *key,
|
||||
u8 *pos, size_t payload_len, u8 *ta)
|
||||
{
|
||||
u8 rc4key[16];
|
||||
|
||||
ieee80211_tkip_gen_rc4key(key, ta, rc4key);
|
||||
pos = ieee80211_tkip_add_iv(pos, key, rc4key[0], rc4key[1], rc4key[2]);
|
||||
ieee80211_wep_encrypt_data(tfm, rc4key, 16, pos, payload_len);
|
||||
}
|
||||
|
||||
|
||||
/* Decrypt packet payload with TKIP using @key. @pos is a pointer to the
|
||||
* beginning of the buffer containing IEEE 802.11 header payload, i.e.,
|
||||
* including IV, Ext. IV, real data, Michael MIC, ICV. @payload_len is the
|
||||
* length of payload, including IV, Ext. IV, MIC, ICV. */
|
||||
int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
|
||||
struct ieee80211_key *key,
|
||||
u8 *payload, size_t payload_len, u8 *ta,
|
||||
int only_iv, int queue,
|
||||
u32 *out_iv32, u16 *out_iv16)
|
||||
{
|
||||
u32 iv32;
|
||||
u32 iv16;
|
||||
u8 rc4key[16], keyid, *pos = payload;
|
||||
int res;
|
||||
|
||||
if (payload_len < 12)
|
||||
return -1;
|
||||
|
||||
iv16 = (pos[0] << 8) | pos[2];
|
||||
keyid = pos[3];
|
||||
iv32 = pos[4] | (pos[5] << 8) | (pos[6] << 16) | (pos[7] << 24);
|
||||
pos += 8;
|
||||
#ifdef CONFIG_TKIP_DEBUG
|
||||
{
|
||||
int i;
|
||||
printk(KERN_DEBUG "TKIP decrypt: data(len=%zd)", payload_len);
|
||||
for (i = 0; i < payload_len; i++)
|
||||
printk(" %02x", payload[i]);
|
||||
printk("\n");
|
||||
printk(KERN_DEBUG "TKIP decrypt: iv16=%04x iv32=%08x\n",
|
||||
iv16, iv32);
|
||||
}
|
||||
#endif /* CONFIG_TKIP_DEBUG */
|
||||
|
||||
if (!(keyid & (1 << 5)))
|
||||
return TKIP_DECRYPT_NO_EXT_IV;
|
||||
|
||||
if ((keyid >> 6) != key->conf.keyidx)
|
||||
return TKIP_DECRYPT_INVALID_KEYIDX;
|
||||
|
||||
if (key->u.tkip.rx_initialized[queue] &&
|
||||
(iv32 < key->u.tkip.iv32_rx[queue] ||
|
||||
(iv32 == key->u.tkip.iv32_rx[queue] &&
|
||||
iv16 <= key->u.tkip.iv16_rx[queue]))) {
|
||||
#ifdef CONFIG_TKIP_DEBUG
|
||||
printk(KERN_DEBUG "TKIP replay detected for RX frame from "
|
||||
MAC_FMT " (RX IV (%04x,%02x) <= prev. IV (%04x,%02x)\n",
|
||||
MAC_ARG(ta),
|
||||
iv32, iv16, key->u.tkip.iv32_rx[queue],
|
||||
key->u.tkip.iv16_rx[queue]);
|
||||
#endif /* CONFIG_TKIP_DEBUG */
|
||||
return TKIP_DECRYPT_REPLAY;
|
||||
}
|
||||
|
||||
if (only_iv) {
|
||||
res = TKIP_DECRYPT_OK;
|
||||
key->u.tkip.rx_initialized[queue] = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (!key->u.tkip.rx_initialized[queue] ||
|
||||
key->u.tkip.iv32_rx[queue] != iv32) {
|
||||
key->u.tkip.rx_initialized[queue] = 1;
|
||||
/* IV16 wrapped around - perform TKIP phase 1 */
|
||||
tkip_mixing_phase1(ta, &key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
|
||||
iv32, key->u.tkip.p1k_rx[queue]);
|
||||
#ifdef CONFIG_TKIP_DEBUG
|
||||
{
|
||||
int i;
|
||||
printk(KERN_DEBUG "TKIP decrypt: Phase1 TA=" MAC_FMT
|
||||
" TK=", MAC_ARG(ta));
|
||||
for (i = 0; i < 16; i++)
|
||||
printk("%02x ",
|
||||
key->conf.key[
|
||||
ALG_TKIP_TEMP_ENCR_KEY + i]);
|
||||
printk("\n");
|
||||
printk(KERN_DEBUG "TKIP decrypt: P1K=");
|
||||
for (i = 0; i < 5; i++)
|
||||
printk("%04x ", key->u.tkip.p1k_rx[queue][i]);
|
||||
printk("\n");
|
||||
}
|
||||
#endif /* CONFIG_TKIP_DEBUG */
|
||||
}
|
||||
|
||||
tkip_mixing_phase2(key->u.tkip.p1k_rx[queue],
|
||||
&key->conf.key[ALG_TKIP_TEMP_ENCR_KEY],
|
||||
iv16, rc4key);
|
||||
#ifdef CONFIG_TKIP_DEBUG
|
||||
{
|
||||
int i;
|
||||
printk(KERN_DEBUG "TKIP decrypt: Phase2 rc4key=");
|
||||
for (i = 0; i < 16; i++)
|
||||
printk("%02x ", rc4key[i]);
|
||||
printk("\n");
|
||||
}
|
||||
#endif /* CONFIG_TKIP_DEBUG */
|
||||
|
||||
res = ieee80211_wep_decrypt_data(tfm, rc4key, 16, pos, payload_len - 12);
|
||||
done:
|
||||
if (res == TKIP_DECRYPT_OK) {
|
||||
/*
|
||||
* Record previously received IV, will be copied into the
|
||||
* key information after MIC verification. It is possible
|
||||
* that we don't catch replays of fragments but that's ok
|
||||
* because the Michael MIC verication will then fail.
|
||||
*/
|
||||
*out_iv32 = iv32;
|
||||
*out_iv16 = iv16;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
37
package/mac80211/src/net/mac80211/tkip.h
Normal file
37
package/mac80211/src/net/mac80211/tkip.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-2004, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef TKIP_H
|
||||
#define TKIP_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/crypto.h>
|
||||
#include "ieee80211_key.h"
|
||||
|
||||
u8 * ieee80211_tkip_add_iv(u8 *pos, struct ieee80211_key *key,
|
||||
u8 iv0, u8 iv1, u8 iv2);
|
||||
void ieee80211_tkip_gen_phase1key(struct ieee80211_key *key, u8 *ta,
|
||||
u16 *phase1key);
|
||||
void ieee80211_tkip_gen_rc4key(struct ieee80211_key *key, u8 *ta,
|
||||
u8 *rc4key);
|
||||
void ieee80211_tkip_encrypt_data(struct crypto_blkcipher *tfm,
|
||||
struct ieee80211_key *key,
|
||||
u8 *pos, size_t payload_len, u8 *ta);
|
||||
enum {
|
||||
TKIP_DECRYPT_OK = 0,
|
||||
TKIP_DECRYPT_NO_EXT_IV = -1,
|
||||
TKIP_DECRYPT_INVALID_KEYIDX = -2,
|
||||
TKIP_DECRYPT_REPLAY = -3,
|
||||
};
|
||||
int ieee80211_tkip_decrypt_data(struct crypto_blkcipher *tfm,
|
||||
struct ieee80211_key *key,
|
||||
u8 *payload, size_t payload_len, u8 *ta,
|
||||
int only_iv, int queue,
|
||||
u32 *out_iv32, u16 *out_iv16);
|
||||
|
||||
#endif /* TKIP_H */
|
||||
1898
package/mac80211/src/net/mac80211/tx.c
Normal file
1898
package/mac80211/src/net/mac80211/tx.c
Normal file
File diff suppressed because it is too large
Load Diff
485
package/mac80211/src/net/mac80211/util.c
Normal file
485
package/mac80211/src/net/mac80211/util.c
Normal file
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* Copyright 2002-2005, Instant802 Networks, Inc.
|
||||
* Copyright 2005-2006, Devicescape Software, Inc.
|
||||
* Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
|
||||
* Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* utilities for mac80211
|
||||
*/
|
||||
|
||||
#include <net/mac80211.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/etherdevice.h>
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/wireless.h>
|
||||
#include <linux/bitmap.h>
|
||||
#include <net/cfg80211.h>
|
||||
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
#include "wme.h"
|
||||
|
||||
/* privid for wiphys to determine whether they belong to us or not */
|
||||
void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
|
||||
|
||||
/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
|
||||
/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
|
||||
const unsigned char rfc1042_header[] =
|
||||
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
|
||||
|
||||
/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
|
||||
const unsigned char bridge_tunnel_header[] =
|
||||
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
|
||||
|
||||
/* No encapsulation header if EtherType < 0x600 (=length) */
|
||||
static const unsigned char eapol_header[] =
|
||||
{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e };
|
||||
|
||||
|
||||
static int rate_list_match(const int *rate_list, int rate)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!rate_list)
|
||||
return 0;
|
||||
|
||||
for (i = 0; rate_list[i] >= 0; i++)
|
||||
if (rate_list[i] == rate)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ieee80211_prepare_rates(struct ieee80211_local *local,
|
||||
struct ieee80211_hw_mode *mode)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < mode->num_rates; i++) {
|
||||
struct ieee80211_rate *rate = &mode->rates[i];
|
||||
|
||||
rate->flags &= ~(IEEE80211_RATE_SUPPORTED |
|
||||
IEEE80211_RATE_BASIC);
|
||||
|
||||
if (local->supp_rates[mode->mode]) {
|
||||
if (!rate_list_match(local->supp_rates[mode->mode],
|
||||
rate->rate))
|
||||
continue;
|
||||
}
|
||||
|
||||
rate->flags |= IEEE80211_RATE_SUPPORTED;
|
||||
|
||||
/* Use configured basic rate set if it is available. If not,
|
||||
* use defaults that are sane for most cases. */
|
||||
if (local->basic_rates[mode->mode]) {
|
||||
if (rate_list_match(local->basic_rates[mode->mode],
|
||||
rate->rate))
|
||||
rate->flags |= IEEE80211_RATE_BASIC;
|
||||
} else switch (mode->mode) {
|
||||
case MODE_IEEE80211A:
|
||||
if (rate->rate == 60 || rate->rate == 120 ||
|
||||
rate->rate == 240)
|
||||
rate->flags |= IEEE80211_RATE_BASIC;
|
||||
break;
|
||||
case MODE_IEEE80211B:
|
||||
if (rate->rate == 10 || rate->rate == 20)
|
||||
rate->flags |= IEEE80211_RATE_BASIC;
|
||||
break;
|
||||
case MODE_IEEE80211G:
|
||||
if (rate->rate == 10 || rate->rate == 20 ||
|
||||
rate->rate == 55 || rate->rate == 110)
|
||||
rate->flags |= IEEE80211_RATE_BASIC;
|
||||
break;
|
||||
case NUM_IEEE80211_MODES:
|
||||
/* not useful */
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set ERP and MANDATORY flags based on phymode */
|
||||
switch (mode->mode) {
|
||||
case MODE_IEEE80211A:
|
||||
if (rate->rate == 60 || rate->rate == 120 ||
|
||||
rate->rate == 240)
|
||||
rate->flags |= IEEE80211_RATE_MANDATORY;
|
||||
break;
|
||||
case MODE_IEEE80211B:
|
||||
if (rate->rate == 10)
|
||||
rate->flags |= IEEE80211_RATE_MANDATORY;
|
||||
break;
|
||||
case MODE_IEEE80211G:
|
||||
if (rate->rate == 10 || rate->rate == 20 ||
|
||||
rate->rate == 55 || rate->rate == 110 ||
|
||||
rate->rate == 60 || rate->rate == 120 ||
|
||||
rate->rate == 240)
|
||||
rate->flags |= IEEE80211_RATE_MANDATORY;
|
||||
break;
|
||||
case NUM_IEEE80211_MODES:
|
||||
/* not useful */
|
||||
break;
|
||||
}
|
||||
if (ieee80211_is_erp_rate(mode->mode, rate->rate))
|
||||
rate->flags |= IEEE80211_RATE_ERP;
|
||||
}
|
||||
}
|
||||
|
||||
u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len)
|
||||
{
|
||||
u16 fc;
|
||||
|
||||
if (len < 24)
|
||||
return NULL;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
switch (fc & IEEE80211_FCTL_FTYPE) {
|
||||
case IEEE80211_FTYPE_DATA:
|
||||
switch (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) {
|
||||
case IEEE80211_FCTL_TODS:
|
||||
return hdr->addr1;
|
||||
case (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS):
|
||||
return NULL;
|
||||
case IEEE80211_FCTL_FROMDS:
|
||||
return hdr->addr2;
|
||||
case 0:
|
||||
return hdr->addr3;
|
||||
}
|
||||
break;
|
||||
case IEEE80211_FTYPE_MGMT:
|
||||
return hdr->addr3;
|
||||
case IEEE80211_FTYPE_CTL:
|
||||
if ((fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PSPOLL)
|
||||
return hdr->addr1;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ieee80211_get_hdrlen(u16 fc)
|
||||
{
|
||||
int hdrlen = 24;
|
||||
|
||||
switch (fc & IEEE80211_FCTL_FTYPE) {
|
||||
case IEEE80211_FTYPE_DATA:
|
||||
if ((fc & IEEE80211_FCTL_FROMDS) && (fc & IEEE80211_FCTL_TODS))
|
||||
hdrlen = 30; /* Addr4 */
|
||||
/*
|
||||
* The QoS Control field is two bytes and its presence is
|
||||
* indicated by the IEEE80211_STYPE_QOS_DATA bit. Add 2 to
|
||||
* hdrlen if that bit is set.
|
||||
* This works by masking out the bit and shifting it to
|
||||
* bit position 1 so the result has the value 0 or 2.
|
||||
*/
|
||||
hdrlen += (fc & IEEE80211_STYPE_QOS_DATA)
|
||||
>> (ilog2(IEEE80211_STYPE_QOS_DATA)-1);
|
||||
break;
|
||||
case IEEE80211_FTYPE_CTL:
|
||||
/*
|
||||
* ACK and CTS are 10 bytes, all others 16. To see how
|
||||
* to get this condition consider
|
||||
* subtype mask: 0b0000000011110000 (0x00F0)
|
||||
* ACK subtype: 0b0000000011010000 (0x00D0)
|
||||
* CTS subtype: 0b0000000011000000 (0x00C0)
|
||||
* bits that matter: ^^^ (0x00E0)
|
||||
* value of those: 0b0000000011000000 (0x00C0)
|
||||
*/
|
||||
if ((fc & 0xE0) == 0xC0)
|
||||
hdrlen = 10;
|
||||
else
|
||||
hdrlen = 16;
|
||||
break;
|
||||
}
|
||||
|
||||
return hdrlen;
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_get_hdrlen);
|
||||
|
||||
int ieee80211_get_hdrlen_from_skb(const struct sk_buff *skb)
|
||||
{
|
||||
const struct ieee80211_hdr *hdr = (const struct ieee80211_hdr *) skb->data;
|
||||
int hdrlen;
|
||||
|
||||
if (unlikely(skb->len < 10))
|
||||
return 0;
|
||||
hdrlen = ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
|
||||
if (unlikely(hdrlen > skb->len))
|
||||
return 0;
|
||||
return hdrlen;
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_get_hdrlen_from_skb);
|
||||
|
||||
int ieee80211_is_eapol(const struct sk_buff *skb)
|
||||
{
|
||||
const struct ieee80211_hdr *hdr;
|
||||
u16 fc;
|
||||
int hdrlen;
|
||||
|
||||
if (unlikely(skb->len < 10))
|
||||
return 0;
|
||||
|
||||
hdr = (const struct ieee80211_hdr *) skb->data;
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
if (unlikely(!WLAN_FC_DATA_PRESENT(fc)))
|
||||
return 0;
|
||||
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
|
||||
if (unlikely(skb->len >= hdrlen + sizeof(eapol_header) &&
|
||||
memcmp(skb->data + hdrlen, eapol_header,
|
||||
sizeof(eapol_header)) == 0))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ieee80211_tx_set_iswep(struct ieee80211_txrx_data *tx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
|
||||
|
||||
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
|
||||
if (tx->u.tx.extra_frag) {
|
||||
struct ieee80211_hdr *fhdr;
|
||||
int i;
|
||||
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
|
||||
fhdr = (struct ieee80211_hdr *)
|
||||
tx->u.tx.extra_frag[i]->data;
|
||||
fhdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
|
||||
int rate, int erp, int short_preamble)
|
||||
{
|
||||
int dur;
|
||||
|
||||
/* calculate duration (in microseconds, rounded up to next higher
|
||||
* integer if it includes a fractional microsecond) to send frame of
|
||||
* len bytes (does not include FCS) at the given rate. Duration will
|
||||
* also include SIFS.
|
||||
*
|
||||
* rate is in 100 kbps, so divident is multiplied by 10 in the
|
||||
* DIV_ROUND_UP() operations.
|
||||
*/
|
||||
|
||||
if (local->hw.conf.phymode == MODE_IEEE80211A || erp) {
|
||||
/*
|
||||
* OFDM:
|
||||
*
|
||||
* N_DBPS = DATARATE x 4
|
||||
* N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
|
||||
* (16 = SIGNAL time, 6 = tail bits)
|
||||
* TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
|
||||
*
|
||||
* T_SYM = 4 usec
|
||||
* 802.11a - 17.5.2: aSIFSTime = 16 usec
|
||||
* 802.11g - 19.8.4: aSIFSTime = 10 usec +
|
||||
* signal ext = 6 usec
|
||||
*/
|
||||
dur = 16; /* SIFS + signal ext */
|
||||
dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
|
||||
dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
|
||||
dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
|
||||
4 * rate); /* T_SYM x N_SYM */
|
||||
} else {
|
||||
/*
|
||||
* 802.11b or 802.11g with 802.11b compatibility:
|
||||
* 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
|
||||
* Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
|
||||
*
|
||||
* 802.11 (DS): 15.3.3, 802.11b: 18.3.4
|
||||
* aSIFSTime = 10 usec
|
||||
* aPreambleLength = 144 usec or 72 usec with short preamble
|
||||
* aPLCPHeaderLength = 48 usec or 24 usec with short preamble
|
||||
*/
|
||||
dur = 10; /* aSIFSTime = 10 usec */
|
||||
dur += short_preamble ? (72 + 24) : (144 + 48);
|
||||
|
||||
dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
|
||||
}
|
||||
|
||||
return dur;
|
||||
}
|
||||
|
||||
/* Exported duration function for driver use */
|
||||
__le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, int if_id,
|
||||
size_t frame_len, int rate)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
struct net_device *bdev = dev_get_by_index(if_id);
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
u16 dur;
|
||||
int erp;
|
||||
|
||||
if (unlikely(!bdev))
|
||||
return 0;
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
|
||||
erp = ieee80211_is_erp_rate(hw->conf.phymode, rate);
|
||||
dur = ieee80211_frame_duration(local, frame_len, rate,
|
||||
erp, sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE);
|
||||
|
||||
dev_put(bdev);
|
||||
return cpu_to_le16(dur);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_generic_frame_duration);
|
||||
|
||||
__le16 ieee80211_rts_duration(struct ieee80211_hw *hw, int if_id,
|
||||
size_t frame_len,
|
||||
const struct ieee80211_tx_control *frame_txctl)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
struct ieee80211_rate *rate;
|
||||
struct net_device *bdev = dev_get_by_index(if_id);
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
int short_preamble;
|
||||
int erp;
|
||||
u16 dur;
|
||||
|
||||
if (unlikely(!bdev))
|
||||
return 0;
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
|
||||
short_preamble = sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE;
|
||||
|
||||
rate = frame_txctl->rts_rate;
|
||||
erp = !!(rate->flags & IEEE80211_RATE_ERP);
|
||||
|
||||
/* CTS duration */
|
||||
dur = ieee80211_frame_duration(local, 10, rate->rate,
|
||||
erp, short_preamble);
|
||||
/* Data frame duration */
|
||||
dur += ieee80211_frame_duration(local, frame_len, rate->rate,
|
||||
erp, short_preamble);
|
||||
/* ACK duration */
|
||||
dur += ieee80211_frame_duration(local, 10, rate->rate,
|
||||
erp, short_preamble);
|
||||
|
||||
dev_put(bdev);
|
||||
return cpu_to_le16(dur);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_rts_duration);
|
||||
|
||||
__le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, int if_id,
|
||||
size_t frame_len,
|
||||
const struct ieee80211_tx_control *frame_txctl)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
struct ieee80211_rate *rate;
|
||||
struct net_device *bdev = dev_get_by_index(if_id);
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
int short_preamble;
|
||||
int erp;
|
||||
u16 dur;
|
||||
|
||||
if (unlikely(!bdev))
|
||||
return 0;
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(bdev);
|
||||
short_preamble = sdata->flags & IEEE80211_SDATA_SHORT_PREAMBLE;
|
||||
|
||||
rate = frame_txctl->rts_rate;
|
||||
erp = !!(rate->flags & IEEE80211_RATE_ERP);
|
||||
|
||||
/* Data frame duration */
|
||||
dur = ieee80211_frame_duration(local, frame_len, rate->rate,
|
||||
erp, short_preamble);
|
||||
if (!(frame_txctl->flags & IEEE80211_TXCTL_NO_ACK)) {
|
||||
/* ACK duration */
|
||||
dur += ieee80211_frame_duration(local, 10, rate->rate,
|
||||
erp, short_preamble);
|
||||
}
|
||||
|
||||
dev_put(bdev);
|
||||
return cpu_to_le16(dur);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_ctstoself_duration);
|
||||
|
||||
struct ieee80211_rate *
|
||||
ieee80211_get_rate(struct ieee80211_local *local, int phymode, int hw_rate)
|
||||
{
|
||||
struct ieee80211_hw_mode *mode;
|
||||
int r;
|
||||
|
||||
list_for_each_entry(mode, &local->modes_list, list) {
|
||||
if (mode->mode != phymode)
|
||||
continue;
|
||||
for (r = 0; r < mode->num_rates; r++) {
|
||||
struct ieee80211_rate *rate = &mode->rates[r];
|
||||
if (rate->val == hw_rate ||
|
||||
(rate->flags & IEEE80211_RATE_PREAMBLE2 &&
|
||||
rate->val2 == hw_rate))
|
||||
return rate;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
|
||||
if (test_and_clear_bit(IEEE80211_LINK_STATE_XOFF,
|
||||
&local->state[queue])) {
|
||||
if (test_bit(IEEE80211_LINK_STATE_PENDING,
|
||||
&local->state[queue]))
|
||||
tasklet_schedule(&local->tx_pending_tasklet);
|
||||
else
|
||||
if (!ieee80211_qdisc_installed(local->mdev)) {
|
||||
if (queue == 0)
|
||||
netif_wake_queue(local->mdev);
|
||||
} else
|
||||
__netif_schedule(local->mdev);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_wake_queue);
|
||||
|
||||
void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
|
||||
if (!ieee80211_qdisc_installed(local->mdev) && queue == 0)
|
||||
netif_stop_queue(local->mdev);
|
||||
set_bit(IEEE80211_LINK_STATE_XOFF, &local->state[queue]);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_stop_queue);
|
||||
|
||||
void ieee80211_start_queues(struct ieee80211_hw *hw)
|
||||
{
|
||||
struct ieee80211_local *local = hw_to_local(hw);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < local->hw.queues; i++)
|
||||
clear_bit(IEEE80211_LINK_STATE_XOFF, &local->state[i]);
|
||||
if (!ieee80211_qdisc_installed(local->mdev))
|
||||
netif_start_queue(local->mdev);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_start_queues);
|
||||
|
||||
void ieee80211_stop_queues(struct ieee80211_hw *hw)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < hw->queues; i++)
|
||||
ieee80211_stop_queue(hw, i);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_stop_queues);
|
||||
|
||||
void ieee80211_wake_queues(struct ieee80211_hw *hw)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < hw->queues; i++)
|
||||
ieee80211_wake_queue(hw, i);
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_wake_queues);
|
||||
384
package/mac80211/src/net/mac80211/wep.c
Normal file
384
package/mac80211/src/net/mac80211/wep.c
Normal file
@@ -0,0 +1,384 @@
|
||||
/*
|
||||
* Software WEP encryption implementation
|
||||
* Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
|
||||
* Copyright 2003, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/random.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <linux/crc32.h>
|
||||
#include <linux/crypto.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mm.h>
|
||||
#include <asm/scatterlist.h>
|
||||
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "wep.h"
|
||||
|
||||
|
||||
int ieee80211_wep_init(struct ieee80211_local *local)
|
||||
{
|
||||
/* start WEP IV from a random value */
|
||||
get_random_bytes(&local->wep_iv, WEP_IV_LEN);
|
||||
|
||||
local->wep_tx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0,
|
||||
CRYPTO_ALG_ASYNC);
|
||||
if (IS_ERR(local->wep_tx_tfm))
|
||||
return -ENOMEM;
|
||||
|
||||
local->wep_rx_tfm = crypto_alloc_blkcipher("ecb(arc4)", 0,
|
||||
CRYPTO_ALG_ASYNC);
|
||||
if (IS_ERR(local->wep_rx_tfm)) {
|
||||
crypto_free_blkcipher(local->wep_tx_tfm);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void ieee80211_wep_free(struct ieee80211_local *local)
|
||||
{
|
||||
crypto_free_blkcipher(local->wep_tx_tfm);
|
||||
crypto_free_blkcipher(local->wep_rx_tfm);
|
||||
}
|
||||
|
||||
static inline int ieee80211_wep_weak_iv(u32 iv, int keylen)
|
||||
{
|
||||
/* Fluhrer, Mantin, and Shamir have reported weaknesses in the
|
||||
* key scheduling algorithm of RC4. At least IVs (KeyByte + 3,
|
||||
* 0xff, N) can be used to speedup attacks, so avoid using them. */
|
||||
if ((iv & 0xff00) == 0xff00) {
|
||||
u8 B = (iv >> 16) & 0xff;
|
||||
if (B >= 3 && B < 3 + keylen)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void ieee80211_wep_get_iv(struct ieee80211_local *local,
|
||||
struct ieee80211_key *key, u8 *iv)
|
||||
{
|
||||
local->wep_iv++;
|
||||
if (ieee80211_wep_weak_iv(local->wep_iv, key->conf.keylen))
|
||||
local->wep_iv += 0x0100;
|
||||
|
||||
if (!iv)
|
||||
return;
|
||||
|
||||
*iv++ = (local->wep_iv >> 16) & 0xff;
|
||||
*iv++ = (local->wep_iv >> 8) & 0xff;
|
||||
*iv++ = local->wep_iv & 0xff;
|
||||
*iv++ = key->conf.keyidx << 6;
|
||||
}
|
||||
|
||||
|
||||
static u8 *ieee80211_wep_add_iv(struct ieee80211_local *local,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_key *key)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
u16 fc;
|
||||
int hdrlen;
|
||||
u8 *newhdr;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
fc |= IEEE80211_FCTL_PROTECTED;
|
||||
hdr->frame_control = cpu_to_le16(fc);
|
||||
|
||||
if ((skb_headroom(skb) < WEP_IV_LEN ||
|
||||
skb_tailroom(skb) < WEP_ICV_LEN)) {
|
||||
I802_DEBUG_INC(local->tx_expand_skb_head);
|
||||
if (unlikely(pskb_expand_head(skb, WEP_IV_LEN, WEP_ICV_LEN,
|
||||
GFP_ATOMIC)))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
newhdr = skb_push(skb, WEP_IV_LEN);
|
||||
memmove(newhdr, newhdr + WEP_IV_LEN, hdrlen);
|
||||
ieee80211_wep_get_iv(local, key, newhdr + hdrlen);
|
||||
return newhdr + hdrlen;
|
||||
}
|
||||
|
||||
|
||||
static void ieee80211_wep_remove_iv(struct ieee80211_local *local,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_key *key)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
u16 fc;
|
||||
int hdrlen;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
|
||||
skb_pull(skb, WEP_IV_LEN);
|
||||
}
|
||||
|
||||
|
||||
/* Perform WEP encryption using given key. data buffer must have tailroom
|
||||
* for 4-byte ICV. data_len must not include this ICV. Note: this function
|
||||
* does _not_ add IV. data = RC4(data | CRC32(data)) */
|
||||
void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
|
||||
size_t klen, u8 *data, size_t data_len)
|
||||
{
|
||||
struct blkcipher_desc desc = { .tfm = tfm };
|
||||
struct scatterlist sg;
|
||||
__le32 *icv;
|
||||
|
||||
icv = (__le32 *)(data + data_len);
|
||||
*icv = cpu_to_le32(~crc32_le(~0, data, data_len));
|
||||
|
||||
crypto_blkcipher_setkey(tfm, rc4key, klen);
|
||||
sg.page = virt_to_page(data);
|
||||
sg.offset = offset_in_page(data);
|
||||
sg.length = data_len + WEP_ICV_LEN;
|
||||
crypto_blkcipher_encrypt(&desc, &sg, &sg, sg.length);
|
||||
}
|
||||
|
||||
|
||||
/* Perform WEP encryption on given skb. 4 bytes of extra space (IV) in the
|
||||
* beginning of the buffer 4 bytes of extra space (ICV) in the end of the
|
||||
* buffer will be added. Both IV and ICV will be transmitted, so the
|
||||
* payload length increases with 8 bytes.
|
||||
*
|
||||
* WEP frame payload: IV + TX key idx, RC4(data), ICV = RC4(CRC32(data))
|
||||
*/
|
||||
int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
|
||||
struct ieee80211_key *key)
|
||||
{
|
||||
u32 klen;
|
||||
u8 *rc4key, *iv;
|
||||
size_t len;
|
||||
|
||||
if (!key || key->conf.alg != ALG_WEP)
|
||||
return -1;
|
||||
|
||||
klen = 3 + key->conf.keylen;
|
||||
rc4key = kmalloc(klen, GFP_ATOMIC);
|
||||
if (!rc4key)
|
||||
return -1;
|
||||
|
||||
iv = ieee80211_wep_add_iv(local, skb, key);
|
||||
if (!iv) {
|
||||
kfree(rc4key);
|
||||
return -1;
|
||||
}
|
||||
|
||||
len = skb->len - (iv + WEP_IV_LEN - skb->data);
|
||||
|
||||
/* Prepend 24-bit IV to RC4 key */
|
||||
memcpy(rc4key, iv, 3);
|
||||
|
||||
/* Copy rest of the WEP key (the secret part) */
|
||||
memcpy(rc4key + 3, key->conf.key, key->conf.keylen);
|
||||
|
||||
/* Add room for ICV */
|
||||
skb_put(skb, WEP_ICV_LEN);
|
||||
|
||||
ieee80211_wep_encrypt_data(local->wep_tx_tfm, rc4key, klen,
|
||||
iv + WEP_IV_LEN, len);
|
||||
|
||||
kfree(rc4key);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Perform WEP decryption using given key. data buffer includes encrypted
|
||||
* payload, including 4-byte ICV, but _not_ IV. data_len must not include ICV.
|
||||
* Return 0 on success and -1 on ICV mismatch. */
|
||||
int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
|
||||
size_t klen, u8 *data, size_t data_len)
|
||||
{
|
||||
struct blkcipher_desc desc = { .tfm = tfm };
|
||||
struct scatterlist sg;
|
||||
__le32 crc;
|
||||
|
||||
crypto_blkcipher_setkey(tfm, rc4key, klen);
|
||||
sg.page = virt_to_page(data);
|
||||
sg.offset = offset_in_page(data);
|
||||
sg.length = data_len + WEP_ICV_LEN;
|
||||
crypto_blkcipher_decrypt(&desc, &sg, &sg, sg.length);
|
||||
|
||||
crc = cpu_to_le32(~crc32_le(~0, data, data_len));
|
||||
if (memcmp(&crc, data + data_len, WEP_ICV_LEN) != 0)
|
||||
/* ICV mismatch */
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Perform WEP decryption on given skb. Buffer includes whole WEP part of
|
||||
* the frame: IV (4 bytes), encrypted payload (including SNAP header),
|
||||
* ICV (4 bytes). skb->len includes both IV and ICV.
|
||||
*
|
||||
* Returns 0 if frame was decrypted successfully and ICV was correct and -1 on
|
||||
* failure. If frame is OK, IV and ICV will be removed, i.e., decrypted payload
|
||||
* is moved to the beginning of the skb and skb length will be reduced.
|
||||
*/
|
||||
int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
|
||||
struct ieee80211_key *key)
|
||||
{
|
||||
u32 klen;
|
||||
u8 *rc4key;
|
||||
u8 keyidx;
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
u16 fc;
|
||||
int hdrlen;
|
||||
size_t len;
|
||||
int ret = 0;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
if (!(fc & IEEE80211_FCTL_PROTECTED))
|
||||
return -1;
|
||||
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
|
||||
if (skb->len < 8 + hdrlen)
|
||||
return -1;
|
||||
|
||||
len = skb->len - hdrlen - 8;
|
||||
|
||||
keyidx = skb->data[hdrlen + 3] >> 6;
|
||||
|
||||
if (!key || keyidx != key->conf.keyidx || key->conf.alg != ALG_WEP)
|
||||
return -1;
|
||||
|
||||
klen = 3 + key->conf.keylen;
|
||||
|
||||
rc4key = kmalloc(klen, GFP_ATOMIC);
|
||||
if (!rc4key)
|
||||
return -1;
|
||||
|
||||
/* Prepend 24-bit IV to RC4 key */
|
||||
memcpy(rc4key, skb->data + hdrlen, 3);
|
||||
|
||||
/* Copy rest of the WEP key (the secret part) */
|
||||
memcpy(rc4key + 3, key->conf.key, key->conf.keylen);
|
||||
|
||||
if (ieee80211_wep_decrypt_data(local->wep_rx_tfm, rc4key, klen,
|
||||
skb->data + hdrlen + WEP_IV_LEN,
|
||||
len)) {
|
||||
printk(KERN_DEBUG "WEP decrypt failed (ICV)\n");
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
kfree(rc4key);
|
||||
|
||||
/* Trim ICV */
|
||||
skb_trim(skb, skb->len - WEP_ICV_LEN);
|
||||
|
||||
/* Remove IV */
|
||||
memmove(skb->data + WEP_IV_LEN, skb->data, hdrlen);
|
||||
skb_pull(skb, WEP_IV_LEN);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
u16 fc;
|
||||
int hdrlen;
|
||||
u8 *ivpos;
|
||||
u32 iv;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
if (!(fc & IEEE80211_FCTL_PROTECTED))
|
||||
return NULL;
|
||||
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
ivpos = skb->data + hdrlen;
|
||||
iv = (ivpos[0] << 16) | (ivpos[1] << 8) | ivpos[2];
|
||||
|
||||
if (ieee80211_wep_weak_iv(iv, key->conf.keylen))
|
||||
return ivpos;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_wep_decrypt(struct ieee80211_txrx_data *rx)
|
||||
{
|
||||
if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
|
||||
((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
|
||||
(rx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) {
|
||||
if (ieee80211_wep_decrypt(rx->local, rx->skb, rx->key)) {
|
||||
if (net_ratelimit())
|
||||
printk(KERN_DEBUG "%s: RX WEP frame, decrypt "
|
||||
"failed\n", rx->dev->name);
|
||||
return TXRX_DROP;
|
||||
}
|
||||
} else if (!(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED)) {
|
||||
ieee80211_wep_remove_iv(rx->local, rx->skb, rx->key);
|
||||
/* remove ICV */
|
||||
skb_trim(rx->skb, rx->skb->len - 4);
|
||||
}
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
static int wep_encrypt_skb(struct ieee80211_txrx_data *tx, struct sk_buff *skb)
|
||||
{
|
||||
if (!(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) {
|
||||
if (ieee80211_wep_encrypt(tx->local, skb, tx->key))
|
||||
return -1;
|
||||
} else {
|
||||
tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
|
||||
if (tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) {
|
||||
if (!ieee80211_wep_add_iv(tx->local, skb, tx->key))
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_wep_encrypt(struct ieee80211_txrx_data *tx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
|
||||
u16 fc;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA &&
|
||||
((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
|
||||
(fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_AUTH)))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
tx->u.tx.control->iv_len = WEP_IV_LEN;
|
||||
tx->u.tx.control->icv_len = WEP_ICV_LEN;
|
||||
ieee80211_tx_set_iswep(tx);
|
||||
|
||||
if (wep_encrypt_skb(tx, tx->skb) < 0) {
|
||||
I802_DEBUG_INC(tx->local->tx_handlers_drop_wep);
|
||||
return TXRX_DROP;
|
||||
}
|
||||
|
||||
if (tx->u.tx.extra_frag) {
|
||||
int i;
|
||||
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
|
||||
if (wep_encrypt_skb(tx, tx->u.tx.extra_frag[i]) < 0) {
|
||||
I802_DEBUG_INC(tx->local->
|
||||
tx_handlers_drop_wep);
|
||||
return TXRX_DROP;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
36
package/mac80211/src/net/mac80211/wep.h
Normal file
36
package/mac80211/src/net/mac80211/wep.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Software WEP encryption implementation
|
||||
* Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
|
||||
* Copyright 2003, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef WEP_H
|
||||
#define WEP_H
|
||||
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/types.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_key.h"
|
||||
|
||||
int ieee80211_wep_init(struct ieee80211_local *local);
|
||||
void ieee80211_wep_free(struct ieee80211_local *local);
|
||||
void ieee80211_wep_encrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
|
||||
size_t klen, u8 *data, size_t data_len);
|
||||
int ieee80211_wep_decrypt_data(struct crypto_blkcipher *tfm, u8 *rc4key,
|
||||
size_t klen, u8 *data, size_t data_len);
|
||||
int ieee80211_wep_encrypt(struct ieee80211_local *local, struct sk_buff *skb,
|
||||
struct ieee80211_key *key);
|
||||
int ieee80211_wep_decrypt(struct ieee80211_local *local, struct sk_buff *skb,
|
||||
struct ieee80211_key *key);
|
||||
u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_wep_decrypt(struct ieee80211_txrx_data *rx);
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_wep_encrypt(struct ieee80211_txrx_data *tx);
|
||||
|
||||
#endif /* WEP_H */
|
||||
606
package/mac80211/src/net/mac80211/wme.c
Normal file
606
package/mac80211/src/net/mac80211/wme.c
Normal file
@@ -0,0 +1,606 @@
|
||||
/*
|
||||
* Copyright 2004, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/if_arp.h>
|
||||
#include <linux/types.h>
|
||||
#include <net/ip.h>
|
||||
#include <net/pkt_sched.h>
|
||||
|
||||
#include <net/mac80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "wme.h"
|
||||
|
||||
/* maximum number of hardware queues we support. */
|
||||
#define TC_80211_MAX_QUEUES 8
|
||||
|
||||
struct ieee80211_sched_data
|
||||
{
|
||||
struct tcf_proto *filter_list;
|
||||
struct Qdisc *queues[TC_80211_MAX_QUEUES];
|
||||
struct sk_buff_head requeued[TC_80211_MAX_QUEUES];
|
||||
};
|
||||
|
||||
|
||||
/* given a data frame determine the 802.1p/1d tag to use */
|
||||
static inline unsigned classify_1d(struct sk_buff *skb, struct Qdisc *qd)
|
||||
{
|
||||
struct iphdr *ip;
|
||||
int dscp;
|
||||
int offset;
|
||||
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct tcf_result res = { -1, 0 };
|
||||
|
||||
/* if there is a user set filter list, call out to that */
|
||||
if (q->filter_list) {
|
||||
tc_classify(skb, q->filter_list, &res);
|
||||
if (res.class != -1)
|
||||
return res.class;
|
||||
}
|
||||
|
||||
/* skb->priority values from 256->263 are magic values to
|
||||
* directly indicate a specific 802.1d priority.
|
||||
* This is used to allow 802.1d priority to be passed directly in
|
||||
* from VLAN tags, etc. */
|
||||
if (skb->priority >= 256 && skb->priority <= 263)
|
||||
return skb->priority - 256;
|
||||
|
||||
/* check there is a valid IP header present */
|
||||
offset = ieee80211_get_hdrlen_from_skb(skb) + 8 /* LLC + proto */;
|
||||
if (skb->protocol != __constant_htons(ETH_P_IP) ||
|
||||
skb->len < offset + sizeof(*ip))
|
||||
return 0;
|
||||
|
||||
ip = (struct iphdr *) (skb->data + offset);
|
||||
|
||||
dscp = ip->tos & 0xfc;
|
||||
if (dscp & 0x1c)
|
||||
return 0;
|
||||
return dscp >> 5;
|
||||
}
|
||||
|
||||
|
||||
static inline int wme_downgrade_ac(struct sk_buff *skb)
|
||||
{
|
||||
switch (skb->priority) {
|
||||
case 6:
|
||||
case 7:
|
||||
skb->priority = 5; /* VO -> VI */
|
||||
return 0;
|
||||
case 4:
|
||||
case 5:
|
||||
skb->priority = 3; /* VI -> BE */
|
||||
return 0;
|
||||
case 0:
|
||||
case 3:
|
||||
skb->priority = 2; /* BE -> BK */
|
||||
return 0;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* positive return value indicates which queue to use
|
||||
* negative return value indicates to drop the frame */
|
||||
static inline int classify80211(struct sk_buff *skb, struct Qdisc *qd)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
unsigned short fc = le16_to_cpu(hdr->frame_control);
|
||||
int qos;
|
||||
const int ieee802_1d_to_ac[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
|
||||
|
||||
/* see if frame is data or non data frame */
|
||||
if (unlikely((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)) {
|
||||
/* management frames go on AC_VO queue, but are sent
|
||||
* without QoS control fields */
|
||||
return IEEE80211_TX_QUEUE_DATA0;
|
||||
}
|
||||
|
||||
if (0 /* injected */) {
|
||||
/* use AC from radiotap */
|
||||
}
|
||||
|
||||
/* is this a QoS frame? */
|
||||
qos = fc & IEEE80211_STYPE_QOS_DATA;
|
||||
|
||||
if (!qos) {
|
||||
skb->priority = 0; /* required for correct WPA/11i MIC */
|
||||
return ieee802_1d_to_ac[skb->priority];
|
||||
}
|
||||
|
||||
/* use the data classifier to determine what 802.1d tag the
|
||||
* data frame has */
|
||||
skb->priority = classify_1d(skb, qd);
|
||||
|
||||
/* in case we are a client verify acm is not set for this ac */
|
||||
while (unlikely(local->wmm_acm & BIT(skb->priority))) {
|
||||
if (wme_downgrade_ac(skb)) {
|
||||
/* No AC with lower priority has acm=0, drop packet. */
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* look up which queue to use for frames with this 1d tag */
|
||||
return ieee802_1d_to_ac[skb->priority];
|
||||
}
|
||||
|
||||
|
||||
static int wme_qdiscop_enqueue(struct sk_buff *skb, struct Qdisc* qd)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct ieee80211_tx_packet_data *pkt_data =
|
||||
(struct ieee80211_tx_packet_data *) skb->cb;
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
unsigned short fc = le16_to_cpu(hdr->frame_control);
|
||||
struct Qdisc *qdisc;
|
||||
int err, queue;
|
||||
|
||||
if (pkt_data->flags & IEEE80211_TXPD_REQUEUE) {
|
||||
skb_queue_tail(&q->requeued[pkt_data->queue], skb);
|
||||
qd->q.qlen++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
queue = classify80211(skb, qd);
|
||||
|
||||
/* now we know the 1d priority, fill in the QoS header if there is one
|
||||
*/
|
||||
if (WLAN_FC_IS_QOS_DATA(fc)) {
|
||||
u8 *p = skb->data + ieee80211_get_hdrlen(fc) - 2;
|
||||
u8 qos_hdr = skb->priority & QOS_CONTROL_TAG1D_MASK;
|
||||
if (local->wifi_wme_noack_test)
|
||||
qos_hdr |= QOS_CONTROL_ACK_POLICY_NOACK <<
|
||||
QOS_CONTROL_ACK_POLICY_SHIFT;
|
||||
/* qos header is 2 bytes, second reserved */
|
||||
*p = qos_hdr;
|
||||
p++;
|
||||
*p = 0;
|
||||
}
|
||||
|
||||
if (unlikely(queue >= local->hw.queues)) {
|
||||
#if 0
|
||||
if (net_ratelimit()) {
|
||||
printk(KERN_DEBUG "%s - queue=%d (hw does not "
|
||||
"support) -> %d\n",
|
||||
__func__, queue, local->hw.queues - 1);
|
||||
}
|
||||
#endif
|
||||
queue = local->hw.queues - 1;
|
||||
}
|
||||
|
||||
if (unlikely(queue < 0)) {
|
||||
kfree_skb(skb);
|
||||
err = NET_XMIT_DROP;
|
||||
} else {
|
||||
pkt_data->queue = (unsigned int) queue;
|
||||
qdisc = q->queues[queue];
|
||||
err = qdisc->enqueue(skb, qdisc);
|
||||
if (err == NET_XMIT_SUCCESS) {
|
||||
qd->q.qlen++;
|
||||
qd->bstats.bytes += skb->len;
|
||||
qd->bstats.packets++;
|
||||
return NET_XMIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
qd->qstats.drops++;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* TODO: clean up the cases where master_hard_start_xmit
|
||||
* returns non 0 - it shouldn't ever do that. Once done we
|
||||
* can remove this function */
|
||||
static int wme_qdiscop_requeue(struct sk_buff *skb, struct Qdisc* qd)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct ieee80211_tx_packet_data *pkt_data =
|
||||
(struct ieee80211_tx_packet_data *) skb->cb;
|
||||
struct Qdisc *qdisc;
|
||||
int err;
|
||||
|
||||
/* we recorded which queue to use earlier! */
|
||||
qdisc = q->queues[pkt_data->queue];
|
||||
|
||||
if ((err = qdisc->ops->requeue(skb, qdisc)) == 0) {
|
||||
qd->q.qlen++;
|
||||
return 0;
|
||||
}
|
||||
qd->qstats.drops++;
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
static struct sk_buff *wme_qdiscop_dequeue(struct Qdisc* qd)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct net_device *dev = qd->dev;
|
||||
struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
struct sk_buff *skb;
|
||||
struct Qdisc *qdisc;
|
||||
int queue;
|
||||
|
||||
/* check all the h/w queues in numeric/priority order */
|
||||
for (queue = 0; queue < hw->queues; queue++) {
|
||||
/* see if there is room in this hardware queue */
|
||||
if (test_bit(IEEE80211_LINK_STATE_XOFF,
|
||||
&local->state[queue]) ||
|
||||
test_bit(IEEE80211_LINK_STATE_PENDING,
|
||||
&local->state[queue]))
|
||||
continue;
|
||||
|
||||
/* there is space - try and get a frame */
|
||||
skb = skb_dequeue(&q->requeued[queue]);
|
||||
if (skb) {
|
||||
qd->q.qlen--;
|
||||
return skb;
|
||||
}
|
||||
|
||||
qdisc = q->queues[queue];
|
||||
skb = qdisc->dequeue(qdisc);
|
||||
if (skb) {
|
||||
qd->q.qlen--;
|
||||
return skb;
|
||||
}
|
||||
}
|
||||
/* returning a NULL here when all the h/w queues are full means we
|
||||
* never need to call netif_stop_queue in the driver */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static void wme_qdiscop_reset(struct Qdisc* qd)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
int queue;
|
||||
|
||||
/* QUESTION: should we have some hardware flush functionality here? */
|
||||
|
||||
for (queue = 0; queue < hw->queues; queue++) {
|
||||
skb_queue_purge(&q->requeued[queue]);
|
||||
qdisc_reset(q->queues[queue]);
|
||||
}
|
||||
qd->q.qlen = 0;
|
||||
}
|
||||
|
||||
|
||||
static void wme_qdiscop_destroy(struct Qdisc* qd)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
int queue;
|
||||
|
||||
tcf_destroy_chain(q->filter_list);
|
||||
q->filter_list = NULL;
|
||||
|
||||
for (queue=0; queue < hw->queues; queue++) {
|
||||
skb_queue_purge(&q->requeued[queue]);
|
||||
qdisc_destroy(q->queues[queue]);
|
||||
q->queues[queue] = &noop_qdisc;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* called whenever parameters are updated on existing qdisc */
|
||||
static int wme_qdiscop_tune(struct Qdisc *qd, struct rtattr *opt)
|
||||
{
|
||||
/* struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
*/
|
||||
/* check our options block is the right size */
|
||||
/* copy any options to our local structure */
|
||||
/* Ignore options block for now - always use static mapping
|
||||
struct tc_ieee80211_qopt *qopt = RTA_DATA(opt);
|
||||
|
||||
if (opt->rta_len < RTA_LENGTH(sizeof(*qopt)))
|
||||
return -EINVAL;
|
||||
memcpy(q->tag2queue, qopt->tag2queue, sizeof(qopt->tag2queue));
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* called during initial creation of qdisc on device */
|
||||
static int wme_qdiscop_init(struct Qdisc *qd, struct rtattr *opt)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct net_device *dev = qd->dev;
|
||||
struct ieee80211_local *local;
|
||||
int queues;
|
||||
int err = 0, i;
|
||||
|
||||
/* check that device is a mac80211 device */
|
||||
if (!dev->ieee80211_ptr ||
|
||||
dev->ieee80211_ptr->wiphy->privid != mac80211_wiphy_privid)
|
||||
return -EINVAL;
|
||||
|
||||
/* check this device is an ieee80211 master type device */
|
||||
if (dev->type != ARPHRD_IEEE80211)
|
||||
return -EINVAL;
|
||||
|
||||
/* check that there is no qdisc currently attached to device
|
||||
* this ensures that we will be the root qdisc. (I can't find a better
|
||||
* way to test this explicitly) */
|
||||
if (dev->qdisc_sleeping != &noop_qdisc)
|
||||
return -EINVAL;
|
||||
|
||||
if (qd->flags & TCQ_F_INGRESS)
|
||||
return -EINVAL;
|
||||
|
||||
local = wdev_priv(dev->ieee80211_ptr);
|
||||
queues = local->hw.queues;
|
||||
|
||||
/* if options were passed in, set them */
|
||||
if (opt) {
|
||||
err = wme_qdiscop_tune(qd, opt);
|
||||
}
|
||||
|
||||
/* create child queues */
|
||||
for (i = 0; i < queues; i++) {
|
||||
skb_queue_head_init(&q->requeued[i]);
|
||||
q->queues[i] = qdisc_create_dflt(qd->dev, &pfifo_qdisc_ops,
|
||||
qd->handle);
|
||||
if (!q->queues[i]) {
|
||||
q->queues[i] = &noop_qdisc;
|
||||
printk(KERN_ERR "%s child qdisc %i creation failed", dev->name, i);
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int wme_qdiscop_dump(struct Qdisc *qd, struct sk_buff *skb)
|
||||
{
|
||||
/* struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
unsigned char *p = skb->tail;
|
||||
struct tc_ieee80211_qopt opt;
|
||||
|
||||
memcpy(&opt.tag2queue, q->tag2queue, TC_80211_MAX_TAG + 1);
|
||||
RTA_PUT(skb, TCA_OPTIONS, sizeof(opt), &opt);
|
||||
*/ return skb->len;
|
||||
/*
|
||||
rtattr_failure:
|
||||
skb_trim(skb, p - skb->data);*/
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int wme_classop_graft(struct Qdisc *qd, unsigned long arg,
|
||||
struct Qdisc *new, struct Qdisc **old)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
unsigned long queue = arg - 1;
|
||||
|
||||
if (queue >= hw->queues)
|
||||
return -EINVAL;
|
||||
|
||||
if (!new)
|
||||
new = &noop_qdisc;
|
||||
|
||||
sch_tree_lock(qd);
|
||||
*old = q->queues[queue];
|
||||
q->queues[queue] = new;
|
||||
qdisc_reset(*old);
|
||||
sch_tree_unlock(qd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static struct Qdisc *
|
||||
wme_classop_leaf(struct Qdisc *qd, unsigned long arg)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
unsigned long queue = arg - 1;
|
||||
|
||||
if (queue >= hw->queues)
|
||||
return NULL;
|
||||
|
||||
return q->queues[queue];
|
||||
}
|
||||
|
||||
|
||||
static unsigned long wme_classop_get(struct Qdisc *qd, u32 classid)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
unsigned long queue = TC_H_MIN(classid);
|
||||
|
||||
if (queue - 1 >= hw->queues)
|
||||
return 0;
|
||||
|
||||
return queue;
|
||||
}
|
||||
|
||||
|
||||
static unsigned long wme_classop_bind(struct Qdisc *qd, unsigned long parent,
|
||||
u32 classid)
|
||||
{
|
||||
return wme_classop_get(qd, classid);
|
||||
}
|
||||
|
||||
|
||||
static void wme_classop_put(struct Qdisc *q, unsigned long cl)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static int wme_classop_change(struct Qdisc *qd, u32 handle, u32 parent,
|
||||
struct rtattr **tca, unsigned long *arg)
|
||||
{
|
||||
unsigned long cl = *arg;
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
|
||||
if (cl - 1 > hw->queues)
|
||||
return -ENOENT;
|
||||
|
||||
/* TODO: put code to program hardware queue parameters here,
|
||||
* to allow programming from tc command line */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* we don't support deleting hardware queues
|
||||
* when we add WMM-SA support - TSPECs may be deleted here */
|
||||
static int wme_classop_delete(struct Qdisc *qd, unsigned long cl)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
|
||||
if (cl - 1 > hw->queues)
|
||||
return -ENOENT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int wme_classop_dump_class(struct Qdisc *qd, unsigned long cl,
|
||||
struct sk_buff *skb, struct tcmsg *tcm)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
|
||||
if (cl - 1 > hw->queues)
|
||||
return -ENOENT;
|
||||
tcm->tcm_handle = TC_H_MIN(cl);
|
||||
tcm->tcm_parent = qd->handle;
|
||||
tcm->tcm_info = q->queues[cl-1]->handle; /* do we need this? */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void wme_classop_walk(struct Qdisc *qd, struct qdisc_walker *arg)
|
||||
{
|
||||
struct ieee80211_local *local = wdev_priv(qd->dev->ieee80211_ptr);
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
int queue;
|
||||
|
||||
if (arg->stop)
|
||||
return;
|
||||
|
||||
for (queue = 0; queue < hw->queues; queue++) {
|
||||
if (arg->count < arg->skip) {
|
||||
arg->count++;
|
||||
continue;
|
||||
}
|
||||
/* we should return classids for our internal queues here
|
||||
* as well as the external ones */
|
||||
if (arg->fn(qd, queue+1, arg) < 0) {
|
||||
arg->stop = 1;
|
||||
break;
|
||||
}
|
||||
arg->count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct tcf_proto ** wme_classop_find_tcf(struct Qdisc *qd,
|
||||
unsigned long cl)
|
||||
{
|
||||
struct ieee80211_sched_data *q = qdisc_priv(qd);
|
||||
|
||||
if (cl)
|
||||
return NULL;
|
||||
|
||||
return &q->filter_list;
|
||||
}
|
||||
|
||||
|
||||
/* this qdisc is classful (i.e. has classes, some of which may have leaf qdiscs attached)
|
||||
* - these are the operations on the classes */
|
||||
static struct Qdisc_class_ops class_ops =
|
||||
{
|
||||
.graft = wme_classop_graft,
|
||||
.leaf = wme_classop_leaf,
|
||||
|
||||
.get = wme_classop_get,
|
||||
.put = wme_classop_put,
|
||||
.change = wme_classop_change,
|
||||
.delete = wme_classop_delete,
|
||||
.walk = wme_classop_walk,
|
||||
|
||||
.tcf_chain = wme_classop_find_tcf,
|
||||
.bind_tcf = wme_classop_bind,
|
||||
.unbind_tcf = wme_classop_put,
|
||||
|
||||
.dump = wme_classop_dump_class,
|
||||
};
|
||||
|
||||
|
||||
/* queueing discipline operations */
|
||||
static struct Qdisc_ops wme_qdisc_ops =
|
||||
{
|
||||
.next = NULL,
|
||||
.cl_ops = &class_ops,
|
||||
.id = "ieee80211",
|
||||
.priv_size = sizeof(struct ieee80211_sched_data),
|
||||
|
||||
.enqueue = wme_qdiscop_enqueue,
|
||||
.dequeue = wme_qdiscop_dequeue,
|
||||
.requeue = wme_qdiscop_requeue,
|
||||
.drop = NULL, /* drop not needed since we are always the root qdisc */
|
||||
|
||||
.init = wme_qdiscop_init,
|
||||
.reset = wme_qdiscop_reset,
|
||||
.destroy = wme_qdiscop_destroy,
|
||||
.change = wme_qdiscop_tune,
|
||||
|
||||
.dump = wme_qdiscop_dump,
|
||||
};
|
||||
|
||||
|
||||
void ieee80211_install_qdisc(struct net_device *dev)
|
||||
{
|
||||
struct Qdisc *qdisc;
|
||||
|
||||
qdisc = qdisc_create_dflt(dev, &wme_qdisc_ops, TC_H_ROOT);
|
||||
if (!qdisc) {
|
||||
printk(KERN_ERR "%s: qdisc installation failed\n", dev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* same handle as would be allocated by qdisc_alloc_handle() */
|
||||
qdisc->handle = 0x80010000;
|
||||
|
||||
qdisc_lock_tree(dev);
|
||||
list_add_tail(&qdisc->list, &dev->qdisc_list);
|
||||
dev->qdisc_sleeping = qdisc;
|
||||
qdisc_unlock_tree(dev);
|
||||
}
|
||||
|
||||
|
||||
int ieee80211_qdisc_installed(struct net_device *dev)
|
||||
{
|
||||
return dev->qdisc_sleeping->ops == &wme_qdisc_ops;
|
||||
}
|
||||
|
||||
|
||||
int ieee80211_wme_register(void)
|
||||
{
|
||||
return register_qdisc(&wme_qdisc_ops);
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_wme_unregister(void)
|
||||
{
|
||||
unregister_qdisc(&wme_qdisc_ops);
|
||||
}
|
||||
56
package/mac80211/src/net/mac80211/wme.h
Normal file
56
package/mac80211/src/net/mac80211/wme.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* IEEE 802.11 driver (80211.o) - QoS datatypes
|
||||
* Copyright 2004, Instant802 Networks, Inc.
|
||||
* Copyright 2005, Devicescape Software, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _WME_H
|
||||
#define _WME_H
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include "ieee80211_i.h"
|
||||
|
||||
#define QOS_CONTROL_LEN 2
|
||||
|
||||
#define QOS_CONTROL_ACK_POLICY_NORMAL 0
|
||||
#define QOS_CONTROL_ACK_POLICY_NOACK 1
|
||||
|
||||
#define QOS_CONTROL_TID_MASK 0x0f
|
||||
#define QOS_CONTROL_ACK_POLICY_SHIFT 5
|
||||
|
||||
#define QOS_CONTROL_TAG1D_MASK 0x07
|
||||
|
||||
static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
|
||||
{
|
||||
return (fc & 0x8C) == 0x88;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_SCHED
|
||||
void ieee80211_install_qdisc(struct net_device *dev);
|
||||
int ieee80211_qdisc_installed(struct net_device *dev);
|
||||
|
||||
int ieee80211_wme_register(void);
|
||||
void ieee80211_wme_unregister(void);
|
||||
#else
|
||||
static inline void ieee80211_install_qdisc(struct net_device *dev)
|
||||
{
|
||||
}
|
||||
static inline int ieee80211_qdisc_installed(struct net_device *dev)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int ieee80211_wme_register(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static inline void ieee80211_wme_unregister(void)
|
||||
{
|
||||
}
|
||||
#endif /* CONFIG_NET_SCHED */
|
||||
|
||||
#endif /* _WME_H */
|
||||
609
package/mac80211/src/net/mac80211/wpa.c
Normal file
609
package/mac80211/src/net/mac80211/wpa.c
Normal file
@@ -0,0 +1,609 @@
|
||||
/*
|
||||
* Copyright 2002-2004, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/compiler.h>
|
||||
#include <net/mac80211.h>
|
||||
|
||||
#include "ieee80211_i.h"
|
||||
#include "michael.h"
|
||||
#include "tkip.h"
|
||||
#include "aes_ccm.h"
|
||||
#include "wpa.h"
|
||||
|
||||
static int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
|
||||
u8 *qos_tid, u8 **data, size_t *data_len)
|
||||
{
|
||||
struct ieee80211_hdr *hdr;
|
||||
size_t hdrlen;
|
||||
u16 fc;
|
||||
int a4_included;
|
||||
u8 *pos;
|
||||
|
||||
hdr = (struct ieee80211_hdr *) skb->data;
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
hdrlen = 24;
|
||||
if ((fc & (IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) ==
|
||||
(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS)) {
|
||||
hdrlen += ETH_ALEN;
|
||||
*sa = hdr->addr4;
|
||||
*da = hdr->addr3;
|
||||
} else if (fc & IEEE80211_FCTL_FROMDS) {
|
||||
*sa = hdr->addr3;
|
||||
*da = hdr->addr1;
|
||||
} else if (fc & IEEE80211_FCTL_TODS) {
|
||||
*sa = hdr->addr2;
|
||||
*da = hdr->addr3;
|
||||
} else {
|
||||
*sa = hdr->addr2;
|
||||
*da = hdr->addr1;
|
||||
}
|
||||
|
||||
if (fc & 0x80)
|
||||
hdrlen += 2;
|
||||
|
||||
*data = skb->data + hdrlen;
|
||||
*data_len = skb->len - hdrlen;
|
||||
|
||||
a4_included = (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
|
||||
(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
|
||||
if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
|
||||
fc & IEEE80211_STYPE_QOS_DATA) {
|
||||
pos = (u8 *) &hdr->addr4;
|
||||
if (a4_included)
|
||||
pos += 6;
|
||||
*qos_tid = pos[0] & 0x0f;
|
||||
*qos_tid |= 0x80; /* qos_included flag */
|
||||
} else
|
||||
*qos_tid = 0;
|
||||
|
||||
return skb->len < hdrlen ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx)
|
||||
{
|
||||
u8 *data, *sa, *da, *key, *mic, qos_tid;
|
||||
size_t data_len;
|
||||
u16 fc;
|
||||
struct sk_buff *skb = tx->skb;
|
||||
int authenticator;
|
||||
int wpa_test = 0;
|
||||
|
||||
fc = tx->fc;
|
||||
|
||||
if (!tx->key || tx->key->conf.alg != ALG_TKIP || skb->len < 24 ||
|
||||
!WLAN_FC_DATA_PRESENT(fc))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len))
|
||||
return TXRX_DROP;
|
||||
|
||||
if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
|
||||
!(tx->flags & IEEE80211_TXRXD_FRAGMENTED) &&
|
||||
!(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC) &&
|
||||
!wpa_test) {
|
||||
/* hwaccel - with no need for preallocated room for Michael MIC
|
||||
*/
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
if (skb_tailroom(skb) < MICHAEL_MIC_LEN) {
|
||||
I802_DEBUG_INC(tx->local->tx_expand_skb_head);
|
||||
if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN,
|
||||
MICHAEL_MIC_LEN + TKIP_ICV_LEN,
|
||||
GFP_ATOMIC))) {
|
||||
printk(KERN_DEBUG "%s: failed to allocate more memory "
|
||||
"for Michael MIC\n", tx->dev->name);
|
||||
return TXRX_DROP;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
authenticator = fc & IEEE80211_FCTL_FROMDS; /* FIX */
|
||||
#else
|
||||
authenticator = 1;
|
||||
#endif
|
||||
key = &tx->key->conf.key[authenticator ? ALG_TKIP_TEMP_AUTH_TX_MIC_KEY :
|
||||
ALG_TKIP_TEMP_AUTH_RX_MIC_KEY];
|
||||
mic = skb_put(skb, MICHAEL_MIC_LEN);
|
||||
michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx)
|
||||
{
|
||||
u8 *data, *sa, *da, *key = NULL, qos_tid;
|
||||
size_t data_len;
|
||||
u16 fc;
|
||||
u8 mic[MICHAEL_MIC_LEN];
|
||||
struct sk_buff *skb = rx->skb;
|
||||
int authenticator = 1, wpa_test = 0;
|
||||
|
||||
fc = rx->fc;
|
||||
|
||||
/*
|
||||
* No way to verify the MIC if the hardware stripped it
|
||||
*/
|
||||
if (rx->u.rx.status->flag & RX_FLAG_MMIC_STRIPPED)
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
if (!rx->key || rx->key->conf.alg != ALG_TKIP ||
|
||||
!(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
if (ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len)
|
||||
|| data_len < MICHAEL_MIC_LEN)
|
||||
return TXRX_DROP;
|
||||
|
||||
data_len -= MICHAEL_MIC_LEN;
|
||||
|
||||
#if 0
|
||||
authenticator = fc & IEEE80211_FCTL_TODS; /* FIX */
|
||||
#else
|
||||
authenticator = 1;
|
||||
#endif
|
||||
key = &rx->key->conf.key[authenticator ? ALG_TKIP_TEMP_AUTH_RX_MIC_KEY :
|
||||
ALG_TKIP_TEMP_AUTH_TX_MIC_KEY];
|
||||
michael_mic(key, da, sa, qos_tid & 0x0f, data, data_len, mic);
|
||||
if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
|
||||
if (!(rx->flags & IEEE80211_TXRXD_RXRA_MATCH))
|
||||
return TXRX_DROP;
|
||||
|
||||
printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from "
|
||||
MAC_FMT "\n", rx->dev->name, MAC_ARG(sa));
|
||||
|
||||
mac80211_ev_michael_mic_failure(rx->dev, rx->key->conf.keyidx,
|
||||
(void *) skb->data);
|
||||
return TXRX_DROP;
|
||||
}
|
||||
|
||||
/* remove Michael MIC from payload */
|
||||
skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
|
||||
|
||||
/* update IV in key information to be able to detect replays */
|
||||
rx->key->u.tkip.iv32_rx[rx->u.rx.queue] = rx->u.rx.tkip_iv32;
|
||||
rx->key->u.tkip.iv16_rx[rx->u.rx.queue] = rx->u.rx.tkip_iv16;
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
static int tkip_encrypt_skb(struct ieee80211_txrx_data *tx,
|
||||
struct sk_buff *skb, int test)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
struct ieee80211_key *key = tx->key;
|
||||
int hdrlen, len, tailneed;
|
||||
u16 fc;
|
||||
u8 *pos;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
len = skb->len - hdrlen;
|
||||
|
||||
if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
|
||||
tailneed = 0;
|
||||
else
|
||||
tailneed = TKIP_ICV_LEN;
|
||||
|
||||
if ((skb_headroom(skb) < TKIP_IV_LEN ||
|
||||
skb_tailroom(skb) < tailneed)) {
|
||||
I802_DEBUG_INC(tx->local->tx_expand_skb_head);
|
||||
if (unlikely(pskb_expand_head(skb, TKIP_IV_LEN, tailneed,
|
||||
GFP_ATOMIC)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
pos = skb_push(skb, TKIP_IV_LEN);
|
||||
memmove(pos, pos + TKIP_IV_LEN, hdrlen);
|
||||
pos += hdrlen;
|
||||
|
||||
/* Increase IV for the frame */
|
||||
key->u.tkip.iv16++;
|
||||
if (key->u.tkip.iv16 == 0)
|
||||
key->u.tkip.iv32++;
|
||||
|
||||
if (tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
|
||||
hdr = (struct ieee80211_hdr *)skb->data;
|
||||
|
||||
/* hwaccel - with preallocated room for IV */
|
||||
ieee80211_tkip_add_iv(pos, key,
|
||||
(u8) (key->u.tkip.iv16 >> 8),
|
||||
(u8) (((key->u.tkip.iv16 >> 8) | 0x20) &
|
||||
0x7f),
|
||||
(u8) key->u.tkip.iv16);
|
||||
|
||||
tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Add room for ICV */
|
||||
skb_put(skb, TKIP_ICV_LEN);
|
||||
|
||||
hdr = (struct ieee80211_hdr *) skb->data;
|
||||
ieee80211_tkip_encrypt_data(tx->local->wep_tx_tfm,
|
||||
key, pos, len, hdr->addr2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_tkip_encrypt(struct ieee80211_txrx_data *tx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
|
||||
u16 fc;
|
||||
struct sk_buff *skb = tx->skb;
|
||||
int wpa_test = 0, test = 0;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
if (!WLAN_FC_DATA_PRESENT(fc))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
tx->u.tx.control->icv_len = TKIP_ICV_LEN;
|
||||
tx->u.tx.control->iv_len = TKIP_IV_LEN;
|
||||
ieee80211_tx_set_iswep(tx);
|
||||
|
||||
if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
|
||||
!(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV) &&
|
||||
!wpa_test) {
|
||||
/* hwaccel - with no need for preallocated room for IV/ICV */
|
||||
tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
if (tkip_encrypt_skb(tx, skb, test) < 0)
|
||||
return TXRX_DROP;
|
||||
|
||||
if (tx->u.tx.extra_frag) {
|
||||
int i;
|
||||
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
|
||||
if (tkip_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
|
||||
< 0)
|
||||
return TXRX_DROP;
|
||||
}
|
||||
}
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
|
||||
u16 fc;
|
||||
int hdrlen, res, hwaccel = 0, wpa_test = 0;
|
||||
struct ieee80211_key *key = rx->key;
|
||||
struct sk_buff *skb = rx->skb;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
|
||||
if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
if (!rx->sta || skb->len - hdrlen < 12)
|
||||
return TXRX_DROP;
|
||||
|
||||
if (rx->u.rx.status->flag & RX_FLAG_DECRYPTED) {
|
||||
if (rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED) {
|
||||
/*
|
||||
* Hardware took care of all processing, including
|
||||
* replay protection, and stripped the ICV/IV so
|
||||
* we cannot do any checks here.
|
||||
*/
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
/* let TKIP code verify IV, but skip decryption */
|
||||
hwaccel = 1;
|
||||
}
|
||||
|
||||
res = ieee80211_tkip_decrypt_data(rx->local->wep_rx_tfm,
|
||||
key, skb->data + hdrlen,
|
||||
skb->len - hdrlen, rx->sta->addr,
|
||||
hwaccel, rx->u.rx.queue,
|
||||
&rx->u.rx.tkip_iv32,
|
||||
&rx->u.rx.tkip_iv16);
|
||||
if (res != TKIP_DECRYPT_OK || wpa_test) {
|
||||
printk(KERN_DEBUG "%s: TKIP decrypt failed for RX frame from "
|
||||
MAC_FMT " (res=%d)\n",
|
||||
rx->dev->name, MAC_ARG(rx->sta->addr), res);
|
||||
return TXRX_DROP;
|
||||
}
|
||||
|
||||
/* Trim ICV */
|
||||
skb_trim(skb, skb->len - TKIP_ICV_LEN);
|
||||
|
||||
/* Remove IV */
|
||||
memmove(skb->data + TKIP_IV_LEN, skb->data, hdrlen);
|
||||
skb_pull(skb, TKIP_IV_LEN);
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad,
|
||||
int encrypted)
|
||||
{
|
||||
u16 fc;
|
||||
int a4_included, qos_included;
|
||||
u8 qos_tid, *fc_pos, *data, *sa, *da;
|
||||
int len_a;
|
||||
size_t data_len;
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
|
||||
fc_pos = (u8 *) &hdr->frame_control;
|
||||
fc = fc_pos[0] ^ (fc_pos[1] << 8);
|
||||
a4_included = (fc & (IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS)) ==
|
||||
(IEEE80211_FCTL_TODS | IEEE80211_FCTL_FROMDS);
|
||||
|
||||
ieee80211_get_hdr_info(skb, &sa, &da, &qos_tid, &data, &data_len);
|
||||
data_len -= CCMP_HDR_LEN + (encrypted ? CCMP_MIC_LEN : 0);
|
||||
if (qos_tid & 0x80) {
|
||||
qos_included = 1;
|
||||
qos_tid &= 0x0f;
|
||||
} else
|
||||
qos_included = 0;
|
||||
/* First block, b_0 */
|
||||
|
||||
b_0[0] = 0x59; /* flags: Adata: 1, M: 011, L: 001 */
|
||||
/* Nonce: QoS Priority | A2 | PN */
|
||||
b_0[1] = qos_tid;
|
||||
memcpy(&b_0[2], hdr->addr2, 6);
|
||||
memcpy(&b_0[8], pn, CCMP_PN_LEN);
|
||||
/* l(m) */
|
||||
b_0[14] = (data_len >> 8) & 0xff;
|
||||
b_0[15] = data_len & 0xff;
|
||||
|
||||
|
||||
/* AAD (extra authenticate-only data) / masked 802.11 header
|
||||
* FC | A1 | A2 | A3 | SC | [A4] | [QC] */
|
||||
|
||||
len_a = a4_included ? 28 : 22;
|
||||
if (qos_included)
|
||||
len_a += 2;
|
||||
|
||||
aad[0] = 0; /* (len_a >> 8) & 0xff; */
|
||||
aad[1] = len_a & 0xff;
|
||||
/* Mask FC: zero subtype b4 b5 b6 */
|
||||
aad[2] = fc_pos[0] & ~(BIT(4) | BIT(5) | BIT(6));
|
||||
/* Retry, PwrMgt, MoreData; set Protected */
|
||||
aad[3] = (fc_pos[1] & ~(BIT(3) | BIT(4) | BIT(5))) | BIT(6);
|
||||
memcpy(&aad[4], &hdr->addr1, 18);
|
||||
|
||||
/* Mask Seq#, leave Frag# */
|
||||
aad[22] = *((u8 *) &hdr->seq_ctrl) & 0x0f;
|
||||
aad[23] = 0;
|
||||
if (a4_included) {
|
||||
memcpy(&aad[24], hdr->addr4, 6);
|
||||
aad[30] = 0;
|
||||
aad[31] = 0;
|
||||
} else
|
||||
memset(&aad[24], 0, 8);
|
||||
if (qos_included) {
|
||||
u8 *dpos = &aad[a4_included ? 30 : 24];
|
||||
|
||||
/* Mask QoS Control field */
|
||||
dpos[0] = qos_tid;
|
||||
dpos[1] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static inline void ccmp_pn2hdr(u8 *hdr, u8 *pn, int key_id)
|
||||
{
|
||||
hdr[0] = pn[5];
|
||||
hdr[1] = pn[4];
|
||||
hdr[2] = 0;
|
||||
hdr[3] = 0x20 | (key_id << 6);
|
||||
hdr[4] = pn[3];
|
||||
hdr[5] = pn[2];
|
||||
hdr[6] = pn[1];
|
||||
hdr[7] = pn[0];
|
||||
}
|
||||
|
||||
|
||||
static inline int ccmp_hdr2pn(u8 *pn, u8 *hdr)
|
||||
{
|
||||
pn[0] = hdr[7];
|
||||
pn[1] = hdr[6];
|
||||
pn[2] = hdr[5];
|
||||
pn[3] = hdr[4];
|
||||
pn[4] = hdr[1];
|
||||
pn[5] = hdr[0];
|
||||
return (hdr[3] >> 6) & 0x03;
|
||||
}
|
||||
|
||||
|
||||
static int ccmp_encrypt_skb(struct ieee80211_txrx_data *tx,
|
||||
struct sk_buff *skb, int test)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
struct ieee80211_key *key = tx->key;
|
||||
int hdrlen, len, tailneed;
|
||||
u16 fc;
|
||||
u8 *pos, *pn, *b_0, *aad, *scratch;
|
||||
int i;
|
||||
|
||||
scratch = key->u.ccmp.tx_crypto_buf;
|
||||
b_0 = scratch + 3 * AES_BLOCK_LEN;
|
||||
aad = scratch + 4 * AES_BLOCK_LEN;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
len = skb->len - hdrlen;
|
||||
|
||||
if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
|
||||
tailneed = 0;
|
||||
else
|
||||
tailneed = CCMP_MIC_LEN;
|
||||
|
||||
if ((skb_headroom(skb) < CCMP_HDR_LEN ||
|
||||
skb_tailroom(skb) < tailneed)) {
|
||||
I802_DEBUG_INC(tx->local->tx_expand_skb_head);
|
||||
if (unlikely(pskb_expand_head(skb, CCMP_HDR_LEN, tailneed,
|
||||
GFP_ATOMIC)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
pos = skb_push(skb, CCMP_HDR_LEN);
|
||||
memmove(pos, pos + CCMP_HDR_LEN, hdrlen);
|
||||
hdr = (struct ieee80211_hdr *) pos;
|
||||
pos += hdrlen;
|
||||
|
||||
/* PN = PN + 1 */
|
||||
pn = key->u.ccmp.tx_pn;
|
||||
|
||||
for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
|
||||
pn[i]++;
|
||||
if (pn[i])
|
||||
break;
|
||||
}
|
||||
|
||||
ccmp_pn2hdr(pos, pn, key->conf.keyidx);
|
||||
|
||||
if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) {
|
||||
/* hwaccel - with preallocated room for CCMP header */
|
||||
tx->u.tx.control->key_idx = key->conf.hw_key_idx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pos += CCMP_HDR_LEN;
|
||||
ccmp_special_blocks(skb, pn, b_0, aad, 0);
|
||||
ieee80211_aes_ccm_encrypt(key->u.ccmp.tfm, scratch, b_0, aad, pos, len,
|
||||
pos, skb_put(skb, CCMP_MIC_LEN));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_ccmp_encrypt(struct ieee80211_txrx_data *tx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
|
||||
u16 fc;
|
||||
struct sk_buff *skb = tx->skb;
|
||||
int test = 0;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
if (!WLAN_FC_DATA_PRESENT(fc))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
tx->u.tx.control->icv_len = CCMP_MIC_LEN;
|
||||
tx->u.tx.control->iv_len = CCMP_HDR_LEN;
|
||||
ieee80211_tx_set_iswep(tx);
|
||||
|
||||
if ((tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) &&
|
||||
!(tx->key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) {
|
||||
/* hwaccel - with no need for preallocated room for CCMP "
|
||||
* header or MIC fields */
|
||||
tx->u.tx.control->key_idx = tx->key->conf.hw_key_idx;
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
if (ccmp_encrypt_skb(tx, skb, test) < 0)
|
||||
return TXRX_DROP;
|
||||
|
||||
if (tx->u.tx.extra_frag) {
|
||||
int i;
|
||||
for (i = 0; i < tx->u.tx.num_extra_frag; i++) {
|
||||
if (ccmp_encrypt_skb(tx, tx->u.tx.extra_frag[i], test)
|
||||
< 0)
|
||||
return TXRX_DROP;
|
||||
}
|
||||
}
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) rx->skb->data;
|
||||
u16 fc;
|
||||
int hdrlen;
|
||||
struct ieee80211_key *key = rx->key;
|
||||
struct sk_buff *skb = rx->skb;
|
||||
u8 pn[CCMP_PN_LEN];
|
||||
int data_len;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
hdrlen = ieee80211_get_hdrlen(fc);
|
||||
|
||||
if ((rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
data_len = skb->len - hdrlen - CCMP_HDR_LEN - CCMP_MIC_LEN;
|
||||
if (!rx->sta || data_len < 0)
|
||||
return TXRX_DROP;
|
||||
|
||||
if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
|
||||
(rx->u.rx.status->flag & RX_FLAG_IV_STRIPPED))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
(void) ccmp_hdr2pn(pn, skb->data + hdrlen);
|
||||
|
||||
if (memcmp(pn, key->u.ccmp.rx_pn[rx->u.rx.queue], CCMP_PN_LEN) <= 0) {
|
||||
#ifdef CONFIG_MAC80211_DEBUG
|
||||
u8 *ppn = key->u.ccmp.rx_pn[rx->u.rx.queue];
|
||||
printk(KERN_DEBUG "%s: CCMP replay detected for RX frame from "
|
||||
MAC_FMT " (RX PN %02x%02x%02x%02x%02x%02x <= prev. PN "
|
||||
"%02x%02x%02x%02x%02x%02x)\n", rx->dev->name,
|
||||
MAC_ARG(rx->sta->addr),
|
||||
pn[0], pn[1], pn[2], pn[3], pn[4], pn[5],
|
||||
ppn[0], ppn[1], ppn[2], ppn[3], ppn[4], ppn[5]);
|
||||
#endif /* CONFIG_MAC80211_DEBUG */
|
||||
key->u.ccmp.replays++;
|
||||
return TXRX_DROP;
|
||||
}
|
||||
|
||||
if (!(rx->u.rx.status->flag & RX_FLAG_DECRYPTED)) {
|
||||
/* hardware didn't decrypt/verify MIC */
|
||||
u8 *scratch, *b_0, *aad;
|
||||
|
||||
scratch = key->u.ccmp.rx_crypto_buf;
|
||||
b_0 = scratch + 3 * AES_BLOCK_LEN;
|
||||
aad = scratch + 4 * AES_BLOCK_LEN;
|
||||
|
||||
ccmp_special_blocks(skb, pn, b_0, aad, 1);
|
||||
|
||||
if (ieee80211_aes_ccm_decrypt(
|
||||
key->u.ccmp.tfm, scratch, b_0, aad,
|
||||
skb->data + hdrlen + CCMP_HDR_LEN, data_len,
|
||||
skb->data + skb->len - CCMP_MIC_LEN,
|
||||
skb->data + hdrlen + CCMP_HDR_LEN)) {
|
||||
printk(KERN_DEBUG "%s: CCMP decrypt failed for RX "
|
||||
"frame from " MAC_FMT "\n", rx->dev->name,
|
||||
MAC_ARG(rx->sta->addr));
|
||||
return TXRX_DROP;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(key->u.ccmp.rx_pn[rx->u.rx.queue], pn, CCMP_PN_LEN);
|
||||
|
||||
/* Remove CCMP header and MIC */
|
||||
skb_trim(skb, skb->len - CCMP_MIC_LEN);
|
||||
memmove(skb->data + CCMP_HDR_LEN, skb->data, hdrlen);
|
||||
skb_pull(skb, CCMP_HDR_LEN);
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
31
package/mac80211/src/net/mac80211/wpa.h
Normal file
31
package/mac80211/src/net/mac80211/wpa.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2002-2004, Instant802 Networks, Inc.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef WPA_H
|
||||
#define WPA_H
|
||||
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/types.h>
|
||||
#include "ieee80211_i.h"
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_tx_h_michael_mic_add(struct ieee80211_txrx_data *tx);
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_michael_mic_verify(struct ieee80211_txrx_data *rx);
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_tkip_encrypt(struct ieee80211_txrx_data *tx);
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_tkip_decrypt(struct ieee80211_txrx_data *rx);
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_ccmp_encrypt(struct ieee80211_txrx_data *tx);
|
||||
ieee80211_txrx_result
|
||||
ieee80211_crypto_ccmp_decrypt(struct ieee80211_txrx_data *rx);
|
||||
|
||||
#endif /* WPA_H */
|
||||
31
package/mac80211/src/net/wireless/Kconfig
Normal file
31
package/mac80211/src/net/wireless/Kconfig
Normal file
@@ -0,0 +1,31 @@
|
||||
config CFG80211
|
||||
tristate "Improved wireless configuration API"
|
||||
|
||||
config NL80211
|
||||
bool "nl80211 new netlink interface support"
|
||||
depends CFG80211
|
||||
default y
|
||||
---help---
|
||||
This option turns on the new netlink interface
|
||||
(nl80211) support in cfg80211.
|
||||
|
||||
If =n, drivers using mac80211 will be configured via
|
||||
wireless extension support provided by that subsystem.
|
||||
|
||||
If unsure, say Y.
|
||||
|
||||
config WIRELESS_EXT
|
||||
bool "Wireless extensions"
|
||||
default n
|
||||
---help---
|
||||
This option enables the legacy wireless extensions
|
||||
(wireless network interface configuration via ioctls.)
|
||||
|
||||
Wireless extensions will be replaced by cfg80211 and
|
||||
will be required only by legacy drivers that implement
|
||||
wireless extension handlers. This option does not
|
||||
affect the wireless-extension backward compatibility
|
||||
code in cfg80211.
|
||||
|
||||
Say N (if you can) unless you know you need wireless
|
||||
extensions for external modules.
|
||||
4
package/mac80211/src/net/wireless/Makefile
Normal file
4
package/mac80211/src/net/wireless/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
obj-$(CONFIG_CFG80211) += cfg80211.o
|
||||
|
||||
cfg80211-y += core.o sysfs.o radiotap.o
|
||||
cfg80211-$(CONFIG_NL80211) += nl80211.o
|
||||
372
package/mac80211/src/net/wireless/core.c
Normal file
372
package/mac80211/src/net/wireless/core.c
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* This is the linux wireless configuration interface.
|
||||
*
|
||||
* Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*/
|
||||
|
||||
#include <linux/if.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/nl80211.h>
|
||||
#include <linux/debugfs.h>
|
||||
#include <linux/notifier.h>
|
||||
#include <linux/device.h>
|
||||
#include <net/genetlink.h>
|
||||
#include <net/cfg80211.h>
|
||||
#include <net/wireless.h>
|
||||
#include "nl80211.h"
|
||||
#include "core.h"
|
||||
#include "sysfs.h"
|
||||
|
||||
/* name for sysfs, %d is appended */
|
||||
#define PHY_NAME "phy"
|
||||
|
||||
MODULE_AUTHOR("Johannes Berg");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("wireless configuration support");
|
||||
|
||||
/* RCU might be appropriate here since we usually
|
||||
* only read the list, and that can happen quite
|
||||
* often because we need to do it for each command */
|
||||
LIST_HEAD(cfg80211_drv_list);
|
||||
DEFINE_MUTEX(cfg80211_drv_mutex);
|
||||
static int wiphy_counter;
|
||||
|
||||
/* for debugfs */
|
||||
static struct dentry *ieee80211_debugfs_dir;
|
||||
|
||||
/* requires cfg80211_drv_mutex to be held! */
|
||||
static struct cfg80211_registered_device *cfg80211_drv_by_wiphy(int wiphy)
|
||||
{
|
||||
struct cfg80211_registered_device *result = NULL, *drv;
|
||||
|
||||
list_for_each_entry(drv, &cfg80211_drv_list, list) {
|
||||
if (drv->idx == wiphy) {
|
||||
result = drv;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* requires cfg80211_drv_mutex to be held! */
|
||||
static struct cfg80211_registered_device *
|
||||
__cfg80211_drv_from_info(struct genl_info *info)
|
||||
{
|
||||
int ifindex;
|
||||
struct cfg80211_registered_device *bywiphy = NULL, *byifidx = NULL;
|
||||
struct net_device *dev;
|
||||
int err = -EINVAL;
|
||||
|
||||
if (info->attrs[NL80211_ATTR_WIPHY]) {
|
||||
bywiphy = cfg80211_drv_by_wiphy(
|
||||
nla_get_u32(info->attrs[NL80211_ATTR_WIPHY]));
|
||||
err = -ENODEV;
|
||||
}
|
||||
|
||||
if (info->attrs[NL80211_ATTR_IFINDEX]) {
|
||||
ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
|
||||
dev = dev_get_by_index(ifindex);
|
||||
if (dev) {
|
||||
if (dev->ieee80211_ptr)
|
||||
byifidx =
|
||||
wiphy_to_dev(dev->ieee80211_ptr->wiphy);
|
||||
dev_put(dev);
|
||||
}
|
||||
err = -ENODEV;
|
||||
}
|
||||
|
||||
if (bywiphy && byifidx) {
|
||||
if (bywiphy != byifidx)
|
||||
return ERR_PTR(-EINVAL);
|
||||
else
|
||||
return bywiphy; /* == byifidx */
|
||||
}
|
||||
if (bywiphy)
|
||||
return bywiphy;
|
||||
|
||||
if (byifidx)
|
||||
return byifidx;
|
||||
|
||||
return ERR_PTR(err);
|
||||
}
|
||||
|
||||
struct cfg80211_registered_device *
|
||||
cfg80211_get_dev_from_info(struct genl_info *info)
|
||||
{
|
||||
struct cfg80211_registered_device *drv;
|
||||
|
||||
mutex_lock(&cfg80211_drv_mutex);
|
||||
drv = __cfg80211_drv_from_info(info);
|
||||
|
||||
/* if it is not an error we grab the lock on
|
||||
* it to assure it won't be going away while
|
||||
* we operate on it */
|
||||
if (!IS_ERR(drv))
|
||||
mutex_lock(&drv->mtx);
|
||||
|
||||
mutex_unlock(&cfg80211_drv_mutex);
|
||||
|
||||
return drv;
|
||||
}
|
||||
|
||||
struct cfg80211_registered_device *
|
||||
cfg80211_get_dev_from_ifindex(int ifindex)
|
||||
{
|
||||
struct cfg80211_registered_device *drv = ERR_PTR(-ENODEV);
|
||||
struct net_device *dev;
|
||||
|
||||
mutex_lock(&cfg80211_drv_mutex);
|
||||
dev = dev_get_by_index(ifindex);
|
||||
if (!dev)
|
||||
goto out;
|
||||
if (dev->ieee80211_ptr) {
|
||||
drv = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
|
||||
mutex_lock(&drv->mtx);
|
||||
} else
|
||||
drv = ERR_PTR(-ENODEV);
|
||||
dev_put(dev);
|
||||
out:
|
||||
mutex_unlock(&cfg80211_drv_mutex);
|
||||
return drv;
|
||||
}
|
||||
|
||||
void cfg80211_put_dev(struct cfg80211_registered_device *drv)
|
||||
{
|
||||
BUG_ON(IS_ERR(drv));
|
||||
mutex_unlock(&drv->mtx);
|
||||
}
|
||||
|
||||
int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
|
||||
char *newname)
|
||||
{
|
||||
int idx, taken = -1, result, digits;
|
||||
|
||||
/* prohibit calling the thing phy%d when %d is not its number */
|
||||
sscanf(newname, PHY_NAME "%d%n", &idx, &taken);
|
||||
if (taken == strlen(newname) && idx != rdev->idx) {
|
||||
/* count number of places needed to print idx */
|
||||
digits = 1;
|
||||
while (idx /= 10)
|
||||
digits++;
|
||||
/*
|
||||
* deny the name if it is phy<idx> where <idx> is printed
|
||||
* without leading zeroes. taken == strlen(newname) here
|
||||
*/
|
||||
if (taken == strlen(PHY_NAME) + digits)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* this will check for collisions */
|
||||
result = device_rename(&rdev->wiphy.dev, newname);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
if (!debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
|
||||
rdev->wiphy.debugfsdir,
|
||||
rdev->wiphy.debugfsdir->d_parent,
|
||||
newname))
|
||||
printk(KERN_ERR "cfg80211: failed to rename debugfs dir to %s!\n",
|
||||
newname);
|
||||
|
||||
nl80211_notify_dev_rename(rdev);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* exported functions */
|
||||
|
||||
struct wiphy *wiphy_new(struct cfg80211_ops *ops, int sizeof_priv)
|
||||
{
|
||||
struct cfg80211_registered_device *drv;
|
||||
int alloc_size;
|
||||
|
||||
alloc_size = sizeof(*drv) + sizeof_priv;
|
||||
|
||||
drv = kzalloc(alloc_size, GFP_KERNEL);
|
||||
if (!drv)
|
||||
return NULL;
|
||||
|
||||
drv->ops = ops;
|
||||
|
||||
mutex_lock(&cfg80211_drv_mutex);
|
||||
|
||||
drv->idx = wiphy_counter;
|
||||
|
||||
/* now increase counter for the next device unless
|
||||
* it has wrapped previously */
|
||||
if (wiphy_counter >= 0)
|
||||
wiphy_counter++;
|
||||
|
||||
mutex_unlock(&cfg80211_drv_mutex);
|
||||
|
||||
if (unlikely(drv->idx < 0)) {
|
||||
/* ugh, wrapped! */
|
||||
kfree(drv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* give it a proper name */
|
||||
snprintf(drv->wiphy.dev.bus_id, BUS_ID_SIZE,
|
||||
PHY_NAME "%d", drv->idx);
|
||||
|
||||
mutex_init(&drv->mtx);
|
||||
mutex_init(&drv->devlist_mtx);
|
||||
INIT_LIST_HEAD(&drv->netdev_list);
|
||||
|
||||
device_initialize(&drv->wiphy.dev);
|
||||
drv->wiphy.dev.class = &ieee80211_class;
|
||||
drv->wiphy.dev.platform_data = drv;
|
||||
|
||||
return &drv->wiphy;
|
||||
}
|
||||
EXPORT_SYMBOL(wiphy_new);
|
||||
|
||||
int wiphy_register(struct wiphy *wiphy)
|
||||
{
|
||||
struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
|
||||
int res;
|
||||
|
||||
mutex_lock(&cfg80211_drv_mutex);
|
||||
|
||||
res = device_add(&drv->wiphy.dev);
|
||||
if (res)
|
||||
goto out_unlock;
|
||||
|
||||
list_add(&drv->list, &cfg80211_drv_list);
|
||||
|
||||
/* add to debugfs */
|
||||
drv->wiphy.debugfsdir =
|
||||
debugfs_create_dir(wiphy_name(&drv->wiphy),
|
||||
ieee80211_debugfs_dir);
|
||||
|
||||
res = 0;
|
||||
out_unlock:
|
||||
mutex_unlock(&cfg80211_drv_mutex);
|
||||
return res;
|
||||
}
|
||||
EXPORT_SYMBOL(wiphy_register);
|
||||
|
||||
void wiphy_unregister(struct wiphy *wiphy)
|
||||
{
|
||||
struct cfg80211_registered_device *drv = wiphy_to_dev(wiphy);
|
||||
|
||||
/* protect the device list */
|
||||
mutex_lock(&cfg80211_drv_mutex);
|
||||
|
||||
BUG_ON(!list_empty(&drv->netdev_list));
|
||||
|
||||
/*
|
||||
* Try to grab drv->mtx. If a command is still in progress,
|
||||
* hopefully the driver will refuse it since it's tearing
|
||||
* down the device already. We wait for this command to complete
|
||||
* before unlinking the item from the list.
|
||||
* Note: as codified by the BUG_ON above we cannot get here if
|
||||
* a virtual interface is still associated. Hence, we can only
|
||||
* get to lock contention here if userspace issues a command
|
||||
* that identified the hardware by wiphy index.
|
||||
*/
|
||||
mutex_lock(&drv->mtx);
|
||||
/* unlock again before freeing */
|
||||
mutex_unlock(&drv->mtx);
|
||||
|
||||
list_del(&drv->list);
|
||||
device_del(&drv->wiphy.dev);
|
||||
debugfs_remove(drv->wiphy.debugfsdir);
|
||||
|
||||
mutex_unlock(&cfg80211_drv_mutex);
|
||||
}
|
||||
EXPORT_SYMBOL(wiphy_unregister);
|
||||
|
||||
void cfg80211_dev_free(struct cfg80211_registered_device *drv)
|
||||
{
|
||||
mutex_destroy(&drv->mtx);
|
||||
mutex_destroy(&drv->devlist_mtx);
|
||||
kfree(drv);
|
||||
}
|
||||
|
||||
void wiphy_free(struct wiphy *wiphy)
|
||||
{
|
||||
put_device(&wiphy->dev);
|
||||
}
|
||||
EXPORT_SYMBOL(wiphy_free);
|
||||
|
||||
static int cfg80211_netdev_notifier_call(struct notifier_block * nb,
|
||||
unsigned long state,
|
||||
void *ndev)
|
||||
{
|
||||
struct net_device *dev = ndev;
|
||||
struct cfg80211_registered_device *rdev;
|
||||
|
||||
if (!dev->ieee80211_ptr)
|
||||
return 0;
|
||||
|
||||
rdev = wiphy_to_dev(dev->ieee80211_ptr->wiphy);
|
||||
|
||||
switch (state) {
|
||||
case NETDEV_REGISTER:
|
||||
mutex_lock(&rdev->devlist_mtx);
|
||||
list_add(&dev->ieee80211_ptr->list, &rdev->netdev_list);
|
||||
if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
|
||||
"phy80211")) {
|
||||
printk(KERN_ERR "wireless: failed to add phy80211 "
|
||||
"symlink to netdev!\n");
|
||||
}
|
||||
dev->ieee80211_ptr->netdev = dev;
|
||||
mutex_unlock(&rdev->devlist_mtx);
|
||||
break;
|
||||
case NETDEV_UNREGISTER:
|
||||
mutex_lock(&rdev->devlist_mtx);
|
||||
if (!list_empty(&dev->ieee80211_ptr->list)) {
|
||||
sysfs_remove_link(&dev->dev.kobj, "phy80211");
|
||||
list_del_init(&dev->ieee80211_ptr->list);
|
||||
}
|
||||
mutex_unlock(&rdev->devlist_mtx);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct notifier_block cfg80211_netdev_notifier = {
|
||||
.notifier_call = cfg80211_netdev_notifier_call,
|
||||
};
|
||||
|
||||
static int cfg80211_init(void)
|
||||
{
|
||||
int err = wiphy_sysfs_init();
|
||||
if (err)
|
||||
goto out_fail_sysfs;
|
||||
|
||||
err = register_netdevice_notifier(&cfg80211_netdev_notifier);
|
||||
if (err)
|
||||
goto out_fail_notifier;
|
||||
|
||||
err = nl80211_init();
|
||||
if (err)
|
||||
goto out_fail_nl80211;
|
||||
|
||||
ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL);
|
||||
|
||||
return 0;
|
||||
|
||||
out_fail_nl80211:
|
||||
unregister_netdevice_notifier(&cfg80211_netdev_notifier);
|
||||
out_fail_notifier:
|
||||
wiphy_sysfs_exit();
|
||||
out_fail_sysfs:
|
||||
return err;
|
||||
}
|
||||
subsys_initcall(cfg80211_init);
|
||||
|
||||
static void cfg80211_exit(void)
|
||||
{
|
||||
debugfs_remove(ieee80211_debugfs_dir);
|
||||
nl80211_exit();
|
||||
unregister_netdevice_notifier(&cfg80211_netdev_notifier);
|
||||
wiphy_sysfs_exit();
|
||||
}
|
||||
module_exit(cfg80211_exit);
|
||||
81
package/mac80211/src/net/wireless/core.h
Normal file
81
package/mac80211/src/net/wireless/core.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Wireless configuration interface internals.
|
||||
*
|
||||
* Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*/
|
||||
#ifndef __NET_WIRELESS_CORE_H
|
||||
#define __NET_WIRELESS_CORE_H
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <net/genetlink.h>
|
||||
#include <net/wireless.h>
|
||||
#include <net/cfg80211.h>
|
||||
|
||||
struct cfg80211_registered_device {
|
||||
struct cfg80211_ops *ops;
|
||||
struct list_head list;
|
||||
/* we hold this mutex during any call so that
|
||||
* we cannot do multiple calls at once, and also
|
||||
* to avoid the deregister call to proceed while
|
||||
* any call is in progress */
|
||||
struct mutex mtx;
|
||||
|
||||
/* wiphy index, internal only */
|
||||
int idx;
|
||||
|
||||
/* associate netdev list */
|
||||
struct mutex devlist_mtx;
|
||||
struct list_head netdev_list;
|
||||
|
||||
/* must be last because of the way we do wiphy_priv(),
|
||||
* and it should at least be aligned to NETDEV_ALIGN */
|
||||
struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN)));
|
||||
};
|
||||
|
||||
static inline
|
||||
struct cfg80211_registered_device *wiphy_to_dev(struct wiphy *wiphy)
|
||||
{
|
||||
BUG_ON(!wiphy);
|
||||
return container_of(wiphy, struct cfg80211_registered_device, wiphy);
|
||||
}
|
||||
|
||||
extern struct mutex cfg80211_drv_mutex;
|
||||
extern struct list_head cfg80211_drv_list;
|
||||
|
||||
/*
|
||||
* This function returns a pointer to the driver
|
||||
* that the genl_info item that is passed refers to.
|
||||
* If successful, it returns non-NULL and also locks
|
||||
* the driver's mutex!
|
||||
*
|
||||
* This means that you need to call cfg80211_put_dev()
|
||||
* before being allowed to acquire &cfg80211_drv_mutex!
|
||||
*
|
||||
* This is necessary because we need to lock the global
|
||||
* mutex to get an item off the list safely, and then
|
||||
* we lock the drv mutex so it doesn't go away under us.
|
||||
*
|
||||
* We don't want to keep cfg80211_drv_mutex locked
|
||||
* for all the time in order to allow requests on
|
||||
* other interfaces to go through at the same time.
|
||||
*
|
||||
* The result of this can be a PTR_ERR and hence must
|
||||
* be checked with IS_ERR() for errors.
|
||||
*/
|
||||
extern struct cfg80211_registered_device *
|
||||
cfg80211_get_dev_from_info(struct genl_info *info);
|
||||
|
||||
/* identical to cfg80211_get_dev_from_info but only operate on ifindex */
|
||||
extern struct cfg80211_registered_device *
|
||||
cfg80211_get_dev_from_ifindex(int ifindex);
|
||||
|
||||
extern void cfg80211_put_dev(struct cfg80211_registered_device *drv);
|
||||
|
||||
/* free object */
|
||||
extern void cfg80211_dev_free(struct cfg80211_registered_device *drv);
|
||||
|
||||
extern int cfg80211_dev_rename(struct cfg80211_registered_device *drv,
|
||||
char *newname);
|
||||
|
||||
#endif /* __NET_WIRELESS_CORE_H */
|
||||
431
package/mac80211/src/net/wireless/nl80211.c
Normal file
431
package/mac80211/src/net/wireless/nl80211.c
Normal file
@@ -0,0 +1,431 @@
|
||||
/*
|
||||
* This is the new netlink-based wireless configuration interface.
|
||||
*
|
||||
* Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
|
||||
*/
|
||||
|
||||
#include <linux/if.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/ieee80211.h>
|
||||
#include <linux/nl80211.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <net/genetlink.h>
|
||||
#include <net/cfg80211.h>
|
||||
#include "core.h"
|
||||
#include "nl80211.h"
|
||||
|
||||
/* the netlink family */
|
||||
static struct genl_family nl80211_fam = {
|
||||
.id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
|
||||
.name = "nl80211", /* have users key off the name instead */
|
||||
.hdrsize = 0, /* no private header */
|
||||
.version = 1, /* no particular meaning now */
|
||||
.maxattr = NL80211_ATTR_MAX,
|
||||
};
|
||||
|
||||
/* internal helper: get drv and dev */
|
||||
static int get_drv_dev_by_info_ifindex(struct genl_info *info,
|
||||
struct cfg80211_registered_device **drv,
|
||||
struct net_device **dev)
|
||||
{
|
||||
int ifindex;
|
||||
|
||||
if (!info->attrs[NL80211_ATTR_IFINDEX])
|
||||
return -EINVAL;
|
||||
|
||||
ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
|
||||
*dev = dev_get_by_index(ifindex);
|
||||
if (!*dev)
|
||||
return -ENODEV;
|
||||
|
||||
*drv = cfg80211_get_dev_from_ifindex(ifindex);
|
||||
if (IS_ERR(*drv)) {
|
||||
dev_put(*dev);
|
||||
return PTR_ERR(*drv);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* policy for the attributes */
|
||||
static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = {
|
||||
[NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
|
||||
[NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
|
||||
.len = BUS_ID_SIZE-1 },
|
||||
|
||||
[NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
|
||||
[NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
|
||||
[NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
|
||||
};
|
||||
|
||||
/* message building helper */
|
||||
static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
|
||||
int flags, u8 cmd)
|
||||
{
|
||||
/* since there is no private header just add the generic one */
|
||||
return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
|
||||
}
|
||||
|
||||
/* netlink command implementations */
|
||||
|
||||
static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
|
||||
struct cfg80211_registered_device *dev)
|
||||
{
|
||||
void *hdr;
|
||||
|
||||
hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
|
||||
if (!hdr)
|
||||
return -1;
|
||||
|
||||
NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->idx);
|
||||
NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
|
||||
return genlmsg_end(msg, hdr);
|
||||
|
||||
nla_put_failure:
|
||||
return genlmsg_cancel(msg, hdr);
|
||||
}
|
||||
|
||||
static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
|
||||
{
|
||||
int idx = 0;
|
||||
int start = cb->args[0];
|
||||
struct cfg80211_registered_device *dev;
|
||||
|
||||
mutex_lock(&cfg80211_drv_mutex);
|
||||
list_for_each_entry(dev, &cfg80211_drv_list, list) {
|
||||
if (++idx < start)
|
||||
continue;
|
||||
if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
|
||||
cb->nlh->nlmsg_seq, NLM_F_MULTI,
|
||||
dev) < 0)
|
||||
break;
|
||||
}
|
||||
mutex_unlock(&cfg80211_drv_mutex);
|
||||
|
||||
cb->args[0] = idx;
|
||||
|
||||
return skb->len;
|
||||
}
|
||||
|
||||
static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct sk_buff *msg;
|
||||
struct cfg80211_registered_device *dev;
|
||||
|
||||
dev = cfg80211_get_dev_from_info(info);
|
||||
if (IS_ERR(dev))
|
||||
return PTR_ERR(dev);
|
||||
|
||||
msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
|
||||
if (!msg)
|
||||
goto out_err;
|
||||
|
||||
if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
|
||||
goto out_free;
|
||||
|
||||
cfg80211_put_dev(dev);
|
||||
|
||||
return genlmsg_unicast(msg, info->snd_pid);
|
||||
|
||||
out_free:
|
||||
nlmsg_free(msg);
|
||||
out_err:
|
||||
cfg80211_put_dev(dev);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct cfg80211_registered_device *rdev;
|
||||
int result;
|
||||
|
||||
if (!info->attrs[NL80211_ATTR_WIPHY_NAME])
|
||||
return -EINVAL;
|
||||
|
||||
rdev = cfg80211_get_dev_from_info(info);
|
||||
if (IS_ERR(rdev))
|
||||
return PTR_ERR(rdev);
|
||||
|
||||
result = cfg80211_dev_rename(rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
|
||||
|
||||
cfg80211_put_dev(rdev);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
|
||||
struct net_device *dev)
|
||||
{
|
||||
void *hdr;
|
||||
|
||||
hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
|
||||
if (!hdr)
|
||||
return -1;
|
||||
|
||||
NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
|
||||
NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
|
||||
/* TODO: interface type */
|
||||
return genlmsg_end(msg, hdr);
|
||||
|
||||
nla_put_failure:
|
||||
return genlmsg_cancel(msg, hdr);
|
||||
}
|
||||
|
||||
static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
|
||||
{
|
||||
int wp_idx = 0;
|
||||
int if_idx = 0;
|
||||
int wp_start = cb->args[0];
|
||||
int if_start = cb->args[1];
|
||||
struct cfg80211_registered_device *dev;
|
||||
struct wireless_dev *wdev;
|
||||
|
||||
mutex_lock(&cfg80211_drv_mutex);
|
||||
list_for_each_entry(dev, &cfg80211_drv_list, list) {
|
||||
if (++wp_idx < wp_start)
|
||||
continue;
|
||||
if_idx = 0;
|
||||
|
||||
mutex_lock(&dev->devlist_mtx);
|
||||
list_for_each_entry(wdev, &dev->netdev_list, list) {
|
||||
if (++if_idx < if_start)
|
||||
continue;
|
||||
if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
|
||||
cb->nlh->nlmsg_seq, NLM_F_MULTI,
|
||||
wdev->netdev) < 0)
|
||||
break;
|
||||
}
|
||||
mutex_unlock(&dev->devlist_mtx);
|
||||
}
|
||||
mutex_unlock(&cfg80211_drv_mutex);
|
||||
|
||||
cb->args[0] = wp_idx;
|
||||
cb->args[1] = if_idx;
|
||||
|
||||
return skb->len;
|
||||
}
|
||||
|
||||
static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct sk_buff *msg;
|
||||
struct cfg80211_registered_device *dev;
|
||||
struct net_device *netdev;
|
||||
int err;
|
||||
|
||||
err = get_drv_dev_by_info_ifindex(info, &dev, &netdev);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
|
||||
if (!msg)
|
||||
goto out_err;
|
||||
|
||||
if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0)
|
||||
goto out_free;
|
||||
|
||||
dev_put(netdev);
|
||||
cfg80211_put_dev(dev);
|
||||
|
||||
return genlmsg_unicast(msg, info->snd_pid);
|
||||
|
||||
out_free:
|
||||
nlmsg_free(msg);
|
||||
out_err:
|
||||
dev_put(netdev);
|
||||
cfg80211_put_dev(dev);
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct cfg80211_registered_device *drv;
|
||||
int err, ifindex;
|
||||
enum nl80211_iftype type;
|
||||
struct net_device *dev;
|
||||
|
||||
if (info->attrs[NL80211_ATTR_IFTYPE]) {
|
||||
type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
|
||||
if (type > NL80211_IFTYPE_MAX)
|
||||
return -EINVAL;
|
||||
} else
|
||||
return -EINVAL;
|
||||
|
||||
err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
|
||||
if (err)
|
||||
return err;
|
||||
ifindex = dev->ifindex;
|
||||
dev_put(dev);
|
||||
|
||||
if (!drv->ops->change_virtual_intf) {
|
||||
err = -EOPNOTSUPP;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
rtnl_lock();
|
||||
err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, type);
|
||||
rtnl_unlock();
|
||||
|
||||
unlock:
|
||||
cfg80211_put_dev(drv);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct cfg80211_registered_device *drv;
|
||||
int err;
|
||||
enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
|
||||
|
||||
if (!info->attrs[NL80211_ATTR_IFNAME])
|
||||
return -EINVAL;
|
||||
|
||||
if (info->attrs[NL80211_ATTR_IFTYPE]) {
|
||||
type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
|
||||
if (type > NL80211_IFTYPE_MAX)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
drv = cfg80211_get_dev_from_info(info);
|
||||
if (IS_ERR(drv))
|
||||
return PTR_ERR(drv);
|
||||
|
||||
if (!drv->ops->add_virtual_intf) {
|
||||
err = -EOPNOTSUPP;
|
||||
goto unlock;
|
||||
}
|
||||
|
||||
rtnl_lock();
|
||||
err = drv->ops->add_virtual_intf(&drv->wiphy,
|
||||
nla_data(info->attrs[NL80211_ATTR_IFNAME]), type);
|
||||
rtnl_unlock();
|
||||
|
||||
unlock:
|
||||
cfg80211_put_dev(drv);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
|
||||
{
|
||||
struct cfg80211_registered_device *drv;
|
||||
int ifindex, err;
|
||||
struct net_device *dev;
|
||||
|
||||
err = get_drv_dev_by_info_ifindex(info, &drv, &dev);
|
||||
if (err)
|
||||
return err;
|
||||
ifindex = dev->ifindex;
|
||||
dev_put(dev);
|
||||
|
||||
if (!drv->ops->del_virtual_intf) {
|
||||
err = -EOPNOTSUPP;
|
||||
goto out;
|
||||
}
|
||||
|
||||
rtnl_lock();
|
||||
err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
|
||||
rtnl_unlock();
|
||||
|
||||
out:
|
||||
cfg80211_put_dev(drv);
|
||||
return err;
|
||||
}
|
||||
|
||||
static struct genl_ops nl80211_ops[] = {
|
||||
{
|
||||
.cmd = NL80211_CMD_GET_WIPHY,
|
||||
.doit = nl80211_get_wiphy,
|
||||
.dumpit = nl80211_dump_wiphy,
|
||||
.policy = nl80211_policy,
|
||||
/* can be retrieved by unprivileged users */
|
||||
},
|
||||
{
|
||||
.cmd = NL80211_CMD_SET_WIPHY,
|
||||
.doit = nl80211_set_wiphy,
|
||||
.policy = nl80211_policy,
|
||||
.flags = GENL_ADMIN_PERM,
|
||||
},
|
||||
{
|
||||
.cmd = NL80211_CMD_GET_INTERFACE,
|
||||
.doit = nl80211_get_interface,
|
||||
.dumpit = nl80211_dump_interface,
|
||||
.policy = nl80211_policy,
|
||||
/* can be retrieved by unprivileged users */
|
||||
},
|
||||
{
|
||||
.cmd = NL80211_CMD_SET_INTERFACE,
|
||||
.doit = nl80211_set_interface,
|
||||
.policy = nl80211_policy,
|
||||
.flags = GENL_ADMIN_PERM,
|
||||
},
|
||||
{
|
||||
.cmd = NL80211_CMD_NEW_INTERFACE,
|
||||
.doit = nl80211_new_interface,
|
||||
.policy = nl80211_policy,
|
||||
.flags = GENL_ADMIN_PERM,
|
||||
},
|
||||
{
|
||||
.cmd = NL80211_CMD_DEL_INTERFACE,
|
||||
.doit = nl80211_del_interface,
|
||||
.policy = nl80211_policy,
|
||||
.flags = GENL_ADMIN_PERM,
|
||||
},
|
||||
};
|
||||
|
||||
/* multicast groups */
|
||||
static struct genl_multicast_group nl80211_config_mcgrp = {
|
||||
.name = "config",
|
||||
};
|
||||
|
||||
/* notification functions */
|
||||
|
||||
void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
|
||||
{
|
||||
struct sk_buff *msg;
|
||||
|
||||
msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
|
||||
nlmsg_free(msg);
|
||||
return;
|
||||
}
|
||||
|
||||
genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
|
||||
}
|
||||
|
||||
/* initialisation/exit functions */
|
||||
|
||||
int nl80211_init(void)
|
||||
{
|
||||
int err, i;
|
||||
|
||||
err = genl_register_family(&nl80211_fam);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
|
||||
err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
|
||||
if (err)
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
|
||||
if (err)
|
||||
goto err_out;
|
||||
|
||||
return 0;
|
||||
err_out:
|
||||
genl_unregister_family(&nl80211_fam);
|
||||
return err;
|
||||
}
|
||||
|
||||
void nl80211_exit(void)
|
||||
{
|
||||
genl_unregister_family(&nl80211_fam);
|
||||
}
|
||||
24
package/mac80211/src/net/wireless/nl80211.h
Normal file
24
package/mac80211/src/net/wireless/nl80211.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef __NET_WIRELESS_NL80211_H
|
||||
#define __NET_WIRELESS_NL80211_H
|
||||
|
||||
#include "core.h"
|
||||
|
||||
#ifdef CONFIG_NL80211
|
||||
extern int nl80211_init(void);
|
||||
extern void nl80211_exit(void);
|
||||
extern void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev);
|
||||
#else
|
||||
static inline int nl80211_init(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
static inline void nl80211_exit(void)
|
||||
{
|
||||
}
|
||||
static inline void nl80211_notify_dev_rename(
|
||||
struct cfg80211_registered_device *rdev)
|
||||
{
|
||||
}
|
||||
#endif /* CONFIG_NL80211 */
|
||||
|
||||
#endif /* __NET_WIRELESS_NL80211_H */
|
||||
261
package/mac80211/src/net/wireless/radiotap.c
Normal file
261
package/mac80211/src/net/wireless/radiotap.c
Normal file
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Radiotap parser
|
||||
*
|
||||
* Copyright 2007 Andy Green <andy@warmcat.com>
|
||||
*/
|
||||
|
||||
#include <net/cfg80211.h>
|
||||
#include <net/ieee80211_radiotap.h>
|
||||
#include <asm/unaligned.h>
|
||||
|
||||
/* function prototypes and related defs are in include/net/cfg80211.h */
|
||||
|
||||
/**
|
||||
* ieee80211_radiotap_iterator_init - radiotap parser iterator initialization
|
||||
* @iterator: radiotap_iterator to initialize
|
||||
* @radiotap_header: radiotap header to parse
|
||||
* @max_length: total length we can parse into (eg, whole packet length)
|
||||
*
|
||||
* Returns: 0 or a negative error code if there is a problem.
|
||||
*
|
||||
* This function initializes an opaque iterator struct which can then
|
||||
* be passed to ieee80211_radiotap_iterator_next() to visit every radiotap
|
||||
* argument which is present in the header. It knows about extended
|
||||
* present headers and handles them.
|
||||
*
|
||||
* How to use:
|
||||
* call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
|
||||
* struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
|
||||
* checking for a good 0 return code. Then loop calling
|
||||
* __ieee80211_radiotap_iterator_next()... it returns either 0,
|
||||
* -ENOENT if there are no more args to parse, or -EINVAL if there is a problem.
|
||||
* The iterator's @this_arg member points to the start of the argument
|
||||
* associated with the current argument index that is present, which can be
|
||||
* found in the iterator's @this_arg_index member. This arg index corresponds
|
||||
* to the IEEE80211_RADIOTAP_... defines.
|
||||
*
|
||||
* Radiotap header length:
|
||||
* You can find the CPU-endian total radiotap header length in
|
||||
* iterator->max_length after executing ieee80211_radiotap_iterator_init()
|
||||
* successfully.
|
||||
*
|
||||
* Alignment Gotcha:
|
||||
* You must take care when dereferencing iterator.this_arg
|
||||
* for multibyte types... the pointer is not aligned. Use
|
||||
* get_unaligned((type *)iterator.this_arg) to dereference
|
||||
* iterator.this_arg for type "type" safely on all arches.
|
||||
*
|
||||
* Example code:
|
||||
* See Documentation/networking/radiotap-headers.txt
|
||||
*/
|
||||
|
||||
int ieee80211_radiotap_iterator_init(
|
||||
struct ieee80211_radiotap_iterator *iterator,
|
||||
struct ieee80211_radiotap_header *radiotap_header,
|
||||
int max_length)
|
||||
{
|
||||
/* Linux only supports version 0 radiotap format */
|
||||
if (radiotap_header->it_version)
|
||||
return -EINVAL;
|
||||
|
||||
/* sanity check for allowed length and radiotap length field */
|
||||
if (max_length < le16_to_cpu(get_unaligned(&radiotap_header->it_len)))
|
||||
return -EINVAL;
|
||||
|
||||
iterator->rtheader = radiotap_header;
|
||||
iterator->max_length = le16_to_cpu(get_unaligned(
|
||||
&radiotap_header->it_len));
|
||||
iterator->arg_index = 0;
|
||||
iterator->bitmap_shifter = le32_to_cpu(get_unaligned(
|
||||
&radiotap_header->it_present));
|
||||
iterator->arg = (u8 *)radiotap_header + sizeof(*radiotap_header);
|
||||
iterator->this_arg = NULL;
|
||||
|
||||
/* find payload start allowing for extended bitmap(s) */
|
||||
|
||||
if (unlikely(iterator->bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT))) {
|
||||
while (le32_to_cpu(get_unaligned((__le32 *)iterator->arg)) &
|
||||
(1<<IEEE80211_RADIOTAP_EXT)) {
|
||||
iterator->arg += sizeof(u32);
|
||||
|
||||
/*
|
||||
* check for insanity where the present bitmaps
|
||||
* keep claiming to extend up to or even beyond the
|
||||
* stated radiotap header length
|
||||
*/
|
||||
|
||||
if (((ulong)iterator->arg -
|
||||
(ulong)iterator->rtheader) > iterator->max_length)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
iterator->arg += sizeof(u32);
|
||||
|
||||
/*
|
||||
* no need to check again for blowing past stated radiotap
|
||||
* header length, because ieee80211_radiotap_iterator_next
|
||||
* checks it before it is dereferenced
|
||||
*/
|
||||
}
|
||||
|
||||
/* we are all initialized happily */
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_radiotap_iterator_init);
|
||||
|
||||
|
||||
/**
|
||||
* ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
|
||||
* @iterator: radiotap_iterator to move to next arg (if any)
|
||||
*
|
||||
* Returns: 0 if there is an argument to handle,
|
||||
* -ENOENT if there are no more args or -EINVAL
|
||||
* if there is something else wrong.
|
||||
*
|
||||
* This function provides the next radiotap arg index (IEEE80211_RADIOTAP_*)
|
||||
* in @this_arg_index and sets @this_arg to point to the
|
||||
* payload for the field. It takes care of alignment handling and extended
|
||||
* present fields. @this_arg can be changed by the caller (eg,
|
||||
* incremented to move inside a compound argument like
|
||||
* IEEE80211_RADIOTAP_CHANNEL). The args pointed to are in
|
||||
* little-endian format whatever the endianess of your CPU.
|
||||
*
|
||||
* Alignment Gotcha:
|
||||
* You must take care when dereferencing iterator.this_arg
|
||||
* for multibyte types... the pointer is not aligned. Use
|
||||
* get_unaligned((type *)iterator.this_arg) to dereference
|
||||
* iterator.this_arg for type "type" safely on all arches.
|
||||
*/
|
||||
|
||||
int ieee80211_radiotap_iterator_next(
|
||||
struct ieee80211_radiotap_iterator *iterator)
|
||||
{
|
||||
|
||||
/*
|
||||
* small length lookup table for all radiotap types we heard of
|
||||
* starting from b0 in the bitmap, so we can walk the payload
|
||||
* area of the radiotap header
|
||||
*
|
||||
* There is a requirement to pad args, so that args
|
||||
* of a given length must begin at a boundary of that length
|
||||
* -- but note that compound args are allowed (eg, 2 x u16
|
||||
* for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
|
||||
* a reliable indicator of alignment requirement.
|
||||
*
|
||||
* upper nybble: content alignment for arg
|
||||
* lower nybble: content length for arg
|
||||
*/
|
||||
|
||||
static const u8 rt_sizes[] = {
|
||||
[IEEE80211_RADIOTAP_TSFT] = 0x88,
|
||||
[IEEE80211_RADIOTAP_FLAGS] = 0x11,
|
||||
[IEEE80211_RADIOTAP_RATE] = 0x11,
|
||||
[IEEE80211_RADIOTAP_CHANNEL] = 0x24,
|
||||
[IEEE80211_RADIOTAP_FHSS] = 0x22,
|
||||
[IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
|
||||
[IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
|
||||
[IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
|
||||
[IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
|
||||
[IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
|
||||
[IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
|
||||
[IEEE80211_RADIOTAP_ANTENNA] = 0x11,
|
||||
[IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
|
||||
[IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
|
||||
[IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
|
||||
[IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
|
||||
[IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
|
||||
[IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11,
|
||||
/*
|
||||
* add more here as they are defined in
|
||||
* include/net/ieee80211_radiotap.h
|
||||
*/
|
||||
};
|
||||
|
||||
/*
|
||||
* for every radiotap entry we can at
|
||||
* least skip (by knowing the length)...
|
||||
*/
|
||||
|
||||
while (iterator->arg_index < sizeof(rt_sizes)) {
|
||||
int hit = 0;
|
||||
int pad;
|
||||
|
||||
if (!(iterator->bitmap_shifter & 1))
|
||||
goto next_entry; /* arg not present */
|
||||
|
||||
/*
|
||||
* arg is present, account for alignment padding
|
||||
* 8-bit args can be at any alignment
|
||||
* 16-bit args must start on 16-bit boundary
|
||||
* 32-bit args must start on 32-bit boundary
|
||||
* 64-bit args must start on 64-bit boundary
|
||||
*
|
||||
* note that total arg size can differ from alignment of
|
||||
* elements inside arg, so we use upper nybble of length
|
||||
* table to base alignment on
|
||||
*
|
||||
* also note: these alignments are ** relative to the
|
||||
* start of the radiotap header **. There is no guarantee
|
||||
* that the radiotap header itself is aligned on any
|
||||
* kind of boundary.
|
||||
*
|
||||
* the above is why get_unaligned() is used to dereference
|
||||
* multibyte elements from the radiotap area
|
||||
*/
|
||||
|
||||
pad = (((ulong)iterator->arg) -
|
||||
((ulong)iterator->rtheader)) &
|
||||
((rt_sizes[iterator->arg_index] >> 4) - 1);
|
||||
|
||||
if (pad)
|
||||
iterator->arg +=
|
||||
(rt_sizes[iterator->arg_index] >> 4) - pad;
|
||||
|
||||
/*
|
||||
* this is what we will return to user, but we need to
|
||||
* move on first so next call has something fresh to test
|
||||
*/
|
||||
iterator->this_arg_index = iterator->arg_index;
|
||||
iterator->this_arg = iterator->arg;
|
||||
hit = 1;
|
||||
|
||||
/* internally move on the size of this arg */
|
||||
iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
|
||||
|
||||
/*
|
||||
* check for insanity where we are given a bitmap that
|
||||
* claims to have more arg content than the length of the
|
||||
* radiotap section. We will normally end up equalling this
|
||||
* max_length on the last arg, never exceeding it.
|
||||
*/
|
||||
|
||||
if (((ulong)iterator->arg - (ulong)iterator->rtheader) >
|
||||
iterator->max_length)
|
||||
return -EINVAL;
|
||||
|
||||
next_entry:
|
||||
iterator->arg_index++;
|
||||
if (unlikely((iterator->arg_index & 31) == 0)) {
|
||||
/* completed current u32 bitmap */
|
||||
if (iterator->bitmap_shifter & 1) {
|
||||
/* b31 was set, there is more */
|
||||
/* move to next u32 bitmap */
|
||||
iterator->bitmap_shifter = le32_to_cpu(
|
||||
get_unaligned(iterator->next_bitmap));
|
||||
iterator->next_bitmap++;
|
||||
} else
|
||||
/* no more bitmaps: end */
|
||||
iterator->arg_index = sizeof(rt_sizes);
|
||||
} else /* just try the next bit */
|
||||
iterator->bitmap_shifter >>= 1;
|
||||
|
||||
/* if we found a valid arg earlier, return it now */
|
||||
if (hit)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* we don't know how to handle any more args, we're done */
|
||||
return -ENOENT;
|
||||
}
|
||||
EXPORT_SYMBOL(ieee80211_radiotap_iterator_next);
|
||||
82
package/mac80211/src/net/wireless/sysfs.c
Normal file
82
package/mac80211/src/net/wireless/sysfs.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file provides /sys/class/ieee80211/<wiphy name>/
|
||||
* and some default attributes.
|
||||
*
|
||||
* Copyright 2005-2006 Jiri Benc <jbenc@suse.cz>
|
||||
* Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
|
||||
*
|
||||
* This file is GPLv2 as found in COPYING.
|
||||
*/
|
||||
|
||||
#include <linux/device.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/nl80211.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <net/cfg80211.h>
|
||||
#include "sysfs.h"
|
||||
#include "core.h"
|
||||
|
||||
static inline struct cfg80211_registered_device *dev_to_rdev(
|
||||
struct device *dev)
|
||||
{
|
||||
return container_of(dev, struct cfg80211_registered_device, wiphy.dev);
|
||||
}
|
||||
|
||||
static ssize_t _show_index(struct device *dev, struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", dev_to_rdev(dev)->idx);
|
||||
}
|
||||
|
||||
static ssize_t _show_permaddr(struct device *dev,
|
||||
struct device_attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
unsigned char *addr = dev_to_rdev(dev)->wiphy.perm_addr;
|
||||
|
||||
return sprintf(buf, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n",
|
||||
addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
|
||||
}
|
||||
|
||||
static struct device_attribute ieee80211_dev_attrs[] = {
|
||||
__ATTR(index, S_IRUGO, _show_index, NULL),
|
||||
__ATTR(macaddress, S_IRUGO, _show_permaddr, NULL),
|
||||
{}
|
||||
};
|
||||
|
||||
static void wiphy_dev_release(struct device *dev)
|
||||
{
|
||||
struct cfg80211_registered_device *rdev = dev_to_rdev(dev);
|
||||
|
||||
cfg80211_dev_free(rdev);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HOTPLUG
|
||||
static int wiphy_uevent(struct device *dev, char **envp,
|
||||
int num_envp, char *buf, int size)
|
||||
{
|
||||
/* TODO, we probably need stuff here */
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
struct class ieee80211_class = {
|
||||
.name = "ieee80211",
|
||||
.owner = THIS_MODULE,
|
||||
.dev_release = wiphy_dev_release,
|
||||
.dev_attrs = ieee80211_dev_attrs,
|
||||
#ifdef CONFIG_HOTPLUG
|
||||
.dev_uevent = wiphy_uevent,
|
||||
#endif
|
||||
};
|
||||
|
||||
int wiphy_sysfs_init(void)
|
||||
{
|
||||
return class_register(&ieee80211_class);
|
||||
}
|
||||
|
||||
void wiphy_sysfs_exit(void)
|
||||
{
|
||||
class_unregister(&ieee80211_class);
|
||||
}
|
||||
9
package/mac80211/src/net/wireless/sysfs.h
Normal file
9
package/mac80211/src/net/wireless/sysfs.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef __WIRELESS_SYSFS_H
|
||||
#define __WIRELESS_SYSFS_H
|
||||
|
||||
extern int wiphy_sysfs_init(void);
|
||||
extern void wiphy_sysfs_exit(void);
|
||||
|
||||
extern struct class ieee80211_class;
|
||||
|
||||
#endif /* __WIRELESS_SYSFS_H */
|
||||
Reference in New Issue
Block a user