aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/Kconfig2
-rw-r--r--drivers/net/wireless/Makefile2
-rw-r--r--drivers/net/wireless/airo.c65
-rw-r--r--drivers/net/wireless/hostap/Kconfig71
-rw-r--r--drivers/net/wireless/hostap/Makefile5
-rw-r--r--drivers/net/wireless/hostap/hostap.c1199
-rw-r--r--drivers/net/wireless/hostap/hostap.h57
-rw-r--r--drivers/net/wireless/hostap/hostap_80211.h107
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_rx.c1084
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_tx.c522
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.c3287
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.h273
-rw-r--r--drivers/net/wireless/hostap/hostap_common.h499
-rw-r--r--drivers/net/wireless/hostap/hostap_config.h86
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c985
-rw-r--r--drivers/net/wireless/hostap/hostap_download.c766
-rw-r--r--drivers/net/wireless/hostap/hostap_hw.c3635
-rw-r--r--drivers/net/wireless/hostap/hostap_info.c499
-rw-r--r--drivers/net/wireless/hostap/hostap_ioctl.c4126
-rw-r--r--drivers/net/wireless/hostap/hostap_pci.c455
-rw-r--r--drivers/net/wireless/hostap/hostap_plx.c622
-rw-r--r--drivers/net/wireless/hostap/hostap_proc.c448
-rw-r--r--drivers/net/wireless/hostap/hostap_wlan.h1066
-rw-r--r--drivers/net/wireless/strip.c2
-rw-r--r--drivers/net/wireless/wavelan_cs.c26
-rw-r--r--drivers/net/wireless/wavelan_cs.h6
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h17
-rw-r--r--drivers/net/wireless/wl3501_cs.c11
28 files changed, 19855 insertions, 68 deletions
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index d20e0da05a26..ff5b1b1de2fa 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -459,6 +459,8 @@ config PRISM54
459 say M here and read <file:Documentation/modules.txt>. The module 459 say M here and read <file:Documentation/modules.txt>. The module
460 will be called prism54.ko. 460 will be called prism54.ko.
461 461
462source "drivers/net/wireless/hostap/Kconfig"
463
462# yes, this works even when no drivers are selected 464# yes, this works even when no drivers are selected
463config NET_WIRELESS 465config NET_WIRELESS
464 bool 466 bool
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 0859787581bb..0953cc0cdee6 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -32,6 +32,8 @@ obj-$(CONFIG_PCMCIA_ATMEL) += atmel_cs.o
32 32
33obj-$(CONFIG_PRISM54) += prism54/ 33obj-$(CONFIG_PRISM54) += prism54/
34 34
35obj-$(CONFIG_HOSTAP) += hostap/
36
35# 16-bit wireless PCMCIA client drivers 37# 16-bit wireless PCMCIA client drivers
36obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o 38obj-$(CONFIG_PCMCIA_RAYCS) += ray_cs.o
37obj-$(CONFIG_PCMCIA_WL3501) += wl3501_cs.o 39obj-$(CONFIG_PCMCIA_WL3501) += wl3501_cs.o
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index df20adcd0730..6db1fb6461de 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1040,7 +1040,7 @@ typedef struct {
1040 u16 status; 1040 u16 status;
1041} WifiCtlHdr; 1041} WifiCtlHdr;
1042 1042
1043WifiCtlHdr wifictlhdr8023 = { 1043static WifiCtlHdr wifictlhdr8023 = {
1044 .ctlhdr = { 1044 .ctlhdr = {
1045 .ctl = HOST_DONT_RLSE, 1045 .ctl = HOST_DONT_RLSE,
1046 } 1046 }
@@ -1111,13 +1111,13 @@ static int airo_thread(void *data);
1111static void timer_func( struct net_device *dev ); 1111static void timer_func( struct net_device *dev );
1112static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); 1112static int airo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
1113#ifdef WIRELESS_EXT 1113#ifdef WIRELESS_EXT
1114struct iw_statistics *airo_get_wireless_stats (struct net_device *dev); 1114static struct iw_statistics *airo_get_wireless_stats (struct net_device *dev);
1115static void airo_read_wireless_stats (struct airo_info *local); 1115static void airo_read_wireless_stats (struct airo_info *local);
1116#endif /* WIRELESS_EXT */ 1116#endif /* WIRELESS_EXT */
1117#ifdef CISCO_EXT 1117#ifdef CISCO_EXT
1118static int readrids(struct net_device *dev, aironet_ioctl *comp); 1118static int readrids(struct net_device *dev, aironet_ioctl *comp);
1119static int writerids(struct net_device *dev, aironet_ioctl *comp); 1119static int writerids(struct net_device *dev, aironet_ioctl *comp);
1120int flashcard(struct net_device *dev, aironet_ioctl *comp); 1120static int flashcard(struct net_device *dev, aironet_ioctl *comp);
1121#endif /* CISCO_EXT */ 1121#endif /* CISCO_EXT */
1122#ifdef MICSUPPORT 1122#ifdef MICSUPPORT
1123static void micinit(struct airo_info *ai); 1123static void micinit(struct airo_info *ai);
@@ -1226,6 +1226,12 @@ static int setup_proc_entry( struct net_device *dev,
1226static int takedown_proc_entry( struct net_device *dev, 1226static int takedown_proc_entry( struct net_device *dev,
1227 struct airo_info *apriv ); 1227 struct airo_info *apriv );
1228 1228
1229static int cmdreset(struct airo_info *ai);
1230static int setflashmode (struct airo_info *ai);
1231static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime);
1232static int flashputbuf(struct airo_info *ai);
1233static int flashrestart(struct airo_info *ai,struct net_device *dev);
1234
1229#ifdef MICSUPPORT 1235#ifdef MICSUPPORT
1230/*********************************************************************** 1236/***********************************************************************
1231 * MIC ROUTINES * 1237 * MIC ROUTINES *
@@ -1234,10 +1240,11 @@ static int takedown_proc_entry( struct net_device *dev,
1234 1240
1235static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq); 1241static int RxSeqValid (struct airo_info *ai,miccntx *context,int mcast,u32 micSeq);
1236static void MoveWindow(miccntx *context, u32 micSeq); 1242static void MoveWindow(miccntx *context, u32 micSeq);
1237void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *); 1243static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *);
1238void emmh32_init(emmh32_context *context); 1244static void emmh32_init(emmh32_context *context);
1239void emmh32_update(emmh32_context *context, u8 *pOctets, int len); 1245static void emmh32_update(emmh32_context *context, u8 *pOctets, int len);
1240void emmh32_final(emmh32_context *context, u8 digest[4]); 1246static void emmh32_final(emmh32_context *context, u8 digest[4]);
1247static int flashpchar(struct airo_info *ai,int byte,int dwelltime);
1241 1248
1242/* micinit - Initialize mic seed */ 1249/* micinit - Initialize mic seed */
1243 1250
@@ -1315,7 +1322,7 @@ static int micsetup(struct airo_info *ai) {
1315 return SUCCESS; 1322 return SUCCESS;
1316} 1323}
1317 1324
1318char micsnap[]= {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02}; 1325static char micsnap[] = {0xAA,0xAA,0x03,0x00,0x40,0x96,0x00,0x02};
1319 1326
1320/*=========================================================================== 1327/*===========================================================================
1321 * Description: Mic a packet 1328 * Description: Mic a packet
@@ -1570,7 +1577,7 @@ static void MoveWindow(miccntx *context, u32 micSeq)
1570static unsigned char aes_counter[16]; 1577static unsigned char aes_counter[16];
1571 1578
1572/* expand the key to fill the MMH coefficient array */ 1579/* expand the key to fill the MMH coefficient array */
1573void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm) 1580static void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto_tfm *tfm)
1574{ 1581{
1575 /* take the keying material, expand if necessary, truncate at 16-bytes */ 1582 /* take the keying material, expand if necessary, truncate at 16-bytes */
1576 /* run through AES counter mode to generate context->coeff[] */ 1583 /* run through AES counter mode to generate context->coeff[] */
@@ -1602,7 +1609,7 @@ void emmh32_setseed(emmh32_context *context, u8 *pkey, int keylen, struct crypto
1602} 1609}
1603 1610
1604/* prepare for calculation of a new mic */ 1611/* prepare for calculation of a new mic */
1605void emmh32_init(emmh32_context *context) 1612static void emmh32_init(emmh32_context *context)
1606{ 1613{
1607 /* prepare for new mic calculation */ 1614 /* prepare for new mic calculation */
1608 context->accum = 0; 1615 context->accum = 0;
@@ -1610,7 +1617,7 @@ void emmh32_init(emmh32_context *context)
1610} 1617}
1611 1618
1612/* add some bytes to the mic calculation */ 1619/* add some bytes to the mic calculation */
1613void emmh32_update(emmh32_context *context, u8 *pOctets, int len) 1620static void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1614{ 1621{
1615 int coeff_position, byte_position; 1622 int coeff_position, byte_position;
1616 1623
@@ -1652,7 +1659,7 @@ void emmh32_update(emmh32_context *context, u8 *pOctets, int len)
1652static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L }; 1659static u32 mask32[4] = { 0x00000000L, 0xFF000000L, 0xFFFF0000L, 0xFFFFFF00L };
1653 1660
1654/* calculate the mic */ 1661/* calculate the mic */
1655void emmh32_final(emmh32_context *context, u8 digest[4]) 1662static void emmh32_final(emmh32_context *context, u8 digest[4])
1656{ 1663{
1657 int coeff_position, byte_position; 1664 int coeff_position, byte_position;
1658 u32 val; 1665 u32 val;
@@ -2255,7 +2262,7 @@ static void airo_read_stats(struct airo_info *ai) {
2255 ai->stats.rx_fifo_errors = vals[0]; 2262 ai->stats.rx_fifo_errors = vals[0];
2256} 2263}
2257 2264
2258struct net_device_stats *airo_get_stats(struct net_device *dev) 2265static struct net_device_stats *airo_get_stats(struct net_device *dev)
2259{ 2266{
2260 struct airo_info *local = dev->priv; 2267 struct airo_info *local = dev->priv;
2261 2268
@@ -2414,7 +2421,7 @@ EXPORT_SYMBOL(stop_airo_card);
2414 2421
2415static int add_airo_dev( struct net_device *dev ); 2422static int add_airo_dev( struct net_device *dev );
2416 2423
2417int wll_header_parse(struct sk_buff *skb, unsigned char *haddr) 2424static int wll_header_parse(struct sk_buff *skb, unsigned char *haddr)
2418{ 2425{
2419 memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); 2426 memcpy(haddr, skb->mac.raw + 10, ETH_ALEN);
2420 return ETH_ALEN; 2427 return ETH_ALEN;
@@ -2681,7 +2688,7 @@ static struct net_device *init_wifidev(struct airo_info *ai,
2681 return dev; 2688 return dev;
2682} 2689}
2683 2690
2684int reset_card( struct net_device *dev , int lock) { 2691static int reset_card( struct net_device *dev , int lock) {
2685 struct airo_info *ai = dev->priv; 2692 struct airo_info *ai = dev->priv;
2686 2693
2687 if (lock && down_interruptible(&ai->sem)) 2694 if (lock && down_interruptible(&ai->sem))
@@ -2696,9 +2703,9 @@ int reset_card( struct net_device *dev , int lock) {
2696 return 0; 2703 return 0;
2697} 2704}
2698 2705
2699struct net_device *_init_airo_card( unsigned short irq, int port, 2706static struct net_device *_init_airo_card( unsigned short irq, int port,
2700 int is_pcmcia, struct pci_dev *pci, 2707 int is_pcmcia, struct pci_dev *pci,
2701 struct device *dmdev ) 2708 struct device *dmdev )
2702{ 2709{
2703 struct net_device *dev; 2710 struct net_device *dev;
2704 struct airo_info *ai; 2711 struct airo_info *ai;
@@ -7235,7 +7242,7 @@ static void airo_read_wireless_stats(struct airo_info *local)
7235 local->wstats.miss.beacon = vals[34]; 7242 local->wstats.miss.beacon = vals[34];
7236} 7243}
7237 7244
7238struct iw_statistics *airo_get_wireless_stats(struct net_device *dev) 7245static struct iw_statistics *airo_get_wireless_stats(struct net_device *dev)
7239{ 7246{
7240 struct airo_info *local = dev->priv; 7247 struct airo_info *local = dev->priv;
7241 7248
@@ -7450,14 +7457,8 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
7450 * Flash command switch table 7457 * Flash command switch table
7451 */ 7458 */
7452 7459
7453int flashcard(struct net_device *dev, aironet_ioctl *comp) { 7460static int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7454 int z; 7461 int z;
7455 int cmdreset(struct airo_info *);
7456 int setflashmode(struct airo_info *);
7457 int flashgchar(struct airo_info *,int,int);
7458 int flashpchar(struct airo_info *,int,int);
7459 int flashputbuf(struct airo_info *);
7460 int flashrestart(struct airo_info *,struct net_device *);
7461 7462
7462 /* Only super-user can modify flash */ 7463 /* Only super-user can modify flash */
7463 if (!capable(CAP_NET_ADMIN)) 7464 if (!capable(CAP_NET_ADMIN))
@@ -7515,7 +7516,7 @@ int flashcard(struct net_device *dev, aironet_ioctl *comp) {
7515 * card. 7516 * card.
7516 */ 7517 */
7517 7518
7518int cmdreset(struct airo_info *ai) { 7519static int cmdreset(struct airo_info *ai) {
7519 disable_MAC(ai, 1); 7520 disable_MAC(ai, 1);
7520 7521
7521 if(!waitbusy (ai)){ 7522 if(!waitbusy (ai)){
@@ -7539,7 +7540,7 @@ int cmdreset(struct airo_info *ai) {
7539 * mode 7540 * mode
7540 */ 7541 */
7541 7542
7542int setflashmode (struct airo_info *ai) { 7543static int setflashmode (struct airo_info *ai) {
7543 set_bit (FLAG_FLASHING, &ai->flags); 7544 set_bit (FLAG_FLASHING, &ai->flags);
7544 7545
7545 OUT4500(ai, SWS0, FLASH_COMMAND); 7546 OUT4500(ai, SWS0, FLASH_COMMAND);
@@ -7566,7 +7567,7 @@ int setflashmode (struct airo_info *ai) {
7566 * x 50us for echo . 7567 * x 50us for echo .
7567 */ 7568 */
7568 7569
7569int flashpchar(struct airo_info *ai,int byte,int dwelltime) { 7570static int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
7570 int echo; 7571 int echo;
7571 int waittime; 7572 int waittime;
7572 7573
@@ -7606,7 +7607,7 @@ int flashpchar(struct airo_info *ai,int byte,int dwelltime) {
7606 * Get a character from the card matching matchbyte 7607 * Get a character from the card matching matchbyte
7607 * Step 3) 7608 * Step 3)
7608 */ 7609 */
7609int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){ 7610static int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
7610 int rchar; 7611 int rchar;
7611 unsigned char rbyte=0; 7612 unsigned char rbyte=0;
7612 7613
@@ -7637,7 +7638,7 @@ int flashgchar(struct airo_info *ai,int matchbyte,int dwelltime){
7637 * send to the card 7638 * send to the card
7638 */ 7639 */
7639 7640
7640int flashputbuf(struct airo_info *ai){ 7641static int flashputbuf(struct airo_info *ai){
7641 int nwords; 7642 int nwords;
7642 7643
7643 /* Write stuff */ 7644 /* Write stuff */
@@ -7659,7 +7660,7 @@ int flashputbuf(struct airo_info *ai){
7659/* 7660/*
7660 * 7661 *
7661 */ 7662 */
7662int flashrestart(struct airo_info *ai,struct net_device *dev){ 7663static int flashrestart(struct airo_info *ai,struct net_device *dev){
7663 int i,status; 7664 int i,status;
7664 7665
7665 ssleep(1); /* Added 12/7/00 */ 7666 ssleep(1); /* Added 12/7/00 */
diff --git a/drivers/net/wireless/hostap/Kconfig b/drivers/net/wireless/hostap/Kconfig
new file mode 100644
index 000000000000..1445f3f2600f
--- /dev/null
+++ b/drivers/net/wireless/hostap/Kconfig
@@ -0,0 +1,71 @@
1config HOSTAP
2 tristate "IEEE 802.11 for Host AP (Prism2/2.5/3 and WEP/TKIP/CCMP)"
3 depends on NET_RADIO
4 ---help---
5 Shared driver code for IEEE 802.11b wireless cards based on
6 Intersil Prism2/2.5/3 chipset. This driver supports so called
7 Host AP mode that allows the card to act as an IEEE 802.11
8 access point.
9
10 See <http://hostap.epitest.fi/> for more information about the
11 Host AP driver configuration and tools. This site includes
12 information and tools (hostapd and wpa_supplicant) for WPA/WPA2
13 support.
14
15 This option includes the base Host AP driver code that is shared by
16 different hardware models. You will also need to enable support for
17 PLX/PCI/CS version of the driver to actually use the driver.
18
19 The driver can be compiled as a module and it will be called
20 "hostap.ko".
21
22config HOSTAP_FIRMWARE
23 bool "Support downloading firmware images with Host AP driver"
24 depends on HOSTAP
25 ---help---
26 Configure Host AP driver to include support for firmware image
27 download. Current version supports only downloading to volatile, i.e.,
28 RAM memory. Flash upgrade is not yet supported.
29
30 Firmware image downloading needs user space tool, prism2_srec. It is
31 available from http://hostap.epitest.fi/.
32
33config HOSTAP_PLX
34 tristate "Host AP driver for Prism2/2.5/3 in PLX9052 PCI adaptors"
35 depends on PCI && HOSTAP
36 ---help---
37 Host AP driver's version for Prism2/2.5/3 PC Cards in PLX9052 based
38 PCI adaptors.
39
40 "Host AP support for Prism2/2.5/3 IEEE 802.11b" is required for this
41 driver and its help text includes more information about the Host AP
42 driver.
43
44 The driver can be compiled as a module and will be named
45 "hostap_plx.ko".
46
47config HOSTAP_PCI
48 tristate "Host AP driver for Prism2.5 PCI adaptors"
49 depends on PCI && HOSTAP
50 ---help---
51 Host AP driver's version for Prism2.5 PCI adaptors.
52
53 "Host AP support for Prism2/2.5/3 IEEE 802.11b" is required for this
54 driver and its help text includes more information about the Host AP
55 driver.
56
57 The driver can be compiled as a module and will be named
58 "hostap_pci.ko".
59
60config HOSTAP_CS
61 tristate "Host AP driver for Prism2/2.5/3 PC Cards"
62 depends on PCMCIA!=n && HOSTAP
63 ---help---
64 Host AP driver's version for Prism2/2.5/3 PC Cards.
65
66 "Host AP support for Prism2/2.5/3 IEEE 802.11b" is required for this
67 driver and its help text includes more information about the Host AP
68 driver.
69
70 The driver can be compiled as a module and will be named
71 "hostap_cs.ko".
diff --git a/drivers/net/wireless/hostap/Makefile b/drivers/net/wireless/hostap/Makefile
new file mode 100644
index 000000000000..fc62235bfc24
--- /dev/null
+++ b/drivers/net/wireless/hostap/Makefile
@@ -0,0 +1,5 @@
1obj-$(CONFIG_HOSTAP) += hostap.o
2
3obj-$(CONFIG_HOSTAP_CS) += hostap_cs.o
4obj-$(CONFIG_HOSTAP_PLX) += hostap_plx.o
5obj-$(CONFIG_HOSTAP_PCI) += hostap_pci.o
diff --git a/drivers/net/wireless/hostap/hostap.c b/drivers/net/wireless/hostap/hostap.c
new file mode 100644
index 000000000000..0858eba4575f
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap.c
@@ -0,0 +1,1199 @@
1/*
2 * Host AP (software wireless LAN access point) driver for
3 * Intersil Prism2/2.5/3 - hostap.o module, common routines
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <jkmaline@cc.hut.fi>
7 * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. See README and COPYING for
12 * more details.
13 */
14
15#include <linux/config.h>
16#include <linux/version.h>
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/proc_fs.h>
21#include <linux/if_arp.h>
22#include <linux/delay.h>
23#include <linux/random.h>
24#include <linux/workqueue.h>
25#include <linux/kmod.h>
26#include <linux/rtnetlink.h>
27#include <linux/wireless.h>
28#include <net/iw_handler.h>
29#include <net/ieee80211.h>
30#include <net/ieee80211_crypt.h>
31#include <asm/uaccess.h>
32
33#include "hostap_wlan.h"
34#include "hostap_80211.h"
35#include "hostap_ap.h"
36#include "hostap.h"
37
38MODULE_AUTHOR("Jouni Malinen");
39MODULE_DESCRIPTION("Host AP common routines");
40MODULE_LICENSE("GPL");
41MODULE_VERSION(PRISM2_VERSION);
42
43#define TX_TIMEOUT (2 * HZ)
44
45#define PRISM2_MAX_FRAME_SIZE 2304
46#define PRISM2_MIN_MTU 256
47/* FIX: */
48#define PRISM2_MAX_MTU (PRISM2_MAX_FRAME_SIZE - (6 /* LLC */ + 8 /* WEP */))
49
50
51/* hostap.c */
52static int prism2_wds_add(local_info_t *local, u8 *remote_addr,
53 int rtnl_locked);
54static int prism2_wds_del(local_info_t *local, u8 *remote_addr,
55 int rtnl_locked, int do_not_remove);
56
57/* hostap_ap.c */
58static int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
59 struct iw_quality qual[], int buf_size,
60 int aplist);
61static int prism2_ap_translate_scan(struct net_device *dev, char *buffer);
62static int prism2_hostapd(struct ap_data *ap,
63 struct prism2_hostapd_param *param);
64static void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
65 struct ieee80211_crypt_data ***crypt);
66static void ap_control_kickall(struct ap_data *ap);
67#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
68static int ap_control_add_mac(struct mac_restrictions *mac_restrictions,
69 u8 *mac);
70static int ap_control_del_mac(struct mac_restrictions *mac_restrictions,
71 u8 *mac);
72static void ap_control_flush_macs(struct mac_restrictions *mac_restrictions);
73static int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev,
74 u8 *mac);
75#endif /* !PRISM2_NO_KERNEL_IEEE80211_MGMT */
76
77
78static const long freq_list[] = { 2412, 2417, 2422, 2427, 2432, 2437, 2442,
79 2447, 2452, 2457, 2462, 2467, 2472, 2484 };
80#define FREQ_COUNT (sizeof(freq_list) / sizeof(freq_list[0]))
81
82
83/* See IEEE 802.1H for LLC/SNAP encapsulation/decapsulation */
84/* Ethernet-II snap header (RFC1042 for most EtherTypes) */
85static unsigned char rfc1042_header[] =
86{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
87/* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
88static unsigned char bridge_tunnel_header[] =
89{ 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
90/* No encapsulation header if EtherType < 0x600 (=length) */
91
92
93/* FIX: these could be compiled separately and linked together to hostap.o */
94#include "hostap_ap.c"
95#include "hostap_info.c"
96#include "hostap_ioctl.c"
97#include "hostap_proc.c"
98#include "hostap_80211_rx.c"
99#include "hostap_80211_tx.c"
100
101
102struct net_device * hostap_add_interface(struct local_info *local,
103 int type, int rtnl_locked,
104 const char *prefix,
105 const char *name)
106{
107 struct net_device *dev, *mdev;
108 struct hostap_interface *iface;
109 int ret;
110
111 dev = alloc_etherdev(sizeof(struct hostap_interface));
112 if (dev == NULL)
113 return NULL;
114
115 iface = netdev_priv(dev);
116 iface->dev = dev;
117 iface->local = local;
118 iface->type = type;
119 list_add(&iface->list, &local->hostap_interfaces);
120
121 mdev = local->dev;
122 memcpy(dev->dev_addr, mdev->dev_addr, ETH_ALEN);
123 dev->base_addr = mdev->base_addr;
124 dev->irq = mdev->irq;
125 dev->mem_start = mdev->mem_start;
126 dev->mem_end = mdev->mem_end;
127
128 hostap_setup_dev(dev, local, 0);
129 dev->destructor = free_netdev;
130
131 sprintf(dev->name, "%s%s", prefix, name);
132 if (!rtnl_locked)
133 rtnl_lock();
134
135 ret = 0;
136 if (strchr(dev->name, '%'))
137 ret = dev_alloc_name(dev, dev->name);
138
139 SET_NETDEV_DEV(dev, mdev->class_dev.dev);
140 if (ret >= 0)
141 ret = register_netdevice(dev);
142
143 if (!rtnl_locked)
144 rtnl_unlock();
145
146 if (ret < 0) {
147 printk(KERN_WARNING "%s: failed to add new netdevice!\n",
148 dev->name);
149 free_netdev(dev);
150 return NULL;
151 }
152
153 printk(KERN_DEBUG "%s: registered netdevice %s\n",
154 mdev->name, dev->name);
155
156 return dev;
157}
158
159
160void hostap_remove_interface(struct net_device *dev, int rtnl_locked,
161 int remove_from_list)
162{
163 struct hostap_interface *iface;
164
165 if (!dev)
166 return;
167
168 iface = netdev_priv(dev);
169
170 if (remove_from_list) {
171 list_del(&iface->list);
172 }
173
174 if (dev == iface->local->ddev)
175 iface->local->ddev = NULL;
176 else if (dev == iface->local->apdev)
177 iface->local->apdev = NULL;
178 else if (dev == iface->local->stadev)
179 iface->local->stadev = NULL;
180
181 if (rtnl_locked)
182 unregister_netdevice(dev);
183 else
184 unregister_netdev(dev);
185
186 /* dev->destructor = free_netdev() will free the device data, including
187 * private data, when removing the device */
188}
189
190
191static inline int prism2_wds_special_addr(u8 *addr)
192{
193 if (addr[0] || addr[1] || addr[2] || addr[3] || addr[4] || addr[5])
194 return 0;
195
196 return 1;
197}
198
199
200static int prism2_wds_add(local_info_t *local, u8 *remote_addr,
201 int rtnl_locked)
202{
203 struct net_device *dev;
204 struct list_head *ptr;
205 struct hostap_interface *iface, *empty, *match;
206
207 empty = match = NULL;
208 read_lock_bh(&local->iface_lock);
209 list_for_each(ptr, &local->hostap_interfaces) {
210 iface = list_entry(ptr, struct hostap_interface, list);
211 if (iface->type != HOSTAP_INTERFACE_WDS)
212 continue;
213
214 if (prism2_wds_special_addr(iface->u.wds.remote_addr))
215 empty = iface;
216 else if (memcmp(iface->u.wds.remote_addr, remote_addr,
217 ETH_ALEN) == 0) {
218 match = iface;
219 break;
220 }
221 }
222 if (!match && empty && !prism2_wds_special_addr(remote_addr)) {
223 /* take pre-allocated entry into use */
224 memcpy(empty->u.wds.remote_addr, remote_addr, ETH_ALEN);
225 read_unlock_bh(&local->iface_lock);
226 printk(KERN_DEBUG "%s: using pre-allocated WDS netdevice %s\n",
227 local->dev->name, empty->dev->name);
228 return 0;
229 }
230 read_unlock_bh(&local->iface_lock);
231
232 if (!prism2_wds_special_addr(remote_addr)) {
233 if (match)
234 return -EEXIST;
235 hostap_add_sta(local->ap, remote_addr);
236 }
237
238 if (local->wds_connections >= local->wds_max_connections)
239 return -ENOBUFS;
240
241 /* verify that there is room for wds# postfix in the interface name */
242 if (strlen(local->dev->name) > IFNAMSIZ - 5) {
243 printk(KERN_DEBUG "'%s' too long base device name\n",
244 local->dev->name);
245 return -EINVAL;
246 }
247
248 dev = hostap_add_interface(local, HOSTAP_INTERFACE_WDS, rtnl_locked,
249 local->ddev->name, "wds%d");
250 if (dev == NULL)
251 return -ENOMEM;
252
253 iface = netdev_priv(dev);
254 memcpy(iface->u.wds.remote_addr, remote_addr, ETH_ALEN);
255
256 local->wds_connections++;
257
258 return 0;
259}
260
261
262static int prism2_wds_del(local_info_t *local, u8 *remote_addr,
263 int rtnl_locked, int do_not_remove)
264{
265 unsigned long flags;
266 struct list_head *ptr;
267 struct hostap_interface *iface, *selected = NULL;
268
269 write_lock_irqsave(&local->iface_lock, flags);
270 list_for_each(ptr, &local->hostap_interfaces) {
271 iface = list_entry(ptr, struct hostap_interface, list);
272 if (iface->type != HOSTAP_INTERFACE_WDS)
273 continue;
274
275 if (memcmp(iface->u.wds.remote_addr, remote_addr,
276 ETH_ALEN) == 0) {
277 selected = iface;
278 break;
279 }
280 }
281 if (selected && !do_not_remove)
282 list_del(&selected->list);
283 write_unlock_irqrestore(&local->iface_lock, flags);
284
285 if (selected) {
286 if (do_not_remove)
287 memset(selected->u.wds.remote_addr, 0, ETH_ALEN);
288 else {
289 hostap_remove_interface(selected->dev, rtnl_locked, 0);
290 local->wds_connections--;
291 }
292 }
293
294 return selected ? 0 : -ENODEV;
295}
296
297
298u16 hostap_tx_callback_register(local_info_t *local,
299 void (*func)(struct sk_buff *, int ok, void *),
300 void *data)
301{
302 unsigned long flags;
303 struct hostap_tx_callback_info *entry;
304
305 entry = (struct hostap_tx_callback_info *) kmalloc(sizeof(*entry),
306 GFP_ATOMIC);
307 if (entry == NULL)
308 return 0;
309
310 entry->func = func;
311 entry->data = data;
312
313 spin_lock_irqsave(&local->lock, flags);
314 entry->idx = local->tx_callback ? local->tx_callback->idx + 1 : 1;
315 entry->next = local->tx_callback;
316 local->tx_callback = entry;
317 spin_unlock_irqrestore(&local->lock, flags);
318
319 return entry->idx;
320}
321
322
323int hostap_tx_callback_unregister(local_info_t *local, u16 idx)
324{
325 unsigned long flags;
326 struct hostap_tx_callback_info *cb, *prev = NULL;
327
328 spin_lock_irqsave(&local->lock, flags);
329 cb = local->tx_callback;
330 while (cb != NULL && cb->idx != idx) {
331 prev = cb;
332 cb = cb->next;
333 }
334 if (cb) {
335 if (prev == NULL)
336 local->tx_callback = cb->next;
337 else
338 prev->next = cb->next;
339 kfree(cb);
340 }
341 spin_unlock_irqrestore(&local->lock, flags);
342
343 return cb ? 0 : -1;
344}
345
346
347/* val is in host byte order */
348int hostap_set_word(struct net_device *dev, int rid, u16 val)
349{
350 struct hostap_interface *iface;
351 u16 tmp = cpu_to_le16(val);
352 iface = netdev_priv(dev);
353 return iface->local->func->set_rid(dev, rid, &tmp, 2);
354}
355
356
357int hostap_set_string(struct net_device *dev, int rid, const char *val)
358{
359 struct hostap_interface *iface;
360 char buf[MAX_SSID_LEN + 2];
361 int len;
362
363 iface = netdev_priv(dev);
364 len = strlen(val);
365 if (len > MAX_SSID_LEN)
366 return -1;
367 memset(buf, 0, sizeof(buf));
368 buf[0] = len; /* little endian 16 bit word */
369 memcpy(buf + 2, val, len);
370
371 return iface->local->func->set_rid(dev, rid, &buf, MAX_SSID_LEN + 2);
372}
373
374
375u16 hostap_get_porttype(local_info_t *local)
376{
377 if (local->iw_mode == IW_MODE_ADHOC && local->pseudo_adhoc)
378 return HFA384X_PORTTYPE_PSEUDO_IBSS;
379 if (local->iw_mode == IW_MODE_ADHOC)
380 return HFA384X_PORTTYPE_IBSS;
381 if (local->iw_mode == IW_MODE_INFRA)
382 return HFA384X_PORTTYPE_BSS;
383 if (local->iw_mode == IW_MODE_REPEAT)
384 return HFA384X_PORTTYPE_WDS;
385 if (local->iw_mode == IW_MODE_MONITOR)
386 return HFA384X_PORTTYPE_PSEUDO_IBSS;
387 return HFA384X_PORTTYPE_HOSTAP;
388}
389
390
391int hostap_set_encryption(local_info_t *local)
392{
393 u16 val, old_val;
394 int i, keylen, len, idx;
395 char keybuf[WEP_KEY_LEN + 1];
396 enum { NONE, WEP, OTHER } encrypt_type;
397
398 idx = local->tx_keyidx;
399 if (local->crypt[idx] == NULL || local->crypt[idx]->ops == NULL)
400 encrypt_type = NONE;
401 else if (strcmp(local->crypt[idx]->ops->name, "WEP") == 0)
402 encrypt_type = WEP;
403 else
404 encrypt_type = OTHER;
405
406 if (local->func->get_rid(local->dev, HFA384X_RID_CNFWEPFLAGS, &val, 2,
407 1) < 0) {
408 printk(KERN_DEBUG "Could not read current WEP flags.\n");
409 goto fail;
410 }
411 le16_to_cpus(&val);
412 old_val = val;
413
414 if (encrypt_type != NONE || local->privacy_invoked)
415 val |= HFA384X_WEPFLAGS_PRIVACYINVOKED;
416 else
417 val &= ~HFA384X_WEPFLAGS_PRIVACYINVOKED;
418
419 if (local->open_wep || encrypt_type == NONE ||
420 ((local->ieee_802_1x || local->wpa) && local->host_decrypt))
421 val &= ~HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
422 else
423 val |= HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED;
424
425 if ((encrypt_type != NONE || local->privacy_invoked) &&
426 (encrypt_type == OTHER || local->host_encrypt))
427 val |= HFA384X_WEPFLAGS_HOSTENCRYPT;
428 else
429 val &= ~HFA384X_WEPFLAGS_HOSTENCRYPT;
430 if ((encrypt_type != NONE || local->privacy_invoked) &&
431 (encrypt_type == OTHER || local->host_decrypt))
432 val |= HFA384X_WEPFLAGS_HOSTDECRYPT;
433 else
434 val &= ~HFA384X_WEPFLAGS_HOSTDECRYPT;
435
436 if (val != old_val &&
437 hostap_set_word(local->dev, HFA384X_RID_CNFWEPFLAGS, val)) {
438 printk(KERN_DEBUG "Could not write new WEP flags (0x%x)\n",
439 val);
440 goto fail;
441 }
442
443 if (encrypt_type != WEP)
444 return 0;
445
446 /* 104-bit support seems to require that all the keys are set to the
447 * same keylen */
448 keylen = 6; /* first 5 octets */
449 len = local->crypt[idx]->ops->get_key(keybuf, sizeof(keybuf),
450 NULL, local->crypt[idx]->priv);
451 if (idx >= 0 && idx < WEP_KEYS && len > 5)
452 keylen = WEP_KEY_LEN + 1; /* first 13 octets */
453
454 for (i = 0; i < WEP_KEYS; i++) {
455 memset(keybuf, 0, sizeof(keybuf));
456 if (local->crypt[i]) {
457 (void) local->crypt[i]->ops->get_key(
458 keybuf, sizeof(keybuf),
459 NULL, local->crypt[i]->priv);
460 }
461 if (local->func->set_rid(local->dev,
462 HFA384X_RID_CNFDEFAULTKEY0 + i,
463 keybuf, keylen)) {
464 printk(KERN_DEBUG "Could not set key %d (len=%d)\n",
465 i, keylen);
466 goto fail;
467 }
468 }
469 if (hostap_set_word(local->dev, HFA384X_RID_CNFWEPDEFAULTKEYID, idx)) {
470 printk(KERN_DEBUG "Could not set default keyid %d\n", idx);
471 goto fail;
472 }
473
474 return 0;
475
476 fail:
477 printk(KERN_DEBUG "%s: encryption setup failed\n", local->dev->name);
478 return -1;
479}
480
481
482int hostap_set_antsel(local_info_t *local)
483{
484 u16 val;
485 int ret = 0;
486
487 if (local->antsel_tx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
488 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
489 HFA386X_CR_TX_CONFIGURE,
490 NULL, &val) == 0) {
491 val &= ~(BIT(2) | BIT(1));
492 switch (local->antsel_tx) {
493 case HOSTAP_ANTSEL_DIVERSITY:
494 val |= BIT(1);
495 break;
496 case HOSTAP_ANTSEL_LOW:
497 break;
498 case HOSTAP_ANTSEL_HIGH:
499 val |= BIT(2);
500 break;
501 }
502
503 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
504 HFA386X_CR_TX_CONFIGURE, &val, NULL)) {
505 printk(KERN_INFO "%s: setting TX AntSel failed\n",
506 local->dev->name);
507 ret = -1;
508 }
509 }
510
511 if (local->antsel_rx != HOSTAP_ANTSEL_DO_NOT_TOUCH &&
512 local->func->cmd(local->dev, HFA384X_CMDCODE_READMIF,
513 HFA386X_CR_RX_CONFIGURE,
514 NULL, &val) == 0) {
515 val &= ~(BIT(1) | BIT(0));
516 switch (local->antsel_rx) {
517 case HOSTAP_ANTSEL_DIVERSITY:
518 break;
519 case HOSTAP_ANTSEL_LOW:
520 val |= BIT(0);
521 break;
522 case HOSTAP_ANTSEL_HIGH:
523 val |= BIT(0) | BIT(1);
524 break;
525 }
526
527 if (local->func->cmd(local->dev, HFA384X_CMDCODE_WRITEMIF,
528 HFA386X_CR_RX_CONFIGURE, &val, NULL)) {
529 printk(KERN_INFO "%s: setting RX AntSel failed\n",
530 local->dev->name);
531 ret = -1;
532 }
533 }
534
535 return ret;
536}
537
538
539int hostap_set_roaming(local_info_t *local)
540{
541 u16 val;
542
543 switch (local->host_roaming) {
544 case 1:
545 val = HFA384X_ROAMING_HOST;
546 break;
547 case 2:
548 val = HFA384X_ROAMING_DISABLED;
549 break;
550 case 0:
551 default:
552 val = HFA384X_ROAMING_FIRMWARE;
553 break;
554 }
555
556 return hostap_set_word(local->dev, HFA384X_RID_CNFROAMINGMODE, val);
557}
558
559
560int hostap_set_auth_algs(local_info_t *local)
561{
562 int val = local->auth_algs;
563 /* At least STA f/w v0.6.2 seems to have issues with cnfAuthentication
564 * set to include both Open and Shared Key flags. It tries to use
565 * Shared Key authentication in that case even if WEP keys are not
566 * configured.. STA f/w v0.7.6 is able to handle such configuration,
567 * but it is unknown when this was fixed between 0.6.2 .. 0.7.6. */
568 if (local->sta_fw_ver < PRISM2_FW_VER(0,7,0) &&
569 val != PRISM2_AUTH_OPEN && val != PRISM2_AUTH_SHARED_KEY)
570 val = PRISM2_AUTH_OPEN;
571
572 if (hostap_set_word(local->dev, HFA384X_RID_CNFAUTHENTICATION, val)) {
573 printk(KERN_INFO "%s: cnfAuthentication setting to 0x%x "
574 "failed\n", local->dev->name, local->auth_algs);
575 return -EINVAL;
576 }
577
578 return 0;
579}
580
581
582void hostap_dump_rx_header(const char *name, const struct hfa384x_rx_frame *rx)
583{
584 u16 status, fc;
585
586 status = __le16_to_cpu(rx->status);
587
588 printk(KERN_DEBUG "%s: RX status=0x%04x (port=%d, type=%d, "
589 "fcserr=%d) silence=%d signal=%d rate=%d rxflow=%d; "
590 "jiffies=%ld\n",
591 name, status, (status >> 8) & 0x07, status >> 13, status & 1,
592 rx->silence, rx->signal, rx->rate, rx->rxflow, jiffies);
593
594 fc = __le16_to_cpu(rx->frame_control);
595 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
596 "data_len=%d%s%s\n",
597 fc, HOSTAP_FC_GET_TYPE(fc), HOSTAP_FC_GET_STYPE(fc),
598 __le16_to_cpu(rx->duration_id), __le16_to_cpu(rx->seq_ctrl),
599 __le16_to_cpu(rx->data_len),
600 fc & WLAN_FC_TODS ? " [ToDS]" : "",
601 fc & WLAN_FC_FROMDS ? " [FromDS]" : "");
602
603 printk(KERN_DEBUG " A1=" MACSTR " A2=" MACSTR " A3=" MACSTR " A4="
604 MACSTR "\n",
605 MAC2STR(rx->addr1), MAC2STR(rx->addr2), MAC2STR(rx->addr3),
606 MAC2STR(rx->addr4));
607
608 printk(KERN_DEBUG " dst=" MACSTR " src=" MACSTR " len=%d\n",
609 MAC2STR(rx->dst_addr), MAC2STR(rx->src_addr),
610 __be16_to_cpu(rx->len));
611}
612
613
614void hostap_dump_tx_header(const char *name, const struct hfa384x_tx_frame *tx)
615{
616 u16 fc;
617
618 printk(KERN_DEBUG "%s: TX status=0x%04x retry_count=%d tx_rate=%d "
619 "tx_control=0x%04x; jiffies=%ld\n",
620 name, __le16_to_cpu(tx->status), tx->retry_count, tx->tx_rate,
621 __le16_to_cpu(tx->tx_control), jiffies);
622
623 fc = __le16_to_cpu(tx->frame_control);
624 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d) dur=0x%04x seq=0x%04x "
625 "data_len=%d%s%s\n",
626 fc, HOSTAP_FC_GET_TYPE(fc), HOSTAP_FC_GET_STYPE(fc),
627 __le16_to_cpu(tx->duration_id), __le16_to_cpu(tx->seq_ctrl),
628 __le16_to_cpu(tx->data_len),
629 fc & WLAN_FC_TODS ? " [ToDS]" : "",
630 fc & WLAN_FC_FROMDS ? " [FromDS]" : "");
631
632 printk(KERN_DEBUG " A1=" MACSTR " A2=" MACSTR " A3=" MACSTR " A4="
633 MACSTR "\n",
634 MAC2STR(tx->addr1), MAC2STR(tx->addr2), MAC2STR(tx->addr3),
635 MAC2STR(tx->addr4));
636
637 printk(KERN_DEBUG " dst=" MACSTR " src=" MACSTR " len=%d\n",
638 MAC2STR(tx->dst_addr), MAC2STR(tx->src_addr),
639 __be16_to_cpu(tx->len));
640}
641
642
643int hostap_80211_header_parse(struct sk_buff *skb, unsigned char *haddr)
644{
645 memcpy(haddr, skb->mac.raw + 10, ETH_ALEN); /* addr2 */
646 return ETH_ALEN;
647}
648
649
650int hostap_80211_prism_header_parse(struct sk_buff *skb, unsigned char *haddr)
651{
652 if (*(u32 *)skb->mac.raw == LWNG_CAP_DID_BASE) {
653 memcpy(haddr, skb->mac.raw +
654 sizeof(struct linux_wlan_ng_prism_hdr) + 10,
655 ETH_ALEN); /* addr2 */
656 } else { /* (*(u32 *)skb->mac.raw == htonl(LWNG_CAPHDR_VERSION)) */
657 memcpy(haddr, skb->mac.raw +
658 sizeof(struct linux_wlan_ng_cap_hdr) + 10,
659 ETH_ALEN); /* addr2 */
660 }
661 return ETH_ALEN;
662}
663
664
665int hostap_80211_get_hdrlen(u16 fc)
666{
667 int hdrlen = 24;
668
669 switch (HOSTAP_FC_GET_TYPE(fc)) {
670 case WLAN_FC_TYPE_DATA:
671 if ((fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS))
672 hdrlen = 30; /* Addr4 */
673 break;
674 case WLAN_FC_TYPE_CTRL:
675 switch (HOSTAP_FC_GET_STYPE(fc)) {
676 case WLAN_FC_STYPE_CTS:
677 case WLAN_FC_STYPE_ACK:
678 hdrlen = 10;
679 break;
680 default:
681 hdrlen = 16;
682 break;
683 }
684 break;
685 }
686
687 return hdrlen;
688}
689
690
691struct net_device_stats *hostap_get_stats(struct net_device *dev)
692{
693 struct hostap_interface *iface;
694 iface = netdev_priv(dev);
695 return &iface->stats;
696}
697
698
699static int prism2_close(struct net_device *dev)
700{
701 struct hostap_interface *iface;
702 local_info_t *local;
703
704 PDEBUG(DEBUG_FLOW, "%s: prism2_close\n", dev->name);
705
706 iface = netdev_priv(dev);
707 local = iface->local;
708
709 if (dev == local->ddev) {
710 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
711 }
712#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
713 if (!local->hostapd && dev == local->dev &&
714 (!local->func->card_present || local->func->card_present(local)) &&
715 local->hw_ready && local->ap && local->iw_mode == IW_MODE_MASTER)
716 hostap_deauth_all_stas(dev, local->ap, 1);
717#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
718
719 if (local->func->dev_close && local->func->dev_close(local))
720 return 0;
721
722 if (dev == local->dev) {
723 local->func->hw_shutdown(dev, HOSTAP_HW_ENABLE_CMDCOMPL);
724 }
725
726 if (netif_running(dev)) {
727 netif_stop_queue(dev);
728 netif_device_detach(dev);
729 }
730
731 flush_scheduled_work();
732
733 module_put(local->hw_module);
734
735 local->num_dev_open--;
736
737 if (dev != local->dev && local->dev->flags & IFF_UP &&
738 local->master_dev_auto_open && local->num_dev_open == 1) {
739 /* Close master radio interface automatically if it was also
740 * opened automatically and we are now closing the last
741 * remaining non-master device. */
742 dev_close(local->dev);
743 }
744
745 return 0;
746}
747
748
749static int prism2_open(struct net_device *dev)
750{
751 struct hostap_interface *iface;
752 local_info_t *local;
753
754 PDEBUG(DEBUG_FLOW, "%s: prism2_open\n", dev->name);
755
756 iface = netdev_priv(dev);
757 local = iface->local;
758
759 if (local->no_pri) {
760 printk(KERN_DEBUG "%s: could not set interface UP - no PRI "
761 "f/w\n", dev->name);
762 return 1;
763 }
764
765 if ((local->func->card_present && !local->func->card_present(local)) ||
766 local->hw_downloading)
767 return -ENODEV;
768
769 if (local->func->dev_open && local->func->dev_open(local))
770 return 1;
771
772 if (!try_module_get(local->hw_module))
773 return -ENODEV;
774 local->num_dev_open++;
775
776 if (!local->dev_enabled && local->func->hw_enable(dev, 1)) {
777 printk(KERN_WARNING "%s: could not enable MAC port\n",
778 dev->name);
779 prism2_close(dev);
780 return 1;
781 }
782 if (!local->dev_enabled)
783 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
784 local->dev_enabled = 1;
785
786 if (dev != local->dev && !(local->dev->flags & IFF_UP)) {
787 /* Master radio interface is needed for all operation, so open
788 * it automatically when any virtual net_device is opened. */
789 local->master_dev_auto_open = 1;
790 dev_open(local->dev);
791 }
792
793 netif_device_attach(dev);
794 netif_start_queue(dev);
795
796 return 0;
797}
798
799
800static int prism2_set_mac_address(struct net_device *dev, void *p)
801{
802 struct hostap_interface *iface;
803 local_info_t *local;
804 struct list_head *ptr;
805 struct sockaddr *addr = p;
806
807 iface = netdev_priv(dev);
808 local = iface->local;
809
810 if (local->func->set_rid(dev, HFA384X_RID_CNFOWNMACADDR, addr->sa_data,
811 ETH_ALEN) < 0 || local->func->reset_port(dev))
812 return -EINVAL;
813
814 read_lock_bh(&local->iface_lock);
815 list_for_each(ptr, &local->hostap_interfaces) {
816 iface = list_entry(ptr, struct hostap_interface, list);
817 memcpy(iface->dev->dev_addr, addr->sa_data, ETH_ALEN);
818 }
819 memcpy(local->dev->dev_addr, addr->sa_data, ETH_ALEN);
820 read_unlock_bh(&local->iface_lock);
821
822 return 0;
823}
824
825
826/* TODO: to be further implemented as soon as Prism2 fully supports
827 * GroupAddresses and correct documentation is available */
828void hostap_set_multicast_list_queue(void *data)
829{
830 struct net_device *dev = (struct net_device *) data;
831 struct hostap_interface *iface;
832 local_info_t *local;
833
834 iface = netdev_priv(dev);
835 local = iface->local;
836 if (hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
837 local->is_promisc)) {
838 printk(KERN_INFO "%s: %sabling promiscuous mode failed\n",
839 dev->name, local->is_promisc ? "en" : "dis");
840 }
841}
842
843
844static void hostap_set_multicast_list(struct net_device *dev)
845{
846#if 0
847 /* FIX: promiscuous mode seems to be causing a lot of problems with
848 * some station firmware versions (FCSErr frames, invalid MACPort, etc.
849 * corrupted incoming frames). This code is now commented out while the
850 * problems are investigated. */
851 struct hostap_interface *iface;
852 local_info_t *local;
853
854 iface = netdev_priv(dev);
855 local = iface->local;
856 if ((dev->flags & IFF_ALLMULTI) || (dev->flags & IFF_PROMISC)) {
857 local->is_promisc = 1;
858 } else {
859 local->is_promisc = 0;
860 }
861
862 schedule_work(&local->set_multicast_list_queue);
863#endif
864}
865
866
867static int prism2_change_mtu(struct net_device *dev, int new_mtu)
868{
869 if (new_mtu < PRISM2_MIN_MTU || new_mtu > PRISM2_MAX_MTU)
870 return -EINVAL;
871
872 dev->mtu = new_mtu;
873 return 0;
874}
875
876
877static void prism2_tx_timeout(struct net_device *dev)
878{
879 struct hostap_interface *iface;
880 local_info_t *local;
881 struct hfa384x_regs regs;
882
883 iface = netdev_priv(dev);
884 local = iface->local;
885
886 printk(KERN_WARNING "%s Tx timed out! Resetting card\n", dev->name);
887 netif_stop_queue(local->dev);
888
889 local->func->read_regs(dev, &regs);
890 printk(KERN_DEBUG "%s: CMD=%04x EVSTAT=%04x "
891 "OFFSET0=%04x OFFSET1=%04x SWSUPPORT0=%04x\n",
892 dev->name, regs.cmd, regs.evstat, regs.offset0, regs.offset1,
893 regs.swsupport0);
894
895 local->func->schedule_reset(local);
896}
897
898
899void hostap_setup_dev(struct net_device *dev, local_info_t *local,
900 int main_dev)
901{
902 struct hostap_interface *iface;
903
904 iface = netdev_priv(dev);
905 ether_setup(dev);
906
907 /* kernel callbacks */
908 dev->get_stats = hostap_get_stats;
909 if (iface) {
910 /* Currently, we point to the proper spy_data only on
911 * the main_dev. This could be fixed. Jean II */
912 iface->wireless_data.spy_data = &iface->spy_data;
913 dev->wireless_data = &iface->wireless_data;
914 }
915 dev->wireless_handlers =
916 (struct iw_handler_def *) &hostap_iw_handler_def;
917 dev->do_ioctl = hostap_ioctl;
918 dev->open = prism2_open;
919 dev->stop = prism2_close;
920 dev->hard_start_xmit = hostap_data_start_xmit;
921 dev->set_mac_address = prism2_set_mac_address;
922 dev->set_multicast_list = hostap_set_multicast_list;
923 dev->change_mtu = prism2_change_mtu;
924 dev->tx_timeout = prism2_tx_timeout;
925 dev->watchdog_timeo = TX_TIMEOUT;
926
927 dev->mtu = local->mtu;
928 if (!main_dev) {
929 /* use main radio device queue */
930 dev->tx_queue_len = 0;
931 }
932
933 SET_ETHTOOL_OPS(dev, &prism2_ethtool_ops);
934
935 netif_stop_queue(dev);
936}
937
938
939static int hostap_enable_hostapd(local_info_t *local, int rtnl_locked)
940{
941 struct net_device *dev = local->dev;
942
943 if (local->apdev)
944 return -EEXIST;
945
946 printk(KERN_DEBUG "%s: enabling hostapd mode\n", dev->name);
947
948 local->apdev = hostap_add_interface(local, HOSTAP_INTERFACE_AP,
949 rtnl_locked, local->ddev->name,
950 "ap");
951 if (local->apdev == NULL)
952 return -ENOMEM;
953
954 local->apdev->hard_start_xmit = hostap_mgmt_start_xmit;
955 local->apdev->type = ARPHRD_IEEE80211;
956 local->apdev->hard_header_parse = hostap_80211_header_parse;
957
958 return 0;
959}
960
961
962static int hostap_disable_hostapd(local_info_t *local, int rtnl_locked)
963{
964 struct net_device *dev = local->dev;
965
966 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
967
968 hostap_remove_interface(local->apdev, rtnl_locked, 1);
969 local->apdev = NULL;
970
971 return 0;
972}
973
974
975static int hostap_enable_hostapd_sta(local_info_t *local, int rtnl_locked)
976{
977 struct net_device *dev = local->dev;
978
979 if (local->stadev)
980 return -EEXIST;
981
982 printk(KERN_DEBUG "%s: enabling hostapd STA mode\n", dev->name);
983
984 local->stadev = hostap_add_interface(local, HOSTAP_INTERFACE_STA,
985 rtnl_locked, local->ddev->name,
986 "sta");
987 if (local->stadev == NULL)
988 return -ENOMEM;
989
990 return 0;
991}
992
993
994static int hostap_disable_hostapd_sta(local_info_t *local, int rtnl_locked)
995{
996 struct net_device *dev = local->dev;
997
998 printk(KERN_DEBUG "%s: disabling hostapd mode\n", dev->name);
999
1000 hostap_remove_interface(local->stadev, rtnl_locked, 1);
1001 local->stadev = NULL;
1002
1003 return 0;
1004}
1005
1006
1007int hostap_set_hostapd(local_info_t *local, int val, int rtnl_locked)
1008{
1009 int ret;
1010
1011 if (val < 0 || val > 1)
1012 return -EINVAL;
1013
1014 if (local->hostapd == val)
1015 return 0;
1016
1017 if (val) {
1018 ret = hostap_enable_hostapd(local, rtnl_locked);
1019 if (ret == 0)
1020 local->hostapd = 1;
1021 } else {
1022 local->hostapd = 0;
1023 ret = hostap_disable_hostapd(local, rtnl_locked);
1024 if (ret != 0)
1025 local->hostapd = 1;
1026 }
1027
1028 return ret;
1029}
1030
1031
1032int hostap_set_hostapd_sta(local_info_t *local, int val, int rtnl_locked)
1033{
1034 int ret;
1035
1036 if (val < 0 || val > 1)
1037 return -EINVAL;
1038
1039 if (local->hostapd_sta == val)
1040 return 0;
1041
1042 if (val) {
1043 ret = hostap_enable_hostapd_sta(local, rtnl_locked);
1044 if (ret == 0)
1045 local->hostapd_sta = 1;
1046 } else {
1047 local->hostapd_sta = 0;
1048 ret = hostap_disable_hostapd_sta(local, rtnl_locked);
1049 if (ret != 0)
1050 local->hostapd_sta = 1;
1051 }
1052
1053
1054 return ret;
1055}
1056
1057
1058int prism2_update_comms_qual(struct net_device *dev)
1059{
1060 struct hostap_interface *iface;
1061 local_info_t *local;
1062 int ret = 0;
1063 struct hfa384x_comms_quality sq;
1064
1065 iface = netdev_priv(dev);
1066 local = iface->local;
1067 if (!local->sta_fw_ver)
1068 ret = -1;
1069 else if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1070 if (local->func->get_rid(local->dev,
1071 HFA384X_RID_DBMCOMMSQUALITY,
1072 &sq, sizeof(sq), 1) >= 0) {
1073 local->comms_qual = (s16) le16_to_cpu(sq.comm_qual);
1074 local->avg_signal = (s16) le16_to_cpu(sq.signal_level);
1075 local->avg_noise = (s16) le16_to_cpu(sq.noise_level);
1076 local->last_comms_qual_update = jiffies;
1077 } else
1078 ret = -1;
1079 } else {
1080 if (local->func->get_rid(local->dev, HFA384X_RID_COMMSQUALITY,
1081 &sq, sizeof(sq), 1) >= 0) {
1082 local->comms_qual = le16_to_cpu(sq.comm_qual);
1083 local->avg_signal = HFA384X_LEVEL_TO_dBm(
1084 le16_to_cpu(sq.signal_level));
1085 local->avg_noise = HFA384X_LEVEL_TO_dBm(
1086 le16_to_cpu(sq.noise_level));
1087 local->last_comms_qual_update = jiffies;
1088 } else
1089 ret = -1;
1090 }
1091
1092 return ret;
1093}
1094
1095
1096int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u8 stype,
1097 u8 *body, size_t bodylen)
1098{
1099 struct sk_buff *skb;
1100 struct hostap_ieee80211_mgmt *mgmt;
1101 struct hostap_skb_tx_data *meta;
1102 struct net_device *dev = local->dev;
1103
1104 skb = dev_alloc_skb(IEEE80211_MGMT_HDR_LEN + bodylen);
1105 if (skb == NULL)
1106 return -ENOMEM;
1107
1108 mgmt = (struct hostap_ieee80211_mgmt *)
1109 skb_put(skb, IEEE80211_MGMT_HDR_LEN);
1110 memset(mgmt, 0, IEEE80211_MGMT_HDR_LEN);
1111 mgmt->frame_control =
1112 cpu_to_le16((WLAN_FC_TYPE_MGMT << 2) | (stype << 4));
1113 memcpy(mgmt->da, dst, ETH_ALEN);
1114 memcpy(mgmt->sa, dev->dev_addr, ETH_ALEN);
1115 memcpy(mgmt->bssid, dst, ETH_ALEN);
1116 if (body)
1117 memcpy(skb_put(skb, bodylen), body, bodylen);
1118
1119 meta = (struct hostap_skb_tx_data *) skb->cb;
1120 memset(meta, 0, sizeof(*meta));
1121 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
1122 meta->iface = netdev_priv(dev);
1123
1124 skb->dev = dev;
1125 skb->mac.raw = skb->nh.raw = skb->data;
1126 dev_queue_xmit(skb);
1127
1128 return 0;
1129}
1130
1131
1132int prism2_sta_deauth(local_info_t *local, u16 reason)
1133{
1134 union iwreq_data wrqu;
1135 int ret;
1136
1137 if (local->iw_mode != IW_MODE_INFRA ||
1138 memcmp(local->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) == 0 ||
1139 memcmp(local->bssid, "\x44\x44\x44\x44\x44\x44", ETH_ALEN) == 0)
1140 return 0;
1141
1142 reason = cpu_to_le16(reason);
1143 ret = prism2_sta_send_mgmt(local, local->bssid, WLAN_FC_STYPE_DEAUTH,
1144 (u8 *) &reason, 2);
1145 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
1146 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
1147 return ret;
1148}
1149
1150
1151struct proc_dir_entry *hostap_proc;
1152
1153static int __init hostap_init(void)
1154{
1155 if (proc_net != NULL) {
1156 hostap_proc = proc_mkdir("hostap", proc_net);
1157 if (!hostap_proc)
1158 printk(KERN_WARNING "Failed to mkdir "
1159 "/proc/net/hostap\n");
1160 } else
1161 hostap_proc = NULL;
1162
1163 return 0;
1164}
1165
1166
1167static void __exit hostap_exit(void)
1168{
1169 if (hostap_proc != NULL) {
1170 hostap_proc = NULL;
1171 remove_proc_entry("hostap", proc_net);
1172 }
1173}
1174
1175
1176EXPORT_SYMBOL(hostap_set_word);
1177EXPORT_SYMBOL(hostap_set_string);
1178EXPORT_SYMBOL(hostap_get_porttype);
1179EXPORT_SYMBOL(hostap_set_encryption);
1180EXPORT_SYMBOL(hostap_set_antsel);
1181EXPORT_SYMBOL(hostap_set_roaming);
1182EXPORT_SYMBOL(hostap_set_auth_algs);
1183EXPORT_SYMBOL(hostap_dump_rx_header);
1184EXPORT_SYMBOL(hostap_dump_tx_header);
1185EXPORT_SYMBOL(hostap_80211_header_parse);
1186EXPORT_SYMBOL(hostap_80211_prism_header_parse);
1187EXPORT_SYMBOL(hostap_80211_get_hdrlen);
1188EXPORT_SYMBOL(hostap_get_stats);
1189EXPORT_SYMBOL(hostap_setup_dev);
1190EXPORT_SYMBOL(hostap_proc);
1191EXPORT_SYMBOL(hostap_set_multicast_list_queue);
1192EXPORT_SYMBOL(hostap_set_hostapd);
1193EXPORT_SYMBOL(hostap_set_hostapd_sta);
1194EXPORT_SYMBOL(hostap_add_interface);
1195EXPORT_SYMBOL(hostap_remove_interface);
1196EXPORT_SYMBOL(prism2_update_comms_qual);
1197
1198module_init(hostap_init);
1199module_exit(hostap_exit);
diff --git a/drivers/net/wireless/hostap/hostap.h b/drivers/net/wireless/hostap/hostap.h
new file mode 100644
index 000000000000..2ddcf5fc59c3
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap.h
@@ -0,0 +1,57 @@
1#ifndef HOSTAP_H
2#define HOSTAP_H
3
4/* hostap.c */
5
6extern struct proc_dir_entry *hostap_proc;
7
8u16 hostap_tx_callback_register(local_info_t *local,
9 void (*func)(struct sk_buff *, int ok, void *),
10 void *data);
11int hostap_tx_callback_unregister(local_info_t *local, u16 idx);
12int hostap_set_word(struct net_device *dev, int rid, u16 val);
13int hostap_set_string(struct net_device *dev, int rid, const char *val);
14u16 hostap_get_porttype(local_info_t *local);
15int hostap_set_encryption(local_info_t *local);
16int hostap_set_antsel(local_info_t *local);
17int hostap_set_roaming(local_info_t *local);
18int hostap_set_auth_algs(local_info_t *local);
19void hostap_dump_rx_header(const char *name,
20 const struct hfa384x_rx_frame *rx);
21void hostap_dump_tx_header(const char *name,
22 const struct hfa384x_tx_frame *tx);
23int hostap_80211_header_parse(struct sk_buff *skb, unsigned char *haddr);
24int hostap_80211_prism_header_parse(struct sk_buff *skb, unsigned char *haddr);
25int hostap_80211_get_hdrlen(u16 fc);
26struct net_device_stats *hostap_get_stats(struct net_device *dev);
27void hostap_setup_dev(struct net_device *dev, local_info_t *local,
28 int main_dev);
29void hostap_set_multicast_list_queue(void *data);
30int hostap_set_hostapd(local_info_t *local, int val, int rtnl_locked);
31int hostap_set_hostapd_sta(local_info_t *local, int val, int rtnl_locked);
32void hostap_cleanup(local_info_t *local);
33void hostap_cleanup_handler(void *data);
34struct net_device * hostap_add_interface(struct local_info *local,
35 int type, int rtnl_locked,
36 const char *prefix, const char *name);
37void hostap_remove_interface(struct net_device *dev, int rtnl_locked,
38 int remove_from_list);
39int prism2_update_comms_qual(struct net_device *dev);
40int prism2_sta_send_mgmt(local_info_t *local, u8 *dst, u8 stype,
41 u8 *body, size_t bodylen);
42int prism2_sta_deauth(local_info_t *local, u16 reason);
43
44
45/* hostap_proc.c */
46
47void hostap_init_proc(local_info_t *local);
48void hostap_remove_proc(local_info_t *local);
49
50
51/* hostap_info.c */
52
53void hostap_info_init(local_info_t *local);
54void hostap_info_process(local_info_t *local, struct sk_buff *skb);
55
56
57#endif /* HOSTAP_H */
diff --git a/drivers/net/wireless/hostap/hostap_80211.h b/drivers/net/wireless/hostap/hostap_80211.h
new file mode 100644
index 000000000000..f3ad3445c72e
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_80211.h
@@ -0,0 +1,107 @@
1#ifndef HOSTAP_80211_H
2#define HOSTAP_80211_H
3
4struct hostap_ieee80211_hdr {
5 u16 frame_control;
6 u16 duration_id;
7 u8 addr1[6];
8 u8 addr2[6];
9 u8 addr3[6];
10 u16 seq_ctrl;
11 u8 addr4[6];
12} __attribute__ ((packed));
13
14
15struct hostap_ieee80211_mgmt {
16 u16 frame_control;
17 u16 duration;
18 u8 da[6];
19 u8 sa[6];
20 u8 bssid[6];
21 u16 seq_ctrl;
22 union {
23 struct {
24 u16 auth_alg;
25 u16 auth_transaction;
26 u16 status_code;
27 /* possibly followed by Challenge text */
28 u8 variable[0];
29 } __attribute__ ((packed)) auth;
30 struct {
31 u16 reason_code;
32 } __attribute__ ((packed)) deauth;
33 struct {
34 u16 capab_info;
35 u16 listen_interval;
36 /* followed by SSID and Supported rates */
37 u8 variable[0];
38 } __attribute__ ((packed)) assoc_req;
39 struct {
40 u16 capab_info;
41 u16 status_code;
42 u16 aid;
43 /* followed by Supported rates */
44 u8 variable[0];
45 } __attribute__ ((packed)) assoc_resp, reassoc_resp;
46 struct {
47 u16 capab_info;
48 u16 listen_interval;
49 u8 current_ap[6];
50 /* followed by SSID and Supported rates */
51 u8 variable[0];
52 } __attribute__ ((packed)) reassoc_req;
53 struct {
54 u16 reason_code;
55 } __attribute__ ((packed)) disassoc;
56 struct {
57 } __attribute__ ((packed)) probe_req;
58 struct {
59 u8 timestamp[8];
60 u16 beacon_int;
61 u16 capab_info;
62 /* followed by some of SSID, Supported rates,
63 * FH Params, DS Params, CF Params, IBSS Params, TIM */
64 u8 variable[0];
65 } __attribute__ ((packed)) beacon, probe_resp;
66 } u;
67} __attribute__ ((packed));
68
69
70#define IEEE80211_MGMT_HDR_LEN 24
71#define IEEE80211_DATA_HDR3_LEN 24
72#define IEEE80211_DATA_HDR4_LEN 30
73
74
75struct hostap_80211_rx_status {
76 u32 mac_time;
77 u8 signal;
78 u8 noise;
79 u16 rate; /* in 100 kbps */
80};
81
82
83void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
84 struct hostap_80211_rx_status *rx_stats);
85
86
87/* prism2_rx_80211 'type' argument */
88enum {
89 PRISM2_RX_MONITOR, PRISM2_RX_MGMT, PRISM2_RX_NON_ASSOC,
90 PRISM2_RX_NULLFUNC_ACK
91};
92
93int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
94 struct hostap_80211_rx_status *rx_stats, int type);
95void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
96 struct hostap_80211_rx_status *rx_stats);
97void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
98 struct hostap_80211_rx_status *rx_stats);
99
100void hostap_dump_tx_80211(const char *name, struct sk_buff *skb);
101int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev);
102int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev);
103struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
104 struct ieee80211_crypt_data *crypt);
105int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev);
106
107#endif /* HOSTAP_80211_H */
diff --git a/drivers/net/wireless/hostap/hostap_80211_rx.c b/drivers/net/wireless/hostap/hostap_80211_rx.c
new file mode 100644
index 000000000000..f4ca1e88f314
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_80211_rx.c
@@ -0,0 +1,1084 @@
1#include <linux/etherdevice.h>
2
3#include "hostap_80211.h"
4#include "hostap.h"
5
6void hostap_dump_rx_80211(const char *name, struct sk_buff *skb,
7 struct hostap_80211_rx_status *rx_stats)
8{
9 struct hostap_ieee80211_hdr *hdr;
10 u16 fc;
11
12 hdr = (struct hostap_ieee80211_hdr *) skb->data;
13
14 printk(KERN_DEBUG "%s: RX signal=%d noise=%d rate=%d len=%d "
15 "jiffies=%ld\n",
16 name, rx_stats->signal, rx_stats->noise, rx_stats->rate,
17 skb->len, jiffies);
18
19 if (skb->len < 2)
20 return;
21
22 fc = le16_to_cpu(hdr->frame_control);
23 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d)%s%s",
24 fc, HOSTAP_FC_GET_TYPE(fc), HOSTAP_FC_GET_STYPE(fc),
25 fc & WLAN_FC_TODS ? " [ToDS]" : "",
26 fc & WLAN_FC_FROMDS ? " [FromDS]" : "");
27
28 if (skb->len < IEEE80211_DATA_HDR3_LEN) {
29 printk("\n");
30 return;
31 }
32
33 printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id),
34 le16_to_cpu(hdr->seq_ctrl));
35
36 printk(KERN_DEBUG " A1=" MACSTR " A2=" MACSTR " A3=" MACSTR,
37 MAC2STR(hdr->addr1), MAC2STR(hdr->addr2), MAC2STR(hdr->addr3));
38 if (skb->len >= 30)
39 printk(" A4=" MACSTR, MAC2STR(hdr->addr4));
40 printk("\n");
41}
42
43
44/* Send RX frame to netif with 802.11 (and possible prism) header.
45 * Called from hardware or software IRQ context. */
46int prism2_rx_80211(struct net_device *dev, struct sk_buff *skb,
47 struct hostap_80211_rx_status *rx_stats, int type)
48{
49 struct hostap_interface *iface;
50 local_info_t *local;
51 int hdrlen, phdrlen, head_need, tail_need;
52 u16 fc;
53 int prism_header, ret;
54 struct hostap_ieee80211_hdr *hdr;
55
56 iface = netdev_priv(dev);
57 local = iface->local;
58 dev->last_rx = jiffies;
59
60 if (dev->type == ARPHRD_IEEE80211_PRISM) {
61 if (local->monitor_type == PRISM2_MONITOR_PRISM) {
62 prism_header = 1;
63 phdrlen = sizeof(struct linux_wlan_ng_prism_hdr);
64 } else { /* local->monitor_type == PRISM2_MONITOR_CAPHDR */
65 prism_header = 2;
66 phdrlen = sizeof(struct linux_wlan_ng_cap_hdr);
67 }
68 } else {
69 prism_header = 0;
70 phdrlen = 0;
71 }
72
73 hdr = (struct hostap_ieee80211_hdr *) skb->data;
74 fc = le16_to_cpu(hdr->frame_control);
75
76 if (type == PRISM2_RX_MGMT && (fc & WLAN_FC_PVER)) {
77 printk(KERN_DEBUG "%s: dropped management frame with header "
78 "version %d\n", dev->name, fc & WLAN_FC_PVER);
79 dev_kfree_skb_any(skb);
80 return 0;
81 }
82
83 hdrlen = hostap_80211_get_hdrlen(fc);
84
85 /* check if there is enough room for extra data; if not, expand skb
86 * buffer to be large enough for the changes */
87 head_need = phdrlen;
88 tail_need = 0;
89#ifdef PRISM2_ADD_BOGUS_CRC
90 tail_need += 4;
91#endif /* PRISM2_ADD_BOGUS_CRC */
92
93 head_need -= skb_headroom(skb);
94 tail_need -= skb_tailroom(skb);
95
96 if (head_need > 0 || tail_need > 0) {
97 if (pskb_expand_head(skb, head_need > 0 ? head_need : 0,
98 tail_need > 0 ? tail_need : 0,
99 GFP_ATOMIC)) {
100 printk(KERN_DEBUG "%s: prism2_rx_80211 failed to "
101 "reallocate skb buffer\n", dev->name);
102 dev_kfree_skb_any(skb);
103 return 0;
104 }
105 }
106
107 /* We now have an skb with enough head and tail room, so just insert
108 * the extra data */
109
110#ifdef PRISM2_ADD_BOGUS_CRC
111 memset(skb_put(skb, 4), 0xff, 4); /* Prism2 strips CRC */
112#endif /* PRISM2_ADD_BOGUS_CRC */
113
114 if (prism_header == 1) {
115 struct linux_wlan_ng_prism_hdr *hdr;
116 hdr = (struct linux_wlan_ng_prism_hdr *)
117 skb_push(skb, phdrlen);
118 memset(hdr, 0, phdrlen);
119 hdr->msgcode = LWNG_CAP_DID_BASE;
120 hdr->msglen = sizeof(*hdr);
121 memcpy(hdr->devname, dev->name, sizeof(hdr->devname));
122#define LWNG_SETVAL(f,i,s,l,d) \
123hdr->f.did = LWNG_CAP_DID_BASE | (i << 12); \
124hdr->f.status = s; hdr->f.len = l; hdr->f.data = d
125 LWNG_SETVAL(hosttime, 1, 0, 4, jiffies);
126 LWNG_SETVAL(mactime, 2, 0, 4, rx_stats->mac_time);
127 LWNG_SETVAL(channel, 3, 1 /* no value */, 4, 0);
128 LWNG_SETVAL(rssi, 4, 1 /* no value */, 4, 0);
129 LWNG_SETVAL(sq, 5, 1 /* no value */, 4, 0);
130 LWNG_SETVAL(signal, 6, 0, 4, rx_stats->signal);
131 LWNG_SETVAL(noise, 7, 0, 4, rx_stats->noise);
132 LWNG_SETVAL(rate, 8, 0, 4, rx_stats->rate / 5);
133 LWNG_SETVAL(istx, 9, 0, 4, 0);
134 LWNG_SETVAL(frmlen, 10, 0, 4, skb->len - phdrlen);
135#undef LWNG_SETVAL
136 } else if (prism_header == 2) {
137 struct linux_wlan_ng_cap_hdr *hdr;
138 hdr = (struct linux_wlan_ng_cap_hdr *)
139 skb_push(skb, phdrlen);
140 memset(hdr, 0, phdrlen);
141 hdr->version = htonl(LWNG_CAPHDR_VERSION);
142 hdr->length = htonl(phdrlen);
143 hdr->mactime = __cpu_to_be64(rx_stats->mac_time);
144 hdr->hosttime = __cpu_to_be64(jiffies);
145 hdr->phytype = htonl(4); /* dss_dot11_b */
146 hdr->channel = htonl(local->channel);
147 hdr->datarate = htonl(rx_stats->rate);
148 hdr->antenna = htonl(0); /* unknown */
149 hdr->priority = htonl(0); /* unknown */
150 hdr->ssi_type = htonl(3); /* raw */
151 hdr->ssi_signal = htonl(rx_stats->signal);
152 hdr->ssi_noise = htonl(rx_stats->noise);
153 hdr->preamble = htonl(0); /* unknown */
154 hdr->encoding = htonl(1); /* cck */
155 }
156
157 ret = skb->len - phdrlen;
158 skb->dev = dev;
159 skb->mac.raw = skb->data;
160 skb_pull(skb, hdrlen);
161 if (prism_header)
162 skb_pull(skb, phdrlen);
163 skb->pkt_type = PACKET_OTHERHOST;
164 skb->protocol = __constant_htons(ETH_P_802_2);
165 memset(skb->cb, 0, sizeof(skb->cb));
166 netif_rx(skb);
167
168 return ret;
169}
170
171
172/* Called only as a tasklet (software IRQ) */
173static void monitor_rx(struct net_device *dev, struct sk_buff *skb,
174 struct hostap_80211_rx_status *rx_stats)
175{
176 struct net_device_stats *stats;
177 int len;
178
179 len = prism2_rx_80211(dev, skb, rx_stats, PRISM2_RX_MONITOR);
180 stats = hostap_get_stats(dev);
181 stats->rx_packets++;
182 stats->rx_bytes += len;
183}
184
185
186/* Called only as a tasklet (software IRQ) */
187static struct prism2_frag_entry *
188prism2_frag_cache_find(local_info_t *local, unsigned int seq,
189 unsigned int frag, u8 *src, u8 *dst)
190{
191 struct prism2_frag_entry *entry;
192 int i;
193
194 for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
195 entry = &local->frag_cache[i];
196 if (entry->skb != NULL &&
197 time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
198 printk(KERN_DEBUG "%s: expiring fragment cache entry "
199 "seq=%u last_frag=%u\n",
200 local->dev->name, entry->seq, entry->last_frag);
201 dev_kfree_skb(entry->skb);
202 entry->skb = NULL;
203 }
204
205 if (entry->skb != NULL && entry->seq == seq &&
206 (entry->last_frag + 1 == frag || frag == -1) &&
207 memcmp(entry->src_addr, src, ETH_ALEN) == 0 &&
208 memcmp(entry->dst_addr, dst, ETH_ALEN) == 0)
209 return entry;
210 }
211
212 return NULL;
213}
214
215
216/* Called only as a tasklet (software IRQ) */
217static struct sk_buff *
218prism2_frag_cache_get(local_info_t *local, struct hostap_ieee80211_hdr *hdr)
219{
220 struct sk_buff *skb = NULL;
221 u16 sc;
222 unsigned int frag, seq;
223 struct prism2_frag_entry *entry;
224
225 sc = le16_to_cpu(hdr->seq_ctrl);
226 frag = WLAN_GET_SEQ_FRAG(sc);
227 seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
228
229 if (frag == 0) {
230 /* Reserve enough space to fit maximum frame length */
231 skb = dev_alloc_skb(local->dev->mtu +
232 sizeof(struct hostap_ieee80211_hdr) +
233 8 /* LLC */ +
234 2 /* alignment */ +
235 8 /* WEP */ + ETH_ALEN /* WDS */);
236 if (skb == NULL)
237 return NULL;
238
239 entry = &local->frag_cache[local->frag_next_idx];
240 local->frag_next_idx++;
241 if (local->frag_next_idx >= PRISM2_FRAG_CACHE_LEN)
242 local->frag_next_idx = 0;
243
244 if (entry->skb != NULL)
245 dev_kfree_skb(entry->skb);
246
247 entry->first_frag_time = jiffies;
248 entry->seq = seq;
249 entry->last_frag = frag;
250 entry->skb = skb;
251 memcpy(entry->src_addr, hdr->addr2, ETH_ALEN);
252 memcpy(entry->dst_addr, hdr->addr1, ETH_ALEN);
253 } else {
254 /* received a fragment of a frame for which the head fragment
255 * should have already been received */
256 entry = prism2_frag_cache_find(local, seq, frag, hdr->addr2,
257 hdr->addr1);
258 if (entry != NULL) {
259 entry->last_frag = frag;
260 skb = entry->skb;
261 }
262 }
263
264 return skb;
265}
266
267
268/* Called only as a tasklet (software IRQ) */
269static int prism2_frag_cache_invalidate(local_info_t *local,
270 struct hostap_ieee80211_hdr *hdr)
271{
272 u16 sc;
273 unsigned int seq;
274 struct prism2_frag_entry *entry;
275
276 sc = le16_to_cpu(hdr->seq_ctrl);
277 seq = WLAN_GET_SEQ_SEQ(sc) >> 4;
278
279 entry = prism2_frag_cache_find(local, seq, -1, hdr->addr2, hdr->addr1);
280
281 if (entry == NULL) {
282 printk(KERN_DEBUG "%s: could not invalidate fragment cache "
283 "entry (seq=%u)\n",
284 local->dev->name, seq);
285 return -1;
286 }
287
288 entry->skb = NULL;
289 return 0;
290}
291
292
293static struct hostap_bss_info *__hostap_get_bss(local_info_t *local, u8 *bssid,
294 u8 *ssid, size_t ssid_len)
295{
296 struct list_head *ptr;
297 struct hostap_bss_info *bss;
298
299 list_for_each(ptr, &local->bss_list) {
300 bss = list_entry(ptr, struct hostap_bss_info, list);
301 if (memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
302 (ssid == NULL ||
303 (ssid_len == bss->ssid_len &&
304 memcmp(ssid, bss->ssid, ssid_len) == 0))) {
305 list_move(&bss->list, &local->bss_list);
306 return bss;
307 }
308 }
309
310 return NULL;
311}
312
313
314static struct hostap_bss_info *__hostap_add_bss(local_info_t *local, u8 *bssid,
315 u8 *ssid, size_t ssid_len)
316{
317 struct hostap_bss_info *bss;
318
319 if (local->num_bss_info >= HOSTAP_MAX_BSS_COUNT) {
320 bss = list_entry(local->bss_list.prev,
321 struct hostap_bss_info, list);
322 list_del(&bss->list);
323 local->num_bss_info--;
324 } else {
325 bss = (struct hostap_bss_info *)
326 kmalloc(sizeof(*bss), GFP_ATOMIC);
327 if (bss == NULL)
328 return NULL;
329 }
330
331 memset(bss, 0, sizeof(*bss));
332 memcpy(bss->bssid, bssid, ETH_ALEN);
333 memcpy(bss->ssid, ssid, ssid_len);
334 bss->ssid_len = ssid_len;
335 local->num_bss_info++;
336 list_add(&bss->list, &local->bss_list);
337 return bss;
338}
339
340
341static void __hostap_expire_bss(local_info_t *local)
342{
343 struct hostap_bss_info *bss;
344
345 while (local->num_bss_info > 0) {
346 bss = list_entry(local->bss_list.prev,
347 struct hostap_bss_info, list);
348 if (!time_after(jiffies, bss->last_update + 60 * HZ))
349 break;
350
351 list_del(&bss->list);
352 local->num_bss_info--;
353 kfree(bss);
354 }
355}
356
357
358/* Both IEEE 802.11 Beacon and Probe Response frames have similar structure, so
359 * the same routine can be used to parse both of them. */
360static void hostap_rx_sta_beacon(local_info_t *local, struct sk_buff *skb,
361 int stype)
362{
363 struct hostap_ieee80211_mgmt *mgmt;
364 int left, chan = 0;
365 u8 *pos;
366 u8 *ssid = NULL, *wpa = NULL, *rsn = NULL;
367 size_t ssid_len = 0, wpa_len = 0, rsn_len = 0;
368 struct hostap_bss_info *bss;
369
370 if (skb->len < IEEE80211_MGMT_HDR_LEN + sizeof(mgmt->u.beacon))
371 return;
372
373 mgmt = (struct hostap_ieee80211_mgmt *) skb->data;
374 pos = mgmt->u.beacon.variable;
375 left = skb->len - (pos - skb->data);
376
377 while (left >= 2) {
378 if (2 + pos[1] > left)
379 return; /* parse failed */
380 switch (*pos) {
381 case WLAN_EID_SSID:
382 ssid = pos + 2;
383 ssid_len = pos[1];
384 break;
385 case WLAN_EID_GENERIC:
386 if (pos[1] >= 4 &&
387 pos[2] == 0x00 && pos[3] == 0x50 &&
388 pos[4] == 0xf2 && pos[5] == 1) {
389 wpa = pos;
390 wpa_len = pos[1] + 2;
391 }
392 break;
393 case WLAN_EID_RSN:
394 rsn = pos;
395 rsn_len = pos[1] + 2;
396 break;
397 case WLAN_EID_DS_PARAMS:
398 if (pos[1] >= 1)
399 chan = pos[2];
400 break;
401 }
402 left -= 2 + pos[1];
403 pos += 2 + pos[1];
404 }
405
406 if (wpa_len > MAX_WPA_IE_LEN)
407 wpa_len = MAX_WPA_IE_LEN;
408 if (rsn_len > MAX_WPA_IE_LEN)
409 rsn_len = MAX_WPA_IE_LEN;
410 if (ssid_len > sizeof(bss->ssid))
411 ssid_len = sizeof(bss->ssid);
412
413 spin_lock(&local->lock);
414 bss = __hostap_get_bss(local, mgmt->bssid, ssid, ssid_len);
415 if (bss == NULL)
416 bss = __hostap_add_bss(local, mgmt->bssid, ssid, ssid_len);
417 if (bss) {
418 bss->last_update = jiffies;
419 bss->count++;
420 bss->capab_info = le16_to_cpu(mgmt->u.beacon.capab_info);
421 if (wpa) {
422 memcpy(bss->wpa_ie, wpa, wpa_len);
423 bss->wpa_ie_len = wpa_len;
424 } else
425 bss->wpa_ie_len = 0;
426 if (rsn) {
427 memcpy(bss->rsn_ie, rsn, rsn_len);
428 bss->rsn_ie_len = rsn_len;
429 } else
430 bss->rsn_ie_len = 0;
431 bss->chan = chan;
432 }
433 __hostap_expire_bss(local);
434 spin_unlock(&local->lock);
435}
436
437
438static inline int
439hostap_rx_frame_mgmt(local_info_t *local, struct sk_buff *skb,
440 struct hostap_80211_rx_status *rx_stats, u16 type,
441 u16 stype)
442{
443 if (local->iw_mode == IW_MODE_MASTER) {
444 hostap_update_sta_ps(local, (struct hostap_ieee80211_hdr *)
445 skb->data);
446 }
447
448 if (local->hostapd && type == WLAN_FC_TYPE_MGMT) {
449 if (stype == WLAN_FC_STYPE_BEACON &&
450 local->iw_mode == IW_MODE_MASTER) {
451 struct sk_buff *skb2;
452 /* Process beacon frames also in kernel driver to
453 * update STA(AP) table statistics */
454 skb2 = skb_clone(skb, GFP_ATOMIC);
455 if (skb2)
456 hostap_rx(skb2->dev, skb2, rx_stats);
457 }
458
459 /* send management frames to the user space daemon for
460 * processing */
461 local->apdevstats.rx_packets++;
462 local->apdevstats.rx_bytes += skb->len;
463 if (local->apdev == NULL)
464 return -1;
465 prism2_rx_80211(local->apdev, skb, rx_stats, PRISM2_RX_MGMT);
466 return 0;
467 }
468
469 if (local->iw_mode == IW_MODE_MASTER) {
470 if (type != WLAN_FC_TYPE_MGMT && type != WLAN_FC_TYPE_CTRL) {
471 printk(KERN_DEBUG "%s: unknown management frame "
472 "(type=0x%02x, stype=0x%02x) dropped\n",
473 skb->dev->name, type, stype);
474 return -1;
475 }
476
477 hostap_rx(skb->dev, skb, rx_stats);
478 return 0;
479 } else if (type == WLAN_FC_TYPE_MGMT &&
480 (stype == WLAN_FC_STYPE_BEACON ||
481 stype == WLAN_FC_STYPE_PROBE_RESP)) {
482 hostap_rx_sta_beacon(local, skb, stype);
483 return -1;
484 } else if (type == WLAN_FC_TYPE_MGMT &&
485 (stype == WLAN_FC_STYPE_ASSOC_RESP ||
486 stype == WLAN_FC_STYPE_REASSOC_RESP)) {
487 /* Ignore (Re)AssocResp silently since these are not currently
488 * needed but are still received when WPA/RSN mode is enabled.
489 */
490 return -1;
491 } else {
492 printk(KERN_DEBUG "%s: hostap_rx_frame_mgmt: dropped unhandled"
493 " management frame in non-Host AP mode (type=%d:%d)\n",
494 skb->dev->name, type, stype);
495 return -1;
496 }
497}
498
499
500/* Called only as a tasklet (software IRQ) */
501static inline struct net_device *prism2_rx_get_wds(local_info_t *local,
502 u8 *addr)
503{
504 struct hostap_interface *iface = NULL;
505 struct list_head *ptr;
506
507 read_lock_bh(&local->iface_lock);
508 list_for_each(ptr, &local->hostap_interfaces) {
509 iface = list_entry(ptr, struct hostap_interface, list);
510 if (iface->type == HOSTAP_INTERFACE_WDS &&
511 memcmp(iface->u.wds.remote_addr, addr, ETH_ALEN) == 0)
512 break;
513 iface = NULL;
514 }
515 read_unlock_bh(&local->iface_lock);
516
517 return iface ? iface->dev : NULL;
518}
519
520
521static inline int
522hostap_rx_frame_wds(local_info_t *local, struct hostap_ieee80211_hdr *hdr,
523 u16 fc, struct net_device **wds)
524{
525 /* FIX: is this really supposed to accept WDS frames only in Master
526 * mode? What about Repeater or Managed with WDS frames? */
527 if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) !=
528 (WLAN_FC_TODS | WLAN_FC_FROMDS) &&
529 (local->iw_mode != IW_MODE_MASTER || !(fc & WLAN_FC_TODS)))
530 return 0; /* not a WDS frame */
531
532 /* Possible WDS frame: either IEEE 802.11 compliant (if FromDS)
533 * or own non-standard frame with 4th address after payload */
534 if (memcmp(hdr->addr1, local->dev->dev_addr, ETH_ALEN) != 0 &&
535 (hdr->addr1[0] != 0xff || hdr->addr1[1] != 0xff ||
536 hdr->addr1[2] != 0xff || hdr->addr1[3] != 0xff ||
537 hdr->addr1[4] != 0xff || hdr->addr1[5] != 0xff)) {
538 /* RA (or BSSID) is not ours - drop */
539 PDEBUG(DEBUG_EXTRA, "%s: received WDS frame with "
540 "not own or broadcast %s=" MACSTR "\n",
541 local->dev->name, fc & WLAN_FC_FROMDS ? "RA" : "BSSID",
542 MAC2STR(hdr->addr1));
543 return -1;
544 }
545
546 /* check if the frame came from a registered WDS connection */
547 *wds = prism2_rx_get_wds(local, hdr->addr2);
548 if (*wds == NULL && fc & WLAN_FC_FROMDS &&
549 (local->iw_mode != IW_MODE_INFRA ||
550 !(local->wds_type & HOSTAP_WDS_AP_CLIENT) ||
551 memcmp(hdr->addr2, local->bssid, ETH_ALEN) != 0)) {
552 /* require that WDS link has been registered with TA or the
553 * frame is from current AP when using 'AP client mode' */
554 PDEBUG(DEBUG_EXTRA, "%s: received WDS[4 addr] frame "
555 "from unknown TA=" MACSTR "\n",
556 local->dev->name, MAC2STR(hdr->addr2));
557 if (local->ap && local->ap->autom_ap_wds)
558 hostap_wds_link_oper(local, hdr->addr2, WDS_ADD);
559 return -1;
560 }
561
562 if (*wds && !(fc & WLAN_FC_FROMDS) && local->ap &&
563 hostap_is_sta_assoc(local->ap, hdr->addr2)) {
564 /* STA is actually associated with us even though it has a
565 * registered WDS link. Assume it is in 'AP client' mode.
566 * Since this is a 3-addr frame, assume it is not (bogus) WDS
567 * frame and process it like any normal ToDS frame from
568 * associated STA. */
569 *wds = NULL;
570 }
571
572 return 0;
573}
574
575
576static int hostap_is_eapol_frame(local_info_t *local, struct sk_buff *skb)
577{
578 struct net_device *dev = local->dev;
579 u16 fc, ethertype;
580 struct hostap_ieee80211_hdr *hdr;
581 u8 *pos;
582
583 if (skb->len < 24)
584 return 0;
585
586 hdr = (struct hostap_ieee80211_hdr *) skb->data;
587 fc = le16_to_cpu(hdr->frame_control);
588
589 /* check that the frame is unicast frame to us */
590 if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) == WLAN_FC_TODS &&
591 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0 &&
592 memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
593 /* ToDS frame with own addr BSSID and DA */
594 } else if ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) == WLAN_FC_FROMDS &&
595 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
596 /* FromDS frame with own addr as DA */
597 } else
598 return 0;
599
600 if (skb->len < 24 + 8)
601 return 0;
602
603 /* check for port access entity Ethernet type */
604 pos = skb->data + 24;
605 ethertype = (pos[6] << 8) | pos[7];
606 if (ethertype == ETH_P_PAE)
607 return 1;
608
609 return 0;
610}
611
612
613/* Called only as a tasklet (software IRQ) */
614static inline int
615hostap_rx_frame_decrypt(local_info_t *local, struct sk_buff *skb,
616 struct ieee80211_crypt_data *crypt)
617{
618 struct hostap_ieee80211_hdr *hdr;
619 int res, hdrlen;
620
621 if (crypt == NULL || crypt->ops->decrypt_mpdu == NULL)
622 return 0;
623
624 hdr = (struct hostap_ieee80211_hdr *) skb->data;
625 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
626
627 if (local->tkip_countermeasures &&
628 strcmp(crypt->ops->name, "TKIP") == 0) {
629 if (net_ratelimit()) {
630 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
631 "received packet from " MACSTR "\n",
632 local->dev->name, MAC2STR(hdr->addr2));
633 }
634 return -1;
635 }
636
637 atomic_inc(&crypt->refcnt);
638 res = crypt->ops->decrypt_mpdu(skb, hdrlen, crypt->priv);
639 atomic_dec(&crypt->refcnt);
640 if (res < 0) {
641 printk(KERN_DEBUG "%s: decryption failed (SA=" MACSTR
642 ") res=%d\n",
643 local->dev->name, MAC2STR(hdr->addr2), res);
644 local->comm_tallies.rx_discards_wep_undecryptable++;
645 return -1;
646 }
647
648 return res;
649}
650
651
652/* Called only as a tasklet (software IRQ) */
653static inline int
654hostap_rx_frame_decrypt_msdu(local_info_t *local, struct sk_buff *skb,
655 int keyidx, struct ieee80211_crypt_data *crypt)
656{
657 struct hostap_ieee80211_hdr *hdr;
658 int res, hdrlen;
659
660 if (crypt == NULL || crypt->ops->decrypt_msdu == NULL)
661 return 0;
662
663 hdr = (struct hostap_ieee80211_hdr *) skb->data;
664 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(hdr->frame_control));
665
666 atomic_inc(&crypt->refcnt);
667 res = crypt->ops->decrypt_msdu(skb, keyidx, hdrlen, crypt->priv);
668 atomic_dec(&crypt->refcnt);
669 if (res < 0) {
670 printk(KERN_DEBUG "%s: MSDU decryption/MIC verification failed"
671 " (SA=" MACSTR " keyidx=%d)\n",
672 local->dev->name, MAC2STR(hdr->addr2), keyidx);
673 return -1;
674 }
675
676 return 0;
677}
678
679
680/* All received frames are sent to this function. @skb contains the frame in
681 * IEEE 802.11 format, i.e., in the format it was sent over air.
682 * This function is called only as a tasklet (software IRQ). */
683void hostap_80211_rx(struct net_device *dev, struct sk_buff *skb,
684 struct hostap_80211_rx_status *rx_stats)
685{
686 struct hostap_interface *iface;
687 local_info_t *local;
688 struct hostap_ieee80211_hdr *hdr;
689 size_t hdrlen;
690 u16 fc, type, stype, sc;
691 struct net_device *wds = NULL;
692 struct net_device_stats *stats;
693 unsigned int frag;
694 u8 *payload;
695 struct sk_buff *skb2 = NULL;
696 u16 ethertype;
697 int frame_authorized = 0;
698 int from_assoc_ap = 0;
699 u8 dst[ETH_ALEN];
700 u8 src[ETH_ALEN];
701 struct ieee80211_crypt_data *crypt = NULL;
702 void *sta = NULL;
703 int keyidx = 0;
704
705 iface = netdev_priv(dev);
706 local = iface->local;
707 iface->stats.rx_packets++;
708 iface->stats.rx_bytes += skb->len;
709
710 /* dev is the master radio device; change this to be the default
711 * virtual interface (this may be changed to WDS device below) */
712 dev = local->ddev;
713 iface = netdev_priv(dev);
714
715 hdr = (struct hostap_ieee80211_hdr *) skb->data;
716 stats = hostap_get_stats(dev);
717
718 if (skb->len < 10)
719 goto rx_dropped;
720
721 fc = le16_to_cpu(hdr->frame_control);
722 type = HOSTAP_FC_GET_TYPE(fc);
723 stype = HOSTAP_FC_GET_STYPE(fc);
724 sc = le16_to_cpu(hdr->seq_ctrl);
725 frag = WLAN_GET_SEQ_FRAG(sc);
726 hdrlen = hostap_80211_get_hdrlen(fc);
727
728 /* Put this code here so that we avoid duplicating it in all
729 * Rx paths. - Jean II */
730#ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
731 /* If spy monitoring on */
732 if (iface->spy_data.spy_number > 0) {
733 struct iw_quality wstats;
734 wstats.level = rx_stats->signal;
735 wstats.noise = rx_stats->noise;
736 wstats.updated = 6; /* No qual value */
737 /* Update spy records */
738 wireless_spy_update(dev, hdr->addr2, &wstats);
739 }
740#endif /* IW_WIRELESS_SPY */
741 hostap_update_rx_stats(local->ap, hdr, rx_stats);
742
743 if (local->iw_mode == IW_MODE_MONITOR) {
744 monitor_rx(dev, skb, rx_stats);
745 return;
746 }
747
748 if (local->host_decrypt) {
749 int idx = 0;
750 if (skb->len >= hdrlen + 3)
751 idx = skb->data[hdrlen + 3] >> 6;
752 crypt = local->crypt[idx];
753 sta = NULL;
754
755 /* Use station specific key to override default keys if the
756 * receiver address is a unicast address ("individual RA"). If
757 * bcrx_sta_key parameter is set, station specific key is used
758 * even with broad/multicast targets (this is against IEEE
759 * 802.11, but makes it easier to use different keys with
760 * stations that do not support WEP key mapping). */
761
762 if (!(hdr->addr1[0] & 0x01) || local->bcrx_sta_key)
763 (void) hostap_handle_sta_crypto(local, hdr, &crypt,
764 &sta);
765
766 /* allow NULL decrypt to indicate an station specific override
767 * for default encryption */
768 if (crypt && (crypt->ops == NULL ||
769 crypt->ops->decrypt_mpdu == NULL))
770 crypt = NULL;
771
772 if (!crypt && (fc & WLAN_FC_ISWEP)) {
773#if 0
774 /* This seems to be triggered by some (multicast?)
775 * frames from other than current BSS, so just drop the
776 * frames silently instead of filling system log with
777 * these reports. */
778 printk(KERN_DEBUG "%s: WEP decryption failed (not set)"
779 " (SA=" MACSTR ")\n",
780 local->dev->name, MAC2STR(hdr->addr2));
781#endif
782 local->comm_tallies.rx_discards_wep_undecryptable++;
783 goto rx_dropped;
784 }
785 }
786
787 if (type != WLAN_FC_TYPE_DATA) {
788 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_AUTH &&
789 fc & WLAN_FC_ISWEP && local->host_decrypt &&
790 (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
791 {
792 printk(KERN_DEBUG "%s: failed to decrypt mgmt::auth "
793 "from " MACSTR "\n", dev->name,
794 MAC2STR(hdr->addr2));
795 /* TODO: could inform hostapd about this so that it
796 * could send auth failure report */
797 goto rx_dropped;
798 }
799
800 if (hostap_rx_frame_mgmt(local, skb, rx_stats, type, stype))
801 goto rx_dropped;
802 else
803 goto rx_exit;
804 }
805
806 /* Data frame - extract src/dst addresses */
807 if (skb->len < IEEE80211_DATA_HDR3_LEN)
808 goto rx_dropped;
809
810 switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
811 case WLAN_FC_FROMDS:
812 memcpy(dst, hdr->addr1, ETH_ALEN);
813 memcpy(src, hdr->addr3, ETH_ALEN);
814 break;
815 case WLAN_FC_TODS:
816 memcpy(dst, hdr->addr3, ETH_ALEN);
817 memcpy(src, hdr->addr2, ETH_ALEN);
818 break;
819 case WLAN_FC_FROMDS | WLAN_FC_TODS:
820 if (skb->len < IEEE80211_DATA_HDR4_LEN)
821 goto rx_dropped;
822 memcpy(dst, hdr->addr3, ETH_ALEN);
823 memcpy(src, hdr->addr4, ETH_ALEN);
824 break;
825 case 0:
826 memcpy(dst, hdr->addr1, ETH_ALEN);
827 memcpy(src, hdr->addr2, ETH_ALEN);
828 break;
829 }
830
831 if (hostap_rx_frame_wds(local, hdr, fc, &wds))
832 goto rx_dropped;
833 if (wds) {
834 skb->dev = dev = wds;
835 stats = hostap_get_stats(dev);
836 }
837
838 if (local->iw_mode == IW_MODE_MASTER && !wds &&
839 (fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) == WLAN_FC_FROMDS &&
840 local->stadev &&
841 memcmp(hdr->addr2, local->assoc_ap_addr, ETH_ALEN) == 0) {
842 /* Frame from BSSID of the AP for which we are a client */
843 skb->dev = dev = local->stadev;
844 stats = hostap_get_stats(dev);
845 from_assoc_ap = 1;
846 }
847
848 dev->last_rx = jiffies;
849
850 if ((local->iw_mode == IW_MODE_MASTER ||
851 local->iw_mode == IW_MODE_REPEAT) &&
852 !from_assoc_ap) {
853 switch (hostap_handle_sta_rx(local, dev, skb, rx_stats,
854 wds != NULL)) {
855 case AP_RX_CONTINUE_NOT_AUTHORIZED:
856 frame_authorized = 0;
857 break;
858 case AP_RX_CONTINUE:
859 frame_authorized = 1;
860 break;
861 case AP_RX_DROP:
862 goto rx_dropped;
863 case AP_RX_EXIT:
864 goto rx_exit;
865 }
866 }
867
868 /* Nullfunc frames may have PS-bit set, so they must be passed to
869 * hostap_handle_sta_rx() before being dropped here. */
870 if (stype != WLAN_FC_STYPE_DATA &&
871 stype != WLAN_FC_STYPE_DATA_CFACK &&
872 stype != WLAN_FC_STYPE_DATA_CFPOLL &&
873 stype != WLAN_FC_STYPE_DATA_CFACKPOLL) {
874 if (stype != WLAN_FC_STYPE_NULLFUNC)
875 printk(KERN_DEBUG "%s: RX: dropped data frame "
876 "with no data (type=0x%02x, subtype=0x%02x)\n",
877 dev->name, type, stype);
878 goto rx_dropped;
879 }
880
881 /* skb: hdr + (possibly fragmented, possibly encrypted) payload */
882
883 if (local->host_decrypt && (fc & WLAN_FC_ISWEP) &&
884 (keyidx = hostap_rx_frame_decrypt(local, skb, crypt)) < 0)
885 goto rx_dropped;
886 hdr = (struct hostap_ieee80211_hdr *) skb->data;
887
888 /* skb: hdr + (possibly fragmented) plaintext payload */
889
890 if (local->host_decrypt && (fc & WLAN_FC_ISWEP) &&
891 (frag != 0 || (fc & WLAN_FC_MOREFRAG))) {
892 int flen;
893 struct sk_buff *frag_skb =
894 prism2_frag_cache_get(local, hdr);
895 if (!frag_skb) {
896 printk(KERN_DEBUG "%s: Rx cannot get skb from "
897 "fragment cache (morefrag=%d seq=%u frag=%u)\n",
898 dev->name, (fc & WLAN_FC_MOREFRAG) != 0,
899 WLAN_GET_SEQ_SEQ(sc) >> 4, frag);
900 goto rx_dropped;
901 }
902
903 flen = skb->len;
904 if (frag != 0)
905 flen -= hdrlen;
906
907 if (frag_skb->tail + flen > frag_skb->end) {
908 printk(KERN_WARNING "%s: host decrypted and "
909 "reassembled frame did not fit skb\n",
910 dev->name);
911 prism2_frag_cache_invalidate(local, hdr);
912 goto rx_dropped;
913 }
914
915 if (frag == 0) {
916 /* copy first fragment (including full headers) into
917 * beginning of the fragment cache skb */
918 memcpy(skb_put(frag_skb, flen), skb->data, flen);
919 } else {
920 /* append frame payload to the end of the fragment
921 * cache skb */
922 memcpy(skb_put(frag_skb, flen), skb->data + hdrlen,
923 flen);
924 }
925 dev_kfree_skb(skb);
926 skb = NULL;
927
928 if (fc & WLAN_FC_MOREFRAG) {
929 /* more fragments expected - leave the skb in fragment
930 * cache for now; it will be delivered to upper layers
931 * after all fragments have been received */
932 goto rx_exit;
933 }
934
935 /* this was the last fragment and the frame will be
936 * delivered, so remove skb from fragment cache */
937 skb = frag_skb;
938 hdr = (struct hostap_ieee80211_hdr *) skb->data;
939 prism2_frag_cache_invalidate(local, hdr);
940 }
941
942 /* skb: hdr + (possible reassembled) full MSDU payload; possibly still
943 * encrypted/authenticated */
944
945 if (local->host_decrypt && (fc & WLAN_FC_ISWEP) &&
946 hostap_rx_frame_decrypt_msdu(local, skb, keyidx, crypt))
947 goto rx_dropped;
948
949 hdr = (struct hostap_ieee80211_hdr *) skb->data;
950 if (crypt && !(fc & WLAN_FC_ISWEP) && !local->open_wep) {
951 if (local->ieee_802_1x &&
952 hostap_is_eapol_frame(local, skb)) {
953 /* pass unencrypted EAPOL frames even if encryption is
954 * configured */
955 PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X - passing "
956 "unencrypted EAPOL frame\n", local->dev->name);
957 } else {
958 printk(KERN_DEBUG "%s: encryption configured, but RX "
959 "frame not encrypted (SA=" MACSTR ")\n",
960 local->dev->name, MAC2STR(hdr->addr2));
961 goto rx_dropped;
962 }
963 }
964
965 if (local->drop_unencrypted && !(fc & WLAN_FC_ISWEP) &&
966 !hostap_is_eapol_frame(local, skb)) {
967 if (net_ratelimit()) {
968 printk(KERN_DEBUG "%s: dropped unencrypted RX data "
969 "frame from " MACSTR " (drop_unencrypted=1)\n",
970 dev->name, MAC2STR(hdr->addr2));
971 }
972 goto rx_dropped;
973 }
974
975 /* skb: hdr + (possible reassembled) full plaintext payload */
976
977 payload = skb->data + hdrlen;
978 ethertype = (payload[6] << 8) | payload[7];
979
980 /* If IEEE 802.1X is used, check whether the port is authorized to send
981 * the received frame. */
982 if (local->ieee_802_1x && local->iw_mode == IW_MODE_MASTER) {
983 if (ethertype == ETH_P_PAE) {
984 PDEBUG(DEBUG_EXTRA2, "%s: RX: IEEE 802.1X frame\n",
985 dev->name);
986 if (local->hostapd && local->apdev) {
987 /* Send IEEE 802.1X frames to the user
988 * space daemon for processing */
989 prism2_rx_80211(local->apdev, skb, rx_stats,
990 PRISM2_RX_MGMT);
991 local->apdevstats.rx_packets++;
992 local->apdevstats.rx_bytes += skb->len;
993 goto rx_exit;
994 }
995 } else if (!frame_authorized) {
996 printk(KERN_DEBUG "%s: dropped frame from "
997 "unauthorized port (IEEE 802.1X): "
998 "ethertype=0x%04x\n",
999 dev->name, ethertype);
1000 goto rx_dropped;
1001 }
1002 }
1003
1004 /* convert hdr + possible LLC headers into Ethernet header */
1005 if (skb->len - hdrlen >= 8 &&
1006 ((memcmp(payload, rfc1042_header, 6) == 0 &&
1007 ethertype != ETH_P_AARP && ethertype != ETH_P_IPX) ||
1008 memcmp(payload, bridge_tunnel_header, 6) == 0)) {
1009 /* remove RFC1042 or Bridge-Tunnel encapsulation and
1010 * replace EtherType */
1011 skb_pull(skb, hdrlen + 6);
1012 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1013 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1014 } else {
1015 u16 len;
1016 /* Leave Ethernet header part of hdr and full payload */
1017 skb_pull(skb, hdrlen);
1018 len = htons(skb->len);
1019 memcpy(skb_push(skb, 2), &len, 2);
1020 memcpy(skb_push(skb, ETH_ALEN), src, ETH_ALEN);
1021 memcpy(skb_push(skb, ETH_ALEN), dst, ETH_ALEN);
1022 }
1023
1024 if (wds && ((fc & (WLAN_FC_TODS | WLAN_FC_FROMDS)) == WLAN_FC_TODS) &&
1025 skb->len >= ETH_HLEN + ETH_ALEN) {
1026 /* Non-standard frame: get addr4 from its bogus location after
1027 * the payload */
1028 memcpy(skb->data + ETH_ALEN,
1029 skb->data + skb->len - ETH_ALEN, ETH_ALEN);
1030 skb_trim(skb, skb->len - ETH_ALEN);
1031 }
1032
1033 stats->rx_packets++;
1034 stats->rx_bytes += skb->len;
1035
1036 if (local->iw_mode == IW_MODE_MASTER && !wds &&
1037 local->ap->bridge_packets) {
1038 if (dst[0] & 0x01) {
1039 /* copy multicast frame both to the higher layers and
1040 * to the wireless media */
1041 local->ap->bridged_multicast++;
1042 skb2 = skb_clone(skb, GFP_ATOMIC);
1043 if (skb2 == NULL)
1044 printk(KERN_DEBUG "%s: skb_clone failed for "
1045 "multicast frame\n", dev->name);
1046 } else if (hostap_is_sta_authorized(local->ap, dst)) {
1047 /* send frame directly to the associated STA using
1048 * wireless media and not passing to higher layers */
1049 local->ap->bridged_unicast++;
1050 skb2 = skb;
1051 skb = NULL;
1052 }
1053 }
1054
1055 if (skb2 != NULL) {
1056 /* send to wireless media */
1057 skb2->protocol = __constant_htons(ETH_P_802_3);
1058 skb2->mac.raw = skb2->nh.raw = skb2->data;
1059 /* skb2->nh.raw = skb2->data + ETH_HLEN; */
1060 skb2->dev = dev;
1061 dev_queue_xmit(skb2);
1062 }
1063
1064 if (skb) {
1065 skb->protocol = eth_type_trans(skb, dev);
1066 memset(skb->cb, 0, sizeof(skb->cb));
1067 skb->dev = dev;
1068 netif_rx(skb);
1069 }
1070
1071 rx_exit:
1072 if (sta)
1073 hostap_handle_sta_release(sta);
1074 return;
1075
1076 rx_dropped:
1077 dev_kfree_skb(skb);
1078
1079 stats->rx_dropped++;
1080 goto rx_exit;
1081}
1082
1083
1084EXPORT_SYMBOL(hostap_80211_rx);
diff --git a/drivers/net/wireless/hostap/hostap_80211_tx.c b/drivers/net/wireless/hostap/hostap_80211_tx.c
new file mode 100644
index 000000000000..8f39871d6908
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_80211_tx.c
@@ -0,0 +1,522 @@
1void hostap_dump_tx_80211(const char *name, struct sk_buff *skb)
2{
3 struct hostap_ieee80211_hdr *hdr;
4 u16 fc;
5
6 hdr = (struct hostap_ieee80211_hdr *) skb->data;
7
8 printk(KERN_DEBUG "%s: TX len=%d jiffies=%ld\n",
9 name, skb->len, jiffies);
10
11 if (skb->len < 2)
12 return;
13
14 fc = le16_to_cpu(hdr->frame_control);
15 printk(KERN_DEBUG " FC=0x%04x (type=%d:%d)%s%s",
16 fc, HOSTAP_FC_GET_TYPE(fc), HOSTAP_FC_GET_STYPE(fc),
17 fc & WLAN_FC_TODS ? " [ToDS]" : "",
18 fc & WLAN_FC_FROMDS ? " [FromDS]" : "");
19
20 if (skb->len < IEEE80211_DATA_HDR3_LEN) {
21 printk("\n");
22 return;
23 }
24
25 printk(" dur=0x%04x seq=0x%04x\n", le16_to_cpu(hdr->duration_id),
26 le16_to_cpu(hdr->seq_ctrl));
27
28 printk(KERN_DEBUG " A1=" MACSTR " A2=" MACSTR " A3=" MACSTR,
29 MAC2STR(hdr->addr1), MAC2STR(hdr->addr2), MAC2STR(hdr->addr3));
30 if (skb->len >= 30)
31 printk(" A4=" MACSTR, MAC2STR(hdr->addr4));
32 printk("\n");
33}
34
35
36/* hard_start_xmit function for data interfaces (wlan#, wlan#wds#, wlan#sta)
37 * Convert Ethernet header into a suitable IEEE 802.11 header depending on
38 * device configuration. */
39int hostap_data_start_xmit(struct sk_buff *skb, struct net_device *dev)
40{
41 struct hostap_interface *iface;
42 local_info_t *local;
43 int need_headroom, need_tailroom = 0;
44 struct hostap_ieee80211_hdr hdr;
45 u16 fc, ethertype = 0;
46 enum {
47 WDS_NO = 0, WDS_OWN_FRAME, WDS_COMPLIANT_FRAME
48 } use_wds = WDS_NO;
49 u8 *encaps_data;
50 int hdr_len, encaps_len, skip_header_bytes;
51 int to_assoc_ap = 0;
52 struct hostap_skb_tx_data *meta;
53
54 iface = netdev_priv(dev);
55 local = iface->local;
56
57 if (skb->len < ETH_HLEN) {
58 printk(KERN_DEBUG "%s: hostap_data_start_xmit: short skb "
59 "(len=%d)\n", dev->name, skb->len);
60 kfree_skb(skb);
61 return 0;
62 }
63
64 if (local->ddev != dev) {
65 use_wds = (local->iw_mode == IW_MODE_MASTER &&
66 !(local->wds_type & HOSTAP_WDS_STANDARD_FRAME)) ?
67 WDS_OWN_FRAME : WDS_COMPLIANT_FRAME;
68 if (dev == local->stadev) {
69 to_assoc_ap = 1;
70 use_wds = WDS_NO;
71 } else if (dev == local->apdev) {
72 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
73 "AP device with Ethernet net dev\n", dev->name);
74 kfree_skb(skb);
75 return 0;
76 }
77 } else {
78 if (local->iw_mode == IW_MODE_REPEAT) {
79 printk(KERN_DEBUG "%s: prism2_tx: trying to use "
80 "non-WDS link in Repeater mode\n", dev->name);
81 kfree_skb(skb);
82 return 0;
83 } else if (local->iw_mode == IW_MODE_INFRA &&
84 (local->wds_type & HOSTAP_WDS_AP_CLIENT) &&
85 memcmp(skb->data + ETH_ALEN, dev->dev_addr,
86 ETH_ALEN) != 0) {
87 /* AP client mode: send frames with foreign src addr
88 * using 4-addr WDS frames */
89 use_wds = WDS_COMPLIANT_FRAME;
90 }
91 }
92
93 /* Incoming skb->data: dst_addr[6], src_addr[6], proto[2], payload
94 * ==>
95 * Prism2 TX frame with 802.11 header:
96 * txdesc (address order depending on used mode; includes dst_addr and
97 * src_addr), possible encapsulation (RFC1042/Bridge-Tunnel;
98 * proto[2], payload {, possible addr4[6]} */
99
100 ethertype = (skb->data[12] << 8) | skb->data[13];
101
102 memset(&hdr, 0, sizeof(hdr));
103
104 /* Length of data after IEEE 802.11 header */
105 encaps_data = NULL;
106 encaps_len = 0;
107 skip_header_bytes = ETH_HLEN;
108 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
109 encaps_data = bridge_tunnel_header;
110 encaps_len = sizeof(bridge_tunnel_header);
111 skip_header_bytes -= 2;
112 } else if (ethertype >= 0x600) {
113 encaps_data = rfc1042_header;
114 encaps_len = sizeof(rfc1042_header);
115 skip_header_bytes -= 2;
116 }
117
118 fc = (WLAN_FC_TYPE_DATA << 2) | (WLAN_FC_STYPE_DATA << 4);
119 hdr_len = IEEE80211_DATA_HDR3_LEN;
120
121 if (use_wds != WDS_NO) {
122 /* Note! Prism2 station firmware has problems with sending real
123 * 802.11 frames with four addresses; until these problems can
124 * be fixed or worked around, 4-addr frames needed for WDS are
125 * using incompatible format: FromDS flag is not set and the
126 * fourth address is added after the frame payload; it is
127 * assumed, that the receiving station knows how to handle this
128 * frame format */
129
130 if (use_wds == WDS_COMPLIANT_FRAME) {
131 fc |= WLAN_FC_FROMDS | WLAN_FC_TODS;
132 /* From&To DS: Addr1 = RA, Addr2 = TA, Addr3 = DA,
133 * Addr4 = SA */
134 memcpy(&hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
135 hdr_len += ETH_ALEN;
136 } else {
137 /* bogus 4-addr format to workaround Prism2 station
138 * f/w bug */
139 fc |= WLAN_FC_TODS;
140 /* From DS: Addr1 = DA (used as RA),
141 * Addr2 = BSSID (used as TA), Addr3 = SA (used as DA),
142 */
143
144 /* SA from skb->data + ETH_ALEN will be added after
145 * frame payload; use hdr.addr4 as a temporary buffer
146 */
147 memcpy(&hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
148 need_tailroom += ETH_ALEN;
149 }
150
151 /* send broadcast and multicast frames to broadcast RA, if
152 * configured; otherwise, use unicast RA of the WDS link */
153 if ((local->wds_type & HOSTAP_WDS_BROADCAST_RA) &&
154 skb->data[0] & 0x01)
155 memset(&hdr.addr1, 0xff, ETH_ALEN);
156 else if (iface->type == HOSTAP_INTERFACE_WDS)
157 memcpy(&hdr.addr1, iface->u.wds.remote_addr,
158 ETH_ALEN);
159 else
160 memcpy(&hdr.addr1, local->bssid, ETH_ALEN);
161 memcpy(&hdr.addr2, dev->dev_addr, ETH_ALEN);
162 memcpy(&hdr.addr3, skb->data, ETH_ALEN);
163 } else if (local->iw_mode == IW_MODE_MASTER && !to_assoc_ap) {
164 fc |= WLAN_FC_FROMDS;
165 /* From DS: Addr1 = DA, Addr2 = BSSID, Addr3 = SA */
166 memcpy(&hdr.addr1, skb->data, ETH_ALEN);
167 memcpy(&hdr.addr2, dev->dev_addr, ETH_ALEN);
168 memcpy(&hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
169 } else if (local->iw_mode == IW_MODE_INFRA || to_assoc_ap) {
170 fc |= WLAN_FC_TODS;
171 /* To DS: Addr1 = BSSID, Addr2 = SA, Addr3 = DA */
172 memcpy(&hdr.addr1, to_assoc_ap ?
173 local->assoc_ap_addr : local->bssid, ETH_ALEN);
174 memcpy(&hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
175 memcpy(&hdr.addr3, skb->data, ETH_ALEN);
176 } else if (local->iw_mode == IW_MODE_ADHOC) {
177 /* not From/To DS: Addr1 = DA, Addr2 = SA, Addr3 = BSSID */
178 memcpy(&hdr.addr1, skb->data, ETH_ALEN);
179 memcpy(&hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
180 memcpy(&hdr.addr3, local->bssid, ETH_ALEN);
181 }
182
183 hdr.frame_control = cpu_to_le16(fc);
184
185 skb_pull(skb, skip_header_bytes);
186 need_headroom = local->func->need_tx_headroom + hdr_len + encaps_len;
187 if (skb_tailroom(skb) < need_tailroom) {
188 skb = skb_unshare(skb, GFP_ATOMIC);
189 if (skb == NULL) {
190 iface->stats.tx_dropped++;
191 return 0;
192 }
193 if (pskb_expand_head(skb, need_headroom, need_tailroom,
194 GFP_ATOMIC)) {
195 kfree_skb(skb);
196 iface->stats.tx_dropped++;
197 return 0;
198 }
199 } else if (skb_headroom(skb) < need_headroom) {
200 struct sk_buff *tmp = skb;
201 skb = skb_realloc_headroom(skb, need_headroom);
202 kfree_skb(tmp);
203 if (skb == NULL) {
204 iface->stats.tx_dropped++;
205 return 0;
206 }
207 } else {
208 skb = skb_unshare(skb, GFP_ATOMIC);
209 if (skb == NULL) {
210 iface->stats.tx_dropped++;
211 return 0;
212 }
213 }
214
215 if (encaps_data)
216 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
217 memcpy(skb_push(skb, hdr_len), &hdr, hdr_len);
218 if (use_wds == WDS_OWN_FRAME) {
219 memcpy(skb_put(skb, ETH_ALEN), &hdr.addr4, ETH_ALEN);
220 }
221
222 iface->stats.tx_packets++;
223 iface->stats.tx_bytes += skb->len;
224
225 skb->mac.raw = skb->data;
226 meta = (struct hostap_skb_tx_data *) skb->cb;
227 memset(meta, 0, sizeof(*meta));
228 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
229 meta->wds = use_wds;
230 meta->ethertype = ethertype;
231 meta->iface = iface;
232
233 /* Send IEEE 802.11 encapsulated frame using the master radio device */
234 skb->dev = local->dev;
235 dev_queue_xmit(skb);
236 return 0;
237}
238
239
240/* hard_start_xmit function for hostapd wlan#ap interfaces */
241int hostap_mgmt_start_xmit(struct sk_buff *skb, struct net_device *dev)
242{
243 struct hostap_interface *iface;
244 local_info_t *local;
245 struct hostap_skb_tx_data *meta;
246 struct hostap_ieee80211_hdr *hdr;
247 u16 fc;
248
249 iface = netdev_priv(dev);
250 local = iface->local;
251
252 if (skb->len < 10) {
253 printk(KERN_DEBUG "%s: hostap_mgmt_start_xmit: short skb "
254 "(len=%d)\n", dev->name, skb->len);
255 kfree_skb(skb);
256 return 0;
257 }
258
259 iface->stats.tx_packets++;
260 iface->stats.tx_bytes += skb->len;
261
262 meta = (struct hostap_skb_tx_data *) skb->cb;
263 memset(meta, 0, sizeof(*meta));
264 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
265 meta->iface = iface;
266
267 if (skb->len >= IEEE80211_DATA_HDR3_LEN + sizeof(rfc1042_header) + 2) {
268 hdr = (struct hostap_ieee80211_hdr *) skb->data;
269 fc = le16_to_cpu(hdr->frame_control);
270 if (HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
271 HOSTAP_FC_GET_STYPE(fc) == WLAN_FC_STYPE_DATA) {
272 u8 *pos = &skb->data[IEEE80211_DATA_HDR3_LEN +
273 sizeof(rfc1042_header)];
274 meta->ethertype = (pos[0] << 8) | pos[1];
275 }
276 }
277
278 /* Send IEEE 802.11 encapsulated frame using the master radio device */
279 skb->dev = local->dev;
280 dev_queue_xmit(skb);
281 return 0;
282}
283
284
285/* Called only from software IRQ */
286struct sk_buff * hostap_tx_encrypt(struct sk_buff *skb,
287 struct ieee80211_crypt_data *crypt)
288{
289 struct hostap_interface *iface;
290 local_info_t *local;
291 struct hostap_ieee80211_hdr *hdr;
292 u16 fc;
293 int hdr_len, res;
294
295 iface = netdev_priv(skb->dev);
296 local = iface->local;
297
298 if (skb->len < IEEE80211_DATA_HDR3_LEN) {
299 kfree_skb(skb);
300 return NULL;
301 }
302
303 if (local->tkip_countermeasures &&
304 crypt && crypt->ops && strcmp(crypt->ops->name, "TKIP") == 0) {
305 hdr = (struct hostap_ieee80211_hdr *) skb->data;
306 if (net_ratelimit()) {
307 printk(KERN_DEBUG "%s: TKIP countermeasures: dropped "
308 "TX packet to " MACSTR "\n",
309 local->dev->name, MAC2STR(hdr->addr1));
310 }
311 kfree_skb(skb);
312 return NULL;
313 }
314
315 skb = skb_unshare(skb, GFP_ATOMIC);
316 if (skb == NULL)
317 return NULL;
318
319 if ((skb_headroom(skb) < crypt->ops->extra_prefix_len ||
320 skb_tailroom(skb) < crypt->ops->extra_postfix_len) &&
321 pskb_expand_head(skb, crypt->ops->extra_prefix_len,
322 crypt->ops->extra_postfix_len, GFP_ATOMIC)) {
323 kfree_skb(skb);
324 return NULL;
325 }
326
327 hdr = (struct hostap_ieee80211_hdr *) skb->data;
328 fc = le16_to_cpu(hdr->frame_control);
329 hdr_len = hostap_80211_get_hdrlen(fc);
330
331 /* Host-based IEEE 802.11 fragmentation for TX is not yet supported, so
332 * call both MSDU and MPDU encryption functions from here. */
333 atomic_inc(&crypt->refcnt);
334 res = 0;
335 if (crypt->ops->encrypt_msdu)
336 res = crypt->ops->encrypt_msdu(skb, hdr_len, crypt->priv);
337 if (res == 0 && crypt->ops->encrypt_mpdu)
338 res = crypt->ops->encrypt_mpdu(skb, hdr_len, crypt->priv);
339 atomic_dec(&crypt->refcnt);
340 if (res < 0) {
341 kfree_skb(skb);
342 return NULL;
343 }
344
345 return skb;
346}
347
348
349/* hard_start_xmit function for master radio interface wifi#.
350 * AP processing (TX rate control, power save buffering, etc.).
351 * Use hardware TX function to send the frame. */
352int hostap_master_start_xmit(struct sk_buff *skb, struct net_device *dev)
353{
354 struct hostap_interface *iface;
355 local_info_t *local;
356 int ret = 1;
357 u16 fc;
358 struct hostap_tx_data tx;
359 ap_tx_ret tx_ret;
360 struct hostap_skb_tx_data *meta;
361 int no_encrypt = 0;
362 struct hostap_ieee80211_hdr *hdr;
363
364 iface = netdev_priv(dev);
365 local = iface->local;
366
367 tx.skb = skb;
368 tx.sta_ptr = NULL;
369
370 meta = (struct hostap_skb_tx_data *) skb->cb;
371 if (meta->magic != HOSTAP_SKB_TX_DATA_MAGIC) {
372 printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, "
373 "expected 0x%08x)\n",
374 dev->name, meta->magic, HOSTAP_SKB_TX_DATA_MAGIC);
375 ret = 0;
376 iface->stats.tx_dropped++;
377 goto fail;
378 }
379
380 if (local->host_encrypt) {
381 /* Set crypt to default algorithm and key; will be replaced in
382 * AP code if STA has own alg/key */
383 tx.crypt = local->crypt[local->tx_keyidx];
384 tx.host_encrypt = 1;
385 } else {
386 tx.crypt = NULL;
387 tx.host_encrypt = 0;
388 }
389
390 if (skb->len < 24) {
391 printk(KERN_DEBUG "%s: hostap_master_start_xmit: short skb "
392 "(len=%d)\n", dev->name, skb->len);
393 ret = 0;
394 iface->stats.tx_dropped++;
395 goto fail;
396 }
397
398 /* FIX (?):
399 * Wi-Fi 802.11b test plan suggests that AP should ignore power save
400 * bit in authentication and (re)association frames and assume tha
401 * STA remains awake for the response. */
402 tx_ret = hostap_handle_sta_tx(local, &tx);
403 skb = tx.skb;
404 meta = (struct hostap_skb_tx_data *) skb->cb;
405 hdr = (struct hostap_ieee80211_hdr *) skb->data;
406 fc = le16_to_cpu(hdr->frame_control);
407 switch (tx_ret) {
408 case AP_TX_CONTINUE:
409 break;
410 case AP_TX_CONTINUE_NOT_AUTHORIZED:
411 if (local->ieee_802_1x &&
412 HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
413 meta->ethertype != ETH_P_PAE && !meta->wds) {
414 printk(KERN_DEBUG "%s: dropped frame to unauthorized "
415 "port (IEEE 802.1X): ethertype=0x%04x\n",
416 dev->name, meta->ethertype);
417 hostap_dump_tx_80211(dev->name, skb);
418
419 ret = 0; /* drop packet */
420 iface->stats.tx_dropped++;
421 goto fail;
422 }
423 break;
424 case AP_TX_DROP:
425 ret = 0; /* drop packet */
426 iface->stats.tx_dropped++;
427 goto fail;
428 case AP_TX_RETRY:
429 goto fail;
430 case AP_TX_BUFFERED:
431 /* do not free skb here, it will be freed when the
432 * buffered frame is sent/timed out */
433 ret = 0;
434 goto tx_exit;
435 }
436
437 /* Request TX callback if protocol version is 2 in 802.11 header;
438 * this version 2 is a special case used between hostapd and kernel
439 * driver */
440 if (((fc & WLAN_FC_PVER) == BIT(1)) &&
441 local->ap && local->ap->tx_callback_idx && meta->tx_cb_idx == 0) {
442 meta->tx_cb_idx = local->ap->tx_callback_idx;
443
444 /* remove special version from the frame header */
445 fc &= ~WLAN_FC_PVER;
446 hdr->frame_control = cpu_to_le16(fc);
447 }
448
449 if (HOSTAP_FC_GET_TYPE(fc) != WLAN_FC_TYPE_DATA) {
450 no_encrypt = 1;
451 tx.crypt = NULL;
452 }
453
454 if (local->ieee_802_1x && meta->ethertype == ETH_P_PAE && tx.crypt &&
455 !(fc & WLAN_FC_ISWEP)) {
456 no_encrypt = 1;
457 PDEBUG(DEBUG_EXTRA2, "%s: TX: IEEE 802.1X - passing "
458 "unencrypted EAPOL frame\n", dev->name);
459 tx.crypt = NULL; /* no encryption for IEEE 802.1X frames */
460 }
461
462 if (tx.crypt && (!tx.crypt->ops || !tx.crypt->ops->encrypt_mpdu))
463 tx.crypt = NULL;
464 else if ((tx.crypt || local->crypt[local->tx_keyidx]) && !no_encrypt) {
465 /* Add ISWEP flag both for firmware and host based encryption
466 */
467 fc |= WLAN_FC_ISWEP;
468 hdr->frame_control = cpu_to_le16(fc);
469 } else if (local->drop_unencrypted &&
470 HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
471 meta->ethertype != ETH_P_PAE) {
472 if (net_ratelimit()) {
473 printk(KERN_DEBUG "%s: dropped unencrypted TX data "
474 "frame (drop_unencrypted=1)\n", dev->name);
475 }
476 iface->stats.tx_dropped++;
477 ret = 0;
478 goto fail;
479 }
480
481 if (tx.crypt) {
482 skb = hostap_tx_encrypt(skb, tx.crypt);
483 if (skb == NULL) {
484 printk(KERN_DEBUG "%s: TX - encryption failed\n",
485 dev->name);
486 ret = 0;
487 goto fail;
488 }
489 meta = (struct hostap_skb_tx_data *) skb->cb;
490 if (meta->magic != HOSTAP_SKB_TX_DATA_MAGIC) {
491 printk(KERN_DEBUG "%s: invalid skb->cb magic (0x%08x, "
492 "expected 0x%08x) after hostap_tx_encrypt\n",
493 dev->name, meta->magic,
494 HOSTAP_SKB_TX_DATA_MAGIC);
495 ret = 0;
496 iface->stats.tx_dropped++;
497 goto fail;
498 }
499 }
500
501 if (local->func->tx == NULL || local->func->tx(skb, dev)) {
502 ret = 0;
503 iface->stats.tx_dropped++;
504 } else {
505 ret = 0;
506 iface->stats.tx_packets++;
507 iface->stats.tx_bytes += skb->len;
508 }
509
510 fail:
511 if (!ret && skb)
512 dev_kfree_skb(skb);
513 tx_exit:
514 if (tx.sta_ptr)
515 hostap_handle_sta_release(tx.sta_ptr);
516 return ret;
517}
518
519
520EXPORT_SYMBOL(hostap_dump_tx_80211);
521EXPORT_SYMBOL(hostap_tx_encrypt);
522EXPORT_SYMBOL(hostap_master_start_xmit);
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c
new file mode 100644
index 000000000000..6e109dfb43e7
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_ap.c
@@ -0,0 +1,3287 @@
1/*
2 * Intersil Prism2 driver with Host AP (software access point) support
3 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
4 * <jkmaline@cc.hut.fi>
5 * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
6 *
7 * This file is to be included into hostap.c when S/W AP functionality is
8 * compiled.
9 *
10 * AP: FIX:
11 * - if unicast Class 2 (assoc,reassoc,disassoc) frame received from
12 * unauthenticated STA, send deauth. frame (8802.11: 5.5)
13 * - if unicast Class 3 (data with to/from DS,deauth,pspoll) frame received
14 * from authenticated, but unassoc STA, send disassoc frame (8802.11: 5.5)
15 * - if unicast Class 3 received from unauthenticated STA, send deauth. frame
16 * (8802.11: 5.5)
17 */
18
19static int other_ap_policy[MAX_PARM_DEVICES] = { AP_OTHER_AP_SKIP_ALL,
20 DEF_INTS };
21module_param_array(other_ap_policy, int, NULL, 0444);
22MODULE_PARM_DESC(other_ap_policy, "Other AP beacon monitoring policy (0-3)");
23
24static int ap_max_inactivity[MAX_PARM_DEVICES] = { AP_MAX_INACTIVITY_SEC,
25 DEF_INTS };
26module_param_array(ap_max_inactivity, int, NULL, 0444);
27MODULE_PARM_DESC(ap_max_inactivity, "AP timeout (in seconds) for station "
28 "inactivity");
29
30static int ap_bridge_packets[MAX_PARM_DEVICES] = { 1, DEF_INTS };
31module_param_array(ap_bridge_packets, int, NULL, 0444);
32MODULE_PARM_DESC(ap_bridge_packets, "Bridge packets directly between "
33 "stations");
34
35static int autom_ap_wds[MAX_PARM_DEVICES] = { 0, DEF_INTS };
36module_param_array(autom_ap_wds, int, NULL, 0444);
37MODULE_PARM_DESC(autom_ap_wds, "Add WDS connections to other APs "
38 "automatically");
39
40
41static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta);
42static void hostap_event_expired_sta(struct net_device *dev,
43 struct sta_info *sta);
44static void handle_add_proc_queue(void *data);
45
46#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
47static void handle_wds_oper_queue(void *data);
48static void prism2_send_mgmt(struct net_device *dev,
49 int type, int subtype, char *body,
50 int body_len, u8 *addr, u16 tx_cb_idx);
51#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
52
53
54#ifndef PRISM2_NO_PROCFS_DEBUG
55static int ap_debug_proc_read(char *page, char **start, off_t off,
56 int count, int *eof, void *data)
57{
58 char *p = page;
59 struct ap_data *ap = (struct ap_data *) data;
60
61 if (off != 0) {
62 *eof = 1;
63 return 0;
64 }
65
66 p += sprintf(p, "BridgedUnicastFrames=%u\n", ap->bridged_unicast);
67 p += sprintf(p, "BridgedMulticastFrames=%u\n", ap->bridged_multicast);
68 p += sprintf(p, "max_inactivity=%u\n", ap->max_inactivity / HZ);
69 p += sprintf(p, "bridge_packets=%u\n", ap->bridge_packets);
70 p += sprintf(p, "nullfunc_ack=%u\n", ap->nullfunc_ack);
71 p += sprintf(p, "autom_ap_wds=%u\n", ap->autom_ap_wds);
72 p += sprintf(p, "auth_algs=%u\n", ap->local->auth_algs);
73 p += sprintf(p, "tx_drop_nonassoc=%u\n", ap->tx_drop_nonassoc);
74
75 return (p - page);
76}
77#endif /* PRISM2_NO_PROCFS_DEBUG */
78
79
80static void ap_sta_hash_add(struct ap_data *ap, struct sta_info *sta)
81{
82 sta->hnext = ap->sta_hash[STA_HASH(sta->addr)];
83 ap->sta_hash[STA_HASH(sta->addr)] = sta;
84}
85
86static void ap_sta_hash_del(struct ap_data *ap, struct sta_info *sta)
87{
88 struct sta_info *s;
89
90 s = ap->sta_hash[STA_HASH(sta->addr)];
91 if (s == NULL) return;
92 if (memcmp(s->addr, sta->addr, ETH_ALEN) == 0) {
93 ap->sta_hash[STA_HASH(sta->addr)] = s->hnext;
94 return;
95 }
96
97 while (s->hnext != NULL && memcmp(s->hnext->addr, sta->addr, ETH_ALEN)
98 != 0)
99 s = s->hnext;
100 if (s->hnext != NULL)
101 s->hnext = s->hnext->hnext;
102 else
103 printk("AP: could not remove STA " MACSTR " from hash table\n",
104 MAC2STR(sta->addr));
105}
106
107static void ap_free_sta(struct ap_data *ap, struct sta_info *sta)
108{
109 if (sta->ap && sta->local)
110 hostap_event_expired_sta(sta->local->dev, sta);
111
112 if (ap->proc != NULL) {
113 char name[20];
114 sprintf(name, MACSTR, MAC2STR(sta->addr));
115 remove_proc_entry(name, ap->proc);
116 }
117
118 if (sta->crypt) {
119 sta->crypt->ops->deinit(sta->crypt->priv);
120 kfree(sta->crypt);
121 sta->crypt = NULL;
122 }
123
124 skb_queue_purge(&sta->tx_buf);
125
126 ap->num_sta--;
127#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
128 if (sta->aid > 0)
129 ap->sta_aid[sta->aid - 1] = NULL;
130
131 if (!sta->ap && sta->u.sta.challenge)
132 kfree(sta->u.sta.challenge);
133 del_timer(&sta->timer);
134#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
135
136 kfree(sta);
137}
138
139
140static void hostap_set_tim(local_info_t *local, int aid, int set)
141{
142 if (local->func->set_tim)
143 local->func->set_tim(local->dev, aid, set);
144}
145
146
147static void hostap_event_new_sta(struct net_device *dev, struct sta_info *sta)
148{
149 union iwreq_data wrqu;
150 memset(&wrqu, 0, sizeof(wrqu));
151 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
152 wrqu.addr.sa_family = ARPHRD_ETHER;
153 wireless_send_event(dev, IWEVREGISTERED, &wrqu, NULL);
154}
155
156
157static void hostap_event_expired_sta(struct net_device *dev,
158 struct sta_info *sta)
159{
160 union iwreq_data wrqu;
161 memset(&wrqu, 0, sizeof(wrqu));
162 memcpy(wrqu.addr.sa_data, sta->addr, ETH_ALEN);
163 wrqu.addr.sa_family = ARPHRD_ETHER;
164 wireless_send_event(dev, IWEVEXPIRED, &wrqu, NULL);
165}
166
167
168#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
169
170static void ap_handle_timer(unsigned long data)
171{
172 struct sta_info *sta = (struct sta_info *) data;
173 local_info_t *local;
174 struct ap_data *ap;
175 unsigned long next_time = 0;
176 int was_assoc;
177
178 if (sta == NULL || sta->local == NULL || sta->local->ap == NULL) {
179 PDEBUG(DEBUG_AP, "ap_handle_timer() called with NULL data\n");
180 return;
181 }
182
183 local = sta->local;
184 ap = local->ap;
185 was_assoc = sta->flags & WLAN_STA_ASSOC;
186
187 if (atomic_read(&sta->users) != 0)
188 next_time = jiffies + HZ;
189 else if ((sta->flags & WLAN_STA_PERM) && !(sta->flags & WLAN_STA_AUTH))
190 next_time = jiffies + ap->max_inactivity;
191
192 if (time_before(jiffies, sta->last_rx + ap->max_inactivity)) {
193 /* station activity detected; reset timeout state */
194 sta->timeout_next = STA_NULLFUNC;
195 next_time = sta->last_rx + ap->max_inactivity;
196 } else if (sta->timeout_next == STA_DISASSOC &&
197 !(sta->flags & WLAN_STA_PENDING_POLL)) {
198 /* STA ACKed data nullfunc frame poll */
199 sta->timeout_next = STA_NULLFUNC;
200 next_time = jiffies + ap->max_inactivity;
201 }
202
203 if (next_time) {
204 sta->timer.expires = next_time;
205 add_timer(&sta->timer);
206 return;
207 }
208
209 if (sta->ap)
210 sta->timeout_next = STA_DEAUTH;
211
212 if (sta->timeout_next == STA_DEAUTH && !(sta->flags & WLAN_STA_PERM)) {
213 spin_lock(&ap->sta_table_lock);
214 ap_sta_hash_del(ap, sta);
215 list_del(&sta->list);
216 spin_unlock(&ap->sta_table_lock);
217 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
218 } else if (sta->timeout_next == STA_DISASSOC)
219 sta->flags &= ~WLAN_STA_ASSOC;
220
221 if (was_assoc && !(sta->flags & WLAN_STA_ASSOC) && !sta->ap)
222 hostap_event_expired_sta(local->dev, sta);
223
224 if (sta->timeout_next == STA_DEAUTH && sta->aid > 0 &&
225 !skb_queue_empty(&sta->tx_buf)) {
226 hostap_set_tim(local, sta->aid, 0);
227 sta->flags &= ~WLAN_STA_TIM;
228 }
229
230 if (sta->ap) {
231 if (ap->autom_ap_wds) {
232 PDEBUG(DEBUG_AP, "%s: removing automatic WDS "
233 "connection to AP " MACSTR "\n",
234 local->dev->name, MAC2STR(sta->addr));
235 hostap_wds_link_oper(local, sta->addr, WDS_DEL);
236 }
237 } else if (sta->timeout_next == STA_NULLFUNC) {
238 /* send data frame to poll STA and check whether this frame
239 * is ACKed */
240 /* FIX: WLAN_FC_STYPE_NULLFUNC would be more appropriate, but
241 * it is apparently not retried so TX Exc events are not
242 * received for it */
243 sta->flags |= WLAN_STA_PENDING_POLL;
244 prism2_send_mgmt(local->dev, WLAN_FC_TYPE_DATA,
245 WLAN_FC_STYPE_DATA, NULL, 0,
246 sta->addr, ap->tx_callback_poll);
247 } else {
248 int deauth = sta->timeout_next == STA_DEAUTH;
249 u16 resp;
250 PDEBUG(DEBUG_AP, "%s: sending %s info to STA " MACSTR
251 "(last=%lu, jiffies=%lu)\n",
252 local->dev->name,
253 deauth ? "deauthentication" : "disassociation",
254 MAC2STR(sta->addr), sta->last_rx, jiffies);
255
256 resp = cpu_to_le16(deauth ? WLAN_REASON_PREV_AUTH_NOT_VALID :
257 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
258 prism2_send_mgmt(local->dev, WLAN_FC_TYPE_MGMT,
259 (deauth ? WLAN_FC_STYPE_DEAUTH :
260 WLAN_FC_STYPE_DISASSOC),
261 (char *) &resp, 2, sta->addr, 0);
262 }
263
264 if (sta->timeout_next == STA_DEAUTH) {
265 if (sta->flags & WLAN_STA_PERM) {
266 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " would have been "
267 "removed, but it has 'perm' flag\n",
268 local->dev->name, MAC2STR(sta->addr));
269 } else
270 ap_free_sta(ap, sta);
271 return;
272 }
273
274 if (sta->timeout_next == STA_NULLFUNC) {
275 sta->timeout_next = STA_DISASSOC;
276 sta->timer.expires = jiffies + AP_DISASSOC_DELAY;
277 } else {
278 sta->timeout_next = STA_DEAUTH;
279 sta->timer.expires = jiffies + AP_DEAUTH_DELAY;
280 }
281
282 add_timer(&sta->timer);
283}
284
285
286void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
287 int resend)
288{
289 u8 addr[ETH_ALEN];
290 u16 resp;
291 int i;
292
293 PDEBUG(DEBUG_AP, "%s: Deauthenticate all stations\n", dev->name);
294 memset(addr, 0xff, ETH_ALEN);
295
296 resp = __constant_cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
297
298 /* deauth message sent; try to resend it few times; the message is
299 * broadcast, so it may be delayed until next DTIM; there is not much
300 * else we can do at this point since the driver is going to be shut
301 * down */
302 for (i = 0; i < 5; i++) {
303 prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH,
304 (char *) &resp, 2, addr, 0);
305
306 if (!resend || ap->num_sta <= 0)
307 return;
308
309 mdelay(50);
310 }
311}
312
313
314static int ap_control_proc_read(char *page, char **start, off_t off,
315 int count, int *eof, void *data)
316{
317 char *p = page;
318 struct ap_data *ap = (struct ap_data *) data;
319 char *policy_txt;
320 struct list_head *ptr;
321 struct mac_entry *entry;
322
323 if (off != 0) {
324 *eof = 1;
325 return 0;
326 }
327
328 switch (ap->mac_restrictions.policy) {
329 case MAC_POLICY_OPEN:
330 policy_txt = "open";
331 break;
332 case MAC_POLICY_ALLOW:
333 policy_txt = "allow";
334 break;
335 case MAC_POLICY_DENY:
336 policy_txt = "deny";
337 break;
338 default:
339 policy_txt = "unknown";
340 break;
341 };
342 p += sprintf(p, "MAC policy: %s\n", policy_txt);
343 p += sprintf(p, "MAC entries: %u\n", ap->mac_restrictions.entries);
344 p += sprintf(p, "MAC list:\n");
345 spin_lock_bh(&ap->mac_restrictions.lock);
346 for (ptr = ap->mac_restrictions.mac_list.next;
347 ptr != &ap->mac_restrictions.mac_list; ptr = ptr->next) {
348 if (p - page > PAGE_SIZE - 80) {
349 p += sprintf(p, "All entries did not fit one page.\n");
350 break;
351 }
352
353 entry = list_entry(ptr, struct mac_entry, list);
354 p += sprintf(p, MACSTR "\n", MAC2STR(entry->addr));
355 }
356 spin_unlock_bh(&ap->mac_restrictions.lock);
357
358 return (p - page);
359}
360
361
362static int ap_control_add_mac(struct mac_restrictions *mac_restrictions,
363 u8 *mac)
364{
365 struct mac_entry *entry;
366
367 entry = kmalloc(sizeof(struct mac_entry), GFP_KERNEL);
368 if (entry == NULL)
369 return -1;
370
371 memcpy(entry->addr, mac, ETH_ALEN);
372
373 spin_lock_bh(&mac_restrictions->lock);
374 list_add_tail(&entry->list, &mac_restrictions->mac_list);
375 mac_restrictions->entries++;
376 spin_unlock_bh(&mac_restrictions->lock);
377
378 return 0;
379}
380
381
382static int ap_control_del_mac(struct mac_restrictions *mac_restrictions,
383 u8 *mac)
384{
385 struct list_head *ptr;
386 struct mac_entry *entry;
387
388 spin_lock_bh(&mac_restrictions->lock);
389 for (ptr = mac_restrictions->mac_list.next;
390 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
391 entry = list_entry(ptr, struct mac_entry, list);
392
393 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
394 list_del(ptr);
395 kfree(entry);
396 mac_restrictions->entries--;
397 spin_unlock_bh(&mac_restrictions->lock);
398 return 0;
399 }
400 }
401 spin_unlock_bh(&mac_restrictions->lock);
402 return -1;
403}
404
405
406static int ap_control_mac_deny(struct mac_restrictions *mac_restrictions,
407 u8 *mac)
408{
409 struct list_head *ptr;
410 struct mac_entry *entry;
411 int found = 0;
412
413 if (mac_restrictions->policy == MAC_POLICY_OPEN)
414 return 0;
415
416 spin_lock_bh(&mac_restrictions->lock);
417 for (ptr = mac_restrictions->mac_list.next;
418 ptr != &mac_restrictions->mac_list; ptr = ptr->next) {
419 entry = list_entry(ptr, struct mac_entry, list);
420
421 if (memcmp(entry->addr, mac, ETH_ALEN) == 0) {
422 found = 1;
423 break;
424 }
425 }
426 spin_unlock_bh(&mac_restrictions->lock);
427
428 if (mac_restrictions->policy == MAC_POLICY_ALLOW)
429 return !found;
430 else
431 return found;
432}
433
434
435static void ap_control_flush_macs(struct mac_restrictions *mac_restrictions)
436{
437 struct list_head *ptr, *n;
438 struct mac_entry *entry;
439
440 if (mac_restrictions->entries == 0)
441 return;
442
443 spin_lock_bh(&mac_restrictions->lock);
444 for (ptr = mac_restrictions->mac_list.next, n = ptr->next;
445 ptr != &mac_restrictions->mac_list;
446 ptr = n, n = ptr->next) {
447 entry = list_entry(ptr, struct mac_entry, list);
448 list_del(ptr);
449 kfree(entry);
450 }
451 mac_restrictions->entries = 0;
452 spin_unlock_bh(&mac_restrictions->lock);
453}
454
455
456static int ap_control_kick_mac(struct ap_data *ap, struct net_device *dev,
457 u8 *mac)
458{
459 struct sta_info *sta;
460 u16 resp;
461
462 spin_lock_bh(&ap->sta_table_lock);
463 sta = ap_get_sta(ap, mac);
464 if (sta) {
465 ap_sta_hash_del(ap, sta);
466 list_del(&sta->list);
467 }
468 spin_unlock_bh(&ap->sta_table_lock);
469
470 if (!sta)
471 return -EINVAL;
472
473 resp = cpu_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
474 prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH,
475 (char *) &resp, 2, sta->addr, 0);
476
477 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
478 hostap_event_expired_sta(dev, sta);
479
480 ap_free_sta(ap, sta);
481
482 return 0;
483}
484
485#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
486
487
488static void ap_control_kickall(struct ap_data *ap)
489{
490 struct list_head *ptr, *n;
491 struct sta_info *sta;
492
493 spin_lock_bh(&ap->sta_table_lock);
494 for (ptr = ap->sta_list.next, n = ptr->next; ptr != &ap->sta_list;
495 ptr = n, n = ptr->next) {
496 sta = list_entry(ptr, struct sta_info, list);
497 ap_sta_hash_del(ap, sta);
498 list_del(&sta->list);
499 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
500 hostap_event_expired_sta(sta->local->dev, sta);
501 ap_free_sta(ap, sta);
502 }
503 spin_unlock_bh(&ap->sta_table_lock);
504}
505
506
507#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
508
509#define PROC_LIMIT (PAGE_SIZE - 80)
510
511static int prism2_ap_proc_read(char *page, char **start, off_t off,
512 int count, int *eof, void *data)
513{
514 char *p = page;
515 struct ap_data *ap = (struct ap_data *) data;
516 struct list_head *ptr;
517 int i;
518
519 if (off > PROC_LIMIT) {
520 *eof = 1;
521 return 0;
522 }
523
524 p += sprintf(p, "# BSSID CHAN SIGNAL NOISE RATE SSID FLAGS\n");
525 spin_lock_bh(&ap->sta_table_lock);
526 for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
527 struct sta_info *sta = (struct sta_info *) ptr;
528
529 if (!sta->ap)
530 continue;
531
532 p += sprintf(p, MACSTR " %d %d %d %d '", MAC2STR(sta->addr),
533 sta->u.ap.channel, sta->last_rx_signal,
534 sta->last_rx_silence, sta->last_rx_rate);
535 for (i = 0; i < sta->u.ap.ssid_len; i++)
536 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
537 sta->u.ap.ssid[i] < 127) ?
538 "%c" : "<%02x>"),
539 sta->u.ap.ssid[i]);
540 p += sprintf(p, "'");
541 if (sta->capability & WLAN_CAPABILITY_ESS)
542 p += sprintf(p, " [ESS]");
543 if (sta->capability & WLAN_CAPABILITY_IBSS)
544 p += sprintf(p, " [IBSS]");
545 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
546 p += sprintf(p, " [WEP]");
547 p += sprintf(p, "\n");
548
549 if ((p - page) > PROC_LIMIT) {
550 printk(KERN_DEBUG "hostap: ap proc did not fit\n");
551 break;
552 }
553 }
554 spin_unlock_bh(&ap->sta_table_lock);
555
556 if ((p - page) <= off) {
557 *eof = 1;
558 return 0;
559 }
560
561 *start = page + off;
562
563 return (p - page - off);
564}
565#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
566
567
568void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver)
569{
570 if (!ap)
571 return;
572
573 if (sta_fw_ver == PRISM2_FW_VER(0,8,0)) {
574 PDEBUG(DEBUG_AP, "Using data::nullfunc ACK workaround - "
575 "firmware upgrade recommended\n");
576 ap->nullfunc_ack = 1;
577 } else
578 ap->nullfunc_ack = 0;
579
580 if (sta_fw_ver == PRISM2_FW_VER(1,4,2)) {
581 printk(KERN_WARNING "%s: Warning: secondary station firmware "
582 "version 1.4.2 does not seem to work in Host AP mode\n",
583 ap->local->dev->name);
584 }
585}
586
587
588/* Called only as a tasklet (software IRQ) */
589static void hostap_ap_tx_cb(struct sk_buff *skb, int ok, void *data)
590{
591 struct ap_data *ap = data;
592 u16 fc;
593 struct hostap_ieee80211_hdr *hdr;
594
595 if (!ap->local->hostapd || !ap->local->apdev) {
596 dev_kfree_skb(skb);
597 return;
598 }
599
600 hdr = (struct hostap_ieee80211_hdr *) skb->data;
601 fc = le16_to_cpu(hdr->frame_control);
602
603 /* Pass the TX callback frame to the hostapd; use 802.11 header version
604 * 1 to indicate failure (no ACK) and 2 success (frame ACKed) */
605
606 fc &= ~WLAN_FC_PVER;
607 fc |= ok ? BIT(1) : BIT(0);
608 hdr->frame_control = cpu_to_le16(fc);
609
610 skb->dev = ap->local->apdev;
611 skb_pull(skb, hostap_80211_get_hdrlen(fc));
612 skb->pkt_type = PACKET_OTHERHOST;
613 skb->protocol = __constant_htons(ETH_P_802_2);
614 memset(skb->cb, 0, sizeof(skb->cb));
615 netif_rx(skb);
616}
617
618
619#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
620/* Called only as a tasklet (software IRQ) */
621static void hostap_ap_tx_cb_auth(struct sk_buff *skb, int ok, void *data)
622{
623 struct ap_data *ap = data;
624 struct net_device *dev = ap->local->dev;
625 struct hostap_ieee80211_hdr *hdr;
626 u16 fc, *pos, auth_alg, auth_transaction, status;
627 struct sta_info *sta = NULL;
628 char *txt = NULL;
629
630 if (ap->local->hostapd) {
631 dev_kfree_skb(skb);
632 return;
633 }
634
635 hdr = (struct hostap_ieee80211_hdr *) skb->data;
636 fc = le16_to_cpu(hdr->frame_control);
637 if (HOSTAP_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
638 HOSTAP_FC_GET_STYPE(fc) != WLAN_FC_STYPE_AUTH ||
639 skb->len < IEEE80211_MGMT_HDR_LEN + 6) {
640 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_auth received invalid "
641 "frame\n", dev->name);
642 dev_kfree_skb(skb);
643 return;
644 }
645
646 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
647 auth_alg = le16_to_cpu(*pos++);
648 auth_transaction = le16_to_cpu(*pos++);
649 status = le16_to_cpu(*pos++);
650
651 if (!ok) {
652 txt = "frame was not ACKed";
653 goto done;
654 }
655
656 spin_lock(&ap->sta_table_lock);
657 sta = ap_get_sta(ap, hdr->addr1);
658 if (sta)
659 atomic_inc(&sta->users);
660 spin_unlock(&ap->sta_table_lock);
661
662 if (!sta) {
663 txt = "STA not found";
664 goto done;
665 }
666
667 if (status == WLAN_STATUS_SUCCESS &&
668 ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) ||
669 (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) {
670 txt = "STA authenticated";
671 sta->flags |= WLAN_STA_AUTH;
672 sta->last_auth = jiffies;
673 } else if (status != WLAN_STATUS_SUCCESS)
674 txt = "authentication failed";
675
676 done:
677 if (sta)
678 atomic_dec(&sta->users);
679 if (txt) {
680 PDEBUG(DEBUG_AP, "%s: " MACSTR " auth_cb - alg=%d trans#=%d "
681 "status=%d - %s\n",
682 dev->name, MAC2STR(hdr->addr1), auth_alg,
683 auth_transaction, status, txt);
684 }
685 dev_kfree_skb(skb);
686}
687
688
689/* Called only as a tasklet (software IRQ) */
690static void hostap_ap_tx_cb_assoc(struct sk_buff *skb, int ok, void *data)
691{
692 struct ap_data *ap = data;
693 struct net_device *dev = ap->local->dev;
694 struct hostap_ieee80211_hdr *hdr;
695 u16 fc, *pos, status;
696 struct sta_info *sta = NULL;
697 char *txt = NULL;
698
699 if (ap->local->hostapd) {
700 dev_kfree_skb(skb);
701 return;
702 }
703
704 hdr = (struct hostap_ieee80211_hdr *) skb->data;
705 fc = le16_to_cpu(hdr->frame_control);
706 if (HOSTAP_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
707 (HOSTAP_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ASSOC_RESP &&
708 HOSTAP_FC_GET_STYPE(fc) != WLAN_FC_STYPE_REASSOC_RESP) ||
709 skb->len < IEEE80211_MGMT_HDR_LEN + 4) {
710 printk(KERN_DEBUG "%s: hostap_ap_tx_cb_assoc received invalid "
711 "frame\n", dev->name);
712 dev_kfree_skb(skb);
713 return;
714 }
715
716 if (!ok) {
717 txt = "frame was not ACKed";
718 goto done;
719 }
720
721 spin_lock(&ap->sta_table_lock);
722 sta = ap_get_sta(ap, hdr->addr1);
723 if (sta)
724 atomic_inc(&sta->users);
725 spin_unlock(&ap->sta_table_lock);
726
727 if (!sta) {
728 txt = "STA not found";
729 goto done;
730 }
731
732 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
733 pos++;
734 status = le16_to_cpu(*pos++);
735 if (status == WLAN_STATUS_SUCCESS) {
736 if (!(sta->flags & WLAN_STA_ASSOC))
737 hostap_event_new_sta(dev, sta);
738 txt = "STA associated";
739 sta->flags |= WLAN_STA_ASSOC;
740 sta->last_assoc = jiffies;
741 } else
742 txt = "association failed";
743
744 done:
745 if (sta)
746 atomic_dec(&sta->users);
747 if (txt) {
748 PDEBUG(DEBUG_AP, "%s: " MACSTR " assoc_cb - %s\n",
749 dev->name, MAC2STR(hdr->addr1), txt);
750 }
751 dev_kfree_skb(skb);
752}
753
754/* Called only as a tasklet (software IRQ); TX callback for poll frames used
755 * in verifying whether the STA is still present. */
756static void hostap_ap_tx_cb_poll(struct sk_buff *skb, int ok, void *data)
757{
758 struct ap_data *ap = data;
759 struct hostap_ieee80211_hdr *hdr;
760 struct sta_info *sta;
761
762 if (skb->len < 24)
763 goto fail;
764 hdr = (struct hostap_ieee80211_hdr *) skb->data;
765 if (ok) {
766 spin_lock(&ap->sta_table_lock);
767 sta = ap_get_sta(ap, hdr->addr1);
768 if (sta)
769 sta->flags &= ~WLAN_STA_PENDING_POLL;
770 spin_unlock(&ap->sta_table_lock);
771 } else {
772 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " did not ACK activity "
773 "poll frame\n", ap->local->dev->name,
774 MAC2STR(hdr->addr1));
775 }
776
777 fail:
778 dev_kfree_skb(skb);
779}
780#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
781
782
783void hostap_init_data(local_info_t *local)
784{
785 struct ap_data *ap = local->ap;
786
787 if (ap == NULL) {
788 printk(KERN_WARNING "hostap_init_data: ap == NULL\n");
789 return;
790 }
791 memset(ap, 0, sizeof(struct ap_data));
792 ap->local = local;
793
794 ap->ap_policy = GET_INT_PARM(other_ap_policy, local->card_idx);
795 ap->bridge_packets = GET_INT_PARM(ap_bridge_packets, local->card_idx);
796 ap->max_inactivity =
797 GET_INT_PARM(ap_max_inactivity, local->card_idx) * HZ;
798 ap->autom_ap_wds = GET_INT_PARM(autom_ap_wds, local->card_idx);
799
800 spin_lock_init(&ap->sta_table_lock);
801 INIT_LIST_HEAD(&ap->sta_list);
802
803 /* Initialize task queue structure for AP management */
804 INIT_WORK(&local->ap->add_sta_proc_queue, handle_add_proc_queue, ap);
805
806 ap->tx_callback_idx =
807 hostap_tx_callback_register(local, hostap_ap_tx_cb, ap);
808 if (ap->tx_callback_idx == 0)
809 printk(KERN_WARNING "%s: failed to register TX callback for "
810 "AP\n", local->dev->name);
811#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
812 INIT_WORK(&local->ap->wds_oper_queue, handle_wds_oper_queue, local);
813
814 ap->tx_callback_auth =
815 hostap_tx_callback_register(local, hostap_ap_tx_cb_auth, ap);
816 ap->tx_callback_assoc =
817 hostap_tx_callback_register(local, hostap_ap_tx_cb_assoc, ap);
818 ap->tx_callback_poll =
819 hostap_tx_callback_register(local, hostap_ap_tx_cb_poll, ap);
820 if (ap->tx_callback_auth == 0 || ap->tx_callback_assoc == 0 ||
821 ap->tx_callback_poll == 0)
822 printk(KERN_WARNING "%s: failed to register TX callback for "
823 "AP\n", local->dev->name);
824
825 spin_lock_init(&ap->mac_restrictions.lock);
826 INIT_LIST_HEAD(&ap->mac_restrictions.mac_list);
827#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
828
829 ap->initialized = 1;
830}
831
832
833void hostap_init_ap_proc(local_info_t *local)
834{
835 struct ap_data *ap = local->ap;
836
837 ap->proc = local->proc;
838 if (ap->proc == NULL)
839 return;
840
841#ifndef PRISM2_NO_PROCFS_DEBUG
842 create_proc_read_entry("ap_debug", 0, ap->proc,
843 ap_debug_proc_read, ap);
844#endif /* PRISM2_NO_PROCFS_DEBUG */
845
846#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
847 create_proc_read_entry("ap_control", 0, ap->proc,
848 ap_control_proc_read, ap);
849 create_proc_read_entry("ap", 0, ap->proc,
850 prism2_ap_proc_read, ap);
851#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
852
853}
854
855
856void hostap_free_data(struct ap_data *ap)
857{
858 struct list_head *n, *ptr;
859
860 if (ap == NULL || !ap->initialized) {
861 printk(KERN_DEBUG "hostap_free_data: ap has not yet been "
862 "initialized - skip resource freeing\n");
863 return;
864 }
865
866#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
867 if (ap->crypt)
868 ap->crypt->deinit(ap->crypt_priv);
869 ap->crypt = ap->crypt_priv = NULL;
870#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
871
872 list_for_each_safe(ptr, n, &ap->sta_list) {
873 struct sta_info *sta = list_entry(ptr, struct sta_info, list);
874 ap_sta_hash_del(ap, sta);
875 list_del(&sta->list);
876 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
877 hostap_event_expired_sta(sta->local->dev, sta);
878 ap_free_sta(ap, sta);
879 }
880
881#ifndef PRISM2_NO_PROCFS_DEBUG
882 if (ap->proc != NULL) {
883 remove_proc_entry("ap_debug", ap->proc);
884 }
885#endif /* PRISM2_NO_PROCFS_DEBUG */
886
887#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
888 if (ap->proc != NULL) {
889 remove_proc_entry("ap", ap->proc);
890 remove_proc_entry("ap_control", ap->proc);
891 }
892 ap_control_flush_macs(&ap->mac_restrictions);
893#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
894
895 ap->initialized = 0;
896}
897
898
899/* caller should have mutex for AP STA list handling */
900static struct sta_info* ap_get_sta(struct ap_data *ap, u8 *sta)
901{
902 struct sta_info *s;
903
904 s = ap->sta_hash[STA_HASH(sta)];
905 while (s != NULL && memcmp(s->addr, sta, ETH_ALEN) != 0)
906 s = s->hnext;
907 return s;
908}
909
910
911#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
912
913/* Called from timer handler and from scheduled AP queue handlers */
914static void prism2_send_mgmt(struct net_device *dev,
915 int type, int subtype, char *body,
916 int body_len, u8 *addr, u16 tx_cb_idx)
917{
918 struct hostap_interface *iface;
919 local_info_t *local;
920 struct hostap_ieee80211_hdr *hdr;
921 u16 fc;
922 struct sk_buff *skb;
923 struct hostap_skb_tx_data *meta;
924 int hdrlen;
925
926 iface = netdev_priv(dev);
927 local = iface->local;
928 dev = local->dev; /* always use master radio device */
929 iface = netdev_priv(dev);
930
931 if (!(dev->flags & IFF_UP)) {
932 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt - device is not UP - "
933 "cannot send frame\n", dev->name);
934 return;
935 }
936
937 skb = dev_alloc_skb(sizeof(*hdr) + body_len);
938 if (skb == NULL) {
939 PDEBUG(DEBUG_AP, "%s: prism2_send_mgmt failed to allocate "
940 "skb\n", dev->name);
941 return;
942 }
943
944 fc = (type << 2) | (subtype << 4);
945 hdrlen = hostap_80211_get_hdrlen(fc);
946 hdr = (struct hostap_ieee80211_hdr *) skb_put(skb, hdrlen);
947 if (body)
948 memcpy(skb_put(skb, body_len), body, body_len);
949
950 memset(hdr, 0, hdrlen);
951
952 /* FIX: ctrl::ack sending used special HFA384X_TX_CTRL_802_11
953 * tx_control instead of using local->tx_control */
954
955
956 memcpy(hdr->addr1, addr, ETH_ALEN); /* DA / RA */
957 if (type == WLAN_FC_TYPE_DATA) {
958 fc |= WLAN_FC_FROMDS;
959 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* BSSID */
960 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* SA */
961 } else if (type == WLAN_FC_TYPE_CTRL) {
962 /* control:ACK does not have addr2 or addr3 */
963 memset(hdr->addr2, 0, ETH_ALEN);
964 memset(hdr->addr3, 0, ETH_ALEN);
965 } else {
966 memcpy(hdr->addr2, dev->dev_addr, ETH_ALEN); /* SA */
967 memcpy(hdr->addr3, dev->dev_addr, ETH_ALEN); /* BSSID */
968 }
969
970 hdr->frame_control = cpu_to_le16(fc);
971
972 meta = (struct hostap_skb_tx_data *) skb->cb;
973 memset(meta, 0, sizeof(*meta));
974 meta->magic = HOSTAP_SKB_TX_DATA_MAGIC;
975 meta->iface = iface;
976 meta->tx_cb_idx = tx_cb_idx;
977
978 skb->dev = dev;
979 skb->mac.raw = skb->nh.raw = skb->data;
980 dev_queue_xmit(skb);
981}
982#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
983
984
985static int prism2_sta_proc_read(char *page, char **start, off_t off,
986 int count, int *eof, void *data)
987{
988 char *p = page;
989 struct sta_info *sta = (struct sta_info *) data;
990 int i;
991
992 /* FIX: possible race condition.. the STA data could have just expired,
993 * but proc entry was still here so that the read could have started;
994 * some locking should be done here.. */
995
996 if (off != 0) {
997 *eof = 1;
998 return 0;
999 }
1000
1001 p += sprintf(p, "%s=" MACSTR "\nusers=%d\naid=%d\n"
1002 "flags=0x%04x%s%s%s%s%s%s%s\n"
1003 "capability=0x%02x\nlisten_interval=%d\nsupported_rates=",
1004 sta->ap ? "AP" : "STA",
1005 MAC2STR(sta->addr), atomic_read(&sta->users), sta->aid,
1006 sta->flags,
1007 sta->flags & WLAN_STA_AUTH ? " AUTH" : "",
1008 sta->flags & WLAN_STA_ASSOC ? " ASSOC" : "",
1009 sta->flags & WLAN_STA_PS ? " PS" : "",
1010 sta->flags & WLAN_STA_TIM ? " TIM" : "",
1011 sta->flags & WLAN_STA_PERM ? " PERM" : "",
1012 sta->flags & WLAN_STA_AUTHORIZED ? " AUTHORIZED" : "",
1013 sta->flags & WLAN_STA_PENDING_POLL ? " POLL" : "",
1014 sta->capability, sta->listen_interval);
1015 /* supported_rates: 500 kbit/s units with msb ignored */
1016 for (i = 0; i < sizeof(sta->supported_rates); i++)
1017 if (sta->supported_rates[i] != 0)
1018 p += sprintf(p, "%d%sMbps ",
1019 (sta->supported_rates[i] & 0x7f) / 2,
1020 sta->supported_rates[i] & 1 ? ".5" : "");
1021 p += sprintf(p, "\njiffies=%lu\nlast_auth=%lu\nlast_assoc=%lu\n"
1022 "last_rx=%lu\nlast_tx=%lu\nrx_packets=%lu\n"
1023 "tx_packets=%lu\n"
1024 "rx_bytes=%lu\ntx_bytes=%lu\nbuffer_count=%d\n"
1025 "last_rx: silence=%d dBm signal=%d dBm rate=%d%s Mbps\n"
1026 "tx_rate=%d\ntx[1M]=%d\ntx[2M]=%d\ntx[5.5M]=%d\n"
1027 "tx[11M]=%d\n"
1028 "rx[1M]=%d\nrx[2M]=%d\nrx[5.5M]=%d\nrx[11M]=%d\n",
1029 jiffies, sta->last_auth, sta->last_assoc, sta->last_rx,
1030 sta->last_tx,
1031 sta->rx_packets, sta->tx_packets, sta->rx_bytes,
1032 sta->tx_bytes, skb_queue_len(&sta->tx_buf),
1033 sta->last_rx_silence,
1034 sta->last_rx_signal, sta->last_rx_rate / 10,
1035 sta->last_rx_rate % 10 ? ".5" : "",
1036 sta->tx_rate, sta->tx_count[0], sta->tx_count[1],
1037 sta->tx_count[2], sta->tx_count[3], sta->rx_count[0],
1038 sta->rx_count[1], sta->rx_count[2], sta->rx_count[3]);
1039 if (sta->crypt && sta->crypt->ops && sta->crypt->ops->print_stats)
1040 p = sta->crypt->ops->print_stats(p, sta->crypt->priv);
1041#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1042 if (sta->ap) {
1043 if (sta->u.ap.channel >= 0)
1044 p += sprintf(p, "channel=%d\n", sta->u.ap.channel);
1045 p += sprintf(p, "ssid=");
1046 for (i = 0; i < sta->u.ap.ssid_len; i++)
1047 p += sprintf(p, ((sta->u.ap.ssid[i] >= 32 &&
1048 sta->u.ap.ssid[i] < 127) ?
1049 "%c" : "<%02x>"),
1050 sta->u.ap.ssid[i]);
1051 p += sprintf(p, "\n");
1052 }
1053#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1054
1055 return (p - page);
1056}
1057
1058
1059static void handle_add_proc_queue(void *data)
1060{
1061 struct ap_data *ap = (struct ap_data *) data;
1062 struct sta_info *sta;
1063 char name[20];
1064 struct add_sta_proc_data *entry, *prev;
1065
1066 entry = ap->add_sta_proc_entries;
1067 ap->add_sta_proc_entries = NULL;
1068
1069 while (entry) {
1070 spin_lock_bh(&ap->sta_table_lock);
1071 sta = ap_get_sta(ap, entry->addr);
1072 if (sta)
1073 atomic_inc(&sta->users);
1074 spin_unlock_bh(&ap->sta_table_lock);
1075
1076 if (sta) {
1077 sprintf(name, MACSTR, MAC2STR(sta->addr));
1078 sta->proc = create_proc_read_entry(
1079 name, 0, ap->proc,
1080 prism2_sta_proc_read, sta);
1081
1082 atomic_dec(&sta->users);
1083 }
1084
1085 prev = entry;
1086 entry = entry->next;
1087 kfree(prev);
1088 }
1089}
1090
1091
1092static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
1093{
1094 struct sta_info *sta;
1095
1096 sta = (struct sta_info *)
1097 kmalloc(sizeof(struct sta_info), GFP_ATOMIC);
1098 if (sta == NULL) {
1099 PDEBUG(DEBUG_AP, "AP: kmalloc failed\n");
1100 return NULL;
1101 }
1102
1103 /* initialize STA info data */
1104 memset(sta, 0, sizeof(struct sta_info));
1105 sta->local = ap->local;
1106 skb_queue_head_init(&sta->tx_buf);
1107 memcpy(sta->addr, addr, ETH_ALEN);
1108
1109 atomic_inc(&sta->users);
1110 spin_lock_bh(&ap->sta_table_lock);
1111 list_add(&sta->list, &ap->sta_list);
1112 ap->num_sta++;
1113 ap_sta_hash_add(ap, sta);
1114 spin_unlock_bh(&ap->sta_table_lock);
1115
1116 if (ap->proc) {
1117 struct add_sta_proc_data *entry;
1118 /* schedule a non-interrupt context process to add a procfs
1119 * entry for the STA since procfs code use GFP_KERNEL */
1120 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
1121 if (entry) {
1122 memcpy(entry->addr, sta->addr, ETH_ALEN);
1123 entry->next = ap->add_sta_proc_entries;
1124 ap->add_sta_proc_entries = entry;
1125 schedule_work(&ap->add_sta_proc_queue);
1126 } else
1127 printk(KERN_DEBUG "Failed to add STA proc data\n");
1128 }
1129
1130#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1131 init_timer(&sta->timer);
1132 sta->timer.expires = jiffies + ap->max_inactivity;
1133 sta->timer.data = (unsigned long) sta;
1134 sta->timer.function = ap_handle_timer;
1135 if (!ap->local->hostapd)
1136 add_timer(&sta->timer);
1137#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1138
1139 return sta;
1140}
1141
1142
1143static int ap_tx_rate_ok(int rateidx, struct sta_info *sta,
1144 local_info_t *local)
1145{
1146 if (rateidx > sta->tx_max_rate ||
1147 !(sta->tx_supp_rates & (1 << rateidx)))
1148 return 0;
1149
1150 if (local->tx_rate_control != 0 &&
1151 !(local->tx_rate_control & (1 << rateidx)))
1152 return 0;
1153
1154 return 1;
1155}
1156
1157
1158static void prism2_check_tx_rates(struct sta_info *sta)
1159{
1160 int i;
1161
1162 sta->tx_supp_rates = 0;
1163 for (i = 0; i < sizeof(sta->supported_rates); i++) {
1164 if ((sta->supported_rates[i] & 0x7f) == 2)
1165 sta->tx_supp_rates |= WLAN_RATE_1M;
1166 if ((sta->supported_rates[i] & 0x7f) == 4)
1167 sta->tx_supp_rates |= WLAN_RATE_2M;
1168 if ((sta->supported_rates[i] & 0x7f) == 11)
1169 sta->tx_supp_rates |= WLAN_RATE_5M5;
1170 if ((sta->supported_rates[i] & 0x7f) == 22)
1171 sta->tx_supp_rates |= WLAN_RATE_11M;
1172 }
1173 sta->tx_max_rate = sta->tx_rate = sta->tx_rate_idx = 0;
1174 if (sta->tx_supp_rates & WLAN_RATE_1M) {
1175 sta->tx_max_rate = 0;
1176 if (ap_tx_rate_ok(0, sta, sta->local)) {
1177 sta->tx_rate = 10;
1178 sta->tx_rate_idx = 0;
1179 }
1180 }
1181 if (sta->tx_supp_rates & WLAN_RATE_2M) {
1182 sta->tx_max_rate = 1;
1183 if (ap_tx_rate_ok(1, sta, sta->local)) {
1184 sta->tx_rate = 20;
1185 sta->tx_rate_idx = 1;
1186 }
1187 }
1188 if (sta->tx_supp_rates & WLAN_RATE_5M5) {
1189 sta->tx_max_rate = 2;
1190 if (ap_tx_rate_ok(2, sta, sta->local)) {
1191 sta->tx_rate = 55;
1192 sta->tx_rate_idx = 2;
1193 }
1194 }
1195 if (sta->tx_supp_rates & WLAN_RATE_11M) {
1196 sta->tx_max_rate = 3;
1197 if (ap_tx_rate_ok(3, sta, sta->local)) {
1198 sta->tx_rate = 110;
1199 sta->tx_rate_idx = 3;
1200 }
1201 }
1202}
1203
1204
1205#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1206
1207static void ap_crypt_init(struct ap_data *ap)
1208{
1209 ap->crypt = ieee80211_get_crypto_ops("WEP");
1210
1211 if (ap->crypt) {
1212 if (ap->crypt->init) {
1213 ap->crypt_priv = ap->crypt->init(0);
1214 if (ap->crypt_priv == NULL)
1215 ap->crypt = NULL;
1216 else {
1217 u8 key[WEP_KEY_LEN];
1218 get_random_bytes(key, WEP_KEY_LEN);
1219 ap->crypt->set_key(key, WEP_KEY_LEN, NULL,
1220 ap->crypt_priv);
1221 }
1222 }
1223 }
1224
1225 if (ap->crypt == NULL) {
1226 printk(KERN_WARNING "AP could not initialize WEP: load module "
1227 "ieee80211_crypt_wep.ko\n");
1228 }
1229}
1230
1231
1232/* Generate challenge data for shared key authentication. IEEE 802.11 specifies
1233 * that WEP algorithm is used for generating challange. This should be unique,
1234 * but otherwise there is not really need for randomness etc. Initialize WEP
1235 * with pseudo random key and then use increasing IV to get unique challenge
1236 * streams.
1237 *
1238 * Called only as a scheduled task for pending AP frames.
1239 */
1240static char * ap_auth_make_challenge(struct ap_data *ap)
1241{
1242 char *tmpbuf;
1243 struct sk_buff *skb;
1244
1245 if (ap->crypt == NULL) {
1246 ap_crypt_init(ap);
1247 if (ap->crypt == NULL)
1248 return NULL;
1249 }
1250
1251 tmpbuf = (char *) kmalloc(WLAN_AUTH_CHALLENGE_LEN, GFP_ATOMIC);
1252 if (tmpbuf == NULL) {
1253 PDEBUG(DEBUG_AP, "AP: kmalloc failed for challenge\n");
1254 return NULL;
1255 }
1256
1257 skb = dev_alloc_skb(WLAN_AUTH_CHALLENGE_LEN +
1258 ap->crypt->extra_prefix_len +
1259 ap->crypt->extra_postfix_len);
1260 if (skb == NULL) {
1261 kfree(tmpbuf);
1262 return NULL;
1263 }
1264
1265 skb_reserve(skb, ap->crypt->extra_prefix_len);
1266 memset(skb_put(skb, WLAN_AUTH_CHALLENGE_LEN), 0,
1267 WLAN_AUTH_CHALLENGE_LEN);
1268 if (ap->crypt->encrypt_mpdu(skb, 0, ap->crypt_priv)) {
1269 dev_kfree_skb(skb);
1270 kfree(tmpbuf);
1271 return NULL;
1272 }
1273
1274 memcpy(tmpbuf, skb->data + ap->crypt->extra_prefix_len,
1275 WLAN_AUTH_CHALLENGE_LEN);
1276 dev_kfree_skb(skb);
1277
1278 return tmpbuf;
1279}
1280
1281
1282/* Called only as a scheduled task for pending AP frames. */
1283static void handle_authen(local_info_t *local, struct sk_buff *skb,
1284 struct hostap_80211_rx_status *rx_stats)
1285{
1286 struct net_device *dev = local->dev;
1287 struct hostap_ieee80211_hdr *hdr =
1288 (struct hostap_ieee80211_hdr *) skb->data;
1289 size_t hdrlen;
1290 struct ap_data *ap = local->ap;
1291 char body[8 + WLAN_AUTH_CHALLENGE_LEN], *challenge = NULL;
1292 int len, olen;
1293 u16 auth_alg, auth_transaction, status_code, *pos;
1294 u16 resp = WLAN_STATUS_SUCCESS, fc;
1295 struct sta_info *sta = NULL;
1296 struct ieee80211_crypt_data *crypt;
1297 char *txt = "";
1298
1299 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1300
1301 fc = le16_to_cpu(hdr->frame_control);
1302 hdrlen = hostap_80211_get_hdrlen(fc);
1303
1304 if (len < 6) {
1305 PDEBUG(DEBUG_AP, "%s: handle_authen - too short payload "
1306 "(len=%d) from " MACSTR "\n", dev->name, len,
1307 MAC2STR(hdr->addr2));
1308 return;
1309 }
1310
1311 spin_lock_bh(&local->ap->sta_table_lock);
1312 sta = ap_get_sta(local->ap, hdr->addr2);
1313 if (sta)
1314 atomic_inc(&sta->users);
1315 spin_unlock_bh(&local->ap->sta_table_lock);
1316
1317 if (sta && sta->crypt)
1318 crypt = sta->crypt;
1319 else {
1320 int idx = 0;
1321 if (skb->len >= hdrlen + 3)
1322 idx = skb->data[hdrlen + 3] >> 6;
1323 crypt = local->crypt[idx];
1324 }
1325
1326 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1327 auth_alg = __le16_to_cpu(*pos);
1328 pos++;
1329 auth_transaction = __le16_to_cpu(*pos);
1330 pos++;
1331 status_code = __le16_to_cpu(*pos);
1332 pos++;
1333
1334 if (memcmp(dev->dev_addr, hdr->addr2, ETH_ALEN) == 0 ||
1335 ap_control_mac_deny(&ap->mac_restrictions, hdr->addr2)) {
1336 txt = "authentication denied";
1337 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1338 goto fail;
1339 }
1340
1341 if (((local->auth_algs & PRISM2_AUTH_OPEN) &&
1342 auth_alg == WLAN_AUTH_OPEN) ||
1343 ((local->auth_algs & PRISM2_AUTH_SHARED_KEY) &&
1344 crypt && auth_alg == WLAN_AUTH_SHARED_KEY)) {
1345 } else {
1346 txt = "unsupported algorithm";
1347 resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG;
1348 goto fail;
1349 }
1350
1351 if (len >= 8) {
1352 u8 *u = (u8 *) pos;
1353 if (*u == WLAN_EID_CHALLENGE) {
1354 if (*(u + 1) != WLAN_AUTH_CHALLENGE_LEN) {
1355 txt = "invalid challenge len";
1356 resp = WLAN_STATUS_CHALLENGE_FAIL;
1357 goto fail;
1358 }
1359 if (len - 8 < WLAN_AUTH_CHALLENGE_LEN) {
1360 txt = "challenge underflow";
1361 resp = WLAN_STATUS_CHALLENGE_FAIL;
1362 goto fail;
1363 }
1364 challenge = (char *) (u + 2);
1365 }
1366 }
1367
1368 if (sta && sta->ap) {
1369 if (time_after(jiffies, sta->u.ap.last_beacon +
1370 (10 * sta->listen_interval * HZ) / 1024)) {
1371 PDEBUG(DEBUG_AP, "%s: no beacons received for a while,"
1372 " assuming AP " MACSTR " is now STA\n",
1373 dev->name, MAC2STR(sta->addr));
1374 sta->ap = 0;
1375 sta->flags = 0;
1376 sta->u.sta.challenge = NULL;
1377 } else {
1378 txt = "AP trying to authenticate?";
1379 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1380 goto fail;
1381 }
1382 }
1383
1384 if ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 1) ||
1385 (auth_alg == WLAN_AUTH_SHARED_KEY &&
1386 (auth_transaction == 1 ||
1387 (auth_transaction == 3 && sta != NULL &&
1388 sta->u.sta.challenge != NULL)))) {
1389 } else {
1390 txt = "unknown authentication transaction number";
1391 resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION;
1392 goto fail;
1393 }
1394
1395 if (sta == NULL) {
1396 txt = "new STA";
1397
1398 if (local->ap->num_sta >= MAX_STA_COUNT) {
1399 /* FIX: might try to remove some old STAs first? */
1400 txt = "no more room for new STAs";
1401 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1402 goto fail;
1403 }
1404
1405 sta = ap_add_sta(local->ap, hdr->addr2);
1406 if (sta == NULL) {
1407 txt = "ap_add_sta failed";
1408 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1409 goto fail;
1410 }
1411 }
1412
1413 switch (auth_alg) {
1414 case WLAN_AUTH_OPEN:
1415 txt = "authOK";
1416 /* IEEE 802.11 standard is not completely clear about
1417 * whether STA is considered authenticated after
1418 * authentication OK frame has been send or after it
1419 * has been ACKed. In order to reduce interoperability
1420 * issues, mark the STA authenticated before ACK. */
1421 sta->flags |= WLAN_STA_AUTH;
1422 break;
1423
1424 case WLAN_AUTH_SHARED_KEY:
1425 if (auth_transaction == 1) {
1426 if (sta->u.sta.challenge == NULL) {
1427 sta->u.sta.challenge =
1428 ap_auth_make_challenge(local->ap);
1429 if (sta->u.sta.challenge == NULL) {
1430 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1431 goto fail;
1432 }
1433 }
1434 } else {
1435 if (sta->u.sta.challenge == NULL ||
1436 challenge == NULL ||
1437 memcmp(sta->u.sta.challenge, challenge,
1438 WLAN_AUTH_CHALLENGE_LEN) != 0 ||
1439 !(fc & WLAN_FC_ISWEP)) {
1440 txt = "challenge response incorrect";
1441 resp = WLAN_STATUS_CHALLENGE_FAIL;
1442 goto fail;
1443 }
1444
1445 txt = "challenge OK - authOK";
1446 /* IEEE 802.11 standard is not completely clear about
1447 * whether STA is considered authenticated after
1448 * authentication OK frame has been send or after it
1449 * has been ACKed. In order to reduce interoperability
1450 * issues, mark the STA authenticated before ACK. */
1451 sta->flags |= WLAN_STA_AUTH;
1452 kfree(sta->u.sta.challenge);
1453 sta->u.sta.challenge = NULL;
1454 }
1455 break;
1456 }
1457
1458 fail:
1459 pos = (u16 *) body;
1460 *pos = cpu_to_le16(auth_alg);
1461 pos++;
1462 *pos = cpu_to_le16(auth_transaction + 1);
1463 pos++;
1464 *pos = cpu_to_le16(resp); /* status_code */
1465 pos++;
1466 olen = 6;
1467
1468 if (resp == WLAN_STATUS_SUCCESS && sta != NULL &&
1469 sta->u.sta.challenge != NULL &&
1470 auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 1) {
1471 u8 *tmp = (u8 *) pos;
1472 *tmp++ = WLAN_EID_CHALLENGE;
1473 *tmp++ = WLAN_AUTH_CHALLENGE_LEN;
1474 pos++;
1475 memcpy(pos, sta->u.sta.challenge, WLAN_AUTH_CHALLENGE_LEN);
1476 olen += 2 + WLAN_AUTH_CHALLENGE_LEN;
1477 }
1478
1479 prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_AUTH,
1480 body, olen, hdr->addr2, ap->tx_callback_auth);
1481
1482 if (sta) {
1483 sta->last_rx = jiffies;
1484 atomic_dec(&sta->users);
1485 }
1486
1487 if (resp) {
1488 PDEBUG(DEBUG_AP, "%s: " MACSTR " auth (alg=%d trans#=%d "
1489 "stat=%d len=%d fc=%04x) ==> %d (%s)\n",
1490 dev->name, MAC2STR(hdr->addr2), auth_alg,
1491 auth_transaction, status_code, len, fc, resp, txt);
1492 }
1493}
1494
1495
1496/* Called only as a scheduled task for pending AP frames. */
1497static void handle_assoc(local_info_t *local, struct sk_buff *skb,
1498 struct hostap_80211_rx_status *rx_stats, int reassoc)
1499{
1500 struct net_device *dev = local->dev;
1501 struct hostap_ieee80211_hdr *hdr =
1502 (struct hostap_ieee80211_hdr *) skb->data;
1503 char body[12], *p, *lpos;
1504 int len, left;
1505 u16 *pos;
1506 u16 resp = WLAN_STATUS_SUCCESS;
1507 struct sta_info *sta = NULL;
1508 int send_deauth = 0;
1509 char *txt = "";
1510 u8 prev_ap[ETH_ALEN];
1511
1512 left = len = skb->len - IEEE80211_MGMT_HDR_LEN;
1513
1514 if (len < (reassoc ? 10 : 4)) {
1515 PDEBUG(DEBUG_AP, "%s: handle_assoc - too short payload "
1516 "(len=%d, reassoc=%d) from " MACSTR "\n",
1517 dev->name, len, reassoc, MAC2STR(hdr->addr2));
1518 return;
1519 }
1520
1521 spin_lock_bh(&local->ap->sta_table_lock);
1522 sta = ap_get_sta(local->ap, hdr->addr2);
1523 if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) {
1524 spin_unlock_bh(&local->ap->sta_table_lock);
1525 txt = "trying to associate before authentication";
1526 send_deauth = 1;
1527 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1528 sta = NULL; /* do not decrement sta->users */
1529 goto fail;
1530 }
1531 atomic_inc(&sta->users);
1532 spin_unlock_bh(&local->ap->sta_table_lock);
1533
1534 pos = (u16 *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1535 sta->capability = __le16_to_cpu(*pos);
1536 pos++; left -= 2;
1537 sta->listen_interval = __le16_to_cpu(*pos);
1538 pos++; left -= 2;
1539
1540 if (reassoc) {
1541 memcpy(prev_ap, pos, ETH_ALEN);
1542 pos++; pos++; pos++; left -= 6;
1543 } else
1544 memset(prev_ap, 0, ETH_ALEN);
1545
1546 if (left >= 2) {
1547 unsigned int ileft;
1548 unsigned char *u = (unsigned char *) pos;
1549
1550 if (*u == WLAN_EID_SSID) {
1551 u++; left--;
1552 ileft = *u;
1553 u++; left--;
1554
1555 if (ileft > left || ileft > MAX_SSID_LEN) {
1556 txt = "SSID overflow";
1557 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1558 goto fail;
1559 }
1560
1561 if (ileft != strlen(local->essid) ||
1562 memcmp(local->essid, u, ileft) != 0) {
1563 txt = "not our SSID";
1564 resp = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
1565 goto fail;
1566 }
1567
1568 u += ileft;
1569 left -= ileft;
1570 }
1571
1572 if (left >= 2 && *u == WLAN_EID_SUPP_RATES) {
1573 u++; left--;
1574 ileft = *u;
1575 u++; left--;
1576
1577 if (ileft > left || ileft == 0 ||
1578 ileft > WLAN_SUPP_RATES_MAX) {
1579 txt = "SUPP_RATES len error";
1580 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1581 goto fail;
1582 }
1583
1584 memset(sta->supported_rates, 0,
1585 sizeof(sta->supported_rates));
1586 memcpy(sta->supported_rates, u, ileft);
1587 prism2_check_tx_rates(sta);
1588
1589 u += ileft;
1590 left -= ileft;
1591 }
1592
1593 if (left > 0) {
1594 PDEBUG(DEBUG_AP, "%s: assoc from " MACSTR " with extra"
1595 " data (%d bytes) [",
1596 dev->name, MAC2STR(hdr->addr2), left);
1597 while (left > 0) {
1598 PDEBUG2(DEBUG_AP, "<%02x>", *u);
1599 u++; left--;
1600 }
1601 PDEBUG2(DEBUG_AP, "]\n");
1602 }
1603 } else {
1604 txt = "frame underflow";
1605 resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
1606 goto fail;
1607 }
1608
1609 /* get a unique AID */
1610 if (sta->aid > 0)
1611 txt = "OK, old AID";
1612 else {
1613 spin_lock_bh(&local->ap->sta_table_lock);
1614 for (sta->aid = 1; sta->aid <= MAX_AID_TABLE_SIZE; sta->aid++)
1615 if (local->ap->sta_aid[sta->aid - 1] == NULL)
1616 break;
1617 if (sta->aid > MAX_AID_TABLE_SIZE) {
1618 sta->aid = 0;
1619 spin_unlock_bh(&local->ap->sta_table_lock);
1620 resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
1621 txt = "no room for more AIDs";
1622 } else {
1623 local->ap->sta_aid[sta->aid - 1] = sta;
1624 spin_unlock_bh(&local->ap->sta_table_lock);
1625 txt = "OK, new AID";
1626 }
1627 }
1628
1629 fail:
1630 pos = (u16 *) body;
1631
1632 if (send_deauth) {
1633 *pos = __constant_cpu_to_le16(
1634 WLAN_REASON_STA_REQ_ASSOC_WITHOUT_AUTH);
1635 pos++;
1636 } else {
1637 /* FIX: CF-Pollable and CF-PollReq should be set to match the
1638 * values in beacons/probe responses */
1639 /* FIX: how about privacy and WEP? */
1640 /* capability */
1641 *pos = __constant_cpu_to_le16(WLAN_CAPABILITY_ESS);
1642 pos++;
1643
1644 /* status_code */
1645 *pos = __cpu_to_le16(resp);
1646 pos++;
1647
1648 *pos = __cpu_to_le16((sta && sta->aid > 0 ? sta->aid : 0) |
1649 BIT(14) | BIT(15)); /* AID */
1650 pos++;
1651
1652 /* Supported rates (Information element) */
1653 p = (char *) pos;
1654 *p++ = WLAN_EID_SUPP_RATES;
1655 lpos = p;
1656 *p++ = 0; /* len */
1657 if (local->tx_rate_control & WLAN_RATE_1M) {
1658 *p++ = local->basic_rates & WLAN_RATE_1M ? 0x82 : 0x02;
1659 (*lpos)++;
1660 }
1661 if (local->tx_rate_control & WLAN_RATE_2M) {
1662 *p++ = local->basic_rates & WLAN_RATE_2M ? 0x84 : 0x04;
1663 (*lpos)++;
1664 }
1665 if (local->tx_rate_control & WLAN_RATE_5M5) {
1666 *p++ = local->basic_rates & WLAN_RATE_5M5 ?
1667 0x8b : 0x0b;
1668 (*lpos)++;
1669 }
1670 if (local->tx_rate_control & WLAN_RATE_11M) {
1671 *p++ = local->basic_rates & WLAN_RATE_11M ?
1672 0x96 : 0x16;
1673 (*lpos)++;
1674 }
1675 pos = (u16 *) p;
1676 }
1677
1678 prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT,
1679 (send_deauth ? WLAN_FC_STYPE_DEAUTH :
1680 (reassoc ? WLAN_FC_STYPE_REASSOC_RESP :
1681 WLAN_FC_STYPE_ASSOC_RESP)),
1682 body, (u8 *) pos - (u8 *) body,
1683 hdr->addr2,
1684 send_deauth ? 0 : local->ap->tx_callback_assoc);
1685
1686 if (sta) {
1687 if (resp == WLAN_STATUS_SUCCESS) {
1688 sta->last_rx = jiffies;
1689 /* STA will be marked associated from TX callback, if
1690 * AssocResp is ACKed */
1691 }
1692 atomic_dec(&sta->users);
1693 }
1694
1695#if 0
1696 PDEBUG(DEBUG_AP, "%s: " MACSTR " %sassoc (len=%d prev_ap=" MACSTR
1697 ") => %d(%d) (%s)\n",
1698 dev->name, MAC2STR(hdr->addr2), reassoc ? "re" : "", len,
1699 MAC2STR(prev_ap), resp, send_deauth, txt);
1700#endif
1701}
1702
1703
1704/* Called only as a scheduled task for pending AP frames. */
1705static void handle_deauth(local_info_t *local, struct sk_buff *skb,
1706 struct hostap_80211_rx_status *rx_stats)
1707{
1708 struct net_device *dev = local->dev;
1709 struct hostap_ieee80211_hdr *hdr =
1710 (struct hostap_ieee80211_hdr *) skb->data;
1711 char *body = (char *) (skb->data + IEEE80211_MGMT_HDR_LEN);
1712 int len;
1713 u16 reason_code, *pos;
1714 struct sta_info *sta = NULL;
1715
1716 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1717
1718 if (len < 2) {
1719 printk("handle_deauth - too short payload (len=%d)\n", len);
1720 return;
1721 }
1722
1723 pos = (u16 *) body;
1724 reason_code = __le16_to_cpu(*pos);
1725
1726 PDEBUG(DEBUG_AP, "%s: deauthentication: " MACSTR " len=%d, "
1727 "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
1728 reason_code);
1729
1730 spin_lock_bh(&local->ap->sta_table_lock);
1731 sta = ap_get_sta(local->ap, hdr->addr2);
1732 if (sta != NULL) {
1733 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1734 hostap_event_expired_sta(local->dev, sta);
1735 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
1736 }
1737 spin_unlock_bh(&local->ap->sta_table_lock);
1738 if (sta == NULL) {
1739 printk("%s: deauthentication from " MACSTR ", "
1740 "reason_code=%d, but STA not authenticated\n", dev->name,
1741 MAC2STR(hdr->addr2), reason_code);
1742 }
1743}
1744
1745
1746/* Called only as a scheduled task for pending AP frames. */
1747static void handle_disassoc(local_info_t *local, struct sk_buff *skb,
1748 struct hostap_80211_rx_status *rx_stats)
1749{
1750 struct net_device *dev = local->dev;
1751 struct hostap_ieee80211_hdr *hdr =
1752 (struct hostap_ieee80211_hdr *) skb->data;
1753 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1754 int len;
1755 u16 reason_code, *pos;
1756 struct sta_info *sta = NULL;
1757
1758 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1759
1760 if (len < 2) {
1761 printk("handle_disassoc - too short payload (len=%d)\n", len);
1762 return;
1763 }
1764
1765 pos = (u16 *) body;
1766 reason_code = __le16_to_cpu(*pos);
1767
1768 PDEBUG(DEBUG_AP, "%s: disassociation: " MACSTR " len=%d, "
1769 "reason_code=%d\n", dev->name, MAC2STR(hdr->addr2), len,
1770 reason_code);
1771
1772 spin_lock_bh(&local->ap->sta_table_lock);
1773 sta = ap_get_sta(local->ap, hdr->addr2);
1774 if (sta != NULL) {
1775 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap)
1776 hostap_event_expired_sta(local->dev, sta);
1777 sta->flags &= ~WLAN_STA_ASSOC;
1778 }
1779 spin_unlock_bh(&local->ap->sta_table_lock);
1780 if (sta == NULL) {
1781 printk("%s: disassociation from " MACSTR ", "
1782 "reason_code=%d, but STA not authenticated\n",
1783 dev->name, MAC2STR(hdr->addr2), reason_code);
1784 }
1785}
1786
1787
1788/* Called only as a scheduled task for pending AP frames. */
1789static void ap_handle_data_nullfunc(local_info_t *local,
1790 struct hostap_ieee80211_hdr *hdr)
1791{
1792 struct net_device *dev = local->dev;
1793
1794 /* some STA f/w's seem to require control::ACK frame for
1795 * data::nullfunc, but at least Prism2 station f/w version 0.8.0 does
1796 * not send this..
1797 * send control::ACK for the data::nullfunc */
1798
1799 printk(KERN_DEBUG "Sending control::ACK for data::nullfunc\n");
1800 prism2_send_mgmt(dev, WLAN_FC_TYPE_CTRL, WLAN_FC_STYPE_ACK,
1801 NULL, 0, hdr->addr2, 0);
1802}
1803
1804
1805/* Called only as a scheduled task for pending AP frames. */
1806static void ap_handle_dropped_data(local_info_t *local,
1807 struct hostap_ieee80211_hdr *hdr)
1808{
1809 struct net_device *dev = local->dev;
1810 struct sta_info *sta;
1811 u16 reason;
1812
1813 spin_lock_bh(&local->ap->sta_table_lock);
1814 sta = ap_get_sta(local->ap, hdr->addr2);
1815 if (sta)
1816 atomic_inc(&sta->users);
1817 spin_unlock_bh(&local->ap->sta_table_lock);
1818
1819 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC)) {
1820 PDEBUG(DEBUG_AP, "ap_handle_dropped_data: STA is now okay?\n");
1821 atomic_dec(&sta->users);
1822 return;
1823 }
1824
1825 reason = __constant_cpu_to_le16(
1826 WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA);
1827 prism2_send_mgmt(dev, WLAN_FC_TYPE_MGMT,
1828 ((sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) ?
1829 WLAN_FC_STYPE_DEAUTH : WLAN_FC_STYPE_DISASSOC),
1830 (char *) &reason, sizeof(reason), hdr->addr2, 0);
1831
1832 if (sta)
1833 atomic_dec(&sta->users);
1834}
1835
1836#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
1837
1838
1839/* Called only as a scheduled task for pending AP frames. */
1840static void pspoll_send_buffered(local_info_t *local, struct sta_info *sta,
1841 struct sk_buff *skb)
1842{
1843 if (!(sta->flags & WLAN_STA_PS)) {
1844 /* Station has moved to non-PS mode, so send all buffered
1845 * frames using normal device queue. */
1846 dev_queue_xmit(skb);
1847 return;
1848 }
1849
1850 /* add a flag for hostap_handle_sta_tx() to know that this skb should
1851 * be passed through even though STA is using PS */
1852 memcpy(skb->cb, AP_SKB_CB_MAGIC, AP_SKB_CB_MAGIC_LEN);
1853 skb->cb[AP_SKB_CB_MAGIC_LEN] = AP_SKB_CB_BUFFERED_FRAME;
1854 if (!skb_queue_empty(&sta->tx_buf)) {
1855 /* indicate to STA that more frames follow */
1856 skb->cb[AP_SKB_CB_MAGIC_LEN] |= AP_SKB_CB_ADD_MOREDATA;
1857 }
1858 dev_queue_xmit(skb);
1859}
1860
1861
1862/* Called only as a scheduled task for pending AP frames. */
1863static void handle_pspoll(local_info_t *local,
1864 struct hostap_ieee80211_hdr *hdr,
1865 struct hostap_80211_rx_status *rx_stats)
1866{
1867 struct net_device *dev = local->dev;
1868 struct sta_info *sta;
1869 u16 aid;
1870 struct sk_buff *skb;
1871
1872 PDEBUG(DEBUG_PS2, "handle_pspoll: BSSID=" MACSTR ", TA=" MACSTR
1873 " PWRMGT=%d\n",
1874 MAC2STR(hdr->addr1), MAC2STR(hdr->addr2),
1875 !!(le16_to_cpu(hdr->frame_control) & WLAN_FC_PWRMGT));
1876
1877 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
1878 PDEBUG(DEBUG_AP, "handle_pspoll - addr1(BSSID)=" MACSTR
1879 " not own MAC\n", MAC2STR(hdr->addr1));
1880 return;
1881 }
1882
1883 aid = __le16_to_cpu(hdr->duration_id);
1884 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) {
1885 PDEBUG(DEBUG_PS, " PSPOLL and AID[15:14] not set\n");
1886 return;
1887 }
1888 aid &= ~BIT(15) & ~BIT(14);
1889 if (aid == 0 || aid > MAX_AID_TABLE_SIZE) {
1890 PDEBUG(DEBUG_PS, " invalid aid=%d\n", aid);
1891 return;
1892 }
1893 PDEBUG(DEBUG_PS2, " aid=%d\n", aid);
1894
1895 spin_lock_bh(&local->ap->sta_table_lock);
1896 sta = ap_get_sta(local->ap, hdr->addr2);
1897 if (sta)
1898 atomic_inc(&sta->users);
1899 spin_unlock_bh(&local->ap->sta_table_lock);
1900
1901 if (sta == NULL) {
1902 PDEBUG(DEBUG_PS, " STA not found\n");
1903 return;
1904 }
1905 if (sta->aid != aid) {
1906 PDEBUG(DEBUG_PS, " received aid=%i does not match with "
1907 "assoc.aid=%d\n", aid, sta->aid);
1908 return;
1909 }
1910
1911 /* FIX: todo:
1912 * - add timeout for buffering (clear aid in TIM vector if buffer timed
1913 * out (expiry time must be longer than ListenInterval for
1914 * the corresponding STA; "8802-11: 11.2.1.9 AP aging function"
1915 * - what to do, if buffered, pspolled, and sent frame is not ACKed by
1916 * sta; store buffer for later use and leave TIM aid bit set? use
1917 * TX event to check whether frame was ACKed?
1918 */
1919
1920 while ((skb = skb_dequeue(&sta->tx_buf)) != NULL) {
1921 /* send buffered frame .. */
1922 PDEBUG(DEBUG_PS2, "Sending buffered frame to STA after PS POLL"
1923 " (buffer_count=%d)\n", skb_queue_len(&sta->tx_buf));
1924
1925 pspoll_send_buffered(local, sta, skb);
1926
1927 if (sta->flags & WLAN_STA_PS) {
1928 /* send only one buffered packet per PS Poll */
1929 /* FIX: should ignore further PS Polls until the
1930 * buffered packet that was just sent is acknowledged
1931 * (Tx or TxExc event) */
1932 break;
1933 }
1934 }
1935
1936 if (skb_queue_empty(&sta->tx_buf)) {
1937 /* try to clear aid from TIM */
1938 if (!(sta->flags & WLAN_STA_TIM))
1939 PDEBUG(DEBUG_PS2, "Re-unsetting TIM for aid %d\n",
1940 aid);
1941 hostap_set_tim(local, aid, 0);
1942 sta->flags &= ~WLAN_STA_TIM;
1943 }
1944
1945 atomic_dec(&sta->users);
1946}
1947
1948
1949#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
1950
1951static void handle_wds_oper_queue(void *data)
1952{
1953 local_info_t *local = data;
1954 struct wds_oper_data *entry, *prev;
1955
1956 spin_lock_bh(&local->lock);
1957 entry = local->ap->wds_oper_entries;
1958 local->ap->wds_oper_entries = NULL;
1959 spin_unlock_bh(&local->lock);
1960
1961 while (entry) {
1962 PDEBUG(DEBUG_AP, "%s: %s automatic WDS connection "
1963 "to AP " MACSTR "\n",
1964 local->dev->name,
1965 entry->type == WDS_ADD ? "adding" : "removing",
1966 MAC2STR(entry->addr));
1967 if (entry->type == WDS_ADD)
1968 prism2_wds_add(local, entry->addr, 0);
1969 else if (entry->type == WDS_DEL)
1970 prism2_wds_del(local, entry->addr, 0, 1);
1971
1972 prev = entry;
1973 entry = entry->next;
1974 kfree(prev);
1975 }
1976}
1977
1978
1979/* Called only as a scheduled task for pending AP frames. */
1980static void handle_beacon(local_info_t *local, struct sk_buff *skb,
1981 struct hostap_80211_rx_status *rx_stats)
1982{
1983 struct hostap_ieee80211_hdr *hdr =
1984 (struct hostap_ieee80211_hdr *) skb->data;
1985 char *body = skb->data + IEEE80211_MGMT_HDR_LEN;
1986 int len, left;
1987 u16 *pos, beacon_int, capability;
1988 char *ssid = NULL;
1989 unsigned char *supp_rates = NULL;
1990 int ssid_len = 0, supp_rates_len = 0;
1991 struct sta_info *sta = NULL;
1992 int new_sta = 0, channel = -1;
1993
1994 len = skb->len - IEEE80211_MGMT_HDR_LEN;
1995
1996 if (len < 8 + 2 + 2) {
1997 printk(KERN_DEBUG "handle_beacon - too short payload "
1998 "(len=%d)\n", len);
1999 return;
2000 }
2001
2002 pos = (u16 *) body;
2003 left = len;
2004
2005 /* Timestamp (8 octets) */
2006 pos += 4; left -= 8;
2007 /* Beacon interval (2 octets) */
2008 beacon_int = __le16_to_cpu(*pos);
2009 pos++; left -= 2;
2010 /* Capability information (2 octets) */
2011 capability = __le16_to_cpu(*pos);
2012 pos++; left -= 2;
2013
2014 if (local->ap->ap_policy != AP_OTHER_AP_EVEN_IBSS &&
2015 capability & WLAN_CAPABILITY_IBSS)
2016 return;
2017
2018 if (left >= 2) {
2019 unsigned int ileft;
2020 unsigned char *u = (unsigned char *) pos;
2021
2022 if (*u == WLAN_EID_SSID) {
2023 u++; left--;
2024 ileft = *u;
2025 u++; left--;
2026
2027 if (ileft > left || ileft > MAX_SSID_LEN) {
2028 PDEBUG(DEBUG_AP, "SSID: overflow\n");
2029 return;
2030 }
2031
2032 if (local->ap->ap_policy == AP_OTHER_AP_SAME_SSID &&
2033 (ileft != strlen(local->essid) ||
2034 memcmp(local->essid, u, ileft) != 0)) {
2035 /* not our SSID */
2036 return;
2037 }
2038
2039 ssid = u;
2040 ssid_len = ileft;
2041
2042 u += ileft;
2043 left -= ileft;
2044 }
2045
2046 if (*u == WLAN_EID_SUPP_RATES) {
2047 u++; left--;
2048 ileft = *u;
2049 u++; left--;
2050
2051 if (ileft > left || ileft == 0 || ileft > 8) {
2052 PDEBUG(DEBUG_AP, " - SUPP_RATES len error\n");
2053 return;
2054 }
2055
2056 supp_rates = u;
2057 supp_rates_len = ileft;
2058
2059 u += ileft;
2060 left -= ileft;
2061 }
2062
2063 if (*u == WLAN_EID_DS_PARAMS) {
2064 u++; left--;
2065 ileft = *u;
2066 u++; left--;
2067
2068 if (ileft > left || ileft != 1) {
2069 PDEBUG(DEBUG_AP, " - DS_PARAMS len error\n");
2070 return;
2071 }
2072
2073 channel = *u;
2074
2075 u += ileft;
2076 left -= ileft;
2077 }
2078 }
2079
2080 spin_lock_bh(&local->ap->sta_table_lock);
2081 sta = ap_get_sta(local->ap, hdr->addr2);
2082 if (sta != NULL)
2083 atomic_inc(&sta->users);
2084 spin_unlock_bh(&local->ap->sta_table_lock);
2085
2086 if (sta == NULL) {
2087 /* add new AP */
2088 new_sta = 1;
2089 sta = ap_add_sta(local->ap, hdr->addr2);
2090 if (sta == NULL) {
2091 printk(KERN_INFO "prism2: kmalloc failed for AP "
2092 "data structure\n");
2093 return;
2094 }
2095 hostap_event_new_sta(local->dev, sta);
2096
2097 /* mark APs authentication and associated for pseudo ad-hoc
2098 * style communication */
2099 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
2100
2101 if (local->ap->autom_ap_wds) {
2102 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
2103 }
2104 }
2105
2106 sta->ap = 1;
2107 if (ssid) {
2108 sta->u.ap.ssid_len = ssid_len;
2109 memcpy(sta->u.ap.ssid, ssid, ssid_len);
2110 sta->u.ap.ssid[ssid_len] = '\0';
2111 } else {
2112 sta->u.ap.ssid_len = 0;
2113 sta->u.ap.ssid[0] = '\0';
2114 }
2115 sta->u.ap.channel = channel;
2116 sta->rx_packets++;
2117 sta->rx_bytes += len;
2118 sta->u.ap.last_beacon = sta->last_rx = jiffies;
2119 sta->capability = capability;
2120 sta->listen_interval = beacon_int;
2121
2122 atomic_dec(&sta->users);
2123
2124 if (new_sta) {
2125 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
2126 memcpy(sta->supported_rates, supp_rates, supp_rates_len);
2127 prism2_check_tx_rates(sta);
2128 }
2129}
2130
2131#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2132
2133
2134/* Called only as a tasklet. */
2135static void handle_ap_item(local_info_t *local, struct sk_buff *skb,
2136 struct hostap_80211_rx_status *rx_stats)
2137{
2138#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2139 struct net_device *dev = local->dev;
2140#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2141 u16 fc, type, stype;
2142 struct hostap_ieee80211_hdr *hdr;
2143
2144 /* FIX: should give skb->len to handler functions and check that the
2145 * buffer is long enough */
2146 hdr = (struct hostap_ieee80211_hdr *) skb->data;
2147 fc = le16_to_cpu(hdr->frame_control);
2148 type = HOSTAP_FC_GET_TYPE(fc);
2149 stype = HOSTAP_FC_GET_STYPE(fc);
2150
2151#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2152 if (!local->hostapd && type == WLAN_FC_TYPE_DATA) {
2153 PDEBUG(DEBUG_AP, "handle_ap_item - data frame\n");
2154
2155 if (!(fc & WLAN_FC_TODS) || (fc & WLAN_FC_FROMDS)) {
2156 if (stype == WLAN_FC_STYPE_NULLFUNC) {
2157 /* no ToDS nullfunc seems to be used to check
2158 * AP association; so send reject message to
2159 * speed up re-association */
2160 ap_handle_dropped_data(local, hdr);
2161 goto done;
2162 }
2163 PDEBUG(DEBUG_AP, " not ToDS frame (fc=0x%04x)\n",
2164 fc);
2165 goto done;
2166 }
2167
2168 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2169 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(BSSID)="
2170 MACSTR " not own MAC\n",
2171 MAC2STR(hdr->addr1));
2172 goto done;
2173 }
2174
2175 if (local->ap->nullfunc_ack && stype == WLAN_FC_STYPE_NULLFUNC)
2176 ap_handle_data_nullfunc(local, hdr);
2177 else
2178 ap_handle_dropped_data(local, hdr);
2179 goto done;
2180 }
2181
2182 if (type == WLAN_FC_TYPE_MGMT && stype == WLAN_FC_STYPE_BEACON) {
2183 handle_beacon(local, skb, rx_stats);
2184 goto done;
2185 }
2186#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2187
2188 if (type == WLAN_FC_TYPE_CTRL && stype == WLAN_FC_STYPE_PSPOLL) {
2189 handle_pspoll(local, hdr, rx_stats);
2190 goto done;
2191 }
2192
2193 if (local->hostapd) {
2194 PDEBUG(DEBUG_AP, "Unknown frame in AP queue: type=0x%02x "
2195 "subtype=0x%02x\n", type, stype);
2196 goto done;
2197 }
2198
2199#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2200 if (type != WLAN_FC_TYPE_MGMT) {
2201 PDEBUG(DEBUG_AP, "handle_ap_item - not a management frame?\n");
2202 goto done;
2203 }
2204
2205 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN)) {
2206 PDEBUG(DEBUG_AP, "handle_ap_item - addr1(DA)=" MACSTR
2207 " not own MAC\n", MAC2STR(hdr->addr1));
2208 goto done;
2209 }
2210
2211 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN)) {
2212 PDEBUG(DEBUG_AP, "handle_ap_item - addr3(BSSID)=" MACSTR
2213 " not own MAC\n", MAC2STR(hdr->addr3));
2214 goto done;
2215 }
2216
2217 switch (stype) {
2218 case WLAN_FC_STYPE_ASSOC_REQ:
2219 handle_assoc(local, skb, rx_stats, 0);
2220 break;
2221 case WLAN_FC_STYPE_ASSOC_RESP:
2222 PDEBUG(DEBUG_AP, "==> ASSOC RESP (ignored)\n");
2223 break;
2224 case WLAN_FC_STYPE_REASSOC_REQ:
2225 handle_assoc(local, skb, rx_stats, 1);
2226 break;
2227 case WLAN_FC_STYPE_REASSOC_RESP:
2228 PDEBUG(DEBUG_AP, "==> REASSOC RESP (ignored)\n");
2229 break;
2230 case WLAN_FC_STYPE_ATIM:
2231 PDEBUG(DEBUG_AP, "==> ATIM (ignored)\n");
2232 break;
2233 case WLAN_FC_STYPE_DISASSOC:
2234 handle_disassoc(local, skb, rx_stats);
2235 break;
2236 case WLAN_FC_STYPE_AUTH:
2237 handle_authen(local, skb, rx_stats);
2238 break;
2239 case WLAN_FC_STYPE_DEAUTH:
2240 handle_deauth(local, skb, rx_stats);
2241 break;
2242 default:
2243 PDEBUG(DEBUG_AP, "Unknown mgmt frame subtype 0x%02x\n", stype);
2244 break;
2245 }
2246#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2247
2248 done:
2249 dev_kfree_skb(skb);
2250}
2251
2252
2253/* Called only as a tasklet (software IRQ) */
2254void hostap_rx(struct net_device *dev, struct sk_buff *skb,
2255 struct hostap_80211_rx_status *rx_stats)
2256{
2257 struct hostap_interface *iface;
2258 local_info_t *local;
2259 u16 fc;
2260 struct hostap_ieee80211_hdr *hdr;
2261
2262 iface = netdev_priv(dev);
2263 local = iface->local;
2264
2265 if (skb->len < 16)
2266 goto drop;
2267
2268 local->stats.rx_packets++;
2269
2270 hdr = (struct hostap_ieee80211_hdr *) skb->data;
2271 fc = le16_to_cpu(hdr->frame_control);
2272
2273 if (local->ap->ap_policy == AP_OTHER_AP_SKIP_ALL &&
2274 HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
2275 HOSTAP_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
2276 goto drop;
2277
2278 skb->protocol = __constant_htons(ETH_P_HOSTAP);
2279 handle_ap_item(local, skb, rx_stats);
2280 return;
2281
2282 drop:
2283 dev_kfree_skb(skb);
2284}
2285
2286
2287/* Called only as a tasklet (software IRQ) */
2288static void schedule_packet_send(local_info_t *local, struct sta_info *sta)
2289{
2290 struct sk_buff *skb;
2291 struct hostap_ieee80211_hdr *hdr;
2292 struct hostap_80211_rx_status rx_stats;
2293
2294 if (skb_queue_empty(&sta->tx_buf))
2295 return;
2296
2297 skb = dev_alloc_skb(16);
2298 if (skb == NULL) {
2299 printk(KERN_DEBUG "%s: schedule_packet_send: skb alloc "
2300 "failed\n", local->dev->name);
2301 return;
2302 }
2303
2304 hdr = (struct hostap_ieee80211_hdr *) skb_put(skb, 16);
2305
2306 /* Generate a fake pspoll frame to start packet delivery */
2307 hdr->frame_control = __constant_cpu_to_le16(
2308 (WLAN_FC_TYPE_CTRL << 2) | (WLAN_FC_STYPE_PSPOLL << 4));
2309 memcpy(hdr->addr1, local->dev->dev_addr, ETH_ALEN);
2310 memcpy(hdr->addr2, sta->addr, ETH_ALEN);
2311 hdr->duration_id = cpu_to_le16(sta->aid | BIT(15) | BIT(14));
2312
2313 PDEBUG(DEBUG_PS2, "%s: Scheduling buffered packet delivery for "
2314 "STA " MACSTR "\n", local->dev->name, MAC2STR(sta->addr));
2315
2316 skb->dev = local->dev;
2317
2318 memset(&rx_stats, 0, sizeof(rx_stats));
2319 hostap_rx(local->dev, skb, &rx_stats);
2320}
2321
2322
2323static int prism2_ap_get_sta_qual(local_info_t *local, struct sockaddr addr[],
2324 struct iw_quality qual[], int buf_size,
2325 int aplist)
2326{
2327 struct ap_data *ap = local->ap;
2328 struct list_head *ptr;
2329 int count = 0;
2330
2331 spin_lock_bh(&ap->sta_table_lock);
2332
2333 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2334 ptr = ptr->next) {
2335 struct sta_info *sta = (struct sta_info *) ptr;
2336
2337 if (aplist && !sta->ap)
2338 continue;
2339 addr[count].sa_family = ARPHRD_ETHER;
2340 memcpy(addr[count].sa_data, sta->addr, ETH_ALEN);
2341 if (sta->last_rx_silence == 0)
2342 qual[count].qual = sta->last_rx_signal < 27 ?
2343 0 : (sta->last_rx_signal - 27) * 92 / 127;
2344 else
2345 qual[count].qual = sta->last_rx_signal -
2346 sta->last_rx_silence - 35;
2347 qual[count].level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2348 qual[count].noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2349 qual[count].updated = sta->last_rx_updated;
2350
2351 sta->last_rx_updated = 0;
2352
2353 count++;
2354 if (count >= buf_size)
2355 break;
2356 }
2357 spin_unlock_bh(&ap->sta_table_lock);
2358
2359 return count;
2360}
2361
2362
2363/* Translate our list of Access Points & Stations to a card independant
2364 * format that the Wireless Tools will understand - Jean II */
2365static int prism2_ap_translate_scan(struct net_device *dev, char *buffer)
2366{
2367 struct hostap_interface *iface;
2368 local_info_t *local;
2369 struct ap_data *ap;
2370 struct list_head *ptr;
2371 struct iw_event iwe;
2372 char *current_ev = buffer;
2373 char *end_buf = buffer + IW_SCAN_MAX_DATA;
2374#if !defined(PRISM2_NO_KERNEL_IEEE80211_MGMT)
2375 char buf[64];
2376#endif
2377
2378 iface = netdev_priv(dev);
2379 local = iface->local;
2380 ap = local->ap;
2381
2382 spin_lock_bh(&ap->sta_table_lock);
2383
2384 for (ptr = ap->sta_list.next; ptr != NULL && ptr != &ap->sta_list;
2385 ptr = ptr->next) {
2386 struct sta_info *sta = (struct sta_info *) ptr;
2387
2388 /* First entry *MUST* be the AP MAC address */
2389 memset(&iwe, 0, sizeof(iwe));
2390 iwe.cmd = SIOCGIWAP;
2391 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
2392 memcpy(iwe.u.ap_addr.sa_data, sta->addr, ETH_ALEN);
2393 iwe.len = IW_EV_ADDR_LEN;
2394 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2395 IW_EV_ADDR_LEN);
2396
2397 /* Use the mode to indicate if it's a station or
2398 * an Access Point */
2399 memset(&iwe, 0, sizeof(iwe));
2400 iwe.cmd = SIOCGIWMODE;
2401 if (sta->ap)
2402 iwe.u.mode = IW_MODE_MASTER;
2403 else
2404 iwe.u.mode = IW_MODE_INFRA;
2405 iwe.len = IW_EV_UINT_LEN;
2406 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2407 IW_EV_UINT_LEN);
2408
2409 /* Some quality */
2410 memset(&iwe, 0, sizeof(iwe));
2411 iwe.cmd = IWEVQUAL;
2412 if (sta->last_rx_silence == 0)
2413 iwe.u.qual.qual = sta->last_rx_signal < 27 ?
2414 0 : (sta->last_rx_signal - 27) * 92 / 127;
2415 else
2416 iwe.u.qual.qual = sta->last_rx_signal -
2417 sta->last_rx_silence - 35;
2418 iwe.u.qual.level = HFA384X_LEVEL_TO_dBm(sta->last_rx_signal);
2419 iwe.u.qual.noise = HFA384X_LEVEL_TO_dBm(sta->last_rx_silence);
2420 iwe.u.qual.updated = sta->last_rx_updated;
2421 iwe.len = IW_EV_QUAL_LEN;
2422 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
2423 IW_EV_QUAL_LEN);
2424
2425#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2426 if (sta->ap) {
2427 memset(&iwe, 0, sizeof(iwe));
2428 iwe.cmd = SIOCGIWESSID;
2429 iwe.u.data.length = sta->u.ap.ssid_len;
2430 iwe.u.data.flags = 1;
2431 current_ev = iwe_stream_add_point(current_ev, end_buf,
2432 &iwe,
2433 sta->u.ap.ssid);
2434
2435 memset(&iwe, 0, sizeof(iwe));
2436 iwe.cmd = SIOCGIWENCODE;
2437 if (sta->capability & WLAN_CAPABILITY_PRIVACY)
2438 iwe.u.data.flags =
2439 IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
2440 else
2441 iwe.u.data.flags = IW_ENCODE_DISABLED;
2442 current_ev = iwe_stream_add_point(current_ev, end_buf,
2443 &iwe,
2444 sta->u.ap.ssid
2445 /* 0 byte memcpy */);
2446
2447 if (sta->u.ap.channel > 0 &&
2448 sta->u.ap.channel <= FREQ_COUNT) {
2449 memset(&iwe, 0, sizeof(iwe));
2450 iwe.cmd = SIOCGIWFREQ;
2451 iwe.u.freq.m = freq_list[sta->u.ap.channel - 1]
2452 * 100000;
2453 iwe.u.freq.e = 1;
2454 current_ev = iwe_stream_add_event(
2455 current_ev, end_buf, &iwe,
2456 IW_EV_FREQ_LEN);
2457 }
2458
2459 memset(&iwe, 0, sizeof(iwe));
2460 iwe.cmd = IWEVCUSTOM;
2461 sprintf(buf, "beacon_interval=%d",
2462 sta->listen_interval);
2463 iwe.u.data.length = strlen(buf);
2464 current_ev = iwe_stream_add_point(current_ev, end_buf,
2465 &iwe, buf);
2466 }
2467#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2468
2469 sta->last_rx_updated = 0;
2470
2471 /* To be continued, we should make good use of IWEVCUSTOM */
2472 }
2473
2474 spin_unlock_bh(&ap->sta_table_lock);
2475
2476 return current_ev - buffer;
2477}
2478
2479
2480static int prism2_hostapd_add_sta(struct ap_data *ap,
2481 struct prism2_hostapd_param *param)
2482{
2483 struct sta_info *sta;
2484
2485 spin_lock_bh(&ap->sta_table_lock);
2486 sta = ap_get_sta(ap, param->sta_addr);
2487 if (sta)
2488 atomic_inc(&sta->users);
2489 spin_unlock_bh(&ap->sta_table_lock);
2490
2491 if (sta == NULL) {
2492 sta = ap_add_sta(ap, param->sta_addr);
2493 if (sta == NULL)
2494 return -1;
2495 }
2496
2497 if (!(sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2498 hostap_event_new_sta(sta->local->dev, sta);
2499
2500 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
2501 sta->last_rx = jiffies;
2502 sta->aid = param->u.add_sta.aid;
2503 sta->capability = param->u.add_sta.capability;
2504 sta->tx_supp_rates = param->u.add_sta.tx_supp_rates;
2505 if (sta->tx_supp_rates & WLAN_RATE_1M)
2506 sta->supported_rates[0] = 2;
2507 if (sta->tx_supp_rates & WLAN_RATE_2M)
2508 sta->supported_rates[1] = 4;
2509 if (sta->tx_supp_rates & WLAN_RATE_5M5)
2510 sta->supported_rates[2] = 11;
2511 if (sta->tx_supp_rates & WLAN_RATE_11M)
2512 sta->supported_rates[3] = 22;
2513 prism2_check_tx_rates(sta);
2514 atomic_dec(&sta->users);
2515 return 0;
2516}
2517
2518
2519static int prism2_hostapd_remove_sta(struct ap_data *ap,
2520 struct prism2_hostapd_param *param)
2521{
2522 struct sta_info *sta;
2523
2524 spin_lock_bh(&ap->sta_table_lock);
2525 sta = ap_get_sta(ap, param->sta_addr);
2526 if (sta) {
2527 ap_sta_hash_del(ap, sta);
2528 list_del(&sta->list);
2529 }
2530 spin_unlock_bh(&ap->sta_table_lock);
2531
2532 if (!sta)
2533 return -ENOENT;
2534
2535 if ((sta->flags & WLAN_STA_ASSOC) && !sta->ap && sta->local)
2536 hostap_event_expired_sta(sta->local->dev, sta);
2537 ap_free_sta(ap, sta);
2538
2539 return 0;
2540}
2541
2542
2543static int prism2_hostapd_get_info_sta(struct ap_data *ap,
2544 struct prism2_hostapd_param *param)
2545{
2546 struct sta_info *sta;
2547
2548 spin_lock_bh(&ap->sta_table_lock);
2549 sta = ap_get_sta(ap, param->sta_addr);
2550 if (sta)
2551 atomic_inc(&sta->users);
2552 spin_unlock_bh(&ap->sta_table_lock);
2553
2554 if (!sta)
2555 return -ENOENT;
2556
2557 param->u.get_info_sta.inactive_sec = (jiffies - sta->last_rx) / HZ;
2558
2559 atomic_dec(&sta->users);
2560
2561 return 1;
2562}
2563
2564
2565static int prism2_hostapd_set_flags_sta(struct ap_data *ap,
2566 struct prism2_hostapd_param *param)
2567{
2568 struct sta_info *sta;
2569
2570 spin_lock_bh(&ap->sta_table_lock);
2571 sta = ap_get_sta(ap, param->sta_addr);
2572 if (sta) {
2573 sta->flags |= param->u.set_flags_sta.flags_or;
2574 sta->flags &= param->u.set_flags_sta.flags_and;
2575 }
2576 spin_unlock_bh(&ap->sta_table_lock);
2577
2578 if (!sta)
2579 return -ENOENT;
2580
2581 return 0;
2582}
2583
2584
2585static int prism2_hostapd_sta_clear_stats(struct ap_data *ap,
2586 struct prism2_hostapd_param *param)
2587{
2588 struct sta_info *sta;
2589 int rate;
2590
2591 spin_lock_bh(&ap->sta_table_lock);
2592 sta = ap_get_sta(ap, param->sta_addr);
2593 if (sta) {
2594 sta->rx_packets = sta->tx_packets = 0;
2595 sta->rx_bytes = sta->tx_bytes = 0;
2596 for (rate = 0; rate < WLAN_RATE_COUNT; rate++) {
2597 sta->tx_count[rate] = 0;
2598 sta->rx_count[rate] = 0;
2599 }
2600 }
2601 spin_unlock_bh(&ap->sta_table_lock);
2602
2603 if (!sta)
2604 return -ENOENT;
2605
2606 return 0;
2607}
2608
2609
2610static int prism2_hostapd(struct ap_data *ap,
2611 struct prism2_hostapd_param *param)
2612{
2613 switch (param->cmd) {
2614 case PRISM2_HOSTAPD_FLUSH:
2615 ap_control_kickall(ap);
2616 return 0;
2617 case PRISM2_HOSTAPD_ADD_STA:
2618 return prism2_hostapd_add_sta(ap, param);
2619 case PRISM2_HOSTAPD_REMOVE_STA:
2620 return prism2_hostapd_remove_sta(ap, param);
2621 case PRISM2_HOSTAPD_GET_INFO_STA:
2622 return prism2_hostapd_get_info_sta(ap, param);
2623 case PRISM2_HOSTAPD_SET_FLAGS_STA:
2624 return prism2_hostapd_set_flags_sta(ap, param);
2625 case PRISM2_HOSTAPD_STA_CLEAR_STATS:
2626 return prism2_hostapd_sta_clear_stats(ap, param);
2627 default:
2628 printk(KERN_WARNING "prism2_hostapd: unknown cmd=%d\n",
2629 param->cmd);
2630 return -EOPNOTSUPP;
2631 }
2632}
2633
2634
2635/* Update station info for host-based TX rate control and return current
2636 * TX rate */
2637static int ap_update_sta_tx_rate(struct sta_info *sta, struct net_device *dev)
2638{
2639 int ret = sta->tx_rate;
2640 struct hostap_interface *iface;
2641 local_info_t *local;
2642
2643 iface = netdev_priv(dev);
2644 local = iface->local;
2645
2646 sta->tx_count[sta->tx_rate_idx]++;
2647 sta->tx_since_last_failure++;
2648 sta->tx_consecutive_exc = 0;
2649 if (sta->tx_since_last_failure >= WLAN_RATE_UPDATE_COUNT &&
2650 sta->tx_rate_idx < sta->tx_max_rate) {
2651 /* use next higher rate */
2652 int old_rate, new_rate;
2653 old_rate = new_rate = sta->tx_rate_idx;
2654 while (new_rate < sta->tx_max_rate) {
2655 new_rate++;
2656 if (ap_tx_rate_ok(new_rate, sta, local)) {
2657 sta->tx_rate_idx = new_rate;
2658 break;
2659 }
2660 }
2661 if (old_rate != sta->tx_rate_idx) {
2662 switch (sta->tx_rate_idx) {
2663 case 0: sta->tx_rate = 10; break;
2664 case 1: sta->tx_rate = 20; break;
2665 case 2: sta->tx_rate = 55; break;
2666 case 3: sta->tx_rate = 110; break;
2667 default: sta->tx_rate = 0; break;
2668 }
2669 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " TX rate raised to"
2670 " %d\n", dev->name, MAC2STR(sta->addr),
2671 sta->tx_rate);
2672 }
2673 sta->tx_since_last_failure = 0;
2674 }
2675
2676 return ret;
2677}
2678
2679
2680/* Called only from software IRQ. Called for each TX frame prior possible
2681 * encryption and transmit. */
2682ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx)
2683{
2684 struct sta_info *sta = NULL;
2685 struct sk_buff *skb = tx->skb;
2686 int set_tim, ret;
2687 struct hostap_ieee80211_hdr *hdr;
2688 struct hostap_skb_tx_data *meta;
2689
2690 meta = (struct hostap_skb_tx_data *) skb->cb;
2691 ret = AP_TX_CONTINUE;
2692 if (local->ap == NULL || skb->len < 10 ||
2693 meta->iface->type == HOSTAP_INTERFACE_STA)
2694 goto out;
2695
2696 hdr = (struct hostap_ieee80211_hdr *) skb->data;
2697
2698 if (hdr->addr1[0] & 0x01) {
2699 /* broadcast/multicast frame - no AP related processing */
2700 goto out;
2701 }
2702
2703 /* unicast packet - check whether destination STA is associated */
2704 spin_lock(&local->ap->sta_table_lock);
2705 sta = ap_get_sta(local->ap, hdr->addr1);
2706 if (sta)
2707 atomic_inc(&sta->users);
2708 spin_unlock(&local->ap->sta_table_lock);
2709
2710 if (local->iw_mode == IW_MODE_MASTER && sta == NULL && !meta->wds &&
2711 meta->iface->type != HOSTAP_INTERFACE_MASTER &&
2712 meta->iface->type != HOSTAP_INTERFACE_AP) {
2713#if 0
2714 /* This can happen, e.g., when wlan0 is added to a bridge and
2715 * bridging code does not know which port is the correct target
2716 * for a unicast frame. In this case, the packet is send to all
2717 * ports of the bridge. Since this is a valid scenario, do not
2718 * print out any errors here. */
2719 if (net_ratelimit()) {
2720 printk(KERN_DEBUG "AP: drop packet to non-associated "
2721 "STA " MACSTR "\n", MAC2STR(hdr->addr1));
2722 }
2723#endif
2724 local->ap->tx_drop_nonassoc++;
2725 ret = AP_TX_DROP;
2726 goto out;
2727 }
2728
2729 if (sta == NULL)
2730 goto out;
2731
2732 if (!(sta->flags & WLAN_STA_AUTHORIZED))
2733 ret = AP_TX_CONTINUE_NOT_AUTHORIZED;
2734
2735 /* Set tx_rate if using host-based TX rate control */
2736 if (!local->fw_tx_rate_control)
2737 local->ap->last_tx_rate = meta->rate =
2738 ap_update_sta_tx_rate(sta, local->dev);
2739
2740 if (local->iw_mode != IW_MODE_MASTER)
2741 goto out;
2742
2743 if (!(sta->flags & WLAN_STA_PS))
2744 goto out;
2745
2746 if (memcmp(skb->cb, AP_SKB_CB_MAGIC, AP_SKB_CB_MAGIC_LEN) == 0) {
2747 if (skb->cb[AP_SKB_CB_MAGIC_LEN] & AP_SKB_CB_ADD_MOREDATA) {
2748 /* indicate to STA that more frames follow */
2749 hdr->frame_control |=
2750 __constant_cpu_to_le16(WLAN_FC_MOREDATA);
2751 }
2752
2753 if (skb->cb[AP_SKB_CB_MAGIC_LEN] & AP_SKB_CB_BUFFERED_FRAME) {
2754 /* packet was already buffered and now send due to
2755 * PS poll, so do not rebuffer it */
2756 goto out;
2757 }
2758 }
2759
2760 if (skb_queue_len(&sta->tx_buf) >= STA_MAX_TX_BUFFER) {
2761 PDEBUG(DEBUG_PS, "%s: No more space in STA (" MACSTR ")'s PS "
2762 "mode buffer\n", local->dev->name, MAC2STR(sta->addr));
2763 /* Make sure that TIM is set for the station (it might not be
2764 * after AP wlan hw reset). */
2765 /* FIX: should fix hw reset to restore bits based on STA
2766 * buffer state.. */
2767 hostap_set_tim(local, sta->aid, 1);
2768 sta->flags |= WLAN_STA_TIM;
2769 ret = AP_TX_DROP;
2770 goto out;
2771 }
2772
2773 /* STA in PS mode, buffer frame for later delivery */
2774 set_tim = skb_queue_empty(&sta->tx_buf);
2775 skb_queue_tail(&sta->tx_buf, skb);
2776 /* FIX: could save RX time to skb and expire buffered frames after
2777 * some time if STA does not poll for them */
2778
2779 if (set_tim) {
2780 if (sta->flags & WLAN_STA_TIM)
2781 PDEBUG(DEBUG_PS2, "Re-setting TIM for aid %d\n",
2782 sta->aid);
2783 hostap_set_tim(local, sta->aid, 1);
2784 sta->flags |= WLAN_STA_TIM;
2785 }
2786
2787 ret = AP_TX_BUFFERED;
2788
2789 out:
2790 if (sta != NULL) {
2791 if (ret == AP_TX_CONTINUE ||
2792 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) {
2793 sta->tx_packets++;
2794 sta->tx_bytes += skb->len;
2795 sta->last_tx = jiffies;
2796 }
2797
2798 if ((ret == AP_TX_CONTINUE ||
2799 ret == AP_TX_CONTINUE_NOT_AUTHORIZED) &&
2800 sta->crypt && tx->host_encrypt) {
2801 tx->crypt = sta->crypt;
2802 tx->sta_ptr = sta; /* hostap_handle_sta_release() will
2803 * be called to release sta info
2804 * later */
2805 } else
2806 atomic_dec(&sta->users);
2807 }
2808
2809 return ret;
2810}
2811
2812
2813void hostap_handle_sta_release(void *ptr)
2814{
2815 struct sta_info *sta = ptr;
2816 atomic_dec(&sta->users);
2817}
2818
2819
2820/* Called only as a tasklet (software IRQ) */
2821void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb)
2822{
2823 struct sta_info *sta;
2824 struct hostap_ieee80211_hdr *hdr;
2825 struct hostap_skb_tx_data *meta;
2826
2827 hdr = (struct hostap_ieee80211_hdr *) skb->data;
2828 meta = (struct hostap_skb_tx_data *) skb->cb;
2829
2830 spin_lock(&local->ap->sta_table_lock);
2831 sta = ap_get_sta(local->ap, hdr->addr1);
2832 if (!sta) {
2833 spin_unlock(&local->ap->sta_table_lock);
2834 PDEBUG(DEBUG_AP, "%s: Could not find STA " MACSTR " for this "
2835 "TX error (@%lu)\n",
2836 local->dev->name, MAC2STR(hdr->addr1), jiffies);
2837 return;
2838 }
2839
2840 sta->tx_since_last_failure = 0;
2841 sta->tx_consecutive_exc++;
2842
2843 if (sta->tx_consecutive_exc >= WLAN_RATE_DECREASE_THRESHOLD &&
2844 sta->tx_rate_idx > 0 && meta->rate <= sta->tx_rate) {
2845 /* use next lower rate */
2846 int old, rate;
2847 old = rate = sta->tx_rate_idx;
2848 while (rate > 0) {
2849 rate--;
2850 if (ap_tx_rate_ok(rate, sta, local)) {
2851 sta->tx_rate_idx = rate;
2852 break;
2853 }
2854 }
2855 if (old != sta->tx_rate_idx) {
2856 switch (sta->tx_rate_idx) {
2857 case 0: sta->tx_rate = 10; break;
2858 case 1: sta->tx_rate = 20; break;
2859 case 2: sta->tx_rate = 55; break;
2860 case 3: sta->tx_rate = 110; break;
2861 default: sta->tx_rate = 0; break;
2862 }
2863 PDEBUG(DEBUG_AP, "%s: STA " MACSTR " TX rate lowered "
2864 "to %d\n", local->dev->name, MAC2STR(sta->addr),
2865 sta->tx_rate);
2866 }
2867 sta->tx_consecutive_exc = 0;
2868 }
2869 spin_unlock(&local->ap->sta_table_lock);
2870}
2871
2872
2873static void hostap_update_sta_ps2(local_info_t *local, struct sta_info *sta,
2874 int pwrmgt, int type, int stype)
2875{
2876 if (pwrmgt && !(sta->flags & WLAN_STA_PS)) {
2877 sta->flags |= WLAN_STA_PS;
2878 PDEBUG(DEBUG_PS2, "STA " MACSTR " changed to use PS "
2879 "mode (type=0x%02X, stype=0x%02X)\n",
2880 MAC2STR(sta->addr), type, stype);
2881 } else if (!pwrmgt && (sta->flags & WLAN_STA_PS)) {
2882 sta->flags &= ~WLAN_STA_PS;
2883 PDEBUG(DEBUG_PS2, "STA " MACSTR " changed to not use "
2884 "PS mode (type=0x%02X, stype=0x%02X)\n",
2885 MAC2STR(sta->addr), type, stype);
2886 if (type != WLAN_FC_TYPE_CTRL || stype != WLAN_FC_STYPE_PSPOLL)
2887 schedule_packet_send(local, sta);
2888 }
2889}
2890
2891
2892/* Called only as a tasklet (software IRQ). Called for each RX frame to update
2893 * STA power saving state. pwrmgt is a flag from 802.11 frame_control field. */
2894int hostap_update_sta_ps(local_info_t *local, struct hostap_ieee80211_hdr *hdr)
2895{
2896 struct sta_info *sta;
2897 u16 fc;
2898
2899 spin_lock(&local->ap->sta_table_lock);
2900 sta = ap_get_sta(local->ap, hdr->addr2);
2901 if (sta)
2902 atomic_inc(&sta->users);
2903 spin_unlock(&local->ap->sta_table_lock);
2904
2905 if (!sta)
2906 return -1;
2907
2908 fc = le16_to_cpu(hdr->frame_control);
2909 hostap_update_sta_ps2(local, sta, fc & WLAN_FC_PWRMGT,
2910 HOSTAP_FC_GET_TYPE(fc), HOSTAP_FC_GET_STYPE(fc));
2911
2912 atomic_dec(&sta->users);
2913 return 0;
2914}
2915
2916
2917/* Called only as a tasklet (software IRQ). Called for each RX frame after
2918 * getting RX header and payload from hardware. */
2919ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
2920 struct sk_buff *skb,
2921 struct hostap_80211_rx_status *rx_stats,
2922 int wds)
2923{
2924 int ret;
2925 struct sta_info *sta;
2926 u16 fc, type, stype;
2927 struct hostap_ieee80211_hdr *hdr;
2928
2929 if (local->ap == NULL)
2930 return AP_RX_CONTINUE;
2931
2932 hdr = (struct hostap_ieee80211_hdr *) skb->data;
2933
2934 fc = le16_to_cpu(hdr->frame_control);
2935 type = HOSTAP_FC_GET_TYPE(fc);
2936 stype = HOSTAP_FC_GET_STYPE(fc);
2937
2938 spin_lock(&local->ap->sta_table_lock);
2939 sta = ap_get_sta(local->ap, hdr->addr2);
2940 if (sta)
2941 atomic_inc(&sta->users);
2942 spin_unlock(&local->ap->sta_table_lock);
2943
2944 if (sta && !(sta->flags & WLAN_STA_AUTHORIZED))
2945 ret = AP_RX_CONTINUE_NOT_AUTHORIZED;
2946 else
2947 ret = AP_RX_CONTINUE;
2948
2949
2950 if (fc & WLAN_FC_TODS) {
2951 if (!wds && (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) {
2952 if (local->hostapd) {
2953 prism2_rx_80211(local->apdev, skb, rx_stats,
2954 PRISM2_RX_NON_ASSOC);
2955#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2956 } else {
2957 printk(KERN_DEBUG "%s: dropped received packet"
2958 " from non-associated STA " MACSTR
2959 " (type=0x%02x, subtype=0x%02x)\n",
2960 dev->name, MAC2STR(hdr->addr2), type,
2961 stype);
2962 hostap_rx(dev, skb, rx_stats);
2963#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2964 }
2965 ret = AP_RX_EXIT;
2966 goto out;
2967 }
2968 } else if (fc & WLAN_FC_FROMDS) {
2969 if (!wds) {
2970 /* FromDS frame - not for us; probably
2971 * broadcast/multicast in another BSS - drop */
2972 if (memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2973 printk(KERN_DEBUG "Odd.. FromDS packet "
2974 "received with own BSSID\n");
2975 hostap_dump_rx_80211(dev->name, skb, rx_stats);
2976 }
2977 ret = AP_RX_DROP;
2978 goto out;
2979 }
2980 } else if (stype == WLAN_FC_STYPE_NULLFUNC && sta == NULL &&
2981 memcmp(hdr->addr1, dev->dev_addr, ETH_ALEN) == 0) {
2982
2983 if (local->hostapd) {
2984 prism2_rx_80211(local->apdev, skb, rx_stats,
2985 PRISM2_RX_NON_ASSOC);
2986#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
2987 } else {
2988 /* At least Lucent f/w seems to send data::nullfunc
2989 * frames with no ToDS flag when the current AP returns
2990 * after being unavailable for some time. Speed up
2991 * re-association by informing the station about it not
2992 * being associated. */
2993 printk(KERN_DEBUG "%s: rejected received nullfunc "
2994 "frame without ToDS from not associated STA "
2995 MACSTR "\n",
2996 dev->name, MAC2STR(hdr->addr2));
2997 hostap_rx(dev, skb, rx_stats);
2998#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
2999 }
3000 ret = AP_RX_EXIT;
3001 goto out;
3002 } else if (stype == WLAN_FC_STYPE_NULLFUNC) {
3003 /* At least Lucent cards seem to send periodic nullfunc
3004 * frames with ToDS. Let these through to update SQ
3005 * stats and PS state. Nullfunc frames do not contain
3006 * any data and they will be dropped below. */
3007 } else {
3008 /* If BSSID (Addr3) is foreign, this frame is a normal
3009 * broadcast frame from an IBSS network. Drop it silently.
3010 * If BSSID is own, report the dropping of this frame. */
3011 if (memcmp(hdr->addr3, dev->dev_addr, ETH_ALEN) == 0) {
3012 printk(KERN_DEBUG "%s: dropped received packet from "
3013 MACSTR " with no ToDS flag (type=0x%02x, "
3014 "subtype=0x%02x)\n", dev->name,
3015 MAC2STR(hdr->addr2), type, stype);
3016 hostap_dump_rx_80211(dev->name, skb, rx_stats);
3017 }
3018 ret = AP_RX_DROP;
3019 goto out;
3020 }
3021
3022 if (sta) {
3023 hostap_update_sta_ps2(local, sta, fc & WLAN_FC_PWRMGT,
3024 type, stype);
3025
3026 sta->rx_packets++;
3027 sta->rx_bytes += skb->len;
3028 sta->last_rx = jiffies;
3029 }
3030
3031 if (local->ap->nullfunc_ack && stype == WLAN_FC_STYPE_NULLFUNC &&
3032 fc & WLAN_FC_TODS) {
3033 if (local->hostapd) {
3034 prism2_rx_80211(local->apdev, skb, rx_stats,
3035 PRISM2_RX_NULLFUNC_ACK);
3036#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3037 } else {
3038 /* some STA f/w's seem to require control::ACK frame
3039 * for data::nullfunc, but Prism2 f/w 0.8.0 (at least
3040 * from Compaq) does not send this.. Try to generate
3041 * ACK for these frames from the host driver to make
3042 * power saving work with, e.g., Lucent WaveLAN f/w */
3043 hostap_rx(dev, skb, rx_stats);
3044#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3045 }
3046 ret = AP_RX_EXIT;
3047 goto out;
3048 }
3049
3050 out:
3051 if (sta)
3052 atomic_dec(&sta->users);
3053
3054 return ret;
3055}
3056
3057
3058/* Called only as a tasklet (software IRQ) */
3059int hostap_handle_sta_crypto(local_info_t *local,
3060 struct hostap_ieee80211_hdr *hdr,
3061 struct ieee80211_crypt_data **crypt,
3062 void **sta_ptr)
3063{
3064 struct sta_info *sta;
3065
3066 spin_lock(&local->ap->sta_table_lock);
3067 sta = ap_get_sta(local->ap, hdr->addr2);
3068 if (sta)
3069 atomic_inc(&sta->users);
3070 spin_unlock(&local->ap->sta_table_lock);
3071
3072 if (!sta)
3073 return -1;
3074
3075 if (sta->crypt) {
3076 *crypt = sta->crypt;
3077 *sta_ptr = sta;
3078 /* hostap_handle_sta_release() will be called to release STA
3079 * info */
3080 } else
3081 atomic_dec(&sta->users);
3082
3083 return 0;
3084}
3085
3086
3087/* Called only as a tasklet (software IRQ) */
3088int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr)
3089{
3090 struct sta_info *sta;
3091 int ret = 0;
3092
3093 spin_lock(&ap->sta_table_lock);
3094 sta = ap_get_sta(ap, sta_addr);
3095 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap)
3096 ret = 1;
3097 spin_unlock(&ap->sta_table_lock);
3098
3099 return ret;
3100}
3101
3102
3103/* Called only as a tasklet (software IRQ) */
3104int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr)
3105{
3106 struct sta_info *sta;
3107 int ret = 0;
3108
3109 spin_lock(&ap->sta_table_lock);
3110 sta = ap_get_sta(ap, sta_addr);
3111 if (sta != NULL && (sta->flags & WLAN_STA_ASSOC) && !sta->ap &&
3112 ((sta->flags & WLAN_STA_AUTHORIZED) ||
3113 ap->local->ieee_802_1x == 0))
3114 ret = 1;
3115 spin_unlock(&ap->sta_table_lock);
3116
3117 return ret;
3118}
3119
3120
3121/* Called only as a tasklet (software IRQ) */
3122int hostap_add_sta(struct ap_data *ap, u8 *sta_addr)
3123{
3124 struct sta_info *sta;
3125 int ret = 1;
3126
3127 if (!ap)
3128 return -1;
3129
3130 spin_lock(&ap->sta_table_lock);
3131 sta = ap_get_sta(ap, sta_addr);
3132 if (sta)
3133 ret = 0;
3134 spin_unlock(&ap->sta_table_lock);
3135
3136 if (ret == 1) {
3137 sta = ap_add_sta(ap, sta_addr);
3138 if (!sta)
3139 ret = -1;
3140 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
3141 sta->ap = 1;
3142 memset(sta->supported_rates, 0, sizeof(sta->supported_rates));
3143 /* No way of knowing which rates are supported since we did not
3144 * get supported rates element from beacon/assoc req. Assume
3145 * that remote end supports all 802.11b rates. */
3146 sta->supported_rates[0] = 0x82;
3147 sta->supported_rates[1] = 0x84;
3148 sta->supported_rates[2] = 0x0b;
3149 sta->supported_rates[3] = 0x16;
3150 sta->tx_supp_rates = WLAN_RATE_1M | WLAN_RATE_2M |
3151 WLAN_RATE_5M5 | WLAN_RATE_11M;
3152 sta->tx_rate = 110;
3153 sta->tx_max_rate = sta->tx_rate_idx = 3;
3154 }
3155
3156 return ret;
3157}
3158
3159
3160/* Called only as a tasklet (software IRQ) */
3161int hostap_update_rx_stats(struct ap_data *ap,
3162 struct hostap_ieee80211_hdr *hdr,
3163 struct hostap_80211_rx_status *rx_stats)
3164{
3165 struct sta_info *sta;
3166
3167 if (!ap)
3168 return -1;
3169
3170 spin_lock(&ap->sta_table_lock);
3171 sta = ap_get_sta(ap, hdr->addr2);
3172 if (sta) {
3173 sta->last_rx_silence = rx_stats->noise;
3174 sta->last_rx_signal = rx_stats->signal;
3175 sta->last_rx_rate = rx_stats->rate;
3176 sta->last_rx_updated = 7;
3177 if (rx_stats->rate == 10)
3178 sta->rx_count[0]++;
3179 else if (rx_stats->rate == 20)
3180 sta->rx_count[1]++;
3181 else if (rx_stats->rate == 55)
3182 sta->rx_count[2]++;
3183 else if (rx_stats->rate == 110)
3184 sta->rx_count[3]++;
3185 }
3186 spin_unlock(&ap->sta_table_lock);
3187
3188 return sta ? 0 : -1;
3189}
3190
3191
3192void hostap_update_rates(local_info_t *local)
3193{
3194 struct list_head *ptr;
3195 struct ap_data *ap = local->ap;
3196
3197 if (!ap)
3198 return;
3199
3200 spin_lock_bh(&ap->sta_table_lock);
3201 for (ptr = ap->sta_list.next; ptr != &ap->sta_list; ptr = ptr->next) {
3202 struct sta_info *sta = (struct sta_info *) ptr;
3203 prism2_check_tx_rates(sta);
3204 }
3205 spin_unlock_bh(&ap->sta_table_lock);
3206}
3207
3208
3209static void * ap_crypt_get_ptrs(struct ap_data *ap, u8 *addr, int permanent,
3210 struct ieee80211_crypt_data ***crypt)
3211{
3212 struct sta_info *sta;
3213
3214 spin_lock_bh(&ap->sta_table_lock);
3215 sta = ap_get_sta(ap, addr);
3216 if (sta)
3217 atomic_inc(&sta->users);
3218 spin_unlock_bh(&ap->sta_table_lock);
3219
3220 if (!sta && permanent)
3221 sta = ap_add_sta(ap, addr);
3222
3223 if (!sta)
3224 return NULL;
3225
3226 if (permanent)
3227 sta->flags |= WLAN_STA_PERM;
3228
3229 *crypt = &sta->crypt;
3230
3231 return sta;
3232}
3233
3234
3235void hostap_add_wds_links(local_info_t *local)
3236{
3237 struct ap_data *ap = local->ap;
3238 struct list_head *ptr;
3239
3240 spin_lock_bh(&ap->sta_table_lock);
3241 list_for_each(ptr, &ap->sta_list) {
3242 struct sta_info *sta = list_entry(ptr, struct sta_info, list);
3243 if (sta->ap)
3244 hostap_wds_link_oper(local, sta->addr, WDS_ADD);
3245 }
3246 spin_unlock_bh(&ap->sta_table_lock);
3247
3248 schedule_work(&local->ap->wds_oper_queue);
3249}
3250
3251
3252void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type)
3253{
3254 struct wds_oper_data *entry;
3255
3256 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
3257 if (!entry)
3258 return;
3259 memcpy(entry->addr, addr, ETH_ALEN);
3260 entry->type = type;
3261 spin_lock_bh(&local->lock);
3262 entry->next = local->ap->wds_oper_entries;
3263 local->ap->wds_oper_entries = entry;
3264 spin_unlock_bh(&local->lock);
3265
3266 schedule_work(&local->ap->wds_oper_queue);
3267}
3268
3269
3270EXPORT_SYMBOL(hostap_init_data);
3271EXPORT_SYMBOL(hostap_init_ap_proc);
3272EXPORT_SYMBOL(hostap_free_data);
3273EXPORT_SYMBOL(hostap_check_sta_fw_version);
3274EXPORT_SYMBOL(hostap_handle_sta_tx);
3275EXPORT_SYMBOL(hostap_handle_sta_release);
3276EXPORT_SYMBOL(hostap_handle_sta_tx_exc);
3277EXPORT_SYMBOL(hostap_update_sta_ps);
3278EXPORT_SYMBOL(hostap_handle_sta_rx);
3279EXPORT_SYMBOL(hostap_is_sta_assoc);
3280EXPORT_SYMBOL(hostap_is_sta_authorized);
3281EXPORT_SYMBOL(hostap_add_sta);
3282EXPORT_SYMBOL(hostap_update_rates);
3283EXPORT_SYMBOL(hostap_add_wds_links);
3284EXPORT_SYMBOL(hostap_wds_link_oper);
3285#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3286EXPORT_SYMBOL(hostap_deauth_all_stas);
3287#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
diff --git a/drivers/net/wireless/hostap/hostap_ap.h b/drivers/net/wireless/hostap/hostap_ap.h
new file mode 100644
index 000000000000..137f78e4532b
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_ap.h
@@ -0,0 +1,273 @@
1#ifndef HOSTAP_AP_H
2#define HOSTAP_AP_H
3
4/* AP data structures for STAs */
5
6/* maximum number of frames to buffer per STA */
7#define STA_MAX_TX_BUFFER 32
8
9/* Flags used in skb->cb[6] to control how the packet is handled in TX path.
10 * skb->cb[0..5] must contain magic value 'hostap' to indicate that cb[6] is
11 * used. */
12#define AP_SKB_CB_MAGIC "hostap"
13#define AP_SKB_CB_MAGIC_LEN 6
14#define AP_SKB_CB_BUFFERED_FRAME BIT(0)
15#define AP_SKB_CB_ADD_MOREDATA BIT(1)
16
17
18/* STA flags */
19#define WLAN_STA_AUTH BIT(0)
20#define WLAN_STA_ASSOC BIT(1)
21#define WLAN_STA_PS BIT(2)
22#define WLAN_STA_TIM BIT(3) /* TIM bit is on for PS stations */
23#define WLAN_STA_PERM BIT(4) /* permanent; do not remove entry on expiration */
24#define WLAN_STA_AUTHORIZED BIT(5) /* If 802.1X is used, this flag is
25 * controlling whether STA is authorized to
26 * send and receive non-IEEE 802.1X frames
27 */
28#define WLAN_STA_PENDING_POLL BIT(6) /* pending activity poll not ACKed */
29
30#define WLAN_RATE_1M BIT(0)
31#define WLAN_RATE_2M BIT(1)
32#define WLAN_RATE_5M5 BIT(2)
33#define WLAN_RATE_11M BIT(3)
34#define WLAN_RATE_COUNT 4
35
36/* Maximum size of Supported Rates info element. IEEE 802.11 has a limit of 8,
37 * but some pre-standard IEEE 802.11g products use longer elements. */
38#define WLAN_SUPP_RATES_MAX 32
39
40/* Try to increase TX rate after # successfully sent consecutive packets */
41#define WLAN_RATE_UPDATE_COUNT 50
42
43/* Decrease TX rate after # consecutive dropped packets */
44#define WLAN_RATE_DECREASE_THRESHOLD 2
45
46struct sta_info {
47 struct list_head list;
48 struct sta_info *hnext; /* next entry in hash table list */
49 atomic_t users; /* number of users (do not remove if > 0) */
50 struct proc_dir_entry *proc;
51
52 u8 addr[6];
53 u16 aid; /* STA's unique AID (1 .. 2007) or 0 if not yet assigned */
54 u32 flags;
55 u16 capability;
56 u16 listen_interval; /* or beacon_int for APs */
57 u8 supported_rates[WLAN_SUPP_RATES_MAX];
58
59 unsigned long last_auth;
60 unsigned long last_assoc;
61 unsigned long last_rx;
62 unsigned long last_tx;
63 unsigned long rx_packets, tx_packets;
64 unsigned long rx_bytes, tx_bytes;
65 struct sk_buff_head tx_buf;
66 /* FIX: timeout buffers with an expiry time somehow derived from
67 * listen_interval */
68
69 s8 last_rx_silence; /* Noise in dBm */
70 s8 last_rx_signal; /* Signal strength in dBm */
71 u8 last_rx_rate; /* TX rate in 0.1 Mbps */
72 u8 last_rx_updated; /* IWSPY's struct iw_quality::updated */
73
74 u8 tx_supp_rates; /* bit field of supported TX rates */
75 u8 tx_rate; /* current TX rate (in 0.1 Mbps) */
76 u8 tx_rate_idx; /* current TX rate (WLAN_RATE_*) */
77 u8 tx_max_rate; /* max TX rate (WLAN_RATE_*) */
78 u32 tx_count[WLAN_RATE_COUNT]; /* number of frames sent (per rate) */
79 u32 rx_count[WLAN_RATE_COUNT]; /* number of frames received (per rate)
80 */
81 u32 tx_since_last_failure;
82 u32 tx_consecutive_exc;
83
84 struct ieee80211_crypt_data *crypt;
85
86 int ap; /* whether this station is an AP */
87
88 local_info_t *local;
89
90#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
91 union {
92 struct {
93 char *challenge; /* shared key authentication
94 * challenge */
95 } sta;
96 struct {
97 int ssid_len;
98 unsigned char ssid[MAX_SSID_LEN + 1]; /* AP's ssid */
99 int channel;
100 unsigned long last_beacon; /* last RX beacon time */
101 } ap;
102 } u;
103
104 struct timer_list timer;
105 enum { STA_NULLFUNC = 0, STA_DISASSOC, STA_DEAUTH } timeout_next;
106#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
107};
108
109
110#define MAX_STA_COUNT 1024
111
112/* Maximum number of AIDs to use for STAs; must be 2007 or lower
113 * (8802.11 limitation) */
114#define MAX_AID_TABLE_SIZE 128
115
116#define STA_HASH_SIZE 256
117#define STA_HASH(sta) (sta[5])
118
119
120/* Default value for maximum station inactivity. After AP_MAX_INACTIVITY_SEC
121 * has passed since last received frame from the station, a nullfunc data
122 * frame is sent to the station. If this frame is not acknowledged and no other
123 * frames have been received, the station will be disassociated after
124 * AP_DISASSOC_DELAY. Similarily, a the station will be deauthenticated after
125 * AP_DEAUTH_DELAY. AP_TIMEOUT_RESOLUTION is the resolution that is used with
126 * max inactivity timer. */
127#define AP_MAX_INACTIVITY_SEC (5 * 60)
128#define AP_DISASSOC_DELAY (HZ)
129#define AP_DEAUTH_DELAY (HZ)
130
131/* ap_policy: whether to accept frames to/from other APs/IBSS */
132typedef enum {
133 AP_OTHER_AP_SKIP_ALL = 0,
134 AP_OTHER_AP_SAME_SSID = 1,
135 AP_OTHER_AP_ALL = 2,
136 AP_OTHER_AP_EVEN_IBSS = 3
137} ap_policy_enum;
138
139#define PRISM2_AUTH_OPEN BIT(0)
140#define PRISM2_AUTH_SHARED_KEY BIT(1)
141
142
143/* MAC address-based restrictions */
144struct mac_entry {
145 struct list_head list;
146 u8 addr[6];
147};
148
149struct mac_restrictions {
150 enum { MAC_POLICY_OPEN = 0, MAC_POLICY_ALLOW, MAC_POLICY_DENY } policy;
151 unsigned int entries;
152 struct list_head mac_list;
153 spinlock_t lock;
154};
155
156
157struct add_sta_proc_data {
158 u8 addr[ETH_ALEN];
159 struct add_sta_proc_data *next;
160};
161
162
163typedef enum { WDS_ADD, WDS_DEL } wds_oper_type;
164struct wds_oper_data {
165 wds_oper_type type;
166 u8 addr[ETH_ALEN];
167 struct wds_oper_data *next;
168};
169
170
171struct ap_data {
172 int initialized; /* whether ap_data has been initialized */
173 local_info_t *local;
174 int bridge_packets; /* send packet to associated STAs directly to the
175 * wireless media instead of higher layers in the
176 * kernel */
177 unsigned int bridged_unicast; /* number of unicast frames bridged on
178 * wireless media */
179 unsigned int bridged_multicast; /* number of non-unicast frames
180 * bridged on wireless media */
181 unsigned int tx_drop_nonassoc; /* number of unicast TX packets dropped
182 * because they were to an address that
183 * was not associated */
184 int nullfunc_ack; /* use workaround for nullfunc frame ACKs */
185
186 spinlock_t sta_table_lock;
187 int num_sta; /* number of entries in sta_list */
188 struct list_head sta_list; /* STA info list head */
189 struct sta_info *sta_hash[STA_HASH_SIZE];
190
191 struct proc_dir_entry *proc;
192
193 ap_policy_enum ap_policy;
194 unsigned int max_inactivity;
195 int autom_ap_wds;
196
197 struct mac_restrictions mac_restrictions; /* MAC-based auth */
198 int last_tx_rate;
199
200 struct work_struct add_sta_proc_queue;
201 struct add_sta_proc_data *add_sta_proc_entries;
202
203 struct work_struct wds_oper_queue;
204 struct wds_oper_data *wds_oper_entries;
205
206 u16 tx_callback_idx;
207
208#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
209 /* pointers to STA info; based on allocated AID or NULL if AID free
210 * AID is in the range 1-2007, so sta_aid[0] corresponders to AID 1
211 * and so on
212 */
213 struct sta_info *sta_aid[MAX_AID_TABLE_SIZE];
214
215 u16 tx_callback_auth, tx_callback_assoc, tx_callback_poll;
216
217 /* WEP operations for generating challenges to be used with shared key
218 * authentication */
219 struct ieee80211_crypto_ops *crypt;
220 void *crypt_priv;
221#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
222};
223
224
225void hostap_rx(struct net_device *dev, struct sk_buff *skb,
226 struct hostap_80211_rx_status *rx_stats);
227void hostap_init_data(local_info_t *local);
228void hostap_init_ap_proc(local_info_t *local);
229void hostap_free_data(struct ap_data *ap);
230void hostap_check_sta_fw_version(struct ap_data *ap, int sta_fw_ver);
231
232typedef enum {
233 AP_TX_CONTINUE, AP_TX_DROP, AP_TX_RETRY, AP_TX_BUFFERED,
234 AP_TX_CONTINUE_NOT_AUTHORIZED
235} ap_tx_ret;
236struct hostap_tx_data {
237 struct sk_buff *skb;
238 int host_encrypt;
239 struct ieee80211_crypt_data *crypt;
240 void *sta_ptr;
241};
242ap_tx_ret hostap_handle_sta_tx(local_info_t *local, struct hostap_tx_data *tx);
243void hostap_handle_sta_release(void *ptr);
244void hostap_handle_sta_tx_exc(local_info_t *local, struct sk_buff *skb);
245int hostap_update_sta_ps(local_info_t *local,
246 struct hostap_ieee80211_hdr *hdr);
247typedef enum {
248 AP_RX_CONTINUE, AP_RX_DROP, AP_RX_EXIT, AP_RX_CONTINUE_NOT_AUTHORIZED
249} ap_rx_ret;
250ap_rx_ret hostap_handle_sta_rx(local_info_t *local, struct net_device *dev,
251 struct sk_buff *skb,
252 struct hostap_80211_rx_status *rx_stats,
253 int wds);
254int hostap_handle_sta_crypto(local_info_t *local,
255 struct hostap_ieee80211_hdr *hdr,
256 struct ieee80211_crypt_data **crypt,
257 void **sta_ptr);
258int hostap_is_sta_assoc(struct ap_data *ap, u8 *sta_addr);
259int hostap_is_sta_authorized(struct ap_data *ap, u8 *sta_addr);
260int hostap_add_sta(struct ap_data *ap, u8 *sta_addr);
261int hostap_update_rx_stats(struct ap_data *ap,
262 struct hostap_ieee80211_hdr *hdr,
263 struct hostap_80211_rx_status *rx_stats);
264void hostap_update_rates(local_info_t *local);
265void hostap_add_wds_links(local_info_t *local);
266void hostap_wds_link_oper(local_info_t *local, u8 *addr, wds_oper_type type);
267
268#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
269void hostap_deauth_all_stas(struct net_device *dev, struct ap_data *ap,
270 int resend);
271#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
272
273#endif /* HOSTAP_AP_H */
diff --git a/drivers/net/wireless/hostap/hostap_common.h b/drivers/net/wireless/hostap/hostap_common.h
new file mode 100644
index 000000000000..3b79d9e95e6f
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_common.h
@@ -0,0 +1,499 @@
1#ifndef HOSTAP_COMMON_H
2#define HOSTAP_COMMON_H
3
4#define BIT(x) (1 << (x))
5
6#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
7#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
8
9
10#ifndef ETH_P_PAE
11#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */
12#endif /* ETH_P_PAE */
13
14#define ETH_P_PREAUTH 0x88C7 /* IEEE 802.11i pre-authentication */
15
16
17
18/* IEEE 802.11 defines */
19
20#define WLAN_FC_PVER (BIT(1) | BIT(0))
21#define WLAN_FC_TODS BIT(8)
22#define WLAN_FC_FROMDS BIT(9)
23#define WLAN_FC_MOREFRAG BIT(10)
24#define WLAN_FC_RETRY BIT(11)
25#define WLAN_FC_PWRMGT BIT(12)
26#define WLAN_FC_MOREDATA BIT(13)
27#define WLAN_FC_ISWEP BIT(14)
28#define WLAN_FC_ORDER BIT(15)
29
30/*
31 * To be replaced with ieee80211.h WLAN_FC_GET_* once HostAP code is updated to
32 * use the versions without right shift.
33 */
34#define HOSTAP_FC_GET_TYPE(fc) (((fc) & (BIT(3) | BIT(2))) >> 2)
35#define HOSTAP_FC_GET_STYPE(fc) \
36 (((fc) & (BIT(7) | BIT(6) | BIT(5) | BIT(4))) >> 4)
37
38#define WLAN_FC_TYPE_MGMT 0
39#define WLAN_FC_TYPE_CTRL 1
40#define WLAN_FC_TYPE_DATA 2
41
42/* management */
43#define WLAN_FC_STYPE_ASSOC_REQ 0
44#define WLAN_FC_STYPE_ASSOC_RESP 1
45#define WLAN_FC_STYPE_REASSOC_REQ 2
46#define WLAN_FC_STYPE_REASSOC_RESP 3
47#define WLAN_FC_STYPE_PROBE_REQ 4
48#define WLAN_FC_STYPE_PROBE_RESP 5
49#define WLAN_FC_STYPE_BEACON 8
50#define WLAN_FC_STYPE_ATIM 9
51#define WLAN_FC_STYPE_DISASSOC 10
52#define WLAN_FC_STYPE_AUTH 11
53#define WLAN_FC_STYPE_DEAUTH 12
54
55/* control */
56#define WLAN_FC_STYPE_PSPOLL 10
57#define WLAN_FC_STYPE_RTS 11
58#define WLAN_FC_STYPE_CTS 12
59#define WLAN_FC_STYPE_ACK 13
60#define WLAN_FC_STYPE_CFEND 14
61#define WLAN_FC_STYPE_CFENDACK 15
62
63/* data */
64#define WLAN_FC_STYPE_DATA 0
65#define WLAN_FC_STYPE_DATA_CFACK 1
66#define WLAN_FC_STYPE_DATA_CFPOLL 2
67#define WLAN_FC_STYPE_DATA_CFACKPOLL 3
68#define WLAN_FC_STYPE_NULLFUNC 4
69#define WLAN_FC_STYPE_CFACK 5
70#define WLAN_FC_STYPE_CFPOLL 6
71#define WLAN_FC_STYPE_CFACKPOLL 7
72
73#define WLAN_CAPABILITY_ESS WLAN_CAPABILITY_BSS
74
75
76/* Information Element IDs */
77#define WLAN_EID_SSID 0
78#define WLAN_EID_SUPP_RATES 1
79#define WLAN_EID_FH_PARAMS 2
80#define WLAN_EID_DS_PARAMS 3
81#define WLAN_EID_CF_PARAMS 4
82#define WLAN_EID_TIM 5
83#define WLAN_EID_IBSS_PARAMS 6
84#define WLAN_EID_CHALLENGE 16
85#define WLAN_EID_RSN 48
86#define WLAN_EID_GENERIC 221
87
88
89/* HFA384X Configuration RIDs */
90#define HFA384X_RID_CNFPORTTYPE 0xFC00
91#define HFA384X_RID_CNFOWNMACADDR 0xFC01
92#define HFA384X_RID_CNFDESIREDSSID 0xFC02
93#define HFA384X_RID_CNFOWNCHANNEL 0xFC03
94#define HFA384X_RID_CNFOWNSSID 0xFC04
95#define HFA384X_RID_CNFOWNATIMWINDOW 0xFC05
96#define HFA384X_RID_CNFSYSTEMSCALE 0xFC06
97#define HFA384X_RID_CNFMAXDATALEN 0xFC07
98#define HFA384X_RID_CNFWDSADDRESS 0xFC08
99#define HFA384X_RID_CNFPMENABLED 0xFC09
100#define HFA384X_RID_CNFPMEPS 0xFC0A
101#define HFA384X_RID_CNFMULTICASTRECEIVE 0xFC0B
102#define HFA384X_RID_CNFMAXSLEEPDURATION 0xFC0C
103#define HFA384X_RID_CNFPMHOLDOVERDURATION 0xFC0D
104#define HFA384X_RID_CNFOWNNAME 0xFC0E
105#define HFA384X_RID_CNFOWNDTIMPERIOD 0xFC10
106#define HFA384X_RID_CNFWDSADDRESS1 0xFC11 /* AP f/w only */
107#define HFA384X_RID_CNFWDSADDRESS2 0xFC12 /* AP f/w only */
108#define HFA384X_RID_CNFWDSADDRESS3 0xFC13 /* AP f/w only */
109#define HFA384X_RID_CNFWDSADDRESS4 0xFC14 /* AP f/w only */
110#define HFA384X_RID_CNFWDSADDRESS5 0xFC15 /* AP f/w only */
111#define HFA384X_RID_CNFWDSADDRESS6 0xFC16 /* AP f/w only */
112#define HFA384X_RID_CNFMULTICASTPMBUFFERING 0xFC17 /* AP f/w only */
113#define HFA384X_RID_UNKNOWN1 0xFC20
114#define HFA384X_RID_UNKNOWN2 0xFC21
115#define HFA384X_RID_CNFWEPDEFAULTKEYID 0xFC23
116#define HFA384X_RID_CNFDEFAULTKEY0 0xFC24
117#define HFA384X_RID_CNFDEFAULTKEY1 0xFC25
118#define HFA384X_RID_CNFDEFAULTKEY2 0xFC26
119#define HFA384X_RID_CNFDEFAULTKEY3 0xFC27
120#define HFA384X_RID_CNFWEPFLAGS 0xFC28
121#define HFA384X_RID_CNFWEPKEYMAPPINGTABLE 0xFC29
122#define HFA384X_RID_CNFAUTHENTICATION 0xFC2A
123#define HFA384X_RID_CNFMAXASSOCSTA 0xFC2B /* AP f/w only */
124#define HFA384X_RID_CNFTXCONTROL 0xFC2C
125#define HFA384X_RID_CNFROAMINGMODE 0xFC2D
126#define HFA384X_RID_CNFHOSTAUTHENTICATION 0xFC2E /* AP f/w only */
127#define HFA384X_RID_CNFRCVCRCERROR 0xFC30
128#define HFA384X_RID_CNFMMLIFE 0xFC31
129#define HFA384X_RID_CNFALTRETRYCOUNT 0xFC32
130#define HFA384X_RID_CNFBEACONINT 0xFC33
131#define HFA384X_RID_CNFAPPCFINFO 0xFC34 /* AP f/w only */
132#define HFA384X_RID_CNFSTAPCFINFO 0xFC35
133#define HFA384X_RID_CNFPRIORITYQUSAGE 0xFC37
134#define HFA384X_RID_CNFTIMCTRL 0xFC40
135#define HFA384X_RID_UNKNOWN3 0xFC41 /* added in STA f/w 0.7.x */
136#define HFA384X_RID_CNFTHIRTY2TALLY 0xFC42 /* added in STA f/w 0.8.0 */
137#define HFA384X_RID_CNFENHSECURITY 0xFC43 /* AP f/w or STA f/w >= 1.6.3 */
138#define HFA384X_RID_CNFDBMADJUST 0xFC46 /* added in STA f/w 1.3.1 */
139#define HFA384X_RID_GENERICELEMENT 0xFC48 /* added in STA f/w 1.7.0;
140 * write only */
141#define HFA384X_RID_PROPAGATIONDELAY 0xFC49 /* added in STA f/w 1.7.6 */
142#define HFA384X_RID_GROUPADDRESSES 0xFC80
143#define HFA384X_RID_CREATEIBSS 0xFC81
144#define HFA384X_RID_FRAGMENTATIONTHRESHOLD 0xFC82
145#define HFA384X_RID_RTSTHRESHOLD 0xFC83
146#define HFA384X_RID_TXRATECONTROL 0xFC84
147#define HFA384X_RID_PROMISCUOUSMODE 0xFC85
148#define HFA384X_RID_FRAGMENTATIONTHRESHOLD0 0xFC90 /* AP f/w only */
149#define HFA384X_RID_FRAGMENTATIONTHRESHOLD1 0xFC91 /* AP f/w only */
150#define HFA384X_RID_FRAGMENTATIONTHRESHOLD2 0xFC92 /* AP f/w only */
151#define HFA384X_RID_FRAGMENTATIONTHRESHOLD3 0xFC93 /* AP f/w only */
152#define HFA384X_RID_FRAGMENTATIONTHRESHOLD4 0xFC94 /* AP f/w only */
153#define HFA384X_RID_FRAGMENTATIONTHRESHOLD5 0xFC95 /* AP f/w only */
154#define HFA384X_RID_FRAGMENTATIONTHRESHOLD6 0xFC96 /* AP f/w only */
155#define HFA384X_RID_RTSTHRESHOLD0 0xFC97 /* AP f/w only */
156#define HFA384X_RID_RTSTHRESHOLD1 0xFC98 /* AP f/w only */
157#define HFA384X_RID_RTSTHRESHOLD2 0xFC99 /* AP f/w only */
158#define HFA384X_RID_RTSTHRESHOLD3 0xFC9A /* AP f/w only */
159#define HFA384X_RID_RTSTHRESHOLD4 0xFC9B /* AP f/w only */
160#define HFA384X_RID_RTSTHRESHOLD5 0xFC9C /* AP f/w only */
161#define HFA384X_RID_RTSTHRESHOLD6 0xFC9D /* AP f/w only */
162#define HFA384X_RID_TXRATECONTROL0 0xFC9E /* AP f/w only */
163#define HFA384X_RID_TXRATECONTROL1 0xFC9F /* AP f/w only */
164#define HFA384X_RID_TXRATECONTROL2 0xFCA0 /* AP f/w only */
165#define HFA384X_RID_TXRATECONTROL3 0xFCA1 /* AP f/w only */
166#define HFA384X_RID_TXRATECONTROL4 0xFCA2 /* AP f/w only */
167#define HFA384X_RID_TXRATECONTROL5 0xFCA3 /* AP f/w only */
168#define HFA384X_RID_TXRATECONTROL6 0xFCA4 /* AP f/w only */
169#define HFA384X_RID_CNFSHORTPREAMBLE 0xFCB0
170#define HFA384X_RID_CNFEXCLUDELONGPREAMBLE 0xFCB1
171#define HFA384X_RID_CNFAUTHENTICATIONRSPTO 0xFCB2
172#define HFA384X_RID_CNFBASICRATES 0xFCB3
173#define HFA384X_RID_CNFSUPPORTEDRATES 0xFCB4
174#define HFA384X_RID_CNFFALLBACKCTRL 0xFCB5 /* added in STA f/w 1.3.1 */
175#define HFA384X_RID_WEPKEYDISABLE 0xFCB6 /* added in STA f/w 1.3.1 */
176#define HFA384X_RID_WEPKEYMAPINDEX 0xFCB7 /* ? */
177#define HFA384X_RID_BROADCASTKEYID 0xFCB8 /* ? */
178#define HFA384X_RID_ENTSECFLAGEYID 0xFCB9 /* ? */
179#define HFA384X_RID_CNFPASSIVESCANCTRL 0xFCBA /* added in STA f/w 1.5.0 */
180#define HFA384X_RID_SSNHANDLINGMODE 0xFCBB /* added in STA f/w 1.7.0 */
181#define HFA384X_RID_MDCCONTROL 0xFCBC /* added in STA f/w 1.7.0 */
182#define HFA384X_RID_MDCCOUNTRY 0xFCBD /* added in STA f/w 1.7.0 */
183#define HFA384X_RID_TXPOWERMAX 0xFCBE /* added in STA f/w 1.7.0 */
184#define HFA384X_RID_CNFLFOENABLED 0xFCBF /* added in STA f/w 1.6.3 */
185#define HFA384X_RID_CAPINFO 0xFCC0 /* added in STA f/w 1.7.0 */
186#define HFA384X_RID_LISTENINTERVAL 0xFCC1 /* added in STA f/w 1.7.0 */
187#define HFA384X_RID_SW_ANT_DIV 0xFCC2 /* added in STA f/w 1.7.0; Prism3 */
188#define HFA384X_RID_LED_CTRL 0xFCC4 /* added in STA f/w 1.7.6 */
189#define HFA384X_RID_HFODELAY 0xFCC5 /* added in STA f/w 1.7.6 */
190#define HFA384X_RID_DISALLOWEDBSSID 0xFCC6 /* added in STA f/w 1.8.0 */
191#define HFA384X_RID_TICKTIME 0xFCE0
192#define HFA384X_RID_SCANREQUEST 0xFCE1
193#define HFA384X_RID_JOINREQUEST 0xFCE2
194#define HFA384X_RID_AUTHENTICATESTATION 0xFCE3 /* AP f/w only */
195#define HFA384X_RID_CHANNELINFOREQUEST 0xFCE4 /* AP f/w only */
196#define HFA384X_RID_HOSTSCAN 0xFCE5 /* added in STA f/w 1.3.1 */
197
198/* HFA384X Information RIDs */
199#define HFA384X_RID_MAXLOADTIME 0xFD00
200#define HFA384X_RID_DOWNLOADBUFFER 0xFD01
201#define HFA384X_RID_PRIID 0xFD02
202#define HFA384X_RID_PRISUPRANGE 0xFD03
203#define HFA384X_RID_CFIACTRANGES 0xFD04
204#define HFA384X_RID_NICSERNUM 0xFD0A
205#define HFA384X_RID_NICID 0xFD0B
206#define HFA384X_RID_MFISUPRANGE 0xFD0C
207#define HFA384X_RID_CFISUPRANGE 0xFD0D
208#define HFA384X_RID_CHANNELLIST 0xFD10
209#define HFA384X_RID_REGULATORYDOMAINS 0xFD11
210#define HFA384X_RID_TEMPTYPE 0xFD12
211#define HFA384X_RID_CIS 0xFD13
212#define HFA384X_RID_STAID 0xFD20
213#define HFA384X_RID_STASUPRANGE 0xFD21
214#define HFA384X_RID_MFIACTRANGES 0xFD22
215#define HFA384X_RID_CFIACTRANGES2 0xFD23
216#define HFA384X_RID_PRODUCTNAME 0xFD24 /* added in STA f/w 1.3.1;
217 * only Prism2.5(?) */
218#define HFA384X_RID_PORTSTATUS 0xFD40
219#define HFA384X_RID_CURRENTSSID 0xFD41
220#define HFA384X_RID_CURRENTBSSID 0xFD42
221#define HFA384X_RID_COMMSQUALITY 0xFD43
222#define HFA384X_RID_CURRENTTXRATE 0xFD44
223#define HFA384X_RID_CURRENTBEACONINTERVAL 0xFD45
224#define HFA384X_RID_CURRENTSCALETHRESHOLDS 0xFD46
225#define HFA384X_RID_PROTOCOLRSPTIME 0xFD47
226#define HFA384X_RID_SHORTRETRYLIMIT 0xFD48
227#define HFA384X_RID_LONGRETRYLIMIT 0xFD49
228#define HFA384X_RID_MAXTRANSMITLIFETIME 0xFD4A
229#define HFA384X_RID_MAXRECEIVELIFETIME 0xFD4B
230#define HFA384X_RID_CFPOLLABLE 0xFD4C
231#define HFA384X_RID_AUTHENTICATIONALGORITHMS 0xFD4D
232#define HFA384X_RID_PRIVACYOPTIONIMPLEMENTED 0xFD4F
233#define HFA384X_RID_DBMCOMMSQUALITY 0xFD51 /* added in STA f/w 1.3.1 */
234#define HFA384X_RID_CURRENTTXRATE1 0xFD80 /* AP f/w only */
235#define HFA384X_RID_CURRENTTXRATE2 0xFD81 /* AP f/w only */
236#define HFA384X_RID_CURRENTTXRATE3 0xFD82 /* AP f/w only */
237#define HFA384X_RID_CURRENTTXRATE4 0xFD83 /* AP f/w only */
238#define HFA384X_RID_CURRENTTXRATE5 0xFD84 /* AP f/w only */
239#define HFA384X_RID_CURRENTTXRATE6 0xFD85 /* AP f/w only */
240#define HFA384X_RID_OWNMACADDR 0xFD86 /* AP f/w only */
241#define HFA384X_RID_SCANRESULTSTABLE 0xFD88 /* added in STA f/w 0.8.3 */
242#define HFA384X_RID_HOSTSCANRESULTS 0xFD89 /* added in STA f/w 1.3.1 */
243#define HFA384X_RID_AUTHENTICATIONUSED 0xFD8A /* added in STA f/w 1.3.4 */
244#define HFA384X_RID_CNFFAASWITCHCTRL 0xFD8B /* added in STA f/w 1.6.3 */
245#define HFA384X_RID_ASSOCIATIONFAILURE 0xFD8D /* added in STA f/w 1.8.0 */
246#define HFA384X_RID_PHYTYPE 0xFDC0
247#define HFA384X_RID_CURRENTCHANNEL 0xFDC1
248#define HFA384X_RID_CURRENTPOWERSTATE 0xFDC2
249#define HFA384X_RID_CCAMODE 0xFDC3
250#define HFA384X_RID_SUPPORTEDDATARATES 0xFDC6
251#define HFA384X_RID_LFO_VOLT_REG_TEST_RES 0xFDC7 /* added in STA f/w 1.7.1 */
252#define HFA384X_RID_BUILDSEQ 0xFFFE
253#define HFA384X_RID_FWID 0xFFFF
254
255
256struct hfa384x_comp_ident
257{
258 u16 id;
259 u16 variant;
260 u16 major;
261 u16 minor;
262} __attribute__ ((packed));
263
264#define HFA384X_COMP_ID_PRI 0x15
265#define HFA384X_COMP_ID_STA 0x1f
266#define HFA384X_COMP_ID_FW_AP 0x14b
267
268struct hfa384x_sup_range
269{
270 u16 role;
271 u16 id;
272 u16 variant;
273 u16 bottom;
274 u16 top;
275} __attribute__ ((packed));
276
277
278struct hfa384x_build_id
279{
280 u16 pri_seq;
281 u16 sec_seq;
282} __attribute__ ((packed));
283
284/* FD01 - Download Buffer */
285struct hfa384x_rid_download_buffer
286{
287 u16 page;
288 u16 offset;
289 u16 length;
290} __attribute__ ((packed));
291
292/* BSS connection quality (RID FD43 range, RID FD51 dBm-normalized) */
293struct hfa384x_comms_quality {
294 u16 comm_qual; /* 0 .. 92 */
295 u16 signal_level; /* 27 .. 154 */
296 u16 noise_level; /* 27 .. 154 */
297} __attribute__ ((packed));
298
299
300/* netdevice private ioctls (used, e.g., with iwpriv from user space) */
301
302/* New wireless extensions API - SET/GET convention (even ioctl numbers are
303 * root only)
304 */
305#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
306#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
307#define PRISM2_IOCTL_WRITEMIF (SIOCIWFIRSTPRIV + 2)
308#define PRISM2_IOCTL_READMIF (SIOCIWFIRSTPRIV + 3)
309#define PRISM2_IOCTL_MONITOR (SIOCIWFIRSTPRIV + 4)
310#define PRISM2_IOCTL_RESET (SIOCIWFIRSTPRIV + 6)
311#define PRISM2_IOCTL_INQUIRE (SIOCIWFIRSTPRIV + 8)
312#define PRISM2_IOCTL_WDS_ADD (SIOCIWFIRSTPRIV + 10)
313#define PRISM2_IOCTL_WDS_DEL (SIOCIWFIRSTPRIV + 12)
314#define PRISM2_IOCTL_SET_RID_WORD (SIOCIWFIRSTPRIV + 14)
315#define PRISM2_IOCTL_MACCMD (SIOCIWFIRSTPRIV + 16)
316#define PRISM2_IOCTL_ADDMAC (SIOCIWFIRSTPRIV + 18)
317#define PRISM2_IOCTL_DELMAC (SIOCIWFIRSTPRIV + 20)
318#define PRISM2_IOCTL_KICKMAC (SIOCIWFIRSTPRIV + 22)
319
320/* following are not in SIOCGIWPRIV list; check permission in the driver code
321 */
322#define PRISM2_IOCTL_DOWNLOAD (SIOCDEVPRIVATE + 13)
323#define PRISM2_IOCTL_HOSTAPD (SIOCDEVPRIVATE + 14)
324
325
326/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
327enum {
328 /* PRISM2_PARAM_PTYPE = 1, */ /* REMOVED 2003-10-22 */
329 PRISM2_PARAM_TXRATECTRL = 2,
330 PRISM2_PARAM_BEACON_INT = 3,
331 PRISM2_PARAM_PSEUDO_IBSS = 4,
332 PRISM2_PARAM_ALC = 5,
333 /* PRISM2_PARAM_TXPOWER = 6, */ /* REMOVED 2003-10-22 */
334 PRISM2_PARAM_DUMP = 7,
335 PRISM2_PARAM_OTHER_AP_POLICY = 8,
336 PRISM2_PARAM_AP_MAX_INACTIVITY = 9,
337 PRISM2_PARAM_AP_BRIDGE_PACKETS = 10,
338 PRISM2_PARAM_DTIM_PERIOD = 11,
339 PRISM2_PARAM_AP_NULLFUNC_ACK = 12,
340 PRISM2_PARAM_MAX_WDS = 13,
341 PRISM2_PARAM_AP_AUTOM_AP_WDS = 14,
342 PRISM2_PARAM_AP_AUTH_ALGS = 15,
343 PRISM2_PARAM_MONITOR_ALLOW_FCSERR = 16,
344 PRISM2_PARAM_HOST_ENCRYPT = 17,
345 PRISM2_PARAM_HOST_DECRYPT = 18,
346 PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX = 19,
347 PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX = 20,
348 PRISM2_PARAM_HOST_ROAMING = 21,
349 PRISM2_PARAM_BCRX_STA_KEY = 22,
350 PRISM2_PARAM_IEEE_802_1X = 23,
351 PRISM2_PARAM_ANTSEL_TX = 24,
352 PRISM2_PARAM_ANTSEL_RX = 25,
353 PRISM2_PARAM_MONITOR_TYPE = 26,
354 PRISM2_PARAM_WDS_TYPE = 27,
355 PRISM2_PARAM_HOSTSCAN = 28,
356 PRISM2_PARAM_AP_SCAN = 29,
357 PRISM2_PARAM_ENH_SEC = 30,
358 PRISM2_PARAM_IO_DEBUG = 31,
359 PRISM2_PARAM_BASIC_RATES = 32,
360 PRISM2_PARAM_OPER_RATES = 33,
361 PRISM2_PARAM_HOSTAPD = 34,
362 PRISM2_PARAM_HOSTAPD_STA = 35,
363 PRISM2_PARAM_WPA = 36,
364 PRISM2_PARAM_PRIVACY_INVOKED = 37,
365 PRISM2_PARAM_TKIP_COUNTERMEASURES = 38,
366 PRISM2_PARAM_DROP_UNENCRYPTED = 39,
367 PRISM2_PARAM_SCAN_CHANNEL_MASK = 40,
368};
369
370enum { HOSTAP_ANTSEL_DO_NOT_TOUCH = 0, HOSTAP_ANTSEL_DIVERSITY = 1,
371 HOSTAP_ANTSEL_LOW = 2, HOSTAP_ANTSEL_HIGH = 3 };
372
373
374/* PRISM2_IOCTL_MACCMD ioctl() subcommands: */
375enum { AP_MAC_CMD_POLICY_OPEN = 0, AP_MAC_CMD_POLICY_ALLOW = 1,
376 AP_MAC_CMD_POLICY_DENY = 2, AP_MAC_CMD_FLUSH = 3,
377 AP_MAC_CMD_KICKALL = 4 };
378
379
380/* PRISM2_IOCTL_DOWNLOAD ioctl() dl_cmd: */
381enum {
382 PRISM2_DOWNLOAD_VOLATILE = 1 /* RAM */,
383 /* Note! Old versions of prism2_srec have a fatal error in CRC-16
384 * calculation, which will corrupt all non-volatile downloads.
385 * PRISM2_DOWNLOAD_NON_VOLATILE used to be 2, but it is now 3 to
386 * prevent use of old versions of prism2_srec for non-volatile
387 * download. */
388 PRISM2_DOWNLOAD_NON_VOLATILE = 3 /* FLASH */,
389 PRISM2_DOWNLOAD_VOLATILE_GENESIS = 4 /* RAM in Genesis mode */,
390 /* Persistent versions of volatile download commands (keep firmware
391 * data in memory and automatically re-download after hw_reset */
392 PRISM2_DOWNLOAD_VOLATILE_PERSISTENT = 5,
393 PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT = 6,
394};
395
396struct prism2_download_param {
397 u32 dl_cmd;
398 u32 start_addr;
399 u32 num_areas;
400 struct prism2_download_area {
401 u32 addr; /* wlan card address */
402 u32 len;
403 void __user *ptr; /* pointer to data in user space */
404 } data[0];
405};
406
407#define PRISM2_MAX_DOWNLOAD_AREA_LEN 131072
408#define PRISM2_MAX_DOWNLOAD_LEN 262144
409
410
411/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
412enum {
413 PRISM2_HOSTAPD_FLUSH = 1,
414 PRISM2_HOSTAPD_ADD_STA = 2,
415 PRISM2_HOSTAPD_REMOVE_STA = 3,
416 PRISM2_HOSTAPD_GET_INFO_STA = 4,
417 /* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
418 PRISM2_SET_ENCRYPTION = 6,
419 PRISM2_GET_ENCRYPTION = 7,
420 PRISM2_HOSTAPD_SET_FLAGS_STA = 8,
421 PRISM2_HOSTAPD_GET_RID = 9,
422 PRISM2_HOSTAPD_SET_RID = 10,
423 PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
424 PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
425 PRISM2_HOSTAPD_MLME = 13,
426 PRISM2_HOSTAPD_SCAN_REQ = 14,
427 PRISM2_HOSTAPD_STA_CLEAR_STATS = 15,
428};
429
430#define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
431#define PRISM2_HOSTAPD_RID_HDR_LEN \
432((int) (&((struct prism2_hostapd_param *) 0)->u.rid.data))
433#define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
434((int) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data))
435
436/* Maximum length for algorithm names (-1 for nul termination) used in ioctl()
437 */
438#define HOSTAP_CRYPT_ALG_NAME_LEN 16
439
440
441struct prism2_hostapd_param {
442 u32 cmd;
443 u8 sta_addr[ETH_ALEN];
444 union {
445 struct {
446 u16 aid;
447 u16 capability;
448 u8 tx_supp_rates;
449 } add_sta;
450 struct {
451 u32 inactive_sec;
452 } get_info_sta;
453 struct {
454 u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
455 u32 flags;
456 u32 err;
457 u8 idx;
458 u8 seq[8]; /* sequence counter (set: RX, get: TX) */
459 u16 key_len;
460 u8 key[0];
461 } crypt;
462 struct {
463 u32 flags_and;
464 u32 flags_or;
465 } set_flags_sta;
466 struct {
467 u16 rid;
468 u16 len;
469 u8 data[0];
470 } rid;
471 struct {
472 u8 len;
473 u8 data[0];
474 } generic_elem;
475 struct {
476#define MLME_STA_DEAUTH 0
477#define MLME_STA_DISASSOC 1
478 u16 cmd;
479 u16 reason_code;
480 } mlme;
481 struct {
482 u8 ssid_len;
483 u8 ssid[32];
484 } scan_req;
485 } u;
486};
487
488#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
489#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
490
491#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
492#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
493#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
494#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
495#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
496#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
497
498
499#endif /* HOSTAP_COMMON_H */
diff --git a/drivers/net/wireless/hostap/hostap_config.h b/drivers/net/wireless/hostap/hostap_config.h
new file mode 100644
index 000000000000..0b526febd1a8
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_config.h
@@ -0,0 +1,86 @@
1#ifndef HOSTAP_CONFIG_H
2#define HOSTAP_CONFIG_H
3
4#define PRISM2_VERSION "0.4.1-kernel"
5
6/* In the previous versions of Host AP driver, support for user space version
7 * of IEEE 802.11 management (hostapd) used to be disabled in the default
8 * configuration. From now on, support for hostapd is always included and it is
9 * possible to disable kernel driver version of IEEE 802.11 management with a
10 * separate define, PRISM2_NO_KERNEL_IEEE80211_MGMT. */
11/* #define PRISM2_NO_KERNEL_IEEE80211_MGMT */
12
13/* Maximum number of events handler per one interrupt */
14#define PRISM2_MAX_INTERRUPT_EVENTS 20
15
16/* Use PCI bus master to copy data to/from BAP (only available for
17 * hostap_pci.o).
18 *
19 * Note! This is extremely experimental. PCI bus master is not supported by
20 * Intersil and it seems to have some problems at least on TX path (see below).
21 * The driver code for implementing bus master support is based on guessing
22 * and experimenting suitable control bits and these might not be correct.
23 * This code is included because using bus master makes a huge difference in
24 * host CPU load (something like 40% host CPU usage to 5-10% when sending or
25 * receiving at maximum throughput).
26 *
27 * Note2! Station firmware version 1.3.5 and primary firmware version 1.0.7
28 * have some fixes for PCI corruption and these (or newer) versions are
29 * recommended especially when using bus mastering.
30 *
31 * NOTE: PCI bus mastering code has not been updated for long time and it is
32 * not likely to compile and it will _not_ work as is. Only enable this if you
33 * are prepared to first fix the implementation..
34 */
35/* #define PRISM2_BUS_MASTER */
36
37#ifdef PRISM2_BUS_MASTER
38
39/* PCI bus master implementation seems to be broken in current
40 * hardware/firmware versions. Enable this to use enable command to fix
41 * something before starting bus master operation on TX path. This will add
42 * some latency and an extra interrupt to each TX packet. */
43#define PRISM2_ENABLE_BEFORE_TX_BUS_MASTER
44
45#endif /* PRISM2_BUS_MASTER */
46
47/* Include code for downloading firmware images into volatile RAM. */
48#define PRISM2_DOWNLOAD_SUPPORT
49
50/* Allow kernel configuration to enable download support. */
51#if !defined(PRISM2_DOWNLOAD_SUPPORT) && defined(CONFIG_HOSTAP_FIRMWARE)
52#define PRISM2_DOWNLOAD_SUPPORT
53#endif
54
55#ifdef PRISM2_DOWNLOAD_SUPPORT
56/* Allow writing firmware images into flash, i.e., to non-volatile storage.
57 * Before you enable this option, you should make absolutely sure that you are
58 * using prism2_srec utility that comes with THIS version of the driver!
59 * In addition, please note that it is possible to kill your card with
60 * non-volatile download if you are using incorrect image. This feature has not
61 * been fully tested, so please be careful with it. */
62/* #define PRISM2_NON_VOLATILE_DOWNLOAD */
63#endif /* PRISM2_DOWNLOAD_SUPPORT */
64
65/* Save low-level I/O for debugging. This should not be enabled in normal use.
66 */
67/* #define PRISM2_IO_DEBUG */
68
69/* Following defines can be used to remove unneeded parts of the driver, e.g.,
70 * to limit the size of the kernel module. Definitions can be added here in
71 * hostap_config.h or they can be added to make command with EXTRA_CFLAGS,
72 * e.g.,
73 * 'make pccard EXTRA_CFLAGS="-DPRISM2_NO_DEBUG -DPRISM2_NO_PROCFS_DEBUG"'
74 */
75
76/* Do not include debug messages into the driver */
77/* #define PRISM2_NO_DEBUG */
78
79/* Do not include /proc/net/prism2/wlan#/{registers,debug} */
80/* #define PRISM2_NO_PROCFS_DEBUG */
81
82/* Do not include station functionality (i.e., allow only Master (Host AP) mode
83 */
84/* #define PRISM2_NO_STATION_MODES */
85
86#endif /* HOSTAP_CONFIG_H */
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
new file mode 100644
index 000000000000..a5a6d6a966ee
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -0,0 +1,985 @@
1#define PRISM2_PCCARD
2
3#include <linux/config.h>
4#include <linux/module.h>
5#include <linux/init.h>
6#include <linux/if.h>
7#include <linux/wait.h>
8#include <linux/timer.h>
9#include <linux/skbuff.h>
10#include <linux/netdevice.h>
11#include <linux/workqueue.h>
12#include <linux/wireless.h>
13#include <net/iw_handler.h>
14
15#include <pcmcia/cs_types.h>
16#include <pcmcia/cs.h>
17#include <pcmcia/cistpl.h>
18#include <pcmcia/cisreg.h>
19#include <pcmcia/ds.h>
20
21#include <asm/io.h>
22
23#include "hostap_wlan.h"
24
25
26static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
27static dev_info_t dev_info = "hostap_cs";
28static dev_link_t *dev_list = NULL;
29
30MODULE_AUTHOR("Jouni Malinen");
31MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
32 "cards (PC Card).");
33MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
34MODULE_LICENSE("GPL");
35MODULE_VERSION(PRISM2_VERSION);
36
37
38static int ignore_cis_vcc;
39module_param(ignore_cis_vcc, int, 0444);
40MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");
41
42
43#ifdef PRISM2_IO_DEBUG
44
45static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
46{
47 struct hostap_interface *iface;
48 local_info_t *local;
49 unsigned long flags;
50
51 iface = netdev_priv(dev);
52 local = iface->local;
53 spin_lock_irqsave(&local->lock, flags);
54 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
55 outb(v, dev->base_addr + a);
56 spin_unlock_irqrestore(&local->lock, flags);
57}
58
59static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
60{
61 struct hostap_interface *iface;
62 local_info_t *local;
63 unsigned long flags;
64 u8 v;
65
66 iface = netdev_priv(dev);
67 local = iface->local;
68 spin_lock_irqsave(&local->lock, flags);
69 v = inb(dev->base_addr + a);
70 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
71 spin_unlock_irqrestore(&local->lock, flags);
72 return v;
73}
74
75static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
76{
77 struct hostap_interface *iface;
78 local_info_t *local;
79 unsigned long flags;
80
81 iface = netdev_priv(dev);
82 local = iface->local;
83 spin_lock_irqsave(&local->lock, flags);
84 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
85 outw(v, dev->base_addr + a);
86 spin_unlock_irqrestore(&local->lock, flags);
87}
88
89static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
90{
91 struct hostap_interface *iface;
92 local_info_t *local;
93 unsigned long flags;
94 u16 v;
95
96 iface = netdev_priv(dev);
97 local = iface->local;
98 spin_lock_irqsave(&local->lock, flags);
99 v = inw(dev->base_addr + a);
100 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
101 spin_unlock_irqrestore(&local->lock, flags);
102 return v;
103}
104
105static inline void hfa384x_outsw_debug(struct net_device *dev, int a,
106 u8 *buf, int wc)
107{
108 struct hostap_interface *iface;
109 local_info_t *local;
110 unsigned long flags;
111
112 iface = netdev_priv(dev);
113 local = iface->local;
114 spin_lock_irqsave(&local->lock, flags);
115 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc);
116 outsw(dev->base_addr + a, buf, wc);
117 spin_unlock_irqrestore(&local->lock, flags);
118}
119
120static inline void hfa384x_insw_debug(struct net_device *dev, int a,
121 u8 *buf, int wc)
122{
123 struct hostap_interface *iface;
124 local_info_t *local;
125 unsigned long flags;
126
127 iface = netdev_priv(dev);
128 local = iface->local;
129 spin_lock_irqsave(&local->lock, flags);
130 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc);
131 insw(dev->base_addr + a, buf, wc);
132 spin_unlock_irqrestore(&local->lock, flags);
133}
134
135#define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
136#define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
137#define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
138#define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
139#define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc))
140#define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc))
141
142#else /* PRISM2_IO_DEBUG */
143
144#define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a))
145#define HFA384X_INB(a) inb(dev->base_addr + (a))
146#define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a))
147#define HFA384X_INW(a) inw(dev->base_addr + (a))
148#define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc)
149#define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc)
150
151#endif /* PRISM2_IO_DEBUG */
152
153
154static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
155 int len)
156{
157 u16 d_off;
158 u16 *pos;
159
160 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
161 pos = (u16 *) buf;
162
163 if (len / 2)
164 HFA384X_INSW(d_off, buf, len / 2);
165 pos += len / 2;
166
167 if (len & 1)
168 *((char *) pos) = HFA384X_INB(d_off);
169
170 return 0;
171}
172
173
174static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
175{
176 u16 d_off;
177 u16 *pos;
178
179 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
180 pos = (u16 *) buf;
181
182 if (len / 2)
183 HFA384X_OUTSW(d_off, buf, len / 2);
184 pos += len / 2;
185
186 if (len & 1)
187 HFA384X_OUTB(*((char *) pos), d_off);
188
189 return 0;
190}
191
192
193/* FIX: This might change at some point.. */
194#include "hostap_hw.c"
195
196
197
198static void prism2_detach(dev_link_t *link);
199static void prism2_release(u_long arg);
200static int prism2_event(event_t event, int priority,
201 event_callback_args_t *args);
202
203
204static int prism2_pccard_card_present(local_info_t *local)
205{
206 if (local->link != NULL &&
207 ((local->link->state & (DEV_PRESENT | DEV_CONFIG)) ==
208 (DEV_PRESENT | DEV_CONFIG)))
209 return 1;
210 return 0;
211}
212
213
214/*
215 * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0
216 * Document No. 20-10-00058, January 2004
217 * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf
218 */
219#define SANDISK_WLAN_ACTIVATION_OFF 0x40
220#define SANDISK_HCR_OFF 0x42
221
222
223static void sandisk_set_iobase(local_info_t *local)
224{
225 int res;
226 conf_reg_t reg;
227
228 reg.Function = 0;
229 reg.Action = CS_WRITE;
230 reg.Offset = 0x10; /* 0x3f0 IO base 1 */
231 reg.Value = local->link->io.BasePort1 & 0x00ff;
232 res = pcmcia_access_configuration_register(local->link->handle, &reg);
233 if (res != CS_SUCCESS) {
234 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
235 " res=%d\n", res);
236 }
237 udelay(10);
238
239 reg.Function = 0;
240 reg.Action = CS_WRITE;
241 reg.Offset = 0x12; /* 0x3f2 IO base 2 */
242 reg.Value = (local->link->io.BasePort1 & 0xff00) >> 8;
243 res = pcmcia_access_configuration_register(local->link->handle, &reg);
244 if (res != CS_SUCCESS) {
245 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
246 " res=%d\n", res);
247 }
248}
249
250
251static void sandisk_write_hcr(local_info_t *local, int hcr)
252{
253 struct net_device *dev = local->dev;
254 int i;
255
256 HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF);
257 udelay(50);
258 for (i = 0; i < 10; i++) {
259 HFA384X_OUTB(hcr, SANDISK_HCR_OFF);
260 }
261 udelay(55);
262 HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF);
263}
264
265
266static int sandisk_enable_wireless(struct net_device *dev)
267{
268 int res, ret = 0;
269 conf_reg_t reg;
270 struct hostap_interface *iface = dev->priv;
271 local_info_t *local = iface->local;
272 tuple_t tuple;
273 cisparse_t *parse = NULL;
274 u_char buf[64];
275
276 if (local->link->io.NumPorts1 < 0x42) {
277 /* Not enough ports to be SanDisk multi-function card */
278 ret = -ENODEV;
279 goto done;
280 }
281
282 parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
283 if (parse == NULL) {
284 ret = -ENOMEM;
285 goto done;
286 }
287
288 tuple.DesiredTuple = CISTPL_MANFID;
289 tuple.Attributes = TUPLE_RETURN_COMMON;
290 tuple.TupleData = buf;
291 tuple.TupleDataMax = sizeof(buf);
292 tuple.TupleOffset = 0;
293 if (pcmcia_get_first_tuple(local->link->handle, &tuple) ||
294 pcmcia_get_tuple_data(local->link->handle, &tuple) ||
295 pcmcia_parse_tuple(local->link->handle, &tuple, parse) ||
296 parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) {
297 /* No SanDisk manfid found */
298 ret = -ENODEV;
299 goto done;
300 }
301
302 tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
303 if (pcmcia_get_first_tuple(local->link->handle, &tuple) ||
304 pcmcia_get_tuple_data(local->link->handle, &tuple) ||
305 pcmcia_parse_tuple(local->link->handle, &tuple, parse) ||
306 parse->longlink_mfc.nfn < 2) {
307 /* No multi-function links found */
308 ret = -ENODEV;
309 goto done;
310 }
311
312 printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected"
313 " - using vendor-specific initialization\n", dev->name);
314 local->sandisk_connectplus = 1;
315
316 reg.Function = 0;
317 reg.Action = CS_WRITE;
318 reg.Offset = CISREG_COR;
319 reg.Value = COR_SOFT_RESET;
320 res = pcmcia_access_configuration_register(local->link->handle, &reg);
321 if (res != CS_SUCCESS) {
322 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
323 dev->name, res);
324 goto done;
325 }
326 mdelay(5);
327
328 reg.Function = 0;
329 reg.Action = CS_WRITE;
330 reg.Offset = CISREG_COR;
331 /*
332 * Do not enable interrupts here to avoid some bogus events. Interrupts
333 * will be enabled during the first cor_sreset call.
334 */
335 reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
336 res = pcmcia_access_configuration_register(local->link->handle, &reg);
337 if (res != CS_SUCCESS) {
338 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
339 dev->name, res);
340 goto done;
341 }
342 mdelay(5);
343
344 sandisk_set_iobase(local);
345
346 HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF);
347 udelay(10);
348 HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF);
349 udelay(10);
350
351done:
352 kfree(parse);
353 return ret;
354}
355
356
357static void prism2_pccard_cor_sreset(local_info_t *local)
358{
359 int res;
360 conf_reg_t reg;
361
362 if (!prism2_pccard_card_present(local))
363 return;
364
365 reg.Function = 0;
366 reg.Action = CS_READ;
367 reg.Offset = CISREG_COR;
368 reg.Value = 0;
369 res = pcmcia_access_configuration_register(local->link->handle, &reg);
370 if (res != CS_SUCCESS) {
371 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
372 res);
373 return;
374 }
375 printk(KERN_DEBUG "prism2_pccard_cor_sreset: original COR %02x\n",
376 reg.Value);
377
378 reg.Action = CS_WRITE;
379 reg.Value |= COR_SOFT_RESET;
380 res = pcmcia_access_configuration_register(local->link->handle, &reg);
381 if (res != CS_SUCCESS) {
382 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
383 res);
384 return;
385 }
386
387 mdelay(local->sandisk_connectplus ? 5 : 2);
388
389 reg.Value &= ~COR_SOFT_RESET;
390 if (local->sandisk_connectplus)
391 reg.Value |= COR_IREQ_ENA;
392 res = pcmcia_access_configuration_register(local->link->handle, &reg);
393 if (res != CS_SUCCESS) {
394 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
395 res);
396 return;
397 }
398
399 mdelay(local->sandisk_connectplus ? 5 : 2);
400
401 if (local->sandisk_connectplus)
402 sandisk_set_iobase(local);
403}
404
405
406static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
407{
408 int res;
409 conf_reg_t reg;
410 int old_cor;
411
412 if (!prism2_pccard_card_present(local))
413 return;
414
415 if (local->sandisk_connectplus) {
416 sandisk_write_hcr(local, hcr);
417 return;
418 }
419
420 reg.Function = 0;
421 reg.Action = CS_READ;
422 reg.Offset = CISREG_COR;
423 reg.Value = 0;
424 res = pcmcia_access_configuration_register(local->link->handle, &reg);
425 if (res != CS_SUCCESS) {
426 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
427 "(%d)\n", res);
428 return;
429 }
430 printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n",
431 reg.Value);
432 old_cor = reg.Value;
433
434 reg.Action = CS_WRITE;
435 reg.Value |= COR_SOFT_RESET;
436 res = pcmcia_access_configuration_register(local->link->handle, &reg);
437 if (res != CS_SUCCESS) {
438 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
439 "(%d)\n", res);
440 return;
441 }
442
443 mdelay(10);
444
445 /* Setup Genesis mode */
446 reg.Action = CS_WRITE;
447 reg.Value = hcr;
448 reg.Offset = CISREG_CCSR;
449 res = pcmcia_access_configuration_register(local->link->handle, &reg);
450 if (res != CS_SUCCESS) {
451 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
452 "(%d)\n", res);
453 return;
454 }
455 mdelay(10);
456
457 reg.Action = CS_WRITE;
458 reg.Offset = CISREG_COR;
459 reg.Value = old_cor & ~COR_SOFT_RESET;
460 res = pcmcia_access_configuration_register(local->link->handle, &reg);
461 if (res != CS_SUCCESS) {
462 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
463 "(%d)\n", res);
464 return;
465 }
466
467 mdelay(10);
468}
469
470
471static int prism2_pccard_dev_open(local_info_t *local)
472{
473 local->link->open++;
474 return 0;
475}
476
477
478static int prism2_pccard_dev_close(local_info_t *local)
479{
480 if (local == NULL || local->link == NULL)
481 return 1;
482
483 if (!local->link->open) {
484 printk(KERN_WARNING "%s: prism2_pccard_dev_close(): "
485 "link not open?!\n", local->dev->name);
486 return 1;
487 }
488
489 local->link->open--;
490
491 return 0;
492}
493
494
495static struct prism2_helper_functions prism2_pccard_funcs =
496{
497 .card_present = prism2_pccard_card_present,
498 .cor_sreset = prism2_pccard_cor_sreset,
499 .dev_open = prism2_pccard_dev_open,
500 .dev_close = prism2_pccard_dev_close,
501 .genesis_reset = prism2_pccard_genesis_reset,
502 .hw_type = HOSTAP_HW_PCCARD,
503};
504
505
506/* allocate local data and register with CardServices
507 * initialize dev_link structure, but do not configure the card yet */
508static dev_link_t *prism2_attach(void)
509{
510 dev_link_t *link;
511 client_reg_t client_reg;
512 int ret;
513
514 link = kmalloc(sizeof(dev_link_t), GFP_KERNEL);
515 if (link == NULL)
516 return NULL;
517
518 memset(link, 0, sizeof(dev_link_t));
519
520 PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
521 link->conf.Vcc = 33;
522 link->conf.IntType = INT_MEMORY_AND_IO;
523
524 /* register with CardServices */
525 link->next = dev_list;
526 dev_list = link;
527 client_reg.dev_info = &dev_info;
528 client_reg.Version = 0x0210;
529 client_reg.event_callback_args.client_data = link;
530 ret = pcmcia_register_client(&link->handle, &client_reg);
531 if (ret != CS_SUCCESS) {
532 cs_error(link->handle, RegisterClient, ret);
533 prism2_detach(link);
534 return NULL;
535 }
536 return link;
537}
538
539
540static void prism2_detach(dev_link_t *link)
541{
542 dev_link_t **linkp;
543
544 PDEBUG(DEBUG_FLOW, "prism2_detach\n");
545
546 for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
547 if (*linkp == link)
548 break;
549 if (*linkp == NULL) {
550 printk(KERN_WARNING "%s: Attempt to detach non-existing "
551 "PCMCIA client\n", dev_info);
552 return;
553 }
554
555 if (link->state & DEV_CONFIG) {
556 prism2_release((u_long)link);
557 }
558
559 if (link->handle) {
560 int res = pcmcia_deregister_client(link->handle);
561 if (res) {
562 printk("CardService(DeregisterClient) => %d\n", res);
563 cs_error(link->handle, DeregisterClient, res);
564 }
565 }
566
567 *linkp = link->next;
568 /* release net devices */
569 if (link->priv) {
570 prism2_free_local_data((struct net_device *) link->priv);
571
572 }
573 kfree(link);
574}
575
576
577#define CS_CHECK(fn, ret) \
578do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
579
580#define CFG_CHECK2(fn, retf) \
581do { int ret = (retf); \
582if (ret != 0) { \
583 PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \
584 cs_error(link->handle, fn, ret); \
585 goto next_entry; \
586} \
587} while (0)
588
589
590/* run after a CARD_INSERTION event is received to configure the PCMCIA
591 * socket and make the device available to the system */
592static int prism2_config(dev_link_t *link)
593{
594 struct net_device *dev;
595 struct hostap_interface *iface;
596 local_info_t *local;
597 int ret = 1;
598 tuple_t tuple;
599 cisparse_t *parse;
600 int last_fn, last_ret;
601 u_char buf[64];
602 config_info_t conf;
603 cistpl_cftable_entry_t dflt = { 0 };
604
605 PDEBUG(DEBUG_FLOW, "prism2_config()\n");
606
607 parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
608 if (parse == NULL) {
609 ret = -ENOMEM;
610 goto failed;
611 }
612
613 tuple.DesiredTuple = CISTPL_CONFIG;
614 tuple.Attributes = 0;
615 tuple.TupleData = buf;
616 tuple.TupleDataMax = sizeof(buf);
617 tuple.TupleOffset = 0;
618 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
619 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple));
620 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse));
621 link->conf.ConfigBase = parse->config.base;
622 link->conf.Present = parse->config.rmask[0];
623
624 CS_CHECK(GetConfigurationInfo,
625 pcmcia_get_configuration_info(link->handle, &conf));
626 PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info,
627 ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc);
628 link->conf.Vcc = conf.Vcc;
629
630 /* Look for an appropriate configuration table entry in the CIS */
631 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
632 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple));
633 for (;;) {
634 cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
635 CFG_CHECK2(GetTupleData,
636 pcmcia_get_tuple_data(link->handle, &tuple));
637 CFG_CHECK2(ParseTuple,
638 pcmcia_parse_tuple(link->handle, &tuple, parse));
639
640 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
641 dflt = *cfg;
642 if (cfg->index == 0)
643 goto next_entry;
644 link->conf.ConfigIndex = cfg->index;
645 PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
646 "(default 0x%02X)\n", cfg->index, dflt.index);
647
648 /* Does this card need audio output? */
649 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
650 link->conf.Attributes |= CONF_ENABLE_SPKR;
651 link->conf.Status = CCSR_AUDIO_ENA;
652 }
653
654 /* Use power settings for Vcc and Vpp if present */
655 /* Note that the CIS values need to be rescaled */
656 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
657 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
658 10000 && !ignore_cis_vcc) {
659 PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping"
660 " this entry\n");
661 goto next_entry;
662 }
663 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
664 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] /
665 10000 && !ignore_cis_vcc) {
666 PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch "
667 "- skipping this entry\n");
668 goto next_entry;
669 }
670 }
671
672 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
673 link->conf.Vpp1 = link->conf.Vpp2 =
674 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
675 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
676 link->conf.Vpp1 = link->conf.Vpp2 =
677 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
678
679 /* Do we need to allocate an interrupt? */
680 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
681 link->conf.Attributes |= CONF_ENABLE_IRQ;
682 else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) {
683 /* At least Compaq WL200 does not have IRQInfo1 set,
684 * but it does not work without interrupts.. */
685 printk("Config has no IRQ info, but trying to enable "
686 "IRQ anyway..\n");
687 link->conf.Attributes |= CONF_ENABLE_IRQ;
688 }
689
690 /* IO window settings */
691 PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
692 "dflt.io.nwin=%d\n",
693 cfg->io.nwin, dflt.io.nwin);
694 link->io.NumPorts1 = link->io.NumPorts2 = 0;
695 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
696 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
697 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
698 PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
699 "io.base=0x%04x, len=%d\n", io->flags,
700 io->win[0].base, io->win[0].len);
701 if (!(io->flags & CISTPL_IO_8BIT))
702 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
703 if (!(io->flags & CISTPL_IO_16BIT))
704 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
705 link->io.IOAddrLines = io->flags &
706 CISTPL_IO_LINES_MASK;
707 link->io.BasePort1 = io->win[0].base;
708 link->io.NumPorts1 = io->win[0].len;
709 if (io->nwin > 1) {
710 link->io.Attributes2 = link->io.Attributes1;
711 link->io.BasePort2 = io->win[1].base;
712 link->io.NumPorts2 = io->win[1].len;
713 }
714 }
715
716 /* This reserves IO space but doesn't actually enable it */
717 CFG_CHECK2(RequestIO,
718 pcmcia_request_io(link->handle, &link->io));
719
720 /* This configuration table entry is OK */
721 break;
722
723 next_entry:
724 CS_CHECK(GetNextTuple,
725 pcmcia_get_next_tuple(link->handle, &tuple));
726 }
727
728 /* Need to allocate net_device before requesting IRQ handler */
729 dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
730 &handle_to_dev(link->handle));
731 if (dev == NULL)
732 goto failed;
733 link->priv = dev;
734
735 /*
736 * Allocate an interrupt line. Note that this does not assign a
737 * handler to the interrupt, unless the 'Handler' member of the
738 * irq structure is initialized.
739 */
740 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
741 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
742 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
743 link->irq.Handler = prism2_interrupt;
744 link->irq.Instance = dev;
745 CS_CHECK(RequestIRQ,
746 pcmcia_request_irq(link->handle, &link->irq));
747 }
748
749 /*
750 * This actually configures the PCMCIA socket -- setting up
751 * the I/O windows and the interrupt mapping, and putting the
752 * card and host interface into "Memory and IO" mode.
753 */
754 CS_CHECK(RequestConfiguration,
755 pcmcia_request_configuration(link->handle, &link->conf));
756
757 dev->irq = link->irq.AssignedIRQ;
758 dev->base_addr = link->io.BasePort1;
759
760 /* Finally, report what we've done */
761 printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d",
762 dev_info, link->conf.ConfigIndex,
763 link->conf.Vcc / 10, link->conf.Vcc % 10);
764 if (link->conf.Vpp1)
765 printk(", Vpp %d.%d", link->conf.Vpp1 / 10,
766 link->conf.Vpp1 % 10);
767 if (link->conf.Attributes & CONF_ENABLE_IRQ)
768 printk(", irq %d", link->irq.AssignedIRQ);
769 if (link->io.NumPorts1)
770 printk(", io 0x%04x-0x%04x", link->io.BasePort1,
771 link->io.BasePort1+link->io.NumPorts1-1);
772 if (link->io.NumPorts2)
773 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
774 link->io.BasePort2+link->io.NumPorts2-1);
775 printk("\n");
776
777 link->state |= DEV_CONFIG;
778 link->state &= ~DEV_CONFIG_PENDING;
779
780 iface = netdev_priv(dev);
781 local = iface->local;
782 local->link = link;
783 strcpy(local->node.dev_name, dev->name);
784 link->dev = &local->node;
785
786 local->shutdown = 0;
787
788 sandisk_enable_wireless(dev);
789
790 ret = prism2_hw_config(dev, 1);
791 if (!ret) {
792 ret = hostap_hw_ready(dev);
793 if (ret == 0 && local->ddev)
794 strcpy(local->node.dev_name, local->ddev->name);
795 }
796 kfree(parse);
797 return ret;
798
799 cs_failed:
800 cs_error(link->handle, last_fn, last_ret);
801
802 failed:
803 kfree(parse);
804 prism2_release((u_long)link);
805 return ret;
806}
807
808
809static void prism2_release(u_long arg)
810{
811 dev_link_t *link = (dev_link_t *)arg;
812
813 PDEBUG(DEBUG_FLOW, "prism2_release\n");
814
815 if (link->priv) {
816 struct net_device *dev = link->priv;
817 struct hostap_interface *iface;
818
819 iface = netdev_priv(dev);
820 if (link->state & DEV_CONFIG)
821 prism2_hw_shutdown(dev, 0);
822 iface->local->shutdown = 1;
823 }
824
825 if (link->win)
826 pcmcia_release_window(link->win);
827 pcmcia_release_configuration(link->handle);
828 if (link->io.NumPorts1)
829 pcmcia_release_io(link->handle, &link->io);
830 if (link->irq.AssignedIRQ)
831 pcmcia_release_irq(link->handle, &link->irq);
832
833 link->state &= ~DEV_CONFIG;
834
835 PDEBUG(DEBUG_FLOW, "release - done\n");
836}
837
838
839static int prism2_event(event_t event, int priority,
840 event_callback_args_t *args)
841{
842 dev_link_t *link = args->client_data;
843 struct net_device *dev = (struct net_device *) link->priv;
844
845 switch (event) {
846 case CS_EVENT_CARD_INSERTION:
847 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_INSERTION\n", dev_info);
848 link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
849 if (prism2_config(link)) {
850 PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
851 }
852 break;
853
854 case CS_EVENT_CARD_REMOVAL:
855 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_REMOVAL\n", dev_info);
856 link->state &= ~DEV_PRESENT;
857 if (link->state & DEV_CONFIG) {
858 netif_stop_queue(dev);
859 netif_device_detach(dev);
860 prism2_release((u_long) link);
861 }
862 break;
863
864 case CS_EVENT_PM_SUSPEND:
865 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
866 link->state |= DEV_SUSPEND;
867 /* fall through */
868
869 case CS_EVENT_RESET_PHYSICAL:
870 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_RESET_PHYSICAL\n", dev_info);
871 if (link->state & DEV_CONFIG) {
872 if (link->open) {
873 netif_stop_queue(dev);
874 netif_device_detach(dev);
875 }
876 prism2_suspend(dev);
877 pcmcia_release_configuration(link->handle);
878 }
879 break;
880
881 case CS_EVENT_PM_RESUME:
882 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);
883 link->state &= ~DEV_SUSPEND;
884 /* fall through */
885
886 case CS_EVENT_CARD_RESET:
887 PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_CARD_RESET\n", dev_info);
888 if (link->state & DEV_CONFIG) {
889 pcmcia_request_configuration(link->handle,
890 &link->conf);
891 prism2_hw_shutdown(dev, 1);
892 prism2_hw_config(dev, link->open ? 0 : 1);
893 if (link->open) {
894 netif_device_attach(dev);
895 netif_start_queue(dev);
896 }
897 }
898 break;
899
900 default:
901 PDEBUG(DEBUG_EXTRA, "%s: prism2_event() - unknown event %d\n",
902 dev_info, event);
903 break;
904 }
905 return 0;
906}
907
908
909static struct pcmcia_device_id hostap_cs_ids[] = {
910 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
911 PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
912 PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
913 PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
914 PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
915 PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002),
916 PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
917 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
918 PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
919 PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
920 PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
921 PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
922 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
923 PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
924 PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000),
925 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
926 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
927 PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
928 PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
929 0x7a954bd9, 0x74be00c6),
930 PCMCIA_DEVICE_PROD_ID1234(
931 "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P",
932 "Eval-RevA",
933 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e),
934 PCMCIA_DEVICE_PROD_ID123(
935 "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
936 0xe6ec52ce, 0x08649af2, 0x4b74baa0),
937 PCMCIA_DEVICE_PROD_ID123(
938 "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
939 0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
940 PCMCIA_DEVICE_PROD_ID123(
941 "Instant Wireless ", " Network PC CARD", "Version 01.02",
942 0x11d901af, 0x6e9bd926, 0x4b74baa0),
943 PCMCIA_DEVICE_PROD_ID123(
944 "SMC", "SMC2632W", "Version 01.02",
945 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
946 PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
947 0x54f7c49c, 0x15a75e5b),
948 PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
949 0x74c5e40d, 0xdb472a18),
950 PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
951 0x0733cc81, 0x0c52f395),
952 PCMCIA_DEVICE_PROD_ID12(
953 "ZoomAir 11Mbps High", "Rate wireless Networking",
954 0x273fe3db, 0x32a1eaee),
955 PCMCIA_DEVICE_NULL
956};
957MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);
958
959
960static struct pcmcia_driver hostap_driver = {
961 .drv = {
962 .name = "hostap_cs",
963 },
964 .attach = prism2_attach,
965 .detach = prism2_detach,
966 .owner = THIS_MODULE,
967 .event = prism2_event,
968 .id_table = hostap_cs_ids,
969};
970
971static int __init init_prism2_pccard(void)
972{
973 printk(KERN_INFO "%s: %s\n", dev_info, version);
974 return pcmcia_register_driver(&hostap_driver);
975}
976
977static void __exit exit_prism2_pccard(void)
978{
979 pcmcia_unregister_driver(&hostap_driver);
980 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
981}
982
983
984module_init(init_prism2_pccard);
985module_exit(exit_prism2_pccard);
diff --git a/drivers/net/wireless/hostap/hostap_download.c b/drivers/net/wireless/hostap/hostap_download.c
new file mode 100644
index 000000000000..ab26b52b3e76
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_download.c
@@ -0,0 +1,766 @@
1static int prism2_enable_aux_port(struct net_device *dev, int enable)
2{
3 u16 val, reg;
4 int i, tries;
5 unsigned long flags;
6 struct hostap_interface *iface;
7 local_info_t *local;
8
9 iface = netdev_priv(dev);
10 local = iface->local;
11
12 if (local->no_pri) {
13 if (enable) {
14 PDEBUG(DEBUG_EXTRA2, "%s: no PRI f/w - assuming Aux "
15 "port is already enabled\n", dev->name);
16 }
17 return 0;
18 }
19
20 spin_lock_irqsave(&local->cmdlock, flags);
21
22 /* wait until busy bit is clear */
23 tries = HFA384X_CMD_BUSY_TIMEOUT;
24 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
25 tries--;
26 udelay(1);
27 }
28 if (tries == 0) {
29 reg = HFA384X_INW(HFA384X_CMD_OFF);
30 spin_unlock_irqrestore(&local->cmdlock, flags);
31 printk("%s: prism2_enable_aux_port - timeout - reg=0x%04x\n",
32 dev->name, reg);
33 return -ETIMEDOUT;
34 }
35
36 val = HFA384X_INW(HFA384X_CONTROL_OFF);
37
38 if (enable) {
39 HFA384X_OUTW(HFA384X_AUX_MAGIC0, HFA384X_PARAM0_OFF);
40 HFA384X_OUTW(HFA384X_AUX_MAGIC1, HFA384X_PARAM1_OFF);
41 HFA384X_OUTW(HFA384X_AUX_MAGIC2, HFA384X_PARAM2_OFF);
42
43 if ((val & HFA384X_AUX_PORT_MASK) != HFA384X_AUX_PORT_DISABLED)
44 printk("prism2_enable_aux_port: was not disabled!?\n");
45 val &= ~HFA384X_AUX_PORT_MASK;
46 val |= HFA384X_AUX_PORT_ENABLE;
47 } else {
48 HFA384X_OUTW(0, HFA384X_PARAM0_OFF);
49 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
50 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
51
52 if ((val & HFA384X_AUX_PORT_MASK) != HFA384X_AUX_PORT_ENABLED)
53 printk("prism2_enable_aux_port: was not enabled!?\n");
54 val &= ~HFA384X_AUX_PORT_MASK;
55 val |= HFA384X_AUX_PORT_DISABLE;
56 }
57 HFA384X_OUTW(val, HFA384X_CONTROL_OFF);
58
59 udelay(5);
60
61 i = 10000;
62 while (i > 0) {
63 val = HFA384X_INW(HFA384X_CONTROL_OFF);
64 val &= HFA384X_AUX_PORT_MASK;
65
66 if ((enable && val == HFA384X_AUX_PORT_ENABLED) ||
67 (!enable && val == HFA384X_AUX_PORT_DISABLED))
68 break;
69
70 udelay(10);
71 i--;
72 }
73
74 spin_unlock_irqrestore(&local->cmdlock, flags);
75
76 if (i == 0) {
77 printk("prism2_enable_aux_port(%d) timed out\n",
78 enable);
79 return -ETIMEDOUT;
80 }
81
82 return 0;
83}
84
85
86static int hfa384x_from_aux(struct net_device *dev, unsigned int addr, int len,
87 void *buf)
88{
89 u16 page, offset;
90 if (addr & 1 || len & 1)
91 return -1;
92
93 page = addr >> 7;
94 offset = addr & 0x7f;
95
96 HFA384X_OUTW(page, HFA384X_AUXPAGE_OFF);
97 HFA384X_OUTW(offset, HFA384X_AUXOFFSET_OFF);
98
99 udelay(5);
100
101#ifdef PRISM2_PCI
102 {
103 u16 *pos = (u16 *) buf;
104 while (len > 0) {
105 *pos++ = HFA384X_INW_DATA(HFA384X_AUXDATA_OFF);
106 len -= 2;
107 }
108 }
109#else /* PRISM2_PCI */
110 HFA384X_INSW(HFA384X_AUXDATA_OFF, buf, len / 2);
111#endif /* PRISM2_PCI */
112
113 return 0;
114}
115
116
117static int hfa384x_to_aux(struct net_device *dev, unsigned int addr, int len,
118 void *buf)
119{
120 u16 page, offset;
121 if (addr & 1 || len & 1)
122 return -1;
123
124 page = addr >> 7;
125 offset = addr & 0x7f;
126
127 HFA384X_OUTW(page, HFA384X_AUXPAGE_OFF);
128 HFA384X_OUTW(offset, HFA384X_AUXOFFSET_OFF);
129
130 udelay(5);
131
132#ifdef PRISM2_PCI
133 {
134 u16 *pos = (u16 *) buf;
135 while (len > 0) {
136 HFA384X_OUTW_DATA(*pos++, HFA384X_AUXDATA_OFF);
137 len -= 2;
138 }
139 }
140#else /* PRISM2_PCI */
141 HFA384X_OUTSW(HFA384X_AUXDATA_OFF, buf, len / 2);
142#endif /* PRISM2_PCI */
143
144 return 0;
145}
146
147
148static int prism2_pda_ok(u8 *buf)
149{
150 u16 *pda = (u16 *) buf;
151 int pos;
152 u16 len, pdr;
153
154 if (buf[0] == 0xff && buf[1] == 0x00 && buf[2] == 0xff &&
155 buf[3] == 0x00)
156 return 0;
157
158 pos = 0;
159 while (pos + 1 < PRISM2_PDA_SIZE / 2) {
160 len = le16_to_cpu(pda[pos]);
161 pdr = le16_to_cpu(pda[pos + 1]);
162 if (len == 0 || pos + len > PRISM2_PDA_SIZE / 2)
163 return 0;
164
165 if (pdr == 0x0000 && len == 2) {
166 /* PDA end found */
167 return 1;
168 }
169
170 pos += len + 1;
171 }
172
173 return 0;
174}
175
176
177static int prism2_download_aux_dump(struct net_device *dev,
178 unsigned int addr, int len, u8 *buf)
179{
180 int res;
181
182 prism2_enable_aux_port(dev, 1);
183 res = hfa384x_from_aux(dev, addr, len, buf);
184 prism2_enable_aux_port(dev, 0);
185 if (res)
186 return -1;
187
188 return 0;
189}
190
191
192static u8 * prism2_read_pda(struct net_device *dev)
193{
194 u8 *buf;
195 int res, i, found = 0;
196#define NUM_PDA_ADDRS 4
197 unsigned int pda_addr[NUM_PDA_ADDRS] = {
198 0x7f0000 /* others than HFA3841 */,
199 0x3f0000 /* HFA3841 */,
200 0x390000 /* apparently used in older cards */,
201 0x7f0002 /* Intel PRO/Wireless 2011B (PCI) */,
202 };
203
204 buf = (u8 *) kmalloc(PRISM2_PDA_SIZE, GFP_KERNEL);
205 if (buf == NULL)
206 return NULL;
207
208 /* Note: wlan card should be in initial state (just after init cmd)
209 * and no other operations should be performed concurrently. */
210
211 prism2_enable_aux_port(dev, 1);
212
213 for (i = 0; i < NUM_PDA_ADDRS; i++) {
214 PDEBUG(DEBUG_EXTRA2, "%s: trying to read PDA from 0x%08x",
215 dev->name, pda_addr[i]);
216 res = hfa384x_from_aux(dev, pda_addr[i], PRISM2_PDA_SIZE, buf);
217 if (res)
218 continue;
219 if (res == 0 && prism2_pda_ok(buf)) {
220 PDEBUG2(DEBUG_EXTRA2, ": OK\n");
221 found = 1;
222 break;
223 } else {
224 PDEBUG2(DEBUG_EXTRA2, ": failed\n");
225 }
226 }
227
228 prism2_enable_aux_port(dev, 0);
229
230 if (!found) {
231 printk(KERN_DEBUG "%s: valid PDA not found\n", dev->name);
232 kfree(buf);
233 buf = NULL;
234 }
235
236 return buf;
237}
238
239
240static int prism2_download_volatile(local_info_t *local,
241 struct prism2_download_data *param)
242{
243 struct net_device *dev = local->dev;
244 int ret = 0, i;
245 u16 param0, param1;
246
247 if (local->hw_downloading) {
248 printk(KERN_WARNING "%s: Already downloading - aborting new "
249 "request\n", dev->name);
250 return -1;
251 }
252
253 local->hw_downloading = 1;
254 if (local->pri_only) {
255 hfa384x_disable_interrupts(dev);
256 } else {
257 prism2_hw_shutdown(dev, 0);
258
259 if (prism2_hw_init(dev, 0)) {
260 printk(KERN_WARNING "%s: Could not initialize card for"
261 " download\n", dev->name);
262 ret = -1;
263 goto out;
264 }
265 }
266
267 if (prism2_enable_aux_port(dev, 1)) {
268 printk(KERN_WARNING "%s: Could not enable AUX port\n",
269 dev->name);
270 ret = -1;
271 goto out;
272 }
273
274 param0 = param->start_addr & 0xffff;
275 param1 = param->start_addr >> 16;
276
277 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
278 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
279 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
280 (HFA384X_PROGMODE_ENABLE_VOLATILE << 8),
281 param0)) {
282 printk(KERN_WARNING "%s: Download command execution failed\n",
283 dev->name);
284 ret = -1;
285 goto out;
286 }
287
288 for (i = 0; i < param->num_areas; i++) {
289 PDEBUG(DEBUG_EXTRA2, "%s: Writing %d bytes at 0x%08x\n",
290 dev->name, param->data[i].len, param->data[i].addr);
291 if (hfa384x_to_aux(dev, param->data[i].addr,
292 param->data[i].len, param->data[i].data)) {
293 printk(KERN_WARNING "%s: RAM download at 0x%08x "
294 "(len=%d) failed\n", dev->name,
295 param->data[i].addr, param->data[i].len);
296 ret = -1;
297 goto out;
298 }
299 }
300
301 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
302 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
303 if (hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
304 (HFA384X_PROGMODE_DISABLE << 8), param0)) {
305 printk(KERN_WARNING "%s: Download command execution failed\n",
306 dev->name);
307 ret = -1;
308 goto out;
309 }
310 /* ProgMode disable causes the hardware to restart itself from the
311 * given starting address. Give hw some time and ACK command just in
312 * case restart did not happen. */
313 mdelay(5);
314 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
315
316 if (prism2_enable_aux_port(dev, 0)) {
317 printk(KERN_DEBUG "%s: Disabling AUX port failed\n",
318 dev->name);
319 /* continue anyway.. restart should have taken care of this */
320 }
321
322 mdelay(5);
323 local->hw_downloading = 0;
324 if (prism2_hw_config(dev, 2)) {
325 printk(KERN_WARNING "%s: Card configuration after RAM "
326 "download failed\n", dev->name);
327 ret = -1;
328 goto out;
329 }
330
331 out:
332 local->hw_downloading = 0;
333 return ret;
334}
335
336
337static int prism2_enable_genesis(local_info_t *local, int hcr)
338{
339 struct net_device *dev = local->dev;
340 u8 initseq[4] = { 0x00, 0xe1, 0xa1, 0xff };
341 u8 readbuf[4];
342
343 printk(KERN_DEBUG "%s: test Genesis mode with HCR 0x%02x\n",
344 dev->name, hcr);
345 local->func->cor_sreset(local);
346 hfa384x_to_aux(dev, 0x7e0038, sizeof(initseq), initseq);
347 local->func->genesis_reset(local, hcr);
348
349 /* Readback test */
350 hfa384x_from_aux(dev, 0x7e0038, sizeof(readbuf), readbuf);
351 hfa384x_to_aux(dev, 0x7e0038, sizeof(initseq), initseq);
352 hfa384x_from_aux(dev, 0x7e0038, sizeof(readbuf), readbuf);
353
354 if (memcmp(initseq, readbuf, sizeof(initseq)) == 0) {
355 printk(KERN_DEBUG "Readback test succeeded, HCR 0x%02x\n",
356 hcr);
357 return 0;
358 } else {
359 printk(KERN_DEBUG "Readback test failed, HCR 0x%02x "
360 "write %02x %02x %02x %02x read %02x %02x %02x %02x\n",
361 hcr, initseq[0], initseq[1], initseq[2], initseq[3],
362 readbuf[0], readbuf[1], readbuf[2], readbuf[3]);
363 return 1;
364 }
365}
366
367
368static int prism2_get_ram_size(local_info_t *local)
369{
370 int ret;
371
372 /* Try to enable genesis mode; 0x1F for x8 SRAM or 0x0F for x16 SRAM */
373 if (prism2_enable_genesis(local, 0x1f) == 0)
374 ret = 8;
375 else if (prism2_enable_genesis(local, 0x0f) == 0)
376 ret = 16;
377 else
378 ret = -1;
379
380 /* Disable genesis mode */
381 local->func->genesis_reset(local, ret == 16 ? 0x07 : 0x17);
382
383 return ret;
384}
385
386
387static int prism2_download_genesis(local_info_t *local,
388 struct prism2_download_data *param)
389{
390 struct net_device *dev = local->dev;
391 int ram16 = 0, i;
392 int ret = 0;
393
394 if (local->hw_downloading) {
395 printk(KERN_WARNING "%s: Already downloading - aborting new "
396 "request\n", dev->name);
397 return -EBUSY;
398 }
399
400 if (!local->func->genesis_reset || !local->func->cor_sreset) {
401 printk(KERN_INFO "%s: Genesis mode downloading not supported "
402 "with this hwmodel\n", dev->name);
403 return -EOPNOTSUPP;
404 }
405
406 local->hw_downloading = 1;
407
408 if (prism2_enable_aux_port(dev, 1)) {
409 printk(KERN_DEBUG "%s: failed to enable AUX port\n",
410 dev->name);
411 ret = -EIO;
412 goto out;
413 }
414
415 if (local->sram_type == -1) {
416 /* 0x1F for x8 SRAM or 0x0F for x16 SRAM */
417 if (prism2_enable_genesis(local, 0x1f) == 0) {
418 ram16 = 0;
419 PDEBUG(DEBUG_EXTRA2, "%s: Genesis mode OK using x8 "
420 "SRAM\n", dev->name);
421 } else if (prism2_enable_genesis(local, 0x0f) == 0) {
422 ram16 = 1;
423 PDEBUG(DEBUG_EXTRA2, "%s: Genesis mode OK using x16 "
424 "SRAM\n", dev->name);
425 } else {
426 printk(KERN_DEBUG "%s: Could not initiate genesis "
427 "mode\n", dev->name);
428 ret = -EIO;
429 goto out;
430 }
431 } else {
432 if (prism2_enable_genesis(local, local->sram_type == 8 ?
433 0x1f : 0x0f)) {
434 printk(KERN_DEBUG "%s: Failed to set Genesis "
435 "mode (sram_type=%d)\n", dev->name,
436 local->sram_type);
437 ret = -EIO;
438 goto out;
439 }
440 ram16 = local->sram_type != 8;
441 }
442
443 for (i = 0; i < param->num_areas; i++) {
444 PDEBUG(DEBUG_EXTRA2, "%s: Writing %d bytes at 0x%08x\n",
445 dev->name, param->data[i].len, param->data[i].addr);
446 if (hfa384x_to_aux(dev, param->data[i].addr,
447 param->data[i].len, param->data[i].data)) {
448 printk(KERN_WARNING "%s: RAM download at 0x%08x "
449 "(len=%d) failed\n", dev->name,
450 param->data[i].addr, param->data[i].len);
451 ret = -EIO;
452 goto out;
453 }
454 }
455
456 PDEBUG(DEBUG_EXTRA2, "Disable genesis mode\n");
457 local->func->genesis_reset(local, ram16 ? 0x07 : 0x17);
458 if (prism2_enable_aux_port(dev, 0)) {
459 printk(KERN_DEBUG "%s: Failed to disable AUX port\n",
460 dev->name);
461 }
462
463 mdelay(5);
464 local->hw_downloading = 0;
465
466 PDEBUG(DEBUG_EXTRA2, "Trying to initialize card\n");
467 /*
468 * Make sure the INIT command does not generate a command completion
469 * event by disabling interrupts.
470 */
471 hfa384x_disable_interrupts(dev);
472 if (prism2_hw_init(dev, 1)) {
473 printk(KERN_DEBUG "%s: Initialization after genesis mode "
474 "download failed\n", dev->name);
475 ret = -EIO;
476 goto out;
477 }
478
479 PDEBUG(DEBUG_EXTRA2, "Card initialized - running PRI only\n");
480 if (prism2_hw_init2(dev, 1)) {
481 printk(KERN_DEBUG "%s: Initialization(2) after genesis mode "
482 "download failed\n", dev->name);
483 ret = -EIO;
484 goto out;
485 }
486
487 out:
488 local->hw_downloading = 0;
489 return ret;
490}
491
492
493#ifdef PRISM2_NON_VOLATILE_DOWNLOAD
494/* Note! Non-volatile downloading functionality has not yet been tested
495 * thoroughly and it may corrupt flash image and effectively kill the card that
496 * is being updated. You have been warned. */
497
498static inline int prism2_download_block(struct net_device *dev,
499 u32 addr, u8 *data,
500 u32 bufaddr, int rest_len)
501{
502 u16 param0, param1;
503 int block_len;
504
505 block_len = rest_len < 4096 ? rest_len : 4096;
506
507 param0 = addr & 0xffff;
508 param1 = addr >> 16;
509
510 HFA384X_OUTW(block_len, HFA384X_PARAM2_OFF);
511 HFA384X_OUTW(param1, HFA384X_PARAM1_OFF);
512
513 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
514 (HFA384X_PROGMODE_ENABLE_NON_VOLATILE << 8),
515 param0)) {
516 printk(KERN_WARNING "%s: Flash download command execution "
517 "failed\n", dev->name);
518 return -1;
519 }
520
521 if (hfa384x_to_aux(dev, bufaddr, block_len, data)) {
522 printk(KERN_WARNING "%s: flash download at 0x%08x "
523 "(len=%d) failed\n", dev->name, addr, block_len);
524 return -1;
525 }
526
527 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
528 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
529 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
530 (HFA384X_PROGMODE_PROGRAM_NON_VOLATILE << 8),
531 0)) {
532 printk(KERN_WARNING "%s: Flash write command execution "
533 "failed\n", dev->name);
534 return -1;
535 }
536
537 return block_len;
538}
539
540
541static int prism2_download_nonvolatile(local_info_t *local,
542 struct prism2_download_data *dl)
543{
544 struct net_device *dev = local->dev;
545 int ret = 0, i;
546 struct {
547 u16 page;
548 u16 offset;
549 u16 len;
550 } dlbuffer;
551 u32 bufaddr;
552
553 if (local->hw_downloading) {
554 printk(KERN_WARNING "%s: Already downloading - aborting new "
555 "request\n", dev->name);
556 return -1;
557 }
558
559 ret = local->func->get_rid(dev, HFA384X_RID_DOWNLOADBUFFER,
560 &dlbuffer, 6, 0);
561
562 if (ret < 0) {
563 printk(KERN_WARNING "%s: Could not read download buffer "
564 "parameters\n", dev->name);
565 goto out;
566 }
567
568 dlbuffer.page = le16_to_cpu(dlbuffer.page);
569 dlbuffer.offset = le16_to_cpu(dlbuffer.offset);
570 dlbuffer.len = le16_to_cpu(dlbuffer.len);
571
572 printk(KERN_DEBUG "Download buffer: %d bytes at 0x%04x:0x%04x\n",
573 dlbuffer.len, dlbuffer.page, dlbuffer.offset);
574
575 bufaddr = (dlbuffer.page << 7) + dlbuffer.offset;
576
577 local->hw_downloading = 1;
578
579 if (!local->pri_only) {
580 prism2_hw_shutdown(dev, 0);
581
582 if (prism2_hw_init(dev, 0)) {
583 printk(KERN_WARNING "%s: Could not initialize card for"
584 " download\n", dev->name);
585 ret = -1;
586 goto out;
587 }
588 }
589
590 hfa384x_disable_interrupts(dev);
591
592 if (prism2_enable_aux_port(dev, 1)) {
593 printk(KERN_WARNING "%s: Could not enable AUX port\n",
594 dev->name);
595 ret = -1;
596 goto out;
597 }
598
599 printk(KERN_DEBUG "%s: starting flash download\n", dev->name);
600 for (i = 0; i < dl->num_areas; i++) {
601 int rest_len = dl->data[i].len;
602 int data_off = 0;
603
604 while (rest_len > 0) {
605 int block_len;
606
607 block_len = prism2_download_block(
608 dev, dl->data[i].addr + data_off,
609 dl->data[i].data + data_off, bufaddr,
610 rest_len);
611
612 if (block_len < 0) {
613 ret = -1;
614 goto out;
615 }
616
617 rest_len -= block_len;
618 data_off += block_len;
619 }
620 }
621
622 HFA384X_OUTW(0, HFA384X_PARAM1_OFF);
623 HFA384X_OUTW(0, HFA384X_PARAM2_OFF);
624 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_DOWNLOAD |
625 (HFA384X_PROGMODE_DISABLE << 8), 0)) {
626 printk(KERN_WARNING "%s: Download command execution failed\n",
627 dev->name);
628 ret = -1;
629 goto out;
630 }
631
632 if (prism2_enable_aux_port(dev, 0)) {
633 printk(KERN_DEBUG "%s: Disabling AUX port failed\n",
634 dev->name);
635 /* continue anyway.. restart should have taken care of this */
636 }
637
638 mdelay(5);
639
640 local->func->hw_reset(dev);
641 local->hw_downloading = 0;
642 if (prism2_hw_config(dev, 2)) {
643 printk(KERN_WARNING "%s: Card configuration after flash "
644 "download failed\n", dev->name);
645 ret = -1;
646 } else {
647 printk(KERN_INFO "%s: Card initialized successfully after "
648 "flash download\n", dev->name);
649 }
650
651 out:
652 local->hw_downloading = 0;
653 return ret;
654}
655#endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
656
657
658static void prism2_download_free_data(struct prism2_download_data *dl)
659{
660 int i;
661
662 if (dl == NULL)
663 return;
664
665 for (i = 0; i < dl->num_areas; i++)
666 kfree(dl->data[i].data);
667 kfree(dl);
668}
669
670
671static int prism2_download(local_info_t *local,
672 struct prism2_download_param *param)
673{
674 int ret = 0;
675 int i;
676 u32 total_len = 0;
677 struct prism2_download_data *dl = NULL;
678
679 printk(KERN_DEBUG "prism2_download: dl_cmd=%d start_addr=0x%08x "
680 "num_areas=%d\n",
681 param->dl_cmd, param->start_addr, param->num_areas);
682
683 if (param->num_areas > 100) {
684 ret = -EINVAL;
685 goto out;
686 }
687
688 dl = kmalloc(sizeof(*dl) + param->num_areas *
689 sizeof(struct prism2_download_data_area), GFP_KERNEL);
690 if (dl == NULL) {
691 ret = -ENOMEM;
692 goto out;
693 }
694 memset(dl, 0, sizeof(*dl) + param->num_areas *
695 sizeof(struct prism2_download_data_area));
696 dl->dl_cmd = param->dl_cmd;
697 dl->start_addr = param->start_addr;
698 dl->num_areas = param->num_areas;
699 for (i = 0; i < param->num_areas; i++) {
700 PDEBUG(DEBUG_EXTRA2,
701 " area %d: addr=0x%08x len=%d ptr=0x%p\n",
702 i, param->data[i].addr, param->data[i].len,
703 param->data[i].ptr);
704
705 dl->data[i].addr = param->data[i].addr;
706 dl->data[i].len = param->data[i].len;
707
708 total_len += param->data[i].len;
709 if (param->data[i].len > PRISM2_MAX_DOWNLOAD_AREA_LEN ||
710 total_len > PRISM2_MAX_DOWNLOAD_LEN) {
711 ret = -E2BIG;
712 goto out;
713 }
714
715 dl->data[i].data = kmalloc(dl->data[i].len, GFP_KERNEL);
716 if (dl->data[i].data == NULL) {
717 ret = -ENOMEM;
718 goto out;
719 }
720
721 if (copy_from_user(dl->data[i].data, param->data[i].ptr,
722 param->data[i].len)) {
723 ret = -EFAULT;
724 goto out;
725 }
726 }
727
728 switch (param->dl_cmd) {
729 case PRISM2_DOWNLOAD_VOLATILE:
730 case PRISM2_DOWNLOAD_VOLATILE_PERSISTENT:
731 ret = prism2_download_volatile(local, dl);
732 break;
733 case PRISM2_DOWNLOAD_VOLATILE_GENESIS:
734 case PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT:
735 ret = prism2_download_genesis(local, dl);
736 break;
737 case PRISM2_DOWNLOAD_NON_VOLATILE:
738#ifdef PRISM2_NON_VOLATILE_DOWNLOAD
739 ret = prism2_download_nonvolatile(local, dl);
740#else /* PRISM2_NON_VOLATILE_DOWNLOAD */
741 printk(KERN_INFO "%s: non-volatile downloading not enabled\n",
742 local->dev->name);
743 ret = -EOPNOTSUPP;
744#endif /* PRISM2_NON_VOLATILE_DOWNLOAD */
745 break;
746 default:
747 printk(KERN_DEBUG "%s: unsupported download command %d\n",
748 local->dev->name, param->dl_cmd);
749 ret = -EINVAL;
750 break;
751 };
752
753 out:
754 if (ret == 0 && dl &&
755 param->dl_cmd == PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT) {
756 prism2_download_free_data(local->dl_pri);
757 local->dl_pri = dl;
758 } else if (ret == 0 && dl &&
759 param->dl_cmd == PRISM2_DOWNLOAD_VOLATILE_PERSISTENT) {
760 prism2_download_free_data(local->dl_sec);
761 local->dl_sec = dl;
762 } else
763 prism2_download_free_data(dl);
764
765 return ret;
766}
diff --git a/drivers/net/wireless/hostap/hostap_hw.c b/drivers/net/wireless/hostap/hostap_hw.c
new file mode 100644
index 000000000000..dc31f5351b36
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_hw.c
@@ -0,0 +1,3635 @@
1/*
2 * Host AP (software wireless LAN access point) driver for
3 * Intersil Prism2/2.5/3.
4 *
5 * Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
6 * <jkmaline@cc.hut.fi>
7 * Copyright (c) 2002-2005, Jouni Malinen <jkmaline@cc.hut.fi>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation. See README and COPYING for
12 * more details.
13 *
14 * FIX:
15 * - there is currently no way of associating TX packets to correct wds device
16 * when TX Exc/OK event occurs, so all tx_packets and some
17 * tx_errors/tx_dropped are added to the main netdevice; using sw_support
18 * field in txdesc might be used to fix this (using Alloc event to increment
19 * tx_packets would need some further info in txfid table)
20 *
21 * Buffer Access Path (BAP) usage:
22 * Prism2 cards have two separate BAPs for accessing the card memory. These
23 * should allow concurrent access to two different frames and the driver
24 * previously used BAP0 for sending data and BAP1 for receiving data.
25 * However, there seems to be number of issues with concurrent access and at
26 * least one know hardware bug in using BAP0 and BAP1 concurrently with PCI
27 * Prism2.5. Therefore, the driver now only uses BAP0 for moving data between
28 * host and card memories. BAP0 accesses are protected with local->baplock
29 * (spin_lock_bh) to prevent concurrent use.
30 */
31
32
33#include <linux/config.h>
34#include <linux/version.h>
35
36#include <asm/delay.h>
37#include <asm/uaccess.h>
38
39#include <linux/slab.h>
40#include <linux/netdevice.h>
41#include <linux/etherdevice.h>
42#include <linux/proc_fs.h>
43#include <linux/if_arp.h>
44#include <linux/delay.h>
45#include <linux/random.h>
46#include <linux/wait.h>
47#include <linux/sched.h>
48#include <linux/rtnetlink.h>
49#include <linux/wireless.h>
50#include <net/iw_handler.h>
51#include <net/ieee80211.h>
52#include <net/ieee80211_crypt.h>
53#include <asm/irq.h>
54
55#include "hostap_80211.h"
56#include "hostap.h"
57#include "hostap_ap.h"
58
59
60/* #define final_version */
61
62static int mtu = 1500;
63module_param(mtu, int, 0444);
64MODULE_PARM_DESC(mtu, "Maximum transfer unit");
65
66static int channel[MAX_PARM_DEVICES] = { 3, DEF_INTS };
67module_param_array(channel, int, NULL, 0444);
68MODULE_PARM_DESC(channel, "Initial channel");
69
70static char essid[33] = "test";
71module_param_string(essid, essid, sizeof(essid), 0444);
72MODULE_PARM_DESC(essid, "Host AP's ESSID");
73
74static int iw_mode[MAX_PARM_DEVICES] = { IW_MODE_MASTER, DEF_INTS };
75module_param_array(iw_mode, int, NULL, 0444);
76MODULE_PARM_DESC(iw_mode, "Initial operation mode");
77
78static int beacon_int[MAX_PARM_DEVICES] = { 100, DEF_INTS };
79module_param_array(beacon_int, int, NULL, 0444);
80MODULE_PARM_DESC(beacon_int, "Beacon interval (1 = 1024 usec)");
81
82static int dtim_period[MAX_PARM_DEVICES] = { 1, DEF_INTS };
83module_param_array(dtim_period, int, NULL, 0444);
84MODULE_PARM_DESC(dtim_period, "DTIM period");
85
86#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
87static int bus_master_threshold_rx[MAX_PARM_DEVICES] = { 100, DEF_INTS };
88module_param_array(bus_master_threshold_rx, int, NULL, 0444);
89MODULE_PARM_DESC(bus_master_threshold_rx, "Packet length threshold for using "
90 "PCI bus master on RX");
91
92static int bus_master_threshold_tx[MAX_PARM_DEVICES] = { 100, DEF_INTS };
93module_param_array(bus_master_threshold_tx, int, NULL, 0444);
94MODULE_PARM_DESC(bus_master_threshold_tx, "Packet length threshold for using "
95 "PCI bus master on TX");
96#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
97
98static char dev_template[16] = "wlan%d";
99module_param_string(dev_template, dev_template, sizeof(dev_template), 0444);
100MODULE_PARM_DESC(dev_template, "Prefix for network device name (default: "
101 "wlan%d)");
102
103#ifdef final_version
104#define EXTRA_EVENTS_WTERR 0
105#else
106/* check WTERR events (Wait Time-out) in development versions */
107#define EXTRA_EVENTS_WTERR HFA384X_EV_WTERR
108#endif
109
110#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
111#define EXTRA_EVENTS_BUS_MASTER (HFA384X_EV_PCI_M0 | HFA384X_EV_PCI_M1)
112#else
113#define EXTRA_EVENTS_BUS_MASTER 0
114#endif
115
116/* Events that will be using BAP0 */
117#define HFA384X_BAP0_EVENTS \
118 (HFA384X_EV_TXEXC | HFA384X_EV_RX | HFA384X_EV_INFO | HFA384X_EV_TX)
119
120/* event mask, i.e., events that will result in an interrupt */
121#define HFA384X_EVENT_MASK \
122 (HFA384X_BAP0_EVENTS | HFA384X_EV_ALLOC | HFA384X_EV_INFDROP | \
123 HFA384X_EV_CMD | HFA384X_EV_TICK | \
124 EXTRA_EVENTS_WTERR | EXTRA_EVENTS_BUS_MASTER)
125
126/* Default TX control flags: use 802.11 headers and request interrupt for
127 * failed transmits. Frames that request ACK callback, will add
128 * _TX_OK flag and _ALT_RTRY flag may be used to select different retry policy.
129 */
130#define HFA384X_TX_CTRL_FLAGS \
131 (HFA384X_TX_CTRL_802_11 | HFA384X_TX_CTRL_TX_EX)
132
133
134/* ca. 1 usec */
135#define HFA384X_CMD_BUSY_TIMEOUT 5000
136#define HFA384X_BAP_BUSY_TIMEOUT 50000
137
138/* ca. 10 usec */
139#define HFA384X_CMD_COMPL_TIMEOUT 20000
140#define HFA384X_DL_COMPL_TIMEOUT 1000000
141
142/* Wait times for initialization; yield to other processes to avoid busy
143 * waiting for long time. */
144#define HFA384X_INIT_TIMEOUT (HZ / 2) /* 500 ms */
145#define HFA384X_ALLOC_COMPL_TIMEOUT (HZ / 20) /* 50 ms */
146
147
148static void prism2_hw_reset(struct net_device *dev);
149static void prism2_check_sta_fw_version(local_info_t *local);
150
151#ifdef PRISM2_DOWNLOAD_SUPPORT
152/* hostap_download.c */
153static int prism2_download_aux_dump(struct net_device *dev,
154 unsigned int addr, int len, u8 *buf);
155static u8 * prism2_read_pda(struct net_device *dev);
156static int prism2_download(local_info_t *local,
157 struct prism2_download_param *param);
158static void prism2_download_free_data(struct prism2_download_data *dl);
159static int prism2_download_volatile(local_info_t *local,
160 struct prism2_download_data *param);
161static int prism2_download_genesis(local_info_t *local,
162 struct prism2_download_data *param);
163static int prism2_get_ram_size(local_info_t *local);
164#endif /* PRISM2_DOWNLOAD_SUPPORT */
165
166
167
168
169#ifndef final_version
170/* magic value written to SWSUPPORT0 reg. for detecting whether card is still
171 * present */
172#define HFA384X_MAGIC 0x8A32
173#endif
174
175
176static u16 hfa384x_read_reg(struct net_device *dev, u16 reg)
177{
178 return HFA384X_INW(reg);
179}
180
181
182static void hfa384x_read_regs(struct net_device *dev,
183 struct hfa384x_regs *regs)
184{
185 regs->cmd = HFA384X_INW(HFA384X_CMD_OFF);
186 regs->evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
187 regs->offset0 = HFA384X_INW(HFA384X_OFFSET0_OFF);
188 regs->offset1 = HFA384X_INW(HFA384X_OFFSET1_OFF);
189 regs->swsupport0 = HFA384X_INW(HFA384X_SWSUPPORT0_OFF);
190}
191
192
193/**
194 * __hostap_cmd_queue_free - Free Prism2 command queue entry (private)
195 * @local: pointer to private Host AP driver data
196 * @entry: Prism2 command queue entry to be freed
197 * @del_req: request the entry to be removed
198 *
199 * Internal helper function for freeing Prism2 command queue entries.
200 * Caller must have acquired local->cmdlock before calling this function.
201 */
202static inline void __hostap_cmd_queue_free(local_info_t *local,
203 struct hostap_cmd_queue *entry,
204 int del_req)
205{
206 if (del_req) {
207 entry->del_req = 1;
208 if (!list_empty(&entry->list)) {
209 list_del_init(&entry->list);
210 local->cmd_queue_len--;
211 }
212 }
213
214 if (atomic_dec_and_test(&entry->usecnt) && entry->del_req)
215 kfree(entry);
216}
217
218
219/**
220 * hostap_cmd_queue_free - Free Prism2 command queue entry
221 * @local: pointer to private Host AP driver data
222 * @entry: Prism2 command queue entry to be freed
223 * @del_req: request the entry to be removed
224 *
225 * Free a Prism2 command queue entry.
226 */
227static inline void hostap_cmd_queue_free(local_info_t *local,
228 struct hostap_cmd_queue *entry,
229 int del_req)
230{
231 unsigned long flags;
232
233 spin_lock_irqsave(&local->cmdlock, flags);
234 __hostap_cmd_queue_free(local, entry, del_req);
235 spin_unlock_irqrestore(&local->cmdlock, flags);
236}
237
238
239/**
240 * prism2_clear_cmd_queue - Free all pending Prism2 command queue entries
241 * @local: pointer to private Host AP driver data
242 */
243static void prism2_clear_cmd_queue(local_info_t *local)
244{
245 struct list_head *ptr, *n;
246 unsigned long flags;
247 struct hostap_cmd_queue *entry;
248
249 spin_lock_irqsave(&local->cmdlock, flags);
250 list_for_each_safe(ptr, n, &local->cmd_queue) {
251 entry = list_entry(ptr, struct hostap_cmd_queue, list);
252 atomic_inc(&entry->usecnt);
253 printk(KERN_DEBUG "%s: removed pending cmd_queue entry "
254 "(type=%d, cmd=0x%04x, param0=0x%04x)\n",
255 local->dev->name, entry->type, entry->cmd,
256 entry->param0);
257 __hostap_cmd_queue_free(local, entry, 1);
258 }
259 if (local->cmd_queue_len) {
260 /* This should not happen; print debug message and clear
261 * queue length. */
262 printk(KERN_DEBUG "%s: cmd_queue_len (%d) not zero after "
263 "flush\n", local->dev->name, local->cmd_queue_len);
264 local->cmd_queue_len = 0;
265 }
266 spin_unlock_irqrestore(&local->cmdlock, flags);
267}
268
269
270/**
271 * hfa384x_cmd_issue - Issue a Prism2 command to the hardware
272 * @dev: pointer to net_device
273 * @entry: Prism2 command queue entry to be issued
274 */
275static inline int hfa384x_cmd_issue(struct net_device *dev,
276 struct hostap_cmd_queue *entry)
277{
278 struct hostap_interface *iface;
279 local_info_t *local;
280 int tries;
281 u16 reg;
282 unsigned long flags;
283
284 iface = netdev_priv(dev);
285 local = iface->local;
286
287 if (local->func->card_present && !local->func->card_present(local))
288 return -ENODEV;
289
290 if (entry->issued) {
291 printk(KERN_DEBUG "%s: driver bug - re-issuing command @%p\n",
292 dev->name, entry);
293 }
294
295 /* wait until busy bit is clear; this should always be clear since the
296 * commands are serialized */
297 tries = HFA384X_CMD_BUSY_TIMEOUT;
298 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
299 tries--;
300 udelay(1);
301 }
302#ifndef final_version
303 if (tries != HFA384X_CMD_BUSY_TIMEOUT) {
304 prism2_io_debug_error(dev, 1);
305 printk(KERN_DEBUG "%s: hfa384x_cmd_issue: cmd reg was busy "
306 "for %d usec\n", dev->name,
307 HFA384X_CMD_BUSY_TIMEOUT - tries);
308 }
309#endif
310 if (tries == 0) {
311 reg = HFA384X_INW(HFA384X_CMD_OFF);
312 prism2_io_debug_error(dev, 2);
313 printk(KERN_DEBUG "%s: hfa384x_cmd_issue - timeout - "
314 "reg=0x%04x\n", dev->name, reg);
315 return -ETIMEDOUT;
316 }
317
318 /* write command */
319 spin_lock_irqsave(&local->cmdlock, flags);
320 HFA384X_OUTW(entry->param0, HFA384X_PARAM0_OFF);
321 HFA384X_OUTW(entry->param1, HFA384X_PARAM1_OFF);
322 HFA384X_OUTW(entry->cmd, HFA384X_CMD_OFF);
323 entry->issued = 1;
324 spin_unlock_irqrestore(&local->cmdlock, flags);
325
326 return 0;
327}
328
329
330/**
331 * hfa384x_cmd - Issue a Prism2 command and wait (sleep) for completion
332 * @dev: pointer to net_device
333 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
334 * @param0: value for Param0 register
335 * @param1: value for Param1 register (pointer; %NULL if not used)
336 * @resp0: pointer for Resp0 data or %NULL if Resp0 is not needed
337 *
338 * Issue given command (possibly after waiting in command queue) and sleep
339 * until the command is completed (or timed out or interrupted). This can be
340 * called only from user process context.
341 */
342static int hfa384x_cmd(struct net_device *dev, u16 cmd, u16 param0,
343 u16 *param1, u16 *resp0)
344{
345 struct hostap_interface *iface;
346 local_info_t *local;
347 int err, res, issue, issued = 0;
348 unsigned long flags;
349 struct hostap_cmd_queue *entry;
350 DECLARE_WAITQUEUE(wait, current);
351
352 iface = netdev_priv(dev);
353 local = iface->local;
354
355 if (in_interrupt()) {
356 printk(KERN_DEBUG "%s: hfa384x_cmd called from interrupt "
357 "context\n", dev->name);
358 return -1;
359 }
360
361 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN) {
362 printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
363 dev->name);
364 return -1;
365 }
366
367 if (signal_pending(current))
368 return -EINTR;
369
370 entry = (struct hostap_cmd_queue *)
371 kmalloc(sizeof(*entry), GFP_ATOMIC);
372 if (entry == NULL) {
373 printk(KERN_DEBUG "%s: hfa384x_cmd - kmalloc failed\n",
374 dev->name);
375 return -ENOMEM;
376 }
377 memset(entry, 0, sizeof(*entry));
378 atomic_set(&entry->usecnt, 1);
379 entry->type = CMD_SLEEP;
380 entry->cmd = cmd;
381 entry->param0 = param0;
382 if (param1)
383 entry->param1 = *param1;
384 init_waitqueue_head(&entry->compl);
385
386 /* prepare to wait for command completion event, but do not sleep yet
387 */
388 add_wait_queue(&entry->compl, &wait);
389 set_current_state(TASK_INTERRUPTIBLE);
390
391 spin_lock_irqsave(&local->cmdlock, flags);
392 issue = list_empty(&local->cmd_queue);
393 if (issue)
394 entry->issuing = 1;
395 list_add_tail(&entry->list, &local->cmd_queue);
396 local->cmd_queue_len++;
397 spin_unlock_irqrestore(&local->cmdlock, flags);
398
399 err = 0;
400 if (!issue)
401 goto wait_completion;
402
403 if (signal_pending(current))
404 err = -EINTR;
405
406 if (!err) {
407 if (hfa384x_cmd_issue(dev, entry))
408 err = -ETIMEDOUT;
409 else
410 issued = 1;
411 }
412
413 wait_completion:
414 if (!err && entry->type != CMD_COMPLETED) {
415 /* sleep until command is completed or timed out */
416 res = schedule_timeout(2 * HZ);
417 } else
418 res = -1;
419
420 if (!err && signal_pending(current))
421 err = -EINTR;
422
423 if (err && issued) {
424 /* the command was issued, so a CmdCompl event should occur
425 * soon; however, there's a pending signal and
426 * schedule_timeout() would be interrupted; wait a short period
427 * of time to avoid removing entry from the list before
428 * CmdCompl event */
429 udelay(300);
430 }
431
432 set_current_state(TASK_RUNNING);
433 remove_wait_queue(&entry->compl, &wait);
434
435 /* If entry->list is still in the list, it must be removed
436 * first and in this case prism2_cmd_ev() does not yet have
437 * local reference to it, and the data can be kfree()'d
438 * here. If the command completion event is still generated,
439 * it will be assigned to next (possibly) pending command, but
440 * the driver will reset the card anyway due to timeout
441 *
442 * If the entry is not in the list prism2_cmd_ev() has a local
443 * reference to it, but keeps cmdlock as long as the data is
444 * needed, so the data can be kfree()'d here. */
445
446 /* FIX: if the entry->list is in the list, it has not been completed
447 * yet, so removing it here is somewhat wrong.. this could cause
448 * references to freed memory and next list_del() causing NULL pointer
449 * dereference.. it would probably be better to leave the entry in the
450 * list and the list should be emptied during hw reset */
451
452 spin_lock_irqsave(&local->cmdlock, flags);
453 if (!list_empty(&entry->list)) {
454 printk(KERN_DEBUG "%s: hfa384x_cmd: entry still in list? "
455 "(entry=%p, type=%d, res=%d)\n", dev->name, entry,
456 entry->type, res);
457 list_del_init(&entry->list);
458 local->cmd_queue_len--;
459 }
460 spin_unlock_irqrestore(&local->cmdlock, flags);
461
462 if (err) {
463 printk(KERN_DEBUG "%s: hfa384x_cmd: interrupted; err=%d\n",
464 dev->name, err);
465 res = err;
466 goto done;
467 }
468
469 if (entry->type != CMD_COMPLETED) {
470 u16 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
471 printk(KERN_DEBUG "%s: hfa384x_cmd: command was not "
472 "completed (res=%d, entry=%p, type=%d, cmd=0x%04x, "
473 "param0=0x%04x, EVSTAT=%04x INTEN=%04x)\n", dev->name,
474 res, entry, entry->type, entry->cmd, entry->param0, reg,
475 HFA384X_INW(HFA384X_INTEN_OFF));
476 if (reg & HFA384X_EV_CMD) {
477 /* Command completion event is pending, but the
478 * interrupt was not delivered - probably an issue
479 * with pcmcia-cs configuration. */
480 printk(KERN_WARNING "%s: interrupt delivery does not "
481 "seem to work\n", dev->name);
482 }
483 prism2_io_debug_error(dev, 3);
484 res = -ETIMEDOUT;
485 goto done;
486 }
487
488 if (resp0 != NULL)
489 *resp0 = entry->resp0;
490#ifndef final_version
491 if (entry->res) {
492 printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x, "
493 "resp0=0x%04x\n",
494 dev->name, cmd, entry->res, entry->resp0);
495 }
496#endif /* final_version */
497
498 res = entry->res;
499 done:
500 hostap_cmd_queue_free(local, entry, 1);
501 return res;
502}
503
504
505/**
506 * hfa384x_cmd_callback - Issue a Prism2 command; callback when completed
507 * @dev: pointer to net_device
508 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
509 * @param0: value for Param0 register
510 * @callback: command completion callback function (%NULL = no callback)
511 * @context: context data to be given to the callback function
512 *
513 * Issue given command (possibly after waiting in command queue) and use
514 * callback function to indicate command completion. This can be called both
515 * from user and interrupt context. The callback function will be called in
516 * hardware IRQ context. It can be %NULL, when no function is called when
517 * command is completed.
518 */
519static int hfa384x_cmd_callback(struct net_device *dev, u16 cmd, u16 param0,
520 void (*callback)(struct net_device *dev,
521 long context, u16 resp0,
522 u16 status),
523 long context)
524{
525 struct hostap_interface *iface;
526 local_info_t *local;
527 int issue, ret;
528 unsigned long flags;
529 struct hostap_cmd_queue *entry;
530
531 iface = netdev_priv(dev);
532 local = iface->local;
533
534 if (local->cmd_queue_len >= HOSTAP_CMD_QUEUE_MAX_LEN + 2) {
535 printk(KERN_DEBUG "%s: hfa384x_cmd: cmd_queue full\n",
536 dev->name);
537 return -1;
538 }
539
540 entry = (struct hostap_cmd_queue *)
541 kmalloc(sizeof(*entry), GFP_ATOMIC);
542 if (entry == NULL) {
543 printk(KERN_DEBUG "%s: hfa384x_cmd_callback - kmalloc "
544 "failed\n", dev->name);
545 return -ENOMEM;
546 }
547 memset(entry, 0, sizeof(*entry));
548 atomic_set(&entry->usecnt, 1);
549 entry->type = CMD_CALLBACK;
550 entry->cmd = cmd;
551 entry->param0 = param0;
552 entry->callback = callback;
553 entry->context = context;
554
555 spin_lock_irqsave(&local->cmdlock, flags);
556 issue = list_empty(&local->cmd_queue);
557 if (issue)
558 entry->issuing = 1;
559 list_add_tail(&entry->list, &local->cmd_queue);
560 local->cmd_queue_len++;
561 spin_unlock_irqrestore(&local->cmdlock, flags);
562
563 if (issue && hfa384x_cmd_issue(dev, entry))
564 ret = -ETIMEDOUT;
565 else
566 ret = 0;
567
568 hostap_cmd_queue_free(local, entry, ret);
569
570 return ret;
571}
572
573
574/**
575 * __hfa384x_cmd_no_wait - Issue a Prism2 command (private)
576 * @dev: pointer to net_device
577 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
578 * @param0: value for Param0 register
579 * @io_debug_num: I/O debug error number
580 *
581 * Shared helper function for hfa384x_cmd_wait() and hfa384x_cmd_no_wait().
582 */
583static int __hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd, u16 param0,
584 int io_debug_num)
585{
586 int tries;
587 u16 reg;
588
589 /* wait until busy bit is clear; this should always be clear since the
590 * commands are serialized */
591 tries = HFA384X_CMD_BUSY_TIMEOUT;
592 while (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY && tries > 0) {
593 tries--;
594 udelay(1);
595 }
596 if (tries == 0) {
597 reg = HFA384X_INW(HFA384X_CMD_OFF);
598 prism2_io_debug_error(dev, io_debug_num);
599 printk(KERN_DEBUG "%s: __hfa384x_cmd_no_wait(%d) - timeout - "
600 "reg=0x%04x\n", dev->name, io_debug_num, reg);
601 return -ETIMEDOUT;
602 }
603
604 /* write command */
605 HFA384X_OUTW(param0, HFA384X_PARAM0_OFF);
606 HFA384X_OUTW(cmd, HFA384X_CMD_OFF);
607
608 return 0;
609}
610
611
612/**
613 * hfa384x_cmd_wait - Issue a Prism2 command and busy wait for completion
614 * @dev: pointer to net_device
615 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
616 * @param0: value for Param0 register
617 */
618static int hfa384x_cmd_wait(struct net_device *dev, u16 cmd, u16 param0)
619{
620 int res, tries;
621 u16 reg;
622
623 res = __hfa384x_cmd_no_wait(dev, cmd, param0, 4);
624 if (res)
625 return res;
626
627 /* wait for command completion */
628 if ((cmd & HFA384X_CMDCODE_MASK) == HFA384X_CMDCODE_DOWNLOAD)
629 tries = HFA384X_DL_COMPL_TIMEOUT;
630 else
631 tries = HFA384X_CMD_COMPL_TIMEOUT;
632
633 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
634 tries > 0) {
635 tries--;
636 udelay(10);
637 }
638 if (tries == 0) {
639 reg = HFA384X_INW(HFA384X_EVSTAT_OFF);
640 prism2_io_debug_error(dev, 5);
641 printk(KERN_DEBUG "%s: hfa384x_cmd_wait - timeout2 - "
642 "reg=0x%04x\n", dev->name, reg);
643 return -ETIMEDOUT;
644 }
645
646 res = (HFA384X_INW(HFA384X_STATUS_OFF) &
647 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) | BIT(9) |
648 BIT(8))) >> 8;
649#ifndef final_version
650 if (res) {
651 printk(KERN_DEBUG "%s: CMD=0x%04x => res=0x%02x\n",
652 dev->name, cmd, res);
653 }
654#endif
655
656 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
657
658 return res;
659}
660
661
662/**
663 * hfa384x_cmd_no_wait - Issue a Prism2 command; do not wait for completion
664 * @dev: pointer to net_device
665 * @cmd: Prism2 command code (HFA384X_CMD_CODE_*)
666 * @param0: value for Param0 register
667 */
668static inline int hfa384x_cmd_no_wait(struct net_device *dev, u16 cmd,
669 u16 param0)
670{
671 return __hfa384x_cmd_no_wait(dev, cmd, param0, 6);
672}
673
674
675/**
676 * prism2_cmd_ev - Prism2 command completion event handler
677 * @dev: pointer to net_device
678 *
679 * Interrupt handler for command completion events. Called by the main
680 * interrupt handler in hardware IRQ context. Read Resp0 and status registers
681 * from the hardware and ACK the event. Depending on the issued command type
682 * either wake up the sleeping process that is waiting for command completion
683 * or call the callback function. Issue the next command, if one is pending.
684 */
685static void prism2_cmd_ev(struct net_device *dev)
686{
687 struct hostap_interface *iface;
688 local_info_t *local;
689 struct hostap_cmd_queue *entry = NULL;
690
691 iface = netdev_priv(dev);
692 local = iface->local;
693
694 spin_lock(&local->cmdlock);
695 if (!list_empty(&local->cmd_queue)) {
696 entry = list_entry(local->cmd_queue.next,
697 struct hostap_cmd_queue, list);
698 atomic_inc(&entry->usecnt);
699 list_del_init(&entry->list);
700 local->cmd_queue_len--;
701
702 if (!entry->issued) {
703 printk(KERN_DEBUG "%s: Command completion event, but "
704 "cmd not issued\n", dev->name);
705 __hostap_cmd_queue_free(local, entry, 1);
706 entry = NULL;
707 }
708 }
709 spin_unlock(&local->cmdlock);
710
711 if (!entry) {
712 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
713 printk(KERN_DEBUG "%s: Command completion event, but no "
714 "pending commands\n", dev->name);
715 return;
716 }
717
718 entry->resp0 = HFA384X_INW(HFA384X_RESP0_OFF);
719 entry->res = (HFA384X_INW(HFA384X_STATUS_OFF) &
720 (BIT(14) | BIT(13) | BIT(12) | BIT(11) | BIT(10) |
721 BIT(9) | BIT(8))) >> 8;
722 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
723
724 /* TODO: rest of the CmdEv handling could be moved to tasklet */
725 if (entry->type == CMD_SLEEP) {
726 entry->type = CMD_COMPLETED;
727 wake_up_interruptible(&entry->compl);
728 } else if (entry->type == CMD_CALLBACK) {
729 if (entry->callback)
730 entry->callback(dev, entry->context, entry->resp0,
731 entry->res);
732 } else {
733 printk(KERN_DEBUG "%s: Invalid command completion type %d\n",
734 dev->name, entry->type);
735 }
736 hostap_cmd_queue_free(local, entry, 1);
737
738 /* issue next command, if pending */
739 entry = NULL;
740 spin_lock(&local->cmdlock);
741 if (!list_empty(&local->cmd_queue)) {
742 entry = list_entry(local->cmd_queue.next,
743 struct hostap_cmd_queue, list);
744 if (entry->issuing) {
745 /* hfa384x_cmd() has already started issuing this
746 * command, so do not start here */
747 entry = NULL;
748 }
749 if (entry)
750 atomic_inc(&entry->usecnt);
751 }
752 spin_unlock(&local->cmdlock);
753
754 if (entry) {
755 /* issue next command; if command issuing fails, remove the
756 * entry from cmd_queue */
757 int res = hfa384x_cmd_issue(dev, entry);
758 spin_lock(&local->cmdlock);
759 __hostap_cmd_queue_free(local, entry, res);
760 spin_unlock(&local->cmdlock);
761 }
762}
763
764
765static inline int hfa384x_wait_offset(struct net_device *dev, u16 o_off)
766{
767 int tries = HFA384X_BAP_BUSY_TIMEOUT;
768 int res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
769
770 while (res && tries > 0) {
771 tries--;
772 udelay(1);
773 res = HFA384X_INW(o_off) & HFA384X_OFFSET_BUSY;
774 }
775 return res;
776}
777
778
779/* Offset must be even */
780static int hfa384x_setup_bap(struct net_device *dev, u16 bap, u16 id,
781 int offset)
782{
783 u16 o_off, s_off;
784 int ret = 0;
785
786 if (offset % 2 || bap > 1)
787 return -EINVAL;
788
789 if (bap == BAP1) {
790 o_off = HFA384X_OFFSET1_OFF;
791 s_off = HFA384X_SELECT1_OFF;
792 } else {
793 o_off = HFA384X_OFFSET0_OFF;
794 s_off = HFA384X_SELECT0_OFF;
795 }
796
797 if (hfa384x_wait_offset(dev, o_off)) {
798 prism2_io_debug_error(dev, 7);
799 printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout before\n",
800 dev->name);
801 ret = -ETIMEDOUT;
802 goto out;
803 }
804
805 HFA384X_OUTW(id, s_off);
806 HFA384X_OUTW(offset, o_off);
807
808 if (hfa384x_wait_offset(dev, o_off)) {
809 prism2_io_debug_error(dev, 8);
810 printk(KERN_DEBUG "%s: hfa384x_setup_bap - timeout after\n",
811 dev->name);
812 ret = -ETIMEDOUT;
813 goto out;
814 }
815#ifndef final_version
816 if (HFA384X_INW(o_off) & HFA384X_OFFSET_ERR) {
817 prism2_io_debug_error(dev, 9);
818 printk(KERN_DEBUG "%s: hfa384x_setup_bap - offset error "
819 "(%d,0x04%x,%d); reg=0x%04x\n",
820 dev->name, bap, id, offset, HFA384X_INW(o_off));
821 ret = -EINVAL;
822 }
823#endif
824
825 out:
826 return ret;
827}
828
829
830static int hfa384x_get_rid(struct net_device *dev, u16 rid, void *buf, int len,
831 int exact_len)
832{
833 struct hostap_interface *iface;
834 local_info_t *local;
835 int res, rlen = 0;
836 struct hfa384x_rid_hdr rec;
837
838 iface = netdev_priv(dev);
839 local = iface->local;
840
841 if (local->no_pri) {
842 printk(KERN_DEBUG "%s: cannot get RID %04x (len=%d) - no PRI "
843 "f/w\n", dev->name, rid, len);
844 return -ENOTTY; /* Well.. not really correct, but return
845 * something unique enough.. */
846 }
847
848 if ((local->func->card_present && !local->func->card_present(local)) ||
849 local->hw_downloading)
850 return -ENODEV;
851
852 res = down_interruptible(&local->rid_bap_sem);
853 if (res)
854 return res;
855
856 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS, rid, NULL, NULL);
857 if (res) {
858 printk(KERN_DEBUG "%s: hfa384x_get_rid: CMDCODE_ACCESS failed "
859 "(res=%d, rid=%04x, len=%d)\n",
860 dev->name, res, rid, len);
861 up(&local->rid_bap_sem);
862 return res;
863 }
864
865 spin_lock_bh(&local->baplock);
866
867 res = hfa384x_setup_bap(dev, BAP0, rid, 0);
868 if (!res)
869 res = hfa384x_from_bap(dev, BAP0, &rec, sizeof(rec));
870
871 if (le16_to_cpu(rec.len) == 0) {
872 /* RID not available */
873 res = -ENODATA;
874 }
875
876 rlen = (le16_to_cpu(rec.len) - 1) * 2;
877 if (!res && exact_len && rlen != len) {
878 printk(KERN_DEBUG "%s: hfa384x_get_rid - RID len mismatch: "
879 "rid=0x%04x, len=%d (expected %d)\n",
880 dev->name, rid, rlen, len);
881 res = -ENODATA;
882 }
883
884 if (!res)
885 res = hfa384x_from_bap(dev, BAP0, buf, len);
886
887 spin_unlock_bh(&local->baplock);
888 up(&local->rid_bap_sem);
889
890 if (res) {
891 if (res != -ENODATA)
892 printk(KERN_DEBUG "%s: hfa384x_get_rid (rid=%04x, "
893 "len=%d) - failed - res=%d\n", dev->name, rid,
894 len, res);
895 if (res == -ETIMEDOUT)
896 prism2_hw_reset(dev);
897 return res;
898 }
899
900 return rlen;
901}
902
903
904static int hfa384x_set_rid(struct net_device *dev, u16 rid, void *buf, int len)
905{
906 struct hostap_interface *iface;
907 local_info_t *local;
908 struct hfa384x_rid_hdr rec;
909 int res;
910
911 iface = netdev_priv(dev);
912 local = iface->local;
913
914 if (local->no_pri) {
915 printk(KERN_DEBUG "%s: cannot set RID %04x (len=%d) - no PRI "
916 "f/w\n", dev->name, rid, len);
917 return -ENOTTY; /* Well.. not really correct, but return
918 * something unique enough.. */
919 }
920
921 if ((local->func->card_present && !local->func->card_present(local)) ||
922 local->hw_downloading)
923 return -ENODEV;
924
925 rec.rid = cpu_to_le16(rid);
926 /* RID len in words and +1 for rec.rid */
927 rec.len = cpu_to_le16(len / 2 + len % 2 + 1);
928
929 res = down_interruptible(&local->rid_bap_sem);
930 if (res)
931 return res;
932
933 spin_lock_bh(&local->baplock);
934 res = hfa384x_setup_bap(dev, BAP0, rid, 0);
935 if (!res)
936 res = hfa384x_to_bap(dev, BAP0, &rec, sizeof(rec));
937 if (!res)
938 res = hfa384x_to_bap(dev, BAP0, buf, len);
939 spin_unlock_bh(&local->baplock);
940
941 if (res) {
942 printk(KERN_DEBUG "%s: hfa384x_set_rid (rid=%04x, len=%d) - "
943 "failed - res=%d\n", dev->name, rid, len, res);
944 up(&local->rid_bap_sem);
945 return res;
946 }
947
948 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ACCESS_WRITE, rid, NULL, NULL);
949 up(&local->rid_bap_sem);
950 if (res) {
951 printk(KERN_DEBUG "%s: hfa384x_set_rid: CMDCODE_ACCESS_WRITE "
952 "failed (res=%d, rid=%04x, len=%d)\n",
953 dev->name, res, rid, len);
954 return res;
955 }
956
957 if (res == -ETIMEDOUT)
958 prism2_hw_reset(dev);
959
960 return res;
961}
962
963
964static void hfa384x_disable_interrupts(struct net_device *dev)
965{
966 /* disable interrupts and clear event status */
967 HFA384X_OUTW(0, HFA384X_INTEN_OFF);
968 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
969}
970
971
972static void hfa384x_enable_interrupts(struct net_device *dev)
973{
974 /* ack pending events and enable interrupts from selected events */
975 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
976 HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
977}
978
979
980static void hfa384x_events_no_bap0(struct net_device *dev)
981{
982 HFA384X_OUTW(HFA384X_EVENT_MASK & ~HFA384X_BAP0_EVENTS,
983 HFA384X_INTEN_OFF);
984}
985
986
987static void hfa384x_events_all(struct net_device *dev)
988{
989 HFA384X_OUTW(HFA384X_EVENT_MASK, HFA384X_INTEN_OFF);
990}
991
992
993static void hfa384x_events_only_cmd(struct net_device *dev)
994{
995 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_INTEN_OFF);
996}
997
998
999static u16 hfa384x_allocate_fid(struct net_device *dev, int len)
1000{
1001 u16 fid;
1002 unsigned long delay;
1003
1004 /* FIX: this could be replace with hfa384x_cmd() if the Alloc event
1005 * below would be handled like CmdCompl event (sleep here, wake up from
1006 * interrupt handler */
1007 if (hfa384x_cmd_wait(dev, HFA384X_CMDCODE_ALLOC, len)) {
1008 printk(KERN_DEBUG "%s: cannot allocate fid, len=%d\n",
1009 dev->name, len);
1010 return 0xffff;
1011 }
1012
1013 delay = jiffies + HFA384X_ALLOC_COMPL_TIMEOUT;
1014 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC) &&
1015 time_before(jiffies, delay))
1016 yield();
1017 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_ALLOC)) {
1018 printk("%s: fid allocate, len=%d - timeout\n", dev->name, len);
1019 return 0xffff;
1020 }
1021
1022 fid = HFA384X_INW(HFA384X_ALLOCFID_OFF);
1023 HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
1024
1025 return fid;
1026}
1027
1028
1029static int prism2_reset_port(struct net_device *dev)
1030{
1031 struct hostap_interface *iface;
1032 local_info_t *local;
1033 int res;
1034
1035 iface = netdev_priv(dev);
1036 local = iface->local;
1037
1038 if (!local->dev_enabled)
1039 return 0;
1040
1041 res = hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0,
1042 NULL, NULL);
1043 if (res)
1044 printk(KERN_DEBUG "%s: reset port failed to disable port\n",
1045 dev->name);
1046 else {
1047 res = hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0,
1048 NULL, NULL);
1049 if (res)
1050 printk(KERN_DEBUG "%s: reset port failed to enable "
1051 "port\n", dev->name);
1052 }
1053
1054 /* It looks like at least some STA firmware versions reset
1055 * fragmentation threshold back to 2346 after enable command. Restore
1056 * the configured value, if it differs from this default. */
1057 if (local->fragm_threshold != 2346 &&
1058 hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
1059 local->fragm_threshold)) {
1060 printk(KERN_DEBUG "%s: failed to restore fragmentation "
1061 "threshold (%d) after Port0 enable\n",
1062 dev->name, local->fragm_threshold);
1063 }
1064
1065 return res;
1066}
1067
1068
1069static int prism2_get_version_info(struct net_device *dev, u16 rid,
1070 const char *txt)
1071{
1072 struct hfa384x_comp_ident comp;
1073 struct hostap_interface *iface;
1074 local_info_t *local;
1075
1076 iface = netdev_priv(dev);
1077 local = iface->local;
1078
1079 if (local->no_pri) {
1080 /* PRI f/w not yet available - cannot read RIDs */
1081 return -1;
1082 }
1083 if (hfa384x_get_rid(dev, rid, &comp, sizeof(comp), 1) < 0) {
1084 printk(KERN_DEBUG "Could not get RID for component %s\n", txt);
1085 return -1;
1086 }
1087
1088 printk(KERN_INFO "%s: %s: id=0x%02x v%d.%d.%d\n", dev->name, txt,
1089 __le16_to_cpu(comp.id), __le16_to_cpu(comp.major),
1090 __le16_to_cpu(comp.minor), __le16_to_cpu(comp.variant));
1091 return 0;
1092}
1093
1094
1095static int prism2_setup_rids(struct net_device *dev)
1096{
1097 struct hostap_interface *iface;
1098 local_info_t *local;
1099 u16 tmp;
1100 int ret = 0;
1101
1102 iface = netdev_priv(dev);
1103 local = iface->local;
1104
1105 hostap_set_word(dev, HFA384X_RID_TICKTIME, 2000);
1106
1107 if (!local->fw_ap) {
1108 tmp = hostap_get_porttype(local);
1109 ret = hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE, tmp);
1110 if (ret) {
1111 printk("%s: Port type setting to %d failed\n",
1112 dev->name, tmp);
1113 goto fail;
1114 }
1115 }
1116
1117 /* Setting SSID to empty string seems to kill the card in Host AP mode
1118 */
1119 if (local->iw_mode != IW_MODE_MASTER || local->essid[0] != '\0') {
1120 ret = hostap_set_string(dev, HFA384X_RID_CNFOWNSSID,
1121 local->essid);
1122 if (ret) {
1123 printk("%s: AP own SSID setting failed\n", dev->name);
1124 goto fail;
1125 }
1126 }
1127
1128 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXDATALEN,
1129 PRISM2_DATA_MAXLEN);
1130 if (ret) {
1131 printk("%s: MAC data length setting to %d failed\n",
1132 dev->name, PRISM2_DATA_MAXLEN);
1133 goto fail;
1134 }
1135
1136 if (hfa384x_get_rid(dev, HFA384X_RID_CHANNELLIST, &tmp, 2, 1) < 0) {
1137 printk("%s: Channel list read failed\n", dev->name);
1138 ret = -EINVAL;
1139 goto fail;
1140 }
1141 local->channel_mask = __le16_to_cpu(tmp);
1142
1143 if (local->channel < 1 || local->channel > 14 ||
1144 !(local->channel_mask & (1 << (local->channel - 1)))) {
1145 printk(KERN_WARNING "%s: Channel setting out of range "
1146 "(%d)!\n", dev->name, local->channel);
1147 ret = -EBUSY;
1148 goto fail;
1149 }
1150
1151 ret = hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel);
1152 if (ret) {
1153 printk("%s: Channel setting to %d failed\n",
1154 dev->name, local->channel);
1155 goto fail;
1156 }
1157
1158 ret = hostap_set_word(dev, HFA384X_RID_CNFBEACONINT,
1159 local->beacon_int);
1160 if (ret) {
1161 printk("%s: Beacon interval setting to %d failed\n",
1162 dev->name, local->beacon_int);
1163 /* this may fail with Symbol/Lucent firmware */
1164 if (ret == -ETIMEDOUT)
1165 goto fail;
1166 }
1167
1168 ret = hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD,
1169 local->dtim_period);
1170 if (ret) {
1171 printk("%s: DTIM period setting to %d failed\n",
1172 dev->name, local->dtim_period);
1173 /* this may fail with Symbol/Lucent firmware */
1174 if (ret == -ETIMEDOUT)
1175 goto fail;
1176 }
1177
1178 ret = hostap_set_word(dev, HFA384X_RID_PROMISCUOUSMODE,
1179 local->is_promisc);
1180 if (ret)
1181 printk(KERN_INFO "%s: Setting promiscuous mode (%d) failed\n",
1182 dev->name, local->is_promisc);
1183
1184 if (!local->fw_ap) {
1185 ret = hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID,
1186 local->essid);
1187 if (ret) {
1188 printk("%s: Desired SSID setting failed\n", dev->name);
1189 goto fail;
1190 }
1191 }
1192
1193 /* Setup TXRateControl, defaults to allow use of 1, 2, 5.5, and
1194 * 11 Mbps in automatic TX rate fallback and 1 and 2 Mbps as basic
1195 * rates */
1196 if (local->tx_rate_control == 0) {
1197 local->tx_rate_control =
1198 HFA384X_RATES_1MBPS |
1199 HFA384X_RATES_2MBPS |
1200 HFA384X_RATES_5MBPS |
1201 HFA384X_RATES_11MBPS;
1202 }
1203 if (local->basic_rates == 0)
1204 local->basic_rates = HFA384X_RATES_1MBPS | HFA384X_RATES_2MBPS;
1205
1206 if (!local->fw_ap) {
1207 ret = hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
1208 local->tx_rate_control);
1209 if (ret) {
1210 printk("%s: TXRateControl setting to %d failed\n",
1211 dev->name, local->tx_rate_control);
1212 goto fail;
1213 }
1214
1215 ret = hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
1216 local->tx_rate_control);
1217 if (ret) {
1218 printk("%s: cnfSupportedRates setting to %d failed\n",
1219 dev->name, local->tx_rate_control);
1220 }
1221
1222 ret = hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
1223 local->basic_rates);
1224 if (ret) {
1225 printk("%s: cnfBasicRates setting to %d failed\n",
1226 dev->name, local->basic_rates);
1227 }
1228
1229 ret = hostap_set_word(dev, HFA384X_RID_CREATEIBSS, 1);
1230 if (ret) {
1231 printk("%s: Create IBSS setting to 1 failed\n",
1232 dev->name);
1233 }
1234 }
1235
1236 if (local->name_set)
1237 (void) hostap_set_string(dev, HFA384X_RID_CNFOWNNAME,
1238 local->name);
1239
1240 if (hostap_set_encryption(local)) {
1241 printk(KERN_INFO "%s: could not configure encryption\n",
1242 dev->name);
1243 }
1244
1245 (void) hostap_set_antsel(local);
1246
1247 if (hostap_set_roaming(local)) {
1248 printk(KERN_INFO "%s: could not set host roaming\n",
1249 dev->name);
1250 }
1251
1252 if (local->sta_fw_ver >= PRISM2_FW_VER(1,6,3) &&
1253 hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY, local->enh_sec))
1254 printk(KERN_INFO "%s: cnfEnhSecurity setting to 0x%x failed\n",
1255 dev->name, local->enh_sec);
1256
1257 /* 32-bit tallies were added in STA f/w 0.8.0, but they were apparently
1258 * not working correctly (last seven counters report bogus values).
1259 * This has been fixed in 0.8.2, so enable 32-bit tallies only
1260 * beginning with that firmware version. Another bug fix for 32-bit
1261 * tallies in 1.4.0; should 16-bit tallies be used for some other
1262 * versions, too? */
1263 if (local->sta_fw_ver >= PRISM2_FW_VER(0,8,2)) {
1264 if (hostap_set_word(dev, HFA384X_RID_CNFTHIRTY2TALLY, 1)) {
1265 printk(KERN_INFO "%s: cnfThirty2Tally setting "
1266 "failed\n", dev->name);
1267 local->tallies32 = 0;
1268 } else
1269 local->tallies32 = 1;
1270 } else
1271 local->tallies32 = 0;
1272
1273 hostap_set_auth_algs(local);
1274
1275 if (hostap_set_word(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
1276 local->fragm_threshold)) {
1277 printk(KERN_INFO "%s: setting FragmentationThreshold to %d "
1278 "failed\n", dev->name, local->fragm_threshold);
1279 }
1280
1281 if (hostap_set_word(dev, HFA384X_RID_RTSTHRESHOLD,
1282 local->rts_threshold)) {
1283 printk(KERN_INFO "%s: setting RTSThreshold to %d failed\n",
1284 dev->name, local->rts_threshold);
1285 }
1286
1287 if (local->manual_retry_count >= 0 &&
1288 hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1289 local->manual_retry_count)) {
1290 printk(KERN_INFO "%s: setting cnfAltRetryCount to %d failed\n",
1291 dev->name, local->manual_retry_count);
1292 }
1293
1294 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1) &&
1295 hfa384x_get_rid(dev, HFA384X_RID_CNFDBMADJUST, &tmp, 2, 1) == 2) {
1296 local->rssi_to_dBm = le16_to_cpu(tmp);
1297 }
1298
1299 if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->wpa &&
1300 hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1)) {
1301 printk(KERN_INFO "%s: setting ssnHandlingMode to 1 failed\n",
1302 dev->name);
1303 }
1304
1305 if (local->sta_fw_ver >= PRISM2_FW_VER(1,7,0) && local->generic_elem &&
1306 hfa384x_set_rid(dev, HFA384X_RID_GENERICELEMENT,
1307 local->generic_elem, local->generic_elem_len)) {
1308 printk(KERN_INFO "%s: setting genericElement failed\n",
1309 dev->name);
1310 }
1311
1312 fail:
1313 return ret;
1314}
1315
1316
1317static int prism2_hw_init(struct net_device *dev, int initial)
1318{
1319 struct hostap_interface *iface;
1320 local_info_t *local;
1321 int ret, first = 1;
1322 unsigned long start, delay;
1323
1324 PDEBUG(DEBUG_FLOW, "prism2_hw_init()\n");
1325
1326 iface = netdev_priv(dev);
1327 local = iface->local;
1328
1329 clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits);
1330
1331 init:
1332 /* initialize HFA 384x */
1333 ret = hfa384x_cmd_no_wait(dev, HFA384X_CMDCODE_INIT, 0);
1334 if (ret) {
1335 printk(KERN_INFO "%s: first command failed - assuming card "
1336 "does not have primary firmware\n", dev_info);
1337 }
1338
1339 if (first && (HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
1340 /* EvStat has Cmd bit set in some cases, so retry once if no
1341 * wait was needed */
1342 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
1343 printk(KERN_DEBUG "%s: init command completed too quickly - "
1344 "retrying\n", dev->name);
1345 first = 0;
1346 goto init;
1347 }
1348
1349 start = jiffies;
1350 delay = jiffies + HFA384X_INIT_TIMEOUT;
1351 while (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD) &&
1352 time_before(jiffies, delay))
1353 yield();
1354 if (!(HFA384X_INW(HFA384X_EVSTAT_OFF) & HFA384X_EV_CMD)) {
1355 printk(KERN_DEBUG "%s: assuming no Primary image in "
1356 "flash - card initialization not completed\n",
1357 dev_info);
1358 local->no_pri = 1;
1359#ifdef PRISM2_DOWNLOAD_SUPPORT
1360 if (local->sram_type == -1)
1361 local->sram_type = prism2_get_ram_size(local);
1362#endif /* PRISM2_DOWNLOAD_SUPPORT */
1363 return 1;
1364 }
1365 local->no_pri = 0;
1366 printk(KERN_DEBUG "prism2_hw_init: initialized in %lu ms\n",
1367 (jiffies - start) * 1000 / HZ);
1368 HFA384X_OUTW(HFA384X_EV_CMD, HFA384X_EVACK_OFF);
1369 return 0;
1370}
1371
1372
1373static int prism2_hw_init2(struct net_device *dev, int initial)
1374{
1375 struct hostap_interface *iface;
1376 local_info_t *local;
1377 int i;
1378
1379 iface = netdev_priv(dev);
1380 local = iface->local;
1381
1382#ifdef PRISM2_DOWNLOAD_SUPPORT
1383 kfree(local->pda);
1384 if (local->no_pri)
1385 local->pda = NULL;
1386 else
1387 local->pda = prism2_read_pda(dev);
1388#endif /* PRISM2_DOWNLOAD_SUPPORT */
1389
1390 hfa384x_disable_interrupts(dev);
1391
1392#ifndef final_version
1393 HFA384X_OUTW(HFA384X_MAGIC, HFA384X_SWSUPPORT0_OFF);
1394 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
1395 printk("SWSUPPORT0 write/read failed: %04X != %04X\n",
1396 HFA384X_INW(HFA384X_SWSUPPORT0_OFF), HFA384X_MAGIC);
1397 goto failed;
1398 }
1399#endif
1400
1401 if (initial || local->pri_only) {
1402 hfa384x_events_only_cmd(dev);
1403 /* get card version information */
1404 if (prism2_get_version_info(dev, HFA384X_RID_NICID, "NIC") ||
1405 prism2_get_version_info(dev, HFA384X_RID_PRIID, "PRI")) {
1406 hfa384x_disable_interrupts(dev);
1407 goto failed;
1408 }
1409
1410 if (prism2_get_version_info(dev, HFA384X_RID_STAID, "STA")) {
1411 printk(KERN_DEBUG "%s: Failed to read STA f/w version "
1412 "- only Primary f/w present\n", dev->name);
1413 local->pri_only = 1;
1414 return 0;
1415 }
1416 local->pri_only = 0;
1417 hfa384x_disable_interrupts(dev);
1418 }
1419
1420 /* FIX: could convert allocate_fid to use sleeping CmdCompl wait and
1421 * enable interrupts before this. This would also require some sort of
1422 * sleeping AllocEv waiting */
1423
1424 /* allocate TX FIDs */
1425 local->txfid_len = PRISM2_TXFID_LEN;
1426 for (i = 0; i < PRISM2_TXFID_COUNT; i++) {
1427 local->txfid[i] = hfa384x_allocate_fid(dev, local->txfid_len);
1428 if (local->txfid[i] == 0xffff && local->txfid_len > 1600) {
1429 local->txfid[i] = hfa384x_allocate_fid(dev, 1600);
1430 if (local->txfid[i] != 0xffff) {
1431 printk(KERN_DEBUG "%s: Using shorter TX FID "
1432 "(1600 bytes)\n", dev->name);
1433 local->txfid_len = 1600;
1434 }
1435 }
1436 if (local->txfid[i] == 0xffff)
1437 goto failed;
1438 local->intransmitfid[i] = PRISM2_TXFID_EMPTY;
1439 }
1440
1441 hfa384x_events_only_cmd(dev);
1442
1443 if (initial) {
1444 struct list_head *ptr;
1445 prism2_check_sta_fw_version(local);
1446
1447 if (hfa384x_get_rid(dev, HFA384X_RID_CNFOWNMACADDR,
1448 &dev->dev_addr, 6, 1) < 0) {
1449 printk("%s: could not get own MAC address\n",
1450 dev->name);
1451 }
1452 list_for_each(ptr, &local->hostap_interfaces) {
1453 iface = list_entry(ptr, struct hostap_interface, list);
1454 memcpy(iface->dev->dev_addr, dev->dev_addr, ETH_ALEN);
1455 }
1456 } else if (local->fw_ap)
1457 prism2_check_sta_fw_version(local);
1458
1459 prism2_setup_rids(dev);
1460
1461 /* MAC is now configured, but port 0 is not yet enabled */
1462 return 0;
1463
1464 failed:
1465 if (!local->no_pri)
1466 printk(KERN_WARNING "%s: Initialization failed\n", dev_info);
1467 return 1;
1468}
1469
1470
1471static int prism2_hw_enable(struct net_device *dev, int initial)
1472{
1473 struct hostap_interface *iface;
1474 local_info_t *local;
1475 int was_resetting;
1476
1477 iface = netdev_priv(dev);
1478 local = iface->local;
1479 was_resetting = local->hw_resetting;
1480
1481 if (hfa384x_cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL, NULL)) {
1482 printk("%s: MAC port 0 enabling failed\n", dev->name);
1483 return 1;
1484 }
1485
1486 local->hw_ready = 1;
1487 local->hw_reset_tries = 0;
1488 local->hw_resetting = 0;
1489 hfa384x_enable_interrupts(dev);
1490
1491 /* at least D-Link DWL-650 seems to require additional port reset
1492 * before it starts acting as an AP, so reset port automatically
1493 * here just in case */
1494 if (initial && prism2_reset_port(dev)) {
1495 printk("%s: MAC port 0 reseting failed\n", dev->name);
1496 return 1;
1497 }
1498
1499 if (was_resetting && netif_queue_stopped(dev)) {
1500 /* If hw_reset() was called during pending transmit, netif
1501 * queue was stopped. Wake it up now since the wlan card has
1502 * been resetted. */
1503 netif_wake_queue(dev);
1504 }
1505
1506 return 0;
1507}
1508
1509
1510static int prism2_hw_config(struct net_device *dev, int initial)
1511{
1512 struct hostap_interface *iface;
1513 local_info_t *local;
1514
1515 iface = netdev_priv(dev);
1516 local = iface->local;
1517
1518 if (local->hw_downloading)
1519 return 1;
1520
1521 if (prism2_hw_init(dev, initial)) {
1522 return local->no_pri ? 0 : 1;
1523 }
1524
1525 if (prism2_hw_init2(dev, initial))
1526 return 1;
1527
1528 /* Enable firmware if secondary image is loaded and at least one of the
1529 * netdevices is up. */
1530 if (!local->pri_only &&
1531 (initial == 0 || (initial == 2 && local->num_dev_open > 0))) {
1532 if (!local->dev_enabled)
1533 prism2_callback(local, PRISM2_CALLBACK_ENABLE);
1534 local->dev_enabled = 1;
1535 return prism2_hw_enable(dev, initial);
1536 }
1537
1538 return 0;
1539}
1540
1541
1542static void prism2_hw_shutdown(struct net_device *dev, int no_disable)
1543{
1544 struct hostap_interface *iface;
1545 local_info_t *local;
1546
1547 iface = netdev_priv(dev);
1548 local = iface->local;
1549
1550 /* Allow only command completion events during disable */
1551 hfa384x_events_only_cmd(dev);
1552
1553 local->hw_ready = 0;
1554 if (local->dev_enabled)
1555 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
1556 local->dev_enabled = 0;
1557
1558 if (local->func->card_present && !local->func->card_present(local)) {
1559 printk(KERN_DEBUG "%s: card already removed or not configured "
1560 "during shutdown\n", dev->name);
1561 return;
1562 }
1563
1564 if ((no_disable & HOSTAP_HW_NO_DISABLE) == 0 &&
1565 hfa384x_cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL, NULL))
1566 printk(KERN_WARNING "%s: Shutdown failed\n", dev_info);
1567
1568 hfa384x_disable_interrupts(dev);
1569
1570 if (no_disable & HOSTAP_HW_ENABLE_CMDCOMPL)
1571 hfa384x_events_only_cmd(dev);
1572 else
1573 prism2_clear_cmd_queue(local);
1574}
1575
1576
1577static void prism2_hw_reset(struct net_device *dev)
1578{
1579 struct hostap_interface *iface;
1580 local_info_t *local;
1581
1582#if 0
1583 static long last_reset = 0;
1584
1585 /* do not reset card more than once per second to avoid ending up in a
1586 * busy loop reseting the card */
1587 if (time_before_eq(jiffies, last_reset + HZ))
1588 return;
1589 last_reset = jiffies;
1590#endif
1591
1592 iface = netdev_priv(dev);
1593 local = iface->local;
1594
1595 if (in_interrupt()) {
1596 printk(KERN_DEBUG "%s: driver bug - prism2_hw_reset() called "
1597 "in interrupt context\n", dev->name);
1598 return;
1599 }
1600
1601 if (local->hw_downloading)
1602 return;
1603
1604 if (local->hw_resetting) {
1605 printk(KERN_WARNING "%s: %s: already resetting card - "
1606 "ignoring reset request\n", dev_info, dev->name);
1607 return;
1608 }
1609
1610 local->hw_reset_tries++;
1611 if (local->hw_reset_tries > 10) {
1612 printk(KERN_WARNING "%s: too many reset tries, skipping\n",
1613 dev->name);
1614 return;
1615 }
1616
1617 printk(KERN_WARNING "%s: %s: resetting card\n", dev_info, dev->name);
1618 hfa384x_disable_interrupts(dev);
1619 local->hw_resetting = 1;
1620 if (local->func->cor_sreset) {
1621 /* Host system seems to hang in some cases with high traffic
1622 * load or shared interrupts during COR sreset. Disable shared
1623 * interrupts during reset to avoid these crashes. COS sreset
1624 * takes quite a long time, so it is unfortunate that this
1625 * seems to be needed. Anyway, I do not know of any better way
1626 * of avoiding the crash. */
1627 disable_irq(dev->irq);
1628 local->func->cor_sreset(local);
1629 enable_irq(dev->irq);
1630 }
1631 prism2_hw_shutdown(dev, 1);
1632 prism2_hw_config(dev, 0);
1633 local->hw_resetting = 0;
1634
1635#ifdef PRISM2_DOWNLOAD_SUPPORT
1636 if (local->dl_pri) {
1637 printk(KERN_DEBUG "%s: persistent download of primary "
1638 "firmware\n", dev->name);
1639 if (prism2_download_genesis(local, local->dl_pri) < 0)
1640 printk(KERN_WARNING "%s: download (PRI) failed\n",
1641 dev->name);
1642 }
1643
1644 if (local->dl_sec) {
1645 printk(KERN_DEBUG "%s: persistent download of secondary "
1646 "firmware\n", dev->name);
1647 if (prism2_download_volatile(local, local->dl_sec) < 0)
1648 printk(KERN_WARNING "%s: download (SEC) failed\n",
1649 dev->name);
1650 }
1651#endif /* PRISM2_DOWNLOAD_SUPPORT */
1652
1653 /* TODO: restore beacon TIM bits for STAs that have buffered frames */
1654}
1655
1656
1657static void prism2_schedule_reset(local_info_t *local)
1658{
1659 schedule_work(&local->reset_queue);
1660}
1661
1662
1663/* Called only as scheduled task after noticing card timeout in interrupt
1664 * context */
1665static void handle_reset_queue(void *data)
1666{
1667 local_info_t *local = (local_info_t *) data;
1668
1669 printk(KERN_DEBUG "%s: scheduled card reset\n", local->dev->name);
1670 prism2_hw_reset(local->dev);
1671
1672 if (netif_queue_stopped(local->dev)) {
1673 int i;
1674
1675 for (i = 0; i < PRISM2_TXFID_COUNT; i++)
1676 if (local->intransmitfid[i] == PRISM2_TXFID_EMPTY) {
1677 PDEBUG(DEBUG_EXTRA, "prism2_tx_timeout: "
1678 "wake up queue\n");
1679 netif_wake_queue(local->dev);
1680 break;
1681 }
1682 }
1683}
1684
1685
1686static int prism2_get_txfid_idx(local_info_t *local)
1687{
1688 int idx, end;
1689 unsigned long flags;
1690
1691 spin_lock_irqsave(&local->txfidlock, flags);
1692 end = idx = local->next_txfid;
1693 do {
1694 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
1695 local->intransmitfid[idx] = PRISM2_TXFID_RESERVED;
1696 spin_unlock_irqrestore(&local->txfidlock, flags);
1697 return idx;
1698 }
1699 idx++;
1700 if (idx >= PRISM2_TXFID_COUNT)
1701 idx = 0;
1702 } while (idx != end);
1703 spin_unlock_irqrestore(&local->txfidlock, flags);
1704
1705 PDEBUG(DEBUG_EXTRA2, "prism2_get_txfid_idx: no room in txfid buf: "
1706 "packet dropped\n");
1707 local->stats.tx_dropped++;
1708
1709 return -1;
1710}
1711
1712
1713/* Called only from hardware IRQ */
1714static void prism2_transmit_cb(struct net_device *dev, long context,
1715 u16 resp0, u16 res)
1716{
1717 struct hostap_interface *iface;
1718 local_info_t *local;
1719 int idx = (int) context;
1720
1721 iface = netdev_priv(dev);
1722 local = iface->local;
1723
1724 if (res) {
1725 printk(KERN_DEBUG "%s: prism2_transmit_cb - res=0x%02x\n",
1726 dev->name, res);
1727 return;
1728 }
1729
1730 if (idx < 0 || idx >= PRISM2_TXFID_COUNT) {
1731 printk(KERN_DEBUG "%s: prism2_transmit_cb called with invalid "
1732 "idx=%d\n", dev->name, idx);
1733 return;
1734 }
1735
1736 if (!test_and_clear_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
1737 printk(KERN_DEBUG "%s: driver bug: prism2_transmit_cb called "
1738 "with no pending transmit\n", dev->name);
1739 }
1740
1741 if (netif_queue_stopped(dev)) {
1742 /* ready for next TX, so wake up queue that was stopped in
1743 * prism2_transmit() */
1744 netif_wake_queue(dev);
1745 }
1746
1747 spin_lock(&local->txfidlock);
1748
1749 /* With reclaim, Resp0 contains new txfid for transmit; the old txfid
1750 * will be automatically allocated for the next TX frame */
1751 local->intransmitfid[idx] = resp0;
1752
1753 PDEBUG(DEBUG_FID, "%s: prism2_transmit_cb: txfid[%d]=0x%04x, "
1754 "resp0=0x%04x, transmit_txfid=0x%04x\n",
1755 dev->name, idx, local->txfid[idx],
1756 resp0, local->intransmitfid[local->next_txfid]);
1757
1758 idx++;
1759 if (idx >= PRISM2_TXFID_COUNT)
1760 idx = 0;
1761 local->next_txfid = idx;
1762
1763 /* check if all TX buffers are occupied */
1764 do {
1765 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY) {
1766 spin_unlock(&local->txfidlock);
1767 return;
1768 }
1769 idx++;
1770 if (idx >= PRISM2_TXFID_COUNT)
1771 idx = 0;
1772 } while (idx != local->next_txfid);
1773 spin_unlock(&local->txfidlock);
1774
1775 /* no empty TX buffers, stop queue */
1776 netif_stop_queue(dev);
1777}
1778
1779
1780/* Called only from software IRQ if PCI bus master is not used (with bus master
1781 * this can be called both from software and hardware IRQ) */
1782static int prism2_transmit(struct net_device *dev, int idx)
1783{
1784 struct hostap_interface *iface;
1785 local_info_t *local;
1786 int res;
1787
1788 iface = netdev_priv(dev);
1789 local = iface->local;
1790
1791 /* The driver tries to stop netif queue so that there would not be
1792 * more than one attempt to transmit frames going on; check that this
1793 * is really the case */
1794
1795 if (test_and_set_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
1796 printk(KERN_DEBUG "%s: driver bug - prism2_transmit() called "
1797 "when previous TX was pending\n", dev->name);
1798 return -1;
1799 }
1800
1801 /* stop the queue for the time that transmit is pending */
1802 netif_stop_queue(dev);
1803
1804 /* transmit packet */
1805 res = hfa384x_cmd_callback(
1806 dev,
1807 HFA384X_CMDCODE_TRANSMIT | HFA384X_CMD_TX_RECLAIM,
1808 local->txfid[idx],
1809 prism2_transmit_cb, (long) idx);
1810
1811 if (res) {
1812 struct net_device_stats *stats;
1813 printk(KERN_DEBUG "%s: prism2_transmit: CMDCODE_TRANSMIT "
1814 "failed (res=%d)\n", dev->name, res);
1815 stats = hostap_get_stats(dev);
1816 stats->tx_dropped++;
1817 netif_wake_queue(dev);
1818 return -1;
1819 }
1820 dev->trans_start = jiffies;
1821
1822 /* Since we did not wait for command completion, the card continues
1823 * to process on the background and we will finish handling when
1824 * command completion event is handled (prism2_cmd_ev() function) */
1825
1826 return 0;
1827}
1828
1829
1830#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
1831/* Called only from hardware IRQ */
1832static void prism2_tx_cb(struct net_device *dev, void *context,
1833 u16 resp0, u16 res)
1834{
1835 struct hostap_interface *iface;
1836 local_info_t *local;
1837 unsigned long addr;
1838 int buf_len = (int) context;
1839
1840 iface = netdev_priv(dev);
1841 local = iface->local;
1842
1843 if (res) {
1844 printk(KERN_DEBUG "%s: prism2_tx_cb - res=0x%02x\n",
1845 dev->name, res);
1846 return;
1847 }
1848
1849 addr = virt_to_phys(local->bus_m0_buf);
1850 HFA384X_OUTW((addr & 0xffff0000) >> 16, HFA384X_PCI_M0_ADDRH_OFF);
1851 HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF);
1852 HFA384X_OUTW(buf_len / 2, HFA384X_PCI_M0_LEN_OFF);
1853 HFA384X_OUTW(HFA384X_PCI_CTL_TO_BAP, HFA384X_PCI_M0_CTL_OFF);
1854}
1855#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
1856
1857
1858/* Send IEEE 802.11 frame (convert the header into Prism2 TX descriptor and
1859 * send the payload with this descriptor) */
1860/* Called only from software IRQ */
1861static int prism2_tx_80211(struct sk_buff *skb, struct net_device *dev)
1862{
1863 struct hostap_interface *iface;
1864 local_info_t *local;
1865 struct hfa384x_tx_frame txdesc;
1866 struct hostap_ieee80211_hdr *hdr;
1867 struct hostap_skb_tx_data *meta;
1868 int hdr_len, data_len, idx, res, ret = -1;
1869 u16 tx_control, fc;
1870
1871 iface = netdev_priv(dev);
1872 local = iface->local;
1873
1874 meta = (struct hostap_skb_tx_data *) skb->cb;
1875 hdr = (struct hostap_ieee80211_hdr *) skb->data;
1876
1877 prism2_callback(local, PRISM2_CALLBACK_TX_START);
1878
1879 if ((local->func->card_present && !local->func->card_present(local)) ||
1880 !local->hw_ready || local->hw_downloading || local->pri_only) {
1881 if (net_ratelimit()) {
1882 printk(KERN_DEBUG "%s: prism2_tx_80211: hw not ready -"
1883 " skipping\n", dev->name);
1884 }
1885 goto fail;
1886 }
1887
1888 memset(&txdesc, 0, sizeof(txdesc));
1889
1890 /* skb->data starts with txdesc->frame_control */
1891 hdr_len = 24;
1892 memcpy(&txdesc.frame_control, skb->data, hdr_len);
1893 fc = le16_to_cpu(txdesc.frame_control);
1894 if (HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA &&
1895 (fc & WLAN_FC_FROMDS) && (fc & WLAN_FC_TODS) && skb->len >= 30) {
1896 /* Addr4 */
1897 memcpy(txdesc.addr4, skb->data + hdr_len, ETH_ALEN);
1898 hdr_len += ETH_ALEN;
1899 }
1900
1901 tx_control = local->tx_control;
1902 if (meta->tx_cb_idx) {
1903 tx_control |= HFA384X_TX_CTRL_TX_OK;
1904 txdesc.sw_support = cpu_to_le16(meta->tx_cb_idx);
1905 }
1906 txdesc.tx_control = cpu_to_le16(tx_control);
1907 txdesc.tx_rate = meta->rate;
1908
1909 data_len = skb->len - hdr_len;
1910 txdesc.data_len = cpu_to_le16(data_len);
1911 txdesc.len = cpu_to_be16(data_len);
1912
1913 idx = prism2_get_txfid_idx(local);
1914 if (idx < 0)
1915 goto fail;
1916
1917 if (local->frame_dump & PRISM2_DUMP_TX_HDR)
1918 hostap_dump_tx_header(dev->name, &txdesc);
1919
1920 spin_lock(&local->baplock);
1921 res = hfa384x_setup_bap(dev, BAP0, local->txfid[idx], 0);
1922
1923#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
1924 if (!res && skb->len >= local->bus_master_threshold_tx) {
1925 u8 *pos;
1926 int buf_len;
1927
1928 local->bus_m0_tx_idx = idx;
1929
1930 /* FIX: BAP0 should be locked during bus master transfer, but
1931 * baplock with BH's disabled is not OK for this; netif queue
1932 * stopping is not enough since BAP0 is used also for RID
1933 * read/write */
1934
1935 /* stop the queue for the time that bus mastering on BAP0 is
1936 * in use */
1937 netif_stop_queue(dev);
1938
1939 spin_unlock(&local->baplock);
1940
1941 /* Copy frame data to bus_m0_buf */
1942 pos = local->bus_m0_buf;
1943 memcpy(pos, &txdesc, sizeof(txdesc));
1944 pos += sizeof(txdesc);
1945 memcpy(pos, skb->data + hdr_len, skb->len - hdr_len);
1946 pos += skb->len - hdr_len;
1947 buf_len = pos - local->bus_m0_buf;
1948 if (buf_len & 1)
1949 buf_len++;
1950
1951#ifdef PRISM2_ENABLE_BEFORE_TX_BUS_MASTER
1952 /* Any RX packet seems to break something with TX bus
1953 * mastering; enable command is enough to fix this.. */
1954 if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_ENABLE, 0,
1955 prism2_tx_cb, (long) buf_len)) {
1956 printk(KERN_DEBUG "%s: TX: enable port0 failed\n",
1957 dev->name);
1958 }
1959#else /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */
1960 prism2_tx_cb(dev, (void *) buf_len, 0, 0);
1961#endif /* PRISM2_ENABLE_BEFORE_TX_BUS_MASTER */
1962
1963 /* Bus master transfer will be started from command completion
1964 * event handler and TX handling will be finished by calling
1965 * prism2_transmit() from bus master event handler */
1966 goto tx_stats;
1967 }
1968#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
1969
1970 if (!res)
1971 res = hfa384x_to_bap(dev, BAP0, &txdesc, sizeof(txdesc));
1972 if (!res)
1973 res = hfa384x_to_bap(dev, BAP0, skb->data + hdr_len,
1974 skb->len - hdr_len);
1975 spin_unlock(&local->baplock);
1976
1977 if (!res)
1978 res = prism2_transmit(dev, idx);
1979 if (res) {
1980 printk(KERN_DEBUG "%s: prism2_tx_80211 - to BAP0 failed\n",
1981 dev->name);
1982 local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
1983 schedule_work(&local->reset_queue);
1984 goto fail;
1985 }
1986
1987 ret = 0;
1988
1989fail:
1990 prism2_callback(local, PRISM2_CALLBACK_TX_END);
1991 return ret;
1992}
1993
1994
1995/* Some SMP systems have reported number of odd errors with hostap_pci. fid
1996 * register has changed values between consecutive reads for an unknown reason.
1997 * This should really not happen, so more debugging is needed. This test
1998 * version is a big slower, but it will detect most of such register changes
1999 * and will try to get the correct fid eventually. */
2000#define EXTRA_FID_READ_TESTS
2001
2002static inline u16 prism2_read_fid_reg(struct net_device *dev, u16 reg)
2003{
2004#ifdef EXTRA_FID_READ_TESTS
2005 u16 val, val2, val3;
2006 int i;
2007
2008 for (i = 0; i < 10; i++) {
2009 val = HFA384X_INW(reg);
2010 val2 = HFA384X_INW(reg);
2011 val3 = HFA384X_INW(reg);
2012
2013 if (val == val2 && val == val3)
2014 return val;
2015
2016 printk(KERN_DEBUG "%s: detected fid change (try=%d, reg=%04x):"
2017 " %04x %04x %04x\n",
2018 dev->name, i, reg, val, val2, val3);
2019 if ((val == val2 || val == val3) && val != 0)
2020 return val;
2021 if (val2 == val3 && val2 != 0)
2022 return val2;
2023 }
2024 printk(KERN_WARNING "%s: Uhhuh.. could not read good fid from reg "
2025 "%04x (%04x %04x %04x)\n", dev->name, reg, val, val2, val3);
2026 return val;
2027#else /* EXTRA_FID_READ_TESTS */
2028 return HFA384X_INW(reg);
2029#endif /* EXTRA_FID_READ_TESTS */
2030}
2031
2032
2033/* Called only as a tasklet (software IRQ) */
2034static void prism2_rx(local_info_t *local)
2035{
2036 struct net_device *dev = local->dev;
2037 int res, rx_pending = 0;
2038 u16 len, hdr_len, rxfid, status, macport;
2039 struct net_device_stats *stats;
2040 struct hfa384x_rx_frame rxdesc;
2041 struct sk_buff *skb = NULL;
2042
2043 prism2_callback(local, PRISM2_CALLBACK_RX_START);
2044 stats = hostap_get_stats(dev);
2045
2046 rxfid = prism2_read_fid_reg(dev, HFA384X_RXFID_OFF);
2047#ifndef final_version
2048 if (rxfid == 0) {
2049 rxfid = HFA384X_INW(HFA384X_RXFID_OFF);
2050 printk(KERN_DEBUG "prism2_rx: rxfid=0 (next 0x%04x)\n",
2051 rxfid);
2052 if (rxfid == 0) {
2053 schedule_work(&local->reset_queue);
2054 goto rx_dropped;
2055 }
2056 /* try to continue with the new rxfid value */
2057 }
2058#endif
2059
2060 spin_lock(&local->baplock);
2061 res = hfa384x_setup_bap(dev, BAP0, rxfid, 0);
2062 if (!res)
2063 res = hfa384x_from_bap(dev, BAP0, &rxdesc, sizeof(rxdesc));
2064
2065 if (res) {
2066 spin_unlock(&local->baplock);
2067 printk(KERN_DEBUG "%s: copy from BAP0 failed %d\n", dev->name,
2068 res);
2069 if (res == -ETIMEDOUT) {
2070 schedule_work(&local->reset_queue);
2071 }
2072 goto rx_dropped;
2073 }
2074
2075 len = le16_to_cpu(rxdesc.data_len);
2076 hdr_len = sizeof(rxdesc);
2077 status = le16_to_cpu(rxdesc.status);
2078 macport = (status >> 8) & 0x07;
2079
2080 /* Drop frames with too large reported payload length. Monitor mode
2081 * seems to sometimes pass frames (e.g., ctrl::ack) with signed and
2082 * negative value, so allow also values 65522 .. 65534 (-14 .. -2) for
2083 * macport 7 */
2084 if (len > PRISM2_DATA_MAXLEN + 8 /* WEP */) {
2085 if (macport == 7 && local->iw_mode == IW_MODE_MONITOR) {
2086 if (len >= (u16) -14) {
2087 hdr_len -= 65535 - len;
2088 hdr_len--;
2089 }
2090 len = 0;
2091 } else {
2092 spin_unlock(&local->baplock);
2093 printk(KERN_DEBUG "%s: Received frame with invalid "
2094 "length 0x%04x\n", dev->name, len);
2095 hostap_dump_rx_header(dev->name, &rxdesc);
2096 goto rx_dropped;
2097 }
2098 }
2099
2100 skb = dev_alloc_skb(len + hdr_len);
2101 if (!skb) {
2102 spin_unlock(&local->baplock);
2103 printk(KERN_DEBUG "%s: RX failed to allocate skb\n",
2104 dev->name);
2105 goto rx_dropped;
2106 }
2107 skb->dev = dev;
2108 memcpy(skb_put(skb, hdr_len), &rxdesc, hdr_len);
2109
2110#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
2111 if (len >= local->bus_master_threshold_rx) {
2112 unsigned long addr;
2113
2114 hfa384x_events_no_bap1(dev);
2115
2116 local->rx_skb = skb;
2117 /* Internal BAP0 offset points to the byte following rxdesc;
2118 * copy rest of the data using bus master */
2119 addr = virt_to_phys(skb_put(skb, len));
2120 HFA384X_OUTW((addr & 0xffff0000) >> 16,
2121 HFA384X_PCI_M0_ADDRH_OFF);
2122 HFA384X_OUTW(addr & 0x0000ffff, HFA384X_PCI_M0_ADDRL_OFF);
2123 if (len & 1)
2124 len++;
2125 HFA384X_OUTW(len / 2, HFA384X_PCI_M0_LEN_OFF);
2126 HFA384X_OUTW(HFA384X_PCI_CTL_FROM_BAP, HFA384X_PCI_M0_CTL_OFF);
2127
2128 /* pci_bus_m1 event will be generated when data transfer is
2129 * complete and the frame will then be added to rx_list and
2130 * rx_tasklet is scheduled */
2131 rx_pending = 1;
2132
2133 /* Have to release baplock before returning, although BAP0
2134 * should really not be used before DMA transfer has been
2135 * completed. */
2136 spin_unlock(&local->baplock);
2137 } else
2138#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
2139 {
2140 if (len > 0)
2141 res = hfa384x_from_bap(dev, BAP0, skb_put(skb, len),
2142 len);
2143 spin_unlock(&local->baplock);
2144 if (res) {
2145 printk(KERN_DEBUG "%s: RX failed to read "
2146 "frame data\n", dev->name);
2147 goto rx_dropped;
2148 }
2149
2150 skb_queue_tail(&local->rx_list, skb);
2151 tasklet_schedule(&local->rx_tasklet);
2152 }
2153
2154 rx_exit:
2155 prism2_callback(local, PRISM2_CALLBACK_RX_END);
2156 if (!rx_pending) {
2157 HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
2158 }
2159
2160 return;
2161
2162 rx_dropped:
2163 stats->rx_dropped++;
2164 if (skb)
2165 dev_kfree_skb(skb);
2166 goto rx_exit;
2167}
2168
2169
2170/* Called only as a tasklet (software IRQ) */
2171static void hostap_rx_skb(local_info_t *local, struct sk_buff *skb)
2172{
2173 struct hfa384x_rx_frame *rxdesc;
2174 struct net_device *dev = skb->dev;
2175 struct hostap_80211_rx_status stats;
2176 int hdrlen, rx_hdrlen;
2177
2178 rx_hdrlen = sizeof(*rxdesc);
2179 if (skb->len < sizeof(*rxdesc)) {
2180 /* Allow monitor mode to receive shorter frames */
2181 if (local->iw_mode == IW_MODE_MONITOR &&
2182 skb->len >= sizeof(*rxdesc) - 30) {
2183 rx_hdrlen = skb->len;
2184 } else {
2185 dev_kfree_skb(skb);
2186 return;
2187 }
2188 }
2189
2190 rxdesc = (struct hfa384x_rx_frame *) skb->data;
2191
2192 if (local->frame_dump & PRISM2_DUMP_RX_HDR &&
2193 skb->len >= sizeof(*rxdesc))
2194 hostap_dump_rx_header(dev->name, rxdesc);
2195
2196 if (le16_to_cpu(rxdesc->status) & HFA384X_RX_STATUS_FCSERR &&
2197 (!local->monitor_allow_fcserr ||
2198 local->iw_mode != IW_MODE_MONITOR))
2199 goto drop;
2200
2201 if (skb->len > PRISM2_DATA_MAXLEN) {
2202 printk(KERN_DEBUG "%s: RX: len(%d) > MAX(%d)\n",
2203 dev->name, skb->len, PRISM2_DATA_MAXLEN);
2204 goto drop;
2205 }
2206
2207 stats.mac_time = le32_to_cpu(rxdesc->time);
2208 stats.signal = rxdesc->signal - local->rssi_to_dBm;
2209 stats.noise = rxdesc->silence - local->rssi_to_dBm;
2210 stats.rate = rxdesc->rate;
2211
2212 /* Convert Prism2 RX structure into IEEE 802.11 header */
2213 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(rxdesc->frame_control));
2214 if (hdrlen > rx_hdrlen)
2215 hdrlen = rx_hdrlen;
2216
2217 memmove(skb_pull(skb, rx_hdrlen - hdrlen),
2218 &rxdesc->frame_control, hdrlen);
2219
2220 hostap_80211_rx(dev, skb, &stats);
2221 return;
2222
2223 drop:
2224 dev_kfree_skb(skb);
2225}
2226
2227
2228/* Called only as a tasklet (software IRQ) */
2229static void hostap_rx_tasklet(unsigned long data)
2230{
2231 local_info_t *local = (local_info_t *) data;
2232 struct sk_buff *skb;
2233
2234 while ((skb = skb_dequeue(&local->rx_list)) != NULL)
2235 hostap_rx_skb(local, skb);
2236}
2237
2238
2239/* Called only from hardware IRQ */
2240static void prism2_alloc_ev(struct net_device *dev)
2241{
2242 struct hostap_interface *iface;
2243 local_info_t *local;
2244 int idx;
2245 u16 fid;
2246
2247 iface = netdev_priv(dev);
2248 local = iface->local;
2249
2250 fid = prism2_read_fid_reg(dev, HFA384X_ALLOCFID_OFF);
2251
2252 PDEBUG(DEBUG_FID, "FID: interrupt: ALLOC - fid=0x%04x\n", fid);
2253
2254 spin_lock(&local->txfidlock);
2255 idx = local->next_alloc;
2256
2257 do {
2258 if (local->txfid[idx] == fid) {
2259 PDEBUG(DEBUG_FID, "FID: found matching txfid[%d]\n",
2260 idx);
2261
2262#ifndef final_version
2263 if (local->intransmitfid[idx] == PRISM2_TXFID_EMPTY)
2264 printk("Already released txfid found at idx "
2265 "%d\n", idx);
2266 if (local->intransmitfid[idx] == PRISM2_TXFID_RESERVED)
2267 printk("Already reserved txfid found at idx "
2268 "%d\n", idx);
2269#endif
2270 local->intransmitfid[idx] = PRISM2_TXFID_EMPTY;
2271 idx++;
2272 local->next_alloc = idx >= PRISM2_TXFID_COUNT ? 0 :
2273 idx;
2274
2275 if (!test_bit(HOSTAP_BITS_TRANSMIT, &local->bits) &&
2276 netif_queue_stopped(dev))
2277 netif_wake_queue(dev);
2278
2279 spin_unlock(&local->txfidlock);
2280 return;
2281 }
2282
2283 idx++;
2284 if (idx >= PRISM2_TXFID_COUNT)
2285 idx = 0;
2286 } while (idx != local->next_alloc);
2287
2288 printk(KERN_WARNING "%s: could not find matching txfid (0x%04x, new "
2289 "read 0x%04x) for alloc event\n", dev->name, fid,
2290 HFA384X_INW(HFA384X_ALLOCFID_OFF));
2291 printk(KERN_DEBUG "TXFIDs:");
2292 for (idx = 0; idx < PRISM2_TXFID_COUNT; idx++)
2293 printk(" %04x[%04x]", local->txfid[idx],
2294 local->intransmitfid[idx]);
2295 printk("\n");
2296 spin_unlock(&local->txfidlock);
2297
2298 /* FIX: should probably schedule reset; reference to one txfid was lost
2299 * completely.. Bad things will happen if we run out of txfids
2300 * Actually, this will cause netdev watchdog to notice TX timeout and
2301 * then card reset after all txfids have been leaked. */
2302}
2303
2304
2305/* Called only as a tasklet (software IRQ) */
2306static void hostap_tx_callback(local_info_t *local,
2307 struct hfa384x_tx_frame *txdesc, int ok,
2308 char *payload)
2309{
2310 u16 sw_support, hdrlen, len;
2311 struct sk_buff *skb;
2312 struct hostap_tx_callback_info *cb;
2313
2314 /* Make sure that frame was from us. */
2315 if (memcmp(txdesc->addr2, local->dev->dev_addr, ETH_ALEN)) {
2316 printk(KERN_DEBUG "%s: TX callback - foreign frame\n",
2317 local->dev->name);
2318 return;
2319 }
2320
2321 sw_support = le16_to_cpu(txdesc->sw_support);
2322
2323 spin_lock(&local->lock);
2324 cb = local->tx_callback;
2325 while (cb != NULL && cb->idx != sw_support)
2326 cb = cb->next;
2327 spin_unlock(&local->lock);
2328
2329 if (cb == NULL) {
2330 printk(KERN_DEBUG "%s: could not find TX callback (idx %d)\n",
2331 local->dev->name, sw_support);
2332 return;
2333 }
2334
2335 hdrlen = hostap_80211_get_hdrlen(le16_to_cpu(txdesc->frame_control));
2336 len = le16_to_cpu(txdesc->data_len);
2337 skb = dev_alloc_skb(hdrlen + len);
2338 if (skb == NULL) {
2339 printk(KERN_DEBUG "%s: hostap_tx_callback failed to allocate "
2340 "skb\n", local->dev->name);
2341 return;
2342 }
2343
2344 memcpy(skb_put(skb, hdrlen), (void *) &txdesc->frame_control, hdrlen);
2345 if (payload)
2346 memcpy(skb_put(skb, len), payload, len);
2347
2348 skb->dev = local->dev;
2349 skb->mac.raw = skb->data;
2350
2351 cb->func(skb, ok, cb->data);
2352}
2353
2354
2355/* Called only as a tasklet (software IRQ) */
2356static int hostap_tx_compl_read(local_info_t *local, int error,
2357 struct hfa384x_tx_frame *txdesc,
2358 char **payload)
2359{
2360 u16 fid, len;
2361 int res, ret = 0;
2362 struct net_device *dev = local->dev;
2363
2364 fid = prism2_read_fid_reg(dev, HFA384X_TXCOMPLFID_OFF);
2365
2366 PDEBUG(DEBUG_FID, "interrupt: TX (err=%d) - fid=0x%04x\n", fid, error);
2367
2368 spin_lock(&local->baplock);
2369 res = hfa384x_setup_bap(dev, BAP0, fid, 0);
2370 if (!res)
2371 res = hfa384x_from_bap(dev, BAP0, txdesc, sizeof(*txdesc));
2372 if (res) {
2373 PDEBUG(DEBUG_EXTRA, "%s: TX (err=%d) - fid=0x%04x - could not "
2374 "read txdesc\n", dev->name, error, fid);
2375 if (res == -ETIMEDOUT) {
2376 schedule_work(&local->reset_queue);
2377 }
2378 ret = -1;
2379 goto fail;
2380 }
2381 if (txdesc->sw_support) {
2382 len = le16_to_cpu(txdesc->data_len);
2383 if (len < PRISM2_DATA_MAXLEN) {
2384 *payload = (char *) kmalloc(len, GFP_ATOMIC);
2385 if (*payload == NULL ||
2386 hfa384x_from_bap(dev, BAP0, *payload, len)) {
2387 PDEBUG(DEBUG_EXTRA, "%s: could not read TX "
2388 "frame payload\n", dev->name);
2389 kfree(*payload);
2390 *payload = NULL;
2391 ret = -1;
2392 goto fail;
2393 }
2394 }
2395 }
2396
2397 fail:
2398 spin_unlock(&local->baplock);
2399
2400 return ret;
2401}
2402
2403
2404/* Called only as a tasklet (software IRQ) */
2405static void prism2_tx_ev(local_info_t *local)
2406{
2407 struct net_device *dev = local->dev;
2408 char *payload = NULL;
2409 struct hfa384x_tx_frame txdesc;
2410
2411 if (hostap_tx_compl_read(local, 0, &txdesc, &payload))
2412 goto fail;
2413
2414 if (local->frame_dump & PRISM2_DUMP_TX_HDR) {
2415 PDEBUG(DEBUG_EXTRA, "%s: TX - status=0x%04x "
2416 "retry_count=%d tx_rate=%d seq_ctrl=%d "
2417 "duration_id=%d\n",
2418 dev->name, le16_to_cpu(txdesc.status),
2419 txdesc.retry_count, txdesc.tx_rate,
2420 le16_to_cpu(txdesc.seq_ctrl),
2421 le16_to_cpu(txdesc.duration_id));
2422 }
2423
2424 if (txdesc.sw_support)
2425 hostap_tx_callback(local, &txdesc, 1, payload);
2426 kfree(payload);
2427
2428 fail:
2429 HFA384X_OUTW(HFA384X_EV_TX, HFA384X_EVACK_OFF);
2430}
2431
2432
2433/* Called only as a tasklet (software IRQ) */
2434static void hostap_sta_tx_exc_tasklet(unsigned long data)
2435{
2436 local_info_t *local = (local_info_t *) data;
2437 struct sk_buff *skb;
2438
2439 while ((skb = skb_dequeue(&local->sta_tx_exc_list)) != NULL) {
2440 struct hfa384x_tx_frame *txdesc =
2441 (struct hfa384x_tx_frame *) skb->data;
2442
2443 if (skb->len >= sizeof(*txdesc)) {
2444 /* Convert Prism2 RX structure into IEEE 802.11 header
2445 */
2446 u16 fc = le16_to_cpu(txdesc->frame_control);
2447 int hdrlen = hostap_80211_get_hdrlen(fc);
2448 memmove(skb_pull(skb, sizeof(*txdesc) - hdrlen),
2449 &txdesc->frame_control, hdrlen);
2450
2451 hostap_handle_sta_tx_exc(local, skb);
2452 }
2453 dev_kfree_skb(skb);
2454 }
2455}
2456
2457
2458/* Called only as a tasklet (software IRQ) */
2459static void prism2_txexc(local_info_t *local)
2460{
2461 struct net_device *dev = local->dev;
2462 u16 status, fc;
2463 int show_dump, res;
2464 char *payload = NULL;
2465 struct hfa384x_tx_frame txdesc;
2466
2467 show_dump = local->frame_dump & PRISM2_DUMP_TXEXC_HDR;
2468 local->stats.tx_errors++;
2469
2470 res = hostap_tx_compl_read(local, 1, &txdesc, &payload);
2471 HFA384X_OUTW(HFA384X_EV_TXEXC, HFA384X_EVACK_OFF);
2472 if (res)
2473 return;
2474
2475 status = le16_to_cpu(txdesc.status);
2476
2477 /* We produce a TXDROP event only for retry or lifetime
2478 * exceeded, because that's the only status that really mean
2479 * that this particular node went away.
2480 * Other errors means that *we* screwed up. - Jean II */
2481 if (status & (HFA384X_TX_STATUS_RETRYERR | HFA384X_TX_STATUS_AGEDERR))
2482 {
2483 union iwreq_data wrqu;
2484
2485 /* Copy 802.11 dest address. */
2486 memcpy(wrqu.addr.sa_data, txdesc.addr1, ETH_ALEN);
2487 wrqu.addr.sa_family = ARPHRD_ETHER;
2488 wireless_send_event(dev, IWEVTXDROP, &wrqu, NULL);
2489 } else
2490 show_dump = 1;
2491
2492 if (local->iw_mode == IW_MODE_MASTER ||
2493 local->iw_mode == IW_MODE_REPEAT ||
2494 local->wds_type & HOSTAP_WDS_AP_CLIENT) {
2495 struct sk_buff *skb;
2496 skb = dev_alloc_skb(sizeof(txdesc));
2497 if (skb) {
2498 memcpy(skb_put(skb, sizeof(txdesc)), &txdesc,
2499 sizeof(txdesc));
2500 skb_queue_tail(&local->sta_tx_exc_list, skb);
2501 tasklet_schedule(&local->sta_tx_exc_tasklet);
2502 }
2503 }
2504
2505 if (txdesc.sw_support)
2506 hostap_tx_callback(local, &txdesc, 0, payload);
2507 kfree(payload);
2508
2509 if (!show_dump)
2510 return;
2511
2512 PDEBUG(DEBUG_EXTRA, "%s: TXEXC - status=0x%04x (%s%s%s%s)"
2513 " tx_control=%04x\n",
2514 dev->name, status,
2515 status & HFA384X_TX_STATUS_RETRYERR ? "[RetryErr]" : "",
2516 status & HFA384X_TX_STATUS_AGEDERR ? "[AgedErr]" : "",
2517 status & HFA384X_TX_STATUS_DISCON ? "[Discon]" : "",
2518 status & HFA384X_TX_STATUS_FORMERR ? "[FormErr]" : "",
2519 le16_to_cpu(txdesc.tx_control));
2520
2521 fc = le16_to_cpu(txdesc.frame_control);
2522 PDEBUG(DEBUG_EXTRA, " retry_count=%d tx_rate=%d fc=0x%04x "
2523 "(%s%s%s::%d%s%s)\n",
2524 txdesc.retry_count, txdesc.tx_rate, fc,
2525 HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT ? "Mgmt" : "",
2526 HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_CTRL ? "Ctrl" : "",
2527 HOSTAP_FC_GET_TYPE(fc) == WLAN_FC_TYPE_DATA ? "Data" : "",
2528 HOSTAP_FC_GET_STYPE(fc),
2529 fc & WLAN_FC_TODS ? " ToDS" : "",
2530 fc & WLAN_FC_FROMDS ? " FromDS" : "");
2531 PDEBUG(DEBUG_EXTRA, " A1=" MACSTR " A2=" MACSTR " A3="
2532 MACSTR " A4=" MACSTR "\n",
2533 MAC2STR(txdesc.addr1), MAC2STR(txdesc.addr2),
2534 MAC2STR(txdesc.addr3), MAC2STR(txdesc.addr4));
2535}
2536
2537
2538/* Called only as a tasklet (software IRQ) */
2539static void hostap_info_tasklet(unsigned long data)
2540{
2541 local_info_t *local = (local_info_t *) data;
2542 struct sk_buff *skb;
2543
2544 while ((skb = skb_dequeue(&local->info_list)) != NULL) {
2545 hostap_info_process(local, skb);
2546 dev_kfree_skb(skb);
2547 }
2548}
2549
2550
2551/* Called only as a tasklet (software IRQ) */
2552static void prism2_info(local_info_t *local)
2553{
2554 struct net_device *dev = local->dev;
2555 u16 fid;
2556 int res, left;
2557 struct hfa384x_info_frame info;
2558 struct sk_buff *skb;
2559
2560 fid = HFA384X_INW(HFA384X_INFOFID_OFF);
2561
2562 spin_lock(&local->baplock);
2563 res = hfa384x_setup_bap(dev, BAP0, fid, 0);
2564 if (!res)
2565 res = hfa384x_from_bap(dev, BAP0, &info, sizeof(info));
2566 if (res) {
2567 spin_unlock(&local->baplock);
2568 printk(KERN_DEBUG "Could not get info frame (fid=0x%04x)\n",
2569 fid);
2570 if (res == -ETIMEDOUT) {
2571 schedule_work(&local->reset_queue);
2572 }
2573 goto out;
2574 }
2575
2576 le16_to_cpus(&info.len);
2577 le16_to_cpus(&info.type);
2578 left = (info.len - 1) * 2;
2579
2580 if (info.len & 0x8000 || info.len == 0 || left > 2060) {
2581 /* data register seems to give 0x8000 in some error cases even
2582 * though busy bit is not set in offset register;
2583 * in addition, length must be at least 1 due to type field */
2584 spin_unlock(&local->baplock);
2585 printk(KERN_DEBUG "%s: Received info frame with invalid "
2586 "length 0x%04x (type 0x%04x)\n", dev->name, info.len,
2587 info.type);
2588 goto out;
2589 }
2590
2591 skb = dev_alloc_skb(sizeof(info) + left);
2592 if (skb == NULL) {
2593 spin_unlock(&local->baplock);
2594 printk(KERN_DEBUG "%s: Could not allocate skb for info "
2595 "frame\n", dev->name);
2596 goto out;
2597 }
2598
2599 memcpy(skb_put(skb, sizeof(info)), &info, sizeof(info));
2600 if (left > 0 && hfa384x_from_bap(dev, BAP0, skb_put(skb, left), left))
2601 {
2602 spin_unlock(&local->baplock);
2603 printk(KERN_WARNING "%s: Info frame read failed (fid=0x%04x, "
2604 "len=0x%04x, type=0x%04x\n",
2605 dev->name, fid, info.len, info.type);
2606 dev_kfree_skb(skb);
2607 goto out;
2608 }
2609 spin_unlock(&local->baplock);
2610
2611 skb_queue_tail(&local->info_list, skb);
2612 tasklet_schedule(&local->info_tasklet);
2613
2614 out:
2615 HFA384X_OUTW(HFA384X_EV_INFO, HFA384X_EVACK_OFF);
2616}
2617
2618
2619/* Called only as a tasklet (software IRQ) */
2620static void hostap_bap_tasklet(unsigned long data)
2621{
2622 local_info_t *local = (local_info_t *) data;
2623 struct net_device *dev = local->dev;
2624 u16 ev;
2625 int frames = 30;
2626
2627 if (local->func->card_present && !local->func->card_present(local))
2628 return;
2629
2630 set_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
2631
2632 /* Process all pending BAP events without generating new interrupts
2633 * for them */
2634 while (frames-- > 0) {
2635 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
2636 if (ev == 0xffff || !(ev & HFA384X_BAP0_EVENTS))
2637 break;
2638 if (ev & HFA384X_EV_RX)
2639 prism2_rx(local);
2640 if (ev & HFA384X_EV_INFO)
2641 prism2_info(local);
2642 if (ev & HFA384X_EV_TX)
2643 prism2_tx_ev(local);
2644 if (ev & HFA384X_EV_TXEXC)
2645 prism2_txexc(local);
2646 }
2647
2648 set_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
2649 clear_bit(HOSTAP_BITS_BAP_TASKLET, &local->bits);
2650
2651 /* Enable interrupts for new BAP events */
2652 hfa384x_events_all(dev);
2653 clear_bit(HOSTAP_BITS_BAP_TASKLET2, &local->bits);
2654}
2655
2656
2657#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
2658/* Called only from hardware IRQ */
2659static void prism2_bus_master_ev(struct net_device *dev, int bap)
2660{
2661 struct hostap_interface *iface;
2662 local_info_t *local;
2663
2664 iface = netdev_priv(dev);
2665 local = iface->local;
2666
2667 if (bap == BAP1) {
2668 /* FIX: frame payload was DMA'd to skb->data; might need to
2669 * invalidate data cache for that memory area */
2670 skb_queue_tail(&local->rx_list, local->rx_skb);
2671 tasklet_schedule(&local->rx_tasklet);
2672 HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
2673 } else {
2674 if (prism2_transmit(dev, local->bus_m0_tx_idx)) {
2675 printk(KERN_DEBUG "%s: prism2_transmit() failed "
2676 "when called from bus master event\n",
2677 dev->name);
2678 local->intransmitfid[local->bus_m0_tx_idx] =
2679 PRISM2_TXFID_EMPTY;
2680 schedule_work(&local->reset_queue);
2681 }
2682 }
2683}
2684#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
2685
2686
2687/* Called only from hardware IRQ */
2688static void prism2_infdrop(struct net_device *dev)
2689{
2690 static unsigned long last_inquire = 0;
2691
2692 PDEBUG(DEBUG_EXTRA, "%s: INFDROP event\n", dev->name);
2693
2694 /* some firmware versions seem to get stuck with
2695 * full CommTallies in high traffic load cases; every
2696 * packet will then cause INFDROP event and CommTallies
2697 * info frame will not be sent automatically. Try to
2698 * get out of this state by inquiring CommTallies. */
2699 if (!last_inquire || time_after(jiffies, last_inquire + HZ)) {
2700 hfa384x_cmd_callback(dev, HFA384X_CMDCODE_INQUIRE,
2701 HFA384X_INFO_COMMTALLIES, NULL, 0);
2702 last_inquire = jiffies;
2703 }
2704}
2705
2706
2707/* Called only from hardware IRQ */
2708static void prism2_ev_tick(struct net_device *dev)
2709{
2710 struct hostap_interface *iface;
2711 local_info_t *local;
2712 u16 evstat, inten;
2713 static int prev_stuck = 0;
2714
2715 iface = netdev_priv(dev);
2716 local = iface->local;
2717
2718 if (time_after(jiffies, local->last_tick_timer + 5 * HZ) &&
2719 local->last_tick_timer) {
2720 evstat = HFA384X_INW(HFA384X_EVSTAT_OFF);
2721 inten = HFA384X_INW(HFA384X_INTEN_OFF);
2722 if (!prev_stuck) {
2723 printk(KERN_INFO "%s: SW TICK stuck? "
2724 "bits=0x%lx EvStat=%04x IntEn=%04x\n",
2725 dev->name, local->bits, evstat, inten);
2726 }
2727 local->sw_tick_stuck++;
2728 if ((evstat & HFA384X_BAP0_EVENTS) &&
2729 (inten & HFA384X_BAP0_EVENTS)) {
2730 printk(KERN_INFO "%s: trying to recover from IRQ "
2731 "hang\n", dev->name);
2732 hfa384x_events_no_bap0(dev);
2733 }
2734 prev_stuck = 1;
2735 } else
2736 prev_stuck = 0;
2737}
2738
2739
2740/* Called only from hardware IRQ */
2741static inline void prism2_check_magic(local_info_t *local)
2742{
2743 /* at least PCI Prism2.5 with bus mastering seems to sometimes
2744 * return 0x0000 in SWSUPPORT0 for unknown reason, but re-reading the
2745 * register once or twice seems to get the correct value.. PCI cards
2746 * cannot anyway be removed during normal operation, so there is not
2747 * really any need for this verification with them. */
2748
2749#ifndef PRISM2_PCI
2750#ifndef final_version
2751 static unsigned long last_magic_err = 0;
2752 struct net_device *dev = local->dev;
2753
2754 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != HFA384X_MAGIC) {
2755 if (!local->hw_ready)
2756 return;
2757 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
2758 if (time_after(jiffies, last_magic_err + 10 * HZ)) {
2759 printk("%s: Interrupt, but SWSUPPORT0 does not match: "
2760 "%04X != %04X - card removed?\n", dev->name,
2761 HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
2762 HFA384X_MAGIC);
2763 last_magic_err = jiffies;
2764 } else if (net_ratelimit()) {
2765 printk(KERN_DEBUG "%s: interrupt - SWSUPPORT0=%04x "
2766 "MAGIC=%04x\n", dev->name,
2767 HFA384X_INW(HFA384X_SWSUPPORT0_OFF),
2768 HFA384X_MAGIC);
2769 }
2770 if (HFA384X_INW(HFA384X_SWSUPPORT0_OFF) != 0xffff)
2771 schedule_work(&local->reset_queue);
2772 return;
2773 }
2774#endif /* final_version */
2775#endif /* !PRISM2_PCI */
2776}
2777
2778
2779/* Called only from hardware IRQ */
2780static irqreturn_t prism2_interrupt(int irq, void *dev_id, struct pt_regs *regs)
2781{
2782 struct net_device *dev = (struct net_device *) dev_id;
2783 struct hostap_interface *iface;
2784 local_info_t *local;
2785 int events = 0;
2786 u16 ev;
2787
2788 iface = netdev_priv(dev);
2789 local = iface->local;
2790
2791 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 0);
2792
2793 if (local->func->card_present && !local->func->card_present(local)) {
2794 if (net_ratelimit()) {
2795 printk(KERN_DEBUG "%s: Interrupt, but dev not OK\n",
2796 dev->name);
2797 }
2798 return IRQ_HANDLED;
2799 }
2800
2801 prism2_check_magic(local);
2802
2803 for (;;) {
2804 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
2805 if (ev == 0xffff) {
2806 if (local->shutdown)
2807 return IRQ_HANDLED;
2808 HFA384X_OUTW(0xffff, HFA384X_EVACK_OFF);
2809 printk(KERN_DEBUG "%s: prism2_interrupt: ev=0xffff\n",
2810 dev->name);
2811 return IRQ_HANDLED;
2812 }
2813
2814 ev &= HFA384X_INW(HFA384X_INTEN_OFF);
2815 if (ev == 0)
2816 break;
2817
2818 if (ev & HFA384X_EV_CMD) {
2819 prism2_cmd_ev(dev);
2820 }
2821
2822 /* Above events are needed even before hw is ready, but other
2823 * events should be skipped during initialization. This may
2824 * change for AllocEv if allocate_fid is implemented without
2825 * busy waiting. */
2826 if (!local->hw_ready || local->hw_resetting ||
2827 !local->dev_enabled) {
2828 ev = HFA384X_INW(HFA384X_EVSTAT_OFF);
2829 if (ev & HFA384X_EV_CMD)
2830 goto next_event;
2831 if ((ev & HFA384X_EVENT_MASK) == 0)
2832 return IRQ_HANDLED;
2833 if (local->dev_enabled && (ev & ~HFA384X_EV_TICK) &&
2834 net_ratelimit()) {
2835 printk(KERN_DEBUG "%s: prism2_interrupt: hw "
2836 "not ready; skipping events 0x%04x "
2837 "(IntEn=0x%04x)%s%s%s\n",
2838 dev->name, ev,
2839 HFA384X_INW(HFA384X_INTEN_OFF),
2840 !local->hw_ready ? " (!hw_ready)" : "",
2841 local->hw_resetting ?
2842 " (hw_resetting)" : "",
2843 !local->dev_enabled ?
2844 " (!dev_enabled)" : "");
2845 }
2846 HFA384X_OUTW(ev, HFA384X_EVACK_OFF);
2847 return IRQ_HANDLED;
2848 }
2849
2850 if (ev & HFA384X_EV_TICK) {
2851 prism2_ev_tick(dev);
2852 HFA384X_OUTW(HFA384X_EV_TICK, HFA384X_EVACK_OFF);
2853 }
2854
2855#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
2856 if (ev & HFA384X_EV_PCI_M0) {
2857 prism2_bus_master_ev(dev, BAP0);
2858 HFA384X_OUTW(HFA384X_EV_PCI_M0, HFA384X_EVACK_OFF);
2859 }
2860
2861 if (ev & HFA384X_EV_PCI_M1) {
2862 /* previous RX has been copied can be ACKed now */
2863 HFA384X_OUTW(HFA384X_EV_RX, HFA384X_EVACK_OFF);
2864
2865 prism2_bus_master_ev(dev, BAP1);
2866 HFA384X_OUTW(HFA384X_EV_PCI_M1, HFA384X_EVACK_OFF);
2867 }
2868#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
2869
2870 if (ev & HFA384X_EV_ALLOC) {
2871 prism2_alloc_ev(dev);
2872 HFA384X_OUTW(HFA384X_EV_ALLOC, HFA384X_EVACK_OFF);
2873 }
2874
2875 /* Reading data from the card is quite time consuming, so do it
2876 * in tasklets. TX, TXEXC, RX, and INFO events will be ACKed
2877 * and unmasked after needed data has been read completely. */
2878 if (ev & HFA384X_BAP0_EVENTS) {
2879 hfa384x_events_no_bap0(dev);
2880 tasklet_schedule(&local->bap_tasklet);
2881 }
2882
2883#ifndef final_version
2884 if (ev & HFA384X_EV_WTERR) {
2885 PDEBUG(DEBUG_EXTRA, "%s: WTERR event\n", dev->name);
2886 HFA384X_OUTW(HFA384X_EV_WTERR, HFA384X_EVACK_OFF);
2887 }
2888#endif /* final_version */
2889
2890 if (ev & HFA384X_EV_INFDROP) {
2891 prism2_infdrop(dev);
2892 HFA384X_OUTW(HFA384X_EV_INFDROP, HFA384X_EVACK_OFF);
2893 }
2894
2895 next_event:
2896 events++;
2897 if (events >= PRISM2_MAX_INTERRUPT_EVENTS) {
2898 PDEBUG(DEBUG_EXTRA, "prism2_interrupt: >%d events "
2899 "(EvStat=0x%04x)\n",
2900 PRISM2_MAX_INTERRUPT_EVENTS,
2901 HFA384X_INW(HFA384X_EVSTAT_OFF));
2902 break;
2903 }
2904 }
2905 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INTERRUPT, 0, 1);
2906 return IRQ_RETVAL(events);
2907}
2908
2909
2910static void prism2_check_sta_fw_version(local_info_t *local)
2911{
2912 struct hfa384x_comp_ident comp;
2913 int id, variant, major, minor;
2914
2915 if (hfa384x_get_rid(local->dev, HFA384X_RID_STAID,
2916 &comp, sizeof(comp), 1) < 0)
2917 return;
2918
2919 local->fw_ap = 0;
2920 id = le16_to_cpu(comp.id);
2921 if (id != HFA384X_COMP_ID_STA) {
2922 if (id == HFA384X_COMP_ID_FW_AP)
2923 local->fw_ap = 1;
2924 return;
2925 }
2926
2927 major = __le16_to_cpu(comp.major);
2928 minor = __le16_to_cpu(comp.minor);
2929 variant = __le16_to_cpu(comp.variant);
2930 local->sta_fw_ver = PRISM2_FW_VER(major, minor, variant);
2931
2932 /* Station firmware versions before 1.4.x seem to have a bug in
2933 * firmware-based WEP encryption when using Host AP mode, so use
2934 * host_encrypt as a default for them. Firmware version 1.4.9 is the
2935 * first one that has been seen to produce correct encryption, but the
2936 * bug might be fixed before that (although, at least 1.4.2 is broken).
2937 */
2938 local->fw_encrypt_ok = local->sta_fw_ver >= PRISM2_FW_VER(1,4,9);
2939
2940 if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
2941 !local->fw_encrypt_ok) {
2942 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
2943 "a workaround for firmware bug in Host AP mode WEP\n",
2944 local->dev->name);
2945 local->host_encrypt = 1;
2946 }
2947
2948 /* IEEE 802.11 standard compliant WDS frames (4 addresses) were broken
2949 * in station firmware versions before 1.5.x. With these versions, the
2950 * driver uses a workaround with bogus frame format (4th address after
2951 * the payload). This is not compatible with other AP devices. Since
2952 * the firmware bug is fixed in the latest station firmware versions,
2953 * automatically enable standard compliant mode for cards using station
2954 * firmware version 1.5.0 or newer. */
2955 if (local->sta_fw_ver >= PRISM2_FW_VER(1,5,0))
2956 local->wds_type |= HOSTAP_WDS_STANDARD_FRAME;
2957 else {
2958 printk(KERN_DEBUG "%s: defaulting to bogus WDS frame as a "
2959 "workaround for firmware bug in Host AP mode WDS\n",
2960 local->dev->name);
2961 }
2962
2963 hostap_check_sta_fw_version(local->ap, local->sta_fw_ver);
2964}
2965
2966
2967static void prism2_crypt_deinit_entries(local_info_t *local, int force)
2968{
2969 struct list_head *ptr, *n;
2970 struct ieee80211_crypt_data *entry;
2971
2972 for (ptr = local->crypt_deinit_list.next, n = ptr->next;
2973 ptr != &local->crypt_deinit_list; ptr = n, n = ptr->next) {
2974 entry = list_entry(ptr, struct ieee80211_crypt_data, list);
2975
2976 if (atomic_read(&entry->refcnt) != 0 && !force)
2977 continue;
2978
2979 list_del(ptr);
2980
2981 if (entry->ops)
2982 entry->ops->deinit(entry->priv);
2983 kfree(entry);
2984 }
2985}
2986
2987
2988static void prism2_crypt_deinit_handler(unsigned long data)
2989{
2990 local_info_t *local = (local_info_t *) data;
2991 unsigned long flags;
2992
2993 spin_lock_irqsave(&local->lock, flags);
2994 prism2_crypt_deinit_entries(local, 0);
2995 if (!list_empty(&local->crypt_deinit_list)) {
2996 printk(KERN_DEBUG "%s: entries remaining in delayed crypt "
2997 "deletion list\n", local->dev->name);
2998 local->crypt_deinit_timer.expires = jiffies + HZ;
2999 add_timer(&local->crypt_deinit_timer);
3000 }
3001 spin_unlock_irqrestore(&local->lock, flags);
3002
3003}
3004
3005
3006static void hostap_passive_scan(unsigned long data)
3007{
3008 local_info_t *local = (local_info_t *) data;
3009 struct net_device *dev = local->dev;
3010 u16 channel;
3011
3012 if (local->passive_scan_interval <= 0)
3013 return;
3014
3015 if (local->passive_scan_state == PASSIVE_SCAN_LISTEN) {
3016 int max_tries = 16;
3017
3018 /* Even though host system does not really know when the WLAN
3019 * MAC is sending frames, try to avoid changing channels for
3020 * passive scanning when a host-generated frame is being
3021 * transmitted */
3022 if (test_bit(HOSTAP_BITS_TRANSMIT, &local->bits)) {
3023 printk(KERN_DEBUG "%s: passive scan detected pending "
3024 "TX - delaying\n", dev->name);
3025 local->passive_scan_timer.expires = jiffies + HZ / 10;
3026 add_timer(&local->passive_scan_timer);
3027 return;
3028 }
3029
3030 do {
3031 local->passive_scan_channel++;
3032 if (local->passive_scan_channel > 14)
3033 local->passive_scan_channel = 1;
3034 max_tries--;
3035 } while (!(local->channel_mask &
3036 (1 << (local->passive_scan_channel - 1))) &&
3037 max_tries > 0);
3038
3039 if (max_tries == 0) {
3040 printk(KERN_INFO "%s: no allowed passive scan channels"
3041 " found\n", dev->name);
3042 return;
3043 }
3044
3045 printk(KERN_DEBUG "%s: passive scan channel %d\n",
3046 dev->name, local->passive_scan_channel);
3047 channel = local->passive_scan_channel;
3048 local->passive_scan_state = PASSIVE_SCAN_WAIT;
3049 local->passive_scan_timer.expires = jiffies + HZ / 10;
3050 } else {
3051 channel = local->channel;
3052 local->passive_scan_state = PASSIVE_SCAN_LISTEN;
3053 local->passive_scan_timer.expires = jiffies +
3054 local->passive_scan_interval * HZ;
3055 }
3056
3057 if (hfa384x_cmd_callback(dev, HFA384X_CMDCODE_TEST |
3058 (HFA384X_TEST_CHANGE_CHANNEL << 8),
3059 channel, NULL, 0))
3060 printk(KERN_ERR "%s: passive scan channel set %d "
3061 "failed\n", dev->name, channel);
3062
3063 add_timer(&local->passive_scan_timer);
3064}
3065
3066
3067/* Called only as a scheduled task when communications quality values should
3068 * be updated. */
3069static void handle_comms_qual_update(void *data)
3070{
3071 local_info_t *local = data;
3072 prism2_update_comms_qual(local->dev);
3073}
3074
3075
3076/* Software watchdog - called as a timer. Hardware interrupt (Tick event) is
3077 * used to monitor that local->last_tick_timer is being updated. If not,
3078 * interrupt busy-loop is assumed and driver tries to recover by masking out
3079 * some events. */
3080static void hostap_tick_timer(unsigned long data)
3081{
3082 static unsigned long last_inquire = 0;
3083 local_info_t *local = (local_info_t *) data;
3084 local->last_tick_timer = jiffies;
3085
3086 /* Inquire CommTallies every 10 seconds to keep the statistics updated
3087 * more often during low load and when using 32-bit tallies. */
3088 if ((!last_inquire || time_after(jiffies, last_inquire + 10 * HZ)) &&
3089 !local->hw_downloading && local->hw_ready &&
3090 !local->hw_resetting && local->dev_enabled) {
3091 hfa384x_cmd_callback(local->dev, HFA384X_CMDCODE_INQUIRE,
3092 HFA384X_INFO_COMMTALLIES, NULL, 0);
3093 last_inquire = jiffies;
3094 }
3095
3096 if ((local->last_comms_qual_update == 0 ||
3097 time_after(jiffies, local->last_comms_qual_update + 10 * HZ)) &&
3098 (local->iw_mode == IW_MODE_INFRA ||
3099 local->iw_mode == IW_MODE_ADHOC)) {
3100 schedule_work(&local->comms_qual_update);
3101 }
3102
3103 local->tick_timer.expires = jiffies + 2 * HZ;
3104 add_timer(&local->tick_timer);
3105}
3106
3107
3108#ifndef PRISM2_NO_PROCFS_DEBUG
3109static int prism2_registers_proc_read(char *page, char **start, off_t off,
3110 int count, int *eof, void *data)
3111{
3112 char *p = page;
3113 local_info_t *local = (local_info_t *) data;
3114
3115 if (off != 0) {
3116 *eof = 1;
3117 return 0;
3118 }
3119
3120#define SHOW_REG(n) \
3121p += sprintf(p, #n "=%04x\n", hfa384x_read_reg(local->dev, HFA384X_##n##_OFF))
3122
3123 SHOW_REG(CMD);
3124 SHOW_REG(PARAM0);
3125 SHOW_REG(PARAM1);
3126 SHOW_REG(PARAM2);
3127 SHOW_REG(STATUS);
3128 SHOW_REG(RESP0);
3129 SHOW_REG(RESP1);
3130 SHOW_REG(RESP2);
3131 SHOW_REG(INFOFID);
3132 SHOW_REG(CONTROL);
3133 SHOW_REG(SELECT0);
3134 SHOW_REG(SELECT1);
3135 SHOW_REG(OFFSET0);
3136 SHOW_REG(OFFSET1);
3137 SHOW_REG(RXFID);
3138 SHOW_REG(ALLOCFID);
3139 SHOW_REG(TXCOMPLFID);
3140 SHOW_REG(SWSUPPORT0);
3141 SHOW_REG(SWSUPPORT1);
3142 SHOW_REG(SWSUPPORT2);
3143 SHOW_REG(EVSTAT);
3144 SHOW_REG(INTEN);
3145 SHOW_REG(EVACK);
3146 /* Do not read data registers, because they change the state of the
3147 * MAC (offset += 2) */
3148 /* SHOW_REG(DATA0); */
3149 /* SHOW_REG(DATA1); */
3150 SHOW_REG(AUXPAGE);
3151 SHOW_REG(AUXOFFSET);
3152 /* SHOW_REG(AUXDATA); */
3153#ifdef PRISM2_PCI
3154 SHOW_REG(PCICOR);
3155 SHOW_REG(PCIHCR);
3156 SHOW_REG(PCI_M0_ADDRH);
3157 SHOW_REG(PCI_M0_ADDRL);
3158 SHOW_REG(PCI_M0_LEN);
3159 SHOW_REG(PCI_M0_CTL);
3160 SHOW_REG(PCI_STATUS);
3161 SHOW_REG(PCI_M1_ADDRH);
3162 SHOW_REG(PCI_M1_ADDRL);
3163 SHOW_REG(PCI_M1_LEN);
3164 SHOW_REG(PCI_M1_CTL);
3165#endif /* PRISM2_PCI */
3166
3167 return (p - page);
3168}
3169#endif /* PRISM2_NO_PROCFS_DEBUG */
3170
3171
3172struct set_tim_data {
3173 struct list_head list;
3174 int aid;
3175 int set;
3176};
3177
3178static int prism2_set_tim(struct net_device *dev, int aid, int set)
3179{
3180 struct list_head *ptr;
3181 struct set_tim_data *new_entry;
3182 struct hostap_interface *iface;
3183 local_info_t *local;
3184
3185 iface = netdev_priv(dev);
3186 local = iface->local;
3187
3188 new_entry = (struct set_tim_data *)
3189 kmalloc(sizeof(*new_entry), GFP_ATOMIC);
3190 if (new_entry == NULL) {
3191 printk(KERN_DEBUG "%s: prism2_set_tim: kmalloc failed\n",
3192 local->dev->name);
3193 return -ENOMEM;
3194 }
3195 memset(new_entry, 0, sizeof(*new_entry));
3196 new_entry->aid = aid;
3197 new_entry->set = set;
3198
3199 spin_lock_bh(&local->set_tim_lock);
3200 list_for_each(ptr, &local->set_tim_list) {
3201 struct set_tim_data *entry =
3202 list_entry(ptr, struct set_tim_data, list);
3203 if (entry->aid == aid) {
3204 PDEBUG(DEBUG_PS2, "%s: prism2_set_tim: aid=%d "
3205 "set=%d ==> %d\n",
3206 local->dev->name, aid, entry->set, set);
3207 entry->set = set;
3208 kfree(new_entry);
3209 new_entry = NULL;
3210 break;
3211 }
3212 }
3213 if (new_entry)
3214 list_add_tail(&new_entry->list, &local->set_tim_list);
3215 spin_unlock_bh(&local->set_tim_lock);
3216
3217 schedule_work(&local->set_tim_queue);
3218
3219 return 0;
3220}
3221
3222
3223static void handle_set_tim_queue(void *data)
3224{
3225 local_info_t *local = (local_info_t *) data;
3226 struct set_tim_data *entry;
3227 u16 val;
3228
3229 for (;;) {
3230 entry = NULL;
3231 spin_lock_bh(&local->set_tim_lock);
3232 if (!list_empty(&local->set_tim_list)) {
3233 entry = list_entry(local->set_tim_list.next,
3234 struct set_tim_data, list);
3235 list_del(&entry->list);
3236 }
3237 spin_unlock_bh(&local->set_tim_lock);
3238 if (!entry)
3239 break;
3240
3241 PDEBUG(DEBUG_PS2, "%s: handle_set_tim_queue: aid=%d set=%d\n",
3242 local->dev->name, entry->aid, entry->set);
3243
3244 val = entry->aid;
3245 if (entry->set)
3246 val |= 0x8000;
3247 if (hostap_set_word(local->dev, HFA384X_RID_CNFTIMCTRL, val)) {
3248 printk(KERN_DEBUG "%s: set_tim failed (aid=%d "
3249 "set=%d)\n",
3250 local->dev->name, entry->aid, entry->set);
3251 }
3252
3253 kfree(entry);
3254 }
3255}
3256
3257
3258static void prism2_clear_set_tim_queue(local_info_t *local)
3259{
3260 struct list_head *ptr, *n;
3261
3262 list_for_each_safe(ptr, n, &local->set_tim_list) {
3263 struct set_tim_data *entry;
3264 entry = list_entry(ptr, struct set_tim_data, list);
3265 list_del(&entry->list);
3266 kfree(entry);
3267 }
3268}
3269
3270
3271static struct net_device *
3272prism2_init_local_data(struct prism2_helper_functions *funcs, int card_idx,
3273 struct device *sdev)
3274{
3275 struct net_device *dev;
3276 struct hostap_interface *iface;
3277 struct local_info *local;
3278 int len, i, ret;
3279
3280 if (funcs == NULL)
3281 return NULL;
3282
3283 len = strlen(dev_template);
3284 if (len >= IFNAMSIZ || strstr(dev_template, "%d") == NULL) {
3285 printk(KERN_WARNING "hostap: Invalid dev_template='%s'\n",
3286 dev_template);
3287 return NULL;
3288 }
3289
3290 len = sizeof(struct hostap_interface) +
3291 3 + sizeof(struct local_info) +
3292 3 + sizeof(struct ap_data);
3293
3294 dev = alloc_etherdev(len);
3295 if (dev == NULL)
3296 return NULL;
3297
3298 iface = netdev_priv(dev);
3299 local = (struct local_info *) ((((long) (iface + 1)) + 3) & ~3);
3300 local->ap = (struct ap_data *) ((((long) (local + 1)) + 3) & ~3);
3301 local->dev = iface->dev = dev;
3302 iface->local = local;
3303 iface->type = HOSTAP_INTERFACE_MASTER;
3304 INIT_LIST_HEAD(&local->hostap_interfaces);
3305
3306 local->hw_module = THIS_MODULE;
3307
3308#ifdef PRISM2_IO_DEBUG
3309 local->io_debug_enabled = 1;
3310#endif /* PRISM2_IO_DEBUG */
3311
3312#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3313 local->bus_m0_buf = (u8 *) kmalloc(sizeof(struct hfa384x_tx_frame) +
3314 PRISM2_DATA_MAXLEN, GFP_DMA);
3315 if (local->bus_m0_buf == NULL)
3316 goto fail;
3317#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3318
3319 local->func = funcs;
3320 local->func->cmd = hfa384x_cmd;
3321 local->func->read_regs = hfa384x_read_regs;
3322 local->func->get_rid = hfa384x_get_rid;
3323 local->func->set_rid = hfa384x_set_rid;
3324 local->func->hw_enable = prism2_hw_enable;
3325 local->func->hw_config = prism2_hw_config;
3326 local->func->hw_reset = prism2_hw_reset;
3327 local->func->hw_shutdown = prism2_hw_shutdown;
3328 local->func->reset_port = prism2_reset_port;
3329 local->func->schedule_reset = prism2_schedule_reset;
3330#ifdef PRISM2_DOWNLOAD_SUPPORT
3331 local->func->read_aux = prism2_download_aux_dump;
3332 local->func->download = prism2_download;
3333#endif /* PRISM2_DOWNLOAD_SUPPORT */
3334 local->func->tx = prism2_tx_80211;
3335 local->func->set_tim = prism2_set_tim;
3336 local->func->need_tx_headroom = 0; /* no need to add txdesc in
3337 * skb->data (FIX: maybe for DMA bus
3338 * mastering? */
3339
3340 local->mtu = mtu;
3341
3342 rwlock_init(&local->iface_lock);
3343 spin_lock_init(&local->txfidlock);
3344 spin_lock_init(&local->cmdlock);
3345 spin_lock_init(&local->baplock);
3346 spin_lock_init(&local->lock);
3347 init_MUTEX(&local->rid_bap_sem);
3348
3349 if (card_idx < 0 || card_idx >= MAX_PARM_DEVICES)
3350 card_idx = 0;
3351 local->card_idx = card_idx;
3352
3353 len = strlen(essid);
3354 memcpy(local->essid, essid,
3355 len > MAX_SSID_LEN ? MAX_SSID_LEN : len);
3356 local->essid[MAX_SSID_LEN] = '\0';
3357 i = GET_INT_PARM(iw_mode, card_idx);
3358 if ((i >= IW_MODE_ADHOC && i <= IW_MODE_REPEAT) ||
3359 i == IW_MODE_MONITOR) {
3360 local->iw_mode = i;
3361 } else {
3362 printk(KERN_WARNING "prism2: Unknown iw_mode %d; using "
3363 "IW_MODE_MASTER\n", i);
3364 local->iw_mode = IW_MODE_MASTER;
3365 }
3366 local->channel = GET_INT_PARM(channel, card_idx);
3367 local->beacon_int = GET_INT_PARM(beacon_int, card_idx);
3368 local->dtim_period = GET_INT_PARM(dtim_period, card_idx);
3369 local->wds_max_connections = 16;
3370 local->tx_control = HFA384X_TX_CTRL_FLAGS;
3371 local->manual_retry_count = -1;
3372 local->rts_threshold = 2347;
3373 local->fragm_threshold = 2346;
3374 local->rssi_to_dBm = 100; /* default; to be overriden by
3375 * cnfDbmAdjust, if available */
3376 local->auth_algs = PRISM2_AUTH_OPEN | PRISM2_AUTH_SHARED_KEY;
3377 local->sram_type = -1;
3378 local->scan_channel_mask = 0xffff;
3379#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3380 local->bus_master_threshold_rx = GET_INT_PARM(bus_master_threshold_rx,
3381 card_idx);
3382 local->bus_master_threshold_tx = GET_INT_PARM(bus_master_threshold_tx,
3383 card_idx);
3384#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3385
3386 /* Initialize task queue structures */
3387 INIT_WORK(&local->reset_queue, handle_reset_queue, local);
3388 INIT_WORK(&local->set_multicast_list_queue,
3389 hostap_set_multicast_list_queue, local->dev);
3390
3391 INIT_WORK(&local->set_tim_queue, handle_set_tim_queue, local);
3392 INIT_LIST_HEAD(&local->set_tim_list);
3393 spin_lock_init(&local->set_tim_lock);
3394
3395 INIT_WORK(&local->comms_qual_update, handle_comms_qual_update, local);
3396
3397 /* Initialize tasklets for handling hardware IRQ related operations
3398 * outside hw IRQ handler */
3399#define HOSTAP_TASKLET_INIT(q, f, d) \
3400do { memset((q), 0, sizeof(*(q))); (q)->func = (f); (q)->data = (d); } \
3401while (0)
3402 HOSTAP_TASKLET_INIT(&local->bap_tasklet, hostap_bap_tasklet,
3403 (unsigned long) local);
3404
3405 HOSTAP_TASKLET_INIT(&local->info_tasklet, hostap_info_tasklet,
3406 (unsigned long) local);
3407 hostap_info_init(local);
3408
3409 HOSTAP_TASKLET_INIT(&local->rx_tasklet,
3410 hostap_rx_tasklet, (unsigned long) local);
3411 skb_queue_head_init(&local->rx_list);
3412
3413 HOSTAP_TASKLET_INIT(&local->sta_tx_exc_tasklet,
3414 hostap_sta_tx_exc_tasklet, (unsigned long) local);
3415 skb_queue_head_init(&local->sta_tx_exc_list);
3416
3417 INIT_LIST_HEAD(&local->cmd_queue);
3418 init_waitqueue_head(&local->hostscan_wq);
3419 INIT_LIST_HEAD(&local->crypt_deinit_list);
3420 init_timer(&local->crypt_deinit_timer);
3421 local->crypt_deinit_timer.data = (unsigned long) local;
3422 local->crypt_deinit_timer.function = prism2_crypt_deinit_handler;
3423
3424 init_timer(&local->passive_scan_timer);
3425 local->passive_scan_timer.data = (unsigned long) local;
3426 local->passive_scan_timer.function = hostap_passive_scan;
3427
3428 init_timer(&local->tick_timer);
3429 local->tick_timer.data = (unsigned long) local;
3430 local->tick_timer.function = hostap_tick_timer;
3431 local->tick_timer.expires = jiffies + 2 * HZ;
3432 add_timer(&local->tick_timer);
3433
3434 INIT_LIST_HEAD(&local->bss_list);
3435
3436 hostap_setup_dev(dev, local, 1);
3437 local->saved_eth_header_parse = dev->hard_header_parse;
3438
3439 dev->hard_start_xmit = hostap_master_start_xmit;
3440 dev->type = ARPHRD_IEEE80211;
3441 dev->hard_header_parse = hostap_80211_header_parse;
3442
3443 rtnl_lock();
3444 ret = dev_alloc_name(dev, "wifi%d");
3445 SET_NETDEV_DEV(dev, sdev);
3446 if (ret >= 0)
3447 ret = register_netdevice(dev);
3448 rtnl_unlock();
3449 if (ret < 0) {
3450 printk(KERN_WARNING "%s: register netdevice failed!\n",
3451 dev_info);
3452 goto fail;
3453 }
3454 printk(KERN_INFO "%s: Registered netdevice %s\n", dev_info, dev->name);
3455
3456#ifndef PRISM2_NO_PROCFS_DEBUG
3457 create_proc_read_entry("registers", 0, local->proc,
3458 prism2_registers_proc_read, local);
3459#endif /* PRISM2_NO_PROCFS_DEBUG */
3460
3461 hostap_init_data(local);
3462 return dev;
3463
3464 fail:
3465#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3466 kfree(local->bus_m0_buf);
3467#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3468 free_netdev(dev);
3469 return NULL;
3470}
3471
3472
3473static int hostap_hw_ready(struct net_device *dev)
3474{
3475 struct hostap_interface *iface;
3476 struct local_info *local;
3477
3478 iface = netdev_priv(dev);
3479 local = iface->local;
3480 local->ddev = hostap_add_interface(local, HOSTAP_INTERFACE_MAIN, 0,
3481 "", dev_template);
3482
3483 if (local->ddev) {
3484 if (local->iw_mode == IW_MODE_INFRA ||
3485 local->iw_mode == IW_MODE_ADHOC) {
3486 netif_carrier_off(local->dev);
3487 netif_carrier_off(local->ddev);
3488 }
3489 hostap_init_proc(local);
3490 hostap_init_ap_proc(local);
3491 return 0;
3492 }
3493
3494 return -1;
3495}
3496
3497
3498static void prism2_free_local_data(struct net_device *dev)
3499{
3500 struct hostap_tx_callback_info *tx_cb, *tx_cb_prev;
3501 int i;
3502 struct hostap_interface *iface;
3503 struct local_info *local;
3504 struct list_head *ptr, *n;
3505
3506 if (dev == NULL)
3507 return;
3508
3509 iface = netdev_priv(dev);
3510 local = iface->local;
3511
3512 flush_scheduled_work();
3513
3514 if (timer_pending(&local->crypt_deinit_timer))
3515 del_timer(&local->crypt_deinit_timer);
3516 prism2_crypt_deinit_entries(local, 1);
3517
3518 if (timer_pending(&local->passive_scan_timer))
3519 del_timer(&local->passive_scan_timer);
3520
3521 if (timer_pending(&local->tick_timer))
3522 del_timer(&local->tick_timer);
3523
3524 prism2_clear_cmd_queue(local);
3525
3526 skb_queue_purge(&local->info_list);
3527 skb_queue_purge(&local->rx_list);
3528 skb_queue_purge(&local->sta_tx_exc_list);
3529
3530 if (local->dev_enabled)
3531 prism2_callback(local, PRISM2_CALLBACK_DISABLE);
3532
3533 for (i = 0; i < WEP_KEYS; i++) {
3534 struct ieee80211_crypt_data *crypt = local->crypt[i];
3535 if (crypt) {
3536 if (crypt->ops)
3537 crypt->ops->deinit(crypt->priv);
3538 kfree(crypt);
3539 local->crypt[i] = NULL;
3540 }
3541 }
3542
3543 if (local->ap != NULL)
3544 hostap_free_data(local->ap);
3545
3546#ifndef PRISM2_NO_PROCFS_DEBUG
3547 if (local->proc != NULL)
3548 remove_proc_entry("registers", local->proc);
3549#endif /* PRISM2_NO_PROCFS_DEBUG */
3550 hostap_remove_proc(local);
3551
3552 tx_cb = local->tx_callback;
3553 while (tx_cb != NULL) {
3554 tx_cb_prev = tx_cb;
3555 tx_cb = tx_cb->next;
3556 kfree(tx_cb_prev);
3557 }
3558
3559 hostap_set_hostapd(local, 0, 0);
3560 hostap_set_hostapd_sta(local, 0, 0);
3561
3562 for (i = 0; i < PRISM2_FRAG_CACHE_LEN; i++) {
3563 if (local->frag_cache[i].skb != NULL)
3564 dev_kfree_skb(local->frag_cache[i].skb);
3565 }
3566
3567#ifdef PRISM2_DOWNLOAD_SUPPORT
3568 prism2_download_free_data(local->dl_pri);
3569 prism2_download_free_data(local->dl_sec);
3570#endif /* PRISM2_DOWNLOAD_SUPPORT */
3571
3572 list_for_each_safe(ptr, n, &local->hostap_interfaces) {
3573 iface = list_entry(ptr, struct hostap_interface, list);
3574 if (iface->type == HOSTAP_INTERFACE_MASTER) {
3575 /* special handling for this interface below */
3576 continue;
3577 }
3578 hostap_remove_interface(iface->dev, 0, 1);
3579 }
3580
3581 prism2_clear_set_tim_queue(local);
3582
3583 list_for_each_safe(ptr, n, &local->bss_list) {
3584 struct hostap_bss_info *bss =
3585 list_entry(ptr, struct hostap_bss_info, list);
3586 kfree(bss);
3587 }
3588
3589#if defined(PRISM2_PCI) && defined(PRISM2_BUS_MASTER)
3590 kfree(local->bus_m0_buf);
3591#endif /* PRISM2_PCI and PRISM2_BUS_MASTER */
3592 kfree(local->pda);
3593 kfree(local->last_scan_results);
3594 kfree(local->generic_elem);
3595
3596 unregister_netdev(local->dev);
3597 free_netdev(local->dev);
3598}
3599
3600
3601#ifndef PRISM2_PLX
3602static void prism2_suspend(struct net_device *dev)
3603{
3604 struct hostap_interface *iface;
3605 struct local_info *local;
3606 union iwreq_data wrqu;
3607
3608 iface = dev->priv;
3609 local = iface->local;
3610
3611 /* Send disconnect event, e.g., to trigger reassociation after resume
3612 * if wpa_supplicant is used. */
3613 memset(&wrqu, 0, sizeof(wrqu));
3614 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
3615 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
3616
3617 /* Disable hardware and firmware */
3618 prism2_hw_shutdown(dev, 0);
3619}
3620#endif /* PRISM2_PLX */
3621
3622
3623/* These might at some point be compiled separately and used as separate
3624 * kernel modules or linked into one */
3625#ifdef PRISM2_DOWNLOAD_SUPPORT
3626#include "hostap_download.c"
3627#endif /* PRISM2_DOWNLOAD_SUPPORT */
3628
3629#ifdef PRISM2_CALLBACK
3630/* External hostap_callback.c file can be used to, e.g., blink activity led.
3631 * This can use platform specific code and must define prism2_callback()
3632 * function (if PRISM2_CALLBACK is not defined, these function calls are not
3633 * used. */
3634#include "hostap_callback.c"
3635#endif /* PRISM2_CALLBACK */
diff --git a/drivers/net/wireless/hostap/hostap_info.c b/drivers/net/wireless/hostap/hostap_info.c
new file mode 100644
index 000000000000..5aa998fdf1c4
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_info.c
@@ -0,0 +1,499 @@
1/* Host AP driver Info Frame processing (part of hostap.o module) */
2
3
4/* Called only as a tasklet (software IRQ) */
5static void prism2_info_commtallies16(local_info_t *local, unsigned char *buf,
6 int left)
7{
8 struct hfa384x_comm_tallies *tallies;
9
10 if (left < sizeof(struct hfa384x_comm_tallies)) {
11 printk(KERN_DEBUG "%s: too short (len=%d) commtallies "
12 "info frame\n", local->dev->name, left);
13 return;
14 }
15
16 tallies = (struct hfa384x_comm_tallies *) buf;
17#define ADD_COMM_TALLIES(name) \
18local->comm_tallies.name += le16_to_cpu(tallies->name)
19 ADD_COMM_TALLIES(tx_unicast_frames);
20 ADD_COMM_TALLIES(tx_multicast_frames);
21 ADD_COMM_TALLIES(tx_fragments);
22 ADD_COMM_TALLIES(tx_unicast_octets);
23 ADD_COMM_TALLIES(tx_multicast_octets);
24 ADD_COMM_TALLIES(tx_deferred_transmissions);
25 ADD_COMM_TALLIES(tx_single_retry_frames);
26 ADD_COMM_TALLIES(tx_multiple_retry_frames);
27 ADD_COMM_TALLIES(tx_retry_limit_exceeded);
28 ADD_COMM_TALLIES(tx_discards);
29 ADD_COMM_TALLIES(rx_unicast_frames);
30 ADD_COMM_TALLIES(rx_multicast_frames);
31 ADD_COMM_TALLIES(rx_fragments);
32 ADD_COMM_TALLIES(rx_unicast_octets);
33 ADD_COMM_TALLIES(rx_multicast_octets);
34 ADD_COMM_TALLIES(rx_fcs_errors);
35 ADD_COMM_TALLIES(rx_discards_no_buffer);
36 ADD_COMM_TALLIES(tx_discards_wrong_sa);
37 ADD_COMM_TALLIES(rx_discards_wep_undecryptable);
38 ADD_COMM_TALLIES(rx_message_in_msg_fragments);
39 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments);
40#undef ADD_COMM_TALLIES
41}
42
43
44/* Called only as a tasklet (software IRQ) */
45static void prism2_info_commtallies32(local_info_t *local, unsigned char *buf,
46 int left)
47{
48 struct hfa384x_comm_tallies32 *tallies;
49
50 if (left < sizeof(struct hfa384x_comm_tallies32)) {
51 printk(KERN_DEBUG "%s: too short (len=%d) commtallies32 "
52 "info frame\n", local->dev->name, left);
53 return;
54 }
55
56 tallies = (struct hfa384x_comm_tallies32 *) buf;
57#define ADD_COMM_TALLIES(name) \
58local->comm_tallies.name += le32_to_cpu(tallies->name)
59 ADD_COMM_TALLIES(tx_unicast_frames);
60 ADD_COMM_TALLIES(tx_multicast_frames);
61 ADD_COMM_TALLIES(tx_fragments);
62 ADD_COMM_TALLIES(tx_unicast_octets);
63 ADD_COMM_TALLIES(tx_multicast_octets);
64 ADD_COMM_TALLIES(tx_deferred_transmissions);
65 ADD_COMM_TALLIES(tx_single_retry_frames);
66 ADD_COMM_TALLIES(tx_multiple_retry_frames);
67 ADD_COMM_TALLIES(tx_retry_limit_exceeded);
68 ADD_COMM_TALLIES(tx_discards);
69 ADD_COMM_TALLIES(rx_unicast_frames);
70 ADD_COMM_TALLIES(rx_multicast_frames);
71 ADD_COMM_TALLIES(rx_fragments);
72 ADD_COMM_TALLIES(rx_unicast_octets);
73 ADD_COMM_TALLIES(rx_multicast_octets);
74 ADD_COMM_TALLIES(rx_fcs_errors);
75 ADD_COMM_TALLIES(rx_discards_no_buffer);
76 ADD_COMM_TALLIES(tx_discards_wrong_sa);
77 ADD_COMM_TALLIES(rx_discards_wep_undecryptable);
78 ADD_COMM_TALLIES(rx_message_in_msg_fragments);
79 ADD_COMM_TALLIES(rx_message_in_bad_msg_fragments);
80#undef ADD_COMM_TALLIES
81}
82
83
84/* Called only as a tasklet (software IRQ) */
85static void prism2_info_commtallies(local_info_t *local, unsigned char *buf,
86 int left)
87{
88 if (local->tallies32)
89 prism2_info_commtallies32(local, buf, left);
90 else
91 prism2_info_commtallies16(local, buf, left);
92}
93
94
95#ifndef PRISM2_NO_STATION_MODES
96#ifndef PRISM2_NO_DEBUG
97static const char* hfa384x_linkstatus_str(u16 linkstatus)
98{
99 switch (linkstatus) {
100 case HFA384X_LINKSTATUS_CONNECTED:
101 return "Connected";
102 case HFA384X_LINKSTATUS_DISCONNECTED:
103 return "Disconnected";
104 case HFA384X_LINKSTATUS_AP_CHANGE:
105 return "Access point change";
106 case HFA384X_LINKSTATUS_AP_OUT_OF_RANGE:
107 return "Access point out of range";
108 case HFA384X_LINKSTATUS_AP_IN_RANGE:
109 return "Access point in range";
110 case HFA384X_LINKSTATUS_ASSOC_FAILED:
111 return "Association failed";
112 default:
113 return "Unknown";
114 }
115}
116#endif /* PRISM2_NO_DEBUG */
117
118
119/* Called only as a tasklet (software IRQ) */
120static void prism2_info_linkstatus(local_info_t *local, unsigned char *buf,
121 int left)
122{
123 u16 val;
124 int non_sta_mode;
125
126 /* Alloc new JoinRequests to occur since LinkStatus for the previous
127 * has been received */
128 local->last_join_time = 0;
129
130 if (left != 2) {
131 printk(KERN_DEBUG "%s: invalid linkstatus info frame "
132 "length %d\n", local->dev->name, left);
133 return;
134 }
135
136 non_sta_mode = local->iw_mode == IW_MODE_MASTER ||
137 local->iw_mode == IW_MODE_REPEAT ||
138 local->iw_mode == IW_MODE_MONITOR;
139
140 val = buf[0] | (buf[1] << 8);
141 if (!non_sta_mode || val != HFA384X_LINKSTATUS_DISCONNECTED) {
142 PDEBUG(DEBUG_EXTRA, "%s: LinkStatus=%d (%s)\n",
143 local->dev->name, val, hfa384x_linkstatus_str(val));
144 }
145
146 if (non_sta_mode) {
147 netif_carrier_on(local->dev);
148 netif_carrier_on(local->ddev);
149 return;
150 }
151
152 /* Get current BSSID later in scheduled task */
153 set_bit(PRISM2_INFO_PENDING_LINKSTATUS, &local->pending_info);
154 local->prev_link_status = val;
155 schedule_work(&local->info_queue);
156}
157
158
159static void prism2_host_roaming(local_info_t *local)
160{
161 struct hfa384x_join_request req;
162 struct net_device *dev = local->dev;
163 struct hfa384x_hostscan_result *selected, *entry;
164 int i;
165 unsigned long flags;
166
167 if (local->last_join_time &&
168 time_before(jiffies, local->last_join_time + 10 * HZ)) {
169 PDEBUG(DEBUG_EXTRA, "%s: last join request has not yet been "
170 "completed - waiting for it before issuing new one\n",
171 dev->name);
172 return;
173 }
174
175 /* ScanResults are sorted: first ESS results in decreasing signal
176 * quality then IBSS results in similar order.
177 * Trivial roaming policy: just select the first entry.
178 * This could probably be improved by adding hysteresis to limit
179 * number of handoffs, etc.
180 *
181 * Could do periodic RID_SCANREQUEST or Inquire F101 to get new
182 * ScanResults */
183 spin_lock_irqsave(&local->lock, flags);
184 if (local->last_scan_results == NULL ||
185 local->last_scan_results_count == 0) {
186 spin_unlock_irqrestore(&local->lock, flags);
187 PDEBUG(DEBUG_EXTRA, "%s: no scan results for host roaming\n",
188 dev->name);
189 return;
190 }
191
192 selected = &local->last_scan_results[0];
193
194 if (local->preferred_ap[0] || local->preferred_ap[1] ||
195 local->preferred_ap[2] || local->preferred_ap[3] ||
196 local->preferred_ap[4] || local->preferred_ap[5]) {
197 /* Try to find preferred AP */
198 PDEBUG(DEBUG_EXTRA, "%s: Preferred AP BSSID " MACSTR "\n",
199 dev->name, MAC2STR(local->preferred_ap));
200 for (i = 0; i < local->last_scan_results_count; i++) {
201 entry = &local->last_scan_results[i];
202 if (memcmp(local->preferred_ap, entry->bssid, 6) == 0)
203 {
204 PDEBUG(DEBUG_EXTRA, "%s: using preferred AP "
205 "selection\n", dev->name);
206 selected = entry;
207 break;
208 }
209 }
210 }
211
212 memcpy(req.bssid, selected->bssid, 6);
213 req.channel = selected->chid;
214 spin_unlock_irqrestore(&local->lock, flags);
215
216 PDEBUG(DEBUG_EXTRA, "%s: JoinRequest: BSSID=" MACSTR " channel=%d\n",
217 dev->name, MAC2STR(req.bssid), le16_to_cpu(req.channel));
218 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
219 sizeof(req))) {
220 printk(KERN_DEBUG "%s: JoinRequest failed\n", dev->name);
221 }
222 local->last_join_time = jiffies;
223}
224
225
226static void hostap_report_scan_complete(local_info_t *local)
227{
228 union iwreq_data wrqu;
229
230 /* Inform user space about new scan results (just empty event,
231 * SIOCGIWSCAN can be used to fetch data */
232 wrqu.data.length = 0;
233 wrqu.data.flags = 0;
234 wireless_send_event(local->dev, SIOCGIWSCAN, &wrqu, NULL);
235
236 /* Allow SIOCGIWSCAN handling to occur since we have received
237 * scanning result */
238 local->scan_timestamp = 0;
239}
240
241
242/* Called only as a tasklet (software IRQ) */
243static void prism2_info_scanresults(local_info_t *local, unsigned char *buf,
244 int left)
245{
246 u16 *pos;
247 int new_count, i;
248 unsigned long flags;
249 struct hfa384x_scan_result *res;
250 struct hfa384x_hostscan_result *results, *prev;
251
252 if (left < 4) {
253 printk(KERN_DEBUG "%s: invalid scanresult info frame "
254 "length %d\n", local->dev->name, left);
255 return;
256 }
257
258 pos = (u16 *) buf;
259 pos++;
260 pos++;
261 left -= 4;
262
263 new_count = left / sizeof(struct hfa384x_scan_result);
264 results = kmalloc(new_count * sizeof(struct hfa384x_hostscan_result),
265 GFP_ATOMIC);
266 if (results == NULL)
267 return;
268
269 /* Convert to hostscan result format. */
270 res = (struct hfa384x_scan_result *) pos;
271 for (i = 0; i < new_count; i++) {
272 memcpy(&results[i], &res[i],
273 sizeof(struct hfa384x_scan_result));
274 results[i].atim = 0;
275 }
276
277 spin_lock_irqsave(&local->lock, flags);
278 local->last_scan_type = PRISM2_SCAN;
279 prev = local->last_scan_results;
280 local->last_scan_results = results;
281 local->last_scan_results_count = new_count;
282 spin_unlock_irqrestore(&local->lock, flags);
283 kfree(prev);
284
285 hostap_report_scan_complete(local);
286
287 /* Perform rest of ScanResults handling later in scheduled task */
288 set_bit(PRISM2_INFO_PENDING_SCANRESULTS, &local->pending_info);
289 schedule_work(&local->info_queue);
290}
291
292
293/* Called only as a tasklet (software IRQ) */
294static void prism2_info_hostscanresults(local_info_t *local,
295 unsigned char *buf, int left)
296{
297 int i, result_size, copy_len, new_count;
298 struct hfa384x_hostscan_result *results, *prev;
299 unsigned long flags;
300 u16 *pos;
301 u8 *ptr;
302
303 wake_up_interruptible(&local->hostscan_wq);
304
305 if (left < 4) {
306 printk(KERN_DEBUG "%s: invalid hostscanresult info frame "
307 "length %d\n", local->dev->name, left);
308 return;
309 }
310
311 pos = (u16 *) buf;
312 copy_len = result_size = le16_to_cpu(*pos);
313 if (result_size == 0) {
314 printk(KERN_DEBUG "%s: invalid result_size (0) in "
315 "hostscanresults\n", local->dev->name);
316 return;
317 }
318 if (copy_len > sizeof(struct hfa384x_hostscan_result))
319 copy_len = sizeof(struct hfa384x_hostscan_result);
320
321 pos++;
322 pos++;
323 left -= 4;
324 ptr = (u8 *) pos;
325
326 new_count = left / result_size;
327 results = kmalloc(new_count * sizeof(struct hfa384x_hostscan_result),
328 GFP_ATOMIC);
329 if (results == NULL)
330 return;
331 memset(results, 0, new_count * sizeof(struct hfa384x_hostscan_result));
332
333 for (i = 0; i < new_count; i++) {
334 memcpy(&results[i], ptr, copy_len);
335 ptr += result_size;
336 left -= result_size;
337 }
338
339 if (left) {
340 printk(KERN_DEBUG "%s: short HostScan result entry (%d/%d)\n",
341 local->dev->name, left, result_size);
342 }
343
344 spin_lock_irqsave(&local->lock, flags);
345 local->last_scan_type = PRISM2_HOSTSCAN;
346 prev = local->last_scan_results;
347 local->last_scan_results = results;
348 local->last_scan_results_count = new_count;
349 spin_unlock_irqrestore(&local->lock, flags);
350 kfree(prev);
351
352 hostap_report_scan_complete(local);
353}
354#endif /* PRISM2_NO_STATION_MODES */
355
356
357/* Called only as a tasklet (software IRQ) */
358void hostap_info_process(local_info_t *local, struct sk_buff *skb)
359{
360 struct hfa384x_info_frame *info;
361 unsigned char *buf;
362 int left;
363#ifndef PRISM2_NO_DEBUG
364 int i;
365#endif /* PRISM2_NO_DEBUG */
366
367 info = (struct hfa384x_info_frame *) skb->data;
368 buf = skb->data + sizeof(*info);
369 left = skb->len - sizeof(*info);
370
371 switch (info->type) {
372 case HFA384X_INFO_COMMTALLIES:
373 prism2_info_commtallies(local, buf, left);
374 break;
375
376#ifndef PRISM2_NO_STATION_MODES
377 case HFA384X_INFO_LINKSTATUS:
378 prism2_info_linkstatus(local, buf, left);
379 break;
380
381 case HFA384X_INFO_SCANRESULTS:
382 prism2_info_scanresults(local, buf, left);
383 break;
384
385 case HFA384X_INFO_HOSTSCANRESULTS:
386 prism2_info_hostscanresults(local, buf, left);
387 break;
388#endif /* PRISM2_NO_STATION_MODES */
389
390#ifndef PRISM2_NO_DEBUG
391 default:
392 PDEBUG(DEBUG_EXTRA, "%s: INFO - len=%d type=0x%04x\n",
393 local->dev->name, info->len, info->type);
394 PDEBUG(DEBUG_EXTRA, "Unknown info frame:");
395 for (i = 0; i < (left < 100 ? left : 100); i++)
396 PDEBUG2(DEBUG_EXTRA, " %02x", buf[i]);
397 PDEBUG2(DEBUG_EXTRA, "\n");
398 break;
399#endif /* PRISM2_NO_DEBUG */
400 }
401}
402
403
404#ifndef PRISM2_NO_STATION_MODES
405static void handle_info_queue_linkstatus(local_info_t *local)
406{
407 int val = local->prev_link_status;
408 int connected;
409 union iwreq_data wrqu;
410
411 connected =
412 val == HFA384X_LINKSTATUS_CONNECTED ||
413 val == HFA384X_LINKSTATUS_AP_CHANGE ||
414 val == HFA384X_LINKSTATUS_AP_IN_RANGE;
415
416 if (local->func->get_rid(local->dev, HFA384X_RID_CURRENTBSSID,
417 local->bssid, ETH_ALEN, 1) < 0) {
418 printk(KERN_DEBUG "%s: could not read CURRENTBSSID after "
419 "LinkStatus event\n", local->dev->name);
420 } else {
421 PDEBUG(DEBUG_EXTRA, "%s: LinkStatus: BSSID=" MACSTR "\n",
422 local->dev->name,
423 MAC2STR((unsigned char *) local->bssid));
424 if (local->wds_type & HOSTAP_WDS_AP_CLIENT)
425 hostap_add_sta(local->ap, local->bssid);
426 }
427
428 /* Get BSSID if we have a valid AP address */
429 if (connected) {
430 netif_carrier_on(local->dev);
431 netif_carrier_on(local->ddev);
432 memcpy(wrqu.ap_addr.sa_data, local->bssid, ETH_ALEN);
433 } else {
434 netif_carrier_off(local->dev);
435 netif_carrier_off(local->ddev);
436 memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
437 }
438 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
439
440 /*
441 * Filter out sequential disconnect events in order not to cause a
442 * flood of SIOCGIWAP events that have a race condition with EAPOL
443 * frames and can confuse wpa_supplicant about the current association
444 * status.
445 */
446 if (connected || local->prev_linkstatus_connected)
447 wireless_send_event(local->dev, SIOCGIWAP, &wrqu, NULL);
448 local->prev_linkstatus_connected = connected;
449}
450
451
452static void handle_info_queue_scanresults(local_info_t *local)
453{
454 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA)
455 prism2_host_roaming(local);
456
457 if (local->host_roaming == 2 && local->iw_mode == IW_MODE_INFRA &&
458 memcmp(local->preferred_ap, "\x00\x00\x00\x00\x00\x00",
459 ETH_ALEN) != 0) {
460 /*
461 * Firmware seems to be getting into odd state in host_roaming
462 * mode 2 when hostscan is used without join command, so try
463 * to fix this by re-joining the current AP. This does not
464 * actually trigger a new association if the current AP is
465 * still in the scan results.
466 */
467 prism2_host_roaming(local);
468 }
469}
470
471
472/* Called only as scheduled task after receiving info frames (used to avoid
473 * pending too much time in HW IRQ handler). */
474static void handle_info_queue(void *data)
475{
476 local_info_t *local = (local_info_t *) data;
477
478 if (test_and_clear_bit(PRISM2_INFO_PENDING_LINKSTATUS,
479 &local->pending_info))
480 handle_info_queue_linkstatus(local);
481
482 if (test_and_clear_bit(PRISM2_INFO_PENDING_SCANRESULTS,
483 &local->pending_info))
484 handle_info_queue_scanresults(local);
485}
486#endif /* PRISM2_NO_STATION_MODES */
487
488
489void hostap_info_init(local_info_t *local)
490{
491 skb_queue_head_init(&local->info_list);
492#ifndef PRISM2_NO_STATION_MODES
493 INIT_WORK(&local->info_queue, handle_info_queue, local);
494#endif /* PRISM2_NO_STATION_MODES */
495}
496
497
498EXPORT_SYMBOL(hostap_info_init);
499EXPORT_SYMBOL(hostap_info_process);
diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c
new file mode 100644
index 000000000000..f892aa87b13e
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_ioctl.c
@@ -0,0 +1,4126 @@
1/* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
2
3#ifdef in_atomic
4/* Get kernel_locked() for in_atomic() */
5#include <linux/smp_lock.h>
6#endif
7#include <linux/ethtool.h>
8
9
10static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
11{
12 struct hostap_interface *iface;
13 local_info_t *local;
14 struct iw_statistics *wstats;
15
16 iface = netdev_priv(dev);
17 local = iface->local;
18
19 /* Why are we doing that ? Jean II */
20 if (iface->type != HOSTAP_INTERFACE_MAIN)
21 return NULL;
22
23 wstats = &local->wstats;
24
25 wstats->status = 0;
26 wstats->discard.code =
27 local->comm_tallies.rx_discards_wep_undecryptable;
28 wstats->discard.misc =
29 local->comm_tallies.rx_fcs_errors +
30 local->comm_tallies.rx_discards_no_buffer +
31 local->comm_tallies.tx_discards_wrong_sa;
32
33 wstats->discard.retries =
34 local->comm_tallies.tx_retry_limit_exceeded;
35 wstats->discard.fragment =
36 local->comm_tallies.rx_message_in_bad_msg_fragments;
37
38 if (local->iw_mode != IW_MODE_MASTER &&
39 local->iw_mode != IW_MODE_REPEAT) {
40 int update = 1;
41#ifdef in_atomic
42 /* RID reading might sleep and it must not be called in
43 * interrupt context or while atomic. However, this
44 * function seems to be called while atomic (at least in Linux
45 * 2.5.59). Update signal quality values only if in suitable
46 * context. Otherwise, previous values read from tick timer
47 * will be used. */
48 if (in_atomic())
49 update = 0;
50#endif /* in_atomic */
51
52 if (update && prism2_update_comms_qual(dev) == 0)
53 wstats->qual.updated = 7;
54
55 wstats->qual.qual = local->comms_qual;
56 wstats->qual.level = local->avg_signal;
57 wstats->qual.noise = local->avg_noise;
58 } else {
59 wstats->qual.qual = 0;
60 wstats->qual.level = 0;
61 wstats->qual.noise = 0;
62 wstats->qual.updated = 0;
63 }
64
65 return wstats;
66}
67
68
69static int prism2_get_datarates(struct net_device *dev, u8 *rates)
70{
71 struct hostap_interface *iface;
72 local_info_t *local;
73 u8 buf[12];
74 int len;
75 u16 val;
76
77 iface = netdev_priv(dev);
78 local = iface->local;
79
80 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
81 sizeof(buf), 0);
82 if (len < 2)
83 return 0;
84
85 val = le16_to_cpu(*(u16 *) buf); /* string length */
86
87 if (len - 2 < val || val > 10)
88 return 0;
89
90 memcpy(rates, buf + 2, val);
91 return val;
92}
93
94
95static int prism2_get_name(struct net_device *dev,
96 struct iw_request_info *info,
97 char *name, char *extra)
98{
99 u8 rates[10];
100 int len, i, over2 = 0;
101
102 len = prism2_get_datarates(dev, rates);
103
104 for (i = 0; i < len; i++) {
105 if (rates[i] == 0x0b || rates[i] == 0x16) {
106 over2 = 1;
107 break;
108 }
109 }
110
111 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
112
113 return 0;
114}
115
116
117static void prism2_crypt_delayed_deinit(local_info_t *local,
118 struct ieee80211_crypt_data **crypt)
119{
120 struct ieee80211_crypt_data *tmp;
121 unsigned long flags;
122
123 tmp = *crypt;
124 *crypt = NULL;
125
126 if (tmp == NULL)
127 return;
128
129 /* must not run ops->deinit() while there may be pending encrypt or
130 * decrypt operations. Use a list of delayed deinits to avoid needing
131 * locking. */
132
133 spin_lock_irqsave(&local->lock, flags);
134 list_add(&tmp->list, &local->crypt_deinit_list);
135 if (!timer_pending(&local->crypt_deinit_timer)) {
136 local->crypt_deinit_timer.expires = jiffies + HZ;
137 add_timer(&local->crypt_deinit_timer);
138 }
139 spin_unlock_irqrestore(&local->lock, flags);
140}
141
142
143static int prism2_ioctl_siwencode(struct net_device *dev,
144 struct iw_request_info *info,
145 struct iw_point *erq, char *keybuf)
146{
147 struct hostap_interface *iface;
148 local_info_t *local;
149 int i;
150 struct ieee80211_crypt_data **crypt;
151
152 iface = netdev_priv(dev);
153 local = iface->local;
154
155 i = erq->flags & IW_ENCODE_INDEX;
156 if (i < 1 || i > 4)
157 i = local->tx_keyidx;
158 else
159 i--;
160 if (i < 0 || i >= WEP_KEYS)
161 return -EINVAL;
162
163 crypt = &local->crypt[i];
164
165 if (erq->flags & IW_ENCODE_DISABLED) {
166 if (*crypt)
167 prism2_crypt_delayed_deinit(local, crypt);
168 goto done;
169 }
170
171 if (*crypt != NULL && (*crypt)->ops != NULL &&
172 strcmp((*crypt)->ops->name, "WEP") != 0) {
173 /* changing to use WEP; deinit previously used algorithm */
174 prism2_crypt_delayed_deinit(local, crypt);
175 }
176
177 if (*crypt == NULL) {
178 struct ieee80211_crypt_data *new_crypt;
179
180 /* take WEP into use */
181 new_crypt = (struct ieee80211_crypt_data *)
182 kmalloc(sizeof(struct ieee80211_crypt_data),
183 GFP_KERNEL);
184 if (new_crypt == NULL)
185 return -ENOMEM;
186 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
187 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
188 if (!new_crypt->ops) {
189 request_module("ieee80211_crypt_wep");
190 new_crypt->ops = ieee80211_get_crypto_ops("WEP");
191 }
192 if (new_crypt->ops)
193 new_crypt->priv = new_crypt->ops->init(i);
194 if (!new_crypt->ops || !new_crypt->priv) {
195 kfree(new_crypt);
196 new_crypt = NULL;
197
198 printk(KERN_WARNING "%s: could not initialize WEP: "
199 "load module hostap_crypt_wep.o\n",
200 dev->name);
201 return -EOPNOTSUPP;
202 }
203 *crypt = new_crypt;
204 }
205
206 if (erq->length > 0) {
207 int len = erq->length <= 5 ? 5 : 13;
208 int first = 1, j;
209 if (len > erq->length)
210 memset(keybuf + erq->length, 0, len - erq->length);
211 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
212 for (j = 0; j < WEP_KEYS; j++) {
213 if (j != i && local->crypt[j]) {
214 first = 0;
215 break;
216 }
217 }
218 if (first)
219 local->tx_keyidx = i;
220 } else {
221 /* No key data - just set the default TX key index */
222 local->tx_keyidx = i;
223 }
224
225 done:
226 local->open_wep = erq->flags & IW_ENCODE_OPEN;
227
228 if (hostap_set_encryption(local)) {
229 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
230 return -EINVAL;
231 }
232
233 /* Do not reset port0 if card is in Managed mode since resetting will
234 * generate new IEEE 802.11 authentication which may end up in looping
235 * with IEEE 802.1X. Prism2 documentation seem to require port reset
236 * after WEP configuration. However, keys are apparently changed at
237 * least in Managed mode. */
238 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
239 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
240 return -EINVAL;
241 }
242
243 return 0;
244}
245
246
247static int prism2_ioctl_giwencode(struct net_device *dev,
248 struct iw_request_info *info,
249 struct iw_point *erq, char *key)
250{
251 struct hostap_interface *iface;
252 local_info_t *local;
253 int i, len;
254 u16 val;
255 struct ieee80211_crypt_data *crypt;
256
257 iface = netdev_priv(dev);
258 local = iface->local;
259
260 i = erq->flags & IW_ENCODE_INDEX;
261 if (i < 1 || i > 4)
262 i = local->tx_keyidx;
263 else
264 i--;
265 if (i < 0 || i >= WEP_KEYS)
266 return -EINVAL;
267
268 crypt = local->crypt[i];
269 erq->flags = i + 1;
270
271 if (crypt == NULL || crypt->ops == NULL) {
272 erq->length = 0;
273 erq->flags |= IW_ENCODE_DISABLED;
274 return 0;
275 }
276
277 if (strcmp(crypt->ops->name, "WEP") != 0) {
278 /* only WEP is supported with wireless extensions, so just
279 * report that encryption is used */
280 erq->length = 0;
281 erq->flags |= IW_ENCODE_ENABLED;
282 return 0;
283 }
284
285 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
286 * the keys from driver buffer */
287 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
288 erq->length = (len >= 0 ? len : 0);
289
290 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
291 {
292 printk("CNFWEPFLAGS reading failed\n");
293 return -EOPNOTSUPP;
294 }
295 le16_to_cpus(&val);
296 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
297 erq->flags |= IW_ENCODE_ENABLED;
298 else
299 erq->flags |= IW_ENCODE_DISABLED;
300 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
301 erq->flags |= IW_ENCODE_RESTRICTED;
302 else
303 erq->flags |= IW_ENCODE_OPEN;
304
305 return 0;
306}
307
308
309static int hostap_set_rate(struct net_device *dev)
310{
311 struct hostap_interface *iface;
312 local_info_t *local;
313 int ret, basic_rates;
314
315 iface = netdev_priv(dev);
316 local = iface->local;
317
318 basic_rates = local->basic_rates & local->tx_rate_control;
319 if (!basic_rates || basic_rates != local->basic_rates) {
320 printk(KERN_INFO "%s: updating basic rate set automatically "
321 "to match with the new supported rate set\n",
322 dev->name);
323 if (!basic_rates)
324 basic_rates = local->tx_rate_control;
325
326 local->basic_rates = basic_rates;
327 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
328 basic_rates))
329 printk(KERN_WARNING "%s: failed to set "
330 "cnfBasicRates\n", dev->name);
331 }
332
333 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
334 local->tx_rate_control) ||
335 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
336 local->tx_rate_control) ||
337 local->func->reset_port(dev));
338
339 if (ret) {
340 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
341 "setting to 0x%x failed\n",
342 dev->name, local->tx_rate_control);
343 }
344
345 /* Update TX rate configuration for all STAs based on new operational
346 * rate set. */
347 hostap_update_rates(local);
348
349 return ret;
350}
351
352
353static int prism2_ioctl_siwrate(struct net_device *dev,
354 struct iw_request_info *info,
355 struct iw_param *rrq, char *extra)
356{
357 struct hostap_interface *iface;
358 local_info_t *local;
359
360 iface = netdev_priv(dev);
361 local = iface->local;
362
363 if (rrq->fixed) {
364 switch (rrq->value) {
365 case 11000000:
366 local->tx_rate_control = HFA384X_RATES_11MBPS;
367 break;
368 case 5500000:
369 local->tx_rate_control = HFA384X_RATES_5MBPS;
370 break;
371 case 2000000:
372 local->tx_rate_control = HFA384X_RATES_2MBPS;
373 break;
374 case 1000000:
375 local->tx_rate_control = HFA384X_RATES_1MBPS;
376 break;
377 default:
378 local->tx_rate_control = HFA384X_RATES_1MBPS |
379 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
380 HFA384X_RATES_11MBPS;
381 break;
382 }
383 } else {
384 switch (rrq->value) {
385 case 11000000:
386 local->tx_rate_control = HFA384X_RATES_1MBPS |
387 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
388 HFA384X_RATES_11MBPS;
389 break;
390 case 5500000:
391 local->tx_rate_control = HFA384X_RATES_1MBPS |
392 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
393 break;
394 case 2000000:
395 local->tx_rate_control = HFA384X_RATES_1MBPS |
396 HFA384X_RATES_2MBPS;
397 break;
398 case 1000000:
399 local->tx_rate_control = HFA384X_RATES_1MBPS;
400 break;
401 default:
402 local->tx_rate_control = HFA384X_RATES_1MBPS |
403 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
404 HFA384X_RATES_11MBPS;
405 break;
406 }
407 }
408
409 return hostap_set_rate(dev);
410}
411
412
413static int prism2_ioctl_giwrate(struct net_device *dev,
414 struct iw_request_info *info,
415 struct iw_param *rrq, char *extra)
416{
417 u16 val;
418 struct hostap_interface *iface;
419 local_info_t *local;
420 int ret = 0;
421
422 iface = netdev_priv(dev);
423 local = iface->local;
424
425 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
426 0)
427 return -EINVAL;
428
429 if ((val & 0x1) && (val > 1))
430 rrq->fixed = 0;
431 else
432 rrq->fixed = 1;
433
434 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
435 !local->fw_tx_rate_control) {
436 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
437 * Host AP mode, so use the recorded TX rate of the last sent
438 * frame */
439 rrq->value = local->ap->last_tx_rate > 0 ?
440 local->ap->last_tx_rate * 100000 : 11000000;
441 return 0;
442 }
443
444 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
445 0)
446 return -EINVAL;
447
448 switch (val) {
449 case HFA384X_RATES_1MBPS:
450 rrq->value = 1000000;
451 break;
452 case HFA384X_RATES_2MBPS:
453 rrq->value = 2000000;
454 break;
455 case HFA384X_RATES_5MBPS:
456 rrq->value = 5500000;
457 break;
458 case HFA384X_RATES_11MBPS:
459 rrq->value = 11000000;
460 break;
461 default:
462 /* should not happen */
463 rrq->value = 11000000;
464 ret = -EINVAL;
465 break;
466 }
467
468 return ret;
469}
470
471
472static int prism2_ioctl_siwsens(struct net_device *dev,
473 struct iw_request_info *info,
474 struct iw_param *sens, char *extra)
475{
476 struct hostap_interface *iface;
477 local_info_t *local;
478
479 iface = netdev_priv(dev);
480 local = iface->local;
481
482 /* Set the desired AP density */
483 if (sens->value < 1 || sens->value > 3)
484 return -EINVAL;
485
486 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
487 local->func->reset_port(dev))
488 return -EINVAL;
489
490 return 0;
491}
492
493static int prism2_ioctl_giwsens(struct net_device *dev,
494 struct iw_request_info *info,
495 struct iw_param *sens, char *extra)
496{
497 struct hostap_interface *iface;
498 local_info_t *local;
499 u16 val;
500
501 iface = netdev_priv(dev);
502 local = iface->local;
503
504 /* Get the current AP density */
505 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
506 0)
507 return -EINVAL;
508
509 sens->value = __le16_to_cpu(val);
510 sens->fixed = 1;
511
512 return 0;
513}
514
515
516/* Deprecated in new wireless extension API */
517static int prism2_ioctl_giwaplist(struct net_device *dev,
518 struct iw_request_info *info,
519 struct iw_point *data, char *extra)
520{
521 struct hostap_interface *iface;
522 local_info_t *local;
523 struct sockaddr *addr;
524 struct iw_quality *qual;
525
526 iface = netdev_priv(dev);
527 local = iface->local;
528
529 if (local->iw_mode != IW_MODE_MASTER) {
530 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
531 "in Host AP mode\n");
532 data->length = 0;
533 return -EOPNOTSUPP;
534 }
535
536 addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
537 qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
538 if (addr == NULL || qual == NULL) {
539 kfree(addr);
540 kfree(qual);
541 data->length = 0;
542 return -ENOMEM;
543 }
544
545 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
546
547 memcpy(extra, &addr, sizeof(struct sockaddr) * data->length);
548 data->flags = 1; /* has quality information */
549 memcpy(extra + sizeof(struct sockaddr) * data->length, &qual,
550 sizeof(struct iw_quality) * data->length);
551
552 kfree(addr);
553 kfree(qual);
554
555 return 0;
556}
557
558
559static int prism2_ioctl_siwrts(struct net_device *dev,
560 struct iw_request_info *info,
561 struct iw_param *rts, char *extra)
562{
563 struct hostap_interface *iface;
564 local_info_t *local;
565 u16 val;
566
567 iface = netdev_priv(dev);
568 local = iface->local;
569
570 if (rts->disabled)
571 val = __constant_cpu_to_le16(2347);
572 else if (rts->value < 0 || rts->value > 2347)
573 return -EINVAL;
574 else
575 val = __cpu_to_le16(rts->value);
576
577 if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
578 local->func->reset_port(dev))
579 return -EINVAL;
580
581 local->rts_threshold = rts->value;
582
583 return 0;
584}
585
586static int prism2_ioctl_giwrts(struct net_device *dev,
587 struct iw_request_info *info,
588 struct iw_param *rts, char *extra)
589{
590 struct hostap_interface *iface;
591 local_info_t *local;
592 u16 val;
593
594 iface = netdev_priv(dev);
595 local = iface->local;
596
597 if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
598 0)
599 return -EINVAL;
600
601 rts->value = __le16_to_cpu(val);
602 rts->disabled = (rts->value == 2347);
603 rts->fixed = 1;
604
605 return 0;
606}
607
608
609static int prism2_ioctl_siwfrag(struct net_device *dev,
610 struct iw_request_info *info,
611 struct iw_param *rts, char *extra)
612{
613 struct hostap_interface *iface;
614 local_info_t *local;
615 u16 val;
616
617 iface = netdev_priv(dev);
618 local = iface->local;
619
620 if (rts->disabled)
621 val = __constant_cpu_to_le16(2346);
622 else if (rts->value < 256 || rts->value > 2346)
623 return -EINVAL;
624 else
625 val = __cpu_to_le16(rts->value & ~0x1); /* even numbers only */
626
627 local->fragm_threshold = rts->value & ~0x1;
628 if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
629 2)
630 || local->func->reset_port(dev))
631 return -EINVAL;
632
633 return 0;
634}
635
636static int prism2_ioctl_giwfrag(struct net_device *dev,
637 struct iw_request_info *info,
638 struct iw_param *rts, char *extra)
639{
640 struct hostap_interface *iface;
641 local_info_t *local;
642 u16 val;
643
644 iface = netdev_priv(dev);
645 local = iface->local;
646
647 if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
648 &val, 2, 1) < 0)
649 return -EINVAL;
650
651 rts->value = __le16_to_cpu(val);
652 rts->disabled = (rts->value == 2346);
653 rts->fixed = 1;
654
655 return 0;
656}
657
658
659#ifndef PRISM2_NO_STATION_MODES
660static int hostap_join_ap(struct net_device *dev)
661{
662 struct hostap_interface *iface;
663 local_info_t *local;
664 struct hfa384x_join_request req;
665 unsigned long flags;
666 int i;
667 struct hfa384x_hostscan_result *entry;
668
669 iface = netdev_priv(dev);
670 local = iface->local;
671
672 memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
673 req.channel = 0;
674
675 spin_lock_irqsave(&local->lock, flags);
676 for (i = 0; i < local->last_scan_results_count; i++) {
677 if (!local->last_scan_results)
678 break;
679 entry = &local->last_scan_results[i];
680 if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
681 req.channel = entry->chid;
682 break;
683 }
684 }
685 spin_unlock_irqrestore(&local->lock, flags);
686
687 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
688 sizeof(req))) {
689 printk(KERN_DEBUG "%s: JoinRequest " MACSTR
690 " failed\n",
691 dev->name, MAC2STR(local->preferred_ap));
692 return -1;
693 }
694
695 printk(KERN_DEBUG "%s: Trying to join BSSID " MACSTR "\n",
696 dev->name, MAC2STR(local->preferred_ap));
697
698 return 0;
699}
700#endif /* PRISM2_NO_STATION_MODES */
701
702
703static int prism2_ioctl_siwap(struct net_device *dev,
704 struct iw_request_info *info,
705 struct sockaddr *ap_addr, char *extra)
706{
707#ifdef PRISM2_NO_STATION_MODES
708 return -EOPNOTSUPP;
709#else /* PRISM2_NO_STATION_MODES */
710 struct hostap_interface *iface;
711 local_info_t *local;
712
713 iface = netdev_priv(dev);
714 local = iface->local;
715
716 memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
717
718 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
719 struct hfa384x_scan_request scan_req;
720 memset(&scan_req, 0, sizeof(scan_req));
721 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
722 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
723 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
724 &scan_req, sizeof(scan_req))) {
725 printk(KERN_DEBUG "%s: ScanResults request failed - "
726 "preferred AP delayed to next unsolicited "
727 "scan\n", dev->name);
728 }
729 } else if (local->host_roaming == 2 &&
730 local->iw_mode == IW_MODE_INFRA) {
731 if (hostap_join_ap(dev))
732 return -EINVAL;
733 } else {
734 printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
735 "in Managed mode when host_roaming is enabled\n",
736 dev->name);
737 }
738
739 return 0;
740#endif /* PRISM2_NO_STATION_MODES */
741}
742
743static int prism2_ioctl_giwap(struct net_device *dev,
744 struct iw_request_info *info,
745 struct sockaddr *ap_addr, char *extra)
746{
747 struct hostap_interface *iface;
748 local_info_t *local;
749
750 iface = netdev_priv(dev);
751 local = iface->local;
752
753 ap_addr->sa_family = ARPHRD_ETHER;
754 switch (iface->type) {
755 case HOSTAP_INTERFACE_AP:
756 memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
757 break;
758 case HOSTAP_INTERFACE_STA:
759 memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
760 break;
761 case HOSTAP_INTERFACE_WDS:
762 memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
763 break;
764 default:
765 if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
766 &ap_addr->sa_data, ETH_ALEN, 1) < 0)
767 return -EOPNOTSUPP;
768
769 /* local->bssid is also updated in LinkStatus handler when in
770 * station mode */
771 memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
772 break;
773 }
774
775 return 0;
776}
777
778
779static int prism2_ioctl_siwnickn(struct net_device *dev,
780 struct iw_request_info *info,
781 struct iw_point *data, char *nickname)
782{
783 struct hostap_interface *iface;
784 local_info_t *local;
785
786 iface = netdev_priv(dev);
787 local = iface->local;
788
789 memset(local->name, 0, sizeof(local->name));
790 memcpy(local->name, nickname, data->length);
791 local->name_set = 1;
792
793 if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
794 local->func->reset_port(dev))
795 return -EINVAL;
796
797 return 0;
798}
799
800static int prism2_ioctl_giwnickn(struct net_device *dev,
801 struct iw_request_info *info,
802 struct iw_point *data, char *nickname)
803{
804 struct hostap_interface *iface;
805 local_info_t *local;
806 int len;
807 char name[MAX_NAME_LEN + 3];
808 u16 val;
809
810 iface = netdev_priv(dev);
811 local = iface->local;
812
813 len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
814 &name, MAX_NAME_LEN + 2, 0);
815 val = __le16_to_cpu(*(u16 *) name);
816 if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
817 return -EOPNOTSUPP;
818
819 name[val + 2] = '\0';
820 data->length = val + 1;
821 memcpy(nickname, name + 2, val + 1);
822
823 return 0;
824}
825
826
827static int prism2_ioctl_siwfreq(struct net_device *dev,
828 struct iw_request_info *info,
829 struct iw_freq *freq, char *extra)
830{
831 struct hostap_interface *iface;
832 local_info_t *local;
833
834 iface = netdev_priv(dev);
835 local = iface->local;
836
837 /* freq => chan. */
838 if (freq->e == 1 &&
839 freq->m / 100000 >= freq_list[0] &&
840 freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
841 int ch;
842 int fr = freq->m / 100000;
843 for (ch = 0; ch < FREQ_COUNT; ch++) {
844 if (fr == freq_list[ch]) {
845 freq->e = 0;
846 freq->m = ch + 1;
847 break;
848 }
849 }
850 }
851
852 if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
853 !(local->channel_mask & (1 << (freq->m - 1))))
854 return -EINVAL;
855
856 local->channel = freq->m; /* channel is used in prism2_setup_rids() */
857 if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
858 local->func->reset_port(dev))
859 return -EINVAL;
860
861 return 0;
862}
863
864static int prism2_ioctl_giwfreq(struct net_device *dev,
865 struct iw_request_info *info,
866 struct iw_freq *freq, char *extra)
867{
868 struct hostap_interface *iface;
869 local_info_t *local;
870 u16 val;
871
872 iface = netdev_priv(dev);
873 local = iface->local;
874
875 if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
876 0)
877 return -EINVAL;
878
879 le16_to_cpus(&val);
880 if (val < 1 || val > FREQ_COUNT)
881 return -EINVAL;
882
883 freq->m = freq_list[val - 1] * 100000;
884 freq->e = 1;
885
886 return 0;
887}
888
889
890static void hostap_monitor_set_type(local_info_t *local)
891{
892 struct net_device *dev = local->ddev;
893
894 if (dev == NULL)
895 return;
896
897 if (local->monitor_type == PRISM2_MONITOR_PRISM ||
898 local->monitor_type == PRISM2_MONITOR_CAPHDR) {
899 dev->type = ARPHRD_IEEE80211_PRISM;
900 dev->hard_header_parse =
901 hostap_80211_prism_header_parse;
902 } else {
903 dev->type = ARPHRD_IEEE80211;
904 dev->hard_header_parse = hostap_80211_header_parse;
905 }
906}
907
908
909static int prism2_ioctl_siwessid(struct net_device *dev,
910 struct iw_request_info *info,
911 struct iw_point *data, char *ssid)
912{
913 struct hostap_interface *iface;
914 local_info_t *local;
915
916 iface = netdev_priv(dev);
917 local = iface->local;
918
919 if (iface->type == HOSTAP_INTERFACE_WDS)
920 return -EOPNOTSUPP;
921
922 if (data->flags == 0)
923 ssid[0] = '\0'; /* ANY */
924
925 if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
926 /* Setting SSID to empty string seems to kill the card in
927 * Host AP mode */
928 printk(KERN_DEBUG "%s: Host AP mode does not support "
929 "'Any' essid\n", dev->name);
930 return -EINVAL;
931 }
932
933 memcpy(local->essid, ssid, data->length);
934 local->essid[data->length] = '\0';
935
936 if ((!local->fw_ap &&
937 hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
938 || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
939 local->func->reset_port(dev))
940 return -EINVAL;
941
942 return 0;
943}
944
945static int prism2_ioctl_giwessid(struct net_device *dev,
946 struct iw_request_info *info,
947 struct iw_point *data, char *essid)
948{
949 struct hostap_interface *iface;
950 local_info_t *local;
951 u16 val;
952
953 iface = netdev_priv(dev);
954 local = iface->local;
955
956 if (iface->type == HOSTAP_INTERFACE_WDS)
957 return -EOPNOTSUPP;
958
959 data->flags = 1; /* active */
960 if (local->iw_mode == IW_MODE_MASTER) {
961 data->length = strlen(local->essid);
962 memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
963 } else {
964 int len;
965 char ssid[MAX_SSID_LEN + 2];
966 memset(ssid, 0, sizeof(ssid));
967 len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
968 &ssid, MAX_SSID_LEN + 2, 0);
969 val = __le16_to_cpu(*(u16 *) ssid);
970 if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
971 return -EOPNOTSUPP;
972 }
973 data->length = val;
974 memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
975 }
976
977 return 0;
978}
979
980
981static int prism2_ioctl_giwrange(struct net_device *dev,
982 struct iw_request_info *info,
983 struct iw_point *data, char *extra)
984{
985 struct hostap_interface *iface;
986 local_info_t *local;
987 struct iw_range *range = (struct iw_range *) extra;
988 u8 rates[10];
989 u16 val;
990 int i, len, over2;
991
992 iface = netdev_priv(dev);
993 local = iface->local;
994
995 data->length = sizeof(struct iw_range);
996 memset(range, 0, sizeof(struct iw_range));
997
998 /* TODO: could fill num_txpower and txpower array with
999 * something; however, there are 128 different values.. */
1000
1001 range->txpower_capa = IW_TXPOW_DBM;
1002
1003 if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
1004 {
1005 range->min_pmp = 1 * 1024;
1006 range->max_pmp = 65535 * 1024;
1007 range->min_pmt = 1 * 1024;
1008 range->max_pmt = 1000 * 1024;
1009 range->pmp_flags = IW_POWER_PERIOD;
1010 range->pmt_flags = IW_POWER_TIMEOUT;
1011 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
1012 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
1013 }
1014
1015 range->we_version_compiled = WIRELESS_EXT;
1016 range->we_version_source = 18;
1017
1018 range->retry_capa = IW_RETRY_LIMIT;
1019 range->retry_flags = IW_RETRY_LIMIT;
1020 range->min_retry = 0;
1021 range->max_retry = 255;
1022
1023 range->num_channels = FREQ_COUNT;
1024
1025 val = 0;
1026 for (i = 0; i < FREQ_COUNT; i++) {
1027 if (local->channel_mask & (1 << i)) {
1028 range->freq[val].i = i + 1;
1029 range->freq[val].m = freq_list[i] * 100000;
1030 range->freq[val].e = 1;
1031 val++;
1032 }
1033 if (val == IW_MAX_FREQUENCIES)
1034 break;
1035 }
1036 range->num_frequency = val;
1037
1038 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1039 range->max_qual.qual = 70; /* what is correct max? This was not
1040 * documented exactly. At least
1041 * 69 has been observed. */
1042 range->max_qual.level = 0; /* dB */
1043 range->max_qual.noise = 0; /* dB */
1044
1045 /* What would be suitable values for "average/typical" qual? */
1046 range->avg_qual.qual = 20;
1047 range->avg_qual.level = -60;
1048 range->avg_qual.noise = -95;
1049 } else {
1050 range->max_qual.qual = 92; /* 0 .. 92 */
1051 range->max_qual.level = 154; /* 27 .. 154 */
1052 range->max_qual.noise = 154; /* 27 .. 154 */
1053 }
1054 range->sensitivity = 3;
1055
1056 range->max_encoding_tokens = WEP_KEYS;
1057 range->num_encoding_sizes = 2;
1058 range->encoding_size[0] = 5;
1059 range->encoding_size[1] = 13;
1060
1061 over2 = 0;
1062 len = prism2_get_datarates(dev, rates);
1063 range->num_bitrates = 0;
1064 for (i = 0; i < len; i++) {
1065 if (range->num_bitrates < IW_MAX_BITRATES) {
1066 range->bitrate[range->num_bitrates] =
1067 rates[i] * 500000;
1068 range->num_bitrates++;
1069 }
1070 if (rates[i] == 0x0b || rates[i] == 0x16)
1071 over2 = 1;
1072 }
1073 /* estimated maximum TCP throughput values (bps) */
1074 range->throughput = over2 ? 5500000 : 1500000;
1075
1076 range->min_rts = 0;
1077 range->max_rts = 2347;
1078 range->min_frag = 256;
1079 range->max_frag = 2346;
1080
1081 /* Event capability (kernel + driver) */
1082 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1083 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1084 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1085 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1086 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1087 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1088 IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1089 IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1090 IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1091
1092 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1093 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1094
1095 return 0;
1096}
1097
1098
1099static int hostap_monitor_mode_enable(local_info_t *local)
1100{
1101 struct net_device *dev = local->dev;
1102
1103 printk(KERN_DEBUG "Enabling monitor mode\n");
1104 hostap_monitor_set_type(local);
1105
1106 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1107 HFA384X_PORTTYPE_PSEUDO_IBSS)) {
1108 printk(KERN_DEBUG "Port type setting for monitor mode "
1109 "failed\n");
1110 return -EOPNOTSUPP;
1111 }
1112
1113 /* Host decrypt is needed to get the IV and ICV fields;
1114 * however, monitor mode seems to remove WEP flag from frame
1115 * control field */
1116 if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
1117 HFA384X_WEPFLAGS_HOSTENCRYPT |
1118 HFA384X_WEPFLAGS_HOSTDECRYPT)) {
1119 printk(KERN_DEBUG "WEP flags setting failed\n");
1120 return -EOPNOTSUPP;
1121 }
1122
1123 if (local->func->reset_port(dev) ||
1124 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1125 (HFA384X_TEST_MONITOR << 8),
1126 0, NULL, NULL)) {
1127 printk(KERN_DEBUG "Setting monitor mode failed\n");
1128 return -EOPNOTSUPP;
1129 }
1130
1131 return 0;
1132}
1133
1134
1135static int hostap_monitor_mode_disable(local_info_t *local)
1136{
1137 struct net_device *dev = local->ddev;
1138
1139 if (dev == NULL)
1140 return -1;
1141
1142 printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
1143 dev->type = ARPHRD_ETHER;
1144 dev->hard_header_parse = local->saved_eth_header_parse;
1145 if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1146 (HFA384X_TEST_STOP << 8),
1147 0, NULL, NULL))
1148 return -1;
1149 return hostap_set_encryption(local);
1150}
1151
1152
1153static int prism2_ioctl_siwmode(struct net_device *dev,
1154 struct iw_request_info *info,
1155 __u32 *mode, char *extra)
1156{
1157 struct hostap_interface *iface;
1158 local_info_t *local;
1159 int double_reset = 0;
1160
1161 iface = netdev_priv(dev);
1162 local = iface->local;
1163
1164 if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
1165 *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
1166 *mode != IW_MODE_MONITOR)
1167 return -EOPNOTSUPP;
1168
1169#ifdef PRISM2_NO_STATION_MODES
1170 if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
1171 return -EOPNOTSUPP;
1172#endif /* PRISM2_NO_STATION_MODES */
1173
1174 if (*mode == local->iw_mode)
1175 return 0;
1176
1177 if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
1178 printk(KERN_WARNING "%s: empty SSID not allowed in Master "
1179 "mode\n", dev->name);
1180 return -EINVAL;
1181 }
1182
1183 if (local->iw_mode == IW_MODE_MONITOR)
1184 hostap_monitor_mode_disable(local);
1185
1186 if ((local->iw_mode == IW_MODE_ADHOC ||
1187 local->iw_mode == IW_MODE_MONITOR) && *mode == IW_MODE_MASTER) {
1188 /* There seems to be a firmware bug in at least STA f/w v1.5.6
1189 * that leaves beacon frames to use IBSS type when moving from
1190 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1191 * enough to workaround this. */
1192 double_reset = 1;
1193 }
1194
1195 printk(KERN_DEBUG "prism2: %s: operating mode changed "
1196 "%d -> %d\n", dev->name, local->iw_mode, *mode);
1197 local->iw_mode = *mode;
1198
1199 if (local->iw_mode == IW_MODE_MONITOR)
1200 hostap_monitor_mode_enable(local);
1201 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1202 !local->fw_encrypt_ok) {
1203 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1204 "a workaround for firmware bug in Host AP mode WEP\n",
1205 dev->name);
1206 local->host_encrypt = 1;
1207 }
1208
1209 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1210 hostap_get_porttype(local)))
1211 return -EOPNOTSUPP;
1212
1213 if (local->func->reset_port(dev))
1214 return -EINVAL;
1215 if (double_reset && local->func->reset_port(dev))
1216 return -EINVAL;
1217
1218 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1219 {
1220 /* netif_carrier is used only in client modes for now, so make
1221 * sure carrier is on when moving to non-client modes. */
1222 netif_carrier_on(local->dev);
1223 netif_carrier_on(local->ddev);
1224 }
1225 return 0;
1226}
1227
1228
1229static int prism2_ioctl_giwmode(struct net_device *dev,
1230 struct iw_request_info *info,
1231 __u32 *mode, char *extra)
1232{
1233 struct hostap_interface *iface;
1234 local_info_t *local;
1235
1236 iface = netdev_priv(dev);
1237 local = iface->local;
1238
1239 switch (iface->type) {
1240 case HOSTAP_INTERFACE_STA:
1241 *mode = IW_MODE_INFRA;
1242 break;
1243 case HOSTAP_INTERFACE_WDS:
1244 *mode = IW_MODE_REPEAT;
1245 break;
1246 default:
1247 *mode = local->iw_mode;
1248 break;
1249 }
1250 return 0;
1251}
1252
1253
1254static int prism2_ioctl_siwpower(struct net_device *dev,
1255 struct iw_request_info *info,
1256 struct iw_param *wrq, char *extra)
1257{
1258#ifdef PRISM2_NO_STATION_MODES
1259 return -EOPNOTSUPP;
1260#else /* PRISM2_NO_STATION_MODES */
1261 int ret = 0;
1262
1263 if (wrq->disabled)
1264 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1265
1266 switch (wrq->flags & IW_POWER_MODE) {
1267 case IW_POWER_UNICAST_R:
1268 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1269 if (ret)
1270 return ret;
1271 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1272 if (ret)
1273 return ret;
1274 break;
1275 case IW_POWER_ALL_R:
1276 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1277 if (ret)
1278 return ret;
1279 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1280 if (ret)
1281 return ret;
1282 break;
1283 case IW_POWER_ON:
1284 break;
1285 default:
1286 return -EINVAL;
1287 }
1288
1289 if (wrq->flags & IW_POWER_TIMEOUT) {
1290 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1291 if (ret)
1292 return ret;
1293 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1294 wrq->value / 1024);
1295 if (ret)
1296 return ret;
1297 }
1298 if (wrq->flags & IW_POWER_PERIOD) {
1299 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1300 if (ret)
1301 return ret;
1302 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1303 wrq->value / 1024);
1304 if (ret)
1305 return ret;
1306 }
1307
1308 return ret;
1309#endif /* PRISM2_NO_STATION_MODES */
1310}
1311
1312
1313static int prism2_ioctl_giwpower(struct net_device *dev,
1314 struct iw_request_info *info,
1315 struct iw_param *rrq, char *extra)
1316{
1317#ifdef PRISM2_NO_STATION_MODES
1318 return -EOPNOTSUPP;
1319#else /* PRISM2_NO_STATION_MODES */
1320 struct hostap_interface *iface;
1321 local_info_t *local;
1322 u16 enable, mcast;
1323
1324 iface = netdev_priv(dev);
1325 local = iface->local;
1326
1327 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1328 < 0)
1329 return -EINVAL;
1330
1331 if (!__le16_to_cpu(enable)) {
1332 rrq->disabled = 1;
1333 return 0;
1334 }
1335
1336 rrq->disabled = 0;
1337
1338 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1339 u16 timeout;
1340 if (local->func->get_rid(dev,
1341 HFA384X_RID_CNFPMHOLDOVERDURATION,
1342 &timeout, 2, 1) < 0)
1343 return -EINVAL;
1344
1345 rrq->flags = IW_POWER_TIMEOUT;
1346 rrq->value = __le16_to_cpu(timeout) * 1024;
1347 } else {
1348 u16 period;
1349 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1350 &period, 2, 1) < 0)
1351 return -EINVAL;
1352
1353 rrq->flags = IW_POWER_PERIOD;
1354 rrq->value = __le16_to_cpu(period) * 1024;
1355 }
1356
1357 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1358 2, 1) < 0)
1359 return -EINVAL;
1360
1361 if (__le16_to_cpu(mcast))
1362 rrq->flags |= IW_POWER_ALL_R;
1363 else
1364 rrq->flags |= IW_POWER_UNICAST_R;
1365
1366 return 0;
1367#endif /* PRISM2_NO_STATION_MODES */
1368}
1369
1370
1371static int prism2_ioctl_siwretry(struct net_device *dev,
1372 struct iw_request_info *info,
1373 struct iw_param *rrq, char *extra)
1374{
1375 struct hostap_interface *iface;
1376 local_info_t *local;
1377
1378 iface = netdev_priv(dev);
1379 local = iface->local;
1380
1381 if (rrq->disabled)
1382 return -EINVAL;
1383
1384 /* setting retry limits is not supported with the current station
1385 * firmware code; simulate this with alternative retry count for now */
1386 if (rrq->flags == IW_RETRY_LIMIT) {
1387 if (rrq->value < 0) {
1388 /* disable manual retry count setting and use firmware
1389 * defaults */
1390 local->manual_retry_count = -1;
1391 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1392 } else {
1393 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1394 rrq->value)) {
1395 printk(KERN_DEBUG "%s: Alternate retry count "
1396 "setting to %d failed\n",
1397 dev->name, rrq->value);
1398 return -EOPNOTSUPP;
1399 }
1400
1401 local->manual_retry_count = rrq->value;
1402 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1403 }
1404 return 0;
1405 }
1406
1407 return -EOPNOTSUPP;
1408
1409#if 0
1410 /* what could be done, if firmware would support this.. */
1411
1412 if (rrq->flags & IW_RETRY_LIMIT) {
1413 if (rrq->flags & IW_RETRY_MAX)
1414 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1415 else if (rrq->flags & IW_RETRY_MIN)
1416 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1417 else {
1418 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1419 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1420 }
1421
1422 }
1423
1424 if (rrq->flags & IW_RETRY_LIFETIME) {
1425 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1426 }
1427
1428 return 0;
1429#endif /* 0 */
1430}
1431
1432static int prism2_ioctl_giwretry(struct net_device *dev,
1433 struct iw_request_info *info,
1434 struct iw_param *rrq, char *extra)
1435{
1436 struct hostap_interface *iface;
1437 local_info_t *local;
1438 u16 shortretry, longretry, lifetime, altretry;
1439
1440 iface = netdev_priv(dev);
1441 local = iface->local;
1442
1443 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1444 2, 1) < 0 ||
1445 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1446 2, 1) < 0 ||
1447 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1448 &lifetime, 2, 1) < 0)
1449 return -EINVAL;
1450
1451 le16_to_cpus(&shortretry);
1452 le16_to_cpus(&longretry);
1453 le16_to_cpus(&lifetime);
1454
1455 rrq->disabled = 0;
1456
1457 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1458 rrq->flags = IW_RETRY_LIFETIME;
1459 rrq->value = lifetime * 1024;
1460 } else {
1461 if (local->manual_retry_count >= 0) {
1462 rrq->flags = IW_RETRY_LIMIT;
1463 if (local->func->get_rid(dev,
1464 HFA384X_RID_CNFALTRETRYCOUNT,
1465 &altretry, 2, 1) >= 0)
1466 rrq->value = le16_to_cpu(altretry);
1467 else
1468 rrq->value = local->manual_retry_count;
1469 } else if ((rrq->flags & IW_RETRY_MAX)) {
1470 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1471 rrq->value = longretry;
1472 } else {
1473 rrq->flags = IW_RETRY_LIMIT;
1474 rrq->value = shortretry;
1475 if (shortretry != longretry)
1476 rrq->flags |= IW_RETRY_MIN;
1477 }
1478 }
1479 return 0;
1480}
1481
1482
1483/* Note! This TX power controlling is experimental and should not be used in
1484 * production use. It just sets raw power register and does not use any kind of
1485 * feedback information from the measured TX power (CR58). This is now
1486 * commented out to make sure that it is not used by accident. TX power
1487 * configuration will be enabled again after proper algorithm using feedback
1488 * has been implemented. */
1489
1490#ifdef RAW_TXPOWER_SETTING
1491/* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1492 * This version assumes following mapping:
1493 * CR31 is 7-bit value with -64 to +63 range.
1494 * -64 is mapped into +20dBm and +63 into -43dBm.
1495 * This is certainly not an exact mapping for every card, but at least
1496 * increasing dBm value should correspond to increasing TX power.
1497 */
1498
1499static int prism2_txpower_hfa386x_to_dBm(u16 val)
1500{
1501 signed char tmp;
1502
1503 if (val > 255)
1504 val = 255;
1505
1506 tmp = val;
1507 tmp >>= 2;
1508
1509 return -12 - tmp;
1510}
1511
1512static u16 prism2_txpower_dBm_to_hfa386x(int val)
1513{
1514 signed char tmp;
1515
1516 if (val > 20)
1517 return 128;
1518 else if (val < -43)
1519 return 127;
1520
1521 tmp = val;
1522 tmp = -12 - tmp;
1523 tmp <<= 2;
1524
1525 return (unsigned char) tmp;
1526}
1527#endif /* RAW_TXPOWER_SETTING */
1528
1529
1530static int prism2_ioctl_siwtxpow(struct net_device *dev,
1531 struct iw_request_info *info,
1532 struct iw_param *rrq, char *extra)
1533{
1534 struct hostap_interface *iface;
1535 local_info_t *local;
1536#ifdef RAW_TXPOWER_SETTING
1537 char *tmp;
1538#endif
1539 u16 val;
1540 int ret = 0;
1541
1542 iface = netdev_priv(dev);
1543 local = iface->local;
1544
1545 if (rrq->disabled) {
1546 if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1547 val = 0xff; /* use all standby and sleep modes */
1548 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1549 HFA386X_CR_A_D_TEST_MODES2,
1550 &val, NULL);
1551 printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1552 dev->name, ret ? "failed" : "OK");
1553 local->txpower_type = PRISM2_TXPOWER_OFF;
1554 }
1555 return (ret ? -EOPNOTSUPP : 0);
1556 }
1557
1558 if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1559 val = 0; /* disable all standby and sleep modes */
1560 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1561 HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1562 printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1563 dev->name, ret ? "failed" : "OK");
1564 local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1565 }
1566
1567#ifdef RAW_TXPOWER_SETTING
1568 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1569 printk(KERN_DEBUG "Setting ALC on\n");
1570 val = HFA384X_TEST_CFG_BIT_ALC;
1571 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1572 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1573 local->txpower_type = PRISM2_TXPOWER_AUTO;
1574 return 0;
1575 }
1576
1577 if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1578 printk(KERN_DEBUG "Setting ALC off\n");
1579 val = HFA384X_TEST_CFG_BIT_ALC;
1580 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1581 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1582 local->txpower_type = PRISM2_TXPOWER_FIXED;
1583 }
1584
1585 if (rrq->flags == IW_TXPOW_DBM)
1586 tmp = "dBm";
1587 else if (rrq->flags == IW_TXPOW_MWATT)
1588 tmp = "mW";
1589 else
1590 tmp = "UNKNOWN";
1591 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1592
1593 if (rrq->flags != IW_TXPOW_DBM) {
1594 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1595 return -EOPNOTSUPP;
1596 }
1597
1598 local->txpower = rrq->value;
1599 val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1600 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1601 HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1602 ret = -EOPNOTSUPP;
1603#else /* RAW_TXPOWER_SETTING */
1604 if (rrq->fixed)
1605 ret = -EOPNOTSUPP;
1606#endif /* RAW_TXPOWER_SETTING */
1607
1608 return ret;
1609}
1610
1611static int prism2_ioctl_giwtxpow(struct net_device *dev,
1612 struct iw_request_info *info,
1613 struct iw_param *rrq, char *extra)
1614{
1615#ifdef RAW_TXPOWER_SETTING
1616 struct hostap_interface *iface;
1617 local_info_t *local;
1618 u16 resp0;
1619
1620 iface = netdev_priv(dev);
1621 local = iface->local;
1622
1623 rrq->flags = IW_TXPOW_DBM;
1624 rrq->disabled = 0;
1625 rrq->fixed = 0;
1626
1627 if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1628 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1629 HFA386X_CR_MANUAL_TX_POWER,
1630 NULL, &resp0) == 0) {
1631 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1632 } else {
1633 /* Could not get real txpower; guess 15 dBm */
1634 rrq->value = 15;
1635 }
1636 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1637 rrq->value = 0;
1638 rrq->disabled = 1;
1639 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1640 rrq->value = local->txpower;
1641 rrq->fixed = 1;
1642 } else {
1643 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1644 local->txpower_type);
1645 }
1646 return 0;
1647#else /* RAW_TXPOWER_SETTING */
1648 return -EOPNOTSUPP;
1649#endif /* RAW_TXPOWER_SETTING */
1650}
1651
1652
1653#ifndef PRISM2_NO_STATION_MODES
1654
1655/* HostScan request works with and without host_roaming mode. In addition, it
1656 * does not break current association. However, it requires newer station
1657 * firmware version (>= 1.3.1) than scan request. */
1658static int prism2_request_hostscan(struct net_device *dev,
1659 u8 *ssid, u8 ssid_len)
1660{
1661 struct hostap_interface *iface;
1662 local_info_t *local;
1663 struct hfa384x_hostscan_request scan_req;
1664
1665 iface = netdev_priv(dev);
1666 local = iface->local;
1667
1668 memset(&scan_req, 0, sizeof(scan_req));
1669 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1670 local->scan_channel_mask);
1671 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1672 if (ssid) {
1673 if (ssid_len > 32)
1674 return -EINVAL;
1675 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1676 memcpy(scan_req.target_ssid, ssid, ssid_len);
1677 }
1678
1679 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1680 sizeof(scan_req))) {
1681 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1682 return -EINVAL;
1683 }
1684 return 0;
1685}
1686
1687
1688static int prism2_request_scan(struct net_device *dev)
1689{
1690 struct hostap_interface *iface;
1691 local_info_t *local;
1692 struct hfa384x_scan_request scan_req;
1693 int ret = 0;
1694
1695 iface = netdev_priv(dev);
1696 local = iface->local;
1697
1698 memset(&scan_req, 0, sizeof(scan_req));
1699 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1700 local->scan_channel_mask);
1701 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1702
1703 /* FIX:
1704 * It seems to be enough to set roaming mode for a short moment to
1705 * host-based and then setup scanrequest data and return the mode to
1706 * firmware-based.
1707 *
1708 * Master mode would need to drop to Managed mode for a short while
1709 * to make scanning work.. Or sweep through the different channels and
1710 * use passive scan based on beacons. */
1711
1712 if (!local->host_roaming)
1713 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1714 HFA384X_ROAMING_HOST);
1715
1716 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1717 sizeof(scan_req))) {
1718 printk(KERN_DEBUG "SCANREQUEST failed\n");
1719 ret = -EINVAL;
1720 }
1721
1722 if (!local->host_roaming)
1723 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1724 HFA384X_ROAMING_FIRMWARE);
1725
1726 return 0;
1727}
1728
1729#else /* !PRISM2_NO_STATION_MODES */
1730
1731static inline int prism2_request_hostscan(struct net_device *dev,
1732 u8 *ssid, u8 ssid_len)
1733{
1734 return -EOPNOTSUPP;
1735}
1736
1737
1738static inline int prism2_request_scan(struct net_device *dev)
1739{
1740 return -EOPNOTSUPP;
1741}
1742
1743#endif /* !PRISM2_NO_STATION_MODES */
1744
1745
1746static int prism2_ioctl_siwscan(struct net_device *dev,
1747 struct iw_request_info *info,
1748 struct iw_point *data, char *extra)
1749{
1750 struct hostap_interface *iface;
1751 local_info_t *local;
1752 int ret;
1753 u8 *ssid = NULL, ssid_len = 0;
1754 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1755
1756 iface = netdev_priv(dev);
1757 local = iface->local;
1758
1759 if (data->length < sizeof(struct iw_scan_req))
1760 req = NULL;
1761
1762 if (local->iw_mode == IW_MODE_MASTER) {
1763 /* In master mode, we just return the results of our local
1764 * tables, so we don't need to start anything...
1765 * Jean II */
1766 data->length = 0;
1767 return 0;
1768 }
1769
1770 if (!local->dev_enabled)
1771 return -ENETDOWN;
1772
1773 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1774 ssid = req->essid;
1775 ssid_len = req->essid_len;
1776
1777 if (ssid_len &&
1778 ((local->iw_mode != IW_MODE_INFRA &&
1779 local->iw_mode != IW_MODE_ADHOC) ||
1780 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1781 return -EOPNOTSUPP;
1782 }
1783
1784 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1785 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1786 else
1787 ret = prism2_request_scan(dev);
1788
1789 if (ret == 0)
1790 local->scan_timestamp = jiffies;
1791
1792 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1793
1794 return ret;
1795}
1796
1797
1798#ifndef PRISM2_NO_STATION_MODES
1799static char * __prism2_translate_scan(local_info_t *local,
1800 struct hfa384x_hostscan_result *scan,
1801 struct hostap_bss_info *bss,
1802 char *current_ev, char *end_buf)
1803{
1804 int i, chan;
1805 struct iw_event iwe;
1806 char *current_val;
1807 u16 capabilities;
1808 u8 *pos;
1809 u8 *ssid, *bssid;
1810 size_t ssid_len;
1811 char *buf;
1812
1813 if (bss) {
1814 ssid = bss->ssid;
1815 ssid_len = bss->ssid_len;
1816 bssid = bss->bssid;
1817 } else {
1818 ssid = scan->ssid;
1819 ssid_len = le16_to_cpu(scan->ssid_len);
1820 bssid = scan->bssid;
1821 }
1822 if (ssid_len > 32)
1823 ssid_len = 32;
1824
1825 /* First entry *MUST* be the AP MAC address */
1826 memset(&iwe, 0, sizeof(iwe));
1827 iwe.cmd = SIOCGIWAP;
1828 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1829 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1830 /* FIX:
1831 * I do not know how this is possible, but iwe_stream_add_event
1832 * seems to re-order memcpy execution so that len is set only
1833 * after copying.. Pre-setting len here "fixes" this, but real
1834 * problems should be solved (after which these iwe.len
1835 * settings could be removed from this function). */
1836 iwe.len = IW_EV_ADDR_LEN;
1837 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1838 IW_EV_ADDR_LEN);
1839
1840 /* Other entries will be displayed in the order we give them */
1841
1842 memset(&iwe, 0, sizeof(iwe));
1843 iwe.cmd = SIOCGIWESSID;
1844 iwe.u.data.length = ssid_len;
1845 iwe.u.data.flags = 1;
1846 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1847 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1848
1849 memset(&iwe, 0, sizeof(iwe));
1850 iwe.cmd = SIOCGIWMODE;
1851 if (bss) {
1852 capabilities = bss->capab_info;
1853 } else {
1854 capabilities = le16_to_cpu(scan->capability);
1855 }
1856 if (capabilities & (WLAN_CAPABILITY_ESS |
1857 WLAN_CAPABILITY_IBSS)) {
1858 if (capabilities & WLAN_CAPABILITY_ESS)
1859 iwe.u.mode = IW_MODE_MASTER;
1860 else
1861 iwe.u.mode = IW_MODE_ADHOC;
1862 iwe.len = IW_EV_UINT_LEN;
1863 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1864 IW_EV_UINT_LEN);
1865 }
1866
1867 memset(&iwe, 0, sizeof(iwe));
1868 iwe.cmd = SIOCGIWFREQ;
1869 if (scan) {
1870 chan = scan->chid;
1871 } else if (bss) {
1872 chan = bss->chan;
1873 } else {
1874 chan = 0;
1875 }
1876
1877 if (chan > 0) {
1878 iwe.u.freq.m = freq_list[le16_to_cpu(chan - 1)] * 100000;
1879 iwe.u.freq.e = 1;
1880 iwe.len = IW_EV_FREQ_LEN;
1881 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1882 IW_EV_FREQ_LEN);
1883 }
1884
1885 if (scan) {
1886 memset(&iwe, 0, sizeof(iwe));
1887 iwe.cmd = IWEVQUAL;
1888 if (local->last_scan_type == PRISM2_HOSTSCAN) {
1889 iwe.u.qual.level = le16_to_cpu(scan->sl);
1890 iwe.u.qual.noise = le16_to_cpu(scan->anl);
1891 } else {
1892 iwe.u.qual.level =
1893 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1894 iwe.u.qual.noise =
1895 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1896 }
1897 iwe.len = IW_EV_QUAL_LEN;
1898 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1899 IW_EV_QUAL_LEN);
1900 }
1901
1902 memset(&iwe, 0, sizeof(iwe));
1903 iwe.cmd = SIOCGIWENCODE;
1904 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1905 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1906 else
1907 iwe.u.data.flags = IW_ENCODE_DISABLED;
1908 iwe.u.data.length = 0;
1909 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1910 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1911
1912 /* TODO: add SuppRates into BSS table */
1913 if (scan) {
1914 memset(&iwe, 0, sizeof(iwe));
1915 iwe.cmd = SIOCGIWRATE;
1916 current_val = current_ev + IW_EV_LCP_LEN;
1917 pos = scan->sup_rates;
1918 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1919 if (pos[i] == 0)
1920 break;
1921 /* Bit rate given in 500 kb/s units (+ 0x80) */
1922 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1923 current_val = iwe_stream_add_value(
1924 current_ev, current_val, end_buf, &iwe,
1925 IW_EV_PARAM_LEN);
1926 }
1927 /* Check if we added any event */
1928 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1929 current_ev = current_val;
1930 }
1931
1932 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1933 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_KERNEL);
1934 if (buf && scan) {
1935 memset(&iwe, 0, sizeof(iwe));
1936 iwe.cmd = IWEVCUSTOM;
1937 sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
1938 iwe.u.data.length = strlen(buf);
1939 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1940 buf);
1941
1942 memset(&iwe, 0, sizeof(iwe));
1943 iwe.cmd = IWEVCUSTOM;
1944 sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
1945 iwe.u.data.length = strlen(buf);
1946 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1947 buf);
1948
1949 if (local->last_scan_type == PRISM2_HOSTSCAN &&
1950 (capabilities & WLAN_CAPABILITY_IBSS)) {
1951 memset(&iwe, 0, sizeof(iwe));
1952 iwe.cmd = IWEVCUSTOM;
1953 sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
1954 iwe.u.data.length = strlen(buf);
1955 current_ev = iwe_stream_add_point(current_ev, end_buf,
1956 &iwe, buf);
1957 }
1958 }
1959 kfree(buf);
1960
1961 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1962 memset(&iwe, 0, sizeof(iwe));
1963 iwe.cmd = IWEVGENIE;
1964 iwe.u.data.length = bss->wpa_ie_len;
1965 current_ev = iwe_stream_add_point(
1966 current_ev, end_buf, &iwe, bss->wpa_ie);
1967 }
1968
1969 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1970 memset(&iwe, 0, sizeof(iwe));
1971 iwe.cmd = IWEVGENIE;
1972 iwe.u.data.length = bss->rsn_ie_len;
1973 current_ev = iwe_stream_add_point(
1974 current_ev, end_buf, &iwe, bss->rsn_ie);
1975 }
1976
1977 return current_ev;
1978}
1979
1980
1981/* Translate scan data returned from the card to a card independant
1982 * format that the Wireless Tools will understand - Jean II */
1983static inline int prism2_translate_scan(local_info_t *local,
1984 char *buffer, int buflen)
1985{
1986 struct hfa384x_hostscan_result *scan;
1987 int entry, hostscan;
1988 char *current_ev = buffer;
1989 char *end_buf = buffer + buflen;
1990 struct list_head *ptr;
1991
1992 spin_lock_bh(&local->lock);
1993
1994 list_for_each(ptr, &local->bss_list) {
1995 struct hostap_bss_info *bss;
1996 bss = list_entry(ptr, struct hostap_bss_info, list);
1997 bss->included = 0;
1998 }
1999
2000 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
2001 for (entry = 0; entry < local->last_scan_results_count; entry++) {
2002 int found = 0;
2003 scan = &local->last_scan_results[entry];
2004
2005 /* Report every SSID if the AP is using multiple SSIDs. If no
2006 * BSS record is found (e.g., when WPA mode is disabled),
2007 * report the AP once. */
2008 list_for_each(ptr, &local->bss_list) {
2009 struct hostap_bss_info *bss;
2010 bss = list_entry(ptr, struct hostap_bss_info, list);
2011 if (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) {
2012 bss->included = 1;
2013 current_ev = __prism2_translate_scan(
2014 local, scan, bss, current_ev, end_buf);
2015 found++;
2016 }
2017 }
2018 if (!found) {
2019 current_ev = __prism2_translate_scan(
2020 local, scan, NULL, current_ev, end_buf);
2021 }
2022 /* Check if there is space for one more entry */
2023 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2024 /* Ask user space to try again with a bigger buffer */
2025 spin_unlock_bh(&local->lock);
2026 return -E2BIG;
2027 }
2028 }
2029
2030 /* Prism2 firmware has limits (32 at least in some versions) for number
2031 * of BSSes in scan results. Extend this limit by using local BSS list.
2032 */
2033 list_for_each(ptr, &local->bss_list) {
2034 struct hostap_bss_info *bss;
2035 bss = list_entry(ptr, struct hostap_bss_info, list);
2036 if (bss->included)
2037 continue;
2038 current_ev = __prism2_translate_scan(local, NULL, bss,
2039 current_ev, end_buf);
2040 /* Check if there is space for one more entry */
2041 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2042 /* Ask user space to try again with a bigger buffer */
2043 spin_unlock_bh(&local->lock);
2044 return -E2BIG;
2045 }
2046 }
2047
2048 spin_unlock_bh(&local->lock);
2049
2050 return current_ev - buffer;
2051}
2052#endif /* PRISM2_NO_STATION_MODES */
2053
2054
2055static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2056 struct iw_request_info *info,
2057 struct iw_point *data, char *extra)
2058{
2059#ifdef PRISM2_NO_STATION_MODES
2060 return -EOPNOTSUPP;
2061#else /* PRISM2_NO_STATION_MODES */
2062 struct hostap_interface *iface;
2063 local_info_t *local;
2064 int res;
2065
2066 iface = netdev_priv(dev);
2067 local = iface->local;
2068
2069 /* Wait until the scan is finished. We can probably do better
2070 * than that - Jean II */
2071 if (local->scan_timestamp &&
2072 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2073 /* Important note : we don't want to block the caller
2074 * until results are ready for various reasons.
2075 * First, managing wait queues is complex and racy
2076 * (there may be multiple simultaneous callers).
2077 * Second, we grab some rtnetlink lock before comming
2078 * here (in dev_ioctl()).
2079 * Third, the caller can wait on the Wireless Event
2080 * - Jean II */
2081 return -EAGAIN;
2082 }
2083 local->scan_timestamp = 0;
2084
2085 res = prism2_translate_scan(local, extra, data->length);
2086
2087 if (res >= 0) {
2088 data->length = res;
2089 return 0;
2090 } else {
2091 data->length = 0;
2092 return res;
2093 }
2094#endif /* PRISM2_NO_STATION_MODES */
2095}
2096
2097
2098static int prism2_ioctl_giwscan(struct net_device *dev,
2099 struct iw_request_info *info,
2100 struct iw_point *data, char *extra)
2101{
2102 struct hostap_interface *iface;
2103 local_info_t *local;
2104 int res;
2105
2106 iface = netdev_priv(dev);
2107 local = iface->local;
2108
2109 if (local->iw_mode == IW_MODE_MASTER) {
2110 /* In MASTER mode, it doesn't make sense to go around
2111 * scanning the frequencies and make the stations we serve
2112 * wait when what the user is really interested about is the
2113 * list of stations and access points we are talking to.
2114 * So, just extract results from our cache...
2115 * Jean II */
2116
2117 /* Translate to WE format */
2118 res = prism2_ap_translate_scan(dev, extra);
2119 if (res >= 0) {
2120 printk(KERN_DEBUG "Scan result translation succeeded "
2121 "(length=%d)\n", res);
2122 data->length = res;
2123 return 0;
2124 } else {
2125 printk(KERN_DEBUG
2126 "Scan result translation failed (res=%d)\n",
2127 res);
2128 data->length = 0;
2129 return res;
2130 }
2131 } else {
2132 /* Station mode */
2133 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2134 }
2135}
2136
2137
2138static const struct iw_priv_args prism2_priv[] = {
2139 { PRISM2_IOCTL_MONITOR,
2140 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2141 { PRISM2_IOCTL_READMIF,
2142 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2143 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2144 { PRISM2_IOCTL_WRITEMIF,
2145 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2146 { PRISM2_IOCTL_RESET,
2147 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2148 { PRISM2_IOCTL_INQUIRE,
2149 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2150 { PRISM2_IOCTL_SET_RID_WORD,
2151 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2152 { PRISM2_IOCTL_MACCMD,
2153 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2154 { PRISM2_IOCTL_WDS_ADD,
2155 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2156 { PRISM2_IOCTL_WDS_DEL,
2157 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2158 { PRISM2_IOCTL_ADDMAC,
2159 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2160 { PRISM2_IOCTL_DELMAC,
2161 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2162 { PRISM2_IOCTL_KICKMAC,
2163 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2164 /* --- raw access to sub-ioctls --- */
2165 { PRISM2_IOCTL_PRISM2_PARAM,
2166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2167 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2168 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2169 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2170 /* --- sub-ioctls handlers --- */
2171 { PRISM2_IOCTL_PRISM2_PARAM,
2172 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2173 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2174 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2175 /* --- sub-ioctls definitions --- */
2176 { PRISM2_PARAM_TXRATECTRL,
2177 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2178 { PRISM2_PARAM_TXRATECTRL,
2179 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2180 { PRISM2_PARAM_BEACON_INT,
2181 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2182 { PRISM2_PARAM_BEACON_INT,
2183 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2184#ifndef PRISM2_NO_STATION_MODES
2185 { PRISM2_PARAM_PSEUDO_IBSS,
2186 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2187 { PRISM2_PARAM_PSEUDO_IBSS,
2188 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2189#endif /* PRISM2_NO_STATION_MODES */
2190 { PRISM2_PARAM_ALC,
2191 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2192 { PRISM2_PARAM_ALC,
2193 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2194 { PRISM2_PARAM_DUMP,
2195 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2196 { PRISM2_PARAM_DUMP,
2197 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2198 { PRISM2_PARAM_OTHER_AP_POLICY,
2199 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2200 { PRISM2_PARAM_OTHER_AP_POLICY,
2201 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2202 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2203 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2204 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2205 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2206 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2207 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2208 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2209 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2210 { PRISM2_PARAM_DTIM_PERIOD,
2211 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2212 { PRISM2_PARAM_DTIM_PERIOD,
2213 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2214 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2215 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2216 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2217 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2218 { PRISM2_PARAM_MAX_WDS,
2219 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2220 { PRISM2_PARAM_MAX_WDS,
2221 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2222 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2223 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2224 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2225 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2226 { PRISM2_PARAM_AP_AUTH_ALGS,
2227 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2228 { PRISM2_PARAM_AP_AUTH_ALGS,
2229 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2230 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2231 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2232 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2233 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2234 { PRISM2_PARAM_HOST_ENCRYPT,
2235 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2236 { PRISM2_PARAM_HOST_ENCRYPT,
2237 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2238 { PRISM2_PARAM_HOST_DECRYPT,
2239 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2240 { PRISM2_PARAM_HOST_DECRYPT,
2241 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2242 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2243 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_rx" },
2244 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2245 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_rx" },
2246 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2247 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_tx" },
2248 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2249 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_tx" },
2250#ifndef PRISM2_NO_STATION_MODES
2251 { PRISM2_PARAM_HOST_ROAMING,
2252 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2253 { PRISM2_PARAM_HOST_ROAMING,
2254 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2255#endif /* PRISM2_NO_STATION_MODES */
2256 { PRISM2_PARAM_BCRX_STA_KEY,
2257 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2258 { PRISM2_PARAM_BCRX_STA_KEY,
2259 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2260 { PRISM2_PARAM_IEEE_802_1X,
2261 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2262 { PRISM2_PARAM_IEEE_802_1X,
2263 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2264 { PRISM2_PARAM_ANTSEL_TX,
2265 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2266 { PRISM2_PARAM_ANTSEL_TX,
2267 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2268 { PRISM2_PARAM_ANTSEL_RX,
2269 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2270 { PRISM2_PARAM_ANTSEL_RX,
2271 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2272 { PRISM2_PARAM_MONITOR_TYPE,
2273 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2274 { PRISM2_PARAM_MONITOR_TYPE,
2275 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2276 { PRISM2_PARAM_WDS_TYPE,
2277 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2278 { PRISM2_PARAM_WDS_TYPE,
2279 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2280 { PRISM2_PARAM_HOSTSCAN,
2281 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2282 { PRISM2_PARAM_HOSTSCAN,
2283 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2284 { PRISM2_PARAM_AP_SCAN,
2285 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2286 { PRISM2_PARAM_AP_SCAN,
2287 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2288 { PRISM2_PARAM_ENH_SEC,
2289 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2290 { PRISM2_PARAM_ENH_SEC,
2291 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2292#ifdef PRISM2_IO_DEBUG
2293 { PRISM2_PARAM_IO_DEBUG,
2294 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2295 { PRISM2_PARAM_IO_DEBUG,
2296 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2297#endif /* PRISM2_IO_DEBUG */
2298 { PRISM2_PARAM_BASIC_RATES,
2299 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2300 { PRISM2_PARAM_BASIC_RATES,
2301 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2302 { PRISM2_PARAM_OPER_RATES,
2303 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2304 { PRISM2_PARAM_OPER_RATES,
2305 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2306 { PRISM2_PARAM_HOSTAPD,
2307 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2308 { PRISM2_PARAM_HOSTAPD,
2309 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2310 { PRISM2_PARAM_HOSTAPD_STA,
2311 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2312 { PRISM2_PARAM_HOSTAPD_STA,
2313 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2314 { PRISM2_PARAM_WPA,
2315 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2316 { PRISM2_PARAM_WPA,
2317 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2318 { PRISM2_PARAM_PRIVACY_INVOKED,
2319 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2320 { PRISM2_PARAM_PRIVACY_INVOKED,
2321 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2322 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2323 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2324 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2325 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2326 { PRISM2_PARAM_DROP_UNENCRYPTED,
2327 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2328 { PRISM2_PARAM_DROP_UNENCRYPTED,
2329 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
2330 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2331 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2332 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2333 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
2334};
2335
2336
2337static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2338{
2339 struct hostap_interface *iface;
2340 local_info_t *local;
2341
2342 iface = netdev_priv(dev);
2343 local = iface->local;
2344
2345 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2346 return -EOPNOTSUPP;
2347
2348 return 0;
2349}
2350
2351
2352static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2353 struct iw_request_info *info,
2354 void *wrqu, char *extra)
2355{
2356 struct hostap_interface *iface;
2357 local_info_t *local;
2358 int *i = (int *) extra;
2359 int param = *i;
2360 int value = *(i + 1);
2361 int ret = 0;
2362 u16 val;
2363
2364 iface = netdev_priv(dev);
2365 local = iface->local;
2366
2367 switch (param) {
2368 case PRISM2_PARAM_TXRATECTRL:
2369 local->fw_tx_rate_control = value;
2370 break;
2371
2372 case PRISM2_PARAM_BEACON_INT:
2373 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2374 local->func->reset_port(dev))
2375 ret = -EINVAL;
2376 else
2377 local->beacon_int = value;
2378 break;
2379
2380#ifndef PRISM2_NO_STATION_MODES
2381 case PRISM2_PARAM_PSEUDO_IBSS:
2382 if (value == local->pseudo_adhoc)
2383 break;
2384
2385 if (value != 0 && value != 1) {
2386 ret = -EINVAL;
2387 break;
2388 }
2389
2390 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2391 dev->name, local->pseudo_adhoc, value);
2392 local->pseudo_adhoc = value;
2393 if (local->iw_mode != IW_MODE_ADHOC)
2394 break;
2395
2396 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2397 hostap_get_porttype(local))) {
2398 ret = -EOPNOTSUPP;
2399 break;
2400 }
2401
2402 if (local->func->reset_port(dev))
2403 ret = -EINVAL;
2404 break;
2405#endif /* PRISM2_NO_STATION_MODES */
2406
2407 case PRISM2_PARAM_ALC:
2408 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2409 value == 0 ? "Disabling" : "Enabling");
2410 val = HFA384X_TEST_CFG_BIT_ALC;
2411 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2412 (HFA384X_TEST_CFG_BITS << 8),
2413 value == 0 ? 0 : 1, &val, NULL);
2414 break;
2415
2416 case PRISM2_PARAM_DUMP:
2417 local->frame_dump = value;
2418 break;
2419
2420 case PRISM2_PARAM_OTHER_AP_POLICY:
2421 if (value < 0 || value > 3) {
2422 ret = -EINVAL;
2423 break;
2424 }
2425 if (local->ap != NULL)
2426 local->ap->ap_policy = value;
2427 break;
2428
2429 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2430 if (value < 0 || value > 7 * 24 * 60 * 60) {
2431 ret = -EINVAL;
2432 break;
2433 }
2434 if (local->ap != NULL)
2435 local->ap->max_inactivity = value * HZ;
2436 break;
2437
2438 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2439 if (local->ap != NULL)
2440 local->ap->bridge_packets = value;
2441 break;
2442
2443 case PRISM2_PARAM_DTIM_PERIOD:
2444 if (value < 0 || value > 65535) {
2445 ret = -EINVAL;
2446 break;
2447 }
2448 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2449 || local->func->reset_port(dev))
2450 ret = -EINVAL;
2451 else
2452 local->dtim_period = value;
2453 break;
2454
2455 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2456 if (local->ap != NULL)
2457 local->ap->nullfunc_ack = value;
2458 break;
2459
2460 case PRISM2_PARAM_MAX_WDS:
2461 local->wds_max_connections = value;
2462 break;
2463
2464 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2465 if (local->ap != NULL) {
2466 if (!local->ap->autom_ap_wds && value) {
2467 /* add WDS link to all APs in STA table */
2468 hostap_add_wds_links(local);
2469 }
2470 local->ap->autom_ap_wds = value;
2471 }
2472 break;
2473
2474 case PRISM2_PARAM_AP_AUTH_ALGS:
2475 local->auth_algs = value;
2476 if (hostap_set_auth_algs(local))
2477 ret = -EINVAL;
2478 break;
2479
2480 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2481 local->monitor_allow_fcserr = value;
2482 break;
2483
2484 case PRISM2_PARAM_HOST_ENCRYPT:
2485 local->host_encrypt = value;
2486 if (hostap_set_encryption(local) ||
2487 local->func->reset_port(dev))
2488 ret = -EINVAL;
2489 break;
2490
2491 case PRISM2_PARAM_HOST_DECRYPT:
2492 local->host_decrypt = value;
2493 if (hostap_set_encryption(local) ||
2494 local->func->reset_port(dev))
2495 ret = -EINVAL;
2496 break;
2497
2498 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2499 local->bus_master_threshold_rx = value;
2500 break;
2501
2502 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2503 local->bus_master_threshold_tx = value;
2504 break;
2505
2506#ifndef PRISM2_NO_STATION_MODES
2507 case PRISM2_PARAM_HOST_ROAMING:
2508 if (value < 0 || value > 2) {
2509 ret = -EINVAL;
2510 break;
2511 }
2512 local->host_roaming = value;
2513 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2514 ret = -EINVAL;
2515 break;
2516#endif /* PRISM2_NO_STATION_MODES */
2517
2518 case PRISM2_PARAM_BCRX_STA_KEY:
2519 local->bcrx_sta_key = value;
2520 break;
2521
2522 case PRISM2_PARAM_IEEE_802_1X:
2523 local->ieee_802_1x = value;
2524 break;
2525
2526 case PRISM2_PARAM_ANTSEL_TX:
2527 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2528 ret = -EINVAL;
2529 break;
2530 }
2531 local->antsel_tx = value;
2532 hostap_set_antsel(local);
2533 break;
2534
2535 case PRISM2_PARAM_ANTSEL_RX:
2536 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2537 ret = -EINVAL;
2538 break;
2539 }
2540 local->antsel_rx = value;
2541 hostap_set_antsel(local);
2542 break;
2543
2544 case PRISM2_PARAM_MONITOR_TYPE:
2545 if (value != PRISM2_MONITOR_80211 &&
2546 value != PRISM2_MONITOR_CAPHDR &&
2547 value != PRISM2_MONITOR_PRISM) {
2548 ret = -EINVAL;
2549 break;
2550 }
2551 local->monitor_type = value;
2552 if (local->iw_mode == IW_MODE_MONITOR)
2553 hostap_monitor_set_type(local);
2554 break;
2555
2556 case PRISM2_PARAM_WDS_TYPE:
2557 local->wds_type = value;
2558 break;
2559
2560 case PRISM2_PARAM_HOSTSCAN:
2561 {
2562 struct hfa384x_hostscan_request scan_req;
2563 u16 rate;
2564
2565 memset(&scan_req, 0, sizeof(scan_req));
2566 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
2567 switch (value) {
2568 case 1: rate = HFA384X_RATES_1MBPS; break;
2569 case 2: rate = HFA384X_RATES_2MBPS; break;
2570 case 3: rate = HFA384X_RATES_5MBPS; break;
2571 case 4: rate = HFA384X_RATES_11MBPS; break;
2572 default: rate = HFA384X_RATES_1MBPS; break;
2573 }
2574 scan_req.txrate = cpu_to_le16(rate);
2575 /* leave SSID empty to accept all SSIDs */
2576
2577 if (local->iw_mode == IW_MODE_MASTER) {
2578 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2579 HFA384X_PORTTYPE_BSS) ||
2580 local->func->reset_port(dev))
2581 printk(KERN_DEBUG "Leaving Host AP mode "
2582 "for HostScan failed\n");
2583 }
2584
2585 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2586 sizeof(scan_req))) {
2587 printk(KERN_DEBUG "HOSTSCAN failed\n");
2588 ret = -EINVAL;
2589 }
2590 if (local->iw_mode == IW_MODE_MASTER) {
2591 wait_queue_t __wait;
2592 init_waitqueue_entry(&__wait, current);
2593 add_wait_queue(&local->hostscan_wq, &__wait);
2594 set_current_state(TASK_INTERRUPTIBLE);
2595 schedule_timeout(HZ);
2596 if (signal_pending(current))
2597 ret = -EINTR;
2598 set_current_state(TASK_RUNNING);
2599 remove_wait_queue(&local->hostscan_wq, &__wait);
2600
2601 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2602 HFA384X_PORTTYPE_HOSTAP) ||
2603 local->func->reset_port(dev))
2604 printk(KERN_DEBUG "Returning to Host AP mode "
2605 "after HostScan failed\n");
2606 }
2607 break;
2608 }
2609
2610 case PRISM2_PARAM_AP_SCAN:
2611 local->passive_scan_interval = value;
2612 if (timer_pending(&local->passive_scan_timer))
2613 del_timer(&local->passive_scan_timer);
2614 if (value > 0) {
2615 local->passive_scan_timer.expires = jiffies +
2616 local->passive_scan_interval * HZ;
2617 add_timer(&local->passive_scan_timer);
2618 }
2619 break;
2620
2621 case PRISM2_PARAM_ENH_SEC:
2622 if (value < 0 || value > 3) {
2623 ret = -EINVAL;
2624 break;
2625 }
2626 local->enh_sec = value;
2627 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2628 local->enh_sec) ||
2629 local->func->reset_port(dev)) {
2630 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2631 "1.6.3 or newer\n", dev->name);
2632 ret = -EOPNOTSUPP;
2633 }
2634 break;
2635
2636#ifdef PRISM2_IO_DEBUG
2637 case PRISM2_PARAM_IO_DEBUG:
2638 local->io_debug_enabled = value;
2639 break;
2640#endif /* PRISM2_IO_DEBUG */
2641
2642 case PRISM2_PARAM_BASIC_RATES:
2643 if ((value & local->tx_rate_control) != value || value == 0) {
2644 printk(KERN_INFO "%s: invalid basic rate set - basic "
2645 "rates must be in supported rate set\n",
2646 dev->name);
2647 ret = -EINVAL;
2648 break;
2649 }
2650 local->basic_rates = value;
2651 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2652 local->basic_rates) ||
2653 local->func->reset_port(dev))
2654 ret = -EINVAL;
2655 break;
2656
2657 case PRISM2_PARAM_OPER_RATES:
2658 local->tx_rate_control = value;
2659 if (hostap_set_rate(dev))
2660 ret = -EINVAL;
2661 break;
2662
2663 case PRISM2_PARAM_HOSTAPD:
2664 ret = hostap_set_hostapd(local, value, 1);
2665 break;
2666
2667 case PRISM2_PARAM_HOSTAPD_STA:
2668 ret = hostap_set_hostapd_sta(local, value, 1);
2669 break;
2670
2671 case PRISM2_PARAM_WPA:
2672 local->wpa = value;
2673 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2674 ret = -EOPNOTSUPP;
2675 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2676 value ? 1 : 0))
2677 ret = -EINVAL;
2678 break;
2679
2680 case PRISM2_PARAM_PRIVACY_INVOKED:
2681 local->privacy_invoked = value;
2682 if (hostap_set_encryption(local) ||
2683 local->func->reset_port(dev))
2684 ret = -EINVAL;
2685 break;
2686
2687 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2688 local->tkip_countermeasures = value;
2689 break;
2690
2691 case PRISM2_PARAM_DROP_UNENCRYPTED:
2692 local->drop_unencrypted = value;
2693 break;
2694
2695 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2696 local->scan_channel_mask = value;
2697 break;
2698
2699 default:
2700 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2701 dev->name, param);
2702 ret = -EOPNOTSUPP;
2703 break;
2704 }
2705
2706 return ret;
2707}
2708
2709
2710static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2711 struct iw_request_info *info,
2712 void *wrqu, char *extra)
2713{
2714 struct hostap_interface *iface;
2715 local_info_t *local;
2716 int *param = (int *) extra;
2717 int ret = 0;
2718
2719 iface = netdev_priv(dev);
2720 local = iface->local;
2721
2722 switch (*param) {
2723 case PRISM2_PARAM_TXRATECTRL:
2724 *param = local->fw_tx_rate_control;
2725 break;
2726
2727 case PRISM2_PARAM_BEACON_INT:
2728 *param = local->beacon_int;
2729 break;
2730
2731 case PRISM2_PARAM_PSEUDO_IBSS:
2732 *param = local->pseudo_adhoc;
2733 break;
2734
2735 case PRISM2_PARAM_ALC:
2736 ret = -EOPNOTSUPP; /* FIX */
2737 break;
2738
2739 case PRISM2_PARAM_DUMP:
2740 *param = local->frame_dump;
2741 break;
2742
2743 case PRISM2_PARAM_OTHER_AP_POLICY:
2744 if (local->ap != NULL)
2745 *param = local->ap->ap_policy;
2746 else
2747 ret = -EOPNOTSUPP;
2748 break;
2749
2750 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2751 if (local->ap != NULL)
2752 *param = local->ap->max_inactivity / HZ;
2753 else
2754 ret = -EOPNOTSUPP;
2755 break;
2756
2757 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2758 if (local->ap != NULL)
2759 *param = local->ap->bridge_packets;
2760 else
2761 ret = -EOPNOTSUPP;
2762 break;
2763
2764 case PRISM2_PARAM_DTIM_PERIOD:
2765 *param = local->dtim_period;
2766 break;
2767
2768 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2769 if (local->ap != NULL)
2770 *param = local->ap->nullfunc_ack;
2771 else
2772 ret = -EOPNOTSUPP;
2773 break;
2774
2775 case PRISM2_PARAM_MAX_WDS:
2776 *param = local->wds_max_connections;
2777 break;
2778
2779 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2780 if (local->ap != NULL)
2781 *param = local->ap->autom_ap_wds;
2782 else
2783 ret = -EOPNOTSUPP;
2784 break;
2785
2786 case PRISM2_PARAM_AP_AUTH_ALGS:
2787 *param = local->auth_algs;
2788 break;
2789
2790 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2791 *param = local->monitor_allow_fcserr;
2792 break;
2793
2794 case PRISM2_PARAM_HOST_ENCRYPT:
2795 *param = local->host_encrypt;
2796 break;
2797
2798 case PRISM2_PARAM_HOST_DECRYPT:
2799 *param = local->host_decrypt;
2800 break;
2801
2802 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2803 *param = local->bus_master_threshold_rx;
2804 break;
2805
2806 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2807 *param = local->bus_master_threshold_tx;
2808 break;
2809
2810 case PRISM2_PARAM_HOST_ROAMING:
2811 *param = local->host_roaming;
2812 break;
2813
2814 case PRISM2_PARAM_BCRX_STA_KEY:
2815 *param = local->bcrx_sta_key;
2816 break;
2817
2818 case PRISM2_PARAM_IEEE_802_1X:
2819 *param = local->ieee_802_1x;
2820 break;
2821
2822 case PRISM2_PARAM_ANTSEL_TX:
2823 *param = local->antsel_tx;
2824 break;
2825
2826 case PRISM2_PARAM_ANTSEL_RX:
2827 *param = local->antsel_rx;
2828 break;
2829
2830 case PRISM2_PARAM_MONITOR_TYPE:
2831 *param = local->monitor_type;
2832 break;
2833
2834 case PRISM2_PARAM_WDS_TYPE:
2835 *param = local->wds_type;
2836 break;
2837
2838 case PRISM2_PARAM_HOSTSCAN:
2839 ret = -EOPNOTSUPP;
2840 break;
2841
2842 case PRISM2_PARAM_AP_SCAN:
2843 *param = local->passive_scan_interval;
2844 break;
2845
2846 case PRISM2_PARAM_ENH_SEC:
2847 *param = local->enh_sec;
2848 break;
2849
2850#ifdef PRISM2_IO_DEBUG
2851 case PRISM2_PARAM_IO_DEBUG:
2852 *param = local->io_debug_enabled;
2853 break;
2854#endif /* PRISM2_IO_DEBUG */
2855
2856 case PRISM2_PARAM_BASIC_RATES:
2857 *param = local->basic_rates;
2858 break;
2859
2860 case PRISM2_PARAM_OPER_RATES:
2861 *param = local->tx_rate_control;
2862 break;
2863
2864 case PRISM2_PARAM_HOSTAPD:
2865 *param = local->hostapd;
2866 break;
2867
2868 case PRISM2_PARAM_HOSTAPD_STA:
2869 *param = local->hostapd_sta;
2870 break;
2871
2872 case PRISM2_PARAM_WPA:
2873 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2874 ret = -EOPNOTSUPP;
2875 *param = local->wpa;
2876 break;
2877
2878 case PRISM2_PARAM_PRIVACY_INVOKED:
2879 *param = local->privacy_invoked;
2880 break;
2881
2882 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2883 *param = local->tkip_countermeasures;
2884 break;
2885
2886 case PRISM2_PARAM_DROP_UNENCRYPTED:
2887 *param = local->drop_unencrypted;
2888 break;
2889
2890 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2891 *param = local->scan_channel_mask;
2892 break;
2893
2894 default:
2895 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2896 dev->name, *param);
2897 ret = -EOPNOTSUPP;
2898 break;
2899 }
2900
2901 return ret;
2902}
2903
2904
2905static int prism2_ioctl_priv_readmif(struct net_device *dev,
2906 struct iw_request_info *info,
2907 void *wrqu, char *extra)
2908{
2909 struct hostap_interface *iface;
2910 local_info_t *local;
2911 u16 resp0;
2912
2913 iface = netdev_priv(dev);
2914 local = iface->local;
2915
2916 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2917 &resp0))
2918 return -EOPNOTSUPP;
2919 else
2920 *extra = resp0;
2921
2922 return 0;
2923}
2924
2925
2926static int prism2_ioctl_priv_writemif(struct net_device *dev,
2927 struct iw_request_info *info,
2928 void *wrqu, char *extra)
2929{
2930 struct hostap_interface *iface;
2931 local_info_t *local;
2932 u16 cr, val;
2933
2934 iface = netdev_priv(dev);
2935 local = iface->local;
2936
2937 cr = *extra;
2938 val = *(extra + 1);
2939 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2940 return -EOPNOTSUPP;
2941
2942 return 0;
2943}
2944
2945
2946static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2947{
2948 struct hostap_interface *iface;
2949 local_info_t *local;
2950 int ret = 0;
2951 u32 mode;
2952
2953 iface = netdev_priv(dev);
2954 local = iface->local;
2955
2956 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2957 "- update software to use iwconfig mode monitor\n",
2958 dev->name, current->pid, current->comm);
2959
2960 /* Backward compatibility code - this can be removed at some point */
2961
2962 if (*i == 0) {
2963 /* Disable monitor mode - old mode was not saved, so go to
2964 * Master mode */
2965 mode = IW_MODE_MASTER;
2966 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2967 } else if (*i == 1) {
2968 /* netlink socket mode is not supported anymore since it did
2969 * not separate different devices from each other and was not
2970 * best method for delivering large amount of packets to
2971 * user space */
2972 ret = -EOPNOTSUPP;
2973 } else if (*i == 2 || *i == 3) {
2974 switch (*i) {
2975 case 2:
2976 local->monitor_type = PRISM2_MONITOR_80211;
2977 break;
2978 case 3:
2979 local->monitor_type = PRISM2_MONITOR_PRISM;
2980 break;
2981 }
2982 mode = IW_MODE_MONITOR;
2983 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2984 hostap_monitor_mode_enable(local);
2985 } else
2986 ret = -EINVAL;
2987
2988 return ret;
2989}
2990
2991
2992static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2993{
2994 struct hostap_interface *iface;
2995 local_info_t *local;
2996
2997 iface = netdev_priv(dev);
2998 local = iface->local;
2999
3000 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
3001 switch (*i) {
3002 case 0:
3003 /* Disable and enable card */
3004 local->func->hw_shutdown(dev, 1);
3005 local->func->hw_config(dev, 0);
3006 break;
3007
3008 case 1:
3009 /* COR sreset */
3010 local->func->hw_reset(dev);
3011 break;
3012
3013 case 2:
3014 /* Disable and enable port 0 */
3015 local->func->reset_port(dev);
3016 break;
3017
3018 case 3:
3019 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
3020 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
3021 NULL))
3022 return -EINVAL;
3023 break;
3024
3025 case 4:
3026 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
3027 NULL))
3028 return -EINVAL;
3029 break;
3030
3031 default:
3032 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
3033 return -EOPNOTSUPP;
3034 }
3035
3036 return 0;
3037}
3038
3039
3040static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
3041{
3042 int rid = *i;
3043 int value = *(i + 1);
3044
3045 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
3046
3047 if (hostap_set_word(dev, rid, value))
3048 return -EINVAL;
3049
3050 return 0;
3051}
3052
3053
3054#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3055static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3056{
3057 int ret = 0;
3058
3059 switch (*cmd) {
3060 case AP_MAC_CMD_POLICY_OPEN:
3061 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3062 break;
3063 case AP_MAC_CMD_POLICY_ALLOW:
3064 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3065 break;
3066 case AP_MAC_CMD_POLICY_DENY:
3067 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3068 break;
3069 case AP_MAC_CMD_FLUSH:
3070 ap_control_flush_macs(&local->ap->mac_restrictions);
3071 break;
3072 case AP_MAC_CMD_KICKALL:
3073 ap_control_kickall(local->ap);
3074 hostap_deauth_all_stas(local->dev, local->ap, 0);
3075 break;
3076 default:
3077 ret = -EOPNOTSUPP;
3078 break;
3079 }
3080
3081 return ret;
3082}
3083#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3084
3085
3086#ifdef PRISM2_DOWNLOAD_SUPPORT
3087static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3088{
3089 struct prism2_download_param *param;
3090 int ret = 0;
3091
3092 if (p->length < sizeof(struct prism2_download_param) ||
3093 p->length > 1024 || !p->pointer)
3094 return -EINVAL;
3095
3096 param = (struct prism2_download_param *)
3097 kmalloc(p->length, GFP_KERNEL);
3098 if (param == NULL)
3099 return -ENOMEM;
3100
3101 if (copy_from_user(param, p->pointer, p->length)) {
3102 ret = -EFAULT;
3103 goto out;
3104 }
3105
3106 if (p->length < sizeof(struct prism2_download_param) +
3107 param->num_areas * sizeof(struct prism2_download_area)) {
3108 ret = -EINVAL;
3109 goto out;
3110 }
3111
3112 ret = local->func->download(local, param);
3113
3114 out:
3115 if (param != NULL)
3116 kfree(param);
3117
3118 return ret;
3119}
3120#endif /* PRISM2_DOWNLOAD_SUPPORT */
3121
3122
3123static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3124 size_t len)
3125{
3126 struct hostap_interface *iface = dev->priv;
3127 local_info_t *local = iface->local;
3128 u8 *buf;
3129
3130 /*
3131 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3132 * includes it.
3133 */
3134 buf = kmalloc(len + 2, GFP_KERNEL);
3135 if (buf == NULL)
3136 return -ENOMEM;
3137
3138 *((u16 *) buf) = cpu_to_le16(len);
3139 memcpy(buf + 2, elem, len);
3140
3141 kfree(local->generic_elem);
3142 local->generic_elem = buf;
3143 local->generic_elem_len = len + 2;
3144
3145 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3146 buf, len + 2);
3147}
3148
3149
3150static int prism2_ioctl_siwauth(struct net_device *dev,
3151 struct iw_request_info *info,
3152 struct iw_param *data, char *extra)
3153{
3154 struct hostap_interface *iface = dev->priv;
3155 local_info_t *local = iface->local;
3156
3157 switch (data->flags & IW_AUTH_INDEX) {
3158 case IW_AUTH_WPA_VERSION:
3159 case IW_AUTH_CIPHER_PAIRWISE:
3160 case IW_AUTH_CIPHER_GROUP:
3161 case IW_AUTH_KEY_MGMT:
3162 /*
3163 * Host AP driver does not use these parameters and allows
3164 * wpa_supplicant to control them internally.
3165 */
3166 break;
3167 case IW_AUTH_TKIP_COUNTERMEASURES:
3168 local->tkip_countermeasures = data->value;
3169 break;
3170 case IW_AUTH_DROP_UNENCRYPTED:
3171 local->drop_unencrypted = data->value;
3172 break;
3173 case IW_AUTH_80211_AUTH_ALG:
3174 local->auth_algs = data->value;
3175 break;
3176 case IW_AUTH_WPA_ENABLED:
3177 if (data->value == 0) {
3178 local->wpa = 0;
3179 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3180 break;
3181 prism2_set_genericelement(dev, "", 0);
3182 local->host_roaming = 0;
3183 local->privacy_invoked = 0;
3184 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3185 0) ||
3186 hostap_set_roaming(local) ||
3187 hostap_set_encryption(local) ||
3188 local->func->reset_port(dev))
3189 return -EINVAL;
3190 break;
3191 }
3192 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3193 return -EOPNOTSUPP;
3194 local->host_roaming = 2;
3195 local->privacy_invoked = 1;
3196 local->wpa = 1;
3197 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3198 hostap_set_roaming(local) ||
3199 hostap_set_encryption(local) ||
3200 local->func->reset_port(dev))
3201 return -EINVAL;
3202 break;
3203 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3204 local->ieee_802_1x = data->value;
3205 break;
3206 case IW_AUTH_PRIVACY_INVOKED:
3207 local->privacy_invoked = data->value;
3208 break;
3209 default:
3210 return -EOPNOTSUPP;
3211 }
3212 return 0;
3213}
3214
3215
3216static int prism2_ioctl_giwauth(struct net_device *dev,
3217 struct iw_request_info *info,
3218 struct iw_param *data, char *extra)
3219{
3220 struct hostap_interface *iface = dev->priv;
3221 local_info_t *local = iface->local;
3222
3223 switch (data->flags & IW_AUTH_INDEX) {
3224 case IW_AUTH_WPA_VERSION:
3225 case IW_AUTH_CIPHER_PAIRWISE:
3226 case IW_AUTH_CIPHER_GROUP:
3227 case IW_AUTH_KEY_MGMT:
3228 /*
3229 * Host AP driver does not use these parameters and allows
3230 * wpa_supplicant to control them internally.
3231 */
3232 return -EOPNOTSUPP;
3233 case IW_AUTH_TKIP_COUNTERMEASURES:
3234 data->value = local->tkip_countermeasures;
3235 break;
3236 case IW_AUTH_DROP_UNENCRYPTED:
3237 data->value = local->drop_unencrypted;
3238 break;
3239 case IW_AUTH_80211_AUTH_ALG:
3240 data->value = local->auth_algs;
3241 break;
3242 case IW_AUTH_WPA_ENABLED:
3243 data->value = local->wpa;
3244 break;
3245 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3246 data->value = local->ieee_802_1x;
3247 break;
3248 default:
3249 return -EOPNOTSUPP;
3250 }
3251 return 0;
3252}
3253
3254
3255static int prism2_ioctl_siwencodeext(struct net_device *dev,
3256 struct iw_request_info *info,
3257 struct iw_point *erq, char *extra)
3258{
3259 struct hostap_interface *iface = dev->priv;
3260 local_info_t *local = iface->local;
3261 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3262 int i, ret = 0;
3263 struct ieee80211_crypto_ops *ops;
3264 struct ieee80211_crypt_data **crypt;
3265 void *sta_ptr;
3266 u8 *addr;
3267 const char *alg, *module;
3268
3269 i = erq->flags & IW_ENCODE_INDEX;
3270 if (i > WEP_KEYS)
3271 return -EINVAL;
3272 if (i < 1 || i > WEP_KEYS)
3273 i = local->tx_keyidx;
3274 else
3275 i--;
3276 if (i < 0 || i >= WEP_KEYS)
3277 return -EINVAL;
3278
3279 addr = ext->addr.sa_data;
3280 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3281 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3282 sta_ptr = NULL;
3283 crypt = &local->crypt[i];
3284 } else {
3285 if (i != 0)
3286 return -EINVAL;
3287 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3288 if (sta_ptr == NULL) {
3289 if (local->iw_mode == IW_MODE_INFRA) {
3290 /*
3291 * TODO: add STA entry for the current AP so
3292 * that unicast key can be used. For now, this
3293 * is emulated by using default key idx 0.
3294 */
3295 i = 0;
3296 crypt = &local->crypt[i];
3297 } else
3298 return -EINVAL;
3299 }
3300 }
3301
3302 if ((erq->flags & IW_ENCODE_DISABLED) ||
3303 ext->alg == IW_ENCODE_ALG_NONE) {
3304 if (*crypt)
3305 prism2_crypt_delayed_deinit(local, crypt);
3306 goto done;
3307 }
3308
3309 switch (ext->alg) {
3310 case IW_ENCODE_ALG_WEP:
3311 alg = "WEP";
3312 module = "ieee80211_crypt_wep";
3313 break;
3314 case IW_ENCODE_ALG_TKIP:
3315 alg = "TKIP";
3316 module = "ieee80211_crypt_tkip";
3317 break;
3318 case IW_ENCODE_ALG_CCMP:
3319 alg = "CCMP";
3320 module = "ieee80211_crypt_ccmp";
3321 break;
3322 default:
3323 printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3324 local->dev->name, ext->alg);
3325 ret = -EOPNOTSUPP;
3326 goto done;
3327 }
3328
3329 ops = ieee80211_get_crypto_ops(alg);
3330 if (ops == NULL) {
3331 request_module(module);
3332 ops = ieee80211_get_crypto_ops(alg);
3333 }
3334 if (ops == NULL) {
3335 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3336 local->dev->name, alg);
3337 ret = -EOPNOTSUPP;
3338 goto done;
3339 }
3340
3341 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3342 /*
3343 * Per station encryption and other than WEP algorithms
3344 * require host-based encryption, so force them on
3345 * automatically.
3346 */
3347 local->host_decrypt = local->host_encrypt = 1;
3348 }
3349
3350 if (*crypt == NULL || (*crypt)->ops != ops) {
3351 struct ieee80211_crypt_data *new_crypt;
3352
3353 prism2_crypt_delayed_deinit(local, crypt);
3354
3355 new_crypt = (struct ieee80211_crypt_data *)
3356 kmalloc(sizeof(struct ieee80211_crypt_data),
3357 GFP_KERNEL);
3358 if (new_crypt == NULL) {
3359 ret = -ENOMEM;
3360 goto done;
3361 }
3362 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3363 new_crypt->ops = ops;
3364 new_crypt->priv = new_crypt->ops->init(i);
3365 if (new_crypt->priv == NULL) {
3366 kfree(new_crypt);
3367 ret = -EINVAL;
3368 goto done;
3369 }
3370
3371 *crypt = new_crypt;
3372 }
3373
3374 /*
3375 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3376 * existing seq# should not be changed.
3377 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3378 * should be changed to something else than zero.
3379 */
3380 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3381 && (*crypt)->ops->set_key &&
3382 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3383 (*crypt)->priv) < 0) {
3384 printk(KERN_DEBUG "%s: key setting failed\n",
3385 local->dev->name);
3386 ret = -EINVAL;
3387 goto done;
3388 }
3389
3390 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3391 if (!sta_ptr)
3392 local->tx_keyidx = i;
3393 else if (i) {
3394 ret = -EINVAL;
3395 goto done;
3396 }
3397 }
3398
3399
3400 if (sta_ptr == NULL && ext->key_len > 0) {
3401 int first = 1, j;
3402 for (j = 0; j < WEP_KEYS; j++) {
3403 if (j != i && local->crypt[j]) {
3404 first = 0;
3405 break;
3406 }
3407 }
3408 if (first)
3409 local->tx_keyidx = i;
3410 }
3411
3412 done:
3413 if (sta_ptr)
3414 hostap_handle_sta_release(sta_ptr);
3415
3416 local->open_wep = erq->flags & IW_ENCODE_OPEN;
3417
3418 /*
3419 * Do not reset port0 if card is in Managed mode since resetting will
3420 * generate new IEEE 802.11 authentication which may end up in looping
3421 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3422 * after WEP configuration. However, keys are apparently changed at
3423 * least in Managed mode.
3424 */
3425 if (ret == 0 &&
3426 (hostap_set_encryption(local) ||
3427 (local->iw_mode != IW_MODE_INFRA &&
3428 local->func->reset_port(local->dev))))
3429 ret = -EINVAL;
3430
3431 return ret;
3432}
3433
3434
3435static int prism2_ioctl_giwencodeext(struct net_device *dev,
3436 struct iw_request_info *info,
3437 struct iw_point *erq, char *extra)
3438{
3439 struct hostap_interface *iface = dev->priv;
3440 local_info_t *local = iface->local;
3441 struct ieee80211_crypt_data **crypt;
3442 void *sta_ptr;
3443 int max_key_len, i;
3444 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3445 u8 *addr;
3446
3447 max_key_len = erq->length - sizeof(*ext);
3448 if (max_key_len < 0)
3449 return -EINVAL;
3450
3451 i = erq->flags & IW_ENCODE_INDEX;
3452 if (i < 1 || i > WEP_KEYS)
3453 i = local->tx_keyidx;
3454 else
3455 i--;
3456
3457 addr = ext->addr.sa_data;
3458 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3459 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3460 sta_ptr = NULL;
3461 crypt = &local->crypt[i];
3462 } else {
3463 i = 0;
3464 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3465 if (sta_ptr == NULL)
3466 return -EINVAL;
3467 }
3468 erq->flags = i + 1;
3469 memset(ext, 0, sizeof(*ext));
3470
3471 if (*crypt == NULL || (*crypt)->ops == NULL) {
3472 ext->alg = IW_ENCODE_ALG_NONE;
3473 ext->key_len = 0;
3474 erq->flags |= IW_ENCODE_DISABLED;
3475 } else {
3476 if (strcmp((*crypt)->ops->name, "WEP") == 0)
3477 ext->alg = IW_ENCODE_ALG_WEP;
3478 else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3479 ext->alg = IW_ENCODE_ALG_TKIP;
3480 else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3481 ext->alg = IW_ENCODE_ALG_CCMP;
3482 else
3483 return -EINVAL;
3484
3485 if ((*crypt)->ops->get_key) {
3486 ext->key_len =
3487 (*crypt)->ops->get_key(ext->key,
3488 max_key_len,
3489 ext->tx_seq,
3490 (*crypt)->priv);
3491 if (ext->key_len &&
3492 (ext->alg == IW_ENCODE_ALG_TKIP ||
3493 ext->alg == IW_ENCODE_ALG_CCMP))
3494 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3495 }
3496 }
3497
3498 if (sta_ptr)
3499 hostap_handle_sta_release(sta_ptr);
3500
3501 return 0;
3502}
3503
3504
3505static int prism2_ioctl_set_encryption(local_info_t *local,
3506 struct prism2_hostapd_param *param,
3507 int param_len)
3508{
3509 int ret = 0;
3510 struct ieee80211_crypto_ops *ops;
3511 struct ieee80211_crypt_data **crypt;
3512 void *sta_ptr;
3513
3514 param->u.crypt.err = 0;
3515 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3516
3517 if (param_len !=
3518 (int) ((char *) param->u.crypt.key - (char *) param) +
3519 param->u.crypt.key_len)
3520 return -EINVAL;
3521
3522 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3523 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3524 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3525 if (param->u.crypt.idx >= WEP_KEYS)
3526 return -EINVAL;
3527 sta_ptr = NULL;
3528 crypt = &local->crypt[param->u.crypt.idx];
3529 } else {
3530 if (param->u.crypt.idx)
3531 return -EINVAL;
3532 sta_ptr = ap_crypt_get_ptrs(
3533 local->ap, param->sta_addr,
3534 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3535 &crypt);
3536
3537 if (sta_ptr == NULL) {
3538 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3539 return -EINVAL;
3540 }
3541 }
3542
3543 if (strcmp(param->u.crypt.alg, "none") == 0) {
3544 if (crypt)
3545 prism2_crypt_delayed_deinit(local, crypt);
3546 goto done;
3547 }
3548
3549 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3550 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3551 request_module("ieee80211_crypt_wep");
3552 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3553 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3554 request_module("ieee80211_crypt_tkip");
3555 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3556 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3557 request_module("ieee80211_crypt_ccmp");
3558 ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
3559 }
3560 if (ops == NULL) {
3561 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3562 local->dev->name, param->u.crypt.alg);
3563 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3564 ret = -EINVAL;
3565 goto done;
3566 }
3567
3568 /* station based encryption and other than WEP algorithms require
3569 * host-based encryption, so force them on automatically */
3570 local->host_decrypt = local->host_encrypt = 1;
3571
3572 if (*crypt == NULL || (*crypt)->ops != ops) {
3573 struct ieee80211_crypt_data *new_crypt;
3574
3575 prism2_crypt_delayed_deinit(local, crypt);
3576
3577 new_crypt = (struct ieee80211_crypt_data *)
3578 kmalloc(sizeof(struct ieee80211_crypt_data),
3579 GFP_KERNEL);
3580 if (new_crypt == NULL) {
3581 ret = -ENOMEM;
3582 goto done;
3583 }
3584 memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
3585 new_crypt->ops = ops;
3586 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3587 if (new_crypt->priv == NULL) {
3588 kfree(new_crypt);
3589 param->u.crypt.err =
3590 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3591 ret = -EINVAL;
3592 goto done;
3593 }
3594
3595 *crypt = new_crypt;
3596 }
3597
3598 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3599 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3600 (*crypt)->ops->set_key(param->u.crypt.key,
3601 param->u.crypt.key_len, param->u.crypt.seq,
3602 (*crypt)->priv) < 0) {
3603 printk(KERN_DEBUG "%s: key setting failed\n",
3604 local->dev->name);
3605 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3606 ret = -EINVAL;
3607 goto done;
3608 }
3609
3610 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3611 if (!sta_ptr)
3612 local->tx_keyidx = param->u.crypt.idx;
3613 else if (param->u.crypt.idx) {
3614 printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3615 local->dev->name);
3616 param->u.crypt.err =
3617 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3618 ret = -EINVAL;
3619 goto done;
3620 }
3621 }
3622
3623 done:
3624 if (sta_ptr)
3625 hostap_handle_sta_release(sta_ptr);
3626
3627 /* Do not reset port0 if card is in Managed mode since resetting will
3628 * generate new IEEE 802.11 authentication which may end up in looping
3629 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3630 * after WEP configuration. However, keys are apparently changed at
3631 * least in Managed mode. */
3632 if (ret == 0 &&
3633 (hostap_set_encryption(local) ||
3634 (local->iw_mode != IW_MODE_INFRA &&
3635 local->func->reset_port(local->dev)))) {
3636 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3637 return -EINVAL;
3638 }
3639
3640 return ret;
3641}
3642
3643
3644static int prism2_ioctl_get_encryption(local_info_t *local,
3645 struct prism2_hostapd_param *param,
3646 int param_len)
3647{
3648 struct ieee80211_crypt_data **crypt;
3649 void *sta_ptr;
3650 int max_key_len;
3651
3652 param->u.crypt.err = 0;
3653
3654 max_key_len = param_len -
3655 (int) ((char *) param->u.crypt.key - (char *) param);
3656 if (max_key_len < 0)
3657 return -EINVAL;
3658
3659 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3660 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3661 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3662 sta_ptr = NULL;
3663 if (param->u.crypt.idx >= WEP_KEYS)
3664 param->u.crypt.idx = local->tx_keyidx;
3665 crypt = &local->crypt[param->u.crypt.idx];
3666 } else {
3667 param->u.crypt.idx = 0;
3668 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3669 &crypt);
3670
3671 if (sta_ptr == NULL) {
3672 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3673 return -EINVAL;
3674 }
3675 }
3676
3677 if (*crypt == NULL || (*crypt)->ops == NULL) {
3678 memcpy(param->u.crypt.alg, "none", 5);
3679 param->u.crypt.key_len = 0;
3680 param->u.crypt.idx = 0xff;
3681 } else {
3682 strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3683 HOSTAP_CRYPT_ALG_NAME_LEN);
3684 param->u.crypt.key_len = 0;
3685
3686 memset(param->u.crypt.seq, 0, 8);
3687 if ((*crypt)->ops->get_key) {
3688 param->u.crypt.key_len =
3689 (*crypt)->ops->get_key(param->u.crypt.key,
3690 max_key_len,
3691 param->u.crypt.seq,
3692 (*crypt)->priv);
3693 }
3694 }
3695
3696 if (sta_ptr)
3697 hostap_handle_sta_release(sta_ptr);
3698
3699 return 0;
3700}
3701
3702
3703static int prism2_ioctl_get_rid(local_info_t *local,
3704 struct prism2_hostapd_param *param,
3705 int param_len)
3706{
3707 int max_len, res;
3708
3709 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3710 if (max_len < 0)
3711 return -EINVAL;
3712
3713 res = local->func->get_rid(local->dev, param->u.rid.rid,
3714 param->u.rid.data, param->u.rid.len, 0);
3715 if (res >= 0) {
3716 param->u.rid.len = res;
3717 return 0;
3718 }
3719
3720 return res;
3721}
3722
3723
3724static int prism2_ioctl_set_rid(local_info_t *local,
3725 struct prism2_hostapd_param *param,
3726 int param_len)
3727{
3728 int max_len;
3729
3730 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3731 if (max_len < 0 || max_len < param->u.rid.len)
3732 return -EINVAL;
3733
3734 return local->func->set_rid(local->dev, param->u.rid.rid,
3735 param->u.rid.data, param->u.rid.len);
3736}
3737
3738
3739static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3740 struct prism2_hostapd_param *param,
3741 int param_len)
3742{
3743 printk(KERN_DEBUG "%ssta: associated as client with AP " MACSTR "\n",
3744 local->dev->name, MAC2STR(param->sta_addr));
3745 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3746 return 0;
3747}
3748
3749
3750static int prism2_ioctl_siwgenie(struct net_device *dev,
3751 struct iw_request_info *info,
3752 struct iw_point *data, char *extra)
3753{
3754 return prism2_set_genericelement(dev, extra, data->length);
3755}
3756
3757
3758static int prism2_ioctl_giwgenie(struct net_device *dev,
3759 struct iw_request_info *info,
3760 struct iw_point *data, char *extra)
3761{
3762 struct hostap_interface *iface = dev->priv;
3763 local_info_t *local = iface->local;
3764 int len = local->generic_elem_len - 2;
3765
3766 if (len <= 0 || local->generic_elem == NULL) {
3767 data->length = 0;
3768 return 0;
3769 }
3770
3771 if (data->length < len)
3772 return -E2BIG;
3773
3774 data->length = len;
3775 memcpy(extra, local->generic_elem + 2, len);
3776
3777 return 0;
3778}
3779
3780
3781static int prism2_ioctl_set_generic_element(local_info_t *local,
3782 struct prism2_hostapd_param *param,
3783 int param_len)
3784{
3785 int max_len, len;
3786
3787 len = param->u.generic_elem.len;
3788 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3789 if (max_len < 0 || max_len < len)
3790 return -EINVAL;
3791
3792 return prism2_set_genericelement(local->dev,
3793 param->u.generic_elem.data, len);
3794}
3795
3796
3797static int prism2_ioctl_siwmlme(struct net_device *dev,
3798 struct iw_request_info *info,
3799 struct iw_point *data, char *extra)
3800{
3801 struct hostap_interface *iface = dev->priv;
3802 local_info_t *local = iface->local;
3803 struct iw_mlme *mlme = (struct iw_mlme *) extra;
3804 u16 reason;
3805
3806 reason = cpu_to_le16(mlme->reason_code);
3807
3808 switch (mlme->cmd) {
3809 case IW_MLME_DEAUTH:
3810 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3811 WLAN_FC_STYPE_DEAUTH,
3812 (u8 *) &reason, 2);
3813 case IW_MLME_DISASSOC:
3814 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3815 WLAN_FC_STYPE_DISASSOC,
3816 (u8 *) &reason, 2);
3817 default:
3818 return -EOPNOTSUPP;
3819 }
3820}
3821
3822
3823static int prism2_ioctl_mlme(local_info_t *local,
3824 struct prism2_hostapd_param *param)
3825{
3826 u16 reason;
3827
3828 reason = cpu_to_le16(param->u.mlme.reason_code);
3829 switch (param->u.mlme.cmd) {
3830 case MLME_STA_DEAUTH:
3831 return prism2_sta_send_mgmt(local, param->sta_addr,
3832 WLAN_FC_STYPE_DEAUTH,
3833 (u8 *) &reason, 2);
3834 case MLME_STA_DISASSOC:
3835 return prism2_sta_send_mgmt(local, param->sta_addr,
3836 WLAN_FC_STYPE_DISASSOC,
3837 (u8 *) &reason, 2);
3838 default:
3839 return -EOPNOTSUPP;
3840 }
3841}
3842
3843
3844static int prism2_ioctl_scan_req(local_info_t *local,
3845 struct prism2_hostapd_param *param)
3846{
3847#ifndef PRISM2_NO_STATION_MODES
3848 if ((local->iw_mode != IW_MODE_INFRA &&
3849 local->iw_mode != IW_MODE_ADHOC) ||
3850 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3851 return -EOPNOTSUPP;
3852
3853 if (!local->dev_enabled)
3854 return -ENETDOWN;
3855
3856 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3857 param->u.scan_req.ssid_len);
3858#else /* PRISM2_NO_STATION_MODES */
3859 return -EOPNOTSUPP;
3860#endif /* PRISM2_NO_STATION_MODES */
3861}
3862
3863
3864static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3865{
3866 struct prism2_hostapd_param *param;
3867 int ret = 0;
3868 int ap_ioctl = 0;
3869
3870 if (p->length < sizeof(struct prism2_hostapd_param) ||
3871 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3872 return -EINVAL;
3873
3874 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
3875 if (param == NULL)
3876 return -ENOMEM;
3877
3878 if (copy_from_user(param, p->pointer, p->length)) {
3879 ret = -EFAULT;
3880 goto out;
3881 }
3882
3883 switch (param->cmd) {
3884 case PRISM2_SET_ENCRYPTION:
3885 ret = prism2_ioctl_set_encryption(local, param, p->length);
3886 break;
3887 case PRISM2_GET_ENCRYPTION:
3888 ret = prism2_ioctl_get_encryption(local, param, p->length);
3889 break;
3890 case PRISM2_HOSTAPD_GET_RID:
3891 ret = prism2_ioctl_get_rid(local, param, p->length);
3892 break;
3893 case PRISM2_HOSTAPD_SET_RID:
3894 ret = prism2_ioctl_set_rid(local, param, p->length);
3895 break;
3896 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3897 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3898 break;
3899 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3900 ret = prism2_ioctl_set_generic_element(local, param,
3901 p->length);
3902 break;
3903 case PRISM2_HOSTAPD_MLME:
3904 ret = prism2_ioctl_mlme(local, param);
3905 break;
3906 case PRISM2_HOSTAPD_SCAN_REQ:
3907 ret = prism2_ioctl_scan_req(local, param);
3908 break;
3909 default:
3910 ret = prism2_hostapd(local->ap, param);
3911 ap_ioctl = 1;
3912 break;
3913 }
3914
3915 if (ret == 1 || !ap_ioctl) {
3916 if (copy_to_user(p->pointer, param, p->length)) {
3917 ret = -EFAULT;
3918 goto out;
3919 } else if (ap_ioctl)
3920 ret = 0;
3921 }
3922
3923 out:
3924 if (param != NULL)
3925 kfree(param);
3926
3927 return ret;
3928}
3929
3930
3931static void prism2_get_drvinfo(struct net_device *dev,
3932 struct ethtool_drvinfo *info)
3933{
3934 struct hostap_interface *iface;
3935 local_info_t *local;
3936
3937 iface = netdev_priv(dev);
3938 local = iface->local;
3939
3940 strncpy(info->driver, "hostap", sizeof(info->driver) - 1);
3941 strncpy(info->version, PRISM2_VERSION,
3942 sizeof(info->version) - 1);
3943 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
3944 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3945 (local->sta_fw_ver >> 8) & 0xff,
3946 local->sta_fw_ver & 0xff);
3947}
3948
3949static struct ethtool_ops prism2_ethtool_ops = {
3950 .get_drvinfo = prism2_get_drvinfo
3951};
3952
3953
3954/* Structures to export the Wireless Handlers */
3955
3956static const iw_handler prism2_handler[] =
3957{
3958 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3959 (iw_handler) prism2_get_name, /* SIOCGIWNAME */
3960 (iw_handler) NULL, /* SIOCSIWNWID */
3961 (iw_handler) NULL, /* SIOCGIWNWID */
3962 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
3963 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
3964 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
3965 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
3966 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
3967 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
3968 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3969 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
3970 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3971 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3972 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3973 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
3974 iw_handler_set_spy, /* SIOCSIWSPY */
3975 iw_handler_get_spy, /* SIOCGIWSPY */
3976 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3977 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3978 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
3979 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
3980 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
3981 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
3982 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
3983 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
3984 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
3985 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
3986 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
3987 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
3988 (iw_handler) NULL, /* -- hole -- */
3989 (iw_handler) NULL, /* -- hole -- */
3990 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
3991 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
3992 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
3993 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
3994 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
3995 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
3996 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
3997 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
3998 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
3999 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
4000 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
4001 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
4002 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
4003 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
4004 (iw_handler) NULL, /* -- hole -- */
4005 (iw_handler) NULL, /* -- hole -- */
4006 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
4007 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
4008 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
4009 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
4010 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
4011 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
4012 (iw_handler) NULL, /* SIOCSIWPMKSA */
4013 (iw_handler) NULL, /* -- hole -- */
4014};
4015
4016static const iw_handler prism2_private_handler[] =
4017{ /* SIOCIWFIRSTPRIV + */
4018 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
4019 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
4020 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
4021 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
4022};
4023
4024static const struct iw_handler_def hostap_iw_handler_def =
4025{
4026 .num_standard = sizeof(prism2_handler) / sizeof(iw_handler),
4027 .num_private = sizeof(prism2_private_handler) / sizeof(iw_handler),
4028 .num_private_args = sizeof(prism2_priv) / sizeof(struct iw_priv_args),
4029 .standard = (iw_handler *) prism2_handler,
4030 .private = (iw_handler *) prism2_private_handler,
4031 .private_args = (struct iw_priv_args *) prism2_priv,
4032 .get_wireless_stats = hostap_get_wireless_stats,
4033};
4034
4035
4036int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4037{
4038 struct iwreq *wrq = (struct iwreq *) ifr;
4039 struct hostap_interface *iface;
4040 local_info_t *local;
4041 int ret = 0;
4042
4043 iface = netdev_priv(dev);
4044 local = iface->local;
4045
4046 switch (cmd) {
4047 /* Private ioctls (iwpriv) that have not yet been converted
4048 * into new wireless extensions API */
4049
4050 case PRISM2_IOCTL_INQUIRE:
4051 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4052 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
4053 break;
4054
4055 case PRISM2_IOCTL_MONITOR:
4056 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4057 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
4058 break;
4059
4060 case PRISM2_IOCTL_RESET:
4061 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4062 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
4063 break;
4064
4065 case PRISM2_IOCTL_WDS_ADD:
4066 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4067 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
4068 break;
4069
4070 case PRISM2_IOCTL_WDS_DEL:
4071 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4072 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
4073 break;
4074
4075 case PRISM2_IOCTL_SET_RID_WORD:
4076 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4077 else ret = prism2_ioctl_priv_set_rid_word(dev,
4078 (int *) wrq->u.name);
4079 break;
4080
4081#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4082 case PRISM2_IOCTL_MACCMD:
4083 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4084 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4085 break;
4086
4087 case PRISM2_IOCTL_ADDMAC:
4088 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4089 else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4090 wrq->u.ap_addr.sa_data);
4091 break;
4092 case PRISM2_IOCTL_DELMAC:
4093 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4094 else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4095 wrq->u.ap_addr.sa_data);
4096 break;
4097 case PRISM2_IOCTL_KICKMAC:
4098 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4099 else ret = ap_control_kick_mac(local->ap, local->dev,
4100 wrq->u.ap_addr.sa_data);
4101 break;
4102#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4103
4104
4105 /* Private ioctls that are not used with iwpriv;
4106 * in SIOCDEVPRIVATE range */
4107
4108#ifdef PRISM2_DOWNLOAD_SUPPORT
4109 case PRISM2_IOCTL_DOWNLOAD:
4110 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4111 else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4112 break;
4113#endif /* PRISM2_DOWNLOAD_SUPPORT */
4114
4115 case PRISM2_IOCTL_HOSTAPD:
4116 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4117 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);
4118 break;
4119
4120 default:
4121 ret = -EOPNOTSUPP;
4122 break;
4123 }
4124
4125 return ret;
4126}
diff --git a/drivers/net/wireless/hostap/hostap_pci.c b/drivers/net/wireless/hostap/hostap_pci.c
new file mode 100644
index 000000000000..786c146f533e
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_pci.c
@@ -0,0 +1,455 @@
1#define PRISM2_PCI
2
3/* Host AP driver's support for Intersil Prism2.5 PCI cards is based on
4 * driver patches from Reyk Floeter <reyk@vantronix.net> and
5 * Andy Warner <andyw@pobox.com> */
6
7#include <linux/config.h>
8#include <linux/version.h>
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/if.h>
12#include <linux/skbuff.h>
13#include <linux/netdevice.h>
14#include <linux/workqueue.h>
15#include <linux/wireless.h>
16#include <net/iw_handler.h>
17
18#include <linux/ioport.h>
19#include <linux/pci.h>
20#include <asm/io.h>
21
22#include "hostap_wlan.h"
23
24
25static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
26static char *dev_info = "hostap_pci";
27
28
29MODULE_AUTHOR("Jouni Malinen");
30MODULE_DESCRIPTION("Support for Intersil Prism2.5-based 802.11 wireless LAN "
31 "PCI cards.");
32MODULE_SUPPORTED_DEVICE("Intersil Prism2.5-based WLAN PCI cards");
33MODULE_LICENSE("GPL");
34MODULE_VERSION(PRISM2_VERSION);
35
36
37/* FIX: do we need mb/wmb/rmb with memory operations? */
38
39
40static struct pci_device_id prism2_pci_id_table[] __devinitdata = {
41 /* Intersil Prism3 ISL3872 11Mb/s WLAN Controller */
42 { 0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID },
43 /* Intersil Prism2.5 ISL3874 11Mb/s WLAN Controller */
44 { 0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID },
45 /* Samsung MagicLAN SWL-2210P */
46 { 0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID },
47 { 0 }
48};
49
50
51#ifdef PRISM2_IO_DEBUG
52
53static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
54{
55 struct hostap_interface *iface;
56 local_info_t *local;
57 unsigned long flags;
58
59 iface = netdev_priv(dev);
60 local = iface->local;
61
62 spin_lock_irqsave(&local->lock, flags);
63 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
64 writeb(v, local->mem_start + a);
65 spin_unlock_irqrestore(&local->lock, flags);
66}
67
68static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
69{
70 struct hostap_interface *iface;
71 local_info_t *local;
72 unsigned long flags;
73 u8 v;
74
75 iface = netdev_priv(dev);
76 local = iface->local;
77
78 spin_lock_irqsave(&local->lock, flags);
79 v = readb(local->mem_start + a);
80 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
81 spin_unlock_irqrestore(&local->lock, flags);
82 return v;
83}
84
85static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
86{
87 struct hostap_interface *iface;
88 local_info_t *local;
89 unsigned long flags;
90
91 iface = netdev_priv(dev);
92 local = iface->local;
93
94 spin_lock_irqsave(&local->lock, flags);
95 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
96 writew(v, local->mem_start + a);
97 spin_unlock_irqrestore(&local->lock, flags);
98}
99
100static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
101{
102 struct hostap_interface *iface;
103 local_info_t *local;
104 unsigned long flags;
105 u16 v;
106
107 iface = netdev_priv(dev);
108 local = iface->local;
109
110 spin_lock_irqsave(&local->lock, flags);
111 v = readw(local->mem_start + a);
112 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
113 spin_unlock_irqrestore(&local->lock, flags);
114 return v;
115}
116
117#define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
118#define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
119#define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
120#define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
121#define HFA384X_OUTW_DATA(v,a) hfa384x_outw_debug(dev, (a), cpu_to_le16((v)))
122#define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw_debug(dev, (a)))
123
124#else /* PRISM2_IO_DEBUG */
125
126static inline void hfa384x_outb(struct net_device *dev, int a, u8 v)
127{
128 struct hostap_interface *iface;
129 local_info_t *local;
130 iface = netdev_priv(dev);
131 local = iface->local;
132 writeb(v, local->mem_start + a);
133}
134
135static inline u8 hfa384x_inb(struct net_device *dev, int a)
136{
137 struct hostap_interface *iface;
138 local_info_t *local;
139 iface = netdev_priv(dev);
140 local = iface->local;
141 return readb(local->mem_start + a);
142}
143
144static inline void hfa384x_outw(struct net_device *dev, int a, u16 v)
145{
146 struct hostap_interface *iface;
147 local_info_t *local;
148 iface = netdev_priv(dev);
149 local = iface->local;
150 writew(v, local->mem_start + a);
151}
152
153static inline u16 hfa384x_inw(struct net_device *dev, int a)
154{
155 struct hostap_interface *iface;
156 local_info_t *local;
157 iface = netdev_priv(dev);
158 local = iface->local;
159 return readw(local->mem_start + a);
160}
161
162#define HFA384X_OUTB(v,a) hfa384x_outb(dev, (a), (v))
163#define HFA384X_INB(a) hfa384x_inb(dev, (a))
164#define HFA384X_OUTW(v,a) hfa384x_outw(dev, (a), (v))
165#define HFA384X_INW(a) hfa384x_inw(dev, (a))
166#define HFA384X_OUTW_DATA(v,a) hfa384x_outw(dev, (a), cpu_to_le16((v)))
167#define HFA384X_INW_DATA(a) (u16) le16_to_cpu(hfa384x_inw(dev, (a)))
168
169#endif /* PRISM2_IO_DEBUG */
170
171
172static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
173 int len)
174{
175 u16 d_off;
176 u16 *pos;
177
178 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
179 pos = (u16 *) buf;
180
181 for ( ; len > 1; len -= 2)
182 *pos++ = HFA384X_INW_DATA(d_off);
183
184 if (len & 1)
185 *((char *) pos) = HFA384X_INB(d_off);
186
187 return 0;
188}
189
190
191static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
192{
193 u16 d_off;
194 u16 *pos;
195
196 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
197 pos = (u16 *) buf;
198
199 for ( ; len > 1; len -= 2)
200 HFA384X_OUTW_DATA(*pos++, d_off);
201
202 if (len & 1)
203 HFA384X_OUTB(*((char *) pos), d_off);
204
205 return 0;
206}
207
208
209/* FIX: This might change at some point.. */
210#include "hostap_hw.c"
211
212static void prism2_pci_cor_sreset(local_info_t *local)
213{
214 struct net_device *dev = local->dev;
215 u16 reg;
216
217 reg = HFA384X_INB(HFA384X_PCICOR_OFF);
218 printk(KERN_DEBUG "%s: Original COR value: 0x%0x\n", dev->name, reg);
219
220 /* linux-wlan-ng uses extremely long hold and settle times for
221 * COR sreset. A comment in the driver code mentions that the long
222 * delays appear to be necessary. However, at least IBM 22P6901 seems
223 * to work fine with shorter delays.
224 *
225 * Longer delays can be configured by uncommenting following line: */
226/* #define PRISM2_PCI_USE_LONG_DELAYS */
227
228#ifdef PRISM2_PCI_USE_LONG_DELAYS
229 int i;
230
231 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
232 mdelay(250);
233
234 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
235 mdelay(500);
236
237 /* Wait for f/w to complete initialization (CMD:BUSY == 0) */
238 i = 2000000 / 10;
239 while ((HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) && --i)
240 udelay(10);
241
242#else /* PRISM2_PCI_USE_LONG_DELAYS */
243
244 HFA384X_OUTW(reg | 0x0080, HFA384X_PCICOR_OFF);
245 mdelay(2);
246 HFA384X_OUTW(reg & ~0x0080, HFA384X_PCICOR_OFF);
247 mdelay(2);
248
249#endif /* PRISM2_PCI_USE_LONG_DELAYS */
250
251 if (HFA384X_INW(HFA384X_CMD_OFF) & HFA384X_CMD_BUSY) {
252 printk(KERN_DEBUG "%s: COR sreset timeout\n", dev->name);
253 }
254}
255
256
257static void prism2_pci_genesis_reset(local_info_t *local, int hcr)
258{
259 struct net_device *dev = local->dev;
260
261 HFA384X_OUTW(0x00C5, HFA384X_PCICOR_OFF);
262 mdelay(10);
263 HFA384X_OUTW(hcr, HFA384X_PCIHCR_OFF);
264 mdelay(10);
265 HFA384X_OUTW(0x0045, HFA384X_PCICOR_OFF);
266 mdelay(10);
267}
268
269
270static struct prism2_helper_functions prism2_pci_funcs =
271{
272 .card_present = NULL,
273 .cor_sreset = prism2_pci_cor_sreset,
274 .dev_open = NULL,
275 .dev_close = NULL,
276 .genesis_reset = prism2_pci_genesis_reset,
277 .hw_type = HOSTAP_HW_PCI,
278};
279
280
281static int prism2_pci_probe(struct pci_dev *pdev,
282 const struct pci_device_id *id)
283{
284 unsigned long phymem;
285 void __iomem *mem = NULL;
286 local_info_t *local = NULL;
287 struct net_device *dev = NULL;
288 static int cards_found /* = 0 */;
289 int irq_registered = 0;
290 struct hostap_interface *iface;
291
292 if (pci_enable_device(pdev))
293 return -EIO;
294
295 phymem = pci_resource_start(pdev, 0);
296
297 if (!request_mem_region(phymem, pci_resource_len(pdev, 0), "Prism2")) {
298 printk(KERN_ERR "prism2: Cannot reserve PCI memory region\n");
299 goto err_out_disable;
300 }
301
302 mem = ioremap(phymem, pci_resource_len(pdev, 0));
303 if (mem == NULL) {
304 printk(KERN_ERR "prism2: Cannot remap PCI memory region\n") ;
305 goto fail;
306 }
307
308#ifdef PRISM2_BUS_MASTER
309 pci_set_master(pdev);
310#endif /* PRISM2_BUS_MASTER */
311
312 dev = prism2_init_local_data(&prism2_pci_funcs, cards_found,
313 &pdev->dev);
314 if (dev == NULL)
315 goto fail;
316 iface = netdev_priv(dev);
317 local = iface->local;
318 cards_found++;
319
320 dev->irq = pdev->irq;
321 local->mem_start = mem;
322
323 prism2_pci_cor_sreset(local);
324
325 pci_set_drvdata(pdev, dev);
326
327 if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name,
328 dev)) {
329 printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
330 goto fail;
331 } else
332 irq_registered = 1;
333
334 if (!local->pri_only && prism2_hw_config(dev, 1)) {
335 printk(KERN_DEBUG "%s: hardware initialization failed\n",
336 dev_info);
337 goto fail;
338 }
339
340 printk(KERN_INFO "%s: Intersil Prism2.5 PCI: "
341 "mem=0x%lx, irq=%d\n", dev->name, phymem, dev->irq);
342
343 return hostap_hw_ready(dev);
344
345 fail:
346 if (irq_registered && dev)
347 free_irq(dev->irq, dev);
348
349 if (mem)
350 iounmap(mem);
351
352 release_mem_region(phymem, pci_resource_len(pdev, 0));
353
354 err_out_disable:
355 pci_disable_device(pdev);
356 prism2_free_local_data(dev);
357
358 return -ENODEV;
359}
360
361
362static void prism2_pci_remove(struct pci_dev *pdev)
363{
364 struct net_device *dev;
365 struct hostap_interface *iface;
366 void __iomem *mem_start;
367
368 dev = pci_get_drvdata(pdev);
369 iface = netdev_priv(dev);
370
371 /* Reset the hardware, and ensure interrupts are disabled. */
372 prism2_pci_cor_sreset(iface->local);
373 hfa384x_disable_interrupts(dev);
374
375 if (dev->irq)
376 free_irq(dev->irq, dev);
377
378 mem_start = iface->local->mem_start;
379 prism2_free_local_data(dev);
380
381 iounmap(mem_start);
382
383 release_mem_region(pci_resource_start(pdev, 0),
384 pci_resource_len(pdev, 0));
385 pci_disable_device(pdev);
386}
387
388
389#ifdef CONFIG_PM
390static int prism2_pci_suspend(struct pci_dev *pdev, u32 state)
391{
392 struct net_device *dev = pci_get_drvdata(pdev);
393
394 if (netif_running(dev)) {
395 netif_stop_queue(dev);
396 netif_device_detach(dev);
397 }
398 prism2_suspend(dev);
399 pci_save_state(pdev);
400 pci_disable_device(pdev);
401 pci_set_power_state(pdev, 3);
402
403 return 0;
404}
405
406static int prism2_pci_resume(struct pci_dev *pdev)
407{
408 struct net_device *dev = pci_get_drvdata(pdev);
409
410 pci_enable_device(pdev);
411 pci_restore_state(pdev);
412 prism2_hw_config(dev, 0);
413 if (netif_running(dev)) {
414 netif_device_attach(dev);
415 netif_start_queue(dev);
416 }
417
418 return 0;
419}
420#endif /* CONFIG_PM */
421
422
423MODULE_DEVICE_TABLE(pci, prism2_pci_id_table);
424
425static struct pci_driver prism2_pci_drv_id = {
426 .name = "prism2_pci",
427 .id_table = prism2_pci_id_table,
428 .probe = prism2_pci_probe,
429 .remove = prism2_pci_remove,
430#ifdef CONFIG_PM
431 .suspend = prism2_pci_suspend,
432 .resume = prism2_pci_resume,
433#endif /* CONFIG_PM */
434 /* Linux 2.4.6 added save_state and enable_wake that are not used here
435 */
436};
437
438
439static int __init init_prism2_pci(void)
440{
441 printk(KERN_INFO "%s: %s\n", dev_info, version);
442
443 return pci_register_driver(&prism2_pci_drv_id);
444}
445
446
447static void __exit exit_prism2_pci(void)
448{
449 pci_unregister_driver(&prism2_pci_drv_id);
450 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
451}
452
453
454module_init(init_prism2_pci);
455module_exit(exit_prism2_pci);
diff --git a/drivers/net/wireless/hostap/hostap_plx.c b/drivers/net/wireless/hostap/hostap_plx.c
new file mode 100644
index 000000000000..c2f5b1f2b857
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_plx.c
@@ -0,0 +1,622 @@
1#define PRISM2_PLX
2
3/* Host AP driver's support for PC Cards on PCI adapters using PLX9052 is
4 * based on:
5 * - Host AP driver patch from james@madingley.org
6 * - linux-wlan-ng driver, Copyright (C) AbsoluteValue Systems, Inc.
7 */
8
9
10#include <linux/config.h>
11#include <linux/version.h>
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/if.h>
15#include <linux/skbuff.h>
16#include <linux/netdevice.h>
17#include <linux/workqueue.h>
18#include <linux/wireless.h>
19#include <net/iw_handler.h>
20
21#include <linux/ioport.h>
22#include <linux/pci.h>
23#include <asm/io.h>
24
25#include "hostap_wlan.h"
26
27
28static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)";
29static char *dev_info = "hostap_plx";
30
31
32MODULE_AUTHOR("Jouni Malinen");
33MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
34 "cards (PLX).");
35MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PLX)");
36MODULE_LICENSE("GPL");
37MODULE_VERSION(PRISM2_VERSION);
38
39
40static int ignore_cis;
41module_param(ignore_cis, int, 0444);
42MODULE_PARM_DESC(ignore_cis, "Do not verify manfid information in CIS");
43
44
45#define PLX_MIN_ATTR_LEN 512 /* at least 2 x 256 is needed for CIS */
46#define COR_SRESET 0x80
47#define COR_LEVLREQ 0x40
48#define COR_ENABLE_FUNC 0x01
49/* PCI Configuration Registers */
50#define PLX_PCIIPR 0x3d /* PCI Interrupt Pin */
51/* Local Configuration Registers */
52#define PLX_INTCSR 0x4c /* Interrupt Control/Status Register */
53#define PLX_INTCSR_PCI_INTEN BIT(6) /* PCI Interrupt Enable */
54#define PLX_CNTRL 0x50
55#define PLX_CNTRL_SERIAL_EEPROM_PRESENT BIT(28)
56
57
58#define PLXDEV(vendor,dev,str) { vendor, dev, PCI_ANY_ID, PCI_ANY_ID }
59
60static struct pci_device_id prism2_plx_id_table[] __devinitdata = {
61 PLXDEV(0x10b7, 0x7770, "3Com AirConnect PCI 777A"),
62 PLXDEV(0x111a, 0x1023, "Siemens SpeedStream SS1023"),
63 PLXDEV(0x126c, 0x8030, "Nortel emobility"),
64 PLXDEV(0x1385, 0x4100, "Netgear MA301"),
65 PLXDEV(0x15e8, 0x0130, "National Datacomm NCP130 (PLX9052)"),
66 PLXDEV(0x15e8, 0x0131, "National Datacomm NCP130 (TMD7160)"),
67 PLXDEV(0x1638, 0x1100, "Eumitcom WL11000"),
68 PLXDEV(0x16ab, 0x1101, "Global Sun Tech GL24110P (?)"),
69 PLXDEV(0x16ab, 0x1102, "Linksys WPC11 with WDT11"),
70 PLXDEV(0x16ab, 0x1103, "Longshine 8031"),
71 PLXDEV(0x16ec, 0x3685, "US Robotics USR2415"),
72 PLXDEV(0xec80, 0xec00, "Belkin F5D6000"),
73 { 0 }
74};
75
76
77/* Array of known Prism2/2.5 PC Card manufactured ids. If your card's manfid
78 * is not listed here, you will need to add it here to get the driver
79 * initialized. */
80static struct prism2_plx_manfid {
81 u16 manfid1, manfid2;
82} prism2_plx_known_manfids[] = {
83 { 0x000b, 0x7110 } /* D-Link DWL-650 Rev. P1 */,
84 { 0x000b, 0x7300 } /* Philips 802.11b WLAN PCMCIA */,
85 { 0x0101, 0x0777 } /* 3Com AirConnect PCI 777A */,
86 { 0x0126, 0x8000 } /* Proxim RangeLAN */,
87 { 0x0138, 0x0002 } /* Compaq WL100 */,
88 { 0x0156, 0x0002 } /* Intersil Prism II Ref. Design (and others) */,
89 { 0x026f, 0x030b } /* Buffalo WLI-CF-S11G */,
90 { 0x0274, 0x1612 } /* Linksys WPC11 Ver 2.5 */,
91 { 0x0274, 0x1613 } /* Linksys WPC11 Ver 3 */,
92 { 0x028a, 0x0002 } /* D-Link DRC-650 */,
93 { 0x0250, 0x0002 } /* Samsung SWL2000-N */,
94 { 0xc250, 0x0002 } /* EMTAC A2424i */,
95 { 0xd601, 0x0002 } /* Z-Com XI300 */,
96 { 0xd601, 0x0005 } /* Zcomax XI-325H 200mW */,
97 { 0, 0}
98};
99
100
101#ifdef PRISM2_IO_DEBUG
102
103static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
104{
105 struct hostap_interface *iface;
106 local_info_t *local;
107 unsigned long flags;
108
109 iface = netdev_priv(dev);
110 local = iface->local;
111
112 spin_lock_irqsave(&local->lock, flags);
113 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
114 outb(v, dev->base_addr + a);
115 spin_unlock_irqrestore(&local->lock, flags);
116}
117
118static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
119{
120 struct hostap_interface *iface;
121 local_info_t *local;
122 unsigned long flags;
123 u8 v;
124
125 iface = netdev_priv(dev);
126 local = iface->local;
127
128 spin_lock_irqsave(&local->lock, flags);
129 v = inb(dev->base_addr + a);
130 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
131 spin_unlock_irqrestore(&local->lock, flags);
132 return v;
133}
134
135static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
136{
137 struct hostap_interface *iface;
138 local_info_t *local;
139 unsigned long flags;
140
141 iface = netdev_priv(dev);
142 local = iface->local;
143
144 spin_lock_irqsave(&local->lock, flags);
145 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
146 outw(v, dev->base_addr + a);
147 spin_unlock_irqrestore(&local->lock, flags);
148}
149
150static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
151{
152 struct hostap_interface *iface;
153 local_info_t *local;
154 unsigned long flags;
155 u16 v;
156
157 iface = netdev_priv(dev);
158 local = iface->local;
159
160 spin_lock_irqsave(&local->lock, flags);
161 v = inw(dev->base_addr + a);
162 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
163 spin_unlock_irqrestore(&local->lock, flags);
164 return v;
165}
166
167static inline void hfa384x_outsw_debug(struct net_device *dev, int a,
168 u8 *buf, int wc)
169{
170 struct hostap_interface *iface;
171 local_info_t *local;
172 unsigned long flags;
173
174 iface = netdev_priv(dev);
175 local = iface->local;
176
177 spin_lock_irqsave(&local->lock, flags);
178 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc);
179 outsw(dev->base_addr + a, buf, wc);
180 spin_unlock_irqrestore(&local->lock, flags);
181}
182
183static inline void hfa384x_insw_debug(struct net_device *dev, int a,
184 u8 *buf, int wc)
185{
186 struct hostap_interface *iface;
187 local_info_t *local;
188 unsigned long flags;
189
190 iface = netdev_priv(dev);
191 local = iface->local;
192
193 spin_lock_irqsave(&local->lock, flags);
194 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc);
195 insw(dev->base_addr + a, buf, wc);
196 spin_unlock_irqrestore(&local->lock, flags);
197}
198
199#define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
200#define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
201#define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
202#define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
203#define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc))
204#define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc))
205
206#else /* PRISM2_IO_DEBUG */
207
208#define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a))
209#define HFA384X_INB(a) inb(dev->base_addr + (a))
210#define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a))
211#define HFA384X_INW(a) inw(dev->base_addr + (a))
212#define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc)
213#define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc)
214
215#endif /* PRISM2_IO_DEBUG */
216
217
218static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
219 int len)
220{
221 u16 d_off;
222 u16 *pos;
223
224 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
225 pos = (u16 *) buf;
226
227 if (len / 2)
228 HFA384X_INSW(d_off, buf, len / 2);
229 pos += len / 2;
230
231 if (len & 1)
232 *((char *) pos) = HFA384X_INB(d_off);
233
234 return 0;
235}
236
237
238static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
239{
240 u16 d_off;
241 u16 *pos;
242
243 d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
244 pos = (u16 *) buf;
245
246 if (len / 2)
247 HFA384X_OUTSW(d_off, buf, len / 2);
248 pos += len / 2;
249
250 if (len & 1)
251 HFA384X_OUTB(*((char *) pos), d_off);
252
253 return 0;
254}
255
256
257/* FIX: This might change at some point.. */
258#include "hostap_hw.c"
259
260
261static void prism2_plx_cor_sreset(local_info_t *local)
262{
263 unsigned char corsave;
264
265 printk(KERN_DEBUG "%s: Doing reset via direct COR access.\n",
266 dev_info);
267
268 /* Set sreset bit of COR and clear it after hold time */
269
270 if (local->attr_mem == NULL) {
271 /* TMD7160 - COR at card's first I/O addr */
272 corsave = inb(local->cor_offset);
273 outb(corsave | COR_SRESET, local->cor_offset);
274 mdelay(2);
275 outb(corsave & ~COR_SRESET, local->cor_offset);
276 mdelay(2);
277 } else {
278 /* PLX9052 */
279 corsave = readb(local->attr_mem + local->cor_offset);
280 writeb(corsave | COR_SRESET,
281 local->attr_mem + local->cor_offset);
282 mdelay(2);
283 writeb(corsave & ~COR_SRESET,
284 local->attr_mem + local->cor_offset);
285 mdelay(2);
286 }
287}
288
289
290static void prism2_plx_genesis_reset(local_info_t *local, int hcr)
291{
292 unsigned char corsave;
293
294 if (local->attr_mem == NULL) {
295 /* TMD7160 - COR at card's first I/O addr */
296 corsave = inb(local->cor_offset);
297 outb(corsave | COR_SRESET, local->cor_offset);
298 mdelay(10);
299 outb(hcr, local->cor_offset + 2);
300 mdelay(10);
301 outb(corsave & ~COR_SRESET, local->cor_offset);
302 mdelay(10);
303 } else {
304 /* PLX9052 */
305 corsave = readb(local->attr_mem + local->cor_offset);
306 writeb(corsave | COR_SRESET,
307 local->attr_mem + local->cor_offset);
308 mdelay(10);
309 writeb(hcr, local->attr_mem + local->cor_offset + 2);
310 mdelay(10);
311 writeb(corsave & ~COR_SRESET,
312 local->attr_mem + local->cor_offset);
313 mdelay(10);
314 }
315}
316
317
318static struct prism2_helper_functions prism2_plx_funcs =
319{
320 .card_present = NULL,
321 .cor_sreset = prism2_plx_cor_sreset,
322 .dev_open = NULL,
323 .dev_close = NULL,
324 .genesis_reset = prism2_plx_genesis_reset,
325 .hw_type = HOSTAP_HW_PLX,
326};
327
328
329static int prism2_plx_check_cis(void __iomem *attr_mem, int attr_len,
330 unsigned int *cor_offset,
331 unsigned int *cor_index)
332{
333#define CISTPL_CONFIG 0x1A
334#define CISTPL_MANFID 0x20
335#define CISTPL_END 0xFF
336#define CIS_MAX_LEN 256
337 u8 *cis;
338 int i, pos;
339 unsigned int rmsz, rasz, manfid1, manfid2;
340 struct prism2_plx_manfid *manfid;
341
342 cis = kmalloc(CIS_MAX_LEN, GFP_KERNEL);
343 if (cis == NULL)
344 return -ENOMEM;
345
346 /* read CIS; it is in even offsets in the beginning of attr_mem */
347 for (i = 0; i < CIS_MAX_LEN; i++)
348 cis[i] = readb(attr_mem + 2 * i);
349 printk(KERN_DEBUG "%s: CIS: %02x %02x %02x %02x %02x %02x ...\n",
350 dev_info, cis[0], cis[1], cis[2], cis[3], cis[4], cis[5]);
351
352 /* set reasonable defaults for Prism2 cards just in case CIS parsing
353 * fails */
354 *cor_offset = 0x3e0;
355 *cor_index = 0x01;
356 manfid1 = manfid2 = 0;
357
358 pos = 0;
359 while (pos < CIS_MAX_LEN - 1 && cis[pos] != CISTPL_END) {
360 if (pos + cis[pos + 1] >= CIS_MAX_LEN)
361 goto cis_error;
362
363 switch (cis[pos]) {
364 case CISTPL_CONFIG:
365 if (cis[pos + 1] < 1)
366 goto cis_error;
367 rmsz = (cis[pos + 2] & 0x3c) >> 2;
368 rasz = cis[pos + 2] & 0x03;
369 if (4 + rasz + rmsz > cis[pos + 1])
370 goto cis_error;
371 *cor_index = cis[pos + 3] & 0x3F;
372 *cor_offset = 0;
373 for (i = 0; i <= rasz; i++)
374 *cor_offset += cis[pos + 4 + i] << (8 * i);
375 printk(KERN_DEBUG "%s: cor_index=0x%x "
376 "cor_offset=0x%x\n", dev_info,
377 *cor_index, *cor_offset);
378 if (*cor_offset > attr_len) {
379 printk(KERN_ERR "%s: COR offset not within "
380 "attr_mem\n", dev_info);
381 kfree(cis);
382 return -1;
383 }
384 break;
385
386 case CISTPL_MANFID:
387 if (cis[pos + 1] < 4)
388 goto cis_error;
389 manfid1 = cis[pos + 2] + (cis[pos + 3] << 8);
390 manfid2 = cis[pos + 4] + (cis[pos + 5] << 8);
391 printk(KERN_DEBUG "%s: manfid=0x%04x, 0x%04x\n",
392 dev_info, manfid1, manfid2);
393 break;
394 }
395
396 pos += cis[pos + 1] + 2;
397 }
398
399 if (pos >= CIS_MAX_LEN || cis[pos] != CISTPL_END)
400 goto cis_error;
401
402 for (manfid = prism2_plx_known_manfids; manfid->manfid1 != 0; manfid++)
403 if (manfid1 == manfid->manfid1 && manfid2 == manfid->manfid2) {
404 kfree(cis);
405 return 0;
406 }
407
408 printk(KERN_INFO "%s: unknown manfid 0x%04x, 0x%04x - assuming this is"
409 " not supported card\n", dev_info, manfid1, manfid2);
410 goto fail;
411
412 cis_error:
413 printk(KERN_WARNING "%s: invalid CIS data\n", dev_info);
414
415 fail:
416 kfree(cis);
417 if (ignore_cis) {
418 printk(KERN_INFO "%s: ignore_cis parameter set - ignoring "
419 "errors during CIS verification\n", dev_info);
420 return 0;
421 }
422 return -1;
423}
424
425
426static int prism2_plx_probe(struct pci_dev *pdev,
427 const struct pci_device_id *id)
428{
429 unsigned int pccard_ioaddr, plx_ioaddr;
430 unsigned long pccard_attr_mem;
431 unsigned int pccard_attr_len;
432 void __iomem *attr_mem = NULL;
433 unsigned int cor_offset, cor_index;
434 u32 reg;
435 local_info_t *local = NULL;
436 struct net_device *dev = NULL;
437 struct hostap_interface *iface;
438 static int cards_found /* = 0 */;
439 int irq_registered = 0;
440 int tmd7160;
441
442 if (pci_enable_device(pdev))
443 return -EIO;
444
445 /* National Datacomm NCP130 based on TMD7160, not PLX9052. */
446 tmd7160 = (pdev->vendor == 0x15e8) && (pdev->device == 0x0131);
447
448 plx_ioaddr = pci_resource_start(pdev, 1);
449 pccard_ioaddr = pci_resource_start(pdev, tmd7160 ? 2 : 3);
450
451 if (tmd7160) {
452 /* TMD7160 */
453 attr_mem = NULL; /* no access to PC Card attribute memory */
454
455 printk(KERN_INFO "TMD7160 PCI/PCMCIA adapter: io=0x%x, "
456 "irq=%d, pccard_io=0x%x\n",
457 plx_ioaddr, pdev->irq, pccard_ioaddr);
458
459 cor_offset = plx_ioaddr;
460 cor_index = 0x04;
461
462 outb(cor_index | COR_LEVLREQ | COR_ENABLE_FUNC, plx_ioaddr);
463 mdelay(1);
464 reg = inb(plx_ioaddr);
465 if (reg != (cor_index | COR_LEVLREQ | COR_ENABLE_FUNC)) {
466 printk(KERN_ERR "%s: Error setting COR (expected="
467 "0x%02x, was=0x%02x)\n", dev_info,
468 cor_index | COR_LEVLREQ | COR_ENABLE_FUNC, reg);
469 goto fail;
470 }
471 } else {
472 /* PLX9052 */
473 pccard_attr_mem = pci_resource_start(pdev, 2);
474 pccard_attr_len = pci_resource_len(pdev, 2);
475 if (pccard_attr_len < PLX_MIN_ATTR_LEN)
476 goto fail;
477
478
479 attr_mem = ioremap(pccard_attr_mem, pccard_attr_len);
480 if (attr_mem == NULL) {
481 printk(KERN_ERR "%s: cannot remap attr_mem\n",
482 dev_info);
483 goto fail;
484 }
485
486 printk(KERN_INFO "PLX9052 PCI/PCMCIA adapter: "
487 "mem=0x%lx, plx_io=0x%x, irq=%d, pccard_io=0x%x\n",
488 pccard_attr_mem, plx_ioaddr, pdev->irq, pccard_ioaddr);
489
490 if (prism2_plx_check_cis(attr_mem, pccard_attr_len,
491 &cor_offset, &cor_index)) {
492 printk(KERN_INFO "Unknown PC Card CIS - not a "
493 "Prism2/2.5 card?\n");
494 goto fail;
495 }
496
497 printk(KERN_DEBUG "Prism2/2.5 PC Card detected in PLX9052 "
498 "adapter\n");
499
500 /* Write COR to enable PC Card */
501 writeb(cor_index | COR_LEVLREQ | COR_ENABLE_FUNC,
502 attr_mem + cor_offset);
503
504 /* Enable PCI interrupts if they are not already enabled */
505 reg = inl(plx_ioaddr + PLX_INTCSR);
506 printk(KERN_DEBUG "PLX_INTCSR=0x%x\n", reg);
507 if (!(reg & PLX_INTCSR_PCI_INTEN)) {
508 outl(reg | PLX_INTCSR_PCI_INTEN,
509 plx_ioaddr + PLX_INTCSR);
510 if (!(inl(plx_ioaddr + PLX_INTCSR) &
511 PLX_INTCSR_PCI_INTEN)) {
512 printk(KERN_WARNING "%s: Could not enable "
513 "Local Interrupts\n", dev_info);
514 goto fail;
515 }
516 }
517
518 reg = inl(plx_ioaddr + PLX_CNTRL);
519 printk(KERN_DEBUG "PLX_CNTRL=0x%x (Serial EEPROM "
520 "present=%d)\n",
521 reg, (reg & PLX_CNTRL_SERIAL_EEPROM_PRESENT) != 0);
522 /* should set PLX_PCIIPR to 0x01 (INTA#) if Serial EEPROM is
523 * not present; but are there really such cards in use(?) */
524 }
525
526 dev = prism2_init_local_data(&prism2_plx_funcs, cards_found,
527 &pdev->dev);
528 if (dev == NULL)
529 goto fail;
530 iface = netdev_priv(dev);
531 local = iface->local;
532 cards_found++;
533
534 dev->irq = pdev->irq;
535 dev->base_addr = pccard_ioaddr;
536 local->attr_mem = attr_mem;
537 local->cor_offset = cor_offset;
538
539 pci_set_drvdata(pdev, dev);
540
541 if (request_irq(dev->irq, prism2_interrupt, SA_SHIRQ, dev->name,
542 dev)) {
543 printk(KERN_WARNING "%s: request_irq failed\n", dev->name);
544 goto fail;
545 } else
546 irq_registered = 1;
547
548 if (prism2_hw_config(dev, 1)) {
549 printk(KERN_DEBUG "%s: hardware initialization failed\n",
550 dev_info);
551 goto fail;
552 }
553
554 return hostap_hw_ready(dev);
555
556 fail:
557 prism2_free_local_data(dev);
558
559 if (irq_registered && dev)
560 free_irq(dev->irq, dev);
561
562 if (attr_mem)
563 iounmap(attr_mem);
564
565 pci_disable_device(pdev);
566
567 return -ENODEV;
568}
569
570
571static void prism2_plx_remove(struct pci_dev *pdev)
572{
573 struct net_device *dev;
574 struct hostap_interface *iface;
575
576 dev = pci_get_drvdata(pdev);
577 iface = netdev_priv(dev);
578
579 /* Reset the hardware, and ensure interrupts are disabled. */
580 prism2_plx_cor_sreset(iface->local);
581 hfa384x_disable_interrupts(dev);
582
583 if (iface->local->attr_mem)
584 iounmap(iface->local->attr_mem);
585 if (dev->irq)
586 free_irq(dev->irq, dev);
587
588 prism2_free_local_data(dev);
589 pci_disable_device(pdev);
590}
591
592
593MODULE_DEVICE_TABLE(pci, prism2_plx_id_table);
594
595static struct pci_driver prism2_plx_drv_id = {
596 .name = "prism2_plx",
597 .id_table = prism2_plx_id_table,
598 .probe = prism2_plx_probe,
599 .remove = prism2_plx_remove,
600 .suspend = NULL,
601 .resume = NULL,
602 .enable_wake = NULL
603};
604
605
606static int __init init_prism2_plx(void)
607{
608 printk(KERN_INFO "%s: %s\n", dev_info, version);
609
610 return pci_register_driver(&prism2_plx_drv_id);
611}
612
613
614static void __exit exit_prism2_plx(void)
615{
616 pci_unregister_driver(&prism2_plx_drv_id);
617 printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
618}
619
620
621module_init(init_prism2_plx);
622module_exit(exit_prism2_plx);
diff --git a/drivers/net/wireless/hostap/hostap_proc.c b/drivers/net/wireless/hostap/hostap_proc.c
new file mode 100644
index 000000000000..a0a4cbd4937a
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_proc.c
@@ -0,0 +1,448 @@
1/* /proc routines for Host AP driver */
2
3#define PROC_LIMIT (PAGE_SIZE - 80)
4
5
6#ifndef PRISM2_NO_PROCFS_DEBUG
7static int prism2_debug_proc_read(char *page, char **start, off_t off,
8 int count, int *eof, void *data)
9{
10 char *p = page;
11 local_info_t *local = (local_info_t *) data;
12 int i;
13
14 if (off != 0) {
15 *eof = 1;
16 return 0;
17 }
18
19 p += sprintf(p, "next_txfid=%d next_alloc=%d\n",
20 local->next_txfid, local->next_alloc);
21 for (i = 0; i < PRISM2_TXFID_COUNT; i++)
22 p += sprintf(p, "FID: tx=%04X intransmit=%04X\n",
23 local->txfid[i], local->intransmitfid[i]);
24 p += sprintf(p, "FW TX rate control: %d\n", local->fw_tx_rate_control);
25 p += sprintf(p, "beacon_int=%d\n", local->beacon_int);
26 p += sprintf(p, "dtim_period=%d\n", local->dtim_period);
27 p += sprintf(p, "wds_max_connections=%d\n",
28 local->wds_max_connections);
29 p += sprintf(p, "dev_enabled=%d\n", local->dev_enabled);
30 p += sprintf(p, "sw_tick_stuck=%d\n", local->sw_tick_stuck);
31 for (i = 0; i < WEP_KEYS; i++) {
32 if (local->crypt[i] && local->crypt[i]->ops) {
33 p += sprintf(p, "crypt[%d]=%s\n",
34 i, local->crypt[i]->ops->name);
35 }
36 }
37 p += sprintf(p, "pri_only=%d\n", local->pri_only);
38 p += sprintf(p, "pci=%d\n", local->func->hw_type == HOSTAP_HW_PCI);
39 p += sprintf(p, "sram_type=%d\n", local->sram_type);
40 p += sprintf(p, "no_pri=%d\n", local->no_pri);
41
42 return (p - page);
43}
44#endif /* PRISM2_NO_PROCFS_DEBUG */
45
46
47static int prism2_stats_proc_read(char *page, char **start, off_t off,
48 int count, int *eof, void *data)
49{
50 char *p = page;
51 local_info_t *local = (local_info_t *) data;
52 struct comm_tallies_sums *sums = (struct comm_tallies_sums *)
53 &local->comm_tallies;
54
55 if (off != 0) {
56 *eof = 1;
57 return 0;
58 }
59
60 p += sprintf(p, "TxUnicastFrames=%u\n", sums->tx_unicast_frames);
61 p += sprintf(p, "TxMulticastframes=%u\n", sums->tx_multicast_frames);
62 p += sprintf(p, "TxFragments=%u\n", sums->tx_fragments);
63 p += sprintf(p, "TxUnicastOctets=%u\n", sums->tx_unicast_octets);
64 p += sprintf(p, "TxMulticastOctets=%u\n", sums->tx_multicast_octets);
65 p += sprintf(p, "TxDeferredTransmissions=%u\n",
66 sums->tx_deferred_transmissions);
67 p += sprintf(p, "TxSingleRetryFrames=%u\n",
68 sums->tx_single_retry_frames);
69 p += sprintf(p, "TxMultipleRetryFrames=%u\n",
70 sums->tx_multiple_retry_frames);
71 p += sprintf(p, "TxRetryLimitExceeded=%u\n",
72 sums->tx_retry_limit_exceeded);
73 p += sprintf(p, "TxDiscards=%u\n", sums->tx_discards);
74 p += sprintf(p, "RxUnicastFrames=%u\n", sums->rx_unicast_frames);
75 p += sprintf(p, "RxMulticastFrames=%u\n", sums->rx_multicast_frames);
76 p += sprintf(p, "RxFragments=%u\n", sums->rx_fragments);
77 p += sprintf(p, "RxUnicastOctets=%u\n", sums->rx_unicast_octets);
78 p += sprintf(p, "RxMulticastOctets=%u\n", sums->rx_multicast_octets);
79 p += sprintf(p, "RxFCSErrors=%u\n", sums->rx_fcs_errors);
80 p += sprintf(p, "RxDiscardsNoBuffer=%u\n",
81 sums->rx_discards_no_buffer);
82 p += sprintf(p, "TxDiscardsWrongSA=%u\n", sums->tx_discards_wrong_sa);
83 p += sprintf(p, "RxDiscardsWEPUndecryptable=%u\n",
84 sums->rx_discards_wep_undecryptable);
85 p += sprintf(p, "RxMessageInMsgFragments=%u\n",
86 sums->rx_message_in_msg_fragments);
87 p += sprintf(p, "RxMessageInBadMsgFragments=%u\n",
88 sums->rx_message_in_bad_msg_fragments);
89 /* FIX: this may grow too long for one page(?) */
90
91 return (p - page);
92}
93
94
95static int prism2_wds_proc_read(char *page, char **start, off_t off,
96 int count, int *eof, void *data)
97{
98 char *p = page;
99 local_info_t *local = (local_info_t *) data;
100 struct list_head *ptr;
101 struct hostap_interface *iface;
102
103 if (off > PROC_LIMIT) {
104 *eof = 1;
105 return 0;
106 }
107
108 read_lock_bh(&local->iface_lock);
109 list_for_each(ptr, &local->hostap_interfaces) {
110 iface = list_entry(ptr, struct hostap_interface, list);
111 if (iface->type != HOSTAP_INTERFACE_WDS)
112 continue;
113 p += sprintf(p, "%s\t" MACSTR "\n",
114 iface->dev->name,
115 MAC2STR(iface->u.wds.remote_addr));
116 if ((p - page) > PROC_LIMIT) {
117 printk(KERN_DEBUG "%s: wds proc did not fit\n",
118 local->dev->name);
119 break;
120 }
121 }
122 read_unlock_bh(&local->iface_lock);
123
124 if ((p - page) <= off) {
125 *eof = 1;
126 return 0;
127 }
128
129 *start = page + off;
130
131 return (p - page - off);
132}
133
134
135static int prism2_bss_list_proc_read(char *page, char **start, off_t off,
136 int count, int *eof, void *data)
137{
138 char *p = page;
139 local_info_t *local = (local_info_t *) data;
140 struct list_head *ptr;
141 struct hostap_bss_info *bss;
142 int i;
143
144 if (off > PROC_LIMIT) {
145 *eof = 1;
146 return 0;
147 }
148
149 p += sprintf(p, "#BSSID\tlast_update\tcount\tcapab_info\tSSID(txt)\t"
150 "SSID(hex)\tWPA IE\n");
151 spin_lock_bh(&local->lock);
152 list_for_each(ptr, &local->bss_list) {
153 bss = list_entry(ptr, struct hostap_bss_info, list);
154 p += sprintf(p, MACSTR "\t%lu\t%u\t0x%x\t",
155 MAC2STR(bss->bssid), bss->last_update,
156 bss->count, bss->capab_info);
157 for (i = 0; i < bss->ssid_len; i++) {
158 p += sprintf(p, "%c",
159 bss->ssid[i] >= 32 && bss->ssid[i] < 127 ?
160 bss->ssid[i] : '_');
161 }
162 p += sprintf(p, "\t");
163 for (i = 0; i < bss->ssid_len; i++) {
164 p += sprintf(p, "%02x", bss->ssid[i]);
165 }
166 p += sprintf(p, "\t");
167 for (i = 0; i < bss->wpa_ie_len; i++) {
168 p += sprintf(p, "%02x", bss->wpa_ie[i]);
169 }
170 p += sprintf(p, "\n");
171 if ((p - page) > PROC_LIMIT) {
172 printk(KERN_DEBUG "%s: BSS proc did not fit\n",
173 local->dev->name);
174 break;
175 }
176 }
177 spin_unlock_bh(&local->lock);
178
179 if ((p - page) <= off) {
180 *eof = 1;
181 return 0;
182 }
183
184 *start = page + off;
185
186 return (p - page - off);
187}
188
189
190static int prism2_crypt_proc_read(char *page, char **start, off_t off,
191 int count, int *eof, void *data)
192{
193 char *p = page;
194 local_info_t *local = (local_info_t *) data;
195 int i;
196
197 if (off > PROC_LIMIT) {
198 *eof = 1;
199 return 0;
200 }
201
202 p += sprintf(p, "tx_keyidx=%d\n", local->tx_keyidx);
203 for (i = 0; i < WEP_KEYS; i++) {
204 if (local->crypt[i] && local->crypt[i]->ops &&
205 local->crypt[i]->ops->print_stats) {
206 p = local->crypt[i]->ops->print_stats(
207 p, local->crypt[i]->priv);
208 }
209 }
210
211 if ((p - page) <= off) {
212 *eof = 1;
213 return 0;
214 }
215
216 *start = page + off;
217
218 return (p - page - off);
219}
220
221
222static int prism2_pda_proc_read(char *page, char **start, off_t off,
223 int count, int *eof, void *data)
224{
225 local_info_t *local = (local_info_t *) data;
226
227 if (local->pda == NULL || off >= PRISM2_PDA_SIZE) {
228 *eof = 1;
229 return 0;
230 }
231
232 if (off + count > PRISM2_PDA_SIZE)
233 count = PRISM2_PDA_SIZE - off;
234
235 memcpy(page, local->pda + off, count);
236 return count;
237}
238
239
240static int prism2_aux_dump_proc_read(char *page, char **start, off_t off,
241 int count, int *eof, void *data)
242{
243 local_info_t *local = (local_info_t *) data;
244
245 if (local->func->read_aux == NULL) {
246 *eof = 1;
247 return 0;
248 }
249
250 if (local->func->read_aux(local->dev, off, count, page)) {
251 *eof = 1;
252 return 0;
253 }
254 *start = page;
255
256 return count;
257}
258
259
260#ifdef PRISM2_IO_DEBUG
261static int prism2_io_debug_proc_read(char *page, char **start, off_t off,
262 int count, int *eof, void *data)
263{
264 local_info_t *local = (local_info_t *) data;
265 int head = local->io_debug_head;
266 int start_bytes, left, copy, copied;
267
268 if (off + count > PRISM2_IO_DEBUG_SIZE * 4) {
269 *eof = 1;
270 if (off >= PRISM2_IO_DEBUG_SIZE * 4)
271 return 0;
272 count = PRISM2_IO_DEBUG_SIZE * 4 - off;
273 }
274
275 copied = 0;
276 start_bytes = (PRISM2_IO_DEBUG_SIZE - head) * 4;
277 left = count;
278
279 if (off < start_bytes) {
280 copy = start_bytes - off;
281 if (copy > count)
282 copy = count;
283 memcpy(page, ((u8 *) &local->io_debug[head]) + off, copy);
284 left -= copy;
285 if (left > 0)
286 memcpy(&page[copy], local->io_debug, left);
287 } else {
288 memcpy(page, ((u8 *) local->io_debug) + (off - start_bytes),
289 left);
290 }
291
292 *start = page;
293
294 return count;
295}
296#endif /* PRISM2_IO_DEBUG */
297
298
299#ifndef PRISM2_NO_STATION_MODES
300static int prism2_scan_results_proc_read(char *page, char **start, off_t off,
301 int count, int *eof, void *data)
302{
303 char *p = page;
304 local_info_t *local = (local_info_t *) data;
305 int entry, i, len, total = 0;
306 struct hfa384x_hostscan_result *scanres;
307 u8 *pos;
308
309 p += sprintf(p, "CHID ANL SL BcnInt Capab Rate BSSID ATIM SupRates "
310 "SSID\n");
311
312 spin_lock_bh(&local->lock);
313 for (entry = 0; entry < local->last_scan_results_count; entry++) {
314 scanres = &local->last_scan_results[entry];
315
316 if (total + (p - page) <= off) {
317 total += p - page;
318 p = page;
319 }
320 if (total + (p - page) > off + count)
321 break;
322 if ((p - page) > (PAGE_SIZE - 200))
323 break;
324
325 p += sprintf(p, "%d %d %d %d 0x%02x %d " MACSTR " %d ",
326 le16_to_cpu(scanres->chid),
327 (s16) le16_to_cpu(scanres->anl),
328 (s16) le16_to_cpu(scanres->sl),
329 le16_to_cpu(scanres->beacon_interval),
330 le16_to_cpu(scanres->capability),
331 le16_to_cpu(scanres->rate),
332 MAC2STR(scanres->bssid),
333 le16_to_cpu(scanres->atim));
334
335 pos = scanres->sup_rates;
336 for (i = 0; i < sizeof(scanres->sup_rates); i++) {
337 if (pos[i] == 0)
338 break;
339 p += sprintf(p, "<%02x>", pos[i]);
340 }
341 p += sprintf(p, " ");
342
343 pos = scanres->ssid;
344 len = le16_to_cpu(scanres->ssid_len);
345 if (len > 32)
346 len = 32;
347 for (i = 0; i < len; i++) {
348 unsigned char c = pos[i];
349 if (c >= 32 && c < 127)
350 p += sprintf(p, "%c", c);
351 else
352 p += sprintf(p, "<%02x>", c);
353 }
354 p += sprintf(p, "\n");
355 }
356 spin_unlock_bh(&local->lock);
357
358 total += (p - page);
359 if (total >= off + count)
360 *eof = 1;
361
362 if (total < off) {
363 *eof = 1;
364 return 0;
365 }
366
367 len = total - off;
368 if (len > (p - page))
369 len = p - page;
370 *start = p - len;
371 if (len > count)
372 len = count;
373
374 return len;
375}
376#endif /* PRISM2_NO_STATION_MODES */
377
378
379void hostap_init_proc(local_info_t *local)
380{
381 local->proc = NULL;
382
383 if (hostap_proc == NULL) {
384 printk(KERN_WARNING "%s: hostap proc directory not created\n",
385 local->dev->name);
386 return;
387 }
388
389 local->proc = proc_mkdir(local->ddev->name, hostap_proc);
390 if (local->proc == NULL) {
391 printk(KERN_INFO "/proc/net/hostap/%s creation failed\n",
392 local->ddev->name);
393 return;
394 }
395
396#ifndef PRISM2_NO_PROCFS_DEBUG
397 create_proc_read_entry("debug", 0, local->proc,
398 prism2_debug_proc_read, local);
399#endif /* PRISM2_NO_PROCFS_DEBUG */
400 create_proc_read_entry("stats", 0, local->proc,
401 prism2_stats_proc_read, local);
402 create_proc_read_entry("wds", 0, local->proc,
403 prism2_wds_proc_read, local);
404 create_proc_read_entry("pda", 0, local->proc,
405 prism2_pda_proc_read, local);
406 create_proc_read_entry("aux_dump", 0, local->proc,
407 prism2_aux_dump_proc_read, local);
408 create_proc_read_entry("bss_list", 0, local->proc,
409 prism2_bss_list_proc_read, local);
410 create_proc_read_entry("crypt", 0, local->proc,
411 prism2_crypt_proc_read, local);
412#ifdef PRISM2_IO_DEBUG
413 create_proc_read_entry("io_debug", 0, local->proc,
414 prism2_io_debug_proc_read, local);
415#endif /* PRISM2_IO_DEBUG */
416#ifndef PRISM2_NO_STATION_MODES
417 create_proc_read_entry("scan_results", 0, local->proc,
418 prism2_scan_results_proc_read, local);
419#endif /* PRISM2_NO_STATION_MODES */
420}
421
422
423void hostap_remove_proc(local_info_t *local)
424{
425 if (local->proc != NULL) {
426#ifndef PRISM2_NO_STATION_MODES
427 remove_proc_entry("scan_results", local->proc);
428#endif /* PRISM2_NO_STATION_MODES */
429#ifdef PRISM2_IO_DEBUG
430 remove_proc_entry("io_debug", local->proc);
431#endif /* PRISM2_IO_DEBUG */
432 remove_proc_entry("pda", local->proc);
433 remove_proc_entry("aux_dump", local->proc);
434 remove_proc_entry("wds", local->proc);
435 remove_proc_entry("stats", local->proc);
436 remove_proc_entry("bss_list", local->proc);
437 remove_proc_entry("crypt", local->proc);
438#ifndef PRISM2_NO_PROCFS_DEBUG
439 remove_proc_entry("debug", local->proc);
440#endif /* PRISM2_NO_PROCFS_DEBUG */
441 if (hostap_proc != NULL)
442 remove_proc_entry(local->proc->name, hostap_proc);
443 }
444}
445
446
447EXPORT_SYMBOL(hostap_init_proc);
448EXPORT_SYMBOL(hostap_remove_proc);
diff --git a/drivers/net/wireless/hostap/hostap_wlan.h b/drivers/net/wireless/hostap/hostap_wlan.h
new file mode 100644
index 000000000000..a632d45f334d
--- /dev/null
+++ b/drivers/net/wireless/hostap/hostap_wlan.h
@@ -0,0 +1,1066 @@
1#ifndef HOSTAP_WLAN_H
2#define HOSTAP_WLAN_H
3
4#include "hostap_config.h"
5#include "hostap_common.h"
6
7#define MAX_PARM_DEVICES 8
8#define PARM_MIN_MAX "1-" __MODULE_STRING(MAX_PARM_DEVICES)
9#define DEF_INTS -1, -1, -1, -1, -1, -1, -1
10#define GET_INT_PARM(var,idx) var[var[idx] < 0 ? 0 : idx]
11
12
13/* Specific skb->protocol value that indicates that the packet already contains
14 * txdesc header.
15 * FIX: This might need own value that would be allocated especially for Prism2
16 * txdesc; ETH_P_CONTROL is commented as "Card specific control frames".
17 * However, these skb's should have only minimal path in the kernel side since
18 * prism2_send_mgmt() sends these with dev_queue_xmit() to prism2_tx(). */
19#define ETH_P_HOSTAP ETH_P_CONTROL
20
21#ifndef ARPHRD_IEEE80211
22#define ARPHRD_IEEE80211 801
23#endif
24#ifndef ARPHRD_IEEE80211_PRISM
25#define ARPHRD_IEEE80211_PRISM 802
26#endif
27
28/* ARPHRD_IEEE80211_PRISM uses a bloated version of Prism2 RX frame header
29 * (from linux-wlan-ng) */
30struct linux_wlan_ng_val {
31 u32 did;
32 u16 status, len;
33 u32 data;
34} __attribute__ ((packed));
35
36struct linux_wlan_ng_prism_hdr {
37 u32 msgcode, msglen;
38 char devname[16];
39 struct linux_wlan_ng_val hosttime, mactime, channel, rssi, sq, signal,
40 noise, rate, istx, frmlen;
41} __attribute__ ((packed));
42
43struct linux_wlan_ng_cap_hdr {
44 u32 version;
45 u32 length;
46 u64 mactime;
47 u64 hosttime;
48 u32 phytype;
49 u32 channel;
50 u32 datarate;
51 u32 antenna;
52 u32 priority;
53 u32 ssi_type;
54 s32 ssi_signal;
55 s32 ssi_noise;
56 u32 preamble;
57 u32 encoding;
58} __attribute__ ((packed));
59
60#define LWNG_CAP_DID_BASE (4 | (1 << 6)) /* section 4, group 1 */
61#define LWNG_CAPHDR_VERSION 0x80211001
62
63struct hfa384x_rx_frame {
64 /* HFA384X RX frame descriptor */
65 u16 status; /* HFA384X_RX_STATUS_ flags */
66 u32 time; /* timestamp, 1 microsecond resolution */
67 u8 silence; /* 27 .. 154; seems to be 0 */
68 u8 signal; /* 27 .. 154 */
69 u8 rate; /* 10, 20, 55, or 110 */
70 u8 rxflow;
71 u32 reserved;
72
73 /* 802.11 */
74 u16 frame_control;
75 u16 duration_id;
76 u8 addr1[6];
77 u8 addr2[6];
78 u8 addr3[6];
79 u16 seq_ctrl;
80 u8 addr4[6];
81 u16 data_len;
82
83 /* 802.3 */
84 u8 dst_addr[6];
85 u8 src_addr[6];
86 u16 len;
87
88 /* followed by frame data; max 2304 bytes */
89} __attribute__ ((packed));
90
91
92struct hfa384x_tx_frame {
93 /* HFA384X TX frame descriptor */
94 u16 status; /* HFA384X_TX_STATUS_ flags */
95 u16 reserved1;
96 u16 reserved2;
97 u32 sw_support;
98 u8 retry_count; /* not yet implemented */
99 u8 tx_rate; /* Host AP only; 0 = firmware, or 10, 20, 55, 110 */
100 u16 tx_control; /* HFA384X_TX_CTRL_ flags */
101
102 /* 802.11 */
103 u16 frame_control; /* parts not used */
104 u16 duration_id;
105 u8 addr1[6];
106 u8 addr2[6]; /* filled by firmware */
107 u8 addr3[6];
108 u16 seq_ctrl; /* filled by firmware */
109 u8 addr4[6];
110 u16 data_len;
111
112 /* 802.3 */
113 u8 dst_addr[6];
114 u8 src_addr[6];
115 u16 len;
116
117 /* followed by frame data; max 2304 bytes */
118} __attribute__ ((packed));
119
120
121struct hfa384x_rid_hdr
122{
123 u16 len;
124 u16 rid;
125} __attribute__ ((packed));
126
127
128/* Macro for converting signal levels (range 27 .. 154) to wireless ext
129 * dBm value with some accuracy */
130#define HFA384X_LEVEL_TO_dBm(v) 0x100 + (v) * 100 / 255 - 100
131
132#define HFA384X_LEVEL_TO_dBm_sign(v) (v) * 100 / 255 - 100
133
134struct hfa384x_scan_request {
135 u16 channel_list;
136 u16 txrate; /* HFA384X_RATES_* */
137} __attribute__ ((packed));
138
139struct hfa384x_hostscan_request {
140 u16 channel_list;
141 u16 txrate;
142 u16 target_ssid_len;
143 u8 target_ssid[32];
144} __attribute__ ((packed));
145
146struct hfa384x_join_request {
147 u8 bssid[6];
148 u16 channel;
149} __attribute__ ((packed));
150
151struct hfa384x_info_frame {
152 u16 len;
153 u16 type;
154} __attribute__ ((packed));
155
156struct hfa384x_comm_tallies {
157 u16 tx_unicast_frames;
158 u16 tx_multicast_frames;
159 u16 tx_fragments;
160 u16 tx_unicast_octets;
161 u16 tx_multicast_octets;
162 u16 tx_deferred_transmissions;
163 u16 tx_single_retry_frames;
164 u16 tx_multiple_retry_frames;
165 u16 tx_retry_limit_exceeded;
166 u16 tx_discards;
167 u16 rx_unicast_frames;
168 u16 rx_multicast_frames;
169 u16 rx_fragments;
170 u16 rx_unicast_octets;
171 u16 rx_multicast_octets;
172 u16 rx_fcs_errors;
173 u16 rx_discards_no_buffer;
174 u16 tx_discards_wrong_sa;
175 u16 rx_discards_wep_undecryptable;
176 u16 rx_message_in_msg_fragments;
177 u16 rx_message_in_bad_msg_fragments;
178} __attribute__ ((packed));
179
180struct hfa384x_comm_tallies32 {
181 u32 tx_unicast_frames;
182 u32 tx_multicast_frames;
183 u32 tx_fragments;
184 u32 tx_unicast_octets;
185 u32 tx_multicast_octets;
186 u32 tx_deferred_transmissions;
187 u32 tx_single_retry_frames;
188 u32 tx_multiple_retry_frames;
189 u32 tx_retry_limit_exceeded;
190 u32 tx_discards;
191 u32 rx_unicast_frames;
192 u32 rx_multicast_frames;
193 u32 rx_fragments;
194 u32 rx_unicast_octets;
195 u32 rx_multicast_octets;
196 u32 rx_fcs_errors;
197 u32 rx_discards_no_buffer;
198 u32 tx_discards_wrong_sa;
199 u32 rx_discards_wep_undecryptable;
200 u32 rx_message_in_msg_fragments;
201 u32 rx_message_in_bad_msg_fragments;
202} __attribute__ ((packed));
203
204struct hfa384x_scan_result_hdr {
205 u16 reserved;
206 u16 scan_reason;
207#define HFA384X_SCAN_IN_PROGRESS 0 /* no results available yet */
208#define HFA384X_SCAN_HOST_INITIATED 1
209#define HFA384X_SCAN_FIRMWARE_INITIATED 2
210#define HFA384X_SCAN_INQUIRY_FROM_HOST 3
211} __attribute__ ((packed));
212
213#define HFA384X_SCAN_MAX_RESULTS 32
214
215struct hfa384x_scan_result {
216 u16 chid;
217 u16 anl;
218 u16 sl;
219 u8 bssid[6];
220 u16 beacon_interval;
221 u16 capability;
222 u16 ssid_len;
223 u8 ssid[32];
224 u8 sup_rates[10];
225 u16 rate;
226} __attribute__ ((packed));
227
228struct hfa384x_hostscan_result {
229 u16 chid;
230 u16 anl;
231 u16 sl;
232 u8 bssid[6];
233 u16 beacon_interval;
234 u16 capability;
235 u16 ssid_len;
236 u8 ssid[32];
237 u8 sup_rates[10];
238 u16 rate;
239 u16 atim;
240} __attribute__ ((packed));
241
242struct comm_tallies_sums {
243 unsigned int tx_unicast_frames;
244 unsigned int tx_multicast_frames;
245 unsigned int tx_fragments;
246 unsigned int tx_unicast_octets;
247 unsigned int tx_multicast_octets;
248 unsigned int tx_deferred_transmissions;
249 unsigned int tx_single_retry_frames;
250 unsigned int tx_multiple_retry_frames;
251 unsigned int tx_retry_limit_exceeded;
252 unsigned int tx_discards;
253 unsigned int rx_unicast_frames;
254 unsigned int rx_multicast_frames;
255 unsigned int rx_fragments;
256 unsigned int rx_unicast_octets;
257 unsigned int rx_multicast_octets;
258 unsigned int rx_fcs_errors;
259 unsigned int rx_discards_no_buffer;
260 unsigned int tx_discards_wrong_sa;
261 unsigned int rx_discards_wep_undecryptable;
262 unsigned int rx_message_in_msg_fragments;
263 unsigned int rx_message_in_bad_msg_fragments;
264};
265
266
267struct hfa384x_regs {
268 u16 cmd;
269 u16 evstat;
270 u16 offset0;
271 u16 offset1;
272 u16 swsupport0;
273};
274
275
276#if defined(PRISM2_PCCARD) || defined(PRISM2_PLX)
277/* I/O ports for HFA384X Controller access */
278#define HFA384X_CMD_OFF 0x00
279#define HFA384X_PARAM0_OFF 0x02
280#define HFA384X_PARAM1_OFF 0x04
281#define HFA384X_PARAM2_OFF 0x06
282#define HFA384X_STATUS_OFF 0x08
283#define HFA384X_RESP0_OFF 0x0A
284#define HFA384X_RESP1_OFF 0x0C
285#define HFA384X_RESP2_OFF 0x0E
286#define HFA384X_INFOFID_OFF 0x10
287#define HFA384X_CONTROL_OFF 0x14
288#define HFA384X_SELECT0_OFF 0x18
289#define HFA384X_SELECT1_OFF 0x1A
290#define HFA384X_OFFSET0_OFF 0x1C
291#define HFA384X_OFFSET1_OFF 0x1E
292#define HFA384X_RXFID_OFF 0x20
293#define HFA384X_ALLOCFID_OFF 0x22
294#define HFA384X_TXCOMPLFID_OFF 0x24
295#define HFA384X_SWSUPPORT0_OFF 0x28
296#define HFA384X_SWSUPPORT1_OFF 0x2A
297#define HFA384X_SWSUPPORT2_OFF 0x2C
298#define HFA384X_EVSTAT_OFF 0x30
299#define HFA384X_INTEN_OFF 0x32
300#define HFA384X_EVACK_OFF 0x34
301#define HFA384X_DATA0_OFF 0x36
302#define HFA384X_DATA1_OFF 0x38
303#define HFA384X_AUXPAGE_OFF 0x3A
304#define HFA384X_AUXOFFSET_OFF 0x3C
305#define HFA384X_AUXDATA_OFF 0x3E
306#endif /* PRISM2_PCCARD || PRISM2_PLX */
307
308#ifdef PRISM2_PCI
309/* Memory addresses for ISL3874 controller access */
310#define HFA384X_CMD_OFF 0x00
311#define HFA384X_PARAM0_OFF 0x04
312#define HFA384X_PARAM1_OFF 0x08
313#define HFA384X_PARAM2_OFF 0x0C
314#define HFA384X_STATUS_OFF 0x10
315#define HFA384X_RESP0_OFF 0x14
316#define HFA384X_RESP1_OFF 0x18
317#define HFA384X_RESP2_OFF 0x1C
318#define HFA384X_INFOFID_OFF 0x20
319#define HFA384X_CONTROL_OFF 0x28
320#define HFA384X_SELECT0_OFF 0x30
321#define HFA384X_SELECT1_OFF 0x34
322#define HFA384X_OFFSET0_OFF 0x38
323#define HFA384X_OFFSET1_OFF 0x3C
324#define HFA384X_RXFID_OFF 0x40
325#define HFA384X_ALLOCFID_OFF 0x44
326#define HFA384X_TXCOMPLFID_OFF 0x48
327#define HFA384X_PCICOR_OFF 0x4C
328#define HFA384X_SWSUPPORT0_OFF 0x50
329#define HFA384X_SWSUPPORT1_OFF 0x54
330#define HFA384X_SWSUPPORT2_OFF 0x58
331#define HFA384X_PCIHCR_OFF 0x5C
332#define HFA384X_EVSTAT_OFF 0x60
333#define HFA384X_INTEN_OFF 0x64
334#define HFA384X_EVACK_OFF 0x68
335#define HFA384X_DATA0_OFF 0x6C
336#define HFA384X_DATA1_OFF 0x70
337#define HFA384X_AUXPAGE_OFF 0x74
338#define HFA384X_AUXOFFSET_OFF 0x78
339#define HFA384X_AUXDATA_OFF 0x7C
340#define HFA384X_PCI_M0_ADDRH_OFF 0x80
341#define HFA384X_PCI_M0_ADDRL_OFF 0x84
342#define HFA384X_PCI_M0_LEN_OFF 0x88
343#define HFA384X_PCI_M0_CTL_OFF 0x8C
344#define HFA384X_PCI_STATUS_OFF 0x98
345#define HFA384X_PCI_M1_ADDRH_OFF 0xA0
346#define HFA384X_PCI_M1_ADDRL_OFF 0xA4
347#define HFA384X_PCI_M1_LEN_OFF 0xA8
348#define HFA384X_PCI_M1_CTL_OFF 0xAC
349
350/* PCI bus master control bits (these are undocumented; based on guessing and
351 * experimenting..) */
352#define HFA384X_PCI_CTL_FROM_BAP (BIT(5) | BIT(1) | BIT(0))
353#define HFA384X_PCI_CTL_TO_BAP (BIT(5) | BIT(0))
354
355#endif /* PRISM2_PCI */
356
357
358/* Command codes for CMD reg. */
359#define HFA384X_CMDCODE_INIT 0x00
360#define HFA384X_CMDCODE_ENABLE 0x01
361#define HFA384X_CMDCODE_DISABLE 0x02
362#define HFA384X_CMDCODE_ALLOC 0x0A
363#define HFA384X_CMDCODE_TRANSMIT 0x0B
364#define HFA384X_CMDCODE_INQUIRE 0x11
365#define HFA384X_CMDCODE_ACCESS 0x21
366#define HFA384X_CMDCODE_ACCESS_WRITE (0x21 | BIT(8))
367#define HFA384X_CMDCODE_DOWNLOAD 0x22
368#define HFA384X_CMDCODE_READMIF 0x30
369#define HFA384X_CMDCODE_WRITEMIF 0x31
370#define HFA384X_CMDCODE_TEST 0x38
371
372#define HFA384X_CMDCODE_MASK 0x3F
373
374/* Test mode operations */
375#define HFA384X_TEST_CHANGE_CHANNEL 0x08
376#define HFA384X_TEST_MONITOR 0x0B
377#define HFA384X_TEST_STOP 0x0F
378#define HFA384X_TEST_CFG_BITS 0x15
379#define HFA384X_TEST_CFG_BIT_ALC BIT(3)
380
381#define HFA384X_CMD_BUSY BIT(15)
382
383#define HFA384X_CMD_TX_RECLAIM BIT(8)
384
385#define HFA384X_OFFSET_ERR BIT(14)
386#define HFA384X_OFFSET_BUSY BIT(15)
387
388
389/* ProgMode for download command */
390#define HFA384X_PROGMODE_DISABLE 0
391#define HFA384X_PROGMODE_ENABLE_VOLATILE 1
392#define HFA384X_PROGMODE_ENABLE_NON_VOLATILE 2
393#define HFA384X_PROGMODE_PROGRAM_NON_VOLATILE 3
394
395#define HFA384X_AUX_MAGIC0 0xfe01
396#define HFA384X_AUX_MAGIC1 0xdc23
397#define HFA384X_AUX_MAGIC2 0xba45
398
399#define HFA384X_AUX_PORT_DISABLED 0
400#define HFA384X_AUX_PORT_DISABLE BIT(14)
401#define HFA384X_AUX_PORT_ENABLE BIT(15)
402#define HFA384X_AUX_PORT_ENABLED (BIT(14) | BIT(15))
403#define HFA384X_AUX_PORT_MASK (BIT(14) | BIT(15))
404
405#define PRISM2_PDA_SIZE 1024
406
407
408/* Events; EvStat, Interrupt mask (IntEn), and acknowledge bits (EvAck) */
409#define HFA384X_EV_TICK BIT(15)
410#define HFA384X_EV_WTERR BIT(14)
411#define HFA384X_EV_INFDROP BIT(13)
412#ifdef PRISM2_PCI
413#define HFA384X_EV_PCI_M1 BIT(9)
414#define HFA384X_EV_PCI_M0 BIT(8)
415#endif /* PRISM2_PCI */
416#define HFA384X_EV_INFO BIT(7)
417#define HFA384X_EV_DTIM BIT(5)
418#define HFA384X_EV_CMD BIT(4)
419#define HFA384X_EV_ALLOC BIT(3)
420#define HFA384X_EV_TXEXC BIT(2)
421#define HFA384X_EV_TX BIT(1)
422#define HFA384X_EV_RX BIT(0)
423
424
425/* HFA384X Information frames */
426#define HFA384X_INFO_HANDOVERADDR 0xF000 /* AP f/w ? */
427#define HFA384X_INFO_HANDOVERDEAUTHADDR 0xF001 /* AP f/w 1.3.7 */
428#define HFA384X_INFO_COMMTALLIES 0xF100
429#define HFA384X_INFO_SCANRESULTS 0xF101
430#define HFA384X_INFO_CHANNELINFORESULTS 0xF102 /* AP f/w only */
431#define HFA384X_INFO_HOSTSCANRESULTS 0xF103
432#define HFA384X_INFO_LINKSTATUS 0xF200
433#define HFA384X_INFO_ASSOCSTATUS 0xF201 /* ? */
434#define HFA384X_INFO_AUTHREQ 0xF202 /* ? */
435#define HFA384X_INFO_PSUSERCNT 0xF203 /* ? */
436#define HFA384X_INFO_KEYIDCHANGED 0xF204 /* ? */
437
438enum { HFA384X_LINKSTATUS_CONNECTED = 1,
439 HFA384X_LINKSTATUS_DISCONNECTED = 2,
440 HFA384X_LINKSTATUS_AP_CHANGE = 3,
441 HFA384X_LINKSTATUS_AP_OUT_OF_RANGE = 4,
442 HFA384X_LINKSTATUS_AP_IN_RANGE = 5,
443 HFA384X_LINKSTATUS_ASSOC_FAILED = 6 };
444
445enum { HFA384X_PORTTYPE_BSS = 1, HFA384X_PORTTYPE_WDS = 2,
446 HFA384X_PORTTYPE_PSEUDO_IBSS = 3, HFA384X_PORTTYPE_IBSS = 0,
447 HFA384X_PORTTYPE_HOSTAP = 6 };
448
449#define HFA384X_RATES_1MBPS BIT(0)
450#define HFA384X_RATES_2MBPS BIT(1)
451#define HFA384X_RATES_5MBPS BIT(2)
452#define HFA384X_RATES_11MBPS BIT(3)
453
454#define HFA384X_ROAMING_FIRMWARE 1
455#define HFA384X_ROAMING_HOST 2
456#define HFA384X_ROAMING_DISABLED 3
457
458#define HFA384X_WEPFLAGS_PRIVACYINVOKED BIT(0)
459#define HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED BIT(1)
460#define HFA384X_WEPFLAGS_HOSTENCRYPT BIT(4)
461#define HFA384X_WEPFLAGS_HOSTDECRYPT BIT(7)
462
463#define HFA384X_RX_STATUS_MSGTYPE (BIT(15) | BIT(14) | BIT(13))
464#define HFA384X_RX_STATUS_PCF BIT(12)
465#define HFA384X_RX_STATUS_MACPORT (BIT(10) | BIT(9) | BIT(8))
466#define HFA384X_RX_STATUS_UNDECR BIT(1)
467#define HFA384X_RX_STATUS_FCSERR BIT(0)
468
469#define HFA384X_RX_STATUS_GET_MSGTYPE(s) \
470(((s) & HFA384X_RX_STATUS_MSGTYPE) >> 13)
471#define HFA384X_RX_STATUS_GET_MACPORT(s) \
472(((s) & HFA384X_RX_STATUS_MACPORT) >> 8)
473
474enum { HFA384X_RX_MSGTYPE_NORMAL = 0, HFA384X_RX_MSGTYPE_RFC1042 = 1,
475 HFA384X_RX_MSGTYPE_BRIDGETUNNEL = 2, HFA384X_RX_MSGTYPE_MGMT = 4 };
476
477
478#define HFA384X_TX_CTRL_ALT_RTRY BIT(5)
479#define HFA384X_TX_CTRL_802_11 BIT(3)
480#define HFA384X_TX_CTRL_802_3 0
481#define HFA384X_TX_CTRL_TX_EX BIT(2)
482#define HFA384X_TX_CTRL_TX_OK BIT(1)
483
484#define HFA384X_TX_STATUS_RETRYERR BIT(0)
485#define HFA384X_TX_STATUS_AGEDERR BIT(1)
486#define HFA384X_TX_STATUS_DISCON BIT(2)
487#define HFA384X_TX_STATUS_FORMERR BIT(3)
488
489/* HFA3861/3863 (BBP) Control Registers */
490#define HFA386X_CR_TX_CONFIGURE 0x12 /* CR9 */
491#define HFA386X_CR_RX_CONFIGURE 0x14 /* CR10 */
492#define HFA386X_CR_A_D_TEST_MODES2 0x1A /* CR13 */
493#define HFA386X_CR_MANUAL_TX_POWER 0x3E /* CR31 */
494#define HFA386X_CR_MEASURED_TX_POWER 0x74 /* CR58 */
495
496
497#ifdef __KERNEL__
498
499#define PRISM2_TXFID_COUNT 8
500#define PRISM2_DATA_MAXLEN 2304
501#define PRISM2_TXFID_LEN (PRISM2_DATA_MAXLEN + sizeof(struct hfa384x_tx_frame))
502#define PRISM2_TXFID_EMPTY 0xffff
503#define PRISM2_TXFID_RESERVED 0xfffe
504#define PRISM2_DUMMY_FID 0xffff
505#define MAX_SSID_LEN 32
506#define MAX_NAME_LEN 32 /* this is assumed to be equal to MAX_SSID_LEN */
507
508#define PRISM2_DUMP_RX_HDR BIT(0)
509#define PRISM2_DUMP_TX_HDR BIT(1)
510#define PRISM2_DUMP_TXEXC_HDR BIT(2)
511
512struct hostap_tx_callback_info {
513 u16 idx;
514 void (*func)(struct sk_buff *, int ok, void *);
515 void *data;
516 struct hostap_tx_callback_info *next;
517};
518
519
520/* IEEE 802.11 requires that STA supports concurrent reception of at least
521 * three fragmented frames. This define can be increased to support more
522 * concurrent frames, but it should be noted that each entry can consume about
523 * 2 kB of RAM and increasing cache size will slow down frame reassembly. */
524#define PRISM2_FRAG_CACHE_LEN 4
525
526struct prism2_frag_entry {
527 unsigned long first_frag_time;
528 unsigned int seq;
529 unsigned int last_frag;
530 struct sk_buff *skb;
531 u8 src_addr[ETH_ALEN];
532 u8 dst_addr[ETH_ALEN];
533};
534
535
536struct hostap_cmd_queue {
537 struct list_head list;
538 wait_queue_head_t compl;
539 volatile enum { CMD_SLEEP, CMD_CALLBACK, CMD_COMPLETED } type;
540 void (*callback)(struct net_device *dev, long context, u16 resp0,
541 u16 res);
542 long context;
543 u16 cmd, param0, param1;
544 u16 resp0, res;
545 volatile int issued, issuing;
546
547 atomic_t usecnt;
548 int del_req;
549};
550
551/* options for hw_shutdown */
552#define HOSTAP_HW_NO_DISABLE BIT(0)
553#define HOSTAP_HW_ENABLE_CMDCOMPL BIT(1)
554
555typedef struct local_info local_info_t;
556
557struct prism2_helper_functions {
558 /* these functions are defined in hardware model specific files
559 * (hostap_{cs,plx,pci}.c */
560 int (*card_present)(local_info_t *local);
561 void (*cor_sreset)(local_info_t *local);
562 int (*dev_open)(local_info_t *local);
563 int (*dev_close)(local_info_t *local);
564 void (*genesis_reset)(local_info_t *local, int hcr);
565
566 /* the following functions are from hostap_hw.c, but they may have some
567 * hardware model specific code */
568
569 /* FIX: low-level commands like cmd might disappear at some point to
570 * make it easier to change them if needed (e.g., cmd would be replaced
571 * with write_mif/read_mif/testcmd/inquire); at least get_rid and
572 * set_rid might move to hostap_{cs,plx,pci}.c */
573 int (*cmd)(struct net_device *dev, u16 cmd, u16 param0, u16 *param1,
574 u16 *resp0);
575 void (*read_regs)(struct net_device *dev, struct hfa384x_regs *regs);
576 int (*get_rid)(struct net_device *dev, u16 rid, void *buf, int len,
577 int exact_len);
578 int (*set_rid)(struct net_device *dev, u16 rid, void *buf, int len);
579 int (*hw_enable)(struct net_device *dev, int initial);
580 int (*hw_config)(struct net_device *dev, int initial);
581 void (*hw_reset)(struct net_device *dev);
582 void (*hw_shutdown)(struct net_device *dev, int no_disable);
583 int (*reset_port)(struct net_device *dev);
584 void (*schedule_reset)(local_info_t *local);
585 int (*download)(local_info_t *local,
586 struct prism2_download_param *param);
587 int (*tx)(struct sk_buff *skb, struct net_device *dev);
588 int (*set_tim)(struct net_device *dev, int aid, int set);
589 int (*read_aux)(struct net_device *dev, unsigned addr, int len,
590 u8 *buf);
591
592 int need_tx_headroom; /* number of bytes of headroom needed before
593 * IEEE 802.11 header */
594 enum { HOSTAP_HW_PCCARD, HOSTAP_HW_PLX, HOSTAP_HW_PCI } hw_type;
595};
596
597
598struct prism2_download_data {
599 u32 dl_cmd;
600 u32 start_addr;
601 u32 num_areas;
602 struct prism2_download_data_area {
603 u32 addr; /* wlan card address */
604 u32 len;
605 u8 *data; /* allocated data */
606 } data[0];
607};
608
609
610#define HOSTAP_MAX_BSS_COUNT 64
611#define MAX_WPA_IE_LEN 64
612
613struct hostap_bss_info {
614 struct list_head list;
615 unsigned long last_update;
616 unsigned int count;
617 u8 bssid[ETH_ALEN];
618 u16 capab_info;
619 u8 ssid[32];
620 size_t ssid_len;
621 u8 wpa_ie[MAX_WPA_IE_LEN];
622 size_t wpa_ie_len;
623 u8 rsn_ie[MAX_WPA_IE_LEN];
624 size_t rsn_ie_len;
625 int chan;
626 int included;
627};
628
629
630/* Per radio private Host AP data - shared by all net devices interfaces used
631 * by each radio (wlan#, wlan#ap, wlan#sta, WDS).
632 * ((struct hostap_interface *) netdev_priv(dev))->local points to this
633 * structure. */
634struct local_info {
635 struct module *hw_module;
636 int card_idx;
637 int dev_enabled;
638 int master_dev_auto_open; /* was master device opened automatically */
639 int num_dev_open; /* number of open devices */
640 struct net_device *dev; /* master radio device */
641 struct net_device *ddev; /* main data device */
642 struct list_head hostap_interfaces; /* Host AP interface list (contains
643 * struct hostap_interface entries)
644 */
645 rwlock_t iface_lock; /* hostap_interfaces read lock; use write lock
646 * when removing entries from the list.
647 * TX and RX paths can use read lock. */
648 spinlock_t cmdlock, baplock, lock;
649 struct semaphore rid_bap_sem;
650 u16 infofid; /* MAC buffer id for info frame */
651 /* txfid, intransmitfid, next_txtid, and next_alloc are protected by
652 * txfidlock */
653 spinlock_t txfidlock;
654 int txfid_len; /* length of allocated TX buffers */
655 u16 txfid[PRISM2_TXFID_COUNT]; /* buffer IDs for TX frames */
656 /* buffer IDs for intransmit frames or PRISM2_TXFID_EMPTY if
657 * corresponding txfid is free for next TX frame */
658 u16 intransmitfid[PRISM2_TXFID_COUNT];
659 int next_txfid; /* index to the next txfid to be checked for
660 * availability */
661 int next_alloc; /* index to the next intransmitfid to be checked for
662 * allocation events */
663
664 /* bitfield for atomic bitops */
665#define HOSTAP_BITS_TRANSMIT 0
666#define HOSTAP_BITS_BAP_TASKLET 1
667#define HOSTAP_BITS_BAP_TASKLET2 2
668 long bits;
669
670 struct ap_data *ap;
671
672 char essid[MAX_SSID_LEN + 1];
673 char name[MAX_NAME_LEN + 1];
674 int name_set;
675 u16 channel_mask; /* mask of allowed channels */
676 u16 scan_channel_mask; /* mask of channels to be scanned */
677 struct comm_tallies_sums comm_tallies;
678 struct net_device_stats stats;
679 struct proc_dir_entry *proc;
680 int iw_mode; /* operating mode (IW_MODE_*) */
681 int pseudo_adhoc; /* 0: IW_MODE_ADHOC is real 802.11 compliant IBSS
682 * 1: IW_MODE_ADHOC is "pseudo IBSS" */
683 char bssid[ETH_ALEN];
684 int channel;
685 int beacon_int;
686 int dtim_period;
687 int mtu;
688 int frame_dump; /* dump RX/TX frame headers, PRISM2_DUMP_ flags */
689 int fw_tx_rate_control;
690 u16 tx_rate_control;
691 u16 basic_rates;
692 int hw_resetting;
693 int hw_ready;
694 int hw_reset_tries; /* how many times reset has been tried */
695 int hw_downloading;
696 int shutdown;
697 int pri_only;
698 int no_pri; /* no PRI f/w present */
699 int sram_type; /* 8 = x8 SRAM, 16 = x16 SRAM, -1 = unknown */
700
701 enum {
702 PRISM2_TXPOWER_AUTO = 0, PRISM2_TXPOWER_OFF,
703 PRISM2_TXPOWER_FIXED, PRISM2_TXPOWER_UNKNOWN
704 } txpower_type;
705 int txpower; /* if txpower_type == PRISM2_TXPOWER_FIXED */
706
707 /* command queue for hfa384x_cmd(); protected with cmdlock */
708 struct list_head cmd_queue;
709 /* max_len for cmd_queue; in addition, cmd_callback can use two
710 * additional entries to prevent sleeping commands from stopping
711 * transmits */
712#define HOSTAP_CMD_QUEUE_MAX_LEN 16
713 int cmd_queue_len; /* number of entries in cmd_queue */
714
715 /* if card timeout is detected in interrupt context, reset_queue is
716 * used to schedule card reseting to be done in user context */
717 struct work_struct reset_queue;
718
719 /* For scheduling a change of the promiscuous mode RID */
720 int is_promisc;
721 struct work_struct set_multicast_list_queue;
722
723 struct work_struct set_tim_queue;
724 struct list_head set_tim_list;
725 spinlock_t set_tim_lock;
726
727 int wds_max_connections;
728 int wds_connections;
729#define HOSTAP_WDS_BROADCAST_RA BIT(0)
730#define HOSTAP_WDS_AP_CLIENT BIT(1)
731#define HOSTAP_WDS_STANDARD_FRAME BIT(2)
732 u32 wds_type;
733 u16 tx_control; /* flags to be used in TX description */
734 int manual_retry_count; /* -1 = use f/w default; otherwise retry count
735 * to be used with all frames */
736
737 struct iw_statistics wstats;
738 unsigned long scan_timestamp; /* Time started to scan */
739 enum {
740 PRISM2_MONITOR_80211 = 0, PRISM2_MONITOR_PRISM = 1,
741 PRISM2_MONITOR_CAPHDR = 2
742 } monitor_type;
743 int (*saved_eth_header_parse)(struct sk_buff *skb,
744 unsigned char *haddr);
745 int monitor_allow_fcserr;
746
747 int hostapd; /* whether user space daemon, hostapd, is used for AP
748 * management */
749 int hostapd_sta; /* whether hostapd is used with an extra STA interface
750 */
751 struct net_device *apdev;
752 struct net_device_stats apdevstats;
753
754 char assoc_ap_addr[ETH_ALEN];
755 struct net_device *stadev;
756 struct net_device_stats stadevstats;
757
758#define WEP_KEYS 4
759#define WEP_KEY_LEN 13
760 struct ieee80211_crypt_data *crypt[WEP_KEYS];
761 int tx_keyidx; /* default TX key index (crypt[tx_keyidx]) */
762 struct timer_list crypt_deinit_timer;
763 struct list_head crypt_deinit_list;
764
765 int open_wep; /* allow unencrypted frames */
766 int host_encrypt;
767 int host_decrypt;
768 int privacy_invoked; /* force privacy invoked flag even if no keys are
769 * configured */
770 int fw_encrypt_ok; /* whether firmware-based WEP encrypt is working
771 * in Host AP mode (STA f/w 1.4.9 or newer) */
772 int bcrx_sta_key; /* use individual keys to override default keys even
773 * with RX of broad/multicast frames */
774
775 struct prism2_frag_entry frag_cache[PRISM2_FRAG_CACHE_LEN];
776 unsigned int frag_next_idx;
777
778 int ieee_802_1x; /* is IEEE 802.1X used */
779
780 int antsel_tx, antsel_rx;
781 int rts_threshold; /* dot11RTSThreshold */
782 int fragm_threshold; /* dot11FragmentationThreshold */
783 int auth_algs; /* PRISM2_AUTH_ flags */
784
785 int enh_sec; /* cnfEnhSecurity options (broadcast SSID hide/ignore) */
786 int tallies32; /* 32-bit tallies in use */
787
788 struct prism2_helper_functions *func;
789
790 int bus_master_threshold_tx;
791 int bus_master_threshold_rx;
792 u8 *bus_m1_buf;
793
794 u8 *pda;
795 int fw_ap;
796#define PRISM2_FW_VER(major, minor, variant) \
797(((major) << 16) | ((minor) << 8) | variant)
798 u32 sta_fw_ver;
799
800 /* Tasklets for handling hardware IRQ related operations outside hw IRQ
801 * handler */
802 struct tasklet_struct bap_tasklet;
803
804 struct tasklet_struct info_tasklet;
805 struct sk_buff_head info_list; /* info frames as skb's for
806 * info_tasklet */
807
808 struct hostap_tx_callback_info *tx_callback; /* registered TX callbacks
809 */
810
811 struct tasklet_struct rx_tasklet;
812 struct sk_buff_head rx_list;
813
814 struct tasklet_struct sta_tx_exc_tasklet;
815 struct sk_buff_head sta_tx_exc_list;
816
817 int host_roaming;
818 unsigned long last_join_time; /* time of last JoinRequest */
819 struct hfa384x_hostscan_result *last_scan_results;
820 int last_scan_results_count;
821 enum { PRISM2_SCAN, PRISM2_HOSTSCAN } last_scan_type;
822 struct work_struct info_queue;
823 long pending_info; /* bit field of pending info_queue items */
824#define PRISM2_INFO_PENDING_LINKSTATUS 0
825#define PRISM2_INFO_PENDING_SCANRESULTS 1
826 int prev_link_status; /* previous received LinkStatus info */
827 int prev_linkstatus_connected;
828 u8 preferred_ap[6]; /* use this AP if possible */
829
830#ifdef PRISM2_CALLBACK
831 void *callback_data; /* Can be used in callbacks; e.g., allocate
832 * on enable event and free on disable event.
833 * Host AP driver code does not touch this. */
834#endif /* PRISM2_CALLBACK */
835
836 wait_queue_head_t hostscan_wq;
837
838 /* Passive scan in Host AP mode */
839 struct timer_list passive_scan_timer;
840 int passive_scan_interval; /* in seconds, 0 = disabled */
841 int passive_scan_channel;
842 enum { PASSIVE_SCAN_WAIT, PASSIVE_SCAN_LISTEN } passive_scan_state;
843
844 struct timer_list tick_timer;
845 unsigned long last_tick_timer;
846 unsigned int sw_tick_stuck;
847
848 /* commsQuality / dBmCommsQuality data from periodic polling; only
849 * valid for Managed and Ad-hoc modes */
850 unsigned long last_comms_qual_update;
851 int comms_qual; /* in some odd unit.. */
852 int avg_signal; /* in dB (note: negative) */
853 int avg_noise; /* in dB (note: negative) */
854 struct work_struct comms_qual_update;
855
856 /* RSSI to dBm adjustment (for RX descriptor fields) */
857 int rssi_to_dBm; /* substract from RSSI to get approximate dBm value */
858
859 /* BSS list / protected by local->lock */
860 struct list_head bss_list;
861 int num_bss_info;
862 int wpa; /* WPA support enabled */
863 int tkip_countermeasures;
864 int drop_unencrypted;
865 /* Generic IEEE 802.11 info element to be added to
866 * ProbeResp/Beacon/(Re)AssocReq */
867 u8 *generic_elem;
868 size_t generic_elem_len;
869
870#ifdef PRISM2_DOWNLOAD_SUPPORT
871 /* Persistent volatile download data */
872 struct prism2_download_data *dl_pri;
873 struct prism2_download_data *dl_sec;
874#endif /* PRISM2_DOWNLOAD_SUPPORT */
875
876#ifdef PRISM2_IO_DEBUG
877#define PRISM2_IO_DEBUG_SIZE 10000
878 u32 io_debug[PRISM2_IO_DEBUG_SIZE];
879 int io_debug_head;
880 int io_debug_enabled;
881#endif /* PRISM2_IO_DEBUG */
882
883 /* struct local_info is used also in hostap.o that does not define
884 * any PRISM2_{PCCARD,PLX,PCI}. Make sure that the hardware version
885 * specific fields are in the end of the struct (these could also be
886 * moved to void *priv or something like that). */
887#ifdef PRISM2_PCCARD
888 dev_node_t node;
889 dev_link_t *link;
890 int sandisk_connectplus;
891#endif /* PRISM2_PCCARD */
892
893#ifdef PRISM2_PLX
894 void __iomem *attr_mem;
895 unsigned int cor_offset;
896#endif /* PRISM2_PLX */
897
898#ifdef PRISM2_PCI
899 void __iomem *mem_start;
900#ifdef PRISM2_BUS_MASTER
901 /* bus master for BAP0 (TX) */
902 int bus_m0_tx_idx;
903 u8 *bus_m0_buf;
904
905 /* bus master for BAP1 (RX) */
906 struct sk_buff *rx_skb;
907#endif /* PRISM2_BUS_MASTER */
908#endif /* PRISM2_PCI */
909
910 /* NOTE! Do not add common entries here after hardware version
911 * specific blocks. */
912};
913
914
915/* Per interface private Host AP data
916 * Allocated for each net device that Host AP uses (wlan#, wlan#ap, wlan#sta,
917 * WDS) and netdev_priv(dev) points to this structure. */
918struct hostap_interface {
919 struct list_head list; /* list entry in Host AP interface list */
920 struct net_device *dev; /* pointer to this device */
921 struct local_info *local; /* pointer to shared private data */
922 struct net_device_stats stats;
923 struct iw_spy_data spy_data; /* iwspy support */
924 struct iw_public_data wireless_data;
925
926 enum {
927 HOSTAP_INTERFACE_MASTER,
928 HOSTAP_INTERFACE_MAIN,
929 HOSTAP_INTERFACE_AP,
930 HOSTAP_INTERFACE_STA,
931 HOSTAP_INTERFACE_WDS,
932 } type;
933
934 union {
935 struct hostap_interface_wds {
936 u8 remote_addr[ETH_ALEN];
937 } wds;
938 } u;
939};
940
941
942#define HOSTAP_SKB_TX_DATA_MAGIC 0xf08a36a2
943
944/* TX meta data - stored in skb->cb buffer, so this must be not increase over
945 * 48-byte limit */
946struct hostap_skb_tx_data {
947 unsigned int magic; /* HOSTAP_SKB_TX_DATA_MAGIC */
948 int rate; /* transmit rate */
949 struct hostap_interface *iface;
950 unsigned long jiffies; /* queueing timestamp */
951 int wds;
952 unsigned short ethertype;
953 int tx_cb_idx;
954};
955
956
957#ifndef PRISM2_NO_DEBUG
958
959#define DEBUG_FID BIT(0)
960#define DEBUG_PS BIT(1)
961#define DEBUG_FLOW BIT(2)
962#define DEBUG_AP BIT(3)
963#define DEBUG_HW BIT(4)
964#define DEBUG_EXTRA BIT(5)
965#define DEBUG_EXTRA2 BIT(6)
966#define DEBUG_PS2 BIT(7)
967#define DEBUG_MASK (DEBUG_PS | DEBUG_AP | DEBUG_HW | DEBUG_EXTRA)
968#define PDEBUG(n, args...) \
969do { if ((n) & DEBUG_MASK) printk(KERN_DEBUG args); } while (0)
970#define PDEBUG2(n, args...) \
971do { if ((n) & DEBUG_MASK) printk(args); } while (0)
972
973#else /* PRISM2_NO_DEBUG */
974
975#define PDEBUG(n, args...)
976#define PDEBUG2(n, args...)
977
978#endif /* PRISM2_NO_DEBUG */
979
980enum { BAP0 = 0, BAP1 = 1 };
981
982#define PRISM2_IO_DEBUG_CMD_INB 0
983#define PRISM2_IO_DEBUG_CMD_INW 1
984#define PRISM2_IO_DEBUG_CMD_INSW 2
985#define PRISM2_IO_DEBUG_CMD_OUTB 3
986#define PRISM2_IO_DEBUG_CMD_OUTW 4
987#define PRISM2_IO_DEBUG_CMD_OUTSW 5
988#define PRISM2_IO_DEBUG_CMD_ERROR 6
989#define PRISM2_IO_DEBUG_CMD_INTERRUPT 7
990
991#ifdef PRISM2_IO_DEBUG
992
993#define PRISM2_IO_DEBUG_ENTRY(cmd, reg, value) \
994(((cmd) << 24) | ((reg) << 16) | value)
995
996static inline void prism2_io_debug_add(struct net_device *dev, int cmd,
997 int reg, int value)
998{
999 struct hostap_interface *iface = netdev_priv(dev);
1000 local_info_t *local = iface->local;
1001
1002 if (!local->io_debug_enabled)
1003 return;
1004
1005 local->io_debug[local->io_debug_head] = jiffies & 0xffffffff;
1006 if (++local->io_debug_head >= PRISM2_IO_DEBUG_SIZE)
1007 local->io_debug_head = 0;
1008 local->io_debug[local->io_debug_head] =
1009 PRISM2_IO_DEBUG_ENTRY(cmd, reg, value);
1010 if (++local->io_debug_head >= PRISM2_IO_DEBUG_SIZE)
1011 local->io_debug_head = 0;
1012}
1013
1014
1015static inline void prism2_io_debug_error(struct net_device *dev, int err)
1016{
1017 struct hostap_interface *iface = netdev_priv(dev);
1018 local_info_t *local = iface->local;
1019 unsigned long flags;
1020
1021 if (!local->io_debug_enabled)
1022 return;
1023
1024 spin_lock_irqsave(&local->lock, flags);
1025 prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_ERROR, 0, err);
1026 if (local->io_debug_enabled == 1) {
1027 local->io_debug_enabled = 0;
1028 printk(KERN_DEBUG "%s: I/O debug stopped\n", dev->name);
1029 }
1030 spin_unlock_irqrestore(&local->lock, flags);
1031}
1032
1033#else /* PRISM2_IO_DEBUG */
1034
1035static inline void prism2_io_debug_add(struct net_device *dev, int cmd,
1036 int reg, int value)
1037{
1038}
1039
1040static inline void prism2_io_debug_error(struct net_device *dev, int err)
1041{
1042}
1043
1044#endif /* PRISM2_IO_DEBUG */
1045
1046
1047#ifdef PRISM2_CALLBACK
1048enum {
1049 /* Called when card is enabled */
1050 PRISM2_CALLBACK_ENABLE,
1051
1052 /* Called when card is disabled */
1053 PRISM2_CALLBACK_DISABLE,
1054
1055 /* Called when RX/TX starts/ends */
1056 PRISM2_CALLBACK_RX_START, PRISM2_CALLBACK_RX_END,
1057 PRISM2_CALLBACK_TX_START, PRISM2_CALLBACK_TX_END
1058};
1059void prism2_callback(local_info_t *local, int event);
1060#else /* PRISM2_CALLBACK */
1061#define prism2_callback(d, e) do { } while (0)
1062#endif /* PRISM2_CALLBACK */
1063
1064#endif /* __KERNEL__ */
1065
1066#endif /* HOSTAP_WLAN_H */
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index 6c42b573a95a..4b0acae22b0d 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -209,7 +209,7 @@ enum {
209 NoStructure = 0, /* Really old firmware */ 209 NoStructure = 0, /* Really old firmware */
210 StructuredMessages = 1, /* Parsable AT response msgs */ 210 StructuredMessages = 1, /* Parsable AT response msgs */
211 ChecksummedMessages = 2 /* Parsable AT response msgs with checksums */ 211 ChecksummedMessages = 2 /* Parsable AT response msgs with checksums */
212} FirmwareLevel; 212};
213 213
214struct strip { 214struct strip {
215 int magic; 215 int magic;
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index f6130a53b796..183c4732ef65 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -59,6 +59,12 @@
59/* Do *NOT* add other headers here, you are guaranteed to be wrong - Jean II */ 59/* Do *NOT* add other headers here, you are guaranteed to be wrong - Jean II */
60#include "wavelan_cs.p.h" /* Private header */ 60#include "wavelan_cs.p.h" /* Private header */
61 61
62#ifdef WAVELAN_ROAMING
63static void wl_cell_expiry(unsigned long data);
64static void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp);
65static void wv_nwid_filter(unsigned char mode, net_local *lp);
66#endif /* WAVELAN_ROAMING */
67
62/************************* MISC SUBROUTINES **************************/ 68/************************* MISC SUBROUTINES **************************/
63/* 69/*
64 * Subroutines which won't fit in one of the following category 70 * Subroutines which won't fit in one of the following category
@@ -500,9 +506,9 @@ fee_write(u_long base, /* i/o port of the card */
500 506
501#ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */ 507#ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */
502 508
503unsigned char WAVELAN_BEACON_ADDRESS[]= {0x09,0x00,0x0e,0x20,0x03,0x00}; 509static unsigned char WAVELAN_BEACON_ADDRESS[] = {0x09,0x00,0x0e,0x20,0x03,0x00};
504 510
505void wv_roam_init(struct net_device *dev) 511static void wv_roam_init(struct net_device *dev)
506{ 512{
507 net_local *lp= netdev_priv(dev); 513 net_local *lp= netdev_priv(dev);
508 514
@@ -531,7 +537,7 @@ void wv_roam_init(struct net_device *dev)
531 printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name); 537 printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name);
532} 538}
533 539
534void wv_roam_cleanup(struct net_device *dev) 540static void wv_roam_cleanup(struct net_device *dev)
535{ 541{
536 wavepoint_history *ptr,*old_ptr; 542 wavepoint_history *ptr,*old_ptr;
537 net_local *lp= netdev_priv(dev); 543 net_local *lp= netdev_priv(dev);
@@ -550,7 +556,7 @@ void wv_roam_cleanup(struct net_device *dev)
550} 556}
551 557
552/* Enable/Disable NWID promiscuous mode on a given device */ 558/* Enable/Disable NWID promiscuous mode on a given device */
553void wv_nwid_filter(unsigned char mode, net_local *lp) 559static void wv_nwid_filter(unsigned char mode, net_local *lp)
554{ 560{
555 mm_t m; 561 mm_t m;
556 unsigned long flags; 562 unsigned long flags;
@@ -575,7 +581,7 @@ void wv_nwid_filter(unsigned char mode, net_local *lp)
575} 581}
576 582
577/* Find a record in the WavePoint table matching a given NWID */ 583/* Find a record in the WavePoint table matching a given NWID */
578wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp) 584static wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
579{ 585{
580 wavepoint_history *ptr=lp->wavepoint_table.head; 586 wavepoint_history *ptr=lp->wavepoint_table.head;
581 587
@@ -588,7 +594,7 @@ wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
588} 594}
589 595
590/* Create a new wavepoint table entry */ 596/* Create a new wavepoint table entry */
591wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp) 597static wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp)
592{ 598{
593 wavepoint_history *new_wavepoint; 599 wavepoint_history *new_wavepoint;
594 600
@@ -624,7 +630,7 @@ wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_
624} 630}
625 631
626/* Remove a wavepoint entry from WavePoint table */ 632/* Remove a wavepoint entry from WavePoint table */
627void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp) 633static void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
628{ 634{
629 if(wavepoint==NULL) 635 if(wavepoint==NULL)
630 return; 636 return;
@@ -646,7 +652,7 @@ void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
646} 652}
647 653
648/* Timer callback function - checks WavePoint table for stale entries */ 654/* Timer callback function - checks WavePoint table for stale entries */
649void wl_cell_expiry(unsigned long data) 655static void wl_cell_expiry(unsigned long data)
650{ 656{
651 net_local *lp=(net_local *)data; 657 net_local *lp=(net_local *)data;
652 wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point; 658 wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point;
@@ -686,7 +692,7 @@ void wl_cell_expiry(unsigned long data)
686} 692}
687 693
688/* Update SNR history of a wavepoint */ 694/* Update SNR history of a wavepoint */
689void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq) 695static void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq)
690{ 696{
691 int i=0,num_missed=0,ptr=0; 697 int i=0,num_missed=0,ptr=0;
692 int average_fast=0,average_slow=0; 698 int average_fast=0,average_slow=0;
@@ -723,7 +729,7 @@ void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsi
723} 729}
724 730
725/* Perform a handover to a new WavePoint */ 731/* Perform a handover to a new WavePoint */
726void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp) 732static void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
727{ 733{
728 kio_addr_t base = lp->dev->base_addr; 734 kio_addr_t base = lp->dev->base_addr;
729 mm_t m; 735 mm_t m;
diff --git a/drivers/net/wireless/wavelan_cs.h b/drivers/net/wireless/wavelan_cs.h
index 29cff6daf860..fabc63ee153c 100644
--- a/drivers/net/wireless/wavelan_cs.h
+++ b/drivers/net/wireless/wavelan_cs.h
@@ -62,7 +62,7 @@
62 * like DEC RoamAbout, or Digital Ocean, Epson, ...), you must modify this 62 * like DEC RoamAbout, or Digital Ocean, Epson, ...), you must modify this
63 * part to accommodate your hardware... 63 * part to accommodate your hardware...
64 */ 64 */
65const unsigned char MAC_ADDRESSES[][3] = 65static const unsigned char MAC_ADDRESSES[][3] =
66{ 66{
67 { 0x08, 0x00, 0x0E }, /* AT&T Wavelan (standard) & DEC RoamAbout */ 67 { 0x08, 0x00, 0x0E }, /* AT&T Wavelan (standard) & DEC RoamAbout */
68 { 0x08, 0x00, 0x6A }, /* AT&T Wavelan (alternate) */ 68 { 0x08, 0x00, 0x6A }, /* AT&T Wavelan (alternate) */
@@ -79,14 +79,14 @@ const unsigned char MAC_ADDRESSES[][3] =
79 * (as read in the offset register of the dac area). 79 * (as read in the offset register of the dac area).
80 * Used to map channel numbers used by `wfreqsel' to frequencies 80 * Used to map channel numbers used by `wfreqsel' to frequencies
81 */ 81 */
82const short channel_bands[] = { 0x30, 0x58, 0x64, 0x7A, 0x80, 0xA8, 82static const short channel_bands[] = { 0x30, 0x58, 0x64, 0x7A, 0x80, 0xA8,
83 0xD0, 0xF0, 0xF8, 0x150 }; 83 0xD0, 0xF0, 0xF8, 0x150 };
84 84
85/* Frequencies of the 1.0 modem (fixed frequencies). 85/* Frequencies of the 1.0 modem (fixed frequencies).
86 * Use to map the PSA `subband' to a frequency 86 * Use to map the PSA `subband' to a frequency
87 * Note : all frequencies apart from the first one need to be multiplied by 10 87 * Note : all frequencies apart from the first one need to be multiplied by 10
88 */ 88 */
89const int fixed_bands[] = { 915e6, 2.425e8, 2.46e8, 2.484e8, 2.4305e8 }; 89static const int fixed_bands[] = { 915e6, 2.425e8, 2.46e8, 2.484e8, 2.4305e8 };
90 90
91 91
92/*************************** PC INTERFACE ****************************/ 92/*************************** PC INTERFACE ****************************/
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h
index 677ff71883cb..01d882be8790 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/net/wireless/wavelan_cs.p.h
@@ -647,23 +647,6 @@ struct net_local
647 void __iomem *mem; 647 void __iomem *mem;
648}; 648};
649 649
650/**************************** PROTOTYPES ****************************/
651
652#ifdef WAVELAN_ROAMING
653/* ---------------------- ROAMING SUBROUTINES -----------------------*/
654
655wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp);
656wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local *lp);
657void wl_del_wavepoint(wavepoint_history *wavepoint, net_local *lp);
658void wl_cell_expiry(unsigned long data);
659wavepoint_history *wl_best_sigqual(int fast_search, net_local *lp);
660void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq);
661void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp);
662void wv_nwid_filter(unsigned char mode, net_local *lp);
663void wv_roam_init(struct net_device *dev);
664void wv_roam_cleanup(struct net_device *dev);
665#endif /* WAVELAN_ROAMING */
666
667/* ----------------- MODEM MANAGEMENT SUBROUTINES ----------------- */ 650/* ----------------- MODEM MANAGEMENT SUBROUTINES ----------------- */
668static inline u_char /* data */ 651static inline u_char /* data */
669 hasr_read(u_long); /* Read the host interface : base address */ 652 hasr_read(u_long); /* Read the host interface : base address */
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index dd902126d018..7cc5edbf6ede 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -296,7 +296,8 @@ static int wl3501_get_flash_mac_addr(struct wl3501_card *this)
296 * 296 *
297 * Move 'size' bytes from PC to card. (Shouldn't be interrupted) 297 * Move 'size' bytes from PC to card. (Shouldn't be interrupted)
298 */ 298 */
299void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src, int size) 299static void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src,
300 int size)
300{ 301{
301 /* switch to SRAM Page 0 */ 302 /* switch to SRAM Page 0 */
302 wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 : 303 wl3501_switch_page(this, (dest & 0x8000) ? WL3501_BSS_SPAGE1 :
@@ -317,8 +318,8 @@ void wl3501_set_to_wla(struct wl3501_card *this, u16 dest, void *src, int size)
317 * 318 *
318 * Move 'size' bytes from card to PC. (Shouldn't be interrupted) 319 * Move 'size' bytes from card to PC. (Shouldn't be interrupted)
319 */ 320 */
320void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest, 321static void wl3501_get_from_wla(struct wl3501_card *this, u16 src, void *dest,
321 int size) 322 int size)
322{ 323{
323 /* switch to SRAM Page 0 */ 324 /* switch to SRAM Page 0 */
324 wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 : 325 wl3501_switch_page(this, (src & 0x8000) ? WL3501_BSS_SPAGE1 :
@@ -1438,14 +1439,14 @@ fail:
1438 goto out; 1439 goto out;
1439} 1440}
1440 1441
1441struct net_device_stats *wl3501_get_stats(struct net_device *dev) 1442static struct net_device_stats *wl3501_get_stats(struct net_device *dev)
1442{ 1443{
1443 struct wl3501_card *this = dev->priv; 1444 struct wl3501_card *this = dev->priv;
1444 1445
1445 return &this->stats; 1446 return &this->stats;
1446} 1447}
1447 1448
1448struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev) 1449static struct iw_statistics *wl3501_get_wireless_stats(struct net_device *dev)
1449{ 1450{
1450 struct wl3501_card *this = dev->priv; 1451 struct wl3501_card *this = dev->priv;
1451 struct iw_statistics *wstats = &this->wstats; 1452 struct iw_statistics *wstats = &this->wstats;