add d80211 from a recent wireless-dev checkout
SVN-Revision: 5939
This commit is contained in:
parent
f9d5bdd6f3
commit
c8fea8d380
38 changed files with 20054 additions and 0 deletions
52
package/d80211/Makefile
Normal file
52
package/d80211/Makefile
Normal file
|
@ -0,0 +1,52 @@
|
|||
#
|
||||
# Copyright (C) 2006 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
# $Id:$
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=kmod-d80211
|
||||
PKG_VERSION:=20061230
|
||||
|
||||
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define KernelPackage/d80211
|
||||
SUBMENU:=Wireless Drivers
|
||||
DEPENDS:=@LINUX_2_6 kmod-crypto
|
||||
TITLE:=DeviceScape 802.11 stack
|
||||
DESCRIPTION:=DeviceScape 802.11 stack
|
||||
VERSION:=$(LINUX_VERSION)+$(PKG_VERSION)-$(BOARD)-$(LINUX_RELEASE)
|
||||
FILES:=$(PKG_BUILD_DIR)/*.ko
|
||||
AUTOLOAD:=$(call AutoLoad,20,d80211 rc80211_simple)
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
$(CP) ./src/* $(PKG_BUILD_DIR)/
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(MAKE) -C "$(LINUX_DIR)" \
|
||||
CROSS_COMPILE="$(TARGET_CROSS)" \
|
||||
ARCH="$(LINUX_KARCH)" \
|
||||
SUBDIRS="$(PKG_BUILD_DIR)" \
|
||||
EXTRA_CFLAGS="-I$(PKG_BUILD_DIR)/include" \
|
||||
modules
|
||||
endef
|
||||
|
||||
define Build/InstallDev
|
||||
mkdir -p $(STAGING_DIR)/usr/include/net
|
||||
$(CP) ./src/include/net/* $(STAGING_DIR)/usr/include/net/
|
||||
endef
|
||||
|
||||
define Build/UninstallDev
|
||||
rm -f $(STAGING_DIR)/usr/include/net/d80211*
|
||||
endef
|
||||
|
||||
$(eval $(call KernelPackage,d80211))
|
69
package/d80211/src/Kconfig
Normal file
69
package/d80211/src/Kconfig
Normal file
|
@ -0,0 +1,69 @@
|
|||
config D80211
|
||||
tristate "Generic IEEE 802.11 Networking Stack (dscape)"
|
||||
select CRYPTO
|
||||
select CRYPTO_ARC4
|
||||
select CRYPTO_AES
|
||||
---help---
|
||||
This option enables the hardware independent IEEE 802.11
|
||||
networking stack.
|
||||
|
||||
config D80211_LEDS
|
||||
bool "Enable LED triggers"
|
||||
depends on D80211
|
||||
select NEW_LEDS
|
||||
select LEDS_TRIGGERS
|
||||
---help---
|
||||
This option enables a few LED triggers for different
|
||||
packet receive/transmit events.
|
||||
|
||||
config D80211_DEBUG
|
||||
bool "Enable debugging output"
|
||||
depends on D80211
|
||||
---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 D80211_VERBOSE_DEBUG
|
||||
bool "Verbose debugging output"
|
||||
depends on D80211_DEBUG
|
||||
|
||||
config D80211_LOWTX_FRAME_DUMP
|
||||
bool "Debug frame dumping"
|
||||
depends on D80211_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 D80211_DEBUG
|
||||
|
||||
config D80211_DEBUG_COUNTERS
|
||||
bool "Extra statistics for TX/RX debugging"
|
||||
depends on D80211_DEBUG
|
||||
|
||||
config HOSTAPD_WPA_TESTING
|
||||
bool "Support for TKIP countermeasures testing"
|
||||
depends on D80211_DEBUG
|
||||
|
||||
config D80211_IBSS_DEBUG
|
||||
bool "Support for IBSS testing"
|
||||
depends on D80211_DEBUG
|
||||
---help---
|
||||
Say Y here if you intend to debug the IBSS code.
|
||||
|
||||
config D80211_VERBOSE_PS_DEBUG
|
||||
bool "Verbose powersave mode debugging"
|
||||
depends on D80211_DEBUG
|
||||
---help---
|
||||
Say Y here to print out verbose powersave
|
||||
mode debug messages.
|
20
package/d80211/src/Makefile
Normal file
20
package/d80211/src/Makefile
Normal file
|
@ -0,0 +1,20 @@
|
|||
obj-m += 80211.o rc80211_simple.o
|
||||
|
||||
80211-objs := \
|
||||
ieee80211.o \
|
||||
ieee80211_ioctl.o \
|
||||
sta_info.o \
|
||||
wep.o \
|
||||
wpa.o \
|
||||
ieee80211_scan.o \
|
||||
ieee80211_sta.o \
|
||||
ieee80211_dev.o \
|
||||
ieee80211_iface.o \
|
||||
ieee80211_rate.o \
|
||||
ieee80211_sysfs.o \
|
||||
ieee80211_sysfs_sta.o \
|
||||
michael.o \
|
||||
tkip.o \
|
||||
aes_ccm.o \
|
||||
wme.o \
|
||||
fifo_qdisc.o
|
155
package/d80211/src/aes_ccm.c
Normal file
155
package/d80211/src/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/d80211.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/d80211/src/aes_ccm.h
Normal file
26
package/d80211/src/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 */
|
102
package/d80211/src/fifo_qdisc.c
Normal file
102
package/d80211/src/fifo_qdisc.c
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* 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.
|
||||
*
|
||||
* If building without CONFIG_NET_SCHED we need a simple
|
||||
* fifo qdisc to install by default as the sub-qdisc.
|
||||
* This is a simple replacement for sch_fifo.
|
||||
*/
|
||||
|
||||
#include <linux/skbuff.h>
|
||||
#include <net/pkt_sched.h>
|
||||
#include <net/d80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "wme.h"
|
||||
|
||||
static int pfifo_enqueue(struct sk_buff *skb, struct Qdisc* qd)
|
||||
{
|
||||
struct sk_buff_head *q = qdisc_priv(qd);
|
||||
|
||||
if (skb_queue_len(q) > qd->dev->tx_queue_len) {
|
||||
qd->qstats.drops++;
|
||||
kfree_skb(skb);
|
||||
return NET_XMIT_DROP;
|
||||
}
|
||||
|
||||
skb_queue_tail(q, skb);
|
||||
qd->q.qlen++;
|
||||
qd->bstats.bytes += skb->len;
|
||||
qd->bstats.packets++;
|
||||
|
||||
return NET_XMIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int pfifo_requeue(struct sk_buff *skb, struct Qdisc* qd)
|
||||
{
|
||||
struct sk_buff_head *q = qdisc_priv(qd);
|
||||
|
||||
skb_queue_head(q, skb);
|
||||
qd->q.qlen++;
|
||||
qd->bstats.bytes += skb->len;
|
||||
qd->bstats.packets++;
|
||||
|
||||
return NET_XMIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static struct sk_buff *pfifo_dequeue(struct Qdisc* qd)
|
||||
{
|
||||
struct sk_buff_head *q = qdisc_priv(qd);
|
||||
|
||||
return skb_dequeue(q);
|
||||
}
|
||||
|
||||
|
||||
static int pfifo_init(struct Qdisc* qd, struct rtattr *opt)
|
||||
{
|
||||
struct sk_buff_head *q = qdisc_priv(qd);
|
||||
|
||||
skb_queue_head_init(q);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void pfifo_reset(struct Qdisc* qd)
|
||||
{
|
||||
struct sk_buff_head *q = qdisc_priv(qd);
|
||||
|
||||
skb_queue_purge(q);
|
||||
qd->q.qlen = 0;
|
||||
}
|
||||
|
||||
|
||||
static int pfifo_dump(struct Qdisc *qd, struct sk_buff *skb)
|
||||
{
|
||||
return skb->len;
|
||||
}
|
||||
|
||||
|
||||
struct Qdisc_ops pfifo_qdisc_ops =
|
||||
{
|
||||
.next = NULL,
|
||||
.cl_ops = NULL,
|
||||
.id = "ieee80211_pfifo",
|
||||
.priv_size = sizeof(struct sk_buff_head),
|
||||
|
||||
.enqueue = pfifo_enqueue,
|
||||
.dequeue = pfifo_dequeue,
|
||||
.requeue = pfifo_requeue,
|
||||
.drop = NULL,
|
||||
|
||||
.init = pfifo_init,
|
||||
.reset = pfifo_reset,
|
||||
.destroy = NULL,
|
||||
.change = NULL,
|
||||
|
||||
.dump = pfifo_dump,
|
||||
};
|
||||
|
434
package/d80211/src/hostapd_ioctl.h
Normal file
434
package/d80211/src/hostapd_ioctl.h
Normal file
|
@ -0,0 +1,434 @@
|
|||
/*
|
||||
* Host AP (software wireless LAN access point) user space daemon for
|
||||
* Host AP kernel driver
|
||||
* Copyright 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
|
||||
* 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 HOSTAPD_IOCTL_H
|
||||
#define HOSTAPD_IOCTL_H
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#include <linux/types.h>
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
|
||||
#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
|
||||
#define PRISM2_IOCTL_HOSTAPD (SIOCIWFIRSTPRIV + 3)
|
||||
#define PRISM2_IOCTL_TEST_PARAM (SIOCIWFIRSTPRIV + 4)
|
||||
|
||||
/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
|
||||
enum {
|
||||
PRISM2_PARAM_PTYPE = 1,
|
||||
PRISM2_PARAM_TXRATECTRL = 2,
|
||||
PRISM2_PARAM_BEACON_INT = 3,
|
||||
PRISM2_PARAM_PSEUDO_IBSS = 4,
|
||||
PRISM2_PARAM_ALC = 5,
|
||||
PRISM2_PARAM_TXPOWER = 6,
|
||||
PRISM2_PARAM_DUMP = 7,
|
||||
PRISM2_PARAM_OTHER_AP_POLICY = 8,
|
||||
PRISM2_PARAM_AP_MAX_INACTIVITY = 9,
|
||||
PRISM2_PARAM_AP_BRIDGE_PACKETS = 10,
|
||||
PRISM2_PARAM_DTIM_PERIOD = 11,
|
||||
PRISM2_PARAM_AP_NULLFUNC_ACK = 12,
|
||||
PRISM2_PARAM_MAX_WDS = 13,
|
||||
PRISM2_PARAM_AP_AUTOM_AP_WDS = 14,
|
||||
PRISM2_PARAM_AP_AUTH_ALGS = 15,
|
||||
PRISM2_PARAM_MONITOR_ALLOW_FCSERR = 16,
|
||||
PRISM2_PARAM_HOST_ENCRYPT = 17,
|
||||
PRISM2_PARAM_HOST_DECRYPT = 18,
|
||||
PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX = 19,
|
||||
PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX = 20,
|
||||
PRISM2_PARAM_HOST_ROAMING = 21,
|
||||
PRISM2_PARAM_BCRX_STA_KEY = 22,
|
||||
PRISM2_PARAM_IEEE_802_1X = 23,
|
||||
PRISM2_PARAM_ANTSEL_TX = 24,
|
||||
PRISM2_PARAM_ANTSEL_RX = 25,
|
||||
PRISM2_PARAM_MONITOR_TYPE = 26,
|
||||
PRISM2_PARAM_WDS_TYPE = 27,
|
||||
PRISM2_PARAM_HOSTSCAN = 28,
|
||||
PRISM2_PARAM_AP_SCAN = 29,
|
||||
|
||||
/* Instant802 additions */
|
||||
PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES = 1001,
|
||||
PRISM2_PARAM_DROP_UNENCRYPTED = 1002,
|
||||
PRISM2_PARAM_PREAMBLE = 1003,
|
||||
PRISM2_PARAM_RATE_LIMIT = 1004, /* no longer used */
|
||||
PRISM2_PARAM_RATE_LIMIT_BURST = 1005, /* no longer used */
|
||||
PRISM2_PARAM_SHORT_SLOT_TIME = 1006,
|
||||
PRISM2_PARAM_TEST_MODE = 1007,
|
||||
PRISM2_PARAM_NEXT_MODE = 1008,
|
||||
PRISM2_PARAM_CLEAR_KEYS = 1009,
|
||||
PRISM2_PARAM_RADIO_ENABLED = 1010,
|
||||
PRISM2_PARAM_ANTENNA_SEL = 1011,
|
||||
PRISM2_PARAM_CALIB_INT = 1012,
|
||||
PRISM2_PARAM_ANTENNA_MODE = 1013,
|
||||
PRISM2_PARAM_PRIVACY_INVOKED = 1014,
|
||||
PRISM2_PARAM_BROADCAST_SSID = 1015,
|
||||
PRISM2_PARAM_STAT_TIME = 1016,
|
||||
PRISM2_PARAM_STA_ANTENNA_SEL = 1017,
|
||||
PRISM2_PARAM_FORCE_UNICAST_RATE = 1018,
|
||||
PRISM2_PARAM_RATE_CTRL_NUM_UP = 1019,
|
||||
PRISM2_PARAM_RATE_CTRL_NUM_DOWN = 1020,
|
||||
PRISM2_PARAM_MAX_RATECTRL_RATE = 1021,
|
||||
PRISM2_PARAM_TX_POWER_REDUCTION = 1022,
|
||||
PRISM2_PARAM_EAPOL = 1023,
|
||||
PRISM2_PARAM_KEY_TX_RX_THRESHOLD = 1024,
|
||||
PRISM2_PARAM_KEY_INDEX = 1025,
|
||||
PRISM2_PARAM_DEFAULT_WEP_ONLY = 1026,
|
||||
PRISM2_PARAM_WIFI_WME_NOACK_TEST = 1033,
|
||||
PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS = 1034,
|
||||
PRISM2_PARAM_SCAN_FLAGS = 1035,
|
||||
PRISM2_PARAM_HW_MODES = 1036,
|
||||
PRISM2_PARAM_CREATE_IBSS = 1037,
|
||||
PRISM2_PARAM_WMM_ENABLED = 1038,
|
||||
PRISM2_PARAM_MIXED_CELL = 1039,
|
||||
PRISM2_PARAM_KEY_MGMT = 1040,
|
||||
PRISM2_PARAM_RADAR_DETECT = 1043,
|
||||
PRISM2_PARAM_SPECTRUM_MGMT = 1044,
|
||||
PRISM2_PARAM_USER_SPACE_MLME = 1045,
|
||||
PRISM2_PARAM_MGMT_IF = 1046,
|
||||
/* NOTE: Please try to coordinate with other active development
|
||||
* branches before allocating new param numbers so that each new param
|
||||
* will be unique within all branches and the allocated number will not
|
||||
* need to be changed when merging new features. Existing numbers in
|
||||
* the mainline (or main devel branch) must not be changed when merging
|
||||
* in new features. */
|
||||
};
|
||||
|
||||
/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
|
||||
enum {
|
||||
PRISM2_HOSTAPD_FLUSH = 1,
|
||||
PRISM2_HOSTAPD_ADD_STA = 2,
|
||||
PRISM2_HOSTAPD_REMOVE_STA = 3,
|
||||
PRISM2_HOSTAPD_GET_INFO_STA = 4,
|
||||
/* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
|
||||
PRISM2_SET_ENCRYPTION = 6,
|
||||
PRISM2_GET_ENCRYPTION = 7,
|
||||
PRISM2_HOSTAPD_SET_FLAGS_STA = 8,
|
||||
PRISM2_HOSTAPD_GET_RID = 9,
|
||||
PRISM2_HOSTAPD_SET_RID = 10,
|
||||
PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
|
||||
PRISM2_HOSTAPD_MLME = 13,
|
||||
|
||||
/* Instant802 additions */
|
||||
PRISM2_HOSTAPD_SET_BEACON = 1001,
|
||||
PRISM2_HOSTAPD_GET_HW_FEATURES = 1002,
|
||||
PRISM2_HOSTAPD_SCAN = 1003,
|
||||
PRISM2_HOSTAPD_WPA_TRIGGER = 1004,
|
||||
PRISM2_HOSTAPD_SET_RATE_SETS = 1005,
|
||||
PRISM2_HOSTAPD_ADD_IF = 1006,
|
||||
PRISM2_HOSTAPD_REMOVE_IF = 1007,
|
||||
PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE = 1008,
|
||||
PRISM2_HOSTAPD_GET_LOAD_STATS = 1009,
|
||||
PRISM2_HOSTAPD_SET_STA_VLAN = 1010,
|
||||
PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM = 1011,
|
||||
PRISM2_HOSTAPD_SET_CHANNEL_FLAG = 1012,
|
||||
PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN = 1013,
|
||||
PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS = 1014,
|
||||
PRISM2_HOSTAPD_GET_TX_STATS = 1016,
|
||||
PRISM2_HOSTAPD_UPDATE_IF = 1017,
|
||||
PRISM2_HOSTAPD_SCAN_REQ = 1019,
|
||||
PRISM2_STA_GET_STATE = 1020,
|
||||
PRISM2_HOSTAPD_FLUSH_IFS = 1021,
|
||||
PRISM2_HOSTAPD_SET_RADAR_PARAMS = 1023,
|
||||
PRISM2_HOSTAPD_SET_QUIET_PARAMS = 1024,
|
||||
PRISM2_HOSTAPD_GET_TX_POWER = 1025,
|
||||
/* NOTE: Please try to coordinate with other active development
|
||||
* branches before allocating new param numbers so that each new param
|
||||
* will be unique within all branches and the allocated number will not
|
||||
* need to be changed when merging new features. Existing numbers in
|
||||
* the mainline (or main devel branch) must not be changed when merging
|
||||
* in new features. */
|
||||
};
|
||||
|
||||
/* these definitions mirror the ieee80211_i.h
|
||||
* IEEE80211_DISABLED, ... IEEE80211_ASSOCIATED enumeration */
|
||||
enum {
|
||||
PRISM2_PARAM_STA_DISABLED,
|
||||
PRISM2_PARAM_STA_AUTHENTICATE,
|
||||
PRISM2_PARAM_STA_ASSOCIATE,
|
||||
PRISM2_PARAM_STA_ASSOCIATED,
|
||||
};
|
||||
|
||||
#define PRISM2_HOSTAPD_MAX_BUF_SIZE 2048
|
||||
#define HOSTAP_CRYPT_ALG_NAME_LEN 16
|
||||
|
||||
/* Use this to make sure that structure elements are correctly aligned
|
||||
* for access as other types. Most commonly, this affects the placeholder
|
||||
* types used for data at the end of a structure in this union.
|
||||
*/
|
||||
#ifdef __GNUC__
|
||||
#undef ALIGNED
|
||||
#define ALIGNED __attribute__ ((aligned))
|
||||
#else
|
||||
/* Check if it has been defined elsewhere */
|
||||
#ifndef ALIGNED
|
||||
#error "Must define ALIGNED to generate aligned structure elements"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct prism2_hostapd_param {
|
||||
u32 cmd;
|
||||
u8 sta_addr[ETH_ALEN];
|
||||
u8 pad[2];
|
||||
union {
|
||||
struct {
|
||||
u16 aid;
|
||||
u16 capability;
|
||||
u8 supp_rates[32];
|
||||
u8 wds_flags;
|
||||
#define IEEE80211_STA_DYNAMIC_ENC BIT(0)
|
||||
u8 enc_flags;
|
||||
u16 listen_interval;
|
||||
} add_sta;
|
||||
struct {
|
||||
u32 inactive_msec;
|
||||
u32 rx_packets;
|
||||
u32 tx_packets;
|
||||
u32 rx_bytes;
|
||||
u32 tx_bytes;
|
||||
u32 current_tx_rate; /* in 100 kbps */
|
||||
u32 channel_use;
|
||||
u32 flags;
|
||||
u32 num_ps_buf_frames;
|
||||
u32 tx_retry_failed;
|
||||
u32 tx_retry_count;
|
||||
u32 last_rssi;
|
||||
u32 last_ack_rssi;
|
||||
} get_info_sta;
|
||||
struct {
|
||||
char alg[HOSTAP_CRYPT_ALG_NAME_LEN];
|
||||
u32 flags;
|
||||
u32 err;
|
||||
u8 idx;
|
||||
#define HOSTAP_SEQ_COUNTER_SIZE 8
|
||||
u8 seq_counter[HOSTAP_SEQ_COUNTER_SIZE];
|
||||
u16 key_len;
|
||||
u8 key[0] ALIGNED;
|
||||
} crypt;
|
||||
struct {
|
||||
u32 flags_and;
|
||||
u32 flags_or;
|
||||
} set_flags_sta;
|
||||
struct {
|
||||
u16 rid;
|
||||
u16 len;
|
||||
u8 data[0] ALIGNED;
|
||||
} rid;
|
||||
struct {
|
||||
u16 head_len;
|
||||
u16 tail_len;
|
||||
u8 data[0] ALIGNED; /* head_len + tail_len bytes */
|
||||
} beacon;
|
||||
struct {
|
||||
u16 num_modes;
|
||||
u16 flags;
|
||||
u8 data[0] ALIGNED; /* num_modes * feature data */
|
||||
} hw_features;
|
||||
struct {
|
||||
u8 now;
|
||||
s8 our_mode_only;
|
||||
s16 last_rx;
|
||||
u16 channel;
|
||||
s16 interval; /* seconds */
|
||||
s32 listen; /* microseconds */
|
||||
} scan;
|
||||
struct {
|
||||
#define WPA_TRIGGER_FAIL_TX_MIC BIT(0)
|
||||
#define WPA_TRIGGER_FAIL_TX_ICV BIT(1)
|
||||
#define WPA_TRIGGER_FAIL_RX_MIC BIT(2)
|
||||
#define WPA_TRIGGER_FAIL_RX_ICV BIT(3)
|
||||
#define WPA_TRIGGER_TX_REPLAY BIT(4)
|
||||
#define WPA_TRIGGER_TX_REPLAY_FRAG BIT(5)
|
||||
#define WPA_TRIGGER_TX_SKIP_SEQ BIT(6)
|
||||
u32 trigger;
|
||||
} wpa_trigger;
|
||||
struct {
|
||||
u16 mode; /* MODE_* */
|
||||
u16 num_supported_rates;
|
||||
u16 num_basic_rates;
|
||||
u8 data[0] ALIGNED; /* num_supported_rates * u16 +
|
||||
* num_basic_rates * u16 */
|
||||
} set_rate_sets;
|
||||
struct {
|
||||
u8 type; /* WDS, VLAN, etc */
|
||||
u8 name[IFNAMSIZ];
|
||||
u8 data[0] ALIGNED;
|
||||
} if_info;
|
||||
struct dot11_counters {
|
||||
u32 dot11TransmittedFragmentCount;
|
||||
u32 dot11MulticastTransmittedFrameCount;
|
||||
u32 dot11FailedCount;
|
||||
u32 dot11ReceivedFragmentCount;
|
||||
u32 dot11MulticastReceivedFrameCount;
|
||||
u32 dot11FCSErrorCount;
|
||||
u32 dot11TransmittedFrameCount;
|
||||
u32 dot11WEPUndecryptableCount;
|
||||
u32 dot11ACKFailureCount;
|
||||
u32 dot11RTSFailureCount;
|
||||
u32 dot11RTSSuccessCount;
|
||||
} dot11CountersTable;
|
||||
struct {
|
||||
#define LOAD_STATS_CLEAR BIT(1)
|
||||
u32 flags;
|
||||
u32 channel_use;
|
||||
} get_load_stats;
|
||||
struct {
|
||||
char vlan_name[IFNAMSIZ];
|
||||
int vlan_id;
|
||||
} set_sta_vlan;
|
||||
struct {
|
||||
u8 len;
|
||||
u8 data[0] ALIGNED;
|
||||
} set_generic_info_elem;
|
||||
struct {
|
||||
u16 mode; /* MODE_* */
|
||||
u16 chan;
|
||||
u32 flag;
|
||||
u8 power_level; /* regulatory limit in dBm */
|
||||
u8 antenna_max;
|
||||
} set_channel_flag;
|
||||
struct {
|
||||
u32 rd;
|
||||
} set_regulatory_domain;
|
||||
struct {
|
||||
u32 queue;
|
||||
s32 aifs;
|
||||
u32 cw_min;
|
||||
u32 cw_max;
|
||||
u32 burst_time; /* maximum burst time in 0.1 ms, i.e.,
|
||||
* 10 = 1 ms */
|
||||
} tx_queue_params;
|
||||
struct {
|
||||
u32 bss_count;
|
||||
u8 bssid_mask[ETH_ALEN];
|
||||
} set_bss;
|
||||
struct ieee80211_tx_stats {
|
||||
struct {
|
||||
unsigned int len; /* num packets in queue */
|
||||
unsigned int limit; /* queue len (soft) limit
|
||||
*/
|
||||
unsigned int count; /* total num frames sent */
|
||||
} data[4];
|
||||
} get_tx_stats;
|
||||
struct {
|
||||
u8 ssid_len;
|
||||
u8 ssid[0] ALIGNED;
|
||||
} scan_req;
|
||||
struct {
|
||||
u32 state;
|
||||
} sta_get_state;
|
||||
struct {
|
||||
#define MLME_STA_DEAUTH 0
|
||||
#define MLME_STA_DISASSOC 1
|
||||
u16 cmd;
|
||||
u16 reason_code;
|
||||
} mlme;
|
||||
struct {
|
||||
u8 radar_firpwr_threshold;
|
||||
u8 radar_rssi_threshold;
|
||||
u8 pulse_height_threshold;
|
||||
u8 pulse_rssi_threshold;
|
||||
u8 pulse_inband_threshold;
|
||||
} radar;
|
||||
struct {
|
||||
unsigned int period;
|
||||
unsigned int offset;
|
||||
unsigned int duration;
|
||||
} quiet;
|
||||
struct {
|
||||
unsigned int tx_power_min;
|
||||
unsigned int tx_power_max;
|
||||
} tx_power;
|
||||
struct {
|
||||
u8 dummy[80]; /* Make sizeof() this struct large enough
|
||||
* with some compiler versions. */
|
||||
} dummy;
|
||||
} u;
|
||||
};
|
||||
|
||||
|
||||
#ifndef IEEE80211_TX_QUEUE_NUMS
|
||||
#define IEEE80211_TX_QUEUE_NUMS
|
||||
/* TODO: these need to be synchronized with ieee80211.h; make a shared header
|
||||
* file that can be included into low-level drivers, 80211.o, and hostapd */
|
||||
/* tx_queue_params - queue */
|
||||
enum {
|
||||
IEEE80211_TX_QUEUE_DATA0 = 0, /* used for EDCA AC_VO data */
|
||||
IEEE80211_TX_QUEUE_DATA1 = 1, /* used for EDCA AC_VI data */
|
||||
IEEE80211_TX_QUEUE_DATA2 = 2, /* used for EDCA AC_BE data */
|
||||
IEEE80211_TX_QUEUE_DATA3 = 3, /* used for EDCA AC_BK data */
|
||||
IEEE80211_TX_QUEUE_DATA4 = 4,
|
||||
IEEE80211_TX_QUEUE_AFTER_BEACON = 6,
|
||||
IEEE80211_TX_QUEUE_BEACON = 7
|
||||
};
|
||||
#endif /* IEEE80211_TX_QUEUE_NUMS */
|
||||
|
||||
|
||||
#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
|
||||
#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
|
||||
|
||||
#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
|
||||
#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
|
||||
#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
|
||||
#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
|
||||
#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
|
||||
#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
|
||||
|
||||
#define HOSTAP_HW_FLAG_NULLFUNC_OK BIT(0)
|
||||
|
||||
enum {
|
||||
IEEE80211_KEY_MGMT_NONE = 0,
|
||||
IEEE80211_KEY_MGMT_IEEE8021X = 1,
|
||||
IEEE80211_KEY_MGMT_WPA_PSK = 2,
|
||||
IEEE80211_KEY_MGMT_WPA_EAP = 3,
|
||||
};
|
||||
|
||||
|
||||
/* Data structures used for get_hw_features ioctl */
|
||||
struct hostapd_ioctl_hw_modes_hdr {
|
||||
int mode;
|
||||
int num_channels;
|
||||
int num_rates;
|
||||
};
|
||||
|
||||
struct ieee80211_channel_data {
|
||||
short chan; /* channel number (IEEE 802.11) */
|
||||
short freq; /* frequency in MHz */
|
||||
int flag; /* flag for hostapd use (IEEE80211_CHAN_*) */
|
||||
};
|
||||
|
||||
struct ieee80211_rate_data {
|
||||
int rate; /* rate in 100 kbps */
|
||||
int flags; /* IEEE80211_RATE_ flags */
|
||||
};
|
||||
|
||||
|
||||
/* ADD_IF, REMOVE_IF, and UPDATE_IF 'type' argument */
|
||||
enum {
|
||||
HOSTAP_IF_WDS = 1, HOSTAP_IF_VLAN = 2, HOSTAP_IF_BSS = 3,
|
||||
HOSTAP_IF_STA = 4
|
||||
};
|
||||
|
||||
struct hostapd_if_wds {
|
||||
u8 remote_addr[ETH_ALEN];
|
||||
};
|
||||
|
||||
struct hostapd_if_vlan {
|
||||
u8 id;
|
||||
};
|
||||
|
||||
struct hostapd_if_bss {
|
||||
u8 bssid[ETH_ALEN];
|
||||
};
|
||||
|
||||
struct hostapd_if_sta {
|
||||
};
|
||||
|
||||
#endif /* HOSTAPD_IOCTL_H */
|
4865
package/d80211/src/ieee80211.c
Normal file
4865
package/d80211/src/ieee80211.c
Normal file
File diff suppressed because it is too large
Load diff
117
package/d80211/src/ieee80211_dev.c
Normal file
117
package/d80211/src/ieee80211_dev.c
Normal file
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* 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/interrupt.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <net/d80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_led.h"
|
||||
|
||||
struct ieee80211_dev_list {
|
||||
struct list_head list;
|
||||
int dev_index;
|
||||
struct ieee80211_local *local;
|
||||
};
|
||||
|
||||
static LIST_HEAD(dev_list);
|
||||
static DEFINE_SPINLOCK(dev_list_lock);
|
||||
|
||||
|
||||
/* Caller must hold dev_list_lock */
|
||||
static struct ieee80211_dev_list *__ieee80211_dev_find(int index)
|
||||
{
|
||||
struct ieee80211_dev_list *dev_item;
|
||||
|
||||
list_for_each_entry(dev_item, &dev_list, list) {
|
||||
if (dev_item->dev_index == index)
|
||||
return dev_item;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ieee80211_dev_alloc_index(struct ieee80211_local *local)
|
||||
{
|
||||
struct ieee80211_dev_list *dev_item, *new;
|
||||
int index = 0;
|
||||
|
||||
new = kmalloc(sizeof(struct ieee80211_dev_list), GFP_KERNEL);
|
||||
if (!new)
|
||||
return -ENOMEM;
|
||||
new->local = local;
|
||||
spin_lock(&dev_list_lock);
|
||||
list_for_each_entry(dev_item, &dev_list, list) {
|
||||
if (index < dev_item->dev_index)
|
||||
break;
|
||||
index++;
|
||||
}
|
||||
new->dev_index = index;
|
||||
list_add_tail(&new->list, &dev_item->list);
|
||||
spin_unlock(&dev_list_lock);
|
||||
local->hw.index = index;
|
||||
return index;
|
||||
}
|
||||
|
||||
void ieee80211_dev_free_index(struct ieee80211_local *local)
|
||||
{
|
||||
struct ieee80211_dev_list *dev_item;
|
||||
|
||||
spin_lock(&dev_list_lock);
|
||||
dev_item = __ieee80211_dev_find(local->hw.index);
|
||||
if (dev_item)
|
||||
list_del(&dev_item->list);
|
||||
spin_unlock(&dev_list_lock);
|
||||
if (dev_item)
|
||||
kfree(dev_item);
|
||||
local->hw.index = -1;
|
||||
}
|
||||
|
||||
struct ieee80211_local *ieee80211_dev_find(int index)
|
||||
{
|
||||
struct ieee80211_dev_list *dev_item;
|
||||
|
||||
spin_lock(&dev_list_lock);
|
||||
dev_item = __ieee80211_dev_find(index);
|
||||
spin_unlock(&dev_list_lock);
|
||||
return dev_item ? dev_item->local : NULL;
|
||||
}
|
||||
|
||||
int ieee80211_dev_find_index(struct ieee80211_local *local)
|
||||
{
|
||||
struct ieee80211_dev_list *dev_item;
|
||||
int index = -1;
|
||||
|
||||
spin_lock(&dev_list_lock);
|
||||
list_for_each_entry(dev_item, &dev_list, list) {
|
||||
if (dev_item->local == local) {
|
||||
index = dev_item->dev_index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
spin_unlock(&dev_list_lock);
|
||||
return index;
|
||||
}
|
||||
|
||||
struct ieee80211_local *ieee80211_dev_alloc(gfp_t flags)
|
||||
{
|
||||
struct ieee80211_local *local;
|
||||
|
||||
local = kzalloc(sizeof(struct ieee80211_local), flags);
|
||||
if (!local)
|
||||
return NULL;
|
||||
local->hw.index = -1;
|
||||
ieee80211_dev_sysfs_init(local);
|
||||
return local;
|
||||
}
|
||||
|
||||
void ieee80211_dev_free(struct ieee80211_local *local)
|
||||
{
|
||||
ieee80211_dev_sysfs_put(local);
|
||||
}
|
707
package/d80211/src/ieee80211_i.h
Normal file
707
package/d80211/src/ieee80211_i.h
Normal file
|
@ -0,0 +1,707 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#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 "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 IEEE80211_MAX_SSID_LEN 32
|
||||
|
||||
#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
|
||||
|
||||
|
||||
/* 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;
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
typedef enum {
|
||||
TXRX_CONTINUE, TXRX_DROP, TXRX_QUEUED
|
||||
} ieee80211_txrx_result;
|
||||
|
||||
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 fragmented:1; /* whether the MSDU was fragmented */
|
||||
union {
|
||||
struct {
|
||||
struct ieee80211_tx_control *control;
|
||||
unsigned int unicast:1;
|
||||
unsigned int ps_buffered:1;
|
||||
unsigned int short_preamble:1;
|
||||
unsigned int probe_last_frag:1;
|
||||
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_rateidx;
|
||||
int last_frag_hwrate;
|
||||
int mgmt_interface;
|
||||
|
||||
/* 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;
|
||||
unsigned int in_scan:1;
|
||||
/* frame is destined to interface currently processed
|
||||
* (including multicast frames) */
|
||||
unsigned int ra_match:1;
|
||||
} rx;
|
||||
} u;
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
int wpa_test;
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
};
|
||||
|
||||
/* Stored in sk_buff->cb */
|
||||
struct ieee80211_tx_packet_data {
|
||||
int ifindex;
|
||||
unsigned long jiffies;
|
||||
unsigned int req_tx_status:1;
|
||||
unsigned int do_not_encrypt:1;
|
||||
unsigned int pkt_probe_resp:1;
|
||||
unsigned int requeue:1;
|
||||
unsigned int queue:4;
|
||||
unsigned int mgmt_iface:1;
|
||||
};
|
||||
|
||||
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;
|
||||
unsigned int last_frag_rate_ctrl_probe:1;
|
||||
};
|
||||
|
||||
struct ieee80211_passive_scan {
|
||||
unsigned int in_scan:1; /* this must be cleared before calling
|
||||
* netif_oper(WAKEUP) */
|
||||
unsigned int our_mode_only:1; /* only scan our physical mode a/b/g/etc
|
||||
*/
|
||||
int interval; /* time in seconds between scans */
|
||||
int time; /* time in microseconds to scan for */
|
||||
int channel; /* channel to be scanned */
|
||||
int tries;
|
||||
|
||||
int mode_idx;
|
||||
int chan_idx;
|
||||
|
||||
int freq;
|
||||
int rx_packets;
|
||||
int rx_beacon;
|
||||
int txrx_count;
|
||||
|
||||
struct timer_list timer;
|
||||
|
||||
struct sk_buff *skb; /* skb to transmit before changing channels,
|
||||
* maybe null for none */
|
||||
struct ieee80211_tx_control tx_control;
|
||||
|
||||
unsigned int num_scans;
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
u8 ssid[IEEE80211_MAX_SSID_LEN];
|
||||
size_t ssid_len;
|
||||
u8 *generic_elem;
|
||||
size_t generic_elem_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 {
|
||||
u8 id;
|
||||
};
|
||||
|
||||
struct ieee80211_if_sta {
|
||||
enum {
|
||||
IEEE80211_DISABLED, IEEE80211_AUTHENTICATE,
|
||||
IEEE80211_ASSOCIATE, IEEE80211_ASSOCIATED,
|
||||
IEEE80211_IBSS_SEARCH, IEEE80211_IBSS_JOINED
|
||||
} state;
|
||||
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 ssid_set:1;
|
||||
unsigned int bssid_set:1;
|
||||
unsigned int prev_bssid_set:1;
|
||||
unsigned int authenticated:1;
|
||||
unsigned int associated:1;
|
||||
unsigned int probereq_poll:1;
|
||||
unsigned int use_protection:1;
|
||||
unsigned int create_ibss:1;
|
||||
unsigned int mixed_cell:1;
|
||||
unsigned int wmm_enabled:1;
|
||||
|
||||
int key_mgmt;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
struct ieee80211_sub_if_data {
|
||||
struct list_head list;
|
||||
unsigned int type;
|
||||
|
||||
struct net_device *dev;
|
||||
struct ieee80211_local *local;
|
||||
|
||||
int mc_count;
|
||||
unsigned int allmulti:1;
|
||||
unsigned int promisc:1;
|
||||
|
||||
struct net_device_stats stats;
|
||||
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 */
|
||||
|
||||
/* 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 kset key_kset;
|
||||
|
||||
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;
|
||||
|
||||
struct attribute_group *sysfs_group;
|
||||
};
|
||||
|
||||
#define IEEE80211_DEV_TO_SUB_IF(dev) netdev_priv(dev)
|
||||
|
||||
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;
|
||||
|
||||
struct ieee80211_ops *ops;
|
||||
|
||||
struct net_device *mdev; /* wmaster# - "master" 802.11 device */
|
||||
struct net_device *apdev; /* wlan#ap - management frames (hostapd) */
|
||||
int open_count;
|
||||
int monitors;
|
||||
struct iw_statistics wstats;
|
||||
|
||||
struct class_device class_dev;
|
||||
|
||||
enum {
|
||||
IEEE80211_DEV_UNITIALIZED = 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;
|
||||
enum {
|
||||
ieee80211_rx_msg = 1,
|
||||
ieee80211_tx_status_msg = 2
|
||||
} ieee80211_msg_enum;
|
||||
|
||||
spinlock_t generic_lock;
|
||||
/* Station data structures */
|
||||
struct kset sta_kset;
|
||||
spinlock_t sta_lock; /* mutex for STA data structures */
|
||||
int num_sta; /* number of stations in sta_list */
|
||||
struct list_head sta_list;
|
||||
struct list_head deleted_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;
|
||||
|
||||
int mc_count; /* total count of multicast entries in all interfaces */
|
||||
int iff_allmultis, iff_promiscs;
|
||||
/* number of interfaces with corresponding IFF_ flags */
|
||||
|
||||
/* Current rate table. This is a pointer to hw->modes structure. */
|
||||
struct ieee80211_rate *curr_rates;
|
||||
int num_curr_rates;
|
||||
|
||||
struct rate_control_ref *rate_ctrl;
|
||||
|
||||
int next_mode; /* MODE_IEEE80211*
|
||||
* The mode preference for next channel change. This is
|
||||
* used to select .11g vs. .11b channels (or 4.9 GHz vs.
|
||||
* .11a) when the channel number is not unique. */
|
||||
|
||||
/* 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 cts_protect_erp_frames;
|
||||
int fragmentation_threshold;
|
||||
int short_retry_limit; /* dot11ShortRetryLimit */
|
||||
int long_retry_limit; /* dot11LongRetryLimit */
|
||||
int short_preamble; /* use short preamble with IEEE 802.11b */
|
||||
|
||||
struct crypto_blkcipher *wep_tx_tfm;
|
||||
struct crypto_blkcipher *wep_rx_tfm;
|
||||
u32 wep_iv;
|
||||
int key_tx_rx_threshold; /* number of times any key can be used in TX
|
||||
* or RX before generating a rekey
|
||||
* notification; 0 = notification disabled. */
|
||||
|
||||
int bridge_packets; /* bridge packets between associated stations and
|
||||
* deliver multicast frames both back to wireless
|
||||
* media and to the local net stack */
|
||||
|
||||
struct ieee80211_passive_scan scan;
|
||||
|
||||
|
||||
ieee80211_rx_handler *rx_pre_handlers;
|
||||
ieee80211_rx_handler *rx_handlers;
|
||||
ieee80211_tx_handler *tx_handlers;
|
||||
|
||||
spinlock_t sub_if_lock; /* mutex for STA data structures */
|
||||
struct list_head sub_if_list;
|
||||
int sta_scanning;
|
||||
int scan_hw_mode_idx;
|
||||
int scan_channel_idx;
|
||||
enum { SCAN_SET_CHANNEL, SCAN_SEND_PROBE } scan_state;
|
||||
unsigned long last_scan_completed;
|
||||
struct work_struct scan_work;
|
||||
int scan_oper_channel;
|
||||
int scan_oper_channel_val;
|
||||
int scan_oper_power_level;
|
||||
int scan_oper_freq;
|
||||
int scan_oper_phymode;
|
||||
int scan_oper_antenna_max;
|
||||
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;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
u32 wpa_trigger;
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
/* 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_D80211_LEDS
|
||||
int tx_led_counter, rx_led_counter;
|
||||
struct led_trigger *tx_led, *rx_led;
|
||||
char tx_led_name[32], rx_led_name[32];
|
||||
#endif
|
||||
|
||||
u32 channel_use;
|
||||
u32 channel_use_raw;
|
||||
u32 stat_time;
|
||||
struct timer_list stat_timer;
|
||||
|
||||
struct proc_dir_entry *proc, *proc_sta, *proc_iface;
|
||||
|
||||
struct work_struct sta_proc_add;
|
||||
|
||||
enum {
|
||||
STA_ANTENNA_SEL_AUTO = 0,
|
||||
STA_ANTENNA_SEL_SW_CTRL = 1,
|
||||
STA_ANTENNA_SEL_SW_CTRL_DEBUG = 2
|
||||
} sta_antenna_sel;
|
||||
|
||||
int rate_ctrl_num_up, rate_ctrl_num_down;
|
||||
|
||||
#ifdef CONFIG_D80211_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_D80211_DEBUG_COUNTERS */
|
||||
#define I802_DEBUG_INC(c) do { } while (0)
|
||||
#endif /* CONFIG_D80211_DEBUG_COUNTERS */
|
||||
|
||||
|
||||
int default_wep_only; /* only default WEP keys are used with this
|
||||
* interface; this is used to decide when hwaccel
|
||||
* can be used with default keys */
|
||||
int total_ps_buffered; /* total number of all buffered unicast and
|
||||
* multicast packets for power saving stations
|
||||
*/
|
||||
int allow_broadcast_always; /* whether to allow TX of broadcast frames
|
||||
* even when there are no associated STAs
|
||||
*/
|
||||
|
||||
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_*) */
|
||||
|
||||
int user_space_mlme;
|
||||
};
|
||||
|
||||
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_local *local,
|
||||
struct ieee80211_if_ap *bss, int aid)
|
||||
{
|
||||
spin_lock(&local->sta_lock);
|
||||
bss->tim[(aid)/8] |= 1<<((aid) % 8);
|
||||
spin_unlock(&local->sta_lock);
|
||||
}
|
||||
|
||||
static inline void bss_tim_clear(struct ieee80211_local *local,
|
||||
struct ieee80211_if_ap *bss, int aid)
|
||||
{
|
||||
spin_lock(&local->sta_lock);
|
||||
bss->tim[(aid)/8] &= !(1<<((aid) % 8));
|
||||
spin_unlock(&local->sta_lock);
|
||||
}
|
||||
|
||||
/* ieee80211.c */
|
||||
void ieee80211_release_hw(struct ieee80211_local *local);
|
||||
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);
|
||||
struct ieee80211_key_conf *
|
||||
ieee80211_key_data2conf(struct ieee80211_local *local,
|
||||
struct ieee80211_key *data);
|
||||
struct ieee80211_key *ieee80211_key_alloc(struct ieee80211_sub_if_data *sdata,
|
||||
int idx, size_t key_len, gfp_t flags);
|
||||
void ieee80211_key_free(struct ieee80211_key *key);
|
||||
void ieee80211_key_release(struct kobject *kobj);
|
||||
void ieee80211_rx_mgmt(struct ieee80211_local *local, struct sk_buff *skb,
|
||||
struct ieee80211_rx_status *status, u32 msg_type);
|
||||
void ieee80211_prepare_rates(struct ieee80211_local *local);
|
||||
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);
|
||||
void ieee80211_if_mgmt_setup(struct net_device *dev);
|
||||
void ieee80211_if_shutdown(struct net_device *dev);
|
||||
int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
|
||||
const char *name);
|
||||
struct net_device_stats *ieee80211_dev_stats(struct net_device *dev);
|
||||
|
||||
/* ieee80211_ioctl.c */
|
||||
int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
|
||||
extern const struct iw_handler_def ieee80211_iw_handler_def;
|
||||
extern const struct iw_handler_def ieee80211_iw_master_handler_def;
|
||||
|
||||
/* Set hw encryption from ieee80211 */
|
||||
int ieee80211_set_hw_encryption(struct net_device *dev,
|
||||
struct sta_info *sta, u8 addr[ETH_ALEN],
|
||||
struct ieee80211_key *key);
|
||||
|
||||
/* ieee80211_scan.c */
|
||||
void ieee80211_init_scan(struct ieee80211_local *local);
|
||||
void ieee80211_stop_scan(struct ieee80211_local *local);
|
||||
|
||||
|
||||
|
||||
/* 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_init_client(struct net_device *dev);
|
||||
/* ieee80211_sta.c */
|
||||
void ieee80211_sta_work(void *ptr);
|
||||
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);
|
||||
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);
|
||||
|
||||
/* ieee80211_dev.c */
|
||||
int ieee80211_dev_alloc_index(struct ieee80211_local *local);
|
||||
void ieee80211_dev_free_index(struct ieee80211_local *local);
|
||||
struct ieee80211_local *ieee80211_dev_find(int index);
|
||||
int ieee80211_dev_find_index(struct ieee80211_local *local);
|
||||
struct ieee80211_local *ieee80211_dev_alloc(gfp_t flags);
|
||||
void ieee80211_dev_free(struct ieee80211_local *local);
|
||||
|
||||
/* ieee80211_iface.c */
|
||||
int ieee80211_if_add(struct net_device *dev, const char *name,
|
||||
int format, struct net_device **new_dev);
|
||||
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);
|
||||
void ieee80211_if_del(struct net_device *dev);
|
||||
int ieee80211_if_remove(struct net_device *dev, const char *name, int id);
|
||||
void ieee80211_if_free(struct net_device *dev);
|
||||
void ieee80211_if_flush(struct net_device *dev);
|
||||
void ieee80211_if_sdata_init(struct ieee80211_sub_if_data *sdata);
|
||||
int ieee80211_if_add_mgmt(struct ieee80211_local *local);
|
||||
void ieee80211_if_del_mgmt(struct ieee80211_local *local);
|
||||
|
||||
/* ieee80211_sysfs.c */
|
||||
int ieee80211_sysfs_add_netdevice(struct net_device *dev);
|
||||
void ieee80211_sysfs_remove_netdevice(struct net_device *dev);
|
||||
void ieee80211_dev_sysfs_init(struct ieee80211_local *local);
|
||||
void ieee80211_dev_sysfs_put(struct ieee80211_local *local);
|
||||
int ieee80211_dev_sysfs_add(struct ieee80211_local *local);
|
||||
void ieee80211_dev_sysfs_del(struct ieee80211_local *local);
|
||||
int ieee80211_sysfs_init(void);
|
||||
void ieee80211_sysfs_deinit(void);
|
||||
int ieee80211_sysfs_change_if_type(struct net_device *dev);
|
||||
|
||||
/* ieee80211_sysfs_sta.c */
|
||||
int ieee80211_sta_kset_sysfs_register(struct ieee80211_local *local);
|
||||
void ieee80211_sta_kset_sysfs_unregister(struct ieee80211_local *local);
|
||||
int ieee80211_sta_sysfs_add(struct sta_info *sta);
|
||||
void ieee80211_sta_sysfs_remove(struct sta_info *sta);
|
||||
int ieee80211_key_kset_sysfs_register(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_key_kset_sysfs_unregister(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_key_sysfs_set_kset(struct ieee80211_key *key, struct kset *kset);
|
||||
int ieee80211_key_sysfs_add(struct ieee80211_key *key);
|
||||
void ieee80211_key_sysfs_remove(struct ieee80211_key *key);
|
||||
int ieee80211_key_sysfs_add_default(struct ieee80211_sub_if_data *sdata);
|
||||
void ieee80211_key_sysfs_remove_default(struct ieee80211_sub_if_data *sdata);
|
||||
|
||||
#endif /* IEEE80211_I_H */
|
372
package/d80211/src/ieee80211_iface.c
Normal file
372
package/d80211/src/ieee80211_iface.c
Normal file
|
@ -0,0 +1,372 @@
|
|||
/*
|
||||
* 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/d80211.h>
|
||||
#include <net/d80211_mgmt.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "sta_info.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);
|
||||
}
|
||||
|
||||
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,
|
||||
int format, struct net_device **new_dev)
|
||||
{
|
||||
struct net_device *ndev, *tmp_dev;
|
||||
struct ieee80211_local *local = dev->ieee80211_ptr;
|
||||
struct ieee80211_sub_if_data *sdata = NULL, *sdata_parent;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
ASSERT_RTNL();
|
||||
ndev = *new_dev = alloc_netdev(sizeof(struct ieee80211_sub_if_data),
|
||||
"", ieee80211_if_setup);
|
||||
if (!ndev)
|
||||
return -ENOMEM;
|
||||
|
||||
ndev->ieee80211_ptr = local;
|
||||
if (strlen(name) == 0) {
|
||||
i = 0;
|
||||
do {
|
||||
sprintf(ndev->name, "%s.%d", dev->name, i++);
|
||||
tmp_dev = dev_get_by_name(ndev->name);
|
||||
if (!tmp_dev)
|
||||
break;
|
||||
dev_put(tmp_dev);
|
||||
} while (i < 10000);
|
||||
} else if (format) {
|
||||
ret = dev_alloc_name(ndev, name);
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
} else {
|
||||
snprintf(ndev->name, IFNAMSIZ, "%s", name);
|
||||
}
|
||||
|
||||
memcpy(ndev->dev_addr, local->hw.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;
|
||||
ndev->flags = dev->flags & IFF_MULTICAST;
|
||||
SET_NETDEV_DEV(ndev, local->hw.dev);
|
||||
|
||||
sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
|
||||
sdata->type = IEEE80211_IF_TYPE_AP;
|
||||
sdata->dev = ndev;
|
||||
sdata->local = local;
|
||||
sdata_parent = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
ieee80211_if_sdata_init(sdata);
|
||||
|
||||
ret = register_netdevice(ndev);
|
||||
if (ret)
|
||||
goto fail;
|
||||
ret = ieee80211_sysfs_add_netdevice(ndev);
|
||||
if (ret) {
|
||||
/* ndev will be freed by ndev->destructor */
|
||||
unregister_netdevice(ndev);
|
||||
*new_dev = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
list_add(&sdata->list, &local->sub_if_list);
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
free_netdev(ndev);
|
||||
*new_dev = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ieee80211_if_add_mgmt(struct ieee80211_local *local)
|
||||
{
|
||||
struct net_device *ndev;
|
||||
struct ieee80211_sub_if_data *nsdata;
|
||||
int ret;
|
||||
|
||||
ASSERT_RTNL();
|
||||
|
||||
ndev = alloc_netdev(sizeof(struct ieee80211_sub_if_data), "",
|
||||
ieee80211_if_mgmt_setup);
|
||||
if (!ndev)
|
||||
return -ENOMEM;
|
||||
ret = dev_alloc_name(ndev, "wmgmt%d");
|
||||
if (ret < 0)
|
||||
goto fail;
|
||||
|
||||
ndev->ieee80211_ptr = local;
|
||||
memcpy(ndev->dev_addr, local->hw.perm_addr, ETH_ALEN);
|
||||
SET_NETDEV_DEV(ndev, local->hw.dev);
|
||||
|
||||
nsdata = IEEE80211_DEV_TO_SUB_IF(ndev);
|
||||
nsdata->type = IEEE80211_IF_TYPE_MGMT;
|
||||
nsdata->dev = ndev;
|
||||
nsdata->local = local;
|
||||
ieee80211_if_sdata_init(nsdata);
|
||||
|
||||
ret = register_netdevice(ndev);
|
||||
if (ret)
|
||||
goto fail;
|
||||
ret = ieee80211_sysfs_add_netdevice(ndev);
|
||||
if (ret)
|
||||
goto fail_sysfs;
|
||||
if (local->open_count > 0)
|
||||
dev_open(ndev);
|
||||
local->apdev = ndev;
|
||||
return 0;
|
||||
|
||||
fail_sysfs:
|
||||
unregister_netdevice(ndev);
|
||||
fail:
|
||||
free_netdev(ndev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ieee80211_if_del_mgmt(struct ieee80211_local *local)
|
||||
{
|
||||
struct net_device *apdev;
|
||||
|
||||
ASSERT_RTNL();
|
||||
apdev = local->apdev;
|
||||
ieee80211_sysfs_remove_netdevice(apdev);
|
||||
local->apdev = NULL;
|
||||
unregister_netdevice(apdev);
|
||||
}
|
||||
|
||||
void ieee80211_if_set_type(struct net_device *dev, int type)
|
||||
{
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
|
||||
sdata->type = type;
|
||||
switch (type) {
|
||||
case IEEE80211_IF_TYPE_WDS:
|
||||
sdata->bss = NULL;
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_VLAN:
|
||||
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;
|
||||
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, dev);
|
||||
|
||||
ifsta->capab = WLAN_CAPABILITY_ESS;
|
||||
ifsta->auth_algs = IEEE80211_AUTH_ALG_OPEN |
|
||||
IEEE80211_AUTH_ALG_SHARED_KEY;
|
||||
ifsta->create_ibss = 1;
|
||||
ifsta->wmm_enabled = 1;
|
||||
|
||||
msdata = IEEE80211_DEV_TO_SUB_IF(sdata->local->mdev);
|
||||
sdata->bss = &msdata->u.ap;
|
||||
break;
|
||||
}
|
||||
case IEEE80211_IF_TYPE_MNTR:
|
||||
dev->type = ARPHRD_IEEE80211_PRISM;
|
||||
break;
|
||||
default:
|
||||
printk(KERN_WARNING "%s: %s: Unknown interface type 0x%x",
|
||||
dev->name, __FUNCTION__, type);
|
||||
}
|
||||
ieee80211_sysfs_change_if_type(dev);
|
||||
}
|
||||
|
||||
/* Must be called with rtnl lock held. */
|
||||
void ieee80211_if_reinit(struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_local *local = dev->ieee80211_ptr;
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
struct sta_info *sta;
|
||||
int i;
|
||||
|
||||
ASSERT_RTNL();
|
||||
ieee80211_if_sdata_deinit(sdata);
|
||||
for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
|
||||
if (!sdata->keys[i])
|
||||
continue;
|
||||
#if 0
|
||||
/* The interface is down at the moment, so there is not
|
||||
* really much point in disabling the keys at this point. */
|
||||
memset(addr, 0xff, ETH_ALEN);
|
||||
if (local->ops->set_key)
|
||||
local->ops->set_key(dev, DISABLE_KEY, addr,
|
||||
local->keys[i], 0);
|
||||
#endif
|
||||
ieee80211_key_free(sdata->keys[i]);
|
||||
}
|
||||
|
||||
/* Shouldn't be necessary but won't hurt */
|
||||
ieee80211_if_shutdown(dev);
|
||||
|
||||
switch (sdata->type) {
|
||||
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->sub_if_list, 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);
|
||||
__ieee80211_if_del(local, tsdata);
|
||||
}
|
||||
}
|
||||
|
||||
kfree(sdata->u.ap.beacon_head);
|
||||
kfree(sdata->u.ap.beacon_tail);
|
||||
kfree(sdata->u.ap.generic_elem);
|
||||
|
||||
if (dev != local->mdev) {
|
||||
struct sk_buff *skb;
|
||||
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_put(sta);
|
||||
sta_info_free(sta, 0);
|
||||
} else {
|
||||
#ifdef CONFIG_D80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: Someone had deleted my STA "
|
||||
"entry for the WDS link\n", dev->name);
|
||||
#endif /* CONFIG_D80211_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;
|
||||
}
|
||||
|
||||
/* 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_if_reinit(dev);
|
||||
list_del(&sdata->list);
|
||||
ieee80211_sysfs_remove_netdevice(dev);
|
||||
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 = dev->ieee80211_ptr;
|
||||
struct ieee80211_sub_if_data *sdata, *n;
|
||||
|
||||
ASSERT_RTNL();
|
||||
|
||||
list_for_each_entry_safe(sdata, n, &local->sub_if_list, list) {
|
||||
if ((sdata->type == id || id == -1) &&
|
||||
strcmp(name, sdata->dev->name) == 0 &&
|
||||
sdata->dev != local->mdev) {
|
||||
__ieee80211_if_del(local, sdata);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
void ieee80211_if_free(struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_local *local = dev->ieee80211_ptr;
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
|
||||
/* local->apdev must be NULL when freeing management interface */
|
||||
BUG_ON(dev == local->apdev);
|
||||
ieee80211_if_sdata_deinit(sdata);
|
||||
free_netdev(dev);
|
||||
}
|
||||
|
||||
/* Must be called with rtnl lock held. */
|
||||
void ieee80211_if_flush(struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_local *local = dev->ieee80211_ptr;
|
||||
struct ieee80211_sub_if_data *sdata, *n;
|
||||
|
||||
ASSERT_RTNL();
|
||||
list_for_each_entry_safe(sdata, n, &local->sub_if_list, list) {
|
||||
__ieee80211_if_del(local, sdata);
|
||||
}
|
||||
}
|
||||
|
||||
void ieee80211_if_del(struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_local *local = dev->ieee80211_ptr;
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
|
||||
rtnl_lock();
|
||||
if (sdata->type == IEEE80211_IF_TYPE_MGMT)
|
||||
ieee80211_if_del_mgmt(local);
|
||||
else
|
||||
__ieee80211_if_del(local, sdata);
|
||||
rtnl_unlock();
|
||||
}
|
3243
package/d80211/src/ieee80211_ioctl.c
Normal file
3243
package/d80211/src/ieee80211_ioctl.c
Normal file
File diff suppressed because it is too large
Load diff
89
package/d80211/src/ieee80211_key.h
Normal file
89
package/d80211/src/ieee80211_key.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* 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/kobject.h>
|
||||
#include <linux/crypto.h>
|
||||
#include <net/d80211.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_key {
|
||||
struct kobject kobj;
|
||||
|
||||
int hw_key_idx; /* filled and used by low-level driver */
|
||||
ieee80211_key_alg alg;
|
||||
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;
|
||||
int tx_rx_count; /* number of times this key has been used */
|
||||
int keylen;
|
||||
|
||||
/* if the low level driver can provide hardware acceleration it should
|
||||
* clear this flag */
|
||||
unsigned int force_sw_encrypt:1;
|
||||
int keyidx:8; /* WEP key index */
|
||||
unsigned int default_tx_key:1; /* This key is the new default TX key
|
||||
* (used only for broadcast keys). */
|
||||
|
||||
u8 key[0];
|
||||
};
|
||||
|
||||
#endif /* IEEE80211_KEY_H */
|
91
package/d80211/src/ieee80211_led.c
Normal file
91
package/d80211/src/ieee80211_led.c
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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_init(struct ieee80211_local *local)
|
||||
{
|
||||
local->rx_led = kzalloc(sizeof(struct led_trigger), GFP_KERNEL);
|
||||
if (!local->rx_led)
|
||||
return;
|
||||
snprintf(local->rx_led_name, sizeof(local->rx_led_name),
|
||||
"wiphy%drx", local->hw.index);
|
||||
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)
|
||||
return;
|
||||
snprintf(local->tx_led_name, sizeof(local->tx_led_name),
|
||||
"wiphy%dtx", local->hw.index);
|
||||
local->tx_led->name = local->tx_led_name;
|
||||
if (led_trigger_register(local->tx_led)) {
|
||||
kfree(local->tx_led);
|
||||
local->tx_led = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void ieee80211_led_exit(struct ieee80211_local *local)
|
||||
{
|
||||
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_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);
|
32
package/d80211/src/ieee80211_led.h
Normal file
32
package/d80211/src/ieee80211_led.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* 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_D80211_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_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_init(struct ieee80211_local *local)
|
||||
{
|
||||
}
|
||||
static inline void ieee80211_led_exit(struct ieee80211_local *local)
|
||||
{
|
||||
}
|
||||
#endif
|
140
package/d80211/src/ieee80211_rate.c
Normal file
140
package/d80211/src/ieee80211_rate.c
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* 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 "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 = kmalloc(sizeof(*alg), GFP_KERNEL);
|
||||
if (alg == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(alg, 0, sizeof(*alg));
|
||||
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);
|
||||
}
|
161
package/d80211/src/ieee80211_rate.h
Normal file
161
package/d80211/src/ieee80211_rate.h
Normal file
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* 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/d80211.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 */
|
||||
int startidx, endidx, rateidx;
|
||||
struct ieee80211_rate *nonerp;
|
||||
int nonerp_idx;
|
||||
|
||||
/* parameters from the caller to rate_control_get_rate(): */
|
||||
int mgmt_data; /* this is data frame that is used for management
|
||||
* (e.g., IEEE 802.1X EAPOL) */
|
||||
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);
|
||||
int (*add_sta_attrs)(void *priv, void *priv_sta,
|
||||
struct kobject *kobj);
|
||||
void (*remove_sta_attrs)(void *priv, void *priv_sta,
|
||||
struct kobject *kobj);
|
||||
};
|
||||
|
||||
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 int rate_control_add_attrs(struct rate_control_ref *ref,
|
||||
struct kobject *kobj)
|
||||
{
|
||||
if (ref->ops->add_attrs)
|
||||
return ref->ops->add_attrs(ref->priv, kobj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void rate_control_remove_attrs(struct rate_control_ref *ref,
|
||||
struct kobject *kobj)
|
||||
{
|
||||
if (ref->ops->remove_attrs)
|
||||
ref->ops->remove_attrs(ref->priv, kobj);
|
||||
}
|
||||
|
||||
static inline int rate_control_add_sta_attrs(struct sta_info *sta,
|
||||
struct kobject *kobj)
|
||||
{
|
||||
struct rate_control_ref *ref = sta->rate_ctrl;
|
||||
if (ref->ops->add_sta_attrs)
|
||||
return ref->ops->add_sta_attrs(ref->priv, sta->rate_ctrl_priv,
|
||||
kobj);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void rate_control_remove_sta_attrs(struct sta_info *sta,
|
||||
struct kobject *kobj)
|
||||
{
|
||||
struct rate_control_ref *ref = sta->rate_ctrl;
|
||||
if (ref->ops->remove_sta_attrs)
|
||||
ref->ops->remove_sta_attrs(ref->priv, sta->rate_ctrl_priv,
|
||||
kobj);
|
||||
}
|
||||
|
||||
#endif /* IEEE80211_RATE_H */
|
347
package/d80211/src/ieee80211_scan.c
Normal file
347
package/d80211/src/ieee80211_scan.c
Normal file
|
@ -0,0 +1,347 @@
|
|||
/*
|
||||
* 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/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/skbuff.h>
|
||||
|
||||
#include <net/d80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
|
||||
|
||||
/* Maximum number of seconds to wait for the traffic load to get below
|
||||
* threshold before forcing a passive scan. */
|
||||
#define MAX_SCAN_WAIT 60
|
||||
/* Threshold (pkts/sec TX or RX) for delaying passive scan */
|
||||
#define SCAN_TXRX_THRESHOLD 75
|
||||
|
||||
static void get_channel_params(struct ieee80211_local *local, int channel,
|
||||
struct ieee80211_hw_modes **mode,
|
||||
struct ieee80211_channel **chan)
|
||||
{
|
||||
int m;
|
||||
|
||||
for (m = 0; m < local->hw.num_modes; m++) {
|
||||
*mode = &local->hw.modes[m];
|
||||
if ((*mode)->mode == local->hw.conf.phymode)
|
||||
break;
|
||||
}
|
||||
local->scan.mode_idx = m;
|
||||
local->scan.chan_idx = 0;
|
||||
do {
|
||||
*chan = &(*mode)->channels[local->scan.chan_idx];
|
||||
if ((*chan)->chan == channel) {
|
||||
return;
|
||||
}
|
||||
local->scan.chan_idx++;
|
||||
} while (local->scan.chan_idx < (*mode)->num_channels);
|
||||
*chan = NULL;
|
||||
}
|
||||
|
||||
|
||||
static void next_chan_same_mode(struct ieee80211_local *local,
|
||||
struct ieee80211_hw_modes **mode,
|
||||
struct ieee80211_channel **chan)
|
||||
{
|
||||
int m, prev;
|
||||
|
||||
for (m = 0; m < local->hw.num_modes; m++) {
|
||||
*mode = &local->hw.modes[m];
|
||||
if ((*mode)->mode == local->hw.conf.phymode)
|
||||
break;
|
||||
}
|
||||
local->scan.mode_idx = m;
|
||||
|
||||
/* Select next channel - scan only channels marked with W_SCAN flag */
|
||||
prev = local->scan.chan_idx;
|
||||
do {
|
||||
local->scan.chan_idx++;
|
||||
if (local->scan.chan_idx >= (*mode)->num_channels)
|
||||
local->scan.chan_idx = 0;
|
||||
*chan = &(*mode)->channels[local->scan.chan_idx];
|
||||
if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
|
||||
break;
|
||||
} while (local->scan.chan_idx != prev);
|
||||
}
|
||||
|
||||
|
||||
static void next_chan_all_modes(struct ieee80211_local *local,
|
||||
struct ieee80211_hw_modes **mode,
|
||||
struct ieee80211_channel **chan)
|
||||
{
|
||||
int prev, prev_m;
|
||||
|
||||
if (local->scan.mode_idx >= local->hw.num_modes) {
|
||||
local->scan.mode_idx = 0;
|
||||
local->scan.chan_idx = 0;
|
||||
}
|
||||
|
||||
/* Select next channel - scan only channels marked with W_SCAN flag */
|
||||
prev = local->scan.chan_idx;
|
||||
prev_m = local->scan.mode_idx;
|
||||
do {
|
||||
*mode = &local->hw.modes[local->scan.mode_idx];
|
||||
local->scan.chan_idx++;
|
||||
if (local->scan.chan_idx >= (*mode)->num_channels) {
|
||||
local->scan.chan_idx = 0;
|
||||
local->scan.mode_idx++;
|
||||
if (local->scan.mode_idx >= local->hw.num_modes)
|
||||
local->scan.mode_idx = 0;
|
||||
*mode = &local->hw.modes[local->scan.mode_idx];
|
||||
}
|
||||
*chan = &(*mode)->channels[local->scan.chan_idx];
|
||||
if ((*chan)->flag & IEEE80211_CHAN_W_SCAN)
|
||||
break;
|
||||
} while (local->scan.chan_idx != prev ||
|
||||
local->scan.mode_idx != prev_m);
|
||||
}
|
||||
|
||||
|
||||
static void ieee80211_scan_start(struct ieee80211_local *local,
|
||||
struct ieee80211_scan_conf *conf)
|
||||
{
|
||||
int old_mode_idx = local->scan.mode_idx;
|
||||
int old_chan_idx = local->scan.chan_idx;
|
||||
struct ieee80211_hw_modes *mode = NULL;
|
||||
struct ieee80211_channel *chan = NULL;
|
||||
int ret;
|
||||
|
||||
if (!local->ops->passive_scan) {
|
||||
printk(KERN_DEBUG "%s: Scan handler called, yet the hardware "
|
||||
"does not support passive scanning. Disabled.\n",
|
||||
local->mdev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((local->scan.tries < MAX_SCAN_WAIT &&
|
||||
local->scan.txrx_count > SCAN_TXRX_THRESHOLD)) {
|
||||
local->scan.tries++;
|
||||
/* Count TX/RX packets during one second interval and allow
|
||||
* scan to start only if the number of packets is below the
|
||||
* threshold. */
|
||||
local->scan.txrx_count = 0;
|
||||
local->scan.timer.expires = jiffies + HZ;
|
||||
add_timer(&local->scan.timer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!local->scan.skb) {
|
||||
printk(KERN_DEBUG "%s: Scan start called even though scan.skb "
|
||||
"is not set\n", local->mdev->name);
|
||||
}
|
||||
|
||||
if (local->scan.our_mode_only) {
|
||||
if (local->scan.channel > 0) {
|
||||
get_channel_params(local, local->scan.channel, &mode,
|
||||
&chan);
|
||||
} else
|
||||
next_chan_same_mode(local, &mode, &chan);
|
||||
}
|
||||
else
|
||||
next_chan_all_modes(local, &mode, &chan);
|
||||
|
||||
conf->scan_channel = chan->chan;
|
||||
conf->scan_freq = chan->freq;
|
||||
conf->scan_channel_val = chan->val;
|
||||
conf->scan_phymode = mode->mode;
|
||||
conf->scan_power_level = chan->power_level;
|
||||
conf->scan_antenna_max = chan->antenna_max;
|
||||
conf->scan_time = 2 * local->hw.channel_change_time +
|
||||
local->scan.time; /* 10ms scan time+hardware changes */
|
||||
conf->skb = local->scan.skb ?
|
||||
skb_clone(local->scan.skb, GFP_ATOMIC) : NULL;
|
||||
conf->tx_control = &local->scan.tx_control;
|
||||
#if 0
|
||||
printk(KERN_DEBUG "%s: Doing scan on mode: %d freq: %d chan: %d "
|
||||
"for %d ms\n",
|
||||
local->mdev->name, conf->scan_phymode, conf->scan_freq,
|
||||
conf->scan_channel, conf->scan_time);
|
||||
#endif
|
||||
local->scan.rx_packets = 0;
|
||||
local->scan.rx_beacon = 0;
|
||||
local->scan.freq = chan->freq;
|
||||
local->scan.in_scan = 1;
|
||||
|
||||
ieee80211_netif_oper(local_to_hw(local), NETIF_STOP);
|
||||
|
||||
ret = local->ops->passive_scan(local_to_hw(local),
|
||||
IEEE80211_SCAN_START, conf);
|
||||
|
||||
if (ret == 0) {
|
||||
long usec = local->hw.channel_change_time +
|
||||
local->scan.time;
|
||||
usec += 1000000L / HZ - 1;
|
||||
usec /= 1000000L / HZ;
|
||||
local->scan.timer.expires = jiffies + usec;
|
||||
} else {
|
||||
local->scan.in_scan = 0;
|
||||
if (conf->skb)
|
||||
dev_kfree_skb(conf->skb);
|
||||
ieee80211_netif_oper(local_to_hw(local), NETIF_WAKE);
|
||||
if (ret == -EAGAIN) {
|
||||
local->scan.timer.expires = jiffies +
|
||||
(local->scan.interval * HZ / 100);
|
||||
local->scan.mode_idx = old_mode_idx;
|
||||
local->scan.chan_idx = old_chan_idx;
|
||||
} else {
|
||||
printk(KERN_DEBUG "%s: Got unknown error from "
|
||||
"passive_scan %d\n", local->mdev->name, ret);
|
||||
local->scan.timer.expires = jiffies +
|
||||
(local->scan.interval * HZ);
|
||||
}
|
||||
local->scan.in_scan = 0;
|
||||
}
|
||||
|
||||
add_timer(&local->scan.timer);
|
||||
}
|
||||
|
||||
|
||||
static void ieee80211_scan_stop(struct ieee80211_local *local,
|
||||
struct ieee80211_scan_conf *conf)
|
||||
{
|
||||
struct ieee80211_hw_modes *mode;
|
||||
struct ieee80211_channel *chan;
|
||||
int wait;
|
||||
|
||||
if (!local->ops->passive_scan)
|
||||
return;
|
||||
|
||||
if (local->scan.mode_idx >= local->hw.num_modes) {
|
||||
local->scan.mode_idx = 0;
|
||||
local->scan.chan_idx = 0;
|
||||
}
|
||||
|
||||
mode = &local->hw.modes[local->scan.mode_idx];
|
||||
|
||||
if (local->scan.chan_idx >= mode->num_channels) {
|
||||
local->scan.chan_idx = 0;
|
||||
}
|
||||
|
||||
chan = &mode->channels[local->scan.chan_idx];
|
||||
|
||||
local->ops->passive_scan(local_to_hw(local), IEEE80211_SCAN_END,
|
||||
conf);
|
||||
|
||||
#ifdef CONFIG_D80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: Did scan on mode: %d freq: %d chan: %d "
|
||||
"GOT: %d Beacon: %d (%d)\n",
|
||||
local->mdev->name,
|
||||
mode->mode, chan->freq, chan->chan,
|
||||
local->scan.rx_packets, local->scan.rx_beacon,
|
||||
local->scan.tries);
|
||||
#endif /* CONFIG_D80211_VERBOSE_DEBUG */
|
||||
local->scan.num_scans++;
|
||||
|
||||
local->scan.in_scan = 0;
|
||||
ieee80211_netif_oper(local_to_hw(local), NETIF_WAKE);
|
||||
|
||||
local->scan.tries = 0;
|
||||
/* Use random interval of scan.interval .. 2 * scan.interval */
|
||||
wait = (local->scan.interval * HZ * ((net_random() & 127) + 128)) /
|
||||
128;
|
||||
local->scan.timer.expires = jiffies + wait;
|
||||
|
||||
add_timer(&local->scan.timer);
|
||||
}
|
||||
|
||||
|
||||
static void ieee80211_scan_handler(unsigned long ullocal)
|
||||
{
|
||||
struct ieee80211_local *local = (struct ieee80211_local *) ullocal;
|
||||
struct ieee80211_scan_conf conf;
|
||||
|
||||
if (local->scan.interval == 0 && !local->scan.in_scan) {
|
||||
/* Passive scanning is disabled - keep the timer always
|
||||
* running to make code cleaner. */
|
||||
local->scan.timer.expires = jiffies + 10 * HZ;
|
||||
add_timer(&local->scan.timer);
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&conf, 0, sizeof(struct ieee80211_scan_conf));
|
||||
conf.running_freq = local->hw.conf.freq;
|
||||
conf.running_channel = local->hw.conf.channel;
|
||||
conf.running_phymode = local->hw.conf.phymode;
|
||||
conf.running_channel_val = local->hw.conf.channel_val;
|
||||
conf.running_power_level = local->hw.conf.power_level;
|
||||
conf.running_antenna_max = local->hw.conf.antenna_max;
|
||||
|
||||
if (local->scan.in_scan == 0)
|
||||
ieee80211_scan_start(local, &conf);
|
||||
else
|
||||
ieee80211_scan_stop(local, &conf);
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_init_scan(struct ieee80211_local *local)
|
||||
{
|
||||
struct ieee80211_hdr hdr;
|
||||
u16 fc;
|
||||
int len = 10;
|
||||
struct rate_control_extra extra;
|
||||
|
||||
/* Only initialize passive scanning if the hardware supports it */
|
||||
if (!local->ops->passive_scan) {
|
||||
local->scan.skb = NULL;
|
||||
memset(&local->scan.tx_control, 0,
|
||||
sizeof(local->scan.tx_control));
|
||||
printk(KERN_DEBUG "%s: Does not support passive scan, "
|
||||
"disabled\n", local->mdev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
local->scan.interval = 0;
|
||||
local->scan.our_mode_only = 1;
|
||||
local->scan.time = 10000;
|
||||
local->scan.timer.function = ieee80211_scan_handler;
|
||||
local->scan.timer.data = (unsigned long) local;
|
||||
local->scan.timer.expires = jiffies + local->scan.interval * HZ;
|
||||
add_timer(&local->scan.timer);
|
||||
|
||||
/* Create a CTS from for broadcasting before
|
||||
* the low level changes channels */
|
||||
local->scan.skb = alloc_skb(len, GFP_KERNEL);
|
||||
if (!local->scan.skb) {
|
||||
printk(KERN_WARNING "%s: Failed to allocate CTS packet for "
|
||||
"passive scan\n", local->mdev->name);
|
||||
return;
|
||||
}
|
||||
|
||||
fc = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS;
|
||||
hdr.frame_control = cpu_to_le16(fc);
|
||||
hdr.duration_id =
|
||||
cpu_to_le16(2 * local->hw.channel_change_time +
|
||||
local->scan.time);
|
||||
memcpy(hdr.addr1, local->mdev->dev_addr, ETH_ALEN); /* DA */
|
||||
hdr.seq_ctrl = 0;
|
||||
|
||||
memcpy(skb_put(local->scan.skb, len), &hdr, len);
|
||||
|
||||
memset(&local->scan.tx_control, 0, sizeof(local->scan.tx_control));
|
||||
local->scan.tx_control.key_idx = HW_KEY_IDX_INVALID;
|
||||
local->scan.tx_control.flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
|
||||
memset(&extra, 0, sizeof(extra));
|
||||
extra.endidx = local->num_curr_rates;
|
||||
local->scan.tx_control.tx_rate =
|
||||
rate_control_get_rate(local, local->mdev,
|
||||
local->scan.skb, &extra)->val;
|
||||
local->scan.tx_control.flags |= IEEE80211_TXCTL_NO_ACK;
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_stop_scan(struct ieee80211_local *local)
|
||||
{
|
||||
if (local->ops->passive_scan) {
|
||||
del_timer_sync(&local->scan.timer);
|
||||
dev_kfree_skb(local->scan.skb);
|
||||
local->scan.skb = NULL;
|
||||
}
|
||||
}
|
2891
package/d80211/src/ieee80211_sta.c
Normal file
2891
package/d80211/src/ieee80211_sta.c
Normal file
File diff suppressed because it is too large
Load diff
787
package/d80211/src/ieee80211_sysfs.c
Normal file
787
package/d80211/src/ieee80211_sysfs.c
Normal file
|
@ -0,0 +1,787 @@
|
|||
/*
|
||||
* 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/device.h>
|
||||
#include <linux/if.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
#include <net/d80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
|
||||
#define to_ieee80211_local(class) \
|
||||
container_of(class, struct ieee80211_local, class_dev)
|
||||
#define to_net_dev(class) \
|
||||
container_of(class, struct net_device, class_dev)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static const char *ieee80211_mode_str_short(int mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case MODE_IEEE80211A:
|
||||
return "802.11a";
|
||||
case MODE_IEEE80211B:
|
||||
return "802.11b";
|
||||
case MODE_IEEE80211G:
|
||||
return "802.11g";
|
||||
case MODE_ATHEROS_TURBO:
|
||||
return "AtherosTurbo";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
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";
|
||||
case MODE_ATHEROS_TURBO:
|
||||
return "Atheros Turbo (5 GHz)";
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
/* attributes in /sys/class/ieee80211/phyX/ */
|
||||
|
||||
static ssize_t store_add_iface(struct class_device *dev,
|
||||
const char *buf, size_t len)
|
||||
{
|
||||
struct ieee80211_local *local = to_ieee80211_local(dev);
|
||||
struct net_device *new_dev;
|
||||
int res;
|
||||
|
||||
if (!capable(CAP_NET_ADMIN))
|
||||
return -EPERM;
|
||||
if (len > IFNAMSIZ)
|
||||
return -EINVAL;
|
||||
res = rtnl_lock_local(local);
|
||||
if (res)
|
||||
return res;
|
||||
res = ieee80211_if_add(local->mdev, buf, 0, &new_dev);
|
||||
if (res == 0)
|
||||
ieee80211_if_set_type(new_dev, IEEE80211_IF_TYPE_STA);
|
||||
rtnl_unlock();
|
||||
return res < 0 ? res : len;
|
||||
}
|
||||
|
||||
static ssize_t store_remove_iface(struct class_device *dev,
|
||||
const char *buf, size_t len)
|
||||
{
|
||||
struct ieee80211_local *local = to_ieee80211_local(dev);
|
||||
int res;
|
||||
|
||||
if (!capable(CAP_NET_ADMIN))
|
||||
return -EPERM;
|
||||
if (len > IFNAMSIZ)
|
||||
return -EINVAL;
|
||||
res = rtnl_lock_local(local);
|
||||
if (res)
|
||||
return res;
|
||||
res = ieee80211_if_remove(local->mdev, buf, -1);
|
||||
rtnl_unlock();
|
||||
return res < 0 ? res : len;
|
||||
}
|
||||
|
||||
static ssize_t store_rate_ctrl_alg(struct class_device *dev,
|
||||
const char *buf, size_t len)
|
||||
{
|
||||
struct ieee80211_local *local = to_ieee80211_local(dev);
|
||||
int res;
|
||||
|
||||
if (!capable(CAP_NET_ADMIN))
|
||||
return -EPERM;
|
||||
res = rtnl_lock_local(local);
|
||||
if (res)
|
||||
return res;
|
||||
res = ieee80211_init_rate_ctrl_alg(local, buf);
|
||||
rtnl_unlock();
|
||||
return res < 0 ? res : len;
|
||||
}
|
||||
|
||||
static ssize_t ieee80211_local_show(struct class_device *dev, char *buf,
|
||||
ssize_t (*format)(struct ieee80211_local *, char *))
|
||||
{
|
||||
struct ieee80211_local *local = to_ieee80211_local(dev);
|
||||
ssize_t ret = -EINVAL;
|
||||
|
||||
if (local->reg_state == IEEE80211_DEV_REGISTERED)
|
||||
ret = (*format)(local, buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define IEEE80211_LOCAL_FMT(name, field, format_string) \
|
||||
static ssize_t ieee80211_local_fmt_##name(struct ieee80211_local *local,\
|
||||
char *buf) \
|
||||
{ \
|
||||
return sprintf(buf, format_string, local->field); \
|
||||
}
|
||||
|
||||
#define __IEEE80211_LOCAL_SHOW(name) \
|
||||
static ssize_t ieee80211_local_show_##name(struct class_device *cd, \
|
||||
char *buf) \
|
||||
{ \
|
||||
return ieee80211_local_show(cd, buf, \
|
||||
ieee80211_local_fmt_##name); \
|
||||
}
|
||||
|
||||
#define IEEE80211_LOCAL_SHOW(name, field, format) \
|
||||
IEEE80211_LOCAL_FMT(name, field, format "\n") \
|
||||
__IEEE80211_LOCAL_SHOW(name)
|
||||
|
||||
IEEE80211_LOCAL_SHOW(channel, hw.conf.channel, "%d");
|
||||
IEEE80211_LOCAL_SHOW(frequency, hw.conf.freq, "%d");
|
||||
IEEE80211_LOCAL_SHOW(radar_detect, hw.conf.radar_detect, "%d");
|
||||
IEEE80211_LOCAL_SHOW(antenna_sel, hw.conf.antenna_sel, "%d");
|
||||
IEEE80211_LOCAL_SHOW(bridge_packets, bridge_packets, "%d");
|
||||
IEEE80211_LOCAL_SHOW(key_tx_rx_threshold, key_tx_rx_threshold, "%d");
|
||||
IEEE80211_LOCAL_SHOW(rts_threshold, rts_threshold, "%d");
|
||||
IEEE80211_LOCAL_SHOW(fragmentation_threshold, fragmentation_threshold, "%d");
|
||||
IEEE80211_LOCAL_SHOW(short_retry_limit, short_retry_limit, "%d");
|
||||
IEEE80211_LOCAL_SHOW(long_retry_limit, long_retry_limit, "%d");
|
||||
IEEE80211_LOCAL_SHOW(total_ps_buffered, total_ps_buffered, "%d");
|
||||
|
||||
static ssize_t ieee80211_local_fmt_mode(struct ieee80211_local *local,
|
||||
char *buf)
|
||||
{
|
||||
return sprintf(buf, "%s\n", ieee80211_mode_str(local->hw.conf.phymode));
|
||||
}
|
||||
__IEEE80211_LOCAL_SHOW(mode);
|
||||
|
||||
static ssize_t ieee80211_local_fmt_wep_iv(struct ieee80211_local *local,
|
||||
char *buf)
|
||||
{
|
||||
return sprintf(buf, "%#06x\n", local->wep_iv & 0xffffff);
|
||||
}
|
||||
__IEEE80211_LOCAL_SHOW(wep_iv);
|
||||
|
||||
static ssize_t ieee80211_local_fmt_tx_power_reduction(struct ieee80211_local
|
||||
*local, char *buf)
|
||||
{
|
||||
short tx_power_reduction = local->hw.conf.tx_power_reduction;
|
||||
|
||||
return sprintf(buf, "%d.%d dBm\n", tx_power_reduction / 10,
|
||||
tx_power_reduction % 10);
|
||||
}
|
||||
__IEEE80211_LOCAL_SHOW(tx_power_reduction);
|
||||
|
||||
static ssize_t ieee80211_local_fmt_modes(struct ieee80211_local *local,
|
||||
char *buf)
|
||||
{
|
||||
int i;
|
||||
struct ieee80211_hw_modes *mode;
|
||||
char *p = buf;
|
||||
|
||||
/* FIXME: locking against ieee80211_update_hw? */
|
||||
for (i = 0; i < local->hw.num_modes; i++) {
|
||||
mode = &local->hw.modes[i];
|
||||
p += sprintf(p, "%s\n", ieee80211_mode_str_short(mode->mode));
|
||||
}
|
||||
return (p - buf);
|
||||
}
|
||||
__IEEE80211_LOCAL_SHOW(modes);
|
||||
|
||||
static ssize_t ieee80211_local_fmt_rate_ctrl_alg(struct ieee80211_local *local,
|
||||
char *buf)
|
||||
{
|
||||
struct rate_control_ref *ref = local->rate_ctrl;
|
||||
if (ref)
|
||||
return sprintf(buf, "%s\n", ref->ops->name);
|
||||
return 0;
|
||||
}
|
||||
__IEEE80211_LOCAL_SHOW(rate_ctrl_alg);
|
||||
|
||||
static struct class_device_attribute ieee80211_class_dev_attrs[] = {
|
||||
__ATTR(add_iface, S_IWUGO, NULL, store_add_iface),
|
||||
__ATTR(remove_iface, S_IWUGO, NULL, store_remove_iface),
|
||||
__ATTR(channel, S_IRUGO, ieee80211_local_show_channel, NULL),
|
||||
__ATTR(frequency, S_IRUGO, ieee80211_local_show_frequency, NULL),
|
||||
__ATTR(radar_detect, S_IRUGO, ieee80211_local_show_radar_detect, NULL),
|
||||
__ATTR(antenna_sel, S_IRUGO, ieee80211_local_show_antenna_sel, NULL),
|
||||
__ATTR(bridge_packets, S_IRUGO, ieee80211_local_show_bridge_packets, NULL),
|
||||
__ATTR(key_tx_rx_threshold, S_IRUGO, ieee80211_local_show_key_tx_rx_threshold, NULL),
|
||||
__ATTR(rts_threshold, S_IRUGO, ieee80211_local_show_rts_threshold, NULL),
|
||||
__ATTR(fragmentation_threshold, S_IRUGO, ieee80211_local_show_fragmentation_threshold, NULL),
|
||||
__ATTR(short_retry_limit, S_IRUGO, ieee80211_local_show_short_retry_limit, NULL),
|
||||
__ATTR(long_retry_limit, S_IRUGO, ieee80211_local_show_long_retry_limit, NULL),
|
||||
__ATTR(total_ps_buffered, S_IRUGO, ieee80211_local_show_total_ps_buffered, NULL),
|
||||
__ATTR(mode, S_IRUGO, ieee80211_local_show_mode, NULL),
|
||||
__ATTR(wep_iv, S_IRUGO, ieee80211_local_show_wep_iv, NULL),
|
||||
__ATTR(tx_power_reduction, S_IRUGO, ieee80211_local_show_tx_power_reduction, NULL),
|
||||
__ATTR(modes, S_IRUGO, ieee80211_local_show_modes, NULL),
|
||||
__ATTR(rate_ctrl_alg, S_IRUGO | S_IWUGO, ieee80211_local_show_rate_ctrl_alg, store_rate_ctrl_alg),
|
||||
{}
|
||||
};
|
||||
|
||||
/* attributes in /sys/class/ieee80211/phyX/statistics/ */
|
||||
|
||||
#define IEEE80211_LOCAL_ATTR(name, field, format) \
|
||||
IEEE80211_LOCAL_SHOW(name, field, format) \
|
||||
static CLASS_DEVICE_ATTR(name, S_IRUGO, ieee80211_local_show_##name, NULL);
|
||||
|
||||
IEEE80211_LOCAL_ATTR(transmitted_fragment_count, dot11TransmittedFragmentCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(multicast_transmitted_frame_count, dot11MulticastTransmittedFrameCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(failed_count, dot11FailedCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(retry_count, dot11RetryCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(multiple_retry_count, dot11MultipleRetryCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(frame_duplicate_count, dot11FrameDuplicateCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(received_fragment_count, dot11ReceivedFragmentCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(multicast_received_frame_count, dot11MulticastReceivedFrameCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(transmitted_frame_count, dot11TransmittedFrameCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(wep_undecryptable_count, dot11WEPUndecryptableCount, "%u");
|
||||
IEEE80211_LOCAL_ATTR(num_scans, scan.num_scans, "%u");
|
||||
|
||||
#ifdef CONFIG_D80211_DEBUG_COUNTERS
|
||||
IEEE80211_LOCAL_ATTR(tx_handlers_drop, tx_handlers_drop, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_handlers_queued, tx_handlers_queued, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_handlers_drop_unencrypted, tx_handlers_drop_unencrypted, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_handlers_drop_fragment, tx_handlers_drop_fragment, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_handlers_drop_wep, tx_handlers_drop_wep, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_handlers_drop_not_assoc, tx_handlers_drop_not_assoc, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_handlers_drop_unauth_port, tx_handlers_drop_unauth_port, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_handlers_drop, rx_handlers_drop, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_handlers_queued, rx_handlers_queued, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_handlers_drop_nullfunc, rx_handlers_drop_nullfunc, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_handlers_drop_defrag, rx_handlers_drop_defrag, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_handlers_drop_short, rx_handlers_drop_short, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_handlers_drop_passive_scan, rx_handlers_drop_passive_scan, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_expand_skb_head, tx_expand_skb_head, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_expand_skb_head_cloned, tx_expand_skb_head_cloned, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_expand_skb_head, rx_expand_skb_head, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_expand_skb_head2, rx_expand_skb_head2, "%u");
|
||||
IEEE80211_LOCAL_ATTR(rx_handlers_fragments, rx_handlers_fragments, "%u");
|
||||
IEEE80211_LOCAL_ATTR(tx_status_drop, tx_status_drop, "%u");
|
||||
|
||||
static ssize_t ieee80211_local_fmt_wme_rx_queue(struct ieee80211_local *local,
|
||||
char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += sprintf(p, "%u\n", local->wme_rx_queue[i]);
|
||||
return (p - buf);
|
||||
}
|
||||
__IEEE80211_LOCAL_SHOW(wme_rx_queue);
|
||||
static CLASS_DEVICE_ATTR(wme_rx_queue, S_IRUGO,
|
||||
ieee80211_local_show_wme_rx_queue, NULL);
|
||||
|
||||
static ssize_t ieee80211_local_fmt_wme_tx_queue(struct ieee80211_local *local,
|
||||
char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += sprintf(p, "%u\n", local->wme_tx_queue[i]);
|
||||
return (p - buf);
|
||||
}
|
||||
__IEEE80211_LOCAL_SHOW(wme_tx_queue);
|
||||
static CLASS_DEVICE_ATTR(wme_tx_queue, S_IRUGO,
|
||||
ieee80211_local_show_wme_tx_queue, NULL);
|
||||
#endif
|
||||
|
||||
static ssize_t ieee80211_stats_show(struct class_device *dev, char *buf,
|
||||
ssize_t (*format)(struct ieee80211_low_level_stats *, char *))
|
||||
{
|
||||
struct ieee80211_local *local = to_ieee80211_local(dev);
|
||||
struct ieee80211_low_level_stats stats;
|
||||
ssize_t ret = -EINVAL;
|
||||
|
||||
if (!local->ops->get_stats)
|
||||
return -EOPNOTSUPP;
|
||||
ret = rtnl_lock_local(local);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = local->ops->get_stats(local_to_hw(local), &stats);
|
||||
rtnl_unlock();
|
||||
if (!ret)
|
||||
ret = (*format)(&stats, buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define IEEE80211_STATS_FMT(name, field, format_string) \
|
||||
static ssize_t ieee80211_stats_fmt_##name(struct ieee80211_low_level_stats \
|
||||
*stats, char *buf) \
|
||||
{ \
|
||||
return sprintf(buf, format_string, stats->field); \
|
||||
}
|
||||
|
||||
#define __IEEE80211_STATS_SHOW(name) \
|
||||
static ssize_t ieee80211_stats_show_##name(struct class_device *cd, \
|
||||
char *buf) \
|
||||
{ \
|
||||
return ieee80211_stats_show(cd, buf, \
|
||||
ieee80211_stats_fmt_##name); \
|
||||
}
|
||||
|
||||
#define IEEE80211_STATS_ATTR(name, field, format) \
|
||||
IEEE80211_STATS_FMT(name, field, format "\n") \
|
||||
__IEEE80211_STATS_SHOW(name) \
|
||||
static CLASS_DEVICE_ATTR(name, S_IRUGO, ieee80211_stats_show_##name, NULL);
|
||||
|
||||
IEEE80211_STATS_ATTR(ack_failure_count, dot11ACKFailureCount, "%u");
|
||||
IEEE80211_STATS_ATTR(rts_failure_count, dot11RTSFailureCount, "%u");
|
||||
IEEE80211_STATS_ATTR(fcs_error_count, dot11FCSErrorCount, "%u");
|
||||
IEEE80211_STATS_ATTR(rts_success_count, dot11RTSSuccessCount, "%u");
|
||||
|
||||
static struct attribute *ieee80211_stats_attrs[] = {
|
||||
&class_device_attr_transmitted_fragment_count.attr,
|
||||
&class_device_attr_multicast_transmitted_frame_count.attr,
|
||||
&class_device_attr_failed_count.attr,
|
||||
&class_device_attr_retry_count.attr,
|
||||
&class_device_attr_multiple_retry_count.attr,
|
||||
&class_device_attr_frame_duplicate_count.attr,
|
||||
&class_device_attr_received_fragment_count.attr,
|
||||
&class_device_attr_multicast_received_frame_count.attr,
|
||||
&class_device_attr_transmitted_frame_count.attr,
|
||||
&class_device_attr_wep_undecryptable_count.attr,
|
||||
&class_device_attr_ack_failure_count.attr,
|
||||
&class_device_attr_rts_failure_count.attr,
|
||||
&class_device_attr_fcs_error_count.attr,
|
||||
&class_device_attr_rts_success_count.attr,
|
||||
&class_device_attr_num_scans.attr,
|
||||
#ifdef CONFIG_D80211_DEBUG_COUNTERS
|
||||
&class_device_attr_tx_handlers_drop.attr,
|
||||
&class_device_attr_tx_handlers_queued.attr,
|
||||
&class_device_attr_tx_handlers_drop_unencrypted.attr,
|
||||
&class_device_attr_tx_handlers_drop_fragment.attr,
|
||||
&class_device_attr_tx_handlers_drop_wep.attr,
|
||||
&class_device_attr_tx_handlers_drop_not_assoc.attr,
|
||||
&class_device_attr_tx_handlers_drop_unauth_port.attr,
|
||||
&class_device_attr_rx_handlers_drop.attr,
|
||||
&class_device_attr_rx_handlers_queued.attr,
|
||||
&class_device_attr_rx_handlers_drop_nullfunc.attr,
|
||||
&class_device_attr_rx_handlers_drop_defrag.attr,
|
||||
&class_device_attr_rx_handlers_drop_short.attr,
|
||||
&class_device_attr_rx_handlers_drop_passive_scan.attr,
|
||||
&class_device_attr_tx_expand_skb_head.attr,
|
||||
&class_device_attr_tx_expand_skb_head_cloned.attr,
|
||||
&class_device_attr_rx_expand_skb_head.attr,
|
||||
&class_device_attr_rx_expand_skb_head2.attr,
|
||||
&class_device_attr_rx_handlers_fragments.attr,
|
||||
&class_device_attr_tx_status_drop.attr,
|
||||
&class_device_attr_wme_rx_queue.attr,
|
||||
&class_device_attr_wme_tx_queue.attr,
|
||||
#endif
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct attribute_group ieee80211_stats_group = {
|
||||
.name = "statistics",
|
||||
.attrs = ieee80211_stats_attrs,
|
||||
};
|
||||
|
||||
/* attributes in /sys/class/net/X/ */
|
||||
|
||||
static ssize_t ieee80211_if_show(struct class_device *cd, char *buf,
|
||||
ssize_t (*format)(const struct ieee80211_sub_if_data *,
|
||||
char *))
|
||||
{
|
||||
struct net_device *dev = to_net_dev(cd);
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
ssize_t ret = -EINVAL;
|
||||
|
||||
read_lock(&dev_base_lock);
|
||||
if (dev->reg_state == NETREG_REGISTERED) {
|
||||
ret = (*format)(sdata, buf);
|
||||
}
|
||||
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) \
|
||||
{ \
|
||||
return sprintf(buf, 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) \
|
||||
{ \
|
||||
return sprintf(buf, "%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) \
|
||||
{ \
|
||||
return sprintf(buf, MAC_FMT "\n", MAC_ARG(sdata->field)); \
|
||||
}
|
||||
|
||||
#define __IEEE80211_IF_SHOW(name) \
|
||||
static ssize_t ieee80211_if_show_##name(struct class_device *cd, \
|
||||
char *buf) \
|
||||
{ \
|
||||
return ieee80211_if_show(cd, buf, ieee80211_if_fmt_##name); \
|
||||
} \
|
||||
static CLASS_DEVICE_ATTR(name, S_IRUGO, ieee80211_if_show_##name, NULL);
|
||||
|
||||
#define IEEE80211_IF_SHOW(name, field, format) \
|
||||
IEEE80211_IF_FMT_##format(name, field) \
|
||||
__IEEE80211_IF_SHOW(name)
|
||||
|
||||
/* common attributes */
|
||||
IEEE80211_IF_SHOW(channel_use, channel_use, DEC);
|
||||
IEEE80211_IF_SHOW(drop_unencrypted, drop_unencrypted, DEC);
|
||||
IEEE80211_IF_SHOW(eapol, eapol, DEC);
|
||||
IEEE80211_IF_SHOW(ieee8021_x, ieee802_1x, DEC);
|
||||
|
||||
/* STA/IBSS attributes */
|
||||
IEEE80211_IF_SHOW(state, u.sta.state, DEC);
|
||||
IEEE80211_IF_SHOW(bssid, u.sta.bssid, MAC);
|
||||
IEEE80211_IF_SHOW(prev_bssid, u.sta.prev_bssid, MAC);
|
||||
IEEE80211_IF_SHOW(ssid_len, u.sta.ssid_len, SIZE);
|
||||
IEEE80211_IF_SHOW(aid, u.sta.aid, DEC);
|
||||
IEEE80211_IF_SHOW(ap_capab, u.sta.ap_capab, HEX);
|
||||
IEEE80211_IF_SHOW(capab, u.sta.capab, HEX);
|
||||
IEEE80211_IF_SHOW(extra_ie_len, u.sta.extra_ie_len, SIZE);
|
||||
IEEE80211_IF_SHOW(auth_tries, u.sta.auth_tries, DEC);
|
||||
IEEE80211_IF_SHOW(assoc_tries, u.sta.assoc_tries, DEC);
|
||||
IEEE80211_IF_SHOW(auth_algs, u.sta.auth_algs, HEX);
|
||||
IEEE80211_IF_SHOW(auth_alg, u.sta.auth_alg, DEC);
|
||||
IEEE80211_IF_SHOW(auth_transaction, u.sta.auth_transaction, DEC);
|
||||
|
||||
static ssize_t ieee80211_if_fmt_flags(const struct
|
||||
ieee80211_sub_if_data *sdata, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%s%s%s%s%s%s%s\n",
|
||||
sdata->u.sta.ssid_set ? "SSID\n" : "",
|
||||
sdata->u.sta.bssid_set ? "BSSID\n" : "",
|
||||
sdata->u.sta.prev_bssid_set ? "prev BSSID\n" : "",
|
||||
sdata->u.sta.authenticated ? "AUTH\n" : "",
|
||||
sdata->u.sta.associated ? "ASSOC\n" : "",
|
||||
sdata->u.sta.probereq_poll ? "PROBEREQ POLL\n" : "",
|
||||
sdata->u.sta.use_protection ? "CTS prot\n" : "");
|
||||
}
|
||||
__IEEE80211_IF_SHOW(flags);
|
||||
|
||||
/* AP attributes */
|
||||
IEEE80211_IF_SHOW(num_sta_ps, u.ap.num_sta_ps, ATOMIC);
|
||||
IEEE80211_IF_SHOW(dtim_period, u.ap.dtim_period, DEC);
|
||||
IEEE80211_IF_SHOW(dtim_count, u.ap.dtim_count, DEC);
|
||||
IEEE80211_IF_SHOW(num_beacons, u.ap.num_beacons, DEC);
|
||||
IEEE80211_IF_SHOW(force_unicast_rateidx, u.ap.force_unicast_rateidx, DEC);
|
||||
IEEE80211_IF_SHOW(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)
|
||||
{
|
||||
return sprintf(buf, "%u\n", skb_queue_len(&sdata->u.ap.ps_bc_buf));
|
||||
}
|
||||
__IEEE80211_IF_SHOW(num_buffered_multicast);
|
||||
|
||||
static ssize_t ieee80211_if_fmt_beacon_head_len(const struct
|
||||
ieee80211_sub_if_data *sdata, char *buf)
|
||||
{
|
||||
if (sdata->u.ap.beacon_head)
|
||||
return sprintf(buf, "%d\n", sdata->u.ap.beacon_head_len);
|
||||
return sprintf(buf, "\n");
|
||||
}
|
||||
__IEEE80211_IF_SHOW(beacon_head_len);
|
||||
|
||||
static ssize_t ieee80211_if_fmt_beacon_tail_len(const struct
|
||||
ieee80211_sub_if_data *sdata, char *buf)
|
||||
{
|
||||
if (sdata->u.ap.beacon_tail)
|
||||
return sprintf(buf, "%d\n", sdata->u.ap.beacon_tail_len);
|
||||
return sprintf(buf, "\n");
|
||||
}
|
||||
__IEEE80211_IF_SHOW(beacon_tail_len);
|
||||
|
||||
/* WDS attributes */
|
||||
IEEE80211_IF_SHOW(peer, u.wds.remote_addr, MAC);
|
||||
|
||||
/* VLAN attributes */
|
||||
IEEE80211_IF_SHOW(vlan_id, u.vlan.id, DEC);
|
||||
|
||||
/* MONITOR attributes */
|
||||
static ssize_t ieee80211_if_fmt_mode(const struct
|
||||
ieee80211_sub_if_data *sdata, char *buf)
|
||||
{
|
||||
struct ieee80211_local *local = sdata->local;
|
||||
|
||||
return sprintf(buf, "%s\n",
|
||||
((local->hw.flags & IEEE80211_HW_MONITOR_DURING_OPER) ||
|
||||
local->open_count == local->monitors) ?
|
||||
"hard" : "soft");
|
||||
}
|
||||
__IEEE80211_IF_SHOW(mode);
|
||||
|
||||
static struct attribute *ieee80211_sta_attrs[] = {
|
||||
&class_device_attr_channel_use.attr,
|
||||
&class_device_attr_drop_unencrypted.attr,
|
||||
&class_device_attr_eapol.attr,
|
||||
&class_device_attr_ieee8021_x.attr,
|
||||
&class_device_attr_state.attr,
|
||||
&class_device_attr_bssid.attr,
|
||||
&class_device_attr_prev_bssid.attr,
|
||||
&class_device_attr_ssid_len.attr,
|
||||
&class_device_attr_aid.attr,
|
||||
&class_device_attr_ap_capab.attr,
|
||||
&class_device_attr_capab.attr,
|
||||
&class_device_attr_extra_ie_len.attr,
|
||||
&class_device_attr_auth_tries.attr,
|
||||
&class_device_attr_assoc_tries.attr,
|
||||
&class_device_attr_auth_algs.attr,
|
||||
&class_device_attr_auth_alg.attr,
|
||||
&class_device_attr_auth_transaction.attr,
|
||||
&class_device_attr_flags.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *ieee80211_ap_attrs[] = {
|
||||
&class_device_attr_channel_use.attr,
|
||||
&class_device_attr_drop_unencrypted.attr,
|
||||
&class_device_attr_eapol.attr,
|
||||
&class_device_attr_ieee8021_x.attr,
|
||||
&class_device_attr_num_sta_ps.attr,
|
||||
&class_device_attr_dtim_period.attr,
|
||||
&class_device_attr_dtim_count.attr,
|
||||
&class_device_attr_num_beacons.attr,
|
||||
&class_device_attr_force_unicast_rateidx.attr,
|
||||
&class_device_attr_max_ratectrl_rateidx.attr,
|
||||
&class_device_attr_num_buffered_multicast.attr,
|
||||
&class_device_attr_beacon_head_len.attr,
|
||||
&class_device_attr_beacon_tail_len.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *ieee80211_wds_attrs[] = {
|
||||
&class_device_attr_channel_use.attr,
|
||||
&class_device_attr_drop_unencrypted.attr,
|
||||
&class_device_attr_eapol.attr,
|
||||
&class_device_attr_ieee8021_x.attr,
|
||||
&class_device_attr_peer.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *ieee80211_vlan_attrs[] = {
|
||||
&class_device_attr_channel_use.attr,
|
||||
&class_device_attr_drop_unencrypted.attr,
|
||||
&class_device_attr_eapol.attr,
|
||||
&class_device_attr_ieee8021_x.attr,
|
||||
&class_device_attr_vlan_id.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute *ieee80211_monitor_attrs[] = {
|
||||
&class_device_attr_mode.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
static struct attribute_group ieee80211_sta_group = {
|
||||
.name = "sta",
|
||||
.attrs = ieee80211_sta_attrs,
|
||||
};
|
||||
|
||||
static struct attribute_group ieee80211_ap_group = {
|
||||
.name = "ap",
|
||||
.attrs = ieee80211_ap_attrs,
|
||||
};
|
||||
|
||||
static struct attribute_group ieee80211_wds_group = {
|
||||
.name = "wds",
|
||||
.attrs = ieee80211_wds_attrs,
|
||||
};
|
||||
|
||||
static struct attribute_group ieee80211_vlan_group = {
|
||||
.name = "vlan",
|
||||
.attrs = ieee80211_vlan_attrs,
|
||||
};
|
||||
|
||||
static struct attribute_group ieee80211_monitor_group = {
|
||||
.name = "monitor",
|
||||
.attrs = ieee80211_monitor_attrs,
|
||||
};
|
||||
|
||||
/* /sys/class/ieee80211/phyX functions */
|
||||
|
||||
static void ieee80211_class_dev_release(struct class_device *dev)
|
||||
{
|
||||
ieee80211_release_hw(to_ieee80211_local(dev));
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HOTPLUG
|
||||
static int ieee80211_uevent(struct class_device *cd, char **envp,
|
||||
int num_envp, char *buf, int size)
|
||||
{
|
||||
struct ieee80211_local *local = to_ieee80211_local(cd);
|
||||
|
||||
if (num_envp < 2)
|
||||
return -ENOMEM;
|
||||
envp[0] = buf;
|
||||
if (snprintf(buf, size, "IEEE80211_DEV=phy%d",
|
||||
local->hw.index) + 1 >= size)
|
||||
return -ENOMEM;
|
||||
envp[1] = NULL;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static struct class ieee80211_class = {
|
||||
.name = "ieee80211",
|
||||
.class_dev_attrs = ieee80211_class_dev_attrs,
|
||||
.release = ieee80211_class_dev_release,
|
||||
#ifdef CONFIG_HOTPLUG
|
||||
.uevent = ieee80211_uevent,
|
||||
#endif
|
||||
};
|
||||
|
||||
void ieee80211_dev_sysfs_init(struct ieee80211_local *local)
|
||||
{
|
||||
local->class_dev.class = &ieee80211_class;
|
||||
local->class_dev.class_data = local;
|
||||
class_device_initialize(&local->class_dev);
|
||||
}
|
||||
|
||||
void ieee80211_dev_sysfs_put(struct ieee80211_local *local)
|
||||
{
|
||||
class_device_put(&local->class_dev);
|
||||
}
|
||||
|
||||
int ieee80211_dev_sysfs_add(struct ieee80211_local *local)
|
||||
{
|
||||
int res;
|
||||
|
||||
snprintf(local->class_dev.class_id, BUS_ID_SIZE,
|
||||
"phy%d", local->hw.index);
|
||||
res = class_device_add(&local->class_dev);
|
||||
if (res)
|
||||
return res;
|
||||
res = sysfs_create_group(&local->class_dev.kobj,
|
||||
&ieee80211_stats_group);
|
||||
if (res)
|
||||
class_device_del(&local->class_dev);
|
||||
return res;
|
||||
}
|
||||
|
||||
void ieee80211_dev_sysfs_del(struct ieee80211_local *local)
|
||||
{
|
||||
sysfs_remove_group(&local->class_dev.kobj, &ieee80211_stats_group);
|
||||
class_device_del(&local->class_dev);
|
||||
}
|
||||
|
||||
/* /sys/class/net/X functions */
|
||||
|
||||
static void __ieee80211_remove_if_group(struct kobject *kobj,
|
||||
struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
if (sdata->sysfs_group) {
|
||||
sysfs_remove_group(kobj, sdata->sysfs_group);
|
||||
sdata->sysfs_group = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void ieee80211_remove_if_group(struct kobject *kobj,
|
||||
struct net_device *dev)
|
||||
{
|
||||
__ieee80211_remove_if_group(kobj, IEEE80211_DEV_TO_SUB_IF(dev));
|
||||
}
|
||||
|
||||
static int ieee80211_add_if_group(struct kobject *kobj,
|
||||
struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
|
||||
int res = 0;
|
||||
|
||||
__ieee80211_remove_if_group(kobj, sdata);
|
||||
switch (sdata->type) {
|
||||
case IEEE80211_IF_TYPE_STA:
|
||||
sdata->sysfs_group = &ieee80211_sta_group;
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_AP:
|
||||
sdata->sysfs_group = &ieee80211_ap_group;
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_WDS:
|
||||
sdata->sysfs_group = &ieee80211_wds_group;
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_VLAN:
|
||||
sdata->sysfs_group = &ieee80211_vlan_group;
|
||||
break;
|
||||
case IEEE80211_IF_TYPE_MNTR:
|
||||
sdata->sysfs_group = &ieee80211_monitor_group;
|
||||
break;
|
||||
default:
|
||||
goto out;
|
||||
}
|
||||
res = sysfs_create_group(kobj, sdata->sysfs_group);
|
||||
if (res)
|
||||
sdata->sysfs_group = NULL;
|
||||
out:
|
||||
return res;
|
||||
}
|
||||
|
||||
int ieee80211_sysfs_change_if_type(struct net_device *dev)
|
||||
{
|
||||
return ieee80211_add_if_group(&dev->class_dev.kobj, dev);
|
||||
}
|
||||
|
||||
int ieee80211_sysfs_add_netdevice(struct net_device *dev)
|
||||
{
|
||||
struct ieee80211_local *local = dev->ieee80211_ptr;
|
||||
int res;
|
||||
|
||||
res = sysfs_create_link(&dev->class_dev.kobj, &local->class_dev.kobj,
|
||||
"hw");
|
||||
if (res)
|
||||
goto err_out;
|
||||
res = ieee80211_add_if_group(&dev->class_dev.kobj, dev);
|
||||
if (res)
|
||||
goto err_link;
|
||||
res = ieee80211_key_kset_sysfs_register(IEEE80211_DEV_TO_SUB_IF(dev));
|
||||
return res;
|
||||
|
||||
err_link:
|
||||
sysfs_remove_link(&dev->class_dev.kobj, "hw");
|
||||
err_out:
|
||||
return res;
|
||||
}
|
||||
|
||||
void ieee80211_sysfs_remove_netdevice(struct net_device *dev)
|
||||
{
|
||||
ieee80211_key_kset_sysfs_unregister(IEEE80211_DEV_TO_SUB_IF(dev));
|
||||
ieee80211_remove_if_group(&dev->class_dev.kobj, dev);
|
||||
sysfs_remove_link(&dev->class_dev.kobj, "hw");
|
||||
}
|
||||
|
||||
/* general module functions */
|
||||
|
||||
int ieee80211_sysfs_init(void)
|
||||
{
|
||||
return class_register(&ieee80211_class);
|
||||
}
|
||||
|
||||
void ieee80211_sysfs_deinit(void)
|
||||
{
|
||||
class_unregister(&ieee80211_class);
|
||||
}
|
437
package/d80211/src/ieee80211_sysfs_sta.c
Normal file
437
package/d80211/src/ieee80211_sysfs_sta.c
Normal file
|
@ -0,0 +1,437 @@
|
|||
/*
|
||||
* Copyright 2003-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.
|
||||
*/
|
||||
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_key.h"
|
||||
#include "sta_info.h"
|
||||
|
||||
static ssize_t sta_sysfs_show(struct kobject *, struct attribute *, char *);
|
||||
static ssize_t key_sysfs_show(struct kobject *, struct attribute *, char *);
|
||||
|
||||
static struct sysfs_ops sta_ktype_ops = {
|
||||
.show = sta_sysfs_show,
|
||||
};
|
||||
|
||||
static struct sysfs_ops key_ktype_ops = {
|
||||
.show = key_sysfs_show,
|
||||
};
|
||||
|
||||
/* sta attributtes */
|
||||
|
||||
#define STA_SHOW(name, field, format_string) \
|
||||
static ssize_t show_sta_##name(const struct sta_info *sta, char *buf) \
|
||||
{ \
|
||||
return sprintf(buf, format_string, sta->field); \
|
||||
}
|
||||
#define STA_SHOW_D(name, field) STA_SHOW(name, field, "%d\n")
|
||||
#define STA_SHOW_U(name, field) STA_SHOW(name, field, "%u\n")
|
||||
#define STA_SHOW_LU(name, field) STA_SHOW(name, field, "%lu\n")
|
||||
#define STA_SHOW_S(name, field) STA_SHOW(name, field, "%s\n")
|
||||
|
||||
#define STA_SHOW_RATE(name, field) \
|
||||
static ssize_t show_sta_##name(const struct sta_info *sta, char *buf) \
|
||||
{ \
|
||||
struct ieee80211_local *local = sta->dev->ieee80211_ptr; \
|
||||
return sprintf(buf, "%d\n", \
|
||||
(sta->field >= 0 && \
|
||||
sta->field < local->num_curr_rates) ? \
|
||||
local->curr_rates[sta->field].rate : -1); \
|
||||
}
|
||||
|
||||
#define __STA_ATTR(name) \
|
||||
static struct sta_attribute sta_attr_##name = \
|
||||
__ATTR(name, S_IRUGO, show_sta_##name, NULL)
|
||||
|
||||
#define STA_ATTR(name, field, format) \
|
||||
STA_SHOW_##format(name, field) \
|
||||
__STA_ATTR(name)
|
||||
|
||||
STA_ATTR(aid, aid, D);
|
||||
STA_ATTR(key_idx_compression, key_idx_compression, D);
|
||||
STA_ATTR(dev, dev->name, S);
|
||||
STA_ATTR(vlan_id, vlan_id, D);
|
||||
STA_ATTR(rx_packets, rx_packets, LU);
|
||||
STA_ATTR(tx_packets, tx_packets, LU);
|
||||
STA_ATTR(rx_bytes, rx_bytes, LU);
|
||||
STA_ATTR(tx_bytes, tx_bytes, LU);
|
||||
STA_ATTR(rx_duplicates, num_duplicates, LU);
|
||||
STA_ATTR(rx_fragments, rx_fragments, LU);
|
||||
STA_ATTR(rx_dropped, rx_dropped, LU);
|
||||
STA_ATTR(tx_fragments, tx_fragments, LU);
|
||||
STA_ATTR(tx_filtered, tx_filtered_count, LU);
|
||||
STA_ATTR(txrate, txrate, RATE);
|
||||
STA_ATTR(last_txrate, last_txrate, RATE);
|
||||
STA_ATTR(tx_retry_failed, tx_retry_failed, LU);
|
||||
STA_ATTR(tx_retry_count, tx_retry_count, LU);
|
||||
STA_ATTR(last_rssi, last_rssi, D);
|
||||
STA_ATTR(last_signal, last_signal, D);
|
||||
STA_ATTR(last_noise, last_noise, D);
|
||||
STA_ATTR(channel_use, channel_use, D);
|
||||
STA_ATTR(wep_weak_iv_count, wep_weak_iv_count, D);
|
||||
|
||||
static ssize_t show_sta_flags(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
return sprintf(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" : "");
|
||||
}
|
||||
__STA_ATTR(flags);
|
||||
|
||||
static ssize_t show_sta_num_ps_buf_frames(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%u\n", skb_queue_len(&sta->ps_tx_buf));
|
||||
}
|
||||
__STA_ATTR(num_ps_buf_frames);
|
||||
|
||||
static ssize_t show_sta_last_ack_rssi(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d %d %d\n", sta->last_ack_rssi[0],
|
||||
sta->last_ack_rssi[1], sta->last_ack_rssi[2]);
|
||||
}
|
||||
__STA_ATTR(last_ack_rssi);
|
||||
|
||||
static ssize_t show_sta_last_ack_ms(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", sta->last_ack ?
|
||||
jiffies_to_msecs(jiffies - sta->last_ack) : -1);
|
||||
}
|
||||
__STA_ATTR(last_ack_ms);
|
||||
|
||||
static ssize_t show_sta_inactive_ms(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
return sprintf(buf, "%d\n", jiffies_to_msecs(jiffies - sta->last_rx));
|
||||
}
|
||||
__STA_ATTR(inactive_ms);
|
||||
|
||||
static ssize_t show_sta_last_seq_ctrl(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += sprintf(p, "%x ", sta->last_seq_ctrl[i]);
|
||||
p += sprintf(p, "\n");
|
||||
return (p - buf);
|
||||
}
|
||||
__STA_ATTR(last_seq_ctrl);
|
||||
|
||||
#ifdef CONFIG_D80211_DEBUG_COUNTERS
|
||||
static ssize_t show_sta_wme_rx_queue(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += sprintf(p, "%u ", sta->wme_rx_queue[i]);
|
||||
p += sprintf(p, "\n");
|
||||
return (p - buf);
|
||||
}
|
||||
__STA_ATTR(wme_rx_queue);
|
||||
|
||||
static ssize_t show_sta_wme_tx_queue(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += sprintf(p, "%u ", sta->wme_tx_queue[i]);
|
||||
p += sprintf(p, "\n");
|
||||
return (p - buf);
|
||||
}
|
||||
__STA_ATTR(wme_tx_queue);
|
||||
#endif
|
||||
|
||||
static struct attribute *sta_ktype_attrs[] = {
|
||||
&sta_attr_aid.attr,
|
||||
&sta_attr_key_idx_compression.attr,
|
||||
&sta_attr_dev.attr,
|
||||
&sta_attr_vlan_id.attr,
|
||||
&sta_attr_rx_packets.attr,
|
||||
&sta_attr_tx_packets.attr,
|
||||
&sta_attr_rx_bytes.attr,
|
||||
&sta_attr_tx_bytes.attr,
|
||||
&sta_attr_rx_duplicates.attr,
|
||||
&sta_attr_rx_fragments.attr,
|
||||
&sta_attr_rx_dropped.attr,
|
||||
&sta_attr_tx_fragments.attr,
|
||||
&sta_attr_tx_filtered.attr,
|
||||
&sta_attr_txrate.attr,
|
||||
&sta_attr_last_txrate.attr,
|
||||
&sta_attr_tx_retry_failed.attr,
|
||||
&sta_attr_tx_retry_count.attr,
|
||||
&sta_attr_last_rssi.attr,
|
||||
&sta_attr_last_signal.attr,
|
||||
&sta_attr_last_noise.attr,
|
||||
&sta_attr_channel_use.attr,
|
||||
&sta_attr_wep_weak_iv_count.attr,
|
||||
|
||||
&sta_attr_flags.attr,
|
||||
&sta_attr_num_ps_buf_frames.attr,
|
||||
&sta_attr_last_ack_rssi.attr,
|
||||
&sta_attr_last_ack_ms.attr,
|
||||
&sta_attr_inactive_ms.attr,
|
||||
&sta_attr_last_seq_ctrl.attr,
|
||||
#ifdef CONFIG_D80211_DEBUG_COUNTERS
|
||||
&sta_attr_wme_rx_queue.attr,
|
||||
&sta_attr_wme_tx_queue.attr,
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
/* keys attributtes */
|
||||
|
||||
struct key_attribute {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(const struct ieee80211_key *, char *buf);
|
||||
ssize_t (*store)(struct ieee80211_key *, const char *buf,
|
||||
size_t count);
|
||||
};
|
||||
|
||||
#define KEY_SHOW(name, field, format_string) \
|
||||
static ssize_t show_key_##name(const struct ieee80211_key *key, char *buf)\
|
||||
{ \
|
||||
return sprintf(buf, format_string, key->field); \
|
||||
}
|
||||
#define KEY_SHOW_D(name, field) KEY_SHOW(name, field, "%d\n")
|
||||
|
||||
#define __KEY_ATTR(name) \
|
||||
static struct key_attribute key_attr_##name = \
|
||||
__ATTR(name, S_IRUSR, show_key_##name, NULL)
|
||||
|
||||
#define KEY_ATTR(name, field, format) \
|
||||
KEY_SHOW_##format(name, field) \
|
||||
__KEY_ATTR(name)
|
||||
|
||||
KEY_ATTR(length, keylen, D);
|
||||
KEY_ATTR(sw_encrypt, force_sw_encrypt, D);
|
||||
KEY_ATTR(index, keyidx, D);
|
||||
KEY_ATTR(hw_index, hw_key_idx, D);
|
||||
KEY_ATTR(tx_rx_count, tx_rx_count, D);
|
||||
|
||||
static ssize_t show_key_algorithm(const struct ieee80211_key *key, char *buf)
|
||||
{
|
||||
char *alg;
|
||||
|
||||
switch (key->alg) {
|
||||
case ALG_WEP:
|
||||
alg = "WEP";
|
||||
break;
|
||||
case ALG_TKIP:
|
||||
alg = "TKIP";
|
||||
break;
|
||||
case ALG_CCMP:
|
||||
alg = "CCMP";
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
return sprintf(buf, "%s\n", alg);
|
||||
}
|
||||
__KEY_ATTR(algorithm);
|
||||
|
||||
static ssize_t show_key_tx_spec(const struct ieee80211_key *key, char *buf)
|
||||
{
|
||||
const u8 *tpn;
|
||||
|
||||
switch (key->alg) {
|
||||
case ALG_WEP:
|
||||
return sprintf(buf, "\n");
|
||||
case ALG_TKIP:
|
||||
return sprintf(buf, "%08x %04x\n", key->u.tkip.iv32,
|
||||
key->u.tkip.iv16);
|
||||
case ALG_CCMP:
|
||||
tpn = key->u.ccmp.tx_pn;
|
||||
return sprintf(buf, "%02x%02x%02x%02x%02x%02x\n", tpn[0],
|
||||
tpn[1], tpn[2], tpn[3], tpn[4], tpn[5]);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
__KEY_ATTR(tx_spec);
|
||||
|
||||
static ssize_t show_key_rx_spec(const struct ieee80211_key *key, char *buf)
|
||||
{
|
||||
int i;
|
||||
const u8 *rpn;
|
||||
char *p = buf;
|
||||
|
||||
switch (key->alg) {
|
||||
case ALG_WEP:
|
||||
return sprintf(buf, "\n");
|
||||
case ALG_TKIP:
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
|
||||
p += sprintf(p, "%08x %04x\n",
|
||||
key->u.tkip.iv32_rx[i],
|
||||
key->u.tkip.iv16_rx[i]);
|
||||
return (p - buf);
|
||||
case ALG_CCMP:
|
||||
for (i = 0; i < NUM_RX_DATA_QUEUES; i++) {
|
||||
rpn = key->u.ccmp.rx_pn[i];
|
||||
p += sprintf(p, "%02x%02x%02x%02x%02x%02x\n", rpn[0],
|
||||
rpn[1], rpn[2], rpn[3], rpn[4], rpn[5]);
|
||||
}
|
||||
return (p - buf);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
__KEY_ATTR(rx_spec);
|
||||
|
||||
static ssize_t show_key_replays(const struct ieee80211_key *key, char *buf)
|
||||
{
|
||||
if (key->alg != ALG_CCMP)
|
||||
return 0;
|
||||
return sprintf(buf, "%u\n", key->u.ccmp.replays);
|
||||
}
|
||||
__KEY_ATTR(replays);
|
||||
|
||||
static ssize_t show_key_key(const struct ieee80211_key *key, char *buf)
|
||||
{
|
||||
int i;
|
||||
char *p = buf;
|
||||
|
||||
for (i = 0; i < key->keylen; i++)
|
||||
p += sprintf(p, "%02x", key->key[i]);
|
||||
p += sprintf(p, "\n");
|
||||
return (p - buf);
|
||||
}
|
||||
__KEY_ATTR(key);
|
||||
|
||||
static struct attribute *key_ktype_attrs[] = {
|
||||
&key_attr_length.attr,
|
||||
&key_attr_sw_encrypt.attr,
|
||||
&key_attr_index.attr,
|
||||
&key_attr_hw_index.attr,
|
||||
&key_attr_tx_rx_count.attr,
|
||||
&key_attr_algorithm.attr,
|
||||
&key_attr_tx_spec.attr,
|
||||
&key_attr_rx_spec.attr,
|
||||
&key_attr_replays.attr,
|
||||
&key_attr_key.attr,
|
||||
NULL
|
||||
};
|
||||
|
||||
/* structures and functions */
|
||||
|
||||
static struct kobj_type sta_ktype = {
|
||||
.release = sta_info_release,
|
||||
.sysfs_ops = &sta_ktype_ops,
|
||||
.default_attrs = sta_ktype_attrs,
|
||||
};
|
||||
|
||||
static struct kobj_type key_ktype = {
|
||||
.release = ieee80211_key_release,
|
||||
.sysfs_ops = &key_ktype_ops,
|
||||
.default_attrs = key_ktype_attrs,
|
||||
};
|
||||
|
||||
static ssize_t sta_sysfs_show(struct kobject *kobj, struct attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct sta_attribute *sta_attr;
|
||||
struct sta_info *sta;
|
||||
|
||||
sta_attr = container_of(attr, struct sta_attribute, attr);
|
||||
sta = container_of(kobj, struct sta_info, kobj);
|
||||
return sta_attr->show(sta, buf);
|
||||
}
|
||||
|
||||
static ssize_t key_sysfs_show(struct kobject *kobj, struct attribute *attr,
|
||||
char *buf)
|
||||
{
|
||||
struct key_attribute *key_attr;
|
||||
struct ieee80211_key *key;
|
||||
|
||||
key_attr = container_of(attr, struct key_attribute, attr);
|
||||
key = container_of(kobj, struct ieee80211_key, kobj);
|
||||
return key_attr->show(key, buf);
|
||||
}
|
||||
|
||||
int ieee80211_sta_kset_sysfs_register(struct ieee80211_local *local)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = kobject_set_name(&local->sta_kset.kobj, "sta");
|
||||
if (res)
|
||||
return res;
|
||||
local->sta_kset.kobj.parent = &local->class_dev.kobj;
|
||||
local->sta_kset.ktype = &sta_ktype;
|
||||
return kset_register(&local->sta_kset);
|
||||
}
|
||||
|
||||
void ieee80211_sta_kset_sysfs_unregister(struct ieee80211_local *local)
|
||||
{
|
||||
kset_unregister(&local->sta_kset);
|
||||
}
|
||||
|
||||
int ieee80211_key_kset_sysfs_register(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = kobject_set_name(&sdata->key_kset.kobj, "keys");
|
||||
if (res)
|
||||
return res;
|
||||
sdata->key_kset.kobj.parent = &sdata->dev->class_dev.kobj;
|
||||
sdata->key_kset.ktype = &key_ktype;
|
||||
return kset_register(&sdata->key_kset);
|
||||
}
|
||||
|
||||
void ieee80211_key_kset_sysfs_unregister(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
kset_unregister(&sdata->key_kset);
|
||||
}
|
||||
|
||||
int ieee80211_sta_sysfs_add(struct sta_info *sta)
|
||||
{
|
||||
return kobject_add(&sta->kobj);
|
||||
}
|
||||
|
||||
void ieee80211_sta_sysfs_remove(struct sta_info *sta)
|
||||
{
|
||||
kobject_del(&sta->kobj);
|
||||
}
|
||||
|
||||
void ieee80211_key_sysfs_set_kset(struct ieee80211_key *key, struct kset *kset)
|
||||
{
|
||||
key->kobj.kset = kset;
|
||||
if (!kset)
|
||||
key->kobj.ktype = &key_ktype;
|
||||
}
|
||||
|
||||
int ieee80211_key_sysfs_add(struct ieee80211_key *key)
|
||||
{
|
||||
return kobject_add(&key->kobj);
|
||||
}
|
||||
|
||||
void ieee80211_key_sysfs_remove(struct ieee80211_key *key)
|
||||
{
|
||||
if (key)
|
||||
kobject_del(&key->kobj);
|
||||
}
|
||||
|
||||
int ieee80211_key_sysfs_add_default(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
return sysfs_create_link(&sdata->key_kset.kobj,
|
||||
&sdata->default_key->kobj, "default");
|
||||
}
|
||||
|
||||
void ieee80211_key_sysfs_remove_default(struct ieee80211_sub_if_data *sdata)
|
||||
{
|
||||
sysfs_remove_link(&sdata->key_kset.kobj, "default");
|
||||
}
|
1064
package/d80211/src/include/net/d80211.h
Normal file
1064
package/d80211/src/include/net/d80211.h
Normal file
File diff suppressed because it is too large
Load diff
98
package/d80211/src/include/net/d80211_common.h
Normal file
98
package/d80211/src/include/net/d80211_common.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* 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 D80211_COMMON_H
|
||||
#define D80211_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,
|
||||
ieee80211_msg_passive_scan = 3,
|
||||
ieee80211_msg_wep_frame_unknown_key = 4,
|
||||
ieee80211_msg_michael_mic_failure = 5,
|
||||
/* hole at 6, was monitor but never sent to userspace */
|
||||
ieee80211_msg_sta_not_assoc = 7,
|
||||
ieee80211_msg_set_aid_for_sta = 8 /* used by Intersil MVC driver */,
|
||||
ieee80211_msg_key_threshold_notification = 9,
|
||||
ieee80211_msg_radar = 11,
|
||||
};
|
||||
|
||||
struct ieee80211_msg_set_aid_for_sta {
|
||||
char sta_address[ETH_ALEN];
|
||||
u16 aid;
|
||||
};
|
||||
|
||||
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,
|
||||
ieee80211_phytype_dsss_dot11_turbog = 255,
|
||||
ieee80211_phytype_dsss_dot11_turbo = 256,
|
||||
};
|
||||
|
||||
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 /* D80211_COMMON_H */
|
223
package/d80211/src/include/net/d80211_mgmt.h
Normal file
223
package/d80211/src/include/net/d80211_mgmt.h
Normal file
|
@ -0,0 +1,223 @@
|
|||
/*
|
||||
* IEEE 802.11 -- shared defines for 80211.o and hostapd
|
||||
* Copyright 2002, Jouni Malinen <jkmaline@cc.hut.fi>
|
||||
* 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 D802_11_MGMT_H
|
||||
#define D802_11_MGMT_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
struct ieee80211_mgmt {
|
||||
__le16 frame_control;
|
||||
__le16 duration;
|
||||
u8 da[6];
|
||||
u8 sa[6];
|
||||
u8 bssid[6];
|
||||
__le16 seq_ctrl;
|
||||
union {
|
||||
struct {
|
||||
__le16 auth_alg;
|
||||
__le16 auth_transaction;
|
||||
__le16 status_code;
|
||||
/* possibly followed by Challenge text */
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) auth;
|
||||
struct {
|
||||
__le16 reason_code;
|
||||
} __attribute__ ((packed)) deauth;
|
||||
struct {
|
||||
__le16 capab_info;
|
||||
__le16 listen_interval;
|
||||
/* followed by SSID and Supported rates */
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) assoc_req;
|
||||
struct {
|
||||
__le16 capab_info;
|
||||
__le16 status_code;
|
||||
__le16 aid;
|
||||
/* followed by Supported rates */
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) assoc_resp, reassoc_resp;
|
||||
struct {
|
||||
__le16 capab_info;
|
||||
__le16 listen_interval;
|
||||
u8 current_ap[6];
|
||||
/* followed by SSID and Supported rates */
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) reassoc_req;
|
||||
struct {
|
||||
__le16 reason_code;
|
||||
} __attribute__ ((packed)) disassoc;
|
||||
struct {
|
||||
__le64 timestamp;
|
||||
__le16 beacon_int;
|
||||
__le16 capab_info;
|
||||
/* followed by some of SSID, Supported rates,
|
||||
* FH Params, DS Params, CF Params, IBSS Params, TIM */
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) beacon;
|
||||
struct {
|
||||
/* only variable items: SSID, Supported rates */
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) probe_req;
|
||||
struct {
|
||||
__le64 timestamp;
|
||||
__le16 beacon_int;
|
||||
__le16 capab_info;
|
||||
/* followed by some of SSID, Supported rates,
|
||||
* FH Params, DS Params, CF Params, IBSS Params */
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) probe_resp;
|
||||
struct {
|
||||
u8 category;
|
||||
union {
|
||||
struct {
|
||||
u8 action_code;
|
||||
u8 dialog_token;
|
||||
u8 status_code;
|
||||
u8 variable[0];
|
||||
} __attribute__ ((packed)) wme_action;
|
||||
struct{
|
||||
u8 action_code;
|
||||
u8 element_id;
|
||||
u8 length;
|
||||
u8 switch_mode;
|
||||
u8 new_chan;
|
||||
u8 switch_count;
|
||||
} __attribute__((packed)) chan_switch;
|
||||
} u;
|
||||
} __attribute__ ((packed)) action;
|
||||
} u;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
|
||||
/* Authentication algorithms */
|
||||
#define WLAN_AUTH_OPEN 0
|
||||
#define WLAN_AUTH_SHARED_KEY 1
|
||||
#define WLAN_AUTH_LEAP 128
|
||||
|
||||
#define WLAN_AUTH_CHALLENGE_LEN 128
|
||||
|
||||
#define WLAN_CAPABILITY_ESS BIT(0)
|
||||
#define WLAN_CAPABILITY_IBSS BIT(1)
|
||||
#define WLAN_CAPABILITY_CF_POLLABLE BIT(2)
|
||||
#define WLAN_CAPABILITY_CF_POLL_REQUEST BIT(3)
|
||||
#define WLAN_CAPABILITY_PRIVACY BIT(4)
|
||||
#define WLAN_CAPABILITY_SHORT_PREAMBLE BIT(5)
|
||||
#define WLAN_CAPABILITY_PBCC BIT(6)
|
||||
#define WLAN_CAPABILITY_CHANNEL_AGILITY BIT(7)
|
||||
/* 802.11h */
|
||||
#define WLAN_CAPABILITY_SPECTRUM_MGMT BIT(8)
|
||||
#define WLAN_CAPABILITY_SHORT_SLOT_TIME BIT(10)
|
||||
#define WLAN_CAPABILITY_DSSS_OFDM BIT(13)
|
||||
|
||||
/* Status codes */
|
||||
enum ieee80211_statuscode {
|
||||
WLAN_STATUS_SUCCESS = 0,
|
||||
WLAN_STATUS_UNSPECIFIED_FAILURE = 1,
|
||||
WLAN_STATUS_CAPS_UNSUPPORTED = 10,
|
||||
WLAN_STATUS_REASSOC_NO_ASSOC = 11,
|
||||
WLAN_STATUS_ASSOC_DENIED_UNSPEC = 12,
|
||||
WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG = 13,
|
||||
WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION = 14,
|
||||
WLAN_STATUS_CHALLENGE_FAIL = 15,
|
||||
WLAN_STATUS_AUTH_TIMEOUT = 16,
|
||||
WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA = 17,
|
||||
WLAN_STATUS_ASSOC_DENIED_RATES = 18,
|
||||
/* 802.11b */
|
||||
WLAN_STATUS_ASSOC_DENIED_NOSHORTPREAMBLE = 19,
|
||||
WLAN_STATUS_ASSOC_DENIED_NOPBCC = 20,
|
||||
WLAN_STATUS_ASSOC_DENIED_NOAGILITY = 21,
|
||||
/* 802.11h */
|
||||
WLAN_STATUS_ASSOC_DENIED_NOSPECTRUM = 22,
|
||||
WLAN_STATUS_ASSOC_REJECTED_BAD_POWER = 23,
|
||||
WLAN_STATUS_ASSOC_REJECTED_BAD_SUPP_CHAN = 24,
|
||||
/* 802.11g */
|
||||
WLAN_STATUS_ASSOC_DENIED_NOSHORTTIME = 25,
|
||||
WLAN_STATUS_ASSOC_DENIED_NODSSSOFDM = 26,
|
||||
/* 802.11i */
|
||||
WLAN_STATUS_INVALID_IE = 40,
|
||||
WLAN_STATUS_INVALID_GROUP_CIPHER = 41,
|
||||
WLAN_STATUS_INVALID_PAIRWISE_CIPHER = 42,
|
||||
WLAN_STATUS_INVALID_AKMP = 43,
|
||||
WLAN_STATUS_UNSUPP_RSN_VERSION = 44,
|
||||
WLAN_STATUS_INVALID_RSN_IE_CAP = 45,
|
||||
WLAN_STATUS_CIPHER_SUITE_REJECTED = 46,
|
||||
};
|
||||
|
||||
|
||||
/* Reason codes */
|
||||
enum ieee80211_reasoncode {
|
||||
WLAN_REASON_UNSPECIFIED = 1,
|
||||
WLAN_REASON_PREV_AUTH_NOT_VALID = 2,
|
||||
WLAN_REASON_DEAUTH_LEAVING = 3,
|
||||
WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY = 4,
|
||||
WLAN_REASON_DISASSOC_AP_BUSY = 5,
|
||||
WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA = 6,
|
||||
WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA = 7,
|
||||
WLAN_REASON_DISASSOC_STA_HAS_LEFT = 8,
|
||||
WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH = 9,
|
||||
/* 802.11h */
|
||||
WLAN_REASON_DISASSOC_BAD_POWER = 10,
|
||||
WLAN_REASON_DISASSOC_BAD_SUPP_CHAN = 11,
|
||||
/* 802.11i */
|
||||
WLAN_REASON_INVALID_IE = 13,
|
||||
WLAN_REASON_MIC_FAILURE = 14,
|
||||
WLAN_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
|
||||
WLAN_REASON_GROUP_KEY_HANDSHAKE_TIMEOUT = 16,
|
||||
WLAN_REASON_IE_DIFFERENT = 17,
|
||||
WLAN_REASON_INVALID_GROUP_CIPHER = 18,
|
||||
WLAN_REASON_INVALID_PAIRWISE_CIPHER = 19,
|
||||
WLAN_REASON_INVALID_AKMP = 20,
|
||||
WLAN_REASON_UNSUPP_RSN_VERSION = 21,
|
||||
WLAN_REASON_INVALID_RSN_IE_CAP = 22,
|
||||
WLAN_REASON_IEEE8021X_FAILED = 23,
|
||||
WLAN_REASON_CIPHER_SUITE_REJECTED = 24,
|
||||
};
|
||||
|
||||
|
||||
/* Information Element IDs */
|
||||
enum ieee80211_eid {
|
||||
WLAN_EID_SSID = 0,
|
||||
WLAN_EID_SUPP_RATES = 1,
|
||||
WLAN_EID_FH_PARAMS = 2,
|
||||
WLAN_EID_DS_PARAMS = 3,
|
||||
WLAN_EID_CF_PARAMS = 4,
|
||||
WLAN_EID_TIM = 5,
|
||||
WLAN_EID_IBSS_PARAMS = 6,
|
||||
WLAN_EID_CHALLENGE = 16,
|
||||
/* 802.11d */
|
||||
WLAN_EID_COUNTRY = 7,
|
||||
WLAN_EID_HP_PARAMS = 8,
|
||||
WLAN_EID_HP_TABLE = 9,
|
||||
WLAN_EID_REQUEST = 10,
|
||||
/* 802.11h */
|
||||
WLAN_EID_PWR_CONSTRAINT = 32,
|
||||
WLAN_EID_PWR_CAPABILITY = 33,
|
||||
WLAN_EID_TPC_REQUEST = 34,
|
||||
WLAN_EID_TPC_REPORT = 35,
|
||||
WLAN_EID_SUPPORTED_CHANNELS = 36,
|
||||
WLAN_EID_CHANNEL_SWITCH = 37,
|
||||
WLAN_EID_MEASURE_REQUEST = 38,
|
||||
WLAN_EID_MEASURE_REPORT = 39,
|
||||
WLAN_EID_QUIET = 40,
|
||||
WLAN_EID_IBSS_DFS = 41,
|
||||
/* 802.11g */
|
||||
WLAN_EID_ERP_INFO = 42,
|
||||
WLAN_EID_EXT_SUPP_RATES = 50,
|
||||
/* 802.11i */
|
||||
WLAN_EID_RSN = 48,
|
||||
WLAN_EID_WPA = 221,
|
||||
WLAN_EID_GENERIC = 221,
|
||||
WLAN_EID_VENDOR_SPECIFIC = 221,
|
||||
WLAN_EID_QOS_PARAMETER = 222
|
||||
};
|
||||
|
||||
#endif /* D802_11_MGMT_H */
|
46
package/d80211/src/include/net/d80211_shared.h
Normal file
46
package/d80211/src/include/net/d80211_shared.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* IEEE 802.11 -- shared defines for low-level drivers, 80211.o, and hostapd
|
||||
* 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 D80211_SHARED_H
|
||||
#define D80211_SHARED_H
|
||||
|
||||
/* 802.11g is backwards-compatible with 802.11b, so a wlan card can
|
||||
* actually be both in 11b and 11g modes at the same time. */
|
||||
enum {
|
||||
MODE_IEEE80211A = 0 /* IEEE 802.11a */,
|
||||
MODE_IEEE80211B = 1 /* IEEE 802.11b only */,
|
||||
MODE_ATHEROS_TURBO = 2 /* Atheros Turbo mode (2x.11a at 5 GHz) */,
|
||||
MODE_IEEE80211G = 3 /* IEEE 802.11g (and 802.11b compatibility) */,
|
||||
MODE_ATHEROS_TURBOG = 4 /* Atheros Turbo mode (2x.11g at 2.4 GHz) */,
|
||||
NUM_IEEE80211_MODES = 5
|
||||
};
|
||||
|
||||
#define IEEE80211_CHAN_W_SCAN 0x00000001
|
||||
#define IEEE80211_CHAN_W_ACTIVE_SCAN 0x00000002
|
||||
#define IEEE80211_CHAN_W_IBSS 0x00000004
|
||||
|
||||
/* Low-level driver should set PREAMBLE2, OFDM, CCK, and TURBO flags.
|
||||
* BASIC, SUPPORTED, ERP, and MANDATORY flags are set in 80211.o based on the
|
||||
* configuration. */
|
||||
#define IEEE80211_RATE_ERP 0x00000001
|
||||
#define IEEE80211_RATE_BASIC 0x00000002
|
||||
#define IEEE80211_RATE_PREAMBLE2 0x00000004
|
||||
#define IEEE80211_RATE_SUPPORTED 0x00000010
|
||||
#define IEEE80211_RATE_OFDM 0x00000020
|
||||
#define IEEE80211_RATE_CCK 0x00000040
|
||||
#define IEEE80211_RATE_TURBO 0x00000080
|
||||
#define IEEE80211_RATE_MANDATORY 0x00000100
|
||||
|
||||
#define IEEE80211_RATE_CCK_2 (IEEE80211_RATE_CCK | IEEE80211_RATE_PREAMBLE2)
|
||||
#define IEEE80211_RATE_MODULATION(f) \
|
||||
(f & (IEEE80211_RATE_CCK | IEEE80211_RATE_OFDM))
|
||||
|
||||
|
||||
#endif /* D80211_SHARED_H */
|
104
package/d80211/src/michael.c
Normal file
104
package/d80211/src/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/d80211/src/michael.h
Normal file
20
package/d80211/src/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 */
|
398
package/d80211/src/rc80211_simple.c
Normal file
398
package/d80211/src/rc80211_simple.c
Normal file
|
@ -0,0 +1,398 @@
|
|||
/*
|
||||
* 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/d80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.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;
|
||||
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;
|
||||
}
|
||||
|
||||
maxrate = sdata->bss ? sdata->bss->max_ratectrl_rateidx : -1;
|
||||
|
||||
if (i > local->num_curr_rates)
|
||||
i = local->num_curr_rates - 2;
|
||||
|
||||
while (i + 1 < local->num_curr_rates) {
|
||||
i++;
|
||||
if (sta->supp_rates & BIT(i) &&
|
||||
local->curr_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;
|
||||
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;
|
||||
}
|
||||
|
||||
if (i > local->num_curr_rates)
|
||||
i = local->num_curr_rates;
|
||||
|
||||
while (i > 0) {
|
||||
i--;
|
||||
if (sta->supp_rates & BIT(i) &&
|
||||
local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED) {
|
||||
sta->txrate = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static struct ieee80211_rate *
|
||||
rate_control_lowest_rate(struct ieee80211_local *local)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < local->num_curr_rates; i++) {
|
||||
struct ieee80211_rate *rate = &local->curr_rates[i];
|
||||
|
||||
if (rate->flags & IEEE80211_RATE_SUPPORTED
|
||||
)
|
||||
return rate;
|
||||
}
|
||||
|
||||
printk(KERN_DEBUG "rate_control_lowest_rate - no supported rates "
|
||||
"found\n");
|
||||
return &local->curr_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;
|
||||
};
|
||||
|
||||
|
||||
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 = 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) {
|
||||
sta->antenna_sel = sta->antenna_sel == 1 ? 2 : 1;
|
||||
if (local->sta_antenna_sel == STA_ANTENNA_SEL_SW_CTRL_DEBUG) {
|
||||
printk(KERN_DEBUG "%s: " MAC_FMT " TX antenna --> %d "
|
||||
"(@%lu)\n",
|
||||
dev->name, MAC_ARG(hdr->addr1),
|
||||
sta->antenna_sel, jiffies);
|
||||
}
|
||||
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
|
||||
|
||||
if (per_failed > local->rate_ctrl_num_down) {
|
||||
rate_control_rate_dec(local, sta);
|
||||
} else if (per_failed < local->rate_ctrl_num_up) {
|
||||
rate_control_rate_inc(local, sta);
|
||||
}
|
||||
srctrl->tx_avg_rate_sum += local->curr_rates[sta->txrate].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_D80211_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_D80211_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 = dev->ieee80211_ptr;
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
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);
|
||||
}
|
||||
|
||||
sta = sta_info_get(local, hdr->addr1);
|
||||
|
||||
if (!sta)
|
||||
return rate_control_lowest_rate(local);
|
||||
|
||||
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 >= local->num_curr_rates)
|
||||
rateidx = local->num_curr_rates - 1;
|
||||
|
||||
sta->last_txrate = rateidx;
|
||||
nonerp_idx = rateidx;
|
||||
while (nonerp_idx > 0 &&
|
||||
((local->curr_rates[nonerp_idx].flags & IEEE80211_RATE_ERP) ||
|
||||
!(local->curr_rates[nonerp_idx].flags &
|
||||
IEEE80211_RATE_SUPPORTED) ||
|
||||
!(sta->supp_rates & BIT(nonerp_idx))))
|
||||
nonerp_idx--;
|
||||
extra->nonerp_idx = nonerp_idx;
|
||||
extra->nonerp = &local->curr_rates[extra->nonerp_idx];
|
||||
|
||||
sta_info_put(sta);
|
||||
|
||||
return &local->curr_rates[rateidx];
|
||||
}
|
||||
|
||||
|
||||
static void rate_control_simple_rate_init(void *priv, void *priv_sta,
|
||||
struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
int i;
|
||||
sta->txrate = 0;
|
||||
/* TODO: what is a good starting rate for STA? About middle? Maybe not
|
||||
* the lowest or the highest rate.. Could consider using RSSI from
|
||||
* previous packets? Need to have IEEE 802.1X auth succeed immediately
|
||||
* after assoc.. */
|
||||
for (i = 0; i < local->num_curr_rates; i++) {
|
||||
if ((sta->supp_rates & BIT(i)) &&
|
||||
(local->curr_rates[i].flags & IEEE80211_RATE_SUPPORTED))
|
||||
sta->txrate = i;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
static ssize_t show_sta_tx_avg_rate_sum(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
struct sta_rate_control *srctrl = sta->rate_ctrl_priv;
|
||||
|
||||
return sprintf(buf, "%d\n", srctrl->tx_avg_rate_sum);
|
||||
}
|
||||
|
||||
static ssize_t show_sta_tx_avg_rate_num(const struct sta_info *sta, char *buf)
|
||||
{
|
||||
struct sta_rate_control *srctrl = sta->rate_ctrl_priv;
|
||||
|
||||
return sprintf(buf, "%d\n", srctrl->tx_avg_rate_num);
|
||||
}
|
||||
|
||||
static struct sta_attribute sta_attr_tx_avg_rate_sum =
|
||||
__ATTR(tx_avg_rate_sum, S_IRUSR, show_sta_tx_avg_rate_sum, NULL);
|
||||
static struct sta_attribute sta_attr_tx_avg_rate_num =
|
||||
__ATTR(tx_avg_rate_num, S_IRUSR, show_sta_tx_avg_rate_num, NULL);
|
||||
|
||||
static struct attribute *rate_control_simple_sta_attrs[] = {
|
||||
&sta_attr_tx_avg_rate_sum.attr,
|
||||
&sta_attr_tx_avg_rate_num.attr,
|
||||
NULL,
|
||||
};
|
||||
|
||||
static struct attribute_group rate_control_simple_sta_group = {
|
||||
.name = "rate_control_simple",
|
||||
.attrs = rate_control_simple_sta_attrs,
|
||||
};
|
||||
|
||||
static int rate_control_simple_add_sta_attrs(void *priv, void *priv_sta,
|
||||
struct kobject *kobj)
|
||||
{
|
||||
return sysfs_create_group(kobj, &rate_control_simple_sta_group);
|
||||
}
|
||||
|
||||
static void rate_control_simple_remove_sta_attrs(void *priv, void *priv_sta,
|
||||
struct kobject *kobj)
|
||||
{
|
||||
sysfs_remove_group(kobj, &rate_control_simple_sta_group);
|
||||
}
|
||||
|
||||
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,
|
||||
.add_sta_attrs = rate_control_simple_add_sta_attrs,
|
||||
.remove_sta_attrs = rate_control_simple_remove_sta_attrs,
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
module_init(rate_control_simple_init);
|
||||
module_exit(rate_control_simple_exit);
|
||||
|
||||
MODULE_DESCRIPTION("Simple rate control algorithm for ieee80211");
|
||||
MODULE_LICENSE("GPL");
|
460
package/d80211/src/sta_info.c
Normal file
460
package/d80211/src/sta_info.c
Normal file
|
@ -0,0 +1,460 @@
|
|||
/*
|
||||
* Copyright 2002-2005, 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/module.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kobject.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/if_arp.h>
|
||||
|
||||
#include <net/d80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "ieee80211_rate.h"
|
||||
#include "sta_info.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 void 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;
|
||||
if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
|
||||
local->sta_hash[STA_HASH(sta->addr)] = s->hnext;
|
||||
return;
|
||||
}
|
||||
|
||||
while (s->hnext && memcmp(s->hnext->addr, sta->addr, ETH_ALEN) != 0)
|
||||
s = s->hnext;
|
||||
if (s->hnext)
|
||||
s->hnext = s->hnext->hnext;
|
||||
else
|
||||
printk(KERN_ERR "%s: could not remove STA " MAC_FMT " from "
|
||||
"hash table\n", local->mdev->name, MAC_ARG(sta->addr));
|
||||
}
|
||||
|
||||
static inline struct sta_info *__sta_info_get(struct sta_info *sta)
|
||||
{
|
||||
return kobject_get(&sta->kobj) ? sta : NULL;
|
||||
}
|
||||
|
||||
struct sta_info * sta_info_get(struct ieee80211_local *local, u8 *addr)
|
||||
{
|
||||
struct sta_info *sta;
|
||||
|
||||
spin_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;
|
||||
}
|
||||
spin_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;
|
||||
int min_txrate = 9999999;
|
||||
int i;
|
||||
|
||||
spin_lock_bh(&local->sta_lock);
|
||||
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;
|
||||
}
|
||||
}
|
||||
spin_unlock_bh(&local->sta_lock);
|
||||
if (min_txrate == 9999999)
|
||||
min_txrate = 0;
|
||||
|
||||
return min_txrate;
|
||||
}
|
||||
|
||||
|
||||
void sta_info_put(struct sta_info *sta)
|
||||
{
|
||||
kobject_put(&sta->kobj);
|
||||
}
|
||||
EXPORT_SYMBOL(sta_info_put);
|
||||
|
||||
void sta_info_release(struct kobject *kobj)
|
||||
{
|
||||
struct sta_info *sta = container_of(kobj, struct sta_info, kobj);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
if (kobject_set_name(&sta->kobj, MAC_FMT, MAC_ARG(addr))) {
|
||||
kfree(sta);
|
||||
return NULL;
|
||||
}
|
||||
sta->kobj.kset = &local->sta_kset;
|
||||
kobject_init(&sta->kobj);
|
||||
|
||||
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);
|
||||
kobject_put(&sta->kobj);
|
||||
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() */
|
||||
spin_lock_bh(&local->sta_lock);
|
||||
list_add(&sta->list, &local->sta_list);
|
||||
local->num_sta++;
|
||||
sta_info_hash_add(local, sta);
|
||||
spin_unlock_bh(&local->sta_lock);
|
||||
if (local->ops->sta_table_notification)
|
||||
local->ops->sta_table_notification(local_to_hw(local),
|
||||
local->num_sta);
|
||||
sta->key_idx_compression = HW_KEY_IDX_INVALID;
|
||||
|
||||
#ifdef CONFIG_D80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: Added STA " MAC_FMT "\n",
|
||||
local->mdev->name, MAC_ARG(addr));
|
||||
#endif /* CONFIG_D80211_VERBOSE_DEBUG */
|
||||
|
||||
if (!in_interrupt()) {
|
||||
sta->sysfs_registered = 1;
|
||||
ieee80211_sta_sysfs_add(sta);
|
||||
rate_control_add_sta_attrs(sta, &sta->kobj);
|
||||
} else {
|
||||
/* procfs entry adding might sleep, so schedule process context
|
||||
* task for adding proc entry for STAs that do not yet have
|
||||
* one. */
|
||||
schedule_work(&local->sta_proc_add);
|
||||
}
|
||||
|
||||
return sta;
|
||||
}
|
||||
|
||||
static void finish_sta_info_free(struct ieee80211_local *local,
|
||||
struct sta_info *sta)
|
||||
{
|
||||
#ifdef CONFIG_D80211_VERBOSE_DEBUG
|
||||
printk(KERN_DEBUG "%s: Removed STA " MAC_FMT "\n",
|
||||
local->mdev->name, MAC_ARG(sta->addr));
|
||||
#endif /* CONFIG_D80211_VERBOSE_DEBUG */
|
||||
|
||||
if (sta->key) {
|
||||
ieee80211_key_sysfs_remove(sta->key);
|
||||
ieee80211_key_free(sta->key);
|
||||
sta->key = NULL;
|
||||
}
|
||||
|
||||
rate_control_remove_sta_attrs(sta, &sta->kobj);
|
||||
ieee80211_sta_sysfs_remove(sta);
|
||||
|
||||
sta_info_put(sta);
|
||||
}
|
||||
|
||||
void sta_info_free(struct sta_info *sta, int locked)
|
||||
{
|
||||
struct sk_buff *skb;
|
||||
struct ieee80211_local *local = sta->local;
|
||||
struct ieee80211_sub_if_data *sdata;
|
||||
|
||||
if (!locked)
|
||||
spin_lock_bh(&local->sta_lock);
|
||||
sta_info_hash_del(local, sta);
|
||||
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);
|
||||
if (!locked)
|
||||
spin_unlock_bh(&local->sta_lock);
|
||||
if (local->ops->sta_table_notification)
|
||||
local->ops->sta_table_notification(local_to_hw(local),
|
||||
local->num_sta);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (sta->key) {
|
||||
if (local->ops->set_key) {
|
||||
struct ieee80211_key_conf *key;
|
||||
key = ieee80211_key_data2conf(local, sta->key);
|
||||
if (key) {
|
||||
local->ops->set_key(local_to_hw(local),
|
||||
DISABLE_KEY,
|
||||
sta->addr, key, sta->aid);
|
||||
kfree(key);
|
||||
}
|
||||
}
|
||||
} else if (sta->key_idx_compression != HW_KEY_IDX_INVALID) {
|
||||
struct ieee80211_key_conf conf;
|
||||
memset(&conf, 0, sizeof(conf));
|
||||
conf.hw_key_idx = sta->key_idx_compression;
|
||||
conf.alg = ALG_NULL;
|
||||
conf.flags |= IEEE80211_KEY_FORCE_SW_ENCRYPT;
|
||||
local->ops->set_key(local_to_hw(local), DISABLE_KEY,
|
||||
sta->addr, &conf, sta->aid);
|
||||
sta->key_idx_compression = HW_KEY_IDX_INVALID;
|
||||
}
|
||||
|
||||
if (in_atomic()) {
|
||||
list_add(&sta->list, &local->deleted_sta_list);
|
||||
schedule_work(&local->sta_proc_add);
|
||||
} else
|
||||
finish_sta_info_free(local, 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;
|
||||
|
||||
spin_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);
|
||||
}
|
||||
spin_unlock_bh(&local->sta_lock);
|
||||
|
||||
local->sta_cleanup.expires = jiffies + STA_INFO_CLEANUP_INTERVAL;
|
||||
add_timer(&local->sta_cleanup);
|
||||
}
|
||||
|
||||
|
||||
static void sta_info_proc_add_task(void *data)
|
||||
{
|
||||
struct ieee80211_local *local = data;
|
||||
struct sta_info *sta, *tmp;
|
||||
|
||||
while (1) {
|
||||
spin_lock_bh(&local->sta_lock);
|
||||
if (!list_empty(&local->deleted_sta_list)) {
|
||||
sta = list_entry(local->deleted_sta_list.next,
|
||||
struct sta_info, list);
|
||||
list_del(local->deleted_sta_list.next);
|
||||
} else
|
||||
sta = NULL;
|
||||
spin_unlock_bh(&local->sta_lock);
|
||||
if (!sta)
|
||||
break;
|
||||
finish_sta_info_free(local, sta);
|
||||
}
|
||||
|
||||
while (1) {
|
||||
sta = NULL;
|
||||
spin_lock_bh(&local->sta_lock);
|
||||
list_for_each_entry(tmp, &local->sta_list, list) {
|
||||
if (!tmp->sysfs_registered) {
|
||||
sta = tmp;
|
||||
__sta_info_get(sta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
spin_unlock_bh(&local->sta_lock);
|
||||
|
||||
if (!sta)
|
||||
break;
|
||||
|
||||
sta->sysfs_registered = 1;
|
||||
ieee80211_sta_sysfs_add(sta);
|
||||
rate_control_add_sta_attrs(sta, &sta->kobj);
|
||||
sta_info_put(sta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void sta_info_init(struct ieee80211_local *local)
|
||||
{
|
||||
spin_lock_init(&local->sta_lock);
|
||||
INIT_LIST_HEAD(&local->sta_list);
|
||||
INIT_LIST_HEAD(&local->deleted_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;
|
||||
|
||||
INIT_WORK(&local->sta_proc_add, sta_info_proc_add_task, local);
|
||||
}
|
||||
|
||||
int sta_info_start(struct ieee80211_local *local)
|
||||
{
|
||||
int res;
|
||||
|
||||
res = ieee80211_sta_kset_sysfs_register(local);
|
||||
if (res)
|
||||
return res;
|
||||
add_timer(&local->sta_cleanup);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sta_info_stop(struct ieee80211_local *local)
|
||||
{
|
||||
struct sta_info *sta, *tmp;
|
||||
|
||||
del_timer(&local->sta_cleanup);
|
||||
|
||||
list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
|
||||
/* sta_info_free must be called with 0 as the last
|
||||
* parameter to ensure all sysfs sta entries are
|
||||
* unregistered. We don't need locking at this
|
||||
* point. */
|
||||
sta_info_free(sta, 0);
|
||||
}
|
||||
ieee80211_sta_kset_sysfs_unregister(local);
|
||||
}
|
||||
|
||||
|
||||
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->local, 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;
|
||||
|
||||
spin_lock_bh(&local->sta_lock);
|
||||
list_for_each_entry_safe(sta, tmp, &local->sta_list, list)
|
||||
if (!dev || dev == sta->dev)
|
||||
sta_info_free(sta, 1);
|
||||
spin_unlock_bh(&local->sta_lock);
|
||||
}
|
149
package/d80211/src/sta_info.h
Normal file
149
package/d80211/src/sta_info.h
Normal file
|
@ -0,0 +1,149 @@
|
|||
/*
|
||||
* 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 "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)
|
||||
#define WLAN_STA_WME BIT(9)
|
||||
#define WLAN_STA_WDS BIT(27)
|
||||
|
||||
|
||||
struct sta_info {
|
||||
struct list_head list;
|
||||
struct kobject kobj;
|
||||
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;
|
||||
|
||||
int antenna_sel;
|
||||
|
||||
|
||||
int key_idx_compression; /* key table index for compression and TX
|
||||
* filtering; used only if sta->key is not
|
||||
* set */
|
||||
|
||||
unsigned int sysfs_registered:1;
|
||||
unsigned int assoc_ap:1; /* whether this is an AP that we are
|
||||
* associated with as a client */
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
u32 wpa_trigger;
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
#ifdef CONFIG_D80211_DEBUG_COUNTERS
|
||||
unsigned int wme_rx_queue[NUM_RX_DATA_QUEUES];
|
||||
unsigned int wme_tx_queue[NUM_RX_DATA_QUEUES];
|
||||
#endif /* CONFIG_D80211_DEBUG_COUNTERS */
|
||||
|
||||
int vlan_id;
|
||||
|
||||
u16 listen_interval;
|
||||
};
|
||||
|
||||
|
||||
/* 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)
|
||||
|
||||
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_free(struct sta_info *sta, int locked);
|
||||
void sta_info_release(struct kobject *kobj);
|
||||
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 */
|
341
package/d80211/src/tkip.c
Normal file
341
package/d80211/src/tkip.c
Normal file
|
@ -0,0 +1,341 @@
|
|||
/*
|
||||
* 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/d80211.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->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->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->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->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 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->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->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->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->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) {
|
||||
/* FIX: these should be updated only after Michael MIC has been
|
||||
* verified */
|
||||
/* Record previously received IV */
|
||||
key->u.tkip.iv32_rx[queue] = iv32;
|
||||
key->u.tkip.iv16_rx[queue] = iv16;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
36
package/d80211/src/tkip.h
Normal file
36
package/d80211/src/tkip.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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);
|
||||
|
||||
#endif /* TKIP_H */
|
327
package/d80211/src/wep.c
Normal file
327
package/d80211/src/wep.c
Normal file
|
@ -0,0 +1,327 @@
|
|||
/*
|
||||
* 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 <asm/scatterlist.h>
|
||||
|
||||
#include <net/d80211.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;
|
||||
}
|
||||
|
||||
|
||||
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->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->keyidx << 6;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
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->alg != ALG_WEP)
|
||||
return -1;
|
||||
|
||||
klen = 3 + key->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->key, key->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->keyidx || key->alg != ALG_WEP)
|
||||
return -1;
|
||||
|
||||
klen = 3 + key->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->key, key->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;
|
||||
}
|
||||
|
||||
|
||||
int ieee80211_wep_get_keyidx(struct sk_buff *skb)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
u16 fc;
|
||||
int hdrlen;
|
||||
|
||||
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;
|
||||
|
||||
return skb->data[hdrlen + 3] >> 6;
|
||||
}
|
||||
|
||||
|
||||
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->keylen))
|
||||
return ivpos;
|
||||
|
||||
return NULL;
|
||||
}
|
40
package/d80211/src/wep.h
Normal file
40
package/d80211/src/wep.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* 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_get_iv(struct ieee80211_local *local,
|
||||
struct ieee80211_key *key, u8 *iv);
|
||||
u8 * ieee80211_wep_add_iv(struct ieee80211_local *local,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_key *key);
|
||||
void ieee80211_wep_remove_iv(struct ieee80211_local *local,
|
||||
struct sk_buff *skb,
|
||||
struct ieee80211_key *key);
|
||||
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);
|
||||
int ieee80211_wep_get_keyidx(struct sk_buff *skb);
|
||||
u8 * ieee80211_wep_is_weak_iv(struct sk_buff *skb, struct ieee80211_key *key);
|
||||
|
||||
#endif /* WEP_H */
|
693
package/d80211/src/wme.c
Normal file
693
package/d80211/src/wme.c
Normal file
|
@ -0,0 +1,693 @@
|
|||
/*
|
||||
* 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/d80211.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "wme.h"
|
||||
|
||||
#define CHILD_QDISC_OPS pfifo_qdisc_ops
|
||||
|
||||
static inline int WLAN_FC_IS_QOS_DATA(u16 fc)
|
||||
{
|
||||
return (fc & 0x8C) == 0x88;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx)
|
||||
{
|
||||
u8 *data = rx->skb->data;
|
||||
int tid;
|
||||
|
||||
/* does the frame have a qos control field? */
|
||||
if (WLAN_FC_IS_QOS_DATA(rx->fc)) {
|
||||
u8 *qc = data + ieee80211_get_hdrlen(rx->fc) - QOS_CONTROL_LEN;
|
||||
/* frame has qos control */
|
||||
tid = qc[0] & QOS_CONTROL_TID_MASK;
|
||||
} else {
|
||||
if (unlikely((rx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT)) {
|
||||
/* Separate TID for management frames */
|
||||
tid = NUM_RX_DATA_QUEUES - 1;
|
||||
} else {
|
||||
/* no qos control present */
|
||||
tid = 0; /* 802.1d - Best Effort */
|
||||
}
|
||||
}
|
||||
#ifdef CONFIG_D80211_DEBUG_COUNTERS
|
||||
I802_DEBUG_INC(rx->local->wme_rx_queue[tid]);
|
||||
if (rx->sta) {
|
||||
I802_DEBUG_INC(rx->sta->wme_rx_queue[tid]);
|
||||
}
|
||||
#endif /* CONFIG_D80211_DEBUG_COUNTERS */
|
||||
|
||||
rx->u.rx.queue = tid;
|
||||
/* Set skb->priority to 1d tag if highest order bit of TID is not set.
|
||||
* For now, set skb->priority to 0 for other cases. */
|
||||
rx->skb->priority = (tid > 7) ? 0 : tid;
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx)
|
||||
{
|
||||
u16 fc = rx->fc;
|
||||
u8 *data = rx->skb->data;
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) data;
|
||||
|
||||
if (!WLAN_FC_IS_QOS_DATA(fc))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
/* remove the qos control field, update frame type and meta-data */
|
||||
memmove(data + 2, data, ieee80211_get_hdrlen(fc) - 2);
|
||||
hdr = (struct ieee80211_hdr *) skb_pull(rx->skb, 2);
|
||||
/* change frame type to non QOS */
|
||||
rx->fc = fc &= ~IEEE80211_STYPE_QOS_DATA;
|
||||
hdr->frame_control = cpu_to_le16(fc);
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
/* 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;
|
||||
|
||||
#ifdef CONFIG_NET_SCHED
|
||||
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;
|
||||
}
|
||||
#endif /* CONFIG_NET_SCHED */
|
||||
|
||||
/* 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;
|
||||
switch (dscp) {
|
||||
case 0x20:
|
||||
return 2;
|
||||
case 0x40:
|
||||
return 1;
|
||||
case 0x60:
|
||||
return 3;
|
||||
case 0x80:
|
||||
return 4;
|
||||
case 0xa0:
|
||||
return 5;
|
||||
case 0xc0:
|
||||
return 6;
|
||||
case 0xe0:
|
||||
return 7;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 = qd->dev->ieee80211_ptr;
|
||||
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);
|
||||
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 (unlikely(pkt_data->mgmt_iface)) {
|
||||
/* Data frames from hostapd (mainly, EAPOL) use AC_VO
|
||||
* and they will include QoS control fields if
|
||||
* the target STA is using WME. */
|
||||
skb->priority = 7;
|
||||
return ieee802_1d_to_ac[skb->priority];
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
/* incase 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 = 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->requeue) {
|
||||
skb_queue_tail(&q->requeued[pkt_data->queue], skb);
|
||||
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 = 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)
|
||||
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 = 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 = qd->dev->ieee80211_ptr;
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
struct tcf_proto *tp;
|
||||
int queue;
|
||||
|
||||
while ((tp = q->filter_list) != NULL) {
|
||||
q->filter_list = tp->next;
|
||||
tp->ops->destroy(tp);
|
||||
}
|
||||
|
||||
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 = dev->ieee80211_ptr;
|
||||
int queues = local->hw.queues;
|
||||
int err = 0, i;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* 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, &CHILD_QDISC_OPS);
|
||||
if (q->queues[i] == 0) {
|
||||
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 = 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 = 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 = 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)
|
||||
{
|
||||
/* printk(KERN_DEBUG "entering %s\n", __func__); */
|
||||
}
|
||||
|
||||
|
||||
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 = qd->dev->ieee80211_ptr;
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
/* printk(KERN_DEBUG "entering %s\n", __func__); */
|
||||
|
||||
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 = qd->dev->ieee80211_ptr;
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
/* printk(KERN_DEBUG "entering %s\n", __func__); */
|
||||
|
||||
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 = qd->dev->ieee80211_ptr;
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
/* printk(KERN_DEBUG "entering %s\n", __func__); */
|
||||
|
||||
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 = qd->dev->ieee80211_ptr;
|
||||
struct ieee80211_hw *hw = &local->hw;
|
||||
int queue;
|
||||
/* printk(KERN_DEBUG "entering %s\n", __func__); */
|
||||
|
||||
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);
|
||||
/* printk("entering %s\n", __func__); */
|
||||
|
||||
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);
|
||||
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_wme_register(void)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
#ifdef CONFIG_NET_SCHED
|
||||
err = register_qdisc(&wme_qdisc_ops);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
void ieee80211_wme_unregister(void)
|
||||
{
|
||||
#ifdef CONFIG_NET_SCHED
|
||||
unregister_qdisc(&wme_qdisc_ops);
|
||||
#endif
|
||||
}
|
38
package/d80211/src/wme.h
Normal file
38
package/d80211/src/wme.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_parse_qos(struct ieee80211_txrx_data *rx);
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_remove_qos_control(struct ieee80211_txrx_data *rx);
|
||||
|
||||
void ieee80211_install_qdisc(struct net_device *dev);
|
||||
|
||||
int ieee80211_wme_register(void);
|
||||
void ieee80211_wme_unregister(void);
|
||||
|
||||
#endif
|
846
package/d80211/src/wpa.c
Normal file
846
package/d80211/src/wpa.c
Normal file
|
@ -0,0 +1,846 @@
|
|||
/*
|
||||
* 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/iw_handler.h>
|
||||
|
||||
#include <net/d80211.h>
|
||||
#include <net/d80211_common.h>
|
||||
#include "ieee80211_i.h"
|
||||
#include "michael.h"
|
||||
#include "tkip.h"
|
||||
#include "aes_ccm.h"
|
||||
#include "wpa.h"
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
#include "hostapd_ioctl.h"
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
|
||||
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->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;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if ((tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) ||
|
||||
(!tx->u.tx.unicast &&
|
||||
tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC)) {
|
||||
wpa_test = 1;
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
if (!tx->key->force_sw_encrypt &&
|
||||
!tx->fragmented &&
|
||||
!(tx->local->hw.flags & IEEE80211_HW_TKIP_INCLUDE_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->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);
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) {
|
||||
printk(KERN_INFO "%s: WPA testing - corrupting TX Michael MIC "
|
||||
"for STA " MAC_FMT "\n",
|
||||
tx->dev->name, MAC_ARG(tx->sta->addr));
|
||||
tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
|
||||
tx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_MIC;
|
||||
tx->wpa_test = 1;
|
||||
mic[0]++;
|
||||
} else if (!tx->u.tx.unicast &&
|
||||
tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_MIC) {
|
||||
printk(KERN_INFO "%s: WPA testing - corrupting TX Michael MIC "
|
||||
"for Group Key\n", tx->dev->name);
|
||||
tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
|
||||
tx->local->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_MIC;
|
||||
tx->wpa_test = 1;
|
||||
mic[0]++;
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
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;
|
||||
|
||||
/* If device handles decryption totally, skip this check */
|
||||
if ((rx->local->hw.flags & IEEE80211_HW_DEVICE_HIDES_WEP) ||
|
||||
(rx->local->hw.flags & IEEE80211_HW_DEVICE_STRIPS_MIC))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
if (!rx->key || rx->key->alg != ALG_TKIP ||
|
||||
!(rx->fc & IEEE80211_FCTL_PROTECTED) || !WLAN_FC_DATA_PRESENT(fc))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
|
||||
wpa_test = 1;
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
|
||||
!rx->key->force_sw_encrypt) {
|
||||
if (rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) {
|
||||
if (skb->len < MICHAEL_MIC_LEN)
|
||||
return TXRX_DROP;
|
||||
}
|
||||
/* Need to verify Michael MIC sometimes in software even when
|
||||
* hwaccel is used. Atheros ar5212: fragmented frames and QoS
|
||||
* frames. */
|
||||
if (!rx->fragmented && !wpa_test)
|
||||
goto remove_mic;
|
||||
}
|
||||
|
||||
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->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);
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_MIC) {
|
||||
printk(KERN_INFO "%s: WPA testing - corrupting RX Michael MIC "
|
||||
"for STA " MAC_FMT "\n",
|
||||
rx->dev->name, MAC_ARG(rx->sta->addr));
|
||||
rx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_RX_MIC;
|
||||
mic[0]++;
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
if (memcmp(mic, data + data_len, MICHAEL_MIC_LEN) != 0 || wpa_test) {
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
int i;
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
if (!rx->u.rx.ra_match)
|
||||
return TXRX_DROP;
|
||||
|
||||
printk(KERN_DEBUG "%s: invalid Michael MIC in data frame from "
|
||||
MAC_FMT "\n", rx->dev->name, MAC_ARG(sa));
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
printk(KERN_DEBUG " received");
|
||||
for (i = 0; i < MICHAEL_MIC_LEN; i++)
|
||||
printk(" %02x", data[data_len + i]);
|
||||
printk(" expected");
|
||||
for (i = 0; i < MICHAEL_MIC_LEN; i++)
|
||||
printk(" %02x", mic[i]);
|
||||
printk("\n");
|
||||
printk(KERN_DEBUG " SA=" MAC_FMT " DA=" MAC_FMT " key",
|
||||
MAC_ARG(sa), MAC_ARG(da));
|
||||
for (i = 0; i < 8; i++)
|
||||
printk(" %02x", key[i]);
|
||||
printk(" (%d)\n", authenticator);
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
do {
|
||||
struct ieee80211_hdr *hdr;
|
||||
union iwreq_data wrqu;
|
||||
char *buf = kmalloc(128, GFP_ATOMIC);
|
||||
if (!buf)
|
||||
break;
|
||||
|
||||
/* TODO: needed parameters: count, key type, TSC */
|
||||
hdr = (struct ieee80211_hdr *) skb->data;
|
||||
sprintf(buf, "MLME-MICHAELMICFAILURE.indication("
|
||||
"keyid=%d %scast addr=" MAC_FMT ")",
|
||||
rx->key->keyidx,
|
||||
hdr->addr1[0] & 0x01 ? "broad" : "uni",
|
||||
MAC_ARG(hdr->addr2));
|
||||
memset(&wrqu, 0, sizeof(wrqu));
|
||||
wrqu.data.length = strlen(buf);
|
||||
wireless_send_event(rx->dev, IWEVCUSTOM, &wrqu, buf);
|
||||
kfree(buf);
|
||||
} while (0);
|
||||
|
||||
if (!rx->local->apdev)
|
||||
return TXRX_DROP;
|
||||
|
||||
ieee80211_rx_mgmt(rx->local, rx->skb, rx->u.rx.status,
|
||||
ieee80211_msg_michael_mic_failure);
|
||||
|
||||
return TXRX_QUEUED;
|
||||
}
|
||||
|
||||
remove_mic:
|
||||
/* remove Michael MIC from payload */
|
||||
skb_trim(skb, skb->len - MICHAEL_MIC_LEN);
|
||||
|
||||
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;
|
||||
|
||||
tailneed = !tx->key->force_sw_encrypt ? 0 : 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;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (test & WPA_TRIGGER_TX_REPLAY)
|
||||
goto skip_iv_inc;
|
||||
iv_inc:
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
/* Increase IV for the frame */
|
||||
key->u.tkip.iv16++;
|
||||
if (key->u.tkip.iv16 == 0)
|
||||
key->u.tkip.iv32++;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
|
||||
test = 0;
|
||||
goto iv_inc;
|
||||
}
|
||||
skip_iv_inc:
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
if (!tx->key->force_sw_encrypt
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
&& !tx->wpa_test
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
) {
|
||||
u32 flags = tx->local->hw.flags;
|
||||
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);
|
||||
|
||||
if (flags & IEEE80211_HW_TKIP_REQ_PHASE2_KEY)
|
||||
ieee80211_tkip_gen_rc4key(key, hdr->addr2,
|
||||
tx->u.tx.control->tkip_key);
|
||||
else if (flags & IEEE80211_HW_TKIP_REQ_PHASE1_KEY) {
|
||||
if (key->u.tkip.iv16 == 0 ||
|
||||
!key->u.tkip.tx_initialized) {
|
||||
ieee80211_tkip_gen_phase1key(key, hdr->addr2,
|
||||
(u16 *)tx->u.tx.control->tkip_key);
|
||||
key->u.tkip.tx_initialized = 1;
|
||||
tx->u.tx.control->flags |=
|
||||
IEEE80211_TXCTL_TKIP_NEW_PHASE1_KEY;
|
||||
} else
|
||||
tx->u.tx.control->flags &=
|
||||
~IEEE80211_TXCTL_TKIP_NEW_PHASE1_KEY;
|
||||
}
|
||||
|
||||
tx->u.tx.control->key_idx = tx->key->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_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
|
||||
u16 fc;
|
||||
struct ieee80211_key *key = tx->key;
|
||||
struct sk_buff *skb = tx->skb;
|
||||
int wpa_test = 0, test = 0;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
if (!key || key->alg != ALG_TKIP || !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);
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if ((tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) ||
|
||||
(!tx->u.tx.unicast &&
|
||||
tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV)) {
|
||||
wpa_test = 1;
|
||||
}
|
||||
|
||||
if (tx->sta) {
|
||||
test = tx->sta->wpa_trigger;
|
||||
tx->sta->wpa_trigger &=
|
||||
~(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
|
||||
WPA_TRIGGER_TX_SKIP_SEQ);
|
||||
} else {
|
||||
test = tx->local->wpa_trigger;
|
||||
tx->local->wpa_trigger &=
|
||||
~(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
|
||||
WPA_TRIGGER_TX_SKIP_SEQ);
|
||||
}
|
||||
if (test &
|
||||
(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
|
||||
WPA_TRIGGER_TX_SKIP_SEQ)) {
|
||||
printk(KERN_INFO "%s: WPA testing - TKIP TX packet number "
|
||||
"%s%s%s%s\n", tx->dev->name,
|
||||
tx->sta ? "[UNICAST]" : "[MULTICAST]",
|
||||
test & WPA_TRIGGER_TX_REPLAY ? "[REPLAY]" : "",
|
||||
test & WPA_TRIGGER_TX_REPLAY_FRAG ?
|
||||
"[REPLAY FRAG]" : "",
|
||||
test & WPA_TRIGGER_TX_SKIP_SEQ ? "[SKIP SEQ]" : "");
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
if (!tx->key->force_sw_encrypt &&
|
||||
!(tx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV) &&
|
||||
!wpa_test) {
|
||||
/* hwaccel - with no need for preallocated room for IV/ICV */
|
||||
tx->u.tx.control->key_idx = tx->key->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;
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (test & WPA_TRIGGER_TX_REPLAY_FRAG)
|
||||
test |= WPA_TRIGGER_TX_REPLAY;
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (tx->sta && tx->sta->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) {
|
||||
printk(KERN_INFO "%s: WPA testing - corrupting TX TKIP ICV "
|
||||
"for STA " MAC_FMT "\n",
|
||||
tx->dev->name, MAC_ARG(tx->sta->addr));
|
||||
tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
|
||||
tx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_ICV;
|
||||
skb->data[skb->len - 1]++;
|
||||
} else if (!tx->u.tx.unicast &&
|
||||
tx->local->wpa_trigger & WPA_TRIGGER_FAIL_TX_ICV) {
|
||||
printk(KERN_INFO "%s: WPA testing - corrupting TX TKIP ICV "
|
||||
"for Group Key\n",
|
||||
tx->dev->name);
|
||||
tx->u.tx.control->key_idx = HW_KEY_IDX_INVALID;
|
||||
tx->local->wpa_trigger &= ~WPA_TRIGGER_FAIL_TX_ICV;
|
||||
skb->data[skb->len - 1]++;
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
return TXRX_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_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->key || rx->key->alg != ALG_TKIP ||
|
||||
!(rx->fc & IEEE80211_FCTL_PROTECTED) ||
|
||||
(rx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
if (!rx->sta || skb->len - hdrlen < 12)
|
||||
return TXRX_DROP;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (rx->sta && rx->sta->wpa_trigger & WPA_TRIGGER_FAIL_RX_ICV) {
|
||||
printk(KERN_INFO "%s: WPA testing - corrupting RX TKIP ICV "
|
||||
"for STA " MAC_FMT "\n",
|
||||
rx->dev->name, MAC_ARG(rx->sta->addr));
|
||||
rx->sta->wpa_trigger &= ~WPA_TRIGGER_FAIL_RX_ICV;
|
||||
skb->data[skb->len - 1]++;
|
||||
wpa_test = 1;
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
|
||||
!rx->key->force_sw_encrypt) {
|
||||
if (!(rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV)) {
|
||||
/* Hardware takes care of all processing, including
|
||||
* replay protection, so no need to continue 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);
|
||||
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;
|
||||
|
||||
tailneed = !key->force_sw_encrypt ? 0 : 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;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (test & WPA_TRIGGER_TX_REPLAY)
|
||||
goto skip_pn_inc;
|
||||
pn_inc:
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
for (i = CCMP_PN_LEN - 1; i >= 0; i--) {
|
||||
pn[i]++;
|
||||
if (pn[i])
|
||||
break;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (test & WPA_TRIGGER_TX_SKIP_SEQ) {
|
||||
test = 0;
|
||||
goto pn_inc;
|
||||
}
|
||||
skip_pn_inc:
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
ccmp_pn2hdr(pos, pn, key->keyidx);
|
||||
|
||||
if (!key->force_sw_encrypt) {
|
||||
/* hwaccel - with preallocated room for CCMP header */
|
||||
tx->u.tx.control->key_idx = key->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_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
|
||||
struct ieee80211_key *key = tx->key;
|
||||
u16 fc;
|
||||
struct sk_buff *skb = tx->skb;
|
||||
int test = 0;
|
||||
|
||||
fc = le16_to_cpu(hdr->frame_control);
|
||||
|
||||
if (!key || key->alg != ALG_CCMP || !WLAN_FC_DATA_PRESENT(fc))
|
||||
return TXRX_CONTINUE;
|
||||
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (tx->sta) {
|
||||
test = tx->sta->wpa_trigger;
|
||||
tx->sta->wpa_trigger = 0;
|
||||
} else {
|
||||
test = tx->local->wpa_trigger;
|
||||
tx->local->wpa_trigger = 0;
|
||||
}
|
||||
if (test &
|
||||
(WPA_TRIGGER_TX_REPLAY | WPA_TRIGGER_TX_REPLAY_FRAG |
|
||||
WPA_TRIGGER_TX_SKIP_SEQ)) {
|
||||
printk(KERN_INFO "%s: WPA testing - CCMP TX packet number "
|
||||
"%s%s%s%s\n", tx->dev->name,
|
||||
tx->sta ? "[UNICAST]" : "[MULTICAST]",
|
||||
test & WPA_TRIGGER_TX_REPLAY ? "[REPLAY]" : "",
|
||||
test & WPA_TRIGGER_TX_REPLAY_FRAG ?
|
||||
"[REPLAY FRAG]" : "",
|
||||
test & WPA_TRIGGER_TX_SKIP_SEQ ? "[SKIP SEQ]" : "");
|
||||
}
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
|
||||
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->force_sw_encrypt &&
|
||||
!(tx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV)) {
|
||||
/* hwaccel - with no need for preallocated room for CCMP "
|
||||
* header or MIC fields */
|
||||
tx->u.tx.control->key_idx = tx->key->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;
|
||||
#ifdef CONFIG_HOSTAPD_WPA_TESTING
|
||||
if (test & WPA_TRIGGER_TX_REPLAY_FRAG)
|
||||
test |= WPA_TRIGGER_TX_REPLAY;
|
||||
#endif /* CONFIG_HOSTAPD_WPA_TESTING */
|
||||
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_rx_h_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 (!key || key->alg != ALG_CCMP ||
|
||||
!(rx->fc & IEEE80211_FCTL_PROTECTED) ||
|
||||
(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) &&
|
||||
!key->force_sw_encrypt &&
|
||||
!(rx->local->hw.flags & IEEE80211_HW_WEP_INCLUDE_IV))
|
||||
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_D80211_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_D80211_DEBUG */
|
||||
key->u.ccmp.replays++;
|
||||
return TXRX_DROP;
|
||||
}
|
||||
|
||||
if ((rx->u.rx.status->flag & RX_FLAG_DECRYPTED) &&
|
||||
!key->force_sw_encrypt) {
|
||||
/* hwaccel has already decrypted frame and verified MIC */
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
|
34
package/d80211/src/wpa.h
Normal file
34
package/d80211/src/wpa.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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_tx_h_tkip_encrypt(struct ieee80211_txrx_data *tx);
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_tkip_decrypt(struct ieee80211_txrx_data *rx);
|
||||
|
||||
ieee80211_txrx_result
|
||||
ieee80211_tx_h_ccmp_encrypt(struct ieee80211_txrx_data *tx);
|
||||
ieee80211_txrx_result
|
||||
ieee80211_rx_h_ccmp_decrypt(struct ieee80211_txrx_data *rx);
|
||||
|
||||
int ieee80211_get_hdr_info(const struct sk_buff *skb, u8 **sa, u8 **da,
|
||||
u8 *qos_tid, u8 **data, size_t *data_len);
|
||||
|
||||
#endif /* WPA_H */
|
Loading…
Reference in a new issue